Section Bijection.
(**************************************************************************)
(** We now show that if f and g are injections resp from A to B and from  *)
(** B to A, then there is a subset J of A s.t. h, defined to be f on A    *)
(** and the converse of g on A\J is a bijection from A to B               *)
Variable f g : Relation U.  (* f and g are relations *)
Hypothesis f_inj : injection U A B f. (* f and g are injections *)
Hypothesis g_inj : injection U B A g.
Let Imf : Ensemble U -> Ensemble U := Im U f.
Let Img : Ensemble U -> Ensemble U := Im U g.
(** Constructing J s.t. g(B\f(J))=A\J *)
(** (Setminus U A C) denotes the difference A\C         *)
(** (Included U A C) means that A is included in C  *)
Let F (C : SU) := Setminus U A (Img (Setminus U B (Imf C))).
Let D (C : SU) := Included U C (F C).
Let J := Set_Sum U D.
(**  We show that so-built J is the subset we are looking for *)
(** J is Tarski's fix-point of F, a function which is growing *)
(** w.r.t. inclusion                                          *)
(** Lemma: F is growing *)
(** We show F(J)=A\Img(B\Imf(J))=J *)
(** First left-to-right inclusion *)
(** Lemma: J_is_in_FJ (Included U J (F J))  *)
(** Then right-to-left inclusion *)
(** Lemma: FJ_is_in_J (Included U (F J) J)  *)
(** We show that h, which is f on J and g elsewhere, is a bijection *)
Inductive h (x y : U) : Prop :=
| hl_intro : In U J x -> f x y -> h x y
| hr_intro : Setminus U B (Imf J) y -> g y x -> h x y.
(** Theorem: h_bij (bijection U A B h) *)

(** h satisfies from_at_most_one_input *)
Lemma h4 : from_at_most_one_input U h.