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 "cprop_connectives.ma".
17 record equivalence_relation (A:Type0) : Type1 ≝
18 { eq_rel:2> A → A → CProp0;
19 refl: reflexive ? eq_rel;
20 sym: symmetric ? eq_rel;
21 trans: transitive ? eq_rel
24 record setoid : Type1 ≝
26 eq: equivalence_relation carr
29 definition reflexive1: ∀A:Type1.∀R:A→A→CProp1.CProp1 ≝ λA:Type1.λR:A→A→CProp1.∀x:A.R x x.
30 definition symmetric1: ∀A:Type1.∀R:A→A→CProp1.CProp1 ≝ λC:Type1.λlt:C→C→CProp1. ∀x,y:C.lt x y → lt y x.
31 definition transitive1: ∀A:Type1.∀R:A→A→CProp1.CProp1 ≝ λA:Type1.λR:A→A→CProp1.∀x,y,z:A.R x y → R y z → R x z.
33 record equivalence_relation1 (A:Type1) : Type2 ≝
34 { eq_rel1:2> A → A → CProp1;
35 refl1: reflexive1 ? eq_rel1;
36 sym1: symmetric1 ? eq_rel1;
37 trans1: transitive1 ? eq_rel1
40 record setoid1: Type2 ≝
42 eq1: equivalence_relation1 carr1
45 definition setoid1_of_setoid: setoid → setoid1.
57 coercion setoid1_of_setoid.
59 definition reflexive2: ∀A:Type2.∀R:A→A→CProp2.CProp2 ≝ λA:Type2.λR:A→A→CProp2.∀x:A.R x x.
60 definition symmetric2: ∀A:Type2.∀R:A→A→CProp2.CProp2 ≝ λC:Type2.λlt:C→C→CProp2. ∀x,y:C.lt x y → lt y x.
61 definition transitive2: ∀A:Type2.∀R:A→A→CProp2.CProp2 ≝ λA:Type2.λR:A→A→CProp2.∀x,y,z:A.R x y → R y z → R x z.
63 record equivalence_relation2 (A:Type2) : Type3 ≝
64 { eq_rel2:2> A → A → CProp2;
65 refl2: reflexive2 ? eq_rel2;
66 sym2: symmetric2 ? eq_rel2;
67 trans2: transitive2 ? eq_rel2
70 record setoid2: Type3 ≝
72 eq2: equivalence_relation2 carr2
75 definition setoid2_of_setoid1: setoid1 → setoid2.
87 coercion setoid2_of_setoid1.
89 interpretation "setoid2 eq" 'eq x y = (eq_rel2 _ (eq2 _) x y).
90 interpretation "setoid1 eq" 'eq x y = (eq_rel1 _ (eq1 _) x y).
91 interpretation "setoid eq" 'eq x y = (eq_rel _ (eq _) x y).
92 interpretation "setoid2 symmetry" 'invert r = (sym2 ____ r).
93 interpretation "setoid1 symmetry" 'invert r = (sym1 ____ r).
94 interpretation "setoid symmetry" 'invert r = (sym ____ r).
95 notation ".= r" with precedence 50 for @{'trans $r}.
96 interpretation "trans2" 'trans r = (trans2 _____ r).
97 interpretation "trans1" 'trans r = (trans1 _____ r).
98 interpretation "trans" 'trans r = (trans _____ r).
100 record unary_morphism (A,B: setoid) : Type0 ≝
102 prop1: ∀a,a'. eq ? a a' → eq ? (fun1 a) (fun1 a')
105 record unary_morphism1 (A,B: setoid1) : Type1 ≝
107 prop11: ∀a,a'. eq1 ? a a' → eq1 ? (fun11 a) (fun11 a')
110 record unary_morphism2 (A,B: setoid2) : Type2 ≝
112 prop12: ∀a,a'. eq2 ? a a' → eq2 ? (fun12 a) (fun12 a')
115 record binary_morphism (A,B,C:setoid) : Type0 ≝
117 prop2: ∀a,a',b,b'. eq ? a a' → eq ? b b' → eq ? (fun2 a b) (fun2 a' b')
120 record binary_morphism1 (A,B,C:setoid1) : Type1 ≝
121 { fun21:2> A → B → C;
122 prop21: ∀a,a',b,b'. eq1 ? a a' → eq1 ? b b' → eq1 ? (fun21 a b) (fun21 a' b')
125 record binary_morphism2 (A,B,C:setoid2) : Type2 ≝
126 { fun22:2> A → B → C;
127 prop22: ∀a,a',b,b'. eq2 ? a a' → eq2 ? b b' → eq2 ? (fun22 a b) (fun22 a' b')
130 notation "† c" with precedence 90 for @{'prop1 $c }.
131 notation "l ‡ r" with precedence 90 for @{'prop2 $l $r }.
132 notation "#" with precedence 90 for @{'refl}.
133 interpretation "prop1" 'prop1 c = (prop1 _____ c).
134 interpretation "prop11" 'prop1 c = (prop11 _____ c).
135 interpretation "prop12" 'prop1 c = (prop12 _____ c).
136 interpretation "prop2" 'prop2 l r = (prop2 ________ l r).
137 interpretation "prop21" 'prop2 l r = (prop21 ________ l r).
138 interpretation "prop22" 'prop2 l r = (prop22 ________ l r).
139 interpretation "refl" 'refl = (refl ___).
140 interpretation "refl1" 'refl = (refl1 ___).
141 interpretation "refl2" 'refl = (refl2 ___).
143 definition CPROP: setoid1.
148 | intros 1; split; intro; assumption
149 | intros 3; cases i; split; assumption
150 | intros 5; cases i; cases i1; split; intro;
151 [ apply (f2 (f x1)) | apply (f1 (f3 z1))]]]
154 alias symbol "eq" = "setoid1 eq".
155 definition fi': ∀A,B:CPROP. A = B → B → A.
156 intros; apply (fi ?? e); assumption.
159 notation ". r" with precedence 50 for @{'fi $r}.
160 interpretation "fi" 'fi r = (fi' __ r).
162 definition and_morphism: binary_morphism1 CPROP CPROP CPROP.
165 | intros; split; intro; cases a1; split;
167 | apply (if ?? e1 b1)
169 | apply (fi ?? e1 b1)]]
172 interpretation "and_morphism" 'and a b = (fun21 ___ and_morphism a b).
174 definition or_morphism: binary_morphism1 CPROP CPROP CPROP.
177 | intros; split; intro; cases o; [1,3:left |2,4: right]
180 | apply (if ?? e1 b1)
181 | apply (fi ?? e1 b1)]]
184 interpretation "or_morphism" 'or a b = (fun21 ___ or_morphism a b).
186 definition if_morphism: binary_morphism1 CPROP CPROP CPROP.
188 [ apply (λA,B. A → B)
189 | intros; split; intros;
190 [ apply (if ?? e1); apply f; apply (fi ?? e); assumption
191 | apply (fi ?? e1); apply f; apply (if ?? e); assumption]]
194 record category : Type1 ≝
196 arrows: objs → objs → setoid;
197 id: ∀o:objs. arrows o o;
198 comp: ∀o1,o2,o3. binary_morphism1 (arrows o1 o2) (arrows o2 o3) (arrows o1 o3);
199 comp_assoc: ∀o1,o2,o3,o4. ∀a12,a23,a34.
200 comp o1 o3 o4 (comp o1 o2 o3 a12 a23) a34 = comp o1 o2 o4 a12 (comp o2 o3 o4 a23 a34);
201 id_neutral_left: ∀o1,o2. ∀a: arrows o1 o2. comp ??? (id o1) a = a;
202 id_neutral_right: ∀o1,o2. ∀a: arrows o1 o2. comp ??? a (id o2) = a
205 record category1 : Type2 ≝
207 arrows1: objs1 → objs1 → setoid1;
208 id1: ∀o:objs1. arrows1 o o;
209 comp1: ∀o1,o2,o3. binary_morphism1 (arrows1 o1 o2) (arrows1 o2 o3) (arrows1 o1 o3);
210 comp_assoc1: ∀o1,o2,o3,o4. ∀a12,a23,a34.
211 comp1 o1 o3 o4 (comp1 o1 o2 o3 a12 a23) a34 = comp1 o1 o2 o4 a12 (comp1 o2 o3 o4 a23 a34);
212 id_neutral_right1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? (id1 o1) a = a;
213 id_neutral_left1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? a (id1 o2) = a
216 record category2 : Type3 ≝
218 arrows2: objs2 → objs2 → setoid2;
219 id2: ∀o:objs2. arrows2 o o;
220 comp2: ∀o1,o2,o3. binary_morphism2 (arrows2 o1 o2) (arrows2 o2 o3) (arrows2 o1 o3);
221 comp_assoc2: ∀o1,o2,o3,o4. ∀a12,a23,a34.
222 comp2 o1 o3 o4 (comp2 o1 o2 o3 a12 a23) a34 = comp2 o1 o2 o4 a12 (comp2 o2 o3 o4 a23 a34);
223 id_neutral_right2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? (id2 o1) a = a;
224 id_neutral_left2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? a (id2 o2) = a
227 notation "'ASSOC'" with precedence 90 for @{'assoc}.
229 interpretation "category2 composition" 'compose x y = (fun22 ___ (comp2 ____) y x).
230 interpretation "category2 assoc" 'assoc = (comp_assoc2 ________).
231 interpretation "category1 composition" 'compose x y = (fun21 ___ (comp1 ____) y x).
232 interpretation "category1 assoc" 'assoc = (comp_assoc1 ________).
233 interpretation "category composition" 'compose x y = (fun2 ___ (comp ____) y x).
234 interpretation "category assoc" 'assoc = (comp_assoc ________).
236 definition unary_morphism_setoid: setoid → setoid → setoid.
239 [ apply (unary_morphism s s1);
241 [ intros (f g); apply (∀a:s. eq ? (f a) (g a));
242 | intros 1; simplify; intros; apply refl;
243 | simplify; intros; apply sym; apply f;
244 | simplify; intros; apply trans; [2: apply f; | skip | apply f1]]]
247 definition SET: category1.
250 | apply rule (λS,T:setoid.unary_morphism_setoid S T);
251 | intros; constructor 1; [ apply (λx:carr o.x); | intros; assumption ]
252 | intros; constructor 1; [ intros; constructor 1; [ apply (λx. t1 (t x)); | intros;
254 | intros; whd; intros; simplify; whd in H1; whd in H;
255 apply trans; [ apply (b (a' a1)); | lapply (prop1 ?? b (a a1) (a' a1));
256 [ apply Hletin | apply (e a1); ] | apply e1; ]]
257 | intros; whd; intros; simplify; apply refl;
258 | intros; simplify; whd; intros; simplify; apply refl;
259 | intros; simplify; whd; intros; simplify; apply refl;
263 definition setoid_of_SET: objs1 SET → setoid.
264 intros; apply o; qed.
265 coercion setoid_of_SET.
267 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
268 interpretation "unary morphism" 'Imply a b = (arrows1 SET a b).
270 definition unary_morphism1_setoid1: setoid1 → setoid1 → setoid1.
273 [ apply (unary_morphism1 s s1);
276 alias symbol "eq" = "setoid1 eq".
277 apply (∀a: carr1 s. f a = g a);
278 | intros 1; simplify; intros; apply refl1;
279 | simplify; intros; apply sym1; apply f;
280 | simplify; intros; apply trans1; [2: apply f; | skip | apply f1]]]
283 definition SET1: category2.
286 | apply rule (λS,T.unary_morphism1_setoid1 S T);
287 | intros; constructor 1; [ apply (λx.x); | intros; assumption ]
288 | intros; constructor 1; [ intros; constructor 1; [ apply (λx. t1 (t x)); | intros;
290 | intros; whd; intros; simplify; whd in H1; whd in H;
291 apply trans1; [ apply (b (a' a1)); | lapply (prop11 ?? b (a a1) (a' a1));
292 [ apply Hletin | apply (e a1); ] | apply e1; ]]
293 | intros; whd; intros; simplify; apply refl1;
294 | intros; simplify; whd; intros; simplify; apply refl1;
295 | intros; simplify; whd; intros; simplify; apply refl1;
299 definition setoid1_OF_SET1: objs2 SET1 → setoid1.
300 intros; apply o; qed.
302 coercion setoid1_OF_SET1.
304 definition setoid2_OF_category2: Type_OF_category2 SET1 → setoid2.
305 intro; apply (setoid2_of_setoid1 t); qed.
306 coercion setoid2_OF_category2.
308 definition objs2_OF_category1: Type_OF_category1 SET → objs2 SET1.
309 intro; apply (setoid1_of_setoid t); qed.
310 coercion objs2_OF_category1.
312 definition Type1_OF_SET1: Type_OF_category2 SET1 → Type1.
313 intro; whd in t; apply (carr1 t);
315 coercion Type1_OF_SET1.
317 definition Type_OF_setoid1_of_carr: ∀U. carr U → Type_OF_setoid1 ?(*(setoid1_of_SET U)*).
321 coercion Type_OF_setoid1_of_carr.
323 definition carr' ≝ λx:Type_OF_category1 SET.Type_OF_Type0 (carr x).
324 coercion carr'. (* we prefer the lower carrier projection *)
326 interpretation "unary morphism1" 'Imply a b = (arrows2 SET1 a b).
328 lemma unary_morphism1_of_arrows1_SET1: ∀S,T. (S ⇒ T) → unary_morphism1 S T.
331 coercion unary_morphism1_of_arrows1_SET1.