(* 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                                                     *)


(*****************************************************************************)
(*          Projet Formel - Calculus of Inductive Constructions V5.10        *)
(*****************************************************************************)
(*									     *)
(*	                      Equalizers                		     *)
(*									     *)
(*****************************************************************************)
(*									     *)
(*                     A. SAIBI	  May 95                  		     *)
(*									     *)
(*****************************************************************************)

Require Export CatProperty.

Set Implicit Arguments.
Unset Strict Implicit.

(* Equalizers *)

Section equaz_def.

Variables (C : Category) (a b : C) (I : Type) (k : I -> (a --> b)).

 Section equaz_laws.

 Variables (c : C) (e : c --> a).

 Definition Equalizer_eq (r : C) (h : r --> a) :=
   forall i j : I, h o k i =_S h o k j.

 Definition Equalizer_law1 := Equalizer_eq e.

 Variable E_diese : forall (r : C) (h : r --> a), Equalizer_eq h -> (r --> c).

 Definition Equalizer_law2 :=
   forall (r : C) (h : r --> a) (p : Equalizer_eq h), h =_S E_diese p o e.

 Definition Equalizer_law3 :=
   forall (r : C) (h : r --> a) (p : Equalizer_eq h) (l : r --> c),
   h =_S l o e -> l =_S E_diese p.

 End equaz_laws.

Structure Equalizer : Type := 
  {E_ob : C;
   E_mor : E_ob --> a;
   Prf_E_law1 : Equalizer_law1 E_mor;
   E_diese : forall (r : C) (h : r --> a), Equalizer_eq h -> (r --> E_ob);
   Prf_E_law2 : Equalizer_law2 E_mor E_diese;
   Prf_E_law3 : Equalizer_law3 E_mor E_diese}.

Variable f : Equalizer.

(* tout Equalizer est monic *)

Lemma E_monic : Monic_law (E_mor f).
Proof.
(* Goal: @Monic_law C a (E_ob f) (E_mor f) *)
unfold Monic_law in |- *; intros c j l H.
(* Goal: @Equal (@Hom C c (E_ob f)) j l *)
cut (Equalizer_eq (j o E_mor f)).
(* Goal: forall _ : @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)), @Equal (@Hom C c (E_ob f)) j l *)
(* Goal: @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)) *)
intro p.
(* Goal: @Equal (@Hom C c (E_ob f)) j l *)
(* Goal: @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)) *)
(* *) apply Trans with (E_diese f p).
(* Goal: @Equal (@Hom C c (E_ob f)) j (@E_diese f c (@Comp C c (E_ob f) a j (E_mor f)) p) *)
(* Goal: @Equal (@Hom C c (E_ob f)) (@E_diese f c (@Comp C c (E_ob f) a j (E_mor f)) p) l *)
(* Goal: @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)) *)
apply (Prf_E_law3 p (l:=j)).
(* Goal: @Equal (@Hom C c a) (@Comp C c (E_ob f) a j (E_mor f)) (@Comp C c (E_ob f) a j (E_mor f)) *)
(* Goal: @Equal (@Hom C c (E_ob f)) (@E_diese f c (@Comp C c (E_ob f) a j (E_mor f)) p) l *)
(* Goal: @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)) *)
apply Refl.
(* Goal: @Equal (@Hom C c (E_ob f)) (@E_diese f c (@Comp C c (E_ob f) a j (E_mor f)) p) l *)
(* Goal: @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)) *)
apply Sym; apply (Prf_E_law3 p (l:=l)).
(* Goal: @Equal (@Hom C c a) (@Comp C c (E_ob f) a j (E_mor f)) (@Comp C c (E_ob f) a l (E_mor f)) *)
(* Goal: @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)) *)
apply H.
(* Goal: @Equalizer_eq c (@Comp C c (E_ob f) a j (E_mor f)) *)
unfold Equalizer_eq in |- *; intros i1 i2.
(* Goal: @Equal (@Hom C c b) (@Comp C c a b (@Comp C c (E_ob f) a j (E_mor f)) (k i1)) (@Comp C c a b (@Comp C c (E_ob f) a j (E_mor f)) (k i2)) *)
(* *) apply Trans with (j o E_mor f o k i1).
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) (E_ob f) a (@Comp C (E_ob f) a (E_ob f) (E_mor f) (@E_diese f a (@Id C a) (Epic_Equalizer_id p))) (E_mor f)) (@Comp C (E_ob f) a a (E_mor f) (@Comp C a (E_ob f) a (@E_diese f a (@Id C a) (Epic_Equalizer_id p)) (E_mor f))) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Comp C a (E_ob f) a (@E_diese f a (@Id C a) (Epic_Equalizer_id p)) (E_mor f))) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
apply Ass1.
(* Goal: @Equal (@Hom C c b) (@Comp C c (E_ob f) b j (@Comp C (E_ob f) a b (E_mor f) (k i1))) (@Comp C c a b (@Comp C c (E_ob f) a j (E_mor f)) (k i2)) *)
(* *) apply Trans with (j o E_mor f o k i2).
(* Goal: @Equal (@Hom C c b) (@Comp C c (E_ob f) b j (@Comp C (E_ob f) a b (E_mor f) (k i1))) (@Comp C c (E_ob f) b j (@Comp C (E_ob f) a b (E_mor f) (k i2))) *)
(* Goal: @Equal (@Hom C c b) (@Comp C c (E_ob f) b j (@Comp C (E_ob f) a b (E_mor f) (k i2))) (@Comp C c a b (@Comp C c (E_ob f) a j (E_mor f)) (k i2)) *)
apply Comp_l; apply (Prf_E_law1 f i1 i2).
(* Goal: @Equal (@Hom C c b) (@Comp C c (E_ob f) b j (@Comp C (E_ob f) a b (E_mor f) (k i2))) (@Comp C c a b (@Comp C c (E_ob f) a j (E_mor f)) (k i2)) *)
apply Ass.
Qed.

