(* 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 Product                                                 *)
(*                                                                           *)
(*          Amokrane Saibi,  May 1994                                        *)
(*                                                                           *)
(*****************************************************************************)


Require Export Category. 
Require Export SetoidPROD.

Set Implicit Arguments.
Unset Strict Implicit.

Section ProdCat.

Variable A B : Category.

Structure POb : Type :=  {Ob_l : A; Ob_r : B}.

 Section pmor_setoid_def.

 Variable u t : POb.

 Structure Pmor : Type := 
   {Hom_l : Ob_l u --> Ob_l t; Hom_r : Ob_r u --> Ob_r t}.

 Definition Equal_Pmor (f g : Pmor) :=
   Hom_l f =_S Hom_l g /\ Hom_r f =_S Hom_r g.

 Lemma Equal_Pmor_equiv : Equivalence Equal_Pmor.
 Proof.
(* Goal: @Equivalence Pmor Equal_Pmor *)
 apply Build_Equivalence.
(* Goal: @Reflexive Pmor Equal_Pmor *)
(* Goal: @Partial_equivalence Pmor Equal_Pmor *)
 unfold Reflexive, Equal_Pmor in |- *; intro x; split; apply Refl.  
(* Goal: @Partial_equivalence Pmor Equal_Pmor *)
 apply Build_Partial_equivalence.
(* Goal: @Transitive Pmor Equal_Pmor *)
(* Goal: @Symmetric Pmor Equal_Pmor *)
 unfold Transitive, Equal_Pmor in |- *; intros x1 x2 x3 H H0.
(* Goal: and (@Equal (@Hom A (Ob_l u) (Ob_l t)) (Hom_l x1) (Hom_l x3)) (@Equal (@Hom B (Ob_r u) (Ob_r t)) (Hom_r x1) (Hom_r x3)) *)
(* Goal: @Symmetric Pmor Equal_Pmor *)
 elim H; intros H1 H2; elim H0; intros H3 H4; split.
(* Goal: @Equal (@Hom A (Ob_l u) (Ob_l t)) (Hom_l x1) (Hom_l x3) *)
(* Goal: @Equal (@Hom B (Ob_r u) (Ob_r t)) (Hom_r x1) (Hom_r x3) *)
(* Goal: @Symmetric Pmor Equal_Pmor *)
 (* *) apply Trans with (Hom_l x2); assumption.
(* Goal: @Equal (@Hom B (Ob_r u) (Ob_r t)) (Hom_r x1) (Hom_r x3) *)
(* Goal: @Symmetric Pmor Equal_Pmor *)
 (* *) apply Trans with (Hom_r x2); assumption.
(* Goal: @Symmetric Pmor Equal_Pmor *)
 unfold Symmetric, Equal_Pmor in |- *; intros x1 x2 H.
(* Goal: and (@Equal (@Hom A (Ob_l u) (Ob_l t)) (Hom_l x2) (Hom_l x1)) (@Equal (@Hom B (Ob_r u) (Ob_r t)) (Hom_r x2) (Hom_r x1)) *)
 elim H; intros H1 H2; split; apply Sym; assumption.
 Qed.

 Canonical Structure Prod_Hom : Setoid := Equal_Pmor_equiv.

 Definition Prod_Hom' := SPROD (Ob_l u --> Ob_l t) (Ob_r u --> Ob_r t).

 Definition Build1_Pmor :
   (Ob_l u --> Ob_l t) -> (Ob_r u --> Ob_r t) -> Prod_Hom := Build_Pmor.
                
 End pmor_setoid_def.

(* composition *)

Definition Comp_Pmor (a b c : POb) (f : Prod_Hom a b) 
  (g : Prod_Hom b c) := Build_Pmor (Hom_l f o Hom_l g) (Hom_r f o Hom_r g).

