(* 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)).
(* Proof of lem_rdom_eq_rdom2                                              *)
intros; apply axs_extensionnalite; unfold iff in |- *; split; intros.
unfold rdom in H.
elim (axs_comprehension (fun x : E => exists y : E, In (couple x y) r) a v2);
intros; generalize (H0 H); clear H H0 H1; intros.
elim H; clear H; intros.
elim H0; clear H0; intros.
unfold rdom2 in |- *.
elim
(axs_comprehension (fun x : E => exists y : E, In (couple x y) r)
(reunion (reunion r)) v2); intros; apply H2; clear H1 H2;
intros.
split; [ idtac | exists x; auto with zfc ].
elim (axs_reunion (reunion r) v2); intros; apply H2; clear H1 H2; intros.
exists (singleton v2); split; [ idtac | apply lem_x_in_sing_x ].
elim (axs_reunion r (singleton v2)); intros; apply H2; clear H1 H2; intros.
exists (couple v2 x); split;
[ auto with zfc
| unfold couple in |- *;
elim (axs_paire (singleton v2) (paire v2 x) (singleton v2));
intros; apply H2; left; reflexivity ].
unfold rdom2 in H.
elim
(axs_comprehension (fun x : E => exists y : E, In (couple x y) r)
(reunion (reunion r)) v2); intros; generalize (H0 H);
clear H H0 H1; intros.
elim H; clear H; intros; elim H0; clear H0; intros.
unfold rdom in |- *.
elim (axs_comprehension (fun x : E => exists y : E, In (couple x y) r) a v2);
intros; apply H2; clear H1 H2; intros.
split; [ idtac | exists x; auto with zfc ].
unfold rel_sig in rRel; unfold inc in rRel.
generalize (rRel (couple v2 x) H0); intros.
elim (lem_cartesian_propertie a b (couple v2 x)); intros; generalize (H2 H1);
clear H1 H2 H3; intros.
elim H1; clear H1; intros; elim H1; clear H1; intros; elim H1; clear H1;
intros; elim H2; clear H2; intros.
elim (lem_couple_propertie v2 x0 x x1); intros; generalize (H4 H3);
clear H3 H4 H5; intros.
elim H3; clear H3; intros.
generalize H1; rewrite H3; tauto.
Qed.
(* End of proof of lem_rdom_eq_rdom2                                       *)
(* Proof of lem_rImg_eq_rImg2                                              *)
intros; apply axs_extensionnalite; unfold iff in |- *; split; intros.
unfold rImg in H.
elim (axs_comprehension (fun y : E => exists x : E, In (couple x y) r) b v2);
intros; generalize (H0 H); clear H H0 H1; intros.
elim H; clear H; intros; elim H0; clear H0; intros.
unfold rImg2 in |- *.
elim
(axs_comprehension (fun y : E => exists x : E, In (couple x y) r)
(reunion (reunion r)) v2); intros; apply H2; clear H1 H2;
intros.
split; [ idtac | exists x; auto with zfc ].
elim (axs_reunion (reunion r) v2); intros; apply H2; clear H1 H2; intros.
exists (paire x v2); split;
[ idtac | elim (axs_paire x v2 v2); intros; apply H2; right; reflexivity ].
elim (axs_reunion r (paire x v2)); intros; apply H2; clear H1 H2; intros.
exists (couple x v2); split;
[ auto with zfc
| unfold couple in |- *;
elim (axs_paire (singleton x) (paire x v2) (paire x v2));
intros; apply H2; right; reflexivity ].
unfold rImg2 in H.
elim
(axs_comprehension (fun y : E => exists x : E, In (couple x y) r)
(reunion (reunion r)) v2); intros; generalize (H0 H);
clear H H0 H1; intros.
elim H; clear H; intros; elim H0; clear H0; intros.
unfold rImg in |- *.
elim (axs_comprehension (fun y : E => exists x : E, In (couple x y) r) b v2);
intros; apply H2; clear H1 H2; intros.
split; [ idtac | exists x; auto with zfc ].
unfold rel_sig in rRel; unfold inc in rRel.
generalize (rRel (couple x v2) H0); clear rRel H H0; intros.
elim (lem_cartesian_propertie a b (couple x v2)); 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.
elim (lem_couple_propertie x x0 v2 x1); intros; generalize (H2 H1);
clear H1 H2 H3; intros.
elim H1; clear H1; intros; generalize H0; rewrite H2; tauto.
Qed.
(* End of proof of lem_rImg_eq_rImg2                                       *)
(* Proof of lem_rel_and_rdom                                               *)
intros; unfold rdom in |- *.
elim (axs_comprehension (fun x0 : E => exists y : E, In (couple x0 y) r) a x);
intros; apply H1; clear H0 H1; intros.
split; [ idtac | exists y; auto with zfc ].
unfold rel_sig in rRel; unfold inc in rRel.
generalize (rRel (couple x y) H); intros.
elim (lem_cartesian_propertie a b (couple x y)); intros; generalize (H1 H0);
clear H0 H1 H2; intros.
elim H0; clear H0; intros; elim H0; clear H0; intros; elim H0; clear H0;
intros; elim H1; clear H1; intros.
elim (lem_couple_propertie x x0 y x1); intros; generalize (H3 H2);
clear H2 H3 H4; intros.
elim H2; clear H2; intros; generalize H0; rewrite H2; tauto.
Qed.
(* End of proof of lem_rel_and_rdom                                        *)
(* Proof of lem_rel_and_rdom2                                              *)
unfold rdom2 in |- *; intros.
elim
(axs_comprehension (fun x0 : E => exists y : E, In (couple x0 y) r)
(reunion (reunion r)) x); intros; apply H1; clear H0 H1;
intros.
split; [ idtac | exists y; auto with zfc ].
elim (axs_reunion (reunion r) x); intros; apply H1; clear H0 H1; intros.
exists (singleton x); split; [ idtac | apply lem_x_in_sing_x ].
elim (axs_reunion r (singleton x)); intros; apply H1; clear H0 H1; intros.
exists (couple x y); split; [ auto with zfc | idtac ].
elim (axs_paire (singleton x) (paire x y) (singleton x)); intros; apply H1;
clear H0 H1; intros.
left; reflexivity.
Qed.
(* End of proof of lem_rel_and_rdom2                                       *)
(* Proof of lem_rel_and_rImg                                               *)
unfold rImg in |- *; intros.
elim (axs_comprehension (fun y0 : E => exists x : E, In (couple x y0) r) b y);
intros; apply H1; clear H0 H1; intros.
split; [ idtac | exists x; auto with zfc ].
generalize (rRel (couple x y) H); intros.
elim (lem_cartesian_propertie a b (couple x y)); intros; generalize (H1 H0);
clear H0 H1 H2; intros.
elim H0; clear H0; intros; elim H0; clear H0; intros; elim H0; clear H0;
intros; elim H1; clear H1; intros.
elim (lem_couple_propertie x x0 y x1); intros; generalize (H3 H2);
clear H2 H3 H4; intros; elim H2; clear H2; intros.
rewrite H3; auto with zfc.
Qed.
(* End of proof of lem_rel_and_rImg                                        *)
(* Proof of lem_rel_and_rImg2                                              *)
unfold rImg2 in |- *; intros.
elim
(axs_comprehension (fun y0 : E => exists x : E, In (couple x y0) r)
(reunion (reunion r)) y); intros; apply H1; clear H0 H1;
intros.
split; [ idtac | exists x; auto with zfc ].
elim (axs_reunion (reunion r) y); intros; apply H1; clear H0 H1; intros.
exists (paire x y); split;
[ idtac
| elim (axs_paire x y y); intros; apply H1; intros; right; reflexivity ].
elim (axs_reunion r (paire x y)); intros; apply H1; clear H0 H1; intros.
exists (couple x y); split;
[ auto with zfc
| elim (axs_paire (singleton x) (paire x y) (paire x y)); intros; apply H1;
right; reflexivity ].
Qed.
(* End of proof of lem_rel_and_rImg2                                       *)
(***************************************************************************)
(***************************************************************************)
(* Relation partielle vs relation totale                                   *)
(* Nous considerons ici qu'une relation est totale si tous les elements de *)
(* son domaine sont "consommes" par la relation.                           *)
(***************************************************************************)
(***************************************************************************)
Definition rel_total (r a b : E) (rRel : rel_sig r a b) :=
rdom r a b rRel = a.
Definition rel_partiel (r a b : E) (rRel : rel_sig r a b) :=
exists x : E, In x a -> forall y : E, ~ In (couple x y) r.
(***************************************************************************)
(***************************************************************************)
(* Proprietes de base des relations                                        *)
(***************************************************************************)
(***************************************************************************)
(***************************************************************************)
(* Toute application est une relation                                      *)
(***************************************************************************)
(* Proof of lem_fun_is_rel                                                 *)
unfold rel in |- *; intros.
unfold fun_ in Af.
elim Af; clear Af; intros; elim H0; clear H0; intros; elim H0; clear H0;
intros.
unfold inc in H0.
generalize (H0 c H); clear H H0 H1; intros.
elim (lem_cartesian_propertie x x0 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 x1; exists x2; auto with zfc.
Qed.
(* End of proof of lem_fun_is_rel                                          *)
(***************************************************************************)
(* Le domaine et l'image d'une relation non vide sont non vides            *)
(***************************************************************************)
(* Lemma lem_rel_not_empty_so_rdom_not_empty : (r:E)(rRel:(rel r)) ~(r=Vide) -> ~((rdom2 r rRel)=Vide) . (* Proof of lem_rel_not_empty_so_rdom_not_empty                            *)
Save.
(* End of proof of lem_rel_not_empty_so_rdom_not_empty                     *)
*)
(***************************************************************************)
(* Considerons maintenant des relations dont l'image est tout ou partie du *)
(* domaine.                                                                *)
(***************************************************************************)
(***************************************************************************)
(* Reflexivite & irreflexivite                                             *)
(***************************************************************************)
Definition reflexivity (r a : E) (rRel : rel_sig r a a) :=
forall x : E, In x (rdom r a a rRel) -> In (couple x x) r.
Definition irreflexivity (r a : E) (rRel : rel_sig r a a) :=
forall x : E, In x (rdom r a a rRel) -> ~ In (couple x x) r.

(***************************************************************************)
(* Le domaine d'une relation reflexive est inclus dans l'image             *)
(***************************************************************************)
Lemma lem_refl_dom_inc_img :
forall (r a : E) (rRel : rel_sig r a a),
reflexivity r a rRel -> inc (rdom r a a rRel) (rImg r a a rRel).