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