src/HOLCF/UpperPD.thy
author huffman
Tue Oct 12 06:20:05 2010 -0700 (2010-10-12)
changeset 40006 116e94f9543b
parent 40002 c5b5f7a3a3b1
child 40321 d065b195ec89
permissions -rw-r--r--
remove unneeded lemmas from Fun_Cpo.thy
     1 (*  Title:      HOLCF/UpperPD.thy
     2     Author:     Brian Huffman
     3 *)
     4 
     5 header {* Upper powerdomain *}
     6 
     7 theory UpperPD
     8 imports CompactBasis
     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 (fast intro: upper_le.ideal_principal)
    78 
    79 instantiation upper_pd :: (bifinite) below
    80 begin
    81 
    82 definition
    83   "x \<sqsubseteq> y \<longleftrightarrow> Rep_upper_pd x \<subseteq> Rep_upper_pd y"
    84 
    85 instance ..
    86 end
    87 
    88 instance upper_pd :: (bifinite) po
    89 using type_definition_upper_pd below_upper_pd_def
    90 by (rule upper_le.typedef_ideal_po)
    91 
    92 instance upper_pd :: (bifinite) cpo
    93 using type_definition_upper_pd below_upper_pd_def
    94 by (rule upper_le.typedef_ideal_cpo)
    95 
    96 definition
    97   upper_principal :: "'a pd_basis \<Rightarrow> 'a upper_pd" where
    98   "upper_principal t = Abs_upper_pd {u. u \<le>\<sharp> t}"
    99 
   100 interpretation upper_pd:
   101   ideal_completion upper_le upper_principal Rep_upper_pd
   102 using type_definition_upper_pd below_upper_pd_def
   103 using upper_principal_def pd_basis_countable
   104 by (rule upper_le.typedef_ideal_completion)
   105 
   106 text {* Upper powerdomain is pointed *}
   107 
   108 lemma upper_pd_minimal: "upper_principal (PDUnit compact_bot) \<sqsubseteq> ys"
   109 by (induct ys rule: upper_pd.principal_induct, simp, simp)
   110 
   111 instance upper_pd :: (bifinite) pcpo
   112 by intro_classes (fast intro: upper_pd_minimal)
   113 
   114 lemma inst_upper_pd_pcpo: "\<bottom> = upper_principal (PDUnit compact_bot)"
   115 by (rule upper_pd_minimal [THEN UU_I, symmetric])
   116 
   117 
   118 subsection {* Monadic unit and plus *}
   119 
   120 definition
   121   upper_unit :: "'a \<rightarrow> 'a upper_pd" where
   122   "upper_unit = compact_basis.basis_fun (\<lambda>a. upper_principal (PDUnit a))"
   123 
   124 definition
   125   upper_plus :: "'a upper_pd \<rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd" where
   126   "upper_plus = upper_pd.basis_fun (\<lambda>t. upper_pd.basis_fun (\<lambda>u.
   127       upper_principal (PDPlus t u)))"
   128 
   129 abbreviation
   130   upper_add :: "'a upper_pd \<Rightarrow> 'a upper_pd \<Rightarrow> 'a upper_pd"
   131     (infixl "+\<sharp>" 65) where
   132   "xs +\<sharp> ys == upper_plus\<cdot>xs\<cdot>ys"
   133 
   134 syntax
   135   "_upper_pd" :: "args \<Rightarrow> 'a upper_pd" ("{_}\<sharp>")
   136 
   137 translations
   138   "{x,xs}\<sharp>" == "{x}\<sharp> +\<sharp> {xs}\<sharp>"
   139   "{x}\<sharp>" == "CONST upper_unit\<cdot>x"
   140 
   141 lemma upper_unit_Rep_compact_basis [simp]:
   142   "{Rep_compact_basis a}\<sharp> = upper_principal (PDUnit a)"
   143 unfolding upper_unit_def
   144 by (simp add: compact_basis.basis_fun_principal PDUnit_upper_mono)
   145 
   146 lemma upper_plus_principal [simp]:
   147   "upper_principal t +\<sharp> upper_principal u = upper_principal (PDPlus t u)"
   148 unfolding upper_plus_def
   149 by (simp add: upper_pd.basis_fun_principal
   150     upper_pd.basis_fun_mono PDPlus_upper_mono)
   151 
   152 interpretation upper_add: semilattice upper_add proof
   153   fix xs ys zs :: "'a upper_pd"
   154   show "(xs +\<sharp> ys) +\<sharp> zs = xs +\<sharp> (ys +\<sharp> zs)"
   155     apply (induct xs ys arbitrary: zs rule: upper_pd.principal_induct2, simp, simp)
   156     apply (rule_tac x=zs in upper_pd.principal_induct, simp)
   157     apply (simp add: PDPlus_assoc)
   158     done
   159   show "xs +\<sharp> ys = ys +\<sharp> xs"
   160     apply (induct xs ys rule: upper_pd.principal_induct2, simp, simp)
   161     apply (simp add: PDPlus_commute)
   162     done
   163   show "xs +\<sharp> xs = xs"
   164     apply (induct xs rule: upper_pd.principal_induct, simp)
   165     apply (simp add: PDPlus_absorb)
   166     done
   167 qed
   168 
   169 lemmas upper_plus_assoc = upper_add.assoc
   170 lemmas upper_plus_commute = upper_add.commute
   171 lemmas upper_plus_absorb = upper_add.idem
   172 lemmas upper_plus_left_commute = upper_add.left_commute
   173 lemmas upper_plus_left_absorb = upper_add.left_idem
   174 
   175 text {* Useful for @{text "simp add: upper_plus_ac"} *}
   176 lemmas upper_plus_ac =
   177   upper_plus_assoc upper_plus_commute upper_plus_left_commute
   178 
   179 text {* Useful for @{text "simp only: upper_plus_aci"} *}
   180 lemmas upper_plus_aci =
   181   upper_plus_ac upper_plus_absorb upper_plus_left_absorb
   182 
   183 lemma upper_plus_below1: "xs +\<sharp> ys \<sqsubseteq> xs"
   184 apply (induct xs ys rule: upper_pd.principal_induct2, simp, simp)
   185 apply (simp add: PDPlus_upper_le)
   186 done
   187 
   188 lemma upper_plus_below2: "xs +\<sharp> ys \<sqsubseteq> ys"
   189 by (subst upper_plus_commute, rule upper_plus_below1)
   190 
   191 lemma upper_plus_greatest: "\<lbrakk>xs \<sqsubseteq> ys; xs \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> xs \<sqsubseteq> ys +\<sharp> zs"
   192 apply (subst upper_plus_absorb [of xs, symmetric])
   193 apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
   194 done
   195 
   196 lemma upper_below_plus_iff:
   197   "xs \<sqsubseteq> ys +\<sharp> zs \<longleftrightarrow> xs \<sqsubseteq> ys \<and> xs \<sqsubseteq> zs"
   198 apply safe
   199 apply (erule below_trans [OF _ upper_plus_below1])
   200 apply (erule below_trans [OF _ upper_plus_below2])
   201 apply (erule (1) upper_plus_greatest)
   202 done
   203 
   204 lemma upper_plus_below_unit_iff:
   205   "xs +\<sharp> ys \<sqsubseteq> {z}\<sharp> \<longleftrightarrow> xs \<sqsubseteq> {z}\<sharp> \<or> ys \<sqsubseteq> {z}\<sharp>"
   206 apply (induct xs rule: upper_pd.principal_induct, simp)
   207 apply (induct ys rule: upper_pd.principal_induct, simp)
   208 apply (induct z rule: compact_basis.principal_induct, simp)
   209 apply (simp add: upper_le_PDPlus_PDUnit_iff)
   210 done
   211 
   212 lemma upper_unit_below_iff [simp]: "{x}\<sharp> \<sqsubseteq> {y}\<sharp> \<longleftrightarrow> x \<sqsubseteq> y"
   213 apply (induct x rule: compact_basis.principal_induct, simp)
   214 apply (induct y rule: compact_basis.principal_induct, simp)
   215 apply simp
   216 done
   217 
   218 lemmas upper_pd_below_simps =
   219   upper_unit_below_iff
   220   upper_below_plus_iff
   221   upper_plus_below_unit_iff
   222 
   223 lemma upper_unit_eq_iff [simp]: "{x}\<sharp> = {y}\<sharp> \<longleftrightarrow> x = y"
   224 unfolding po_eq_conv by simp
   225 
   226 lemma upper_unit_strict [simp]: "{\<bottom>}\<sharp> = \<bottom>"
   227 using upper_unit_Rep_compact_basis [of compact_bot]
   228 by (simp add: inst_upper_pd_pcpo)
   229 
   230 lemma upper_plus_strict1 [simp]: "\<bottom> +\<sharp> ys = \<bottom>"
   231 by (rule UU_I, rule upper_plus_below1)
   232 
   233 lemma upper_plus_strict2 [simp]: "xs +\<sharp> \<bottom> = \<bottom>"
   234 by (rule UU_I, rule upper_plus_below2)
   235 
   236 lemma upper_unit_strict_iff [simp]: "{x}\<sharp> = \<bottom> \<longleftrightarrow> x = \<bottom>"
   237 unfolding upper_unit_strict [symmetric] by (rule upper_unit_eq_iff)
   238 
   239 lemma upper_plus_strict_iff [simp]:
   240   "xs +\<sharp> ys = \<bottom> \<longleftrightarrow> xs = \<bottom> \<or> ys = \<bottom>"
   241 apply (rule iffI)
   242 apply (erule rev_mp)
   243 apply (rule upper_pd.principal_induct2 [where x=xs and y=ys], simp, simp)
   244 apply (simp add: inst_upper_pd_pcpo upper_pd.principal_eq_iff
   245                  upper_le_PDPlus_PDUnit_iff)
   246 apply auto
   247 done
   248 
   249 lemma compact_upper_unit: "compact x \<Longrightarrow> compact {x}\<sharp>"
   250 by (auto dest!: compact_basis.compact_imp_principal)
   251 
   252 lemma compact_upper_unit_iff [simp]: "compact {x}\<sharp> \<longleftrightarrow> compact x"
   253 apply (safe elim!: compact_upper_unit)
   254 apply (simp only: compact_def upper_unit_below_iff [symmetric])
   255 apply (erule adm_subst [OF cont_Rep_CFun2])
   256 done
   257 
   258 lemma compact_upper_plus [simp]:
   259   "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs +\<sharp> ys)"
   260 by (auto dest!: upper_pd.compact_imp_principal)
   261 
   262 
   263 subsection {* Induction rules *}
   264 
   265 lemma upper_pd_induct1:
   266   assumes P: "adm P"
   267   assumes unit: "\<And>x. P {x}\<sharp>"
   268   assumes insert: "\<And>x ys. \<lbrakk>P {x}\<sharp>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<sharp> +\<sharp> ys)"
   269   shows "P (xs::'a upper_pd)"
   270 apply (induct xs rule: upper_pd.principal_induct, rule P)
   271 apply (induct_tac a rule: pd_basis_induct1)
   272 apply (simp only: upper_unit_Rep_compact_basis [symmetric])
   273 apply (rule unit)
   274 apply (simp only: upper_unit_Rep_compact_basis [symmetric]
   275                   upper_plus_principal [symmetric])
   276 apply (erule insert [OF unit])
   277 done
   278 
   279 lemma upper_pd_induct:
   280   assumes P: "adm P"
   281   assumes unit: "\<And>x. P {x}\<sharp>"
   282   assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs +\<sharp> ys)"
   283   shows "P (xs::'a upper_pd)"
   284 apply (induct xs rule: upper_pd.principal_induct, rule P)
   285 apply (induct_tac a rule: pd_basis_induct)
   286 apply (simp only: upper_unit_Rep_compact_basis [symmetric] unit)
   287 apply (simp only: upper_plus_principal [symmetric] plus)
   288 done
   289 
   290 
   291 subsection {* Monadic bind *}
   292 
   293 definition
   294   upper_bind_basis ::
   295   "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
   296   "upper_bind_basis = fold_pd
   297     (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
   298     (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<sharp> y\<cdot>f)"
   299 
   300 lemma ACI_upper_bind:
   301   "class.ab_semigroup_idem_mult (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<sharp> y\<cdot>f)"
   302 apply unfold_locales
   303 apply (simp add: upper_plus_assoc)
   304 apply (simp add: upper_plus_commute)
   305 apply (simp add: eta_cfun)
   306 done
   307 
   308 lemma upper_bind_basis_simps [simp]:
   309   "upper_bind_basis (PDUnit a) =
   310     (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
   311   "upper_bind_basis (PDPlus t u) =
   312     (\<Lambda> f. upper_bind_basis t\<cdot>f +\<sharp> upper_bind_basis u\<cdot>f)"
   313 unfolding upper_bind_basis_def
   314 apply -
   315 apply (rule fold_pd_PDUnit [OF ACI_upper_bind])
   316 apply (rule fold_pd_PDPlus [OF ACI_upper_bind])
   317 done
   318 
   319 lemma upper_bind_basis_mono:
   320   "t \<le>\<sharp> u \<Longrightarrow> upper_bind_basis t \<sqsubseteq> upper_bind_basis u"
   321 unfolding cfun_below_iff
   322 apply (erule upper_le_induct, safe)
   323 apply (simp add: monofun_cfun)
   324 apply (simp add: below_trans [OF upper_plus_below1])
   325 apply (simp add: upper_below_plus_iff)
   326 done
   327 
   328 definition
   329   upper_bind :: "'a upper_pd \<rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
   330   "upper_bind = upper_pd.basis_fun upper_bind_basis"
   331 
   332 lemma upper_bind_principal [simp]:
   333   "upper_bind\<cdot>(upper_principal t) = upper_bind_basis t"
   334 unfolding upper_bind_def
   335 apply (rule upper_pd.basis_fun_principal)
   336 apply (erule upper_bind_basis_mono)
   337 done
   338 
   339 lemma upper_bind_unit [simp]:
   340   "upper_bind\<cdot>{x}\<sharp>\<cdot>f = f\<cdot>x"
   341 by (induct x rule: compact_basis.principal_induct, simp, simp)
   342 
   343 lemma upper_bind_plus [simp]:
   344   "upper_bind\<cdot>(xs +\<sharp> ys)\<cdot>f = upper_bind\<cdot>xs\<cdot>f +\<sharp> upper_bind\<cdot>ys\<cdot>f"
   345 by (induct xs ys rule: upper_pd.principal_induct2, simp, simp, simp)
   346 
   347 lemma upper_bind_strict [simp]: "upper_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
   348 unfolding upper_unit_strict [symmetric] by (rule upper_bind_unit)
   349 
   350 
   351 subsection {* Map *}
   352 
   353 definition
   354   upper_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a upper_pd \<rightarrow> 'b upper_pd" where
   355   "upper_map = (\<Lambda> f xs. upper_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<sharp>))"
   356 
   357 lemma upper_map_unit [simp]:
   358   "upper_map\<cdot>f\<cdot>{x}\<sharp> = {f\<cdot>x}\<sharp>"
   359 unfolding upper_map_def by simp
   360 
   361 lemma upper_map_plus [simp]:
   362   "upper_map\<cdot>f\<cdot>(xs +\<sharp> ys) = upper_map\<cdot>f\<cdot>xs +\<sharp> upper_map\<cdot>f\<cdot>ys"
   363 unfolding upper_map_def by simp
   364 
   365 lemma upper_map_ident: "upper_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
   366 by (induct xs rule: upper_pd_induct, simp_all)
   367 
   368 lemma upper_map_ID: "upper_map\<cdot>ID = ID"
   369 by (simp add: cfun_eq_iff ID_def upper_map_ident)
   370 
   371 lemma upper_map_map:
   372   "upper_map\<cdot>f\<cdot>(upper_map\<cdot>g\<cdot>xs) = upper_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
   373 by (induct xs rule: upper_pd_induct, simp_all)
   374 
   375 lemma ep_pair_upper_map: "ep_pair e p \<Longrightarrow> ep_pair (upper_map\<cdot>e) (upper_map\<cdot>p)"
   376 apply default
   377 apply (induct_tac x rule: upper_pd_induct, simp_all add: ep_pair.e_inverse)
   378 apply (induct_tac y rule: upper_pd_induct)
   379 apply (simp_all add: ep_pair.e_p_below monofun_cfun)
   380 done
   381 
   382 lemma deflation_upper_map: "deflation d \<Longrightarrow> deflation (upper_map\<cdot>d)"
   383 apply default
   384 apply (induct_tac x rule: upper_pd_induct, simp_all add: deflation.idem)
   385 apply (induct_tac x rule: upper_pd_induct)
   386 apply (simp_all add: deflation.below monofun_cfun)
   387 done
   388 
   389 (* FIXME: long proof! *)
   390 lemma finite_deflation_upper_map:
   391   assumes "finite_deflation d" shows "finite_deflation (upper_map\<cdot>d)"
   392 proof (rule finite_deflation_intro)
   393   interpret d: finite_deflation d by fact
   394   have "deflation d" by fact
   395   thus "deflation (upper_map\<cdot>d)" by (rule deflation_upper_map)
   396   have "finite (range (\<lambda>x. d\<cdot>x))" by (rule d.finite_range)
   397   hence "finite (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))"
   398     by (rule finite_vimageI, simp add: inj_on_def Rep_compact_basis_inject)
   399   hence "finite (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x)))" by simp
   400   hence "finite (Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))"
   401     by (rule finite_vimageI, simp add: inj_on_def Rep_pd_basis_inject)
   402   hence *: "finite (upper_principal ` Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))" by simp
   403   hence "finite (range (\<lambda>xs. upper_map\<cdot>d\<cdot>xs))"
   404     apply (rule rev_finite_subset)
   405     apply clarsimp
   406     apply (induct_tac xs rule: upper_pd.principal_induct)
   407     apply (simp add: adm_mem_finite *)
   408     apply (rename_tac t, induct_tac t rule: pd_basis_induct)
   409     apply (simp only: upper_unit_Rep_compact_basis [symmetric] upper_map_unit)
   410     apply simp
   411     apply (subgoal_tac "\<exists>b. d\<cdot>(Rep_compact_basis a) = Rep_compact_basis b")
   412     apply clarsimp
   413     apply (rule imageI)
   414     apply (rule vimageI2)
   415     apply (simp add: Rep_PDUnit)
   416     apply (rule range_eqI)
   417     apply (erule sym)
   418     apply (rule exI)
   419     apply (rule Abs_compact_basis_inverse [symmetric])
   420     apply (simp add: d.compact)
   421     apply (simp only: upper_plus_principal [symmetric] upper_map_plus)
   422     apply clarsimp
   423     apply (rule imageI)
   424     apply (rule vimageI2)
   425     apply (simp add: Rep_PDPlus)
   426     done
   427   thus "finite {xs. upper_map\<cdot>d\<cdot>xs = xs}"
   428     by (rule finite_range_imp_finite_fixes)
   429 qed
   430 
   431 subsection {* Upper powerdomain is a bifinite domain *}
   432 
   433 definition
   434   upper_approx :: "nat \<Rightarrow> udom upper_pd \<rightarrow> udom upper_pd"
   435 where
   436   "upper_approx = (\<lambda>i. upper_map\<cdot>(udom_approx i))"
   437 
   438 lemma upper_approx: "approx_chain upper_approx"
   439 proof (rule approx_chain.intro)
   440   show "chain (\<lambda>i. upper_approx i)"
   441     unfolding upper_approx_def by simp
   442   show "(\<Squnion>i. upper_approx i) = ID"
   443     unfolding upper_approx_def
   444     by (simp add: lub_distribs upper_map_ID)
   445   show "\<And>i. finite_deflation (upper_approx i)"
   446     unfolding upper_approx_def
   447     by (intro finite_deflation_upper_map finite_deflation_udom_approx)
   448 qed
   449 
   450 definition upper_defl :: "defl \<rightarrow> defl"
   451 where "upper_defl = defl_fun1 upper_approx upper_map"
   452 
   453 lemma cast_upper_defl:
   454   "cast\<cdot>(upper_defl\<cdot>A) =
   455     udom_emb upper_approx oo upper_map\<cdot>(cast\<cdot>A) oo udom_prj upper_approx"
   456 unfolding upper_defl_def
   457 apply (rule cast_defl_fun1 [OF upper_approx])
   458 apply (erule finite_deflation_upper_map)
   459 done
   460 
   461 instantiation upper_pd :: (bifinite) bifinite
   462 begin
   463 
   464 definition
   465   "emb = udom_emb upper_approx oo upper_map\<cdot>emb"
   466 
   467 definition
   468   "prj = upper_map\<cdot>prj oo udom_prj upper_approx"
   469 
   470 definition
   471   "defl (t::'a upper_pd itself) = upper_defl\<cdot>DEFL('a)"
   472 
   473 instance proof
   474   show "ep_pair emb (prj :: udom \<rightarrow> 'a upper_pd)"
   475     unfolding emb_upper_pd_def prj_upper_pd_def
   476     using ep_pair_udom [OF upper_approx]
   477     by (intro ep_pair_comp ep_pair_upper_map ep_pair_emb_prj)
   478 next
   479   show "cast\<cdot>DEFL('a upper_pd) = emb oo (prj :: udom \<rightarrow> 'a upper_pd)"
   480     unfolding emb_upper_pd_def prj_upper_pd_def defl_upper_pd_def cast_upper_defl
   481     by (simp add: cast_DEFL oo_def cfun_eq_iff upper_map_map)
   482 qed
   483 
   484 end
   485 
   486 lemma DEFL_upper: "DEFL('a upper_pd) = upper_defl\<cdot>DEFL('a)"
   487 by (rule defl_upper_pd_def)
   488 
   489 
   490 subsection {* Join *}
   491 
   492 definition
   493   upper_join :: "'a upper_pd upper_pd \<rightarrow> 'a upper_pd" where
   494   "upper_join = (\<Lambda> xss. upper_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
   495 
   496 lemma upper_join_unit [simp]:
   497   "upper_join\<cdot>{xs}\<sharp> = xs"
   498 unfolding upper_join_def by simp
   499 
   500 lemma upper_join_plus [simp]:
   501   "upper_join\<cdot>(xss +\<sharp> yss) = upper_join\<cdot>xss +\<sharp> upper_join\<cdot>yss"
   502 unfolding upper_join_def by simp
   503 
   504 lemma upper_join_map_unit:
   505   "upper_join\<cdot>(upper_map\<cdot>upper_unit\<cdot>xs) = xs"
   506 by (induct xs rule: upper_pd_induct, simp_all)
   507 
   508 lemma upper_join_map_join:
   509   "upper_join\<cdot>(upper_map\<cdot>upper_join\<cdot>xsss) = upper_join\<cdot>(upper_join\<cdot>xsss)"
   510 by (induct xsss rule: upper_pd_induct, simp_all)
   511 
   512 lemma upper_join_map_map:
   513   "upper_join\<cdot>(upper_map\<cdot>(upper_map\<cdot>f)\<cdot>xss) =
   514    upper_map\<cdot>f\<cdot>(upper_join\<cdot>xss)"
   515 by (induct xss rule: upper_pd_induct, simp_all)
   516 
   517 end