src/HOL/HOLCF/UpperPD.thy
author huffman
Sun Dec 19 05:15:31 2010 -0800 (2010-12-19)
changeset 41286 3d7685a4a5ff
parent 41284 6d66975b711f
child 41287 029a6fc1bfb8
permissions -rw-r--r--
reintroduce 'bifinite' class, now with existentially-quantified approx function (cf. b525988432e9)
     1 (*  Title:      HOLCF/UpperPD.thy
     2     Author:     Brian Huffman
     3 *)
     4 
     5 header {* Upper powerdomain *}
     6 
     7 theory UpperPD
     8 imports Compact_Basis
     9 begin
    10 
    11 subsection {* Basis preorder *}
    12 
    13 definition
    14   upper_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<sharp>" 50) where
    15   "upper_le = (\<lambda>u v. \<forall>y\<in>Rep_pd_basis v. \<exists>x\<in>Rep_pd_basis u. x \<sqsubseteq> y)"
    16 
    17 lemma upper_le_refl [simp]: "t \<le>\<sharp> t"
    18 unfolding upper_le_def by fast
    19 
    20 lemma upper_le_trans: "\<lbrakk>t \<le>\<sharp> u; u \<le>\<sharp> v\<rbrakk> \<Longrightarrow> t \<le>\<sharp> v"
    21 unfolding upper_le_def
    22 apply (rule ballI)
    23 apply (drule (1) bspec, erule bexE)
    24 apply (drule (1) bspec, erule bexE)
    25 apply (erule rev_bexI)
    26 apply (erule (1) below_trans)
    27 done
    28 
    29 interpretation upper_le: preorder upper_le
    30 by (rule preorder.intro, rule upper_le_refl, rule upper_le_trans)
    31 
    32 lemma upper_le_minimal [simp]: "PDUnit compact_bot \<le>\<sharp> t"
    33 unfolding upper_le_def Rep_PDUnit by simp
    34 
    35 lemma PDUnit_upper_mono: "x \<sqsubseteq> y \<Longrightarrow> PDUnit x \<le>\<sharp> PDUnit y"
    36 unfolding upper_le_def Rep_PDUnit by simp
    37 
    38 lemma PDPlus_upper_mono: "\<lbrakk>s \<le>\<sharp> t; u \<le>\<sharp> v\<rbrakk> \<Longrightarrow> PDPlus s u \<le>\<sharp> PDPlus t v"
    39 unfolding upper_le_def Rep_PDPlus by fast
    40 
    41 lemma PDPlus_upper_le: "PDPlus t u \<le>\<sharp> t"
    42 unfolding upper_le_def Rep_PDPlus by fast
    43 
    44 lemma upper_le_PDUnit_PDUnit_iff [simp]:
    45   "(PDUnit a \<le>\<sharp> PDUnit b) = (a \<sqsubseteq> b)"
    46 unfolding upper_le_def Rep_PDUnit by fast
    47 
    48 lemma upper_le_PDPlus_PDUnit_iff:
    49   "(PDPlus t u \<le>\<sharp> PDUnit a) = (t \<le>\<sharp> PDUnit a \<or> u \<le>\<sharp> PDUnit a)"
    50 unfolding upper_le_def Rep_PDPlus Rep_PDUnit by fast
    51 
    52 lemma upper_le_PDPlus_iff: "(t \<le>\<sharp> PDPlus u v) = (t \<le>\<sharp> u \<and> t \<le>\<sharp> v)"
    53 unfolding upper_le_def Rep_PDPlus by fast
    54 
    55 lemma upper_le_induct [induct set: upper_le]:
    56   assumes le: "t \<le>\<sharp> u"
    57   assumes 1: "\<And>a b. a \<sqsubseteq> b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
    58   assumes 2: "\<And>t u a. P t (PDUnit a) \<Longrightarrow> P (PDPlus t u) (PDUnit a)"
    59   assumes 3: "\<And>t u v. \<lbrakk>P t u; P t v\<rbrakk> \<Longrightarrow> P t (PDPlus u v)"
    60   shows "P t u"
    61 using le apply (induct u arbitrary: t rule: pd_basis_induct)
    62 apply (erule rev_mp)
    63 apply (induct_tac t rule: pd_basis_induct)
    64 apply (simp add: 1)
    65 apply (simp add: upper_le_PDPlus_PDUnit_iff)
    66 apply (simp add: 2)
    67 apply (subst PDPlus_commute)
    68 apply (simp add: 2)
    69 apply (simp add: upper_le_PDPlus_iff 3)
    70 done
    71 
    72 
    73 subsection {* Type definition *}
    74 
    75 typedef (open) 'a upper_pd =
    76   "{S::'a pd_basis set. upper_le.ideal S}"
    77 by (rule upper_le.ex_ideal)
    78 
    79 type_notation (xsymbols) upper_pd ("('(_')\<sharp>)")
    80 
    81 instantiation upper_pd :: ("domain") below
    82 begin
    83 
    84 definition
    85   "x \<sqsubseteq> y \<longleftrightarrow> Rep_upper_pd x \<subseteq> Rep_upper_pd y"
    86 
    87 instance ..
    88 end
    89 
    90 instance upper_pd :: ("domain") po
    91 using type_definition_upper_pd below_upper_pd_def
    92 by (rule upper_le.typedef_ideal_po)
    93 
    94 instance upper_pd :: ("domain") cpo
    95 using type_definition_upper_pd below_upper_pd_def
    96 by (rule upper_le.typedef_ideal_cpo)
    97 
    98 definition
    99   upper_principal :: "'a pd_basis \<Rightarrow> 'a upper_pd" where
   100   "upper_principal t = Abs_upper_pd {u. u \<le>\<sharp> t}"
   101 
   102 interpretation upper_pd:
   103   ideal_completion upper_le upper_principal Rep_upper_pd
   104 using type_definition_upper_pd below_upper_pd_def
   105 using upper_principal_def pd_basis_countable
   106 by (rule upper_le.typedef_ideal_completion)
   107 
   108 text {* Upper powerdomain is pointed *}
   109 
   110 lemma upper_pd_minimal: "upper_principal (PDUnit compact_bot) \<sqsubseteq> ys"
   111 by (induct ys rule: upper_pd.principal_induct, simp, simp)
   112 
   113 instance upper_pd :: ("domain") pcpo
   114 by intro_classes (fast intro: upper_pd_minimal)
   115 
   116 lemma inst_upper_pd_pcpo: "\<bottom> = upper_principal (PDUnit compact_bot)"
   117 by (rule upper_pd_minimal [THEN UU_I, symmetric])
   118 
   119 
   120 subsection {* Monadic unit and plus *}
   121 
   122 definition
   123   upper_unit :: "'a \<rightarrow> 'a upper_pd" where
   124   "upper_unit = compact_basis.basis_fun (\<lambda>a. upper_principal (PDUnit a))"
   125 
   126 definition
   127   upper_plus :: "'a upper_pd \<rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd" where
   128   "upper_plus = upper_pd.basis_fun (\<lambda>t. upper_pd.basis_fun (\<lambda>u.
   129       upper_principal (PDPlus t u)))"
   130 
   131 abbreviation
   132   upper_add :: "'a upper_pd \<Rightarrow> 'a upper_pd \<Rightarrow> 'a upper_pd"
   133     (infixl "+\<sharp>" 65) where
   134   "xs +\<sharp> ys == upper_plus\<cdot>xs\<cdot>ys"
   135 
   136 syntax
   137   "_upper_pd" :: "args \<Rightarrow> 'a upper_pd" ("{_}\<sharp>")
   138 
   139 translations
   140   "{x,xs}\<sharp>" == "{x}\<sharp> +\<sharp> {xs}\<sharp>"
   141   "{x}\<sharp>" == "CONST upper_unit\<cdot>x"
   142 
   143 lemma upper_unit_Rep_compact_basis [simp]:
   144   "{Rep_compact_basis a}\<sharp> = upper_principal (PDUnit a)"
   145 unfolding upper_unit_def
   146 by (simp add: compact_basis.basis_fun_principal PDUnit_upper_mono)
   147 
   148 lemma upper_plus_principal [simp]:
   149   "upper_principal t +\<sharp> upper_principal u = upper_principal (PDPlus t u)"
   150 unfolding upper_plus_def
   151 by (simp add: upper_pd.basis_fun_principal
   152     upper_pd.basis_fun_mono PDPlus_upper_mono)
   153 
   154 interpretation upper_add: semilattice upper_add proof
   155   fix xs ys zs :: "'a upper_pd"
   156   show "(xs +\<sharp> ys) +\<sharp> zs = xs +\<sharp> (ys +\<sharp> zs)"
   157     apply (induct xs ys arbitrary: zs rule: upper_pd.principal_induct2, simp, simp)
   158     apply (rule_tac x=zs in upper_pd.principal_induct, simp)
   159     apply (simp add: PDPlus_assoc)
   160     done
   161   show "xs +\<sharp> ys = ys +\<sharp> xs"
   162     apply (induct xs ys rule: upper_pd.principal_induct2, simp, simp)
   163     apply (simp add: PDPlus_commute)
   164     done
   165   show "xs +\<sharp> xs = xs"
   166     apply (induct xs rule: upper_pd.principal_induct, simp)
   167     apply (simp add: PDPlus_absorb)
   168     done
   169 qed
   170 
   171 lemmas upper_plus_assoc = upper_add.assoc
   172 lemmas upper_plus_commute = upper_add.commute
   173 lemmas upper_plus_absorb = upper_add.idem
   174 lemmas upper_plus_left_commute = upper_add.left_commute
   175 lemmas upper_plus_left_absorb = upper_add.left_idem
   176 
   177 text {* Useful for @{text "simp add: upper_plus_ac"} *}
   178 lemmas upper_plus_ac =
   179   upper_plus_assoc upper_plus_commute upper_plus_left_commute
   180 
   181 text {* Useful for @{text "simp only: upper_plus_aci"} *}
   182 lemmas upper_plus_aci =
   183   upper_plus_ac upper_plus_absorb upper_plus_left_absorb
   184 
   185 lemma upper_plus_below1: "xs +\<sharp> ys \<sqsubseteq> xs"
   186 apply (induct xs ys rule: upper_pd.principal_induct2, simp, simp)
   187 apply (simp add: PDPlus_upper_le)
   188 done
   189 
   190 lemma upper_plus_below2: "xs +\<sharp> ys \<sqsubseteq> ys"
   191 by (subst upper_plus_commute, rule upper_plus_below1)
   192 
   193 lemma upper_plus_greatest: "\<lbrakk>xs \<sqsubseteq> ys; xs \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> xs \<sqsubseteq> ys +\<sharp> zs"
   194 apply (subst upper_plus_absorb [of xs, symmetric])
   195 apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
   196 done
   197 
   198 lemma upper_below_plus_iff [simp]:
   199   "xs \<sqsubseteq> ys +\<sharp> zs \<longleftrightarrow> xs \<sqsubseteq> ys \<and> xs \<sqsubseteq> zs"
   200 apply safe
   201 apply (erule below_trans [OF _ upper_plus_below1])
   202 apply (erule below_trans [OF _ upper_plus_below2])
   203 apply (erule (1) upper_plus_greatest)
   204 done
   205 
   206 lemma upper_plus_below_unit_iff [simp]:
   207   "xs +\<sharp> ys \<sqsubseteq> {z}\<sharp> \<longleftrightarrow> xs \<sqsubseteq> {z}\<sharp> \<or> ys \<sqsubseteq> {z}\<sharp>"
   208 apply (induct xs rule: upper_pd.principal_induct, simp)
   209 apply (induct ys rule: upper_pd.principal_induct, simp)
   210 apply (induct z rule: compact_basis.principal_induct, simp)
   211 apply (simp add: upper_le_PDPlus_PDUnit_iff)
   212 done
   213 
   214 lemma upper_unit_below_iff [simp]: "{x}\<sharp> \<sqsubseteq> {y}\<sharp> \<longleftrightarrow> x \<sqsubseteq> y"
   215 apply (induct x rule: compact_basis.principal_induct, simp)
   216 apply (induct y rule: compact_basis.principal_induct, simp)
   217 apply simp
   218 done
   219 
   220 lemmas upper_pd_below_simps =
   221   upper_unit_below_iff
   222   upper_below_plus_iff
   223   upper_plus_below_unit_iff
   224 
   225 lemma upper_unit_eq_iff [simp]: "{x}\<sharp> = {y}\<sharp> \<longleftrightarrow> x = y"
   226 unfolding po_eq_conv by simp
   227 
   228 lemma upper_unit_strict [simp]: "{\<bottom>}\<sharp> = \<bottom>"
   229 using upper_unit_Rep_compact_basis [of compact_bot]
   230 by (simp add: inst_upper_pd_pcpo)
   231 
   232 lemma upper_plus_strict1 [simp]: "\<bottom> +\<sharp> ys = \<bottom>"
   233 by (rule UU_I, rule upper_plus_below1)
   234 
   235 lemma upper_plus_strict2 [simp]: "xs +\<sharp> \<bottom> = \<bottom>"
   236 by (rule UU_I, rule upper_plus_below2)
   237 
   238 lemma upper_unit_bottom_iff [simp]: "{x}\<sharp> = \<bottom> \<longleftrightarrow> x = \<bottom>"
   239 unfolding upper_unit_strict [symmetric] by (rule upper_unit_eq_iff)
   240 
   241 lemma upper_plus_bottom_iff [simp]:
   242   "xs +\<sharp> ys = \<bottom> \<longleftrightarrow> xs = \<bottom> \<or> ys = \<bottom>"
   243 apply (rule iffI)
   244 apply (erule rev_mp)
   245 apply (rule upper_pd.principal_induct2 [where x=xs and y=ys], simp, simp)
   246 apply (simp add: inst_upper_pd_pcpo upper_pd.principal_eq_iff
   247                  upper_le_PDPlus_PDUnit_iff)
   248 apply auto
   249 done
   250 
   251 lemma compact_upper_unit: "compact x \<Longrightarrow> compact {x}\<sharp>"
   252 by (auto dest!: compact_basis.compact_imp_principal)
   253 
   254 lemma compact_upper_unit_iff [simp]: "compact {x}\<sharp> \<longleftrightarrow> compact x"
   255 apply (safe elim!: compact_upper_unit)
   256 apply (simp only: compact_def upper_unit_below_iff [symmetric])
   257 apply (erule adm_subst [OF cont_Rep_cfun2])
   258 done
   259 
   260 lemma compact_upper_plus [simp]:
   261   "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs +\<sharp> ys)"
   262 by (auto dest!: upper_pd.compact_imp_principal)
   263 
   264 
   265 subsection {* Induction rules *}
   266 
   267 lemma upper_pd_induct1:
   268   assumes P: "adm P"
   269   assumes unit: "\<And>x. P {x}\<sharp>"
   270   assumes insert: "\<And>x ys. \<lbrakk>P {x}\<sharp>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<sharp> +\<sharp> ys)"
   271   shows "P (xs::'a upper_pd)"
   272 apply (induct xs rule: upper_pd.principal_induct, rule P)
   273 apply (induct_tac a rule: pd_basis_induct1)
   274 apply (simp only: upper_unit_Rep_compact_basis [symmetric])
   275 apply (rule unit)
   276 apply (simp only: upper_unit_Rep_compact_basis [symmetric]
   277                   upper_plus_principal [symmetric])
   278 apply (erule insert [OF unit])
   279 done
   280 
   281 lemma upper_pd_induct
   282   [case_names adm upper_unit upper_plus, induct type: upper_pd]:
   283   assumes P: "adm P"
   284   assumes unit: "\<And>x. P {x}\<sharp>"
   285   assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs +\<sharp> ys)"
   286   shows "P (xs::'a upper_pd)"
   287 apply (induct xs rule: upper_pd.principal_induct, rule P)
   288 apply (induct_tac a rule: pd_basis_induct)
   289 apply (simp only: upper_unit_Rep_compact_basis [symmetric] unit)
   290 apply (simp only: upper_plus_principal [symmetric] plus)
   291 done
   292 
   293 
   294 subsection {* Monadic bind *}
   295 
   296 definition
   297   upper_bind_basis ::
   298   "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
   299   "upper_bind_basis = fold_pd
   300     (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
   301     (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<sharp> y\<cdot>f)"
   302 
   303 lemma ACI_upper_bind:
   304   "class.ab_semigroup_idem_mult (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<sharp> y\<cdot>f)"
   305 apply unfold_locales
   306 apply (simp add: upper_plus_assoc)
   307 apply (simp add: upper_plus_commute)
   308 apply (simp add: eta_cfun)
   309 done
   310 
   311 lemma upper_bind_basis_simps [simp]:
   312   "upper_bind_basis (PDUnit a) =
   313     (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
   314   "upper_bind_basis (PDPlus t u) =
   315     (\<Lambda> f. upper_bind_basis t\<cdot>f +\<sharp> upper_bind_basis u\<cdot>f)"
   316 unfolding upper_bind_basis_def
   317 apply -
   318 apply (rule fold_pd_PDUnit [OF ACI_upper_bind])
   319 apply (rule fold_pd_PDPlus [OF ACI_upper_bind])
   320 done
   321 
   322 lemma upper_bind_basis_mono:
   323   "t \<le>\<sharp> u \<Longrightarrow> upper_bind_basis t \<sqsubseteq> upper_bind_basis u"
   324 unfolding cfun_below_iff
   325 apply (erule upper_le_induct, safe)
   326 apply (simp add: monofun_cfun)
   327 apply (simp add: below_trans [OF upper_plus_below1])
   328 apply simp
   329 done
   330 
   331 definition
   332   upper_bind :: "'a upper_pd \<rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
   333   "upper_bind = upper_pd.basis_fun upper_bind_basis"
   334 
   335 syntax
   336   "_upper_bind" :: "[logic, logic, logic] \<Rightarrow> logic"
   337     ("(3\<Union>\<sharp>_\<in>_./ _)" [0, 0, 10] 10)
   338 
   339 translations
   340   "\<Union>\<sharp>x\<in>xs. e" == "CONST upper_bind\<cdot>xs\<cdot>(\<Lambda> x. e)"
   341 
   342 lemma upper_bind_principal [simp]:
   343   "upper_bind\<cdot>(upper_principal t) = upper_bind_basis t"
   344 unfolding upper_bind_def
   345 apply (rule upper_pd.basis_fun_principal)
   346 apply (erule upper_bind_basis_mono)
   347 done
   348 
   349 lemma upper_bind_unit [simp]:
   350   "upper_bind\<cdot>{x}\<sharp>\<cdot>f = f\<cdot>x"
   351 by (induct x rule: compact_basis.principal_induct, simp, simp)
   352 
   353 lemma upper_bind_plus [simp]:
   354   "upper_bind\<cdot>(xs +\<sharp> ys)\<cdot>f = upper_bind\<cdot>xs\<cdot>f +\<sharp> upper_bind\<cdot>ys\<cdot>f"
   355 by (induct xs ys rule: upper_pd.principal_induct2, simp, simp, simp)
   356 
   357 lemma upper_bind_strict [simp]: "upper_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
   358 unfolding upper_unit_strict [symmetric] by (rule upper_bind_unit)
   359 
   360 lemma upper_bind_bind:
   361   "upper_bind\<cdot>(upper_bind\<cdot>xs\<cdot>f)\<cdot>g = upper_bind\<cdot>xs\<cdot>(\<Lambda> x. upper_bind\<cdot>(f\<cdot>x)\<cdot>g)"
   362 by (induct xs, simp_all)
   363 
   364 
   365 subsection {* Map *}
   366 
   367 definition
   368   upper_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a upper_pd \<rightarrow> 'b upper_pd" where
   369   "upper_map = (\<Lambda> f xs. upper_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<sharp>))"
   370 
   371 lemma upper_map_unit [simp]:
   372   "upper_map\<cdot>f\<cdot>{x}\<sharp> = {f\<cdot>x}\<sharp>"
   373 unfolding upper_map_def by simp
   374 
   375 lemma upper_map_plus [simp]:
   376   "upper_map\<cdot>f\<cdot>(xs +\<sharp> ys) = upper_map\<cdot>f\<cdot>xs +\<sharp> upper_map\<cdot>f\<cdot>ys"
   377 unfolding upper_map_def by simp
   378 
   379 lemma upper_map_bottom [simp]: "upper_map\<cdot>f\<cdot>\<bottom> = {f\<cdot>\<bottom>}\<sharp>"
   380 unfolding upper_map_def by simp
   381 
   382 lemma upper_map_ident: "upper_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
   383 by (induct xs rule: upper_pd_induct, simp_all)
   384 
   385 lemma upper_map_ID: "upper_map\<cdot>ID = ID"
   386 by (simp add: cfun_eq_iff ID_def upper_map_ident)
   387 
   388 lemma upper_map_map:
   389   "upper_map\<cdot>f\<cdot>(upper_map\<cdot>g\<cdot>xs) = upper_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
   390 by (induct xs rule: upper_pd_induct, simp_all)
   391 
   392 lemma upper_bind_map:
   393   "upper_bind\<cdot>(upper_map\<cdot>f\<cdot>xs)\<cdot>g = upper_bind\<cdot>xs\<cdot>(\<Lambda> x. g\<cdot>(f\<cdot>x))"
   394 by (simp add: upper_map_def upper_bind_bind)
   395 
   396 lemma upper_map_bind:
   397   "upper_map\<cdot>f\<cdot>(upper_bind\<cdot>xs\<cdot>g) = upper_bind\<cdot>xs\<cdot>(\<Lambda> x. upper_map\<cdot>f\<cdot>(g\<cdot>x))"
   398 by (simp add: upper_map_def upper_bind_bind)
   399 
   400 lemma ep_pair_upper_map: "ep_pair e p \<Longrightarrow> ep_pair (upper_map\<cdot>e) (upper_map\<cdot>p)"
   401 apply default
   402 apply (induct_tac x rule: upper_pd_induct, simp_all add: ep_pair.e_inverse)
   403 apply (induct_tac y rule: upper_pd_induct)
   404 apply (simp_all add: ep_pair.e_p_below monofun_cfun del: upper_below_plus_iff)
   405 done
   406 
   407 lemma deflation_upper_map: "deflation d \<Longrightarrow> deflation (upper_map\<cdot>d)"
   408 apply default
   409 apply (induct_tac x rule: upper_pd_induct, simp_all add: deflation.idem)
   410 apply (induct_tac x rule: upper_pd_induct)
   411 apply (simp_all add: deflation.below monofun_cfun del: upper_below_plus_iff)
   412 done
   413 
   414 (* FIXME: long proof! *)
   415 lemma finite_deflation_upper_map:
   416   assumes "finite_deflation d" shows "finite_deflation (upper_map\<cdot>d)"
   417 proof (rule finite_deflation_intro)
   418   interpret d: finite_deflation d by fact
   419   have "deflation d" by fact
   420   thus "deflation (upper_map\<cdot>d)" by (rule deflation_upper_map)
   421   have "finite (range (\<lambda>x. d\<cdot>x))" by (rule d.finite_range)
   422   hence "finite (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))"
   423     by (rule finite_vimageI, simp add: inj_on_def Rep_compact_basis_inject)
   424   hence "finite (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x)))" by simp
   425   hence "finite (Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))"
   426     by (rule finite_vimageI, simp add: inj_on_def Rep_pd_basis_inject)
   427   hence *: "finite (upper_principal ` Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))" by simp
   428   hence "finite (range (\<lambda>xs. upper_map\<cdot>d\<cdot>xs))"
   429     apply (rule rev_finite_subset)
   430     apply clarsimp
   431     apply (induct_tac xs rule: upper_pd.principal_induct)
   432     apply (simp add: adm_mem_finite *)
   433     apply (rename_tac t, induct_tac t rule: pd_basis_induct)
   434     apply (simp only: upper_unit_Rep_compact_basis [symmetric] upper_map_unit)
   435     apply simp
   436     apply (subgoal_tac "\<exists>b. d\<cdot>(Rep_compact_basis a) = Rep_compact_basis b")
   437     apply clarsimp
   438     apply (rule imageI)
   439     apply (rule vimageI2)
   440     apply (simp add: Rep_PDUnit)
   441     apply (rule range_eqI)
   442     apply (erule sym)
   443     apply (rule exI)
   444     apply (rule Abs_compact_basis_inverse [symmetric])
   445     apply (simp add: d.compact)
   446     apply (simp only: upper_plus_principal [symmetric] upper_map_plus)
   447     apply clarsimp
   448     apply (rule imageI)
   449     apply (rule vimageI2)
   450     apply (simp add: Rep_PDPlus)
   451     done
   452   thus "finite {xs. upper_map\<cdot>d\<cdot>xs = xs}"
   453     by (rule finite_range_imp_finite_fixes)
   454 qed
   455 
   456 subsection {* Upper powerdomain is a domain *}
   457 
   458 lemma approx_chain_upper_map:
   459   assumes "approx_chain a"
   460   shows "approx_chain (\<lambda>i. upper_map\<cdot>(a i))"
   461   using assms unfolding approx_chain_def
   462   by (simp add: lub_APP upper_map_ID finite_deflation_upper_map)
   463 
   464 instance upper_pd :: ("domain") bifinite
   465 proof
   466   show "\<exists>(a::nat \<Rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd). approx_chain a"
   467     using bifinite [where 'a='a]
   468     by (fast intro!: approx_chain_upper_map)
   469 qed
   470 
   471 definition
   472   upper_approx :: "nat \<Rightarrow> udom upper_pd \<rightarrow> udom upper_pd"
   473 where
   474   "upper_approx = (\<lambda>i. upper_map\<cdot>(udom_approx i))"
   475 
   476 lemma upper_approx: "approx_chain upper_approx"
   477 using upper_map_ID finite_deflation_upper_map
   478 unfolding upper_approx_def by (rule approx_chain_lemma1)
   479 
   480 definition upper_defl :: "defl \<rightarrow> defl"
   481 where "upper_defl = defl_fun1 upper_approx upper_map"
   482 
   483 lemma cast_upper_defl:
   484   "cast\<cdot>(upper_defl\<cdot>A) =
   485     udom_emb upper_approx oo upper_map\<cdot>(cast\<cdot>A) oo udom_prj upper_approx"
   486 using upper_approx finite_deflation_upper_map
   487 unfolding upper_defl_def by (rule cast_defl_fun1)
   488 
   489 instantiation upper_pd :: ("domain") liftdomain
   490 begin
   491 
   492 definition
   493   "emb = udom_emb upper_approx oo upper_map\<cdot>emb"
   494 
   495 definition
   496   "prj = upper_map\<cdot>prj oo udom_prj upper_approx"
   497 
   498 definition
   499   "defl (t::'a upper_pd itself) = upper_defl\<cdot>DEFL('a)"
   500 
   501 definition
   502   "(liftemb :: 'a upper_pd u \<rightarrow> udom) = udom_emb u_approx oo u_map\<cdot>emb"
   503 
   504 definition
   505   "(liftprj :: udom \<rightarrow> 'a upper_pd u) = u_map\<cdot>prj oo udom_prj u_approx"
   506 
   507 definition
   508   "liftdefl (t::'a upper_pd itself) = u_defl\<cdot>DEFL('a upper_pd)"
   509 
   510 instance
   511 using liftemb_upper_pd_def liftprj_upper_pd_def liftdefl_upper_pd_def
   512 proof (rule liftdomain_class_intro)
   513   show "ep_pair emb (prj :: udom \<rightarrow> 'a upper_pd)"
   514     unfolding emb_upper_pd_def prj_upper_pd_def
   515     using ep_pair_udom [OF upper_approx]
   516     by (intro ep_pair_comp ep_pair_upper_map ep_pair_emb_prj)
   517 next
   518   show "cast\<cdot>DEFL('a upper_pd) = emb oo (prj :: udom \<rightarrow> 'a upper_pd)"
   519     unfolding emb_upper_pd_def prj_upper_pd_def defl_upper_pd_def cast_upper_defl
   520     by (simp add: cast_DEFL oo_def cfun_eq_iff upper_map_map)
   521 qed
   522 
   523 end
   524 
   525 lemma DEFL_upper: "DEFL('a upper_pd) = upper_defl\<cdot>DEFL('a)"
   526 by (rule defl_upper_pd_def)
   527 
   528 
   529 subsection {* Join *}
   530 
   531 definition
   532   upper_join :: "'a upper_pd upper_pd \<rightarrow> 'a upper_pd" where
   533   "upper_join = (\<Lambda> xss. upper_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
   534 
   535 lemma upper_join_unit [simp]:
   536   "upper_join\<cdot>{xs}\<sharp> = xs"
   537 unfolding upper_join_def by simp
   538 
   539 lemma upper_join_plus [simp]:
   540   "upper_join\<cdot>(xss +\<sharp> yss) = upper_join\<cdot>xss +\<sharp> upper_join\<cdot>yss"
   541 unfolding upper_join_def by simp
   542 
   543 lemma upper_join_bottom [simp]: "upper_join\<cdot>\<bottom> = \<bottom>"
   544 unfolding upper_join_def by simp
   545 
   546 lemma upper_join_map_unit:
   547   "upper_join\<cdot>(upper_map\<cdot>upper_unit\<cdot>xs) = xs"
   548 by (induct xs rule: upper_pd_induct, simp_all)
   549 
   550 lemma upper_join_map_join:
   551   "upper_join\<cdot>(upper_map\<cdot>upper_join\<cdot>xsss) = upper_join\<cdot>(upper_join\<cdot>xsss)"
   552 by (induct xsss rule: upper_pd_induct, simp_all)
   553 
   554 lemma upper_join_map_map:
   555   "upper_join\<cdot>(upper_map\<cdot>(upper_map\<cdot>f)\<cdot>xss) =
   556    upper_map\<cdot>f\<cdot>(upper_join\<cdot>xss)"
   557 by (induct xss rule: upper_pd_induct, simp_all)
   558 
   559 end