]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/formal_topology/overlap/o-algebra.ma
some 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 "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 notation < "hovbox(a ∧ b)" left associative with precedence 35
93 for @{ 'oa_meet_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
94
95 notation > "hovbox(∧ f)" non associative with precedence 60
96 for @{ 'oa_meet $f }.
97 notation > "hovbox(a ∧ b)" left associative with precedence 50
98 for @{ 'oa_meet (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
99
100 interpretation "o-algebra meet" 'oa_meet f = 
101   (fun_1 __ (oa_meet __) f).
102 interpretation "o-algebra meet with explicit function" 'oa_meet_mk f = 
103   (fun_1 __ (oa_meet __) (mk_unary_morphism _ _ f _)).
104
105 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (\emsp) \nbsp term 90 p)" 
106 non associative with precedence 49 for @{ 'oa_join $p }.
107 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (ident i ∈  I) break term 90 p)" 
108 non associative with precedence 49 for @{ 'oa_join_mk (λ${ident i}:$I.$p) }.
109 notation < "hovbox(a ∨ b)" left associative with precedence 49
110 for @{ 'oa_join_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
111
112 notation > "hovbox(∨ f)" non associative with precedence 59
113 for @{ 'oa_join $f }.
114 notation > "hovbox(a ∨ b)" left associative with precedence 49
115 for @{ 'oa_join (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
116
117 interpretation "o-algebra join" 'oa_join f = 
118   (fun_1 __ (oa_join __) f).
119 interpretation "o-algebra join with explicit function" 'oa_join_mk f = 
120   (fun_1 __ (oa_join __) (mk_unary_morphism _ _ f _)).
121
122 record ORelation (P,Q : OAlgebra) : Type ≝ {
123   or_f_ : arrows1 SET P Q;
124   or_f_minus_star_ : arrows1 SET P Q;
125   or_f_star_ : arrows1 SET Q P;
126   or_f_minus_ : arrows1 SET Q P;
127   or_prop1_ : ∀p,q. (or_f_ p ≤ q) = (p ≤ or_f_star_ q);
128   or_prop2_ : ∀p,q. (or_f_minus_ p ≤ q) = (p ≤ or_f_minus_star_ q);
129   or_prop3_ : ∀p,q. (or_f_ p >< q) = (p >< or_f_minus_ q)
130 }.
131
132
133 definition ORelation_setoid : OAlgebra → OAlgebra → setoid1.
134 intros (P Q);
135 constructor 1;
136 [ apply (ORelation P Q);
137 | constructor 1;
138    [ apply (λp,q. And4 (eq1 ? (or_f_minus_star_ ?? p) (or_f_minus_star_ ?? q)) 
139              (eq1 ? (or_f_minus_ ?? p) (or_f_minus_ ?? q)) 
140              (eq1 ? (or_f_ ?? p) (or_f_ ?? q)) 
141              (eq1 ? (or_f_star_ ?? p) (or_f_star_ ?? q))); 
142    | whd; simplify; intros; repeat split; intros; apply refl1;
143    | whd; simplify; intros; cases H; clear H; split; 
144      intro a; apply sym; generalize in match a;assumption;
145    | whd; simplify; intros; cases H; cases H1; clear H H1; split; intro a;
146      [ apply (.= (H2 a)); apply H6;
147      | apply (.= (H3 a)); apply H7;
148      | apply (.= (H4 a)); apply H8;
149      | apply (.= (H5 a)); apply H9;]]]
150 qed.  
151
152 definition or_f_minus_star: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET P Q.
153  intros; constructor 1;
154   [ apply or_f_minus_star_;
155   | intros; cases H; assumption]
156 qed.
157
158 definition or_f: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET P Q.
159  intros; constructor 1;
160   [ apply or_f_;
161   | intros; cases H; assumption]
162 qed.
163
164 coercion or_f.
165
166 definition or_f_minus: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET Q P.
167  intros; constructor 1;
168   [ apply or_f_minus_;
169   | intros; cases H; assumption]
170 qed.
171
172 definition or_f_star: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET Q P.
173  intros; constructor 1;
174   [ apply or_f_star_;
175   | intros; cases H; assumption]
176 qed.
177
178 lemma arrows1_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → arrows1 SET P Q.
179 intros; apply (or_f ?? c);
180 qed.
181
182 coercion arrows1_OF_ORelation_setoid nocomposites.
183
184 lemma umorphism_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → P ⇒ Q.
185 intros; apply (or_f ?? c);
186 qed.
187
188 coercion umorphism_OF_ORelation_setoid.
189
190
191 lemma uncurry_arrows : ∀B,C. arrows1 SET B C → B → C. 
192 intros; apply ((fun_1 ?? c) t);
193 qed.
194
195 coercion uncurry_arrows 1.
196
197 lemma hint3 : ∀P,Q. arrows1 SET P Q → P ⇒ Q. intros; apply c;qed.
198 coercion hint3 nocomposites.
199
200 (*
201 lemma hint2: OAlgebra → setoid. intros; apply (oa_P o). qed.
202 coercion hint2 nocomposites.
203 *)
204
205
206 notation "r \sup *" non associative with precedence 90 for @{'OR_f_star $r}.
207 notation > "r *" non associative with precedence 90 for @{'OR_f_star $r}.
208
209 notation "r \sup (⎻* )" non associative with precedence 90 for @{'OR_f_minus_star $r}.
210 notation > "r⎻*" non associative with precedence 90 for @{'OR_f_minus_star $r}.
211
212 notation "r \sup ⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
213 notation > "r⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
214
215 interpretation "o-relation f⎻*" 'OR_f_minus_star r = (fun_1 __ (or_f_minus_star _ _) r).
216 interpretation "o-relation f⎻" 'OR_f_minus r = (fun_1 __ (or_f_minus _ _) r).
217 interpretation "o-relation f*" 'OR_f_star r = (fun_1 __ (or_f_star _ _) r).
218
219 definition or_prop1 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
220    (F p ≤ q) = (p ≤ F* q).
221 intros; apply (or_prop1_ ?? F p q);
222 qed.
223
224 definition or_prop2 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
225    (F⎻ p ≤ q) = (p ≤ F⎻* q).
226 intros; apply (or_prop2_ ?? F p q);
227 qed.
228
229 definition or_prop3 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
230    (F p >< q) = (p >< F⎻ q).
231 intros; apply (or_prop3_ ?? F p q);
232 qed.
233
234 definition ORelation_composition : ∀P,Q,R. 
235   binary_morphism1 (ORelation_setoid P Q) (ORelation_setoid Q R) (ORelation_setoid P R).
236 intros;
237 constructor 1;
238 [ intros (F G);
239   constructor 1;
240   [ lapply (G ∘ F);
241     apply (G ∘ F);
242   | apply (G⎻* ∘ F⎻* );
243   | apply (F* ∘ G* );
244   | apply (F⎻ ∘ G⎻);
245   | intros; 
246     change with ((G (F p) ≤ q) = (p ≤ (F* (G* q))));
247     apply (.= (or_prop1 :?));
248     apply (or_prop1 :?);
249   | intros;
250     change with ((F⎻ (G⎻ p) ≤ q) = (p ≤ (G⎻* (F⎻* q))));
251     apply (.= (or_prop2 :?));
252     apply or_prop2 ; 
253   | intros; change with ((G (F (p)) >< q) = (p >< (F⎻ (G⎻ q))));
254     apply (.= (or_prop3 :?));
255     apply or_prop3;
256   ]
257 | intros; split; simplify; 
258    [1,3: unfold arrows1_OF_ORelation_setoid; apply ((†H)‡(†H1));
259    |2,4: apply ((†H1)‡(†H));]]
260 qed.
261
262 definition OA : category1.
263 split;
264 [ apply (OAlgebra);
265 | intros; apply (ORelation_setoid o o1);
266 | intro O; split;
267   [1,2,3,4: apply id1;
268   |5,6,7:intros; apply refl1;] 
269 | apply ORelation_composition;
270 | intros (P Q R S F G H); split;
271    [ change with (H⎻* ∘ G⎻* ∘ F⎻* = H⎻* ∘ (G⎻* ∘ F⎻* ));
272      apply (comp_assoc1 ????? (F⎻* ) (G⎻* ) (H⎻* ));
273    | apply ((comp_assoc1 ????? (H⎻) (G⎻) (F⎻))^-1);
274    | apply ((comp_assoc1 ????? F G H)^-1);
275    | apply ((comp_assoc1 ????? H* G* F* ));]
276 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_left1;
277 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_right1;]
278 qed.