Section fparts_in_def.
Variable E : Setoid.
(* Add_part. *)
Definition add_part (A : part_set E) (x : E) := union A (single x).
unfold add_part in |- *; auto with algebra.
Qed.
Hint Resolve add_part_comp: algebra.
simpl in |- *; auto with algebra.
Qed.
Hint Resolve add_part_in: algebra.
unfold add_part in |- *.
intros.
apply Trans with (union A (union (single x) (single y))); auto with algebra.
apply Trans with (union A (union (single y) (single x))); auto with algebra.
Qed.
Hint Immediate add_part_com: algebra.
intro A.
case A.
simpl in |- *; unfold pred_compatible, eq_part, in_part in |- *;
simpl in |- *.
intuition eauto.
Qed.
Hint Resolve add_in: algebra.
simpl in |- *.
unfold eq_part, add_part, union, single in |- *; simpl in |- *.
intro.
case A; simpl in |- *.
intros a pa.
intuition.
Qed.
simpl in |- *.
unfold eq_part, add_part, union, single in |- *; simpl in |- *.
intro.
case A; simpl in |- *.
intros a pa.
intuition.
Qed.
intros A B.
case A; case B; simpl in |- *.
intros a pa b pb.
unfold eq_part, add_part, union, single in |- *; simpl in |- *.
intros.
elim (classic (Equal x x0)); intros.
split; intros.
apply pa with x; auto with algebra.
cut (b x).
intro.
absurd (b x); auto with algebra.
apply pb with x0; auto with algebra.
cut (a x).
intro.
absurd (a x); auto with algebra.
apply pa with x0; auto with algebra.
elim (H1 x0); intros.
split; intros.
lapply H3.
intros.
elim H6; intros.
auto with algebra.
absurd (Equal x0 x); auto with algebra.
left; auto with algebra.
lapply H4; intros.
elim H6; intros.
auto with algebra.
absurd (Equal x0 x); auto with algebra.
left.
auto with algebra.
Qed.
(* Minus_part. *)
Definition minus_part (A : part_set E) (x : E) := diff A (single x).
unfold minus_part in |- *; auto with algebra.
Qed.
Hint Resolve minus_part_comp: algebra.
simpl in |- *.
intro.
case A; simpl in |- *.
intros a pa.
intuition.
Qed.
Hint Resolve minus_part_not_in: algebra.
unfold minus_part in |- *.
intros.
simpl in |- *.
unfold eq_part, diff, single in |- *; simpl in |- *.
intro.
intuition.
Qed.
Hint Immediate minus_part_com: algebra.
simpl in |- *.
unfold eq_part, minus_part, diff, single in |- *; simpl in |- *.
intro A.
case A; unfold pred_compatible in |- *; simpl in |- *.
intros a pa x neg_a_x x0.
generalize (pa x0 x).
intuition auto with algebra.
Qed.
Hint Resolve minus_not_in: algebra.
simpl in |- *.
unfold eq_part, minus_part, diff, single in |- *; simpl in |- *.
intro.
case A; simpl in |- *.
intros a pa.
intuition.
Qed.
Hint Resolve minus_trans_not_in: algebra.
(* Some lemmas. *)
simpl in |- *.
unfold eq_part, union, empty in |- *; simpl in |- *.
intuition.
Qed.
Hint Resolve union_unit_l: algebra.
unfold add_part in |- *.
auto with algebra.
Qed.
Hint Resolve single_add: algebra.
simpl in |- *.
unfold eq_part, add_part, minus_part, union, diff, single in |- *;
simpl in |- *.
intro.
case A; simpl in |- *.
intros a pa.
intros.
intuition.
apply pa with x; auto with algebra.
apply NNPP; intuition.
Qed.
Hint Resolve minus_add: algebra.
simpl in |- *.
unfold eq_part, add_part, minus_part, union, diff, single in |- *;
simpl in |- *.
intro.
case A; simpl in |- *.
intros a pa.
intros.
intuition.
apply H.
apply pa with x0; auto with algebra.
Qed.
Hint Resolve add_minus: algebra.
(* Cardinal. *)
Inductive cardinal : part_set E -> nat -> Prop :=
| cardinal_empty : forall A : part_set E, Equal A (empty E) -> cardinal A 0
| cardinal_add :
forall (A B : part_set E) (n : nat),
cardinal B n ->
forall x : E,
~ in_part x B -> Equal A (add_part B x) -> cardinal A (S n).
Hint Immediate cardinal_empty: algebra.
intros.
inversion H1.
rewrite <- H0.
rewrite <- H4.
apply cardinal_empty.
apply Trans with A; auto with algebra.
rewrite <- H0.
rewrite <- H6.
apply cardinal_add with B0 x; auto with algebra.
apply Trans with A; auto with algebra.
Qed.
Hint Resolve cardinal_comp: algebra.
intros.
apply cardinal_comp with A n; auto with algebra.
Qed.
intros.
apply cardinal_comp with A n; auto with algebra.
Qed.
auto with algebra.
Qed.
Hint Resolve cardinal_empty_O: algebra.
intro.
apply cardinal_add with (empty E) x; auto with algebra.
Qed.
Hint Resolve cardinal_single: algebra.
intros.
apply cardinal_add with (single x) y; auto with algebra.
Qed.
Hint Resolve cardinal_pair: algebra.
intros.
inversion H.
auto with algebra.
Qed.
Hint Resolve cardinal_O_empty: algebra.
intros.
inversion H.
exists x.
apply Trans with (add_part B x); auto with algebra.
apply Trans with (add_part (empty E) x); auto with algebra.
Qed.
(* Some lemmas. *)
intros A.
case A.
intros a pa.
simpl in |- *.
unfold eq_part, empty in |- *; simpl in |- *.
intuition eauto.
Qed.
Hint Immediate not_in_empty: algebra.
unfold in_part in |- *.
intros x A B.
case A; case B; simpl in |- *.
intros a pa b pb.
unfold eq_part in |- *; simpl in |- *.
intuition.
elim (H0 x); auto with algebra.
Qed.
unfold in_part in |- *.
intros x y A.
case A; intros a pa.
simpl in |- *.
intuition.
apply H.
apply (pa y x); auto with algebra.
Qed.
intros.
exists (minus_part B y).
split.
apply Sym.
apply minus_add.
cut (in_part y (add_part B x)).
intros.
apply add_part_in_el_diff with x; auto with algebra.
apply in_part_comp_r with A; auto with algebra.
apply in_part_comp_r with (add_part C y); auto with algebra.
split.
apply add_part_simpl with y; auto with algebra.
unfold not in |- *; intro.
absurd (Equal y x); auto with algebra.
apply add_part_in_el_not_in with (minus_part B y); auto with algebra.
apply Trans with (add_part (add_part (minus_part B y) y) x);
auto with algebra.
apply Trans with (add_part B x); auto with algebra.
apply Trans with A; auto with algebra.
apply add_part_comp; auto with algebra.
apply Sym.
apply minus_add; auto with algebra.
apply add_part_in_el_diff with x; auto with algebra.
apply in_part_comp_r with (add_part C y); auto with algebra.
apply Trans with A; auto with algebra.
split.
apply minus_trans_not_in; auto with algebra.
auto with algebra.
Qed.
simple induction n.
auto with algebra.
intros.
inversion c.
apply (H0 n0 H1 A B x H4 H6 c).
Qed.
simple induction n.
intros.
apply cardinal_empty.
inversion H1.
elim (classic (Equal x0 x)); intros.
apply Trans with B0.
apply add_part_simpl with x; auto with algebra.
apply not_in_part_trans_eq with x0; auto with algebra.
apply Trans with A; auto with algebra.
apply Trans with (add_part B0 x0); auto with algebra.
auto with algebra.
absurd (in_part x (single x0)).
intuition.
apply in_part_comp_r with (add_part B0 x0); auto with algebra.
apply in_part_comp_r with A; auto with algebra.
apply in_part_comp_r with (add_part B x); auto with algebra.
apply Trans with (add_part (empty E) x0); auto with algebra.
intros.
inversion H2.
elim (classic (Equal x x0)); intros.
apply cardinal_comp_l with B0; auto with algebra.
apply add_part_simpl with x; auto with algebra.
apply not_in_part_trans_eq with x0; auto with algebra.
apply Trans with A; auto with algebra.
apply Trans with (add_part B0 x0); auto with algebra.
elim (cardinal_sup3 (A:=A) (B:=B) (C:=B0) (x:=x) (y:=x0)); auto with algebra.
intros C H9.
elim H9; clear H9; intros.
elim H10; clear H10; intros.
elim H11; clear H11; intros.
apply cardinal_add with C x0; auto with algebra.
apply H with B0 x; auto with algebra.
Qed.

Lemma cardinalO_unique :
forall A : part_set E, cardinal A 0 -> forall m : nat, cardinal A m -> 0 = m.