1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "basics/core_notation/comprehension_2.ma".
16 include "formal_topology/categories.ma".
18 inductive bool : Type[0] := true : bool | false : bool.
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]
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.
34 intros; cases x in e; cases y; simplify; intros; try apply refl1; whd in e; cases e;
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 ?).
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}.
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).
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 *)
56 definition if_then_else ≝ λT:Type.λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
57 notation > "'If' term 19 e 'then' term 19 t 'else' term 90 f" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
58 notation < "'If' \nbsp term 19 e \nbsp 'then' \nbsp term 19 t \nbsp 'else' \nbsp term 90 f \nbsp" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
59 interpretation "Formula if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
61 notation > "hvbox(a break ≤ b)" non associative with precedence 45 for @{oa_leq $a $b}.
62 notation > "a >< b" non associative with precedence 45 for @{oa_overlap $a $b}.
63 notation > "⋁ p" non associative with precedence 45 for @{oa_join ? $p}.
64 notation > "⋀ p" non associative with precedence 45 for @{oa_meet ? $p}.
65 notation > "𝟙" non associative with precedence 90 for @{oa_one}.
66 notation > "𝟘" non associative with precedence 90 for @{oa_zero}.
67 record OAlgebra : Type[2] := {
69 oa_leq : oa_P × oa_P ⇒_1 CPROP;
70 oa_overlap: oa_P × oa_P ⇒_1 CPROP;
71 oa_meet: ∀I:SET.(I ⇒_2 oa_P) ⇒_2. oa_P;
72 oa_join: ∀I:SET.(I ⇒_2 oa_P) ⇒_2. oa_P;
75 oa_leq_refl: ∀a:oa_P. a ≤ a;
76 oa_leq_antisym: ∀a,b:oa_P.a ≤ b → b ≤ a → a = b;
77 oa_leq_trans: ∀a,b,c:oa_P.a ≤ b → b ≤ c → a ≤ c;
78 oa_overlap_sym: ∀a,b:oa_P.a >< b → b >< a;
79 oa_meet_inf: ∀I:SET.∀p_i:I ⇒_2 oa_P.∀p:oa_P.p ≤ (⋀ p_i) = (∀i:I.p ≤ (p_i i));
80 oa_join_sup: ∀I:SET.∀p_i:I ⇒_2 oa_P.∀p:oa_P.(⋁ p_i) ≤ p = (∀i:I.p_i i ≤ p);
81 oa_zero_bot: ∀p:oa_P.𝟘 ≤ p;
82 oa_one_top: ∀p:oa_P.p ≤ 𝟙;
83 oa_overlap_preserves_meet_: ∀p,q:oa_P.p >< q →
84 p >< (⋀ { x ∈ BOOL | If x then p else q | IF_THEN_ELSE_p oa_P p q });
85 oa_join_split: ∀I:SET.∀p.∀q:I ⇒_2 oa_P.p >< (⋁ q) = (∃i:I.p >< (q i));
87 1) enum non e' il nome giusto perche' non e' suriettiva
88 2) manca (vedere altro capitolo) la "suriettivita'" come immagine di insiemi di oa_base
89 oa_enum : ums oa_base oa_P;
90 oa_density: ∀p,q.(∀i.oa_overlap p (oa_enum i) → oa_overlap q (oa_enum i)) → oa_leq p q
92 oa_density: ∀p,q.(∀r.p >< r → q >< r) → p ≤ q
95 notation "hvbox(a break ≤ b)" non associative with precedence 45 for @{ 'leq $a $b }.
97 interpretation "o-algebra leq" 'leq a b = (fun21 ??? (oa_leq ?) a b).
99 notation "hovbox(a mpadded width -150% (>)< b)" non associative with precedence 45
100 for @{ 'overlap $a $b}.
101 interpretation "o-algebra overlap" 'overlap a b = (fun21 ??? (oa_overlap ?) a b).
103 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (\emsp) \nbsp term 90 p)"
104 non associative with precedence 55 for @{ 'oa_meet $p }.
105 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (ident i ∈ I) break term 90 p)"
106 non associative with precedence 55 for @{ 'oa_meet_mk (λ${ident i}:$I.$p) }.
108 notation > "hovbox(∧ f)" non associative with precedence 65
109 for @{ 'oa_meet $f }.
110 interpretation "o-algebra meet" 'oa_meet f =
111 (fun12 ?? (oa_meet ??) f).
112 interpretation "o-algebra meet with explicit function" 'oa_meet_mk f =
113 (fun12 ?? (oa_meet ??) (mk_unary_morphism1 ?? f ?)).
115 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (\emsp) \nbsp term 90 p)"
116 non associative with precedence 55 for @{ 'oa_join $p }.
117 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (ident i ∈ I) break term 90 p)"
118 non associative with precedence 55 for @{ 'oa_join_mk (λ${ident i}:$I.$p) }.
120 notation > "hovbox(∨ f)" non associative with precedence 65
121 for @{ 'oa_join $f }.
122 interpretation "o-algebra join" 'oa_join f =
123 (fun12 ?? (oa_join ??) f).
124 interpretation "o-algebra join with explicit function" 'oa_join_mk f =
125 (fun12 ?? (oa_join ??) (mk_unary_morphism ?? f ?)).
127 definition binary_meet : ∀O:OAlgebra. O × O ⇒_1 O.
130 apply (∧ { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p ? p q });
131 | intros; lapply (prop12 ? O (oa_meet O BOOL));
132 [2: apply ({ x ∈ BOOL | match x with [ true ⇒ a | false ⇒ b ] | IF_THEN_ELSE_p ? a b });
133 |3: apply ({ x ∈ BOOL | match x with [ true ⇒ a' | false ⇒ b' ] | IF_THEN_ELSE_p ? a' b' });
135 intro x; simplify; cases x; simplify; assumption;]
138 interpretation "o-algebra binary meet" 'and a b =
139 (fun21 ??? (binary_meet ?) a b).
141 prefer coercion Type[1]_OF_OAlgebra.
143 definition binary_join : ∀O:OAlgebra. O × O ⇒_1 O.
146 apply (∨ { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p ? p q });
147 | intros; lapply (prop12 ? O (oa_join O BOOL));
148 [2: apply ({ x ∈ BOOL | match x with [ true ⇒ a | false ⇒ b ] | IF_THEN_ELSE_p ? a b });
149 |3: apply ({ x ∈ BOOL | match x with [ true ⇒ a' | false ⇒ b' ] | IF_THEN_ELSE_p ? a' b' });
151 intro x; simplify; cases x; simplify; assumption;]
154 interpretation "o-algebra binary join" 'or a b =
155 (fun21 ??? (binary_join ?) a b).
157 lemma oa_overlap_preservers_meet: ∀O:OAlgebra.∀p,q:O.p >< q → p >< (p ∧ q).
158 intros; lapply (oa_overlap_preserves_meet_ O p q f) as H; clear f;
159 (** screenshot "screenoa". *)
163 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (\emsp) \nbsp term 90 p)"
164 non associative with precedence 49 for @{ 'oa_join $p }.
165 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (ident i ∈ I) break term 90 p)"
166 non associative with precedence 49 for @{ 'oa_join_mk (λ${ident i}:$I.$p) }.
167 notation < "hovbox(a ∨ b)" left associative with precedence 49
168 for @{ 'oa_join_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
170 notation > "hovbox(∨ f)" non associative with precedence 64
171 for @{ 'oa_join $f }.
172 notation > "hovbox(a ∨ b)" left associative with precedence 49
173 for @{ 'oa_join (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
175 interpretation "o-algebra join" 'oa_join f =
176 (fun12 ?? (oa_join ??) f).
177 interpretation "o-algebra join with explicit function" 'oa_join_mk f =
178 (fun12 ?? (oa_join ??) (mk_unary_morphism ?? f ?)).
180 record ORelation (P,Q : OAlgebra) : Type[2] ≝ {
182 or_f_minus_star_ : P ⇒_2 Q;
183 or_f_star_ : Q ⇒_2 P;
184 or_f_minus_ : Q ⇒_2 P;
185 or_prop1_ : ∀p,q. (or_f_ p ≤ q) = (p ≤ or_f_star_ q);
186 or_prop2_ : ∀p,q. (or_f_minus_ p ≤ q) = (p ≤ or_f_minus_star_ q);
187 or_prop3_ : ∀p,q. (or_f_ p >< q) = (p >< or_f_minus_ q)
190 definition ORelation_setoid : OAlgebra → OAlgebra → setoid2.
193 [ apply (ORelation P Q);
195 (* tenere solo una uguaglianza e usare la proposizione 9.9 per
196 le altre (unicita' degli aggiunti e del simmetrico) *)
198 (or_f_minus_star_ ?? p = or_f_minus_star_ ?? q)
199 (or_f_minus_ ?? p = or_f_minus_ ?? q)
200 (or_f_ ?? p = or_f_ ?? q)
201 (or_f_star_ ?? p = or_f_star_ ?? q));
202 | whd; simplify; intros; repeat split; intros; apply refl2;
203 | whd; simplify; intros; cases a; clear a; split;
204 intro a; apply sym1; generalize in match a;assumption;
205 | whd; simplify; intros; cases a; cases a1; clear a a1; split; intro a;
206 [ apply (.= (e a)); apply e4;
207 | apply (.= (e1 a)); apply e5;
208 | apply (.= (e2 a)); apply e6;
209 | apply (.= (e3 a)); apply e7;]]]
212 definition ORelation_of_ORelation_setoid :
213 ∀P,Q.ORelation_setoid P Q → ORelation P Q ≝ λP,Q,x.x.
214 coercion ORelation_of_ORelation_setoid.
216 definition or_f_minus_star: ∀P,Q:OAlgebra.(ORelation_setoid P Q) ⇒_2 (P ⇒_2 Q).
217 intros; constructor 1;
218 [ apply or_f_minus_star_;
219 | intros; cases e; assumption]
222 definition or_f: ∀P,Q:OAlgebra.(ORelation_setoid P Q) ⇒_2 (P ⇒_2 Q).
223 intros; constructor 1;
225 | intros; cases e; assumption]
228 definition or_f_minus: ∀P,Q:OAlgebra.(ORelation_setoid P Q) ⇒_2 (Q ⇒_2 P).
229 intros; constructor 1;
231 | intros; cases e; assumption]
234 definition or_f_star: ∀P,Q:OAlgebra.(ORelation_setoid P Q) ⇒_2 (Q ⇒_2 P).
235 intros; constructor 1;
237 | intros; cases e; assumption]
240 lemma arrows1_of_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → (P ⇒_2 Q).
241 intros; apply (or_f ?? c);
243 coercion arrows1_of_ORelation_setoid.
245 interpretation "o-relation f⎻*" 'OR_f_minus_star r = (fun12 ?? (or_f_minus_star ? ?) r).
246 interpretation "o-relation f⎻" 'OR_f_minus r = (fun12 ?? (or_f_minus ? ?) r).
247 interpretation "o-relation f*" 'OR_f_star r = (fun12 ?? (or_f_star ? ?) r).
249 definition or_prop1 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
250 (F p ≤ q) =_1 (p ≤ F* q).
251 intros; apply (or_prop1_ ?? F p q);
254 definition or_prop2 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
255 (F⎻ p ≤ q) = (p ≤ F⎻* q).
256 intros; apply (or_prop2_ ?? F p q);
259 definition or_prop3 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
260 (F p >< q) = (p >< F⎻ q).
261 intros; apply (or_prop3_ ?? F p q);
264 definition ORelation_composition : ∀P,Q,R.
265 (ORelation_setoid P Q) × (ORelation_setoid Q R) ⇒_2 (ORelation_setoid P R).
271 | apply rule (G⎻* ∘ F⎻* );
275 change with ((G (F p) ≤ q) = (p ≤ (F* (G* q))));
276 apply (.= (or_prop1 :?));
279 change with ((F⎻ (G⎻ p) ≤ q) = (p ≤ (G⎻* (F⎻* q))));
280 apply (.= (or_prop2 :?));
282 | intros; change with ((G (F (p)) >< q) = (p >< (F⎻ (G⎻ q))));
283 apply (.= (or_prop3 :?));
286 | intros; split; simplify;
287 [3: unfold arrows1_of_ORelation_setoid; apply ((†e)‡(†e1));
288 |1: apply ((†e)‡(†e1));
289 |2,4: apply ((†e1)‡(†e));]]
292 definition OA : category2.
295 | intros; apply (ORelation_setoid o o1);
298 |5,6,7:intros; apply refl1;]
299 | apply ORelation_composition;
300 | intros (P Q R S F G H); split;
301 [ change with (H⎻* ∘ G⎻* ∘ F⎻* = H⎻* ∘ (G⎻* ∘ F⎻* ));
302 apply (comp_assoc2 ????? (F⎻* ) (G⎻* ) (H⎻* ));
303 | apply ((comp_assoc2 ????? (H⎻) (G⎻) (F⎻))^-1);
304 | apply ((comp_assoc2 ????? F G H)^-1);
305 | apply ((comp_assoc2 ????? H* G* F* ));]
306 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_left2;
307 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_right2;]
310 definition OAlgebra_of_objs2_OA: objs2 OA → OAlgebra ≝ λx.x.
311 coercion OAlgebra_of_objs2_OA.
313 definition ORelation_setoid_of_arrows2_OA:
314 ∀P,Q. arrows2 OA P Q → ORelation_setoid P Q ≝ λP,Q,c.c.
315 coercion ORelation_setoid_of_arrows2_OA.
317 prefer coercion Type_OF_objs2.
319 notation > "B ⇒_\o2 C" right associative with precedence 72 for @{'arrows2_OA $B $C}.
320 notation "B ⇒\sub (\o 2) C" right associative with precedence 72 for @{'arrows2_OA $B $C}.
321 interpretation "'arrows2_OA" 'arrows2_OA A B = (arrows2 OA A B).
323 (* qui la notazione non va *)
324 lemma leq_to_eq_join: ∀S:OA.∀p,q:S. p ≤ q → q = (binary_join ? p q).
326 apply oa_leq_antisym;
327 [ apply oa_density; intros;
328 apply oa_overlap_sym;
329 unfold binary_join; simplify;
330 apply (. (oa_join_split : ?));
331 exists; [ apply false ]
332 apply oa_overlap_sym;
334 | unfold binary_join; simplify;
335 apply (. (oa_join_sup : ?)); intro;
336 cases i; whd in ⊢ (? ? ? ? ? % ?);
337 [ assumption | apply oa_leq_refl ]]
340 lemma overlap_monotone_left: ∀S:OA.∀p,q,r:S. p ≤ q → p >< r → q >< r.
342 apply (. (leq_to_eq_join : ?)‡#);
345 | apply oa_overlap_sym;
346 unfold binary_join; simplify;
347 apply (. (oa_join_split : ?));
348 exists [ apply true ]
349 apply oa_overlap_sym;
353 (* Part of proposition 9.9 *)
354 lemma f_minus_image_monotone: ∀S,T.∀R:arrows2 OA S T.∀p,q. p ≤ q → R⎻ p ≤ R⎻ q.
356 apply (. (or_prop2 : ?));
357 apply oa_leq_trans; [2: apply f; | skip | apply (. (or_prop2 : ?)^ -1); apply oa_leq_refl;]
360 (* Part of proposition 9.9 *)
361 lemma f_minus_star_image_monotone: ∀S,T.∀R:arrows2 OA S T.∀p,q. p ≤ q → R⎻* p ≤ R⎻* q.
363 apply (. (or_prop2 : ?)^ -1);
364 apply oa_leq_trans; [3: apply f; | skip | apply (. (or_prop2 : ?)); apply oa_leq_refl;]
367 (* Part of proposition 9.9 *)
368 lemma f_image_monotone: ∀S,T.∀R:arrows2 OA S T.∀p,q. p ≤ q → R p ≤ R q.
370 apply (. (or_prop1 : ?));
371 apply oa_leq_trans; [2: apply f; | skip | apply (. (or_prop1 : ?)^ -1); apply oa_leq_refl;]
374 (* Part of proposition 9.9 *)
375 lemma f_star_image_monotone: ∀S,T.∀R:arrows2 OA S T.∀p,q. p ≤ q → R* p ≤ R* q.
377 apply (. (or_prop1 : ?)^ -1);
378 apply oa_leq_trans; [3: apply f; | skip | apply (. (or_prop1 : ?)); apply oa_leq_refl;]
381 lemma lemma_10_2_a: ∀S,T.∀R:arrows2 OA S T.∀p. p ≤ R⎻* (R⎻ p).
383 apply (. (or_prop2 : ?)^-1);
387 lemma lemma_10_2_b: ∀S,T.∀R:arrows2 OA S T.∀p. R⎻ (R⎻* p) ≤ p.
389 apply (. (or_prop2 : ?));
393 lemma lemma_10_2_c: ∀S,T.∀R:arrows2 OA S T.∀p. p ≤ R* (R p).
395 apply (. (or_prop1 : ?)^-1);
399 lemma lemma_10_2_d: ∀S,T.∀R:arrows2 OA S T.∀p. R (R* p) ≤ p.
401 apply (. (or_prop1 : ?));
405 lemma lemma_10_3_a: ∀S,T.∀R:arrows2 OA S T.∀p. R⎻ (R⎻* (R⎻ p)) = R⎻ p.
406 intros; apply oa_leq_antisym;
407 [ apply lemma_10_2_b;
408 | apply f_minus_image_monotone;
409 apply lemma_10_2_a; ]
412 lemma lemma_10_3_b: ∀S,T.∀R:arrows2 OA S T.∀p. R* (R (R* p)) = R* p.
413 intros; apply oa_leq_antisym;
414 [ apply f_star_image_monotone;
415 apply (lemma_10_2_d ?? R p);
416 | apply lemma_10_2_c; ]
419 lemma lemma_10_3_c: ∀S,T.∀R:arrows2 OA S T.∀p. R (R* (R p)) = R p.
420 intros; apply oa_leq_antisym;
421 [ apply lemma_10_2_d;
422 | apply f_image_monotone;
423 apply (lemma_10_2_c ?? R p); ]
426 lemma lemma_10_3_d: ∀S,T.∀R:arrows2 OA S T.∀p. R⎻* (R⎻ (R⎻* p)) = R⎻* p.
427 intros; apply oa_leq_antisym;
428 [ apply f_minus_star_image_monotone;
429 apply (lemma_10_2_b ?? R p);
430 | apply lemma_10_2_a; ]
433 lemma lemma_10_4_a: ∀S,T.∀R:arrows2 OA S T.∀p. R⎻* (R⎻ (R⎻* (R⎻ p))) = R⎻* (R⎻ p).
434 intros; apply (†(lemma_10_3_a ?? R p));
437 lemma lemma_10_4_b: ∀S,T.∀R:arrows2 OA S T.∀p. R (R* (R (R* p))) = R (R* p).
438 intros; unfold in ⊢ (? ? ? % %); apply (†(lemma_10_3_b ?? R p));
441 lemma oa_overlap_sym': ∀o:OA.∀U,V:o. (U >< V) = (V >< U).
442 intros; split; intro; apply oa_overlap_sym; assumption.