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 notation "hvbox(a break = \sub \ID b)" non associative with precedence 45
20 notation > "hvbox(a break =_\ID b)" non associative with precedence 45
21 for @{ cic:/matita/logic/equality/eq.ind#xpointer(1/1) ? $a $b }.
23 interpretation "ID eq" 'eqID x y = (cic:/matita/logic/equality/eq.ind#xpointer(1/1) ? x y).
25 record equivalence_relation (A:Type0) : Type1 ≝
26 { eq_rel:2> A → A → CProp0;
27 refl: reflexive ? eq_rel;
28 sym: symmetric ? eq_rel;
29 trans: transitive ? eq_rel
32 record setoid : Type1 ≝
34 eq: equivalence_relation carr
37 record equivalence_relation1 (A:Type1) : Type2 ≝
38 { eq_rel1:2> A → A → CProp1;
39 refl1: reflexive1 ? eq_rel1;
40 sym1: symmetric1 ? eq_rel1;
41 trans1: transitive1 ? eq_rel1
44 record setoid1: Type2 ≝
46 eq1: equivalence_relation1 carr1
49 definition setoid1_of_setoid: setoid → setoid1.
61 coercion setoid1_of_setoid.
62 prefer coercion Type_OF_setoid.
64 record equivalence_relation2 (A:Type2) : Type3 ≝
65 { eq_rel2:2> A → A → CProp2;
66 refl2: reflexive2 ? eq_rel2;
67 sym2: symmetric2 ? eq_rel2;
68 trans2: transitive2 ? eq_rel2
71 record setoid2: Type3 ≝
73 eq2: equivalence_relation2 carr2
76 definition setoid2_of_setoid1: setoid1 → setoid2.
88 coercion setoid2_of_setoid1.
89 prefer coercion Type_OF_setoid2.
90 prefer coercion Type_OF_setoid.
91 prefer coercion Type_OF_setoid1.
92 (* we prefer 0 < 1 < 2 *)
94 record equivalence_relation3 (A:Type3) : Type4 ≝
95 { eq_rel3:2> A → A → CProp3;
96 refl3: reflexive3 ? eq_rel3;
97 sym3: symmetric3 ? eq_rel3;
98 trans3: transitive3 ? eq_rel3
101 record setoid3: Type4 ≝
103 eq3: equivalence_relation3 carr3
107 interpretation "setoid3 eq" 'eq t x y = (eq_rel3 ? (eq3 t) x y).
108 interpretation "setoid2 eq" 'eq t x y = (eq_rel2 ? (eq2 t) x y).
109 interpretation "setoid1 eq" 'eq t x y = (eq_rel1 ? (eq1 t) x y).
110 interpretation "setoid eq" 'eq t x y = (eq_rel ? (eq t) x y).
112 notation > "hvbox(a break =_12 b)" non associative with precedence 45
113 for @{ eq_rel2 (carr2 (setoid2_of_setoid1 ?)) (eq2 (setoid2_of_setoid1 ?)) $a $b }.
114 notation > "hvbox(a break =_0 b)" non associative with precedence 45
115 for @{ eq_rel ? (eq ?) $a $b }.
116 notation > "hvbox(a break =_1 b)" non associative with precedence 45
117 for @{ eq_rel1 ? (eq1 ?) $a $b }.
118 notation > "hvbox(a break =_2 b)" non associative with precedence 45
119 for @{ eq_rel2 ? (eq2 ?) $a $b }.
120 notation > "hvbox(a break =_3 b)" non associative with precedence 45
121 for @{ eq_rel3 ? (eq3 ?) $a $b }.
123 interpretation "setoid3 symmetry" 'invert r = (sym3 ???? r).
124 interpretation "setoid2 symmetry" 'invert r = (sym2 ???? r).
125 interpretation "setoid1 symmetry" 'invert r = (sym1 ???? r).
126 interpretation "setoid symmetry" 'invert r = (sym ???? r).
127 notation ".= r" with precedence 50 for @{'trans $r}.
128 interpretation "trans3" 'trans r = (trans3 ????? r).
129 interpretation "trans2" 'trans r = (trans2 ????? r).
130 interpretation "trans1" 'trans r = (trans1 ????? r).
131 interpretation "trans" 'trans r = (trans ????? r).
133 record unary_morphism (A,B: setoid) : Type0 ≝
135 prop1: ∀a,a'. eq ? a a' → eq ? (fun1 a) (fun1 a')
138 record unary_morphism1 (A,B: setoid1) : Type1 ≝
140 prop11: ∀a,a'. eq1 ? a a' → eq1 ? (fun11 a) (fun11 a')
143 record unary_morphism2 (A,B: setoid2) : Type2 ≝
145 prop12: ∀a,a'. eq2 ? a a' → eq2 ? (fun12 a) (fun12 a')
148 record unary_morphism3 (A,B: setoid3) : Type3 ≝
150 prop13: ∀a,a'. eq3 ? a a' → eq3 ? (fun13 a) (fun13 a')
153 record binary_morphism (A,B,C:setoid) : Type0 ≝
155 prop2: ∀a,a',b,b'. eq ? a a' → eq ? b b' → eq ? (fun2 a b) (fun2 a' b')
158 record binary_morphism1 (A,B,C:setoid1) : Type1 ≝
159 { fun21:2> A → B → C;
160 prop21: ∀a,a',b,b'. eq1 ? a a' → eq1 ? b b' → eq1 ? (fun21 a b) (fun21 a' b')
163 record binary_morphism2 (A,B,C:setoid2) : Type2 ≝
164 { fun22:2> A → B → C;
165 prop22: ∀a,a',b,b'. eq2 ? a a' → eq2 ? b b' → eq2 ? (fun22 a b) (fun22 a' b')
168 record binary_morphism3 (A,B,C:setoid3) : Type3 ≝
169 { fun23:2> A → B → C;
170 prop23: ∀a,a',b,b'. eq3 ? a a' → eq3 ? b b' → eq3 ? (fun23 a b) (fun23 a' b')
173 notation "† c" with precedence 90 for @{'prop1 $c }.
174 notation "l ‡ r" with precedence 90 for @{'prop2 $l $r }.
175 notation "#" with precedence 90 for @{'refl}.
176 interpretation "prop1" 'prop1 c = (prop1 ????? c).
177 interpretation "prop11" 'prop1 c = (prop11 ????? c).
178 interpretation "prop12" 'prop1 c = (prop12 ????? c).
179 interpretation "prop13" 'prop1 c = (prop13 ????? c).
180 interpretation "prop2" 'prop2 l r = (prop2 ???????? l r).
181 interpretation "prop21" 'prop2 l r = (prop21 ???????? l r).
182 interpretation "prop22" 'prop2 l r = (prop22 ???????? l r).
183 interpretation "prop23" 'prop2 l r = (prop23 ???????? l r).
184 interpretation "refl" 'refl = (refl ???).
185 interpretation "refl1" 'refl = (refl1 ???).
186 interpretation "refl2" 'refl = (refl2 ???).
187 interpretation "refl3" 'refl = (refl3 ???).
189 definition unary_morphism2_of_unary_morphism1:
190 ∀S,T:setoid1.unary_morphism1 S T → unary_morphism2 (setoid2_of_setoid1 S) T.
193 [ apply (fun11 ?? u);
194 | apply (prop11 ?? u); ]
197 definition CPROP: setoid1.
202 | intros 1; split; intro; assumption
203 | intros 3; cases i; split; assumption
204 | intros 5; cases i; cases i1; split; intro;
205 [ apply (f2 (f x1)) | apply (f1 (f3 z1))]]]
208 definition CProp0_of_CPROP: carr1 CPROP → CProp0 ≝ λx.x.
209 coercion CProp0_of_CPROP.
211 alias symbol "eq" = "setoid1 eq".
212 definition fi': ∀A,B:CPROP. A = B → B → A.
213 intros; apply (fi ?? e); assumption.
216 notation ". r" with precedence 50 for @{'fi $r}.
217 interpretation "fi" 'fi r = (fi' ?? r).
219 definition and_morphism: binary_morphism1 CPROP CPROP CPROP.
222 | intros; split; intro; cases a1; split;
224 | apply (if ?? e1 b1)
226 | apply (fi ?? e1 b1)]]
229 interpretation "and_morphism" 'and a b = (fun21 ??? and_morphism a b).
231 definition or_morphism: binary_morphism1 CPROP CPROP CPROP.
234 | intros; split; intro; cases o; [1,3:left |2,4: right]
237 | apply (if ?? e1 b1)
238 | apply (fi ?? e1 b1)]]
241 interpretation "or_morphism" 'or a b = (fun21 ??? or_morphism a b).
243 definition if_morphism: binary_morphism1 CPROP CPROP CPROP.
245 [ apply (λA,B. A → B)
246 | intros; split; intros;
247 [ apply (if ?? e1); apply f; apply (fi ?? e); assumption
248 | apply (fi ?? e1); apply f; apply (if ?? e); assumption]]
252 record category : Type1 ≝
254 arrows: objs → objs → setoid;
255 id: ∀o:objs. arrows o o;
256 comp: ∀o1,o2,o3. binary_morphism (arrows o1 o2) (arrows o2 o3) (arrows o1 o3);
257 comp_assoc: ∀o1,o2,o3,o4. ∀a12,a23,a34.
258 comp o1 o3 o4 (comp o1 o2 o3 a12 a23) a34 = comp o1 o2 o4 a12 (comp o2 o3 o4 a23 a34);
259 id_neutral_left: ∀o1,o2. ∀a: arrows o1 o2. comp ??? (id o1) a = a;
260 id_neutral_right: ∀o1,o2. ∀a: arrows o1 o2. comp ??? a (id o2) = a
263 record category1 : Type2 ≝
265 arrows1: objs1 → objs1 → setoid1;
266 id1: ∀o:objs1. arrows1 o o;
267 comp1: ∀o1,o2,o3. binary_morphism1 (arrows1 o1 o2) (arrows1 o2 o3) (arrows1 o1 o3);
268 comp_assoc1: ∀o1,o2,o3,o4. ∀a12,a23,a34.
269 comp1 o1 o3 o4 (comp1 o1 o2 o3 a12 a23) a34 = comp1 o1 o2 o4 a12 (comp1 o2 o3 o4 a23 a34);
270 id_neutral_right1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? (id1 o1) a = a;
271 id_neutral_left1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? a (id1 o2) = a
274 record category2 : Type3 ≝
276 arrows2: objs2 → objs2 → setoid2;
277 id2: ∀o:objs2. arrows2 o o;
278 comp2: ∀o1,o2,o3. binary_morphism2 (arrows2 o1 o2) (arrows2 o2 o3) (arrows2 o1 o3);
279 comp_assoc2: ∀o1,o2,o3,o4. ∀a12,a23,a34.
280 comp2 o1 o3 o4 (comp2 o1 o2 o3 a12 a23) a34 = comp2 o1 o2 o4 a12 (comp2 o2 o3 o4 a23 a34);
281 id_neutral_right2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? (id2 o1) a = a;
282 id_neutral_left2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? a (id2 o2) = a
285 record category3 : Type4 ≝
287 arrows3: objs3 → objs3 → setoid3;
288 id3: ∀o:objs3. arrows3 o o;
289 comp3: ∀o1,o2,o3. binary_morphism3 (arrows3 o1 o2) (arrows3 o2 o3) (arrows3 o1 o3);
290 comp_assoc3: ∀o1,o2,o3,o4. ∀a12,a23,a34.
291 comp3 o1 o3 o4 (comp3 o1 o2 o3 a12 a23) a34 = comp3 o1 o2 o4 a12 (comp3 o2 o3 o4 a23 a34);
292 id_neutral_right3: ∀o1,o2. ∀a: arrows3 o1 o2. comp3 ??? (id3 o1) a = a;
293 id_neutral_left3: ∀o1,o2. ∀a: arrows3 o1 o2. comp3 ??? a (id3 o2) = a
296 notation "'ASSOC'" with precedence 90 for @{'assoc}.
298 interpretation "category2 composition" 'compose x y = (fun22 ??? (comp2 ????) y x).
299 interpretation "category2 assoc" 'assoc = (comp_assoc2 ????????).
300 interpretation "category1 composition" 'compose x y = (fun21 ??? (comp1 ????) y x).
301 interpretation "category1 assoc" 'assoc = (comp_assoc1 ????????).
302 interpretation "category composition" 'compose x y = (fun2 ??? (comp ????) y x).
303 interpretation "category assoc" 'assoc = (comp_assoc ????????).
305 definition category2_of_category1: category1 → category2.
309 | intros; apply (setoid2_of_setoid1 (arrows1 c o o1));
313 [ intros; apply (comp1 c o1 o2 o3 c1 c2);
314 | intros; whd in e e1 a a' b b'; change with (eq1 ? (b∘a) (b'∘a')); apply (e‡e1); ]
315 | intros; simplify; whd in a12 a23 a34; whd; apply rule (ASSOC);
316 | intros; simplify; whd in a; whd; apply id_neutral_right1;
317 | intros; simplify; whd in a; whd; apply id_neutral_left1; ]
319 (*coercion category2_of_category1.*)
321 record functor2 (C1: category2) (C2: category2) : Type3 ≝
322 { map_objs2:1> C1 → C2;
323 map_arrows2: ∀S,T. unary_morphism2 (arrows2 ? S T) (arrows2 ? (map_objs2 S) (map_objs2 T));
324 respects_id2: ∀o:C1. map_arrows2 ?? (id2 ? o) = id2 ? (map_objs2 o);
326 ∀o1,o2,o3.∀f1:arrows2 ? o1 o2.∀f2:arrows2 ? o2 o3.
327 map_arrows2 ?? (f2 ∘ f1) = map_arrows2 ?? f2 ∘ map_arrows2 ?? f1}.
329 definition functor2_setoid: category2 → category2 → setoid3.
332 [ apply (functor2 C1 C2);
335 apply (∀c:C1. cic:/matita/logic/equality/eq.ind#xpointer(1/1) ? (f c) (g c));
336 | simplify; intros; apply cic:/matita/logic/equality/eq.ind#xpointer(1/1/1);
337 | simplify; intros; apply cic:/matita/logic/equality/sym_eq.con; apply H;
338 | simplify; intros; apply cic:/matita/logic/equality/trans_eq.con;
339 [2: apply H; | skip | apply H1;]]]
342 definition functor2_of_functor2_setoid: ∀S,T. functor2_setoid S T → functor2 S T ≝ λS,T,x.x.
343 coercion functor2_of_functor2_setoid.
345 definition CAT2: category3.
348 | apply functor2_setoid;
349 | intros; constructor 1;
351 | intros; constructor 1;
353 | intros; assumption;]
354 | intros; apply rule #;
355 | intros; apply rule #; ]
356 | intros; constructor 1;
357 [ intros; constructor 1;
358 [ intros; apply (c1 (c o));
359 | intros; constructor 1;
360 [ intro; apply (map_arrows2 ?? c1 ?? (map_arrows2 ?? c ?? c2));
361 | intros; apply (††e); ]
363 apply (.= †(respects_id2 : ?));
364 apply (respects_id2 : ?);
366 apply (.= †(respects_comp2 : ?));
367 apply (respects_comp2 : ?); ]
368 | intros; intro; simplify;
369 apply (cic:/matita/logic/equality/eq_ind.con ????? (e ?));
370 apply (cic:/matita/logic/equality/eq_ind.con ????? (e1 ?));
372 | intros; intro; simplify; constructor 1;
373 | intros; intro; simplify; constructor 1;
374 | intros; intro; simplify; constructor 1; ]
377 definition category2_of_objs3_CAT2: objs3 CAT2 → category2 ≝ λx.x.
378 coercion category2_of_objs3_CAT2.
380 definition functor2_setoid_of_arrows3_CAT2: ∀S,T. arrows3 CAT2 S T → functor2_setoid S T ≝ λS,T,x.x.
381 coercion functor2_setoid_of_arrows3_CAT2.
383 definition unary_morphism_setoid: setoid → setoid → setoid.
386 [ apply (unary_morphism s s1);
388 [ intros (f g); apply (∀a:s. eq ? (f a) (g a));
389 | intros 1; simplify; intros; apply refl;
390 | simplify; intros; apply sym; apply f;
391 | simplify; intros; apply trans; [2: apply f; | skip | apply f1]]]
394 definition SET: category1.
397 | apply rule (λS,T:setoid.setoid1_of_setoid (unary_morphism_setoid S T));
398 | intros; constructor 1; [ apply (λx:carr o.x); | intros; assumption ]
399 | intros; constructor 1; [ intros; constructor 1; [ apply (λx. c1 (c x)); | intros;
401 | intros; whd; intros; simplify; whd in H1; whd in H;
402 apply trans; [ apply (b (a' a1)); | lapply (prop1 ?? b (a a1) (a' a1));
403 [ apply Hletin | apply (e a1); ] | apply e1; ]]
404 | intros; whd; intros; simplify; apply refl;
405 | intros; simplify; whd; intros; simplify; apply refl;
406 | intros; simplify; whd; intros; simplify; apply refl;
410 definition setoid_of_SET: objs1 SET → setoid ≝ λx.x.
411 coercion setoid_of_SET.
413 definition unary_morphism_setoid_of_arrows1_SET:
414 ∀P,Q.arrows1 SET P Q → unary_morphism_setoid P Q ≝ λP,Q,x.x.
415 coercion unary_morphism_setoid_of_arrows1_SET.
417 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
418 interpretation "unary morphism" 'Imply a b = (arrows1 SET a b).
420 definition unary_morphism1_setoid1: setoid1 → setoid1 → setoid1.
423 [ apply (unary_morphism1 s s1);
426 alias symbol "eq" = "setoid1 eq".
427 apply (∀a: carr1 s. f a = g a);
428 | intros 1; simplify; intros; apply refl1;
429 | simplify; intros; apply sym1; apply f;
430 | simplify; intros; apply trans1; [2: apply f; | skip | apply f1]]]
433 definition unary_morphism1_of_unary_morphism1_setoid1 :
434 ∀S,T. unary_morphism1_setoid1 S T → unary_morphism1 S T ≝ λP,Q,x.x.
435 coercion unary_morphism1_of_unary_morphism1_setoid1.
437 definition SET1: objs3 CAT2.
440 | apply rule (λS,T.setoid2_of_setoid1 (unary_morphism1_setoid1 S T));
441 | intros; constructor 1; [ apply (λx.x); | intros; assumption ]
442 | intros; constructor 1; [ intros; constructor 1; [ apply (λx. c1 (c x)); | intros;
444 | intros; whd; intros; simplify; whd in H1; whd in H;
445 apply trans1; [ apply (b (a' a1)); | lapply (prop11 ?? b (a a1) (a' a1));
446 [ apply Hletin | apply (e a1); ] | apply e1; ]]
447 | intros; whd; intros; simplify; apply refl1;
448 | intros; simplify; whd; intros; simplify; apply refl1;
449 | intros; simplify; whd; intros; simplify; apply refl1;
453 definition setoid1_of_SET1: objs2 SET1 → setoid1 ≝ λx.x.
454 coercion setoid1_of_SET1.
456 definition unary_morphism1_setoid1_of_arrows2_SET1:
457 ∀P,Q.arrows2 SET1 P Q → unary_morphism1_setoid1 P Q ≝ λP,Q,x.x.
458 coercion unary_morphism1_setoid1_of_arrows2_SET1.
460 variant objs2_of_category1: objs1 SET → objs2 SET1 ≝ setoid1_of_setoid.
461 coercion objs2_of_category1.
463 prefer coercion Type_OF_setoid. (* we prefer the lower carrier projection *)
464 prefer coercion Type_OF_objs1.
466 interpretation "unary morphism1" 'Imply a b = (arrows2 SET1 a b).