1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "logic/cprop_connectives.ma".
17 definition Type0 := Type.
18 definition Type1 := Type.
19 definition Type2 := Type.
20 definition Type0_lt_Type1 := (Type0 : Type1).
21 definition Type1_lt_Type2 := (Type1 : Type2).
23 record equivalence_relation (A:Type) : Type ≝
24 { eq_rel:2> A → A → CProp;
25 refl: reflexive ? eq_rel;
26 sym: symmetric ? eq_rel;
27 trans: transitive ? eq_rel
30 record setoid : Type1 ≝
32 eq: equivalence_relation carr
35 definition reflexive1 ≝ λA:Type.λR:A→A→CProp.∀x:A.R x x.
36 definition symmetric1 ≝ λC:Type.λlt:C→C→CProp. ∀x,y:C.lt x y → lt y x.
37 definition transitive1 ≝ λA:Type.λR:A→A→CProp.∀x,y,z:A.R x y → R y z → R x z.
39 record equivalence_relation1 (A:Type) : Type2 ≝
40 { eq_rel1:2> A → A → CProp;
41 refl1: reflexive1 ? eq_rel1;
42 sym1: symmetric1 ? eq_rel1;
43 trans1: transitive1 ? eq_rel1
46 record setoid1: Type ≝
48 eq1: equivalence_relation1 carr1
51 definition setoid1_of_setoid: setoid → setoid1.
63 coercion setoid1_of_setoid.
66 definition Leibniz: Type → setoid.
71 [ apply (λx,y:T.cic:/matita/logic/equality/eq.ind#xpointer(1/1) ? x y)
72 | alias id "refl_eq" = "cic:/matita/logic/equality/eq.ind#xpointer(1/1/1)".
74 | alias id "sym_eq" = "cic:/matita/logic/equality/sym_eq.con".
76 | alias id "trans_eq" = "cic:/matita/logic/equality/trans_eq.con".
83 interpretation "setoid1 eq" 'eq x y = (eq_rel1 _ (eq1 _) x y).
84 interpretation "setoid eq" 'eq x y = (eq_rel _ (eq _) x y).
85 interpretation "setoid1 symmetry" 'invert r = (sym1 ____ r).
86 interpretation "setoid symmetry" 'invert r = (sym ____ r).
87 notation ".= r" with precedence 50 for @{'trans $r}.
88 interpretation "trans1" 'trans r = (trans1 _____ r).
89 interpretation "trans" 'trans r = (trans _____ r).
91 record unary_morphism (A,B: setoid1) : Type0 ≝
93 prop_1: ∀a,a'. eq1 ? a a' → eq1 ? (fun_1 a) (fun_1 a')
96 record binary_morphism (A,B,C:setoid) : Type0 ≝
98 prop: ∀a,a',b,b'. eq ? a a' → eq ? b b' → eq ? (fun a b) (fun a' b')
101 record binary_morphism1 (A,B,C:setoid1) : Type0 ≝
103 prop1: ∀a,a',b,b'. eq1 ? a a' → eq1 ? b b' → eq1 ? (fun1 a b) (fun1 a' b')
106 notation "† c" with precedence 90 for @{'prop1 $c }.
107 notation "l ‡ r" with precedence 90 for @{'prop $l $r }.
108 notation "#" with precedence 90 for @{'refl}.
109 interpretation "prop_1" 'prop1 c = (prop_1 _____ c).
110 interpretation "prop1" 'prop l r = (prop1 ________ l r).
111 interpretation "prop" 'prop l r = (prop ________ l r).
112 interpretation "refl1" 'refl = (refl1 ___).
113 interpretation "refl" 'refl = (refl ___).
115 definition CPROP: setoid1.
120 | intros 1; split; intro; assumption
121 | intros 3; cases H; split; assumption
122 | intros 5; cases H; cases H1; split; intro;
123 [ apply (H4 (H2 H6)) | apply (H3 (H5 H6))]]]
126 definition if': ∀A,B:CPROP. A = B → A → B.
127 intros; apply (if ?? H); assumption.
130 notation ". r" with precedence 50 for @{'if $r}.
131 interpretation "if" 'if r = (if' __ r).
133 definition and_morphism: binary_morphism1 CPROP CPROP CPROP.
136 | intros; split; intro; cases H2; split;
138 | apply (if ?? H1 b1)
140 | apply (fi ?? H1 b1)]]
143 interpretation "and_morphism" 'and a b = (fun1 ___ and_morphism a b).
145 definition or_morphism: binary_morphism1 CPROP CPROP CPROP.
148 | intros; split; intro; cases H2; [1,3:left |2,4: right]
151 | apply (if ?? H1 b1)
152 | apply (fi ?? H1 b1)]]
155 interpretation "or_morphism" 'or a b = (fun1 ___ or_morphism a b).
157 definition if_morphism: binary_morphism1 CPROP CPROP CPROP.
159 [ apply (λA,B. A → B)
160 | intros; split; intros;
161 [ apply (if ?? H1); apply H2; apply (fi ?? H); assumption
162 | apply (fi ?? H1); apply H2; apply (if ?? H); assumption]]
166 definition eq_morphism: ∀S:setoid. binary_morphism S S CPROP.
169 [ apply (eq_rel ? (eq S))
170 | intros; split; intro;
171 [ apply (.= H \sup -1);
180 record category : Type1 ≝
182 arrows: objs → objs → setoid;
183 id: ∀o:objs. arrows o o;
184 comp: ∀o1,o2,o3. binary_morphism (arrows o1 o2) (arrows o2 o3) (arrows o1 o3);
185 comp_assoc: ∀o1,o2,o3,o4. ∀a12,a23,a34.
186 comp o1 o3 o4 (comp o1 o2 o3 a12 a23) a34 = comp o1 o2 o4 a12 (comp o2 o3 o4 a23 a34);
187 id_neutral_left: ∀o1,o2. ∀a: arrows o1 o2. comp ??? (id o1) a = a;
188 id_neutral_right: ∀o1,o2. ∀a: arrows o1 o2. comp ??? a (id o2) = a
191 record category1 : Type2 ≝
193 arrows1: objs1 → objs1 → setoid1;
194 id1: ∀o:objs1. arrows1 o o;
195 comp1: ∀o1,o2,o3. binary_morphism1 (arrows1 o1 o2) (arrows1 o2 o3) (arrows1 o1 o3);
196 comp_assoc1: ∀o1,o2,o3,o4. ∀a12,a23,a34.
197 comp1 o1 o3 o4 (comp1 o1 o2 o3 a12 a23) a34 = comp1 o1 o2 o4 a12 (comp1 o2 o3 o4 a23 a34);
198 id_neutral_right1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? (id1 o1) a = a;
199 id_neutral_left1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? a (id1 o2) = a
202 notation "'ASSOC'" with precedence 90 for @{'assoc}.
203 notation "'ASSOC1'" with precedence 90 for @{'assoc1}.
205 interpretation "category1 composition" 'compose x y = (fun1 ___ (comp1 ____) y x).
206 interpretation "category1 assoc" 'assoc1 = (comp_assoc1 ________).
207 interpretation "category composition" 'compose x y = (fun ___ (comp ____) y x).
208 interpretation "category assoc" 'assoc = (comp_assoc ________).
210 definition unary_morphism_setoid: setoid → setoid → setoid.
213 [ apply (unary_morphism s s1);
215 [ intros (f g); apply (∀a. f a = g a);
216 | intros 1; simplify; intros; apply refl;
217 | simplify; intros; apply sym; apply H;
218 | simplify; intros; apply trans; [2: apply H; | skip | apply H1]]]
221 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
222 interpretation "unary morphism" 'Imply a b = (unary_morphism_setoid a b).
223 interpretation "unary morphism" 'Imply a b = (unary_morphism a b).
225 definition SET: category1.
228 | apply rule (λS,T.unary_morphism_setoid S T);
229 | intros; constructor 1; [ apply (λx.x); | intros; assumption ]
230 | intros; constructor 1; [ intros; constructor 1; [ apply (λx. c1 (c x)); | intros;
232 | intros; whd; intros; simplify; whd in H1; whd in H;
233 apply trans; [ apply (b (a' a1)); | lapply (prop_1 ?? b (a a1) (a' a1));
234 [ apply Hletin | apply (H a1); ] | apply H1; ]]
235 | intros; whd; intros; simplify; apply refl;
236 | intros; simplify; whd; intros; simplify; apply refl;
237 | intros; simplify; whd; intros; simplify; apply refl;
241 definition setoid_OF_SET: objs1 SET → setoid.
242 intros; apply o; qed.
244 coercion setoid_OF_SET.
247 definition prop_1_SET :
248 ∀A,B:SET.∀w:arrows1 SET A B.∀a,b:A.eq1 ? a b→eq1 ? (w a) (w b).
249 intros; apply (prop_1 A B w a b H);
252 interpretation "SET dagger" 'prop1 h = (prop_1_SET _ _ _ _ _ h).