(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(* Contribution to the Coq Library   V6.3 (July 1999)                    *)
(* Definitions of the empty set, pair, union, intersection, comprehension  *)
(*  axiom and powerset, together with their properties                     *)
(* Useful types (actually top and bottom)   *)
Inductive Un : Set :=
void : Un.
Inductive F : Set :=.
(* The empty set  (vide = french for empty)   *)
Definition Vide : Ens := sup F (fun f : F => match f return Ens with
end).
(* The axioms of the empty set *)
unfold Vide in |- *; simpl in |- *; intros E H; cut False.
simple induction 1.
elim H; intros x; elim x.
Qed.
unfold Vide in |- *; simple induction E; simpl in |- *; intros A e H H0;
split.
intros; elim (H0 (e x)); auto with zfc.
exists x; auto with zfc.
simple induction y.
Qed.
(* Pair *)
Definition Paire : forall E E' : Ens, Ens.
intros.
apply (sup bool).
simple induction 1.
exact E.
exact E'.
Defined.
(* The pair construction is extentional *)
unfold Paire in |- *.
simpl in |- *.
intros; split.
simple induction x.
exists true; auto with zfc.
exists false; auto with zfc.
simple induction y; simpl in |- *.
exists true; auto with zfc.
exists false; auto with zfc.
Qed.
unfold Paire in |- *; simpl in |- *; intros; split.
simple induction x.
exists true; auto with zfc.
exists false; auto with zfc.
simple induction y.
exists true; auto with zfc.
exists false; auto with zfc.
Qed.
Hint Resolve Paire_sound_right Paire_sound_left: zfc.
(* The axioms of the pair *)
unfold Paire in |- *; simpl in |- *; exists true; simpl in |- *;
auto with zfc.
Qed.
unfold Paire in |- *; simpl in |- *; exists false; simpl in |- *;
auto with zfc.
Qed.
unfold Paire in |- *; simpl in |- *.
simple induction 1; intros b; elim b; simpl in |- *; auto with zfc.
Qed.
Hint Resolve IN_Paire_left IN_Paire_right Vide_est_vide: zfc.
(* The singleton set  *)
(* Note that we could define it directly using the base type Un *)
Definition Sing (E : Ens) := Paire E E.
(* The axioms  *)
unfold Sing in |- *; auto with zfc.
Qed.
unfold Sing in |- *; intros E E' H; elim (Paire_IN E' E' E);
auto with zfc.
Qed.
Hint Resolve IN_Sing IN_Sing_EQ: zfc.
unfold Sing in |- *; intros; apply EQ_tran with (Paire A A');
auto with zfc.
Qed.
Hint Resolve Sing_sound: zfc.
intros; cut (IN E1 (Sing E2)).
intros; auto with zfc.
apply IN_sound_right with (Sing E1); auto with zfc.
Qed.
Hint Resolve EQ_Sing_EQ: zfc.
(* We here need sigma types -- i.e. computational existentials *)
Inductive sig (A : Type) (P : A -> Prop) : Type :=
exist : forall x : A, P x -> sig A P.
(* The set obtained by the comprehension (or separation) axiom *)
Definition Comp : Ens -> (Ens -> Prop) -> Ens.
simple induction 1; intros A f fr P.
apply (sup (sig A (fun x => P (f x)))).
simple induction 1; intros x p; exact (f x).
Defined.
(* The comprehension/separation axioms *)
unfold Comp, INC in |- *; simple induction E; simpl in |- *; intros.
elim H0; simple induction x; intros; exists x0; auto with zfc.
Qed.
simple induction E; simpl in |- *; intros B f Hr A P H i; elim i; intros c;
elim c; simpl in |- *; intros x q e; apply H with (f x);
auto with zfc.
Qed.
simple induction E; simpl in |- *; intros B f HR A P H i; elim i;
simpl in |- *; intros.
cut (P (f x)).
intros Pf.
exists (exist B (fun x : B => P (f x)) x Pf); simpl in |- *;
auto with zfc.
apply H with A; auto with zfc.
Qed.
(* Again, extentionality is not stated, but easy *)
(* Projections of a set: *)
(*  1: its base type     *)
Definition pi1 : Ens -> Type.
simple induction 1.
intros A f r.
exact A.
Defined.
(*  2: the function      *)
Definition pi2 : forall E : Ens, pi1 E -> Ens.
simple induction E.
intros A f r.
exact f.
Defined.
(* The Union set   *)
Definition Union : forall E : Ens, Ens.
simple induction 1; intros A f r.
apply (sup (depprod A (fun x : A => pi1 (f x)))).
simple induction 1; intros a b.
exact (pi2 (f a) b).
Defined.
simple induction E; intros A f r; simple induction E'; intros A' f' r';
simpl in |- *; simple induction 1; intros e1 e2 a.
apply e1.
Defined.
simple induction E; simpl in |- *.
intros A f r.
simple induction 1; simpl in |- *.
intros.
exists x; auto with zfc.
Qed.
simple induction E; intros A f r.
intros.
simpl in |- *.
elim (IN_EXType (sup A f) E' H).
intros x e.
cut (EQ (pi2 (sup A f) x) E'); auto with zfc.
intros e1.
cut (IN E'' (pi2 (sup A f) x)).
intros i1.
elim (IN_EXType _ _ i1).
intros x0 e2.
simpl in x0.
exists (dep_i A (fun x : A => pi1 (f x)) x x0).
simpl in |- *.
exact e2.
apply IN_sound_right with E'; auto with zfc.
Qed.

Theorem IN_INC_Union : forall E E' : Ens, IN E' E -> INC E' (Union E).