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