(* Contribution to the Coq Library   V6.3 (July 1999)                    *)
(***************************************************************************)
(* File: ZFrelations.v                                                     *)
(* auteur: alex@sysal.ibp.fr                                               *)
(* date: 19/10/95                                                          *)
(***************************************************************************)
Require Export axs_fundation.
(***************************************************************************)
(***************************************************************************)
(* Une relation est un ensemble de couples                                 *)
(* Nous nous interessons ici aux relations binaires.                       *)
(***************************************************************************)
(***************************************************************************)
Definition rel (r : E) :=
forall c : E, In c r -> exists x : E, (exists y : E, c = couple x y).
Definition rel_sig (r a b : E) := inc r (cartesien a b).
(* Proof of lem_rel_sig_is_rel                                             *)
unfold rel_sig in |- *; unfold inc in |- *; intros.
unfold rel in |- *; intros.
generalize (H c H0); clear H H0; intros.
elim (lem_cartesian_propertie a b c); intros; generalize (H0 H);
clear H H0 H1; intros.
elim H; clear H; intros; elim H; clear H; intros; elim H; clear H; intros;
elim H0; clear H0; intros.
exists x; exists x0; auto with zfc.
Qed.
(* End of proof of lem_rel_sig_is_rel                                      *)
(* Proof of lem_rel_to_rel_sig                                             *)
intros.
unfold rel in H.
exists
(subset (fun z : E => exists t : E, In (couple z t) r) (reunion (reunion r))).
exists
(subset (fun t : E => exists z : E, In (couple z t) r) (reunion (reunion r))).
unfold rel_sig in |- *; unfold inc in |- *; intros.
generalize (H v0 H0); intros.
elim H1; clear H1; intros; elim H1; clear H1; intros.
elim
(lem_cartesian_propertie
(subset (fun z : E => exists t : E, In (couple z t) r)
(reunion (reunion r)))
(subset (fun t : E => exists z : E, In (couple z t) r)
(reunion (reunion r))) v0); intros; apply H3;
clear H2 H3; intros.
exists x; exists x0; split; [ idtac | split; [ idtac | auto with zfc ] ].
elim
(axs_comprehension (fun z : E => exists t : E, In (couple z t) r)
(reunion (reunion r)) x); intros; apply H3; clear H2 H3;
intros.
generalize H0; rewrite H1; intros.
split; [ idtac | exists x0; auto with zfc ].
elim (axs_reunion (reunion r) x); intros; apply H4; clear H3 H4; intros.
exists (singleton x); split; [ idtac | apply lem_x_in_sing_x ].
elim (axs_reunion r (singleton x)); intros; apply H4; clear H3 H4; intros.
exists (couple x x0); split; [ auto with zfc | idtac ].
unfold couple in |- *;
elim (axs_paire (singleton x) (paire x x0) (singleton x));
intros; apply H4; left; reflexivity.
generalize H0; rewrite H1; intros.
elim
(axs_comprehension (fun t : E => exists z : E, In (couple z t) r)
(reunion (reunion r)) x0); intros; apply H4; clear H3 H4;
intros.
split; [ idtac | exists x; auto with zfc ].
elim (axs_reunion (reunion r) x0); intros; apply H4; clear H3 H4; intros.
exists (paire x x0); split;
[ idtac | elim (axs_paire x x0 x0); intros; apply H4; right; reflexivity ].
elim (axs_reunion r (paire x x0)); intros; apply H4; clear H3 H4; intros.
exists (couple x x0); split;
[ auto with zfc
| elim (axs_paire (singleton x) (paire x x0) (paire x x0)); intros; apply H4;
right; reflexivity ].
Qed.
(* End of proof of lem_rel_to_rel_sig                                      *)
(***************************************************************************)
(***************************************************************************)
(* Notions de domaine et d'image d'une relation binaire                    *)
(***************************************************************************)
(***************************************************************************)
Definition rdom (r a b : E) (rRel : rel_sig r a b) :=
subset (fun x : E => exists y : E, In (couple x y) r) a.
Definition rImg (r a b : E) (rRel : rel_sig r a b) :=
subset (fun y : E => exists x : E, In (couple x y) r) b.
Definition rdom2 (r : E) (rRel : rel r) :=
subset (fun x : E => exists y : E, In (couple x y) r) (reunion (reunion r)).
Definition rImg2 (r : E) (rRel : rel r) :=
subset (fun y : E => exists x : E, In (couple x y) r) (reunion (reunion r)).

Lemma lem_rdom_eq_rdom2 :
forall (r a b : E) (rRel : rel_sig r a b),
rdom r a b rRel = rdom2 r (lem_rel_sig_to_rel r a b rRel).