src/HOL/HOLCF/ConvexPD.thy
author huffman
Sun Dec 19 05:15:31 2010 -0800 (2010-12-19)
changeset 41286 3d7685a4a5ff
parent 41111 b497cc48e563
child 41287 029a6fc1bfb8
permissions -rw-r--r--
reintroduce 'bifinite' class, now with existentially-quantified approx function (cf. b525988432e9)
     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 (rule convex_le.ex_ideal)
   125 
   126 type_notation (xsymbols) convex_pd ("('(_')\<natural>)")
   127 
   128 instantiation convex_pd :: ("domain") below
   129 begin
   130 
   131 definition
   132   "x \<sqsubseteq> y \<longleftrightarrow> Rep_convex_pd x \<subseteq> Rep_convex_pd y"
   133 
   134 instance ..
   135 end
   136 
   137 instance convex_pd :: ("domain") po
   138 using type_definition_convex_pd below_convex_pd_def
   139 by (rule convex_le.typedef_ideal_po)
   140 
   141 instance convex_pd :: ("domain") cpo
   142 using type_definition_convex_pd below_convex_pd_def
   143 by (rule convex_le.typedef_ideal_cpo)
   144 
   145 definition
   146   convex_principal :: "'a pd_basis \<Rightarrow> 'a convex_pd" where
   147   "convex_principal t = Abs_convex_pd {u. u \<le>\<natural> t}"
   148 
   149 interpretation convex_pd:
   150   ideal_completion convex_le convex_principal Rep_convex_pd
   151 using type_definition_convex_pd below_convex_pd_def
   152 using convex_principal_def pd_basis_countable
   153 by (rule convex_le.typedef_ideal_completion)
   154 
   155 text {* Convex powerdomain is pointed *}
   156 
   157 lemma convex_pd_minimal: "convex_principal (PDUnit compact_bot) \<sqsubseteq> ys"
   158 by (induct ys rule: convex_pd.principal_induct, simp, simp)
   159 
   160 instance convex_pd :: ("domain") pcpo
   161 by intro_classes (fast intro: convex_pd_minimal)
   162 
   163 lemma inst_convex_pd_pcpo: "\<bottom> = convex_principal (PDUnit compact_bot)"
   164 by (rule convex_pd_minimal [THEN UU_I, symmetric])
   165 
   166 
   167 subsection {* Monadic unit and plus *}
   168 
   169 definition
   170   convex_unit :: "'a \<rightarrow> 'a convex_pd" where
   171   "convex_unit = compact_basis.basis_fun (\<lambda>a. convex_principal (PDUnit a))"
   172 
   173 definition
   174   convex_plus :: "'a convex_pd \<rightarrow> 'a convex_pd \<rightarrow> 'a convex_pd" where
   175   "convex_plus = convex_pd.basis_fun (\<lambda>t. convex_pd.basis_fun (\<lambda>u.
   176       convex_principal (PDPlus t u)))"
   177 
   178 abbreviation
   179   convex_add :: "'a convex_pd \<Rightarrow> 'a convex_pd \<Rightarrow> 'a convex_pd"
   180     (infixl "+\<natural>" 65) where
   181   "xs +\<natural> ys == convex_plus\<cdot>xs\<cdot>ys"
   182 
   183 syntax
   184   "_convex_pd" :: "args \<Rightarrow> 'a convex_pd" ("{_}\<natural>")
   185 
   186 translations
   187   "{x,xs}\<natural>" == "{x}\<natural> +\<natural> {xs}\<natural>"
   188   "{x}\<natural>" == "CONST convex_unit\<cdot>x"
   189 
   190 lemma convex_unit_Rep_compact_basis [simp]:
   191   "{Rep_compact_basis a}\<natural> = convex_principal (PDUnit a)"
   192 unfolding convex_unit_def
   193 by (simp add: compact_basis.basis_fun_principal PDUnit_convex_mono)
   194 
   195 lemma convex_plus_principal [simp]:
   196   "convex_principal t +\<natural> convex_principal u = convex_principal (PDPlus t u)"
   197 unfolding convex_plus_def
   198 by (simp add: convex_pd.basis_fun_principal
   199     convex_pd.basis_fun_mono PDPlus_convex_mono)
   200 
   201 interpretation convex_add: semilattice convex_add proof
   202   fix xs ys zs :: "'a convex_pd"
   203   show "(xs +\<natural> ys) +\<natural> zs = xs +\<natural> (ys +\<natural> zs)"
   204     apply (induct xs ys arbitrary: zs rule: convex_pd.principal_induct2, simp, simp)
   205     apply (rule_tac x=zs in convex_pd.principal_induct, simp)
   206     apply (simp add: PDPlus_assoc)
   207     done
   208   show "xs +\<natural> ys = ys +\<natural> xs"
   209     apply (induct xs ys rule: convex_pd.principal_induct2, simp, simp)
   210     apply (simp add: PDPlus_commute)
   211     done
   212   show "xs +\<natural> xs = xs"
   213     apply (induct xs rule: convex_pd.principal_induct, simp)
   214     apply (simp add: PDPlus_absorb)
   215     done
   216 qed
   217 
   218 lemmas convex_plus_assoc = convex_add.assoc
   219 lemmas convex_plus_commute = convex_add.commute
   220 lemmas convex_plus_absorb = convex_add.idem
   221 lemmas convex_plus_left_commute = convex_add.left_commute
   222 lemmas convex_plus_left_absorb = convex_add.left_idem
   223 
   224 text {* Useful for @{text "simp add: convex_plus_ac"} *}
   225 lemmas convex_plus_ac =
   226   convex_plus_assoc convex_plus_commute convex_plus_left_commute
   227 
   228 text {* Useful for @{text "simp only: convex_plus_aci"} *}
   229 lemmas convex_plus_aci =
   230   convex_plus_ac convex_plus_absorb convex_plus_left_absorb
   231 
   232 lemma convex_unit_below_plus_iff [simp]:
   233   "{x}\<natural> \<sqsubseteq> ys +\<natural> zs \<longleftrightarrow> {x}\<natural> \<sqsubseteq> ys \<and> {x}\<natural> \<sqsubseteq> zs"
   234 apply (induct x rule: compact_basis.principal_induct, simp)
   235 apply (induct ys rule: convex_pd.principal_induct, simp)
   236 apply (induct zs rule: convex_pd.principal_induct, simp)
   237 apply simp
   238 done
   239 
   240 lemma convex_plus_below_unit_iff [simp]:
   241   "xs +\<natural> ys \<sqsubseteq> {z}\<natural> \<longleftrightarrow> xs \<sqsubseteq> {z}\<natural> \<and> ys \<sqsubseteq> {z}\<natural>"
   242 apply (induct xs rule: convex_pd.principal_induct, simp)
   243 apply (induct ys rule: convex_pd.principal_induct, simp)
   244 apply (induct z rule: compact_basis.principal_induct, simp)
   245 apply simp
   246 done
   247 
   248 lemma convex_unit_below_iff [simp]: "{x}\<natural> \<sqsubseteq> {y}\<natural> \<longleftrightarrow> x \<sqsubseteq> y"
   249 apply (induct x rule: compact_basis.principal_induct, simp)
   250 apply (induct y rule: compact_basis.principal_induct, simp)
   251 apply simp
   252 done
   253 
   254 lemma convex_unit_eq_iff [simp]: "{x}\<natural> = {y}\<natural> \<longleftrightarrow> x = y"
   255 unfolding po_eq_conv by simp
   256 
   257 lemma convex_unit_strict [simp]: "{\<bottom>}\<natural> = \<bottom>"
   258 using convex_unit_Rep_compact_basis [of compact_bot]
   259 by (simp add: inst_convex_pd_pcpo)
   260 
   261 lemma convex_unit_bottom_iff [simp]: "{x}\<natural> = \<bottom> \<longleftrightarrow> x = \<bottom>"
   262 unfolding convex_unit_strict [symmetric] by (rule convex_unit_eq_iff)
   263 
   264 lemma compact_convex_unit: "compact x \<Longrightarrow> compact {x}\<natural>"
   265 by (auto dest!: compact_basis.compact_imp_principal)
   266 
   267 lemma compact_convex_unit_iff [simp]: "compact {x}\<natural> \<longleftrightarrow> compact x"
   268 apply (safe elim!: compact_convex_unit)
   269 apply (simp only: compact_def convex_unit_below_iff [symmetric])
   270 apply (erule adm_subst [OF cont_Rep_cfun2])
   271 done
   272 
   273 lemma compact_convex_plus [simp]:
   274   "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs +\<natural> ys)"
   275 by (auto dest!: convex_pd.compact_imp_principal)
   276 
   277 
   278 subsection {* Induction rules *}
   279 
   280 lemma convex_pd_induct1:
   281   assumes P: "adm P"
   282   assumes unit: "\<And>x. P {x}\<natural>"
   283   assumes insert: "\<And>x ys. \<lbrakk>P {x}\<natural>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<natural> +\<natural> ys)"
   284   shows "P (xs::'a convex_pd)"
   285 apply (induct xs rule: convex_pd.principal_induct, rule P)
   286 apply (induct_tac a rule: pd_basis_induct1)
   287 apply (simp only: convex_unit_Rep_compact_basis [symmetric])
   288 apply (rule unit)
   289 apply (simp only: convex_unit_Rep_compact_basis [symmetric]
   290                   convex_plus_principal [symmetric])
   291 apply (erule insert [OF unit])
   292 done
   293 
   294 lemma convex_pd_induct
   295   [case_names adm convex_unit convex_plus, induct type: convex_pd]:
   296   assumes P: "adm P"
   297   assumes unit: "\<And>x. P {x}\<natural>"
   298   assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs +\<natural> ys)"
   299   shows "P (xs::'a convex_pd)"
   300 apply (induct xs rule: convex_pd.principal_induct, rule P)
   301 apply (induct_tac a rule: pd_basis_induct)
   302 apply (simp only: convex_unit_Rep_compact_basis [symmetric] unit)
   303 apply (simp only: convex_plus_principal [symmetric] plus)
   304 done
   305 
   306 
   307 subsection {* Monadic bind *}
   308 
   309 definition
   310   convex_bind_basis ::
   311   "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
   312   "convex_bind_basis = fold_pd
   313     (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
   314     (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<natural> y\<cdot>f)"
   315 
   316 lemma ACI_convex_bind:
   317   "class.ab_semigroup_idem_mult (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<natural> y\<cdot>f)"
   318 apply unfold_locales
   319 apply (simp add: convex_plus_assoc)
   320 apply (simp add: convex_plus_commute)
   321 apply (simp add: eta_cfun)
   322 done
   323 
   324 lemma convex_bind_basis_simps [simp]:
   325   "convex_bind_basis (PDUnit a) =
   326     (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
   327   "convex_bind_basis (PDPlus t u) =
   328     (\<Lambda> f. convex_bind_basis t\<cdot>f +\<natural> convex_bind_basis u\<cdot>f)"
   329 unfolding convex_bind_basis_def
   330 apply -
   331 apply (rule fold_pd_PDUnit [OF ACI_convex_bind])
   332 apply (rule fold_pd_PDPlus [OF ACI_convex_bind])
   333 done
   334 
   335 lemma convex_bind_basis_mono:
   336   "t \<le>\<natural> u \<Longrightarrow> convex_bind_basis t \<sqsubseteq> convex_bind_basis u"
   337 apply (erule convex_le_induct)
   338 apply (erule (1) below_trans)
   339 apply (simp add: monofun_LAM monofun_cfun)
   340 apply (simp add: monofun_LAM monofun_cfun)
   341 done
   342 
   343 definition
   344   convex_bind :: "'a convex_pd \<rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
   345   "convex_bind = convex_pd.basis_fun convex_bind_basis"
   346 
   347 syntax
   348   "_convex_bind" :: "[logic, logic, logic] \<Rightarrow> logic"
   349     ("(3\<Union>\<natural>_\<in>_./ _)" [0, 0, 10] 10)
   350 
   351 translations
   352   "\<Union>\<natural>x\<in>xs. e" == "CONST convex_bind\<cdot>xs\<cdot>(\<Lambda> x. e)"
   353 
   354 lemma convex_bind_principal [simp]:
   355   "convex_bind\<cdot>(convex_principal t) = convex_bind_basis t"
   356 unfolding convex_bind_def
   357 apply (rule convex_pd.basis_fun_principal)
   358 apply (erule convex_bind_basis_mono)
   359 done
   360 
   361 lemma convex_bind_unit [simp]:
   362   "convex_bind\<cdot>{x}\<natural>\<cdot>f = f\<cdot>x"
   363 by (induct x rule: compact_basis.principal_induct, simp, simp)
   364 
   365 lemma convex_bind_plus [simp]:
   366   "convex_bind\<cdot>(xs +\<natural> ys)\<cdot>f = convex_bind\<cdot>xs\<cdot>f +\<natural> convex_bind\<cdot>ys\<cdot>f"
   367 by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
   368 
   369 lemma convex_bind_strict [simp]: "convex_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
   370 unfolding convex_unit_strict [symmetric] by (rule convex_bind_unit)
   371 
   372 lemma convex_bind_bind:
   373   "convex_bind\<cdot>(convex_bind\<cdot>xs\<cdot>f)\<cdot>g =
   374     convex_bind\<cdot>xs\<cdot>(\<Lambda> x. convex_bind\<cdot>(f\<cdot>x)\<cdot>g)"
   375 by (induct xs, simp_all)
   376 
   377 
   378 subsection {* Map *}
   379 
   380 definition
   381   convex_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a convex_pd \<rightarrow> 'b convex_pd" where
   382   "convex_map = (\<Lambda> f xs. convex_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<natural>))"
   383 
   384 lemma convex_map_unit [simp]:
   385   "convex_map\<cdot>f\<cdot>{x}\<natural> = {f\<cdot>x}\<natural>"
   386 unfolding convex_map_def by simp
   387 
   388 lemma convex_map_plus [simp]:
   389   "convex_map\<cdot>f\<cdot>(xs +\<natural> ys) = convex_map\<cdot>f\<cdot>xs +\<natural> convex_map\<cdot>f\<cdot>ys"
   390 unfolding convex_map_def by simp
   391 
   392 lemma convex_map_bottom [simp]: "convex_map\<cdot>f\<cdot>\<bottom> = {f\<cdot>\<bottom>}\<natural>"
   393 unfolding convex_map_def by simp
   394 
   395 lemma convex_map_ident: "convex_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
   396 by (induct xs rule: convex_pd_induct, simp_all)
   397 
   398 lemma convex_map_ID: "convex_map\<cdot>ID = ID"
   399 by (simp add: cfun_eq_iff ID_def convex_map_ident)
   400 
   401 lemma convex_map_map:
   402   "convex_map\<cdot>f\<cdot>(convex_map\<cdot>g\<cdot>xs) = convex_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
   403 by (induct xs rule: convex_pd_induct, simp_all)
   404 
   405 lemma convex_bind_map:
   406   "convex_bind\<cdot>(convex_map\<cdot>f\<cdot>xs)\<cdot>g = convex_bind\<cdot>xs\<cdot>(\<Lambda> x. g\<cdot>(f\<cdot>x))"
   407 by (simp add: convex_map_def convex_bind_bind)
   408 
   409 lemma convex_map_bind:
   410   "convex_map\<cdot>f\<cdot>(convex_bind\<cdot>xs\<cdot>g) = convex_bind\<cdot>xs\<cdot>(\<Lambda> x. convex_map\<cdot>f\<cdot>(g\<cdot>x))"
   411 by (simp add: convex_map_def convex_bind_bind)
   412 
   413 lemma ep_pair_convex_map: "ep_pair e p \<Longrightarrow> ep_pair (convex_map\<cdot>e) (convex_map\<cdot>p)"
   414 apply default
   415 apply (induct_tac x rule: convex_pd_induct, simp_all add: ep_pair.e_inverse)
   416 apply (induct_tac y rule: convex_pd_induct)
   417 apply (simp_all add: ep_pair.e_p_below monofun_cfun)
   418 done
   419 
   420 lemma deflation_convex_map: "deflation d \<Longrightarrow> deflation (convex_map\<cdot>d)"
   421 apply default
   422 apply (induct_tac x rule: convex_pd_induct, simp_all add: deflation.idem)
   423 apply (induct_tac x rule: convex_pd_induct)
   424 apply (simp_all add: deflation.below monofun_cfun)
   425 done
   426 
   427 (* FIXME: long proof! *)
   428 lemma finite_deflation_convex_map:
   429   assumes "finite_deflation d" shows "finite_deflation (convex_map\<cdot>d)"
   430 proof (rule finite_deflation_intro)
   431   interpret d: finite_deflation d by fact
   432   have "deflation d" by fact
   433   thus "deflation (convex_map\<cdot>d)" by (rule deflation_convex_map)
   434   have "finite (range (\<lambda>x. d\<cdot>x))" by (rule d.finite_range)
   435   hence "finite (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))"
   436     by (rule finite_vimageI, simp add: inj_on_def Rep_compact_basis_inject)
   437   hence "finite (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x)))" by simp
   438   hence "finite (Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))"
   439     by (rule finite_vimageI, simp add: inj_on_def Rep_pd_basis_inject)
   440   hence *: "finite (convex_principal ` Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))" by simp
   441   hence "finite (range (\<lambda>xs. convex_map\<cdot>d\<cdot>xs))"
   442     apply (rule rev_finite_subset)
   443     apply clarsimp
   444     apply (induct_tac xs rule: convex_pd.principal_induct)
   445     apply (simp add: adm_mem_finite *)
   446     apply (rename_tac t, induct_tac t rule: pd_basis_induct)
   447     apply (simp only: convex_unit_Rep_compact_basis [symmetric] convex_map_unit)
   448     apply simp
   449     apply (subgoal_tac "\<exists>b. d\<cdot>(Rep_compact_basis a) = Rep_compact_basis b")
   450     apply clarsimp
   451     apply (rule imageI)
   452     apply (rule vimageI2)
   453     apply (simp add: Rep_PDUnit)
   454     apply (rule range_eqI)
   455     apply (erule sym)
   456     apply (rule exI)
   457     apply (rule Abs_compact_basis_inverse [symmetric])
   458     apply (simp add: d.compact)
   459     apply (simp only: convex_plus_principal [symmetric] convex_map_plus)
   460     apply clarsimp
   461     apply (rule imageI)
   462     apply (rule vimageI2)
   463     apply (simp add: Rep_PDPlus)
   464     done
   465   thus "finite {xs. convex_map\<cdot>d\<cdot>xs = xs}"
   466     by (rule finite_range_imp_finite_fixes)
   467 qed
   468 
   469 subsection {* Convex powerdomain is a domain *}
   470 
   471 lemma approx_chain_convex_map:
   472   assumes "approx_chain a"
   473   shows "approx_chain (\<lambda>i. convex_map\<cdot>(a i))"
   474   using assms unfolding approx_chain_def
   475   by (simp add: lub_APP convex_map_ID finite_deflation_convex_map)
   476 
   477 instance convex_pd :: ("domain") bifinite
   478 proof
   479   show "\<exists>(a::nat \<Rightarrow> 'a convex_pd \<rightarrow> 'a convex_pd). approx_chain a"
   480     using bifinite [where 'a='a]
   481     by (fast intro!: approx_chain_convex_map)
   482 qed
   483 
   484 definition
   485   convex_approx :: "nat \<Rightarrow> udom convex_pd \<rightarrow> udom convex_pd"
   486 where
   487   "convex_approx = (\<lambda>i. convex_map\<cdot>(udom_approx i))"
   488 
   489 lemma convex_approx: "approx_chain convex_approx"
   490 using convex_map_ID finite_deflation_convex_map
   491 unfolding convex_approx_def by (rule approx_chain_lemma1)
   492 
   493 definition convex_defl :: "defl \<rightarrow> defl"
   494 where "convex_defl = defl_fun1 convex_approx convex_map"
   495 
   496 lemma cast_convex_defl:
   497   "cast\<cdot>(convex_defl\<cdot>A) =
   498     udom_emb convex_approx oo convex_map\<cdot>(cast\<cdot>A) oo udom_prj convex_approx"
   499 using convex_approx finite_deflation_convex_map
   500 unfolding convex_defl_def by (rule cast_defl_fun1)
   501 
   502 instantiation convex_pd :: ("domain") liftdomain
   503 begin
   504 
   505 definition
   506   "emb = udom_emb convex_approx oo convex_map\<cdot>emb"
   507 
   508 definition
   509   "prj = convex_map\<cdot>prj oo udom_prj convex_approx"
   510 
   511 definition
   512   "defl (t::'a convex_pd itself) = convex_defl\<cdot>DEFL('a)"
   513 
   514 definition
   515   "(liftemb :: 'a convex_pd u \<rightarrow> udom) = udom_emb u_approx oo u_map\<cdot>emb"
   516 
   517 definition
   518   "(liftprj :: udom \<rightarrow> 'a convex_pd u) = u_map\<cdot>prj oo udom_prj u_approx"
   519 
   520 definition
   521   "liftdefl (t::'a convex_pd itself) = u_defl\<cdot>DEFL('a convex_pd)"
   522 
   523 instance
   524 using liftemb_convex_pd_def liftprj_convex_pd_def liftdefl_convex_pd_def
   525 proof (rule liftdomain_class_intro)
   526   show "ep_pair emb (prj :: udom \<rightarrow> 'a convex_pd)"
   527     unfolding emb_convex_pd_def prj_convex_pd_def
   528     using ep_pair_udom [OF convex_approx]
   529     by (intro ep_pair_comp ep_pair_convex_map ep_pair_emb_prj)
   530 next
   531   show "cast\<cdot>DEFL('a convex_pd) = emb oo (prj :: udom \<rightarrow> 'a convex_pd)"
   532     unfolding emb_convex_pd_def prj_convex_pd_def defl_convex_pd_def cast_convex_defl
   533     by (simp add: cast_DEFL oo_def cfun_eq_iff convex_map_map)
   534 qed
   535 
   536 end
   537 
   538 text {* DEFL of type constructor = type combinator *}
   539 
   540 lemma DEFL_convex: "DEFL('a convex_pd) = convex_defl\<cdot>DEFL('a)"
   541 by (rule defl_convex_pd_def)
   542 
   543 
   544 subsection {* Join *}
   545 
   546 definition
   547   convex_join :: "'a convex_pd convex_pd \<rightarrow> 'a convex_pd" where
   548   "convex_join = (\<Lambda> xss. convex_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
   549 
   550 lemma convex_join_unit [simp]:
   551   "convex_join\<cdot>{xs}\<natural> = xs"
   552 unfolding convex_join_def by simp
   553 
   554 lemma convex_join_plus [simp]:
   555   "convex_join\<cdot>(xss +\<natural> yss) = convex_join\<cdot>xss +\<natural> convex_join\<cdot>yss"
   556 unfolding convex_join_def by simp
   557 
   558 lemma convex_join_bottom [simp]: "convex_join\<cdot>\<bottom> = \<bottom>"
   559 unfolding convex_join_def by simp
   560 
   561 lemma convex_join_map_unit:
   562   "convex_join\<cdot>(convex_map\<cdot>convex_unit\<cdot>xs) = xs"
   563 by (induct xs rule: convex_pd_induct, simp_all)
   564 
   565 lemma convex_join_map_join:
   566   "convex_join\<cdot>(convex_map\<cdot>convex_join\<cdot>xsss) = convex_join\<cdot>(convex_join\<cdot>xsss)"
   567 by (induct xsss rule: convex_pd_induct, simp_all)
   568 
   569 lemma convex_join_map_map:
   570   "convex_join\<cdot>(convex_map\<cdot>(convex_map\<cdot>f)\<cdot>xss) =
   571    convex_map\<cdot>f\<cdot>(convex_join\<cdot>xss)"
   572 by (induct xss rule: convex_pd_induct, simp_all)
   573 
   574 
   575 subsection {* Conversions to other powerdomains *}
   576 
   577 text {* Convex to upper *}
   578 
   579 lemma convex_le_imp_upper_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<sharp> u"
   580 unfolding convex_le_def by simp
   581 
   582 definition
   583   convex_to_upper :: "'a convex_pd \<rightarrow> 'a upper_pd" where
   584   "convex_to_upper = convex_pd.basis_fun upper_principal"
   585 
   586 lemma convex_to_upper_principal [simp]:
   587   "convex_to_upper\<cdot>(convex_principal t) = upper_principal t"
   588 unfolding convex_to_upper_def
   589 apply (rule convex_pd.basis_fun_principal)
   590 apply (rule upper_pd.principal_mono)
   591 apply (erule convex_le_imp_upper_le)
   592 done
   593 
   594 lemma convex_to_upper_unit [simp]:
   595   "convex_to_upper\<cdot>{x}\<natural> = {x}\<sharp>"
   596 by (induct x rule: compact_basis.principal_induct, simp, simp)
   597 
   598 lemma convex_to_upper_plus [simp]:
   599   "convex_to_upper\<cdot>(xs +\<natural> ys) = convex_to_upper\<cdot>xs +\<sharp> convex_to_upper\<cdot>ys"
   600 by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
   601 
   602 lemma convex_to_upper_bind [simp]:
   603   "convex_to_upper\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
   604     upper_bind\<cdot>(convex_to_upper\<cdot>xs)\<cdot>(convex_to_upper oo f)"
   605 by (induct xs rule: convex_pd_induct, simp, simp, simp)
   606 
   607 lemma convex_to_upper_map [simp]:
   608   "convex_to_upper\<cdot>(convex_map\<cdot>f\<cdot>xs) = upper_map\<cdot>f\<cdot>(convex_to_upper\<cdot>xs)"
   609 by (simp add: convex_map_def upper_map_def cfcomp_LAM)
   610 
   611 lemma convex_to_upper_join [simp]:
   612   "convex_to_upper\<cdot>(convex_join\<cdot>xss) =
   613     upper_bind\<cdot>(convex_to_upper\<cdot>xss)\<cdot>convex_to_upper"
   614 by (simp add: convex_join_def upper_join_def cfcomp_LAM eta_cfun)
   615 
   616 text {* Convex to lower *}
   617 
   618 lemma convex_le_imp_lower_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<flat> u"
   619 unfolding convex_le_def by simp
   620 
   621 definition
   622   convex_to_lower :: "'a convex_pd \<rightarrow> 'a lower_pd" where
   623   "convex_to_lower = convex_pd.basis_fun lower_principal"
   624 
   625 lemma convex_to_lower_principal [simp]:
   626   "convex_to_lower\<cdot>(convex_principal t) = lower_principal t"
   627 unfolding convex_to_lower_def
   628 apply (rule convex_pd.basis_fun_principal)
   629 apply (rule lower_pd.principal_mono)
   630 apply (erule convex_le_imp_lower_le)
   631 done
   632 
   633 lemma convex_to_lower_unit [simp]:
   634   "convex_to_lower\<cdot>{x}\<natural> = {x}\<flat>"
   635 by (induct x rule: compact_basis.principal_induct, simp, simp)
   636 
   637 lemma convex_to_lower_plus [simp]:
   638   "convex_to_lower\<cdot>(xs +\<natural> ys) = convex_to_lower\<cdot>xs +\<flat> convex_to_lower\<cdot>ys"
   639 by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
   640 
   641 lemma convex_to_lower_bind [simp]:
   642   "convex_to_lower\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
   643     lower_bind\<cdot>(convex_to_lower\<cdot>xs)\<cdot>(convex_to_lower oo f)"
   644 by (induct xs rule: convex_pd_induct, simp, simp, simp)
   645 
   646 lemma convex_to_lower_map [simp]:
   647   "convex_to_lower\<cdot>(convex_map\<cdot>f\<cdot>xs) = lower_map\<cdot>f\<cdot>(convex_to_lower\<cdot>xs)"
   648 by (simp add: convex_map_def lower_map_def cfcomp_LAM)
   649 
   650 lemma convex_to_lower_join [simp]:
   651   "convex_to_lower\<cdot>(convex_join\<cdot>xss) =
   652     lower_bind\<cdot>(convex_to_lower\<cdot>xss)\<cdot>convex_to_lower"
   653 by (simp add: convex_join_def lower_join_def cfcomp_LAM eta_cfun)
   654 
   655 text {* Ordering property *}
   656 
   657 lemma convex_pd_below_iff:
   658   "(xs \<sqsubseteq> ys) =
   659     (convex_to_upper\<cdot>xs \<sqsubseteq> convex_to_upper\<cdot>ys \<and>
   660      convex_to_lower\<cdot>xs \<sqsubseteq> convex_to_lower\<cdot>ys)"
   661 apply (induct xs rule: convex_pd.principal_induct, simp)
   662 apply (induct ys rule: convex_pd.principal_induct, simp)
   663 apply (simp add: convex_le_def)
   664 done
   665 
   666 lemmas convex_plus_below_plus_iff =
   667   convex_pd_below_iff [where xs="xs +\<natural> ys" and ys="zs +\<natural> ws", standard]
   668 
   669 lemmas convex_pd_below_simps =
   670   convex_unit_below_plus_iff
   671   convex_plus_below_unit_iff
   672   convex_plus_below_plus_iff
   673   convex_unit_below_iff
   674   convex_to_upper_unit
   675   convex_to_upper_plus
   676   convex_to_lower_unit
   677   convex_to_lower_plus
   678   upper_pd_below_simps
   679   lower_pd_below_simps
   680 
   681 end