(* 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 Coq - Calculus of Inductive Constructions V5.10           *)
(*****************************************************************************)
(*                                                                           *)
(*          Category Theory : Functor exercises                              *)
(*                                                                           *)
(*          Amokrane Saibi May 1994                                          *)
(*                                                                           *)
(*****************************************************************************)

Require Export Functor.
Require Export CatProperty.

Set Implicit Arguments.
Unset Strict Implicit.

(* exersise *)

Section functor_prop.

Variable C D : Category. 

(* exercises *)

Lemma Functor_preserves_iso :
 forall (F : Functor C D) (a b : C), Iso a b -> Iso (F a) (F b).
Proof.
(* Goal: forall (F : Functor C D) (a b : Ob C) (_ : @Iso C a b), @Iso D (@FOb C D F a) (@FOb C D F b) *)
intros F a b f.
(* Goal: @Iso D (@FOb C D F a) (@FOb C D F b) *)
apply Build_Iso with (FMor F (Iso_mor f)) (FMor F (Inv_iso f)).
(* Goal: @AreIsos D (@FOb C D F a) (@FOb C D F b) (@FMor C D F a b (@Iso_mor C a b f)) (@FMor C D F b a (@Inv_iso C a b f)) *)
red in |- *; split; red in |- *.
(* Goal: @Equal (@Hom D (@FOb C D F b) (@FOb C D F b)) (@Comp D (@FOb C D F b) (@FOb C D F a) (@FOb C D F b) (@FMor C D F b a (@Inv_iso C a b f)) (@FMor C D F a b (@Iso_mor C a b f))) (@Id D (@FOb C D F b)) *)
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@Comp D (@FOb C D F a) (@FOb C D F b) (@FOb C D F a) (@FMor C D F a b (@Iso_mor C a b f)) (@FMor C D F b a (@Inv_iso C a b f))) (@Id D (@FOb C D F a)) *)
(* *) apply Trans with (FMor F (Inv_iso f o Iso_mor f)).
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@Comp D (@FOb C D F a) (@FOb C D F b) (@FOb C D F a) (@FMor C D F a b (@Iso_mor C a b f)) (@FMor C D F b a (@Inv_iso C a b f))) (@FMor C D F a a (@Comp C a b a (@Iso_mor C a b f) (@Inv_iso C a b f))) *)
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@FMor C D F a a (@Comp C a b a (@Iso_mor C a b f) (@Inv_iso C a b f))) (@Id D (@FOb C D F a)) *)
apply FComp1.
(* Goal: @Equal (@Hom D (@FOb C D F b) (@FOb C D F b)) (@FMor C D F b b (@Comp C b a b (@Inv_iso C a b f) (@Iso_mor C a b f))) (@Id D (@FOb C D F b)) *)
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@Comp D (@FOb C D F a) (@FOb C D F b) (@FOb C D F a) (@FMor C D F a b (@Iso_mor C a b f)) (@FMor C D F b a (@Inv_iso C a b f))) (@Id D (@FOb C D F a)) *)
(* *) apply Trans with (FMor F (Id b)).
(* Goal: @Equal (@Hom D (@FOb C D F b) (@FOb C D F b)) (@FMor C D F b b (@Comp C b a b (@Inv_iso C a b f) (@Iso_mor C a b f))) (@FMor C D F b b (@Id C b)) *)
(* Goal: @Equal (@Hom D (@FOb C D F b) (@FOb C D F b)) (@FMor C D F b b (@Id C b)) (@Id D (@FOb C D F b)) *)
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@Comp D (@FOb C D F a) (@FOb C D F b) (@FOb C D F a) (@FMor C D F a b (@Iso_mor C a b f)) (@FMor C D F b a (@Inv_iso C a b f))) (@Id D (@FOb C D F a)) *)
apply FPres; apply (Idl_inv f).
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@FMor C D F a a (@Id C a)) (@Id D (@FOb C D F a)) *)
apply FId.
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@Comp D (@FOb C D F a) (@FOb C D F b) (@FOb C D F a) (@FMor C D F a b (@Iso_mor C a b f)) (@FMor C D F b a (@Inv_iso C a b f))) (@Id D (@FOb C D F a)) *)
(* *) apply Trans with (FMor F (Iso_mor f o Inv_iso f)).
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@Comp D (@FOb C D F a) (@FOb C D F b) (@FOb C D F a) (@FMor C D F a b (@Iso_mor C a b f)) (@FMor C D F b a (@Inv_iso C a b f))) (@FMor C D F a a (@Comp C a b a (@Iso_mor C a b f) (@Inv_iso C a b f))) *)
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@FMor C D F a a (@Comp C a b a (@Iso_mor C a b f) (@Inv_iso C a b f))) (@Id D (@FOb C D F a)) *)
apply FComp1.
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@FMor C D F a a (@Comp C a b a (@Iso_mor C a b f) (@Inv_iso C a b f))) (@Id D (@FOb C D F a)) *)
(* *) apply Trans with (FMor F (Id a)).
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@FMor C D F a a (@Comp C a b a (@Iso_mor C a b f) (@Inv_iso C a b f))) (@FMor C D F a a (@Id C a)) *)
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@FMor C D F a a (@Id C a)) (@Id D (@FOb C D F a)) *)
apply FPres; apply (Idr_inv f).
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F a)) (@FMor C D F a a (@Id C a)) (@Id D (@FOb C D F a)) *)
apply FId.
Qed.

(* faithful *)

Definition Faithful_law (F : Functor C D) :=
  forall (a b : C) (f g : a --> b), FMor F f =_S FMor F g -> f =_S g.

