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