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