src/HOLCF/ConvexPD.thy
author huffman
Wed Nov 10 17:56:08 2010 -0800 (2010-11-10)
changeset 40502 8e92772bc0e8
parent 40497 d2e876d6da8c
child 40576 fa5e0cacd5e7
permissions -rw-r--r--
move map functions to new theory file Map_Functions; add theory file Plain_HOLCF
     1 (*  Title:      HOLCF/ConvexPD.thy
     2     Author:     Brian Huffman
     3 *)
     4 
     5 header {* Convex powerdomain *}
     6 
     7 theory ConvexPD
     8 imports UpperPD LowerPD
     9 begin
    10 
    11 subsection {* Basis preorder *}
    12 
    13 definition
    14   convex_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<natural>" 50) where
    15   "convex_le = (\<lambda>u v. u \<le>\<sharp> v \<and> u \<le>\<flat> v)"
    16 
    17 lemma convex_le_refl [simp]: "t \<le>\<natural> t"
    18 unfolding convex_le_def by (fast intro: upper_le_refl lower_le_refl)
    19 
    20 lemma convex_le_trans: "\<lbrakk>t \<le>\<natural> u; u \<le>\<natural> v\<rbrakk> \<Longrightarrow> t \<le>\<natural> v"
    21 unfolding convex_le_def by (fast intro: upper_le_trans lower_le_trans)
    22 
    23 interpretation convex_le: preorder convex_le
    24 by (rule preorder.intro, rule convex_le_refl, rule convex_le_trans)
    25 
    26 lemma upper_le_minimal [simp]: "PDUnit compact_bot \<le>\<natural> t"
    27 unfolding convex_le_def Rep_PDUnit by simp
    28 
    29 lemma PDUnit_convex_mono: "x \<sqsubseteq> y \<Longrightarrow> PDUnit x \<le>\<natural> PDUnit y"
    30 unfolding convex_le_def by (fast intro: PDUnit_upper_mono PDUnit_lower_mono)
    31 
    32 lemma PDPlus_convex_mono: "\<lbrakk>s \<le>\<natural> t; u \<le>\<natural> v\<rbrakk> \<Longrightarrow> PDPlus s u \<le>\<natural> PDPlus t v"
    33 unfolding convex_le_def by (fast intro: PDPlus_upper_mono PDPlus_lower_mono)
    34 
    35 lemma convex_le_PDUnit_PDUnit_iff [simp]:
    36   "(PDUnit a \<le>\<natural> PDUnit b) = (a \<sqsubseteq> b)"
    37 unfolding convex_le_def upper_le_def lower_le_def Rep_PDUnit by fast
    38 
    39 lemma convex_le_PDUnit_lemma1:
    40   "(PDUnit a \<le>\<natural> t) = (\<forall>b\<in>Rep_pd_basis t. a \<sqsubseteq> b)"
    41 unfolding convex_le_def upper_le_def lower_le_def Rep_PDUnit
    42 using Rep_pd_basis_nonempty [of t, folded ex_in_conv] by fast
    43 
    44 lemma convex_le_PDUnit_PDPlus_iff [simp]:
    45   "(PDUnit a \<le>\<natural> PDPlus t u) = (PDUnit a \<le>\<natural> t \<and> PDUnit a \<le>\<natural> u)"
    46 unfolding convex_le_PDUnit_lemma1 Rep_PDPlus by fast
    47 
    48 lemma convex_le_PDUnit_lemma2:
    49   "(t \<le>\<natural> PDUnit b) = (\<forall>a\<in>Rep_pd_basis t. a \<sqsubseteq> b)"
    50 unfolding convex_le_def upper_le_def lower_le_def Rep_PDUnit
    51 using Rep_pd_basis_nonempty [of t, folded ex_in_conv] by fast
    52 
    53 lemma convex_le_PDPlus_PDUnit_iff [simp]:
    54   "(PDPlus t u \<le>\<natural> PDUnit a) = (t \<le>\<natural> PDUnit a \<and> u \<le>\<natural> PDUnit a)"
    55 unfolding convex_le_PDUnit_lemma2 Rep_PDPlus by fast
    56 
    57 lemma convex_le_PDPlus_lemma:
    58   assumes z: "PDPlus t u \<le>\<natural> z"
    59   shows "\<exists>v w. z = PDPlus v w \<and> t \<le>\<natural> v \<and> u \<le>\<natural> w"
    60 proof (intro exI conjI)
    61   let ?A = "{b\<in>Rep_pd_basis z. \<exists>a\<in>Rep_pd_basis t. a \<sqsubseteq> b}"
    62   let ?B = "{b\<in>Rep_pd_basis z. \<exists>a\<in>Rep_pd_basis u. a \<sqsubseteq> b}"
    63   let ?v = "Abs_pd_basis ?A"
    64   let ?w = "Abs_pd_basis ?B"
    65   have Rep_v: "Rep_pd_basis ?v = ?A"
    66     apply (rule Abs_pd_basis_inverse)
    67     apply (rule Rep_pd_basis_nonempty [of t, folded ex_in_conv, THEN exE])
    68     apply (cut_tac z, simp only: convex_le_def lower_le_def, clarify)
    69     apply (drule_tac x=x in bspec, simp add: Rep_PDPlus, erule bexE)
    70     apply (simp add: pd_basis_def)
    71     apply fast
    72     done
    73   have Rep_w: "Rep_pd_basis ?w = ?B"
    74     apply (rule Abs_pd_basis_inverse)
    75     apply (rule Rep_pd_basis_nonempty [of u, folded ex_in_conv, THEN exE])
    76     apply (cut_tac z, simp only: convex_le_def lower_le_def, clarify)
    77     apply (drule_tac x=x in bspec, simp add: Rep_PDPlus, erule bexE)
    78     apply (simp add: pd_basis_def)
    79     apply fast
    80     done
    81   show "z = PDPlus ?v ?w"
    82     apply (insert z)
    83     apply (simp add: convex_le_def, erule conjE)
    84     apply (simp add: Rep_pd_basis_inject [symmetric] Rep_PDPlus)
    85     apply (simp add: Rep_v Rep_w)
    86     apply (rule equalityI)
    87      apply (rule subsetI)
    88      apply (simp only: upper_le_def)
    89      apply (drule (1) bspec, erule bexE)
    90      apply (simp add: Rep_PDPlus)
    91      apply fast
    92     apply fast
    93     done
    94   show "t \<le>\<natural> ?v" "u \<le>\<natural> ?w"
    95    apply (insert z)
    96    apply (simp_all add: convex_le_def upper_le_def lower_le_def Rep_PDPlus Rep_v Rep_w)
    97    apply fast+
    98    done
    99 qed
   100 
   101 lemma convex_le_induct [induct set: convex_le]:
   102   assumes le: "t \<le>\<natural> u"
   103   assumes 2: "\<And>t u v. \<lbrakk>P t u; P u v\<rbrakk> \<Longrightarrow> P t v"
   104   assumes 3: "\<And>a b. a \<sqsubseteq> b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
   105   assumes 4: "\<And>t u v w. \<lbrakk>P t v; P u w\<rbrakk> \<Longrightarrow> P (PDPlus t u) (PDPlus v w)"
   106   shows "P t u"
   107 using le apply (induct t arbitrary: u rule: pd_basis_induct)
   108 apply (erule rev_mp)
   109 apply (induct_tac u rule: pd_basis_induct1)
   110 apply (simp add: 3)
   111 apply (simp, clarify, rename_tac a b t)
   112 apply (subgoal_tac "P (PDPlus (PDUnit a) (PDUnit a)) (PDPlus (PDUnit b) t)")
   113 apply (simp add: PDPlus_absorb)
   114 apply (erule (1) 4 [OF 3])
   115 apply (drule convex_le_PDPlus_lemma, clarify)
   116 apply (simp add: 4)
   117 done
   118 
   119 
   120 subsection {* Type definition *}
   121 
   122 typedef (open) 'a convex_pd =
   123   "{S::'a pd_basis set. convex_le.ideal S}"
   124 by (fast intro: convex_le.ideal_principal)
   125 
   126 instantiation convex_pd :: ("domain") below
   127 begin
   128 
   129 definition
   130   "x \<sqsubseteq> y \<longleftrightarrow> Rep_convex_pd x \<subseteq> Rep_convex_pd y"
   131 
   132 instance ..
   133 end
   134 
   135 instance convex_pd :: ("domain") po
   136 using type_definition_convex_pd below_convex_pd_def
   137 by (rule convex_le.typedef_ideal_po)
   138 
   139 instance convex_pd :: ("domain") cpo
   140 using type_definition_convex_pd below_convex_pd_def
   141 by (rule convex_le.typedef_ideal_cpo)
   142 
   143 definition
   144   convex_principal :: "'a pd_basis \<Rightarrow> 'a convex_pd" where
   145   "convex_principal t = Abs_convex_pd {u. u \<le>\<natural> t}"
   146 
   147 interpretation convex_pd:
   148   ideal_completion convex_le convex_principal Rep_convex_pd
   149 using type_definition_convex_pd below_convex_pd_def
   150 using convex_principal_def pd_basis_countable
   151 by (rule convex_le.typedef_ideal_completion)
   152 
   153 text {* Convex powerdomain is pointed *}
   154 
   155 lemma convex_pd_minimal: "convex_principal (PDUnit compact_bot) \<sqsubseteq> ys"
   156 by (induct ys rule: convex_pd.principal_induct, simp, simp)
   157 
   158 instance convex_pd :: ("domain") pcpo
   159 by intro_classes (fast intro: convex_pd_minimal)
   160 
   161 lemma inst_convex_pd_pcpo: "\<bottom> = convex_principal (PDUnit compact_bot)"
   162 by (rule convex_pd_minimal [THEN UU_I, symmetric])
   163 
   164 
   165 subsection {* Monadic unit and plus *}
   166 
   167 definition
   168   convex_unit :: "'a \<rightarrow> 'a convex_pd" where
   169   "convex_unit = compact_basis.basis_fun (\<lambda>a. convex_principal (PDUnit a))"
   170 
   171 definition
   172   convex_plus :: "'a convex_pd \<rightarrow> 'a convex_pd \<rightarrow> 'a convex_pd" where
   173   "convex_plus = convex_pd.basis_fun (\<lambda>t. convex_pd.basis_fun (\<lambda>u.
   174       convex_principal (PDPlus t u)))"
   175 
   176 abbreviation
   177   convex_add :: "'a convex_pd \<Rightarrow> 'a convex_pd \<Rightarrow> 'a convex_pd"
   178     (infixl "+\<natural>" 65) where
   179   "xs +\<natural> ys == convex_plus\<cdot>xs\<cdot>ys"
   180 
   181 syntax
   182   "_convex_pd" :: "args \<Rightarrow> 'a convex_pd" ("{_}\<natural>")
   183 
   184 translations
   185   "{x,xs}\<natural>" == "{x}\<natural> +\<natural> {xs}\<natural>"
   186   "{x}\<natural>" == "CONST convex_unit\<cdot>x"
   187 
   188 lemma convex_unit_Rep_compact_basis [simp]:
   189   "{Rep_compact_basis a}\<natural> = convex_principal (PDUnit a)"
   190 unfolding convex_unit_def
   191 by (simp add: compact_basis.basis_fun_principal PDUnit_convex_mono)
   192 
   193 lemma convex_plus_principal [simp]:
   194   "convex_principal t +\<natural> convex_principal u = convex_principal (PDPlus t u)"
   195 unfolding convex_plus_def
   196 by (simp add: convex_pd.basis_fun_principal
   197     convex_pd.basis_fun_mono PDPlus_convex_mono)
   198 
   199 interpretation convex_add: semilattice convex_add proof
   200   fix xs ys zs :: "'a convex_pd"
   201   show "(xs +\<natural> ys) +\<natural> zs = xs +\<natural> (ys +\<natural> zs)"
   202     apply (induct xs ys arbitrary: zs rule: convex_pd.principal_induct2, simp, simp)
   203     apply (rule_tac x=zs in convex_pd.principal_induct, simp)
   204     apply (simp add: PDPlus_assoc)
   205     done
   206   show "xs +\<natural> ys = ys +\<natural> xs"
   207     apply (induct xs ys rule: convex_pd.principal_induct2, simp, simp)
   208     apply (simp add: PDPlus_commute)
   209     done
   210   show "xs +\<natural> xs = xs"
   211     apply (induct xs rule: convex_pd.principal_induct, simp)
   212     apply (simp add: PDPlus_absorb)
   213     done
   214 qed
   215 
   216 lemmas convex_plus_assoc = convex_add.assoc
   217 lemmas convex_plus_commute = convex_add.commute
   218 lemmas convex_plus_absorb = convex_add.idem
   219 lemmas convex_plus_left_commute = convex_add.left_commute
   220 lemmas convex_plus_left_absorb = convex_add.left_idem
   221 
   222 text {* Useful for @{text "simp add: convex_plus_ac"} *}
   223 lemmas convex_plus_ac =
   224   convex_plus_assoc convex_plus_commute convex_plus_left_commute
   225 
   226 text {* Useful for @{text "simp only: convex_plus_aci"} *}
   227 lemmas convex_plus_aci =
   228   convex_plus_ac convex_plus_absorb convex_plus_left_absorb
   229 
   230 lemma convex_unit_below_plus_iff [simp]:
   231   "{x}\<natural> \<sqsubseteq> ys +\<natural> zs \<longleftrightarrow> {x}\<natural> \<sqsubseteq> ys \<and> {x}\<natural> \<sqsubseteq> zs"
   232 apply (induct x rule: compact_basis.principal_induct, simp)
   233 apply (induct ys rule: convex_pd.principal_induct, simp)
   234 apply (induct zs rule: convex_pd.principal_induct, simp)
   235 apply simp
   236 done
   237 
   238 lemma convex_plus_below_unit_iff [simp]:
   239   "xs +\<natural> ys \<sqsubseteq> {z}\<natural> \<longleftrightarrow> xs \<sqsubseteq> {z}\<natural> \<and> ys \<sqsubseteq> {z}\<natural>"
   240 apply (induct xs rule: convex_pd.principal_induct, simp)
   241 apply (induct ys rule: convex_pd.principal_induct, simp)
   242 apply (induct z rule: compact_basis.principal_induct, simp)
   243 apply simp
   244 done
   245 
   246 lemma convex_unit_below_iff [simp]: "{x}\<natural> \<sqsubseteq> {y}\<natural> \<longleftrightarrow> x \<sqsubseteq> y"
   247 apply (induct x rule: compact_basis.principal_induct, simp)
   248 apply (induct y rule: compact_basis.principal_induct, simp)
   249 apply simp
   250 done
   251 
   252 lemma convex_unit_eq_iff [simp]: "{x}\<natural> = {y}\<natural> \<longleftrightarrow> x = y"
   253 unfolding po_eq_conv by simp
   254 
   255 lemma convex_unit_strict [simp]: "{\<bottom>}\<natural> = \<bottom>"
   256 using convex_unit_Rep_compact_basis [of compact_bot]
   257 by (simp add: inst_convex_pd_pcpo)
   258 
   259 lemma convex_unit_bottom_iff [simp]: "{x}\<natural> = \<bottom> \<longleftrightarrow> x = \<bottom>"
   260 unfolding convex_unit_strict [symmetric] by (rule convex_unit_eq_iff)
   261 
   262 lemma compact_convex_unit: "compact x \<Longrightarrow> compact {x}\<natural>"
   263 by (auto dest!: compact_basis.compact_imp_principal)
   264 
   265 lemma compact_convex_unit_iff [simp]: "compact {x}\<natural> \<longleftrightarrow> compact x"
   266 apply (safe elim!: compact_convex_unit)
   267 apply (simp only: compact_def convex_unit_below_iff [symmetric])
   268 apply (erule adm_subst [OF cont_Rep_cfun2])
   269 done
   270 
   271 lemma compact_convex_plus [simp]:
   272   "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs +\<natural> ys)"
   273 by (auto dest!: convex_pd.compact_imp_principal)
   274 
   275 
   276 subsection {* Induction rules *}
   277 
   278 lemma convex_pd_induct1:
   279   assumes P: "adm P"
   280   assumes unit: "\<And>x. P {x}\<natural>"
   281   assumes insert: "\<And>x ys. \<lbrakk>P {x}\<natural>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<natural> +\<natural> ys)"
   282   shows "P (xs::'a convex_pd)"
   283 apply (induct xs rule: convex_pd.principal_induct, rule P)
   284 apply (induct_tac a rule: pd_basis_induct1)
   285 apply (simp only: convex_unit_Rep_compact_basis [symmetric])
   286 apply (rule unit)
   287 apply (simp only: convex_unit_Rep_compact_basis [symmetric]
   288                   convex_plus_principal [symmetric])
   289 apply (erule insert [OF unit])
   290 done
   291 
   292 lemma convex_pd_induct:
   293   assumes P: "adm P"
   294   assumes unit: "\<And>x. P {x}\<natural>"
   295   assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs +\<natural> ys)"
   296   shows "P (xs::'a convex_pd)"
   297 apply (induct xs rule: convex_pd.principal_induct, rule P)
   298 apply (induct_tac a rule: pd_basis_induct)
   299 apply (simp only: convex_unit_Rep_compact_basis [symmetric] unit)
   300 apply (simp only: convex_plus_principal [symmetric] plus)
   301 done
   302 
   303 
   304 subsection {* Monadic bind *}
   305 
   306 definition
   307   convex_bind_basis ::
   308   "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
   309   "convex_bind_basis = fold_pd
   310     (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
   311     (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<natural> y\<cdot>f)"
   312 
   313 lemma ACI_convex_bind:
   314   "class.ab_semigroup_idem_mult (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<natural> y\<cdot>f)"
   315 apply unfold_locales
   316 apply (simp add: convex_plus_assoc)
   317 apply (simp add: convex_plus_commute)
   318 apply (simp add: eta_cfun)
   319 done
   320 
   321 lemma convex_bind_basis_simps [simp]:
   322   "convex_bind_basis (PDUnit a) =
   323     (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
   324   "convex_bind_basis (PDPlus t u) =
   325     (\<Lambda> f. convex_bind_basis t\<cdot>f +\<natural> convex_bind_basis u\<cdot>f)"
   326 unfolding convex_bind_basis_def
   327 apply -
   328 apply (rule fold_pd_PDUnit [OF ACI_convex_bind])
   329 apply (rule fold_pd_PDPlus [OF ACI_convex_bind])
   330 done
   331 
   332 lemma convex_bind_basis_mono:
   333   "t \<le>\<natural> u \<Longrightarrow> convex_bind_basis t \<sqsubseteq> convex_bind_basis u"
   334 apply (erule convex_le_induct)
   335 apply (erule (1) below_trans)
   336 apply (simp add: monofun_LAM monofun_cfun)
   337 apply (simp add: monofun_LAM monofun_cfun)
   338 done
   339 
   340 definition
   341   convex_bind :: "'a convex_pd \<rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
   342   "convex_bind = convex_pd.basis_fun convex_bind_basis"
   343 
   344 lemma convex_bind_principal [simp]:
   345   "convex_bind\<cdot>(convex_principal t) = convex_bind_basis t"
   346 unfolding convex_bind_def
   347 apply (rule convex_pd.basis_fun_principal)
   348 apply (erule convex_bind_basis_mono)
   349 done
   350 
   351 lemma convex_bind_unit [simp]:
   352   "convex_bind\<cdot>{x}\<natural>\<cdot>f = f\<cdot>x"
   353 by (induct x rule: compact_basis.principal_induct, simp, simp)
   354 
   355 lemma convex_bind_plus [simp]:
   356   "convex_bind\<cdot>(xs +\<natural> ys)\<cdot>f = convex_bind\<cdot>xs\<cdot>f +\<natural> convex_bind\<cdot>ys\<cdot>f"
   357 by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
   358 
   359 lemma convex_bind_strict [simp]: "convex_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
   360 unfolding convex_unit_strict [symmetric] by (rule convex_bind_unit)
   361 
   362 
   363 subsection {* Map *}
   364 
   365 definition
   366   convex_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a convex_pd \<rightarrow> 'b convex_pd" where
   367   "convex_map = (\<Lambda> f xs. convex_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<natural>))"
   368 
   369 lemma convex_map_unit [simp]:
   370   "convex_map\<cdot>f\<cdot>{x}\<natural> = {f\<cdot>x}\<natural>"
   371 unfolding convex_map_def by simp
   372 
   373 lemma convex_map_plus [simp]:
   374   "convex_map\<cdot>f\<cdot>(xs +\<natural> ys) = convex_map\<cdot>f\<cdot>xs +\<natural> convex_map\<cdot>f\<cdot>ys"
   375 unfolding convex_map_def by simp
   376 
   377 lemma convex_map_ident: "convex_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
   378 by (induct xs rule: convex_pd_induct, simp_all)
   379 
   380 lemma convex_map_ID: "convex_map\<cdot>ID = ID"
   381 by (simp add: cfun_eq_iff ID_def convex_map_ident)
   382 
   383 lemma convex_map_map:
   384   "convex_map\<cdot>f\<cdot>(convex_map\<cdot>g\<cdot>xs) = convex_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
   385 by (induct xs rule: convex_pd_induct, simp_all)
   386 
   387 lemma ep_pair_convex_map: "ep_pair e p \<Longrightarrow> ep_pair (convex_map\<cdot>e) (convex_map\<cdot>p)"
   388 apply default
   389 apply (induct_tac x rule: convex_pd_induct, simp_all add: ep_pair.e_inverse)
   390 apply (induct_tac y rule: convex_pd_induct)
   391 apply (simp_all add: ep_pair.e_p_below monofun_cfun)
   392 done
   393 
   394 lemma deflation_convex_map: "deflation d \<Longrightarrow> deflation (convex_map\<cdot>d)"
   395 apply default
   396 apply (induct_tac x rule: convex_pd_induct, simp_all add: deflation.idem)
   397 apply (induct_tac x rule: convex_pd_induct)
   398 apply (simp_all add: deflation.below monofun_cfun)
   399 done
   400 
   401 (* FIXME: long proof! *)
   402 lemma finite_deflation_convex_map:
   403   assumes "finite_deflation d" shows "finite_deflation (convex_map\<cdot>d)"
   404 proof (rule finite_deflation_intro)
   405   interpret d: finite_deflation d by fact
   406   have "deflation d" by fact
   407   thus "deflation (convex_map\<cdot>d)" by (rule deflation_convex_map)
   408   have "finite (range (\<lambda>x. d\<cdot>x))" by (rule d.finite_range)
   409   hence "finite (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))"
   410     by (rule finite_vimageI, simp add: inj_on_def Rep_compact_basis_inject)
   411   hence "finite (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x)))" by simp
   412   hence "finite (Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))"
   413     by (rule finite_vimageI, simp add: inj_on_def Rep_pd_basis_inject)
   414   hence *: "finite (convex_principal ` Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))" by simp
   415   hence "finite (range (\<lambda>xs. convex_map\<cdot>d\<cdot>xs))"
   416     apply (rule rev_finite_subset)
   417     apply clarsimp
   418     apply (induct_tac xs rule: convex_pd.principal_induct)
   419     apply (simp add: adm_mem_finite *)
   420     apply (rename_tac t, induct_tac t rule: pd_basis_induct)
   421     apply (simp only: convex_unit_Rep_compact_basis [symmetric] convex_map_unit)
   422     apply simp
   423     apply (subgoal_tac "\<exists>b. d\<cdot>(Rep_compact_basis a) = Rep_compact_basis b")
   424     apply clarsimp
   425     apply (rule imageI)
   426     apply (rule vimageI2)
   427     apply (simp add: Rep_PDUnit)
   428     apply (rule range_eqI)
   429     apply (erule sym)
   430     apply (rule exI)
   431     apply (rule Abs_compact_basis_inverse [symmetric])
   432     apply (simp add: d.compact)
   433     apply (simp only: convex_plus_principal [symmetric] convex_map_plus)
   434     apply clarsimp
   435     apply (rule imageI)
   436     apply (rule vimageI2)
   437     apply (simp add: Rep_PDPlus)
   438     done
   439   thus "finite {xs. convex_map\<cdot>d\<cdot>xs = xs}"
   440     by (rule finite_range_imp_finite_fixes)
   441 qed
   442 
   443 subsection {* Convex powerdomain is a domain *}
   444 
   445 definition
   446   convex_approx :: "nat \<Rightarrow> udom convex_pd \<rightarrow> udom convex_pd"
   447 where
   448   "convex_approx = (\<lambda>i. convex_map\<cdot>(udom_approx i))"
   449 
   450 lemma convex_approx: "approx_chain convex_approx"
   451 using convex_map_ID finite_deflation_convex_map
   452 unfolding convex_approx_def by (rule approx_chain_lemma1)
   453 
   454 definition convex_defl :: "defl \<rightarrow> defl"
   455 where "convex_defl = defl_fun1 convex_approx convex_map"
   456 
   457 lemma cast_convex_defl:
   458   "cast\<cdot>(convex_defl\<cdot>A) =
   459     udom_emb convex_approx oo convex_map\<cdot>(cast\<cdot>A) oo udom_prj convex_approx"
   460 using convex_approx finite_deflation_convex_map
   461 unfolding convex_defl_def by (rule cast_defl_fun1)
   462 
   463 instantiation convex_pd :: ("domain") liftdomain
   464 begin
   465 
   466 definition
   467   "emb = udom_emb convex_approx oo convex_map\<cdot>emb"
   468 
   469 definition
   470   "prj = convex_map\<cdot>prj oo udom_prj convex_approx"
   471 
   472 definition
   473   "defl (t::'a convex_pd itself) = convex_defl\<cdot>DEFL('a)"
   474 
   475 definition
   476   "(liftemb :: 'a convex_pd u \<rightarrow> udom) = udom_emb u_approx oo u_map\<cdot>emb"
   477 
   478 definition
   479   "(liftprj :: udom \<rightarrow> 'a convex_pd u) = u_map\<cdot>prj oo udom_prj u_approx"
   480 
   481 definition
   482   "liftdefl (t::'a convex_pd itself) = u_defl\<cdot>DEFL('a convex_pd)"
   483 
   484 instance
   485 using liftemb_convex_pd_def liftprj_convex_pd_def liftdefl_convex_pd_def
   486 proof (rule liftdomain_class_intro)
   487   show "ep_pair emb (prj :: udom \<rightarrow> 'a convex_pd)"
   488     unfolding emb_convex_pd_def prj_convex_pd_def
   489     using ep_pair_udom [OF convex_approx]
   490     by (intro ep_pair_comp ep_pair_convex_map ep_pair_emb_prj)
   491 next
   492   show "cast\<cdot>DEFL('a convex_pd) = emb oo (prj :: udom \<rightarrow> 'a convex_pd)"
   493     unfolding emb_convex_pd_def prj_convex_pd_def defl_convex_pd_def cast_convex_defl
   494     by (simp add: cast_DEFL oo_def cfun_eq_iff convex_map_map)
   495 qed
   496 
   497 end
   498 
   499 text {* DEFL of type constructor = type combinator *}
   500 
   501 lemma DEFL_convex: "DEFL('a convex_pd) = convex_defl\<cdot>DEFL('a)"
   502 by (rule defl_convex_pd_def)
   503 
   504 
   505 subsection {* Join *}
   506 
   507 definition
   508   convex_join :: "'a convex_pd convex_pd \<rightarrow> 'a convex_pd" where
   509   "convex_join = (\<Lambda> xss. convex_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
   510 
   511 lemma convex_join_unit [simp]:
   512   "convex_join\<cdot>{xs}\<natural> = xs"
   513 unfolding convex_join_def by simp
   514 
   515 lemma convex_join_plus [simp]:
   516   "convex_join\<cdot>(xss +\<natural> yss) = convex_join\<cdot>xss +\<natural> convex_join\<cdot>yss"
   517 unfolding convex_join_def by simp
   518 
   519 lemma convex_join_map_unit:
   520   "convex_join\<cdot>(convex_map\<cdot>convex_unit\<cdot>xs) = xs"
   521 by (induct xs rule: convex_pd_induct, simp_all)
   522 
   523 lemma convex_join_map_join:
   524   "convex_join\<cdot>(convex_map\<cdot>convex_join\<cdot>xsss) = convex_join\<cdot>(convex_join\<cdot>xsss)"
   525 by (induct xsss rule: convex_pd_induct, simp_all)
   526 
   527 lemma convex_join_map_map:
   528   "convex_join\<cdot>(convex_map\<cdot>(convex_map\<cdot>f)\<cdot>xss) =
   529    convex_map\<cdot>f\<cdot>(convex_join\<cdot>xss)"
   530 by (induct xss rule: convex_pd_induct, simp_all)
   531 
   532 
   533 subsection {* Conversions to other powerdomains *}
   534 
   535 text {* Convex to upper *}
   536 
   537 lemma convex_le_imp_upper_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<sharp> u"
   538 unfolding convex_le_def by simp
   539 
   540 definition
   541   convex_to_upper :: "'a convex_pd \<rightarrow> 'a upper_pd" where
   542   "convex_to_upper = convex_pd.basis_fun upper_principal"
   543 
   544 lemma convex_to_upper_principal [simp]:
   545   "convex_to_upper\<cdot>(convex_principal t) = upper_principal t"
   546 unfolding convex_to_upper_def
   547 apply (rule convex_pd.basis_fun_principal)
   548 apply (rule upper_pd.principal_mono)
   549 apply (erule convex_le_imp_upper_le)
   550 done
   551 
   552 lemma convex_to_upper_unit [simp]:
   553   "convex_to_upper\<cdot>{x}\<natural> = {x}\<sharp>"
   554 by (induct x rule: compact_basis.principal_induct, simp, simp)
   555 
   556 lemma convex_to_upper_plus [simp]:
   557   "convex_to_upper\<cdot>(xs +\<natural> ys) = convex_to_upper\<cdot>xs +\<sharp> convex_to_upper\<cdot>ys"
   558 by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
   559 
   560 lemma convex_to_upper_bind [simp]:
   561   "convex_to_upper\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
   562     upper_bind\<cdot>(convex_to_upper\<cdot>xs)\<cdot>(convex_to_upper oo f)"
   563 by (induct xs rule: convex_pd_induct, simp, simp, simp)
   564 
   565 lemma convex_to_upper_map [simp]:
   566   "convex_to_upper\<cdot>(convex_map\<cdot>f\<cdot>xs) = upper_map\<cdot>f\<cdot>(convex_to_upper\<cdot>xs)"
   567 by (simp add: convex_map_def upper_map_def cfcomp_LAM)
   568 
   569 lemma convex_to_upper_join [simp]:
   570   "convex_to_upper\<cdot>(convex_join\<cdot>xss) =
   571     upper_bind\<cdot>(convex_to_upper\<cdot>xss)\<cdot>convex_to_upper"
   572 by (simp add: convex_join_def upper_join_def cfcomp_LAM eta_cfun)
   573 
   574 text {* Convex to lower *}
   575 
   576 lemma convex_le_imp_lower_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<flat> u"
   577 unfolding convex_le_def by simp
   578 
   579 definition
   580   convex_to_lower :: "'a convex_pd \<rightarrow> 'a lower_pd" where
   581   "convex_to_lower = convex_pd.basis_fun lower_principal"
   582 
   583 lemma convex_to_lower_principal [simp]:
   584   "convex_to_lower\<cdot>(convex_principal t) = lower_principal t"
   585 unfolding convex_to_lower_def
   586 apply (rule convex_pd.basis_fun_principal)
   587 apply (rule lower_pd.principal_mono)
   588 apply (erule convex_le_imp_lower_le)
   589 done
   590 
   591 lemma convex_to_lower_unit [simp]:
   592   "convex_to_lower\<cdot>{x}\<natural> = {x}\<flat>"
   593 by (induct x rule: compact_basis.principal_induct, simp, simp)
   594 
   595 lemma convex_to_lower_plus [simp]:
   596   "convex_to_lower\<cdot>(xs +\<natural> ys) = convex_to_lower\<cdot>xs +\<flat> convex_to_lower\<cdot>ys"
   597 by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
   598 
   599 lemma convex_to_lower_bind [simp]:
   600   "convex_to_lower\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
   601     lower_bind\<cdot>(convex_to_lower\<cdot>xs)\<cdot>(convex_to_lower oo f)"
   602 by (induct xs rule: convex_pd_induct, simp, simp, simp)
   603 
   604 lemma convex_to_lower_map [simp]:
   605   "convex_to_lower\<cdot>(convex_map\<cdot>f\<cdot>xs) = lower_map\<cdot>f\<cdot>(convex_to_lower\<cdot>xs)"
   606 by (simp add: convex_map_def lower_map_def cfcomp_LAM)
   607 
   608 lemma convex_to_lower_join [simp]:
   609   "convex_to_lower\<cdot>(convex_join\<cdot>xss) =
   610     lower_bind\<cdot>(convex_to_lower\<cdot>xss)\<cdot>convex_to_lower"
   611 by (simp add: convex_join_def lower_join_def cfcomp_LAM eta_cfun)
   612 
   613 text {* Ordering property *}
   614 
   615 lemma convex_pd_below_iff:
   616   "(xs \<sqsubseteq> ys) =
   617     (convex_to_upper\<cdot>xs \<sqsubseteq> convex_to_upper\<cdot>ys \<and>
   618      convex_to_lower\<cdot>xs \<sqsubseteq> convex_to_lower\<cdot>ys)"
   619 apply (induct xs rule: convex_pd.principal_induct, simp)
   620 apply (induct ys rule: convex_pd.principal_induct, simp)
   621 apply (simp add: convex_le_def)
   622 done
   623 
   624 lemmas convex_plus_below_plus_iff =
   625   convex_pd_below_iff [where xs="xs +\<natural> ys" and ys="zs +\<natural> ws", standard]
   626 
   627 lemmas convex_pd_below_simps =
   628   convex_unit_below_plus_iff
   629   convex_plus_below_unit_iff
   630   convex_plus_below_plus_iff
   631   convex_unit_below_iff
   632   convex_to_upper_unit
   633   convex_to_upper_plus
   634   convex_to_lower_unit
   635   convex_to_lower_plus
   636   upper_pd_below_simps
   637   lower_pd_below_simps
   638 
   639 end