| 27409 |      1 | (*  Title:      HOLCF/Algebraic.thy
 | 
|  |      2 |     Author:     Brian Huffman
 | 
|  |      3 | *)
 | 
|  |      4 | 
 | 
|  |      5 | header {* Algebraic deflations *}
 | 
|  |      6 | 
 | 
|  |      7 | theory Algebraic
 | 
|  |      8 | imports Completion Fix Eventual
 | 
|  |      9 | begin
 | 
|  |     10 | 
 | 
|  |     11 | subsection {* Constructing finite deflations by iteration *}
 | 
|  |     12 | 
 | 
|  |     13 | lemma finite_deflation_imp_deflation:
 | 
|  |     14 |   "finite_deflation d \<Longrightarrow> deflation d"
 | 
|  |     15 | unfolding finite_deflation_def by simp
 | 
|  |     16 | 
 | 
|  |     17 | lemma le_Suc_induct:
 | 
|  |     18 |   assumes le: "i \<le> j"
 | 
|  |     19 |   assumes step: "\<And>i. P i (Suc i)"
 | 
|  |     20 |   assumes refl: "\<And>i. P i i"
 | 
|  |     21 |   assumes trans: "\<And>i j k. \<lbrakk>P i j; P j k\<rbrakk> \<Longrightarrow> P i k"
 | 
|  |     22 |   shows "P i j"
 | 
|  |     23 | proof (cases "i = j")
 | 
|  |     24 |   assume "i = j"
 | 
|  |     25 |   thus "P i j" by (simp add: refl)
 | 
|  |     26 | next
 | 
|  |     27 |   assume "i \<noteq> j"
 | 
|  |     28 |   with le have "i < j" by simp
 | 
|  |     29 |   thus "P i j" using step trans by (rule less_Suc_induct)
 | 
|  |     30 | qed
 | 
|  |     31 | 
 | 
|  |     32 | text {* A pre-deflation is like a deflation, but not idempotent. *}
 | 
|  |     33 | 
 | 
|  |     34 | locale pre_deflation =
 | 
|  |     35 |   fixes f :: "'a \<rightarrow> 'a::cpo"
 | 
|  |     36 |   assumes less: "\<And>x. f\<cdot>x \<sqsubseteq> x"
 | 
|  |     37 |   assumes finite_range: "finite (range (\<lambda>x. f\<cdot>x))"
 | 
|  |     38 | begin
 | 
|  |     39 | 
 | 
|  |     40 | lemma iterate_less: "iterate i\<cdot>f\<cdot>x \<sqsubseteq> x"
 | 
|  |     41 | by (induct i, simp_all add: trans_less [OF less])
 | 
|  |     42 | 
 | 
|  |     43 | lemma iterate_fixed: "f\<cdot>x = x \<Longrightarrow> iterate i\<cdot>f\<cdot>x = x"
 | 
|  |     44 | by (induct i, simp_all)
 | 
|  |     45 | 
 | 
|  |     46 | lemma antichain_iterate_app: "i \<le> j \<Longrightarrow> iterate j\<cdot>f\<cdot>x \<sqsubseteq> iterate i\<cdot>f\<cdot>x"
 | 
|  |     47 | apply (erule le_Suc_induct)
 | 
|  |     48 | apply (simp add: less)
 | 
|  |     49 | apply (rule refl_less)
 | 
|  |     50 | apply (erule (1) trans_less)
 | 
|  |     51 | done
 | 
|  |     52 | 
 | 
|  |     53 | lemma finite_range_iterate_app: "finite (range (\<lambda>i. iterate i\<cdot>f\<cdot>x))"
 | 
|  |     54 | proof (rule finite_subset)
 | 
|  |     55 |   show "range (\<lambda>i. iterate i\<cdot>f\<cdot>x) \<subseteq> insert x (range (\<lambda>x. f\<cdot>x))"
 | 
|  |     56 |     by (clarify, case_tac i, simp_all)
 | 
|  |     57 |   show "finite (insert x (range (\<lambda>x. f\<cdot>x)))"
 | 
|  |     58 |     by (simp add: finite_range)
 | 
|  |     59 | qed
 | 
|  |     60 | 
 | 
|  |     61 | lemma eventually_constant_iterate_app:
 | 
|  |     62 |   "eventually_constant (\<lambda>i. iterate i\<cdot>f\<cdot>x)"
 | 
|  |     63 | unfolding eventually_constant_def MOST_nat_le
 | 
|  |     64 | proof -
 | 
|  |     65 |   let ?Y = "\<lambda>i. iterate i\<cdot>f\<cdot>x"
 | 
|  |     66 |   have "\<exists>j. \<forall>k. ?Y j \<sqsubseteq> ?Y k"
 | 
|  |     67 |     apply (rule finite_range_has_max)
 | 
|  |     68 |     apply (erule antichain_iterate_app)
 | 
