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