1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "datatypes/categories.ma".
16 include "logic/cprop_connectives.ma".
18 inductive bool : Type := true : bool | false : bool.
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]
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.
34 intros; cases x in H; cases y; simplify; intros; try apply refl; whd in H; cases H;
37 interpretation "unary morphism comprehension with no proof" 'comprehension T P =
38 (mk_unary_morphism T _ P _).
40 notation > "hvbox({ ident i ∈ s | term 19 p | by })" with precedence 90
41 for @{ 'comprehension_by $s (λ${ident i}. $p) $by}.
42 notation < "hvbox({ ident i ∈ s | term 19 p })" with precedence 90
43 for @{ 'comprehension_by $s (λ${ident i}:$_. $p) $by}.
45 interpretation "unary morphism comprehension with proof" 'comprehension_by s \eta.f p =
46 (mk_unary_morphism s _ f p).
48 record OAlgebra : Type := {
50 oa_leq : binary_morphism1 oa_P oa_P CPROP; (* CPROP is setoid1 *)
51 oa_overlap: binary_morphism1 oa_P oa_P CPROP;
52 oa_meet: ∀I:SET.unary_morphism (arrows1 SET I oa_P) oa_P;
53 oa_join: ∀I:SET.unary_morphism (arrows1 SET I oa_P) oa_P;
56 oa_leq_refl: ∀a:oa_P. oa_leq a a;
57 oa_leq_antisym: ∀a,b:oa_P.oa_leq a b → oa_leq b a → a = b;
58 oa_leq_trans: ∀a,b,c:oa_P.oa_leq a b → oa_leq b c → oa_leq a c;
59 oa_overlap_sym: ∀a,b:oa_P.oa_overlap a b → oa_overlap b a;
60 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);
61 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;
62 oa_zero_bot: ∀p:oa_P.oa_leq oa_zero p;
63 oa_one_top: ∀p:oa_P.oa_leq p oa_one;
64 oa_overlap_preservers_meet_:
65 ∀p,q.oa_overlap p q → oa_overlap p
66 (oa_meet ? { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p oa_P p q });
68 ∀I:SET.∀p.∀q:arrows1 SET I oa_P.oa_overlap p (oa_join I q) ⇔ ∃i:I.oa_overlap p (q i);
70 oa_enum : ums oa_base oa_P;
71 oa_density: ∀p,q.(∀i.oa_overlap p (oa_enum i) → oa_overlap q (oa_enum i)) → oa_leq p q
74 ∀p,q.(∀r.oa_overlap p r → oa_overlap q r) → oa_leq p q
77 interpretation "o-algebra leq" 'leq a b = (fun1 ___ (oa_leq _) a b).
79 notation "hovbox(a mpadded width -150% (>)< b)" non associative with precedence 45
80 for @{ 'overlap $a $b}.
81 interpretation "o-algebra overlap" 'overlap a b = (fun1 ___ (oa_overlap _) a b).
83 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (\emsp) \nbsp term 90 p)"
84 non associative with precedence 50 for @{ 'oa_meet $p }.
85 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∧) \below (ident i ∈ I) break term 90 p)"
86 non associative with precedence 50 for @{ 'oa_meet_mk (λ${ident i}:$I.$p) }.
89 notation < "hovbox(a ∧ b)" left associative with precedence 35
90 for @{ 'oa_meet_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
92 notation > "hovbox(∧ f)" non associative with precedence 60
95 notation > "hovbox(a ∧ b)" left associative with precedence 50
96 for @{ 'oa_meet (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
98 interpretation "o-algebra meet" 'oa_meet f =
99 (fun_1 __ (oa_meet __) f).
100 interpretation "o-algebra meet with explicit function" 'oa_meet_mk f =
101 (fun_1 __ (oa_meet __) (mk_unary_morphism _ _ f _)).
103 definition binary_meet : ∀O:OAlgebra. binary_morphism1 O O O.
106 apply (∧ { x ∈ BOOL | match x with [ true ⇒ p | false ⇒ q ] | IF_THEN_ELSE_p ? p q });
107 | intros; apply (prop_1 ?? (oa_meet O BOOL)); intro x; simplify;
108 cases x; simplify; assumption;]
111 notation "hovbox(a ∧ b)" left associative with precedence 35
112 for @{ 'oa_meet_bin $a $b }.
113 interpretation "o-algebra binary meet" 'oa_meet_bin a b =
114 (fun1 ___ (binary_meet _) a b).
116 lemma oa_overlap_preservers_meet: ∀O:OAlgebra.∀p,q:O.p >< q → p >< (p ∧ q).
117 intros; lapply (oa_overlap_preservers_meet_ O p q f);
118 lapply (prop1 O O CPROP (oa_overlap O) p p ? (p ∧ q) # ?);
119 [3: apply (if ?? (Hletin1)); apply Hletin;|skip] apply refl1;
122 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (\emsp) \nbsp term 90 p)"
123 non associative with precedence 49 for @{ 'oa_join $p }.
124 notation < "hovbox(mstyle scriptlevel 1 scriptsizemultiplier 1.7 (∨) \below (ident i ∈ I) break term 90 p)"
125 non associative with precedence 49 for @{ 'oa_join_mk (λ${ident i}:$I.$p) }.
126 notation < "hovbox(a ∨ b)" left associative with precedence 49
127 for @{ 'oa_join_mk (λ${ident i}:$_.match $i with [ true ⇒ $a | false ⇒ $b ]) }.
129 notation > "hovbox(∨ f)" non associative with precedence 59
130 for @{ 'oa_join $f }.
131 notation > "hovbox(a ∨ b)" left associative with precedence 49
132 for @{ 'oa_join (mk_unary_morphism BOOL ? (λx__:bool.match x__ with [ true ⇒ $a | false ⇒ $b ]) (IF_THEN_ELSE_p ? $a $b)) }.
134 interpretation "o-algebra join" 'oa_join f =
135 (fun_1 __ (oa_join __) f).
136 interpretation "o-algebra join with explicit function" 'oa_join_mk f =
137 (fun_1 __ (oa_join __) (mk_unary_morphism _ _ f _)).
139 record ORelation (P,Q : OAlgebra) : Type ≝ {
140 or_f_ : arrows1 SET P Q;
141 or_f_minus_star_ : arrows1 SET P Q;
142 or_f_star_ : arrows1 SET Q P;
143 or_f_minus_ : arrows1 SET Q P;
144 or_prop1_ : ∀p,q. (or_f_ p ≤ q) = (p ≤ or_f_star_ q);
145 or_prop2_ : ∀p,q. (or_f_minus_ p ≤ q) = (p ≤ or_f_minus_star_ q);
146 or_prop3_ : ∀p,q. (or_f_ p >< q) = (p >< or_f_minus_ q)
150 definition ORelation_setoid : OAlgebra → OAlgebra → setoid1.
153 [ apply (ORelation P Q);
155 [ apply (λp,q. And4 (eq1 ? (or_f_minus_star_ ?? p) (or_f_minus_star_ ?? q))
156 (eq1 ? (or_f_minus_ ?? p) (or_f_minus_ ?? q))
157 (eq1 ? (or_f_ ?? p) (or_f_ ?? q))
158 (eq1 ? (or_f_star_ ?? p) (or_f_star_ ?? q)));
159 | whd; simplify; intros; repeat split; intros; apply refl1;
160 | whd; simplify; intros; cases H; clear H; split;
161 intro a; apply sym; generalize in match a;assumption;
162 | whd; simplify; intros; cases H; cases H1; clear H H1; split; intro a;
163 [ apply (.= (H2 a)); apply H6;
164 | apply (.= (H3 a)); apply H7;
165 | apply (.= (H4 a)); apply H8;
166 | apply (.= (H5 a)); apply H9;]]]
169 definition or_f_minus_star: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET P Q.
170 intros; constructor 1;
171 [ apply or_f_minus_star_;
172 | intros; cases H; assumption]
175 definition or_f: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET P Q.
176 intros; constructor 1;
178 | intros; cases H; assumption]
183 definition or_f_minus: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET Q P.
184 intros; constructor 1;
186 | intros; cases H; assumption]
189 definition or_f_star: ∀P,Q:OAlgebra.ORelation_setoid P Q ⇒ arrows1 SET Q P.
190 intros; constructor 1;
192 | intros; cases H; assumption]
195 lemma arrows1_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → arrows1 SET P Q.
196 intros; apply (or_f ?? c);
199 coercion arrows1_OF_ORelation_setoid nocomposites.
201 lemma umorphism_OF_ORelation_setoid : ∀P,Q. ORelation_setoid P Q → P ⇒ Q.
202 intros; apply (or_f ?? c);
205 coercion umorphism_OF_ORelation_setoid.
208 lemma uncurry_arrows : ∀B,C. arrows1 SET B C → B → C.
209 intros; apply ((fun_1 ?? c) t);
212 coercion uncurry_arrows 1.
214 lemma hint3 : ∀P,Q. arrows1 SET P Q → P ⇒ Q. intros; apply c;qed.
215 coercion hint3 nocomposites.
218 lemma hint2: OAlgebra → setoid. intros; apply (oa_P o). qed.
219 coercion hint2 nocomposites.
223 notation "r \sup *" non associative with precedence 90 for @{'OR_f_star $r}.
224 notation > "r *" non associative with precedence 90 for @{'OR_f_star $r}.
226 notation "r \sup (⎻* )" non associative with precedence 90 for @{'OR_f_minus_star $r}.
227 notation > "r⎻*" non associative with precedence 90 for @{'OR_f_minus_star $r}.
229 notation "r \sup ⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
230 notation > "r⎻" non associative with precedence 90 for @{'OR_f_minus $r}.
232 interpretation "o-relation f⎻*" 'OR_f_minus_star r = (fun_1 __ (or_f_minus_star _ _) r).
233 interpretation "o-relation f⎻" 'OR_f_minus r = (fun_1 __ (or_f_minus _ _) r).
234 interpretation "o-relation f*" 'OR_f_star r = (fun_1 __ (or_f_star _ _) r).
236 definition or_prop1 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
237 (F p ≤ q) = (p ≤ F* q).
238 intros; apply (or_prop1_ ?? F p q);
241 definition or_prop2 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
242 (F⎻ p ≤ q) = (p ≤ F⎻* q).
243 intros; apply (or_prop2_ ?? F p q);
246 definition or_prop3 : ∀P,Q:OAlgebra.∀F:ORelation_setoid P Q.∀p,q.
247 (F p >< q) = (p >< F⎻ q).
248 intros; apply (or_prop3_ ?? F p q);
251 definition ORelation_composition : ∀P,Q,R.
252 binary_morphism1 (ORelation_setoid P Q) (ORelation_setoid Q R) (ORelation_setoid P R).
259 | apply (G⎻* ∘ F⎻* );
263 change with ((G (F p) ≤ q) = (p ≤ (F* (G* q))));
264 apply (.= (or_prop1 :?));
267 change with ((F⎻ (G⎻ p) ≤ q) = (p ≤ (G⎻* (F⎻* q))));
268 apply (.= (or_prop2 :?));
270 | intros; change with ((G (F (p)) >< q) = (p >< (F⎻ (G⎻ q))));
271 apply (.= (or_prop3 :?));
274 | intros; split; simplify;
275 [1,3: unfold arrows1_OF_ORelation_setoid; apply ((†H)‡(†H1));
276 |2,4: apply ((†H1)‡(†H));]]
279 definition OA : category1.
282 | intros; apply (ORelation_setoid o o1);
285 |5,6,7:intros; apply refl1;]
286 | apply ORelation_composition;
287 | intros (P Q R S F G H); split;
288 [ change with (H⎻* ∘ G⎻* ∘ F⎻* = H⎻* ∘ (G⎻* ∘ F⎻* ));
289 apply (comp_assoc1 ????? (F⎻* ) (G⎻* ) (H⎻* ));
290 | apply ((comp_assoc1 ????? (H⎻) (G⎻) (F⎻))^-1);
291 | apply ((comp_assoc1 ????? F G H)^-1);
292 | apply ((comp_assoc1 ????? H* G* F* ));]
293 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_left1;
294 | intros; split; unfold ORelation_composition; simplify; apply id_neutral_right1;]