|  |     69 |     apply (rule finite_range_iterate_app)
 | 
|  |     70 |     done
 | 
|  |     71 |   then obtain j where j: "\<And>k. ?Y j \<sqsubseteq> ?Y k" by fast
 | 
|  |     72 |   show "\<exists>z m. \<forall>n\<ge>m. ?Y n = z"
 | 
|  |     73 |   proof (intro exI allI impI)
 | 
|  |     74 |     fix k
 | 
|  |     75 |     assume "j \<le> k"
 | 
|  |     76 |     hence "?Y k \<sqsubseteq> ?Y j" by (rule antichain_iterate_app)
 | 
|  |     77 |     also have "?Y j \<sqsubseteq> ?Y k" by (rule j)
 | 
|  |     78 |     finally show "?Y k = ?Y j" .
 | 
|  |     79 |   qed
 | 
|  |     80 | qed
 | 
|  |     81 | 
 | 
|  |     82 | lemma eventually_constant_iterate:
 | 
|  |     83 |   "eventually_constant (\<lambda>n. iterate n\<cdot>f)"
 | 
|  |     84 | proof -
 | 
|  |     85 |   have "\<forall>y\<in>range (\<lambda>x. f\<cdot>x). eventually_constant (\<lambda>i. iterate i\<cdot>f\<cdot>y)"
 | 
|  |     86 |     by (simp add: eventually_constant_iterate_app)
 | 
|  |     87 |   hence "\<forall>y\<in>range (\<lambda>x. f\<cdot>x). MOST i. MOST j. iterate j\<cdot>f\<cdot>y = iterate i\<cdot>f\<cdot>y"
 | 
|  |     88 |     unfolding eventually_constant_MOST_MOST .
 | 
|  |     89 |   hence "MOST i. MOST j. \<forall>y\<in>range (\<lambda>x. f\<cdot>x). iterate j\<cdot>f\<cdot>y = iterate i\<cdot>f\<cdot>y"
 | 
|  |     90 |     by (simp only: MOST_finite_Ball_distrib [OF finite_range])
 | 
|  |     91 |   hence "MOST i. MOST j. \<forall>x. iterate j\<cdot>f\<cdot>(f\<cdot>x) = iterate i\<cdot>f\<cdot>(f\<cdot>x)"
 | 
|  |     92 |     by simp
 | 
|  |     93 |   hence "MOST i. MOST j. \<forall>x. iterate (Suc j)\<cdot>f\<cdot>x = iterate (Suc i)\<cdot>f\<cdot>x"
 | 
|  |     94 |     by (simp only: iterate_Suc2)
 | 
|  |     95 |   hence "MOST i. MOST j. iterate (Suc j)\<cdot>f = iterate (Suc i)\<cdot>f"
 | 
|  |     96 |     by (simp only: expand_cfun_eq)
 | 
|  |     97 |   hence "eventually_constant (\<lambda>i. iterate (Suc i)\<cdot>f)"
 | 
|  |     98 |     unfolding eventually_constant_MOST_MOST .
 | 
|  |     99 |   thus "eventually_constant (\<lambda>i. iterate i\<cdot>f)"
 | 
|  |    100 |     by (rule eventually_constant_SucD)
 | 
|  |    101 | qed
 | 
|  |    102 | 
 | 
|  |    103 | abbreviation
 | 
|  |    104 |   d :: "'a \<rightarrow> 'a"
 | 
|  |    105 | where
 | 
|  |    106 |   "d \<equiv> eventual (\<lambda>n. iterate n\<cdot>f)"
 | 
|  |    107 | 
 | 
|  |    108 | lemma MOST_d: "MOST n. P (iterate n\<cdot>f) \<Longrightarrow> P d"
 | 
|  |    109 | using eventually_constant_iterate by (rule MOST_eventual)
 | 
|  |    110 | 
 | 
|  |    111 | lemma f_d: "f\<cdot>(d\<cdot>x) = d\<cdot>x"
 | 
|  |    112 | apply (rule MOST_d)
 | 
|  |    113 | apply (subst iterate_Suc [symmetric])
 | 
|  |    114 | apply (rule eventually_constant_MOST_Suc_eq)
 | 
|  |    115 | apply (rule eventually_constant_iterate_app)
 | 
|  |    116 | done
 | 
|  |    117 | 
 | 
|  |    118 | lemma d_fixed_iff: "d\<cdot>x = x \<longleftrightarrow> f\<cdot>x = x"
 | 
|  |    119 | proof
 | 
|  |    120 |   assume "d\<cdot>x = x"
 | 
|  |    121 |   with f_d [where x=x]
 | 
|  |    122 |   show "f\<cdot>x = x" by simp
 | 
|  |    123 | next
 | 
|  |    124 |   assume f: "f\<cdot>x = x"
 | 
