]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/formal_topology/overlap/o-algebra.ma
one line
[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 "datatypes/categories.ma".
16 include "logic/cprop_connectives.ma". 
17
18 inductive bool : Type := 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 definition setoid_OF_SET: objs1 SET → setoid.
30  intros; apply o; qed.
31
32 coercion setoid_OF_SET.
33
34 lemma IF_THEN_ELSE_p :
35   ∀S:setoid.∀a,b:S.∀x,y:BOOL.x = y → 
36     (λm.match m with [ true ⇒ a | false ⇒ b ]) x =
37     (λm.match m with [ true ⇒ a | false ⇒ b ]) y.
38 whd in ⊢ (?→?→?→%→?);
39 intros; cases x in H; cases y; simplify; intros; try apply refl; whd in H; cases H;
40 qed. 
41
42 interpretation "unary morphism comprehension with no proof" 'comprehension T P = 
43   (mk_unary_morphism T _ P _).
44
45 notation > "hvbox({ ident i ∈ s | term 19 p | by })" with precedence 90
46 for @{ 'comprehension_by $s (λ${ident i}. $p) $by}.
47 notation < "hvbox({ ident i ∈ s | term 19 p })" with precedence 90
48 for @{ 'comprehension_by $s (λ${ident i}:$_. $p) $by}.
49
50 interpretation "unary morphism comprehension with proof" 'comprehension_by s \eta.f p = 
51   (mk_unary_morphism s _ f p).
52
53 record OAlgebra : Type := {
54   oa_P :> SET;
55   oa_leq : binary_morphism1 oa_P oa_P CPROP; (* CPROP is setoid1 *)
56   oa_overlap: binary_morphism1 oa_P oa_P CPROP;
57   oa_meet: ∀I:SET.unary_morphism (arrows1 SET I oa_P) oa_P;
58   oa_join: ∀I:SET.unary_morphism (arrows1 SET I oa_P) oa_P;
59   oa_one: oa_P;
60   oa_zero: oa_P;
61   oa_leq_refl: ∀a:oa_P. oa_leq a a; 
62   oa_leq_antisym: ∀a,b:oa_P.oa_leq a b → oa_leq b a → a = b;
63   oa_leq_trans: ∀a,b,c:oa_P.oa_leq a b → oa_leq b c → oa_leq a c;
64   oa_overlap_sym: ∀a,b:oa_P.oa_overlap a b → oa_overlap b a;
65   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);
66   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;
67   oa_zero_bot: ∀p:oa_P.oa_leq oa_zero p;
68   oa_one_top: ∀p:oa_P.oa_leq p oa_one;
69   oa_overlap_preservers_meet_: 
70       ∀p,q.oa_overlap p q → oa_overlap p 
71        (oa_meet ? { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p oa_P p q });
72   oa_join_split:
73       ∀I:SET.∀p.∀q:arrows1 SET I oa_P.oa_overlap p (oa_join I q) ⇔ ∃i:I.oa_overlap p (q i);
74   (*oa_base : setoid;
75   oa_enum : ums oa_base oa_P;
76   oa_density: ∀p,q.(∀i.oa_overlap p (oa_enum i) → oa_overlap q (oa_enum i)) → oa_leq p q
77   *)
78   oa_density: 
79       ∀p,q.(∀r.oa_overlap p r → oa_overlap q r) → oa_leq p q
80 }.
81
82 interpretation "o-algebra leq" 'leq a b = (fun1 ___ (oa_leq _) a b).
83
84 notation "hovbox(a mpadded width -150% (>)< b)" non associative with precedence 45
85 for @{ 'overlap $a $b}.
86 interpretation "o-algebra overlap" 'overlap a b = (fun1 ___ (oa_overlap _) a b).
87
88 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (\emsp) \nbsp term 90 p)" 
89 non associative with precedence 50 for @{ 'oa_meet $p }.
90 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (ident i ∈  I) break term 90 p)" 
91 non associative with precedence 50 for @{ 'oa_meet_mk (λ${ident i}:$I.$p) }.
92
93 (*
94 notation < "hovbox(a ∧ b)" left associative with precedence 35
95 for @{ 'oa_meet_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
96 *)
97 notation > "hovbox(∧ f)" non associative with precedence 60
98 for @{ 'oa_meet $f }.
99 (*
100 notation > "hovbox(a ∧ b)" left associative with precedence 50
101 for @{ 'oa_meet (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
102 *)
103 interpretation "o-algebra meet" 'oa_meet f = 
104   (fun_1 __ (oa_meet __) f).
105 interpretation "o-algebra meet with explicit function" 'oa_meet_mk f = 
106   (fun_1 __ (oa_meet __) (mk_unary_morphism _ _ f _)).
107
108 definition binary_meet : ∀O:OAlgebra. binary_morphism1 O O O.
109 intros; split;
110 [ intros (p q); 
111   apply (∧ { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p ? p q });
112 | intros; apply (prop_1 ?? (oa_meet O BOOL)); intro x; simplify;
113   cases x; simplify; assumption;]
114 qed.
115
116 notation "hovbox(a ∧ b)" left associative with precedence 35
117 for @{ 'oa_meet_bin $a $b }.
118 interpretation "o-algebra binary meet" 'oa_meet_bin a b = 
119   (fun1 ___ (binary_meet _) a b).
120
121 lemma oa_overlap_preservers_meet: ∀O:OAlgebra.∀p,q:O.p >< q → p >< (p ∧ q).
122 intros;  lapply (oa_overlap_preservers_meet_ O p q f);
123 lapply (prop1 O O CPROP (oa_overlap O) p p ? (p ∧ q) # ?);
124 [3: apply (if ?? (Hletin1)); apply Hletin;|skip] apply refl1;
125 qed.
126
127 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (\emsp) \nbsp term 90 p)" 
128 non associative with precedence 49 for @{ 'oa_join $p }.
129 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (ident i ∈  I) break term 90 p)" 
130 non associative with precedence 49 for @{ 'oa_join_mk (λ${ident i}:$I.$p) }.
131 notation < "hovbox(a ∨ b)" left associative with precedence 49
132 for @{ 'oa_join_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
133
134 notation > "hovbox(∨ f)" non associative with precedence 59
135 for @{ 'oa_join $f }.
136 notation > "hovbox(a ∨ b)" left associative with precedence 49
137 for @{ 'oa_join (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
138
139 interpretation "o-algebra join" 'oa_join f = 
140   (fun_1 __ (oa_join __) f).
141 interpretation "o-algebra join with explicit function" 'oa_join_mk f = 
142   (fun_1 __ (oa_join __) (mk_unary_morphism _ _ f _)).
143
144 record ORelation (P,Q : OAlgebra) : Type ≝ {
145   or_f_ : arrows1 SET P Q;
146   or_f_minus_star_ : arrows1 SET P Q;
147   or_f_star_ : arrows1 SET Q P;
148   or_f_minus_ : arrows1 SET Q P;
149   or_prop1_ : ∀p,q. (or_f_ p ≤ q) = (p ≤ or_f_star_ q);
150   or_prop2_ : ∀p,q. (or_f_minus_ p ≤ q) = (p ≤ or_f_minus_star_ q);
151   or_prop3_ : ∀p,q. (or_f_ p >< q) = (p >< or_f_minus_ q)
152 }.
153
154
155 definition ORelation_setoid : OAlgebra → OAlgebra → setoid1.
156 intros (P Q);
157 constructor 1;
158 [ apply (ORelation P Q);
159 | constructor 1;
160    [ apply (λp,q. And4 (eq1 ? (or_f_minus_star_ ?? p) (or_f_minus_star_ ?? q)) 
161              (eq1 ? (or_f_minus_ ?? p) (or_f_minus_ ?? q)) 
162              (eq1 ? (or_f_ ?? p) (or_f_ ?? q)) 
163              (eq1 ? (or_f_star_ ?? p) (or_f_star_ ?? q))); 
164    | whd; simplify; intros; repeat split; intros; apply refl1;
165    | whd; simplify; intros; cases H; clear H; split; 
166      intro a; apply sym; generalize in match a;assumption;
167    | whd; simplify; intros; cases H; cases H1; clear H H1; split; intro a;
168      [ apply (.= (H2 a)); apply H6;
169      | apply (.= (H3 a)); apply H7;
170      | apply (.= (H4 a)); apply H8;
171      | apply (.= (H5 a)); apply H9;]]]
172 qed.  
173
174 definition or_f_minus_star: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET P Q.
175  intros; constructor 1;
176   [ apply or_f_minus_star_;
177   | intros; cases H; assumption]
178 qed.
179
180 definition or_f: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET P Q.
181  intros; constructor 1;
182   [ apply or_f_;
183   | intros; cases H; assumption]
184 qed.
185
186 coercion or_f.
187
188 definition or_f_minus: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET Q P.
189  intros; constructor 1;
190   [ apply or_f_minus_;
191   | intros; cases H; assumption]
192 qed.
193
194 definition or_f_star: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET Q P.
195  intros; constructor 1;
196   [ apply or_f_star_;
197   | intros; cases H; assumption]
198 qed.
199
200 lemma arrows1_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → arrows1 SET P Q.
201 intros; apply (or_f ?? c);
202 qed.
203
204 coercion arrows1_OF_ORelation_setoid nocomposites.
205
206 lemma umorphism_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → P ⇒ Q.
207 intros; apply (or_f ?? c);
208 qed.
209
210 coercion umorphism_OF_ORelation_setoid.
211
212
213 lemma uncurry_arrows : ∀B,C. arrows1 SET B C → B → C. 
214 intros; apply ((fun_1 ?? c) t);
215 qed.
216
217 coercion uncurry_arrows 1.
218
219 lemma hint3 : ∀P,Q. arrows1 SET P Q → P ⇒ Q. intros; apply c;qed.
220 coercion hint3 nocomposites.
221
222 (*
223 lemma hint2: OAlgebra → setoid. intros; apply (oa_P o). qed.
224 coercion hint2 nocomposites.
225 *)
226
227
228 notation "r \sup *" non associative with precedence 90 for @{'OR_f_star $r}.
229 notation > "r *" non associative with precedence 90 for @{'OR_f_star $r}.
230
231 notation "r \sup (⎻* )" non associative with precedence 90 for @{'OR_f_minus_star $r}.
232 notation > "r⎻*" non associative with precedence 90 for @{'OR_f_minus_star $r}.
233
234 notation "r \sup ⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
235 notation > "r⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
236
237 interpretation "o-relation f⎻*" 'OR_f_minus_star r = (fun_1 __ (or_f_minus_star _ _) r).
238 interpretation "o-relation f⎻" 'OR_f_minus r = (fun_1 __ (or_f_minus _ _) r).
239 interpretation "o-relation f*" 'OR_f_star r = (fun_1 __ (or_f_star _ _) r).
240
241 definition or_prop1 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
242    (F p ≤ q) = (p ≤ F* q).
243 intros; apply (or_prop1_ ?? F p q);
244 qed.
245
246 definition or_prop2 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
247    (F⎻ p ≤ q) = (p ≤ F⎻* q).
248 intros; apply (or_prop2_ ?? F p q);
249 qed.
250
251 definition or_prop3 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
252    (F p >< q) = (p >< F⎻ q).
253 intros; apply (or_prop3_ ?? F p q);
254 qed.
255
256 definition ORelation_composition : ∀P,Q,R. 
257   binary_morphism1 (ORelation_setoid P Q) (ORelation_setoid Q R) (ORelation_setoid P R).
258 intros;
259 constructor 1;
260 [ intros (F G);
261   constructor 1;
262   [ lapply (G ∘ F);
263     apply (G ∘ F);
264   | apply (G⎻* ∘ F⎻* );
265   | apply (F* ∘ G* );
266   | apply (F⎻ ∘ G⎻);
267   | intros; 
268     change with ((G (F p) ≤ q) = (p ≤ (F* (G* q))));
269     apply (.= (or_prop1 :?));
270     apply (or_prop1 :?);
271   | intros;
272     change with ((F⎻ (G⎻ p) ≤ q) = (p ≤ (G⎻* (F⎻* q))));
273     apply (.= (or_prop2 :?));
274     apply or_prop2 ; 
275   | intros; change with ((G (F (p)) >< q) = (p >< (F⎻ (G⎻ q))));
276     apply (.= (or_prop3 :?));
277     apply or_prop3;
278   ]
279 | intros; split; simplify; 
280    [1,3: unfold arrows1_OF_ORelation_setoid; apply ((†H)‡(†H1));
281    |2,4: apply ((†H1)‡(†H));]]
282 qed.
283
284 definition OA : category1.
285 split;
286 [ apply (OAlgebra);
287 | intros; apply (ORelation_setoid o o1);
288 | intro O; split;
289   [1,2,3,4: apply id1;
290   |5,6,7:intros; apply refl1;] 
291 | apply ORelation_composition;
292 | intros (P Q R S F G H); split;
293    [ change with (H⎻* ∘ G⎻* ∘ F⎻* = H⎻* ∘ (G⎻* ∘ F⎻* ));
294      apply (comp_assoc1 ????? (F⎻* ) (G⎻* ) (H⎻* ));
295    | apply ((comp_assoc1 ????? (H⎻) (G⎻) (F⎻))^-1);
296    | apply ((comp_assoc1 ????? F G H)^-1);
297    | apply ((comp_assoc1 ????? H* G* F* ));]
298 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_left1;
299 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_right1;]
300 qed.