(* 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        *)
(*****************************************************************************)
(*									     *)
(*	                       SET is CCC                		     *)
(*									     *)
(*****************************************************************************)
(*									     *)
(*                     A. SAIBI	  May 95                  		     *)
(*									     *)
(*****************************************************************************)

Require Export SetoidPROD.
Require Export Binary_Products.
Require Export SET.

Set Implicit Arguments.
Unset Strict Implicit.

Section verif_prod.

Variable A B : Setoid.

(* construction de together *)

 Section set_op_together_def.

 Variable C : Setoid.

  Section set_together_def.

  Variables (f : Map C A) (g : Map C B).

  Definition S_together_fun (c : C) := Build_Sprod (f c) (g c).

  Lemma S_together_map_law : Map_law S_together_fun.
  Proof.
(* Goal: @Map_law C (SPROD A B) S_together_fun *)
  unfold Map_law in |- *.
(* Goal: forall (x y : Carrier C) (_ : @Equal C x y), @Equal (SPROD A B) (S_together_fun x) (S_together_fun y) *)
  intros c1 c2 H; unfold S_together_fun in |- *; simpl in |- *.
(* Goal: @Equal_Sprod A B (@Build_Sprod A B (@Ap C A f c1) (@Ap C B g c1)) (@Build_Sprod A B (@Ap C A f c2) (@Ap C B g c2)) *)
  unfold Equal_Sprod in |- *; simpl in |- *; split; apply Pres1; trivial.
  Qed.

  Definition S_together := Build_Map S_together_map_law.

  End set_together_def.

 (* ve'rification des lois *)

 Lemma S_together_l : Map2_congl_law S_together.
 Proof.
 unfold Map2_congl_law in |- *; simpl in |- *; intros g g' f H;
(* Goal: @Ext C (SPROD A B) (@Together_prod SET A B (SPROD A B) (fun C : Setoid => @Build_Map2 (Map_setoid C A) (Map_setoid C B) (Map_setoid C (SPROD A B)) (@S_together C) (@S_together_l C) (@S_together_r C)) C (@Comp SET C (SPROD A B) A h (Proj1_SPROD A B)) (@Comp SET C (SPROD A B) B h (Proj2_SPROD A B))) h *)
  unfold Ext in |- *; simpl in |- *.
(* Goal: forall x : Carrier C, @Equal_Sprod A B (S_together_fun f g x) (S_together_fun f' g x) *)
 intro c; unfold Equal_Sprod in |- *; simpl in |- *; split.
(* Goal: @Equal B (@Ap C B g c) (@Ap C B g c) *)
 apply Refl.
(* Goal: @Equal A (@Ap C A f c) (@Ap C A f' c) *)
(* Goal: @Equal B (@Ap C B g c) (@Ap C B g c) *)
 apply (H c).
 Qed.

 Lemma S_together_r : Map2_congr_law S_together.
 Proof.
 unfold Map2_congr_law in |- *; simpl in |- *; intros f f' g H;
(* Goal: @Ext C (SPROD A B) (@Together_prod SET A B (SPROD A B) (fun C : Setoid => @Build_Map2 (Map_setoid C A) (Map_setoid C B) (Map_setoid C (SPROD A B)) (@S_together C) (@S_together_l C) (@S_together_r C)) C (@Comp SET C (SPROD A B) A h (Proj1_SPROD A B)) (@Comp SET C (SPROD A B) B h (Proj2_SPROD A B))) h *)
  unfold Ext in |- *; simpl in |- *.
(* Goal: forall x : Carrier C, @Equal_Sprod A B (S_together_fun f g x) (S_together_fun f' g x) *)
 intro c; unfold Equal_Sprod in |- *; simpl in |- *; split.
(* Goal: @Equal A (@Ap C A f c) (@Ap C A f' c) *)
(* Goal: @Equal B (@Ap C B g c) (@Ap C B g c) *)
 apply (H c).
(* Goal: @Equal B (@Ap C B g c) (@Ap C B g c) *)
 apply Refl.
 Qed.

 Definition S_op_together := Build_Map2 S_together_l S_together_r.
 
 End set_op_together_def. 

Lemma Eq1_Sprod : Eq1_prod_law (Proj1_SPROD A B) S_op_together.
Proof.
(* Goal: @Eq1_prod_law SET A B (SPROD A B) (Proj1_SPROD A B) S_op_together *)
unfold S_op_together, Eq1_prod_law in |- *; simpl in |- *; intros C f g.
(* Goal: @Ext C (SPROD A B) (@Together_prod SET A B (SPROD A B) (fun C : Setoid => @Build_Map2 (Map_setoid C A) (Map_setoid C B) (Map_setoid C (SPROD A B)) (@S_together C) (@S_together_l C) (@S_together_r C)) C (@Comp SET C (SPROD A B) A h (Proj1_SPROD A B)) (@Comp SET C (SPROD A B) B h (Proj2_SPROD A B))) h *)
unfold Ext in |- *; simpl in |- *.
(* Goal: @Equal B (@Ap C B g c) (@Ap C B g c) *)
intro c; apply Refl.
Qed.

Lemma Eq2_Sprod : Eq2_prod_law (Proj2_SPROD A B) S_op_together.
Proof.
(* Goal: @Eq2_prod_law SET A B (SPROD A B) (Proj2_SPROD A B) S_op_together *)
unfold S_op_together, Eq2_prod_law in |- *; simpl in |- *; intros C f g.
(* Goal: @Ext C (SPROD A B) (@Together_prod SET A B (SPROD A B) (fun C : Setoid => @Build_Map2 (Map_setoid C A) (Map_setoid C B) (Map_setoid C (SPROD A B)) (@S_together C) (@S_together_l C) (@S_together_r C)) C (@Comp SET C (SPROD A B) A h (Proj1_SPROD A B)) (@Comp SET C (SPROD A B) B h (Proj2_SPROD A B))) h *)
unfold Ext in |- *; simpl in |- *.
(* Goal: @Equal B (@Ap C B g c) (@Ap C B g c) *)
intro c; apply Refl.
Qed.

Lemma Unique_S_together :
 Unique_together_law (Proj1_SPROD A B) (Proj2_SPROD A B) S_op_together.
Proof.
(* Goal: @Unique_together_law SET A B (SPROD A B) (Proj1_SPROD A B) (Proj2_SPROD A B) S_op_together *)
unfold Unique_together_law, S_op_together in |- *; simpl in |- *; intros C h.
(* Goal: @Ext C (SPROD A B) (@Together_prod SET A B (SPROD A B) (fun C : Setoid => @Build_Map2 (Map_setoid C A) (Map_setoid C B) (Map_setoid C (SPROD A B)) (@S_together C) (@S_together_l C) (@S_together_r C)) C (@Comp SET C (SPROD A B) A h (Proj1_SPROD A B)) (@Comp SET C (SPROD A B) B h (Proj2_SPROD A B))) h *)
unfold Ext in |- *; simpl in |- *.
(* Goal: @Equal B (@Ap C B g c) (@Ap C B g c) *)
intro c; unfold Equal_Sprod in |- *; simpl in |- *; split; apply Refl.
Qed.

Definition SET_hasBinProd :=
  Build_BinProd Eq1_Sprod Eq2_Sprod Unique_S_together.

End verif_prod.