src/HOL/Library/Complete_Partial_Order2.thy
changeset 62652 7248d106c607
child 62837 237ef2bab6c7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Complete_Partial_Order2.thy	Fri Mar 18 08:01:49 2016 +0100
     1.3 @@ -0,0 +1,1708 @@
     1.4 +(*  Title:      src/HOL/Library/Complete_Partial_Order2
     1.5 +    Author:     Andreas Lochbihler, ETH Zurich
     1.6 +*)
     1.7 +
     1.8 +section {* Formalisation of chain-complete partial orders, continuity and admissibility *}
     1.9 +
    1.10 +theory Complete_Partial_Order2 imports 
    1.11 +  Main
    1.12 +  "~~/src/HOL/Library/Lattice_Syntax"
    1.13 +begin
    1.14 +
    1.15 +context begin interpretation lifting_syntax .
    1.16 +
    1.17 +lemma chain_transfer [transfer_rule]:
    1.18 +  "((A ===> A ===> op =) ===> rel_set A ===> op =) Complete_Partial_Order.chain Complete_Partial_Order.chain"
    1.19 +unfolding chain_def[abs_def] by transfer_prover
    1.20 +
    1.21 +end
    1.22 +
    1.23 +lemma linorder_chain [simp, intro!]:
    1.24 +  fixes Y :: "_ :: linorder set"
    1.25 +  shows "Complete_Partial_Order.chain op \<le> Y"
    1.26 +by(auto intro: chainI)
    1.27 +
    1.28 +lemma fun_lub_apply: "\<And>Sup. fun_lub Sup Y x = Sup ((\<lambda>f. f x) ` Y)"
    1.29 +by(simp add: fun_lub_def image_def)
    1.30 +
    1.31 +lemma fun_lub_empty [simp]: "fun_lub lub {} = (\<lambda>_. lub {})"
    1.32 +by(rule ext)(simp add: fun_lub_apply)
    1.33 +
    1.34 +lemma chain_fun_ordD: 
    1.35 +  assumes "Complete_Partial_Order.chain (fun_ord le) Y"
    1.36 +  shows "Complete_Partial_Order.chain le ((\<lambda>f. f x) ` Y)"
    1.37 +by(rule chainI)(auto dest: chainD[OF assms] simp add: fun_ord_def)
    1.38 +
    1.39 +lemma chain_Diff:
    1.40 +  "Complete_Partial_Order.chain ord A
    1.41 +  \<Longrightarrow> Complete_Partial_Order.chain ord (A - B)"
    1.42 +by(erule chain_subset) blast
    1.43 +
    1.44 +lemma chain_rel_prodD1:
    1.45 +  "Complete_Partial_Order.chain (rel_prod orda ordb) Y
    1.46 +  \<Longrightarrow> Complete_Partial_Order.chain orda (fst ` Y)"
    1.47 +by(auto 4 3 simp add: chain_def)
    1.48 +
    1.49 +lemma chain_rel_prodD2:
    1.50 +  "Complete_Partial_Order.chain (rel_prod orda ordb) Y
    1.51 +  \<Longrightarrow> Complete_Partial_Order.chain ordb (snd ` Y)"
    1.52 +by(auto 4 3 simp add: chain_def)
    1.53 +
    1.54 +
    1.55 +context ccpo begin
    1.56 +
    1.57 +lemma ccpo_fun: "class.ccpo (fun_lub Sup) (fun_ord op \<le>) (mk_less (fun_ord op \<le>))"
    1.58 +  by standard (auto 4 3 simp add: mk_less_def fun_ord_def fun_lub_apply
    1.59 +    intro: order.trans antisym chain_imageI ccpo_Sup_upper ccpo_Sup_least)
    1.60 +
    1.61 +lemma ccpo_Sup_below_iff: "Complete_Partial_Order.chain op \<le> Y \<Longrightarrow> Sup Y \<le> x \<longleftrightarrow> (\<forall>y\<in>Y. y \<le> x)"
    1.62 +by(fast intro: order_trans[OF ccpo_Sup_upper] ccpo_Sup_least)
    1.63 +
    1.64 +lemma Sup_minus_bot: 
    1.65 +  assumes chain: "Complete_Partial_Order.chain op \<le> A"
    1.66 +  shows "\<Squnion>(A - {\<Squnion>{}}) = \<Squnion>A"
    1.67 +apply(rule antisym)
    1.68 + apply(blast intro: ccpo_Sup_least chain_Diff[OF chain] ccpo_Sup_upper[OF chain])
    1.69 +apply(rule ccpo_Sup_least[OF chain])
    1.70 +apply(case_tac "x = \<Squnion>{}")
    1.71 +by(blast intro: ccpo_Sup_least chain_empty ccpo_Sup_upper[OF chain_Diff[OF chain]])+
    1.72 +
    1.73 +lemma mono_lub:
    1.74 +  fixes le_b (infix "\<sqsubseteq>" 60)
    1.75 +  assumes chain: "Complete_Partial_Order.chain (fun_ord op \<le>) Y"
    1.76 +  and mono: "\<And>f. f \<in> Y \<Longrightarrow> monotone le_b op \<le> f"
    1.77 +  shows "monotone op \<sqsubseteq> op \<le> (fun_lub Sup Y)"
    1.78 +proof(rule monotoneI)
    1.79 +  fix x y
    1.80 +  assume "x \<sqsubseteq> y"
    1.81 +
    1.82 +  have chain'': "\<And>x. Complete_Partial_Order.chain op \<le> ((\<lambda>f. f x) ` Y)"
    1.83 +    using chain by(rule chain_imageI)(simp add: fun_ord_def)
    1.84 +  then show "fun_lub Sup Y x \<le> fun_lub Sup Y y" unfolding fun_lub_apply
    1.85 +  proof(rule ccpo_Sup_least)
    1.86 +    fix x'
    1.87 +    assume "x' \<in> (\<lambda>f. f x) ` Y"
    1.88 +    then obtain f where "f \<in> Y" "x' = f x" by blast
    1.89 +    note `x' = f x` also
    1.90 +    from `f \<in> Y` `x \<sqsubseteq> y` have "f x \<le> f y" by(blast dest: mono monotoneD)
    1.91 +    also have "\<dots> \<le> \<Squnion>((\<lambda>f. f y) ` Y)" using chain''
    1.92 +      by(rule ccpo_Sup_upper)(simp add: `f \<in> Y`)
    1.93 +    finally show "x' \<le> \<Squnion>((\<lambda>f. f y) ` Y)" .
    1.94 +  qed
    1.95 +qed
    1.96 +
    1.97 +context
    1.98 +  fixes le_b (infix "\<sqsubseteq>" 60) and Y f
    1.99 +  assumes chain: "Complete_Partial_Order.chain le_b Y" 
   1.100 +  and mono1: "\<And>y. y \<in> Y \<Longrightarrow> monotone le_b op \<le> (\<lambda>x. f x y)"
   1.101 +  and mono2: "\<And>x a b. \<lbrakk> x \<in> Y; a \<sqsubseteq> b; a \<in> Y; b \<in> Y \<rbrakk> \<Longrightarrow> f x a \<le> f x b"
   1.102 +begin
   1.103 +
   1.104 +lemma Sup_mono: 
   1.105 +  assumes le: "x \<sqsubseteq> y" and x: "x \<in> Y" and y: "y \<in> Y"
   1.106 +  shows "\<Squnion>(f x ` Y) \<le> \<Squnion>(f y ` Y)" (is "_ \<le> ?rhs")
   1.107 +proof(rule ccpo_Sup_least)
   1.108 +  from chain show chain': "Complete_Partial_Order.chain op \<le> (f x ` Y)" when "x \<in> Y" for x
   1.109 +    by(rule chain_imageI) (insert that, auto dest: mono2)
   1.110 +
   1.111 +  fix x'
   1.112 +  assume "x' \<in> f x ` Y"
   1.113 +  then obtain y' where "y' \<in> Y" "x' = f x y'" by blast note this(2)
   1.114 +  also from mono1[OF `y' \<in> Y`] le have "\<dots> \<le> f y y'" by(rule monotoneD)
   1.115 +  also have "\<dots> \<le> ?rhs" using chain'[OF y]
   1.116 +    by (auto intro!: ccpo_Sup_upper simp add: `y' \<in> Y`)
   1.117 +  finally show "x' \<le> ?rhs" .
   1.118 +qed(rule x)
   1.119 +
   1.120 +lemma diag_Sup: "\<Squnion>((\<lambda>x. \<Squnion>(f x ` Y)) ` Y) = \<Squnion>((\<lambda>x. f x x) ` Y)" (is "?lhs = ?rhs")
   1.121 +proof(rule antisym)
   1.122 +  have chain1: "Complete_Partial_Order.chain op \<le> ((\<lambda>x. \<Squnion>(f x ` Y)) ` Y)"
   1.123 +    using chain by(rule chain_imageI)(rule Sup_mono)
   1.124 +  have chain2: "\<And>y'. y' \<in> Y \<Longrightarrow> Complete_Partial_Order.chain op \<le> (f y' ` Y)" using chain
   1.125 +    by(rule chain_imageI)(auto dest: mono2)
   1.126 +  have chain3: "Complete_Partial_Order.chain op \<le> ((\<lambda>x. f x x) ` Y)"
   1.127 +    using chain by(rule chain_imageI)(auto intro: monotoneD[OF mono1] mono2 order.trans)
   1.128 +
   1.129 +  show "?lhs \<le> ?rhs" using chain1
   1.130 +  proof(rule ccpo_Sup_least)
   1.131 +    fix x'
   1.132 +    assume "x' \<in> (\<lambda>x. \<Squnion>(f x ` Y)) ` Y"
   1.133 +    then obtain y' where "y' \<in> Y" "x' = \<Squnion>(f y' ` Y)" by blast note this(2)
   1.134 +    also have "\<dots> \<le> ?rhs" using chain2[OF `y' \<in> Y`]
   1.135 +    proof(rule ccpo_Sup_least)
   1.136 +      fix x
   1.137 +      assume "x \<in> f y' ` Y"
   1.138 +      then obtain y where "y \<in> Y" and x: "x = f y' y" by blast
   1.139 +      def y'' \<equiv> "if y \<sqsubseteq> y' then y' else y"
   1.140 +      from chain `y \<in> Y` `y' \<in> Y` have "y \<sqsubseteq> y' \<or> y' \<sqsubseteq> y" by(rule chainD)
   1.141 +      hence "f y' y \<le> f y'' y''" using `y \<in> Y` `y' \<in> Y`
   1.142 +        by(auto simp add: y''_def intro: mono2 monotoneD[OF mono1])
   1.143 +      also from `y \<in> Y` `y' \<in> Y` have "y'' \<in> Y" by(simp add: y''_def)
   1.144 +      from chain3 have "f y'' y'' \<le> ?rhs" by(rule ccpo_Sup_upper)(simp add: `y'' \<in> Y`)
   1.145 +      finally show "x \<le> ?rhs" by(simp add: x)
   1.146 +    qed
   1.147 +    finally show "x' \<le> ?rhs" .
   1.148 +  qed
   1.149 +
   1.150 +  show "?rhs \<le> ?lhs" using chain3
   1.151 +  proof(rule ccpo_Sup_least)
   1.152 +    fix y
   1.153 +    assume "y \<in> (\<lambda>x. f x x) ` Y"
   1.154 +    then obtain x where "x \<in> Y" and "y = f x x" by blast note this(2)
   1.155 +    also from chain2[OF `x \<in> Y`] have "\<dots> \<le> \<Squnion>(f x ` Y)"
   1.156 +      by(rule ccpo_Sup_upper)(simp add: `x \<in> Y`)
   1.157 +    also have "\<dots> \<le> ?lhs" by(rule ccpo_Sup_upper[OF chain1])(simp add: `x \<in> Y`)
   1.158 +    finally show "y \<le> ?lhs" .
   1.159 +  qed
   1.160 +qed
   1.161 +
   1.162 +end
   1.163 +
   1.164 +lemma Sup_image_mono_le:
   1.165 +  fixes le_b (infix "\<sqsubseteq>" 60) and Sup_b ("\<Or>_" [900] 900)
   1.166 +  assumes ccpo: "class.ccpo Sup_b op \<sqsubseteq> lt_b"
   1.167 +  assumes chain: "Complete_Partial_Order.chain op \<sqsubseteq> Y"
   1.168 +  and mono: "\<And>x y. \<lbrakk> x \<sqsubseteq> y; x \<in> Y \<rbrakk> \<Longrightarrow> f x \<le> f y"
   1.169 +  shows "Sup (f ` Y) \<le> f (\<Or>Y)"
   1.170 +proof(rule ccpo_Sup_least)
   1.171 +  show "Complete_Partial_Order.chain op \<le> (f ` Y)"
   1.172 +    using chain by(rule chain_imageI)(rule mono)
   1.173 +
   1.174 +  fix x
   1.175 +  assume "x \<in> f ` Y"
   1.176 +  then obtain y where "y \<in> Y" and "x = f y" by blast note this(2)
   1.177 +  also have "y \<sqsubseteq> \<Or>Y" using ccpo chain `y \<in> Y` by(rule ccpo.ccpo_Sup_upper)
   1.178 +  hence "f y \<le> f (\<Or>Y)" using `y \<in> Y` by(rule mono)
   1.179 +  finally show "x \<le> \<dots>" .
   1.180 +qed
   1.181 +
   1.182 +lemma swap_Sup:
   1.183 +  fixes le_b (infix "\<sqsubseteq>" 60)
   1.184 +  assumes Y: "Complete_Partial_Order.chain op \<sqsubseteq> Y"
   1.185 +  and Z: "Complete_Partial_Order.chain (fun_ord op \<le>) Z"
   1.186 +  and mono: "\<And>f. f \<in> Z \<Longrightarrow> monotone op \<sqsubseteq> op \<le> f"
   1.187 +  shows "\<Squnion>((\<lambda>x. \<Squnion>(x ` Y)) ` Z) = \<Squnion>((\<lambda>x. \<Squnion>((\<lambda>f. f x) ` Z)) ` Y)"
   1.188 +  (is "?lhs = ?rhs")
   1.189 +proof(cases "Y = {}")
   1.190 +  case True
   1.191 +  then show ?thesis
   1.192 +    by (simp add: image_constant_conv cong del: strong_SUP_cong)
   1.193 +next
   1.194 +  case False
   1.195 +  have chain1: "\<And>f. f \<in> Z \<Longrightarrow> Complete_Partial_Order.chain op \<le> (f ` Y)"
   1.196 +    by(rule chain_imageI[OF Y])(rule monotoneD[OF mono])
   1.197 +  have chain2: "Complete_Partial_Order.chain op \<le> ((\<lambda>x. \<Squnion>(x ` Y)) ` Z)" using Z
   1.198 +  proof(rule chain_imageI)
   1.199 +    fix f g
   1.200 +    assume "f \<in> Z" "g \<in> Z"
   1.201 +      and "fun_ord op \<le> f g"
   1.202 +    from chain1[OF `f \<in> Z`] show "\<Squnion>(f ` Y) \<le> \<Squnion>(g ` Y)"
   1.203 +    proof(rule ccpo_Sup_least)
   1.204 +      fix x
   1.205 +      assume "x \<in> f ` Y"
   1.206 +      then obtain y where "y \<in> Y" "x = f y" by blast note this(2)
   1.207 +      also have "\<dots> \<le> g y" using `fun_ord op \<le> f g` by(simp add: fun_ord_def)
   1.208 +      also have "\<dots> \<le> \<Squnion>(g ` Y)" using chain1[OF `g \<in> Z`]
   1.209 +        by(rule ccpo_Sup_upper)(simp add: `y \<in> Y`)
   1.210 +      finally show "x \<le> \<Squnion>(g ` Y)" .
   1.211 +    qed
   1.212 +  qed
   1.213 +  have chain3: "\<And>x. Complete_Partial_Order.chain op \<le> ((\<lambda>f. f x) ` Z)"
   1.214 +    using Z by(rule chain_imageI)(simp add: fun_ord_def)
   1.215 +  have chain4: "Complete_Partial_Order.chain op \<le> ((\<lambda>x. \<Squnion>((\<lambda>f. f x) ` Z)) ` Y)"
   1.216 +    using Y
   1.217 +  proof(rule chain_imageI)
   1.218 +    fix f x y
   1.219 +    assume "x \<sqsubseteq> y"
   1.220 +    show "\<Squnion>((\<lambda>f. f x) ` Z) \<le> \<Squnion>((\<lambda>f. f y) ` Z)" (is "_ \<le> ?rhs") using chain3
   1.221 +    proof(rule ccpo_Sup_least)
   1.222 +      fix x'
   1.223 +      assume "x' \<in> (\<lambda>f. f x) ` Z"
   1.224 +      then obtain f where "f \<in> Z" "x' = f x" by blast note this(2)
   1.225 +      also have "f x \<le> f y" using `f \<in> Z` `x \<sqsubseteq> y` by(rule monotoneD[OF mono])
   1.226 +      also have "f y \<le> ?rhs" using chain3
   1.227 +        by(rule ccpo_Sup_upper)(simp add: `f \<in> Z`)
   1.228 +      finally show "x' \<le> ?rhs" .
   1.229 +    qed
   1.230 +  qed
   1.231 +
   1.232 +  from chain2 have "?lhs \<le> ?rhs"
   1.233 +  proof(rule ccpo_Sup_least)
   1.234 +    fix x
   1.235 +    assume "x \<in> (\<lambda>x. \<Squnion>(x ` Y)) ` Z"
   1.236 +    then obtain f where "f \<in> Z" "x = \<Squnion>(f ` Y)" by blast note this(2)
   1.237 +    also have "\<dots> \<le> ?rhs" using chain1[OF `f \<in> Z`]
   1.238 +    proof(rule ccpo_Sup_least)
   1.239 +      fix x'
   1.240 +      assume "x' \<in> f ` Y"
   1.241 +      then obtain y where "y \<in> Y" "x' = f y" by blast note this(2)
   1.242 +      also have "f y \<le> \<Squnion>((\<lambda>f. f y) ` Z)" using chain3
   1.243 +        by(rule ccpo_Sup_upper)(simp add: `f \<in> Z`)
   1.244 +      also have "\<dots> \<le> ?rhs" using chain4 by(rule ccpo_Sup_upper)(simp add: `y \<in> Y`)
   1.245 +      finally show "x' \<le> ?rhs" .
   1.246 +    qed
   1.247 +    finally show "x \<le> ?rhs" .
   1.248 +  qed
   1.249 +  moreover
   1.250 +  have "?rhs \<le> ?lhs" using chain4
   1.251 +  proof(rule ccpo_Sup_least)
   1.252 +    fix x
   1.253 +    assume "x \<in> (\<lambda>x. \<Squnion>((\<lambda>f. f x) ` Z)) ` Y"
   1.254 +    then obtain y where "y \<in> Y" "x = \<Squnion>((\<lambda>f. f y) ` Z)" by blast note this(2)
   1.255 +    also have "\<dots> \<le> ?lhs" using chain3
   1.256 +    proof(rule ccpo_Sup_least)
   1.257 +      fix x'
   1.258 +      assume "x' \<in> (\<lambda>f. f y) ` Z"
   1.259 +      then obtain f where "f \<in> Z" "x' = f y" by blast note this(2)
   1.260 +      also have "f y \<le> \<Squnion>(f ` Y)" using chain1[OF `f \<in> Z`]
   1.261 +        by(rule ccpo_Sup_upper)(simp add: `y \<in> Y`)
   1.262 +      also have "\<dots> \<le> ?lhs" using chain2
   1.263 +        by(rule ccpo_Sup_upper)(simp add: `f \<in> Z`)
   1.264 +      finally show "x' \<le> ?lhs" .
   1.265 +    qed
   1.266 +    finally show "x \<le> ?lhs" .
   1.267 +  qed
   1.268 +  ultimately show "?lhs = ?rhs" by(rule antisym)
   1.269 +qed
   1.270 +
   1.271 +lemma fixp_mono:
   1.272 +  assumes fg: "fun_ord op \<le> f g"
   1.273 +  and f: "monotone op \<le> op \<le> f"
   1.274 +  and g: "monotone op \<le> op \<le> g"
   1.275 +  shows "ccpo_class.fixp f \<le> ccpo_class.fixp g"
   1.276 +unfolding fixp_def
   1.277 +proof(rule ccpo_Sup_least)
   1.278 +  fix x
   1.279 +  assume "x \<in> ccpo_class.iterates f"
   1.280 +  thus "x \<le> \<Squnion>ccpo_class.iterates g"
   1.281 +  proof induction
   1.282 +    case (step x)
   1.283 +    from f step.IH have "f x \<le> f (\<Squnion>ccpo_class.iterates g)" by(rule monotoneD)
   1.284 +    also have "\<dots> \<le> g (\<Squnion>ccpo_class.iterates g)" using fg by(simp add: fun_ord_def)
   1.285 +    also have "\<dots> = \<Squnion>ccpo_class.iterates g" by(fold fixp_def fixp_unfold[OF g]) simp
   1.286 +    finally show ?case .
   1.287 +  qed(blast intro: ccpo_Sup_least)
   1.288 +qed(rule chain_iterates[OF f])
   1.289 +
   1.290 +context fixes ordb :: "'b \<Rightarrow> 'b \<Rightarrow> bool" (infix "\<sqsubseteq>" 60) begin
   1.291 +
   1.292 +lemma iterates_mono:
   1.293 +  assumes f: "f \<in> ccpo.iterates (fun_lub Sup) (fun_ord op \<le>) F"
   1.294 +  and mono: "\<And>f. monotone op \<sqsubseteq> op \<le> f \<Longrightarrow> monotone op \<sqsubseteq> op \<le> (F f)"
   1.295 +  shows "monotone op \<sqsubseteq> op \<le> f"
   1.296 +using f
   1.297 +by(induction rule: ccpo.iterates.induct[OF ccpo_fun, consumes 1, case_names step Sup])(blast intro: mono mono_lub)+
   1.298 +
   1.299 +lemma fixp_preserves_mono:
   1.300 +  assumes mono: "\<And>x. monotone (fun_ord op \<le>) op \<le> (\<lambda>f. F f x)"
   1.301 +  and mono2: "\<And>f. monotone op \<sqsubseteq> op \<le> f \<Longrightarrow> monotone op \<sqsubseteq> op \<le> (F f)"
   1.302 +  shows "monotone op \<sqsubseteq> op \<le> (ccpo.fixp (fun_lub Sup) (fun_ord op \<le>) F)"
   1.303 +  (is "monotone _ _ ?fixp")
   1.304 +proof(rule monotoneI)
   1.305 +  have mono: "monotone (fun_ord op \<le>) (fun_ord op \<le>) F"
   1.306 +    by(rule monotoneI)(auto simp add: fun_ord_def intro: monotoneD[OF mono])
   1.307 +  let ?iter = "ccpo.iterates (fun_lub Sup) (fun_ord op \<le>) F"
   1.308 +  have chain: "\<And>x. Complete_Partial_Order.chain op \<le> ((\<lambda>f. f x) ` ?iter)"
   1.309 +    by(rule chain_imageI[OF ccpo.chain_iterates[OF ccpo_fun mono]])(simp add: fun_ord_def)
   1.310 +
   1.311 +  fix x y
   1.312 +  assume "x \<sqsubseteq> y"
   1.313 +  show "?fixp x \<le> ?fixp y"
   1.314 +    unfolding ccpo.fixp_def[OF ccpo_fun] fun_lub_apply using chain
   1.315 +  proof(rule ccpo_Sup_least)
   1.316 +    fix x'
   1.317 +    assume "x' \<in> (\<lambda>f. f x) ` ?iter"
   1.318 +    then obtain f where "f \<in> ?iter" "x' = f x" by blast note this(2)
   1.319 +    also have "f x \<le> f y"
   1.320 +      by(rule monotoneD[OF iterates_mono[OF `f \<in> ?iter` mono2]])(blast intro: `x \<sqsubseteq> y`)+
   1.321 +    also have "f y \<le> \<Squnion>((\<lambda>f. f y) ` ?iter)" using chain
   1.322 +      by(rule ccpo_Sup_upper)(simp add: `f \<in> ?iter`)
   1.323 +    finally show "x' \<le> \<dots>" .
   1.324 +  qed
   1.325 +qed
   1.326 +
   1.327 +end
   1.328 +
   1.329 +end
   1.330 +
   1.331 +lemma monotone2monotone:
   1.332 +  assumes 2: "\<And>x. monotone ordb ordc (\<lambda>y. f x y)"
   1.333 +  and t: "monotone orda ordb (\<lambda>x. t x)"
   1.334 +  and 1: "\<And>y. monotone orda ordc (\<lambda>x. f x y)"
   1.335 +  and trans: "transp ordc"
   1.336 +  shows "monotone orda ordc (\<lambda>x. f x (t x))"
   1.337 +by(blast intro: monotoneI transpD[OF trans] monotoneD[OF t] monotoneD[OF 2] monotoneD[OF 1])
   1.338 +
   1.339 +subsection {* Continuity *}
   1.340 +
   1.341 +definition cont :: "('a set \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b set \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
   1.342 +where
   1.343 +  "cont luba orda lubb ordb f \<longleftrightarrow> 
   1.344 +  (\<forall>Y. Complete_Partial_Order.chain orda Y \<longrightarrow> Y \<noteq> {} \<longrightarrow> f (luba Y) = lubb (f ` Y))"
   1.345 +
   1.346 +definition mcont :: "('a set \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b set \<Rightarrow> 'b) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> bool"
   1.347 +where
   1.348 +  "mcont luba orda lubb ordb f \<longleftrightarrow>
   1.349 +   monotone orda ordb f \<and> cont luba orda lubb ordb f"
   1.350 +
   1.351 +subsubsection {* Theorem collection @{text cont_intro} *}
   1.352 +
   1.353 +named_theorems cont_intro "continuity and admissibility intro rules"
   1.354 +ML {*
   1.355 +(* apply cont_intro rules as intro and try to solve 
   1.356 +   the remaining of the emerging subgoals with simp *)
   1.357 +fun cont_intro_tac ctxt =
   1.358 +  REPEAT_ALL_NEW (resolve_tac ctxt (rev (Named_Theorems.get ctxt @{named_theorems cont_intro})))
   1.359 +  THEN_ALL_NEW (SOLVED' (simp_tac ctxt))
   1.360 +
   1.361 +fun cont_intro_simproc ctxt ct =
   1.362 +  let
   1.363 +    fun mk_stmt t = t
   1.364 +      |> HOLogic.mk_Trueprop
   1.365 +      |> Thm.cterm_of ctxt
   1.366 +      |> Goal.init
   1.367 +    fun mk_thm t =
   1.368 +      case SINGLE (cont_intro_tac ctxt 1) (mk_stmt t) of
   1.369 +        SOME thm => SOME (Goal.finish ctxt thm RS @{thm Eq_TrueI})
   1.370 +      | NONE => NONE
   1.371 +  in
   1.372 +    case Thm.term_of ct of
   1.373 +      t as Const (@{const_name ccpo.admissible}, _) $ _ $ _ $ _ => mk_thm t
   1.374 +    | t as Const (@{const_name mcont}, _) $ _ $ _ $ _ $ _ $ _ => mk_thm t
   1.375 +    | t as Const (@{const_name monotone}, _) $ _ $ _ $ _ => mk_thm t
   1.376 +    | _ => NONE
   1.377 +  end
   1.378 +  handle THM _ => NONE 
   1.379 +  | TYPE _ => NONE
   1.380 +*}
   1.381 +
   1.382 +simproc_setup "cont_intro"
   1.383 +  ( "ccpo.admissible lub ord P"
   1.384 +  | "mcont lub ord lub' ord' f"
   1.385 +  | "monotone ord ord' f"
   1.386 +  ) = {* K cont_intro_simproc *}
   1.387 +
   1.388 +lemmas [cont_intro] =
   1.389 +  call_mono
   1.390 +  let_mono
   1.391 +  if_mono
   1.392 +  option.const_mono
   1.393 +  tailrec.const_mono
   1.394 +  bind_mono
   1.395 +
   1.396 +declare if_mono[simp]
   1.397 +
   1.398 +lemma monotone_id' [cont_intro]: "monotone ord ord (\<lambda>x. x)"
   1.399 +by(simp add: monotone_def)
   1.400 +
   1.401 +lemma monotone_applyI:
   1.402 +  "monotone orda ordb F \<Longrightarrow> monotone (fun_ord orda) ordb (\<lambda>f. F (f x))"
   1.403 +by(rule monotoneI)(auto simp add: fun_ord_def dest: monotoneD)
   1.404 +
   1.405 +lemma monotone_if_fun [partial_function_mono]:
   1.406 +  "\<lbrakk> monotone (fun_ord orda) (fun_ord ordb) F; monotone (fun_ord orda) (fun_ord ordb) G \<rbrakk>
   1.407 +  \<Longrightarrow> monotone (fun_ord orda) (fun_ord ordb) (\<lambda>f n. if c n then F f n else G f n)"
   1.408 +by(simp add: monotone_def fun_ord_def)
   1.409 +
   1.410 +lemma monotone_fun_apply_fun [partial_function_mono]: 
   1.411 +  "monotone (fun_ord (fun_ord ord)) (fun_ord ord) (\<lambda>f n. f t (g n))"
   1.412 +by(rule monotoneI)(simp add: fun_ord_def)
   1.413 +
   1.414 +lemma monotone_fun_ord_apply: 
   1.415 +  "monotone orda (fun_ord ordb) f \<longleftrightarrow> (\<forall>x. monotone orda ordb (\<lambda>y. f y x))"
   1.416 +by(auto simp add: monotone_def fun_ord_def)
   1.417 +
   1.418 +context preorder begin
   1.419 +
   1.420 +lemma transp_le [simp, cont_intro]: "transp op \<le>"
   1.421 +by(rule transpI)(rule order_trans)
   1.422 +
   1.423 +lemma monotone_const [simp, cont_intro]: "monotone ord op \<le> (\<lambda>_. c)"
   1.424 +by(rule monotoneI) simp
   1.425 +
   1.426 +end
   1.427 +
   1.428 +lemma transp_le [cont_intro, simp]:
   1.429 +  "class.preorder ord (mk_less ord) \<Longrightarrow> transp ord"
   1.430 +by(rule preorder.transp_le)
   1.431 +
   1.432 +context partial_function_definitions begin
   1.433 +
   1.434 +declare const_mono [cont_intro, simp]
   1.435 +
   1.436 +lemma transp_le [cont_intro, simp]: "transp leq"
   1.437 +by(rule transpI)(rule leq_trans)
   1.438 +
   1.439 +lemma preorder [cont_intro, simp]: "class.preorder leq (mk_less leq)"
   1.440 +by(unfold_locales)(auto simp add: mk_less_def intro: leq_refl leq_trans)
   1.441 +
   1.442 +declare ccpo[cont_intro, simp]
   1.443 +
   1.444 +end
   1.445 +
   1.446 +lemma contI [intro?]:
   1.447 +  "(\<And>Y. \<lbrakk> Complete_Partial_Order.chain orda Y; Y \<noteq> {} \<rbrakk> \<Longrightarrow> f (luba Y) = lubb (f ` Y)) 
   1.448 +  \<Longrightarrow> cont luba orda lubb ordb f"
   1.449 +unfolding cont_def by blast
   1.450 +
   1.451 +lemma contD:
   1.452 +  "\<lbrakk> cont luba orda lubb ordb f; Complete_Partial_Order.chain orda Y; Y \<noteq> {} \<rbrakk> 
   1.453 +  \<Longrightarrow> f (luba Y) = lubb (f ` Y)"
   1.454 +unfolding cont_def by blast
   1.455 +
   1.456 +lemma cont_id [simp, cont_intro]: "\<And>Sup. cont Sup ord Sup ord id"
   1.457 +by(rule contI) simp
   1.458 +
   1.459 +lemma cont_id' [simp, cont_intro]: "\<And>Sup. cont Sup ord Sup ord (\<lambda>x. x)"
   1.460 +using cont_id[unfolded id_def] .
   1.461 +
   1.462 +lemma cont_applyI [cont_intro]:
   1.463 +  assumes cont: "cont luba orda lubb ordb g"
   1.464 +  shows "cont (fun_lub luba) (fun_ord orda) lubb ordb (\<lambda>f. g (f x))"
   1.465 +by(rule contI)(drule chain_fun_ordD[where x=x], simp add: fun_lub_apply image_image contD[OF cont])
   1.466 +
   1.467 +lemma call_cont: "cont (fun_lub lub) (fun_ord ord) lub ord (\<lambda>f. f t)"
   1.468 +by(simp add: cont_def fun_lub_apply)
   1.469 +
   1.470 +lemma cont_if [cont_intro]:
   1.471 +  "\<lbrakk> cont luba orda lubb ordb f; cont luba orda lubb ordb g \<rbrakk>
   1.472 +  \<Longrightarrow> cont luba orda lubb ordb (\<lambda>x. if c then f x else g x)"
   1.473 +by(cases c) simp_all
   1.474 +
   1.475 +lemma mcontI [intro?]:
   1.476 +   "\<lbrakk> monotone orda ordb f; cont luba orda lubb ordb f \<rbrakk> \<Longrightarrow> mcont luba orda lubb ordb f"
   1.477 +by(simp add: mcont_def)
   1.478 +
   1.479 +lemma mcont_mono: "mcont luba orda lubb ordb f \<Longrightarrow> monotone orda ordb f"
   1.480 +by(simp add: mcont_def)
   1.481 +
   1.482 +lemma mcont_cont [simp]: "mcont luba orda lubb ordb f \<Longrightarrow> cont luba orda lubb ordb f"
   1.483 +by(simp add: mcont_def)
   1.484 +
   1.485 +lemma mcont_monoD:
   1.486 +  "\<lbrakk> mcont luba orda lubb ordb f; orda x y \<rbrakk> \<Longrightarrow> ordb (f x) (f y)"
   1.487 +by(auto simp add: mcont_def dest: monotoneD)
   1.488 +
   1.489 +lemma mcont_contD:
   1.490 +  "\<lbrakk> mcont luba orda lubb ordb f; Complete_Partial_Order.chain orda Y; Y \<noteq> {} \<rbrakk>
   1.491 +  \<Longrightarrow> f (luba Y) = lubb (f ` Y)"
   1.492 +by(auto simp add: mcont_def dest: contD)
   1.493 +
   1.494 +lemma mcont_call [cont_intro, simp]:
   1.495 +  "mcont (fun_lub lub) (fun_ord ord) lub ord (\<lambda>f. f t)"
   1.496 +by(simp add: mcont_def call_mono call_cont)
   1.497 +
   1.498 +lemma mcont_id' [cont_intro, simp]: "mcont lub ord lub ord (\<lambda>x. x)"
   1.499 +by(simp add: mcont_def monotone_id')
   1.500 +
   1.501 +lemma mcont_applyI:
   1.502 +  "mcont luba orda lubb ordb (\<lambda>x. F x) \<Longrightarrow> mcont (fun_lub luba) (fun_ord orda) lubb ordb (\<lambda>f. F (f x))"
   1.503 +by(simp add: mcont_def monotone_applyI cont_applyI)
   1.504 +
   1.505 +lemma mcont_if [cont_intro, simp]:
   1.506 +  "\<lbrakk> mcont luba orda lubb ordb (\<lambda>x. f x); mcont luba orda lubb ordb (\<lambda>x. g x) \<rbrakk>
   1.507 +  \<Longrightarrow> mcont luba orda lubb ordb (\<lambda>x. if c then f x else g x)"
   1.508 +by(simp add: mcont_def cont_if)
   1.509 +
   1.510 +lemma cont_fun_lub_apply: 
   1.511 +  "cont luba orda (fun_lub lubb) (fun_ord ordb) f \<longleftrightarrow> (\<forall>x. cont luba orda lubb ordb (\<lambda>y. f y x))"
   1.512 +by(simp add: cont_def fun_lub_def fun_eq_iff)(auto simp add: image_def)
   1.513 +
   1.514 +lemma mcont_fun_lub_apply: 
   1.515 +  "mcont luba orda (fun_lub lubb) (fun_ord ordb) f \<longleftrightarrow> (\<forall>x. mcont luba orda lubb ordb (\<lambda>y. f y x))"
   1.516 +by(auto simp add: monotone_fun_ord_apply cont_fun_lub_apply mcont_def)
   1.517 +
   1.518 +context ccpo begin
   1.519 +
   1.520 +lemma cont_const [simp, cont_intro]: "cont luba orda Sup op \<le> (\<lambda>x. c)"
   1.521 +by (rule contI) (simp add: image_constant_conv cong del: strong_SUP_cong)
   1.522 +
   1.523 +lemma mcont_const [cont_intro, simp]:
   1.524 +  "mcont luba orda Sup op \<le> (\<lambda>x. c)"
   1.525 +by(simp add: mcont_def)
   1.526 +
   1.527 +lemma cont_apply:
   1.528 +  assumes 2: "\<And>x. cont lubb ordb Sup op \<le> (\<lambda>y. f x y)"
   1.529 +  and t: "cont luba orda lubb ordb (\<lambda>x. t x)"
   1.530 +  and 1: "\<And>y. cont luba orda Sup op \<le> (\<lambda>x. f x y)"
   1.531 +  and mono: "monotone orda ordb (\<lambda>x. t x)"
   1.532 +  and mono2: "\<And>x. monotone ordb op \<le> (\<lambda>y. f x y)"
   1.533 +  and mono1: "\<And>y. monotone orda op \<le> (\<lambda>x. f x y)"
   1.534 +  shows "cont luba orda Sup op \<le> (\<lambda>x. f x (t x))"
   1.535 +proof
   1.536 +  fix Y
   1.537 +  assume chain: "Complete_Partial_Order.chain orda Y" and "Y \<noteq> {}"
   1.538 +  moreover from chain have chain': "Complete_Partial_Order.chain ordb (t ` Y)"
   1.539 +    by(rule chain_imageI)(rule monotoneD[OF mono])
   1.540 +  ultimately show "f (luba Y) (t (luba Y)) = \<Squnion>((\<lambda>x. f x (t x)) ` Y)"
   1.541 +    by(simp add: contD[OF 1] contD[OF t] contD[OF 2] image_image)
   1.542 +      (rule diag_Sup[OF chain], auto intro: monotone2monotone[OF mono2 mono monotone_const transpI] monotoneD[OF mono1])
   1.543 +qed
   1.544 +
   1.545 +lemma mcont2mcont':
   1.546 +  "\<lbrakk> \<And>x. mcont lub' ord' Sup op \<le> (\<lambda>y. f x y);
   1.547 +     \<And>y. mcont lub ord Sup op \<le> (\<lambda>x. f x y);
   1.548 +     mcont lub ord lub' ord' (\<lambda>y. t y) \<rbrakk>
   1.549 +  \<Longrightarrow> mcont lub ord Sup op \<le> (\<lambda>x. f x (t x))"
   1.550 +unfolding mcont_def by(blast intro: transp_le monotone2monotone cont_apply)
   1.551 +
   1.552 +lemma mcont2mcont:
   1.553 +  "\<lbrakk>mcont lub' ord' Sup op \<le> (\<lambda>x. f x); mcont lub ord lub' ord' (\<lambda>x. t x)\<rbrakk> 
   1.554 +  \<Longrightarrow> mcont lub ord Sup op \<le> (\<lambda>x. f (t x))"
   1.555 +by(rule mcont2mcont'[OF _ mcont_const]) 
   1.556 +
   1.557 +context
   1.558 +  fixes ord :: "'b \<Rightarrow> 'b \<Rightarrow> bool" (infix "\<sqsubseteq>" 60) 
   1.559 +  and lub :: "'b set \<Rightarrow> 'b" ("\<Or>_" [900] 900)
   1.560 +begin
   1.561 +
   1.562 +lemma cont_fun_lub_Sup:
   1.563 +  assumes chainM: "Complete_Partial_Order.chain (fun_ord op \<le>) M"
   1.564 +  and mcont [rule_format]: "\<forall>f\<in>M. mcont lub op \<sqsubseteq> Sup op \<le> f"
   1.565 +  shows "cont lub op \<sqsubseteq> Sup op \<le> (fun_lub Sup M)"
   1.566 +proof(rule contI)
   1.567 +  fix Y
   1.568 +  assume chain: "Complete_Partial_Order.chain op \<sqsubseteq> Y"
   1.569 +    and Y: "Y \<noteq> {}"
   1.570 +  from swap_Sup[OF chain chainM mcont[THEN mcont_mono]]
   1.571 +  show "fun_lub Sup M (\<Or>Y) = \<Squnion>(fun_lub Sup M ` Y)"
   1.572 +    by(simp add: mcont_contD[OF mcont chain Y] fun_lub_apply cong: image_cong)
   1.573 +qed
   1.574 +
   1.575 +lemma mcont_fun_lub_Sup:
   1.576 +  "\<lbrakk> Complete_Partial_Order.chain (fun_ord op \<le>) M;
   1.577 +    \<forall>f\<in>M. mcont lub ord Sup op \<le> f \<rbrakk>
   1.578 +  \<Longrightarrow> mcont lub op \<sqsubseteq> Sup op \<le> (fun_lub Sup M)"
   1.579 +by(simp add: mcont_def cont_fun_lub_Sup mono_lub)
   1.580 +
   1.581 +lemma iterates_mcont:
   1.582 +  assumes f: "f \<in> ccpo.iterates (fun_lub Sup) (fun_ord op \<le>) F"
   1.583 +  and mono: "\<And>f. mcont lub op \<sqsubseteq> Sup op \<le> f \<Longrightarrow> mcont lub op \<sqsubseteq> Sup op \<le> (F f)"
   1.584 +  shows "mcont lub op \<sqsubseteq> Sup op \<le> f"
   1.585 +using f
   1.586 +by(induction rule: ccpo.iterates.induct[OF ccpo_fun, consumes 1, case_names step Sup])(blast intro: mono mcont_fun_lub_Sup)+
   1.587 +
   1.588 +lemma fixp_preserves_mcont:
   1.589 +  assumes mono: "\<And>x. monotone (fun_ord op \<le>) op \<le> (\<lambda>f. F f x)"
   1.590 +  and mcont: "\<And>f. mcont lub op \<sqsubseteq> Sup op \<le> f \<Longrightarrow> mcont lub op \<sqsubseteq> Sup op \<le> (F f)"
   1.591 +  shows "mcont lub op \<sqsubseteq> Sup op \<le> (ccpo.fixp (fun_lub Sup) (fun_ord op \<le>) F)"
   1.592 +  (is "mcont _ _ _ _ ?fixp")
   1.593 +unfolding mcont_def
   1.594 +proof(intro conjI monotoneI contI)
   1.595 +  have mono: "monotone (fun_ord op \<le>) (fun_ord op \<le>) F"
   1.596 +    by(rule monotoneI)(auto simp add: fun_ord_def intro: monotoneD[OF mono])
   1.597 +  let ?iter = "ccpo.iterates (fun_lub Sup) (fun_ord op \<le>) F"
   1.598 +  have chain: "\<And>x. Complete_Partial_Order.chain op \<le> ((\<lambda>f. f x) ` ?iter)"
   1.599 +    by(rule chain_imageI[OF ccpo.chain_iterates[OF ccpo_fun mono]])(simp add: fun_ord_def)
   1.600 +
   1.601 +  {
   1.602 +    fix x y
   1.603 +    assume "x \<sqsubseteq> y"
   1.604 +    show "?fixp x \<le> ?fixp y"
   1.605 +      unfolding ccpo.fixp_def[OF ccpo_fun] fun_lub_apply using chain
   1.606 +    proof(rule ccpo_Sup_least)
   1.607 +      fix x'
   1.608 +      assume "x' \<in> (\<lambda>f. f x) ` ?iter"
   1.609 +      then obtain f where "f \<in> ?iter" "x' = f x" by blast note this(2)
   1.610 +      also from _ `x \<sqsubseteq> y` have "f x \<le> f y"
   1.611 +        by(rule mcont_monoD[OF iterates_mcont[OF `f \<in> ?iter` mcont]])
   1.612 +      also have "f y \<le> \<Squnion>((\<lambda>f. f y) ` ?iter)" using chain
   1.613 +        by(rule ccpo_Sup_upper)(simp add: `f \<in> ?iter`)
   1.614 +      finally show "x' \<le> \<dots>" .
   1.615 +    qed
   1.616 +  next
   1.617 +    fix Y
   1.618 +    assume chain: "Complete_Partial_Order.chain op \<sqsubseteq> Y"
   1.619 +      and Y: "Y \<noteq> {}"
   1.620 +    { fix f
   1.621 +      assume "f \<in> ?iter"
   1.622 +      hence "f (\<Or>Y) = \<Squnion>(f ` Y)"
   1.623 +        using mcont chain Y by(rule mcont_contD[OF iterates_mcont]) }
   1.624 +    moreover have "\<Squnion>((\<lambda>f. \<Squnion>(f ` Y)) ` ?iter) = \<Squnion>((\<lambda>x. \<Squnion>((\<lambda>f. f x) ` ?iter)) ` Y)"
   1.625 +      using chain ccpo.chain_iterates[OF ccpo_fun mono]
   1.626 +      by(rule swap_Sup)(rule mcont_mono[OF iterates_mcont[OF _ mcont]])
   1.627 +    ultimately show "?fixp (\<Or>Y) = \<Squnion>(?fixp ` Y)" unfolding ccpo.fixp_def[OF ccpo_fun]
   1.628 +      by(simp add: fun_lub_apply cong: image_cong)
   1.629 +  }
   1.630 +qed
   1.631 +
   1.632 +end
   1.633 +
   1.634 +context
   1.635 +  fixes F :: "'c \<Rightarrow> 'c" and U :: "'c \<Rightarrow> 'b \<Rightarrow> 'a" and C :: "('b \<Rightarrow> 'a) \<Rightarrow> 'c" and f
   1.636 +  assumes mono: "\<And>x. monotone (fun_ord op \<le>) op \<le> (\<lambda>f. U (F (C f)) x)"
   1.637 +  and eq: "f \<equiv> C (ccpo.fixp (fun_lub Sup) (fun_ord op \<le>) (\<lambda>f. U (F (C f))))"
   1.638 +  and inverse: "\<And>f. U (C f) = f"
   1.639 +begin
   1.640 +
   1.641 +lemma fixp_preserves_mono_uc:
   1.642 +  assumes mono2: "\<And>f. monotone ord op \<le> (U f) \<Longrightarrow> monotone ord op \<le> (U (F f))"
   1.643 +  shows "monotone ord op \<le> (U f)"
   1.644 +using fixp_preserves_mono[OF mono mono2] by(subst eq)(simp add: inverse)
   1.645 +
   1.646 +lemma fixp_preserves_mcont_uc:
   1.647 +  assumes mcont: "\<And>f. mcont lubb ordb Sup op \<le> (U f) \<Longrightarrow> mcont lubb ordb Sup op \<le> (U (F f))"
   1.648 +  shows "mcont lubb ordb Sup op \<le> (U f)"
   1.649 +using fixp_preserves_mcont[OF mono mcont] by(subst eq)(simp add: inverse)
   1.650 +
   1.651 +end
   1.652 +
   1.653 +lemmas fixp_preserves_mono1 = fixp_preserves_mono_uc[of "\<lambda>x. x" _ "\<lambda>x. x", OF _ _ refl]
   1.654 +lemmas fixp_preserves_mono2 =
   1.655 +  fixp_preserves_mono_uc[of "case_prod" _ "curry", unfolded case_prod_curry curry_case_prod, OF _ _ refl]
   1.656 +lemmas fixp_preserves_mono3 =
   1.657 +  fixp_preserves_mono_uc[of "\<lambda>f. case_prod (case_prod f)" _ "\<lambda>f. curry (curry f)", unfolded case_prod_curry curry_case_prod, OF _ _ refl]
   1.658 +lemmas fixp_preserves_mono4 =
   1.659 +  fixp_preserves_mono_uc[of "\<lambda>f. case_prod (case_prod (case_prod f))" _ "\<lambda>f. curry (curry (curry f))", unfolded case_prod_curry curry_case_prod, OF _ _ refl]
   1.660 +
   1.661 +lemmas fixp_preserves_mcont1 = fixp_preserves_mcont_uc[of "\<lambda>x. x" _ "\<lambda>x. x", OF _ _ refl]
   1.662 +lemmas fixp_preserves_mcont2 =
   1.663 +  fixp_preserves_mcont_uc[of "case_prod" _ "curry", unfolded case_prod_curry curry_case_prod, OF _ _ refl]
   1.664 +lemmas fixp_preserves_mcont3 =
   1.665 +  fixp_preserves_mcont_uc[of "\<lambda>f. case_prod (case_prod f)" _ "\<lambda>f. curry (curry f)", unfolded case_prod_curry curry_case_prod, OF _ _ refl]
   1.666 +lemmas fixp_preserves_mcont4 =
   1.667 +  fixp_preserves_mcont_uc[of "\<lambda>f. case_prod (case_prod (case_prod f))" _ "\<lambda>f. curry (curry (curry f))", unfolded case_prod_curry curry_case_prod, OF _ _ refl]
   1.668 +
   1.669 +end
   1.670 +
   1.671 +lemma (in preorder) monotone_if_bot:
   1.672 +  fixes bot
   1.673 +  assumes mono: "\<And>x y. \<lbrakk> x \<le> y; \<not> (x \<le> bound) \<rbrakk> \<Longrightarrow> ord (f x) (f y)"
   1.674 +  and bot: "\<And>x. \<not> x \<le> bound \<Longrightarrow> ord bot (f x)" "ord bot bot"
   1.675 +  shows "monotone op \<le> ord (\<lambda>x. if x \<le> bound then bot else f x)"
   1.676 +by(rule monotoneI)(auto intro: bot intro: mono order_trans)
   1.677 +
   1.678 +lemma (in ccpo) mcont_if_bot:
   1.679 +  fixes bot and lub ("\<Or>_" [900] 900) and ord (infix "\<sqsubseteq>" 60)
   1.680 +  assumes ccpo: "class.ccpo lub op \<sqsubseteq> lt"
   1.681 +  and mono: "\<And>x y. \<lbrakk> x \<le> y; \<not> x \<le> bound \<rbrakk> \<Longrightarrow> f x \<sqsubseteq> f y"
   1.682 +  and cont: "\<And>Y. \<lbrakk> Complete_Partial_Order.chain op \<le> Y; Y \<noteq> {}; \<And>x. x \<in> Y \<Longrightarrow> \<not> x \<le> bound \<rbrakk> \<Longrightarrow> f (\<Squnion>Y) = \<Or>(f ` Y)"
   1.683 +  and bot: "\<And>x. \<not> x \<le> bound \<Longrightarrow> bot \<sqsubseteq> f x"
   1.684 +  shows "mcont Sup op \<le> lub op \<sqsubseteq> (\<lambda>x. if x \<le> bound then bot else f x)" (is "mcont _ _ _ _ ?g")
   1.685 +proof(intro mcontI contI)
   1.686 +  interpret c: ccpo lub "op \<sqsubseteq>" lt by(fact ccpo)
   1.687 +  show "monotone op \<le> op \<sqsubseteq> ?g" by(rule monotone_if_bot)(simp_all add: mono bot)
   1.688 +
   1.689 +  fix Y
   1.690 +  assume chain: "Complete_Partial_Order.chain op \<le> Y" and Y: "Y \<noteq> {}"
   1.691 +  show "?g (\<Squnion>Y) = \<Or>(?g ` Y)"
   1.692 +  proof(cases "Y \<subseteq> {x. x \<le> bound}")
   1.693 +    case True
   1.694 +    hence "\<Squnion>Y \<le> bound" using chain by(auto intro: ccpo_Sup_least)
   1.695 +    moreover have "Y \<inter> {x. \<not> x \<le> bound} = {}" using True by auto
   1.696 +    ultimately show ?thesis using True Y
   1.697 +      by (auto simp add: image_constant_conv cong del: c.strong_SUP_cong)
   1.698 +  next
   1.699 +    case False
   1.700 +    let ?Y = "Y \<inter> {x. \<not> x \<le> bound}"
   1.701 +    have chain': "Complete_Partial_Order.chain op \<le> ?Y"
   1.702 +      using chain by(rule chain_subset) simp
   1.703 +
   1.704 +    from False obtain y where ybound: "\<not> y \<le> bound" and y: "y \<in> Y" by blast
   1.705 +    hence "\<not> \<Squnion>Y \<le> bound" by (metis ccpo_Sup_upper chain order.trans)
   1.706 +    hence "?g (\<Squnion>Y) = f (\<Squnion>Y)" by simp
   1.707 +    also have "\<Squnion>Y \<le> \<Squnion>?Y" using chain
   1.708 +    proof(rule ccpo_Sup_least)
   1.709 +      fix x
   1.710 +      assume x: "x \<in> Y"
   1.711 +      show "x \<le> \<Squnion>?Y"
   1.712 +      proof(cases "x \<le> bound")
   1.713 +        case True
   1.714 +        with chainD[OF chain x y] have "x \<le> y" using ybound by(auto intro: order_trans)
   1.715 +        thus ?thesis by(rule order_trans)(auto intro: ccpo_Sup_upper[OF chain'] simp add: y ybound)
   1.716 +      qed(auto intro: ccpo_Sup_upper[OF chain'] simp add: x)
   1.717 +    qed
   1.718 +    hence "\<Squnion>Y = \<Squnion>?Y" by(rule antisym)(blast intro: ccpo_Sup_least[OF chain'] ccpo_Sup_upper[OF chain])
   1.719 +    hence "f (\<Squnion>Y) = f (\<Squnion>?Y)" by simp
   1.720 +    also have "f (\<Squnion>?Y) = \<Or>(f ` ?Y)" using chain' by(rule cont)(insert y ybound, auto)
   1.721 +    also have "\<Or>(f ` ?Y) = \<Or>(?g ` Y)"
   1.722 +    proof(cases "Y \<inter> {x. x \<le> bound} = {}")
   1.723 +      case True
   1.724 +      hence "f ` ?Y = ?g ` Y" by auto
   1.725 +      thus ?thesis by(rule arg_cong)
   1.726 +    next
   1.727 +      case False
   1.728 +      have chain'': "Complete_Partial_Order.chain op \<sqsubseteq> (insert bot (f ` ?Y))"
   1.729 +        using chain by(auto intro!: chainI bot dest: chainD intro: mono)
   1.730 +      hence chain''': "Complete_Partial_Order.chain op \<sqsubseteq> (f ` ?Y)" by(rule chain_subset) blast
   1.731 +      have "bot \<sqsubseteq> \<Or>(f ` ?Y)" using y ybound by(blast intro: c.order_trans[OF bot] c.ccpo_Sup_upper[OF chain'''])
   1.732 +      hence "\<Or>(insert bot (f ` ?Y)) \<sqsubseteq> \<Or>(f ` ?Y)" using chain''
   1.733 +        by(auto intro: c.ccpo_Sup_least c.ccpo_Sup_upper[OF chain''']) 
   1.734 +      with _ have "\<dots> = \<Or>(insert bot (f ` ?Y))"
   1.735 +        by(rule c.antisym)(blast intro: c.ccpo_Sup_least[OF chain'''] c.ccpo_Sup_upper[OF chain''])
   1.736 +      also have "insert bot (f ` ?Y) = ?g ` Y" using False by auto
   1.737 +      finally show ?thesis .
   1.738 +    qed
   1.739 +    finally show ?thesis .
   1.740 +  qed
   1.741 +qed
   1.742 +
   1.743 +context partial_function_definitions begin
   1.744 +
   1.745 +lemma mcont_const [cont_intro, simp]:
   1.746 +  "mcont luba orda lub leq (\<lambda>x. c)"
   1.747 +by(rule ccpo.mcont_const)(rule Partial_Function.ccpo[OF partial_function_definitions_axioms])
   1.748 +
   1.749 +lemmas [cont_intro, simp] =
   1.750 +  ccpo.cont_const[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.751 +
   1.752 +lemma mono2mono:
   1.753 +  assumes "monotone ordb leq (\<lambda>y. f y)" "monotone orda ordb (\<lambda>x. t x)"
   1.754 +  shows "monotone orda leq (\<lambda>x. f (t x))"
   1.755 +using assms by(rule monotone2monotone) simp_all
   1.756 +
   1.757 +lemmas mcont2mcont' = ccpo.mcont2mcont'[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.758 +lemmas mcont2mcont = ccpo.mcont2mcont[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.759 +
   1.760 +lemmas fixp_preserves_mono1 = ccpo.fixp_preserves_mono1[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.761 +lemmas fixp_preserves_mono2 = ccpo.fixp_preserves_mono2[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.762 +lemmas fixp_preserves_mono3 = ccpo.fixp_preserves_mono3[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.763 +lemmas fixp_preserves_mono4 = ccpo.fixp_preserves_mono4[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.764 +lemmas fixp_preserves_mcont1 = ccpo.fixp_preserves_mcont1[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.765 +lemmas fixp_preserves_mcont2 = ccpo.fixp_preserves_mcont2[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.766 +lemmas fixp_preserves_mcont3 = ccpo.fixp_preserves_mcont3[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.767 +lemmas fixp_preserves_mcont4 = ccpo.fixp_preserves_mcont4[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.768 +
   1.769 +lemma monotone_if_bot:
   1.770 +  fixes bot
   1.771 +  assumes g: "\<And>x. g x = (if leq x bound then bot else f x)"
   1.772 +  and mono: "\<And>x y. \<lbrakk> leq x y; \<not> leq x bound \<rbrakk> \<Longrightarrow> ord (f x) (f y)"
   1.773 +  and bot: "\<And>x. \<not> leq x bound \<Longrightarrow> ord bot (f x)" "ord bot bot"
   1.774 +  shows "monotone leq ord g"
   1.775 +unfolding g[abs_def] using preorder mono bot by(rule preorder.monotone_if_bot)
   1.776 +
   1.777 +lemma mcont_if_bot:
   1.778 +  fixes bot
   1.779 +  assumes ccpo: "class.ccpo lub' ord (mk_less ord)"
   1.780 +  and bot: "\<And>x. \<not> leq x bound \<Longrightarrow> ord bot (f x)"
   1.781 +  and g: "\<And>x. g x = (if leq x bound then bot else f x)"
   1.782 +  and mono: "\<And>x y. \<lbrakk> leq x y; \<not> leq x bound \<rbrakk> \<Longrightarrow> ord (f x) (f y)"
   1.783 +  and cont: "\<And>Y. \<lbrakk> Complete_Partial_Order.chain leq Y; Y \<noteq> {}; \<And>x. x \<in> Y \<Longrightarrow> \<not> leq x bound \<rbrakk> \<Longrightarrow> f (lub Y) = lub' (f ` Y)"
   1.784 +  shows "mcont lub leq lub' ord g"
   1.785 +unfolding g[abs_def] using ccpo mono cont bot by(rule ccpo.mcont_if_bot[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]])
   1.786 +
   1.787 +end
   1.788 +
   1.789 +subsection {* Admissibility *}
   1.790 +
   1.791 +lemma admissible_subst:
   1.792 +  assumes adm: "ccpo.admissible luba orda (\<lambda>x. P x)"
   1.793 +  and mcont: "mcont lubb ordb luba orda f"
   1.794 +  shows "ccpo.admissible lubb ordb (\<lambda>x. P (f x))"
   1.795 +apply(rule ccpo.admissibleI)
   1.796 +apply(frule (1) mcont_contD[OF mcont])
   1.797 +apply(auto intro: ccpo.admissibleD[OF adm] chain_imageI dest: mcont_monoD[OF mcont])
   1.798 +done
   1.799 +
   1.800 +lemmas [simp, cont_intro] = 
   1.801 +  admissible_all
   1.802 +  admissible_ball
   1.803 +  admissible_const
   1.804 +  admissible_conj
   1.805 +
   1.806 +lemma admissible_disj' [simp, cont_intro]:
   1.807 +  "\<lbrakk> class.ccpo lub ord (mk_less ord); ccpo.admissible lub ord P; ccpo.admissible lub ord Q \<rbrakk>
   1.808 +  \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. P x \<or> Q x)"
   1.809 +by(rule ccpo.admissible_disj)
   1.810 +
   1.811 +lemma admissible_imp' [cont_intro]:
   1.812 +  "\<lbrakk> class.ccpo lub ord (mk_less ord);
   1.813 +     ccpo.admissible lub ord (\<lambda>x. \<not> P x);
   1.814 +     ccpo.admissible lub ord (\<lambda>x. Q x) \<rbrakk>
   1.815 +  \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. P x \<longrightarrow> Q x)"
   1.816 +unfolding imp_conv_disj by(rule ccpo.admissible_disj)
   1.817 +
   1.818 +lemma admissible_imp [cont_intro]:
   1.819 +  "(Q \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. P x))
   1.820 +  \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. Q \<longrightarrow> P x)"
   1.821 +by(rule ccpo.admissibleI)(auto dest: ccpo.admissibleD)
   1.822 +
   1.823 +lemma admissible_not_mem' [THEN admissible_subst, cont_intro, simp]:
   1.824 +  shows admissible_not_mem: "ccpo.admissible Union op \<subseteq> (\<lambda>A. x \<notin> A)"
   1.825 +by(rule ccpo.admissibleI) auto
   1.826 +
   1.827 +lemma admissible_eqI:
   1.828 +  assumes f: "cont luba orda lub ord (\<lambda>x. f x)"
   1.829 +  and g: "cont luba orda lub ord (\<lambda>x. g x)"
   1.830 +  shows "ccpo.admissible luba orda (\<lambda>x. f x = g x)"
   1.831 +apply(rule ccpo.admissibleI)
   1.832 +apply(simp_all add: contD[OF f] contD[OF g] cong: image_cong)
   1.833 +done
   1.834 +
   1.835 +corollary admissible_eq_mcontI [cont_intro]:
   1.836 +  "\<lbrakk> mcont luba orda lub ord (\<lambda>x. f x); 
   1.837 +    mcont luba orda lub ord (\<lambda>x. g x) \<rbrakk>
   1.838 +  \<Longrightarrow> ccpo.admissible luba orda (\<lambda>x. f x = g x)"
   1.839 +by(rule admissible_eqI)(auto simp add: mcont_def)
   1.840 +
   1.841 +lemma admissible_iff [cont_intro, simp]:
   1.842 +  "\<lbrakk> ccpo.admissible lub ord (\<lambda>x. P x \<longrightarrow> Q x); ccpo.admissible lub ord (\<lambda>x. Q x \<longrightarrow> P x) \<rbrakk>
   1.843 +  \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. P x \<longleftrightarrow> Q x)"
   1.844 +by(subst iff_conv_conj_imp)(rule admissible_conj)
   1.845 +
   1.846 +context ccpo begin
   1.847 +
   1.848 +lemma admissible_leI:
   1.849 +  assumes f: "mcont luba orda Sup op \<le> (\<lambda>x. f x)"
   1.850 +  and g: "mcont luba orda Sup op \<le> (\<lambda>x. g x)"
   1.851 +  shows "ccpo.admissible luba orda (\<lambda>x. f x \<le> g x)"
   1.852 +proof(rule ccpo.admissibleI)
   1.853 +  fix A
   1.854 +  assume chain: "Complete_Partial_Order.chain orda A"
   1.855 +    and le: "\<forall>x\<in>A. f x \<le> g x"
   1.856 +    and False: "A \<noteq> {}"
   1.857 +  have "f (luba A) = \<Squnion>(f ` A)" by(simp add: mcont_contD[OF f] chain False)
   1.858 +  also have "\<dots> \<le> \<Squnion>(g ` A)"
   1.859 +  proof(rule ccpo_Sup_least)
   1.860 +    from chain show "Complete_Partial_Order.chain op \<le> (f ` A)"
   1.861 +      by(rule chain_imageI)(rule mcont_monoD[OF f])
   1.862 +    
   1.863 +    fix x
   1.864 +    assume "x \<in> f ` A"
   1.865 +    then obtain y where "y \<in> A" "x = f y" by blast note this(2)
   1.866 +    also have "f y \<le> g y" using le `y \<in> A` by simp
   1.867 +    also have "Complete_Partial_Order.chain op \<le> (g ` A)"
   1.868 +      using chain by(rule chain_imageI)(rule mcont_monoD[OF g])
   1.869 +    hence "g y \<le> \<Squnion>(g ` A)" by(rule ccpo_Sup_upper)(simp add: `y \<in> A`)
   1.870 +    finally show "x \<le> \<dots>" .
   1.871 +  qed
   1.872 +  also have "\<dots> = g (luba A)" by(simp add: mcont_contD[OF g] chain False)
   1.873 +  finally show "f (luba A) \<le> g (luba A)" .
   1.874 +qed
   1.875 +
   1.876 +end
   1.877 +
   1.878 +lemma admissible_leI:
   1.879 +  fixes ord (infix "\<sqsubseteq>" 60) and lub ("\<Or>_" [900] 900)
   1.880 +  assumes "class.ccpo lub op \<sqsubseteq> (mk_less op \<sqsubseteq>)"
   1.881 +  and "mcont luba orda lub op \<sqsubseteq> (\<lambda>x. f x)"
   1.882 +  and "mcont luba orda lub op \<sqsubseteq> (\<lambda>x. g x)"
   1.883 +  shows "ccpo.admissible luba orda (\<lambda>x. f x \<sqsubseteq> g x)"
   1.884 +using assms by(rule ccpo.admissible_leI)
   1.885 +
   1.886 +declare ccpo_class.admissible_leI[cont_intro]
   1.887 +
   1.888 +context ccpo begin
   1.889 +
   1.890 +lemma admissible_not_below: "ccpo.admissible Sup op \<le> (\<lambda>x. \<not> op \<le> x y)"
   1.891 +by(rule ccpo.admissibleI)(simp add: ccpo_Sup_below_iff)
   1.892 +
   1.893 +end
   1.894 +
   1.895 +lemma (in preorder) preorder [cont_intro, simp]: "class.preorder op \<le> (mk_less op \<le>)"
   1.896 +by(unfold_locales)(auto simp add: mk_less_def intro: order_trans)
   1.897 +
   1.898 +context partial_function_definitions begin
   1.899 +
   1.900 +lemmas [cont_intro, simp] =
   1.901 +  admissible_leI[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.902 +  ccpo.admissible_not_below[THEN admissible_subst, OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.903 +
   1.904 +end
   1.905 +
   1.906 +
   1.907 +inductive compact :: "('a set \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool"
   1.908 +  for lub ord x 
   1.909 +where compact:
   1.910 +  "\<lbrakk> ccpo.admissible lub ord (\<lambda>y. \<not> ord x y);
   1.911 +     ccpo.admissible lub ord (\<lambda>y. x \<noteq> y) \<rbrakk>
   1.912 +  \<Longrightarrow> compact lub ord x"
   1.913 +
   1.914 +hide_fact (open) compact
   1.915 +
   1.916 +context ccpo begin
   1.917 +
   1.918 +lemma compactI:
   1.919 +  assumes "ccpo.admissible Sup op \<le> (\<lambda>y. \<not> x \<le> y)"
   1.920 +  shows "compact Sup op \<le> x"
   1.921 +using assms
   1.922 +proof(rule compact.intros)
   1.923 +  have neq: "(\<lambda>y. x \<noteq> y) = (\<lambda>y. \<not> x \<le> y \<or> \<not> y \<le> x)" by(auto)
   1.924 +  show "ccpo.admissible Sup op \<le> (\<lambda>y. x \<noteq> y)"
   1.925 +    by(subst neq)(rule admissible_disj admissible_not_below assms)+
   1.926 +qed
   1.927 +
   1.928 +lemma compact_bot:
   1.929 +  assumes "x = Sup {}"
   1.930 +  shows "compact Sup op \<le> x"
   1.931 +proof(rule compactI)
   1.932 +  show "ccpo.admissible Sup op \<le> (\<lambda>y. \<not> x \<le> y)" using assms
   1.933 +    by(auto intro!: ccpo.admissibleI intro: ccpo_Sup_least chain_empty)
   1.934 +qed
   1.935 +
   1.936 +end
   1.937 +
   1.938 +lemma admissible_compact_neq' [THEN admissible_subst, cont_intro, simp]:
   1.939 +  shows admissible_compact_neq: "compact lub ord k \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. k \<noteq> x)"
   1.940 +by(simp add: compact.simps)
   1.941 +
   1.942 +lemma admissible_neq_compact' [THEN admissible_subst, cont_intro, simp]:
   1.943 +  shows admissible_neq_compact: "compact lub ord k \<Longrightarrow> ccpo.admissible lub ord (\<lambda>x. x \<noteq> k)"
   1.944 +by(subst eq_commute)(rule admissible_compact_neq)
   1.945 +
   1.946 +context partial_function_definitions begin
   1.947 +
   1.948 +lemmas [cont_intro, simp] = ccpo.compact_bot[OF Partial_Function.ccpo[OF partial_function_definitions_axioms]]
   1.949 +
   1.950 +end
   1.951 +
   1.952 +context ccpo begin
   1.953 +
   1.954 +lemma fixp_strong_induct:
   1.955 +  assumes [cont_intro]: "ccpo.admissible Sup op \<le> P"
   1.956 +  and mono: "monotone op \<le> op \<le> f"
   1.957 +  and bot: "P (\<Squnion>{})"
   1.958 +  and step: "\<And>x. \<lbrakk> x \<le> ccpo_class.fixp f; P x \<rbrakk> \<Longrightarrow> P (f x)"
   1.959 +  shows "P (ccpo_class.fixp f)"
   1.960 +proof(rule fixp_induct[where P="\<lambda>x. x \<le> ccpo_class.fixp f \<and> P x", THEN conjunct2])
   1.961 +  note [cont_intro] = admissible_leI
   1.962 +  show "ccpo.admissible Sup op \<le> (\<lambda>x. x \<le> ccpo_class.fixp f \<and> P x)" by simp
   1.963 +next
   1.964 +  show "\<Squnion>{} \<le> ccpo_class.fixp f \<and> P (\<Squnion>{})"
   1.965 +    by(auto simp add: bot intro: ccpo_Sup_least chain_empty)
   1.966 +next
   1.967 +  fix x
   1.968 +  assume "x \<le> ccpo_class.fixp f \<and> P x"
   1.969 +  thus "f x \<le> ccpo_class.fixp f \<and> P (f x)"
   1.970 +    by(subst fixp_unfold[OF mono])(auto dest: monotoneD[OF mono] intro: step)
   1.971 +qed(rule mono)
   1.972 +
   1.973 +end
   1.974 +
   1.975 +context partial_function_definitions begin
   1.976 +
   1.977 +lemma fixp_strong_induct_uc:
   1.978 +  fixes F :: "'c \<Rightarrow> 'c"
   1.979 +    and U :: "'c \<Rightarrow> 'b \<Rightarrow> 'a"
   1.980 +    and C :: "('b \<Rightarrow> 'a) \<Rightarrow> 'c"
   1.981 +    and P :: "('b \<Rightarrow> 'a) \<Rightarrow> bool"
   1.982 +  assumes mono: "\<And>x. mono_body (\<lambda>f. U (F (C f)) x)"
   1.983 +    and eq: "f \<equiv> C (fixp_fun (\<lambda>f. U (F (C f))))"
   1.984 +    and inverse: "\<And>f. U (C f) = f"
   1.985 +    and adm: "ccpo.admissible lub_fun le_fun P"
   1.986 +    and bot: "P (\<lambda>_. lub {})"
   1.987 +    and step: "\<And>f'. \<lbrakk> P (U f'); le_fun (U f') (U f) \<rbrakk> \<Longrightarrow> P (U (F f'))"
   1.988 +  shows "P (U f)"
   1.989 +unfolding eq inverse
   1.990 +apply (rule ccpo.fixp_strong_induct[OF ccpo adm])
   1.991 +apply (insert mono, auto simp: monotone_def fun_ord_def bot fun_lub_def)[2]
   1.992 +apply (rule_tac f'5="C x" in step)
   1.993 +apply (simp_all add: inverse eq)
   1.994 +done
   1.995 +
   1.996 +end
   1.997 +
   1.998 +subsection {* @{term "op ="} as order *}
   1.999 +
  1.1000 +definition lub_singleton :: "('a set \<Rightarrow> 'a) \<Rightarrow> bool"
  1.1001 +where "lub_singleton lub \<longleftrightarrow> (\<forall>a. lub {a} = a)"
  1.1002 +
  1.1003 +definition the_Sup :: "'a set \<Rightarrow> 'a"
  1.1004 +where "the_Sup A = (THE a. a \<in> A)"
  1.1005 +
  1.1006 +lemma lub_singleton_the_Sup [cont_intro, simp]: "lub_singleton the_Sup"
  1.1007 +by(simp add: lub_singleton_def the_Sup_def)
  1.1008 +
  1.1009 +lemma (in ccpo) lub_singleton: "lub_singleton Sup"
  1.1010 +by(simp add: lub_singleton_def)
  1.1011 +
  1.1012 +lemma (in partial_function_definitions) lub_singleton [cont_intro, simp]: "lub_singleton lub"
  1.1013 +by(rule ccpo.lub_singleton)(rule Partial_Function.ccpo[OF partial_function_definitions_axioms])
  1.1014 +
  1.1015 +lemma preorder_eq [cont_intro, simp]:
  1.1016 +  "class.preorder op = (mk_less op =)"
  1.1017 +by(unfold_locales)(simp_all add: mk_less_def)
  1.1018 +
  1.1019 +lemma monotone_eqI [cont_intro]:
  1.1020 +  assumes "class.preorder ord (mk_less ord)"
  1.1021 +  shows "monotone op = ord f"
  1.1022 +proof -
  1.1023 +  interpret preorder ord "mk_less ord" by fact
  1.1024 +  show ?thesis by(simp add: monotone_def)
  1.1025 +qed
  1.1026 +
  1.1027 +lemma cont_eqI [cont_intro]: 
  1.1028 +  fixes f :: "'a \<Rightarrow> 'b"
  1.1029 +  assumes "lub_singleton lub"
  1.1030 +  shows "cont the_Sup op = lub ord f"
  1.1031 +proof(rule contI)
  1.1032 +  fix Y :: "'a set"
  1.1033 +  assume "Complete_Partial_Order.chain op = Y" "Y \<noteq> {}"
  1.1034 +  then obtain a where "Y = {a}" by(auto simp add: chain_def)
  1.1035 +  thus "f (the_Sup Y) = lub (f ` Y)" using assms
  1.1036 +    by(simp add: the_Sup_def lub_singleton_def)
  1.1037 +qed
  1.1038 +
  1.1039 +lemma mcont_eqI [cont_intro, simp]:
  1.1040 +  "\<lbrakk> class.preorder ord (mk_less ord); lub_singleton lub \<rbrakk>
  1.1041 +  \<Longrightarrow> mcont the_Sup op = lub ord f"
  1.1042 +by(simp add: mcont_def cont_eqI monotone_eqI)
  1.1043 +
  1.1044 +subsection {* ccpo for products *}
  1.1045 +
  1.1046 +definition prod_lub :: "('a set \<Rightarrow> 'a) \<Rightarrow> ('b set \<Rightarrow> 'b) \<Rightarrow> ('a \<times> 'b) set \<Rightarrow> 'a \<times> 'b"
  1.1047 +where "prod_lub Sup_a Sup_b Y = (Sup_a (fst ` Y), Sup_b (snd ` Y))"
  1.1048 +
  1.1049 +lemma lub_singleton_prod_lub [cont_intro, simp]:
  1.1050 +  "\<lbrakk> lub_singleton luba; lub_singleton lubb \<rbrakk> \<Longrightarrow> lub_singleton (prod_lub luba lubb)"
  1.1051 +by(simp add: lub_singleton_def prod_lub_def)
  1.1052 +
  1.1053 +lemma prod_lub_empty [simp]: "prod_lub luba lubb {} = (luba {}, lubb {})"
  1.1054 +by(simp add: prod_lub_def)
  1.1055 +
  1.1056 +lemma preorder_rel_prodI [cont_intro, simp]:
  1.1057 +  assumes "class.preorder orda (mk_less orda)"
  1.1058 +  and "class.preorder ordb (mk_less ordb)"
  1.1059 +  shows "class.preorder (rel_prod orda ordb) (mk_less (rel_prod orda ordb))"
  1.1060 +proof -
  1.1061 +  interpret a: preorder orda "mk_less orda" by fact
  1.1062 +  interpret b: preorder ordb "mk_less ordb" by fact
  1.1063 +  show ?thesis by(unfold_locales)(auto simp add: mk_less_def intro: a.order_trans b.order_trans)
  1.1064 +qed
  1.1065 +
  1.1066 +lemma order_rel_prodI:
  1.1067 +  assumes a: "class.order orda (mk_less orda)"
  1.1068 +  and b: "class.order ordb (mk_less ordb)"
  1.1069 +  shows "class.order (rel_prod orda ordb) (mk_less (rel_prod orda ordb))"
  1.1070 +  (is "class.order ?ord ?ord'")
  1.1071 +proof(intro class.order.intro class.order_axioms.intro)
  1.1072 +  interpret a: order orda "mk_less orda" by(fact a)
  1.1073 +  interpret b: order ordb "mk_less ordb" by(fact b)
  1.1074 +  show "class.preorder ?ord ?ord'" by(rule preorder_rel_prodI) unfold_locales
  1.1075 +
  1.1076 +  fix x y
  1.1077 +  assume "?ord x y" "?ord y x"
  1.1078 +  thus "x = y" by(cases x y rule: prod.exhaust[case_product prod.exhaust]) auto
  1.1079 +qed
  1.1080 +
  1.1081 +lemma monotone_rel_prodI:
  1.1082 +  assumes mono2: "\<And>a. monotone ordb ordc (\<lambda>b. f (a, b))"
  1.1083 +  and mono1: "\<And>b. monotone orda ordc (\<lambda>a. f (a, b))"
  1.1084 +  and a: "class.preorder orda (mk_less orda)"
  1.1085 +  and b: "class.preorder ordb (mk_less ordb)"
  1.1086 +  and c: "class.preorder ordc (mk_less ordc)"
  1.1087 +  shows "monotone (rel_prod orda ordb) ordc f"
  1.1088 +proof -
  1.1089 +  interpret a: preorder orda "mk_less orda" by(rule a)
  1.1090 +  interpret b: preorder ordb "mk_less ordb" by(rule b)
  1.1091 +  interpret c: preorder ordc "mk_less ordc" by(rule c)
  1.1092 +  show ?thesis using mono2 mono1
  1.1093 +    by(auto 7 2 simp add: monotone_def intro: c.order_trans)
  1.1094 +qed
  1.1095 +
  1.1096 +lemma monotone_rel_prodD1:
  1.1097 +  assumes mono: "monotone (rel_prod orda ordb) ordc f"
  1.1098 +  and preorder: "class.preorder ordb (mk_less ordb)"
  1.1099 +  shows "monotone orda ordc (\<lambda>a. f (a, b))"
  1.1100 +proof -
  1.1101 +  interpret preorder ordb "mk_less ordb" by(rule preorder)
  1.1102 +  show ?thesis using mono by(simp add: monotone_def)
  1.1103 +qed
  1.1104 +
  1.1105 +lemma monotone_rel_prodD2:
  1.1106 +  assumes mono: "monotone (rel_prod orda ordb) ordc f"
  1.1107 +  and preorder: "class.preorder orda (mk_less orda)"
  1.1108 +  shows "monotone ordb ordc (\<lambda>b. f (a, b))"
  1.1109 +proof -
  1.1110 +  interpret preorder orda "mk_less orda" by(rule preorder)
  1.1111 +  show ?thesis using mono by(simp add: monotone_def)
  1.1112 +qed
  1.1113 +
  1.1114 +lemma monotone_case_prodI:
  1.1115 +  "\<lbrakk> \<And>a. monotone ordb ordc (f a); \<And>b. monotone orda ordc (\<lambda>a. f a b);
  1.1116 +    class.preorder orda (mk_less orda); class.preorder ordb (mk_less ordb);
  1.1117 +    class.preorder ordc (mk_less ordc) \<rbrakk>
  1.1118 +  \<Longrightarrow> monotone (rel_prod orda ordb) ordc (case_prod f)"
  1.1119 +by(rule monotone_rel_prodI) simp_all
  1.1120 +
  1.1121 +lemma monotone_case_prodD1:
  1.1122 +  assumes mono: "monotone (rel_prod orda ordb) ordc (case_prod f)"
  1.1123 +  and preorder: "class.preorder ordb (mk_less ordb)"
  1.1124 +  shows "monotone orda ordc (\<lambda>a. f a b)"
  1.1125 +using monotone_rel_prodD1[OF assms] by simp
  1.1126 +
  1.1127 +lemma monotone_case_prodD2:
  1.1128 +  assumes mono: "monotone (rel_prod orda ordb) ordc (case_prod f)"
  1.1129 +  and preorder: "class.preorder orda (mk_less orda)"
  1.1130 +  shows "monotone ordb ordc (f a)"
  1.1131 +using monotone_rel_prodD2[OF assms] by simp
  1.1132 +
  1.1133 +context 
  1.1134 +  fixes orda ordb ordc
  1.1135 +  assumes a: "class.preorder orda (mk_less orda)"
  1.1136 +  and b: "class.preorder ordb (mk_less ordb)"
  1.1137 +  and c: "class.preorder ordc (mk_less ordc)"
  1.1138 +begin
  1.1139 +
  1.1140 +lemma monotone_rel_prod_iff:
  1.1141 +  "monotone (rel_prod orda ordb) ordc f \<longleftrightarrow>
  1.1142 +   (\<forall>a. monotone ordb ordc (\<lambda>b. f (a, b))) \<and> 
  1.1143 +   (\<forall>b. monotone orda ordc (\<lambda>a. f (a, b)))"
  1.1144 +using a b c by(blast intro: monotone_rel_prodI dest: monotone_rel_prodD1 monotone_rel_prodD2)
  1.1145 +
  1.1146 +lemma monotone_case_prod_iff [simp]:
  1.1147 +  "monotone (rel_prod orda ordb) ordc (case_prod f) \<longleftrightarrow>
  1.1148 +   (\<forall>a. monotone ordb ordc (f a)) \<and> (\<forall>b. monotone orda ordc (\<lambda>a. f a b))"
  1.1149 +by(simp add: monotone_rel_prod_iff)
  1.1150 +
  1.1151 +end
  1.1152 +
  1.1153 +lemma monotone_case_prod_apply_iff:
  1.1154 +  "monotone orda ordb (\<lambda>x. (case_prod f x) y) \<longleftrightarrow> monotone orda ordb (case_prod (\<lambda>a b. f a b y))"
  1.1155 +by(simp add: monotone_def)
  1.1156 +
  1.1157 +lemma monotone_case_prod_applyD:
  1.1158 +  "monotone orda ordb (\<lambda>x. (case_prod f x) y)
  1.1159 +  \<Longrightarrow> monotone orda ordb (case_prod (\<lambda>a b. f a b y))"
  1.1160 +by(simp add: monotone_case_prod_apply_iff)
  1.1161 +
  1.1162 +lemma monotone_case_prod_applyI:
  1.1163 +  "monotone orda ordb (case_prod (\<lambda>a b. f a b y))
  1.1164 +  \<Longrightarrow> monotone orda ordb (\<lambda>x. (case_prod f x) y)"
  1.1165 +by(simp add: monotone_case_prod_apply_iff)
  1.1166 +
  1.1167 +
  1.1168 +lemma cont_case_prod_apply_iff:
  1.1169 +  "cont luba orda lubb ordb (\<lambda>x. (case_prod f x) y) \<longleftrightarrow> cont luba orda lubb ordb (case_prod (\<lambda>a b. f a b y))"
  1.1170 +by(simp add: cont_def split_def)
  1.1171 +
  1.1172 +lemma cont_case_prod_applyI:
  1.1173 +  "cont luba orda lubb ordb (case_prod (\<lambda>a b. f a b y))
  1.1174 +  \<Longrightarrow> cont luba orda lubb ordb (\<lambda>x. (case_prod f x) y)"
  1.1175 +by(simp add: cont_case_prod_apply_iff)
  1.1176 +
  1.1177 +lemma cont_case_prod_applyD:
  1.1178 +  "cont luba orda lubb ordb (\<lambda>x. (case_prod f x) y)
  1.1179 +  \<Longrightarrow> cont luba orda lubb ordb (case_prod (\<lambda>a b. f a b y))"
  1.1180 +by(simp add: cont_case_prod_apply_iff)
  1.1181 +
  1.1182 +lemma mcont_case_prod_apply_iff [simp]:
  1.1183 +  "mcont luba orda lubb ordb (\<lambda>x. (case_prod f x) y) \<longleftrightarrow> 
  1.1184 +   mcont luba orda lubb ordb (case_prod (\<lambda>a b. f a b y))"
  1.1185 +by(simp add: mcont_def monotone_case_prod_apply_iff cont_case_prod_apply_iff)
  1.1186 +
  1.1187 +lemma cont_prodD1: 
  1.1188 +  assumes cont: "cont (prod_lub luba lubb) (rel_prod orda ordb) lubc ordc f"
  1.1189 +  and "class.preorder orda (mk_less orda)"
  1.1190 +  and luba: "lub_singleton luba"
  1.1191 +  shows "cont lubb ordb lubc ordc (\<lambda>y. f (x, y))"
  1.1192 +proof(rule contI)
  1.1193 +  interpret preorder orda "mk_less orda" by fact
  1.1194 +
  1.1195 +  fix Y :: "'b set"
  1.1196 +  let ?Y = "{x} \<times> Y"
  1.1197 +  assume "Complete_Partial_Order.chain ordb Y" "Y \<noteq> {}"
  1.1198 +  hence "Complete_Partial_Order.chain (rel_prod orda ordb) ?Y" "?Y \<noteq> {}" 
  1.1199 +    by(simp_all add: chain_def)
  1.1200 +  with cont have "f (prod_lub luba lubb ?Y) = lubc (f ` ?Y)" by(rule contD)
  1.1201 +  moreover have "f ` ?Y = (\<lambda>y. f (x, y)) ` Y" by auto
  1.1202 +  ultimately show "f (x, lubb Y) = lubc ((\<lambda>y. f (x, y)) ` Y)" using luba
  1.1203 +    by(simp add: prod_lub_def `Y \<noteq> {}` lub_singleton_def)
  1.1204 +qed
  1.1205 +
  1.1206 +lemma cont_prodD2: 
  1.1207 +  assumes cont: "cont (prod_lub luba lubb) (rel_prod orda ordb) lubc ordc f"
  1.1208 +  and "class.preorder ordb (mk_less ordb)"
  1.1209 +  and lubb: "lub_singleton lubb"
  1.1210 +  shows "cont luba orda lubc ordc (\<lambda>x. f (x, y))"
  1.1211 +proof(rule contI)
  1.1212 +  interpret preorder ordb "mk_less ordb" by fact
  1.1213 +
  1.1214 +  fix Y
  1.1215 +  assume Y: "Complete_Partial_Order.chain orda Y" "Y \<noteq> {}"
  1.1216 +  let ?Y = "Y \<times> {y}"
  1.1217 +  have "f (luba Y, y) = f (prod_lub luba lubb ?Y)"
  1.1218 +    using lubb by(simp add: prod_lub_def Y lub_singleton_def)
  1.1219 +  also from Y have "Complete_Partial_Order.chain (rel_prod orda ordb) ?Y" "?Y \<noteq> {}"
  1.1220 +    by(simp_all add: chain_def)
  1.1221 +  with cont have "f (prod_lub luba lubb ?Y) = lubc (f ` ?Y)" by(rule contD)
  1.1222 +  also have "f ` ?Y = (\<lambda>x. f (x, y)) ` Y" by auto
  1.1223 +  finally show "f (luba Y, y) = lubc \<dots>" .
  1.1224 +qed
  1.1225 +
  1.1226 +lemma cont_case_prodD1:
  1.1227 +  assumes "cont (prod_lub luba lubb) (rel_prod orda ordb) lubc ordc (case_prod f)"
  1.1228 +  and "class.preorder orda (mk_less orda)"
  1.1229 +  and "lub_singleton luba"
  1.1230 +  shows "cont lubb ordb lubc ordc (f x)"
  1.1231 +using cont_prodD1[OF assms] by simp
  1.1232 +
  1.1233 +lemma cont_case_prodD2:
  1.1234 +  assumes "cont (prod_lub luba lubb) (rel_prod orda ordb) lubc ordc (case_prod f)"
  1.1235 +  and "class.preorder ordb (mk_less ordb)"
  1.1236 +  and "lub_singleton lubb"
  1.1237 +  shows "cont luba orda lubc ordc (\<lambda>x. f x y)"
  1.1238 +using cont_prodD2[OF assms] by simp
  1.1239 +
  1.1240 +context ccpo begin
  1.1241 +
  1.1242 +lemma cont_prodI: 
  1.1243 +  assumes mono: "monotone (rel_prod orda ordb) op \<le> f"
  1.1244 +  and cont1: "\<And>x. cont lubb ordb Sup op \<le> (\<lambda>y. f (x, y))"
  1.1245 +  and cont2: "\<And>y. cont luba orda Sup op \<le> (\<lambda>x. f (x, y))"
  1.1246 +  and "class.preorder orda (mk_less orda)"
  1.1247 +  and "class.preorder ordb (mk_less ordb)"
  1.1248 +  shows "cont (prod_lub luba lubb) (rel_prod orda ordb) Sup op \<le> f"
  1.1249 +proof(rule contI)
  1.1250 +  interpret a: preorder orda "mk_less orda" by fact 
  1.1251 +  interpret b: preorder ordb "mk_less ordb" by fact
  1.1252 +  
  1.1253 +  fix Y
  1.1254 +  assume chain: "Complete_Partial_Order.chain (rel_prod orda ordb) Y"
  1.1255 +    and "Y \<noteq> {}"
  1.1256 +  have "f (prod_lub luba lubb Y) = f (luba (fst ` Y), lubb (snd ` Y))"
  1.1257 +    by(simp add: prod_lub_def)
  1.1258 +  also from cont2 have "f (luba (fst ` Y), lubb (snd ` Y)) = \<Squnion>((\<lambda>x. f (x, lubb (snd ` Y))) ` fst ` Y)"
  1.1259 +    by(rule contD)(simp_all add: chain_rel_prodD1[OF chain] `Y \<noteq> {}`)
  1.1260 +  also from cont1 have "\<And>x. f (x, lubb (snd ` Y)) = \<Squnion>((\<lambda>y. f (x, y)) ` snd ` Y)"
  1.1261 +    by(rule contD)(simp_all add: chain_rel_prodD2[OF chain] `Y \<noteq> {}`)
  1.1262 +  hence "\<Squnion>((\<lambda>x. f (x, lubb (snd ` Y))) ` fst ` Y) = \<Squnion>((\<lambda>x. \<dots> x) ` fst ` Y)" by simp
  1.1263 +  also have "\<dots> = \<Squnion>((\<lambda>x. f (fst x, snd x)) ` Y)"
  1.1264 +    unfolding image_image split_def using chain
  1.1265 +    apply(rule diag_Sup)
  1.1266 +    using monotoneD[OF mono]
  1.1267 +    by(auto intro: monotoneI)
  1.1268 +  finally show "f (prod_lub luba lubb Y) = \<Squnion>(f ` Y)" by simp
  1.1269 +qed
  1.1270 +
  1.1271 +lemma cont_case_prodI:
  1.1272 +  assumes "monotone (rel_prod orda ordb) op \<le> (case_prod f)"
  1.1273 +  and "\<And>x. cont lubb ordb Sup op \<le> (\<lambda>y. f x y)"
  1.1274 +  and "\<And>y. cont luba orda Sup op \<le> (\<lambda>x. f x y)"
  1.1275 +  and "class.preorder orda (mk_less orda)"
  1.1276 +  and "class.preorder ordb (mk_less ordb)"
  1.1277 +  shows "cont (prod_lub luba lubb) (rel_prod orda ordb) Sup op \<le> (case_prod f)"
  1.1278 +by(rule cont_prodI)(simp_all add: assms)
  1.1279 +
  1.1280 +lemma cont_case_prod_iff:
  1.1281 +  "\<lbrakk> monotone (rel_prod orda ordb) op \<le> (case_prod f);
  1.1282 +     class.preorder orda (mk_less orda); lub_singleton luba;
  1.1283 +     class.preorder ordb (mk_less ordb); lub_singleton lubb \<rbrakk>
  1.1284 +  \<Longrightarrow> cont (prod_lub luba lubb) (rel_prod orda ordb) Sup op \<le> (case_prod f) \<longleftrightarrow>
  1.1285 +   (\<forall>x. cont lubb ordb Sup op \<le> (\<lambda>y. f x y)) \<and> (\<forall>y. cont luba orda Sup op \<le> (\<lambda>x. f x y))"
  1.1286 +by(blast dest: cont_case_prodD1 cont_case_prodD2 intro: cont_case_prodI)
  1.1287 +
  1.1288 +end
  1.1289 +
  1.1290 +context partial_function_definitions begin
  1.1291 +
  1.1292 +lemma mono2mono2:
  1.1293 +  assumes f: "monotone (rel_prod ordb ordc) leq (\<lambda>(x, y). f x y)"
  1.1294 +  and t: "monotone orda ordb (\<lambda>x. t x)"
  1.1295 +  and t': "monotone orda ordc (\<lambda>x. t' x)"
  1.1296 +  shows "monotone orda leq (\<lambda>x. f (t x) (t' x))"
  1.1297 +proof(rule monotoneI)
  1.1298 +  fix x y
  1.1299 +  assume "orda x y"
  1.1300 +  hence "rel_prod ordb ordc (t x, t' x) (t y, t' y)"
  1.1301 +    using t t' by(auto dest: monotoneD)
  1.1302 +  from monotoneD[OF f this] show "leq (f (t x) (t' x)) (f (t y) (t' y))" by simp
  1.1303 +qed
  1.1304 +
  1.1305 +lemma cont_case_prodI [cont_intro]:
  1.1306 +  "\<lbrakk> monotone (rel_prod orda ordb) leq (case_prod f);
  1.1307 +    \<And>x. cont lubb ordb lub leq (\<lambda>y. f x y);
  1.1308 +    \<And>y. cont luba orda lub leq (\<lambda>x. f x y);
  1.1309 +    class.preorder orda (mk_less orda);
  1.1310 +    class.preorder ordb (mk_less ordb) \<rbrakk>
  1.1311 +  \<Longrightarrow> cont (prod_lub luba lubb) (rel_prod orda ordb) lub leq (case_prod f)"
  1.1312 +by(rule ccpo.cont_case_prodI)(rule Partial_Function.ccpo[OF partial_function_definitions_axioms])
  1.1313 +
  1.1314 +lemma cont_case_prod_iff:
  1.1315 +  "\<lbrakk> monotone (rel_prod orda ordb) leq (case_prod f);
  1.1316 +     class.preorder orda (mk_less orda); lub_singleton luba;
  1.1317 +     class.preorder ordb (mk_less ordb); lub_singleton lubb \<rbrakk>
  1.1318 +  \<Longrightarrow> cont (prod_lub luba lubb) (rel_prod orda ordb) lub leq (case_prod f) \<longleftrightarrow>
  1.1319 +   (\<forall>x. cont lubb ordb lub leq (\<lambda>y. f x y)) \<and> (\<forall>y. cont luba orda lub leq (\<lambda>x. f x y))"
  1.1320 +by(blast dest: cont_case_prodD1 cont_case_prodD2 intro: cont_case_prodI)
  1.1321 +
  1.1322 +lemma mcont_case_prod_iff [simp]:
  1.1323 +  "\<lbrakk> class.preorder orda (mk_less orda); lub_singleton luba;
  1.1324 +     class.preorder ordb (mk_less ordb); lub_singleton lubb \<rbrakk>
  1.1325 +  \<Longrightarrow> mcont (prod_lub luba lubb) (rel_prod orda ordb) lub leq (case_prod f) \<longleftrightarrow>
  1.1326 +   (\<forall>x. mcont lubb ordb lub leq (\<lambda>y. f x y)) \<and> (\<forall>y. mcont luba orda lub leq (\<lambda>x. f x y))"
  1.1327 +unfolding mcont_def by(auto simp add: cont_case_prod_iff)
  1.1328 +
  1.1329 +end
  1.1330 +
  1.1331 +lemma mono2mono_case_prod [cont_intro]:
  1.1332 +  assumes "\<And>x y. monotone orda ordb (\<lambda>f. pair f x y)"
  1.1333 +  shows "monotone orda ordb (\<lambda>f. case_prod (pair f) x)"
  1.1334 +by(rule monotoneI)(auto split: prod.split dest: monotoneD[OF assms])
  1.1335 +
  1.1336 +subsection {* Complete lattices as ccpo *}
  1.1337 +
  1.1338 +context complete_lattice begin
  1.1339 +
  1.1340 +lemma complete_lattice_ccpo: "class.ccpo Sup op \<le> op <"
  1.1341 +by(unfold_locales)(fast intro: Sup_upper Sup_least)+
  1.1342 +
  1.1343 +lemma complete_lattice_ccpo': "class.ccpo Sup op \<le> (mk_less op \<le>)"
  1.1344 +by(unfold_locales)(auto simp add: mk_less_def intro: Sup_upper Sup_least)
  1.1345 +
  1.1346 +lemma complete_lattice_partial_function_definitions: 
  1.1347 +  "partial_function_definitions op \<le> Sup"
  1.1348 +by(unfold_locales)(auto intro: Sup_least Sup_upper)
  1.1349 +
  1.1350 +lemma complete_lattice_partial_function_definitions_dual:
  1.1351 +  "partial_function_definitions op \<ge> Inf"
  1.1352 +by(unfold_locales)(auto intro: Inf_lower Inf_greatest)
  1.1353 +
  1.1354 +lemmas [cont_intro, simp] =
  1.1355 +  Partial_Function.ccpo[OF complete_lattice_partial_function_definitions]
  1.1356 +  Partial_Function.ccpo[OF complete_lattice_partial_function_definitions_dual]
  1.1357 +
  1.1358 +lemma mono2mono_inf:
  1.1359 +  assumes f: "monotone ord op \<le> (\<lambda>x. f x)" 
  1.1360 +  and g: "monotone ord op \<le> (\<lambda>x. g x)"
  1.1361 +  shows "monotone ord op \<le> (\<lambda>x. f x \<sqinter> g x)"
  1.1362 +by(auto 4 3 dest: monotoneD[OF f] monotoneD[OF g] intro: le_infI1 le_infI2 intro!: monotoneI)
  1.1363 +
  1.1364 +lemma mcont_const [simp]: "mcont lub ord Sup op \<le> (\<lambda>_. c)"
  1.1365 +by(rule ccpo.mcont_const[OF complete_lattice_ccpo])
  1.1366 +
  1.1367 +lemma mono2mono_sup:
  1.1368 +  assumes f: "monotone ord op \<le> (\<lambda>x. f x)"
  1.1369 +  and g: "monotone ord op \<le> (\<lambda>x. g x)"
  1.1370 +  shows "monotone ord op \<le> (\<lambda>x. f x \<squnion> g x)"
  1.1371 +by(auto 4 3 intro!: monotoneI intro: sup.coboundedI1 sup.coboundedI2 dest: monotoneD[OF f] monotoneD[OF g])
  1.1372 +
  1.1373 +lemma Sup_image_sup: 
  1.1374 +  assumes "Y \<noteq> {}"
  1.1375 +  shows "\<Squnion>(op \<squnion> x ` Y) = x \<squnion> \<Squnion>Y"
  1.1376 +proof(rule Sup_eqI)
  1.1377 +  fix y
  1.1378 +  assume "y \<in> op \<squnion> x ` Y"
  1.1379 +  then obtain z where "y = x \<squnion> z" and "z \<in> Y" by blast
  1.1380 +  from `z \<in> Y` have "z \<le> \<Squnion>Y" by(rule Sup_upper)
  1.1381 +  with _ show "y \<le> x \<squnion> \<Squnion>Y" unfolding `y = x \<squnion> z` by(rule sup_mono) simp
  1.1382 +next
  1.1383 +  fix y
  1.1384 +  assume upper: "\<And>z. z \<in> op \<squnion> x ` Y \<Longrightarrow> z \<le> y"
  1.1385 +  show "x \<squnion> \<Squnion>Y \<le> y" unfolding Sup_insert[symmetric]
  1.1386 +  proof(rule Sup_least)
  1.1387 +    fix z
  1.1388 +    assume "z \<in> insert x Y"
  1.1389 +    from assms obtain z' where "z' \<in> Y" by blast
  1.1390 +    let ?z = "if z \<in> Y then x \<squnion> z else x \<squnion> z'"
  1.1391 +    have "z \<le> x \<squnion> ?z" using `z' \<in> Y` `z \<in> insert x Y` by auto
  1.1392 +    also have "\<dots> \<le> y" by(rule upper)(auto split: if_split_asm intro: `z' \<in> Y`)
  1.1393 +    finally show "z \<le> y" .
  1.1394 +  qed
  1.1395 +qed
  1.1396 +
  1.1397 +lemma mcont_sup1: "mcont Sup op \<le> Sup op \<le> (\<lambda>y. x \<squnion> y)"
  1.1398 +by(auto 4 3 simp add: mcont_def sup.coboundedI1 sup.coboundedI2 intro!: monotoneI contI intro: Sup_image_sup[symmetric])
  1.1399 +
  1.1400 +lemma mcont_sup2: "mcont Sup op \<le> Sup op \<le> (\<lambda>x. x \<squnion> y)"
  1.1401 +by(subst sup_commute)(rule mcont_sup1)
  1.1402 +
  1.1403 +lemma mcont2mcont_sup [cont_intro, simp]:
  1.1404 +  "\<lbrakk> mcont lub ord Sup op \<le> (\<lambda>x. f x);
  1.1405 +     mcont lub ord Sup op \<le> (\<lambda>x. g x) \<rbrakk>
  1.1406 +  \<Longrightarrow> mcont lub ord Sup op \<le> (\<lambda>x. f x \<squnion> g x)"
  1.1407 +by(best intro: ccpo.mcont2mcont'[OF complete_lattice_ccpo] mcont_sup1 mcont_sup2 ccpo.mcont_const[OF complete_lattice_ccpo])
  1.1408 +
  1.1409 +end
  1.1410 +
  1.1411 +lemmas [cont_intro] = admissible_leI[OF complete_lattice_ccpo']
  1.1412 +
  1.1413 +context complete_distrib_lattice begin
  1.1414 +
  1.1415 +lemma mcont_inf1: "mcont Sup op \<le> Sup op \<le> (\<lambda>y. x \<sqinter> y)"
  1.1416 +by(auto intro: monotoneI contI simp add: le_infI2 inf_Sup mcont_def)
  1.1417 +
  1.1418 +lemma mcont_inf2: "mcont Sup op \<le> Sup op \<le> (\<lambda>x. x \<sqinter> y)"
  1.1419 +by(auto intro: monotoneI contI simp add: le_infI1 Sup_inf mcont_def)
  1.1420 +
  1.1421 +lemma mcont2mcont_inf [cont_intro, simp]:
  1.1422 +  "\<lbrakk> mcont lub ord Sup op \<le> (\<lambda>x. f x);
  1.1423 +    mcont lub ord Sup op \<le> (\<lambda>x. g x) \<rbrakk>
  1.1424 +  \<Longrightarrow> mcont lub ord Sup op \<le> (\<lambda>x. f x \<sqinter> g x)"
  1.1425 +by(best intro: ccpo.mcont2mcont'[OF complete_lattice_ccpo] mcont_inf1 mcont_inf2 ccpo.mcont_const[OF complete_lattice_ccpo])
  1.1426 +
  1.1427 +end
  1.1428 +
  1.1429 +interpretation lfp: partial_function_definitions "op \<le> :: _ :: complete_lattice \<Rightarrow> _" Sup
  1.1430 +by(rule complete_lattice_partial_function_definitions)
  1.1431 +
  1.1432 +declaration {* Partial_Function.init "lfp" @{term lfp.fixp_fun} @{term lfp.mono_body}
  1.1433 +  @{thm lfp.fixp_rule_uc} @{thm lfp.fixp_induct_uc} NONE *}
  1.1434 +
  1.1435 +interpretation gfp: partial_function_definitions "op \<ge> :: _ :: complete_lattice \<Rightarrow> _" Inf
  1.1436 +by(rule complete_lattice_partial_function_definitions_dual)
  1.1437 +
  1.1438 +declaration {* Partial_Function.init "gfp" @{term gfp.fixp_fun} @{term gfp.mono_body}
  1.1439 +  @{thm gfp.fixp_rule_uc} @{thm gfp.fixp_induct_uc} NONE *}
  1.1440 +
  1.1441 +lemma insert_mono [partial_function_mono]:
  1.1442 +   "monotone (fun_ord op \<subseteq>) op \<subseteq> A \<Longrightarrow> monotone (fun_ord op \<subseteq>) op \<subseteq> (\<lambda>y. insert x (A y))"
  1.1443 +by(rule monotoneI)(auto simp add: fun_ord_def dest: monotoneD)
  1.1444 +
  1.1445 +lemma mono2mono_insert [THEN lfp.mono2mono, cont_intro, simp]:
  1.1446 +  shows monotone_insert: "monotone op \<subseteq> op \<subseteq> (insert x)"
  1.1447 +by(rule monotoneI) blast
  1.1448 +
  1.1449 +lemma mcont2mcont_insert[THEN lfp.mcont2mcont, cont_intro, simp]:
  1.1450 +  shows mcont_insert: "mcont Union op \<subseteq> Union op \<subseteq> (insert x)"
  1.1451 +by(blast intro: mcontI contI monotone_insert)
  1.1452 +
  1.1453 +lemma mono2mono_image [THEN lfp.mono2mono, cont_intro, simp]:
  1.1454 +  shows monotone_image: "monotone op \<subseteq> op \<subseteq> (op ` f)"
  1.1455 +by(rule monotoneI) blast
  1.1456 +
  1.1457 +lemma cont_image: "cont Union op \<subseteq> Union op \<subseteq> (op ` f)"
  1.1458 +by(rule contI)(auto)
  1.1459 +
  1.1460 +lemma mcont2mcont_image [THEN lfp.mcont2mcont, cont_intro, simp]:
  1.1461 +  shows mcont_image: "mcont Union op \<subseteq> Union op \<subseteq> (op ` f)"
  1.1462 +by(blast intro: mcontI monotone_image cont_image)
  1.1463 +
  1.1464 +context complete_lattice begin
  1.1465 +
  1.1466 +lemma monotone_Sup [cont_intro, simp]:
  1.1467 +  "monotone ord op \<subseteq> f \<Longrightarrow> monotone ord op \<le> (\<lambda>x. \<Squnion>f x)"
  1.1468 +by(blast intro: monotoneI Sup_least Sup_upper dest: monotoneD)
  1.1469 +
  1.1470 +lemma cont_Sup:
  1.1471 +  assumes "cont lub ord Union op \<subseteq> f"
  1.1472 +  shows "cont lub ord Sup op \<le> (\<lambda>x. \<Squnion>f x)"
  1.1473 +apply(rule contI)
  1.1474 +apply(simp add: contD[OF assms])
  1.1475 +apply(blast intro: Sup_least Sup_upper order_trans antisym)
  1.1476 +done
  1.1477 +
  1.1478 +lemma mcont_Sup: "mcont lub ord Union op \<subseteq> f \<Longrightarrow> mcont lub ord Sup op \<le> (\<lambda>x. \<Squnion>f x)"
  1.1479 +unfolding mcont_def by(blast intro: monotone_Sup cont_Sup)
  1.1480 +
  1.1481 +lemma monotone_SUP:
  1.1482 +  "\<lbrakk> monotone ord op \<subseteq> f; \<And>y. monotone ord op \<le> (\<lambda>x. g x y) \<rbrakk> \<Longrightarrow> monotone ord op \<le> (\<lambda>x. \<Squnion>y\<in>f x. g x y)"
  1.1483 +by(rule monotoneI)(blast dest: monotoneD intro: Sup_upper order_trans intro!: Sup_least)
  1.1484 +
  1.1485 +lemma monotone_SUP2:
  1.1486 +  "(\<And>y. y \<in> A \<Longrightarrow> monotone ord op \<le> (\<lambda>x. g x y)) \<Longrightarrow> monotone ord op \<le> (\<lambda>x. \<Squnion>y\<in>A. g x y)"
  1.1487 +by(rule monotoneI)(blast intro: Sup_upper order_trans dest: monotoneD intro!: Sup_least)
  1.1488 +
  1.1489 +lemma cont_SUP:
  1.1490 +  assumes f: "mcont lub ord Union op \<subseteq> f"
  1.1491 +  and g: "\<And>y. mcont lub ord Sup op \<le> (\<lambda>x. g x y)"
  1.1492 +  shows "cont lub ord Sup op \<le> (\<lambda>x. \<Squnion>y\<in>f x. g x y)"
  1.1493 +proof(rule contI)
  1.1494 +  fix Y
  1.1495 +  assume chain: "Complete_Partial_Order.chain ord Y"
  1.1496 +    and Y: "Y \<noteq> {}"
  1.1497 +  show "\<Squnion>(g (lub Y) ` f (lub Y)) = \<Squnion>((\<lambda>x. \<Squnion>(g x ` f x)) ` Y)" (is "?lhs = ?rhs")
  1.1498 +  proof(rule antisym)
  1.1499 +    show "?lhs \<le> ?rhs"
  1.1500 +    proof(rule Sup_least)
  1.1501 +      fix x
  1.1502 +      assume "x \<in> g (lub Y) ` f (lub Y)"
  1.1503 +      with mcont_contD[OF f chain Y] mcont_contD[OF g chain Y]
  1.1504 +      obtain y z where "y \<in> Y" "z \<in> f y"
  1.1505 +        and x: "x = \<Squnion>((\<lambda>x. g x z) ` Y)" by auto
  1.1506 +      show "x \<le> ?rhs" unfolding x
  1.1507 +      proof(rule Sup_least)
  1.1508 +        fix u
  1.1509 +        assume "u \<in> (\<lambda>x. g x z) ` Y"
  1.1510 +        then obtain y' where "u = g y' z" "y' \<in> Y" by auto
  1.1511 +        from chain `y \<in> Y` `y' \<in> Y` have "ord y y' \<or> ord y' y" by(rule chainD)
  1.1512 +        thus "u \<le> ?rhs"
  1.1513 +        proof
  1.1514 +          note `u = g y' z` also
  1.1515 +          assume "ord y y'"
  1.1516 +          with f have "f y \<subseteq> f y'" by(rule mcont_monoD)
  1.1517 +          with `z \<in> f y`
  1.1518 +          have "g y' z \<le> \<Squnion>(g y' ` f y')" by(auto intro: Sup_upper)
  1.1519 +          also have "\<dots> \<le> ?rhs" using `y' \<in> Y` by(auto intro: Sup_upper)
  1.1520 +          finally show ?thesis .
  1.1521 +        next
  1.1522 +          note `u = g y' z` also
  1.1523 +          assume "ord y' y"
  1.1524 +          with g have "g y' z \<le> g y z" by(rule mcont_monoD)
  1.1525 +          also have "\<dots> \<le> \<Squnion>(g y ` f y)" using `z \<in> f y`
  1.1526 +            by(auto intro: Sup_upper)
  1.1527 +          also have "\<dots> \<le> ?rhs" using `y \<in> Y` by(auto intro: Sup_upper)
  1.1528 +          finally show ?thesis .
  1.1529 +        qed
  1.1530 +      qed
  1.1531 +    qed
  1.1532 +  next
  1.1533 +    show "?rhs \<le> ?lhs"
  1.1534 +    proof(rule Sup_least)
  1.1535 +      fix x
  1.1536 +      assume "x \<in> (\<lambda>x. \<Squnion>(g x ` f x)) ` Y"
  1.1537 +      then obtain y where x: "x = \<Squnion>(g y ` f y)" and "y \<in> Y" by auto
  1.1538 +      show "x \<le> ?lhs" unfolding x
  1.1539 +      proof(rule Sup_least)
  1.1540 +        fix u
  1.1541 +        assume "u \<in> g y ` f y"
  1.1542 +        then obtain z where "u = g y z" "z \<in> f y" by auto
  1.1543 +        note `u = g y z`
  1.1544 +        also have "g y z \<le> \<Squnion>((\<lambda>x. g x z) ` Y)"
  1.1545 +          using `y \<in> Y` by(auto intro: Sup_upper)
  1.1546 +        also have "\<dots> = g (lub Y) z" by(simp add: mcont_contD[OF g chain Y])
  1.1547 +        also have "\<dots> \<le> ?lhs" using `z \<in> f y` `y \<in> Y`
  1.1548 +          by(auto intro: Sup_upper simp add: mcont_contD[OF f chain Y])
  1.1549 +        finally show "u \<le> ?lhs" .
  1.1550 +      qed
  1.1551 +    qed
  1.1552 +  qed
  1.1553 +qed
  1.1554 +
  1.1555 +lemma mcont_SUP [cont_intro, simp]:
  1.1556 +  "\<lbrakk> mcont lub ord Union op \<subseteq> f; \<And>y. mcont lub ord Sup op \<le> (\<lambda>x. g x y) \<rbrakk>
  1.1557 +  \<Longrightarrow> mcont lub ord Sup op \<le> (\<lambda>x. \<Squnion>y\<in>f x. g x y)"
  1.1558 +by(blast intro: mcontI cont_SUP[OF assms] monotone_SUP mcont_mono)
  1.1559 +
  1.1560 +end
  1.1561 +
  1.1562 +lemma admissible_Ball [cont_intro, simp]:
  1.1563 +  "\<lbrakk> \<And>x. ccpo.admissible lub ord (\<lambda>A. P A x);
  1.1564 +     mcont lub ord Union op \<subseteq> f;
  1.1565 +     class.ccpo lub ord (mk_less ord) \<rbrakk>
  1.1566 +  \<Longrightarrow> ccpo.admissible lub ord (\<lambda>A. \<forall>x\<in>f A. P A x)"
  1.1567 +unfolding Ball_def by simp
  1.1568 +
  1.1569 +lemma admissible_Bex'[THEN admissible_subst, cont_intro, simp]:
  1.1570 +  shows admissible_Bex: "ccpo.admissible Union op \<subseteq> (\<lambda>A. \<exists>x\<in>A. P x)"
  1.1571 +by(rule ccpo.admissibleI)(auto)
  1.1572 +
  1.1573 +subsection {* Parallel fixpoint induction *}
  1.1574 +
  1.1575 +context
  1.1576 +  fixes luba :: "'a set \<Rightarrow> 'a"
  1.1577 +  and orda :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
  1.1578 +  and lubb :: "'b set \<Rightarrow> 'b"
  1.1579 +  and ordb :: "'b \<Rightarrow> 'b \<Rightarrow> bool"
  1.1580 +  assumes a: "class.ccpo luba orda (mk_less orda)"
  1.1581 +  and b: "class.ccpo lubb ordb (mk_less ordb)"
  1.1582 +begin
  1.1583 +
  1.1584 +interpretation a: ccpo luba orda "mk_less orda" by(rule a)
  1.1585 +interpretation b: ccpo lubb ordb "mk_less ordb" by(rule b)
  1.1586 +
  1.1587 +lemma ccpo_rel_prodI:
  1.1588 +  "class.ccpo (prod_lub luba lubb) (rel_prod orda ordb) (mk_less (rel_prod orda ordb))"
  1.1589 +  (is "class.ccpo ?lub ?ord ?ord'")
  1.1590 +proof(intro class.ccpo.intro class.ccpo_axioms.intro)
  1.1591 +  show "class.order ?ord ?ord'" by(rule order_rel_prodI) intro_locales
  1.1592 +qed(auto 4 4 simp add: prod_lub_def intro: a.ccpo_Sup_upper b.ccpo_Sup_upper a.ccpo_Sup_least b.ccpo_Sup_least rev_image_eqI dest: chain_rel_prodD1 chain_rel_prodD2)
  1.1593 +
  1.1594 +interpretation ab: ccpo "prod_lub luba lubb" "rel_prod orda ordb" "mk_less (rel_prod orda ordb)"
  1.1595 +by(rule ccpo_rel_prodI)
  1.1596 +
  1.1597 +lemma monotone_map_prod [simp]:
  1.1598 +  "monotone (rel_prod orda ordb) (rel_prod ordc ordd) (map_prod f g) \<longleftrightarrow>
  1.1599 +   monotone orda ordc f \<and> monotone ordb ordd g"
  1.1600 +by(auto simp add: monotone_def)
  1.1601 +
  1.1602 +lemma parallel_fixp_induct:
  1.1603 +  assumes adm: "ccpo.admissible (prod_lub luba lubb) (rel_prod orda ordb) (\<lambda>x. P (fst x) (snd x))"
  1.1604 +  and f: "monotone orda orda f"
  1.1605 +  and g: "monotone ordb ordb g"
  1.1606 +  and bot: "P (luba {}) (lubb {})"
  1.1607 +  and step: "\<And>x y. P x y \<Longrightarrow> P (f x) (g y)"
  1.1608 +  shows "P (ccpo.fixp luba orda f) (ccpo.fixp lubb ordb g)"
  1.1609 +proof -
  1.1610 +  let ?lub = "prod_lub luba lubb"
  1.1611 +    and ?ord = "rel_prod orda ordb"
  1.1612 +    and ?P = "\<lambda>(x, y). P x y"
  1.1613 +  from adm have adm': "ccpo.admissible ?lub ?ord ?P" by(simp add: split_def)
  1.1614 +  hence "?P (ccpo.fixp (prod_lub luba lubb) (rel_prod orda ordb) (map_prod f g))"
  1.1615 +    by(rule ab.fixp_induct)(auto simp add: f g step bot)
  1.1616 +  also have "ccpo.fixp (prod_lub luba lubb) (rel_prod orda ordb) (map_prod f g) = 
  1.1617 +            (ccpo.fixp luba orda f, ccpo.fixp lubb ordb g)" (is "?lhs = (?rhs1, ?rhs2)")
  1.1618 +  proof(rule ab.antisym)
  1.1619 +    have "ccpo.admissible ?lub ?ord (\<lambda>xy. ?ord xy (?rhs1, ?rhs2))"
  1.1620 +      by(rule admissible_leI[OF ccpo_rel_prodI])(auto simp add: prod_lub_def chain_empty intro: a.ccpo_Sup_least b.ccpo_Sup_least)
  1.1621 +    thus "?ord ?lhs (?rhs1, ?rhs2)"
  1.1622 +      by(rule ab.fixp_induct)(auto 4 3 dest: monotoneD[OF f] monotoneD[OF g] simp add: b.fixp_unfold[OF g, symmetric] a.fixp_unfold[OF f, symmetric] f g intro: a.ccpo_Sup_least b.ccpo_Sup_least chain_empty)
  1.1623 +  next
  1.1624 +    have "ccpo.admissible luba orda (\<lambda>x. orda x (fst ?lhs))"
  1.1625 +      by(rule admissible_leI[OF a])(auto intro: a.ccpo_Sup_least simp add: chain_empty)
  1.1626 +    hence "orda ?rhs1 (fst ?lhs)" using f
  1.1627 +    proof(rule a.fixp_induct)
  1.1628 +      fix x
  1.1629 +      assume "orda x (fst ?lhs)"
  1.1630 +      thus "orda (f x) (fst ?lhs)"
  1.1631 +        by(subst ab.fixp_unfold)(auto simp add: f g dest: monotoneD[OF f])
  1.1632 +    qed(auto intro: a.ccpo_Sup_least chain_empty)
  1.1633 +    moreover
  1.1634 +    have "ccpo.admissible lubb ordb (\<lambda>y. ordb y (snd ?lhs))"
  1.1635 +      by(rule admissible_leI[OF b])(auto intro: b.ccpo_Sup_least simp add: chain_empty)
  1.1636 +    hence "ordb ?rhs2 (snd ?lhs)" using g
  1.1637 +    proof(rule b.fixp_induct)
  1.1638 +      fix y
  1.1639 +      assume "ordb y (snd ?lhs)"
  1.1640 +      thus "ordb (g y) (snd ?lhs)"
  1.1641 +        by(subst ab.fixp_unfold)(auto simp add: f g dest: monotoneD[OF g])
  1.1642 +    qed(auto intro: b.ccpo_Sup_least chain_empty)
  1.1643 +    ultimately show "?ord (?rhs1, ?rhs2) ?lhs"
  1.1644 +      by(simp add: rel_prod_conv split_beta)
  1.1645 +  qed
  1.1646 +  finally show ?thesis by simp
  1.1647 +qed
  1.1648 +
  1.1649 +end
  1.1650 +
  1.1651 +lemma parallel_fixp_induct_uc:
  1.1652 +  assumes a: "partial_function_definitions orda luba"
  1.1653 +  and b: "partial_function_definitions ordb lubb"
  1.1654 +  and F: "\<And>x. monotone (fun_ord orda) orda (\<lambda>f. U1 (F (C1 f)) x)"
  1.1655 +  and G: "\<And>y. monotone (fun_ord ordb) ordb (\<lambda>g. U2 (G (C2 g)) y)"
  1.1656 +  and eq1: "f \<equiv> C1 (ccpo.fixp (fun_lub luba) (fun_ord orda) (\<lambda>f. U1 (F (C1 f))))"
  1.1657 +  and eq2: "g \<equiv> C2 (ccpo.fixp (fun_lub lubb) (fun_ord ordb) (\<lambda>g. U2 (G (C2 g))))"
  1.1658 +  and inverse: "\<And>f. U1 (C1 f) = f"
  1.1659 +  and inverse2: "\<And>g. U2 (C2 g) = g"
  1.1660 +  and adm: "ccpo.admissible (prod_lub (fun_lub luba) (fun_lub lubb)) (rel_prod (fun_ord orda) (fun_ord ordb)) (\<lambda>x. P (fst x) (snd x))"
  1.1661 +  and bot: "P (\<lambda>_. luba {}) (\<lambda>_. lubb {})"
  1.1662 +  and step: "\<And>f g. P (U1 f) (U2 g) \<Longrightarrow> P (U1 (F f)) (U2 (G g))"
  1.1663 +  shows "P (U1 f) (U2 g)"
  1.1664 +apply(unfold eq1 eq2 inverse inverse2)
  1.1665 +apply(rule parallel_fixp_induct[OF partial_function_definitions.ccpo[OF a] partial_function_definitions.ccpo[OF b] adm])
  1.1666 +using F apply(simp add: monotone_def fun_ord_def)
  1.1667 +using G apply(simp add: monotone_def fun_ord_def)
  1.1668 +apply(simp add: fun_lub_def bot)
  1.1669 +apply(rule step, simp add: inverse inverse2)
  1.1670 +done
  1.1671 +
  1.1672 +lemmas parallel_fixp_induct_1_1 = parallel_fixp_induct_uc[
  1.1673 +  of _ _ _ _ "\<lambda>x. x" _ "\<lambda>x. x" "\<lambda>x. x" _ "\<lambda>x. x",
  1.1674 +  OF _ _ _ _ _ _ refl refl]
  1.1675 +
  1.1676 +lemmas parallel_fixp_induct_2_2 = parallel_fixp_induct_uc[
  1.1677 +  of _ _ _ _ "case_prod" _ "curry" "case_prod" _ "curry",
  1.1678 +  where P="\<lambda>f g. P (curry f) (curry g)",
  1.1679 +  unfolded case_prod_curry curry_case_prod curry_K,
  1.1680 +  OF _ _ _ _ _ _ refl refl]
  1.1681 +  for P
  1.1682 +
  1.1683 +lemma monotone_fst: "monotone (rel_prod orda ordb) orda fst"
  1.1684 +by(auto intro: monotoneI)
  1.1685 +
  1.1686 +lemma mcont_fst: "mcont (prod_lub luba lubb) (rel_prod orda ordb) luba orda fst"
  1.1687 +by(auto intro!: mcontI monotoneI contI simp add: prod_lub_def)
  1.1688 +
  1.1689 +lemma mcont2mcont_fst [cont_intro, simp]:
  1.1690 +  "mcont lub ord (prod_lub luba lubb) (rel_prod orda ordb) t
  1.1691 +  \<Longrightarrow> mcont lub ord luba orda (\<lambda>x. fst (t x))"
  1.1692 +by(auto intro!: mcontI monotoneI contI dest: mcont_monoD mcont_contD simp add: rel_prod_sel split_beta prod_lub_def image_image)
  1.1693 +
  1.1694 +lemma monotone_snd: "monotone (rel_prod orda ordb) ordb snd"
  1.1695 +by(auto intro: monotoneI)
  1.1696 +
  1.1697 +lemma mcont_snd: "mcont (prod_lub luba lubb) (rel_prod orda ordb) lubb ordb snd"
  1.1698 +by(auto intro!: mcontI monotoneI contI simp add: prod_lub_def)
  1.1699 +
  1.1700 +lemma mcont2mcont_snd [cont_intro, simp]:
  1.1701 +  "mcont lub ord (prod_lub luba lubb) (rel_prod orda ordb) t
  1.1702 +  \<Longrightarrow> mcont lub ord lubb ordb (\<lambda>x. snd (t x))"
  1.1703 +by(auto intro!: mcontI monotoneI contI dest: mcont_monoD mcont_contD simp add: rel_prod_sel split_beta prod_lub_def image_image)
  1.1704 +
  1.1705 +context partial_function_definitions begin
  1.1706 +text \<open>Specialised versions of @{thm [source] mcont_call} for admissibility proofs for parallel fixpoint inductions\<close>
  1.1707 +lemmas mcont_call_fst [cont_intro] = mcont_call[THEN mcont2mcont, OF mcont_fst]
  1.1708 +lemmas mcont_call_snd [cont_intro] = mcont_call[THEN mcont2mcont, OF mcont_snd]
  1.1709 +end
  1.1710 +
  1.1711 +end