]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/formal_topology/relations.ma
decentralizing core notation
[helm.git] / matita / matita / lib / formal_topology / relations.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 "basics/core_notation/comprehension_2.ma".
16 include "formal_topology/subsets.ma".
17 (*
18 record binary_relation (A,B: SET) : Type[1] ≝
19  { satisfy:> binary_morphism1 A B CPROP }.
20
21 notation < "hvbox (x \nbsp \natur term 90 r \nbsp y)"  with precedence 45 for @{'satisfy $r $x $y}.
22 notation > "hvbox (x \natur term 90 r y)"  with precedence 45 for @{'satisfy $r $x $y}.
23 interpretation "relation applied" 'satisfy r x y = (fun21 ??? (satisfy ?? r) x y).
24
25 definition binary_relation_setoid: SET → SET → setoid1.
26  intros (A B);
27  constructor 1;
28   [ apply (binary_relation A B)
29   | constructor 1;
30      [ apply (λA,B.λr,r': binary_relation A B. ∀x,y. r x y ↔ r' x y)
31      | simplify; intros 3; split; intro; assumption
32      | simplify; intros 5; split; intro;
33        [ apply (fi ?? (f ??)) | apply (if ?? (f ??))] assumption
34      | simplify;  intros 7; split; intro;
35         [ apply (if ?? (f1 ??)) | apply (fi ?? (f ??)) ]
36         [ apply (if ?? (f ??)) | apply (fi ?? (f1 ??)) ]
37        assumption]]
38 qed.
39
40 definition binary_relation_of_binary_relation_setoid : 
41   ∀A,B.binary_relation_setoid A B → binary_relation A B ≝ λA,B,c.c.
42 coercion binary_relation_of_binary_relation_setoid.
43
44 definition composition:
45  ∀A,B,C.
46   (binary_relation_setoid A B) × (binary_relation_setoid B C) ⇒_1 (binary_relation_setoid A C).
47  intros;
48  constructor 1;
49   [ intros (R12 R23);
50     constructor 1;
51     constructor 1;
52      [ apply (λs1:A.λs3:C.∃s2:B. s1 ♮R12 s2 ∧ s2 ♮R23 s3);
53      | intros;
54        split; intro; cases e2 (w H3); clear e2; exists; [1,3: apply w ]
55         [ apply (. (e^-1‡#)‡(#‡e1^-1)); assumption
56         | apply (. (e‡#)‡(#‡e1)); assumption]]
57   | intros 8; split; intro H2; simplify in H2 ⊢ %;
58     cases H2 (w H3); clear H2; exists [1,3: apply w] cases H3 (H2 H4); clear H3;
59     [ lapply (if ?? (e x w) H2) | lapply (fi ?? (e x w) H2) ]
60     [ lapply (if ?? (e1 w y) H4)| lapply (fi ?? (e1 w y) H4) ]
61     exists; try assumption;
62     split; assumption]
63 qed.
64
65 definition REL: category1.
66  constructor 1;
67   [ apply setoid
68   | intros (T T1); apply (binary_relation_setoid T T1)
69   | intros; constructor 1;
70     constructor 1; unfold setoid1_of_setoid; simplify;
71      [ (* changes required to avoid universe inconsistency *)
72        change with (carr o → carr o → CProp); intros; apply (eq ? c c1)
73      | intros; split; intro; change in a a' b b' with (carr o);
74        change in e with (eq ? a a'); change in e1 with (eq ? b b');
75         [ apply (.= (e ^ -1));
76           apply (.= e2);
77           apply e1
78         | apply (.= e);
79           apply (.= e2);
80           apply (e1 ^ -1)]]
81   | apply composition
82   | intros 9;
83     split; intro;
84     cases f (w H); clear f; cases H; clear H;
85     [cases f (w1 H); clear f | cases f1 (w1 H); clear f1]
86     cases H; clear H;
87     exists; try assumption;
88     split; try assumption;
89     exists; try assumption;
90     split; assumption
91   |6,7: intros 5; unfold composition; simplify; split; intro;
92         unfold setoid1_of_setoid in x y; simplify in x y;
93         [1,3: cases e (w H1); clear e; cases H1; clear H1; unfold;
94           [ apply (. (e : eq1 ? x w)‡#); assumption
95           | apply (. #‡(e : eq1 ? w y)^-1); assumption]
96         |2,4: exists; try assumption; split;
97           (* change required to avoid universe inconsistency *)
98           change in x with (carr o1); change in y with (carr o2);
99           first [apply refl | assumption]]]
100 qed.
101
102 definition setoid_of_REL : objs1 REL → setoid ≝ λx.x.
103 coercion setoid_of_REL.
104
105 definition binary_relation_setoid_of_arrow1_REL : 
106   ∀P,Q. arrows1 REL P Q → binary_relation_setoid P Q ≝ λP,Q,x.x.
107 coercion binary_relation_setoid_of_arrow1_REL.
108
109
110 notation > "B ⇒_\r1 C" right associative with precedence 72 for @{'arrows1_REL $B $C}.
111 notation "B ⇒\sub (\r 1) C" right associative with precedence 72 for @{'arrows1_REL $B $C}.
112 interpretation "'arrows1_REL" 'arrows1_REL A B = (arrows1 REL A B).
113 notation > "B ⇒_\r2 C" right associative with precedence 72 for @{'arrows2_REL $B $C}.
114 notation "B ⇒\sub (\r 2) C" right associative with precedence 72 for @{'arrows2_REL $B $C}.
115 interpretation "'arrows2_REL" 'arrows2_REL A B = (arrows2 (category2_of_category1 REL) A B).
116
117
118 definition full_subset: ∀s:REL. Ω^s.
119  apply (λs.{x | True});
120  intros; simplify; split; intro; assumption.
121 qed.
122
123 coercion full_subset.
124
125 definition comprehension: ∀b:REL. (b ⇒_1. CPROP) → Ω^b.
126  apply (λb:REL. λP: b ⇒_1 CPROP. {x | P x});
127  intros; simplify;
128  apply (.= †e); apply refl1.
129 qed.
130
131 interpretation "subset comprehension" 'comprehension s p =
132  (comprehension s (mk_unary_morphism1 ?? p ?)).
133
134 definition ext: ∀X,S:REL. (X ⇒_\r1 S) × S ⇒_1 (Ω^X).
135  intros (X S); constructor 1; 
136   [ apply (λr:X ⇒_\r1 S.λf:S.{x ∈ X | x ♮r f}); intros; simplify; apply (.= (e‡#)); apply refl1
137   | intros; simplify; split; intros; simplify;
138      [ change with (∀x. x ♮a b → x ♮a' b'); intros;
139        apply (. (#‡e1^-1)); whd in e; apply (if ?? (e ??)); assumption
140      | change with (∀x. x ♮a' b' → x ♮a b); intros;
141        apply (. (#‡e1)); whd in e; apply (fi ?? (e ??));assumption]]
142 qed.
143
144 definition extS: ∀X,S:REL. ∀r:X ⇒_\r1 S. Ω^S ⇒_1 Ω^X.
145  (* ∃ is not yet a morphism apply (λX,S,r,F.{x ∈ X | ∃a. a ∈ F ∧ x ♮r a});*)
146  intros (X S r); constructor 1;
147   [ intro F; constructor 1; constructor 1;
148     [ apply (λx. x ∈ X ∧ ∃a:S. a ∈ F ∧ x ♮r a);
149     | intros; split; intro; cases f (H1 H2); clear f; split;
150        [ apply (. (e^-1‡#)); assumption
151        |3: apply (. (e‡#)); assumption
152        |2,4: cases H2 (w H3); exists; [1,3: apply w]
153          [ apply (. (#‡(e^-1‡#))); assumption
154          | apply (. (#‡(e‡#))); assumption]]]
155   | intros; split; simplify; intros; cases f; cases e1; split;
156      [1,3: assumption
157      |2,4: exists; [1,3: apply w]
158       [ apply (. (#‡e^-1)‡#); assumption
159       | apply (. (#‡e)‡#); assumption]]]
160 qed.
161 (*
162 lemma equalset_extS_id_X_X: ∀o:REL.∀X.extS ?? (id1 ? o) X = X.
163  intros;
164  unfold extS; simplify;
165  split; simplify;
166   [ intros 2; change with (a ∈ X);
167     cases f; clear f;
168     cases H; clear H;
169     cases x; clear x;
170     change in f2 with (eq1 ? a w);
171     apply (. (f2\sup -1‡#));
172     assumption
173   | intros 2; change in f with (a ∈ X);
174     split;
175      [ whd; exact I 
176      | exists; [ apply a ]
177        split;
178         [ assumption
179         | change with (a = a); apply refl]]]
180 qed.
181
182 lemma extS_com: ∀o1,o2,o3,c1,c2,S. extS o1 o3 (c2 ∘ c1) S = extS o1 o2 c1 (extS o2 o3 c2 S).
183  intros; unfold extS; simplify; split; intros; simplify; intros;
184   [ cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption]
185     cases H3 (H4 H5); cases H5 (w1 H6); clear H3 H5; cases H6 (H7 H8); clear H6;
186     exists; [apply w1] split [2: assumption] constructor 1; [assumption]
187     exists; [apply w] split; assumption
188   | cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption]
189     cases H3 (H4 H5); cases H4 (w1 H6); clear H3 H4; cases H6 (w2 H7); clear H6;
190     cases H7; clear H7; exists; [apply w2] split; [assumption] exists [apply w] split;
191     assumption]
192 qed.
193 *)
194
195 (* the same as ⋄ for a basic pair *)
196 definition image: ∀U,V:REL. (U ⇒_\r1 V) ⇒_2 (Ω^U ⇒_2 Ω^V).
197  intros; constructor 1;
198  [ intro r; constructor 1;
199    [ apply (λS: Ω^U. {y | ∃x:U. x ♮r y ∧ x ∈ S });
200      intros; simplify; split; intro; cases e1; exists [1,3: apply w]
201      [ apply (. (#‡e^-1)‡#); assumption
202      | apply (. (#‡e)‡#); assumption]
203    | intros; split; 
204      [ intro y; simplify; intro yA; cases yA; exists; [ apply w ];
205        apply (. #‡(#‡e^-1)); assumption;
206      | intro y; simplify; intro yA; cases yA; exists; [ apply w ];
207        apply (. #‡(#‡e)); assumption;]]
208  | simplify; intros; intro y; simplify; split; simplify; intros (b H); cases H;
209    exists; [1,3: apply w]; cases x; split; try assumption;
210    [ apply (if ?? (e ??)); | apply (fi ?? (e ??)); ] assumption;]
211 qed.
212
213 (* the same as □ for a basic pair *)
214 definition minus_star_image: ∀U,V:REL. (U ⇒_\r1 V) ⇒_2 (Ω^U ⇒_2 Ω^V).
215  intros; constructor 1; intros;
216   [ constructor 1;
217     [ apply (λS: Ω^U. {y | ∀x:U. x ♮c y → x ∈ S});
218       intros; simplify; split; intros; apply f;
219       [ apply (. #‡e); | apply (. #‡e ^ -1)] assumption;
220     | intros; split; intro; simplify; intros;
221       [ apply (. #‡e^-1);| apply (. #‡e); ] apply f; assumption;]
222   | intros; intro; simplify; split; simplify; intros; apply f;
223     [ apply (. (e x a2)); assumption | apply (. (e^-1 x a2)); assumption]]
224 qed.
225
226 (* the same as Rest for a basic pair *)
227 definition star_image: ∀U,V:REL. (U ⇒_\r1 V) ⇒_2 (Ω^V ⇒_2 Ω^U).
228  intros; constructor 1;
229   [ intro r; constructor 1; 
230     [ apply (λS: Ω \sup V. {x | ∀y:V. x ♮r y → y ∈ S});
231       intros; simplify; split; intros; apply f;
232       [ apply (. e ‡#);| apply (. e^ -1‡#);] assumption;
233     | intros; split; simplify; intros;
234       [ apply (. #‡e^-1);| apply (. #‡e); ] apply f; assumption;]
235   | intros; intro; simplify; split; simplify; intros; apply f; 
236     [ apply (. e a2 y); | apply (. e^-1 a2 y)] assumption;]
237 qed.
238
239 (* the same as Ext for a basic pair *)
240 definition minus_image: ∀U,V:REL. (U ⇒_\r1 V) ⇒_2 (Ω^V ⇒_2 Ω^U).
241  intros; constructor 1;
242   [ intro r; constructor 1; 
243     [ apply (λS: Ω^V. {x | ∃y:V. x ♮r y ∧ y ∈ S }).
244       intros; simplify; split; intros; cases e1; cases x; exists; [1,3: apply w]
245       split; try assumption; [ apply (. (e^-1‡#)); | apply (. (e‡#));] assumption;
246     | intros; simplify; split; simplify; intros; cases e1; cases x; 
247       exists [1,3: apply w] split; try assumption;
248       [ apply (. (#‡e^-1)); | apply (. (#‡e));] assumption]
249   | intros; intro; simplify; split; simplify; intros; cases e1; exists [1,3: apply w]
250     cases x; split; try assumption;
251     [ apply (. e^-1 a2 w); | apply (. e a2 w)] assumption;]
252 qed.
253
254 definition foo : ∀o1,o2:REL.carr1 (o1 ⇒_\r1 o2) → carr2 (setoid2_of_setoid1 (o1 ⇒_\r1 o2)) ≝ λo1,o2,x.x.
255
256 interpretation "relation f⎻*" 'OR_f_minus_star r = (fun12 ?? (minus_star_image ? ?) (foo ?? r)).
257 interpretation "relation f⎻" 'OR_f_minus r = (fun12 ?? (minus_image ? ?) (foo ?? r)).
258 interpretation "relation f*" 'OR_f_star r = (fun12 ?? (star_image ? ?) (foo ?? r)).
259
260 definition image_coercion: ∀U,V:REL. (U ⇒_\r1 V) → Ω^U ⇒_2 Ω^V.
261 intros (U V r Us); apply (image U V r); qed.
262 coercion image_coercion.
263
264 (* minus_image is the same as ext *)
265
266 theorem image_id: ∀o. (id1 REL o : carr2 (Ω^o ⇒_2 Ω^o)) =_1 (id2 SET1 Ω^o).
267  intros; unfold image_coercion; unfold image; simplify;
268  whd in match (?:carr2 ?);
269   intro U; simplify; split; simplify; intros;
270   [ change with (a ∈ U);
271     cases e; cases x; change in e1 with (w =_1 a); apply (. e1^-1‡#); assumption
272   | change in f with (a ∈ U);
273     exists; [apply a] split; [ change with (a = a); apply refl1 | assumption]]
274 qed.
275
276 theorem minus_star_image_id: ∀o:REL. 
277   ((id1 REL o)⎻* : carr2 (Ω^o ⇒_2 Ω^o)) =_1 (id2 SET1 Ω^o).
278  intros; unfold minus_star_image; simplify; intro U; simplify; 
279  split; simplify; intros;
280   [ change with (a ∈ U); apply f; change with (a=a); apply refl1
281   | change in f1 with (eq1 ? x a); apply (. f1‡#); apply f]
282 qed.
283
284 alias symbol "compose" (instance 5) = "category2 composition".
285 alias symbol "compose" (instance 4) = "category1 composition".
286 theorem image_comp: ∀A,B,C.∀r:B ⇒_\r1 C.∀s:A ⇒_\r1 B. 
287   ((r ∘ s) : carr2 (Ω^A ⇒_2 Ω^C)) =_1 r ∘ s.
288  intros; intro U; split; intro x; (unfold image; unfold SET1; simplify);
289  intro H; cases H; 
290  cases x1; [cases f|cases f1]; exists; [1,3: apply w1] cases x2; split; try assumption;
291    exists; try assumption; split; assumption;
292 qed.
293
294 theorem minus_star_image_comp:
295  ∀A,B,C.∀r:B ⇒_\r1 C.∀s:A ⇒_\r1 B.
296   minus_star_image A C (r ∘ s) =_1 minus_star_image B C r ∘ (minus_star_image A B s).
297  intros; unfold minus_star_image; intro X; simplify; split; simplify; intros;
298  [ whd; intros; simplify; whd; intros; apply f; exists; try assumption; split; assumption;
299  | cases f1; cases x1; apply f; assumption]
300 qed.
301
302
303 (*
304 (*CSC: unused! *)
305 theorem ext_comp:
306  ∀o1,o2,o3: REL.
307   ∀a: arrows1 ? o1 o2.
308    ∀b: arrows1 ? o2 o3.
309     ∀x. ext ?? (b∘a) x = extS ?? a (ext ?? b x).
310  intros;
311  unfold ext; unfold extS; simplify; split; intro; simplify; intros;
312  cases f; clear f; split; try assumption;
313   [ cases f2; clear f2; cases x1; clear x1; exists; [apply w] split;
314      [1: split] assumption;
315   | cases H; clear H; cases x1; clear x1; exists [apply w]; split;
316      [2: cases f] assumption]
317 qed.
318 *)
319
320 axiom daemon : False.
321
322 theorem extS_singleton:
323  ∀o1,o2.∀a.∀x.extS o1 o2 a {(x)} = ext o1 o2 a x. 
324  intros; unfold extS; unfold ext; unfold singleton; simplify;
325  split; intros 2; simplify; simplify in f; 
326  [ cases f; cases e; cases x1; change in f2 with (x =_1 w); apply (. #‡f2); assumption;
327  | split; try apply I; exists [apply x] split; try assumption; change with (x = x); apply rule #;] qed.
328 *)