27411
|
1 |
(* Title: HOLCF/Universal.thy
|
|
2 |
Author: Brian Huffman
|
|
3 |
*)
|
|
4 |
|
|
5 |
theory Universal
|
|
6 |
imports CompactBasis NatIso
|
|
7 |
begin
|
|
8 |
|
|
9 |
subsection {* Basis datatype *}
|
|
10 |
|
|
11 |
types ubasis = nat
|
|
12 |
|
|
13 |
definition
|
|
14 |
node :: "nat \<Rightarrow> ubasis \<Rightarrow> ubasis set \<Rightarrow> ubasis"
|
|
15 |
where
|
30505
|
16 |
"node i a S = Suc (prod2nat (i, prod2nat (a, set2nat S)))"
|
27411
|
17 |
|
30505
|
18 |
lemma node_not_0 [simp]: "node i a S \<noteq> 0"
|
27411
|
19 |
unfolding node_def by simp
|
|
20 |
|
30505
|
21 |
lemma node_gt_0 [simp]: "0 < node i a S"
|
27411
|
22 |
unfolding node_def by simp
|
|
23 |
|
|
24 |
lemma node_inject [simp]:
|
30505
|
25 |
"\<lbrakk>finite S; finite T\<rbrakk>
|
|
26 |
\<Longrightarrow> node i a S = node j b T \<longleftrightarrow> i = j \<and> a = b \<and> S = T"
|
27411
|
27 |
unfolding node_def by simp
|
|
28 |
|
30505
|
29 |
lemma node_gt0: "i < node i a S"
|
27411
|
30 |
unfolding node_def less_Suc_eq_le
|
|
31 |
by (rule le_prod2nat_1)
|
|
32 |
|
30505
|
33 |
lemma node_gt1: "a < node i a S"
|
27411
|
34 |
unfolding node_def less_Suc_eq_le
|
|
35 |
by (rule order_trans [OF le_prod2nat_1 le_prod2nat_2])
|
|
36 |
|
|
37 |
lemma nat_less_power2: "n < 2^n"
|
|
38 |
by (induct n) simp_all
|
|
39 |
|
30505
|
40 |
lemma node_gt2: "\<lbrakk>finite S; b \<in> S\<rbrakk> \<Longrightarrow> b < node i a S"
|
27411
|
41 |
unfolding node_def less_Suc_eq_le set2nat_def
|
|
42 |
apply (rule order_trans [OF _ le_prod2nat_2])
|
|
43 |
apply (rule order_trans [OF _ le_prod2nat_2])
|
30505
|
44 |
apply (rule order_trans [where y="setsum (op ^ 2) {b}"])
|
27411
|
45 |
apply (simp add: nat_less_power2 [THEN order_less_imp_le])
|
|
46 |
apply (erule setsum_mono2, simp, simp)
|
|
47 |
done
|
|
48 |
|
|
49 |
lemma eq_prod2nat_pairI:
|
|
50 |
"\<lbrakk>fst (nat2prod x) = a; snd (nat2prod x) = b\<rbrakk> \<Longrightarrow> x = prod2nat (a, b)"
|
|
51 |
by (erule subst, erule subst, simp)
|
|
52 |
|
|
53 |
lemma node_cases:
|
|
54 |
assumes 1: "x = 0 \<Longrightarrow> P"
|
30505
|
55 |
assumes 2: "\<And>i a S. \<lbrakk>finite S; x = node i a S\<rbrakk> \<Longrightarrow> P"
|
27411
|
56 |
shows "P"
|
|
57 |
apply (cases x)
|
|
58 |
apply (erule 1)
|
|
59 |
apply (rule 2)
|
|
60 |
apply (rule finite_nat2set)
|
|
61 |
apply (simp add: node_def)
|
|
62 |
apply (rule eq_prod2nat_pairI [OF refl])
|
|
63 |
apply (rule eq_prod2nat_pairI [OF refl refl])
|
|
64 |
done
|
|
65 |
|
|
66 |
lemma node_induct:
|
|
67 |
assumes 1: "P 0"
|
30505
|
68 |
assumes 2: "\<And>i a S. \<lbrakk>P a; finite S; \<forall>b\<in>S. P b\<rbrakk> \<Longrightarrow> P (node i a S)"
|
27411
|
69 |
shows "P x"
|
|
70 |
apply (induct x rule: nat_less_induct)
|
|
71 |
apply (case_tac n rule: node_cases)
|
|
72 |
apply (simp add: 1)
|
|
73 |
apply (simp add: 2 node_gt1 node_gt2)
|
|
74 |
done
|
|
75 |
|
|
76 |
subsection {* Basis ordering *}
|
|
77 |
|
|
78 |
inductive
|
|
79 |
ubasis_le :: "nat \<Rightarrow> nat \<Rightarrow> bool"
|
|
80 |
where
|
30505
|
81 |
ubasis_le_refl: "ubasis_le a a"
|
27411
|
82 |
| ubasis_le_trans:
|
30505
|
83 |
"\<lbrakk>ubasis_le a b; ubasis_le b c\<rbrakk> \<Longrightarrow> ubasis_le a c"
|
27411
|
84 |
| ubasis_le_lower:
|
30505
|
85 |
"finite S \<Longrightarrow> ubasis_le a (node i a S)"
|
27411
|
86 |
| ubasis_le_upper:
|
30505
|
87 |
"\<lbrakk>finite S; b \<in> S; ubasis_le a b\<rbrakk> \<Longrightarrow> ubasis_le (node i a S) b"
|
27411
|
88 |
|
|
89 |
lemma ubasis_le_minimal: "ubasis_le 0 x"
|
|
90 |
apply (induct x rule: node_induct)
|
|
91 |
apply (rule ubasis_le_refl)
|
|
92 |
apply (erule ubasis_le_trans)
|
|
93 |
apply (erule ubasis_le_lower)
|
|
94 |
done
|
|
95 |
|
|
96 |
subsubsection {* Generic take function *}
|
|
97 |
|
|
98 |
function
|
|
99 |
ubasis_until :: "(ubasis \<Rightarrow> bool) \<Rightarrow> ubasis \<Rightarrow> ubasis"
|
|
100 |
where
|
|
101 |
"ubasis_until P 0 = 0"
|
30505
|
102 |
| "finite S \<Longrightarrow> ubasis_until P (node i a S) =
|
|
103 |
(if P (node i a S) then node i a S else ubasis_until P a)"
|
27411
|
104 |
apply clarify
|
|
105 |
apply (rule_tac x=b in node_cases)
|
|
106 |
apply simp
|
|
107 |
apply simp
|
|
108 |
apply fast
|
|
109 |
apply simp
|
|
110 |
apply simp
|
|
111 |
apply simp
|
|
112 |
done
|
|
113 |
|
|
114 |
termination ubasis_until
|
|
115 |
apply (relation "measure snd")
|
|
116 |
apply (rule wf_measure)
|
|
117 |
apply (simp add: node_gt1)
|
|
118 |
done
|
|
119 |
|
|
120 |
lemma ubasis_until: "P 0 \<Longrightarrow> P (ubasis_until P x)"
|
|
121 |
by (induct x rule: node_induct) simp_all
|
|
122 |
|
|
123 |
lemma ubasis_until': "0 < ubasis_until P x \<Longrightarrow> P (ubasis_until P x)"
|
|
124 |
by (induct x rule: node_induct) auto
|
|
125 |
|
|
126 |
lemma ubasis_until_same: "P x \<Longrightarrow> ubasis_until P x = x"
|
|
127 |
by (induct x rule: node_induct) simp_all
|
|
128 |
|
|
129 |
lemma ubasis_until_idem:
|
|
130 |
"P 0 \<Longrightarrow> ubasis_until P (ubasis_until P x) = ubasis_until P x"
|
|
131 |
by (rule ubasis_until_same [OF ubasis_until])
|
|
132 |
|
|
133 |
lemma ubasis_until_0:
|
|
134 |
"\<forall>x. x \<noteq> 0 \<longrightarrow> \<not> P x \<Longrightarrow> ubasis_until P x = 0"
|
|
135 |
by (induct x rule: node_induct) simp_all
|
|
136 |
|
|
137 |
lemma ubasis_until_less: "ubasis_le (ubasis_until P x) x"
|
|
138 |
apply (induct x rule: node_induct)
|
|
139 |
apply (simp add: ubasis_le_refl)
|
|
140 |
apply (simp add: ubasis_le_refl)
|
|
141 |
apply (rule impI)
|
|
142 |
apply (erule ubasis_le_trans)
|
|
143 |
apply (erule ubasis_le_lower)
|
|
144 |
done
|
|
145 |
|
|
146 |
lemma ubasis_until_chain:
|
|
147 |
assumes PQ: "\<And>x. P x \<Longrightarrow> Q x"
|
|
148 |
shows "ubasis_le (ubasis_until P x) (ubasis_until Q x)"
|
|
149 |
apply (induct x rule: node_induct)
|
|
150 |
apply (simp add: ubasis_le_refl)
|
|
151 |
apply (simp add: ubasis_le_refl)
|
|
152 |
apply (simp add: PQ)
|
|
153 |
apply clarify
|
|
154 |
apply (rule ubasis_le_trans)
|
|
155 |
apply (rule ubasis_until_less)
|
|
156 |
apply (erule ubasis_le_lower)
|
|
157 |
done
|
|
158 |
|
|
159 |
lemma ubasis_until_mono:
|
30505
|
160 |
assumes "\<And>i a S b. \<lbrakk>finite S; P (node i a S); b \<in> S; ubasis_le a b\<rbrakk> \<Longrightarrow> P b"
|
|
161 |
shows "ubasis_le a b \<Longrightarrow> ubasis_le (ubasis_until P a) (ubasis_until P b)"
|
27411
|
162 |
apply (induct set: ubasis_le)
|
|
163 |
apply (rule ubasis_le_refl)
|
|
164 |
apply (erule (1) ubasis_le_trans)
|
|
165 |
apply (simp add: ubasis_le_refl)
|
|
166 |
apply (rule impI)
|
|
167 |
apply (rule ubasis_le_trans)
|
|
168 |
apply (rule ubasis_until_less)
|
|
169 |
apply (erule ubasis_le_lower)
|
|
170 |
apply simp
|
|
171 |
apply (rule impI)
|
|
172 |
apply (subst ubasis_until_same)
|
|
173 |
apply (erule (3) prems)
|
|
174 |
apply (erule (2) ubasis_le_upper)
|
|
175 |
done
|
|
176 |
|
|
177 |
lemma finite_range_ubasis_until:
|
|
178 |
"finite {x. P x} \<Longrightarrow> finite (range (ubasis_until P))"
|
|
179 |
apply (rule finite_subset [where B="insert 0 {x. P x}"])
|
|
180 |
apply (clarsimp simp add: ubasis_until')
|
|
181 |
apply simp
|
|
182 |
done
|
|
183 |
|
|
184 |
subsubsection {* Take function for @{typ ubasis} *}
|
|
185 |
|
|
186 |
definition
|
|
187 |
ubasis_take :: "nat \<Rightarrow> ubasis \<Rightarrow> ubasis"
|
|
188 |
where
|
|
189 |
"ubasis_take n = ubasis_until (\<lambda>x. x \<le> n)"
|
|
190 |
|
|
191 |
lemma ubasis_take_le: "ubasis_take n x \<le> n"
|
|
192 |
unfolding ubasis_take_def by (rule ubasis_until, rule le0)
|
|
193 |
|
|
194 |
lemma ubasis_take_same: "x \<le> n \<Longrightarrow> ubasis_take n x = x"
|
|
195 |
unfolding ubasis_take_def by (rule ubasis_until_same)
|
|
196 |
|
|
197 |
lemma ubasis_take_idem: "ubasis_take n (ubasis_take n x) = ubasis_take n x"
|
|
198 |
by (rule ubasis_take_same [OF ubasis_take_le])
|
|
199 |
|
|
200 |
lemma ubasis_take_0 [simp]: "ubasis_take 0 x = 0"
|
|
201 |
unfolding ubasis_take_def by (simp add: ubasis_until_0)
|
|
202 |
|
|
203 |
lemma ubasis_take_less: "ubasis_le (ubasis_take n x) x"
|
|
204 |
unfolding ubasis_take_def by (rule ubasis_until_less)
|
|
205 |
|
|
206 |
lemma ubasis_take_chain: "ubasis_le (ubasis_take n x) (ubasis_take (Suc n) x)"
|
|
207 |
unfolding ubasis_take_def by (rule ubasis_until_chain) simp
|
|
208 |
|
|
209 |
lemma ubasis_take_mono:
|
|
210 |
assumes "ubasis_le x y"
|
|
211 |
shows "ubasis_le (ubasis_take n x) (ubasis_take n y)"
|
|
212 |
unfolding ubasis_take_def
|
|
213 |
apply (rule ubasis_until_mono [OF _ prems])
|
|
214 |
apply (frule (2) order_less_le_trans [OF node_gt2])
|
|
215 |
apply (erule order_less_imp_le)
|
|
216 |
done
|
|
217 |
|
|
218 |
lemma finite_range_ubasis_take: "finite (range (ubasis_take n))"
|
|
219 |
apply (rule finite_subset [where B="{..n}"])
|
|
220 |
apply (simp add: subset_eq ubasis_take_le)
|
|
221 |
apply simp
|
|
222 |
done
|
|
223 |
|
|
224 |
lemma ubasis_take_covers: "\<exists>n. ubasis_take n x = x"
|
|
225 |
apply (rule exI [where x=x])
|
|
226 |
apply (simp add: ubasis_take_same)
|
|
227 |
done
|
|
228 |
|
29237
|
229 |
interpretation udom!: preorder ubasis_le
|
27411
|
230 |
apply default
|
|
231 |
apply (rule ubasis_le_refl)
|
|
232 |
apply (erule (1) ubasis_le_trans)
|
|
233 |
done
|
|
234 |
|
29237
|
235 |
interpretation udom!: basis_take ubasis_le ubasis_take
|
27411
|
236 |
apply default
|
|
237 |
apply (rule ubasis_take_less)
|
|
238 |
apply (rule ubasis_take_idem)
|
|
239 |
apply (erule ubasis_take_mono)
|
|
240 |
apply (rule ubasis_take_chain)
|
|
241 |
apply (rule finite_range_ubasis_take)
|
|
242 |
apply (rule ubasis_take_covers)
|
|
243 |
done
|
|
244 |
|
|
245 |
subsection {* Defining the universal domain by ideal completion *}
|
|
246 |
|
|
247 |
typedef (open) udom = "{S. udom.ideal S}"
|
|
248 |
by (fast intro: udom.ideal_principal)
|
|
249 |
|
|
250 |
instantiation udom :: sq_ord
|
|
251 |
begin
|
|
252 |
|
|
253 |
definition
|
|
254 |
"x \<sqsubseteq> y \<longleftrightarrow> Rep_udom x \<subseteq> Rep_udom y"
|
|
255 |
|
|
256 |
instance ..
|
|
257 |
end
|
|
258 |
|
|
259 |
instance udom :: po
|
|
260 |
by (rule udom.typedef_ideal_po
|
|
261 |
[OF type_definition_udom sq_le_udom_def])
|
|
262 |
|
|
263 |
instance udom :: cpo
|
|
264 |
by (rule udom.typedef_ideal_cpo
|
|
265 |
[OF type_definition_udom sq_le_udom_def])
|
|
266 |
|
|
267 |
lemma Rep_udom_lub:
|
|
268 |
"chain Y \<Longrightarrow> Rep_udom (\<Squnion>i. Y i) = (\<Union>i. Rep_udom (Y i))"
|
|
269 |
by (rule udom.typedef_ideal_rep_contlub
|
|
270 |
[OF type_definition_udom sq_le_udom_def])
|
|
271 |
|
|
272 |
lemma ideal_Rep_udom: "udom.ideal (Rep_udom xs)"
|
|
273 |
by (rule Rep_udom [unfolded mem_Collect_eq])
|
|
274 |
|
|
275 |
definition
|
|
276 |
udom_principal :: "nat \<Rightarrow> udom" where
|
|
277 |
"udom_principal t = Abs_udom {u. ubasis_le u t}"
|
|
278 |
|
|
279 |
lemma Rep_udom_principal:
|
|
280 |
"Rep_udom (udom_principal t) = {u. ubasis_le u t}"
|
|
281 |
unfolding udom_principal_def
|
|
282 |
by (simp add: Abs_udom_inverse udom.ideal_principal)
|
|
283 |
|
29237
|
284 |
interpretation udom!:
|
|
285 |
ideal_completion ubasis_le ubasis_take udom_principal Rep_udom
|
27411
|
286 |
apply unfold_locales
|
|
287 |
apply (rule ideal_Rep_udom)
|
|
288 |
apply (erule Rep_udom_lub)
|
|
289 |
apply (rule Rep_udom_principal)
|
|
290 |
apply (simp only: sq_le_udom_def)
|
|
291 |
done
|
|
292 |
|
|
293 |
text {* Universal domain is pointed *}
|
|
294 |
|
|
295 |
lemma udom_minimal: "udom_principal 0 \<sqsubseteq> x"
|
|
296 |
apply (induct x rule: udom.principal_induct)
|
|
297 |
apply (simp, simp add: ubasis_le_minimal)
|
|
298 |
done
|
|
299 |
|
|
300 |
instance udom :: pcpo
|
|
301 |
by intro_classes (fast intro: udom_minimal)
|
|
302 |
|
|
303 |
lemma inst_udom_pcpo: "\<bottom> = udom_principal 0"
|
|
304 |
by (rule udom_minimal [THEN UU_I, symmetric])
|
|
305 |
|
|
306 |
text {* Universal domain is bifinite *}
|
|
307 |
|
|
308 |
instantiation udom :: bifinite
|
|
309 |
begin
|
|
310 |
|
|
311 |
definition
|
|
312 |
approx_udom_def: "approx = udom.completion_approx"
|
|
313 |
|
|
314 |
instance
|
|
315 |
apply (intro_classes, unfold approx_udom_def)
|
|
316 |
apply (rule udom.chain_completion_approx)
|
|
317 |
apply (rule udom.lub_completion_approx)
|
|
318 |
apply (rule udom.completion_approx_idem)
|
|
319 |
apply (rule udom.finite_fixes_completion_approx)
|
|
320 |
done
|
|
321 |
|
|
322 |
end
|
|
323 |
|
|
324 |
lemma approx_udom_principal [simp]:
|
|
325 |
"approx n\<cdot>(udom_principal x) = udom_principal (ubasis_take n x)"
|
|
326 |
unfolding approx_udom_def
|
|
327 |
by (rule udom.completion_approx_principal)
|
|
328 |
|
|
329 |
lemma approx_eq_udom_principal:
|
|
330 |
"\<exists>a\<in>Rep_udom x. approx n\<cdot>x = udom_principal (ubasis_take n a)"
|
|
331 |
unfolding approx_udom_def
|
|
332 |
by (rule udom.completion_approx_eq_principal)
|
|
333 |
|
|
334 |
|
|
335 |
subsection {* Universality of @{typ udom} *}
|
|
336 |
|
|
337 |
defaultsort bifinite
|
|
338 |
|
|
339 |
subsubsection {* Choosing a maximal element from a finite set *}
|
|
340 |
|
|
341 |
lemma finite_has_maximal:
|
|
342 |
fixes A :: "'a::po set"
|
|
343 |
shows "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> \<exists>x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y"
|
|
344 |
proof (induct rule: finite_ne_induct)
|
|
345 |
case (singleton x)
|
|
346 |
show ?case by simp
|
|
347 |
next
|
|
348 |
case (insert a A)
|
|
349 |
from `\<exists>x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y`
|
|
350 |
obtain x where x: "x \<in> A"
|
|
351 |
and x_eq: "\<And>y. \<lbrakk>y \<in> A; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> x = y" by fast
|
|
352 |
show ?case
|
|
353 |
proof (intro bexI ballI impI)
|
|
354 |
fix y
|
|
355 |
assume "y \<in> insert a A" and "(if x \<sqsubseteq> a then a else x) \<sqsubseteq> y"
|
|
356 |
thus "(if x \<sqsubseteq> a then a else x) = y"
|
|
357 |
apply auto
|
|
358 |
apply (frule (1) trans_less)
|
|
359 |
apply (frule (1) x_eq)
|
|
360 |
apply (rule antisym_less, assumption)
|
|
361 |
apply simp
|
|
362 |
apply (erule (1) x_eq)
|
|
363 |
done
|
|
364 |
next
|
|
365 |
show "(if x \<sqsubseteq> a then a else x) \<in> insert a A"
|
|
366 |
by (simp add: x)
|
|
367 |
qed
|
|
368 |
qed
|
|
369 |
|
|
370 |
definition
|
|
371 |
choose :: "'a compact_basis set \<Rightarrow> 'a compact_basis"
|
|
372 |
where
|
|
373 |
"choose A = (SOME x. x \<in> {x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y})"
|
|
374 |
|
|
375 |
lemma choose_lemma:
|
|
376 |
"\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> choose A \<in> {x\<in>A. \<forall>y\<in>A. x \<sqsubseteq> y \<longrightarrow> x = y}"
|
|
377 |
unfolding choose_def
|
|
378 |
apply (rule someI_ex)
|
|
379 |
apply (frule (1) finite_has_maximal, fast)
|
|
380 |
done
|
|
381 |
|
|
382 |
lemma maximal_choose:
|
|
383 |
"\<lbrakk>finite A; y \<in> A; choose A \<sqsubseteq> y\<rbrakk> \<Longrightarrow> choose A = y"
|
|
384 |
apply (cases "A = {}", simp)
|
|
385 |
apply (frule (1) choose_lemma, simp)
|
|
386 |
done
|
|
387 |
|
|
388 |
lemma choose_in: "\<lbrakk>finite A; A \<noteq> {}\<rbrakk> \<Longrightarrow> choose A \<in> A"
|
|
389 |
by (frule (1) choose_lemma, simp)
|
|
390 |
|
|
391 |
function
|
|
392 |
choose_pos :: "'a compact_basis set \<Rightarrow> 'a compact_basis \<Rightarrow> nat"
|
|
393 |
where
|
|
394 |
"choose_pos A x =
|
|
395 |
(if finite A \<and> x \<in> A \<and> x \<noteq> choose A
|
|
396 |
then Suc (choose_pos (A - {choose A}) x) else 0)"
|
|
397 |
by auto
|
|
398 |
|
|
399 |
termination choose_pos
|
|
400 |
apply (relation "measure (card \<circ> fst)", simp)
|
|
401 |
apply clarsimp
|
|
402 |
apply (rule card_Diff1_less)
|
|
403 |
apply assumption
|
|
404 |
apply (erule choose_in)
|
|
405 |
apply clarsimp
|
|
406 |
done
|
|
407 |
|
|
408 |
declare choose_pos.simps [simp del]
|
|
409 |
|
|
410 |
lemma choose_pos_choose: "finite A \<Longrightarrow> choose_pos A (choose A) = 0"
|
|
411 |
by (simp add: choose_pos.simps)
|
|
412 |
|
|
413 |
lemma inj_on_choose_pos [OF refl]:
|
|
414 |
"\<lbrakk>card A = n; finite A\<rbrakk> \<Longrightarrow> inj_on (choose_pos A) A"
|
|
415 |
apply (induct n arbitrary: A)
|
|
416 |
apply simp
|
|
417 |
apply (case_tac "A = {}", simp)
|
|
418 |
apply (frule (1) choose_in)
|
|
419 |
apply (rule inj_onI)
|
|
420 |
apply (drule_tac x="A - {choose A}" in meta_spec, simp)
|
|
421 |
apply (simp add: choose_pos.simps)
|
|
422 |
apply (simp split: split_if_asm)
|
|
423 |
apply (erule (1) inj_onD, simp, simp)
|
|
424 |
done
|
|
425 |
|
|
426 |
lemma choose_pos_bounded [OF refl]:
|
|
427 |
"\<lbrakk>card A = n; finite A; x \<in> A\<rbrakk> \<Longrightarrow> choose_pos A x < n"
|
|
428 |
apply (induct n arbitrary: A)
|
|
429 |
apply simp
|
|
430 |
apply (case_tac "A = {}", simp)
|
|
431 |
apply (frule (1) choose_in)
|
|
432 |
apply (subst choose_pos.simps)
|
|
433 |
apply simp
|
|
434 |
done
|
|
435 |
|
|
436 |
lemma choose_pos_lessD:
|
|
437 |
"\<lbrakk>choose_pos A x < choose_pos A y; finite A; x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> \<not> x \<sqsubseteq> y"
|
|
438 |
apply (induct A x arbitrary: y rule: choose_pos.induct)
|
|
439 |
apply simp
|
|
440 |
apply (case_tac "x = choose A")
|
|
441 |
apply simp
|
|
442 |
apply (rule notI)
|
|
443 |
apply (frule (2) maximal_choose)
|
|
444 |
apply simp
|
|
445 |
apply (case_tac "y = choose A")
|
|
446 |
apply (simp add: choose_pos_choose)
|
|
447 |
apply (drule_tac x=y in meta_spec)
|
|
448 |
apply simp
|
|
449 |
apply (erule meta_mp)
|
|
450 |
apply (simp add: choose_pos.simps)
|
|
451 |
done
|
|
452 |
|
|
453 |
subsubsection {* Rank of basis elements *}
|
|
454 |
|
|
455 |
primrec
|
|
456 |
cb_take :: "nat \<Rightarrow> 'a compact_basis \<Rightarrow> 'a compact_basis"
|
|
457 |
where
|
|
458 |
"cb_take 0 = (\<lambda>x. compact_bot)"
|
|
459 |
| "cb_take (Suc n) = compact_take n"
|
|
460 |
|
|
461 |
lemma cb_take_covers: "\<exists>n. cb_take n x = x"
|
|
462 |
apply (rule exE [OF compact_basis.take_covers [where a=x]])
|
|
463 |
apply (rename_tac n, rule_tac x="Suc n" in exI, simp)
|
|
464 |
done
|
|
465 |
|
|
466 |
lemma cb_take_less: "cb_take n x \<sqsubseteq> x"
|
|
467 |
by (cases n, simp, simp add: compact_basis.take_less)
|
|
468 |
|
|
469 |
lemma cb_take_idem: "cb_take n (cb_take n x) = cb_take n x"
|
|
470 |
by (cases n, simp, simp add: compact_basis.take_take)
|
|
471 |
|
|
472 |
lemma cb_take_mono: "x \<sqsubseteq> y \<Longrightarrow> cb_take n x \<sqsubseteq> cb_take n y"
|
|
473 |
by (cases n, simp, simp add: compact_basis.take_mono)
|
|
474 |
|
|
475 |
lemma cb_take_chain_le: "m \<le> n \<Longrightarrow> cb_take m x \<sqsubseteq> cb_take n x"
|
|
476 |
apply (cases m, simp)
|
|
477 |
apply (cases n, simp)
|
|
478 |
apply (simp add: compact_basis.take_chain_le)
|
|
479 |
done
|
|
480 |
|
|
481 |
lemma range_const: "range (\<lambda>x. c) = {c}"
|
|
482 |
by auto
|
|
483 |
|
|
484 |
lemma finite_range_cb_take: "finite (range (cb_take n))"
|
|
485 |
apply (cases n)
|
|
486 |
apply (simp add: range_const)
|
|
487 |
apply (simp add: compact_basis.finite_range_take)
|
|
488 |
done
|
|
489 |
|
|
490 |
definition
|
|
491 |
rank :: "'a compact_basis \<Rightarrow> nat"
|
|
492 |
where
|
|
493 |
"rank x = (LEAST n. cb_take n x = x)"
|
|
494 |
|
|
495 |
lemma compact_approx_rank: "cb_take (rank x) x = x"
|
|
496 |
unfolding rank_def
|
|
497 |
apply (rule LeastI_ex)
|
|
498 |
apply (rule cb_take_covers)
|
|
499 |
done
|
|
500 |
|
|
501 |
lemma rank_leD: "rank x \<le> n \<Longrightarrow> cb_take n x = x"
|
|
502 |
apply (rule antisym_less [OF cb_take_less])
|
|
503 |
apply (subst compact_approx_rank [symmetric])
|
|
504 |
apply (erule cb_take_chain_le)
|
|
505 |
done
|
|
506 |
|
|
507 |
lemma rank_leI: "cb_take n x = x \<Longrightarrow> rank x \<le> n"
|
|
508 |
unfolding rank_def by (rule Least_le)
|
|
509 |
|
|
510 |
lemma rank_le_iff: "rank x \<le> n \<longleftrightarrow> cb_take n x = x"
|
|
511 |
by (rule iffI [OF rank_leD rank_leI])
|
|
512 |
|
30505
|
513 |
lemma rank_compact_bot [simp]: "rank compact_bot = 0"
|
|
514 |
using rank_leI [of 0 compact_bot] by simp
|
|
515 |
|
|
516 |
lemma rank_eq_0_iff [simp]: "rank x = 0 \<longleftrightarrow> x = compact_bot"
|
|
517 |
using rank_le_iff [of x 0] by auto
|
|
518 |
|
27411
|
519 |
definition
|
|
520 |
rank_le :: "'a compact_basis \<Rightarrow> 'a compact_basis set"
|
|
521 |
where
|
|
522 |
"rank_le x = {y. rank y \<le> rank x}"
|
|
523 |
|
|
524 |
definition
|
|
525 |
rank_lt :: "'a compact_basis \<Rightarrow> 'a compact_basis set"
|
|
526 |
where
|
|
527 |
"rank_lt x = {y. rank y < rank x}"
|
|
528 |
|
|
529 |
definition
|
|
530 |
rank_eq :: "'a compact_basis \<Rightarrow> 'a compact_basis set"
|
|
531 |
where
|
|
532 |
"rank_eq x = {y. rank y = rank x}"
|
|
533 |
|
|
534 |
lemma rank_eq_cong: "rank x = rank y \<Longrightarrow> rank_eq x = rank_eq y"
|
|
535 |
unfolding rank_eq_def by simp
|
|
536 |
|
|
537 |
lemma rank_lt_cong: "rank x = rank y \<Longrightarrow> rank_lt x = rank_lt y"
|
|
538 |
unfolding rank_lt_def by simp
|
|
539 |
|
|
540 |
lemma rank_eq_subset: "rank_eq x \<subseteq> rank_le x"
|
|
541 |
unfolding rank_eq_def rank_le_def by auto
|
|
542 |
|
|
543 |
lemma rank_lt_subset: "rank_lt x \<subseteq> rank_le x"
|
|
544 |
unfolding rank_lt_def rank_le_def by auto
|
|
545 |
|
|
546 |
lemma finite_rank_le: "finite (rank_le x)"
|
|
547 |
unfolding rank_le_def
|
|
548 |
apply (rule finite_subset [where B="range (cb_take (rank x))"])
|
|
549 |
apply clarify
|
|
550 |
apply (rule range_eqI)
|
|
551 |
apply (erule rank_leD [symmetric])
|
|
552 |
apply (rule finite_range_cb_take)
|
|
553 |
done
|
|
554 |
|
|
555 |
lemma finite_rank_eq: "finite (rank_eq x)"
|
|
556 |
by (rule finite_subset [OF rank_eq_subset finite_rank_le])
|
|
557 |
|
|
558 |
lemma finite_rank_lt: "finite (rank_lt x)"
|
|
559 |
by (rule finite_subset [OF rank_lt_subset finite_rank_le])
|
|
560 |
|
|
561 |
lemma rank_lt_Int_rank_eq: "rank_lt x \<inter> rank_eq x = {}"
|
|
562 |
unfolding rank_lt_def rank_eq_def rank_le_def by auto
|
|
563 |
|
|
564 |
lemma rank_lt_Un_rank_eq: "rank_lt x \<union> rank_eq x = rank_le x"
|
|
565 |
unfolding rank_lt_def rank_eq_def rank_le_def by auto
|
|
566 |
|
30505
|
567 |
subsubsection {* Sequencing basis elements *}
|
27411
|
568 |
|
|
569 |
definition
|
30505
|
570 |
place :: "'a compact_basis \<Rightarrow> nat"
|
27411
|
571 |
where
|
30505
|
572 |
"place x = card (rank_lt x) + choose_pos (rank_eq x) x"
|
27411
|
573 |
|
30505
|
574 |
lemma place_bounded: "place x < card (rank_le x)"
|
|
575 |
unfolding place_def
|
27411
|
576 |
apply (rule ord_less_eq_trans)
|
|
577 |
apply (rule add_strict_left_mono)
|
|
578 |
apply (rule choose_pos_bounded)
|
|
579 |
apply (rule finite_rank_eq)
|
|
580 |
apply (simp add: rank_eq_def)
|
|
581 |
apply (subst card_Un_disjoint [symmetric])
|
|
582 |
apply (rule finite_rank_lt)
|
|
583 |
apply (rule finite_rank_eq)
|
|
584 |
apply (rule rank_lt_Int_rank_eq)
|
|
585 |
apply (simp add: rank_lt_Un_rank_eq)
|
|
586 |
done
|
|
587 |
|
30505
|
588 |
lemma place_ge: "card (rank_lt x) \<le> place x"
|
|
589 |
unfolding place_def by simp
|
27411
|
590 |
|
30505
|
591 |
lemma place_rank_mono:
|
27411
|
592 |
fixes x y :: "'a compact_basis"
|
30505
|
593 |
shows "rank x < rank y \<Longrightarrow> place x < place y"
|
|
594 |
apply (rule less_le_trans [OF place_bounded])
|
|
595 |
apply (rule order_trans [OF _ place_ge])
|
27411
|
596 |
apply (rule card_mono)
|
|
597 |
apply (rule finite_rank_lt)
|
|
598 |
apply (simp add: rank_le_def rank_lt_def subset_eq)
|
|
599 |
done
|
|
600 |
|
30505
|
601 |
lemma place_eqD: "place x = place y \<Longrightarrow> x = y"
|
27411
|
602 |
apply (rule linorder_cases [where x="rank x" and y="rank y"])
|
30505
|
603 |
apply (drule place_rank_mono, simp)
|
|
604 |
apply (simp add: place_def)
|
27411
|
605 |
apply (rule inj_on_choose_pos [where A="rank_eq x", THEN inj_onD])
|
|
606 |
apply (rule finite_rank_eq)
|
|
607 |
apply (simp cong: rank_lt_cong rank_eq_cong)
|
|
608 |
apply (simp add: rank_eq_def)
|
|
609 |
apply (simp add: rank_eq_def)
|
30505
|
610 |
apply (drule place_rank_mono, simp)
|
27411
|
611 |
done
|
|
612 |
|
30505
|
613 |
lemma inj_place: "inj place"
|
|
614 |
by (rule inj_onI, erule place_eqD)
|
27411
|
615 |
|
|
616 |
subsubsection {* Embedding and projection on basis elements *}
|
|
617 |
|
30505
|
618 |
definition
|
|
619 |
sub :: "'a compact_basis \<Rightarrow> 'a compact_basis"
|
|
620 |
where
|
|
621 |
"sub x = (case rank x of 0 \<Rightarrow> compact_bot | Suc k \<Rightarrow> cb_take k x)"
|
|
622 |
|
|
623 |
lemma rank_sub_less: "x \<noteq> compact_bot \<Longrightarrow> rank (sub x) < rank x"
|
|
624 |
unfolding sub_def
|
|
625 |
apply (cases "rank x", simp)
|
|
626 |
apply (simp add: less_Suc_eq_le)
|
|
627 |
apply (rule rank_leI)
|
|
628 |
apply (rule cb_take_idem)
|
|
629 |
done
|
|
630 |
|
|
631 |
lemma place_sub_less: "x \<noteq> compact_bot \<Longrightarrow> place (sub x) < place x"
|
|
632 |
apply (rule place_rank_mono)
|
|
633 |
apply (erule rank_sub_less)
|
|
634 |
done
|
|
635 |
|
|
636 |
lemma sub_below: "sub x \<sqsubseteq> x"
|
|
637 |
unfolding sub_def by (cases "rank x", simp_all add: cb_take_less)
|
|
638 |
|
|
639 |
lemma rank_less_imp_below_sub: "\<lbrakk>x \<sqsubseteq> y; rank x < rank y\<rbrakk> \<Longrightarrow> x \<sqsubseteq> sub y"
|
|
640 |
unfolding sub_def
|
|
641 |
apply (cases "rank y", simp)
|
|
642 |
apply (simp add: less_Suc_eq_le)
|
|
643 |
apply (subgoal_tac "cb_take nat x \<sqsubseteq> cb_take nat y")
|
|
644 |
apply (simp add: rank_leD)
|
|
645 |
apply (erule cb_take_mono)
|
|
646 |
done
|
|
647 |
|
27411
|
648 |
function
|
|
649 |
basis_emb :: "'a compact_basis \<Rightarrow> ubasis"
|
|
650 |
where
|
|
651 |
"basis_emb x = (if x = compact_bot then 0 else
|
30505
|
652 |
node (place x) (basis_emb (sub x))
|
|
653 |
(basis_emb ` {y. place y < place x \<and> x \<sqsubseteq> y}))"
|
27411
|
654 |
by auto
|
|
655 |
|
|
656 |
termination basis_emb
|
30505
|
657 |
apply (relation "measure place", simp)
|
|
658 |
apply (simp add: place_sub_less)
|
27411
|
659 |
apply simp
|
|
660 |
done
|
|
661 |
|
|
662 |
declare basis_emb.simps [simp del]
|
|
663 |
|
|
664 |
lemma basis_emb_compact_bot [simp]: "basis_emb compact_bot = 0"
|
|
665 |
by (simp add: basis_emb.simps)
|
|
666 |
|
30505
|
667 |
lemma fin1: "finite {y. place y < place x \<and> x \<sqsubseteq> y}"
|
27411
|
668 |
apply (subst Collect_conj_eq)
|
|
669 |
apply (rule finite_Int)
|
|
670 |
apply (rule disjI1)
|
30505
|
671 |
apply (subgoal_tac "finite (place -` {n. n < place x})", simp)
|
|
672 |
apply (rule finite_vimageI [OF _ inj_place])
|
27411
|
673 |
apply (simp add: lessThan_def [symmetric])
|
|
674 |
done
|
|
675 |
|
30505
|
676 |
lemma fin2: "finite (basis_emb ` {y. place y < place x \<and> x \<sqsubseteq> y})"
|
27411
|
677 |
by (rule finite_imageI [OF fin1])
|
|
678 |
|
30505
|
679 |
lemma rank_place_mono:
|
|
680 |
"\<lbrakk>place x < place y; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> rank x < rank y"
|
|
681 |
apply (rule linorder_cases, assumption)
|
|
682 |
apply (simp add: place_def cong: rank_lt_cong rank_eq_cong)
|
|
683 |
apply (drule choose_pos_lessD)
|
|
684 |
apply (rule finite_rank_eq)
|
|
685 |
apply (simp add: rank_eq_def)
|
|
686 |
apply (simp add: rank_eq_def)
|
|
687 |
apply simp
|
|
688 |
apply (drule place_rank_mono, simp)
|
|
689 |
done
|
|
690 |
|
|
691 |
lemma basis_emb_mono:
|
|
692 |
"x \<sqsubseteq> y \<Longrightarrow> ubasis_le (basis_emb x) (basis_emb y)"
|
|
693 |
proof (induct n \<equiv> "max (place x) (place y)" arbitrary: x y rule: less_induct)
|
27411
|
694 |
case (less n)
|
30505
|
695 |
hence IH:
|
|
696 |
"\<And>(a::'a compact_basis) b.
|
|
697 |
\<lbrakk>max (place a) (place b) < max (place x) (place y); a \<sqsubseteq> b\<rbrakk>
|
|
698 |
\<Longrightarrow> ubasis_le (basis_emb a) (basis_emb b)"
|
|
699 |
by simp
|
|
700 |
show ?case proof (rule linorder_cases)
|
|
701 |
assume "place x < place y"
|
|
702 |
then have "rank x < rank y"
|
|
703 |
using `x \<sqsubseteq> y` by (rule rank_place_mono)
|
|
704 |
with `place x < place y` show ?case
|
|
705 |
apply (case_tac "y = compact_bot", simp)
|
|
706 |
apply (simp add: basis_emb.simps [of y])
|
|
707 |
apply (rule ubasis_le_trans [OF _ ubasis_le_lower [OF fin2]])
|
|
708 |
apply (rule IH)
|
|
709 |
apply (simp add: less_max_iff_disj)
|
|
710 |
apply (erule place_sub_less)
|
|
711 |
apply (erule rank_less_imp_below_sub [OF `x \<sqsubseteq> y`])
|
27411
|
712 |
done
|
30505
|
713 |
next
|
|
714 |
assume "place x = place y"
|
|
715 |
hence "x = y" by (rule place_eqD)
|
|
716 |
thus ?case by (simp add: ubasis_le_refl)
|
|
717 |
next
|
|
718 |
assume "place x > place y"
|
|
719 |
with `x \<sqsubseteq> y` show ?case
|
|
720 |
apply (case_tac "x = compact_bot", simp add: ubasis_le_minimal)
|
|
721 |
apply (simp add: basis_emb.simps [of x])
|
|
722 |
apply (rule ubasis_le_upper [OF fin2], simp)
|
|
723 |
apply (rule IH)
|
|
724 |
apply (simp add: less_max_iff_disj)
|
|
725 |
apply (erule place_sub_less)
|
|
726 |
apply (erule rev_trans_less)
|
|
727 |
apply (rule sub_below)
|
|
728 |
done
|
27411
|
729 |
qed
|
|
730 |
qed
|
|
731 |
|
|
732 |
lemma inj_basis_emb: "inj basis_emb"
|
|
733 |
apply (rule inj_onI)
|
|
734 |
apply (case_tac "x = compact_bot")
|
|
735 |
apply (case_tac [!] "y = compact_bot")
|
|
736 |
apply simp
|
|
737 |
apply (simp add: basis_emb.simps)
|
|
738 |
apply (simp add: basis_emb.simps)
|
|
739 |
apply (simp add: basis_emb.simps)
|
30505
|
740 |
apply (simp add: fin2 inj_eq [OF inj_place])
|
27411
|
741 |
done
|
|
742 |
|
|
743 |
definition
|
30505
|
744 |
basis_prj :: "ubasis \<Rightarrow> 'a compact_basis"
|
27411
|
745 |
where
|
|
746 |
"basis_prj x = inv basis_emb
|
30505
|
747 |
(ubasis_until (\<lambda>x. x \<in> range (basis_emb :: 'a compact_basis \<Rightarrow> ubasis)) x)"
|
27411
|
748 |
|
|
749 |
lemma basis_prj_basis_emb: "\<And>x. basis_prj (basis_emb x) = x"
|
|
750 |
unfolding basis_prj_def
|
|
751 |
apply (subst ubasis_until_same)
|
|
752 |
apply (rule rangeI)
|
|
753 |
apply (rule inv_f_f)
|
|
754 |
apply (rule inj_basis_emb)
|
|
755 |
done
|
|
756 |
|
|
757 |
lemma basis_prj_node:
|
30505
|
758 |
"\<lbrakk>finite S; node i a S \<notin> range (basis_emb :: 'a compact_basis \<Rightarrow> nat)\<rbrakk>
|
|
759 |
\<Longrightarrow> basis_prj (node i a S) = (basis_prj a :: 'a compact_basis)"
|
27411
|
760 |
unfolding basis_prj_def by simp
|
|
761 |
|
|
762 |
lemma basis_prj_0: "basis_prj 0 = compact_bot"
|
|
763 |
apply (subst basis_emb_compact_bot [symmetric])
|
|
764 |
apply (rule basis_prj_basis_emb)
|
|
765 |
done
|
|
766 |
|
30505
|
767 |
lemma node_eq_basis_emb_iff:
|
|
768 |
"finite S \<Longrightarrow> node i a S = basis_emb x \<longleftrightarrow>
|
|
769 |
x \<noteq> compact_bot \<and> i = place x \<and> a = basis_emb (sub x) \<and>
|
|
770 |
S = basis_emb ` {y. place y < place x \<and> x \<sqsubseteq> y}"
|
|
771 |
apply (cases "x = compact_bot", simp)
|
|
772 |
apply (simp add: basis_emb.simps [of x])
|
|
773 |
apply (simp add: fin2)
|
27411
|
774 |
done
|
|
775 |
|
30505
|
776 |
lemma basis_prj_mono: "ubasis_le a b \<Longrightarrow> basis_prj a \<sqsubseteq> basis_prj b"
|
|
777 |
proof (induct a b rule: ubasis_le.induct)
|
|
778 |
case (ubasis_le_refl a) show ?case by (rule refl_less)
|
|
779 |
next
|
|
780 |
case (ubasis_le_trans a b c) thus ?case by - (rule trans_less)
|
|
781 |
next
|
|
782 |
case (ubasis_le_lower S a i) thus ?case
|
|
783 |
apply (case_tac "node i a S \<in> range (basis_emb :: 'a compact_basis \<Rightarrow> nat)")
|
|
784 |
apply (erule rangeE, rename_tac x)
|
|
785 |
apply (simp add: basis_prj_basis_emb)
|
|
786 |
apply (simp add: node_eq_basis_emb_iff)
|
|
787 |
apply (simp add: basis_prj_basis_emb)
|
|
788 |
apply (rule sub_below)
|
|
789 |
apply (simp add: basis_prj_node)
|
|
790 |
done
|
|
791 |
next
|
|
792 |
case (ubasis_le_upper S b a i) thus ?case
|
|
793 |
apply (case_tac "node i a S \<in> range (basis_emb :: 'a compact_basis \<Rightarrow> nat)")
|
|
794 |
apply (erule rangeE, rename_tac x)
|
|
795 |
apply (simp add: basis_prj_basis_emb)
|
|
796 |
apply (clarsimp simp add: node_eq_basis_emb_iff)
|
|
797 |
apply (simp add: basis_prj_basis_emb)
|
|
798 |
apply (simp add: basis_prj_node)
|
|
799 |
done
|
|
800 |
qed
|
|
801 |
|
27411
|
802 |
lemma basis_emb_prj_less: "ubasis_le (basis_emb (basis_prj x)) x"
|
|
803 |
unfolding basis_prj_def
|
|
804 |
apply (subst f_inv_f [where f=basis_emb])
|
|
805 |
apply (rule ubasis_until)
|
|
806 |
apply (rule range_eqI [where x=compact_bot])
|
|
807 |
apply simp
|
|
808 |
apply (rule ubasis_until_less)
|
|
809 |
done
|
|
810 |
|
|
811 |
hide (open) const
|
|
812 |
node
|
|
813 |
choose
|
|
814 |
choose_pos
|
30505
|
815 |
place
|
|
816 |
sub
|
27411
|
817 |
|
|
818 |
subsubsection {* EP-pair from any bifinite domain into @{typ udom} *}
|
|
819 |
|
|
820 |
definition
|
|
821 |
udom_emb :: "'a::bifinite \<rightarrow> udom"
|
|
822 |
where
|
|
823 |
"udom_emb = compact_basis.basis_fun (\<lambda>x. udom_principal (basis_emb x))"
|
|
824 |
|
|
825 |
definition
|
|
826 |
udom_prj :: "udom \<rightarrow> 'a::bifinite"
|
|
827 |
where
|
|
828 |
"udom_prj = udom.basis_fun (\<lambda>x. Rep_compact_basis (basis_prj x))"
|
|
829 |
|
|
830 |
lemma udom_emb_principal:
|
|
831 |
"udom_emb\<cdot>(Rep_compact_basis x) = udom_principal (basis_emb x)"
|
|
832 |
unfolding udom_emb_def
|
|
833 |
apply (rule compact_basis.basis_fun_principal)
|
|
834 |
apply (rule udom.principal_mono)
|
|
835 |
apply (erule basis_emb_mono)
|
|
836 |
done
|
|
837 |
|
|
838 |
lemma udom_prj_principal:
|
|
839 |
"udom_prj\<cdot>(udom_principal x) = Rep_compact_basis (basis_prj x)"
|
|
840 |
unfolding udom_prj_def
|
|
841 |
apply (rule udom.basis_fun_principal)
|
|
842 |
apply (rule compact_basis.principal_mono)
|
|
843 |
apply (erule basis_prj_mono)
|
|
844 |
done
|
|
845 |
|
|
846 |
lemma ep_pair_udom: "ep_pair udom_emb udom_prj"
|
|
847 |
apply default
|
|
848 |
apply (rule compact_basis.principal_induct, simp)
|
|
849 |
apply (simp add: udom_emb_principal udom_prj_principal)
|
|
850 |
apply (simp add: basis_prj_basis_emb)
|
|
851 |
apply (rule udom.principal_induct, simp)
|
|
852 |
apply (simp add: udom_emb_principal udom_prj_principal)
|
|
853 |
apply (rule basis_emb_prj_less)
|
|
854 |
done
|
|
855 |
|
|
856 |
end
|