1 (* Title: HOLCF/Bifinite.thy
6 header {* Bifinite domains and approximation *}
12 subsection {* Bifinite domains *}
16 consts approx :: "nat \<Rightarrow> 'a::approx \<rightarrow> 'a"
18 axclass bifinite < approx
19 chain_approx_app: "chain (\<lambda>i. approx i\<cdot>x)"
20 lub_approx_app [simp]: "(\<Squnion>i. approx i\<cdot>x) = x"
21 approx_idem: "approx i\<cdot>(approx i\<cdot>x) = approx i\<cdot>x"
22 finite_fixes_approx: "finite {x. approx i\<cdot>x = x}"
24 lemma finite_range_imp_finite_fixes:
25 "finite {x. \<exists>y. x = f y} \<Longrightarrow> finite {x. f x = x}"
26 apply (subgoal_tac "{x. f x = x} \<subseteq> {x. \<exists>y. x = f y}")
27 apply (erule (1) finite_subset)
28 apply (clarify, erule subst, rule exI, rule refl)
31 lemma chain_approx [simp]:
32 "chain (approx :: nat \<Rightarrow> 'a::bifinite \<rightarrow> 'a)"
34 apply (rule less_cfun_ext)
36 apply (rule chain_approx_app)
39 lemma lub_approx [simp]: "(\<Squnion>i. approx i) = (\<Lambda>(x::'a::bifinite). x)"
40 by (rule ext_cfun, simp add: contlub_cfun_fun)
42 lemma approx_less: "approx i\<cdot>x \<sqsubseteq> (x::'a::bifinite)"
43 apply (subgoal_tac "approx i\<cdot>x \<sqsubseteq> (\<Squnion>i. approx i\<cdot>x)", simp)
44 apply (rule is_ub_thelub, simp)
47 lemma approx_strict [simp]: "approx i\<cdot>(\<bottom>::'a::bifinite) = \<bottom>"
48 by (rule UU_I, rule approx_less)
51 "i \<le> j \<Longrightarrow> approx i\<cdot>(approx j\<cdot>x) = approx i\<cdot>(x::'a::bifinite)"
52 apply (rule antisym_less)
53 apply (rule monofun_cfun_arg [OF approx_less])
54 apply (rule sq_ord_eq_less_trans [OF approx_idem [symmetric]])
55 apply (rule monofun_cfun_arg)
56 apply (rule monofun_cfun_fun)
57 apply (erule chain_mono3 [OF chain_approx])
61 "j \<le> i \<Longrightarrow> approx i\<cdot>(approx j\<cdot>x) = approx j\<cdot>(x::'a::bifinite)"
62 apply (rule antisym_less)
63 apply (rule approx_less)
64 apply (rule sq_ord_eq_less_trans [OF approx_idem [symmetric]])
65 apply (rule monofun_cfun_fun)
66 apply (erule chain_mono3 [OF chain_approx])
69 lemma approx_approx [simp]:
70 "approx i\<cdot>(approx j\<cdot>x) = approx (min i j)\<cdot>(x::'a::bifinite)"
71 apply (rule_tac x=i and y=j in linorder_le_cases)
72 apply (simp add: approx_approx1 min_def)
73 apply (simp add: approx_approx2 min_def)
76 lemma idem_fixes_eq_range:
77 "\<forall>x. f (f x) = f x \<Longrightarrow> {x. f x = x} = {y. \<exists>x. y = f x}"
78 by (auto simp add: eq_sym_conv)
80 lemma finite_approx: "finite {y::'a::bifinite. \<exists>x. y = approx n\<cdot>x}"
81 using finite_fixes_approx by (simp add: idem_fixes_eq_range)
83 lemma finite_range_approx:
84 "finite (range (\<lambda>x::'a::bifinite. approx n\<cdot>x))"
85 by (simp add: image_def finite_approx)
87 lemma compact_approx [simp]:
88 fixes x :: "'a::bifinite"
89 shows "compact (approx n\<cdot>x)"
90 proof (rule compactI2)
91 fix Y::"nat \<Rightarrow> 'a"
93 have "finite_chain (\<lambda>i. approx n\<cdot>(Y i))"
94 proof (rule finite_range_imp_finch)
95 show "chain (\<lambda>i. approx n\<cdot>(Y i))"
97 have "range (\<lambda>i. approx n\<cdot>(Y i)) \<subseteq> {x. approx n\<cdot>x = x}"
99 thus "finite (range (\<lambda>i. approx n\<cdot>(Y i)))"
100 using finite_fixes_approx by (rule finite_subset)
102 hence "\<exists>j. (\<Squnion>i. approx n\<cdot>(Y i)) = approx n\<cdot>(Y j)"
103 by (simp add: finite_chain_def maxinch_is_thelub Y)
104 then obtain j where j: "(\<Squnion>i. approx n\<cdot>(Y i)) = approx n\<cdot>(Y j)" ..
106 assume "approx n\<cdot>x \<sqsubseteq> (\<Squnion>i. Y i)"
107 hence "approx n\<cdot>(approx n\<cdot>x) \<sqsubseteq> approx n\<cdot>(\<Squnion>i. Y i)"
108 by (rule monofun_cfun_arg)
109 hence "approx n\<cdot>x \<sqsubseteq> (\<Squnion>i. approx n\<cdot>(Y i))"
110 by (simp add: contlub_cfun_arg Y)
111 hence "approx n\<cdot>x \<sqsubseteq> approx n\<cdot>(Y j)"
113 hence "approx n\<cdot>x \<sqsubseteq> Y j"
114 using approx_less by (rule trans_less)
115 thus "\<exists>j. approx n\<cdot>x \<sqsubseteq> Y j" ..
118 lemma bifinite_compact_eq_approx:
119 fixes x :: "'a::bifinite"
120 assumes x: "compact x"
121 shows "\<exists>i. approx i\<cdot>x = x"
123 have chain: "chain (\<lambda>i. approx i\<cdot>x)" by simp
124 have less: "x \<sqsubseteq> (\<Squnion>i. approx i\<cdot>x)" by simp
125 obtain i where i: "x \<sqsubseteq> approx i\<cdot>x"
126 using compactD2 [OF x chain less] ..
127 with approx_less have "approx i\<cdot>x = x"
128 by (rule antisym_less)
129 thus "\<exists>i. approx i\<cdot>x = x" ..
132 lemma bifinite_compact_iff:
133 "compact (x::'a::bifinite) = (\<exists>n. approx n\<cdot>x = x)"
135 apply (erule bifinite_compact_eq_approx)
138 apply (rule compact_approx)
142 assumes adm: "adm P" and P: "\<And>n x. P (approx n\<cdot>x)"
143 shows "P (x::'a::bifinite)"
145 have "P (\<Squnion>n. approx n\<cdot>x)"
146 by (rule admD [OF adm], simp, simp add: P)
150 lemma bifinite_less_ext:
151 fixes x y :: "'a::bifinite"
152 shows "(\<And>i. approx i\<cdot>x \<sqsubseteq> approx i\<cdot>y) \<Longrightarrow> x \<sqsubseteq> y"
153 apply (subgoal_tac "(\<Squnion>i. approx i\<cdot>x) \<sqsubseteq> (\<Squnion>i. approx i\<cdot>y)", simp)
154 apply (rule lub_mono [rule_format], simp, simp, simp)
157 subsection {* Instance for continuous function space *}
159 lemma finite_range_lemma:
160 fixes h :: "'a::cpo \<rightarrow> 'b::cpo"
161 fixes k :: "'c::cpo \<rightarrow> 'd::cpo"
162 shows "\<lbrakk>finite {y. \<exists>x. y = h\<cdot>x}; finite {y. \<exists>x. y = k\<cdot>x}\<rbrakk>
163 \<Longrightarrow> finite {g. \<exists>f. g = (\<Lambda> x. k\<cdot>(f\<cdot>(h\<cdot>x)))}"
164 apply (rule_tac f="\<lambda>g. {(h\<cdot>x, y) |x y. y = g\<cdot>x}" in finite_imageD)
165 apply (rule_tac B="Pow ({y. \<exists>x. y = h\<cdot>x} \<times> {y. \<exists>x. y = k\<cdot>x})"
167 apply (rule image_subsetI)
168 apply (clarsimp, fast)
171 apply (clarsimp simp add: expand_set_eq)
172 apply (rule ext_cfun, simp)
173 apply (drule_tac x="h\<cdot>x" in spec)
174 apply (drule_tac x="k\<cdot>(f\<cdot>(h\<cdot>x))" in spec)
175 apply (drule iffD1, fast)
179 instance "->" :: (bifinite, bifinite) approx ..
183 "approx \<equiv> \<lambda>n. \<Lambda> f x. approx n\<cdot>(f\<cdot>(approx n\<cdot>x))"
185 instance "->" :: (bifinite, bifinite) bifinite
186 apply (intro_classes, unfold approx_cfun_def)
188 apply (simp add: lub_distribs eta_cfun)
191 apply (rule finite_range_imp_finite_fixes)
192 apply (intro finite_range_lemma finite_approx)
195 lemma approx_cfun: "approx n\<cdot>f\<cdot>x = approx n\<cdot>(f\<cdot>(approx n\<cdot>x))"
196 by (simp add: approx_cfun_def)