]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/formal_topology/overlap/o-algebra.ma
the new coercion behaviour (variants + composition with ID) and the new
[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: 
67     ∀I:SET.∀p_i:I ⇒ oa_P.∀p:oa_P.
68       oa_leq p (oa_meet I p_i) = ∀i:I.oa_leq p (p_i i);
69   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;
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   oa_join_split:
76       ∀I:SET.∀p.∀q:I ⇒ oa_P.
77        oa_overlap p (oa_join I q) = ∃i:I.oa_overlap p (q i);
78   (*oa_base : setoid;
79   1) enum non e' il nome giusto perche' non e' suriettiva
80   2) manca (vedere altro capitolo) la "suriettivita'" come immagine di insiemi di oa_base
81   oa_enum : ums oa_base oa_P;
82   oa_density: ∀p,q.(∀i.oa_overlap p (oa_enum i) → oa_overlap q (oa_enum i)) → oa_leq p q
83   *)
84   oa_density: 
85       ∀p,q.(∀r.oa_overlap p r → oa_overlap q r) → oa_leq p q
86 }.
87
88 interpretation "o-algebra leq" 'leq a b = (fun21 ___ (oa_leq _) a b).
89
90 notation "hovbox(a mpadded width -150% (>)< b)" non associative with precedence 45
91 for @{ 'overlap $a $b}.
92 interpretation "o-algebra overlap" 'overlap a b = (fun21 ___ (oa_overlap _) a b).
93
94 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (\emsp) \nbsp term 90 p)" 
95 non associative with precedence 50 for @{ 'oa_meet $p }.
96 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (ident i ∈  I) break term 90 p)" 
97 non associative with precedence 50 for @{ 'oa_meet_mk (λ${ident i}:$I.$p) }.
98
99 notation > "hovbox(∧ f)" non associative with precedence 60
100 for @{ 'oa_meet $f }.
101 interpretation "o-algebra meet" 'oa_meet f = 
102   (fun12 __ (oa_meet __) f).
103 interpretation "o-algebra meet with explicit function" 'oa_meet_mk f = 
104   (fun12 __ (oa_meet __) (mk_unary_morphism _ _ f _)).
105
106 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (\emsp) \nbsp term 90 p)" 
107 non associative with precedence 50 for @{ 'oa_join $p }.
108 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (ident i ∈  I) break term 90 p)" 
109 non associative with precedence 50 for @{ 'oa_join_mk (λ${ident i}:$I.$p) }.
110
111 notation > "hovbox(∨ f)" non associative with precedence 60
112 for @{ 'oa_join $f }.
113 interpretation "o-algebra join" 'oa_join f = 
114   (fun12 __ (oa_join __) f).
115 interpretation "o-algebra join with explicit function" 'oa_join_mk f = 
116   (fun12 __ (oa_join __) (mk_unary_morphism _ _ f _)).
117
118 definition binary_meet : ∀O:OAlgebra. binary_morphism1 O O O.
119 intros; split;
120 [ intros (p q); 
121   apply (∧ { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p ? p q });
122 | intros; lapply (prop12 ? O (oa_meet O BOOL));
123    [2: apply ({ x ∈ BOOL | match x with [ true ⇒ a | false ⇒ b ] | IF_THEN_ELSE_p ? a b });
124    |3: apply ({ x ∈ BOOL | match x with [ true ⇒ a' | false ⇒ b' ] | IF_THEN_ELSE_p ? a' b' });
125    | apply Hletin;]
126   intro x; simplify; cases x; simplify; assumption;]
127 qed.
128
129 interpretation "o-algebra binary meet" 'and a b = 
130   (fun21 ___ (binary_meet _) a b).
131
132 prefer coercion Type1_OF_OAlgebra.
133
134 definition binary_join : ∀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_join 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 interpretation "o-algebra binary join" 'or a b = 
146   (fun21 ___ (binary_join _) a b).
147
148 lemma oa_overlap_preservers_meet: ∀O:OAlgebra.∀p,q:O.p >< q → p >< (p ∧ q).
149 (* next change to avoid universe inconsistency *)
150 change in ⊢ (?→%→%→?) with (Type1_OF_OAlgebra O);
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 record ORelation (P,Q : OAlgebra) : Type2 ≝ {
174   or_f_ : carr2 (P ⇒ Q);
175   or_f_minus_star_ : carr2(P ⇒ Q);
176   or_f_star_ : carr2(Q ⇒ P);
177   or_f_minus_ : carr2(Q ⇒ P);
178   or_prop1_ : ∀p,q. (or_f_ p ≤ q) = (p ≤ or_f_star_ q);
179   or_prop2_ : ∀p,q. (or_f_minus_ p ≤ q) = (p ≤ or_f_minus_star_ q);
180   or_prop3_ : ∀p,q. (or_f_ p >< q) = (p >< or_f_minus_ q)
181 }.
182
183 definition ORelation_setoid : OAlgebra → OAlgebra → setoid2.
184 intros (P Q);
185 constructor 1;
186 [ apply (ORelation P Q);
187 | constructor 1;
188    (* tenere solo una uguaglianza e usare la proposizione 9.9 per
189       le altre (unicita' degli aggiunti e del simmetrico) *)
190    [ apply (λp,q. And42 (eq2 ? (or_f_minus_star_ ?? p) (or_f_minus_star_ ?? q)) 
191              (eq2 ? (or_f_minus_ ?? p) (or_f_minus_ ?? q)) 
192              (eq2 ? (or_f_ ?? p) (or_f_ ?? q)) 
193              (eq2 ? (or_f_star_ ?? p) (or_f_star_ ?? q))); 
194    | whd; simplify; intros; repeat split; intros; apply refl2;
195    | whd; simplify; intros; cases a; clear a; split; 
196      intro a; apply sym1; generalize in match a;assumption;
197    | whd; simplify; intros; cases a; cases a1; clear a a1; split; intro a;
198      [ apply (.= (e a)); apply e4;
199      | apply (.= (e1 a)); apply e5;
200      | apply (.= (e2 a)); apply e6;
201      | apply (.= (e3 a)); apply e7;]]]
202 qed.
203
204 definition ORelation_of_ORelation_setoid : 
205   ∀P,Q.ORelation_setoid P Q → ORelation P Q ≝ λP,Q,x.x.
206 coercion ORelation_of_ORelation_setoid.
207
208 definition or_f_minus_star:
209  ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (P ⇒ Q).
210  intros; constructor 1;
211   [ apply or_f_minus_star_;
212   | intros; cases e; assumption]
213 qed.
214
215 definition or_f: ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (P ⇒ Q).
216  intros; constructor 1;
217   [ apply or_f_;
218   | intros; cases e; assumption]
219 qed.
220
221 definition or_f_minus: ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (Q ⇒ P).
222  intros; constructor 1;
223   [ apply or_f_minus_;
224   | intros; cases e; assumption]
225 qed.
226
227 definition or_f_star: ∀P,Q:OAlgebra.unary_morphism2 (ORelation_setoid P Q) (Q ⇒ P).
228  intros; constructor 1;
229   [ apply or_f_star_;
230   | intros; cases e; assumption]
231 qed.
232
233 lemma arrows1_of_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → (P ⇒ Q). 
234 intros; apply (or_f ?? c);
235 qed.
236 coercion arrows1_of_ORelation_setoid.
237
238 notation "r \sup *" non associative with precedence 90 for @{'OR_f_star $r}.
239 notation > "r *" non associative with precedence 90 for @{'OR_f_star $r}.
240
241 notation "r \sup (⎻* )" non associative with precedence 90 for @{'OR_f_minus_star $r}.
242 notation > "r⎻*" non associative with precedence 90 for @{'OR_f_minus_star $r}.
243
244 notation "r \sup ⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
245 notation > "r⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
246
247 interpretation "o-relation f⎻*" 'OR_f_minus_star r = (fun12 __ (or_f_minus_star _ _) r).
248 interpretation "o-relation f⎻" 'OR_f_minus r = (fun12 __ (or_f_minus _ _) r).
249 interpretation "o-relation f*" 'OR_f_star r = (fun12 __ (or_f_star _ _) r).
250
251 definition or_prop1 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
252    (F p ≤ q) = (p ≤ F* q).
253 intros; apply (or_prop1_ ?? F p q);
254 qed.
255
256 definition or_prop2 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
257    (F⎻ p ≤ q) = (p ≤ F⎻* q).
258 intros; apply (or_prop2_ ?? F p q);
259 qed.
260
261 definition or_prop3 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
262    (F p >< q) = (p >< F⎻ q).
263 intros; apply (or_prop3_ ?? F p q);
264 qed.
265
266 definition ORelation_composition : ∀P,Q,R. 
267   binary_morphism2 (ORelation_setoid P Q) (ORelation_setoid Q R) (ORelation_setoid P R).
268 intros;
269 constructor 1;
270 [ intros (F G);
271   constructor 1;
272   [ apply (G ∘ F);
273   | apply rule (G⎻* ∘ F⎻* );
274   | apply (F* ∘ G* );
275   | apply (F⎻ ∘ G⎻);
276   | intros; 
277     change with ((G (F p) ≤ q) = (p ≤ (F* (G* q))));
278     apply (.= (or_prop1 :?));
279     apply (or_prop1 :?);
280   | intros;
281     change with ((F⎻ (G⎻ p) ≤ q) = (p ≤ (G⎻* (F⎻* q))));
282     apply (.= (or_prop2 :?));
283     apply or_prop2 ; 
284   | intros; change with ((G (F (p)) >< q) = (p >< (F⎻ (G⎻ q))));
285     apply (.= (or_prop3 :?));
286     apply or_prop3;
287   ]
288 | intros; split; simplify; 
289    [3: unfold arrows1_of_ORelation_setoid;
290          apply ((†e)‡(†e1));
291    |1: apply ((†e)‡(†e1));
292    |2,4: apply ((†e1)‡(†e));]]
293 qed.
294
295 definition OA : category2.
296 split;
297 [ apply (OAlgebra);
298 | intros; apply (ORelation_setoid o o1);
299 | intro O; split;
300   [1,2,3,4: apply id2;
301   |5,6,7:intros; apply refl1;] 
302 | apply ORelation_composition;
303 | intros (P Q R S F G H); split;
304    [ change with (H⎻* ∘ G⎻* ∘ F⎻* = H⎻* ∘ (G⎻* ∘ F⎻* ));
305      apply (comp_assoc2 ????? (F⎻* ) (G⎻* ) (H⎻* ));
306    | apply ((comp_assoc2 ????? (H⎻) (G⎻) (F⎻))^-1);
307    | apply ((comp_assoc2 ????? F G H)^-1);
308    | apply ((comp_assoc2 ????? H* G* F* ));]
309 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_left2;
310 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_right2;]
311 qed.
312
313 definition OAlgebra_of_objs2_OA: objs2 OA → OAlgebra ≝ λx.x.
314 coercion OAlgebra_of_objs2_OA.
315
316 definition ORelation_setoid_of_arrows2_OA: 
317   ∀P,Q. arrows2 OA P Q → ORelation_setoid P Q ≝ λP,Q,c.c.
318 coercion ORelation_setoid_of_arrows2_OA.
319
320 prefer coercion Type_OF_objs2.