]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/formal_topology/overlap/categories.ma
c5db6ad6082e91d03461ffba6f3341b924849b0b
[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.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.
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 coercion setoid1_of_setoid.
58 prefer coercion Type_OF_setoid.
59
60 definition reflexive2: ∀A:Type2.∀R:A→A→CProp2.CProp2 ≝ λA:Type2.λR:A→A→CProp2.∀x:A.R x x.
61 definition symmetric2: ∀A:Type2.∀R:A→A→CProp2.CProp2 ≝ λC:Type2.λlt:C→C→CProp2. ∀x,y:C.lt x y → lt y x.
62 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
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 prefer coercion Type_OF_setoid2. 
90 prefer coercion Type_OF_setoid. 
91 prefer coercion Type_OF_setoid1. 
92 (* we prefer 0 < 1 < 2 *)
93
94 interpretation "setoid2 eq" 'eq x y = (eq_rel2 _ (eq2 _) x y).
95 interpretation "setoid1 eq" 'eq x y = (eq_rel1 _ (eq1 _) x y).
96 interpretation "setoid eq" 'eq x y = (eq_rel _ (eq _) x y).
97 interpretation "setoid2 symmetry" 'invert r = (sym2 ____ r).
98 interpretation "setoid1 symmetry" 'invert r = (sym1 ____ r).
99 interpretation "setoid symmetry" 'invert r = (sym ____ r).
100 notation ".= r" with precedence 50 for @{'trans $r}.
101 interpretation "trans2" 'trans r = (trans2 _____ r).
102 interpretation "trans1" 'trans r = (trans1 _____ r).
103 interpretation "trans" 'trans r = (trans _____ r).
104
105 record unary_morphism (A,B: setoid) : Type0 ≝
106  { fun1:1> A → B;
107    prop1: ∀a,a'. eq ? a a' → eq ? (fun1 a) (fun1 a')
108  }.
109
110 record unary_morphism1 (A,B: setoid1) : Type1 ≝
111  { fun11:1> A → B;
112    prop11: ∀a,a'. eq1 ? a a' → eq1 ? (fun11 a) (fun11 a')
113  }.
114
115 record unary_morphism2 (A,B: setoid2) : Type2 ≝
116  { fun12:1> A → B;
117    prop12: ∀a,a'. eq2 ? a a' → eq2 ? (fun12 a) (fun12 a')
118  }.
119
120 record binary_morphism (A,B,C:setoid) : Type0 ≝
121  { fun2:2> A → B → C;
122    prop2: ∀a,a',b,b'. eq ? a a' → eq ? b b' → eq ? (fun2 a b) (fun2 a' b')
123  }.
124
125 record binary_morphism1 (A,B,C:setoid1) : Type1 ≝
126  { fun21:2> A → B → C;
127    prop21: ∀a,a',b,b'. eq1 ? a a' → eq1 ? b b' → eq1 ? (fun21 a b) (fun21 a' b')
128  }.
129
130 record binary_morphism2 (A,B,C:setoid2) : Type2 ≝
131  { fun22:2> A → B → C;
132    prop22: ∀a,a',b,b'. eq2 ? a a' → eq2 ? b b' → eq2 ? (fun22 a b) (fun22 a' b')
133  }.
134
135 notation "† c" with precedence 90 for @{'prop1 $c }.
136 notation "l ‡ r" with precedence 90 for @{'prop2 $l $r }.
137 notation "#" with precedence 90 for @{'refl}.
138 interpretation "prop1" 'prop1 c  = (prop1 _____ c).
139 interpretation "prop11" 'prop1 c = (prop11 _____ c).
140 interpretation "prop12" 'prop1 c = (prop12 _____ c).
141 interpretation "prop2" 'prop2 l r = (prop2 ________ l r).
142 interpretation "prop21" 'prop2 l r = (prop21 ________ l r).
143 interpretation "prop22" 'prop2 l r = (prop22 ________ l r).
144 interpretation "refl" 'refl = (refl ___).
145 interpretation "refl1" 'refl = (refl1 ___).
146 interpretation "refl2" 'refl = (refl2 ___).
147
148 definition CPROP: setoid1.
149  constructor 1;
150   [ apply CProp0
151   | constructor 1;
152      [ apply Iff
153      | intros 1; split; intro; assumption
154      | intros 3; cases i; split; assumption
155      | intros 5; cases i; cases i1; split; intro;
156         [ apply (f2 (f x1)) | apply (f1 (f3 z1))]]]
157 qed.
158
159 definition CProp0_of_CPROP: carr1 CPROP → CProp0 ≝ λx.x.
160 coercion CProp0_of_CPROP.
161
162 alias symbol "eq" = "setoid1 eq".
163 definition fi': ∀A,B:CPROP. A = B → B → A.
164  intros; apply (fi ?? e); assumption.
165 qed.
166
167 notation ". r" with precedence 50 for @{'fi $r}.
168 interpretation "fi" 'fi r = (fi' __ r).
169
170 definition and_morphism: binary_morphism1 CPROP CPROP CPROP.
171  constructor 1;
172   [ apply And
173   | intros; split; intro; cases a1; split;
174      [ apply (if ?? e a2)
175      | apply (if ?? e1 b1)
176      | apply (fi ?? e a2)
177      | apply (fi ?? e1 b1)]]
178 qed.
179
180 interpretation "and_morphism" 'and a b = (fun21 ___ and_morphism a b).
181
182 definition or_morphism: binary_morphism1 CPROP CPROP CPROP.
183  constructor 1;
184   [ apply Or
185   | intros; split; intro; cases o; [1,3:left |2,4: right]
186      [ apply (if ?? e a1)
187      | apply (fi ?? e a1)
188      | apply (if ?? e1 b1)
189      | apply (fi ?? e1 b1)]]
190 qed.
191
192 interpretation "or_morphism" 'or a b = (fun21 ___ or_morphism a b).
193
194 definition if_morphism: binary_morphism1 CPROP CPROP CPROP.
195  constructor 1;
196   [ apply (λA,B. A → B)
197   | intros; split; intros;
198      [ apply (if ?? e1); apply f; apply (fi ?? e); assumption
199      | apply (fi ?? e1); apply f; apply (if ?? e); assumption]]
200 qed.
201
202
203 record category : Type1 ≝
204  { objs:> Type0;
205    arrows: objs → objs → setoid;
206    id: ∀o:objs. arrows o o;
207    comp: ∀o1,o2,o3. binary_morphism (arrows o1 o2) (arrows o2 o3) (arrows o1 o3);
208    comp_assoc: ∀o1,o2,o3,o4. ∀a12,a23,a34.
209     comp o1 o3 o4 (comp o1 o2 o3 a12 a23) a34 = comp o1 o2 o4 a12 (comp o2 o3 o4 a23 a34);
210    id_neutral_left: ∀o1,o2. ∀a: arrows o1 o2. comp ??? (id o1) a = a;
211    id_neutral_right: ∀o1,o2. ∀a: arrows o1 o2. comp ??? a (id o2) = a
212  }.
213
214 record category1 : Type2 ≝
215  { objs1:> Type1;
216    arrows1: objs1 → objs1 → setoid1;
217    id1: ∀o:objs1. arrows1 o o;
218    comp1: ∀o1,o2,o3. binary_morphism1 (arrows1 o1 o2) (arrows1 o2 o3) (arrows1 o1 o3);
219    comp_assoc1: ∀o1,o2,o3,o4. ∀a12,a23,a34.
220     comp1 o1 o3 o4 (comp1 o1 o2 o3 a12 a23) a34 = comp1 o1 o2 o4 a12 (comp1 o2 o3 o4 a23 a34);
221    id_neutral_right1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? (id1 o1) a = a;
222    id_neutral_left1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? a (id1 o2) = a
223  }.
224
225 record category2 : Type3 ≝
226  { objs2:> Type2;
227    arrows2: objs2 → objs2 → setoid2;
228    id2: ∀o:objs2. arrows2 o o;
229    comp2: ∀o1,o2,o3. binary_morphism2 (arrows2 o1 o2) (arrows2 o2 o3) (arrows2 o1 o3);
230    comp_assoc2: ∀o1,o2,o3,o4. ∀a12,a23,a34.
231     comp2 o1 o3 o4 (comp2 o1 o2 o3 a12 a23) a34 = comp2 o1 o2 o4 a12 (comp2 o2 o3 o4 a23 a34);
232    id_neutral_right2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? (id2 o1) a = a;
233    id_neutral_left2: ∀o1,o2. ∀a: arrows2 o1 o2. comp2 ??? a (id2 o2) = a
234  }.
235
236 notation "'ASSOC'" with precedence 90 for @{'assoc}.
237
238 interpretation "category2 composition" 'compose x y = (fun22 ___ (comp2 ____) y x).
239 interpretation "category2 assoc" 'assoc = (comp_assoc2 ________).
240 interpretation "category1 composition" 'compose x y = (fun21 ___ (comp1 ____) y x).
241 interpretation "category1 assoc" 'assoc = (comp_assoc1 ________).
242 interpretation "category composition" 'compose x y = (fun2 ___ (comp ____) y x).
243 interpretation "category assoc" 'assoc = (comp_assoc ________).
244
245 definition unary_morphism_setoid: setoid → setoid → setoid.
246  intros;
247  constructor 1;
248   [ apply (unary_morphism s s1);
249   | constructor 1;
250      [ intros (f g); apply (∀a:s. eq ? (f a) (g a));
251      | intros 1; simplify; intros; apply refl;
252      | simplify; intros; apply sym; apply f;
253      | simplify; intros; apply trans; [2: apply f; | skip | apply f1]]]
254 qed.
255
256 definition SET: category1.
257  constructor 1;
258   [ apply setoid;
259   | apply rule (λS,T:setoid.setoid1_of_setoid (unary_morphism_setoid S T));
260   | intros; constructor 1; [ apply (λx:carr o.x); | intros; assumption ]
261   | intros; constructor 1; [ intros; constructor 1; [ apply (λx. c1 (c x)); | intros;
262      apply († (†e));]
263   | intros; whd; intros; simplify; whd in H1; whd in H;
264     apply trans; [ apply (b (a' a1)); | lapply (prop1 ?? b (a a1) (a' a1));
265      [ apply Hletin | apply (e a1); ]  | apply e1; ]]
266   | intros; whd; intros; simplify; apply refl;
267   | intros; simplify; whd; intros; simplify; apply refl;
268   | intros; simplify; whd; intros; simplify; apply refl;
269   ]
270 qed.
271
272 definition setoid_of_SET: objs1 SET → setoid ≝ λx.x.
273 coercion setoid_of_SET.
274
275 definition unary_morphism_setoid_of_arrows1_SET: 
276   ∀P,Q.arrows1 SET P Q → unary_morphism_setoid P Q  ≝ λP,Q,x.x.
277 coercion unary_morphism_setoid_of_arrows1_SET.
278
279 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
280 interpretation "unary morphism" 'Imply a b = (arrows1 SET a b).
281
282 definition unary_morphism1_setoid1: setoid1 → setoid1 → setoid1.
283  intros;
284  constructor 1;
285   [ apply (unary_morphism1 s s1);
286   | constructor 1;
287      [ intros (f g);
288        alias symbol "eq" = "setoid1 eq".
289        apply (∀a: carr1 s. f a = g a);
290      | intros 1; simplify; intros; apply refl1;
291      | simplify; intros; apply sym1; apply f;
292      | simplify; intros; apply trans1; [2: apply f; | skip | apply f1]]]
293 qed.
294
295 definition unary_morphism1_of_unary_morphism1_setoid1 : 
296   ∀S,T. unary_morphism1_setoid1 S T → unary_morphism1 S T ≝ λP,Q,x.x.
297 coercion unary_morphism1_of_unary_morphism1_setoid1.
298
299 definition SET1: category2.
300  constructor 1;
301   [ apply setoid1;
302   | apply rule (λS,T.setoid2_of_setoid1 (unary_morphism1_setoid1 S T));
303   | intros; constructor 1; [ apply (λx.x); | intros; assumption ]
304   | intros; constructor 1; [ intros; constructor 1; [ apply (λx. c1 (c x)); | intros;
305      apply († (†e));]
306   | intros; whd; intros; simplify; whd in H1; whd in H;
307     apply trans1; [ apply (b (a' a1)); | lapply (prop11 ?? b (a a1) (a' a1));
308      [ apply Hletin | apply (e a1); ]  | apply e1; ]]
309   | intros; whd; intros; simplify; apply refl1;
310   | intros; simplify; whd; intros; simplify; apply refl1;
311   | intros; simplify; whd; intros; simplify; apply refl1;
312   ]
313 qed.
314
315 definition setoid1_of_SET1: objs2 SET1 → setoid1 ≝ λx.x.
316 coercion setoid1_of_SET1.
317
318 definition unary_morphism1_setoid1_of_arrows2_SET1: 
319   ∀P,Q.arrows2 SET1 P Q → unary_morphism1_setoid1 P Q ≝ λP,Q,x.x.
320 coercion unary_morphism1_setoid1_of_arrows2_SET1.
321  
322 variant objs2_of_category1: objs1 SET → objs2 SET1 ≝ setoid1_of_setoid.
323 coercion objs2_of_category1.
324
325 prefer coercion Type_OF_setoid. (* we prefer the lower carrier projection *)
326 prefer coercion Type_OF_objs1.
327
328 interpretation "unary morphism1" 'Imply a b = (arrows2 SET1 a b).