|  |    125 |   have "\<forall>n. iterate n\<cdot>f\<cdot>x = x"
 | 
|  |    126 |     by (rule allI, rule nat.induct, simp, simp add: f)
 | 
|  |    127 |   hence "MOST n. iterate n\<cdot>f\<cdot>x = x"
 | 
|  |    128 |     by (rule ALL_MOST)
 | 
|  |    129 |   thus "d\<cdot>x = x"
 | 
|  |    130 |     by (rule MOST_d)
 | 
|  |    131 | qed
 | 
|  |    132 | 
 | 
|  |    133 | lemma finite_deflation_d: "finite_deflation d"
 | 
|  |    134 | proof
 | 
|  |    135 |   fix x :: 'a
 | 
|  |    136 |   have "d \<in> range (\<lambda>n. iterate n\<cdot>f)"
 | 
|  |    137 |     using eventually_constant_iterate
 | 
|  |    138 |     by (rule eventual_mem_range)
 | 
|  |    139 |   then obtain n where n: "d = iterate n\<cdot>f" ..
 | 
|  |    140 |   have "iterate n\<cdot>f\<cdot>(d\<cdot>x) = d\<cdot>x"
 | 
|  |    141 |     using f_d by (rule iterate_fixed)
 | 
|  |    142 |   thus "d\<cdot>(d\<cdot>x) = d\<cdot>x"
 | 
|  |    143 |     by (simp add: n)
 | 
|  |    144 | next
 | 
|  |    145 |   fix x :: 'a
 | 
|  |    146 |   show "d\<cdot>x \<sqsubseteq> x"
 | 
|  |    147 |     by (rule MOST_d, simp add: iterate_less)
 | 
|  |    148 | next
 | 
|  |    149 |   from finite_range
 | 
|  |    150 |   have "finite {x. f\<cdot>x = x}"
 | 
|  |    151 |     by (rule finite_range_imp_finite_fixes)
 | 
|  |    152 |   thus "finite {x. d\<cdot>x = x}"
 | 
|  |    153 |     by (simp add: d_fixed_iff)
 | 
|  |    154 | qed
 | 
|  |    155 | 
 | 
|  |    156 | end
 | 
|  |    157 | 
 | 
|  |    158 | lemma pre_deflation_d_f:
 | 
| 28611 |    159 |   assumes "finite_deflation d"
 | 
| 27409 |    160 |   assumes f: "\<And>x. f\<cdot>x \<sqsubseteq> x"
 | 
|  |    161 |   shows "pre_deflation (d oo f)"
 | 
|  |    162 | proof
 | 
| 29237 |    163 |   interpret d: finite_deflation d by fact
 | 
| 27409 |    164 |   fix x
 | 
|  |    165 |   show "\<And>x. (d oo f)\<cdot>x \<sqsubseteq> x"
 | 
|  |    166 |     by (simp, rule trans_less [OF d.less f])
 | 
|  |    167 |   show "finite (range (\<lambda>x. (d oo f)\<cdot>x))"
 | 
|  |    168 |     by (rule finite_subset [OF _ d.finite_range], auto)
 | 
|  |    169 | qed
 | 
|  |    170 | 
 | 
|  |    171 | lemma eventual_iterate_oo_fixed_iff:
 | 
| 28611 |    172 |   assumes "finite_deflation d"
 | 
| 27409 |    173 |   assumes f: "\<And>x. f\<cdot>x \<sqsubseteq> x"
 | 
|  |    174 |   shows "eventual (\<lambda>n. iterate n\<cdot>(d oo f))\<cdot>x = x \<longleftrightarrow> d\<cdot>x = x \<and> f\<cdot>x = x"
 | 
|  |    175 | proof -
 | 
| 29237 |    176 |   interpret d: finite_deflation d by fact
 | 
| 27409 |    177 |   let ?e = "d oo f"
 | 
| 29237 |    178 |   interpret e: pre_deflation "d oo f"
 | 
| 27409 |    179 |     using `finite_deflation d` f
 | 
|  |    180 |     by (rule pre_deflation_d_f)
 | 
|  |    181 |   let ?g = "eventual (\<lambda>n. iterate n\<cdot>?e)"
 | 
|  |    182 |   show ?thesis
 | 
|  |    183 |     apply (subst e.d_fixed_iff)
 | 
|  |    184 |     apply simp
 | 
|  |    185 |     apply safe
 | 
|  |    186 |     apply (erule subst)
 | 
|  |    187 |     apply (rule d.idem)
 | 
|  |    188 |     apply (rule antisym_less)
 | 
|  |    189 |     apply (rule f)
 | 
|  |    190 |     apply (erule subst, rule d.less)
 | 
|  |    191 |     apply simp
 | 
|  |    192 |     done
 | 
|  |    193 | qed
 | 
|  |    194 | 
 | 
|  |    195 | subsection {* Type constructor for finite deflations *}
 | 