Lemma Comp_Pmor_congl : Congl_law Comp_Pmor.
Proof.
(* Goal: @Congl_law POb Prod_Hom Comp_Pmor *)
unfold Congl_law in |- *; simpl in |- *.
(* Goal: forall (a b c : POb) (f g : Pmor a b) (h : Pmor b c) (_ : @Equal_Pmor a b f g), @Equal_Pmor a c (@Comp_Pmor a b c f h) (@Comp_Pmor a b c g h) *)
unfold Equal_Pmor, Comp_Pmor in |- *; simpl in |- *.
(* Goal: forall (a b c : POb) (f g : Pmor b c) (h : Pmor a b) (_ : and (@Equal (@Hom A (Ob_l b) (Ob_l c)) (@Hom_l b c f) (@Hom_l b c g)) (@Equal (@Hom B (Ob_r b) (Ob_r c)) (@Hom_r b c f) (@Hom_r b c g))), and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b h) (@Hom_l b c f)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b h) (@Hom_l b c g))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b h) (@Hom_r b c f)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b h) (@Hom_r b c g))) *)
intros a b c f g h H. 
(* Goal: and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b h) (@Hom_l b c f)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b h) (@Hom_l b c g))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b h) (@Hom_r b c f)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b h) (@Hom_r b c g))) *)
elim H; intros H1 H2; split; apply Comp_l; assumption.
Qed.

Lemma Comp_Pmor_congr : Congr_law Comp_Pmor.
Proof.
(* Goal: @Congr_law POb Prod_Hom Comp_Pmor *)
unfold Congr_law in |- *; simpl in |- *.
(* Goal: forall (a b c : POb) (f g : Pmor a b) (h : Pmor b c) (_ : @Equal_Pmor a b f g), @Equal_Pmor a c (@Comp_Pmor a b c f h) (@Comp_Pmor a b c g h) *)
unfold Equal_Pmor, Comp_Pmor in |- *; simpl in |- *.
(* Goal: forall (a b c : POb) (f g : Pmor a b) (h : Pmor b c) (_ : and (@Equal (@Hom A (Ob_l a) (Ob_l b)) (@Hom_l a b f) (@Hom_l a b g)) (@Equal (@Hom B (Ob_r a) (Ob_r b)) (@Hom_r a b f) (@Hom_r a b g))), and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b f) (@Hom_l b c h)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b g) (@Hom_l b c h))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b f) (@Hom_r b c h)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b g) (@Hom_r b c h))) *)
intros a b c f g.
(* Goal: forall (h : Pmor b c) (_ : and (@Equal (@Hom A (Ob_l a) (Ob_l b)) (@Hom_l a b f) (@Hom_l a b g)) (@Equal (@Hom B (Ob_r a) (Ob_r b)) (@Hom_r a b f) (@Hom_r a b g))), and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b f) (@Hom_l b c h)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b g) (@Hom_l b c h))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b f) (@Hom_r b c h)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b g) (@Hom_r b c h))) *)
elim f; elim g; simpl in |- *.
(* Goal: forall (Hom_l0 : Carrier (@Hom A (Ob_l a) (Ob_l b))) (Hom_r0 : Carrier (@Hom B (Ob_r a) (Ob_r b))) (Hom_l1 : Carrier (@Hom A (Ob_l a) (Ob_l b))) (Hom_r1 : Carrier (@Hom B (Ob_r a) (Ob_r b))) (h : Pmor b c) (_ : and (@Equal (@Hom A (Ob_l a) (Ob_l b)) Hom_l1 Hom_l0) (@Equal (@Hom B (Ob_r a) (Ob_r b)) Hom_r1 Hom_r0)), and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) Hom_l1 (@Hom_l b c h)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) Hom_l0 (@Hom_l b c h))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) Hom_r1 (@Hom_r b c h)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) Hom_r0 (@Hom_r b c h))) *)
intros gl gr fl fr H h.
(* Goal: and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) fl (@Hom_l b c H)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) gl (@Hom_l b c H))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) fr (@Hom_r b c H)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) gr (@Hom_r b c H))) *)
elim h; simpl in |- *.
(* Goal: forall (_ : @Equal (@Hom A (Ob_l a) (Ob_l b)) fl gl) (_ : @Equal (@Hom B (Ob_r a) (Ob_r b)) fr gr), and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) fl (@Hom_l b c H)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) gl (@Hom_l b c H))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) fr (@Hom_r b c H)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) gr (@Hom_r b c H))) *)
intros hl hr.
(* Goal: and (@Equal (@Hom A (Ob_l a) (Ob_l c)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) fl (@Hom_l b c H)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) gl (@Hom_l b c H))) (@Equal (@Hom B (Ob_r a) (Ob_r c)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) fr (@Hom_r b c H)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) gr (@Hom_r b c H))) *)
elim H; intros H1 H2; split; apply Comp_r; assumption.
Qed.

