]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/formal_topology/overlap/categories.ma
The universe inconsistency comes from big union, that uses the existential.
[helm.git] / helm / software / matita / contribs / formal_topology / overlap / categories.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "logic/cprop_connectives.ma".
16
17 definition Type0 := Type.
18 definition Type1 := Type.
19 definition Type2 := Type.
20 definition Type3 := Type.
21 definition Type0_lt_Type1 := (Type0 : Type1).
22 definition Type1_lt_Type2 := (Type1 : Type2).
23 definition Type2_lt_Type3 := (Type2 : Type3).
24
25 definition Type_OF_Type0: Type0 → Type := λx.x.
26 definition Type_OF_Type1: Type1 → Type := λx.x.
27 definition Type_OF_Type2: Type2 → Type := λx.x.
28 definition Type_OF_Type3: Type3 → Type := λx.x.
29 coercion Type_OF_Type0.
30 coercion Type_OF_Type1.
31 coercion Type_OF_Type2.
32 coercion Type_OF_Type3.
33
34 definition CProp0 := CProp.
35 definition CProp1 := CProp.
36 definition CProp2 := CProp.
37 definition CProp0_lt_CProp1 := (CProp0 : CProp1).
38 definition CProp1_lt_CProp2 := (CProp1 : CProp2).
39
40 definition CProp_OF_CProp0: CProp0 → CProp := λx.x.
41 definition CProp_OF_CProp1: CProp1 → CProp := λx.x.
42 definition CProp_OF_CProp2: CProp2 → CProp := λx.x.
43
44 record equivalence_relation (A:Type0) : Type1 ≝
45  { eq_rel:2> A → A → CProp0;
46    refl: reflexive ? eq_rel;
47    sym: symmetric ? eq_rel;
48    trans: transitive ? eq_rel
49  }.
50
51 record setoid : Type1 ≝
52  { carr:> Type0;
53    eq: equivalence_relation carr
54  }.
55
56 definition reflexive1 ≝ λA:Type1.λR:A→A→CProp1.∀x:A.R x x.
57 definition symmetric1 ≝ λC:Type1.λlt:C→C→CProp1. ∀x,y:C.lt x y → lt y x.
58 definition transitive1 ≝ λA:Type1.λR:A→A→CProp1.∀x,y,z:A.R x y → R y z → R x z.
59
60 record equivalence_relation1 (A:Type1) : Type1 ≝
61  { eq_rel1:2> A → A → CProp1;
62    refl1: reflexive1 ? eq_rel1;
63    sym1: symmetric1 ? eq_rel1;
64    trans1: transitive1 ? eq_rel1
65  }.
66
67 record setoid1: Type2 ≝
68  { carr1:> Type1;
69    eq1: equivalence_relation1 carr1
70  }.
71
72 definition setoid1_of_setoid: setoid → setoid1.
73  intro;
74  constructor 1;
75   [ apply (carr s)
76   | constructor 1;
77     [ apply (eq_rel s);
78       apply (eq s)
79     | apply (refl s)
80     | apply (sym s)
81     | apply (trans s)]]
82 qed.
83
84 (* questa coercion e' necessaria per problemi di unificazione *)
85 coercion setoid1_of_setoid.
86
87 definition reflexive2 ≝ λA:Type2.λR:A→A→CProp2.∀x:A.R x x.
88 definition symmetric2 ≝ λC:Type2.λlt:C→C→CProp2. ∀x,y:C.lt x y → lt y x.
89 definition transitive2 ≝ λA:Type2.λR:A→A→CProp2.∀x,y,z:A.R x y → R y z → R x z.
90
91 record equivalence_relation2 (A:Type2) : Type2 ≝
92  { eq_rel2:2> A → A → CProp2;
93    refl2: reflexive2 ? eq_rel2;
94    sym2: symmetric2 ? eq_rel2;
95    trans2: transitive2 ? eq_rel2
96  }.
97
98 record setoid2: Type3 ≝
99  { carr2:> Type2;
100    eq2: equivalence_relation2 carr2
101  }.
102
103 definition setoid2_of_setoid1: setoid1 → setoid2.
104  intro;
105  constructor 1;
106   [ apply (carr1 s)
107   | constructor 1;
108     [ apply (eq_rel1 s);
109       apply (eq1 s)
110     | apply (refl1 s)
111     | apply (sym1 s)
112     | apply (trans1 s)]]
113 qed.
114
115 (*coercion setoid2_of_setoid1.*)
116
117 (*
118 definition Leibniz: Type → setoid.
119  intro;
120  constructor 1;
121   [ apply T
122   | constructor 1;
123      [ apply (λx,y:T.cic:/matita/logic/equality/eq.ind#xpointer(1/1) ? x y)
124      | alias id "refl_eq" = "cic:/matita/logic/equality/eq.ind#xpointer(1/1/1)".
125        apply refl_eq
126      | alias id "sym_eq" = "cic:/matita/logic/equality/sym_eq.con".
127        apply sym_eq
128      | alias id "trans_eq" = "cic:/matita/logic/equality/trans_eq.con".
129        apply trans_eq ]]
130 qed.
131
132 coercion Leibniz.
133 *)
134
135 interpretation "setoid2 eq" 'eq x y = (eq_rel2 _ (eq2 _) x y).
136 interpretation "setoid1 eq" 'eq x y = (eq_rel1 _ (eq1 _) x y).
137 interpretation "setoid eq" 'eq x y = (eq_rel _ (eq _) x y).
138 interpretation "setoid2 symmetry" 'invert r = (sym2 ____ r).
139 interpretation "setoid1 symmetry" 'invert r = (sym1 ____ r).
140 interpretation "setoid symmetry" 'invert r = (sym ____ r).
141 notation ".= r" with precedence 50 for @{'trans $r}.
142 interpretation "trans2" 'trans r = (trans2 _____ r).
143 interpretation "trans1" 'trans r = (trans1 _____ r).
144 interpretation "trans" 'trans r = (trans _____ r).
145
146 record unary_morphism (A,B: setoid) : Type0 ≝
147  { fun1:1> A → B;
148    prop1: ∀a,a'. eq ? a a' → eq ? (fun1 a) (fun1 a')
149  }.
150
151 record unary_morphism1 (A,B: setoid1) : Type1 ≝
152  { fun11:1> A → B;
153    prop11: ∀a,a'. eq1 ? a a' → eq1 ? (fun11 a) (fun11 a')
154  }.
155
156 record unary_morphism2 (A,B: setoid2) : Type2 ≝
157  { fun12:1> A → B;
158    prop12: ∀a,a'. eq2 ? a a' → eq2 ? (fun12 a) (fun12 a')
159  }.
160
161 record binary_morphism (A,B,C:setoid) : Type0 ≝
162  { fun2:2> A → B → C;
163    prop2: ∀a,a',b,b'. eq ? a a' → eq ? b b' → eq ? (fun2 a b) (fun2 a' b')
164  }.
165
166 record binary_morphism1 (A,B,C:setoid1) : Type1 ≝
167  { fun21:2> A → B → C;
168    prop21: ∀a,a',b,b'. eq1 ? a a' → eq1 ? b b' → eq1 ? (fun21 a b) (fun21 a' b')
169  }.
170
171 record binary_morphism2 (A,B,C:setoid2) : Type2 ≝
172  { fun22:2> A → B → C;
173    prop22: ∀a,a',b,b'. eq2 ? a a' → eq2 ? b b' → eq2 ? (fun22 a b) (fun22 a' b')
174  }.
175
176 notation "† c" with precedence 90 for @{'prop1 $c }.
177 notation "l ‡ r" with precedence 90 for @{'prop2 $l $r }.
178 notation "#" with precedence 90 for @{'refl}.
179 interpretation "prop1" 'prop1 c  = (prop1 _____ c).
180 interpretation "prop11" 'prop1 c = (prop11 _____ c).
181 interpretation "prop12" 'prop1 c = (prop12 _____ c).
182 interpretation "prop2" 'prop2 l r = (prop2 ________ l r).
183 interpretation "prop21" 'prop2 l r = (prop21 ________ l r).
184 interpretation "refl" 'refl = (refl ___).
185 interpretation "refl1" 'refl = (refl1 ___).
186 interpretation "refl2" 'refl = (refl2 ___).
187
188 definition CPROP: setoid1.
189  constructor 1;
190   [ apply CProp0
191   | constructor 1;
192      [ apply Iff
193      | intros 1; split; intro; assumption
194      | intros 3; cases H; split; assumption
195      | intros 5; cases H; cases H1; split; intro;
196         [ apply (H4 (H2 x1)) | apply (H3 (H5 z1))]]]
197 qed.
198
199 alias symbol "eq" = "setoid1 eq".
200 definition if': ∀A,B:CPROP. A = B → A → B.
201  intros; apply (if ?? e); assumption.
202 qed.
203
204 notation ". r" with precedence 50 for @{'if $r}.
205 interpretation "if" 'if r = (if' __ r).
206
207 definition and_morphism: binary_morphism1 CPROP CPROP CPROP.
208  constructor 1;
209   [ apply And
210   | intros; split; intro; cases H; split;
211      [ apply (if ?? e a1)
212      | apply (if ?? e1 b1)
213      | apply (fi ?? e a1)
214      | apply (fi ?? e1 b1)]]
215 qed.
216
217 interpretation "and_morphism" 'and a b = (fun21 ___ and_morphism a b).
218
219 definition or_morphism: binary_morphism1 CPROP CPROP CPROP.
220  constructor 1;
221   [ apply Or
222   | intros; split; intro; cases H; [1,3:left |2,4: right]
223      [ apply (if ?? e a1)
224      | apply (fi ?? e a1)
225      | apply (if ?? e1 b1)
226      | apply (fi ?? e1 b1)]]
227 qed.
228
229 interpretation "or_morphism" 'or a b = (fun21 ___ or_morphism a b).
230
231 definition if_morphism: binary_morphism1 CPROP CPROP CPROP.
232  constructor 1;
233   [ apply (λA,B. A → B)
234   | intros; split; intros;
235      [ apply (if ?? e1); apply H; apply (fi ?? e); assumption
236      | apply (fi ?? e1); apply H; apply (if ?? e); assumption]]
237 qed.
238
239 (*
240 definition eq_morphism: ∀S:setoid. binary_morphism S S CPROP.
241  intro;
242  constructor 1;
243   [ apply (eq_rel ? (eq S))
244   | intros; split; intro;
245      [ apply (.= H \sup -1);
246        apply (.= H2);
247        assumption
248      | apply (.= H);
249        apply (.= H2);
250        apply (H1 \sup -1)]]
251 qed.
252 *)
253
254 record category : Type1 ≝
255  { objs:> Type0;
256    arrows: objs → objs → setoid;
257    id: ∀o:objs. arrows o o;
258    comp: ∀o1,o2,o3. binary_morphism1 (arrows o1 o2) (arrows o2 o3) (arrows o1 o3);
259    comp_assoc: ∀o1,o2,o3,o4. ∀a12,a23,a34.
260     comp o1 o3 o4 (comp o1 o2 o3 a12 a23) a34 = comp o1 o2 o4 a12 (comp o2 o3 o4 a23 a34);
261    id_neutral_left: ∀o1,o2. ∀a: arrows o1 o2. comp ??? (id o1) a = a;
262    id_neutral_right: ∀o1,o2. ∀a: arrows o1 o2. comp ??? a (id o2) = a
263  }.
264
265 record category1 : Type2 ≝
266  { objs1:> Type1;
267    arrows1: objs1 → objs1 → setoid1;
268    id1: ∀o:objs1. arrows1 o o;
269    comp1: ∀o1,o2,o3. binary_morphism1 (arrows1 o1 o2) (arrows1 o2 o3) (arrows1 o1 o3);
270    comp_assoc1: ∀o1,o2,o3,o4. ∀a12,a23,a34.
271     comp1 o1 o3 o4 (comp1 o1 o2 o3 a12 a23) a34 = comp1 o1 o2 o4 a12 (comp1 o2 o3 o4 a23 a34);
272    id_neutral_right1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? (id1 o1) a = a;
273    id_neutral_left1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? a (id1 o2) = a
274  }.
275
276 record category2 : Type3 ≝
277  { objs2:> Type2;
278    arrows2: objs2 → objs2 → setoid2;
279    id2: ∀o:objs2. arrows2 o o;
280    comp2: ∀o1,o2,o3. binary_morphism2 (arrows2 o1 o2) (arrows2 o2 o3) (arrows2 o1 o3);
281    comp_assoc2: ∀o1,o2,o3,o4. ∀a12,a23,a34.
282     comp2 o1 o3 o4 (comp2 o1 o2 o3 a12 a23) a34 = comp2 o1 o2 o4 a12 (comp2 o2 o3 o4 a23 a34);
283    id_neutral_right2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? (id2 o1) a = a;
284    id_neutral_left2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? a (id2 o2) = a
285  }.
286
287 notation "'ASSOC'" with precedence 90 for @{'assoc}.
288 notation "'ASSOC1'" with precedence 90 for @{'assoc1}.
289 notation "'ASSOC2'" with precedence 90 for @{'assoc2}.
290
291 interpretation "category1 composition" 'compose x y = (fun22 ___ (comp2 ____) y x).
292 interpretation "category1 assoc" 'assoc1 = (comp_assoc2 ________).
293 interpretation "category1 composition" 'compose x y = (fun21 ___ (comp1 ____) y x).
294 interpretation "category1 assoc" 'assoc1 = (comp_assoc1 ________).
295 interpretation "category composition" 'compose x y = (fun2 ___ (comp ____) y x).
296 interpretation "category assoc" 'assoc = (comp_assoc ________).
297
298 (* bug grande come una casa?
299    Ma come fa a passare la quantificazione larga??? *)
300 definition unary_morphism_setoid: setoid → setoid → setoid.
301  intros;
302  constructor 1;
303   [ apply (unary_morphism s s1);
304   | constructor 1;
305      [ intros (f g); apply (∀a:s. eq ? (f a) (g a));
306      | intros 1; simplify; intros; apply refl;
307      | simplify; intros; apply sym; apply H;
308      | simplify; intros; apply trans; [2: apply H; | skip | apply H1]]]
309 qed.
310
311 definition SET: category1.
312  constructor 1;
313   [ apply setoid;
314   | apply rule (λS,T:setoid.unary_morphism_setoid S T);
315   | intros; constructor 1; [ apply (λx:carr o.x); | intros; assumption ]
316   | intros; constructor 1; [ intros; constructor 1; [ apply (λx. t1 (t x)); | intros;
317      apply († (†e));]
318   | intros; whd; intros; simplify; whd in H1; whd in H;
319     apply trans; [ apply (b (a' a1)); | lapply (prop1 ?? b (a a1) (a' a1));
320      [ apply Hletin | apply (e a1); ]  | apply e1; ]]
321   | intros; whd; intros; simplify; apply refl;
322   | intros; simplify; whd; intros; simplify; apply refl;
323   | intros; simplify; whd; intros; simplify; apply refl;
324   ]
325 qed.
326
327 definition setoid_of_SET: objs1 SET → setoid.
328  intros; apply o; qed.
329 coercion setoid_of_SET.
330
331 definition setoid1_of_SET: SET → setoid1.
332  intro; whd in t; apply setoid1_of_setoid; apply t.
333 qed.
334 coercion setoid1_of_SET.
335
336 definition eq': ∀w:SET.equivalence_relation ? := λw.eq w.
337
338 definition prop1_SET : 
339  ∀A,B:SET.∀w:arrows1 SET A B.∀a,b:Type_OF_objs1 A.eq' ? a b→eq' ? (w a) (w b).
340 intros; apply (prop1 A B w a b e);
341 qed.
342
343
344 interpretation "SET dagger" 'prop1 h = (prop1_SET _ _ _ _ _ h).
345 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
346 interpretation "unary morphism" 'Imply a b = (arrows1 SET a b).
347 interpretation "SET eq" 'eq x y = (eq_rel _ (eq' _) x y).
348
349 definition unary_morphism1_setoid1: setoid1 → setoid1 → setoid2.
350  intros;
351  constructor 1;
352   [ apply (unary_morphism1 s s1);
353   | constructor 1;
354      [ intros (f g);
355        alias symbol "eq" = "setoid1 eq".
356        apply (∀a: carr1 s. f a = g a);
357      | intros 1; simplify; intros; apply refl1;
358      | simplify; intros; apply sym1; apply H;
359      | simplify; intros; apply trans1; [2: apply H; | skip | apply H1]]]
360 qed.
361
362 definition SET1: category2.
363  constructor 1;
364   [ apply setoid1;
365   | apply rule (λS,T.unary_morphism1_setoid1 S T);
366   | intros; constructor 1; [ apply (λx.x); | intros; assumption ]
367   | intros; constructor 1; [ intros; constructor 1; [ apply (λx. t1 (t x)); | intros;
368      apply († (†e));]
369   | intros; whd; intros; simplify; whd in H1; whd in H;
370     apply trans1; [ apply (b (a' a1)); | lapply (prop11 ?? b (a a1) (a' a1));
371      [ apply Hletin | apply (e a1); ]  | apply e1; ]]
372   | intros; whd; intros; simplify; apply refl1;
373   | intros; simplify; whd; intros; simplify; apply refl1;
374   | intros; simplify; whd; intros; simplify; apply refl1;
375   ]
376 qed.
377
378 definition setoid1_OF_SET1: objs2 SET1 → setoid1.
379  intros; apply o; qed.
380
381 coercion setoid1_OF_SET1.
382
383 definition eq'': ∀w:SET1.equivalence_relation1 ? := λw.eq1 w.
384
385 definition prop11_SET1 : 
386  ∀A,B:SET1.∀w:arrows2 SET1 A B.∀a,b:Type_OF_objs2 A.eq'' ? a b→eq'' ? (w a) (w b).
387 intros; apply (prop11 A B w a b e);
388 qed.
389
390 definition hint: Type_OF_category2 SET1 → Type1.
391  intro; whd in t; apply (carr1 t);
392 qed.
393 coercion hint.
394
395 interpretation "SET dagger" 'prop1 h = (prop11_SET1 _ _ _ _ _ h).
396 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
397 interpretation "unary morphism1" 'Imply a b = (arrows2 SET1 a b).
398 interpretation "SET1 eq" 'eq x y = (eq_rel1 _ (eq'' _) x y).