|  |    196 | 
 | 
|  |    197 | defaultsort profinite
 | 
|  |    198 | 
 | 
|  |    199 | typedef (open) 'a fin_defl = "{d::'a \<rightarrow> 'a. finite_deflation d}"
 | 
|  |    200 | by (fast intro: finite_deflation_approx)
 | 
|  |    201 | 
 | 
|  |    202 | instantiation fin_defl :: (profinite) sq_ord
 | 
|  |    203 | begin
 | 
|  |    204 | 
 | 
|  |    205 | definition
 | 
|  |    206 |   sq_le_fin_defl_def:
 | 
|  |    207 |     "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep_fin_defl x \<sqsubseteq> Rep_fin_defl y"
 | 
|  |    208 | 
 | 
|  |    209 | instance ..
 | 
|  |    210 | end
 | 
|  |    211 | 
 | 
|  |    212 | instance fin_defl :: (profinite) po
 | 
|  |    213 | by (rule typedef_po [OF type_definition_fin_defl sq_le_fin_defl_def])
 | 
|  |    214 | 
 | 
|  |    215 | lemma finite_deflation_Rep_fin_defl: "finite_deflation (Rep_fin_defl d)"
 | 
|  |    216 | using Rep_fin_defl by simp
 | 
|  |    217 | 
 | 
| 29237 |    218 | interpretation Rep_fin_defl!: finite_deflation "Rep_fin_defl d"
 | 
| 27409 |    219 | by (rule finite_deflation_Rep_fin_defl)
 | 
|  |    220 | 
 | 
|  |    221 | lemma fin_defl_lessI:
 | 
|  |    222 |   "(\<And>x. Rep_fin_defl a\<cdot>x = x \<Longrightarrow> Rep_fin_defl b\<cdot>x = x) \<Longrightarrow> a \<sqsubseteq> b"
 | 
|  |    223 | unfolding sq_le_fin_defl_def
 | 
|  |    224 | by (rule Rep_fin_defl.lessI)
 | 
|  |    225 | 
 | 
|  |    226 | lemma fin_defl_lessD:
 | 
|  |    227 |   "\<lbrakk>a \<sqsubseteq> b; Rep_fin_defl a\<cdot>x = x\<rbrakk> \<Longrightarrow> Rep_fin_defl b\<cdot>x = x"
 | 
|  |    228 | unfolding sq_le_fin_defl_def
 | 
|  |    229 | by (rule Rep_fin_defl.lessD)
 | 
|  |    230 | 
 | 
|  |    231 | lemma fin_defl_eqI:
 | 
|  |    232 |   "(\<And>x. Rep_fin_defl a\<cdot>x = x \<longleftrightarrow> Rep_fin_defl b\<cdot>x = x) \<Longrightarrow> a = b"
 | 
|  |    233 | apply (rule antisym_less)
 | 
|  |    234 | apply (rule fin_defl_lessI, simp)
 | 
|  |    235 | apply (rule fin_defl_lessI, simp)
 | 
|  |    236 | done
 | 
|  |    237 | 
 | 
|  |    238 | lemma Abs_fin_defl_mono:
 | 
|  |    239 |   "\<lbrakk>finite_deflation a; finite_deflation b; a \<sqsubseteq> b\<rbrakk>
 | 
|  |    240 |     \<Longrightarrow> Abs_fin_defl a \<sqsubseteq> Abs_fin_defl b"
 | 
|  |    241 | unfolding sq_le_fin_defl_def
 | 
|  |    242 | by (simp add: Abs_fin_defl_inverse)
 | 
|  |    243 | 
 | 
|  |    244 | 
 | 
|  |    245 | subsection {* Take function for finite deflations *}
 | 
|  |    246 | 
 | 
|  |    247 | definition
 | 
|  |    248 |   fd_take :: "nat \<Rightarrow> 'a fin_defl \<Rightarrow> 'a fin_defl"
 | 
|  |    249 | where
 | 
|  |    250 |   "fd_take i d = Abs_fin_defl (eventual (\<lambda>n. iterate n\<cdot>(approx i oo Rep_fin_defl d)))"
 | 
|  |    251 | 
 | 
|  |    252 | lemma Rep_fin_defl_fd_take:
 | 
|  |    253 |   "Rep_fin_defl (fd_take i d) =
 | 
|  |    254 |     eventual (\<lambda>n. iterate n\<cdot>(approx i oo Rep_fin_defl d))"
 | 
|  |    255 | unfolding fd_take_def
 | 
|  |    256 | apply (rule Abs_fin_defl_inverse [unfolded mem_Collect_eq])
 | 
|  |    257 | apply (rule pre_deflation.finite_deflation_d)
 | 
|  |    258 | apply (rule pre_deflation_d_f)
 | 
|  |    259 | apply (rule finite_deflation_approx)
 | 
