(* 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        *)
(*****************************************************************************)
(*									     *)
(*	                   Monoids Category                		     *)
(*									     *)
(*****************************************************************************)
(*									     *)
(*                     A. SAIBI	  May 95                  		     *)
(*									     *)
(*****************************************************************************)

Require Export SET.
Require Export Monoid.

Set Implicit Arguments.
Unset Strict Implicit.

(* Monoid Morphism composition *)

Section comp_mon.

Variables (m1 m2 m3 : Monoid) (f : MonMor m1 m2) (g : MonMor m2 m3).

Definition Comp_MonMor_map := f o_M g.

Lemma Comp_MonMor_unit_law : MonUnit_law Comp_MonMor_map.
Proof.
(* Goal: @MonUnit_law m1 m3 Comp_MonMor_map *)
unfold MonUnit_law, Comp_MonMor_map in |- *. 
(* Goal: forall a b : Carrier (Mcarrier m1), @Equal (Mcarrier m3) (@Ap (Mcarrier m1) (Mcarrier m3) (@Comp_map (Mcarrier m1) (Mcarrier m2) (Mcarrier m3) (@MonMap m1 m2 f) (@MonMap m2 m3 g)) (@ApMop m1 a b)) (@ApMop m3 (@Ap (Mcarrier m1) (Mcarrier m3) (@Comp_map (Mcarrier m1) (Mcarrier m2) (Mcarrier m3) (@MonMap m1 m2 f) (@MonMap m2 m3 g)) a) (@Ap (Mcarrier m1) (Mcarrier m3) (@Comp_map (Mcarrier m1) (Mcarrier m2) (Mcarrier m3) (@MonMap m1 m2 f) (@MonMap m2 m3 g)) b)) *)
simpl in |- *; unfold Comp_fun in |- *.
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) (Munit m1))) (Munit m3) *)
apply Trans with (g (Munit m2)).
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) (Munit m1))) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (Munit m2)) *)
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (Munit m2)) (Munit m3) *)
apply Pres1; apply MMon_unit.
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (Munit m2)) (Munit m3) *)
apply MMon_unit.
Qed.

Lemma Comp_MonMor_op_law : MonOp_law Comp_MonMor_map.
Proof.
(* Goal: @MonOp_law m1 m3 Comp_MonMor_map *)
unfold MonOp_law, Comp_MonMor_map in |- *.
(* Goal: forall a b : Carrier (Mcarrier m1), @Equal (Mcarrier m3) (@Ap (Mcarrier m1) (Mcarrier m3) (@Comp_map (Mcarrier m1) (Mcarrier m2) (Mcarrier m3) (@MonMap m1 m2 f) (@MonMap m2 m3 g)) (@ApMop m1 a b)) (@ApMop m3 (@Ap (Mcarrier m1) (Mcarrier m3) (@Comp_map (Mcarrier m1) (Mcarrier m2) (Mcarrier m3) (@MonMap m1 m2 f) (@MonMap m2 m3 g)) a) (@Ap (Mcarrier m1) (Mcarrier m3) (@Comp_map (Mcarrier m1) (Mcarrier m2) (Mcarrier m3) (@MonMap m1 m2 f) (@MonMap m2 m3 g)) b)) *)
simpl in |- *; unfold Comp_fun in |- *.
(* Goal: forall a b : Carrier (Mcarrier m1), @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) (@ApMop m1 a b))) (@ApMop m3 (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a)) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) *)
intros a b.
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) (@ApMop m1 a b))) (@ApMop m3 (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a)) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) *)
apply Trans with (g (f a +_M f b)).
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) (@ApMop m1 a b))) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@ApMop m2 (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) *)
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@ApMop m2 (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) (@ApMop m3 (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a)) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) *)
apply (Pres g); apply MMon_op.
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@ApMop m2 (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) (@ApMop m3 (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a)) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) *)
apply MMon_op.
Qed.
 
Canonical Structure Comp_MonMor : MonMor_setoid m1 m3 :=
  Build_MonMor Comp_MonMor_unit_law Comp_MonMor_op_law.

