Section dedup.
Variable A : Type.
Hypothesis A_eq_dec : forall x y : A, {x = y} + {x <> y}.
Fixpoint dedup (xs : list A) : list A :=
match xs with
| [] => []
| x :: xs => let tail := dedup xs in
if in_dec A_eq_dec x xs then
tail
else
x :: tail
end.
Proof using.
intros. simpl in *.
break_match.
+ auto.
+ exfalso. intuition auto with datatypes.
Qed.
Proof using.
induction xs; intros; simpl in *.
- intuition.
- break_if; intuition auto; subst; simpl; auto.
Qed.
Proof using.
intros.
induction xs; simpl; repeat (break_match; simpl);
auto using f_equal2; try discriminate.
- exfalso. apply n. apply in_app_iff.
apply in_app_or in i. intuition auto with datatypes.
- exfalso. apply n. apply in_app_or in i.
break_or_hyp.
+ auto with datatypes.
+ simpl in *; break_or_hyp.
* congruence.
* auto with datatypes.
Qed.
Proof using.
intros. induction xs; simpl; auto.
repeat break_match.
- apply IHxs.
intros. apply H; intuition auto with datatypes.
- exfalso. specialize (H a a).
apply H; intuition auto with datatypes.
do_in_app. intuition.
- exfalso. apply n. intuition auto with datatypes.
- simpl. f_equal.
apply IHxs.
intros. apply H; intuition auto with datatypes.
Qed.
Proof using.
induction xs; intros; simpl in *.
- intuition.
- break_if; simpl in *; intuition.
Qed.
Proof using.
induction xs; simpl.
- constructor.
- break_if; auto.
constructor; auto.
intro.
apply n.
eapply in_dedup_was_in; eauto.
Qed.
Proof using.
induction xs; intros.
- auto.
- simpl. repeat (break_match; simpl); auto using f_equal.
+ exfalso. apply n0. apply remove_preserve; auto.
+ exfalso. apply n. eapply in_remove; eauto.
Qed.
Proof using.
intros xs p ys xs' ys' H.
f_apply H (remove A_eq_dec p).
rewrite remove_dedup_comm, remove_partition in *.
find_rewrite.
rewrite remove_partition.
apply remove_not_in.
apply NoDup_remove_2.
rewrite <- H.
apply NoDup_dedup.
Qed.

Lemma dedup_NoDup_id : forall (xs : list A),
NoDup xs -> dedup xs = xs.