|  |    260 | apply (rule Rep_fin_defl.less)
 | 
|  |    261 | done
 | 
|  |    262 | 
 | 
|  |    263 | lemma fd_take_fixed_iff:
 | 
|  |    264 |   "Rep_fin_defl (fd_take i d)\<cdot>x = x \<longleftrightarrow>
 | 
|  |    265 |     approx i\<cdot>x = x \<and> Rep_fin_defl d\<cdot>x = x"
 | 
|  |    266 | unfolding Rep_fin_defl_fd_take
 | 
|  |    267 | by (rule eventual_iterate_oo_fixed_iff
 | 
|  |    268 |     [OF finite_deflation_approx Rep_fin_defl.less])
 | 
|  |    269 | 
 | 
|  |    270 | lemma fd_take_less: "fd_take n d \<sqsubseteq> d"
 | 
|  |    271 | apply (rule fin_defl_lessI)
 | 
|  |    272 | apply (simp add: fd_take_fixed_iff)
 | 
|  |    273 | done
 | 
|  |    274 | 
 | 
|  |    275 | lemma fd_take_idem: "fd_take n (fd_take n d) = fd_take n d"
 | 
|  |    276 | apply (rule fin_defl_eqI)
 | 
|  |    277 | apply (simp add: fd_take_fixed_iff)
 | 
|  |    278 | done
 | 
|  |    279 | 
 | 
|  |    280 | lemma fd_take_mono: "a \<sqsubseteq> b \<Longrightarrow> fd_take n a \<sqsubseteq> fd_take n b"
 | 
|  |    281 | apply (rule fin_defl_lessI)
 | 
|  |    282 | apply (simp add: fd_take_fixed_iff)
 | 
|  |    283 | apply (simp add: fin_defl_lessD)
 | 
|  |    284 | done
 | 
|  |    285 | 
 | 
|  |    286 | lemma approx_fixed_le_lemma: "\<lbrakk>i \<le> j; approx i\<cdot>x = x\<rbrakk> \<Longrightarrow> approx j\<cdot>x = x"
 | 
|  |    287 | by (erule subst, simp add: min_def)
 | 
|  |    288 | 
 | 
|  |    289 | lemma fd_take_chain: "m \<le> n \<Longrightarrow> fd_take m a \<sqsubseteq> fd_take n a"
 | 
|  |    290 | apply (rule fin_defl_lessI)
 | 
|  |    291 | apply (simp add: fd_take_fixed_iff)
 | 
|  |    292 | apply (simp add: approx_fixed_le_lemma)
 | 
|  |    293 | done
 | 
|  |    294 | 
 | 
|  |    295 | lemma finite_range_fd_take: "finite (range (fd_take n))"
 | 
|  |    296 | apply (rule finite_imageD [where f="\<lambda>a. {x. Rep_fin_defl a\<cdot>x = x}"])
 | 
|  |    297 | apply (rule finite_subset [where B="Pow {x. approx n\<cdot>x = x}"])
 | 
|  |    298 | apply (clarify, simp add: fd_take_fixed_iff)
 | 
|  |    299 | apply (simp add: finite_fixes_approx)
 | 
|  |    300 | apply (rule inj_onI, clarify)
 | 
|  |    301 | apply (simp add: expand_set_eq fin_defl_eqI)
 | 
|  |    302 | done
 | 
|  |    303 | 
 | 
|  |    304 | lemma fd_take_covers: "\<exists>n. fd_take n a = a"
 | 
|  |    305 | apply (rule_tac x=
 | 
|  |    306 |   "Max ((\<lambda>x. LEAST n. approx n\<cdot>x = x) ` {x. Rep_fin_defl a\<cdot>x = x})" in exI)
 | 
|  |    307 | apply (rule antisym_less)
 | 
|  |    308 | apply (rule fd_take_less)
 | 
|  |    309 | apply (rule fin_defl_lessI)
 | 
|  |    310 | apply (simp add: fd_take_fixed_iff)
 | 
|  |    311 | apply (rule approx_fixed_le_lemma)
 | 
|  |    312 | apply (rule Max_ge)
 | 
|  |    313 | apply (rule finite_imageI)
 | 
|  |    314 | apply (rule Rep_fin_defl.finite_fixes)
 | 
|  |    315 | apply (rule imageI)
 | 
|  |    316 | apply (erule CollectI)
 | 
|  |    317 | apply (rule LeastI_ex)
 | 
|  |    318 | apply (rule profinite_compact_eq_approx)
 | 
|  |    319 | apply (erule subst)
 | 
|  |    320 | apply (rule Rep_fin_defl.compact)
 | 
|  |    321 | done
 | 
|  |    322 | 
 | 
| 29237 |    323 | interpretation fin_defl!: basis_take sq_le fd_take
 | 
| 27409 |    324 | apply default
 | 
|  |    325 | apply (rule fd_take_less)
 | 
