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

Require Export SET_BinProds.
Require Export Exponents.

Set Implicit Arguments.
Unset Strict Implicit.

(* expo dans SET *)

Section verif_expo.

Variable A B : Setoid.

(* B(expo A) = A==>B *)

Definition S_expo := Map A B.

(* de'finition de eval *)

Definition S_eval_fun (fxa : SPROD (A ==> B) A) := Sprod_l fxa (Sprod_r fxa).

Lemma S_eval_map_law : Map_law S_eval_fun.
Proof.
(* Goal: @Map_law (Map_setoid (SPROD C A) B) (Map_setoid C (Map_setoid A B)) S_lambda1_fun *)
unfold Map_law in |- *.
(* Goal: forall (x y : Carrier (SPROD (Map_setoid A B) A)) (_ : @Equal (SPROD (Map_setoid A B) A) x y), @Equal B (S_eval_fun x) (S_eval_fun y) *)
intros fxa gxa'; elim fxa; intros f a; elim gxa'; intros g a'; simpl in |- *.
(* Goal: forall _ : @Equal_Sprod (Map_setoid A B) A (@Build_Sprod (Map_setoid A B) A f a) (@Build_Sprod (Map_setoid A B) A g a'), @Equal B (S_eval_fun (@Build_Sprod (Map_setoid A B) A f a)) (S_eval_fun (@Build_Sprod (Map_setoid A B) A g a')) *)
unfold S_eval_fun in |- *; simpl in |- *.
(* Goal: forall _ : @Equal_Sprod (Map_setoid A B) A (@Build_Sprod (Map_setoid A B) A f a) (@Build_Sprod (Map_setoid A B) A g a'), @Equal B (@Ap A B f a) (@Ap A B g a') *)
unfold Equal_Sprod in |- *; simpl in |- *.
(* Goal: forall _ : and (@Ext A B f g) (@Equal A a a'), @Equal B (@Ap A B f a) (@Ap A B g a') *)
intro H; elim H; intros H1 H2.
(* Goal: @Equal B (@Ap A B f a) (@Ap A B g a') *)
(* *) apply Trans with (f a').
(* Goal: @Equal B (@Ap A B f a) (@Ap A B f a') *)
(* Goal: @Equal B (@Ap A B f a') (@Ap A B g a') *)
apply Pres1; trivial.
(* Goal: @Equal B (@Ap A B f a') (@Ap A B g a') *)
apply (H1 a').
Qed.

Definition S_eval := Build_Map S_eval_map_law.

(* de'finition de lambda *)

 Section set_lambda_def.

 Variable C : Setoid.

  Section set_lambda_fun_def.

  Variable f : Map (SPROD C A) B.

   Section set_lambda_fun1_def.

   Variable c : C.

   Definition S_lambda_fun2 (a : A) := f (Build_Sprod c a).

   Lemma S_lambda_map_law2 : Map_law S_lambda_fun2.
   Proof.
(* Goal: @Map_law (Map_setoid (SPROD C A) B) (Map_setoid C (Map_setoid A B)) S_lambda1_fun *)
   unfold Map_law in |- *.
(* Goal: forall (x y : Carrier A) (_ : @Equal A x y), @Equal B (S_lambda_fun2 x) (S_lambda_fun2 y) *)
   intros a1 a2 H; unfold S_lambda_fun2 in |- *.                         
(* Goal: @Equal B (@Ap A B (@Ap C (Map_setoid A B) h c) (@Id_fun A a)) (@Ap A B (@Ap C (Map_setoid A B) h c) a) *)
   apply Pres1.
(* Goal: @Equal (SPROD C A) (@Build_Sprod C A (@Sprod_l C A cxa) (@Id_fun A (@Sprod_r C A cxa))) cxa *)
   simpl in |- *; unfold Equal_Sprod in |- *; simpl in |- *; split.
(* Goal: @Equal A (@Id_fun A a) a *)
   apply Refl.
(* Goal: @Equal C c1 c2 *)
(* Goal: @Equal A a a *)
   trivial.
   Qed.

   Definition S_lambda_fun1 := Build_Map S_lambda_map_law2.

   End set_lambda_fun1_def.

  Lemma S_lambda_map_law1 : Map_law S_lambda_fun1.
  Proof.
(* Goal: @Map_law (Map_setoid (SPROD C A) B) (Map_setoid C (Map_setoid A B)) S_lambda1_fun *)
  unfold Map_law in |- *.
(* Goal: forall (x y : Carrier C) (_ : @Equal C x y), @Equal (Map_setoid A B) (S_lambda_fun1 x) (S_lambda_fun1 y) *)
  intros c1 c2 H; unfold S_lambda_fun1 in |- *; simpl in |- *.
(* Goal: @Ext A B (@Build_Map A B (S_lambda_fun2 c1) (@S_lambda_map_law2 c1)) (@Build_Map A B (S_lambda_fun2 c2) (@S_lambda_map_law2 c2)) *)
  unfold Ext in |- *; intro a; unfold S_lambda_fun2 in |- *; simpl in |- *.
(* Goal: @Equal B (@Ap A B (@Ap C (Map_setoid A B) h c) (@Id_fun A a)) (@Ap A B (@Ap C (Map_setoid A B) h c) a) *)
  apply Pres1.
(* Goal: @Equal (SPROD C A) (@Build_Sprod C A (@Sprod_l C A cxa) (@Id_fun A (@Sprod_r C A cxa))) cxa *)
  simpl in |- *; unfold Equal_Sprod in |- *; simpl in |- *; split.
(* Goal: @Equal C c1 c2 *)
(* Goal: @Equal A a a *)
  trivial.
(* Goal: @Equal A (@Id_fun A a) a *)
  apply Refl.
  Qed.

  Definition S_lambda1_fun := Build_Map S_lambda_map_law1.

  End set_lambda_fun_def.

 Lemma S_lambda_map_law : Map_law S_lambda1_fun.
 Proof.
(* Goal: @Map_law (Map_setoid (SPROD C A) B) (Map_setoid C (Map_setoid A B)) S_lambda1_fun *)
 unfold Map_law in |- *.
(* Goal: forall (x y : Carrier (Map_setoid (SPROD C A) B)) (_ : @Equal (Map_setoid (SPROD C A) B) x y), @Equal (Map_setoid C (Map_setoid A B)) (S_lambda1_fun x) (S_lambda1_fun y) *)
 intros f g H; unfold S_lambda1_fun in |- *; simpl in |- *.
(* Goal: @Ext C (Map_setoid A B) (@Build_Map C (Map_setoid A B) (S_lambda_fun1 f) (@S_lambda_map_law1 f)) (@Build_Map C (Map_setoid A B) (S_lambda_fun1 g) (@S_lambda_map_law1 g)) *)
 unfold Ext in |- *; simpl in |- *; intros c.
(* Goal: @Ext A B (S_lambda_fun1 f c) (S_lambda_fun1 g c) *)
 unfold Ext in |- *; simpl in |- *; intro a. 
(* Goal: @Equal B (@S_lambda_fun2 C f (@Sprod_l C A cxa) (@Id_fun A (@Sprod_r C A cxa))) (@Ap (SPROD C A) B f cxa) *)
 unfold S_lambda_fun2 in |- *.
(* Goal: @Equal B (@Ap (SPROD C A) B f (@Build_Sprod C A c a)) (@Ap (SPROD C A) B g (@Build_Sprod C A c a)) *)
 apply (H (Build_Sprod c a)).
 Qed.

 Definition S_Lambda := Build_Map S_lambda_map_law.

 End set_lambda_def. 

(* ve'rification des lois *)

Lemma S_beta_rule : Beta_rule_law (C1:=SET_hasBinProd) S_eval S_Lambda.
Proof.
(* Goal: @Beta_rule_law SET SET_hasBinProd A B (Map_setoid A B) S_eval S_Lambda *)
unfold Beta_rule_law in |- *; simpl in |- *.
(* Goal: forall (c : Setoid) (f : Map (@H_obj_prod SET SET_hasBinProd c A) B), @Ext (SPROD c A) B (@Comp SET (SPROD c A) (SPROD (Map_setoid A B) A) B (@Mor_prod SET SET_hasBinProd c A (Map_setoid A B) A (@Lambda_expo SET SET_hasBinProd A B (Map_setoid A B) S_Lambda c f) (Id_SET A)) S_eval) f *)
intros C f; unfold Ext in |- *; simpl in |- *.
(* Goal: forall _ : @Equal_Sprod (Map_setoid A B) A (@Build_Sprod (Map_setoid A B) A f a) (@Build_Sprod (Map_setoid A B) A g a'), @Equal B (S_eval_fun (@Build_Sprod (Map_setoid A B) A f a)) (S_eval_fun (@Build_Sprod (Map_setoid A B) A g a')) *)
intro cxa; unfold S_eval_fun in |- *; simpl in |- *.
(* Goal: @Equal B (@S_lambda_fun2 C f (@Sprod_l C A cxa) (@Id_fun A (@Sprod_r C A cxa))) (@Ap (SPROD C A) B f cxa) *)
unfold S_lambda_fun2 in |- *.
(* Goal: @Equal B (@Ap A B (@Ap C (Map_setoid A B) h c) (@Id_fun A a)) (@Ap A B (@Ap C (Map_setoid A B) h c) a) *)
apply Pres1.
(* Goal: @Equal (SPROD C A) (@Build_Sprod C A (@Sprod_l C A cxa) (@Id_fun A (@Sprod_r C A cxa))) cxa *)
simpl in |- *; unfold Equal_Sprod in |- *; simpl in |- *; split.
(* Goal: @Equal A (@Id_fun A a) a *)
apply Refl.
(* Goal: @Equal A (@Id_fun A a) a *)
unfold Id_fun in |- *; apply Refl.
Qed.
                    
Lemma S_eta_rule : Eta_rule_law (C1:=SET_hasBinProd) S_eval S_Lambda.
Proof.
(* Goal: @Eta_rule_law SET SET_hasBinProd A B (Map_setoid A B) S_eval S_Lambda *)
unfold Eta_rule_law in |- *; simpl in |- *.
(* Goal: forall (c : Setoid) (h : Map c (Map_setoid A B)), @Ext c (Map_setoid A B) (@Lambda_expo SET SET_hasBinProd A B (Map_setoid A B) S_Lambda c (@Comp SET (SPROD c A) (SPROD (Map_setoid A B) A) B (@Mor_prod SET SET_hasBinProd c A (Map_setoid A B) A h (Id_SET A)) S_eval)) h *)
intros C h; unfold Ext in |- *; simpl in |- *.
(* Goal: forall x : Carrier C, @Ext A B (@S_lambda_fun1 C (@Comp SET (SPROD C A) (SPROD (Map_setoid A B) A) B (@Mor_prod SET SET_hasBinProd C A (Map_setoid A B) A h (Id_SET A)) S_eval) x) (@Ap C (Map_setoid A B) h x) *)
intro c; unfold Ext in |- *; simpl in |- *.
(* Goal: forall _ : @Equal_Sprod (Map_setoid A B) A (@Build_Sprod (Map_setoid A B) A f a) (@Build_Sprod (Map_setoid A B) A g a'), @Equal B (S_eval_fun (@Build_Sprod (Map_setoid A B) A f a)) (S_eval_fun (@Build_Sprod (Map_setoid A B) A g a')) *)
intro a; unfold S_eval_fun in |- *; simpl in |- *. 
(* Goal: @Equal B (@Ap A B (@Comp_fun (SPROD C A) C (Map_setoid A B) (@H_proj1_prod SET SET_hasBinProd C A) h (@Build_Sprod C A c a)) (@Id_fun A a)) (@Ap A B (@Ap C (Map_setoid A B) h c) a) *)
unfold Comp_fun in |- *; simpl in |- *.
(* Goal: @Equal B (@Ap A B (@Ap C (Map_setoid A B) h c) (@Id_fun A a)) (@Ap A B (@Ap C (Map_setoid A B) h c) a) *)
apply Pres1.
(* Goal: @Equal A (@Id_fun A a) a *)
apply Refl.
Qed.

Canonical Structure SET_hasExponent := Build_Exponent S_beta_rule S_eta_rule.

End verif_expo.