Structure > Faithful : Type := 
  {Faithful_functor :> Functor C D;
   Prf_isFaithful :> Faithful_law Faithful_functor}.

(* full *)

Definition Full_law (F : Functor C D)
  (H : forall a b : C, (F a --> F b) -> (a --> b)) :=
  forall (a b : C) (h : F a --> F b), h =_S FMor F (H a b h).

Structure > Full : Type := 
  {Full_functor :> Functor C D;
   Full_mor :
    forall a b : C, (Full_functor a --> Full_functor b) -> (a --> b);
   Prf_isFull :> Full_law Full_mor}.

End functor_prop.

Section comp_functor_prop.

Variables (C D E : Category) (F : Functor C D) (G : Functor D E).

Lemma IsFaithful_comp :
 Faithful_law F -> Faithful_law G -> Faithful_law (F o_F G).
Proof.
(* Goal: forall (_ : @Faithful_law C D F) (_ : @Faithful_law D E G), @Faithful_law C E (@Comp_Functor C D E F G) *)
intros H1 H2; unfold Faithful_law in |- *; intros a b f g.
(* Goal: forall _ : @Equal (@Hom E (@FOb C E (@Comp_Functor C D E F G) a) (@FOb C E (@Comp_Functor C D E F G) b)) (@FMor C E (@Comp_Functor C D E F G) a b f) (@FMor C E (@Comp_Functor C D E F G) a b g), @Equal (@Hom C a b) f g *)
unfold Comp_Functor, FMor in |- *; simpl in |- *.
(* Goal: forall _ : @Equal (@Hom E (@Comp_FOb C D E F G a) (@Comp_FOb C D E F G b)) (@Comp_FMor C D E F G a b f) (@Comp_FMor C D E F G a b g), @Equal (@Hom C a b) f g *)
unfold Comp_FMor in |- *; auto.
Qed.

Variables (F1 : forall a b : C, (F a --> F b) -> (a --> b))
  (G1 : forall a b : D, (G a --> G b) -> (a --> b)).

Lemma IsFull_comp :
 Full_law F1 ->
 Full_law G1 ->
 let H1 := fun (a b : C) (h : G (F a) --> G (F b)) => F1 (G1 h) in
 Full_law (F:=F o_F G) H1.
Proof.
(* Goal: forall (_ : @Full_law C D F F1) (_ : @Full_law D E G G1), let H1 := fun (a b : Ob C) (h : Carrier (@Hom E (@FOb D E G (@FOb C D F a)) (@FOb D E G (@FOb C D F b)))) => @F1 a b (@G1 (@FOb C D F a) (@FOb C D F b) h) in @Full_law C E (@Comp_Functor C D E F G) H1 *)
intros p1 p2.
(* Goal: let H1 := fun (a b : Ob C) (h : Carrier (@Hom E (@FOb D E G (@FOb C D F a)) (@FOb D E G (@FOb C D F b)))) => @F1 a b (@G1 (@FOb C D F a) (@FOb C D F b) h) in @Full_law C E (@Comp_Functor C D E F G) H1 *)
unfold Full_law in |- *; intros a b h.
(* Goal: @Equal (@Hom E (@FOb C E (@Comp_Functor C D E F G) a) (@FOb C E (@Comp_Functor C D E F G) b)) h (@FMor C E (@Comp_Functor C D E F G) a b (@F1 a b (@G1 (@FOb C D F a) (@FOb C D F b) h))) *)
unfold FMor in |- *; simpl in |- *; unfold Comp_FMor, Comp_FOb in |- *.
(* Goal: @Equal (@Hom E (@FOb D E G (@FOb C D F a)) (@FOb D E G (@FOb C D F b))) h (@FMor D E G (@FOb C D F a) (@FOb C D F b) (@FMor C D F a b (@F1 a b (@G1 (@FOb C D F a) (@FOb C D F b) h)))) *)
(* *) apply Trans with (FMor G (G1 h)).
(* Goal: @Equal (@Hom E (@FOb D E G (@FOb C D F a)) (@FOb D E G (@FOb C D F b))) h (@FMor D E G (@FOb C D F a) (@FOb C D F b) (@G1 (@FOb C D F a) (@FOb C D F b) h)) *)
(* Goal: @Equal (@Hom E (@FOb D E G (@FOb C D F a)) (@FOb D E G (@FOb C D F b))) (@FMor D E G (@FOb C D F a) (@FOb C D F b) (@G1 (@FOb C D F a) (@FOb C D F b) h)) (@FMor D E G (@FOb C D F a) (@FOb C D F b) (@FMor C D F a b (@F1 a b (@G1 (@FOb C D F a) (@FOb C D F b) h)))) *)
apply (p2 _ _ h).
(* Goal: @Equal (@Hom E (@FOb D E G (@FOb C D F a)) (@FOb D E G (@FOb C D F b))) (@FMor D E G (@FOb C D F a) (@FOb C D F b) (@G1 (@FOb C D F a) (@FOb C D F b) h)) (@FMor D E G (@FOb C D F a) (@FOb C D F b) (@FMor C D F a b (@F1 a b (@G1 (@FOb C D F a) (@FOb C D F b) h)))) *)
apply FPres.
(* Goal: @Equal (@Hom D (@FOb C D F a) (@FOb C D F b)) (@G1 (@FOb C D F a) (@FOb C D F b) h) (@FMor C D F a b (@F1 a b (@G1 (@FOb C D F a) (@FOb C D F b) h))) *)
apply (p1 _ _ (G1 h)).
Qed.

End comp_functor_prop.


