(* 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           *)
(*****************************************************************************)
(*                                                                           *)
(*          SET : The Category of Setoids                                    *)
(*                                                                           *)
(*          Peter Aczel, Dec. 92                                             *)
(*          rev. Gerard Huet,  Aug. 1993                                     *)
(*          rev. Amokrane Saibi,  May 1994                                   *)
(*                                                                           *)
(*****************************************************************************)

Require Export Category.

Set Implicit Arguments.
Unset Strict Implicit.

(* Map composition operator *)

Lemma Comp_map_congl : Congl_law Comp_map.
Proof.
(* Goal: @Congl_law Setoid Map_setoid Comp_map *)
unfold Congl_law in |- *; simpl in |- *.
(* Goal: @Ext b a f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Ext in |- *; simpl in |- *.
(* Goal: forall (a b c : Setoid) (f g : Map b c) (h : Map a b) (_ : forall x : Carrier b, @Equal c (@Ap b c f x) (@Ap b c g x)) (x : Carrier a), @Equal c (@Comp_fun a b c h f x) (@Comp_fun a b c h g x) *)
unfold Comp_fun in |- *; auto.
Qed.

Lemma Comp_map_congr : Congr_law Comp_map.
Proof.
(* Goal: @Congr_law Setoid Map_setoid Comp_map *)
unfold Congr_law in |- *; simpl in |- *.
(* Goal: @Ext b a f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Ext in |- *; simpl in |- *.
(* Goal: forall (a b c : Setoid) (f g : Map a b) (h : Map b c) (_ : forall x : Carrier a, @Equal b (@Ap a b f x) (@Ap a b g x)) (x : Carrier a), @Equal c (@Comp_fun a b c f h x) (@Comp_fun a b c g h x) *)
unfold Comp_fun in |- *.
(* Goal: forall (a b c : Setoid) (f g : Map a b) (h : Map b c) (_ : forall x : Carrier a, @Equal b (@Ap a b f x) (@Ap a b g x)) (x : Carrier a), @Equal c (@Ap b c h (@Ap a b f x)) (@Ap b c h (@Ap a b g x)) *)
intros a b c f g h e x.
(* Goal: @Equal c (@Ap b c h (@Ap a b f x)) (@Ap b c h (@Ap a b g x)) *)
apply Pres1; auto.
Qed.

Definition Comp_SET := Build_Comp Comp_map_congl Comp_map_congr.

Lemma Assoc_SET : Assoc_law Comp_SET.
Proof.
(* Goal: @Assoc_law Setoid Map_setoid Comp_SET *)
unfold Assoc_law in |- *; simpl in |- *; intros.
(* Goal: @Ext a d (@Cat_comp Setoid Map_setoid Comp_SET a b d f (@Cat_comp Setoid Map_setoid Comp_SET b c d g h)) (@Cat_comp Setoid Map_setoid Comp_SET a c d (@Cat_comp Setoid Map_setoid Comp_SET a b c f g) h) *)
unfold Ext in |- *; intro x; simpl in |- *.
(* Goal: @Equal d (@Comp_fun b c d g h (@Ap a b f x)) (@Comp_fun a c d (@Cat_comp Setoid Map_setoid Comp_SET a b c f g) h x) *)
apply Refl.
Qed.

(* Id *)

Definition Id_SET := Id_map.
 
Lemma Idl_SET : Idl_law Comp_SET Id_SET.
Proof.
(* Goal: @Idl_law Setoid Map_setoid Comp_SET Id_SET *)
unfold Idl_law in |- *; intros.
(* Goal: @Equal (Map_setoid b a) f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Comp in |- *.
(* Goal: @Equal (Map_setoid b a) f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Ap2 in |- *; simpl in |- *.
(* Goal: @Ext b a f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Ext in |- *; simpl in |- *.
(* Goal: @Equal d (@Comp_fun b c d g h (@Ap a b f x)) (@Comp_fun a c d (@Cat_comp Setoid Map_setoid Comp_SET a b c f g) h x) *)
intro x; apply Refl.
Qed.

Lemma Idr_SET : Idr_law Comp_SET Id_SET.
Proof.
(* Goal: @Idr_law Setoid Map_setoid Comp_SET Id_SET *)
unfold Idr_law in |- *; intros.
(* Goal: @Equal (Map_setoid b a) f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Comp in |- *.
(* Goal: @Equal (Map_setoid b a) f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Ap2 in |- *; simpl in |- *.
(* Goal: @Ext b a f (@Cat_comp Setoid Map_setoid Comp_SET b a a f (Id_SET a)) *)
unfold Ext in |- *; simpl in |- *.
(* Goal: @Equal d (@Comp_fun b c d g h (@Ap a b f x)) (@Comp_fun a c d (@Cat_comp Setoid Map_setoid Comp_SET a b c f g) h x) *)
intro x; apply Refl.
Qed.

Canonical Structure SET := Build_Category Assoc_SET Idl_SET Idr_SET.
