]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/formal_topology/overlap/o-algebra.ma
More re-organization.
[helm.git] / helm / software / matita / contribs / formal_topology / overlap / o-algebra.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 "categories.ma".
16 include "logic/cprop_connectives.ma". 
17
18 inductive bool : Type0 := true : bool | false : bool.
19
20 lemma BOOL : objs1 SET.
21 constructor 1; [apply bool] constructor 1;
22 [ intros (x y); apply (match x with [ true ⇒ match y with [ true ⇒ True | _ ⇒ False] | false ⇒ match y with [ true ⇒ False | false ⇒ True ]]);
23 | whd; simplify; intros; cases x; apply I;
24 | whd; simplify; intros 2; cases x; cases y; simplify; intros; assumption;
25 | whd; simplify; intros 3; cases x; cases y; cases z; simplify; intros; 
26   try assumption; apply I]
27 qed.
28
29 lemma IF_THEN_ELSE_p :
30   ∀S:setoid1.∀a,b:S.∀x,y:BOOL.x = y → 
31     (λm.match m with [ true ⇒ a | false ⇒ b ]) x =
32     (λm.match m with [ true ⇒ a | false ⇒ b ]) y.
33 whd in ⊢ (?→?→?→%→?);
34 intros; cases x in e; cases y; simplify; intros; try apply refl1; whd in e; cases e;
35 qed.
36
37 interpretation "unary morphism comprehension with no proof" 'comprehension T P = 
38   (mk_unary_morphism T _ P _).
39 interpretation "unary morphism1 comprehension with no proof" 'comprehension T P = 
40   (mk_unary_morphism1 T _ P _).
41
42 notation > "hvbox({ ident i ∈ s | term 19 p | by })" with precedence 90
43 for @{ 'comprehension_by $s (λ${ident i}. $p) $by}.
44 notation < "hvbox({ ident i ∈ s | term 19 p })" with precedence 90
45 for @{ 'comprehension_by $s (λ${ident i}:$_. $p) $by}.
46
47 interpretation "unary morphism comprehension with proof" 'comprehension_by s \eta.f p = 
48   (mk_unary_morphism s _ f p).
49 interpretation "unary morphism1 comprehension with proof" 'comprehension_by s \eta.f p = 
50   (mk_unary_morphism1 s _ f p).
51
52 (* per il set-indexing vedere capitolo BPTools (foundational tools), Sect. 0.3.4 complete
53    lattices, Definizione 0.9 *)
54 (* USARE L'ESISTENZIALE DEBOLE *)
55 (*alias symbol "comprehension_by" = "unary morphism comprehension with proof".*)
56 record OAlgebra : Type2 := {
57   oa_P :> SET1;
58   oa_leq : binary_morphism1 oa_P oa_P CPROP; (* CPROP is setoid1, CPROP importante che sia small *)
59   oa_overlap: binary_morphism1 oa_P oa_P CPROP;
60   oa_meet: ∀I:SET.unary_morphism2 (arrows2 SET1 I oa_P) oa_P;
61   oa_join: ∀I:SET.unary_morphism2 (arrows2 SET1 I oa_P) oa_P;
62   oa_one: oa_P;
63   oa_zero: oa_P;
64   oa_leq_refl: ∀a:oa_P. oa_leq a a; 
65   oa_leq_antisym: ∀a,b:oa_P.oa_leq a b → oa_leq b a → a = b;
66   oa_leq_trans: ∀a,b,c:oa_P.oa_leq a b → oa_leq b c → oa_leq a c;
67   oa_overlap_sym: ∀a,b:oa_P.oa_overlap a b → oa_overlap b a;
68   (* Errore: = in oa_meet_inf e oa_join_sup *)
69   oa_meet_inf: ∀I.∀p_i.∀p:oa_P.oa_leq p (oa_meet I p_i) → ∀i:I.oa_leq p (p_i i);
70   oa_join_sup: ∀I.∀p_i.∀p:oa_P.oa_leq (oa_join I p_i) p → ∀i:I.oa_leq (p_i i) p;
71   oa_zero_bot: ∀p:oa_P.oa_leq oa_zero p;
72   oa_one_top: ∀p:oa_P.oa_leq p oa_one;
73   oa_overlap_preserves_meet_: 
74       ∀p,q:oa_P.oa_overlap p q → oa_overlap p 
75        (oa_meet ? { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p oa_P p q });
76   (* ⇔ deve essere =, l'esiste debole *)
77   oa_join_split:
78       ∀I:SET.∀p.∀q:arrows2 SET1 I oa_P.
79        oa_overlap p (oa_join I q) ⇔ ∃i:I.oa_overlap p (q i);
80   (*oa_base : setoid;
81   1) enum non e' il nome giusto perche' non e' suriettiva
82   2) manca (vedere altro capitolo) la "suriettivita'" come immagine di insiemi di oa_base
83   oa_enum : ums oa_base oa_P;
84   oa_density: ∀p,q.(∀i.oa_overlap p (oa_enum i) → oa_overlap q (oa_enum i)) → oa_leq p q
85   *)
86   oa_density: 
87       ∀p,q.(∀r.oa_overlap p r → oa_overlap q r) → oa_leq p q
88 }.
89
90 interpretation "o-algebra leq" 'leq a b = (fun21 ___ (oa_leq _) a b).
91
92 notation "hovbox(a mpadded width -150% (>)< b)" non associative with precedence 45
93 for @{ 'overlap $a $b}.
94 interpretation "o-algebra overlap" 'overlap a b = (fun21 ___ (oa_overlap _) a b).
95
96 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (\emsp) \nbsp term 90 p)" 
97 non associative with precedence 50 for @{ 'oa_meet $p }.
98 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (ident i ∈  I) break term 90 p)" 
99 non associative with precedence 50 for @{ 'oa_meet_mk (λ${ident i}:$I.$p) }.
100
101 (*
102 notation < "hovbox(a ∧ b)" left associative with precedence 35
103 for @{ 'oa_meet_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
104 *)
105 notation > "hovbox(∧ f)" non associative with precedence 60
106 for @{ 'oa_meet $f }.
107 (*
108 notation > "hovbox(a ∧ b)" left associative with precedence 50
109 for @{ 'oa_meet (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
110 *)
111 interpretation "o-algebra meet" 'oa_meet f = 
112   (fun12 __ (oa_meet __) f).
113 interpretation "o-algebra meet with explicit function" 'oa_meet_mk f = 
114   (fun12 __ (oa_meet __) (mk_unary_morphism _ _ f _)).
115
116 definition hint3: OAlgebra → setoid1.
117  intro; apply (oa_P o);
118 qed.
119 coercion hint3.
120
121 definition hint4: ∀A. setoid2_OF_OAlgebra A → hint3 A.
122  intros; apply t;
123 qed.
124 coercion hint4.
125
126 definition binary_meet : ∀O:OAlgebra. binary_morphism1 O O O.
127 intros; split;
128 [ intros (p q); 
129   apply (∧ { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p ? p q });
130 | intros; lapply (prop12 ? O (oa_meet O BOOL));
131    [2: apply ({ x ∈ BOOL | match x with [ true ⇒ a | false ⇒ b ] | IF_THEN_ELSE_p ? a b });
132    |3: apply ({ x ∈ BOOL | match x with [ true ⇒ a' | false ⇒ b' ] | IF_THEN_ELSE_p ? a' b' });
133    | apply Hletin;]
134   intro x; simplify; cases x; simplify; assumption;]
135 qed.
136
137 notation "hovbox(a ∧ b)" left associative with precedence 35
138 for @{ 'oa_meet_bin $a $b }.
139 interpretation "o-algebra binary meet" 'oa_meet_bin a b = 
140   (fun21 ___ (binary_meet _) a b).
141
142 coercion Type1_OF_OAlgebra nocomposites.
143
144 lemma oa_overlap_preservers_meet: ∀O:OAlgebra.∀p,q:O.p >< q → p >< (p ∧ q).
145 (* next change to avoid universe inconsistency *)
146 change in ⊢ (?→%→%→?) with (Type1_OF_OAlgebra O);
147 intros;  lapply (oa_overlap_preserves_meet_ O p q f);
148 lapply (prop21 O O CPROP (oa_overlap O) p p ? (p ∧ q) # ?);
149 [3: apply (if ?? (Hletin1)); apply Hletin;|skip] apply refl1;
150 qed.
151
152 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (\emsp) \nbsp term 90 p)" 
153 non associative with precedence 49 for @{ 'oa_join $p }.
154 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (ident i ∈  I) break term 90 p)" 
155 non associative with precedence 49 for @{ 'oa_join_mk (λ${ident i}:$I.$p) }.
156 notation < "hovbox(a ∨ b)" left associative with precedence 49
157 for @{ 'oa_join_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
158
159 notation > "hovbox(∨ f)" non associative with precedence 59
160 for @{ 'oa_join $f }.
161 notation > "hovbox(a ∨ b)" left associative with precedence 49
162 for @{ 'oa_join (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
163
164 interpretation "o-algebra join" 'oa_join f = 
165   (fun12 __ (oa_join __) f).
166 interpretation "o-algebra join with explicit function" 'oa_join_mk f = 
167   (fun12 __ (oa_join __) (mk_unary_morphism _ _ f _)).
168
169 definition hint5: OAlgebra → objs2 SET1.
170  intro; apply (oa_P o);
171 qed.
172 coercion hint5.
173
174 record ORelation (P,Q : OAlgebra) : Type ≝ {
175   or_f_ : P ⇒ Q;
176   or_f_minus_star_ : P ⇒ Q;
177   or_f_star_ : Q ⇒ P;
178   or_f_minus_ : Q ⇒ P;
179   or_prop1_ : ∀p,q. (or_f_ p ≤ q) = (p ≤ or_f_star_ q);
180   or_prop2_ : ∀p,q. (or_f_minus_ p ≤ q) = (p ≤ or_f_minus_star_ q);
181   or_prop3_ : ∀p,q. (or_f_ p >< q) = (p >< or_f_minus_ q)
182 }.
183
184 definition ORelation_setoid : OAlgebra → OAlgebra → setoid2.
185 intros (P Q);
186 constructor 1;
187 [ apply (ORelation P Q);
188 | constructor 1;
189    (* tenere solo una uguaglianza e usare la proposizione 9.9 per
190       le altre (unicita' degli aggiunti e del simmetrico) *)
191    [ apply (λp,q. And4 (eq2 ? (or_f_minus_star_ ?? p) (or_f_minus_star_ ?? q)) 
192              (eq2 ? (or_f_minus_ ?? p) (or_f_minus_ ?? q)) 
193              (eq2 ? (or_f_ ?? p) (or_f_ ?? q)) 
194              (eq2 ? (or_f_star_ ?? p) (or_f_star_ ?? q))); 
195    | whd; simplify; intros; repeat split; intros; apply refl2;
196    | whd; simplify; intros; cases H; clear H; split; 
197      intro a; apply sym1; generalize in match a;assumption;
198    | whd; simplify; intros; cases H; cases H1; clear H H1; split; intro a;
199      [ apply (.= (e a)); apply e4;
200      | apply (.= (e1 a)); apply e5;
201      | apply (.= (e2 a)); apply e6;
202      | apply (.= (e3 a)); apply e7;]]]
203 qed.
204
205 definition or_f_minus_star:
206  ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (P ⇒ Q).
207  intros; constructor 1;
208   [ apply or_f_minus_star_;
209   | intros; cases e; assumption]
210 qed.
211
212 definition or_f: ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (P ⇒ Q).
213  intros; constructor 1;
214   [ apply or_f_;
215   | intros; cases e; assumption]
216 qed.
217
218 coercion or_f.
219
220 definition or_f_minus: ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (Q ⇒ P).
221  intros; constructor 1;
222   [ apply or_f_minus_;
223   | intros; cases e; assumption]
224 qed.
225
226 definition or_f_star: ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (Q ⇒ P).
227  intros; constructor 1;
228   [ apply or_f_star_;
229   | intros; cases e; assumption]
230 qed.
231
232 lemma arrows1_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → (P ⇒ Q).
233 intros; apply (or_f ?? t);
234 qed.
235
236 coercion arrows1_OF_ORelation_setoid.
237
238 lemma umorphism_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → unary_morphism1 P Q.
239 intros; apply (or_f ?? t);
240 qed.
241
242 coercion umorphism_OF_ORelation_setoid.
243
244 lemma umorphism_setoid_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → unary_morphism1_setoid1 P Q.
245 intros; apply (or_f ?? t);
246 qed.
247
248 coercion umorphism_setoid_OF_ORelation_setoid.
249
250 lemma uncurry_arrows : ∀B,C. ORelation_setoid B C → B → C. 
251 intros; apply ((fun11 ?? t) t1);
252 qed.
253
254 coercion uncurry_arrows 1.
255
256 lemma hint6: ∀P,Q. Type_OF_setoid2 (hint5 P ⇒ hint5 Q) → unary_morphism1 P Q.
257  intros; apply t;
258 qed.
259 coercion hint6.
260
261 notation "r \sup *" non associative with precedence 90 for @{'OR_f_star $r}.
262 notation > "r *" non associative with precedence 90 for @{'OR_f_star $r}.
263
264 notation "r \sup (⎻* )" non associative with precedence 90 for @{'OR_f_minus_star $r}.
265 notation > "r⎻*" non associative with precedence 90 for @{'OR_f_minus_star $r}.
266
267 notation "r \sup ⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
268 notation > "r⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
269
270 interpretation "o-relation f⎻*" 'OR_f_minus_star r = (fun12 __ (or_f_minus_star _ _) r).
271 interpretation "o-relation f⎻" 'OR_f_minus r = (fun12 __ (or_f_minus _ _) r).
272 interpretation "o-relation f*" 'OR_f_star r = (fun12 __ (or_f_star _ _) r).
273
274 definition or_prop1 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
275    (F p ≤ q) = (p ≤ F* q).
276 intros; apply (or_prop1_ ?? F p q);
277 qed.
278
279 definition or_prop2 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
280    (F⎻ p ≤ q) = (p ≤ F⎻* q).
281 intros; apply (or_prop2_ ?? F p q);
282 qed.
283
284 definition or_prop3 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
285    (F p >< q) = (p >< F⎻ q).
286 intros; apply (or_prop3_ ?? F p q);
287 qed.
288
289 definition ORelation_composition : ∀P,Q,R. 
290   binary_morphism2 (ORelation_setoid P Q) (ORelation_setoid Q R) (ORelation_setoid P R).
291 intros;
292 constructor 1;
293 [ intros (F G);
294   constructor 1;
295   [ apply (G ∘ F);
296   | apply rule (G⎻* ∘ F⎻* );
297   | apply (F* ∘ G* );
298   | apply (F⎻ ∘ G⎻);
299   | intros; 
300     change with ((G (F p) ≤ q) = (p ≤ (F* (G* q))));
301     apply (.= (or_prop1 :?));
302     apply (or_prop1 :?);
303   | intros;
304     change with ((F⎻ (G⎻ p) ≤ q) = (p ≤ (G⎻* (F⎻* q))));
305     apply (.= (or_prop2 :?));
306     apply or_prop2 ; 
307   | intros; change with ((G (F (p)) >< q) = (p >< (F⎻ (G⎻ q))));
308     apply (.= (or_prop3 :?));
309     apply or_prop3;
310   ]
311 | intros; split; simplify; 
312    [1,3: unfold umorphism_setoid_OF_ORelation_setoid; unfold arrows1_OF_ORelation_setoid; apply ((†e)‡(†e1));
313    |2,4: apply ((†e1)‡(†e));]]
314 qed.
315
316 definition OA : category2.
317 split;
318 [ apply (OAlgebra);
319 | intros; apply (ORelation_setoid o o1);
320 | intro O; split;
321   [1,2,3,4: apply id2;
322   |5,6,7:intros; apply refl1;] 
323 | apply ORelation_composition;
324 | intros (P Q R S F G H); split;
325    [ change with (H⎻* ∘ G⎻* ∘ F⎻* = H⎻* ∘ (G⎻* ∘ F⎻* ));
326      apply (comp_assoc2 ????? (F⎻* ) (G⎻* ) (H⎻* ));
327    | apply ((comp_assoc2 ????? (H⎻) (G⎻) (F⎻))^-1);
328    | apply ((comp_assoc2 ????? F G H)^-1);
329    | apply ((comp_assoc2 ????? H* G* F* ));]
330 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_left2;
331 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_right2;]
332 qed.
333
334 lemma setoid1_of_OA: OA → setoid1.
335  intro; apply (oa_P t);
336 qed.
337 coercion setoid1_of_OA.
338
339 lemma SET1_of_OA: OA → SET1.
340  intro; whd; apply (setoid1_of_OA t);
341 qed.
342 coercion SET1_of_OA.
343
344 lemma objs2_SET1_OF_OA: OA → objs2 SET1.
345  intro; whd; apply (setoid1_of_OA t);
346 qed.
347 coercion objs2_SET1_OF_OA.
348
349 lemma Type_OF_category2_OF_SET1_OF_OA: OA → Type_OF_category2 SET1.
350  intro; apply (oa_P t);
351 qed.
352 coercion Type_OF_category2_OF_SET1_OF_OA.