|  |    326 | apply (rule fd_take_idem)
 | 
|  |    327 | apply (erule fd_take_mono)
 | 
|  |    328 | apply (rule fd_take_chain, simp)
 | 
|  |    329 | apply (rule finite_range_fd_take)
 | 
|  |    330 | apply (rule fd_take_covers)
 | 
|  |    331 | done
 | 
|  |    332 | 
 | 
|  |    333 | subsection {* Defining algebraic deflations by ideal completion *}
 | 
|  |    334 | 
 | 
|  |    335 | typedef (open) 'a alg_defl =
 | 
|  |    336 |   "{S::'a fin_defl set. sq_le.ideal S}"
 | 
|  |    337 | by (fast intro: sq_le.ideal_principal)
 | 
|  |    338 | 
 | 
|  |    339 | instantiation alg_defl :: (profinite) sq_ord
 | 
|  |    340 | begin
 | 
|  |    341 | 
 | 
|  |    342 | definition
 | 
|  |    343 |   "x \<sqsubseteq> y \<longleftrightarrow> Rep_alg_defl x \<subseteq> Rep_alg_defl y"
 | 
|  |    344 | 
 | 
|  |    345 | instance ..
 | 
|  |    346 | end
 | 
|  |    347 | 
 | 
|  |    348 | instance alg_defl :: (profinite) po
 | 
|  |    349 | by (rule sq_le.typedef_ideal_po
 | 
|  |    350 |     [OF type_definition_alg_defl sq_le_alg_defl_def])
 | 
|  |    351 | 
 | 
|  |    352 | instance alg_defl :: (profinite) cpo
 | 
|  |    353 | by (rule sq_le.typedef_ideal_cpo
 | 
|  |    354 |     [OF type_definition_alg_defl sq_le_alg_defl_def])
 | 
|  |    355 | 
 | 
|  |    356 | lemma Rep_alg_defl_lub:
 | 
|  |    357 |   "chain Y \<Longrightarrow> Rep_alg_defl (\<Squnion>i. Y i) = (\<Union>i. Rep_alg_defl (Y i))"
 | 
|  |    358 | by (rule sq_le.typedef_ideal_rep_contlub
 | 
|  |    359 |     [OF type_definition_alg_defl sq_le_alg_defl_def])
 | 
|  |    360 | 
 | 
|  |    361 | lemma ideal_Rep_alg_defl: "sq_le.ideal (Rep_alg_defl xs)"
 | 
|  |    362 | by (rule Rep_alg_defl [unfolded mem_Collect_eq])
 | 
|  |    363 | 
 | 
|  |    364 | definition
 | 
|  |    365 |   alg_defl_principal :: "'a fin_defl \<Rightarrow> 'a alg_defl" where
 | 
|  |    366 |   "alg_defl_principal t = Abs_alg_defl {u. u \<sqsubseteq> t}"
 | 
|  |    367 | 
 | 
|  |    368 | lemma Rep_alg_defl_principal:
 | 
|  |    369 |   "Rep_alg_defl (alg_defl_principal t) = {u. u \<sqsubseteq> t}"
 | 
|  |    370 | unfolding alg_defl_principal_def
 | 
|  |    371 | by (simp add: Abs_alg_defl_inverse sq_le.ideal_principal)
 | 
|  |    372 | 
 | 
| 29237 |    373 | interpretation alg_defl!:
 | 
|  |    374 |   ideal_completion sq_le fd_take alg_defl_principal Rep_alg_defl
 | 
| 27409 |    375 | apply default
 | 
|  |    376 | apply (rule ideal_Rep_alg_defl)
 | 
|  |    377 | apply (erule Rep_alg_defl_lub)
 | 
|  |    378 | apply (rule Rep_alg_defl_principal)
 | 
|  |    379 | apply (simp only: sq_le_alg_defl_def)
 | 
|  |    380 | done
 | 
|  |    381 | 
 | 
|  |    382 | text {* Algebraic deflations are pointed *}
 | 
|  |    383 | 
 | 
|  |    384 | lemma finite_deflation_UU: "finite_deflation \<bottom>"
 | 
|  |    385 | by default simp_all
 | 
|  |    386 | 
 | 
|  |    387 | lemma alg_defl_minimal:
 | 
|  |    388 |   "alg_defl_principal (Abs_fin_defl \<bottom>) \<sqsubseteq> x"
 | 
|  |    389 | apply (induct x rule: alg_defl.principal_induct, simp)
 | 
|  |    390 | apply (rule alg_defl.principal_mono)
 | 
|  |    391 | apply (induct_tac a)
 | 
|  |    392 | apply (rule Abs_fin_defl_mono)
 | 
|  |    393 | apply (rule finite_deflation_UU)
 | 
|  |    394 | apply simp
 | 
|  |    395 | apply (rule minimal)
 | 
|  |    396 | done
 | 
