]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/formal_topology/overlap/o-algebra.ma
more composites to make all happy!
[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 definition carr' ≝ λx:Type_OF_category1 SET.Type_OF_Type0 (carr x).
52 coercion carr'. (* we prefer the lower carrier projection *)
53
54 (* per il set-indexing vedere capitolo BPTools (foundational tools), Sect. 0.3.4 complete
55    lattices, Definizione 0.9 *)
56 (* USARE L'ESISTENZIALE DEBOLE *)
57 (*alias symbol "comprehension_by" = "unary morphism comprehension with proof".*)
58 record OAlgebra : Type2 := {
59   oa_P :> SET1;
60   oa_leq : binary_morphism1 oa_P oa_P CPROP; (* CPROP is setoid1, CPROP importante che sia small *)
61   oa_overlap: binary_morphism1 oa_P oa_P CPROP;
62   oa_meet: ∀I:SET.unary_morphism2 (I ⇒ oa_P) oa_P;
63   oa_join: ∀I:SET.unary_morphism2 (I ⇒ oa_P) oa_P;
64   oa_one: oa_P;
65   oa_zero: oa_P;
66   oa_leq_refl: ∀a:oa_P. oa_leq a a; 
67   oa_leq_antisym: ∀a,b:oa_P.oa_leq a b → oa_leq b a → a = b;
68   oa_leq_trans: ∀a,b,c:oa_P.oa_leq a b → oa_leq b c → oa_leq a c;
69   oa_overlap_sym: ∀a,b:oa_P.oa_overlap a b → oa_overlap b a;
70   (* Errore: = in oa_meet_inf e oa_join_sup *)
71   oa_meet_inf: ∀I:SET.∀p_i:I ⇒ oa_P.∀p:oa_P.oa_leq p (oa_meet I p_i) = ∀i:I.oa_leq p (p_i i);
72   oa_join_sup: ∀I:SET.∀p_i:I ⇒ oa_P.∀p:oa_P.oa_leq (oa_join I p_i) p = ∀i:I.oa_leq (p_i i) p;
73   oa_zero_bot: ∀p:oa_P.oa_leq oa_zero p;
74   oa_one_top: ∀p:oa_P.oa_leq p oa_one;
75   oa_overlap_preserves_meet_: 
76       ∀p,q:oa_P.oa_overlap p q → oa_overlap p 
77        (oa_meet ? { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p oa_P p q });
78   (* ⇔ deve essere =, l'esiste debole *)
79   oa_join_split:
80       ∀I:SET.∀p.∀q:I ⇒ oa_P.
81        oa_overlap p (oa_join I q) = ∃i:I.oa_overlap p (q i);
82   (*oa_base : setoid;
83   1) enum non e' il nome giusto perche' non e' suriettiva
84   2) manca (vedere altro capitolo) la "suriettivita'" come immagine di insiemi di oa_base
85   oa_enum : ums oa_base oa_P;
86   oa_density: ∀p,q.(∀i.oa_overlap p (oa_enum i) → oa_overlap q (oa_enum i)) → oa_leq p q
87   *)
88   oa_density: 
89       ∀p,q.(∀r.oa_overlap p r → oa_overlap q r) → oa_leq p q
90 }.
91
92 interpretation "o-algebra leq" 'leq a b = (fun21 ___ (oa_leq _) a b).
93
94 notation "hovbox(a mpadded width -150% (>)< b)" non associative with precedence 45
95 for @{ 'overlap $a $b}.
96 interpretation "o-algebra overlap" 'overlap a b = (fun21 ___ (oa_overlap _) a b).
97
98 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (\emsp) \nbsp term 90 p)" 
99 non associative with precedence 50 for @{ 'oa_meet $p }.
100 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (ident i ∈  I) break term 90 p)" 
101 non associative with precedence 50 for @{ 'oa_meet_mk (λ${ident i}:$I.$p) }.
102
103 (*
104 notation < "hovbox(a ∧ b)" left associative with precedence 35
105 for @{ 'oa_meet_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
106 *)
107 notation > "hovbox(∧ f)" non associative with precedence 60
108 for @{ 'oa_meet $f }.
109 (*
110 notation > "hovbox(a ∧ b)" left associative with precedence 50
111 for @{ 'oa_meet (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
112 *)
113 interpretation "o-algebra meet" 'oa_meet f = 
114   (fun12 __ (oa_meet __) f).
115 interpretation "o-algebra meet with explicit function" 'oa_meet_mk f = 
116   (fun12 __ (oa_meet __) (mk_unary_morphism _ _ f _)).
117
118 definition hint3: OAlgebra → setoid1.
119  intro; apply (oa_P o);
120 qed.
121 coercion hint3.
122
123 definition hint4: ∀A. setoid2_OF_OAlgebra A → hint3 A.
124  intros; apply t;
125 qed.
126 coercion hint4.
127
128 definition binary_meet : ∀O:OAlgebra. binary_morphism1 O O O.
129 intros; split;
130 [ intros (p q); 
131   apply (∧ { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p ? p q });
132 | intros; lapply (prop12 ? O (oa_meet O BOOL));
133    [2: apply ({ x ∈ BOOL | match x with [ true ⇒ a | false ⇒ b ] | IF_THEN_ELSE_p ? a b });
134    |3: apply ({ x ∈ BOOL | match x with [ true ⇒ a' | false ⇒ b' ] | IF_THEN_ELSE_p ? a' b' });
135    | apply Hletin;]
136   intro x; simplify; cases x; simplify; assumption;]
137 qed.
138
139 interpretation "o-algebra binary meet" 'and 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) : Type2 ≝ {
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. And42 (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 a; clear a; split; 
197      intro a; apply sym1; generalize in match a;assumption;
198    | whd; simplify; intros; cases a; cases a1; clear a a1; 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.