]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/formal_topology/relations.ma
1503fa5dec6996670e1d5ec0fcbf6de0fbde1849
[helm.git] / helm / software / matita / library / 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 "formal_topology/subsets.ma".
16
17 record binary_relation (A,B: SET) : Type1 ≝
18  { satisfy:> binary_morphism1 A B CPROP }.
19
20 notation < "hvbox (x \nbsp \natur term 90 r \nbsp y)"  with precedence 45 for @{'satisfy $r $x $y}.
21 notation > "hvbox (x \natur term 90 r y)"  with precedence 45 for @{'satisfy $r $x $y}.
22 interpretation "relation applied" 'satisfy r x y = (fun21 ??? (satisfy ?? r) x y).
23
24 definition binary_relation_setoid: SET → SET → setoid1.
25  intros (A B);
26  constructor 1;
27   [ apply (binary_relation A B)
28   | constructor 1;
29      [ apply (λA,B.λr,r': binary_relation A B. ∀x,y. r x y ↔ r' x y)
30      | simplify; intros 3; split; intro; assumption
31      | simplify; intros 5; split; intro;
32        [ apply (fi ?? (f ??)) | apply (if ?? (f ??))] assumption
33      | simplify;  intros 7; split; intro;
34         [ apply (if ?? (f1 ??)) | apply (fi ?? (f ??)) ]
35         [ apply (if ?? (f ??)) | apply (fi ?? (f1 ??)) ]
36        assumption]]
37 qed.
38
39 definition binary_relation_of_binary_relation_setoid : 
40   ∀A,B.binary_relation_setoid A B → binary_relation A B ≝ λA,B,c.c.
41 coercion binary_relation_of_binary_relation_setoid.
42
43 definition composition:
44  ∀A,B,C.
45   (binary_relation_setoid A B) × (binary_relation_setoid B C) ⇒_1 (binary_relation_setoid A C).
46  intros;
47  constructor 1;
48   [ intros (R12 R23);
49     constructor 1;
50     constructor 1;
51      [ apply (λs1:A.λs3:C.∃s2:B. s1 ♮R12 s2 ∧ s2 ♮R23 s3);
52      | intros;
53        split; intro; cases e2 (w H3); clear e2; exists; [1,3: apply w ]
54         [ apply (. (e^-1‡#)‡(#‡e1^-1)); assumption
55         | apply (. (e‡#)‡(#‡e1)); assumption]]
56   | intros 8; split; intro H2; simplify in H2 ⊢ %;
57     cases H2 (w H3); clear H2; exists [1,3: apply w] cases H3 (H2 H4); clear H3;
58     [ lapply (if ?? (e x w) H2) | lapply (fi ?? (e x w) H2) ]
59     [ lapply (if ?? (e1 w y) H4)| lapply (fi ?? (e1 w y) H4) ]
60     exists; try assumption;
61     split; assumption]
62 qed.
63
64 definition REL: category1.
65  constructor 1;
66   [ apply setoid
67   | intros (T T1); apply (binary_relation_setoid T T1)
68   | intros; constructor 1;
69     constructor 1; unfold setoid1_of_setoid; simplify;
70      [ (* changes required to avoid universe inconsistency *)
71        change with (carr o → carr o → CProp); intros; apply (eq ? c c1)
72      | intros; split; intro; change in a a' b b' with (carr o);
73        change in e with (eq ? a a'); change in e1 with (eq ? b b');
74         [ apply (.= (e ^ -1));
75           apply (.= e2);
76           apply e1
77         | apply (.= e);
78           apply (.= e2);
79           apply (e1 ^ -1)]]
80   | apply composition
81   | intros 9;
82     split; intro;
83     cases f (w H); clear f; cases H; clear H;
84     [cases f (w1 H); clear f | cases f1 (w1 H); clear f1]
85     cases H; clear H;
86     exists; try assumption;
87     split; try assumption;
88     exists; try assumption;
89     split; assumption
90   |6,7: intros 5; unfold composition; simplify; split; intro;
91         unfold setoid1_of_setoid in x y; simplify in x y;
92         [1,3: cases e (w H1); clear e; cases H1; clear H1; unfold;
93           [ apply (. (e : eq1 ? x w)‡#); assumption
94           | apply (. #‡(e : eq1 ? w y)^-1); assumption]
95         |2,4: exists; try assumption; split;
96           (* change required to avoid universe inconsistency *)
97           change in x with (carr o1); change in y with (carr o2);
98           first [apply refl | assumption]]]
99 qed.
100
101 definition setoid_of_REL : objs1 REL → setoid ≝ λx.x.
102 coercion setoid_of_REL.
103
104 definition binary_relation_setoid_of_arrow1_REL : 
105   ∀P,Q. arrows1 REL P Q → binary_relation_setoid P Q ≝ λP,Q,x.x.
106 coercion binary_relation_setoid_of_arrow1_REL.
107
108
109 notation > "B ⇒_\r1 C" right associative with precedence 72 for @{'arrows1_REL $B $C}.
110 notation "B ⇒\sub (\r 1) C" right associative with precedence 72 for @{'arrows1_REL $B $C}.
111 interpretation "'arrows1_REL" 'arrows1_REL A B = (arrows1 REL A B).
112 notation > "B ⇒_\r2 C" right associative with precedence 72 for @{'arrows2_REL $B $C}.
113 notation "B ⇒\sub (\r 2) C" right associative with precedence 72 for @{'arrows2_REL $B $C}.
114 interpretation "'arrows2_REL" 'arrows2_REL A B = (arrows2 (category2_of_category1 REL) A B).
115
116
117 definition full_subset: ∀s:REL. Ω^s.
118  apply (λs.{x | True});
119  intros; simplify; split; intro; assumption.
120 qed.
121
122 coercion full_subset.
123
124 definition comprehension: ∀b:REL. (b ⇒_1. CPROP) → Ω^b.
125  apply (λb:REL. λP: b ⇒_1 CPROP. {x | P x});
126  intros; simplify;
127  apply (.= †e); apply refl1.
128 qed.
129
130 interpretation "subset comprehension" 'comprehension s p =
131  (comprehension s (mk_unary_morphism1 ?? p ?)).
132
133 definition ext: ∀X,S:REL. (X ⇒_\r1 S) × S ⇒_1 (Ω^X).
134  intros (X S); constructor 1; 
135   [ apply (λr:X ⇒_\r1 S.λf:S.{x ∈ X | x ♮r f}); intros; simplify; apply (.= (e‡#)); apply refl1
136   | intros; simplify; split; intros; simplify;
137      [ change with (∀x. x ♮a b → x ♮a' b'); intros;
138        apply (. (#‡e1^-1)); whd in e; apply (if ?? (e ??)); assumption
139      | change with (∀x. x ♮a' b' → x ♮a b); intros;
140        apply (. (#‡e1)); whd in e; apply (fi ?? (e ??));assumption]]
141 qed.
142
143 (*
144 definition extS: ∀X,S:REL. ∀r: arrows1 ? X S. Ω \sup S ⇒ Ω \sup 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 (. (H‡#)); assumption
151        |3: apply (. (H\sup -1‡#)); assumption
152        |2,4: cases H2 (w H3); exists; [1,3: apply w]
153          [ apply (. (#‡(H‡#))); assumption
154          | apply (. (#‡(H \sup -1‡#))); assumption]]]
155   | intros; split; simplify; intros; cases f; cases H1; split;
156      [1,3: assumption
157      |2,4: exists; [1,3: apply w]
158       [ apply (. (#‡H)‡#); assumption
159       | apply (. (#‡H\sup -1)‡#); 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 interpretation "relation f⎻*" 'OR_f_minus_star r = (fun12 ?? (minus_star_image ? ?) r).
255 interpretation "relation f⎻" 'OR_f_minus r = (fun12 ?? (minus_image ? ?) r).
256 interpretation "relation f*" 'OR_f_star r = (fun12 ?? (star_image ? ?) r).
257
258 definition image_coercion: ∀U,V:REL. (U ⇒_\r1 V) → Ω^U ⇒_2 Ω^V.
259 intros (U V r Us); apply (image U V r); qed.
260 coercion image_coercion.
261
262 (* minus_image is the same as ext *)
263
264 theorem image_id: ∀o. (id1 REL o : carr2 (Ω^o ⇒_2 Ω^o)) =_1 (id2 SET1 Ω^o).
265  intros; unfold image_coercion; unfold image; simplify;
266  whd in match (?:carr2 ?);
267   intro U; simplify; split; simplify; intros;
268   [ change with (a ∈ U);
269     cases e; cases x; change in e1 with (w =_1 a); apply (. e1^-1‡#); assumption
270   | change in f with (a ∈ U);
271     exists; [apply a] split; [ change with (a = a); apply refl1 | assumption]]
272 qed.
273
274 theorem minus_star_image_id: ∀o:REL. (fun12 ?? (minus_star_image o o) (id1 REL o) : carr2 (Ω^o ⇒_2 Ω^o)) =_1 (id2 SET1 Ω^o).
275  intros; unfold minus_star_image; simplify; intro U; simplify; 
276  split; simplify; intros;
277   [ change with (a ∈ U); apply f; change with (a=a); apply refl1
278   | change in f1 with (eq1 ? x a); apply (. f1‡#); apply f]
279 qed.
280
281 alias symbol "compose" (instance 5) = "category2 composition".
282 alias symbol "compose" (instance 4) = "category1 composition".
283 theorem image_comp: ∀A,B,C.∀r:B ⇒_\r1 C.∀s:A ⇒_\r1 B. 
284   ((r ∘ s) : carr2 (Ω^A ⇒_2 Ω^C)) =_1 r ∘ s.
285  intros; intro U; split; intro x; (unfold image; unfold SET1; simplify);
286  intro H; cases H; 
287  cases x1; [cases f|cases f1]; exists; [1,3: apply w1] cases x2; split; try assumption;
288    exists; try assumption; split; assumption;
289 qed.
290
291 theorem minus_star_image_comp:
292  ∀A,B,C.∀r:B ⇒_\r1 C.∀s:A ⇒_\r1 B.
293   minus_star_image A C (r ∘ s) =_1 minus_star_image B C r ∘ (minus_star_image A B s).
294  intros; unfold minus_star_image; intro X; simplify; split; simplify; intros;
295  [ whd; intros; simplify; whd; intros; apply f; exists; try assumption; split; assumption;
296  | cases f1; cases x1; apply f; assumption]
297 qed.
298
299 (*
300 (*CSC: unused! *)
301 theorem ext_comp:
302  ∀o1,o2,o3: REL.
303   ∀a: arrows1 ? o1 o2.
304    ∀b: arrows1 ? o2 o3.
305     ∀x. ext ?? (b∘a) x = extS ?? a (ext ?? b x).
306  intros;
307  unfold ext; unfold extS; simplify; split; intro; simplify; intros;
308  cases f; clear f; split; try assumption;
309   [ cases f2; clear f2; cases x1; clear x1; exists; [apply w] split;
310      [1: split] assumption;
311   | cases H; clear H; cases x1; clear x1; exists [apply w]; split;
312      [2: cases f] assumption]
313 qed.
314
315 theorem extS_singleton:
316  ∀o1,o2.∀a:arrows1 ? o1 o2.∀x.extS o1 o2 a (singleton o2 x) = ext o1 o2 a x.
317  intros; unfold extS; unfold ext; unfold singleton; simplify;
318  split; intros 2; simplify; cases f; split; try assumption;
319   [ cases H; cases x1; change in f2 with (eq1 ? x w); apply (. #‡f2 \sup -1);
320     assumption
321   | exists; try assumption; split; try assumption; change with (x = x); apply refl]
322 qed.
323 *)