|  |    397 | 
 | 
|  |    398 | instance alg_defl :: (bifinite) pcpo
 | 
|  |    399 | by intro_classes (fast intro: alg_defl_minimal)
 | 
|  |    400 | 
 | 
|  |    401 | lemma inst_alg_defl_pcpo: "\<bottom> = alg_defl_principal (Abs_fin_defl \<bottom>)"
 | 
|  |    402 | by (rule alg_defl_minimal [THEN UU_I, symmetric])
 | 
|  |    403 | 
 | 
|  |    404 | text {* Algebraic deflations are profinite *}
 | 
|  |    405 | 
 | 
|  |    406 | instantiation alg_defl :: (profinite) profinite
 | 
|  |    407 | begin
 | 
|  |    408 | 
 | 
|  |    409 | definition
 | 
|  |    410 |   approx_alg_defl_def: "approx = alg_defl.completion_approx"
 | 
|  |    411 | 
 | 
|  |    412 | instance
 | 
|  |    413 | apply (intro_classes, unfold approx_alg_defl_def)
 | 
|  |    414 | apply (rule alg_defl.chain_completion_approx)
 | 
|  |    415 | apply (rule alg_defl.lub_completion_approx)
 | 
|  |    416 | apply (rule alg_defl.completion_approx_idem)
 | 
|  |    417 | apply (rule alg_defl.finite_fixes_completion_approx)
 | 
|  |    418 | done
 | 
|  |    419 | 
 | 
|  |    420 | end
 | 
|  |    421 | 
 | 
|  |    422 | instance alg_defl :: (bifinite) bifinite ..
 | 
|  |    423 | 
 | 
|  |    424 | lemma approx_alg_defl_principal [simp]:
 | 
|  |    425 |   "approx n\<cdot>(alg_defl_principal t) = alg_defl_principal (fd_take n t)"
 | 
|  |    426 | unfolding approx_alg_defl_def
 | 
|  |    427 | by (rule alg_defl.completion_approx_principal)
 | 
|  |    428 | 
 | 
|  |    429 | lemma approx_eq_alg_defl_principal:
 | 
|  |    430 |   "\<exists>t\<in>Rep_alg_defl xs. approx n\<cdot>xs = alg_defl_principal (fd_take n t)"
 | 
|  |    431 | unfolding approx_alg_defl_def
 | 
|  |    432 | by (rule alg_defl.completion_approx_eq_principal)
 | 
|  |    433 | 
 | 
|  |    434 | 
 | 
|  |    435 | subsection {* Applying algebraic deflations *}
 | 
|  |    436 | 
 | 
|  |    437 | definition
 | 
|  |    438 |   cast :: "'a alg_defl \<rightarrow> 'a \<rightarrow> 'a"
 | 
|  |    439 | where
 | 
|  |    440 |   "cast = alg_defl.basis_fun Rep_fin_defl"
 | 
|  |    441 | 
 | 
|  |    442 | lemma cast_alg_defl_principal:
 | 
|  |    443 |   "cast\<cdot>(alg_defl_principal a) = Rep_fin_defl a"
 | 
|  |    444 | unfolding cast_def
 | 
|  |    445 | apply (rule alg_defl.basis_fun_principal)
 | 
|  |    446 | apply (simp only: sq_le_fin_defl_def)
 | 
|  |    447 | done
 | 
|  |    448 | 
 | 
|  |    449 | lemma deflation_cast: "deflation (cast\<cdot>d)"
 | 
|  |    450 | apply (induct d rule: alg_defl.principal_induct)
 | 
|  |    451 | apply (rule adm_subst [OF _ adm_deflation], simp)
 | 
|  |    452 | apply (simp add: cast_alg_defl_principal)
 | 
|  |    453 | apply (rule finite_deflation_imp_deflation)
 | 
|  |    454 | apply (rule finite_deflation_Rep_fin_defl)
 | 
|  |    455 | done
 | 
|  |    456 | 
 | 
|  |    457 | lemma finite_deflation_cast:
 | 
|  |    458 |   "compact d \<Longrightarrow> finite_deflation (cast\<cdot>d)"
 | 
|  |    459 | apply (drule alg_defl.compact_imp_principal, clarify)
 | 
|  |    460 | apply (simp add: cast_alg_defl_principal)
 | 
|  |    461 | apply (rule finite_deflation_Rep_fin_defl)
 | 
|  |    462 | done
 | 
|  |    463 | 
 | 
| 29237 |    464 | interpretation cast!: deflation "cast\<cdot>d"
 | 
| 27409 |    465 | by (rule deflation_cast)
 | 
|  |    466 | 
 | 
|  |    467 | lemma "cast\<cdot>(\<Squnion>i. alg_defl_principal (Abs_fin_defl (approx i)))\<cdot>x = x"
 | 
|  |    468 | apply (subst contlub_cfun_arg)
 | 
