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