(* un epic Equalizer est iso *)

Lemma Epic_Equalizer_id : Epic_law (E_mor f) -> Equalizer_eq (Id a).
Proof.
(* Goal: forall _ : @Epic_law C (E_ob f) a (E_mor f), @Equalizer_eq a (@Id C a) *)
unfold Equalizer_eq in |- *.
(* Goal: forall (_ : @Epic_law C (E_ob f) a (E_mor f)) (i j : I), @Equal (@Hom C a b) (@Comp C a a b (@Id C a) (k i)) (@Comp C a a b (@Id C a) (k j)) *)
intros ep i1 i2.
(* Goal: @Equal (@Hom C a b) (@Comp C a a b (@Id C a) (k i1)) (@Comp C a a b (@Id C a) (k i2)) *)
(* *) apply Trans with (k i1).
(* Goal: @Equal (@Hom C a b) (@Comp C a a b (@Id C a) (k i1)) (k i1) *)
(* Goal: @Equal (@Hom C a b) (k i1) (@Comp C a a b (@Id C a) (k i2)) *)
apply Idl.
(* Goal: @Equal (@Hom C a b) (k i1) (@Comp C a a b (@Id C a) (k i2)) *)
(* *) apply Trans with (k i2).
(* Goal: @Equal (@Hom C a b) (k i1) (k i2) *)
(* Goal: @Equal (@Hom C a b) (k i2) (@Comp C a a b (@Id C a) (k i2)) *)
apply ep.
(* Goal: @Equal (@Hom C (E_ob f) b) (@Comp C (E_ob f) a b (E_mor f) (k i1)) (@Comp C (E_ob f) a b (E_mor f) (k i2)) *)
(* Goal: @Equal (@Hom C a b) (k i2) (@Comp C a a b (@Id C a) (k i2)) *)
apply (Prf_E_law1 f i1 i2).
(* Goal: @Equal (@Hom C a b) (@Comp C a a b (@Id C a) (k i1)) (k i1) *)
(* Goal: @Equal (@Hom C a b) (k i1) (@Comp C a a b (@Id C a) (k i2)) *)
apply Sym; apply Idl.
Qed.