|  |    469 | apply (rule chainI)
 | 
|  |    470 | apply (rule alg_defl.principal_mono)
 | 
|  |    471 | apply (rule Abs_fin_defl_mono)
 | 
|  |    472 | apply (rule finite_deflation_approx)
 | 
|  |    473 | apply (rule finite_deflation_approx)
 | 
|  |    474 | apply (rule chainE)
 | 
|  |    475 | apply (rule chain_approx)
 | 
|  |    476 | apply (simp add: cast_alg_defl_principal Abs_fin_defl_inverse finite_deflation_approx)
 | 
|  |    477 | done
 | 
|  |    478 | 
 | 
|  |    479 | text {* This lemma says that if we have an ep-pair from
 | 
|  |    480 | a bifinite domain into a universal domain, then e oo p
 | 
|  |    481 | is an algebraic deflation. *}
 | 
|  |    482 | 
 | 
|  |    483 | lemma
 | 
| 28611 |    484 |   assumes "ep_pair e p"
 | 
| 27409 |    485 |   constrains e :: "'a::profinite \<rightarrow> 'b::profinite"
 | 
|  |    486 |   shows "\<exists>d. cast\<cdot>d = e oo p"
 | 
|  |    487 | proof
 | 
| 29237 |    488 |   interpret ep_pair e p by fact
 | 
| 27409 |    489 |   let ?a = "\<lambda>i. e oo approx i oo p"
 | 
|  |    490 |   have a: "\<And>i. finite_deflation (?a i)"
 | 
|  |    491 |     apply (rule finite_deflation_e_d_p)
 | 
|  |    492 |     apply (rule finite_deflation_approx)
 | 
|  |    493 |     done
 | 
|  |    494 |   let ?d = "\<Squnion>i. alg_defl_principal (Abs_fin_defl (?a i))"
 | 
|  |    495 |   show "cast\<cdot>?d = e oo p"
 | 
|  |    496 |     apply (subst contlub_cfun_arg)
 | 
|  |    497 |     apply (rule chainI)
 | 
|  |    498 |     apply (rule alg_defl.principal_mono)
 | 
|  |    499 |     apply (rule Abs_fin_defl_mono [OF a a])
 | 
|  |    500 |     apply (rule chainE, simp)
 | 
|  |    501 |     apply (subst cast_alg_defl_principal)
 | 
|  |    502 |     apply (simp add: Abs_fin_defl_inverse a)
 | 
|  |    503 |     apply (simp add: expand_cfun_eq lub_distribs)
 | 
|  |    504 |     done
 | 
|  |    505 | qed
 | 
|  |    506 | 
 | 
|  |    507 | text {* This lemma says that if we have an ep-pair
 | 
|  |    508 | from a cpo into a bifinite domain, and e oo p is
 | 
|  |    509 | an algebraic deflation, then the cpo is bifinite. *}
 | 
|  |    510 | 
 | 
|  |    511 | lemma
 | 
| 28611 |    512 |   assumes "ep_pair e p"
 | 
| 27409 |    513 |   constrains e :: "'a::cpo \<rightarrow> 'b::profinite"
 | 
|  |    514 |   assumes d: "\<And>x. cast\<cdot>d\<cdot>x = e\<cdot>(p\<cdot>x)"
 | 
|  |    515 |   obtains a :: "nat \<Rightarrow> 'a \<rightarrow> 'a" where
 | 
|  |    516 |     "\<And>i. finite_deflation (a i)"
 | 
|  |    517 |     "(\<Squnion>i. a i) = ID"
 | 
|  |    518 | proof
 | 
| 29237 |    519 |   interpret ep_pair e p by fact
 | 
| 27409 |    520 |   let ?a = "\<lambda>i. p oo cast\<cdot>(approx i\<cdot>d) oo e"
 | 
|  |    521 |   show "\<And>i. finite_deflation (?a i)"
 | 
|  |    522 |     apply (rule finite_deflation_p_d_e)
 | 
|  |    523 |     apply (rule finite_deflation_cast)
 | 
|  |    524 |     apply (rule compact_approx)
 | 
|  |    525 |     apply (rule sq_ord_less_eq_trans [OF _ d])
 | 
|  |    526 |     apply (rule monofun_cfun_fun)
 | 
|  |    527 |     apply (rule monofun_cfun_arg)
 | 
|  |    528 |     apply (rule approx_less)
 | 
|  |    529 |     done
 | 
|  |    530 |   show "(\<Squnion>i. ?a i) = ID"
 | 
|  |    531 |     apply (rule ext_cfun, simp)
 | 
|  |    532 |     apply (simp add: lub_distribs)
 | 
|  |    533 |     apply (simp add: d)
 | 
|  |    534 |     done
 | 
|  |    535 | qed
 | 
|  |    536 | 
 | 
|  |    537 | end
 |