End comp_mon.

Lemma Comp_MonMor_congl : Congl_law Comp_MonMor.
Proof.
(* Goal: @Congl_law Monoid MonMor_setoid Comp_MonMor *)
unfold Congl_law in |- *; simpl in |- *.
(* Goal: @Equal_MonMor m2 m1 f (@Cat_comp Monoid MonMor_setoid Comp_MON m2 m1 m1 f (Id_MON m1)) *)
unfold Equal_MonMor, Ext in |- *; simpl in |- *.
(* Goal: forall (a b c : Monoid) (f g : MonMor a b) (h : MonMor b c) (_ : forall x : Carrier (Mcarrier a), @Equal (Mcarrier b) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b f) x) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b g) x)) (x : Carrier (Mcarrier a)), @Equal (Mcarrier c) (@Comp_fun (Mcarrier a) (Mcarrier b) (Mcarrier c) (@MonMap a b f) (@MonMap b c h) x) (@Comp_fun (Mcarrier a) (Mcarrier b) (Mcarrier c) (@MonMap a b g) (@MonMap b c h) x) *)
unfold Comp_fun in |- *.
(* Goal: forall (a b c : Monoid) (f g : MonMor a b) (h : MonMor b c) (_ : forall x : Carrier (Mcarrier a), @Equal (Mcarrier b) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b f) x) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b g) x)) (x : Carrier (Mcarrier a)), @Equal (Mcarrier c) (@Ap (Mcarrier b) (Mcarrier c) (@MonMap b c h) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b f) x)) (@Ap (Mcarrier b) (Mcarrier c) (@MonMap b c h) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b g) x)) *)
intros m1 m2 m3 f g h H a.
(* Goal: @Equal (Mcarrier m2) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 g) a) *)
apply H.
Qed.

Lemma Comp_MonMor_congr : Congr_law Comp_MonMor.
Proof.
(* Goal: @Congr_law Monoid MonMor_setoid Comp_MonMor *)
unfold Congr_law in |- *; simpl in |- *.
(* Goal: @Equal_MonMor m2 m1 f (@Cat_comp Monoid MonMor_setoid Comp_MON m2 m1 m1 f (Id_MON m1)) *)
unfold Equal_MonMor, Ext in |- *; simpl in |- *.
(* Goal: forall (a b c : Monoid) (f g : MonMor a b) (h : MonMor b c) (_ : forall x : Carrier (Mcarrier a), @Equal (Mcarrier b) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b f) x) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b g) x)) (x : Carrier (Mcarrier a)), @Equal (Mcarrier c) (@Comp_fun (Mcarrier a) (Mcarrier b) (Mcarrier c) (@MonMap a b f) (@MonMap b c h) x) (@Comp_fun (Mcarrier a) (Mcarrier b) (Mcarrier c) (@MonMap a b g) (@MonMap b c h) x) *)
unfold Comp_fun in |- *.
(* Goal: forall (a b c : Monoid) (f g : MonMor a b) (h : MonMor b c) (_ : forall x : Carrier (Mcarrier a), @Equal (Mcarrier b) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b f) x) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b g) x)) (x : Carrier (Mcarrier a)), @Equal (Mcarrier c) (@Ap (Mcarrier b) (Mcarrier c) (@MonMap b c h) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b f) x)) (@Ap (Mcarrier b) (Mcarrier c) (@MonMap b c h) (@Ap (Mcarrier a) (Mcarrier b) (@MonMap a b g) x)) *)
intros m1 m2 m3 f g h H a.
(* Goal: @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 h) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a)) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 h) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 g) a)) *)
apply Pres1.
(* Goal: @Equal (Mcarrier m2) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 g) a) *)
apply H.
Qed.

Definition Comp_MON := Build_Comp Comp_MonMor_congl Comp_MonMor_congr.