Lemma Epic_Equalizer_iso :
 forall p : Epic_law (E_mor f),
 let f1 := E_diese f (Epic_Equalizer_id p) in AreIsos (E_mor f) f1.
Proof.
(* Goal: forall p : @Epic_law C (E_ob f) a (E_mor f), let f1 := @E_diese f a (@Id C a) (Epic_Equalizer_id p) in @AreIsos C (E_ob f) a (E_mor f) f1 *)
intros p.
(* Goal: let f1 := @E_diese f a (@Id C a) (Epic_Equalizer_id p) in @AreIsos C (E_ob f) a (E_mor f) f1 *)
unfold AreIsos, RIso_law in |- *; split.
(* Goal: @Equal (@Hom C a a) (@Comp C a (E_ob f) a (@E_diese f a (@Id C a) (Epic_Equalizer_id p)) (E_mor f)) (@Id C a) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
apply Sym; apply (Prf_E_law2 f (Epic_Equalizer_id p)).
(* Goal: @Equal (@Hom C (E_ob f) (E_ob f)) (@Comp C (E_ob f) a (E_ob f) (E_mor f) (@E_diese f a (@Id C a) (Epic_Equalizer_id p))) (@Id C (E_ob f)) *)
apply E_monic.
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) (E_ob f) a (@Comp C (E_ob f) a (E_ob f) (E_mor f) (@E_diese f a (@Id C a) (Epic_Equalizer_id p))) (E_mor f)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
(* *) apply Trans with (E_mor f o Id a).
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) (E_ob f) a (@Comp C (E_ob f) a (E_ob f) (E_mor f) (@E_diese f a (@Id C a) (Epic_Equalizer_id p))) (E_mor f)) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
(* *) apply Trans with (E_mor f o E_diese f (Epic_Equalizer_id p) o E_mor f).
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) (E_ob f) a (@Comp C (E_ob f) a (E_ob f) (E_mor f) (@E_diese f a (@Id C a) (Epic_Equalizer_id p))) (E_mor f)) (@Comp C (E_ob f) a a (E_mor f) (@Comp C a (E_ob f) a (@E_diese f a (@Id C a) (Epic_Equalizer_id p)) (E_mor f))) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Comp C a (E_ob f) a (@E_diese f a (@Id C a) (Epic_Equalizer_id p)) (E_mor f))) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
apply Ass1.
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Comp C a (E_ob f) a (@E_diese f a (@Id C a) (Epic_Equalizer_id p)) (E_mor f))) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
apply Comp_l.
(* Goal: @Equal (@Hom C a a) (@Comp C a (E_ob f) a (@E_diese f a (@Id C a) (Epic_Equalizer_id p)) (E_mor f)) (@Id C a) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
apply Sym; apply (Prf_E_law2 f (Epic_Equalizer_id p)).
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
(* *) apply Trans with (E_mor f).
(* Goal: @Equal (@Hom C (E_ob f) a) (@Comp C (E_ob f) a a (E_mor f) (@Id C a)) (E_mor f) *)
(* Goal: @Equal (@Hom C (E_ob f) a) (E_mor f) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
apply Idr1.
(* Goal: @Equal (@Hom C (E_ob f) a) (E_mor f) (@Comp C (E_ob f) (E_ob f) a (@Id C (E_ob f)) (E_mor f)) *)
apply Idl1.
Qed.

Lemma Equalizer_iso :
 forall (h1 : a --> E_ob f) (p : RIso_law (E_mor f) h1),
 let f1 := E_diese f (Epic_Equalizer_id (RightInv_epic p)) in
 AreIsos (E_mor f) f1.
Proof.
(* Goal: forall (h1 : Carrier (@Hom C a (E_ob f))) (p : @RIso_law C (E_ob f) a (E_mor f) h1), let f1 := @E_diese f a (@Id C a) (Epic_Equalizer_id (@RightInv_epic C (E_ob f) a (E_mor f) h1 p)) in @AreIsos C (E_ob f) a (E_mor f) f1 *)
intros h1 ri; simpl in |- *; apply Epic_Equalizer_iso.
Qed.

End equaz_def.



