src/HOLCF/UpperPD.thy
changeset 25904 8161f137b0e9
child 25925 3dc4acca4388
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOLCF/UpperPD.thy	Mon Jan 14 19:26:41 2008 +0100
     1.3 @@ -0,0 +1,508 @@
     1.4 +(*  Title:      HOLCF/UpperPD.thy
     1.5 +    ID:         $Id$
     1.6 +    Author:     Brian Huffman
     1.7 +*)
     1.8 +
     1.9 +header {* Upper powerdomain *}
    1.10 +
    1.11 +theory UpperPD
    1.12 +imports CompactBasis
    1.13 +begin
    1.14 +
    1.15 +subsection {* Basis preorder *}
    1.16 +
    1.17 +definition
    1.18 +  upper_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<sharp>" 50) where
    1.19 +  "upper_le = (\<lambda>u v. \<forall>y\<in>Rep_pd_basis v. \<exists>x\<in>Rep_pd_basis u. compact_le x y)"
    1.20 +
    1.21 +lemma upper_le_refl [simp]: "t \<le>\<sharp> t"
    1.22 +unfolding upper_le_def by (fast intro: compact_le_refl)
    1.23 +
    1.24 +lemma upper_le_trans: "\<lbrakk>t \<le>\<sharp> u; u \<le>\<sharp> v\<rbrakk> \<Longrightarrow> t \<le>\<sharp> v"
    1.25 +unfolding upper_le_def
    1.26 +apply (rule ballI)
    1.27 +apply (drule (1) bspec, erule bexE)
    1.28 +apply (drule (1) bspec, erule bexE)
    1.29 +apply (erule rev_bexI)
    1.30 +apply (erule (1) compact_le_trans)
    1.31 +done
    1.32 +
    1.33 +interpretation upper_le: preorder [upper_le]
    1.34 +by (rule preorder.intro, rule upper_le_refl, rule upper_le_trans)
    1.35 +
    1.36 +lemma upper_le_minimal [simp]: "PDUnit compact_bot \<le>\<sharp> t"
    1.37 +unfolding upper_le_def Rep_PDUnit by simp
    1.38 +
    1.39 +lemma PDUnit_upper_mono: "compact_le x y \<Longrightarrow> PDUnit x \<le>\<sharp> PDUnit y"
    1.40 +unfolding upper_le_def Rep_PDUnit by simp
    1.41 +
    1.42 +lemma PDPlus_upper_mono: "\<lbrakk>s \<le>\<sharp> t; u \<le>\<sharp> v\<rbrakk> \<Longrightarrow> PDPlus s u \<le>\<sharp> PDPlus t v"
    1.43 +unfolding upper_le_def Rep_PDPlus by fast
    1.44 +
    1.45 +lemma PDPlus_upper_less: "PDPlus t u \<le>\<sharp> t"
    1.46 +unfolding upper_le_def Rep_PDPlus by (fast intro: compact_le_refl)
    1.47 +
    1.48 +lemma upper_le_PDUnit_PDUnit_iff [simp]:
    1.49 +  "(PDUnit a \<le>\<sharp> PDUnit b) = compact_le a b"
    1.50 +unfolding upper_le_def Rep_PDUnit by fast
    1.51 +
    1.52 +lemma upper_le_PDPlus_PDUnit_iff:
    1.53 +  "(PDPlus t u \<le>\<sharp> PDUnit a) = (t \<le>\<sharp> PDUnit a \<or> u \<le>\<sharp> PDUnit a)"
    1.54 +unfolding upper_le_def Rep_PDPlus Rep_PDUnit by fast
    1.55 +
    1.56 +lemma upper_le_PDPlus_iff: "(t \<le>\<sharp> PDPlus u v) = (t \<le>\<sharp> u \<and> t \<le>\<sharp> v)"
    1.57 +unfolding upper_le_def Rep_PDPlus by fast
    1.58 +
    1.59 +lemma upper_le_induct [induct set: upper_le]:
    1.60 +  assumes le: "t \<le>\<sharp> u"
    1.61 +  assumes 1: "\<And>a b. compact_le a b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
    1.62 +  assumes 2: "\<And>t u a. P t (PDUnit a) \<Longrightarrow> P (PDPlus t u) (PDUnit a)"
    1.63 +  assumes 3: "\<And>t u v. \<lbrakk>P t u; P t v\<rbrakk> \<Longrightarrow> P t (PDPlus u v)"
    1.64 +  shows "P t u"
    1.65 +using le apply (induct u arbitrary: t rule: pd_basis_induct)
    1.66 +apply (erule rev_mp)
    1.67 +apply (induct_tac t rule: pd_basis_induct)
    1.68 +apply (simp add: 1)
    1.69 +apply (simp add: upper_le_PDPlus_PDUnit_iff)
    1.70 +apply (simp add: 2)
    1.71 +apply (subst PDPlus_commute)
    1.72 +apply (simp add: 2)
    1.73 +apply (simp add: upper_le_PDPlus_iff 3)
    1.74 +done
    1.75 +
    1.76 +lemma approx_pd_upper_mono1:
    1.77 +  "i \<le> j \<Longrightarrow> approx_pd i t \<le>\<sharp> approx_pd j t"
    1.78 +apply (induct t rule: pd_basis_induct)
    1.79 +apply (simp add: compact_approx_mono1)
    1.80 +apply (simp add: PDPlus_upper_mono)
    1.81 +done
    1.82 +
    1.83 +lemma approx_pd_upper_le: "approx_pd i t \<le>\<sharp> t"
    1.84 +apply (induct t rule: pd_basis_induct)
    1.85 +apply (simp add: compact_approx_le)
    1.86 +apply (simp add: PDPlus_upper_mono)
    1.87 +done
    1.88 +
    1.89 +lemma approx_pd_upper_mono:
    1.90 +  "t \<le>\<sharp> u \<Longrightarrow> approx_pd n t \<le>\<sharp> approx_pd n u"
    1.91 +apply (erule upper_le_induct)
    1.92 +apply (simp add: compact_approx_mono)
    1.93 +apply (simp add: upper_le_PDPlus_PDUnit_iff)
    1.94 +apply (simp add: upper_le_PDPlus_iff)
    1.95 +done
    1.96 +
    1.97 +
    1.98 +subsection {* Type definition *}
    1.99 +
   1.100 +cpodef (open) 'a upper_pd =
   1.101 +  "{S::'a::bifinite pd_basis set. upper_le.ideal S}"
   1.102 +apply (simp add: upper_le.adm_ideal)
   1.103 +apply (fast intro: upper_le.ideal_principal)
   1.104 +done
   1.105 +
   1.106 +lemma ideal_Rep_upper_pd: "upper_le.ideal (Rep_upper_pd x)"
   1.107 +by (rule Rep_upper_pd [simplified])
   1.108 +
   1.109 +definition
   1.110 +  upper_principal :: "'a pd_basis \<Rightarrow> 'a upper_pd" where
   1.111 +  "upper_principal t = Abs_upper_pd {u. u \<le>\<sharp> t}"
   1.112 +
   1.113 +lemma Rep_upper_principal:
   1.114 +  "Rep_upper_pd (upper_principal t) = {u. u \<le>\<sharp> t}"
   1.115 +unfolding upper_principal_def
   1.116 +apply (rule Abs_upper_pd_inverse [simplified])
   1.117 +apply (rule upper_le.ideal_principal)
   1.118 +done
   1.119 +
   1.120 +interpretation upper_pd:
   1.121 +  bifinite_basis [upper_le upper_principal Rep_upper_pd approx_pd]
   1.122 +apply unfold_locales
   1.123 +apply (rule ideal_Rep_upper_pd)
   1.124 +apply (rule cont_Rep_upper_pd)
   1.125 +apply (rule Rep_upper_principal)
   1.126 +apply (simp only: less_upper_pd_def less_set_def)
   1.127 +apply (rule approx_pd_upper_le)
   1.128 +apply (rule approx_pd_idem)
   1.129 +apply (erule approx_pd_upper_mono)
   1.130 +apply (rule approx_pd_upper_mono1, simp)
   1.131 +apply (rule finite_range_approx_pd)
   1.132 +apply (rule ex_approx_pd_eq)
   1.133 +done
   1.134 +
   1.135 +lemma upper_principal_less_iff [simp]:
   1.136 +  "(upper_principal t \<sqsubseteq> upper_principal u) = (t \<le>\<sharp> u)"
   1.137 +unfolding less_upper_pd_def Rep_upper_principal less_set_def
   1.138 +by (fast intro: upper_le_refl elim: upper_le_trans)
   1.139 +
   1.140 +lemma upper_principal_mono:
   1.141 +  "t \<le>\<sharp> u \<Longrightarrow> upper_principal t \<sqsubseteq> upper_principal u"
   1.142 +by (rule upper_pd.principal_mono)
   1.143 +
   1.144 +lemma compact_upper_principal: "compact (upper_principal t)"
   1.145 +by (rule upper_pd.compact_principal)
   1.146 +
   1.147 +lemma upper_pd_minimal: "upper_principal (PDUnit compact_bot) \<sqsubseteq> ys"
   1.148 +by (induct ys rule: upper_pd.principal_induct, simp, simp)
   1.149 +
   1.150 +instance upper_pd :: (bifinite) pcpo
   1.151 +by (intro_classes, fast intro: upper_pd_minimal)
   1.152 +
   1.153 +lemma inst_upper_pd_pcpo: "\<bottom> = upper_principal (PDUnit compact_bot)"
   1.154 +by (rule upper_pd_minimal [THEN UU_I, symmetric])
   1.155 +
   1.156 +
   1.157 +subsection {* Approximation *}
   1.158 +
   1.159 +instance upper_pd :: (bifinite) approx ..
   1.160 +
   1.161 +defs (overloaded)
   1.162 +  approx_upper_pd_def:
   1.163 +    "approx \<equiv> (\<lambda>n. upper_pd.basis_fun (\<lambda>t. upper_principal (approx_pd n t)))"
   1.164 +
   1.165 +lemma approx_upper_principal [simp]:
   1.166 +  "approx n\<cdot>(upper_principal t) = upper_principal (approx_pd n t)"
   1.167 +unfolding approx_upper_pd_def
   1.168 +apply (rule upper_pd.basis_fun_principal)
   1.169 +apply (erule upper_principal_mono [OF approx_pd_upper_mono])
   1.170 +done
   1.171 +
   1.172 +lemma chain_approx_upper_pd:
   1.173 +  "chain (approx :: nat \<Rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd)"
   1.174 +unfolding approx_upper_pd_def
   1.175 +by (rule upper_pd.chain_basis_fun_take)
   1.176 +
   1.177 +lemma lub_approx_upper_pd:
   1.178 +  "(\<Squnion>i. approx i\<cdot>xs) = (xs::'a upper_pd)"
   1.179 +unfolding approx_upper_pd_def
   1.180 +by (rule upper_pd.lub_basis_fun_take)
   1.181 +
   1.182 +lemma approx_upper_pd_idem:
   1.183 +  "approx n\<cdot>(approx n\<cdot>xs) = approx n\<cdot>(xs::'a upper_pd)"
   1.184 +apply (induct xs rule: upper_pd.principal_induct, simp)
   1.185 +apply (simp add: approx_pd_idem)
   1.186 +done
   1.187 +
   1.188 +lemma approx_eq_upper_principal:
   1.189 +  "\<exists>t\<in>Rep_upper_pd xs. approx n\<cdot>xs = upper_principal (approx_pd n t)"
   1.190 +unfolding approx_upper_pd_def
   1.191 +by (rule upper_pd.basis_fun_take_eq_principal)
   1.192 +
   1.193 +lemma finite_fixes_approx_upper_pd:
   1.194 +  "finite {xs::'a upper_pd. approx n\<cdot>xs = xs}"
   1.195 +unfolding approx_upper_pd_def
   1.196 +by (rule upper_pd.finite_fixes_basis_fun_take)
   1.197 +
   1.198 +instance upper_pd :: (bifinite) bifinite
   1.199 +apply intro_classes
   1.200 +apply (simp add: chain_approx_upper_pd)
   1.201 +apply (rule lub_approx_upper_pd)
   1.202 +apply (rule approx_upper_pd_idem)
   1.203 +apply (rule finite_fixes_approx_upper_pd)
   1.204 +done
   1.205 +
   1.206 +lemma compact_imp_upper_principal:
   1.207 +  "compact xs \<Longrightarrow> \<exists>t. xs = upper_principal t"
   1.208 +apply (drule bifinite_compact_eq_approx)
   1.209 +apply (erule exE)
   1.210 +apply (erule subst)
   1.211 +apply (cut_tac n=i and xs=xs in approx_eq_upper_principal)
   1.212 +apply fast
   1.213 +done
   1.214 +
   1.215 +lemma upper_principal_induct:
   1.216 +  "\<lbrakk>adm P; \<And>t. P (upper_principal t)\<rbrakk> \<Longrightarrow> P xs"
   1.217 +apply (erule approx_induct, rename_tac xs)
   1.218 +apply (cut_tac n=n and xs=xs in approx_eq_upper_principal)
   1.219 +apply (clarify, simp)
   1.220 +done
   1.221 +
   1.222 +lemma upper_principal_induct2:
   1.223 +  "\<lbrakk>\<And>ys. adm (\<lambda>xs. P xs ys); \<And>xs. adm (\<lambda>ys. P xs ys);
   1.224 +    \<And>t u. P (upper_principal t) (upper_principal u)\<rbrakk> \<Longrightarrow> P xs ys"
   1.225 +apply (rule_tac x=ys in spec)
   1.226 +apply (rule_tac xs=xs in upper_principal_induct, simp)
   1.227 +apply (rule allI, rename_tac ys)
   1.228 +apply (rule_tac xs=ys in upper_principal_induct, simp)
   1.229 +apply simp
   1.230 +done
   1.231 +
   1.232 +
   1.233 +subsection {* Monadic unit *}
   1.234 +
   1.235 +definition
   1.236 +  upper_unit :: "'a \<rightarrow> 'a upper_pd" where
   1.237 +  "upper_unit = compact_basis.basis_fun (\<lambda>a. upper_principal (PDUnit a))"
   1.238 +
   1.239 +lemma upper_unit_Rep_compact_basis [simp]:
   1.240 +  "upper_unit\<cdot>(Rep_compact_basis a) = upper_principal (PDUnit a)"
   1.241 +unfolding upper_unit_def
   1.242 +apply (rule compact_basis.basis_fun_principal)
   1.243 +apply (rule upper_principal_mono)
   1.244 +apply (erule PDUnit_upper_mono)
   1.245 +done
   1.246 +
   1.247 +lemma upper_unit_strict [simp]: "upper_unit\<cdot>\<bottom> = \<bottom>"
   1.248 +unfolding inst_upper_pd_pcpo Rep_compact_bot [symmetric] by simp
   1.249 +
   1.250 +lemma approx_upper_unit [simp]:
   1.251 +  "approx n\<cdot>(upper_unit\<cdot>x) = upper_unit\<cdot>(approx n\<cdot>x)"
   1.252 +apply (induct x rule: compact_basis_induct, simp)
   1.253 +apply (simp add: approx_Rep_compact_basis)
   1.254 +done
   1.255 +
   1.256 +lemma upper_unit_less_iff [simp]:
   1.257 +  "(upper_unit\<cdot>x \<sqsubseteq> upper_unit\<cdot>y) = (x \<sqsubseteq> y)"
   1.258 + apply (rule iffI)
   1.259 +  apply (rule bifinite_less_ext)
   1.260 +  apply (drule_tac f="approx i" in monofun_cfun_arg, simp)
   1.261 +  apply (cut_tac x="approx i\<cdot>x" in compact_imp_Rep_compact_basis, simp)
   1.262 +  apply (cut_tac x="approx i\<cdot>y" in compact_imp_Rep_compact_basis, simp)
   1.263 +  apply (clarify, simp add: compact_le_def)
   1.264 + apply (erule monofun_cfun_arg)
   1.265 +done
   1.266 +
   1.267 +lemma upper_unit_eq_iff [simp]:
   1.268 +  "(upper_unit\<cdot>x = upper_unit\<cdot>y) = (x = y)"
   1.269 +unfolding po_eq_conv by simp
   1.270 +
   1.271 +lemma upper_unit_strict_iff [simp]: "(upper_unit\<cdot>x = \<bottom>) = (x = \<bottom>)"
   1.272 +unfolding upper_unit_strict [symmetric] by (rule upper_unit_eq_iff)
   1.273 +
   1.274 +lemma compact_upper_unit_iff [simp]:
   1.275 +  "compact (upper_unit\<cdot>x) = compact x"
   1.276 +unfolding bifinite_compact_iff by simp
   1.277 +
   1.278 +
   1.279 +subsection {* Monadic plus *}
   1.280 +
   1.281 +definition
   1.282 +  upper_plus :: "'a upper_pd \<rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd" where
   1.283 +  "upper_plus = upper_pd.basis_fun (\<lambda>t. upper_pd.basis_fun (\<lambda>u.
   1.284 +      upper_principal (PDPlus t u)))"
   1.285 +
   1.286 +abbreviation
   1.287 +  upper_add :: "'a upper_pd \<Rightarrow> 'a upper_pd \<Rightarrow> 'a upper_pd"
   1.288 +    (infixl "+\<sharp>" 65) where
   1.289 +  "xs +\<sharp> ys == upper_plus\<cdot>xs\<cdot>ys"
   1.290 +
   1.291 +lemma upper_plus_principal [simp]:
   1.292 +  "upper_plus\<cdot>(upper_principal t)\<cdot>(upper_principal u) =
   1.293 +   upper_principal (PDPlus t u)"
   1.294 +unfolding upper_plus_def
   1.295 +by (simp add: upper_pd.basis_fun_principal
   1.296 +    upper_pd.basis_fun_mono PDPlus_upper_mono)
   1.297 +
   1.298 +lemma approx_upper_plus [simp]:
   1.299 +  "approx n\<cdot>(upper_plus\<cdot>xs\<cdot>ys) = upper_plus\<cdot>(approx n\<cdot>xs)\<cdot>(approx n\<cdot>ys)"
   1.300 +by (induct xs ys rule: upper_principal_induct2, simp, simp, simp)
   1.301 +
   1.302 +lemma upper_plus_commute: "upper_plus\<cdot>xs\<cdot>ys = upper_plus\<cdot>ys\<cdot>xs"
   1.303 +apply (induct xs ys rule: upper_principal_induct2, simp, simp)
   1.304 +apply (simp add: PDPlus_commute)
   1.305 +done
   1.306 +
   1.307 +lemma upper_plus_assoc:
   1.308 +  "upper_plus\<cdot>(upper_plus\<cdot>xs\<cdot>ys)\<cdot>zs = upper_plus\<cdot>xs\<cdot>(upper_plus\<cdot>ys\<cdot>zs)"
   1.309 +apply (induct xs ys arbitrary: zs rule: upper_principal_induct2, simp, simp)
   1.310 +apply (rule_tac xs=zs in upper_principal_induct, simp)
   1.311 +apply (simp add: PDPlus_assoc)
   1.312 +done
   1.313 +
   1.314 +lemma upper_plus_absorb: "upper_plus\<cdot>xs\<cdot>xs = xs"
   1.315 +apply (induct xs rule: upper_principal_induct, simp)
   1.316 +apply (simp add: PDPlus_absorb)
   1.317 +done
   1.318 +
   1.319 +lemma upper_plus_less1: "upper_plus\<cdot>xs\<cdot>ys \<sqsubseteq> xs"
   1.320 +apply (induct xs ys rule: upper_principal_induct2, simp, simp)
   1.321 +apply (simp add: PDPlus_upper_less)
   1.322 +done
   1.323 +
   1.324 +lemma upper_plus_less2: "upper_plus\<cdot>xs\<cdot>ys \<sqsubseteq> ys"
   1.325 +by (subst upper_plus_commute, rule upper_plus_less1)
   1.326 +
   1.327 +lemma upper_plus_greatest: "\<lbrakk>xs \<sqsubseteq> ys; xs \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> xs \<sqsubseteq> upper_plus\<cdot>ys\<cdot>zs"
   1.328 +apply (subst upper_plus_absorb [of xs, symmetric])
   1.329 +apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
   1.330 +done
   1.331 +
   1.332 +lemma upper_less_plus_iff:
   1.333 +  "(xs \<sqsubseteq> upper_plus\<cdot>ys\<cdot>zs) = (xs \<sqsubseteq> ys \<and> xs \<sqsubseteq> zs)"
   1.334 +apply safe
   1.335 +apply (erule trans_less [OF _ upper_plus_less1])
   1.336 +apply (erule trans_less [OF _ upper_plus_less2])
   1.337 +apply (erule (1) upper_plus_greatest)
   1.338 +done
   1.339 +
   1.340 +lemma upper_plus_strict1 [simp]: "upper_plus\<cdot>\<bottom>\<cdot>ys = \<bottom>"
   1.341 +by (rule UU_I, rule upper_plus_less1)
   1.342 +
   1.343 +lemma upper_plus_strict2 [simp]: "upper_plus\<cdot>xs\<cdot>\<bottom> = \<bottom>"
   1.344 +by (rule UU_I, rule upper_plus_less2)
   1.345 +
   1.346 +lemma upper_plus_less_unit_iff:
   1.347 +  "(upper_plus\<cdot>xs\<cdot>ys \<sqsubseteq> upper_unit\<cdot>z) =
   1.348 +    (xs \<sqsubseteq> upper_unit\<cdot>z \<or> ys \<sqsubseteq> upper_unit\<cdot>z)"
   1.349 + apply (rule iffI)
   1.350 +  apply (subgoal_tac
   1.351 +    "adm (\<lambda>f. f\<cdot>xs \<sqsubseteq> f\<cdot>(upper_unit\<cdot>z) \<or> f\<cdot>ys \<sqsubseteq> f\<cdot>(upper_unit\<cdot>z))")
   1.352 +   apply (drule admD [rule_format], rule chain_approx)
   1.353 +    apply (drule_tac f="approx i" in monofun_cfun_arg)
   1.354 +    apply (cut_tac xs="approx i\<cdot>xs" in compact_imp_upper_principal, simp)
   1.355 +    apply (cut_tac xs="approx i\<cdot>ys" in compact_imp_upper_principal, simp)
   1.356 +    apply (cut_tac x="approx i\<cdot>z" in compact_imp_Rep_compact_basis, simp)
   1.357 +    apply (clarify, simp add: upper_le_PDPlus_PDUnit_iff)
   1.358 +   apply simp
   1.359 +  apply simp
   1.360 + apply (erule disjE)
   1.361 +  apply (erule trans_less [OF upper_plus_less1])
   1.362 + apply (erule trans_less [OF upper_plus_less2])
   1.363 +done
   1.364 +
   1.365 +lemmas upper_pd_less_simps =
   1.366 +  upper_unit_less_iff
   1.367 +  upper_less_plus_iff
   1.368 +  upper_plus_less_unit_iff
   1.369 +
   1.370 +
   1.371 +subsection {* Induction rules *}
   1.372 +
   1.373 +lemma upper_pd_induct1:
   1.374 +  assumes P: "adm P"
   1.375 +  assumes unit: "\<And>x. P (upper_unit\<cdot>x)"
   1.376 +  assumes insert:
   1.377 +    "\<And>x ys. \<lbrakk>P (upper_unit\<cdot>x); P ys\<rbrakk> \<Longrightarrow> P (upper_plus\<cdot>(upper_unit\<cdot>x)\<cdot>ys)"
   1.378 +  shows "P (xs::'a upper_pd)"
   1.379 +apply (induct xs rule: upper_principal_induct, rule P)
   1.380 +apply (induct_tac t rule: pd_basis_induct1)
   1.381 +apply (simp only: upper_unit_Rep_compact_basis [symmetric])
   1.382 +apply (rule unit)
   1.383 +apply (simp only: upper_unit_Rep_compact_basis [symmetric]
   1.384 +                  upper_plus_principal [symmetric])
   1.385 +apply (erule insert [OF unit])
   1.386 +done
   1.387 +
   1.388 +lemma upper_pd_induct:
   1.389 +  assumes P: "adm P"
   1.390 +  assumes unit: "\<And>x. P (upper_unit\<cdot>x)"
   1.391 +  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (upper_plus\<cdot>xs\<cdot>ys)"
   1.392 +  shows "P (xs::'a upper_pd)"
   1.393 +apply (induct xs rule: upper_principal_induct, rule P)
   1.394 +apply (induct_tac t rule: pd_basis_induct)
   1.395 +apply (simp only: upper_unit_Rep_compact_basis [symmetric] unit)
   1.396 +apply (simp only: upper_plus_principal [symmetric] plus)
   1.397 +done
   1.398 +
   1.399 +
   1.400 +subsection {* Monadic bind *}
   1.401 +
   1.402 +definition
   1.403 +  upper_bind_basis ::
   1.404 +  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
   1.405 +  "upper_bind_basis = fold_pd
   1.406 +    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
   1.407 +    (\<lambda>x y. \<Lambda> f. upper_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
   1.408 +
   1.409 +lemma ACI_upper_bind: "ACIf (\<lambda>x y. \<Lambda> f. upper_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
   1.410 +apply unfold_locales
   1.411 +apply (simp add: upper_plus_commute)
   1.412 +apply (simp add: upper_plus_assoc)
   1.413 +apply (simp add: upper_plus_absorb eta_cfun)
   1.414 +done
   1.415 +
   1.416 +lemma upper_bind_basis_simps [simp]:
   1.417 +  "upper_bind_basis (PDUnit a) =
   1.418 +    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
   1.419 +  "upper_bind_basis (PDPlus t u) =
   1.420 +    (\<Lambda> f. upper_plus\<cdot>(upper_bind_basis t\<cdot>f)\<cdot>(upper_bind_basis u\<cdot>f))"
   1.421 +unfolding upper_bind_basis_def
   1.422 +apply -
   1.423 +apply (rule ACIf.fold_pd_PDUnit [OF ACI_upper_bind])
   1.424 +apply (rule ACIf.fold_pd_PDPlus [OF ACI_upper_bind])
   1.425 +done
   1.426 +
   1.427 +lemma upper_bind_basis_mono:
   1.428 +  "t \<le>\<sharp> u \<Longrightarrow> upper_bind_basis t \<sqsubseteq> upper_bind_basis u"
   1.429 +unfolding expand_cfun_less
   1.430 +apply (erule upper_le_induct, safe)
   1.431 +apply (simp add: compact_le_def monofun_cfun)
   1.432 +apply (simp add: trans_less [OF upper_plus_less1])
   1.433 +apply (simp add: upper_less_plus_iff)
   1.434 +done
   1.435 +
   1.436 +definition
   1.437 +  upper_bind :: "'a upper_pd \<rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
   1.438 +  "upper_bind = upper_pd.basis_fun upper_bind_basis"
   1.439 +
   1.440 +lemma upper_bind_principal [simp]:
   1.441 +  "upper_bind\<cdot>(upper_principal t) = upper_bind_basis t"
   1.442 +unfolding upper_bind_def
   1.443 +apply (rule upper_pd.basis_fun_principal)
   1.444 +apply (erule upper_bind_basis_mono)
   1.445 +done
   1.446 +
   1.447 +lemma upper_bind_unit [simp]:
   1.448 +  "upper_bind\<cdot>(upper_unit\<cdot>x)\<cdot>f = f\<cdot>x"
   1.449 +by (induct x rule: compact_basis_induct, simp, simp)
   1.450 +
   1.451 +lemma upper_bind_plus [simp]:
   1.452 +  "upper_bind\<cdot>(upper_plus\<cdot>xs\<cdot>ys)\<cdot>f =
   1.453 +   upper_plus\<cdot>(upper_bind\<cdot>xs\<cdot>f)\<cdot>(upper_bind\<cdot>ys\<cdot>f)"
   1.454 +by (induct xs ys rule: upper_principal_induct2, simp, simp, simp)
   1.455 +
   1.456 +lemma upper_bind_strict [simp]: "upper_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
   1.457 +unfolding upper_unit_strict [symmetric] by (rule upper_bind_unit)
   1.458 +
   1.459 +
   1.460 +subsection {* Map and join *}
   1.461 +
   1.462 +definition
   1.463 +  upper_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a upper_pd \<rightarrow> 'b upper_pd" where
   1.464 +  "upper_map = (\<Lambda> f xs. upper_bind\<cdot>xs\<cdot>(\<Lambda> x. upper_unit\<cdot>(f\<cdot>x)))"
   1.465 +
   1.466 +definition
   1.467 +  upper_join :: "'a upper_pd upper_pd \<rightarrow> 'a upper_pd" where
   1.468 +  "upper_join = (\<Lambda> xss. upper_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
   1.469 +
   1.470 +lemma upper_map_unit [simp]:
   1.471 +  "upper_map\<cdot>f\<cdot>(upper_unit\<cdot>x) = upper_unit\<cdot>(f\<cdot>x)"
   1.472 +unfolding upper_map_def by simp
   1.473 +
   1.474 +lemma upper_map_plus [simp]:
   1.475 +  "upper_map\<cdot>f\<cdot>(upper_plus\<cdot>xs\<cdot>ys) =
   1.476 +   upper_plus\<cdot>(upper_map\<cdot>f\<cdot>xs)\<cdot>(upper_map\<cdot>f\<cdot>ys)"
   1.477 +unfolding upper_map_def by simp
   1.478 +
   1.479 +lemma upper_join_unit [simp]:
   1.480 +  "upper_join\<cdot>(upper_unit\<cdot>xs) = xs"
   1.481 +unfolding upper_join_def by simp
   1.482 +
   1.483 +lemma upper_join_plus [simp]:
   1.484 +  "upper_join\<cdot>(upper_plus\<cdot>xss\<cdot>yss) =
   1.485 +   upper_plus\<cdot>(upper_join\<cdot>xss)\<cdot>(upper_join\<cdot>yss)"
   1.486 +unfolding upper_join_def by simp
   1.487 +
   1.488 +lemma upper_map_ident: "upper_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
   1.489 +by (induct xs rule: upper_pd_induct, simp_all)
   1.490 +
   1.491 +lemma upper_map_map:
   1.492 +  "upper_map\<cdot>f\<cdot>(upper_map\<cdot>g\<cdot>xs) = upper_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
   1.493 +by (induct xs rule: upper_pd_induct, simp_all)
   1.494 +
   1.495 +lemma upper_join_map_unit:
   1.496 +  "upper_join\<cdot>(upper_map\<cdot>upper_unit\<cdot>xs) = xs"
   1.497 +by (induct xs rule: upper_pd_induct, simp_all)
   1.498 +
   1.499 +lemma upper_join_map_join:
   1.500 +  "upper_join\<cdot>(upper_map\<cdot>upper_join\<cdot>xsss) = upper_join\<cdot>(upper_join\<cdot>xsss)"
   1.501 +by (induct xsss rule: upper_pd_induct, simp_all)
   1.502 +
   1.503 +lemma upper_join_map_map:
   1.504 +  "upper_join\<cdot>(upper_map\<cdot>(upper_map\<cdot>f)\<cdot>xss) =
   1.505 +   upper_map\<cdot>f\<cdot>(upper_join\<cdot>xss)"
   1.506 +by (induct xss rule: upper_pd_induct, simp_all)
   1.507 +
   1.508 +lemma upper_map_approx: "upper_map\<cdot>(approx n)\<cdot>xs = approx n\<cdot>xs"
   1.509 +by (induct xs rule: upper_pd_induct, simp_all)
   1.510 +
   1.511 +end