src/HOLCF/LowerPD.thy
changeset 25904 8161f137b0e9
child 25925 3dc4acca4388
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOLCF/LowerPD.thy	Mon Jan 14 19:26:41 2008 +0100
     1.3 @@ -0,0 +1,538 @@
     1.4 +(*  Title:      HOLCF/LowerPD.thy
     1.5 +    ID:         $Id$
     1.6 +    Author:     Brian Huffman
     1.7 +*)
     1.8 +
     1.9 +header {* Lower powerdomain *}
    1.10 +
    1.11 +theory LowerPD
    1.12 +imports CompactBasis
    1.13 +begin
    1.14 +
    1.15 +subsection {* Basis preorder *}
    1.16 +
    1.17 +definition
    1.18 +  lower_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<flat>" 50) where
    1.19 +  "lower_le = (\<lambda>u v. \<forall>x\<in>Rep_pd_basis u. \<exists>y\<in>Rep_pd_basis v. compact_le x y)"
    1.20 +
    1.21 +lemma lower_le_refl [simp]: "t \<le>\<flat> t"
    1.22 +unfolding lower_le_def by (fast intro: compact_le_refl)
    1.23 +
    1.24 +lemma lower_le_trans: "\<lbrakk>t \<le>\<flat> u; u \<le>\<flat> v\<rbrakk> \<Longrightarrow> t \<le>\<flat> v"
    1.25 +unfolding lower_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 lower_le: preorder [lower_le]
    1.34 +by (rule preorder.intro, rule lower_le_refl, rule lower_le_trans)
    1.35 +
    1.36 +lemma lower_le_minimal [simp]: "PDUnit compact_bot \<le>\<flat> t"
    1.37 +unfolding lower_le_def Rep_PDUnit
    1.38 +by (simp, rule Rep_pd_basis_nonempty [folded ex_in_conv])
    1.39 +
    1.40 +lemma PDUnit_lower_mono: "compact_le x y \<Longrightarrow> PDUnit x \<le>\<flat> PDUnit y"
    1.41 +unfolding lower_le_def Rep_PDUnit by fast
    1.42 +
    1.43 +lemma PDPlus_lower_mono: "\<lbrakk>s \<le>\<flat> t; u \<le>\<flat> v\<rbrakk> \<Longrightarrow> PDPlus s u \<le>\<flat> PDPlus t v"
    1.44 +unfolding lower_le_def Rep_PDPlus by fast
    1.45 +
    1.46 +lemma PDPlus_lower_less: "t \<le>\<flat> PDPlus t u"
    1.47 +unfolding lower_le_def Rep_PDPlus by (fast intro: compact_le_refl)
    1.48 +
    1.49 +lemma lower_le_PDUnit_PDUnit_iff [simp]:
    1.50 +  "(PDUnit a \<le>\<flat> PDUnit b) = compact_le a b"
    1.51 +unfolding lower_le_def Rep_PDUnit by fast
    1.52 +
    1.53 +lemma lower_le_PDUnit_PDPlus_iff:
    1.54 +  "(PDUnit a \<le>\<flat> PDPlus t u) = (PDUnit a \<le>\<flat> t \<or> PDUnit a \<le>\<flat> u)"
    1.55 +unfolding lower_le_def Rep_PDPlus Rep_PDUnit by fast
    1.56 +
    1.57 +lemma lower_le_PDPlus_iff: "(PDPlus t u \<le>\<flat> v) = (t \<le>\<flat> v \<and> u \<le>\<flat> v)"
    1.58 +unfolding lower_le_def Rep_PDPlus by fast
    1.59 +
    1.60 +lemma lower_le_induct [induct set: lower_le]:
    1.61 +  assumes le: "t \<le>\<flat> u"
    1.62 +  assumes 1: "\<And>a b. compact_le a b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
    1.63 +  assumes 2: "\<And>t u a. P (PDUnit a) t \<Longrightarrow> P (PDUnit a) (PDPlus t u)"
    1.64 +  assumes 3: "\<And>t u v. \<lbrakk>P t v; P u v\<rbrakk> \<Longrightarrow> P (PDPlus t u) v"
    1.65 +  shows "P t u"
    1.66 +using le
    1.67 +apply (induct t arbitrary: u rule: pd_basis_induct)
    1.68 +apply (erule rev_mp)
    1.69 +apply (induct_tac u rule: pd_basis_induct)
    1.70 +apply (simp add: 1)
    1.71 +apply (simp add: lower_le_PDUnit_PDPlus_iff)
    1.72 +apply (simp add: 2)
    1.73 +apply (subst PDPlus_commute)
    1.74 +apply (simp add: 2)
    1.75 +apply (simp add: lower_le_PDPlus_iff 3)
    1.76 +done
    1.77 +
    1.78 +lemma approx_pd_lower_mono1:
    1.79 +  "i \<le> j \<Longrightarrow> approx_pd i t \<le>\<flat> approx_pd j t"
    1.80 +apply (induct t rule: pd_basis_induct)
    1.81 +apply (simp add: compact_approx_mono1)
    1.82 +apply (simp add: PDPlus_lower_mono)
    1.83 +done
    1.84 +
    1.85 +lemma approx_pd_lower_le: "approx_pd i t \<le>\<flat> t"
    1.86 +apply (induct t rule: pd_basis_induct)
    1.87 +apply (simp add: compact_approx_le)
    1.88 +apply (simp add: PDPlus_lower_mono)
    1.89 +done
    1.90 +
    1.91 +lemma approx_pd_lower_mono:
    1.92 +  "t \<le>\<flat> u \<Longrightarrow> approx_pd n t \<le>\<flat> approx_pd n u"
    1.93 +apply (erule lower_le_induct)
    1.94 +apply (simp add: compact_approx_mono)
    1.95 +apply (simp add: lower_le_PDUnit_PDPlus_iff)
    1.96 +apply (simp add: lower_le_PDPlus_iff)
    1.97 +done
    1.98 +
    1.99 +
   1.100 +subsection {* Type definition *}
   1.101 +
   1.102 +cpodef (open) 'a lower_pd =
   1.103 +  "{S::'a::bifinite pd_basis set. lower_le.ideal S}"
   1.104 +apply (simp add: lower_le.adm_ideal)
   1.105 +apply (fast intro: lower_le.ideal_principal)
   1.106 +done
   1.107 +
   1.108 +lemma ideal_Rep_lower_pd: "lower_le.ideal (Rep_lower_pd x)"
   1.109 +by (rule Rep_lower_pd [simplified])
   1.110 +
   1.111 +lemma Rep_lower_pd_mono: "x \<sqsubseteq> y \<Longrightarrow> Rep_lower_pd x \<subseteq> Rep_lower_pd y"
   1.112 +unfolding less_lower_pd_def less_set_def .
   1.113 +
   1.114 +
   1.115 +subsection {* Principal ideals *}
   1.116 +
   1.117 +definition
   1.118 +  lower_principal :: "'a pd_basis \<Rightarrow> 'a lower_pd" where
   1.119 +  "lower_principal t = Abs_lower_pd {u. u \<le>\<flat> t}"
   1.120 +
   1.121 +lemma Rep_lower_principal:
   1.122 +  "Rep_lower_pd (lower_principal t) = {u. u \<le>\<flat> t}"
   1.123 +unfolding lower_principal_def
   1.124 +apply (rule Abs_lower_pd_inverse [simplified])
   1.125 +apply (rule lower_le.ideal_principal)
   1.126 +done
   1.127 +
   1.128 +interpretation lower_pd:
   1.129 +  bifinite_basis [lower_le lower_principal Rep_lower_pd approx_pd]
   1.130 +apply unfold_locales
   1.131 +apply (rule ideal_Rep_lower_pd)
   1.132 +apply (rule cont_Rep_lower_pd)
   1.133 +apply (rule Rep_lower_principal)
   1.134 +apply (simp only: less_lower_pd_def less_set_def)
   1.135 +apply (rule approx_pd_lower_le)
   1.136 +apply (rule approx_pd_idem)
   1.137 +apply (erule approx_pd_lower_mono)
   1.138 +apply (rule approx_pd_lower_mono1, simp)
   1.139 +apply (rule finite_range_approx_pd)
   1.140 +apply (rule ex_approx_pd_eq)
   1.141 +done
   1.142 +
   1.143 +lemma lower_principal_less_iff [simp]:
   1.144 +  "(lower_principal t \<sqsubseteq> lower_principal u) = (t \<le>\<flat> u)"
   1.145 +unfolding less_lower_pd_def Rep_lower_principal less_set_def
   1.146 +by (fast intro: lower_le_refl elim: lower_le_trans)
   1.147 +
   1.148 +lemma lower_principal_mono:
   1.149 +  "t \<le>\<flat> u \<Longrightarrow> lower_principal t \<sqsubseteq> lower_principal u"
   1.150 +by (rule lower_principal_less_iff [THEN iffD2])
   1.151 +
   1.152 +lemma compact_lower_principal: "compact (lower_principal t)"
   1.153 +apply (rule compactI2)
   1.154 +apply (simp add: less_lower_pd_def)
   1.155 +apply (simp add: cont2contlubE [OF cont_Rep_lower_pd])
   1.156 +apply (simp add: Rep_lower_principal set_cpo_simps)
   1.157 +apply (simp add: subset_def)
   1.158 +apply (drule spec, drule mp, rule lower_le_refl)
   1.159 +apply (erule exE, rename_tac i)
   1.160 +apply (rule_tac x=i in exI)
   1.161 +apply clarify
   1.162 +apply (erule (1) lower_le.idealD3 [OF ideal_Rep_lower_pd])
   1.163 +done
   1.164 +
   1.165 +lemma lower_pd_minimal: "lower_principal (PDUnit compact_bot) \<sqsubseteq> ys"
   1.166 +by (induct ys rule: lower_pd.principal_induct, simp, simp)
   1.167 +
   1.168 +instance lower_pd :: (bifinite) pcpo
   1.169 +by (intro_classes, fast intro: lower_pd_minimal)
   1.170 +
   1.171 +lemma inst_lower_pd_pcpo: "\<bottom> = lower_principal (PDUnit compact_bot)"
   1.172 +by (rule lower_pd_minimal [THEN UU_I, symmetric])
   1.173 +
   1.174 +
   1.175 +subsection {* Approximation *}
   1.176 +
   1.177 +instance lower_pd :: (bifinite) approx ..
   1.178 +
   1.179 +defs (overloaded)
   1.180 +  approx_lower_pd_def:
   1.181 +    "approx \<equiv> (\<lambda>n. lower_pd.basis_fun (\<lambda>t. lower_principal (approx_pd n t)))"
   1.182 +
   1.183 +lemma approx_lower_principal [simp]:
   1.184 +  "approx n\<cdot>(lower_principal t) = lower_principal (approx_pd n t)"
   1.185 +unfolding approx_lower_pd_def
   1.186 +apply (rule lower_pd.basis_fun_principal)
   1.187 +apply (erule lower_principal_mono [OF approx_pd_lower_mono])
   1.188 +done
   1.189 +
   1.190 +lemma chain_approx_lower_pd:
   1.191 +  "chain (approx :: nat \<Rightarrow> 'a lower_pd \<rightarrow> 'a lower_pd)"
   1.192 +unfolding approx_lower_pd_def
   1.193 +by (rule lower_pd.chain_basis_fun_take)
   1.194 +
   1.195 +lemma lub_approx_lower_pd:
   1.196 +  "(\<Squnion>i. approx i\<cdot>xs) = (xs::'a lower_pd)"
   1.197 +unfolding approx_lower_pd_def
   1.198 +by (rule lower_pd.lub_basis_fun_take)
   1.199 +
   1.200 +lemma approx_lower_pd_idem:
   1.201 +  "approx n\<cdot>(approx n\<cdot>xs) = approx n\<cdot>(xs::'a lower_pd)"
   1.202 +apply (induct xs rule: lower_pd.principal_induct, simp)
   1.203 +apply (simp add: approx_pd_idem)
   1.204 +done
   1.205 +
   1.206 +lemma approx_eq_lower_principal:
   1.207 +  "\<exists>t\<in>Rep_lower_pd xs. approx n\<cdot>xs = lower_principal (approx_pd n t)"
   1.208 +unfolding approx_lower_pd_def
   1.209 +by (rule lower_pd.basis_fun_take_eq_principal)
   1.210 +
   1.211 +lemma finite_fixes_approx_lower_pd:
   1.212 +  "finite {xs::'a lower_pd. approx n\<cdot>xs = xs}"
   1.213 +unfolding approx_lower_pd_def
   1.214 +by (rule lower_pd.finite_fixes_basis_fun_take)
   1.215 +
   1.216 +instance lower_pd :: (bifinite) bifinite
   1.217 +apply intro_classes
   1.218 +apply (simp add: chain_approx_lower_pd)
   1.219 +apply (rule lub_approx_lower_pd)
   1.220 +apply (rule approx_lower_pd_idem)
   1.221 +apply (rule finite_fixes_approx_lower_pd)
   1.222 +done
   1.223 +
   1.224 +lemma compact_imp_lower_principal:
   1.225 +  "compact xs \<Longrightarrow> \<exists>t. xs = lower_principal t"
   1.226 +apply (drule bifinite_compact_eq_approx)
   1.227 +apply (erule exE)
   1.228 +apply (erule subst)
   1.229 +apply (cut_tac n=i and xs=xs in approx_eq_lower_principal)
   1.230 +apply fast
   1.231 +done
   1.232 +
   1.233 +lemma lower_principal_induct:
   1.234 +  "\<lbrakk>adm P; \<And>t. P (lower_principal t)\<rbrakk> \<Longrightarrow> P xs"
   1.235 +apply (erule approx_induct, rename_tac xs)
   1.236 +apply (cut_tac n=n and xs=xs in approx_eq_lower_principal)
   1.237 +apply (clarify, simp)
   1.238 +done
   1.239 +
   1.240 +lemma lower_principal_induct2:
   1.241 +  "\<lbrakk>\<And>ys. adm (\<lambda>xs. P xs ys); \<And>xs. adm (\<lambda>ys. P xs ys);
   1.242 +    \<And>t u. P (lower_principal t) (lower_principal u)\<rbrakk> \<Longrightarrow> P xs ys"
   1.243 +apply (rule_tac x=ys in spec)
   1.244 +apply (rule_tac xs=xs in lower_principal_induct, simp)
   1.245 +apply (rule allI, rename_tac ys)
   1.246 +apply (rule_tac xs=ys in lower_principal_induct, simp)
   1.247 +apply simp
   1.248 +done
   1.249 +
   1.250 +
   1.251 +subsection {* Monadic unit *}
   1.252 +
   1.253 +definition
   1.254 +  lower_unit :: "'a \<rightarrow> 'a lower_pd" where
   1.255 +  "lower_unit = compact_basis.basis_fun (\<lambda>a. lower_principal (PDUnit a))"
   1.256 +
   1.257 +lemma lower_unit_Rep_compact_basis [simp]:
   1.258 +  "lower_unit\<cdot>(Rep_compact_basis a) = lower_principal (PDUnit a)"
   1.259 +unfolding lower_unit_def
   1.260 +apply (rule compact_basis.basis_fun_principal)
   1.261 +apply (rule lower_principal_mono)
   1.262 +apply (erule PDUnit_lower_mono)
   1.263 +done
   1.264 +
   1.265 +lemma lower_unit_strict [simp]: "lower_unit\<cdot>\<bottom> = \<bottom>"
   1.266 +unfolding inst_lower_pd_pcpo Rep_compact_bot [symmetric] by simp
   1.267 +
   1.268 +lemma approx_lower_unit [simp]:
   1.269 +  "approx n\<cdot>(lower_unit\<cdot>x) = lower_unit\<cdot>(approx n\<cdot>x)"
   1.270 +apply (induct x rule: compact_basis_induct, simp)
   1.271 +apply (simp add: approx_Rep_compact_basis)
   1.272 +done
   1.273 +
   1.274 +lemma lower_unit_less_iff [simp]:
   1.275 +  "(lower_unit\<cdot>x \<sqsubseteq> lower_unit\<cdot>y) = (x \<sqsubseteq> y)"
   1.276 + apply (rule iffI)
   1.277 +  apply (rule bifinite_less_ext)
   1.278 +  apply (drule_tac f="approx i" in monofun_cfun_arg, simp)
   1.279 +  apply (cut_tac x="approx i\<cdot>x" in compact_imp_Rep_compact_basis, simp)
   1.280 +  apply (cut_tac x="approx i\<cdot>y" in compact_imp_Rep_compact_basis, simp)
   1.281 +  apply (clarify, simp add: compact_le_def)
   1.282 + apply (erule monofun_cfun_arg)
   1.283 +done
   1.284 +
   1.285 +lemma lower_unit_eq_iff [simp]:
   1.286 +  "(lower_unit\<cdot>x = lower_unit\<cdot>y) = (x = y)"
   1.287 +unfolding po_eq_conv by simp
   1.288 +
   1.289 +lemma lower_unit_strict_iff [simp]: "(lower_unit\<cdot>x = \<bottom>) = (x = \<bottom>)"
   1.290 +unfolding lower_unit_strict [symmetric] by (rule lower_unit_eq_iff)
   1.291 +
   1.292 +lemma compact_lower_unit_iff [simp]:
   1.293 +  "compact (lower_unit\<cdot>x) = compact x"
   1.294 +unfolding bifinite_compact_iff by simp
   1.295 +
   1.296 +
   1.297 +subsection {* Monadic plus *}
   1.298 +
   1.299 +definition
   1.300 +  lower_plus :: "'a lower_pd \<rightarrow> 'a lower_pd \<rightarrow> 'a lower_pd" where
   1.301 +  "lower_plus = lower_pd.basis_fun (\<lambda>t. lower_pd.basis_fun (\<lambda>u.
   1.302 +      lower_principal (PDPlus t u)))"
   1.303 +
   1.304 +abbreviation
   1.305 +  lower_add :: "'a lower_pd \<Rightarrow> 'a lower_pd \<Rightarrow> 'a lower_pd"
   1.306 +    (infixl "+\<flat>" 65) where
   1.307 +  "xs +\<flat> ys == lower_plus\<cdot>xs\<cdot>ys"
   1.308 +
   1.309 +lemma lower_plus_principal [simp]:
   1.310 +  "lower_plus\<cdot>(lower_principal t)\<cdot>(lower_principal u) =
   1.311 +   lower_principal (PDPlus t u)"
   1.312 +unfolding lower_plus_def
   1.313 +by (simp add: lower_pd.basis_fun_principal
   1.314 +    lower_pd.basis_fun_mono PDPlus_lower_mono)
   1.315 +
   1.316 +lemma approx_lower_plus [simp]:
   1.317 +  "approx n\<cdot>(lower_plus\<cdot>xs\<cdot>ys) = lower_plus\<cdot>(approx n\<cdot>xs)\<cdot>(approx n\<cdot>ys)"
   1.318 +by (induct xs ys rule: lower_principal_induct2, simp, simp, simp)
   1.319 +
   1.320 +lemma lower_plus_commute: "lower_plus\<cdot>xs\<cdot>ys = lower_plus\<cdot>ys\<cdot>xs"
   1.321 +apply (induct xs ys rule: lower_principal_induct2, simp, simp)
   1.322 +apply (simp add: PDPlus_commute)
   1.323 +done
   1.324 +
   1.325 +lemma lower_plus_assoc:
   1.326 +  "lower_plus\<cdot>(lower_plus\<cdot>xs\<cdot>ys)\<cdot>zs = lower_plus\<cdot>xs\<cdot>(lower_plus\<cdot>ys\<cdot>zs)"
   1.327 +apply (induct xs ys arbitrary: zs rule: lower_principal_induct2, simp, simp)
   1.328 +apply (rule_tac xs=zs in lower_principal_induct, simp)
   1.329 +apply (simp add: PDPlus_assoc)
   1.330 +done
   1.331 +
   1.332 +lemma lower_plus_absorb: "lower_plus\<cdot>xs\<cdot>xs = xs"
   1.333 +apply (induct xs rule: lower_principal_induct, simp)
   1.334 +apply (simp add: PDPlus_absorb)
   1.335 +done
   1.336 +
   1.337 +lemma lower_plus_less1: "xs \<sqsubseteq> lower_plus\<cdot>xs\<cdot>ys"
   1.338 +apply (induct xs ys rule: lower_principal_induct2, simp, simp)
   1.339 +apply (simp add: PDPlus_lower_less)
   1.340 +done
   1.341 +
   1.342 +lemma lower_plus_less2: "ys \<sqsubseteq> lower_plus\<cdot>xs\<cdot>ys"
   1.343 +by (subst lower_plus_commute, rule lower_plus_less1)
   1.344 +
   1.345 +lemma lower_plus_least: "\<lbrakk>xs \<sqsubseteq> zs; ys \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> lower_plus\<cdot>xs\<cdot>ys \<sqsubseteq> zs"
   1.346 +apply (subst lower_plus_absorb [of zs, symmetric])
   1.347 +apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
   1.348 +done
   1.349 +
   1.350 +lemma lower_plus_less_iff:
   1.351 +  "(lower_plus\<cdot>xs\<cdot>ys \<sqsubseteq> zs) = (xs \<sqsubseteq> zs \<and> ys \<sqsubseteq> zs)"
   1.352 +apply safe
   1.353 +apply (erule trans_less [OF lower_plus_less1])
   1.354 +apply (erule trans_less [OF lower_plus_less2])
   1.355 +apply (erule (1) lower_plus_least)
   1.356 +done
   1.357 +
   1.358 +lemma lower_plus_strict_iff [simp]:
   1.359 +  "(lower_plus\<cdot>xs\<cdot>ys = \<bottom>) = (xs = \<bottom> \<and> ys = \<bottom>)"
   1.360 +apply safe
   1.361 +apply (rule UU_I, erule subst, rule lower_plus_less1)
   1.362 +apply (rule UU_I, erule subst, rule lower_plus_less2)
   1.363 +apply (rule lower_plus_absorb)
   1.364 +done
   1.365 +
   1.366 +lemma lower_plus_strict1 [simp]: "lower_plus\<cdot>\<bottom>\<cdot>ys = ys"
   1.367 +apply (rule antisym_less [OF _ lower_plus_less2])
   1.368 +apply (simp add: lower_plus_least)
   1.369 +done
   1.370 +
   1.371 +lemma lower_plus_strict2 [simp]: "lower_plus\<cdot>xs\<cdot>\<bottom> = xs"
   1.372 +apply (rule antisym_less [OF _ lower_plus_less1])
   1.373 +apply (simp add: lower_plus_least)
   1.374 +done
   1.375 +
   1.376 +lemma lower_unit_less_plus_iff:
   1.377 +  "(lower_unit\<cdot>x \<sqsubseteq> lower_plus\<cdot>ys\<cdot>zs) =
   1.378 +    (lower_unit\<cdot>x \<sqsubseteq> ys \<or> lower_unit\<cdot>x \<sqsubseteq> zs)"
   1.379 + apply (rule iffI)
   1.380 +  apply (subgoal_tac
   1.381 +    "adm (\<lambda>f. f\<cdot>(lower_unit\<cdot>x) \<sqsubseteq> f\<cdot>ys \<or> f\<cdot>(lower_unit\<cdot>x) \<sqsubseteq> f\<cdot>zs)")
   1.382 +   apply (drule admD [rule_format], rule chain_approx)
   1.383 +    apply (drule_tac f="approx i" in monofun_cfun_arg)
   1.384 +    apply (cut_tac x="approx i\<cdot>x" in compact_imp_Rep_compact_basis, simp)
   1.385 +    apply (cut_tac xs="approx i\<cdot>ys" in compact_imp_lower_principal, simp)
   1.386 +    apply (cut_tac xs="approx i\<cdot>zs" in compact_imp_lower_principal, simp)
   1.387 +    apply (clarify, simp add: lower_le_PDUnit_PDPlus_iff)
   1.388 +   apply simp
   1.389 +  apply simp
   1.390 + apply (erule disjE)
   1.391 +  apply (erule trans_less [OF _ lower_plus_less1])
   1.392 + apply (erule trans_less [OF _ lower_plus_less2])
   1.393 +done
   1.394 +
   1.395 +lemmas lower_pd_less_simps =
   1.396 +  lower_unit_less_iff
   1.397 +  lower_plus_less_iff
   1.398 +  lower_unit_less_plus_iff
   1.399 +
   1.400 +
   1.401 +subsection {* Induction rules *}
   1.402 +
   1.403 +lemma lower_pd_induct1:
   1.404 +  assumes P: "adm P"
   1.405 +  assumes unit: "\<And>x. P (lower_unit\<cdot>x)"
   1.406 +  assumes insert:
   1.407 +    "\<And>x ys. \<lbrakk>P (lower_unit\<cdot>x); P ys\<rbrakk> \<Longrightarrow> P (lower_plus\<cdot>(lower_unit\<cdot>x)\<cdot>ys)"
   1.408 +  shows "P (xs::'a lower_pd)"
   1.409 +apply (induct xs rule: lower_principal_induct, rule P)
   1.410 +apply (induct_tac t rule: pd_basis_induct1)
   1.411 +apply (simp only: lower_unit_Rep_compact_basis [symmetric])
   1.412 +apply (rule unit)
   1.413 +apply (simp only: lower_unit_Rep_compact_basis [symmetric]
   1.414 +                  lower_plus_principal [symmetric])
   1.415 +apply (erule insert [OF unit])
   1.416 +done
   1.417 +
   1.418 +lemma lower_pd_induct:
   1.419 +  assumes P: "adm P"
   1.420 +  assumes unit: "\<And>x. P (lower_unit\<cdot>x)"
   1.421 +  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (lower_plus\<cdot>xs\<cdot>ys)"
   1.422 +  shows "P (xs::'a lower_pd)"
   1.423 +apply (induct xs rule: lower_principal_induct, rule P)
   1.424 +apply (induct_tac t rule: pd_basis_induct)
   1.425 +apply (simp only: lower_unit_Rep_compact_basis [symmetric] unit)
   1.426 +apply (simp only: lower_plus_principal [symmetric] plus)
   1.427 +done
   1.428 +
   1.429 +
   1.430 +subsection {* Monadic bind *}
   1.431 +
   1.432 +definition
   1.433 +  lower_bind_basis ::
   1.434 +  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b lower_pd) \<rightarrow> 'b lower_pd" where
   1.435 +  "lower_bind_basis = fold_pd
   1.436 +    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
   1.437 +    (\<lambda>x y. \<Lambda> f. lower_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
   1.438 +
   1.439 +lemma ACI_lower_bind: "ACIf (\<lambda>x y. \<Lambda> f. lower_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
   1.440 +apply unfold_locales
   1.441 +apply (simp add: lower_plus_commute)
   1.442 +apply (simp add: lower_plus_assoc)
   1.443 +apply (simp add: lower_plus_absorb eta_cfun)
   1.444 +done
   1.445 +
   1.446 +lemma lower_bind_basis_simps [simp]:
   1.447 +  "lower_bind_basis (PDUnit a) =
   1.448 +    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
   1.449 +  "lower_bind_basis (PDPlus t u) =
   1.450 +    (\<Lambda> f. lower_plus\<cdot>(lower_bind_basis t\<cdot>f)\<cdot>(lower_bind_basis u\<cdot>f))"
   1.451 +unfolding lower_bind_basis_def
   1.452 +apply -
   1.453 +apply (rule ACIf.fold_pd_PDUnit [OF ACI_lower_bind])
   1.454 +apply (rule ACIf.fold_pd_PDPlus [OF ACI_lower_bind])
   1.455 +done
   1.456 +
   1.457 +lemma lower_bind_basis_mono:
   1.458 +  "t \<le>\<flat> u \<Longrightarrow> lower_bind_basis t \<sqsubseteq> lower_bind_basis u"
   1.459 +unfolding expand_cfun_less
   1.460 +apply (erule lower_le_induct, safe)
   1.461 +apply (simp add: compact_le_def monofun_cfun)
   1.462 +apply (simp add: rev_trans_less [OF lower_plus_less1])
   1.463 +apply (simp add: lower_plus_less_iff)
   1.464 +done
   1.465 +
   1.466 +definition
   1.467 +  lower_bind :: "'a lower_pd \<rightarrow> ('a \<rightarrow> 'b lower_pd) \<rightarrow> 'b lower_pd" where
   1.468 +  "lower_bind = lower_pd.basis_fun lower_bind_basis"
   1.469 +
   1.470 +lemma lower_bind_principal [simp]:
   1.471 +  "lower_bind\<cdot>(lower_principal t) = lower_bind_basis t"
   1.472 +unfolding lower_bind_def
   1.473 +apply (rule lower_pd.basis_fun_principal)
   1.474 +apply (erule lower_bind_basis_mono)
   1.475 +done
   1.476 +
   1.477 +lemma lower_bind_unit [simp]:
   1.478 +  "lower_bind\<cdot>(lower_unit\<cdot>x)\<cdot>f = f\<cdot>x"
   1.479 +by (induct x rule: compact_basis_induct, simp, simp)
   1.480 +
   1.481 +lemma lower_bind_plus [simp]:
   1.482 +  "lower_bind\<cdot>(lower_plus\<cdot>xs\<cdot>ys)\<cdot>f =
   1.483 +   lower_plus\<cdot>(lower_bind\<cdot>xs\<cdot>f)\<cdot>(lower_bind\<cdot>ys\<cdot>f)"
   1.484 +by (induct xs ys rule: lower_principal_induct2, simp, simp, simp)
   1.485 +
   1.486 +lemma lower_bind_strict [simp]: "lower_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
   1.487 +unfolding lower_unit_strict [symmetric] by (rule lower_bind_unit)
   1.488 +
   1.489 +
   1.490 +subsection {* Map and join *}
   1.491 +
   1.492 +definition
   1.493 +  lower_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a lower_pd \<rightarrow> 'b lower_pd" where
   1.494 +  "lower_map = (\<Lambda> f xs. lower_bind\<cdot>xs\<cdot>(\<Lambda> x. lower_unit\<cdot>(f\<cdot>x)))"
   1.495 +
   1.496 +definition
   1.497 +  lower_join :: "'a lower_pd lower_pd \<rightarrow> 'a lower_pd" where
   1.498 +  "lower_join = (\<Lambda> xss. lower_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
   1.499 +
   1.500 +lemma lower_map_unit [simp]:
   1.501 +  "lower_map\<cdot>f\<cdot>(lower_unit\<cdot>x) = lower_unit\<cdot>(f\<cdot>x)"
   1.502 +unfolding lower_map_def by simp
   1.503 +
   1.504 +lemma lower_map_plus [simp]:
   1.505 +  "lower_map\<cdot>f\<cdot>(lower_plus\<cdot>xs\<cdot>ys) =
   1.506 +   lower_plus\<cdot>(lower_map\<cdot>f\<cdot>xs)\<cdot>(lower_map\<cdot>f\<cdot>ys)"
   1.507 +unfolding lower_map_def by simp
   1.508 +
   1.509 +lemma lower_join_unit [simp]:
   1.510 +  "lower_join\<cdot>(lower_unit\<cdot>xs) = xs"
   1.511 +unfolding lower_join_def by simp
   1.512 +
   1.513 +lemma lower_join_plus [simp]:
   1.514 +  "lower_join\<cdot>(lower_plus\<cdot>xss\<cdot>yss) =
   1.515 +   lower_plus\<cdot>(lower_join\<cdot>xss)\<cdot>(lower_join\<cdot>yss)"
   1.516 +unfolding lower_join_def by simp
   1.517 +
   1.518 +lemma lower_map_ident: "lower_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
   1.519 +by (induct xs rule: lower_pd_induct, simp_all)
   1.520 +
   1.521 +lemma lower_map_map:
   1.522 +  "lower_map\<cdot>f\<cdot>(lower_map\<cdot>g\<cdot>xs) = lower_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
   1.523 +by (induct xs rule: lower_pd_induct, simp_all)
   1.524 +
   1.525 +lemma lower_join_map_unit:
   1.526 +  "lower_join\<cdot>(lower_map\<cdot>lower_unit\<cdot>xs) = xs"
   1.527 +by (induct xs rule: lower_pd_induct, simp_all)
   1.528 +
   1.529 +lemma lower_join_map_join:
   1.530 +  "lower_join\<cdot>(lower_map\<cdot>lower_join\<cdot>xsss) = lower_join\<cdot>(lower_join\<cdot>xsss)"
   1.531 +by (induct xsss rule: lower_pd_induct, simp_all)
   1.532 +
   1.533 +lemma lower_join_map_map:
   1.534 +  "lower_join\<cdot>(lower_map\<cdot>(lower_map\<cdot>f)\<cdot>xss) =
   1.535 +   lower_map\<cdot>f\<cdot>(lower_join\<cdot>xss)"
   1.536 +by (induct xss rule: lower_pd_induct, simp_all)
   1.537 +
   1.538 +lemma lower_map_approx: "lower_map\<cdot>(approx n)\<cdot>xs = approx n\<cdot>xs"
   1.539 +by (induct xs rule: lower_pd_induct, simp_all)
   1.540 +
   1.541 +end