Lemma Assoc_MON : Assoc_law Comp_MON.
Proof.
(* Goal: @Assoc_law Monoid MonMor_setoid Comp_MON *)
unfold Assoc_law in |- *; simpl in |- *; intros m1 m2 m3 m4 f g h.
(* Goal: @Equal_MonMor m2 m1 f (@Cat_comp Monoid MonMor_setoid Comp_MON m2 m1 m1 f (Id_MON m1)) *)
unfold Equal_MonMor, Ext in |- *; simpl in |- *.
(* Goal: forall x : Carrier (Mcarrier m2), @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) x) (@Id_fun (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) x)) *)
unfold Comp_fun in |- *; intro a.
(* Goal: @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) *)
apply Refl.
Qed.

(* Id *)

Section id_mon_def.

Variable m : Monoid.

Definition Id_MON_map := Id_SET m.

Lemma Id_MON_unit_law : MonUnit_law Id_MON_map.
Proof.
(* Goal: @MonUnit_law m m Id_MON_map *)
unfold MonUnit_law, Id_MON_map in |- *; simpl in |- *.
(* Goal: @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) *)
unfold Id_fun in |- *; apply Refl. 
Qed.

Lemma Id_MON_op_law : MonOp_law Id_MON_map.
Proof.
(* Goal: @MonOp_law m m Id_MON_map *)
unfold MonOp_law, Id_MON_map in |- *; simpl in |- *.
(* Goal: forall a b : Carrier (Mcarrier m1), @Equal (Mcarrier m3) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) (@ApMop m1 a b))) (@ApMop m3 (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) a)) (@Ap (Mcarrier m2) (Mcarrier m3) (@MonMap m2 m3 g) (@Ap (Mcarrier m1) (Mcarrier m2) (@MonMap m1 m2 f) b))) *)
unfold Id_fun in |- *; intros a b.
(* Goal: @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) *)
apply Refl.
Qed.

Canonical Structure Id_MON : MonMor_setoid m m :=
  Build_MonMor Id_MON_unit_law Id_MON_op_law.

End id_mon_def.

Lemma Idl_MON : Idl_law Comp_MON Id_MON.
Proof.
(* Goal: @Idl_law Monoid MonMor_setoid Comp_MON Id_MON *)
unfold Idl_law in |- *; intros m1 m2 f; simpl in |- *.
(* Goal: @Equal_MonMor m2 m1 f (@Cat_comp Monoid MonMor_setoid Comp_MON m2 m1 m1 f (Id_MON m1)) *)
unfold Equal_MonMor, Ext in |- *; simpl in |- *.
(* Goal: forall x : Carrier (Mcarrier m2), @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) x) (@Id_fun (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) x)) *)
unfold Comp_fun in |- *; intro a.
(* Goal: @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) (@Id_fun (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a)) *)
unfold Id_MON_map in |- *; simpl in |- *; unfold Id_fun in |- *.
(* Goal: @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) *)
apply Refl.
Qed.

Lemma Idr_MON : Idr_law Comp_MON Id_MON.
Proof.
(* Goal: @Idr_law Monoid MonMor_setoid Comp_MON Id_MON *)
unfold Idr_law in |- *; intros m1 m2 f; simpl in |- *.
(* Goal: @Equal_MonMor m2 m1 f (@Cat_comp Monoid MonMor_setoid Comp_MON m2 m1 m1 f (Id_MON m1)) *)
unfold Equal_MonMor, Ext in |- *; simpl in |- *.
(* Goal: forall x : Carrier (Mcarrier m2), @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) x) (@Id_fun (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) x)) *)
unfold Comp_fun in |- *; intro a.
(* Goal: @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) (@Id_fun (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a)) *)
unfold Id_MON_map in |- *; simpl in |- *; unfold Id_fun in |- *.
(* Goal: @Equal (Mcarrier m1) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) (@Ap (Mcarrier m2) (Mcarrier m1) (@MonMap m2 m1 f) a) *)
apply Refl.
Qed.

Canonical Structure MON := Build_Category Assoc_MON Idl_MON Idr_MON.