Definition Comp_PROD := Build_Comp Comp_Pmor_congl Comp_Pmor_congr.

Lemma Assoc_PROD : Assoc_law Comp_PROD.
Proof.
(* Goal: @Assoc_law POb Prod_Hom Comp_PROD *)
unfold Assoc_law in |- *; simpl in |- *.
(* Goal: forall (a b : POb) (f : Pmor b a), @Equal_Pmor b a f (@Cat_comp POb Prod_Hom Comp_PROD b a a f (Id_PROD a)) *)
unfold Equal_Pmor in |- *; simpl in |- *.
(* Goal: forall (a b c d : POb) (f : Pmor a b) (g : Pmor b c) (h : Pmor c d), and (@Equal (@Hom A (Ob_l a) (Ob_l d)) (@Comp A (Ob_l a) (Ob_l b) (Ob_l d) (@Hom_l a b f) (@Comp A (Ob_l b) (Ob_l c) (Ob_l d) (@Hom_l b c g) (@Hom_l c d h))) (@Comp A (Ob_l a) (Ob_l c) (Ob_l d) (@Comp A (Ob_l a) (Ob_l b) (Ob_l c) (@Hom_l a b f) (@Hom_l b c g)) (@Hom_l c d h))) (@Equal (@Hom B (Ob_r a) (Ob_r d)) (@Comp B (Ob_r a) (Ob_r b) (Ob_r d) (@Hom_r a b f) (@Comp B (Ob_r b) (Ob_r c) (Ob_r d) (@Hom_r b c g) (@Hom_r c d h))) (@Comp B (Ob_r a) (Ob_r c) (Ob_r d) (@Comp B (Ob_r a) (Ob_r b) (Ob_r c) (@Hom_r a b f) (@Hom_r b c g)) (@Hom_r c d h))) *)
intros; split; apply Ass.
Qed.

Definition Id_PROD (a : POb) := Build_Pmor (Id (Ob_l a)) (Id (Ob_r a)).

Lemma Idl_PROD : Idl_law Comp_PROD Id_PROD.
Proof.
(* Goal: @Idl_law POb Prod_Hom Comp_PROD Id_PROD *)
unfold Idl_law in |- *; simpl in |- *.
(* Goal: forall (a b : POb) (f : Pmor b a), @Equal_Pmor b a f (@Cat_comp POb Prod_Hom Comp_PROD b a a f (Id_PROD a)) *)
unfold Equal_Pmor in |- *; simpl in |- *.
(* Goal: forall (a b : POb) (f : Pmor a b), and (@Equal (@Hom A (Ob_l a) (Ob_l b)) (@Comp A (Ob_l a) (Ob_l a) (Ob_l b) (@Id A (Ob_l a)) (@Hom_l a b f)) (@Hom_l a b f)) (@Equal (@Hom B (Ob_r a) (Ob_r b)) (@Comp B (Ob_r a) (Ob_r a) (Ob_r b) (@Id B (Ob_r a)) (@Hom_r a b f)) (@Hom_r a b f)) *)
intros; split; apply Idl.
Qed.
 
Lemma Idr_PROD : Idr_law Comp_PROD Id_PROD.
Proof.
(* Goal: @Idr_law POb Prod_Hom Comp_PROD Id_PROD *)
unfold Idr_law in |- *; simpl in |- *.
(* Goal: forall (a b : POb) (f : Pmor b a), @Equal_Pmor b a f (@Cat_comp POb Prod_Hom Comp_PROD b a a f (Id_PROD a)) *)
unfold Equal_Pmor in |- *; simpl in |- *.
(* Goal: forall (a b : POb) (f : Pmor b a), and (@Equal (@Hom A (Ob_l b) (Ob_l a)) (@Hom_l b a f) (@Comp A (Ob_l b) (Ob_l a) (Ob_l a) (@Hom_l b a f) (@Id A (Ob_l a)))) (@Equal (@Hom B (Ob_r b) (Ob_r a)) (@Hom_r b a f) (@Comp B (Ob_r b) (Ob_r a) (Ob_r a) (@Hom_r b a f) (@Id B (Ob_r a)))) *)
intros; split; apply Idr. 
Qed.
 
Canonical Structure PROD := Build_Category Assoc_PROD Idl_PROD Idr_PROD.

End ProdCat.
