it is known as the extended reals, not the infinite reals
authorhoelzl
Fri, 03 Dec 2010 15:25:14 +0100
changeset 412719118eb4eb8dc
parent 41270 81d337539d57
child 41272 ba961a606c67
it is known as the extended reals, not the infinite reals
NEWS
src/HOL/IsaMakefile
src/HOL/Probability/Borel_Space.thy
src/HOL/Probability/Caratheodory.thy
src/HOL/Probability/Complete_Measure.thy
src/HOL/Probability/Information.thy
src/HOL/Probability/Lebesgue_Integration.thy
src/HOL/Probability/Lebesgue_Measure.thy
src/HOL/Probability/Measure.thy
src/HOL/Probability/Positive_Extended_Real.thy
src/HOL/Probability/Positive_Infinite_Real.thy
src/HOL/Probability/Probability_Space.thy
src/HOL/Probability/Product_Measure.thy
src/HOL/Probability/Radon_Nikodym.thy
src/HOL/Probability/ex/Dining_Cryptographers.thy
src/HOL/Probability/ex/Koepf_Duermuth_Countermeasure.thy
     1.1 --- a/NEWS	Mon Dec 06 19:18:02 2010 +0100
     1.2 +++ b/NEWS	Fri Dec 03 15:25:14 2010 +0100
     1.3 @@ -334,8 +334,8 @@
     1.4  of euclidean spaces the real and complex numbers are instantiated to
     1.5  be euclidean_spaces.  INCOMPATIBILITY.
     1.6  
     1.7 -* Probability: Introduced pinfreal as real numbers with infinity. Use
     1.8 -pinfreal as value for measures. Introduce the Radon-Nikodym
     1.9 +* Probability: Introduced pextreal as positive extended real numbers.
    1.10 +Use pextreal as value for measures. Introduce the Radon-Nikodym
    1.11  derivative, product spaces and Fubini's theorem for arbitrary sigma
    1.12  finite measures. Introduces Lebesgue measure based on the integral in
    1.13  Multivariate Analysis.  INCOMPATIBILITY.
     2.1 --- a/src/HOL/IsaMakefile	Mon Dec 06 19:18:02 2010 +0100
     2.2 +++ b/src/HOL/IsaMakefile	Fri Dec 03 15:25:14 2010 +0100
     2.3 @@ -1183,7 +1183,7 @@
     2.4    Probability/ex/Koepf_Duermuth_Countermeasure.thy			\
     2.5    Probability/Information.thy Probability/Lebesgue_Integration.thy	\
     2.6    Probability/Lebesgue_Measure.thy Probability/Measure.thy		\
     2.7 -  Probability/Positive_Infinite_Real.thy				\
     2.8 +  Probability/Positive_Extended_Real.thy				\
     2.9    Probability/Probability_Space.thy Probability/Probability.thy		\
    2.10    Probability/Product_Measure.thy Probability/Radon_Nikodym.thy		\
    2.11    Probability/ROOT.ML Probability/Sigma_Algebra.thy			\
     3.1 --- a/src/HOL/Probability/Borel_Space.thy	Mon Dec 06 19:18:02 2010 +0100
     3.2 +++ b/src/HOL/Probability/Borel_Space.thy	Fri Dec 03 15:25:14 2010 +0100
     3.3 @@ -3,7 +3,7 @@
     3.4  header {*Borel spaces*}
     3.5  
     3.6  theory Borel_Space
     3.7 -  imports Sigma_Algebra Positive_Infinite_Real Multivariate_Analysis
     3.8 +  imports Sigma_Algebra Positive_Extended_Real Multivariate_Analysis
     3.9  begin
    3.10  
    3.11  lemma LIMSEQ_max:
    3.12 @@ -1012,10 +1012,10 @@
    3.13  lemma borel_Real_measurable:
    3.14    "A \<in> sets borel \<Longrightarrow> Real -` A \<in> sets borel"
    3.15  proof (rule borel_measurable_translate)
    3.16 -  fix B :: "pinfreal set" assume "open B"
    3.17 +  fix B :: "pextreal set" assume "open B"
    3.18    then obtain T x where T: "open T" "Real ` (T \<inter> {0..}) = B - {\<omega>}" and
    3.19      x: "\<omega> \<in> B \<Longrightarrow> 0 \<le> x" "\<omega> \<in> B \<Longrightarrow> {Real x <..} \<subseteq> B"
    3.20 -    unfolding open_pinfreal_def by blast
    3.21 +    unfolding open_pextreal_def by blast
    3.22    have "Real -` B = Real -` (B - {\<omega>})" by auto
    3.23    also have "\<dots> = Real -` (Real ` (T \<inter> {0..}))" using T by simp
    3.24    also have "\<dots> = (if 0 \<in> T then T \<union> {.. 0} else T \<inter> {0..})"
    3.25 @@ -1027,7 +1027,7 @@
    3.26  qed simp
    3.27  
    3.28  lemma borel_real_measurable:
    3.29 -  "A \<in> sets borel \<Longrightarrow> (real -` A :: pinfreal set) \<in> sets borel"
    3.30 +  "A \<in> sets borel \<Longrightarrow> (real -` A :: pextreal set) \<in> sets borel"
    3.31  proof (rule borel_measurable_translate)
    3.32    fix B :: "real set" assume "open B"
    3.33    { fix x have "0 < real x \<longleftrightarrow> (\<exists>r>0. x = Real r)" by (cases x) auto }
    3.34 @@ -1035,10 +1035,10 @@
    3.35    have *: "real -` B = (if 0 \<in> B then real -` (B \<inter> {0 <..}) \<union> {0, \<omega>} else real -` (B \<inter> {0 <..}))"
    3.36      by (force simp: Ex_less_real)
    3.37  
    3.38 -  have "open (real -` (B \<inter> {0 <..}) :: pinfreal set)"
    3.39 -    unfolding open_pinfreal_def using `open B`
    3.40 +  have "open (real -` (B \<inter> {0 <..}) :: pextreal set)"
    3.41 +    unfolding open_pextreal_def using `open B`
    3.42      by (auto intro!: open_Int exI[of _ "B \<inter> {0 <..}"] simp: image_iff Ex_less_real)
    3.43 -  then show "(real -` B :: pinfreal set) \<in> sets borel" unfolding * by auto
    3.44 +  then show "(real -` B :: pextreal set) \<in> sets borel" unfolding * by auto
    3.45  qed simp
    3.46  
    3.47  lemma (in sigma_algebra) borel_measurable_Real[intro, simp]:
    3.48 @@ -1046,7 +1046,7 @@
    3.49    shows "(\<lambda>x. Real (f x)) \<in> borel_measurable M"
    3.50    unfolding in_borel_measurable_borel
    3.51  proof safe
    3.52 -  fix S :: "pinfreal set" assume "S \<in> sets borel"
    3.53 +  fix S :: "pextreal set" assume "S \<in> sets borel"
    3.54    from borel_Real_measurable[OF this]
    3.55    have "(Real \<circ> f) -` S \<inter> space M \<in> sets M"
    3.56      using assms
    3.57 @@ -1056,7 +1056,7 @@
    3.58  qed
    3.59  
    3.60  lemma (in sigma_algebra) borel_measurable_real[intro, simp]:
    3.61 -  fixes f :: "'a \<Rightarrow> pinfreal"
    3.62 +  fixes f :: "'a \<Rightarrow> pextreal"
    3.63    assumes "f \<in> borel_measurable M"
    3.64    shows "(\<lambda>x. real (f x)) \<in> borel_measurable M"
    3.65    unfolding in_borel_measurable_borel
    3.66 @@ -1085,7 +1085,7 @@
    3.67      by (simp cong: measurable_cong)
    3.68  qed auto
    3.69  
    3.70 -lemma (in sigma_algebra) borel_measurable_pinfreal_eq_real:
    3.71 +lemma (in sigma_algebra) borel_measurable_pextreal_eq_real:
    3.72    "f \<in> borel_measurable M \<longleftrightarrow>
    3.73      ((\<lambda>x. real (f x)) \<in> borel_measurable M \<and> f -` {\<omega>} \<inter> space M \<in> sets M)"
    3.74  proof safe
    3.75 @@ -1130,8 +1130,8 @@
    3.76    ultimately show "{x\<in>space M. a \<le> f x} \<in> sets M" by auto
    3.77  qed
    3.78  
    3.79 -lemma (in sigma_algebra) less_eq_le_pinfreal_measurable:
    3.80 -  fixes f :: "'a \<Rightarrow> pinfreal"
    3.81 +lemma (in sigma_algebra) less_eq_le_pextreal_measurable:
    3.82 +  fixes f :: "'a \<Rightarrow> pextreal"
    3.83    shows "(\<forall>a. {x\<in>space M. a < f x} \<in> sets M) \<longleftrightarrow> (\<forall>a. {x\<in>space M. a \<le> f x} \<in> sets M)"
    3.84  proof
    3.85    assume a: "\<forall>a. {x\<in>space M. a \<le> f x} \<in> sets M"
    3.86 @@ -1143,9 +1143,9 @@
    3.87        have "{x\<in>space M. a < f x} = (\<Union>i. {x\<in>space M. a + inverse (of_nat (Suc i)) \<le> f x})"
    3.88        proof safe
    3.89          fix x assume "a < f x" and [simp]: "x \<in> space M"
    3.90 -        with ex_pinfreal_inverse_of_nat_Suc_less[of "f x - a"]
    3.91 +        with ex_pextreal_inverse_of_nat_Suc_less[of "f x - a"]
    3.92          obtain n where "a + inverse (of_nat (Suc n)) < f x"
    3.93 -          by (cases "f x", auto simp: pinfreal_minus_order)
    3.94 +          by (cases "f x", auto simp: pextreal_minus_order)
    3.95          then have "a + inverse (of_nat (Suc n)) \<le> f x" by simp
    3.96          then show "x \<in> (\<Union>i. {x \<in> space M. a + inverse (of_nat (Suc i)) \<le> f x})"
    3.97            by auto
    3.98 @@ -1174,7 +1174,7 @@
    3.99          have "{x\<in>space M. f x < a} = (\<Union>i. {x\<in>space M. f x \<le> a - inverse (of_nat (Suc i))})"
   3.100          proof safe
   3.101            fix x assume "f x < a" and [simp]: "x \<in> space M"
   3.102 -          with ex_pinfreal_inverse_of_nat_Suc_less[of "a - f x"]
   3.103 +          with ex_pextreal_inverse_of_nat_Suc_less[of "a - f x"]
   3.104            obtain n where "inverse (of_nat (Suc n)) < a - f x"
   3.105              using preal by (cases "f x") auto
   3.106            then have "f x \<le> a - inverse (of_nat (Suc n)) "
   3.107 @@ -1197,7 +1197,7 @@
   3.108          show "f x = \<omega>"    proof (rule ccontr)
   3.109            assume "f x \<noteq> \<omega>"
   3.110            with real_arch_lt[of "real (f x)"] obtain n where "f x < of_nat n"
   3.111 -            by (auto simp: pinfreal_noteq_omega_Ex)
   3.112 +            by (auto simp: pextreal_noteq_omega_Ex)
   3.113            with *[THEN spec, of n] show False by auto
   3.114          qed
   3.115        qed
   3.116 @@ -1209,8 +1209,8 @@
   3.117    qed
   3.118  qed
   3.119  
   3.120 -lemma (in sigma_algebra) borel_measurable_pinfreal_iff_greater:
   3.121 -  "(f::'a \<Rightarrow> pinfreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. a < f x} \<in> sets M)"
   3.122 +lemma (in sigma_algebra) borel_measurable_pextreal_iff_greater:
   3.123 +  "(f::'a \<Rightarrow> pextreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. a < f x} \<in> sets M)"
   3.124  proof safe
   3.125    fix a assume f: "f \<in> borel_measurable M"
   3.126    have "{x\<in>space M. a < f x} = f -` {a <..} \<inter> space M" by auto
   3.127 @@ -1219,9 +1219,9 @@
   3.128  next
   3.129    assume *: "\<forall>a. {x\<in>space M. a < f x} \<in> sets M"
   3.130    hence **: "\<forall>a. {x\<in>space M. f x < a} \<in> sets M"
   3.131 -    unfolding less_eq_le_pinfreal_measurable
   3.132 +    unfolding less_eq_le_pextreal_measurable
   3.133      unfolding greater_eq_le_measurable .
   3.134 -  show "f \<in> borel_measurable M" unfolding borel_measurable_pinfreal_eq_real borel_measurable_iff_greater
   3.135 +  show "f \<in> borel_measurable M" unfolding borel_measurable_pextreal_eq_real borel_measurable_iff_greater
   3.136    proof safe
   3.137      have "f -` {\<omega>} \<inter> space M = space M - {x\<in>space M. f x < \<omega>}" by auto
   3.138      then show \<omega>: "f -` {\<omega>} \<inter> space M \<in> sets M" using ** by auto
   3.139 @@ -1242,28 +1242,28 @@
   3.140    qed
   3.141  qed
   3.142  
   3.143 -lemma (in sigma_algebra) borel_measurable_pinfreal_iff_less:
   3.144 -  "(f::'a \<Rightarrow> pinfreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. f x < a} \<in> sets M)"
   3.145 -  using borel_measurable_pinfreal_iff_greater unfolding less_eq_le_pinfreal_measurable greater_eq_le_measurable .
   3.146 +lemma (in sigma_algebra) borel_measurable_pextreal_iff_less:
   3.147 +  "(f::'a \<Rightarrow> pextreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. f x < a} \<in> sets M)"
   3.148 +  using borel_measurable_pextreal_iff_greater unfolding less_eq_le_pextreal_measurable greater_eq_le_measurable .
   3.149  
   3.150 -lemma (in sigma_algebra) borel_measurable_pinfreal_iff_le:
   3.151 -  "(f::'a \<Rightarrow> pinfreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. f x \<le> a} \<in> sets M)"
   3.152 -  using borel_measurable_pinfreal_iff_greater unfolding less_eq_ge_measurable .
   3.153 +lemma (in sigma_algebra) borel_measurable_pextreal_iff_le:
   3.154 +  "(f::'a \<Rightarrow> pextreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. f x \<le> a} \<in> sets M)"
   3.155 +  using borel_measurable_pextreal_iff_greater unfolding less_eq_ge_measurable .
   3.156  
   3.157 -lemma (in sigma_algebra) borel_measurable_pinfreal_iff_ge:
   3.158 -  "(f::'a \<Rightarrow> pinfreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. a \<le> f x} \<in> sets M)"
   3.159 -  using borel_measurable_pinfreal_iff_greater unfolding less_eq_le_pinfreal_measurable .
   3.160 +lemma (in sigma_algebra) borel_measurable_pextreal_iff_ge:
   3.161 +  "(f::'a \<Rightarrow> pextreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. {x\<in>space M. a \<le> f x} \<in> sets M)"
   3.162 +  using borel_measurable_pextreal_iff_greater unfolding less_eq_le_pextreal_measurable .
   3.163  
   3.164 -lemma (in sigma_algebra) borel_measurable_pinfreal_eq_const:
   3.165 -  fixes f :: "'a \<Rightarrow> pinfreal" assumes "f \<in> borel_measurable M"
   3.166 +lemma (in sigma_algebra) borel_measurable_pextreal_eq_const:
   3.167 +  fixes f :: "'a \<Rightarrow> pextreal" assumes "f \<in> borel_measurable M"
   3.168    shows "{x\<in>space M. f x = c} \<in> sets M"
   3.169  proof -
   3.170    have "{x\<in>space M. f x = c} = (f -` {c} \<inter> space M)" by auto
   3.171    then show ?thesis using assms by (auto intro!: measurable_sets)
   3.172  qed
   3.173  
   3.174 -lemma (in sigma_algebra) borel_measurable_pinfreal_neq_const:
   3.175 -  fixes f :: "'a \<Rightarrow> pinfreal"
   3.176 +lemma (in sigma_algebra) borel_measurable_pextreal_neq_const:
   3.177 +  fixes f :: "'a \<Rightarrow> pextreal"
   3.178    assumes "f \<in> borel_measurable M"
   3.179    shows "{x\<in>space M. f x \<noteq> c} \<in> sets M"
   3.180  proof -
   3.181 @@ -1271,8 +1271,8 @@
   3.182    then show ?thesis using assms by (auto intro!: measurable_sets)
   3.183  qed
   3.184  
   3.185 -lemma (in sigma_algebra) borel_measurable_pinfreal_less[intro,simp]:
   3.186 -  fixes f g :: "'a \<Rightarrow> pinfreal"
   3.187 +lemma (in sigma_algebra) borel_measurable_pextreal_less[intro,simp]:
   3.188 +  fixes f g :: "'a \<Rightarrow> pextreal"
   3.189    assumes f: "f \<in> borel_measurable M"
   3.190    assumes g: "g \<in> borel_measurable M"
   3.191    shows "{x \<in> space M. f x < g x} \<in> sets M"
   3.192 @@ -1282,17 +1282,17 @@
   3.193      using assms by (auto intro!: borel_measurable_real)
   3.194    from borel_measurable_less[OF this]
   3.195    have "{x \<in> space M. real (f x) < real (g x)} \<in> sets M" .
   3.196 -  moreover have "{x \<in> space M. f x \<noteq> \<omega>} \<in> sets M" using f by (rule borel_measurable_pinfreal_neq_const)
   3.197 -  moreover have "{x \<in> space M. g x = \<omega>} \<in> sets M" using g by (rule borel_measurable_pinfreal_eq_const)
   3.198 -  moreover have "{x \<in> space M. g x \<noteq> \<omega>} \<in> sets M" using g by (rule borel_measurable_pinfreal_neq_const)
   3.199 +  moreover have "{x \<in> space M. f x \<noteq> \<omega>} \<in> sets M" using f by (rule borel_measurable_pextreal_neq_const)
   3.200 +  moreover have "{x \<in> space M. g x = \<omega>} \<in> sets M" using g by (rule borel_measurable_pextreal_eq_const)
   3.201 +  moreover have "{x \<in> space M. g x \<noteq> \<omega>} \<in> sets M" using g by (rule borel_measurable_pextreal_neq_const)
   3.202    moreover have "{x \<in> space M. f x < g x} = ({x \<in> space M. g x = \<omega>} \<inter> {x \<in> space M. f x \<noteq> \<omega>}) \<union>
   3.203      ({x \<in> space M. g x \<noteq> \<omega>} \<inter> {x \<in> space M. f x \<noteq> \<omega>} \<inter> {x \<in> space M. real (f x) < real (g x)})"
   3.204 -    by (auto simp: real_of_pinfreal_strict_mono_iff)
   3.205 +    by (auto simp: real_of_pextreal_strict_mono_iff)
   3.206    ultimately show ?thesis by auto
   3.207  qed
   3.208  
   3.209 -lemma (in sigma_algebra) borel_measurable_pinfreal_le[intro,simp]:
   3.210 -  fixes f :: "'a \<Rightarrow> pinfreal"
   3.211 +lemma (in sigma_algebra) borel_measurable_pextreal_le[intro,simp]:
   3.212 +  fixes f :: "'a \<Rightarrow> pextreal"
   3.213    assumes f: "f \<in> borel_measurable M"
   3.214    assumes g: "g \<in> borel_measurable M"
   3.215    shows "{x \<in> space M. f x \<le> g x} \<in> sets M"
   3.216 @@ -1301,8 +1301,8 @@
   3.217    then show ?thesis using g f by auto
   3.218  qed
   3.219  
   3.220 -lemma (in sigma_algebra) borel_measurable_pinfreal_eq[intro,simp]:
   3.221 -  fixes f :: "'a \<Rightarrow> pinfreal"
   3.222 +lemma (in sigma_algebra) borel_measurable_pextreal_eq[intro,simp]:
   3.223 +  fixes f :: "'a \<Rightarrow> pextreal"
   3.224    assumes f: "f \<in> borel_measurable M"
   3.225    assumes g: "g \<in> borel_measurable M"
   3.226    shows "{w \<in> space M. f w = g w} \<in> sets M"
   3.227 @@ -1311,8 +1311,8 @@
   3.228    then show ?thesis using g f by auto
   3.229  qed
   3.230  
   3.231 -lemma (in sigma_algebra) borel_measurable_pinfreal_neq[intro,simp]:
   3.232 -  fixes f :: "'a \<Rightarrow> pinfreal"
   3.233 +lemma (in sigma_algebra) borel_measurable_pextreal_neq[intro,simp]:
   3.234 +  fixes f :: "'a \<Rightarrow> pextreal"
   3.235    assumes f: "f \<in> borel_measurable M"
   3.236    assumes g: "g \<in> borel_measurable M"
   3.237    shows "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
   3.238 @@ -1321,32 +1321,32 @@
   3.239    thus ?thesis using f g by auto
   3.240  qed
   3.241  
   3.242 -lemma (in sigma_algebra) borel_measurable_pinfreal_add[intro, simp]:
   3.243 -  fixes f :: "'a \<Rightarrow> pinfreal"
   3.244 +lemma (in sigma_algebra) borel_measurable_pextreal_add[intro, simp]:
   3.245 +  fixes f :: "'a \<Rightarrow> pextreal"
   3.246    assumes measure: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
   3.247    shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
   3.248  proof -
   3.249    have *: "(\<lambda>x. f x + g x) =
   3.250       (\<lambda>x. if f x = \<omega> then \<omega> else if g x = \<omega> then \<omega> else Real (real (f x) + real (g x)))"
   3.251 -     by (auto simp: fun_eq_iff pinfreal_noteq_omega_Ex)
   3.252 +     by (auto simp: fun_eq_iff pextreal_noteq_omega_Ex)
   3.253    show ?thesis using assms unfolding *
   3.254      by (auto intro!: measurable_If)
   3.255  qed
   3.256  
   3.257 -lemma (in sigma_algebra) borel_measurable_pinfreal_times[intro, simp]:
   3.258 -  fixes f :: "'a \<Rightarrow> pinfreal" assumes "f \<in> borel_measurable M" "g \<in> borel_measurable M"
   3.259 +lemma (in sigma_algebra) borel_measurable_pextreal_times[intro, simp]:
   3.260 +  fixes f :: "'a \<Rightarrow> pextreal" assumes "f \<in> borel_measurable M" "g \<in> borel_measurable M"
   3.261    shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
   3.262  proof -
   3.263    have *: "(\<lambda>x. f x * g x) =
   3.264       (\<lambda>x. if f x = 0 then 0 else if g x = 0 then 0 else if f x = \<omega> then \<omega> else if g x = \<omega> then \<omega> else
   3.265        Real (real (f x) * real (g x)))"
   3.266 -     by (auto simp: fun_eq_iff pinfreal_noteq_omega_Ex)
   3.267 +     by (auto simp: fun_eq_iff pextreal_noteq_omega_Ex)
   3.268    show ?thesis using assms unfolding *
   3.269      by (auto intro!: measurable_If)
   3.270  qed
   3.271  
   3.272 -lemma (in sigma_algebra) borel_measurable_pinfreal_setsum[simp, intro]:
   3.273 -  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> pinfreal"
   3.274 +lemma (in sigma_algebra) borel_measurable_pextreal_setsum[simp, intro]:
   3.275 +  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> pextreal"
   3.276    assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
   3.277    shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
   3.278  proof cases
   3.279 @@ -1355,56 +1355,56 @@
   3.280      by induct auto
   3.281  qed (simp add: borel_measurable_const)
   3.282  
   3.283 -lemma (in sigma_algebra) borel_measurable_pinfreal_min[simp, intro]:
   3.284 -  fixes f g :: "'a \<Rightarrow> pinfreal"
   3.285 +lemma (in sigma_algebra) borel_measurable_pextreal_min[simp, intro]:
   3.286 +  fixes f g :: "'a \<Rightarrow> pextreal"
   3.287    assumes "f \<in> borel_measurable M"
   3.288    assumes "g \<in> borel_measurable M"
   3.289    shows "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
   3.290    using assms unfolding min_def by (auto intro!: measurable_If)
   3.291  
   3.292 -lemma (in sigma_algebra) borel_measurable_pinfreal_max[simp, intro]:
   3.293 -  fixes f g :: "'a \<Rightarrow> pinfreal"
   3.294 +lemma (in sigma_algebra) borel_measurable_pextreal_max[simp, intro]:
   3.295 +  fixes f g :: "'a \<Rightarrow> pextreal"
   3.296    assumes "f \<in> borel_measurable M"
   3.297    and "g \<in> borel_measurable M"
   3.298    shows "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
   3.299    using assms unfolding max_def by (auto intro!: measurable_If)
   3.300  
   3.301  lemma (in sigma_algebra) borel_measurable_SUP[simp, intro]:
   3.302 -  fixes f :: "'d\<Colon>countable \<Rightarrow> 'a \<Rightarrow> pinfreal"
   3.303 +  fixes f :: "'d\<Colon>countable \<Rightarrow> 'a \<Rightarrow> pextreal"
   3.304    assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
   3.305    shows "(SUP i : A. f i) \<in> borel_measurable M" (is "?sup \<in> borel_measurable M")
   3.306 -  unfolding borel_measurable_pinfreal_iff_greater
   3.307 +  unfolding borel_measurable_pextreal_iff_greater
   3.308  proof safe
   3.309    fix a
   3.310    have "{x\<in>space M. a < ?sup x} = (\<Union>i\<in>A. {x\<in>space M. a < f i x})"
   3.311 -    by (auto simp: less_Sup_iff SUPR_def[where 'a=pinfreal] SUPR_fun_expand[where 'c=pinfreal])
   3.312 +    by (auto simp: less_Sup_iff SUPR_def[where 'a=pextreal] SUPR_fun_expand[where 'c=pextreal])
   3.313    then show "{x\<in>space M. a < ?sup x} \<in> sets M"
   3.314      using assms by auto
   3.315  qed
   3.316  
   3.317  lemma (in sigma_algebra) borel_measurable_INF[simp, intro]:
   3.318 -  fixes f :: "'d :: countable \<Rightarrow> 'a \<Rightarrow> pinfreal"
   3.319 +  fixes f :: "'d :: countable \<Rightarrow> 'a \<Rightarrow> pextreal"
   3.320    assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
   3.321    shows "(INF i : A. f i) \<in> borel_measurable M" (is "?inf \<in> borel_measurable M")
   3.322 -  unfolding borel_measurable_pinfreal_iff_less
   3.323 +  unfolding borel_measurable_pextreal_iff_less
   3.324  proof safe
   3.325    fix a
   3.326    have "{x\<in>space M. ?inf x < a} = (\<Union>i\<in>A. {x\<in>space M. f i x < a})"
   3.327 -    by (auto simp: Inf_less_iff INFI_def[where 'a=pinfreal] INFI_fun_expand)
   3.328 +    by (auto simp: Inf_less_iff INFI_def[where 'a=pextreal] INFI_fun_expand)
   3.329    then show "{x\<in>space M. ?inf x < a} \<in> sets M"
   3.330      using assms by auto
   3.331  qed
   3.332  
   3.333 -lemma (in sigma_algebra) borel_measurable_pinfreal_diff[simp, intro]:
   3.334 -  fixes f g :: "'a \<Rightarrow> pinfreal"
   3.335 +lemma (in sigma_algebra) borel_measurable_pextreal_diff[simp, intro]:
   3.336 +  fixes f g :: "'a \<Rightarrow> pextreal"
   3.337    assumes "f \<in> borel_measurable M"
   3.338    assumes "g \<in> borel_measurable M"
   3.339    shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
   3.340 -  unfolding borel_measurable_pinfreal_iff_greater
   3.341 +  unfolding borel_measurable_pextreal_iff_greater
   3.342  proof safe
   3.343    fix a
   3.344    have "{x \<in> space M. a < f x - g x} = {x \<in> space M. g x + a < f x}"
   3.345 -    by (simp add: pinfreal_less_minus_iff)
   3.346 +    by (simp add: pextreal_less_minus_iff)
   3.347    then show "{x \<in> space M. a < f x - g x} \<in> sets M"
   3.348      using assms by auto
   3.349  qed
     4.1 --- a/src/HOL/Probability/Caratheodory.thy	Mon Dec 06 19:18:02 2010 +0100
     4.2 +++ b/src/HOL/Probability/Caratheodory.thy	Fri Dec 03 15:25:14 2010 +0100
     4.3 @@ -1,14 +1,14 @@
     4.4  header {*Caratheodory Extension Theorem*}
     4.5  
     4.6  theory Caratheodory
     4.7 -  imports Sigma_Algebra Positive_Infinite_Real
     4.8 +  imports Sigma_Algebra Positive_Extended_Real
     4.9  begin
    4.10  
    4.11  text{*From the Hurd/Coble measure theory development, translated by Lawrence Paulson.*}
    4.12  
    4.13  subsection {* Measure Spaces *}
    4.14  
    4.15 -definition "positive f \<longleftrightarrow> f {} = (0::pinfreal)" -- "Positive is enforced by the type"
    4.16 +definition "positive f \<longleftrightarrow> f {} = (0::pextreal)" -- "Positive is enforced by the type"
    4.17  
    4.18  definition
    4.19    additive  where
    4.20 @@ -58,7 +58,7 @@
    4.21       {r . \<exists>A. range A \<subseteq> sets M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i) \<and> (\<Sum>\<^isub>\<infinity> i. f (A i)) = r}"
    4.22  
    4.23  locale measure_space = sigma_algebra +
    4.24 -  fixes \<mu> :: "'a set \<Rightarrow> pinfreal"
    4.25 +  fixes \<mu> :: "'a set \<Rightarrow> pextreal"
    4.26    assumes empty_measure [simp]: "\<mu> {} = 0"
    4.27        and ca: "countably_additive M \<mu>"
    4.28  
    4.29 @@ -148,7 +148,7 @@
    4.30    by (simp add:  lambda_system_def)
    4.31  
    4.32  lemma (in algebra) lambda_system_Compl:
    4.33 -  fixes f:: "'a set \<Rightarrow> pinfreal"
    4.34 +  fixes f:: "'a set \<Rightarrow> pextreal"
    4.35    assumes x: "x \<in> lambda_system M f"
    4.36    shows "space M - x \<in> lambda_system M f"
    4.37    proof -
    4.38 @@ -161,7 +161,7 @@
    4.39    qed
    4.40  
    4.41  lemma (in algebra) lambda_system_Int:
    4.42 -  fixes f:: "'a set \<Rightarrow> pinfreal"
    4.43 +  fixes f:: "'a set \<Rightarrow> pextreal"
    4.44    assumes xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
    4.45    shows "x \<inter> y \<in> lambda_system M f"
    4.46    proof -
    4.47 @@ -196,7 +196,7 @@
    4.48  
    4.49  
    4.50  lemma (in algebra) lambda_system_Un:
    4.51 -  fixes f:: "'a set \<Rightarrow> pinfreal"
    4.52 +  fixes f:: "'a set \<Rightarrow> pextreal"
    4.53    assumes xl: "x \<in> lambda_system M f" and yl: "y \<in> lambda_system M f"
    4.54    shows "x \<union> y \<in> lambda_system M f"
    4.55  proof -
    4.56 @@ -295,7 +295,7 @@
    4.57    by (auto simp add: countably_subadditive_def o_def)
    4.58  
    4.59  lemma (in algebra) increasing_additive_bound:
    4.60 -  fixes A:: "nat \<Rightarrow> 'a set" and  f :: "'a set \<Rightarrow> pinfreal"
    4.61 +  fixes A:: "nat \<Rightarrow> 'a set" and  f :: "'a set \<Rightarrow> pextreal"
    4.62    assumes f: "positive f" and ad: "additive M f"
    4.63        and inc: "increasing M f"
    4.64        and A: "range A \<subseteq> sets M"
    4.65 @@ -315,7 +315,7 @@
    4.66    by (simp add: increasing_def lambda_system_def)
    4.67  
    4.68  lemma (in algebra) lambda_system_strong_sum:
    4.69 -  fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> pinfreal"
    4.70 +  fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> pextreal"
    4.71    assumes f: "positive f" and a: "a \<in> sets M"
    4.72        and A: "range A \<subseteq> lambda_system M f"
    4.73        and disj: "disjoint_family A"
    4.74 @@ -497,7 +497,7 @@
    4.75    assumes posf: "positive f" and ca: "countably_additive M f"
    4.76        and s: "s \<in> sets M"
    4.77    shows "Inf (measure_set M f s) = f s"
    4.78 -  unfolding Inf_pinfreal_def
    4.79 +  unfolding Inf_pextreal_def
    4.80  proof (safe intro!: Greatest_equality)
    4.81    fix z
    4.82    assume z: "z \<in> measure_set M f s"
    4.83 @@ -608,8 +608,8 @@
    4.84    shows "countably_subadditive (| space = space M, sets = Pow (space M) |)
    4.85                    (\<lambda>x. Inf (measure_set M f x))"
    4.86    unfolding countably_subadditive_def o_def
    4.87 -proof (safe, simp, rule pinfreal_le_epsilon)
    4.88 -  fix A :: "nat \<Rightarrow> 'a set" and e :: pinfreal
    4.89 +proof (safe, simp, rule pextreal_le_epsilon)
    4.90 +  fix A :: "nat \<Rightarrow> 'a set" and e :: pextreal
    4.91  
    4.92    let "?outer n" = "Inf (measure_set M f (A n))"
    4.93    assume A: "range A \<subseteq> Pow (space M)"
    4.94 @@ -688,8 +688,8 @@
    4.95      by blast
    4.96    have "Inf (measure_set M f (s\<inter>x)) + Inf (measure_set M f (s-x))
    4.97          \<le> Inf (measure_set M f s)"
    4.98 -    proof (rule pinfreal_le_epsilon)
    4.99 -      fix e :: pinfreal
   4.100 +    proof (rule pextreal_le_epsilon)
   4.101 +      fix e :: pextreal
   4.102        assume e: "0 < e"
   4.103        from inf_measure_close [of f, OF posf e s]
   4.104        obtain A where A: "range A \<subseteq> sets M" and disj: "disjoint_family A"
   4.105 @@ -760,7 +760,7 @@
   4.106  
   4.107  theorem (in algebra) caratheodory:
   4.108    assumes posf: "positive f" and ca: "countably_additive M f"
   4.109 -  shows "\<exists>\<mu> :: 'a set \<Rightarrow> pinfreal. (\<forall>s \<in> sets M. \<mu> s = f s) \<and> measure_space (sigma M) \<mu>"
   4.110 +  shows "\<exists>\<mu> :: 'a set \<Rightarrow> pextreal. (\<forall>s \<in> sets M. \<mu> s = f s) \<and> measure_space (sigma M) \<mu>"
   4.111    proof -
   4.112      have inc: "increasing M f"
   4.113        by (metis additive_increasing ca countably_additive_additive posf)
     5.1 --- a/src/HOL/Probability/Complete_Measure.thy	Mon Dec 06 19:18:02 2010 +0100
     5.2 +++ b/src/HOL/Probability/Complete_Measure.thy	Fri Dec 03 15:25:14 2010 +0100
     5.3 @@ -243,7 +243,7 @@
     5.4  qed
     5.5  
     5.6  lemma (in completeable_measure_space) completion_ex_borel_measurable:
     5.7 -  fixes g :: "'a \<Rightarrow> pinfreal"
     5.8 +  fixes g :: "'a \<Rightarrow> pextreal"
     5.9    assumes g: "g \<in> borel_measurable completion"
    5.10    shows "\<exists>g'\<in>borel_measurable M. (AE x. g x = g' x)"
    5.11  proof -
     6.1 --- a/src/HOL/Probability/Information.thy	Mon Dec 06 19:18:02 2010 +0100
     6.2 +++ b/src/HOL/Probability/Information.thy	Fri Dec 03 15:25:14 2010 +0100
     6.3 @@ -210,7 +210,7 @@
     6.4    have ms: "measure_space M \<nu>" by fact
     6.5    show "(\<Sum>x \<in> space M. log b (real (RN_deriv \<nu> x)) * real (\<nu> {x})) = ?sum"
     6.6      using RN_deriv_finite_measure[OF ms ac]
     6.7 -    by (auto intro!: setsum_cong simp: field_simps real_of_pinfreal_mult[symmetric])
     6.8 +    by (auto intro!: setsum_cong simp: field_simps real_of_pextreal_mult[symmetric])
     6.9  qed
    6.10  
    6.11  lemma (in finite_prob_space) KL_divergence_positive_finite:
    6.12 @@ -285,7 +285,7 @@
    6.13    note jd_commute = this
    6.14  
    6.15    { fix A assume A: "A \<in> sets (sigma (pair_algebra T S))"
    6.16 -    have *: "\<And>x y. indicator ((\<lambda>(x, y). (y, x)) ` A) (x, y) = (indicator A (y, x) :: pinfreal)"
    6.17 +    have *: "\<And>x y. indicator ((\<lambda>(x, y). (y, x)) ` A) (x, y) = (indicator A (y, x) :: pextreal)"
    6.18        unfolding indicator_def by auto
    6.19      have "ST.pair_measure ((\<lambda>(x, y). (y, x)) ` A) = TS.pair_measure A"
    6.20        unfolding ST.pair_measure_def TS.pair_measure_def
    6.21 @@ -361,7 +361,7 @@
    6.22    show ?sum
    6.23      unfolding Let_def mutual_information_def
    6.24      by (subst XY.KL_divergence_eq_finite[OF P_ms finite_variables_absolutely_continuous[OF MX MY]])
    6.25 -       (auto simp add: pair_algebra_def setsum_cartesian_product' real_of_pinfreal_mult[symmetric])
    6.26 +       (auto simp add: pair_algebra_def setsum_cartesian_product' real_of_pextreal_mult[symmetric])
    6.27  
    6.28    show ?positive
    6.29      using XY.KL_divergence_positive_finite[OF P_ps finite_variables_absolutely_continuous[OF MX MY] b_gt_1]
    6.30 @@ -463,7 +463,7 @@
    6.31      by (auto simp: simple_function_def)
    6.32    also have "\<dots> = log b (\<Sum>x\<in>X`space M. if ?d x \<noteq> 0 then 1 else 0)"
    6.33      using distribution_finite[OF `simple_function X`[THEN simple_function_imp_random_variable], simplified]
    6.34 -    by (intro arg_cong[where f="\<lambda>X. log b X"] setsum_cong) (auto simp: real_of_pinfreal_eq_0)
    6.35 +    by (intro arg_cong[where f="\<lambda>X. log b X"] setsum_cong) (auto simp: real_of_pextreal_eq_0)
    6.36    finally show ?thesis
    6.37      using `simple_function X` by (auto simp: setsum_cases real_eq_of_nat simple_function_def)
    6.38  qed
    6.39 @@ -610,14 +610,14 @@
    6.40      then have *: "?XYZ x y z / (?XZ x z * ?YZdZ y z) =
    6.41        (?XYZ x y z / (?X x * ?YZ y z)) / (?XZ x z / (?X x * ?Z z))"
    6.42        using order1(3)
    6.43 -      by (auto simp: real_of_pinfreal_mult[symmetric] real_of_pinfreal_eq_0)
    6.44 +      by (auto simp: real_of_pextreal_mult[symmetric] real_of_pextreal_eq_0)
    6.45      show "?L x y z = ?R x y z"
    6.46      proof cases
    6.47        assume "?XYZ x y z \<noteq> 0"
    6.48        with space b_gt_1 order1 order2 show ?thesis unfolding *
    6.49          by (subst log_divide)
    6.50 -           (auto simp: zero_less_divide_iff zero_less_real_of_pinfreal
    6.51 -                       real_of_pinfreal_eq_0 zero_less_mult_iff)
    6.52 +           (auto simp: zero_less_divide_iff zero_less_real_of_pextreal
    6.53 +                       real_of_pextreal_eq_0 zero_less_mult_iff)
    6.54      qed simp
    6.55    qed
    6.56    also have "\<dots> = (\<Sum>(x, y, z)\<in>?S. ?XYZ x y z * log b (?XYZ x y z / (?X x * ?YZ y z))) -
    6.57 @@ -721,7 +721,7 @@
    6.58    have "- conditional_mutual_information b MX MY MZ X Y Z = - (\<Sum>(x, y, z) \<in> ?M. ?dXYZ {(x, y, z)} *
    6.59      log b (?dXYZ {(x, y, z)} / (?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})))"
    6.60      unfolding conditional_mutual_information_generic_eq[OF assms] neg_equal_iff_equal
    6.61 -    by (intro setsum_cong) (auto intro!: arg_cong[where f="log b"] simp: real_of_pinfreal_mult[symmetric])
    6.62 +    by (intro setsum_cong) (auto intro!: arg_cong[where f="log b"] simp: real_of_pextreal_mult[symmetric])
    6.63    also have "\<dots> \<le> log b (\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z})"
    6.64      unfolding split_beta
    6.65    proof (rule log_setsum_divide)
    6.66 @@ -743,15 +743,15 @@
    6.67      fix x assume "x \<in> ?M"
    6.68      let ?x = "(fst x, fst (snd x), snd (snd x))"
    6.69  
    6.70 -    show "0 \<le> ?dXYZ {?x}" using real_pinfreal_nonneg .
    6.71 +    show "0 \<le> ?dXYZ {?x}" using real_pextreal_nonneg .
    6.72      show "0 \<le> ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
    6.73 -     by (simp add: real_pinfreal_nonneg mult_nonneg_nonneg divide_nonneg_nonneg)
    6.74 +     by (simp add: real_pextreal_nonneg mult_nonneg_nonneg divide_nonneg_nonneg)
    6.75  
    6.76      assume *: "0 < ?dXYZ {?x}"
    6.77      with `x \<in> ?M` show "0 < ?dXZ {(fst x, snd (snd x))} * ?dYZ {(fst (snd x), snd (snd x))} / ?dZ {snd (snd x)}"
    6.78        using finite order
    6.79        by (cases x)
    6.80 -         (auto simp add: zero_less_real_of_pinfreal zero_less_mult_iff zero_less_divide_iff)
    6.81 +         (auto simp add: zero_less_real_of_pextreal zero_less_mult_iff zero_less_divide_iff)
    6.82    qed
    6.83    also have "(\<Sum>(x, y, z) \<in> ?M. ?dXZ {(x, z)} * ?dYZ {(y,z)} / ?dZ {z}) = (\<Sum>z\<in>space MZ. ?dZ {z})"
    6.84      apply (simp add: setsum_cartesian_product')
    6.85 @@ -817,11 +817,11 @@
    6.86      also have "\<dots> = real (?XZ x z) * ?f x x z"
    6.87        using `x \<in> space MX` by (simp add: setsum_cases[OF MX.finite_space])
    6.88      also have "\<dots> = real (?XZ x z) * log b (real (?Z z) / real (?XZ x z))"
    6.89 -      by (auto simp: real_of_pinfreal_mult[symmetric])
    6.90 +      by (auto simp: real_of_pextreal_mult[symmetric])
    6.91      also have "\<dots> = - real (?XZ x z) * log b (real (?XZ x z) / real (?Z z))"
    6.92        using assms[THEN finite_distribution_finite]
    6.93        using finite_distribution_order(6)[OF MX MZ]
    6.94 -      by (auto simp: log_simps field_simps zero_less_mult_iff zero_less_real_of_pinfreal real_of_pinfreal_eq_0)
    6.95 +      by (auto simp: log_simps field_simps zero_less_mult_iff zero_less_real_of_pextreal real_of_pextreal_eq_0)
    6.96      finally have "(\<Sum>x'\<in>space MX. real (?XXZ x x' z) * ?f x x' z) =
    6.97        - real (?XZ x z) * log b (real (?XZ x z) / real (?Z z))" . }
    6.98    note * = this
    6.99 @@ -830,7 +830,7 @@
   6.100      unfolding conditional_entropy_def
   6.101      unfolding conditional_mutual_information_generic_eq[OF MX MX MZ]
   6.102      by (auto simp: setsum_cartesian_product' setsum_negf[symmetric]
   6.103 -                   setsum_commute[of _ "space MZ"] *   simp del: divide_pinfreal_def
   6.104 +                   setsum_commute[of _ "space MZ"] *   simp del: divide_pextreal_def
   6.105               intro!: setsum_cong)
   6.106  qed
   6.107  
   6.108 @@ -853,7 +853,7 @@
   6.109    using finite_distribution_finite[OF finite_random_variable_pairI[OF assms[THEN simple_function_imp_finite_random_variable]]]
   6.110    using finite_distribution_order(5,6)[OF assms[THEN simple_function_imp_finite_random_variable]]
   6.111    using finite_distribution_finite[OF Y[THEN simple_function_imp_finite_random_variable]]
   6.112 -  by (auto simp: setsum_cartesian_product'  setsum_commute[of _ "Y`space M"] setsum_right_distrib real_of_pinfreal_eq_0
   6.113 +  by (auto simp: setsum_cartesian_product'  setsum_commute[of _ "Y`space M"] setsum_right_distrib real_of_pextreal_eq_0
   6.114             intro!: setsum_cong)
   6.115  
   6.116  lemma (in information_space) conditional_entropy_eq_cartesian_product:
   6.117 @@ -880,8 +880,8 @@
   6.118    { fix x z assume "x \<in> X`space M" "z \<in> Z`space M"
   6.119      have "?XZ x z * log b (?XZ x z / (?X x * ?Z z)) =
   6.120            ?XZ x z * log b (?XZ x z / ?Z z) - ?XZ x z * log b (?X x)"
   6.121 -      by (auto simp: log_simps real_of_pinfreal_mult[symmetric] zero_less_mult_iff
   6.122 -                     zero_less_real_of_pinfreal field_simps real_of_pinfreal_eq_0 abs_mult) }
   6.123 +      by (auto simp: log_simps real_of_pextreal_mult[symmetric] zero_less_mult_iff
   6.124 +                     zero_less_real_of_pextreal field_simps real_of_pextreal_eq_0 abs_mult) }
   6.125    note * = this
   6.126    show ?thesis
   6.127      unfolding entropy_eq[OF X] conditional_entropy_eq[OF X Z] mutual_information_eq[OF X Z]
   6.128 @@ -913,8 +913,8 @@
   6.129    { fix x y assume "x \<in> X`space M" "y \<in> Y`space M"
   6.130      have "?XY x y * log b (?XY x y / ?X x) =
   6.131            ?XY x y * log b (?XY x y) - ?XY x y * log b (?X x)"
   6.132 -      by (auto simp: log_simps real_of_pinfreal_mult[symmetric] zero_less_mult_iff
   6.133 -                     zero_less_real_of_pinfreal field_simps real_of_pinfreal_eq_0 abs_mult) }
   6.134 +      by (auto simp: log_simps real_of_pextreal_mult[symmetric] zero_less_mult_iff
   6.135 +                     zero_less_real_of_pextreal field_simps real_of_pextreal_eq_0 abs_mult) }
   6.136    note * = this
   6.137    show ?thesis
   6.138      using setsum_real_joint_distribution_singleton[OF fY fX]
     7.1 --- a/src/HOL/Probability/Lebesgue_Integration.thy	Mon Dec 06 19:18:02 2010 +0100
     7.2 +++ b/src/HOL/Probability/Lebesgue_Integration.thy	Fri Dec 03 15:25:14 2010 +0100
     7.3 @@ -54,7 +54,7 @@
     7.4  qed
     7.5  
     7.6  lemma (in sigma_algebra) simple_function_indicator_representation:
     7.7 -  fixes f ::"'a \<Rightarrow> pinfreal"
     7.8 +  fixes f ::"'a \<Rightarrow> pextreal"
     7.9    assumes f: "simple_function f" and x: "x \<in> space M"
    7.10    shows "f x = (\<Sum>y \<in> f ` space M. y * indicator (f -` {y} \<inter> space M) x)"
    7.11    (is "?l = ?r")
    7.12 @@ -69,7 +69,7 @@
    7.13  qed
    7.14  
    7.15  lemma (in measure_space) simple_function_notspace:
    7.16 -  "simple_function (\<lambda>x. h x * indicator (- space M) x::pinfreal)" (is "simple_function ?h")
    7.17 +  "simple_function (\<lambda>x. h x * indicator (- space M) x::pextreal)" (is "simple_function ?h")
    7.18  proof -
    7.19    have "?h ` space M \<subseteq> {0}" unfolding indicator_def by auto
    7.20    hence [simp, intro]: "finite (?h ` space M)" by (auto intro: finite_subset)
    7.21 @@ -212,7 +212,7 @@
    7.22  qed
    7.23  
    7.24  lemma (in sigma_algebra) borel_measurable_implies_simple_function_sequence:
    7.25 -  fixes u :: "'a \<Rightarrow> pinfreal"
    7.26 +  fixes u :: "'a \<Rightarrow> pextreal"
    7.27    assumes u: "u \<in> borel_measurable M"
    7.28    shows "\<exists>f. (\<forall>i. simple_function (f i) \<and> (\<forall>x\<in>space M. f i x \<noteq> \<omega>)) \<and> f \<up> u"
    7.29  proof -
    7.30 @@ -265,7 +265,7 @@
    7.31      qed simp }
    7.32    note f_upper = this
    7.33  
    7.34 -  let "?g j x" = "of_nat (f x j) / 2^j :: pinfreal"
    7.35 +  let "?g j x" = "of_nat (f x j) / 2^j :: pextreal"
    7.36    show ?thesis unfolding simple_function_def isoton_fun_expand unfolding isoton_def
    7.37    proof (safe intro!: exI[of _ ?g])
    7.38      fix j
    7.39 @@ -350,7 +350,7 @@
    7.40      hence mono: "mono (\<lambda>i. ?g i t)" unfolding mono_iff_le_Suc by auto
    7.41  
    7.42      show "(SUP j. of_nat (f t j) / 2 ^ j) = u t"
    7.43 -    proof (rule pinfreal_SUPI)
    7.44 +    proof (rule pextreal_SUPI)
    7.45        fix j show "of_nat (f t j) / 2 ^ j \<le> u t"
    7.46        proof (rule fI)
    7.47          assume "of_nat j \<le> u t" thus "of_nat (j * 2 ^ j) / 2 ^ j \<le> u t"
    7.48 @@ -362,7 +362,7 @@
    7.49               (auto simp: power_le_zero_eq divide_real_def[symmetric] field_simps zero_le_mult_iff)
    7.50        qed
    7.51      next
    7.52 -      fix y :: pinfreal assume *: "\<And>j. j \<in> UNIV \<Longrightarrow> of_nat (f t j) / 2 ^ j \<le> y"
    7.53 +      fix y :: pextreal assume *: "\<And>j. j \<in> UNIV \<Longrightarrow> of_nat (f t j) / 2 ^ j \<le> y"
    7.54        show "u t \<le> y"
    7.55        proof (cases "u t")
    7.56          case (preal r)
    7.57 @@ -404,7 +404,7 @@
    7.58  qed
    7.59  
    7.60  lemma (in sigma_algebra) borel_measurable_implies_simple_function_sequence':
    7.61 -  fixes u :: "'a \<Rightarrow> pinfreal"
    7.62 +  fixes u :: "'a \<Rightarrow> pextreal"
    7.63    assumes "u \<in> borel_measurable M"
    7.64    obtains (x) f where "f \<up> u" "\<And>i. simple_function (f i)" "\<And>i. \<omega>\<notin>f i`space M"
    7.65  proof -
    7.66 @@ -416,7 +416,7 @@
    7.67  qed
    7.68  
    7.69  lemma (in sigma_algebra) simple_function_eq_borel_measurable:
    7.70 -  fixes f :: "'a \<Rightarrow> pinfreal"
    7.71 +  fixes f :: "'a \<Rightarrow> pextreal"
    7.72    shows "simple_function f \<longleftrightarrow>
    7.73      finite (f`space M) \<and> f \<in> borel_measurable M"
    7.74    using simple_function_borel_measurable[of f]
    7.75 @@ -424,7 +424,7 @@
    7.76    by (fastsimp simp: simple_function_def)
    7.77  
    7.78  lemma (in measure_space) simple_function_restricted:
    7.79 -  fixes f :: "'a \<Rightarrow> pinfreal" assumes "A \<in> sets M"
    7.80 +  fixes f :: "'a \<Rightarrow> pextreal" assumes "A \<in> sets M"
    7.81    shows "sigma_algebra.simple_function (restricted_space A) f \<longleftrightarrow> simple_function (\<lambda>x. f x * indicator A x)"
    7.82      (is "sigma_algebra.simple_function ?R f \<longleftrightarrow> simple_function ?f")
    7.83  proof -
    7.84 @@ -448,7 +448,7 @@
    7.85          using `A \<in> sets M` sets_into_space by (auto intro!: bexI[of _ x])
    7.86      next
    7.87        fix x
    7.88 -      assume "indicator A x \<noteq> (0::pinfreal)"
    7.89 +      assume "indicator A x \<noteq> (0::pextreal)"
    7.90        then have "x \<in> A" by (auto simp: indicator_def split: split_if_asm)
    7.91        moreover assume "x \<in> space M" "\<forall>y\<in>A. ?f x \<noteq> f y"
    7.92        ultimately show "f x = 0" by auto
    7.93 @@ -472,7 +472,7 @@
    7.94    by auto
    7.95  
    7.96  lemma (in sigma_algebra) simple_function_vimage:
    7.97 -  fixes g :: "'a \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
    7.98 +  fixes g :: "'a \<Rightarrow> pextreal" and f :: "'d \<Rightarrow> 'a"
    7.99    assumes g: "simple_function g" and f: "f \<in> S \<rightarrow> space M"
   7.100    shows "sigma_algebra.simple_function (vimage_algebra S f) (\<lambda>x. g (f x))"
   7.101  proof -
   7.102 @@ -751,7 +751,7 @@
   7.103    assume "space M = {}" hence "A = {}" using sets_into_space[OF assms] by auto
   7.104    thus ?thesis unfolding simple_integral_def using `space M = {}` by auto
   7.105  next
   7.106 -  assume "space M \<noteq> {}" hence "(\<lambda>x. 1) ` space M = {1::pinfreal}" by auto
   7.107 +  assume "space M \<noteq> {}" hence "(\<lambda>x. 1) ` space M = {1::pextreal}" by auto
   7.108    thus ?thesis
   7.109      using simple_integral_indicator[OF assms simple_function_const[of 1]]
   7.110      using sets_into_space[OF assms]
   7.111 @@ -762,7 +762,7 @@
   7.112    assumes "simple_function u" "N \<in> null_sets"
   7.113    shows "simple_integral (\<lambda>x. u x * indicator N x) = 0"
   7.114  proof -
   7.115 -  have "AE x. indicator N x = (0 :: pinfreal)"
   7.116 +  have "AE x. indicator N x = (0 :: pextreal)"
   7.117      using `N \<in> null_sets` by (auto simp: indicator_def intro!: AE_I[of _ N])
   7.118    then have "simple_integral (\<lambda>x. u x * indicator N x) = simple_integral (\<lambda>x. 0)"
   7.119      using assms by (intro simple_integral_cong_AE) (auto intro!: AE_disjI2)
   7.120 @@ -806,7 +806,7 @@
   7.121      by (auto simp: indicator_def split: split_if_asm)
   7.122    then show "f x * \<mu> (f -` {f x} \<inter> A) =
   7.123      f x * \<mu> (?f -` {f x} \<inter> space M)"
   7.124 -    unfolding pinfreal_mult_cancel_left by auto
   7.125 +    unfolding pextreal_mult_cancel_left by auto
   7.126  qed
   7.127  
   7.128  lemma (in measure_space) simple_integral_subalgebra[simp]:
   7.129 @@ -816,7 +816,7 @@
   7.130    unfolding measure_space.simple_integral_def_raw[OF assms] by simp
   7.131  
   7.132  lemma (in measure_space) simple_integral_vimage:
   7.133 -  fixes g :: "'a \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
   7.134 +  fixes g :: "'a \<Rightarrow> pextreal" and f :: "'d \<Rightarrow> 'a"
   7.135    assumes f: "bij_betw f S (space M)"
   7.136    shows "simple_integral g =
   7.137           measure_space.simple_integral (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A)) (\<lambda>x. g (f x))"
   7.138 @@ -893,7 +893,7 @@
   7.139              using `\<mu> ?G \<noteq> 0` by (auto simp: indicator_def split: split_if_asm)
   7.140            have "x < (of_nat n / (if \<mu> ?G = \<omega> then 1 else \<mu> ?G)) * \<mu> ?G"
   7.141              using n `\<mu> ?G \<noteq> 0` `0 < n`
   7.142 -            by (auto simp: pinfreal_noteq_omega_Ex field_simps)
   7.143 +            by (auto simp: pextreal_noteq_omega_Ex field_simps)
   7.144            also have "\<dots> = simple_integral ?g" using g `space M \<noteq> {}`
   7.145              by (subst simple_integral_indicator)
   7.146                 (auto simp: image_constant ac_simps dest: simple_functionD)
   7.147 @@ -950,7 +950,7 @@
   7.148    assumes "simple_function f"
   7.149    shows "positive_integral f = simple_integral f"
   7.150    unfolding positive_integral_def
   7.151 -proof (safe intro!: pinfreal_SUPI)
   7.152 +proof (safe intro!: pextreal_SUPI)
   7.153    fix g assume "simple_function g" "g \<le> f"
   7.154    with assms show "simple_integral g \<le> simple_integral f"
   7.155      by (auto intro!: simple_integral_mono simp: le_fun_def)
   7.156 @@ -1017,7 +1017,7 @@
   7.157    using assms by blast
   7.158  
   7.159  lemma (in measure_space) positive_integral_vimage:
   7.160 -  fixes g :: "'a \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
   7.161 +  fixes g :: "'a \<Rightarrow> pextreal" and f :: "'d \<Rightarrow> 'a"
   7.162    assumes f: "bij_betw f S (space M)"
   7.163    shows "positive_integral g =
   7.164           measure_space.positive_integral (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A)) (\<lambda>x. g (f x))"
   7.165 @@ -1039,14 +1039,14 @@
   7.166    show ?thesis
   7.167      unfolding positive_integral_alt1 T.positive_integral_alt1 SUPR_def * image_compose
   7.168    proof (safe intro!: arg_cong[where f=Sup] image_set_cong, simp_all add: comp_def)
   7.169 -    fix g' :: "'a \<Rightarrow> pinfreal" assume "simple_function g'" "\<forall>x\<in>space M. g' x \<le> g x \<and> g' x \<noteq> \<omega>"
   7.170 +    fix g' :: "'a \<Rightarrow> pextreal" assume "simple_function g'" "\<forall>x\<in>space M. g' x \<le> g x \<and> g' x \<noteq> \<omega>"
   7.171      then show "\<exists>h. T.simple_function h \<and> (\<forall>x\<in>S. h x \<le> g (f x) \<and> h x \<noteq> \<omega>) \<and>
   7.172                     T.simple_integral (\<lambda>x. g' (f x)) = T.simple_integral h"
   7.173        using f unfolding bij_betw_def
   7.174        by (auto intro!: exI[of _ "\<lambda>x. g' (f x)"]
   7.175                 simp add: le_fun_def simple_function_vimage[OF _ f_fun])
   7.176    next
   7.177 -    fix g' :: "'d \<Rightarrow> pinfreal" assume g': "T.simple_function g'" "\<forall>x\<in>S. g' x \<le> g (f x) \<and> g' x \<noteq> \<omega>"
   7.178 +    fix g' :: "'d \<Rightarrow> pextreal" assume g': "T.simple_function g'" "\<forall>x\<in>S. g' x \<le> g (f x) \<and> g' x \<noteq> \<omega>"
   7.179      let ?g = "\<lambda>x. g' (the_inv_into S f x)"
   7.180      show "\<exists>h. simple_function h \<and> (\<forall>x\<in>space M. h x \<le> g x \<and> h x \<noteq> \<omega>) \<and>
   7.181                T.simple_integral g' = T.simple_integral (\<lambda>x. h (f x))"
   7.182 @@ -1068,7 +1068,7 @@
   7.183  qed
   7.184  
   7.185  lemma (in measure_space) positive_integral_vimage_inv:
   7.186 -  fixes g :: "'d \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
   7.187 +  fixes g :: "'d \<Rightarrow> pextreal" and f :: "'d \<Rightarrow> 'a"
   7.188    assumes f: "bij_betw f S (space M)"
   7.189    shows "measure_space.positive_integral (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A)) g =
   7.190        positive_integral (\<lambda>x. g (the_inv_into S f x))"
   7.191 @@ -1087,8 +1087,8 @@
   7.192    and "simple_function u"
   7.193    and le: "u \<le> s" and real: "\<omega> \<notin> u`space M"
   7.194    shows "simple_integral u \<le> (SUP i. positive_integral (f i))" (is "_ \<le> ?S")
   7.195 -proof (rule pinfreal_le_mult_one_interval)
   7.196 -  fix a :: pinfreal assume "0 < a" "a < 1"
   7.197 +proof (rule pextreal_le_mult_one_interval)
   7.198 +  fix a :: pextreal assume "0 < a" "a < 1"
   7.199    hence "a \<noteq> 0" by auto
   7.200    let "?B i" = "{x \<in> space M. a * u x \<le> f i x}"
   7.201    have B: "\<And>i. ?B i \<in> sets M"
   7.202 @@ -1117,7 +1117,7 @@
   7.203      next
   7.204        assume "u x \<noteq> 0"
   7.205        with `a < 1` real `x \<in> space M`
   7.206 -      have "a * u x < 1 * u x" by (rule_tac pinfreal_mult_strict_right_mono) (auto simp: image_iff)
   7.207 +      have "a * u x < 1 * u x" by (rule_tac pextreal_mult_strict_right_mono) (auto simp: image_iff)
   7.208        also have "\<dots> \<le> (SUP i. f i x)" using le `f \<up> s`
   7.209          unfolding isoton_fun_expand by (auto simp: isoton_def le_fun_def)
   7.210        finally obtain i where "a * u x < f i x" unfolding SUPR_def
   7.211 @@ -1130,7 +1130,7 @@
   7.212  
   7.213    have "simple_integral u = (SUP i. simple_integral (?uB i))"
   7.214      unfolding simple_integral_indicator[OF B `simple_function u`]
   7.215 -  proof (subst SUPR_pinfreal_setsum, safe)
   7.216 +  proof (subst SUPR_pextreal_setsum, safe)
   7.217      fix x n assume "x \<in> space M"
   7.218      have "\<mu> (u -` {u x} \<inter> space M \<inter> {x \<in> space M. a * u x \<le> f n x})
   7.219        \<le> \<mu> (u -` {u x} \<inter> space M \<inter> {x \<in> space M. a * u x \<le> f (Suc n) x})"
   7.220 @@ -1142,11 +1142,11 @@
   7.221      show "simple_integral u =
   7.222        (\<Sum>i\<in>u ` space M. SUP n. i * \<mu> (u -` {i} \<inter> space M \<inter> ?B n))"
   7.223        using measure_conv unfolding simple_integral_def isoton_def
   7.224 -      by (auto intro!: setsum_cong simp: pinfreal_SUP_cmult)
   7.225 +      by (auto intro!: setsum_cong simp: pextreal_SUP_cmult)
   7.226    qed
   7.227    moreover
   7.228    have "a * (SUP i. simple_integral (?uB i)) \<le> ?S"
   7.229 -    unfolding pinfreal_SUP_cmult[symmetric]
   7.230 +    unfolding pextreal_SUP_cmult[symmetric]
   7.231    proof (safe intro!: SUP_mono bexI)
   7.232      fix i
   7.233      have "a * simple_integral (?uB i) = simple_integral (\<lambda>x. a * ?uB i x)"
   7.234 @@ -1306,7 +1306,7 @@
   7.235      case (insert i P)
   7.236      have "f i \<in> borel_measurable M"
   7.237        "(\<lambda>x. \<Sum>i\<in>P. f i x) \<in> borel_measurable M"
   7.238 -      using insert by (auto intro!: borel_measurable_pinfreal_setsum)
   7.239 +      using insert by (auto intro!: borel_measurable_pextreal_setsum)
   7.240      from positive_integral_add[OF this]
   7.241      show ?case using insert by auto
   7.242    qed simp
   7.243 @@ -1319,7 +1319,7 @@
   7.244    shows "positive_integral (\<lambda>x. f x - g x) = positive_integral f - positive_integral g"
   7.245  proof -
   7.246    have borel: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
   7.247 -    using f g by (rule borel_measurable_pinfreal_diff)
   7.248 +    using f g by (rule borel_measurable_pextreal_diff)
   7.249    have "positive_integral (\<lambda>x. f x - g x) + positive_integral g =
   7.250      positive_integral f"
   7.251      unfolding positive_integral_add[OF borel g, symmetric]
   7.252 @@ -1329,7 +1329,7 @@
   7.253        by (cases "f x", cases "g x", simp, simp, cases "g x", auto)
   7.254    qed
   7.255    with mono show ?thesis
   7.256 -    by (subst minus_pinfreal_eq2[OF _ fin]) (auto intro!: positive_integral_mono)
   7.257 +    by (subst minus_pextreal_eq2[OF _ fin]) (auto intro!: positive_integral_mono)
   7.258  qed
   7.259  
   7.260  lemma (in measure_space) positive_integral_psuminf:
   7.261 @@ -1338,7 +1338,7 @@
   7.262  proof -
   7.263    have "(\<lambda>i. positive_integral (\<lambda>x. \<Sum>i<i. f i x)) \<up> positive_integral (\<lambda>x. \<Sum>\<^isub>\<infinity>i. f i x)"
   7.264      by (rule positive_integral_isoton)
   7.265 -       (auto intro!: borel_measurable_pinfreal_setsum assms positive_integral_mono
   7.266 +       (auto intro!: borel_measurable_pextreal_setsum assms positive_integral_mono
   7.267                       arg_cong[where f=Sup]
   7.268               simp: isoton_def le_fun_def psuminf_def fun_eq_iff SUPR_def Sup_fun_def)
   7.269    thus ?thesis
   7.270 @@ -1347,7 +1347,7 @@
   7.271  
   7.272  text {* Fatou's lemma: convergence theorem on limes inferior *}
   7.273  lemma (in measure_space) positive_integral_lim_INF:
   7.274 -  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> pinfreal"
   7.275 +  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> pextreal"
   7.276    assumes "\<And>i. u i \<in> borel_measurable M"
   7.277    shows "positive_integral (SUP n. INF m. u (m + n)) \<le>
   7.278      (SUP n. INF m. positive_integral (u (m + n)))"
   7.279 @@ -1421,7 +1421,7 @@
   7.280    from G(2) have "(\<lambda>i x. f x * G i x) \<up> (\<lambda>x. f x * g x)"
   7.281      unfolding isoton_fun_expand by (auto intro!: isoton_cmult_right)
   7.282    then have "(\<lambda>i. positive_integral (\<lambda>x. f x * G i x)) \<up> positive_integral (\<lambda>x. f x * g x)"
   7.283 -    using assms(1) G_borel by (auto intro!: positive_integral_isoton borel_measurable_pinfreal_times)
   7.284 +    using assms(1) G_borel by (auto intro!: positive_integral_isoton borel_measurable_pextreal_times)
   7.285    with eq_Tg show "T.positive_integral g = positive_integral (\<lambda>x. f x * g x)"
   7.286      unfolding isoton_def by simp
   7.287  qed
   7.288 @@ -1493,7 +1493,7 @@
   7.289      next
   7.290        fix n x assume "1 \<le> of_nat n * u x"
   7.291        also have "\<dots> \<le> of_nat (Suc n) * u x"
   7.292 -        by (subst (1 2) mult_commute) (auto intro!: pinfreal_mult_cancel)
   7.293 +        by (subst (1 2) mult_commute) (auto intro!: pextreal_mult_cancel)
   7.294        finally show "1 \<le> of_nat (Suc n) * u x" .
   7.295      qed
   7.296      also have "\<dots> = \<mu> ?A"
   7.297 @@ -1774,7 +1774,7 @@
   7.298      using mono by (rule AE_mp) (auto intro!: AE_cong)
   7.299    ultimately show ?thesis using fg
   7.300      by (auto simp: integral_def integrable_def diff_minus
   7.301 -             intro!: add_mono real_of_pinfreal_mono positive_integral_mono_AE)
   7.302 +             intro!: add_mono real_of_pextreal_mono positive_integral_mono_AE)
   7.303  qed
   7.304  
   7.305  lemma (in measure_space) integral_mono:
   7.306 @@ -1861,7 +1861,7 @@
   7.307    also have "\<dots> \<le> positive_integral (\<lambda>x. Real (f x))"
   7.308      using f by (auto intro!: positive_integral_mono)
   7.309    also have "\<dots> < \<omega>"
   7.310 -    using `integrable f` unfolding integrable_def by (auto simp: pinfreal_less_\<omega>)
   7.311 +    using `integrable f` unfolding integrable_def by (auto simp: pextreal_less_\<omega>)
   7.312    finally have pos: "positive_integral (\<lambda>x. Real (g x)) < \<omega>" .
   7.313  
   7.314    have "positive_integral (\<lambda>x. Real (- g x)) \<le> positive_integral (\<lambda>x. Real (\<bar>g x\<bar>))"
   7.315 @@ -1869,7 +1869,7 @@
   7.316    also have "\<dots> \<le> positive_integral (\<lambda>x. Real (f x))"
   7.317      using f by (auto intro!: positive_integral_mono)
   7.318    also have "\<dots> < \<omega>"
   7.319 -    using `integrable f` unfolding integrable_def by (auto simp: pinfreal_less_\<omega>)
   7.320 +    using `integrable f` unfolding integrable_def by (auto simp: pextreal_less_\<omega>)
   7.321    finally have neg: "positive_integral (\<lambda>x. Real (- g x)) < \<omega>" .
   7.322  
   7.323    from neg pos borel show ?thesis
   7.324 @@ -2018,7 +2018,7 @@
   7.325      "positive_integral (\<lambda>x. Real \<bar>f x\<bar>) \<noteq> \<omega>" unfolding integrable_def by auto
   7.326    from positive_integral_0_iff[OF this(1)] this(2)
   7.327    show ?thesis unfolding integral_def *
   7.328 -    by (simp add: real_of_pinfreal_eq_0)
   7.329 +    by (simp add: real_of_pextreal_eq_0)
   7.330  qed
   7.331  
   7.332  lemma (in measure_space) positive_integral_omega:
   7.333 @@ -2125,8 +2125,8 @@
   7.334        by (auto intro!: positive_integral_lim_INF)
   7.335      also have "\<dots> = positive_integral (\<lambda>x. Real (2 * w x)) -
   7.336          (INF n. SUP m. positive_integral (\<lambda>x. Real \<bar>u (m + n) x - u' x\<bar>))"
   7.337 -      unfolding PI_diff pinfreal_INF_minus[OF I2w_fin] pinfreal_SUP_minus ..
   7.338 -    finally show ?thesis using neq_0 I2w_fin by (rule pinfreal_le_minus_imp_0)
   7.339 +      unfolding PI_diff pextreal_INF_minus[OF I2w_fin] pextreal_SUP_minus ..
   7.340 +    finally show ?thesis using neq_0 I2w_fin by (rule pextreal_le_minus_imp_0)
   7.341    qed
   7.342  
   7.343    have [simp]: "\<And>n m x. Real (- \<bar>u (m + n) x - u' x\<bar>) = 0" by auto
   7.344 @@ -2260,7 +2260,7 @@
   7.345      also have "\<dots> = \<bar>enum r\<bar> * real (\<mu> (?A r))"
   7.346        using f fin by (simp add: borel_measurable_vimage integral_cmul_indicator)
   7.347      finally have "integral (\<lambda>x. \<bar>?F r x\<bar>) = \<bar>enum r * real (\<mu> (?A r))\<bar>"
   7.348 -      by (simp add: abs_mult_pos real_pinfreal_pos) }
   7.349 +      by (simp add: abs_mult_pos real_pextreal_pos) }
   7.350    note int_abs_F = this
   7.351  
   7.352    have 1: "\<And>i. integrable (\<lambda>x. ?F i x)"
   7.353 @@ -2329,8 +2329,8 @@
   7.354    show "integrable f" using finite_space finite_measure
   7.355      by (simp add: setsum_\<omega> integrable_def)
   7.356    show ?I using finite_measure
   7.357 -    apply (simp add: integral_def real_of_pinfreal_setsum[symmetric]
   7.358 -      real_of_pinfreal_mult[symmetric] setsum_subtractf[symmetric])
   7.359 +    apply (simp add: integral_def real_of_pextreal_setsum[symmetric]
   7.360 +      real_of_pextreal_mult[symmetric] setsum_subtractf[symmetric])
   7.361      by (rule setsum_cong) (simp_all split: split_if)
   7.362  qed
   7.363  
     8.1 --- a/src/HOL/Probability/Lebesgue_Measure.thy	Mon Dec 06 19:18:02 2010 +0100
     8.2 +++ b/src/HOL/Probability/Lebesgue_Measure.thy	Fri Dec 03 15:25:14 2010 +0100
     8.3 @@ -357,7 +357,7 @@
     8.4  qed
     8.5  
     8.6  lemma lebesgue_simple_function_indicator:
     8.7 -  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pinfreal"
     8.8 +  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
     8.9    assumes f:"lebesgue.simple_function f"
    8.10    shows "f = (\<lambda>x. (\<Sum>y \<in> f ` UNIV. y * indicator (f -` {y}) x))"
    8.11    apply(rule,subst lebesgue.simple_function_indicator_representation[OF f]) by auto
    8.12 @@ -421,7 +421,7 @@
    8.13  
    8.14  lemma lmeasure_singleton[simp]:
    8.15    fixes a :: "'a::ordered_euclidean_space" shows "lmeasure {a} = 0"
    8.16 -  using has_gmeasure_interval[of a a] unfolding zero_pinfreal_def
    8.17 +  using has_gmeasure_interval[of a a] unfolding zero_pextreal_def
    8.18    by (intro has_gmeasure_lmeasure)
    8.19       (simp add: content_closed_interval DIM_positive)
    8.20  
    8.21 @@ -475,7 +475,7 @@
    8.22  qed
    8.23  
    8.24  lemma simple_function_has_integral:
    8.25 -  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pinfreal"
    8.26 +  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
    8.27    assumes f:"lebesgue.simple_function f"
    8.28    and f':"\<forall>x. f x \<noteq> \<omega>"
    8.29    and om:"\<forall>x\<in>range f. lmeasure (f -` {x} \<inter> UNIV) = \<omega> \<longrightarrow> x = 0"
    8.30 @@ -486,9 +486,9 @@
    8.31    have *:"\<And>x. \<forall>y\<in>range f. y * indicator (f -` {y}) x \<noteq> \<omega>"
    8.32      "\<forall>x\<in>range f. x * lmeasure (f -` {x} \<inter> UNIV) \<noteq> \<omega>"
    8.33      using f' om unfolding indicator_def by auto
    8.34 -  show ?case unfolding space_lebesgue real_of_pinfreal_setsum'[OF *(1),THEN sym]
    8.35 -    unfolding real_of_pinfreal_setsum'[OF *(2),THEN sym]
    8.36 -    unfolding real_of_pinfreal_setsum space_lebesgue
    8.37 +  show ?case unfolding space_lebesgue real_of_pextreal_setsum'[OF *(1),THEN sym]
    8.38 +    unfolding real_of_pextreal_setsum'[OF *(2),THEN sym]
    8.39 +    unfolding real_of_pextreal_setsum space_lebesgue
    8.40      apply(rule has_integral_setsum)
    8.41    proof safe show "finite (range f)" using f by (auto dest: lebesgue.simple_functionD)
    8.42      fix y::'a show "((\<lambda>x. real (f y * indicator (f -` {f y}) x)) has_integral
    8.43 @@ -496,8 +496,8 @@
    8.44      proof(cases "f y = 0") case False
    8.45        have mea:"gmeasurable (f -` {f y})" apply(rule lmeasure_finite_gmeasurable)
    8.46          using assms unfolding lebesgue.simple_function_def using False by auto
    8.47 -      have *:"\<And>x. real (indicator (f -` {f y}) x::pinfreal) = (if x \<in> f -` {f y} then 1 else 0)" by auto
    8.48 -      show ?thesis unfolding real_of_pinfreal_mult[THEN sym]
    8.49 +      have *:"\<And>x. real (indicator (f -` {f y}) x::pextreal) = (if x \<in> f -` {f y} then 1 else 0)" by auto
    8.50 +      show ?thesis unfolding real_of_pextreal_mult[THEN sym]
    8.51          apply(rule has_integral_cmul[where 'b=real, unfolded real_scaleR_def])
    8.52          unfolding Int_UNIV_right lmeasure_gmeasure[OF mea,THEN sym]
    8.53          unfolding measure_integral_univ[OF mea] * apply(rule integrable_integral)
    8.54 @@ -510,7 +510,7 @@
    8.55    using assms by auto
    8.56  
    8.57  lemma simple_function_has_integral':
    8.58 -  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pinfreal"
    8.59 +  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
    8.60    assumes f:"lebesgue.simple_function f"
    8.61    and i: "lebesgue.simple_integral f \<noteq> \<omega>"
    8.62    shows "((\<lambda>x. real (f x)) has_integral (real (lebesgue.simple_integral f))) UNIV"
    8.63 @@ -544,7 +544,7 @@
    8.64  qed
    8.65  
    8.66  lemma (in measure_space) positive_integral_monotone_convergence:
    8.67 -  fixes f::"nat \<Rightarrow> 'a \<Rightarrow> pinfreal"
    8.68 +  fixes f::"nat \<Rightarrow> 'a \<Rightarrow> pextreal"
    8.69    assumes i: "\<And>i. f i \<in> borel_measurable M" and mono: "\<And>x. mono (\<lambda>n. f n x)"
    8.70    and lim: "\<And>x. (\<lambda>i. f i x) ----> u x"
    8.71    shows "u \<in> borel_measurable M"
    8.72 @@ -552,7 +552,7 @@
    8.73  proof -
    8.74    from positive_integral_isoton[unfolded isoton_fun_expand isoton_iff_Lim_mono, of f u]
    8.75    show ?ilim using mono lim i by auto
    8.76 -  have "(SUP i. f i) = u" using mono lim SUP_Lim_pinfreal
    8.77 +  have "(SUP i. f i) = u" using mono lim SUP_Lim_pextreal
    8.78      unfolding fun_eq_iff SUPR_fun_expand mono_def by auto
    8.79    moreover have "(SUP i. f i) \<in> borel_measurable M"
    8.80      using i by (rule borel_measurable_SUP)
    8.81 @@ -560,7 +560,7 @@
    8.82  qed
    8.83  
    8.84  lemma positive_integral_has_integral:
    8.85 -  fixes f::"'a::ordered_euclidean_space => pinfreal"
    8.86 +  fixes f::"'a::ordered_euclidean_space => pextreal"
    8.87    assumes f:"f \<in> borel_measurable lebesgue"
    8.88    and int_om:"lebesgue.positive_integral f \<noteq> \<omega>"
    8.89    and f_om:"\<forall>x. f x \<noteq> \<omega>" (* TODO: remove this *)
    8.90 @@ -581,14 +581,14 @@
    8.91    have "(\<lambda>x. real (f x)) integrable_on UNIV \<and>
    8.92      (\<lambda>k. Integration.integral UNIV (\<lambda>x. real (u k x))) ----> Integration.integral UNIV (\<lambda>x. real (f x))"
    8.93      apply(rule monotone_convergence_increasing) apply(rule,rule,rule u_int)
    8.94 -  proof safe case goal1 show ?case apply(rule real_of_pinfreal_mono) using u(2,3) by auto
    8.95 +  proof safe case goal1 show ?case apply(rule real_of_pextreal_mono) using u(2,3) by auto
    8.96    next case goal2 show ?case using u(3) apply(subst lim_Real[THEN sym])
    8.97        prefer 3 apply(subst Real_real') defer apply(subst Real_real')
    8.98        using isotone_Lim[OF u(3)[unfolded isoton_fun_expand, THEN spec]] using f_om u by auto
    8.99    next case goal3
   8.100      show ?case apply(rule bounded_realI[where B="real (lebesgue.positive_integral f)"])
   8.101        apply safe apply(subst abs_of_nonneg) apply(rule integral_nonneg,rule) apply(rule u_int)
   8.102 -      unfolding integral_unique[OF u_int] defer apply(rule real_of_pinfreal_mono[OF _ int_u_le])
   8.103 +      unfolding integral_unique[OF u_int] defer apply(rule real_of_pextreal_mono[OF _ int_u_le])
   8.104        using u int_om by auto
   8.105    qed note int = conjunctD2[OF this]
   8.106  
   8.107 @@ -921,7 +921,7 @@
   8.108  qed
   8.109  
   8.110  lemma borel_fubini_positiv_integral:
   8.111 -  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> pinfreal"
   8.112 +  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> pextreal"
   8.113    assumes f: "f \<in> borel_measurable borel"
   8.114    shows "borel.positive_integral f =
   8.115            borel_product.product_positive_integral {..<DIM('a)} (f \<circ> p2e)"
     9.1 --- a/src/HOL/Probability/Measure.thy	Mon Dec 06 19:18:02 2010 +0100
     9.2 +++ b/src/HOL/Probability/Measure.thy	Fri Dec 03 15:25:14 2010 +0100
     9.3 @@ -103,7 +103,7 @@
     9.4      by (rule additiveD [OF additive]) (auto simp add: s)
     9.5    finally have "\<mu> (space M) = \<mu> s + \<mu> (space M - s)" .
     9.6    thus ?thesis
     9.7 -    unfolding minus_pinfreal_eq2[OF s_less_space fin]
     9.8 +    unfolding minus_pextreal_eq2[OF s_less_space fin]
     9.9      by (simp add: ac_simps)
    9.10  qed
    9.11  
    9.12 @@ -117,7 +117,7 @@
    9.13    have "\<mu> ((A - B) \<union> B) = \<mu> (A - B) + \<mu> B"
    9.14      using measurable by (rule_tac measure_additive[symmetric]) auto
    9.15    thus ?thesis unfolding * using `\<mu> B \<noteq> \<omega>`
    9.16 -    by (simp add: pinfreal_cancel_plus_minus)
    9.17 +    by (simp add: pextreal_cancel_plus_minus)
    9.18  qed
    9.19  
    9.20  lemma (in measure_space) measure_countable_increasing:
    9.21 @@ -225,7 +225,7 @@
    9.22      by (rule INF_leI) simp
    9.23  
    9.24    have "\<mu> (A 0) - (INF n. \<mu> (A n)) = (SUP n. \<mu> (A 0 - A n))"
    9.25 -    unfolding pinfreal_SUP_minus[symmetric]
    9.26 +    unfolding pextreal_SUP_minus[symmetric]
    9.27      using mono A finite by (subst measure_Diff) auto
    9.28    also have "\<dots> = \<mu> (\<Union>i. A 0 - A i)"
    9.29    proof (rule continuity_from_below)
    9.30 @@ -237,7 +237,7 @@
    9.31    also have "\<dots> = \<mu> (A 0) - \<mu> (\<Inter>i. A i)"
    9.32      using mono A finite * by (simp, subst measure_Diff) auto
    9.33    finally show ?thesis
    9.34 -    by (rule pinfreal_diff_eq_diff_imp_eq[OF finite[of 0] le_IM le_MI])
    9.35 +    by (rule pextreal_diff_eq_diff_imp_eq[OF finite[of 0] le_IM le_MI])
    9.36  qed
    9.37  
    9.38  lemma (in measure_space) measure_down:
    9.39 @@ -516,7 +516,7 @@
    9.40      also have "\<dots> \<le> \<mu> (T - S) + \<mu> (S \<inter> T)"
    9.41        using assms by (auto intro!: measure_subadditive)
    9.42      also have "\<dots> < \<mu> (T - S) + \<mu> S"
    9.43 -      by (rule pinfreal_less_add[OF not_\<omega>]) (insert contr, auto)
    9.44 +      by (rule pextreal_less_add[OF not_\<omega>]) (insert contr, auto)
    9.45      also have "\<dots> = \<mu> (T \<union> S)"
    9.46        using assms by (subst measure_additive) auto
    9.47      also have "\<dots> \<le> \<mu> (space M)"
    9.48 @@ -962,8 +962,8 @@
    9.49      fix i
    9.50      have "\<mu> (A i \<inter> S) \<le> \<mu> (A i)"
    9.51        using `range A \<subseteq> sets M` `S \<in> sets M` by (auto intro!: measure_mono)
    9.52 -    also have "\<dots> < \<omega>" using `\<mu> (A i) \<noteq> \<omega>` by (auto simp: pinfreal_less_\<omega>)
    9.53 -    finally show "\<mu> (A i \<inter> S) \<noteq> \<omega>" by (auto simp: pinfreal_less_\<omega>)
    9.54 +    also have "\<dots> < \<omega>" using `\<mu> (A i) \<noteq> \<omega>` by (auto simp: pextreal_less_\<omega>)
    9.55 +    finally show "\<mu> (A i \<inter> S) \<noteq> \<omega>" by (auto simp: pextreal_less_\<omega>)
    9.56    qed
    9.57  qed
    9.58  
    9.59 @@ -1051,14 +1051,14 @@
    9.60    and measurable: "A \<in> sets M" "B \<in> sets M" "A \<inter> B = {}"
    9.61    shows "real (\<mu> (A \<union> B)) = real (\<mu> A) + real (\<mu> B)"
    9.62    unfolding measure_additive[symmetric, OF measurable]
    9.63 -  using finite by (auto simp: real_of_pinfreal_add)
    9.64 +  using finite by (auto simp: real_of_pextreal_add)
    9.65  
    9.66  lemma (in measure_space) real_measure_finite_Union:
    9.67    assumes measurable:
    9.68      "finite S" "\<And>i. i \<in> S \<Longrightarrow> A i \<in> sets M" "disjoint_family_on A S"
    9.69    assumes finite: "\<And>i. i \<in> S \<Longrightarrow> \<mu> (A i) \<noteq> \<omega>"
    9.70    shows "real (\<mu> (\<Union>i\<in>S. A i)) = (\<Sum>i\<in>S. real (\<mu> (A i)))"
    9.71 -  using real_of_pinfreal_setsum[of S, OF finite]
    9.72 +  using real_of_pextreal_setsum[of S, OF finite]
    9.73          measure_finitely_additive''[symmetric, OF measurable]
    9.74    by simp
    9.75  
    9.76 @@ -1093,9 +1093,9 @@
    9.77    shows "real (\<mu> (A \<union> B)) \<le> real (\<mu> A) + real (\<mu> B)"
    9.78  proof -
    9.79    have "real (\<mu> (A \<union> B)) \<le> real (\<mu> A + \<mu> B)"
    9.80 -    using measure_subadditive[OF measurable] fin by (auto intro!: real_of_pinfreal_mono)
    9.81 +    using measure_subadditive[OF measurable] fin by (auto intro!: real_of_pextreal_mono)
    9.82    also have "\<dots> = real (\<mu> A) + real (\<mu> B)"
    9.83 -    using fin by (simp add: real_of_pinfreal_add)
    9.84 +    using fin by (simp add: real_of_pextreal_add)
    9.85    finally show ?thesis .
    9.86  qed
    9.87  
    9.88 @@ -1104,7 +1104,7 @@
    9.89    shows "real (\<mu> (\<Union>i. f i)) \<le> (\<Sum> i. real (\<mu> (f i)))"
    9.90  proof -
    9.91    have "real (\<mu> (\<Union>i. f i)) \<le> real (\<Sum>\<^isub>\<infinity> i. \<mu> (f i))"
    9.92 -    using assms by (auto intro!: real_of_pinfreal_mono measure_countably_subadditive)
    9.93 +    using assms by (auto intro!: real_of_pextreal_mono measure_countably_subadditive)
    9.94    also have "\<dots> = (\<Sum> i. real (\<mu> (f i)))"
    9.95      using assms by (auto intro!: sums_unique psuminf_imp_suminf)
    9.96    finally show ?thesis .
    9.97 @@ -1114,7 +1114,7 @@
    9.98    assumes S: "finite S" "\<And>x. x \<in> S \<Longrightarrow> {x} \<in> sets M"
    9.99    and fin: "\<And>x. x \<in> S \<Longrightarrow> \<mu> {x} \<noteq> \<omega>"
   9.100    shows "real (\<mu> S) = (\<Sum>x\<in>S. real (\<mu> {x}))"
   9.101 -  using measure_finite_singleton[OF S] fin by (simp add: real_of_pinfreal_setsum)
   9.102 +  using measure_finite_singleton[OF S] fin by (simp add: real_of_pextreal_setsum)
   9.103  
   9.104  lemma (in measure_space) real_continuity_from_below:
   9.105    assumes A: "range A \<subseteq> sets M" "\<And>i. A i \<subseteq> A (Suc i)" and "\<mu> (\<Union>i. A i) \<noteq> \<omega>"
   9.106 @@ -1126,7 +1126,7 @@
   9.107    note this[simp]
   9.108  
   9.109    show "mono (\<lambda>i. real (\<mu> (A i)))" unfolding mono_iff_le_Suc using A
   9.110 -    by (auto intro!: real_of_pinfreal_mono measure_mono)
   9.111 +    by (auto intro!: real_of_pextreal_mono measure_mono)
   9.112  
   9.113    show "(SUP n. Real (real (\<mu> (A n)))) = Real (real (\<mu> (\<Union>i. A i)))"
   9.114      using continuity_from_below[OF A(1), OF A(2)]
   9.115 @@ -1145,7 +1145,7 @@
   9.116    note this[simp]
   9.117  
   9.118    show "mono (\<lambda>i. - real (\<mu> (A i)))" unfolding mono_iff_le_Suc using assms
   9.119 -    by (auto intro!: real_of_pinfreal_mono measure_mono)
   9.120 +    by (auto intro!: real_of_pextreal_mono measure_mono)
   9.121  
   9.122    show "(INF n. Real (real (\<mu> (A n)))) =
   9.123      Real (real (\<mu> (\<Inter>i. A i)))"
   9.124 @@ -1171,8 +1171,8 @@
   9.125    hence "\<mu> A \<le> \<mu> (space M)"
   9.126      using assms top by (rule measure_mono)
   9.127    also have "\<dots> < \<omega>"
   9.128 -    using finite_measure_of_space unfolding pinfreal_less_\<omega> .
   9.129 -  finally show ?thesis unfolding pinfreal_less_\<omega> .
   9.130 +    using finite_measure_of_space unfolding pextreal_less_\<omega> .
   9.131 +  finally show ?thesis unfolding pextreal_less_\<omega> .
   9.132  qed
   9.133  
   9.134  lemma (in finite_measure) restricted_finite_measure:
   9.135 @@ -1226,7 +1226,7 @@
   9.136  
   9.137  lemma (in finite_measure) real_measure_mono:
   9.138    "A \<in> sets M \<Longrightarrow> B \<in> sets M \<Longrightarrow> A \<subseteq> B \<Longrightarrow> real (\<mu> A) \<le> real (\<mu> B)"
   9.139 -  by (auto intro!: measure_mono real_of_pinfreal_mono finite_measure)
   9.140 +  by (auto intro!: measure_mono real_of_pextreal_mono finite_measure)
   9.141  
   9.142  lemma (in finite_measure) real_finite_measure_subadditive:
   9.143    assumes measurable: "A \<in> sets M" "B \<in> sets M"
   9.144 @@ -1449,13 +1449,13 @@
   9.145    assumes "disjoint_family A" "x \<in> A i"
   9.146    shows "(\<Sum>\<^isub>\<infinity> n. f n * indicator (A n) x) = f i"
   9.147  proof -
   9.148 -  have **: "\<And>n. f n * indicator (A n) x = (if n = i then f n else 0 :: pinfreal)"
   9.149 +  have **: "\<And>n. f n * indicator (A n) x = (if n = i then f n else 0 :: pextreal)"
   9.150      using `x \<in> A i` assms unfolding disjoint_family_on_def indicator_def by auto
   9.151 -  then have "\<And>n. (\<Sum>j<n. f j * indicator (A j) x) = (if i < n then f i else 0 :: pinfreal)"
   9.152 +  then have "\<And>n. (\<Sum>j<n. f j * indicator (A j) x) = (if i < n then f i else 0 :: pextreal)"
   9.153      by (auto simp: setsum_cases)
   9.154 -  moreover have "(SUP n. if i < n then f i else 0) = (f i :: pinfreal)"
   9.155 -  proof (rule pinfreal_SUPI)
   9.156 -    fix y :: pinfreal assume "\<And>n. n \<in> UNIV \<Longrightarrow> (if i < n then f i else 0) \<le> y"
   9.157 +  moreover have "(SUP n. if i < n then f i else 0) = (f i :: pextreal)"
   9.158 +  proof (rule pextreal_SUPI)
   9.159 +    fix y :: pextreal assume "\<And>n. n \<in> UNIV \<Longrightarrow> (if i < n then f i else 0) \<le> y"
   9.160      from this[of "Suc i"] show "f i \<le> y" by auto
   9.161    qed simp
   9.162    ultimately show ?thesis using `x \<in> A i` unfolding psuminf_def by auto
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/HOL/Probability/Positive_Extended_Real.thy	Fri Dec 03 15:25:14 2010 +0100
    10.3 @@ -0,0 +1,2775 @@
    10.4 +(* Author: Johannes Hoelzl, TU Muenchen *)
    10.5 +
    10.6 +header {* A type for positive real numbers with infinity *}
    10.7 +
    10.8 +theory Positive_Extended_Real
    10.9 +  imports Complex_Main Nat_Bijection Multivariate_Analysis
   10.10 +begin
   10.11 +
   10.12 +lemma (in complete_lattice) Sup_start:
   10.13 +  assumes *: "\<And>x. f x \<le> f 0"
   10.14 +  shows "(SUP n. f n) = f 0"
   10.15 +proof (rule antisym)
   10.16 +  show "f 0 \<le> (SUP n. f n)" by (rule le_SUPI) auto
   10.17 +  show "(SUP n. f n) \<le> f 0" by (rule SUP_leI[OF *])
   10.18 +qed
   10.19 +
   10.20 +lemma (in complete_lattice) Inf_start:
   10.21 +  assumes *: "\<And>x. f 0 \<le> f x"
   10.22 +  shows "(INF n. f n) = f 0"
   10.23 +proof (rule antisym)
   10.24 +  show "(INF n. f n) \<le> f 0" by (rule INF_leI) simp
   10.25 +  show "f 0 \<le> (INF n. f n)" by (rule le_INFI[OF *])
   10.26 +qed
   10.27 +
   10.28 +lemma (in complete_lattice) Sup_mono_offset:
   10.29 +  fixes f :: "'b :: {ordered_ab_semigroup_add,monoid_add} \<Rightarrow> 'a"
   10.30 +  assumes *: "\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y" and "0 \<le> k"
   10.31 +  shows "(SUP n . f (k + n)) = (SUP n. f n)"
   10.32 +proof (rule antisym)
   10.33 +  show "(SUP n. f (k + n)) \<le> (SUP n. f n)"
   10.34 +    by (auto intro!: Sup_mono simp: SUPR_def)
   10.35 +  { fix n :: 'b
   10.36 +    have "0 + n \<le> k + n" using `0 \<le> k` by (rule add_right_mono)
   10.37 +    with * have "f n \<le> f (k + n)" by simp }
   10.38 +  thus "(SUP n. f n) \<le> (SUP n. f (k + n))"
   10.39 +    by (auto intro!: Sup_mono exI simp: SUPR_def)
   10.40 +qed
   10.41 +
   10.42 +lemma (in complete_lattice) Sup_mono_offset_Suc:
   10.43 +  assumes *: "\<And>x. f x \<le> f (Suc x)"
   10.44 +  shows "(SUP n . f (Suc n)) = (SUP n. f n)"
   10.45 +  unfolding Suc_eq_plus1
   10.46 +  apply (subst add_commute)
   10.47 +  apply (rule Sup_mono_offset)
   10.48 +  by (auto intro!: order.lift_Suc_mono_le[of "op \<le>" "op <" f, OF _ *]) default
   10.49 +
   10.50 +lemma (in complete_lattice) Inf_mono_offset:
   10.51 +  fixes f :: "'b :: {ordered_ab_semigroup_add,monoid_add} \<Rightarrow> 'a"
   10.52 +  assumes *: "\<And>x y. x \<le> y \<Longrightarrow> f y \<le> f x" and "0 \<le> k"
   10.53 +  shows "(INF n . f (k + n)) = (INF n. f n)"
   10.54 +proof (rule antisym)
   10.55 +  show "(INF n. f n) \<le> (INF n. f (k + n))"
   10.56 +    by (auto intro!: Inf_mono simp: INFI_def)
   10.57 +  { fix n :: 'b
   10.58 +    have "0 + n \<le> k + n" using `0 \<le> k` by (rule add_right_mono)
   10.59 +    with * have "f (k + n) \<le> f n" by simp }
   10.60 +  thus "(INF n. f (k + n)) \<le> (INF n. f n)"
   10.61 +    by (auto intro!: Inf_mono exI simp: INFI_def)
   10.62 +qed
   10.63 +
   10.64 +lemma (in complete_lattice) isotone_converge:
   10.65 +  fixes f :: "nat \<Rightarrow> 'a" assumes "\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y "
   10.66 +  shows "(INF n. SUP m. f (n + m)) = (SUP n. INF m. f (n + m))"
   10.67 +proof -
   10.68 +  have "\<And>n. (SUP m. f (n + m)) = (SUP n. f n)"
   10.69 +    apply (rule Sup_mono_offset)
   10.70 +    apply (rule assms)
   10.71 +    by simp_all
   10.72 +  moreover
   10.73 +  { fix n have "(INF m. f (n + m)) = f n"
   10.74 +      using Inf_start[of "\<lambda>m. f (n + m)"] assms by simp }
   10.75 +  ultimately show ?thesis by simp
   10.76 +qed
   10.77 +
   10.78 +lemma (in complete_lattice) antitone_converges:
   10.79 +  fixes f :: "nat \<Rightarrow> 'a" assumes "\<And>x y. x \<le> y \<Longrightarrow> f y \<le> f x"
   10.80 +  shows "(INF n. SUP m. f (n + m)) = (SUP n. INF m. f (n + m))"
   10.81 +proof -
   10.82 +  have "\<And>n. (INF m. f (n + m)) = (INF n. f n)"
   10.83 +    apply (rule Inf_mono_offset)
   10.84 +    apply (rule assms)
   10.85 +    by simp_all
   10.86 +  moreover
   10.87 +  { fix n have "(SUP m. f (n + m)) = f n"
   10.88 +      using Sup_start[of "\<lambda>m. f (n + m)"] assms by simp }
   10.89 +  ultimately show ?thesis by simp
   10.90 +qed
   10.91 +
   10.92 +lemma (in complete_lattice) lim_INF_le_lim_SUP:
   10.93 +  fixes f :: "nat \<Rightarrow> 'a"
   10.94 +  shows "(SUP n. INF m. f (n + m)) \<le> (INF n. SUP m. f (n + m))"
   10.95 +proof (rule SUP_leI, rule le_INFI)
   10.96 +  fix i j show "(INF m. f (i + m)) \<le> (SUP m. f (j + m))"
   10.97 +  proof (cases rule: le_cases)
   10.98 +    assume "i \<le> j"
   10.99 +    have "(INF m. f (i + m)) \<le> f (i + (j - i))" by (rule INF_leI) simp
  10.100 +    also have "\<dots> = f (j + 0)" using `i \<le> j` by auto
  10.101 +    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
  10.102 +    finally show ?thesis .
  10.103 +  next
  10.104 +    assume "j \<le> i"
  10.105 +    have "(INF m. f (i + m)) \<le> f (i + 0)" by (rule INF_leI) simp
  10.106 +    also have "\<dots> = f (j + (i - j))" using `j \<le> i` by auto
  10.107 +    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
  10.108 +    finally show ?thesis .
  10.109 +  qed
  10.110 +qed
  10.111 +
  10.112 +text {*
  10.113 +
  10.114 +We introduce the the positive real numbers as needed for measure theory.
  10.115 +
  10.116 +*}
  10.117 +
  10.118 +typedef pextreal = "(Some ` {0::real..}) \<union> {None}"
  10.119 +  by (rule exI[of _ None]) simp
  10.120 +
  10.121 +subsection "Introduce @{typ pextreal} similar to a datatype"
  10.122 +
  10.123 +definition "Real x = Abs_pextreal (Some (sup 0 x))"
  10.124 +definition "\<omega> = Abs_pextreal None"
  10.125 +
  10.126 +definition "pextreal_case f i x = (if x = \<omega> then i else f (THE r. 0 \<le> r \<and> x = Real r))"
  10.127 +
  10.128 +definition "of_pextreal = pextreal_case (\<lambda>x. x) 0"
  10.129 +
  10.130 +defs (overloaded)
  10.131 +  real_of_pextreal_def [code_unfold]: "real == of_pextreal"
  10.132 +
  10.133 +lemma pextreal_Some[simp]: "0 \<le> x \<Longrightarrow> Some x \<in> pextreal"
  10.134 +  unfolding pextreal_def by simp
  10.135 +
  10.136 +lemma pextreal_Some_sup[simp]: "Some (sup 0 x) \<in> pextreal"
  10.137 +  by (simp add: sup_ge1)
  10.138 +
  10.139 +lemma pextreal_None[simp]: "None \<in> pextreal"
  10.140 +  unfolding pextreal_def by simp
  10.141 +
  10.142 +lemma Real_inj[simp]:
  10.143 +  assumes  "0 \<le> x" and "0 \<le> y"
  10.144 +  shows "Real x = Real y \<longleftrightarrow> x = y"
  10.145 +  unfolding Real_def assms[THEN sup_absorb2]
  10.146 +  using assms by (simp add: Abs_pextreal_inject)
  10.147 +
  10.148 +lemma Real_neq_\<omega>[simp]:
  10.149 +  "Real x = \<omega> \<longleftrightarrow> False"
  10.150 +  "\<omega> = Real x \<longleftrightarrow> False"
  10.151 +  by (simp_all add: Abs_pextreal_inject \<omega>_def Real_def)
  10.152 +
  10.153 +lemma Real_neg: "x < 0 \<Longrightarrow> Real x = Real 0"
  10.154 +  unfolding Real_def by (auto simp add: Abs_pextreal_inject intro!: sup_absorb1)
  10.155 +
  10.156 +lemma pextreal_cases[case_names preal infinite, cases type: pextreal]:
  10.157 +  assumes preal: "\<And>r. x = Real r \<Longrightarrow> 0 \<le> r \<Longrightarrow> P" and inf: "x = \<omega> \<Longrightarrow> P"
  10.158 +  shows P
  10.159 +proof (cases x rule: pextreal.Abs_pextreal_cases)
  10.160 +  case (Abs_pextreal y)
  10.161 +  hence "y = None \<or> (\<exists>x \<ge> 0. y = Some x)"
  10.162 +    unfolding pextreal_def by auto
  10.163 +  thus P
  10.164 +  proof (rule disjE)
  10.165 +    assume "\<exists>x\<ge>0. y = Some x" then guess x ..
  10.166 +    thus P by (simp add: preal[of x] Real_def Abs_pextreal(1) sup_absorb2)
  10.167 +  qed (simp add: \<omega>_def Abs_pextreal(1) inf)
  10.168 +qed
  10.169 +
  10.170 +lemma pextreal_case_\<omega>[simp]: "pextreal_case f i \<omega> = i"
  10.171 +  unfolding pextreal_case_def by simp
  10.172 +
  10.173 +lemma pextreal_case_Real[simp]: "pextreal_case f i (Real x) = (if 0 \<le> x then f x else f 0)"
  10.174 +proof (cases "0 \<le> x")
  10.175 +  case True thus ?thesis unfolding pextreal_case_def by (auto intro: theI2)
  10.176 +next
  10.177 +  case False
  10.178 +  moreover have "(THE r. 0 \<le> r \<and> Real 0 = Real r) = 0"
  10.179 +    by (auto intro!: the_equality)
  10.180 +  ultimately show ?thesis unfolding pextreal_case_def by (simp add: Real_neg)
  10.181 +qed
  10.182 +
  10.183 +lemma pextreal_case_cancel[simp]: "pextreal_case (\<lambda>c. i) i x = i"
  10.184 +  by (cases x) simp_all
  10.185 +
  10.186 +lemma pextreal_case_split:
  10.187 +  "P (pextreal_case f i x) = ((x = \<omega> \<longrightarrow> P i) \<and> (\<forall>r\<ge>0. x = Real r \<longrightarrow> P (f r)))"
  10.188 +  by (cases x) simp_all
  10.189 +
  10.190 +lemma pextreal_case_split_asm:
  10.191 +  "P (pextreal_case f i x) = (\<not> (x = \<omega> \<and> \<not> P i \<or> (\<exists>r. r \<ge> 0 \<and> x = Real r \<and> \<not> P (f r))))"
  10.192 +  by (cases x) auto
  10.193 +
  10.194 +lemma pextreal_case_cong[cong]:
  10.195 +  assumes eq: "x = x'" "i = i'" and cong: "\<And>r. 0 \<le> r \<Longrightarrow> f r = f' r"
  10.196 +  shows "pextreal_case f i x = pextreal_case f' i' x'"
  10.197 +  unfolding eq using cong by (cases x') simp_all
  10.198 +
  10.199 +lemma real_Real[simp]: "real (Real x) = (if 0 \<le> x then x else 0)"
  10.200 +  unfolding real_of_pextreal_def of_pextreal_def by simp
  10.201 +
  10.202 +lemma Real_real_image:
  10.203 +  assumes "\<omega> \<notin> A" shows "Real ` real ` A = A"
  10.204 +proof safe
  10.205 +  fix x assume "x \<in> A"
  10.206 +  hence *: "x = Real (real x)"
  10.207 +    using `\<omega> \<notin> A` by (cases x) auto
  10.208 +  show "x \<in> Real ` real ` A"
  10.209 +    using `x \<in> A` by (subst *) (auto intro!: imageI)
  10.210 +next
  10.211 +  fix x assume "x \<in> A"
  10.212 +  thus "Real (real x) \<in> A"
  10.213 +    using `\<omega> \<notin> A` by (cases x) auto
  10.214 +qed
  10.215 +
  10.216 +lemma real_pextreal_nonneg[simp, intro]: "0 \<le> real (x :: pextreal)"
  10.217 +  unfolding real_of_pextreal_def of_pextreal_def
  10.218 +  by (cases x) auto
  10.219 +
  10.220 +lemma real_\<omega>[simp]: "real \<omega> = 0"
  10.221 +  unfolding real_of_pextreal_def of_pextreal_def by simp
  10.222 +
  10.223 +lemma pextreal_noteq_omega_Ex: "X \<noteq> \<omega> \<longleftrightarrow> (\<exists>r\<ge>0. X = Real r)" by (cases X) auto
  10.224 +
  10.225 +subsection "@{typ pextreal} is a monoid for addition"
  10.226 +
  10.227 +instantiation pextreal :: comm_monoid_add
  10.228 +begin
  10.229 +
  10.230 +definition "0 = Real 0"
  10.231 +definition "x + y = pextreal_case (\<lambda>r. pextreal_case (\<lambda>p. Real (r + p)) \<omega> y) \<omega> x"
  10.232 +
  10.233 +lemma pextreal_plus[simp]:
  10.234 +  "Real r + Real p = (if 0 \<le> r then if 0 \<le> p then Real (r + p) else Real r else Real p)"
  10.235 +  "x + 0 = x"
  10.236 +  "0 + x = x"
  10.237 +  "x + \<omega> = \<omega>"
  10.238 +  "\<omega> + x = \<omega>"
  10.239 +  by (simp_all add: plus_pextreal_def Real_neg zero_pextreal_def split: pextreal_case_split)
  10.240 +
  10.241 +lemma \<omega>_neq_0[simp]:
  10.242 +  "\<omega> = 0 \<longleftrightarrow> False"
  10.243 +  "0 = \<omega> \<longleftrightarrow> False"
  10.244 +  by (simp_all add: zero_pextreal_def)
  10.245 +
  10.246 +lemma Real_eq_0[simp]:
  10.247 +  "Real r = 0 \<longleftrightarrow> r \<le> 0"
  10.248 +  "0 = Real r \<longleftrightarrow> r \<le> 0"
  10.249 +  by (auto simp add: Abs_pextreal_inject zero_pextreal_def Real_def sup_real_def)
  10.250 +
  10.251 +lemma Real_0[simp]: "Real 0 = 0" by (simp add: zero_pextreal_def)
  10.252 +
  10.253 +instance
  10.254 +proof
  10.255 +  fix a :: pextreal
  10.256 +  show "0 + a = a" by (cases a) simp_all
  10.257 +
  10.258 +  fix b show "a + b = b + a"
  10.259 +    by (cases a, cases b) simp_all
  10.260 +
  10.261 +  fix c show "a + b + c = a + (b + c)"
  10.262 +    by (cases a, cases b, cases c) simp_all
  10.263 +qed
  10.264 +end
  10.265 +
  10.266 +lemma pextreal_plus_eq_\<omega>[simp]: "(a :: pextreal) + b = \<omega> \<longleftrightarrow> a = \<omega> \<or> b = \<omega>"
  10.267 +  by (cases a, cases b) auto
  10.268 +
  10.269 +lemma pextreal_add_cancel_left:
  10.270 +  "a + b = a + c \<longleftrightarrow> (a = \<omega> \<or> b = c)"
  10.271 +  by (cases a, cases b, cases c, simp_all, cases c, simp_all)
  10.272 +
  10.273 +lemma pextreal_add_cancel_right:
  10.274 +  "b + a = c + a \<longleftrightarrow> (a = \<omega> \<or> b = c)"
  10.275 +  by (cases a, cases b, cases c, simp_all, cases c, simp_all)
  10.276 +
  10.277 +lemma Real_eq_Real:
  10.278 +  "Real a = Real b \<longleftrightarrow> (a = b \<or> (a \<le> 0 \<and> b \<le> 0))"
  10.279 +proof (cases "a \<le> 0 \<or> b \<le> 0")
  10.280 +  case False with Real_inj[of a b] show ?thesis by auto
  10.281 +next
  10.282 +  case True
  10.283 +  thus ?thesis
  10.284 +  proof
  10.285 +    assume "a \<le> 0"
  10.286 +    hence *: "Real a = 0" by simp
  10.287 +    show ?thesis using `a \<le> 0` unfolding * by auto
  10.288 +  next
  10.289 +    assume "b \<le> 0"
  10.290 +    hence *: "Real b = 0" by simp
  10.291 +    show ?thesis using `b \<le> 0` unfolding * by auto
  10.292 +  qed
  10.293 +qed
  10.294 +
  10.295 +lemma real_pextreal_0[simp]: "real (0 :: pextreal) = 0"
  10.296 +  unfolding zero_pextreal_def real_Real by simp
  10.297 +
  10.298 +lemma real_of_pextreal_eq_0: "real X = 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
  10.299 +  by (cases X) auto
  10.300 +
  10.301 +lemma real_of_pextreal_eq: "real X = real Y \<longleftrightarrow>
  10.302 +    (X = Y \<or> (X = 0 \<and> Y = \<omega>) \<or> (Y = 0 \<and> X = \<omega>))"
  10.303 +  by (cases X, cases Y) (auto simp add: real_of_pextreal_eq_0)
  10.304 +
  10.305 +lemma real_of_pextreal_add: "real X + real Y =
  10.306 +    (if X = \<omega> then real Y else if Y = \<omega> then real X else real (X + Y))"
  10.307 +  by (auto simp: pextreal_noteq_omega_Ex)
  10.308 +
  10.309 +subsection "@{typ pextreal} is a monoid for multiplication"
  10.310 +
  10.311 +instantiation pextreal :: comm_monoid_mult
  10.312 +begin
  10.313 +
  10.314 +definition "1 = Real 1"
  10.315 +definition "x * y = (if x = 0 \<or> y = 0 then 0 else
  10.316 +  pextreal_case (\<lambda>r. pextreal_case (\<lambda>p. Real (r * p)) \<omega> y) \<omega> x)"
  10.317 +
  10.318 +lemma pextreal_times[simp]:
  10.319 +  "Real r * Real p = (if 0 \<le> r \<and> 0 \<le> p then Real (r * p) else 0)"
  10.320 +  "\<omega> * x = (if x = 0 then 0 else \<omega>)"
  10.321 +  "x * \<omega> = (if x = 0 then 0 else \<omega>)"
  10.322 +  "0 * x = 0"
  10.323 +  "x * 0 = 0"
  10.324 +  "1 = \<omega> \<longleftrightarrow> False"
  10.325 +  "\<omega> = 1 \<longleftrightarrow> False"
  10.326 +  by (auto simp add: times_pextreal_def one_pextreal_def)
  10.327 +
  10.328 +lemma pextreal_one_mult[simp]:
  10.329 +  "Real x + 1 = (if 0 \<le> x then Real (x + 1) else 1)"
  10.330 +  "1 + Real x = (if 0 \<le> x then Real (1 + x) else 1)"
  10.331 +  unfolding one_pextreal_def by simp_all
  10.332 +
  10.333 +instance
  10.334 +proof
  10.335 +  fix a :: pextreal show "1 * a = a"
  10.336 +    by (cases a) (simp_all add: one_pextreal_def)
  10.337 +
  10.338 +  fix b show "a * b = b * a"
  10.339 +    by (cases a, cases b) (simp_all add: mult_nonneg_nonneg)
  10.340 +
  10.341 +  fix c show "a * b * c = a * (b * c)"
  10.342 +    apply (cases a, cases b, cases c)
  10.343 +    apply (simp_all add: mult_nonneg_nonneg not_le mult_pos_pos)
  10.344 +    apply (cases b, cases c)
  10.345 +    apply (simp_all add: mult_nonneg_nonneg not_le mult_pos_pos)
  10.346 +    done
  10.347 +qed
  10.348 +end
  10.349 +
  10.350 +lemma pextreal_mult_cancel_left:
  10.351 +  "a * b = a * c \<longleftrightarrow> (a = 0 \<or> b = c \<or> (a = \<omega> \<and> b \<noteq> 0 \<and> c \<noteq> 0))"
  10.352 +  by (cases a, cases b, cases c, auto simp: Real_eq_Real mult_le_0_iff, cases c, auto)
  10.353 +
  10.354 +lemma pextreal_mult_cancel_right:
  10.355 +  "b * a = c * a \<longleftrightarrow> (a = 0 \<or> b = c \<or> (a = \<omega> \<and> b \<noteq> 0 \<and> c \<noteq> 0))"
  10.356 +  by (cases a, cases b, cases c, auto simp: Real_eq_Real mult_le_0_iff, cases c, auto)
  10.357 +
  10.358 +lemma Real_1[simp]: "Real 1 = 1" by (simp add: one_pextreal_def)
  10.359 +
  10.360 +lemma real_pextreal_1[simp]: "real (1 :: pextreal) = 1"
  10.361 +  unfolding one_pextreal_def real_Real by simp
  10.362 +
  10.363 +lemma real_of_pextreal_mult: "real X * real Y = real (X * Y :: pextreal)"
  10.364 +  by (cases X, cases Y) (auto simp: zero_le_mult_iff)
  10.365 +
  10.366 +lemma Real_mult_nonneg: assumes "x \<ge> 0" "y \<ge> 0"
  10.367 +  shows "Real (x * y) = Real x * Real y" using assms by auto
  10.368 +
  10.369 +lemma Real_setprod: assumes "\<forall>x\<in>A. f x \<ge> 0" shows "Real (setprod f A) = setprod (\<lambda>x. Real (f x)) A"
  10.370 +proof(cases "finite A")
  10.371 +  case True thus ?thesis using assms
  10.372 +  proof(induct A) case (insert x A)
  10.373 +    have "0 \<le> setprod f A" apply(rule setprod_nonneg) using insert by auto
  10.374 +    thus ?case unfolding setprod_insert[OF insert(1-2)] apply-
  10.375 +      apply(subst Real_mult_nonneg) prefer 3 apply(subst insert(3)[THEN sym])
  10.376 +      using insert by auto
  10.377 +  qed auto
  10.378 +qed auto
  10.379 +
  10.380 +subsection "@{typ pextreal} is a linear order"
  10.381 +
  10.382 +instantiation pextreal :: linorder
  10.383 +begin
  10.384 +
  10.385 +definition "x < y \<longleftrightarrow> pextreal_case (\<lambda>i. pextreal_case (\<lambda>j. i < j) True y) False x"
  10.386 +definition "x \<le> y \<longleftrightarrow> pextreal_case (\<lambda>j. pextreal_case (\<lambda>i. i \<le> j) False x) True y"
  10.387 +
  10.388 +lemma pextreal_less[simp]:
  10.389 +  "Real r < \<omega>"
  10.390 +  "Real r < Real p \<longleftrightarrow> (if 0 \<le> r \<and> 0 \<le> p then r < p else 0 < p)"
  10.391 +  "\<omega> < x \<longleftrightarrow> False"
  10.392 +  "0 < \<omega>"
  10.393 +  "0 < Real r \<longleftrightarrow> 0 < r"
  10.394 +  "x < 0 \<longleftrightarrow> False"
  10.395 +  "0 < (1::pextreal)"
  10.396 +  by (simp_all add: less_pextreal_def zero_pextreal_def one_pextreal_def del: Real_0 Real_1)
  10.397 +
  10.398 +lemma pextreal_less_eq[simp]:
  10.399 +  "x \<le> \<omega>"
  10.400 +  "Real r \<le> Real p \<longleftrightarrow> (if 0 \<le> r \<and> 0 \<le> p then r \<le> p else r \<le> 0)"
  10.401 +  "0 \<le> x"
  10.402 +  by (simp_all add: less_eq_pextreal_def zero_pextreal_def del: Real_0)
  10.403 +
  10.404 +lemma pextreal_\<omega>_less_eq[simp]:
  10.405 +  "\<omega> \<le> x \<longleftrightarrow> x = \<omega>"
  10.406 +  by (cases x) (simp_all add: not_le less_eq_pextreal_def)
  10.407 +
  10.408 +lemma pextreal_less_eq_zero[simp]:
  10.409 +  "(x::pextreal) \<le> 0 \<longleftrightarrow> x = 0"
  10.410 +  by (cases x) (simp_all add: zero_pextreal_def del: Real_0)
  10.411 +
  10.412 +instance
  10.413 +proof
  10.414 +  fix x :: pextreal
  10.415 +  show "x \<le> x" by (cases x) simp_all
  10.416 +  fix y
  10.417 +  show "(x < y) = (x \<le> y \<and> \<not> y \<le> x)"
  10.418 +    by (cases x, cases y) auto
  10.419 +  show "x \<le> y \<or> y \<le> x "
  10.420 +    by (cases x, cases y) auto
  10.421 +  { assume "x \<le> y" "y \<le> x" thus "x = y"
  10.422 +      by (cases x, cases y) auto }
  10.423 +  { fix z assume "x \<le> y" "y \<le> z"
  10.424 +    thus "x \<le> z" by (cases x, cases y, cases z) auto }
  10.425 +qed
  10.426 +end
  10.427 +
  10.428 +lemma pextreal_zero_lessI[intro]:
  10.429 +  "(a :: pextreal) \<noteq> 0 \<Longrightarrow> 0 < a"
  10.430 +  by (cases a) auto
  10.431 +
  10.432 +lemma pextreal_less_omegaI[intro, simp]:
  10.433 +  "a \<noteq> \<omega> \<Longrightarrow> a < \<omega>"
  10.434 +  by (cases a) auto
  10.435 +
  10.436 +lemma pextreal_plus_eq_0[simp]: "(a :: pextreal) + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
  10.437 +  by (cases a, cases b) auto
  10.438 +
  10.439 +lemma pextreal_le_add1[simp, intro]: "n \<le> n + (m::pextreal)"
  10.440 +  by (cases n, cases m) simp_all
  10.441 +
  10.442 +lemma pextreal_le_add2: "(n::pextreal) + m \<le> k \<Longrightarrow> m \<le> k"
  10.443 +  by (cases n, cases m, cases k) simp_all
  10.444 +
  10.445 +lemma pextreal_le_add3: "(n::pextreal) + m \<le> k \<Longrightarrow> n \<le> k"
  10.446 +  by (cases n, cases m, cases k) simp_all
  10.447 +
  10.448 +lemma pextreal_less_\<omega>: "x < \<omega> \<longleftrightarrow> x \<noteq> \<omega>"
  10.449 +  by (cases x) auto
  10.450 +
  10.451 +lemma pextreal_0_less_mult_iff[simp]:
  10.452 +  fixes x y :: pextreal shows "0 < x * y \<longleftrightarrow> 0 < x \<and> 0 < y"
  10.453 +  by (cases x, cases y) (auto simp: zero_less_mult_iff)
  10.454 +
  10.455 +lemma pextreal_ord_one[simp]:
  10.456 +  "Real p < 1 \<longleftrightarrow> p < 1"
  10.457 +  "Real p \<le> 1 \<longleftrightarrow> p \<le> 1"
  10.458 +  "1 < Real p \<longleftrightarrow> 1 < p"
  10.459 +  "1 \<le> Real p \<longleftrightarrow> 1 \<le> p"
  10.460 +  by (simp_all add: one_pextreal_def del: Real_1)
  10.461 +
  10.462 +subsection {* @{text "x - y"} on @{typ pextreal} *}
  10.463 +
  10.464 +instantiation pextreal :: minus
  10.465 +begin
  10.466 +definition "x - y = (if y < x then THE d. x = y + d else 0 :: pextreal)"
  10.467 +
  10.468 +lemma minus_pextreal_eq:
  10.469 +  "(x - y = (z :: pextreal)) \<longleftrightarrow> (if y < x then x = y + z else z = 0)"
  10.470 +  (is "?diff \<longleftrightarrow> ?if")
  10.471 +proof
  10.472 +  assume ?diff
  10.473 +  thus ?if
  10.474 +  proof (cases "y < x")
  10.475 +    case True
  10.476 +    then obtain p where p: "y = Real p" "0 \<le> p" by (cases y) auto
  10.477 +
  10.478 +    show ?thesis unfolding `?diff`[symmetric] if_P[OF True] minus_pextreal_def
  10.479 +    proof (rule theI2[where Q="\<lambda>d. x = y + d"])
  10.480 +      show "x = y + pextreal_case (\<lambda>r. Real (r - real y)) \<omega> x" (is "x = y + ?d")
  10.481 +        using `y < x` p by (cases x) simp_all
  10.482 +
  10.483 +      fix d assume "x = y + d"
  10.484 +      thus "d = ?d" using `y < x` p by (cases d, cases x) simp_all
  10.485 +    qed simp
  10.486 +  qed (simp add: minus_pextreal_def)
  10.487 +next
  10.488 +  assume ?if
  10.489 +  thus ?diff
  10.490 +  proof (cases "y < x")
  10.491 +    case True
  10.492 +    then obtain p where p: "y = Real p" "0 \<le> p" by (cases y) auto
  10.493 +
  10.494 +    from True `?if` have "x = y + z" by simp
  10.495 +
  10.496 +    show ?thesis unfolding minus_pextreal_def if_P[OF True] unfolding `x = y + z`
  10.497 +    proof (rule the_equality)
  10.498 +      fix d :: pextreal assume "y + z = y + d"
  10.499 +      thus "d = z" using `y < x` p
  10.500 +        by (cases d, cases z) simp_all
  10.501 +    qed simp
  10.502 +  qed (simp add: minus_pextreal_def)
  10.503 +qed
  10.504 +
  10.505 +instance ..
  10.506 +end
  10.507 +
  10.508 +lemma pextreal_minus[simp]:
  10.509 +  "Real r - Real p = (if 0 \<le> r \<and> p < r then if 0 \<le> p then Real (r - p) else Real r else 0)"
  10.510 +  "(A::pextreal) - A = 0"
  10.511 +  "\<omega> - Real r = \<omega>"
  10.512 +  "Real r - \<omega> = 0"
  10.513 +  "A - 0 = A"
  10.514 +  "0 - A = 0"
  10.515 +  by (auto simp: minus_pextreal_eq not_less)
  10.516 +
  10.517 +lemma pextreal_le_epsilon:
  10.518 +  fixes x y :: pextreal
  10.519 +  assumes "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
  10.520 +  shows "x \<le> y"
  10.521 +proof (cases y)
  10.522 +  case (preal r)
  10.523 +  then obtain p where x: "x = Real p" "0 \<le> p"
  10.524 +    using assms[of 1] by (cases x) auto
  10.525 +  { fix e have "0 < e \<Longrightarrow> p \<le> r + e"
  10.526 +      using assms[of "Real e"] preal x by auto }
  10.527 +  hence "p \<le> r" by (rule field_le_epsilon)
  10.528 +  thus ?thesis using preal x by auto
  10.529 +qed simp
  10.530 +
  10.531 +instance pextreal :: "{ordered_comm_semiring, comm_semiring_1}"
  10.532 +proof
  10.533 +  show "0 \<noteq> (1::pextreal)" unfolding zero_pextreal_def one_pextreal_def
  10.534 +    by (simp del: Real_1 Real_0)
  10.535 +
  10.536 +  fix a :: pextreal
  10.537 +  show "0 * a = 0" "a * 0 = 0" by simp_all
  10.538 +
  10.539 +  fix b c :: pextreal
  10.540 +  show "(a + b) * c = a * c + b * c"
  10.541 +    by (cases c, cases a, cases b)
  10.542 +       (auto intro!: arg_cong[where f=Real] simp: field_simps not_le mult_le_0_iff mult_less_0_iff)
  10.543 +
  10.544 +  { assume "a \<le> b" thus "c + a \<le> c + b"
  10.545 +     by (cases c, cases a, cases b) auto }
  10.546 +
  10.547 +  assume "a \<le> b" "0 \<le> c"
  10.548 +  thus "c * a \<le> c * b"
  10.549 +    apply (cases c, cases a, cases b)
  10.550 +    by (auto simp: mult_left_mono mult_le_0_iff mult_less_0_iff not_le)
  10.551 +qed
  10.552 +
  10.553 +lemma mult_\<omega>[simp]: "x * y = \<omega> \<longleftrightarrow> (x = \<omega> \<or> y = \<omega>) \<and> x \<noteq> 0 \<and> y \<noteq> 0"
  10.554 +  by (cases x, cases y) auto
  10.555 +
  10.556 +lemma \<omega>_mult[simp]: "(\<omega> = x * y) = ((x = \<omega> \<or> y = \<omega>) \<and> x \<noteq> 0 \<and> y \<noteq> 0)"
  10.557 +  by (cases x, cases y) auto
  10.558 +
  10.559 +lemma pextreal_mult_0[simp]: "x * y = 0 \<longleftrightarrow> x = 0 \<or> (y::pextreal) = 0"
  10.560 +  by (cases x, cases y) (auto simp: mult_le_0_iff)
  10.561 +
  10.562 +lemma pextreal_mult_cancel:
  10.563 +  fixes x y z :: pextreal
  10.564 +  assumes "y \<le> z"
  10.565 +  shows "x * y \<le> x * z"
  10.566 +  using assms
  10.567 +  by (cases x, cases y, cases z)
  10.568 +     (auto simp: mult_le_cancel_left mult_le_0_iff mult_less_0_iff not_le)
  10.569 +
  10.570 +lemma Real_power[simp]:
  10.571 +  "Real x ^ n = (if x \<le> 0 then (if n = 0 then 1 else 0) else Real (x ^ n))"
  10.572 +  by (induct n) auto
  10.573 +
  10.574 +lemma Real_power_\<omega>[simp]:
  10.575 +  "\<omega> ^ n = (if n = 0 then 1 else \<omega>)"
  10.576 +  by (induct n) auto
  10.577 +
  10.578 +lemma pextreal_of_nat[simp]: "of_nat m = Real (real m)"
  10.579 +  by (induct m) (auto simp: real_of_nat_Suc one_pextreal_def simp del: Real_1)
  10.580 +
  10.581 +lemma less_\<omega>_Ex_of_nat: "x < \<omega> \<longleftrightarrow> (\<exists>n. x < of_nat n)"
  10.582 +proof safe
  10.583 +  assume "x < \<omega>"
  10.584 +  then obtain r where "0 \<le> r" "x = Real r" by (cases x) auto
  10.585 +  moreover obtain n where "r < of_nat n" using ex_less_of_nat by auto
  10.586 +  ultimately show "\<exists>n. x < of_nat n" by (auto simp: real_eq_of_nat)
  10.587 +qed auto
  10.588 +
  10.589 +lemma real_of_pextreal_mono:
  10.590 +  fixes a b :: pextreal
  10.591 +  assumes "b \<noteq> \<omega>" "a \<le> b"
  10.592 +  shows "real a \<le> real b"
  10.593 +using assms by (cases b, cases a) auto
  10.594 +
  10.595 +lemma setprod_pextreal_0:
  10.596 +  "(\<Prod>i\<in>I. f i) = (0::pextreal) \<longleftrightarrow> finite I \<and> (\<exists>i\<in>I. f i = 0)"
  10.597 +proof cases
  10.598 +  assume "finite I" then show ?thesis
  10.599 +  proof (induct I)
  10.600 +    case (insert i I)
  10.601 +    then show ?case by simp
  10.602 +  qed simp
  10.603 +qed simp
  10.604 +
  10.605 +lemma setprod_\<omega>:
  10.606 +  "(\<Prod>i\<in>I. f i) = \<omega> \<longleftrightarrow> finite I \<and> (\<exists>i\<in>I. f i = \<omega>) \<and> (\<forall>i\<in>I. f i \<noteq> 0)"
  10.607 +proof cases
  10.608 +  assume "finite I" then show ?thesis
  10.609 +  proof (induct I)
  10.610 +    case (insert i I) then show ?case
  10.611 +      by (auto simp: setprod_pextreal_0)
  10.612 +  qed simp
  10.613 +qed simp
  10.614 +
  10.615 +instance pextreal :: "semiring_char_0"
  10.616 +proof
  10.617 +  fix m n
  10.618 +  show "inj (of_nat::nat\<Rightarrow>pextreal)" by (auto intro!: inj_onI)
  10.619 +qed
  10.620 +
  10.621 +subsection "@{typ pextreal} is a complete lattice"
  10.622 +
  10.623 +instantiation pextreal :: lattice
  10.624 +begin
  10.625 +definition [simp]: "sup x y = (max x y :: pextreal)"
  10.626 +definition [simp]: "inf x y = (min x y :: pextreal)"
  10.627 +instance proof qed simp_all
  10.628 +end
  10.629 +
  10.630 +instantiation pextreal :: complete_lattice
  10.631 +begin
  10.632 +
  10.633 +definition "bot = Real 0"
  10.634 +definition "top = \<omega>"
  10.635 +
  10.636 +definition "Sup S = (LEAST z. \<forall>x\<in>S. x \<le> z :: pextreal)"
  10.637 +definition "Inf S = (GREATEST z. \<forall>x\<in>S. z \<le> x :: pextreal)"
  10.638 +
  10.639 +lemma pextreal_complete_Sup:
  10.640 +  fixes S :: "pextreal set" assumes "S \<noteq> {}"
  10.641 +  shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>S. y \<le> z) \<longrightarrow> x \<le> z)"
  10.642 +proof (cases "\<exists>x\<ge>0. \<forall>a\<in>S. a \<le> Real x")
  10.643 +  case False
  10.644 +  hence *: "\<And>x. x\<ge>0 \<Longrightarrow> \<exists>a\<in>S. \<not>a \<le> Real x" by simp
  10.645 +  show ?thesis
  10.646 +  proof (safe intro!: exI[of _ \<omega>])
  10.647 +    fix y assume **: "\<forall>z\<in>S. z \<le> y"
  10.648 +    show "\<omega> \<le> y" unfolding pextreal_\<omega>_less_eq
  10.649 +    proof (rule ccontr)
  10.650 +      assume "y \<noteq> \<omega>"
  10.651 +      then obtain x where [simp]: "y = Real x" and "0 \<le> x" by (cases y) auto
  10.652 +      from *[OF `0 \<le> x`] show False using ** by auto
  10.653 +    qed
  10.654 +  qed simp
  10.655 +next
  10.656 +  case True then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> Real y" and "0 \<le> y" by auto
  10.657 +  from y[of \<omega>] have "\<omega> \<notin> S" by auto
  10.658 +
  10.659 +  with `S \<noteq> {}` obtain x where "x \<in> S" and "x \<noteq> \<omega>" by auto
  10.660 +
  10.661 +  have bound: "\<forall>x\<in>real ` S. x \<le> y"
  10.662 +  proof
  10.663 +    fix z assume "z \<in> real ` S" then guess a ..
  10.664 +    with y[of a] `\<omega> \<notin> S` `0 \<le> y` show "z \<le> y" by (cases a) auto
  10.665 +  qed
  10.666 +  with reals_complete2[of "real ` S"] `x \<in> S`
  10.667 +  obtain s where s: "\<forall>y\<in>S. real y \<le> s" "\<forall>z. ((\<forall>y\<in>S. real y \<le> z) \<longrightarrow> s \<le> z)"
  10.668 +    by auto
  10.669 +
  10.670 +  show ?thesis
  10.671 +  proof (safe intro!: exI[of _ "Real s"])
  10.672 +    fix z assume "z \<in> S" thus "z \<le> Real s"
  10.673 +      using s `\<omega> \<notin> S` by (cases z) auto
  10.674 +  next
  10.675 +    fix z assume *: "\<forall>y\<in>S. y \<le> z"
  10.676 +    show "Real s \<le> z"
  10.677 +    proof (cases z)
  10.678 +      case (preal u)
  10.679 +      { fix v assume "v \<in> S"
  10.680 +        hence "v \<le> Real u" using * preal by auto
  10.681 +        hence "real v \<le> u" using `\<omega> \<notin> S` `0 \<le> u` by (cases v) auto }
  10.682 +      hence "s \<le> u" using s(2) by auto
  10.683 +      thus "Real s \<le> z" using preal by simp
  10.684 +    qed simp
  10.685 +  qed
  10.686 +qed
  10.687 +
  10.688 +lemma pextreal_complete_Inf:
  10.689 +  fixes S :: "pextreal set" assumes "S \<noteq> {}"
  10.690 +  shows "\<exists>x. (\<forall>y\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> x)"
  10.691 +proof (cases "S = {\<omega>}")
  10.692 +  case True thus ?thesis by (auto intro!: exI[of _ \<omega>])
  10.693 +next
  10.694 +  case False with `S \<noteq> {}` have "S - {\<omega>} \<noteq> {}" by auto
  10.695 +  hence not_empty: "\<exists>x. x \<in> uminus ` real ` (S - {\<omega>})" by auto
  10.696 +  have bounds: "\<exists>x. \<forall>y\<in>uminus ` real ` (S - {\<omega>}). y \<le> x" by (auto intro!: exI[of _ 0])
  10.697 +  from reals_complete2[OF not_empty bounds]
  10.698 +  obtain s where s: "\<And>y. y\<in>S - {\<omega>} \<Longrightarrow> - real y \<le> s" "\<forall>z. ((\<forall>y\<in>S - {\<omega>}. - real y \<le> z) \<longrightarrow> s \<le> z)"
  10.699 +    by auto
  10.700 +
  10.701 +  show ?thesis
  10.702 +  proof (safe intro!: exI[of _ "Real (-s)"])
  10.703 +    fix z assume "z \<in> S"
  10.704 +    show "Real (-s) \<le> z"
  10.705 +    proof (cases z)
  10.706 +      case (preal r)
  10.707 +      with s `z \<in> S` have "z \<in> S - {\<omega>}" by simp
  10.708 +      hence "- r \<le> s" using preal s(1)[of z] by auto
  10.709 +      hence "- s \<le> r" by (subst neg_le_iff_le[symmetric]) simp
  10.710 +      thus ?thesis using preal by simp
  10.711 +    qed simp
  10.712 +  next
  10.713 +    fix z assume *: "\<forall>y\<in>S. z \<le> y"
  10.714 +    show "z \<le> Real (-s)"
  10.715 +    proof (cases z)
  10.716 +      case (preal u)
  10.717 +      { fix v assume "v \<in> S-{\<omega>}"
  10.718 +        hence "Real u \<le> v" using * preal by auto
  10.719 +        hence "- real v \<le> - u" using `0 \<le> u` `v \<in> S - {\<omega>}` by (cases v) auto }
  10.720 +      hence "u \<le> - s" using s(2) by (subst neg_le_iff_le[symmetric]) auto
  10.721 +      thus "z \<le> Real (-s)" using preal by simp
  10.722 +    next
  10.723 +      case infinite
  10.724 +      with * have "S = {\<omega>}" using `S \<noteq> {}` by auto
  10.725 +      with `S - {\<omega>} \<noteq> {}` show ?thesis by simp
  10.726 +    qed
  10.727 +  qed
  10.728 +qed
  10.729 +
  10.730 +instance
  10.731 +proof
  10.732 +  fix x :: pextreal and A
  10.733 +
  10.734 +  show "bot \<le> x" by (cases x) (simp_all add: bot_pextreal_def)
  10.735 +  show "x \<le> top" by (simp add: top_pextreal_def)
  10.736 +
  10.737 +  { assume "x \<in> A"
  10.738 +    with pextreal_complete_Sup[of A]
  10.739 +    obtain s where s: "\<forall>y\<in>A. y \<le> s" "\<forall>z. (\<forall>y\<in>A. y \<le> z) \<longrightarrow> s \<le> z" by auto
  10.740 +    hence "x \<le> s" using `x \<in> A` by auto
  10.741 +    also have "... = Sup A" using s unfolding Sup_pextreal_def
  10.742 +      by (auto intro!: Least_equality[symmetric])
  10.743 +    finally show "x \<le> Sup A" . }
  10.744 +
  10.745 +  { assume "x \<in> A"
  10.746 +    with pextreal_complete_Inf[of A]
  10.747 +    obtain i where i: "\<forall>y\<in>A. i \<le> y" "\<forall>z. (\<forall>y\<in>A. z \<le> y) \<longrightarrow> z \<le> i" by auto
  10.748 +    hence "Inf A = i" unfolding Inf_pextreal_def
  10.749 +      by (auto intro!: Greatest_equality)
  10.750 +    also have "i \<le> x" using i `x \<in> A` by auto
  10.751 +    finally show "Inf A \<le> x" . }
  10.752 +
  10.753 +  { assume *: "\<And>z. z \<in> A \<Longrightarrow> z \<le> x"
  10.754 +    show "Sup A \<le> x"
  10.755 +    proof (cases "A = {}")
  10.756 +      case True
  10.757 +      hence "Sup A = 0" unfolding Sup_pextreal_def
  10.758 +        by (auto intro!: Least_equality)
  10.759 +      thus "Sup A \<le> x" by simp
  10.760 +    next
  10.761 +      case False
  10.762 +      with pextreal_complete_Sup[of A]
  10.763 +      obtain s where s: "\<forall>y\<in>A. y \<le> s" "\<forall>z. (\<forall>y\<in>A. y \<le> z) \<longrightarrow> s \<le> z" by auto
  10.764 +      hence "Sup A = s"
  10.765 +        unfolding Sup_pextreal_def by (auto intro!: Least_equality)
  10.766 +      also have "s \<le> x" using * s by auto
  10.767 +      finally show "Sup A \<le> x" .
  10.768 +    qed }
  10.769 +
  10.770 +  { assume *: "\<And>z. z \<in> A \<Longrightarrow> x \<le> z"
  10.771 +    show "x \<le> Inf A"
  10.772 +    proof (cases "A = {}")
  10.773 +      case True
  10.774 +      hence "Inf A = \<omega>" unfolding Inf_pextreal_def
  10.775 +        by (auto intro!: Greatest_equality)
  10.776 +      thus "x \<le> Inf A" by simp
  10.777 +    next
  10.778 +      case False
  10.779 +      with pextreal_complete_Inf[of A]
  10.780 +      obtain i where i: "\<forall>y\<in>A. i \<le> y" "\<forall>z. (\<forall>y\<in>A. z \<le> y) \<longrightarrow> z \<le> i" by auto
  10.781 +      have "x \<le> i" using * i by auto
  10.782 +      also have "i = Inf A" using i
  10.783 +        unfolding Inf_pextreal_def by (auto intro!: Greatest_equality[symmetric])
  10.784 +      finally show "x \<le> Inf A" .
  10.785 +    qed }
  10.786 +qed
  10.787 +end
  10.788 +
  10.789 +lemma Inf_pextreal_iff:
  10.790 +  fixes z :: pextreal
  10.791 +  shows "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> (\<exists>x\<in>X. x<y) \<longleftrightarrow> Inf X < y"
  10.792 +  by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower less_le_not_le linear
  10.793 +            order_less_le_trans)
  10.794 +
  10.795 +lemma Inf_greater:
  10.796 +  fixes z :: pextreal assumes "Inf X < z"
  10.797 +  shows "\<exists>x \<in> X. x < z"
  10.798 +proof -
  10.799 +  have "X \<noteq> {}" using assms by (auto simp: Inf_empty top_pextreal_def)
  10.800 +  with assms show ?thesis
  10.801 +    by (metis Inf_pextreal_iff mem_def not_leE)
  10.802 +qed
  10.803 +
  10.804 +lemma Inf_close:
  10.805 +  fixes e :: pextreal assumes "Inf X \<noteq> \<omega>" "0 < e"
  10.806 +  shows "\<exists>x \<in> X. x < Inf X + e"
  10.807 +proof (rule Inf_greater)
  10.808 +  show "Inf X < Inf X + e" using assms
  10.809 +    by (cases "Inf X", cases e) auto
  10.810 +qed
  10.811 +
  10.812 +lemma pextreal_SUPI:
  10.813 +  fixes x :: pextreal
  10.814 +  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<le> x"
  10.815 +  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> f i \<le> y) \<Longrightarrow> x \<le> y"
  10.816 +  shows "(SUP i:A. f i) = x"
  10.817 +  unfolding SUPR_def Sup_pextreal_def
  10.818 +  using assms by (auto intro!: Least_equality)
  10.819 +
  10.820 +lemma Sup_pextreal_iff:
  10.821 +  fixes z :: pextreal
  10.822 +  shows "(\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> (\<exists>x\<in>X. y<x) \<longleftrightarrow> y < Sup X"
  10.823 +  by (metis complete_lattice_class.Sup_least complete_lattice_class.Sup_upper less_le_not_le linear
  10.824 +            order_less_le_trans)
  10.825 +
  10.826 +lemma Sup_lesser:
  10.827 +  fixes z :: pextreal assumes "z < Sup X"
  10.828 +  shows "\<exists>x \<in> X. z < x"
  10.829 +proof -
  10.830 +  have "X \<noteq> {}" using assms by (auto simp: Sup_empty bot_pextreal_def)
  10.831 +  with assms show ?thesis
  10.832 +    by (metis Sup_pextreal_iff mem_def not_leE)
  10.833 +qed
  10.834 +
  10.835 +lemma Sup_eq_\<omega>: "\<omega> \<in> S \<Longrightarrow> Sup S = \<omega>"
  10.836 +  unfolding Sup_pextreal_def
  10.837 +  by (auto intro!: Least_equality)
  10.838 +
  10.839 +lemma Sup_close:
  10.840 +  assumes "0 < e" and S: "Sup S \<noteq> \<omega>" "S \<noteq> {}"
  10.841 +  shows "\<exists>X\<in>S. Sup S < X + e"
  10.842 +proof cases
  10.843 +  assume "Sup S = 0"
  10.844 +  moreover obtain X where "X \<in> S" using `S \<noteq> {}` by auto
  10.845 +  ultimately show ?thesis using `0 < e` by (auto intro!: bexI[OF _ `X\<in>S`])
  10.846 +next
  10.847 +  assume "Sup S \<noteq> 0"
  10.848 +  have "\<exists>X\<in>S. Sup S - e < X"
  10.849 +  proof (rule Sup_lesser)
  10.850 +    show "Sup S - e < Sup S" using `0 < e` `Sup S \<noteq> 0` `Sup S \<noteq> \<omega>`
  10.851 +      by (cases e) (auto simp: pextreal_noteq_omega_Ex)
  10.852 +  qed
  10.853 +  then guess X .. note X = this
  10.854 +  with `Sup S \<noteq> \<omega>` Sup_eq_\<omega> have "X \<noteq> \<omega>" by auto
  10.855 +  thus ?thesis using `Sup S \<noteq> \<omega>` X unfolding pextreal_noteq_omega_Ex
  10.856 +    by (cases e) (auto intro!: bexI[OF _ `X\<in>S`] simp: split: split_if_asm)
  10.857 +qed
  10.858 +
  10.859 +lemma Sup_\<omega>: "(SUP i::nat. Real (real i)) = \<omega>"
  10.860 +proof (rule pextreal_SUPI)
  10.861 +  fix y assume *: "\<And>i::nat. i \<in> UNIV \<Longrightarrow> Real (real i) \<le> y"
  10.862 +  thus "\<omega> \<le> y"
  10.863 +  proof (cases y)
  10.864 +    case (preal r)
  10.865 +    then obtain k :: nat where "r < real k"
  10.866 +      using ex_less_of_nat by (auto simp: real_eq_of_nat)
  10.867 +    with *[of k] preal show ?thesis by auto
  10.868 +  qed simp
  10.869 +qed simp
  10.870 +
  10.871 +lemma SUP_\<omega>: "(SUP i:A. f i) = \<omega> \<longleftrightarrow> (\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)"
  10.872 +proof
  10.873 +  assume *: "(SUP i:A. f i) = \<omega>"
  10.874 +  show "(\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)" unfolding *[symmetric]
  10.875 +  proof (intro allI impI)
  10.876 +    fix x assume "x < SUPR A f" then show "\<exists>i\<in>A. x < f i"
  10.877 +      unfolding less_SUP_iff by auto
  10.878 +  qed
  10.879 +next
  10.880 +  assume *: "\<forall>x<\<omega>. \<exists>i\<in>A. x < f i"
  10.881 +  show "(SUP i:A. f i) = \<omega>"
  10.882 +  proof (rule pextreal_SUPI)
  10.883 +    fix y assume **: "\<And>i. i \<in> A \<Longrightarrow> f i \<le> y"
  10.884 +    show "\<omega> \<le> y"
  10.885 +    proof cases
  10.886 +      assume "y < \<omega>"
  10.887 +      from *[THEN spec, THEN mp, OF this]
  10.888 +      obtain i where "i \<in> A" "\<not> (f i \<le> y)" by auto
  10.889 +      with ** show ?thesis by auto
  10.890 +    qed auto
  10.891 +  qed auto
  10.892 +qed
  10.893 +
  10.894 +subsubsection {* Equivalence between @{text "f ----> x"} and @{text SUP} on @{typ pextreal} *}
  10.895 +
  10.896 +lemma monoseq_monoI: "mono f \<Longrightarrow> monoseq f"
  10.897 +  unfolding mono_def monoseq_def by auto
  10.898 +
  10.899 +lemma incseq_mono: "mono f \<longleftrightarrow> incseq f"
  10.900 +  unfolding mono_def incseq_def by auto
  10.901 +
  10.902 +lemma SUP_eq_LIMSEQ:
  10.903 +  assumes "mono f" and "\<And>n. 0 \<le> f n" and "0 \<le> x"
  10.904 +  shows "(SUP n. Real (f n)) = Real x \<longleftrightarrow> f ----> x"
  10.905 +proof
  10.906 +  assume x: "(SUP n. Real (f n)) = Real x"
  10.907 +  { fix n
  10.908 +    have "Real (f n) \<le> Real x" using x[symmetric] by (auto intro: le_SUPI)
  10.909 +    hence "f n \<le> x" using assms by simp }
  10.910 +  show "f ----> x"
  10.911 +  proof (rule LIMSEQ_I)
  10.912 +    fix r :: real assume "0 < r"
  10.913 +    show "\<exists>no. \<forall>n\<ge>no. norm (f n - x) < r"
  10.914 +    proof (rule ccontr)
  10.915 +      assume *: "\<not> ?thesis"
  10.916 +      { fix N
  10.917 +        from * obtain n where "N \<le> n" "r \<le> x - f n"
  10.918 +          using `\<And>n. f n \<le> x` by (auto simp: not_less)
  10.919 +        hence "f N \<le> f n" using `mono f` by (auto dest: monoD)
  10.920 +        hence "f N \<le> x - r" using `r \<le> x - f n` by auto
  10.921 +        hence "Real (f N) \<le> Real (x - r)" and "r \<le> x" using `0 \<le> f N` by auto }
  10.922 +      hence "(SUP n. Real (f n)) \<le> Real (x - r)"
  10.923 +        and "Real (x - r) < Real x" using `0 < r` by (auto intro: SUP_leI)
  10.924 +      hence "(SUP n. Real (f n)) < Real x" by (rule le_less_trans)
  10.925 +      thus False using x by auto
  10.926 +    qed
  10.927 +  qed
  10.928 +next
  10.929 +  assume "f ----> x"
  10.930 +  show "(SUP n. Real (f n)) = Real x"
  10.931 +  proof (rule pextreal_SUPI)
  10.932 +    fix n
  10.933 +    from incseq_le[of f x] `mono f` `f ----> x`
  10.934 +    show "Real (f n) \<le> Real x" using assms incseq_mono by auto
  10.935 +  next
  10.936 +    fix y assume *: "\<And>n. n\<in>UNIV \<Longrightarrow> Real (f n) \<le> y"
  10.937 +    show "Real x \<le> y"
  10.938 +    proof (cases y)
  10.939 +      case (preal r)
  10.940 +      with * have "\<exists>N. \<forall>n\<ge>N. f n \<le> r" using assms by fastsimp
  10.941 +      from LIMSEQ_le_const2[OF `f ----> x` this]
  10.942 +      show "Real x \<le> y" using `0 \<le> x` preal by auto
  10.943 +    qed simp
  10.944 +  qed
  10.945 +qed
  10.946 +
  10.947 +lemma SUPR_bound:
  10.948 +  assumes "\<forall>N. f N \<le> x"
  10.949 +  shows "(SUP n. f n) \<le> x"
  10.950 +  using assms by (simp add: SUPR_def Sup_le_iff)
  10.951 +
  10.952 +lemma pextreal_less_eq_diff_eq_sum:
  10.953 +  fixes x y z :: pextreal
  10.954 +  assumes "y \<le> x" and "x \<noteq> \<omega>"
  10.955 +  shows "z \<le> x - y \<longleftrightarrow> z + y \<le> x"
  10.956 +  using assms
  10.957 +  apply (cases z, cases y, cases x)
  10.958 +  by (simp_all add: field_simps minus_pextreal_eq)
  10.959 +
  10.960 +lemma Real_diff_less_omega: "Real r - x < \<omega>" by (cases x) auto
  10.961 +
  10.962 +subsubsection {* Numbers on @{typ pextreal} *}
  10.963 +
  10.964 +instantiation pextreal :: number
  10.965 +begin
  10.966 +definition [simp]: "number_of x = Real (number_of x)"
  10.967 +instance proof qed
  10.968 +end
  10.969 +
  10.970 +subsubsection {* Division on @{typ pextreal} *}
  10.971 +
  10.972 +instantiation pextreal :: inverse
  10.973 +begin
  10.974 +
  10.975 +definition "inverse x = pextreal_case (\<lambda>x. if x = 0 then \<omega> else Real (inverse x)) 0 x"
  10.976 +definition [simp]: "x / y = x * inverse (y :: pextreal)"
  10.977 +
  10.978 +instance proof qed
  10.979 +end
  10.980 +
  10.981 +lemma pextreal_inverse[simp]:
  10.982 +  "inverse 0 = \<omega>"
  10.983 +  "inverse (Real x) = (if x \<le> 0 then \<omega> else Real (inverse x))"
  10.984 +  "inverse \<omega> = 0"
  10.985 +  "inverse (1::pextreal) = 1"
  10.986 +  "inverse (inverse x) = x"
  10.987 +  by (simp_all add: inverse_pextreal_def one_pextreal_def split: pextreal_case_split del: Real_1)
  10.988 +
  10.989 +lemma pextreal_inverse_le_eq:
  10.990 +  assumes "x \<noteq> 0" "x \<noteq> \<omega>"
  10.991 +  shows "y \<le> z / x \<longleftrightarrow> x * y \<le> (z :: pextreal)"
  10.992 +proof -
  10.993 +  from assms obtain r where r: "x = Real r" "0 < r" by (cases x) auto
  10.994 +  { fix p q :: real assume "0 \<le> p" "0 \<le> q"
  10.995 +    have "p \<le> q * inverse r \<longleftrightarrow> p \<le> q / r" by (simp add: divide_inverse)
  10.996 +    also have "... \<longleftrightarrow> p * r \<le> q" using `0 < r` by (auto simp: field_simps)
  10.997 +    finally have "p \<le> q * inverse r \<longleftrightarrow> p * r \<le> q" . }
  10.998 +  with r show ?thesis
  10.999 +    by (cases y, cases z, auto simp: zero_le_mult_iff field_simps)
 10.1000 +qed
 10.1001 +
 10.1002 +lemma inverse_antimono_strict:
 10.1003 +  fixes x y :: pextreal
 10.1004 +  assumes "x < y" shows "inverse y < inverse x"
 10.1005 +  using assms by (cases x, cases y) auto
 10.1006 +
 10.1007 +lemma inverse_antimono:
 10.1008 +  fixes x y :: pextreal
 10.1009 +  assumes "x \<le> y" shows "inverse y \<le> inverse x"
 10.1010 +  using assms by (cases x, cases y) auto
 10.1011 +
 10.1012 +lemma pextreal_inverse_\<omega>_iff[simp]: "inverse x = \<omega> \<longleftrightarrow> x = 0"
 10.1013 +  by (cases x) auto
 10.1014 +
 10.1015 +subsection "Infinite sum over @{typ pextreal}"
 10.1016 +
 10.1017 +text {*
 10.1018 +
 10.1019 +The infinite sum over @{typ pextreal} has the nice property that it is always
 10.1020 +defined.
 10.1021 +
 10.1022 +*}
 10.1023 +
 10.1024 +definition psuminf :: "(nat \<Rightarrow> pextreal) \<Rightarrow> pextreal" (binder "\<Sum>\<^isub>\<infinity>" 10) where
 10.1025 +  "(\<Sum>\<^isub>\<infinity> x. f x) = (SUP n. \<Sum>i<n. f i)"
 10.1026 +
 10.1027 +subsubsection {* Equivalence between @{text "\<Sum> n. f n"} and @{text "\<Sum>\<^isub>\<infinity> n. f n"} *}
 10.1028 +
 10.1029 +lemma setsum_Real:
 10.1030 +  assumes "\<forall>x\<in>A. 0 \<le> f x"
 10.1031 +  shows "(\<Sum>x\<in>A. Real (f x)) = Real (\<Sum>x\<in>A. f x)"
 10.1032 +proof (cases "finite A")
 10.1033 +  case True
 10.1034 +  thus ?thesis using assms
 10.1035 +  proof induct case (insert x s)
 10.1036 +    hence "0 \<le> setsum f s" apply-apply(rule setsum_nonneg) by auto
 10.1037 +    thus ?case using insert by auto
 10.1038 +  qed auto
 10.1039 +qed simp
 10.1040 +
 10.1041 +lemma setsum_Real':
 10.1042 +  assumes "\<forall>x. 0 \<le> f x"
 10.1043 +  shows "(\<Sum>x\<in>A. Real (f x)) = Real (\<Sum>x\<in>A. f x)"
 10.1044 +  apply(rule setsum_Real) using assms by auto
 10.1045 +
 10.1046 +lemma setsum_\<omega>:
 10.1047 +  "(\<Sum>x\<in>P. f x) = \<omega> \<longleftrightarrow> (finite P \<and> (\<exists>i\<in>P. f i = \<omega>))"
 10.1048 +proof safe
 10.1049 +  assume *: "setsum f P = \<omega>"
 10.1050 +  show "finite P"
 10.1051 +  proof (rule ccontr) assume "infinite P" with * show False by auto qed
 10.1052 +  show "\<exists>i\<in>P. f i = \<omega>"
 10.1053 +  proof (rule ccontr)
 10.1054 +    assume "\<not> ?thesis" hence "\<And>i. i\<in>P \<Longrightarrow> f i \<noteq> \<omega>" by auto
 10.1055 +    from `finite P` this have "setsum f P \<noteq> \<omega>"
 10.1056 +      by induct auto
 10.1057 +    with * show False by auto
 10.1058 +  qed
 10.1059 +next
 10.1060 +  fix i assume "finite P" "i \<in> P" "f i = \<omega>"
 10.1061 +  thus "setsum f P = \<omega>"
 10.1062 +  proof induct
 10.1063 +    case (insert x A)
 10.1064 +    show ?case using insert by (cases "x = i") auto
 10.1065 +  qed simp
 10.1066 +qed
 10.1067 +
 10.1068 +lemma real_of_pextreal_setsum:
 10.1069 +  assumes "\<And>x. x \<in> S \<Longrightarrow> f x \<noteq> \<omega>"
 10.1070 +  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
 10.1071 +proof cases
 10.1072 +  assume "finite S"
 10.1073 +  from this assms show ?thesis
 10.1074 +    by induct (simp_all add: real_of_pextreal_add setsum_\<omega>)
 10.1075 +qed simp
 10.1076 +
 10.1077 +lemma setsum_0:
 10.1078 +  fixes f :: "'a \<Rightarrow> pextreal" assumes "finite A"
 10.1079 +  shows "(\<Sum>x\<in>A. f x) = 0 \<longleftrightarrow> (\<forall>i\<in>A. f i = 0)"
 10.1080 +  using assms by induct auto
 10.1081 +
 10.1082 +lemma suminf_imp_psuminf:
 10.1083 +  assumes "f sums x" and "\<forall>n. 0 \<le> f n"
 10.1084 +  shows "(\<Sum>\<^isub>\<infinity> x. Real (f x)) = Real x"
 10.1085 +  unfolding psuminf_def setsum_Real'[OF assms(2)]
 10.1086 +proof (rule SUP_eq_LIMSEQ[THEN iffD2])
 10.1087 +  show "mono (\<lambda>n. setsum f {..<n})" (is "mono ?S")
 10.1088 +    unfolding mono_iff_le_Suc using assms by simp
 10.1089 +
 10.1090 +  { fix n show "0 \<le> ?S n"
 10.1091 +      using setsum_nonneg[of "{..<n}" f] assms by auto }
 10.1092 +
 10.1093 +  thus "0 \<le> x" "?S ----> x"
 10.1094 +    using `f sums x` LIMSEQ_le_const
 10.1095 +    by (auto simp: atLeast0LessThan sums_def)
 10.1096 +qed
 10.1097 +
 10.1098 +lemma psuminf_equality:
 10.1099 +  assumes "\<And>n. setsum f {..<n} \<le> x"
 10.1100 +  and "\<And>y. y \<noteq> \<omega> \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> y) \<Longrightarrow> x \<le> y"
 10.1101 +  shows "psuminf f = x"
 10.1102 +  unfolding psuminf_def
 10.1103 +proof (safe intro!: pextreal_SUPI)
 10.1104 +  fix n show "setsum f {..<n} \<le> x" using assms(1) .
 10.1105 +next
 10.1106 +  fix y assume *: "\<forall>n. n \<in> UNIV \<longrightarrow> setsum f {..<n} \<le> y"
 10.1107 +  show "x \<le> y"
 10.1108 +  proof (cases "y = \<omega>")
 10.1109 +    assume "y \<noteq> \<omega>" from assms(2)[OF this] *
 10.1110 +    show "x \<le> y" by auto
 10.1111 +  qed simp
 10.1112 +qed
 10.1113 +
 10.1114 +lemma psuminf_\<omega>:
 10.1115 +  assumes "f i = \<omega>"
 10.1116 +  shows "(\<Sum>\<^isub>\<infinity> x. f x) = \<omega>"
 10.1117 +proof (rule psuminf_equality)
 10.1118 +  fix y assume *: "\<And>n. setsum f {..<n} \<le> y"
 10.1119 +  have "setsum f {..<Suc i} = \<omega>" 
 10.1120 +    using assms by (simp add: setsum_\<omega>)
 10.1121 +  thus "\<omega> \<le> y" using *[of "Suc i"] by auto
 10.1122 +qed simp
 10.1123 +
 10.1124 +lemma psuminf_imp_suminf:
 10.1125 +  assumes "(\<Sum>\<^isub>\<infinity> x. f x) \<noteq> \<omega>"
 10.1126 +  shows "(\<lambda>x. real (f x)) sums real (\<Sum>\<^isub>\<infinity> x. f x)"
 10.1127 +proof -
 10.1128 +  have "\<forall>i. \<exists>r. f i = Real r \<and> 0 \<le> r"
 10.1129 +  proof
 10.1130 +    fix i show "\<exists>r. f i = Real r \<and> 0 \<le> r" using psuminf_\<omega> assms by (cases "f i") auto
 10.1131 +  qed
 10.1132 +  from choice[OF this] obtain r where f: "f = (\<lambda>i. Real (r i))"
 10.1133 +    and pos: "\<forall>i. 0 \<le> r i"
 10.1134 +    by (auto simp: fun_eq_iff)
 10.1135 +  hence [simp]: "\<And>i. real (f i) = r i" by auto
 10.1136 +
 10.1137 +  have "mono (\<lambda>n. setsum r {..<n})" (is "mono ?S")
 10.1138 +    unfolding mono_iff_le_Suc using pos by simp
 10.1139 +
 10.1140 +  { fix n have "0 \<le> ?S n"
 10.1141 +      using setsum_nonneg[of "{..<n}" r] pos by auto }
 10.1142 +
 10.1143 +  from assms obtain p where *: "(\<Sum>\<^isub>\<infinity> x. f x) = Real p" and "0 \<le> p"
 10.1144 +    by (cases "(\<Sum>\<^isub>\<infinity> x. f x)") auto
 10.1145 +  show ?thesis unfolding * using * pos `0 \<le> p` SUP_eq_LIMSEQ[OF `mono ?S` `\<And>n. 0 \<le> ?S n` `0 \<le> p`]
 10.1146 +    by (simp add: f atLeast0LessThan sums_def psuminf_def setsum_Real'[OF pos] f)
 10.1147 +qed
 10.1148 +
 10.1149 +lemma psuminf_bound:
 10.1150 +  assumes "\<forall>N. (\<Sum>n<N. f n) \<le> x"
 10.1151 +  shows "(\<Sum>\<^isub>\<infinity> n. f n) \<le> x"
 10.1152 +  using assms by (simp add: psuminf_def SUPR_def Sup_le_iff)
 10.1153 +
 10.1154 +lemma psuminf_bound_add:
 10.1155 +  assumes "\<forall>N. (\<Sum>n<N. f n) + y \<le> x"
 10.1156 +  shows "(\<Sum>\<^isub>\<infinity> n. f n) + y \<le> x"
 10.1157 +proof (cases "x = \<omega>")
 10.1158 +  have "y \<le> x" using assms by (auto intro: pextreal_le_add2)
 10.1159 +  assume "x \<noteq> \<omega>"
 10.1160 +  note move_y = pextreal_less_eq_diff_eq_sum[OF `y \<le> x` this]
 10.1161 +
 10.1162 +  have "\<forall>N. (\<Sum>n<N. f n) \<le> x - y" using assms by (simp add: move_y)
 10.1163 +  hence "(\<Sum>\<^isub>\<infinity> n. f n) \<le> x - y" by (rule psuminf_bound)
 10.1164 +  thus ?thesis by (simp add: move_y)
 10.1165 +qed simp
 10.1166 +
 10.1167 +lemma psuminf_finite:
 10.1168 +  assumes "\<forall>N\<ge>n. f N = 0"
 10.1169 +  shows "(\<Sum>\<^isub>\<infinity> n. f n) = (\<Sum>N<n. f N)"
 10.1170 +proof (rule psuminf_equality)
 10.1171 +  fix N
 10.1172 +  show "setsum f {..<N} \<le> setsum f {..<n}"
 10.1173 +  proof (cases rule: linorder_cases)
 10.1174 +    assume "N < n" thus ?thesis by (auto intro!: setsum_mono3)
 10.1175 +  next
 10.1176 +    assume "n < N"
 10.1177 +    hence *: "{..<N} = {..<n} \<union> {n..<N}" by auto
 10.1178 +    moreover have "setsum f {n..<N} = 0"
 10.1179 +      using assms by (auto intro!: setsum_0')
 10.1180 +    ultimately show ?thesis unfolding *
 10.1181 +      by (subst setsum_Un_disjoint) auto
 10.1182 +  qed simp
 10.1183 +qed simp
 10.1184 +
 10.1185 +lemma psuminf_upper:
 10.1186 +  shows "(\<Sum>n<N. f n) \<le> (\<Sum>\<^isub>\<infinity> n. f n)"
 10.1187 +  unfolding psuminf_def SUPR_def
 10.1188 +  by (auto intro: complete_lattice_class.Sup_upper image_eqI)
 10.1189 +
 10.1190 +lemma psuminf_le:
 10.1191 +  assumes "\<And>N. f N \<le> g N"
 10.1192 +  shows "psuminf f \<le> psuminf g"
 10.1193 +proof (safe intro!: psuminf_bound)
 10.1194 +  fix n
 10.1195 +  have "setsum f {..<n} \<le> setsum g {..<n}" using assms by (auto intro: setsum_mono)
 10.1196 +  also have "... \<le> psuminf g" by (rule psuminf_upper)
 10.1197 +  finally show "setsum f {..<n} \<le> psuminf g" .
 10.1198 +qed
 10.1199 +
 10.1200 +lemma psuminf_const[simp]: "psuminf (\<lambda>n. c) = (if c = 0 then 0 else \<omega>)" (is "_ = ?if")
 10.1201 +proof (rule psuminf_equality)
 10.1202 +  fix y assume *: "\<And>n :: nat. (\<Sum>n<n. c) \<le> y" and "y \<noteq> \<omega>"
 10.1203 +  then obtain r p where
 10.1204 +    y: "y = Real r" "0 \<le> r" and
 10.1205 +    c: "c = Real p" "0 \<le> p"
 10.1206 +      using *[of 1] by (cases c, cases y) auto
 10.1207 +  show "(if c = 0 then 0 else \<omega>) \<le> y"
 10.1208 +  proof (cases "p = 0")
 10.1209 +    assume "p = 0" with c show ?thesis by simp
 10.1210 +  next
 10.1211 +    assume "p \<noteq> 0"
 10.1212 +    with * c y have **: "\<And>n :: nat. real n \<le> r / p"
 10.1213 +      by (auto simp: zero_le_mult_iff field_simps)
 10.1214 +    from ex_less_of_nat[of "r / p"] guess n ..
 10.1215 +    with **[of n] show ?thesis by (simp add: real_eq_of_nat)
 10.1216 +  qed
 10.1217 +qed (cases "c = 0", simp_all)
 10.1218 +
 10.1219 +lemma psuminf_add[simp]: "psuminf (\<lambda>n. f n + g n) = psuminf f + psuminf g"
 10.1220 +proof (rule psuminf_equality)
 10.1221 +  fix n
 10.1222 +  from psuminf_upper[of f n] psuminf_upper[of g n]
 10.1223 +  show "(\<Sum>n<n. f n + g n) \<le> psuminf f + psuminf g"
 10.1224 +    by (auto simp add: setsum_addf intro!: add_mono)
 10.1225 +next
 10.1226 +  fix y assume *: "\<And>n. (\<Sum>n<n. f n + g n) \<le> y" and "y \<noteq> \<omega>"
 10.1227 +  { fix n m
 10.1228 +    have **: "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> y"
 10.1229 +    proof (cases rule: linorder_le_cases)
 10.1230 +      assume "n \<le> m"
 10.1231 +      hence "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> (\<Sum>n<m. f n) + (\<Sum>n<m. g n)"
 10.1232 +        by (auto intro!: add_right_mono setsum_mono3)
 10.1233 +      also have "... \<le> y"
 10.1234 +        using * by (simp add: setsum_addf)
 10.1235 +      finally show ?thesis .
 10.1236 +    next
 10.1237 +      assume "m \<le> n"
 10.1238 +      hence "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> (\<Sum>n<n. f n) + (\<Sum>n<n. g n)"
 10.1239 +        by (auto intro!: add_left_mono setsum_mono3)
 10.1240 +      also have "... \<le> y"
 10.1241 +        using * by (simp add: setsum_addf)
 10.1242 +      finally show ?thesis .
 10.1243 +    qed }
 10.1244 +  hence "\<And>m. \<forall>n. (\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> y" by simp
 10.1245 +  from psuminf_bound_add[OF this]
 10.1246 +  have "\<forall>m. (\<Sum>n<m. g n) + psuminf f \<le> y" by (simp add: ac_simps)
 10.1247 +  from psuminf_bound_add[OF this]
 10.1248 +  show "psuminf f + psuminf g \<le> y" by (simp add: ac_simps)
 10.1249 +qed
 10.1250 +
 10.1251 +lemma psuminf_0: "psuminf f = 0 \<longleftrightarrow> (\<forall>i. f i = 0)"
 10.1252 +proof safe
 10.1253 +  assume "\<forall>i. f i = 0"
 10.1254 +  hence "f = (\<lambda>i. 0)" by (simp add: fun_eq_iff)
 10.1255 +  thus "psuminf f = 0" using psuminf_const by simp
 10.1256 +next
 10.1257 +  fix i assume "psuminf f = 0"
 10.1258 +  hence "(\<Sum>n<Suc i. f n) = 0" using psuminf_upper[of f "Suc i"] by simp
 10.1259 +  thus "f i = 0" by simp
 10.1260 +qed
 10.1261 +
 10.1262 +lemma psuminf_cmult_right[simp]: "psuminf (\<lambda>n. c * f n) = c * psuminf f"
 10.1263 +proof (rule psuminf_equality)
 10.1264 +  fix n show "(\<Sum>n<n. c * f n) \<le> c * psuminf f"
 10.1265 +   by (auto simp: setsum_right_distrib[symmetric] intro: mult_left_mono psuminf_upper)
 10.1266 +next
 10.1267 +  fix y
 10.1268 +  assume "\<And>n. (\<Sum>n<n. c * f n) \<le> y"
 10.1269 +  hence *: "\<And>n. c * (\<Sum>n<n. f n) \<le> y" by (auto simp add: setsum_right_distrib)
 10.1270 +  thus "c * psuminf f \<le> y"
 10.1271 +  proof (cases "c = \<omega> \<or> c = 0")
 10.1272 +    assume "c = \<omega> \<or> c = 0"
 10.1273 +    thus ?thesis
 10.1274 +      using * by (fastsimp simp add: psuminf_0 setsum_0 split: split_if_asm)
 10.1275 +  next
 10.1276 +    assume "\<not> (c = \<omega> \<or> c = 0)"
 10.1277 +    hence "c \<noteq> 0" "c \<noteq> \<omega>" by auto
 10.1278 +    note rewrite_div = pextreal_inverse_le_eq[OF this, of _ y]
 10.1279 +    hence "\<forall>n. (\<Sum>n<n. f n) \<le> y / c" using * by simp
 10.1280 +    hence "psuminf f \<le> y / c" by (rule psuminf_bound)
 10.1281 +    thus ?thesis using rewrite_div by simp
 10.1282 +  qed
 10.1283 +qed
 10.1284 +
 10.1285 +lemma psuminf_cmult_left[simp]: "psuminf (\<lambda>n. f n * c) = psuminf f * c"
 10.1286 +  using psuminf_cmult_right[of c f] by (simp add: ac_simps)
 10.1287 +
 10.1288 +lemma psuminf_half_series: "psuminf (\<lambda>n. (1/2)^Suc n) = 1"
 10.1289 +  using suminf_imp_psuminf[OF power_half_series] by auto
 10.1290 +
 10.1291 +lemma setsum_pinfsum: "(\<Sum>\<^isub>\<infinity> n. \<Sum>m\<in>A. f n m) = (\<Sum>m\<in>A. (\<Sum>\<^isub>\<infinity> n. f n m))"
 10.1292 +proof (cases "finite A")
 10.1293 +  assume "finite A"
 10.1294 +  thus ?thesis by induct simp_all
 10.1295 +qed simp
 10.1296 +
 10.1297 +lemma psuminf_reindex:
 10.1298 +  fixes f:: "nat \<Rightarrow> nat" assumes "bij f"
 10.1299 +  shows "psuminf (g \<circ> f) = psuminf g"
 10.1300 +proof -
 10.1301 +  have [intro, simp]: "\<And>A. inj_on f A" using `bij f` unfolding bij_def by (auto intro: subset_inj_on)
 10.1302 +  have f[intro, simp]: "\<And>x. f (inv f x) = x"
 10.1303 +    using `bij f` unfolding bij_def by (auto intro: surj_f_inv_f)
 10.1304 +  show ?thesis
 10.1305 +  proof (rule psuminf_equality)
 10.1306 +    fix n
 10.1307 +    have "setsum (g \<circ> f) {..<n} = setsum g (f ` {..<n})"
 10.1308 +      by (simp add: setsum_reindex)
 10.1309 +    also have "\<dots> \<le> setsum g {..Max (f ` {..<n})}"
 10.1310 +      by (rule setsum_mono3) auto
 10.1311 +    also have "\<dots> \<le> psuminf g" unfolding lessThan_Suc_atMost[symmetric] by (rule psuminf_upper)
 10.1312 +    finally show "setsum (g \<circ> f) {..<n} \<le> psuminf g" .
 10.1313 +  next
 10.1314 +    fix y assume *: "\<And>n. setsum (g \<circ> f) {..<n} \<le> y"
 10.1315 +    show "psuminf g \<le> y"
 10.1316 +    proof (safe intro!: psuminf_bound)
 10.1317 +      fix N
 10.1318 +      have "setsum g {..<N} \<le> setsum g (f ` {..Max (inv f ` {..<N})})"
 10.1319 +        by (rule setsum_mono3) (auto intro!: image_eqI[where f="f", OF f[symmetric]])
 10.1320 +      also have "\<dots> = setsum (g \<circ> f) {..Max (inv f ` {..<N})}"
 10.1321 +        by (simp add: setsum_reindex)
 10.1322 +      also have "\<dots> \<le> y" unfolding lessThan_Suc_atMost[symmetric] by (rule *)
 10.1323 +      finally show "setsum g {..<N} \<le> y" .
 10.1324 +    qed
 10.1325 +  qed
 10.1326 +qed
 10.1327 +
 10.1328 +lemma pextreal_mult_less_right:
 10.1329 +  assumes "b * a < c * a" "0 < a" "a < \<omega>"
 10.1330 +  shows "b < c"
 10.1331 +  using assms
 10.1332 +  by (cases a, cases b, cases c) (auto split: split_if_asm simp: zero_less_mult_iff zero_le_mult_iff)
 10.1333 +
 10.1334 +lemma pextreal_\<omega>_eq_plus[simp]: "\<omega> = a + b \<longleftrightarrow> (a = \<omega> \<or> b = \<omega>)"
 10.1335 +  by (cases a, cases b) auto
 10.1336 +
 10.1337 +lemma pextreal_of_nat_le_iff:
 10.1338 +  "(of_nat k :: pextreal) \<le> of_nat m \<longleftrightarrow> k \<le> m" by auto
 10.1339 +
 10.1340 +lemma pextreal_of_nat_less_iff:
 10.1341 +  "(of_nat k :: pextreal) < of_nat m \<longleftrightarrow> k < m" by auto
 10.1342 +
 10.1343 +lemma pextreal_bound_add:
 10.1344 +  assumes "\<forall>N. f N + y \<le> (x::pextreal)"
 10.1345 +  shows "(SUP n. f n) + y \<le> x"
 10.1346 +proof (cases "x = \<omega>")
 10.1347 +  have "y \<le> x" using assms by (auto intro: pextreal_le_add2)
 10.1348 +  assume "x \<noteq> \<omega>"
 10.1349 +  note move_y = pextreal_less_eq_diff_eq_sum[OF `y \<le> x` this]
 10.1350 +
 10.1351 +  have "\<forall>N. f N \<le> x - y" using assms by (simp add: move_y)
 10.1352 +  hence "(SUP n. f n) \<le> x - y" by (rule SUPR_bound)
 10.1353 +  thus ?thesis by (simp add: move_y)
 10.1354 +qed simp
 10.1355 +
 10.1356 +lemma SUPR_pextreal_add:
 10.1357 +  fixes f g :: "nat \<Rightarrow> pextreal"
 10.1358 +  assumes f: "\<forall>n. f n \<le> f (Suc n)" and g: "\<forall>n. g n \<le> g (Suc n)"
 10.1359 +  shows "(SUP n. f n + g n) = (SUP n. f n) + (SUP n. g n)"
 10.1360 +proof (rule pextreal_SUPI)
 10.1361 +  fix n :: nat from le_SUPI[of n UNIV f] le_SUPI[of n UNIV g]
 10.1362 +  show "f n + g n \<le> (SUP n. f n) + (SUP n. g n)"
 10.1363 +    by (auto intro!: add_mono)
 10.1364 +next
 10.1365 +  fix y assume *: "\<And>n. n \<in> UNIV \<Longrightarrow> f n + g n \<le> y"
 10.1366 +  { fix n m
 10.1367 +    have "f n + g m \<le> y"
 10.1368 +    proof (cases rule: linorder_le_cases)
 10.1369 +      assume "n \<le> m"
 10.1370 +      hence "f n + g m \<le> f m + g m"
 10.1371 +        using f lift_Suc_mono_le by (auto intro!: add_right_mono)
 10.1372 +      also have "\<dots> \<le> y" using * by simp
 10.1373 +      finally show ?thesis .
 10.1374 +    next
 10.1375 +      assume "m \<le> n"
 10.1376 +      hence "f n + g m \<le> f n + g n"
 10.1377 +        using g lift_Suc_mono_le by (auto intro!: add_left_mono)
 10.1378 +      also have "\<dots> \<le> y" using * by simp
 10.1379 +      finally show ?thesis .
 10.1380 +    qed }
 10.1381 +  hence "\<And>m. \<forall>n. f n + g m \<le> y" by simp
 10.1382 +  from pextreal_bound_add[OF this]
 10.1383 +  have "\<forall>m. (g m) + (SUP n. f n) \<le> y" by (simp add: ac_simps)
 10.1384 +  from pextreal_bound_add[OF this]
 10.1385 +  show "SUPR UNIV f + SUPR UNIV g \<le> y" by (simp add: ac_simps)
 10.1386 +qed
 10.1387 +
 10.1388 +lemma SUPR_pextreal_setsum:
 10.1389 +  fixes f :: "'x \<Rightarrow> nat \<Rightarrow> pextreal"
 10.1390 +  assumes "\<And>i. i \<in> P \<Longrightarrow> \<forall>n. f i n \<le> f i (Suc n)"
 10.1391 +  shows "(SUP n. \<Sum>i\<in>P. f i n) = (\<Sum>i\<in>P. SUP n. f i n)"
 10.1392 +proof cases
 10.1393 +  assume "finite P" from this assms show ?thesis
 10.1394 +  proof induct
 10.1395 +    case (insert i P)
 10.1396 +    thus ?case
 10.1397 +      apply simp
 10.1398 +      apply (subst SUPR_pextreal_add)
 10.1399 +      by (auto intro!: setsum_mono)
 10.1400 +  qed simp
 10.1401 +qed simp
 10.1402 +
 10.1403 +lemma psuminf_SUP_eq:
 10.1404 +  assumes "\<And>n i. f n i \<le> f (Suc n) i"
 10.1405 +  shows "(\<Sum>\<^isub>\<infinity> i. SUP n::nat. f n i) = (SUP n::nat. \<Sum>\<^isub>\<infinity> i. f n i)"
 10.1406 +proof -
 10.1407 +  { fix n :: nat
 10.1408 +    have "(\<Sum>i<n. SUP k. f k i) = (SUP k. \<Sum>i<n. f k i)"
 10.1409 +      using assms by (auto intro!: SUPR_pextreal_setsum[symmetric]) }
 10.1410 +  note * = this
 10.1411 +  show ?thesis
 10.1412 +    unfolding psuminf_def
 10.1413 +    unfolding *
 10.1414 +    apply (subst SUP_commute) ..
 10.1415 +qed
 10.1416 +
 10.1417 +lemma psuminf_commute:
 10.1418 +  shows "(\<Sum>\<^isub>\<infinity> i j. f i j) = (\<Sum>\<^isub>\<infinity> j i. f i j)"
 10.1419 +proof -
 10.1420 +  have "(SUP n. \<Sum> i < n. SUP m. \<Sum> j < m. f i j) = (SUP n. SUP m. \<Sum> i < n. \<Sum> j < m. f i j)"
 10.1421 +    apply (subst SUPR_pextreal_setsum)
 10.1422 +    by auto
 10.1423 +  also have "\<dots> = (SUP m n. \<Sum> j < m. \<Sum> i < n. f i j)"
 10.1424 +    apply (subst SUP_commute)
 10.1425 +    apply (subst setsum_commute)
 10.1426 +    by auto
 10.1427 +  also have "\<dots> = (SUP m. \<Sum> j < m. SUP n. \<Sum> i < n. f i j)"
 10.1428 +    apply (subst SUPR_pextreal_setsum)
 10.1429 +    by auto
 10.1430 +  finally show ?thesis
 10.1431 +    unfolding psuminf_def by auto
 10.1432 +qed
 10.1433 +
 10.1434 +lemma psuminf_2dimen:
 10.1435 +  fixes f:: "nat * nat \<Rightarrow> pextreal"
 10.1436 +  assumes fsums: "\<And>m. g m = (\<Sum>\<^isub>\<infinity> n. f (m,n))"
 10.1437 +  shows "psuminf (f \<circ> prod_decode) = psuminf g"
 10.1438 +proof (rule psuminf_equality)
 10.1439 +  fix n :: nat
 10.1440 +  let ?P = "prod_decode ` {..<n}"
 10.1441 +  have "setsum (f \<circ> prod_decode) {..<n} = setsum f ?P"
 10.1442 +    by (auto simp: setsum_reindex inj_prod_decode)
 10.1443 +  also have "\<dots> \<le> setsum f ({..Max (fst ` ?P)} \<times> {..Max (snd ` ?P)})"
 10.1444 +  proof (safe intro!: setsum_mono3 Max_ge image_eqI)
 10.1445 +    fix a b x assume "(a, b) = prod_decode x"
 10.1446 +    from this[symmetric] show "a = fst (prod_decode x)" "b = snd (prod_decode x)"
 10.1447 +      by simp_all
 10.1448 +  qed simp_all
 10.1449 +  also have "\<dots> = (\<Sum>m\<le>Max (fst ` ?P). (\<Sum>n\<le>Max (snd ` ?P). f (m,n)))"
 10.1450 +    unfolding setsum_cartesian_product by simp
 10.1451 +  also have "\<dots> \<le> (\<Sum>m\<le>Max (fst ` ?P). g m)"
 10.1452 +    by (auto intro!: setsum_mono psuminf_upper simp del: setsum_lessThan_Suc
 10.1453 +        simp: fsums lessThan_Suc_atMost[symmetric])
 10.1454 +  also have "\<dots> \<le> psuminf g"
 10.1455 +    by (auto intro!: psuminf_upper simp del: setsum_lessThan_Suc
 10.1456 +        simp: lessThan_Suc_atMost[symmetric])
 10.1457 +  finally show "setsum (f \<circ> prod_decode) {..<n} \<le> psuminf g" .
 10.1458 +next
 10.1459 +  fix y assume *: "\<And>n. setsum (f \<circ> prod_decode) {..<n} \<le> y"
 10.1460 +  have g: "g = (\<lambda>m. \<Sum>\<^isub>\<infinity> n. f (m,n))" unfolding fsums[symmetric] ..
 10.1461 +  show "psuminf g \<le> y" unfolding g
 10.1462 +  proof (rule psuminf_bound, unfold setsum_pinfsum[symmetric], safe intro!: psuminf_bound)
 10.1463 +    fix N M :: nat
 10.1464 +    let ?P = "{..<N} \<times> {..<M}"
 10.1465 +    let ?M = "Max (prod_encode ` ?P)"
 10.1466 +    have "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> (\<Sum>(m, n)\<in>?P. f (m, n))"
 10.1467 +      unfolding setsum_commute[of _ _ "{..<M}"] unfolding setsum_cartesian_product ..
 10.1468 +    also have "\<dots> \<le> (\<Sum>(m,n)\<in>(prod_decode ` {..?M}). f (m, n))"
 10.1469 +      by (auto intro!: setsum_mono3 image_eqI[where f=prod_decode, OF prod_encode_inverse[symmetric]])
 10.1470 +    also have "\<dots> \<le> y" using *[of "Suc ?M"]
 10.1471 +      by (simp add: lessThan_Suc_atMost[symmetric] setsum_reindex
 10.1472 +               inj_prod_decode del: setsum_lessThan_Suc)
 10.1473 +    finally show "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> y" .
 10.1474 +  qed
 10.1475 +qed
 10.1476 +
 10.1477 +lemma Real_max:
 10.1478 +  assumes "x \<ge> 0" "y \<ge> 0"
 10.1479 +  shows "Real (max x y) = max (Real x) (Real y)"
 10.1480 +  using assms unfolding max_def by (auto simp add:not_le)
 10.1481 +
 10.1482 +lemma Real_real: "Real (real x) = (if x = \<omega> then 0 else x)"
 10.1483 +  using assms by (cases x) auto
 10.1484 +
 10.1485 +lemma inj_on_real: "inj_on real (UNIV - {\<omega>})"
 10.1486 +proof (rule inj_onI)
 10.1487 +  fix x y assume mem: "x \<in> UNIV - {\<omega>}" "y \<in> UNIV - {\<omega>}" and "real x = real y"
 10.1488 +  thus "x = y" by (cases x, cases y) auto
 10.1489 +qed
 10.1490 +
 10.1491 +lemma inj_on_Real: "inj_on Real {0..}"
 10.1492 +  by (auto intro!: inj_onI)
 10.1493 +
 10.1494 +lemma range_Real[simp]: "range Real = UNIV - {\<omega>}"
 10.1495 +proof safe
 10.1496 +  fix x assume "x \<notin> range Real"
 10.1497 +  thus "x = \<omega>" by (cases x) auto
 10.1498 +qed auto
 10.1499 +
 10.1500 +lemma image_Real[simp]: "Real ` {0..} = UNIV - {\<omega>}"
 10.1501 +proof safe
 10.1502 +  fix x assume "x \<notin> Real ` {0..}"
 10.1503 +  thus "x = \<omega>" by (cases x) auto
 10.1504 +qed auto
 10.1505 +
 10.1506 +lemma pextreal_SUP_cmult:
 10.1507 +  fixes f :: "'a \<Rightarrow> pextreal"
 10.1508 +  shows "(SUP i : R. z * f i) = z * (SUP i : R. f i)"
 10.1509 +proof (rule pextreal_SUPI)
 10.1510 +  fix i assume "i \<in> R"
 10.1511 +  from le_SUPI[OF this]
 10.1512 +  show "z * f i \<le> z * (SUP i:R. f i)" by (rule pextreal_mult_cancel)
 10.1513 +next
 10.1514 +  fix y assume "\<And>i. i\<in>R \<Longrightarrow> z * f i \<le> y"
 10.1515 +  hence *: "\<And>i. i\<in>R \<Longrightarrow> z * f i \<le> y" by auto
 10.1516 +  show "z * (SUP i:R. f i) \<le> y"
 10.1517 +  proof (cases "\<forall>i\<in>R. f i = 0")
 10.1518 +    case True
 10.1519 +    show ?thesis
 10.1520 +    proof cases
 10.1521 +      assume "R \<noteq> {}" hence "f ` R = {0}" using True by auto
 10.1522 +      thus ?thesis by (simp add: SUPR_def)
 10.1523 +    qed (simp add: SUPR_def Sup_empty bot_pextreal_def)
 10.1524 +  next
 10.1525 +    case False then obtain i where i: "i \<in> R" and f0: "f i \<noteq> 0" by auto
 10.1526 +    show ?thesis
 10.1527 +    proof (cases "z = 0 \<or> z = \<omega>")
 10.1528 +      case True with f0 *[OF i] show ?thesis by auto
 10.1529 +    next
 10.1530 +      case False hence z: "z \<noteq> 0" "z \<noteq> \<omega>" by auto
 10.1531 +      note div = pextreal_inverse_le_eq[OF this, symmetric]
 10.1532 +      hence "\<And>i. i\<in>R \<Longrightarrow> f i \<le> y / z" using * by auto
 10.1533 +      thus ?thesis unfolding div SUP_le_iff by simp
 10.1534 +    qed
 10.1535 +  qed
 10.1536 +qed
 10.1537 +
 10.1538 +instantiation pextreal :: topological_space
 10.1539 +begin
 10.1540 +
 10.1541 +definition "open A \<longleftrightarrow>
 10.1542 +  (\<exists>T. open T \<and> (Real ` (T\<inter>{0..}) = A - {\<omega>})) \<and> (\<omega> \<in> A \<longrightarrow> (\<exists>x\<ge>0. {Real x <..} \<subseteq> A))"
 10.1543 +
 10.1544 +lemma open_omega: "open A \<Longrightarrow> \<omega> \<in> A \<Longrightarrow> (\<exists>x\<ge>0. {Real x<..} \<subseteq> A)"
 10.1545 +  unfolding open_pextreal_def by auto
 10.1546 +
 10.1547 +lemma open_omegaD: assumes "open A" "\<omega> \<in> A" obtains x where "x\<ge>0" "{Real x<..} \<subseteq> A"
 10.1548 +  using open_omega[OF assms] by auto
 10.1549 +
 10.1550 +lemma pextreal_openE: assumes "open A" obtains A' x where
 10.1551 +  "open A'" "Real ` (A' \<inter> {0..}) = A - {\<omega>}"
 10.1552 +  "x \<ge> 0" "\<omega> \<in> A \<Longrightarrow> {Real x<..} \<subseteq> A"
 10.1553 +  using assms open_pextreal_def by auto
 10.1554 +
 10.1555 +instance
 10.1556 +proof
 10.1557 +  let ?U = "UNIV::pextreal set"
 10.1558 +  show "open ?U" unfolding open_pextreal_def
 10.1559 +    by (auto intro!: exI[of _ "UNIV"] exI[of _ 0])
 10.1560 +next
 10.1561 +  fix S T::"pextreal set" assume "open S" and "open T"
 10.1562 +  from `open S`[THEN pextreal_openE] guess S' xS . note S' = this
 10.1563 +  from `open T`[THEN pextreal_openE] guess T' xT . note T' = this
 10.1564 +
 10.1565 +  from S'(1-3) T'(1-3)
 10.1566 +  show "open (S \<inter> T)" unfolding open_pextreal_def
 10.1567 +  proof (safe intro!: exI[of _ "S' \<inter> T'"] exI[of _ "max xS xT"])
 10.1568 +    fix x assume *: "Real (max xS xT) < x" and "\<omega> \<in> S" "\<omega> \<in> T"
 10.1569 +    from `\<omega> \<in> S`[THEN S'(4)] * show "x \<in> S"
 10.1570 +      by (cases x, auto simp: max_def split: split_if_asm)
 10.1571 +    from `\<omega> \<in> T`[THEN T'(4)] * show "x \<in> T"
 10.1572 +      by (cases x, auto simp: max_def split: split_if_asm)
 10.1573 +  next
 10.1574 +    fix x assume x: "x \<notin> Real ` (S' \<inter> T' \<inter> {0..})"
 10.1575 +    have *: "S' \<inter> T' \<inter> {0..} = (S' \<inter> {0..}) \<inter> (T' \<inter> {0..})" by auto
 10.1576 +    assume "x \<in> T" "x \<in> S"
 10.1577 +    with S'(2) T'(2) show "x = \<omega>"
 10.1578 +      using x[unfolded *] inj_on_image_Int[OF inj_on_Real] by auto
 10.1579 +  qed auto
 10.1580 +next
 10.1581 +  fix K assume openK: "\<forall>S \<in> K. open (S:: pextreal set)"
 10.1582 +  hence "\<forall>S\<in>K. \<exists>T. open T \<and> Real ` (T \<inter> {0..}) = S - {\<omega>}" by (auto simp: open_pextreal_def)
 10.1583 +  from bchoice[OF this] guess T .. note T = this[rule_format]
 10.1584 +
 10.1585 +  show "open (\<Union>K)" unfolding open_pextreal_def
 10.1586 +  proof (safe intro!: exI[of _ "\<Union>(T ` K)"])
 10.1587 +    fix x S assume "0 \<le> x" "x \<in> T S" "S \<in> K"
 10.1588 +    with T[OF `S \<in> K`] show "Real x \<in> \<Union>K" by auto
 10.1589 +  next
 10.1590 +    fix x S assume x: "x \<notin> Real ` (\<Union>T ` K \<inter> {0..})" "S \<in> K" "x \<in> S"
 10.1591 +    hence "x \<notin> Real ` (T S \<inter> {0..})"
 10.1592 +      by (auto simp: image_UN UN_simps[symmetric] simp del: UN_simps)
 10.1593 +    thus "x = \<omega>" using T[OF `S \<in> K`] `x \<in> S` by auto
 10.1594 +  next
 10.1595 +    fix S assume "\<omega> \<in> S" "S \<in> K"
 10.1596 +    from openK[rule_format, OF `S \<in> K`, THEN pextreal_openE] guess S' x .
 10.1597 +    from this(3, 4) `\<omega> \<in> S`
 10.1598 +    show "\<exists>x\<ge>0. {Real x<..} \<subseteq> \<Union>K"
 10.1599 +      by (auto intro!: exI[of _ x] bexI[OF _ `S \<in> K`])
 10.1600 +  next
 10.1601 +    from T[THEN conjunct1] show "open (\<Union>T`K)" by auto
 10.1602 +  qed auto
 10.1603 +qed
 10.1604 +end
 10.1605 +
 10.1606 +lemma open_pextreal_lessThan[simp]:
 10.1607 +  "open {..< a :: pextreal}"
 10.1608 +proof (cases a)
 10.1609 +  case (preal x) thus ?thesis unfolding open_pextreal_def
 10.1610 +  proof (safe intro!: exI[of _ "{..< x}"])
 10.1611 +    fix y assume "y < Real x"
 10.1612 +    moreover assume "y \<notin> Real ` ({..<x} \<inter> {0..})"
 10.1613 +    ultimately have "y \<noteq> Real (real y)" using preal by (cases y) auto
 10.1614 +    thus "y = \<omega>" by (auto simp: Real_real split: split_if_asm)
 10.1615 +  qed auto
 10.1616 +next
 10.1617 +  case infinite thus ?thesis
 10.1618 +    unfolding open_pextreal_def by (auto intro!: exI[of _ UNIV])
 10.1619 +qed
 10.1620 +
 10.1621 +lemma open_pextreal_greaterThan[simp]:
 10.1622 +  "open {a :: pextreal <..}"
 10.1623 +proof (cases a)
 10.1624 +  case (preal x) thus ?thesis unfolding open_pextreal_def
 10.1625 +  proof (safe intro!: exI[of _ "{x <..}"])
 10.1626 +    fix y assume "Real x < y"
 10.1627 +    moreover assume "y \<notin> Real ` ({x<..} \<inter> {0..})"
 10.1628 +    ultimately have "y \<noteq> Real (real y)" using preal by (cases y) auto
 10.1629 +    thus "y = \<omega>" by (auto simp: Real_real split: split_if_asm)
 10.1630 +  qed auto
 10.1631 +next
 10.1632 +  case infinite thus ?thesis
 10.1633 +    unfolding open_pextreal_def by (auto intro!: exI[of _ "{}"])
 10.1634 +qed
 10.1635 +
 10.1636 +lemma pextreal_open_greaterThanLessThan[simp]: "open {a::pextreal <..< b}"
 10.1637 +  unfolding greaterThanLessThan_def by auto
 10.1638 +
 10.1639 +lemma closed_pextreal_atLeast[simp, intro]: "closed {a :: pextreal ..}"
 10.1640 +proof -
 10.1641 +  have "- {a ..} = {..< a}" by auto
 10.1642 +  then show "closed {a ..}"
 10.1643 +    unfolding closed_def using open_pextreal_lessThan by auto
 10.1644 +qed
 10.1645 +
 10.1646 +lemma closed_pextreal_atMost[simp, intro]: "closed {.. b :: pextreal}"
 10.1647 +proof -
 10.1648 +  have "- {.. b} = {b <..}" by auto
 10.1649 +  then show "closed {.. b}" 
 10.1650 +    unfolding closed_def using open_pextreal_greaterThan by auto
 10.1651 +qed
 10.1652 +
 10.1653 +lemma closed_pextreal_atLeastAtMost[simp, intro]:
 10.1654 +  shows "closed {a :: pextreal .. b}"
 10.1655 +  unfolding atLeastAtMost_def by auto
 10.1656 +
 10.1657 +lemma pextreal_dense:
 10.1658 +  fixes x y :: pextreal assumes "x < y"
 10.1659 +  shows "\<exists>z. x < z \<and> z < y"
 10.1660 +proof -
 10.1661 +  from `x < y` obtain p where p: "x = Real p" "0 \<le> p" by (cases x) auto
 10.1662 +  show ?thesis
 10.1663 +  proof (cases y)
 10.1664 +    case (preal r) with p `x < y` have "p < r" by auto
 10.1665 +    with dense obtain z where "p < z" "z < r" by auto
 10.1666 +    thus ?thesis using preal p by (auto intro!: exI[of _ "Real z"])
 10.1667 +  next
 10.1668 +    case infinite thus ?thesis using `x < y` p
 10.1669 +      by (auto intro!: exI[of _ "Real p + 1"])
 10.1670 +  qed
 10.1671 +qed
 10.1672 +
 10.1673 +instance pextreal :: t2_space
 10.1674 +proof
 10.1675 +  fix x y :: pextreal assume "x \<noteq> y"
 10.1676 +  let "?P x (y::pextreal)" = "\<exists> U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
 10.1677 +
 10.1678 +  { fix x y :: pextreal assume "x < y"
 10.1679 +    from pextreal_dense[OF this] obtain z where z: "x < z" "z < y" by auto
 10.1680 +    have "?P x y"
 10.1681 +      apply (rule exI[of _ "{..<z}"])
 10.1682 +      apply (rule exI[of _ "{z<..}"])
 10.1683 +      using z by auto }
 10.1684 +  note * = this
 10.1685 +
 10.1686 +  from `x \<noteq> y`
 10.1687 +  show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
 10.1688 +  proof (cases rule: linorder_cases)
 10.1689 +    assume "x = y" with `x \<noteq> y` show ?thesis by simp
 10.1690 +  next assume "x < y" from *[OF this] show ?thesis by auto
 10.1691 +  next assume "y < x" from *[OF this] show ?thesis by auto
 10.1692 +  qed
 10.1693 +qed
 10.1694 +
 10.1695 +definition (in complete_lattice) isoton :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<up>" 50) where
 10.1696 +  "A \<up> X \<longleftrightarrow> (\<forall>i. A i \<le> A (Suc i)) \<and> (SUP i. A i) = X"
 10.1697 +
 10.1698 +definition (in complete_lattice) antiton (infix "\<down>" 50) where
 10.1699 +  "A \<down> X \<longleftrightarrow> (\<forall>i. A i \<ge> A (Suc i)) \<and> (INF i. A i) = X"
 10.1700 +
 10.1701 +lemma isotoneI[intro?]: "\<lbrakk> \<And>i. f i \<le> f (Suc i) ; (SUP i. f i) = F \<rbrakk> \<Longrightarrow> f \<up> F"
 10.1702 +  unfolding isoton_def by auto
 10.1703 +
 10.1704 +lemma (in complete_lattice) isotonD[dest]:
 10.1705 +  assumes "A \<up> X" shows "A i \<le> A (Suc i)" "(SUP i. A i) = X"
 10.1706 +  using assms unfolding isoton_def by auto
 10.1707 +
 10.1708 +lemma isotonD'[dest]:
 10.1709 +  assumes "(A::_=>_) \<up> X" shows "A i x \<le> A (Suc i) x" "(SUP i. A i) = X"
 10.1710 +  using assms unfolding isoton_def le_fun_def by auto
 10.1711 +
 10.1712 +lemma isoton_mono_le:
 10.1713 +  assumes "f \<up> x" "i \<le> j"
 10.1714 +  shows "f i \<le> f j"
 10.1715 +  using `f \<up> x`[THEN isotonD(1)] lift_Suc_mono_le[of f, OF _ `i \<le> j`] by auto
 10.1716 +
 10.1717 +lemma isoton_const:
 10.1718 +  shows "(\<lambda> i. c) \<up> c"
 10.1719 +unfolding isoton_def by auto
 10.1720 +
 10.1721 +lemma isoton_cmult_right:
 10.1722 +  assumes "f \<up> (x::pextreal)"
 10.1723 +  shows "(\<lambda>i. c * f i) \<up> (c * x)"
 10.1724 +  using assms unfolding isoton_def pextreal_SUP_cmult
 10.1725 +  by (auto intro: pextreal_mult_cancel)
 10.1726 +
 10.1727 +lemma isoton_cmult_left:
 10.1728 +  "f \<up> (x::pextreal) \<Longrightarrow> (\<lambda>i. f i * c) \<up> (x * c)"
 10.1729 +  by (subst (1 2) mult_commute) (rule isoton_cmult_right)
 10.1730 +
 10.1731 +lemma isoton_add:
 10.1732 +  assumes "f \<up> (x::pextreal)" and "g \<up> y"
 10.1733 +  shows "(\<lambda>i. f i + g i) \<up> (x + y)"
 10.1734 +  using assms unfolding isoton_def
 10.1735 +  by (auto intro: pextreal_mult_cancel add_mono simp: SUPR_pextreal_add)
 10.1736 +
 10.1737 +lemma isoton_fun_expand:
 10.1738 +  "f \<up> x \<longleftrightarrow> (\<forall>i. (\<lambda>j. f j i) \<up> (x i))"
 10.1739 +proof -
 10.1740 +  have "\<And>i. {y. \<exists>f'\<in>range f. y = f' i} = range (\<lambda>j. f j i)"
 10.1741 +    by auto
 10.1742 +  with assms show ?thesis
 10.1743 +    by (auto simp add: isoton_def le_fun_def Sup_fun_def SUPR_def)
 10.1744 +qed
 10.1745 +
 10.1746 +lemma isoton_indicator:
 10.1747 +  assumes "f \<up> g"
 10.1748 +  shows "(\<lambda>i x. f i x * indicator A x) \<up> (\<lambda>x. g x * indicator A x :: pextreal)"
 10.1749 +  using assms unfolding isoton_fun_expand by (auto intro!: isoton_cmult_left)
 10.1750 +
 10.1751 +lemma isoton_setsum:
 10.1752 +  fixes f :: "'a \<Rightarrow> nat \<Rightarrow> pextreal"
 10.1753 +  assumes "finite A" "A \<noteq> {}"
 10.1754 +  assumes "\<And> x. x \<in> A \<Longrightarrow> f x \<up> y x"
 10.1755 +  shows "(\<lambda> i. (\<Sum> x \<in> A. f x i)) \<up> (\<Sum> x \<in> A. y x)"
 10.1756 +using assms
 10.1757 +proof (induct A rule:finite_ne_induct)
 10.1758 +  case singleton thus ?case by auto
 10.1759 +next
 10.1760 +  case (insert a A) note asms = this
 10.1761 +  hence *: "(\<lambda> i. \<Sum> x \<in> A. f x i) \<up> (\<Sum> x \<in> A. y x)" by auto
 10.1762 +  have **: "(\<lambda> i. f a i) \<up> y a" using asms by simp
 10.1763 +  have "(\<lambda> i. f a i + (\<Sum> x \<in> A. f x i)) \<up> (y a + (\<Sum> x \<in> A. y x))"
 10.1764 +    using * ** isoton_add by auto
 10.1765 +  thus "(\<lambda> i. \<Sum> x \<in> insert a A. f x i) \<up> (\<Sum> x \<in> insert a A. y x)"
 10.1766 +    using asms by fastsimp
 10.1767 +qed
 10.1768 +
 10.1769 +lemma isoton_Sup:
 10.1770 +  assumes "f \<up> u"
 10.1771 +  shows "f i \<le> u"
 10.1772 +  using le_SUPI[of i UNIV f] assms
 10.1773 +  unfolding isoton_def by auto
 10.1774 +
 10.1775 +lemma isoton_mono:
 10.1776 +  assumes iso: "x \<up> a" "y \<up> b" and *: "\<And>n. x n \<le> y (N n)"
 10.1777 +  shows "a \<le> b"
 10.1778 +proof -
 10.1779 +  from iso have "a = (SUP n. x n)" "b = (SUP n. y n)"
 10.1780 +    unfolding isoton_def by auto
 10.1781 +  with * show ?thesis by (auto intro!: SUP_mono)
 10.1782 +qed
 10.1783 +
 10.1784 +lemma pextreal_le_mult_one_interval:
 10.1785 +  fixes x y :: pextreal
 10.1786 +  assumes "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
 10.1787 +  shows "x \<le> y"
 10.1788 +proof (cases x, cases y)
 10.1789 +  assume "x = \<omega>"
 10.1790 +  with assms[of "1 / 2"]
 10.1791 +  show "x \<le> y" by simp
 10.1792 +next
 10.1793 +  fix r p assume *: "y = Real p" "x = Real r" and **: "0 \<le> r" "0 \<le> p"
 10.1794 +  have "r \<le> p"
 10.1795 +  proof (rule field_le_mult_one_interval)
 10.1796 +    fix z :: real assume "0 < z" and "z < 1"
 10.1797 +    with assms[of "Real z"]
 10.1798 +    show "z * r \<le> p" using ** * by (auto simp: zero_le_mult_iff)
 10.1799 +  qed
 10.1800 +  thus "x \<le> y" using ** * by simp
 10.1801 +qed simp
 10.1802 +
 10.1803 +lemma pextreal_greater_0[intro]:
 10.1804 +  fixes a :: pextreal
 10.1805 +  assumes "a \<noteq> 0"
 10.1806 +  shows "a > 0"
 10.1807 +using assms apply (cases a) by auto
 10.1808 +
 10.1809 +lemma pextreal_mult_strict_right_mono:
 10.1810 +  assumes "a < b" and "0 < c" "c < \<omega>"
 10.1811 +  shows "a * c < b * c"
 10.1812 +  using assms
 10.1813 +  by (cases a, cases b, cases c)
 10.1814 +     (auto simp: zero_le_mult_iff pextreal_less_\<omega>)
 10.1815 +
 10.1816 +lemma minus_pextreal_eq2:
 10.1817 +  fixes x y z :: pextreal
 10.1818 +  assumes "y \<le> x" and "y \<noteq> \<omega>" shows "z = x - y \<longleftrightarrow> z + y = x"
 10.1819 +  using assms
 10.1820 +  apply (subst eq_commute)
 10.1821 +  apply (subst minus_pextreal_eq)
 10.1822 +  by (cases x, cases z, auto simp add: ac_simps not_less)
 10.1823 +
 10.1824 +lemma pextreal_diff_eq_diff_imp_eq:
 10.1825 +  assumes "a \<noteq> \<omega>" "b \<le> a" "c \<le> a"
 10.1826 +  assumes "a - b = a - c"
 10.1827 +  shows "b = c"
 10.1828 +  using assms
 10.1829 +  by (cases a, cases b, cases c) (auto split: split_if_asm)
 10.1830 +
 10.1831 +lemma pextreal_inverse_eq_0: "inverse x = 0 \<longleftrightarrow> x = \<omega>"
 10.1832 +  by (cases x) auto
 10.1833 +
 10.1834 +lemma pextreal_mult_inverse:
 10.1835 +  "\<lbrakk> x \<noteq> \<omega> ; x \<noteq> 0 \<rbrakk> \<Longrightarrow> x * inverse x = 1"
 10.1836 +  by (cases x) auto
 10.1837 +
 10.1838 +lemma pextreal_zero_less_diff_iff:
 10.1839 +  fixes a b :: pextreal shows "0 < a - b \<longleftrightarrow> b < a"
 10.1840 +  apply (cases a, cases b)
 10.1841 +  apply (auto simp: pextreal_noteq_omega_Ex pextreal_less_\<omega>)
 10.1842 +  apply (cases b)
 10.1843 +  by auto
 10.1844 +
 10.1845 +lemma pextreal_less_Real_Ex:
 10.1846 +  fixes a b :: pextreal shows "x < Real r \<longleftrightarrow> (\<exists>p\<ge>0. p < r \<and> x = Real p)"
 10.1847 +  by (cases x) auto
 10.1848 +
 10.1849 +lemma open_Real: assumes "open S" shows "open (Real ` ({0..} \<inter> S))"
 10.1850 +  unfolding open_pextreal_def apply(rule,rule,rule,rule assms) by auto
 10.1851 +
 10.1852 +lemma pextreal_zero_le_diff:
 10.1853 +  fixes a b :: pextreal shows "a - b = 0 \<longleftrightarrow> a \<le> b"
 10.1854 +  by (cases a, cases b, simp_all, cases b, auto)
 10.1855 +
 10.1856 +lemma lim_Real[simp]: assumes "\<forall>n. f n \<ge> 0" "m\<ge>0"
 10.1857 +  shows "(\<lambda>n. Real (f n)) ----> Real m \<longleftrightarrow> (\<lambda>n. f n) ----> m" (is "?l = ?r")
 10.1858 +proof assume ?l show ?r unfolding Lim_sequentially
 10.1859 +  proof safe fix e::real assume e:"e>0"
 10.1860 +    note open_ball[of m e] note open_Real[OF this]
 10.1861 +    note * = `?l`[unfolded tendsto_def,rule_format,OF this]
 10.1862 +    have "eventually (\<lambda>x. Real (f x) \<in> Real ` ({0..} \<inter> ball m e)) sequentially"
 10.1863 +      apply(rule *) unfolding image_iff using assms(2) e by auto
 10.1864 +    thus "\<exists>N. \<forall>n\<ge>N. dist (f n) m < e" unfolding eventually_sequentially 
 10.1865 +      apply safe apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
 10.1866 +    proof- fix n x assume "Real (f n) = Real x" "0 \<le> x"
 10.1867 +      hence *:"f n = x" using assms(1) by auto
 10.1868 +      assume "x \<in> ball m e" thus "dist (f n) m < e" unfolding *
 10.1869 +        by (auto simp add:dist_commute)
 10.1870 +    qed qed
 10.1871 +next assume ?r show ?l unfolding tendsto_def eventually_sequentially 
 10.1872 +  proof safe fix S assume S:"open S" "Real m \<in> S"
 10.1873 +    guess T y using S(1) apply-apply(erule pextreal_openE) . note T=this
 10.1874 +    have "m\<in>real ` (S - {\<omega>})" unfolding image_iff 
 10.1875 +      apply(rule_tac x="Real m" in bexI) using assms(2) S(2) by auto
 10.1876 +    hence "m \<in> T" unfolding T(2)[THEN sym] by auto 
 10.1877 +    from `?r`[unfolded tendsto_def eventually_sequentially,rule_format,OF T(1) this]
 10.1878 +    guess N .. note N=this[rule_format]
 10.1879 +    show "\<exists>N. \<forall>n\<ge>N. Real (f n) \<in> S" apply(rule_tac x=N in exI) 
 10.1880 +    proof safe fix n assume n:"N\<le>n"
 10.1881 +      have "f n \<in> real ` (S - {\<omega>})" using N[OF n] assms unfolding T(2)[THEN sym] 
 10.1882 +        unfolding image_iff apply-apply(rule_tac x="Real (f n)" in bexI)
 10.1883 +        unfolding real_Real by auto
 10.1884 +      then guess x unfolding image_iff .. note x=this
 10.1885 +      show "Real (f n) \<in> S" unfolding x apply(subst Real_real) using x by auto
 10.1886 +    qed
 10.1887 +  qed
 10.1888 +qed
 10.1889 +
 10.1890 +lemma pextreal_INFI:
 10.1891 +  fixes x :: pextreal
 10.1892 +  assumes "\<And>i. i \<in> A \<Longrightarrow> x \<le> f i"
 10.1893 +  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> y \<le> f i) \<Longrightarrow> y \<le> x"
 10.1894 +  shows "(INF i:A. f i) = x"
 10.1895 +  unfolding INFI_def Inf_pextreal_def
 10.1896 +  using assms by (auto intro!: Greatest_equality)
 10.1897 +
 10.1898 +lemma real_of_pextreal_less:"x < y \<Longrightarrow> y\<noteq>\<omega> \<Longrightarrow> real x < real y"
 10.1899 +proof- case goal1
 10.1900 +  have *:"y = Real (real y)" "x = Real (real x)" using goal1 Real_real by auto
 10.1901 +  show ?case using goal1 apply- apply(subst(asm) *(1))apply(subst(asm) *(2))
 10.1902 +    unfolding pextreal_less by auto
 10.1903 +qed
 10.1904 +
 10.1905 +lemma not_less_omega[simp]:"\<not> x < \<omega> \<longleftrightarrow> x = \<omega>"
 10.1906 +  by (metis antisym_conv3 pextreal_less(3)) 
 10.1907 +
 10.1908 +lemma Real_real': assumes "x\<noteq>\<omega>" shows "Real (real x) = x"
 10.1909 +proof- have *:"(THE r. 0 \<le> r \<and> x = Real r) = real x"
 10.1910 +    apply(rule the_equality) using assms unfolding Real_real by auto
 10.1911 +  have "Real (THE r. 0 \<le> r \<and> x = Real r) = x" unfolding *
 10.1912 +    using assms unfolding Real_real by auto
 10.1913 +  thus ?thesis unfolding real_of_pextreal_def of_pextreal_def
 10.1914 +    unfolding pextreal_case_def using assms by auto
 10.1915 +qed 
 10.1916 +
 10.1917 +lemma Real_less_plus_one:"Real x < Real (max (x + 1) 1)" 
 10.1918 +  unfolding pextreal_less by auto
 10.1919 +
 10.1920 +lemma Lim_omega: "f ----> \<omega> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n \<ge> Real B)" (is "?l = ?r")
 10.1921 +proof assume ?r show ?l apply(rule topological_tendstoI)
 10.1922 +    unfolding eventually_sequentially
 10.1923 +  proof- fix S assume "open S" "\<omega> \<in> S"
 10.1924 +    from open_omega[OF this] guess B .. note B=this
 10.1925 +    from `?r`[rule_format,of "(max B 0)+1"] guess N .. note N=this
 10.1926 +    show "\<exists>N. \<forall>n\<ge>N. f n \<in> S" apply(rule_tac x=N in exI)
 10.1927 +    proof safe case goal1 
 10.1928 +      have "Real B < Real ((max B 0) + 1)" by auto
 10.1929 +      also have "... \<le> f n" using goal1 N by auto
 10.1930 +      finally show ?case using B by fastsimp
 10.1931 +    qed
 10.1932 +  qed
 10.1933 +next assume ?l show ?r
 10.1934 +  proof fix B::real have "open {Real B<..}" "\<omega> \<in> {Real B<..}" by auto
 10.1935 +    from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially]
 10.1936 +    guess N .. note N=this
 10.1937 +    show "\<exists>N. \<forall>n\<ge>N. Real B \<le> f n" apply(rule_tac x=N in exI) using N by auto
 10.1938 +  qed
 10.1939 +qed
 10.1940 +
 10.1941 +lemma Lim_bounded_omgea: assumes lim:"f ----> l" and "\<And>n. f n \<le> Real B" shows "l \<noteq> \<omega>"
 10.1942 +proof(rule ccontr,unfold not_not) let ?B = "max (B + 1) 1" assume as:"l=\<omega>"
 10.1943 +  from lim[unfolded this Lim_omega,rule_format,of "?B"]
 10.1944 +  guess N .. note N=this[rule_format,OF le_refl]
 10.1945 +  hence "Real ?B \<le> Real B" using assms(2)[of N] by(rule order_trans) 
 10.1946 +  hence "Real ?B < Real ?B" using Real_less_plus_one[of B] by(rule le_less_trans)
 10.1947 +  thus False by auto
 10.1948 +qed
 10.1949 +
 10.1950 +lemma incseq_le_pextreal: assumes inc: "\<And>n m. n\<ge>m \<Longrightarrow> X n \<ge> X m"
 10.1951 +  and lim: "X ----> (L::pextreal)" shows "X n \<le> L"
 10.1952 +proof(cases "L = \<omega>")
 10.1953 +  case False have "\<forall>n. X n \<noteq> \<omega>"
 10.1954 +  proof(rule ccontr,unfold not_all not_not,safe)
 10.1955 +    case goal1 hence "\<forall>n\<ge>x. X n = \<omega>" using inc[of x] by auto
 10.1956 +    hence "X ----> \<omega>" unfolding tendsto_def eventually_sequentially
 10.1957 +      apply safe apply(rule_tac x=x in exI) by auto
 10.1958 +    note Lim_unique[OF trivial_limit_sequentially this lim]
 10.1959 +    with False show False by auto
 10.1960 +  qed note * =this[rule_format]
 10.1961 +
 10.1962 +  have **:"\<forall>m n. m \<le> n \<longrightarrow> Real (real (X m)) \<le> Real (real (X n))"
 10.1963 +    unfolding Real_real using * inc by auto
 10.1964 +  have "real (X n) \<le> real L" apply-apply(rule incseq_le) defer
 10.1965 +    apply(subst lim_Real[THEN sym]) apply(rule,rule,rule)
 10.1966 +    unfolding Real_real'[OF *] Real_real'[OF False] 
 10.1967 +    unfolding incseq_def using ** lim by auto
 10.1968 +  hence "Real (real (X n)) \<le> Real (real L)" by auto
 10.1969 +  thus ?thesis unfolding Real_real using * False by auto
 10.1970 +qed auto
 10.1971 +
 10.1972 +lemma SUP_Lim_pextreal: assumes "\<And>n m. n\<ge>m \<Longrightarrow> f n \<ge> f m" "f ----> l"
 10.1973 +  shows "(SUP n. f n) = (l::pextreal)" unfolding SUPR_def Sup_pextreal_def
 10.1974 +proof (safe intro!: Least_equality)
 10.1975 +  fix n::nat show "f n \<le> l" apply(rule incseq_le_pextreal)
 10.1976 +    using assms by auto
 10.1977 +next fix y assume y:"\<forall>x\<in>range f. x \<le> y" show "l \<le> y"
 10.1978 +  proof(rule ccontr,cases "y=\<omega>",unfold not_le)
 10.1979 +    case False assume as:"y < l"
 10.1980 +    have l:"l \<noteq> \<omega>" apply(rule Lim_bounded_omgea[OF assms(2), of "real y"])
 10.1981 +      using False y unfolding Real_real by auto
 10.1982 +
 10.1983 +    have yl:"real y < real l" using as apply-
 10.1984 +      apply(subst(asm) Real_real'[THEN sym,OF `y\<noteq>\<omega>`])
 10.1985 +      apply(subst(asm) Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) 
 10.1986 +      unfolding pextreal_less apply(subst(asm) if_P) by auto
 10.1987 +    hence "y + (y - l) * Real (1 / 2) < l" apply-
 10.1988 +      apply(subst Real_real'[THEN sym,OF `y\<noteq>\<omega>`]) apply(subst(2) Real_real'[THEN sym,OF `y\<noteq>\<omega>`])
 10.1989 +      apply(subst Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) apply(subst(2) Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) by auto
 10.1990 +    hence *:"l \<in> {y + (y - l) / 2<..}" by auto
 10.1991 +    have "open {y + (y-l)/2 <..}" by auto
 10.1992 +    note topological_tendstoD[OF assms(2) this *]
 10.1993 +    from this[unfolded eventually_sequentially] guess N .. note this[rule_format, of N]
 10.1994 +    hence "y + (y - l) * Real (1 / 2) < y" using y[rule_format,of "f N"] by auto
 10.1995 +    hence "Real (real y) + (Real (real y) - Real (real l)) * Real (1 / 2) < Real (real y)"
 10.1996 +      unfolding Real_real using `y\<noteq>\<omega>` `l\<noteq>\<omega>` by auto
 10.1997 +    thus False using yl by auto
 10.1998 +  qed auto
 10.1999 +qed
 10.2000 +
 10.2001 +lemma Real_max':"Real x = Real (max x 0)" 
 10.2002 +proof(cases "x < 0") case True
 10.2003 +  hence *:"max x 0 = 0" by auto
 10.2004 +  show ?thesis unfolding * using True by auto
 10.2005 +qed auto
 10.2006 +
 10.2007 +lemma lim_pextreal_increasing: assumes "\<forall>n m. n\<ge>m \<longrightarrow> f n \<ge> f m"
 10.2008 +  obtains l where "f ----> (l::pextreal)"
 10.2009 +proof(cases "\<exists>B. \<forall>n. f n < Real B")
 10.2010 +  case False thus thesis apply- apply(rule that[of \<omega>]) unfolding Lim_omega not_ex not_all
 10.2011 +    apply safe apply(erule_tac x=B in allE,safe) apply(rule_tac x=x in exI,safe)
 10.2012 +    apply(rule order_trans[OF _ assms[rule_format]]) by auto
 10.2013 +next case True then guess B .. note B = this[rule_format]
 10.2014 +  hence *:"\<And>n. f n < \<omega>" apply-apply(rule less_le_trans,assumption) by auto
 10.2015 +  have *:"\<And>n. f n \<noteq> \<omega>" proof- case goal1 show ?case using *[of n] by auto qed
 10.2016 +  have B':"\<And>n. real (f n) \<le> max 0 B" proof- case goal1 thus ?case
 10.2017 +      using B[of n] apply-apply(subst(asm) Real_real'[THEN sym]) defer
 10.2018 +      apply(subst(asm)(2) Real_max') unfolding pextreal_less apply(subst(asm) if_P) using *[of n] by auto
 10.2019 +  qed
 10.2020 +  have "\<exists>l. (\<lambda>n. real (f n)) ----> l" apply(rule Topology_Euclidean_Space.bounded_increasing_convergent)
 10.2021 +  proof safe show "bounded {real (f n) |n. True}"
 10.2022 +      unfolding bounded_def apply(rule_tac x=0 in exI,rule_tac x="max 0 B" in exI)
 10.2023 +      using B' unfolding dist_norm by auto
 10.2024 +    fix n::nat have "Real (real (f n)) \<le> Real (real (f (Suc n)))"
 10.2025 +      using assms[rule_format,of n "Suc n"] apply(subst Real_real)+
 10.2026 +      using *[of n] *[of "Suc n"] by fastsimp
 10.2027 +    thus "real (f n) \<le> real (f (Suc n))" by auto
 10.2028 +  qed then guess l .. note l=this
 10.2029 +  have "0 \<le> l" apply(rule LIMSEQ_le_const[OF l])
 10.2030 +    by(rule_tac x=0 in exI,auto)
 10.2031 +
 10.2032 +  thus ?thesis apply-apply(rule that[of "Real l"])
 10.2033 +    using l apply-apply(subst(asm) lim_Real[THEN sym]) prefer 3
 10.2034 +    unfolding Real_real using * by auto
 10.2035 +qed
 10.2036 +
 10.2037 +lemma setsum_neq_omega: assumes "finite s" "\<And>x. x \<in> s \<Longrightarrow> f x \<noteq> \<omega>"
 10.2038 +  shows "setsum f s \<noteq> \<omega>" using assms
 10.2039 +proof induct case (insert x s)
 10.2040 +  show ?case unfolding setsum.insert[OF insert(1-2)] 
 10.2041 +    using insert by auto
 10.2042 +qed auto
 10.2043 +
 10.2044 +
 10.2045 +lemma real_Real': "0 \<le> x \<Longrightarrow> real (Real x) = x"
 10.2046 +  unfolding real_Real by auto
 10.2047 +
 10.2048 +lemma real_pextreal_pos[intro]:
 10.2049 +  assumes "x \<noteq> 0" "x \<noteq> \<omega>"
 10.2050 +  shows "real x > 0"
 10.2051 +  apply(subst real_Real'[THEN sym,of 0]) defer
 10.2052 +  apply(rule real_of_pextreal_less) using assms by auto
 10.2053 +
 10.2054 +lemma Lim_omega_gt: "f ----> \<omega> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n > Real B)" (is "?l = ?r")
 10.2055 +proof assume ?l thus ?r unfolding Lim_omega apply safe
 10.2056 +    apply(erule_tac x="max B 0 +1" in allE,safe)
 10.2057 +    apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
 10.2058 +    apply(rule_tac y="Real (max B 0 + 1)" in less_le_trans) by auto
 10.2059 +next assume ?r thus ?l unfolding Lim_omega apply safe
 10.2060 +    apply(erule_tac x=B in allE,safe) apply(rule_tac x=N in exI,safe) by auto
 10.2061 +qed
 10.2062 +
 10.2063 +lemma pextreal_minus_le_cancel:
 10.2064 +  fixes a b c :: pextreal
 10.2065 +  assumes "b \<le> a"
 10.2066 +  shows "c - a \<le> c - b"
 10.2067 +  using assms by (cases a, cases b, cases c, simp, simp, simp, cases b, cases c, simp_all)
 10.2068 +
 10.2069 +lemma pextreal_minus_\<omega>[simp]: "x - \<omega> = 0" by (cases x) simp_all
 10.2070 +
 10.2071 +lemma pextreal_minus_mono[intro]: "a - x \<le> (a::pextreal)"
 10.2072 +proof- have "a - x \<le> a - 0"
 10.2073 +    apply(rule pextreal_minus_le_cancel) by auto
 10.2074 +  thus ?thesis by auto
 10.2075 +qed
 10.2076 +
 10.2077 +lemma pextreal_minus_eq_\<omega>[simp]: "x - y = \<omega> \<longleftrightarrow> (x = \<omega> \<and> y \<noteq> \<omega>)"
 10.2078 +  by (cases x, cases y) (auto, cases y, auto)
 10.2079 +
 10.2080 +lemma pextreal_less_minus_iff:
 10.2081 +  fixes a b c :: pextreal
 10.2082 +  shows "a < b - c \<longleftrightarrow> c + a < b"
 10.2083 +  by (cases c, cases a, cases b, auto)
 10.2084 +
 10.2085 +lemma pextreal_minus_less_iff:
 10.2086 +  fixes a b c :: pextreal shows "a - c < b \<longleftrightarrow> (0 < b \<and> (c \<noteq> \<omega> \<longrightarrow> a < b + c))"
 10.2087 +  by (cases c, cases a, cases b, auto)
 10.2088 +
 10.2089 +lemma pextreal_le_minus_iff:
 10.2090 +  fixes a b c :: pextreal
 10.2091 +  shows "a \<le> c - b \<longleftrightarrow> ((c \<le> b \<longrightarrow> a = 0) \<and> (b < c \<longrightarrow> a + b \<le> c))"
 10.2092 +  by (cases a, cases c, cases b, auto simp: pextreal_noteq_omega_Ex)
 10.2093 +
 10.2094 +lemma pextreal_minus_le_iff:
 10.2095 +  fixes a b c :: pextreal
 10.2096 +  shows "a - c \<le> b \<longleftrightarrow> (c \<le> a \<longrightarrow> a \<le> b + c)"
 10.2097 +  by (cases a, cases c, cases b, auto simp: pextreal_noteq_omega_Ex)
 10.2098 +
 10.2099 +lemmas pextreal_minus_order = pextreal_minus_le_iff pextreal_minus_less_iff pextreal_le_minus_iff pextreal_less_minus_iff
 10.2100 +
 10.2101 +lemma pextreal_minus_strict_mono:
 10.2102 +  assumes "a > 0" "x > 0" "a\<noteq>\<omega>"
 10.2103 +  shows "a - x < (a::pextreal)"
 10.2104 +  using assms by(cases x, cases a, auto)
 10.2105 +
 10.2106 +lemma pextreal_minus':
 10.2107 +  "Real r - Real p = (if 0 \<le> r \<and> p \<le> r then if 0 \<le> p then Real (r - p) else Real r else 0)"
 10.2108 +  by (auto simp: minus_pextreal_eq not_less)
 10.2109 +
 10.2110 +lemma pextreal_minus_plus:
 10.2111 +  "x \<le> (a::pextreal) \<Longrightarrow> a - x + x = a"
 10.2112 +  by (cases a, cases x) auto
 10.2113 +
 10.2114 +lemma pextreal_cancel_plus_minus: "b \<noteq> \<omega> \<Longrightarrow> a + b - b = a"
 10.2115 +  by (cases a, cases b) auto
 10.2116 +
 10.2117 +lemma pextreal_minus_le_cancel_right:
 10.2118 +  fixes a b c :: pextreal
 10.2119 +  assumes "a \<le> b" "c \<le> a"
 10.2120 +  shows "a - c \<le> b - c"
 10.2121 +  using assms by (cases a, cases b, cases c, auto, cases c, auto)
 10.2122 +
 10.2123 +lemma real_of_pextreal_setsum':
 10.2124 +  assumes "\<forall>x \<in> S. f x \<noteq> \<omega>"
 10.2125 +  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
 10.2126 +proof cases
 10.2127 +  assume "finite S"
 10.2128 +  from this assms show ?thesis
 10.2129 +    by induct (simp_all add: real_of_pextreal_add setsum_\<omega>)
 10.2130 +qed simp
 10.2131 +
 10.2132 +lemma Lim_omega_pos: "f ----> \<omega> \<longleftrightarrow> (\<forall>B>0. \<exists>N. \<forall>n\<ge>N. f n \<ge> Real B)" (is "?l = ?r")
 10.2133 +  unfolding Lim_omega apply safe defer
 10.2134 +  apply(erule_tac x="max 1 B" in allE) apply safe defer
 10.2135 +  apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
 10.2136 +  apply(rule_tac y="Real (max 1 B)" in order_trans) by auto
 10.2137 +
 10.2138 +lemma pextreal_LimI_finite:
 10.2139 +  assumes "x \<noteq> \<omega>" "\<And>r. 0 < r \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r"
 10.2140 +  shows "u ----> x"
 10.2141 +proof (rule topological_tendstoI, unfold eventually_sequentially)
 10.2142 +  fix S assume "open S" "x \<in> S"
 10.2143 +  then obtain A where "open A" and A_eq: "Real ` (A \<inter> {0..}) = S - {\<omega>}" by (auto elim!: pextreal_openE)
 10.2144 +  then have "x \<in> Real ` (A \<inter> {0..})" using `x \<in> S` `x \<noteq> \<omega>` by auto
 10.2145 +  then have "real x \<in> A" by auto
 10.2146 +  then obtain r where "0 < r" and dist: "\<And>y. dist y (real x) < r \<Longrightarrow> y \<in> A"
 10.2147 +    using `open A` unfolding open_real_def by auto
 10.2148 +  then obtain n where
 10.2149 +    upper: "\<And>N. n \<le> N \<Longrightarrow> u N < x + Real r" and
 10.2150 +    lower: "\<And>N. n \<le> N \<Longrightarrow> x < u N + Real r" using assms(2)[of "Real r"] by auto
 10.2151 +  show "\<exists>N. \<forall>n\<ge>N. u n \<in> S"
 10.2152 +  proof (safe intro!: exI[of _ n])
 10.2153 +    fix N assume "n \<le> N"
 10.2154 +    from upper[OF this] `x \<noteq> \<omega>` `0 < r`
 10.2155 +    have "u N \<noteq> \<omega>" by (force simp: pextreal_noteq_omega_Ex)
 10.2156 +    with `x \<noteq> \<omega>` `0 < r` lower[OF `n \<le> N`] upper[OF `n \<le> N`]
 10.2157 +    have "dist (real (u N)) (real x) < r" "u N \<noteq> \<omega>"
 10.2158 +      by (auto simp: pextreal_noteq_omega_Ex dist_real_def abs_diff_less_iff field_simps)
 10.2159 +    from dist[OF this(1)]
 10.2160 +    have "u N \<in> Real ` (A \<inter> {0..})" using `u N \<noteq> \<omega>`
 10.2161 +      by (auto intro!: image_eqI[of _ _ "real (u N)"] simp: pextreal_noteq_omega_Ex Real_real)
 10.2162 +    thus "u N \<in> S" using A_eq by simp
 10.2163 +  qed
 10.2164 +qed
 10.2165 +
 10.2166 +lemma real_Real_max:"real (Real x) = max x 0"
 10.2167 +  unfolding real_Real by auto
 10.2168 +
 10.2169 +lemma Sup_lim:
 10.2170 +  assumes "\<forall>n. b n \<in> s" "b ----> (a::pextreal)"
 10.2171 +  shows "a \<le> Sup s"
 10.2172 +proof(rule ccontr,unfold not_le)
 10.2173 +  assume as:"Sup s < a" hence om:"Sup s \<noteq> \<omega>" by auto
 10.2174 +  have s:"s \<noteq> {}" using assms by auto
 10.2175 +  { presume *:"\<forall>n. b n < a \<Longrightarrow> False"
 10.2176 +    show False apply(cases,rule *,assumption,unfold not_all not_less)
 10.2177 +    proof- case goal1 then guess n .. note n=this
 10.2178 +      thus False using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of n]]
 10.2179 +        using as by auto
 10.2180 +    qed
 10.2181 +  } assume b:"\<forall>n. b n < a"
 10.2182 +  show False
 10.2183 +  proof(cases "a = \<omega>")
 10.2184 +    case False have *:"a - Sup s > 0" 
 10.2185 +      using False as by(auto simp: pextreal_zero_le_diff)
 10.2186 +    have "(a - Sup s) / 2 \<le> a / 2" unfolding divide_pextreal_def
 10.2187 +      apply(rule mult_right_mono) by auto
 10.2188 +    also have "... = Real (real (a / 2))" apply(rule Real_real'[THEN sym])
 10.2189 +      using False by auto
 10.2190 +    also have "... < Real (real a)" unfolding pextreal_less using as False
 10.2191 +      by(auto simp add: real_of_pextreal_mult[THEN sym])
 10.2192 +    also have "... = a" apply(rule Real_real') using False by auto
 10.2193 +    finally have asup:"a > (a - Sup s) / 2" .
 10.2194 +    have "\<exists>n. a - b n < (a - Sup s) / 2"
 10.2195 +    proof(rule ccontr,unfold not_ex not_less)
 10.2196 +      case goal1
 10.2197 +      have "(a - Sup s) * Real (1 / 2)  > 0" 
 10.2198 +        using * by auto
 10.2199 +      hence "a - (a - Sup s) * Real (1 / 2) < a"
 10.2200 +        apply-apply(rule pextreal_minus_strict_mono)
 10.2201 +        using False * by auto
 10.2202 +      hence *:"a \<in> {a - (a - Sup s) / 2<..}"using asup by auto 
 10.2203 +      note topological_tendstoD[OF assms(2) open_pextreal_greaterThan,OF *]
 10.2204 +      from this[unfolded eventually_sequentially] guess n .. 
 10.2205 +      note n = this[rule_format,of n] 
 10.2206 +      have "b n + (a - Sup s) / 2 \<le> a" 
 10.2207 +        using add_right_mono[OF goal1[rule_format,of n],of "b n"]
 10.2208 +        unfolding pextreal_minus_plus[OF less_imp_le[OF b[rule_format]]]
 10.2209 +        by(auto simp: add_commute)
 10.2210 +      hence "b n \<le> a - (a - Sup s) / 2" unfolding pextreal_le_minus_iff
 10.2211 +        using asup by auto
 10.2212 +      hence "b n \<notin> {a - (a - Sup s) / 2<..}" by auto
 10.2213 +      thus False using n by auto
 10.2214 +    qed
 10.2215 +    then guess n .. note n = this
 10.2216 +    have "Sup s < a - (a - Sup s) / 2"
 10.2217 +      using False as om by (cases a) (auto simp: pextreal_noteq_omega_Ex field_simps)
 10.2218 +    also have "... \<le> b n"
 10.2219 +    proof- note add_right_mono[OF less_imp_le[OF n],of "b n"]
 10.2220 +      note this[unfolded pextreal_minus_plus[OF less_imp_le[OF b[rule_format]]]]
 10.2221 +      hence "a - (a - Sup s) / 2 \<le> (a - Sup s) / 2 + b n - (a - Sup s) / 2"
 10.2222 +        apply(rule pextreal_minus_le_cancel_right) using asup by auto
 10.2223 +      also have "... = b n + (a - Sup s) / 2 - (a - Sup s) / 2" 
 10.2224 +        by(auto simp add: add_commute)
 10.2225 +      also have "... = b n" apply(subst pextreal_cancel_plus_minus)
 10.2226 +      proof(rule ccontr,unfold not_not) case goal1
 10.2227 +        show ?case using asup unfolding goal1 by auto 
 10.2228 +      qed auto
 10.2229 +      finally show ?thesis .
 10.2230 +    qed     
 10.2231 +    finally show False
 10.2232 +      using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of n]] by auto  
 10.2233 +  next case True
 10.2234 +    from assms(2)[unfolded True Lim_omega_gt,rule_format,of "real (Sup s)"]
 10.2235 +    guess N .. note N = this[rule_format,of N]
 10.2236 +    thus False using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of N]] 
 10.2237 +      unfolding Real_real using om by auto
 10.2238 +  qed qed
 10.2239 +
 10.2240 +lemma Sup_mono_lim:
 10.2241 +  assumes "\<forall>a\<in>A. \<exists>b. \<forall>n. b n \<in> B \<and> b ----> (a::pextreal)"
 10.2242 +  shows "Sup A \<le> Sup B"
 10.2243 +  unfolding Sup_le_iff apply(rule) apply(drule assms[rule_format]) apply safe
 10.2244 +  apply(rule_tac b=b in Sup_lim) by auto
 10.2245 +
 10.2246 +lemma pextreal_less_add:
 10.2247 +  assumes "x \<noteq> \<omega>" "a < b"
 10.2248 +  shows "x + a < x + b"
 10.2249 +  using assms by (cases a, cases b, cases x) auto
 10.2250 +
 10.2251 +lemma SUPR_lim:
 10.2252 +  assumes "\<forall>n. b n \<in> B" "(\<lambda>n. f (b n)) ----> (f a::pextreal)"
 10.2253 +  shows "f a \<le> SUPR B f"
 10.2254 +  unfolding SUPR_def apply(rule Sup_lim[of "\<lambda>n. f (b n)"])
 10.2255 +  using assms by auto
 10.2256 +
 10.2257 +lemma SUP_\<omega>_imp:
 10.2258 +  assumes "(SUP i. f i) = \<omega>"
 10.2259 +  shows "\<exists>i. Real x < f i"
 10.2260 +proof (rule ccontr)
 10.2261 +  assume "\<not> ?thesis" hence "\<And>i. f i \<le> Real x" by (simp add: not_less)
 10.2262 +  hence "(SUP i. f i) \<le> Real x" unfolding SUP_le_iff by auto
 10.2263 +  with assms show False by auto
 10.2264 +qed
 10.2265 +
 10.2266 +lemma SUPR_mono_lim:
 10.2267 +  assumes "\<forall>a\<in>A. \<exists>b. \<forall>n. b n \<in> B \<and> (\<lambda>n. f (b n)) ----> (f a::pextreal)"
 10.2268 +  shows "SUPR A f \<le> SUPR B f"
 10.2269 +  unfolding SUPR_def apply(rule Sup_mono_lim)
 10.2270 +  apply safe apply(drule assms[rule_format],safe)
 10.2271 +  apply(rule_tac x="\<lambda>n. f (b n)" in exI) by auto
 10.2272 +
 10.2273 +lemma real_0_imp_eq_0:
 10.2274 +  assumes "x \<noteq> \<omega>" "real x = 0"
 10.2275 +  shows "x = 0"
 10.2276 +using assms by (cases x) auto
 10.2277 +
 10.2278 +lemma SUPR_mono:
 10.2279 +  assumes "\<forall>a\<in>A. \<exists>b\<in>B. f b \<ge> f a"
 10.2280 +  shows "SUPR A f \<le> SUPR B f"
 10.2281 +  unfolding SUPR_def apply(rule Sup_mono)
 10.2282 +  using assms by auto
 10.2283 +
 10.2284 +lemma less_add_Real:
 10.2285 +  fixes x :: real
 10.2286 +  fixes a b :: pextreal
 10.2287 +  assumes "x \<ge> 0" "a < b"
 10.2288 +  shows "a + Real x < b + Real x"
 10.2289 +using assms by (cases a, cases b) auto
 10.2290 +
 10.2291 +lemma le_add_Real:
 10.2292 +  fixes x :: real
 10.2293 +  fixes a b :: pextreal
 10.2294 +  assumes "x \<ge> 0" "a \<le> b"
 10.2295 +  shows "a + Real x \<le> b + Real x"
 10.2296 +using assms by (cases a, cases b) auto
 10.2297 +
 10.2298 +lemma le_imp_less_pextreal:
 10.2299 +  fixes x :: pextreal
 10.2300 +  assumes "x > 0" "a + x \<le> b" "a \<noteq> \<omega>"
 10.2301 +  shows "a < b"
 10.2302 +using assms by (cases x, cases a, cases b) auto
 10.2303 +
 10.2304 +lemma pextreal_INF_minus:
 10.2305 +  fixes f :: "nat \<Rightarrow> pextreal"
 10.2306 +  assumes "c \<noteq> \<omega>"
 10.2307 +  shows "(INF i. c - f i) = c - (SUP i. f i)"
 10.2308 +proof (cases "SUP i. f i")
 10.2309 +  case infinite
 10.2310 +  from `c \<noteq> \<omega>` obtain x where [simp]: "c = Real x" by (cases c) auto
 10.2311 +  from SUP_\<omega>_imp[OF infinite] obtain i where "Real x < f i" by auto
 10.2312 +  have "(INF i. c - f i) \<le> c - f i"
 10.2313 +    by (auto intro!: complete_lattice_class.INF_leI)
 10.2314 +  also have "\<dots> = 0" using `Real x < f i` by (auto simp: minus_pextreal_eq)
 10.2315 +  finally show ?thesis using infinite by auto
 10.2316 +next
 10.2317 +  case (preal r)
 10.2318 +  from `c \<noteq> \<omega>` obtain x where c: "c = Real x" by (cases c) auto
 10.2319 +
 10.2320 +  show ?thesis unfolding c
 10.2321 +  proof (rule pextreal_INFI)
 10.2322 +    fix i have "f i \<le> (SUP i. f i)" by (rule le_SUPI) simp
 10.2323 +    thus "Real x - (SUP i. f i) \<le> Real x - f i" by (rule pextreal_minus_le_cancel)
 10.2324 +  next
 10.2325 +    fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> y \<le> Real x - f i"
 10.2326 +    from this[of 0] obtain p where p: "y = Real p" "0 \<le> p"
 10.2327 +      by (cases "f 0", cases y, auto split: split_if_asm)
 10.2328 +    hence "\<And>i. Real p \<le> Real x - f i" using * by auto
 10.2329 +    hence *: "\<And>i. Real x \<le> f i \<Longrightarrow> Real p = 0"
 10.2330 +      "\<And>i. f i < Real x \<Longrightarrow> Real p + f i \<le> Real x"
 10.2331 +      unfolding pextreal_le_minus_iff by auto
 10.2332 +    show "y \<le> Real x - (SUP i. f i)" unfolding p pextreal_le_minus_iff
 10.2333 +    proof safe
 10.2334 +      assume x_less: "Real x \<le> (SUP i. f i)"
 10.2335 +      show "Real p = 0"
 10.2336 +      proof (rule ccontr)
 10.2337 +        assume "Real p \<noteq> 0"
 10.2338 +        hence "0 < Real p" by auto
 10.2339 +        from Sup_close[OF this, of "range f"]
 10.2340 +        obtain i where e: "(SUP i. f i) < f i + Real p"
 10.2341 +          using preal unfolding SUPR_def by auto
 10.2342 +        hence "Real x \<le> f i + Real p" using x_less by auto
 10.2343 +        show False
 10.2344 +        proof cases
 10.2345 +          assume "\<forall>i. f i < Real x"
 10.2346 +          hence "Real p + f i \<le> Real x" using * by auto
 10.2347 +          hence "f i + Real p \<le> (SUP i. f i)" using x_less by (auto simp: field_simps)
 10.2348 +          thus False using e by auto
 10.2349 +        next
 10.2350 +          assume "\<not> (\<forall>i. f i < Real x)"
 10.2351 +          then obtain i where "Real x \<le> f i" by (auto simp: not_less)
 10.2352 +          from *(1)[OF this] show False using `Real p \<noteq> 0` by auto
 10.2353 +        qed
 10.2354 +      qed
 10.2355 +    next
 10.2356 +      have "\<And>i. f i \<le> (SUP i. f i)" by (rule complete_lattice_class.le_SUPI) auto
 10.2357 +      also assume "(SUP i. f i) < Real x"
 10.2358 +      finally have "\<And>i. f i < Real x" by auto
 10.2359 +      hence *: "\<And>i. Real p + f i \<le> Real x" using * by auto
 10.2360 +      have "Real p \<le> Real x" using *[of 0] by (cases "f 0") (auto split: split_if_asm)
 10.2361 +
 10.2362 +      have SUP_eq: "(SUP i. f i) \<le> Real x - Real p"
 10.2363 +      proof (rule SUP_leI)
 10.2364 +        fix i show "f i \<le> Real x - Real p" unfolding pextreal_le_minus_iff
 10.2365 +        proof safe
 10.2366 +          assume "Real x \<le> Real p"
 10.2367 +          with *[of i] show "f i = 0"
 10.2368 +            by (cases "f i") (auto split: split_if_asm)
 10.2369 +        next
 10.2370 +          assume "Real p < Real x"
 10.2371 +          show "f i + Real p \<le> Real x" using * by (auto simp: field_simps)
 10.2372 +        qed
 10.2373 +      qed
 10.2374 +
 10.2375 +      show "Real p + (SUP i. f i) \<le> Real x"
 10.2376 +      proof cases
 10.2377 +        assume "Real x \<le> Real p"
 10.2378 +        with `Real p \<le> Real x` have [simp]: "Real p = Real x" by (rule antisym)
 10.2379 +        { fix i have "f i = 0" using *[of i] by (cases "f i") (auto split: split_if_asm) }
 10.2380 +        hence "(SUP i. f i) \<le> 0" by (auto intro!: SUP_leI)
 10.2381 +        thus ?thesis by simp
 10.2382 +      next
 10.2383 +        assume "\<not> Real x \<le> Real p" hence "Real p < Real x" unfolding not_le .
 10.2384 +        with SUP_eq show ?thesis unfolding pextreal_le_minus_iff by (auto simp: field_simps)
 10.2385 +      qed
 10.2386 +    qed
 10.2387 +  qed
 10.2388 +qed
 10.2389 +
 10.2390 +lemma pextreal_SUP_minus:
 10.2391 +  fixes f :: "nat \<Rightarrow> pextreal"
 10.2392 +  shows "(SUP i. c - f i) = c - (INF i. f i)"
 10.2393 +proof (rule pextreal_SUPI)
 10.2394 +  fix i have "(INF i. f i) \<le> f i" by (rule INF_leI) simp
 10.2395 +  thus "c - f i \<le> c - (INF i. f i)" by (rule pextreal_minus_le_cancel)
 10.2396 +next
 10.2397 +  fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> c - f i \<le> y"
 10.2398 +  show "c - (INF i. f i) \<le> y"
 10.2399 +  proof (cases y)
 10.2400 +    case (preal p)
 10.2401 +
 10.2402 +    show ?thesis unfolding pextreal_minus_le_iff preal
 10.2403 +    proof safe
 10.2404 +      assume INF_le_x: "(INF i. f i) \<le> c"
 10.2405 +      from * have *: "\<And>i. f i \<le> c \<Longrightarrow> c \<le> Real p + f i"
 10.2406 +        unfolding pextreal_minus_le_iff preal by auto
 10.2407 +
 10.2408 +      have INF_eq: "c - Real p \<le> (INF i. f i)"
 10.2409 +      proof (rule le_INFI)
 10.2410 +        fix i show "c - Real p \<le> f i" unfolding pextreal_minus_le_iff
 10.2411 +        proof safe
 10.2412 +          assume "Real p \<le> c"
 10.2413 +          show "c \<le> f i + Real p"
 10.2414 +          proof cases
 10.2415 +            assume "f i \<le> c" from *[OF this]
 10.2416 +            show ?thesis by (simp add: field_simps)
 10.2417 +          next
 10.2418 +            assume "\<not> f i \<le> c"
 10.2419 +            hence "c \<le> f i" by auto
 10.2420 +            also have "\<dots> \<le> f i + Real p" by auto
 10.2421 +            finally show ?thesis .
 10.2422 +          qed
 10.2423 +        qed
 10.2424 +      qed
 10.2425 +
 10.2426 +      show "c \<le> Real p + (INF i. f i)"
 10.2427 +      proof cases
 10.2428 +        assume "Real p \<le> c"
 10.2429 +        with INF_eq show ?thesis unfolding pextreal_minus_le_iff by (auto simp: field_simps)
 10.2430 +      next
 10.2431 +        assume "\<not> Real p \<le> c"
 10.2432 +        hence "c \<le> Real p" by auto
 10.2433 +        also have "Real p \<le> Real p + (INF i. f i)" by auto
 10.2434 +        finally show ?thesis .
 10.2435 +      qed
 10.2436 +    qed
 10.2437 +  qed simp
 10.2438 +qed
 10.2439 +
 10.2440 +lemma pextreal_le_minus_imp_0:
 10.2441 +  fixes a b :: pextreal
 10.2442 +  shows "a \<le> a - b \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> a \<noteq> \<omega> \<Longrightarrow> b = 0"
 10.2443 +  by (cases a, cases b, auto split: split_if_asm)
 10.2444 +
 10.2445 +lemma lim_INF_eq_lim_SUP:
 10.2446 +  fixes X :: "nat \<Rightarrow> real"
 10.2447 +  assumes "\<And>i. 0 \<le> X i" and "0 \<le> x"
 10.2448 +  and lim_INF: "(SUP n. INF m. Real (X (n + m))) = Real x" (is "(SUP n. ?INF n) = _")
 10.2449 +  and lim_SUP: "(INF n. SUP m. Real (X (n + m))) = Real x" (is "(INF n. ?SUP n) = _")
 10.2450 +  shows "X ----> x"
 10.2451 +proof (rule LIMSEQ_I)
 10.2452 +  fix r :: real assume "0 < r"
 10.2453 +  hence "0 \<le> r" by auto
 10.2454 +  from Sup_close[of "Real r" "range ?INF"]
 10.2455 +  obtain n where inf: "Real x < ?INF n + Real r"
 10.2456 +    unfolding SUPR_def lim_INF[unfolded SUPR_def] using `0 < r` by auto
 10.2457 +
 10.2458 +  from Inf_close[of "range ?SUP" "Real r"]
 10.2459 +  obtain n' where sup: "?SUP n' < Real x + Real r"
 10.2460 +    unfolding INFI_def lim_SUP[unfolded INFI_def] using `0 < r` by auto
 10.2461 +
 10.2462 +  show "\<exists>N. \<forall>n\<ge>N. norm (X n - x) < r"
 10.2463 +  proof (safe intro!: exI[of _ "max n n'"])
 10.2464 +    fix m assume "max n n' \<le> m" hence "n \<le> m" "n' \<le> m" by auto
 10.2465 +
 10.2466 +    note inf
 10.2467 +    also have "?INF n + Real r \<le> Real (X (n + (m - n))) + Real r"
 10.2468 +      by (rule le_add_Real, auto simp: `0 \<le> r` intro: INF_leI)
 10.2469 +    finally have up: "x < X m + r"
 10.2470 +      using `0 \<le> X m` `0 \<le> x` `0 \<le> r` `n \<le> m` by auto
 10.2471 +
 10.2472 +    have "Real (X (n' + (m - n'))) \<le> ?SUP n'"
 10.2473 +      by (auto simp: `0 \<le> r` intro: le_SUPI)
 10.2474 +    also note sup
 10.2475 +    finally have down: "X m < x + r"
 10.2476 +      using `0 \<le> X m` `0 \<le> x` `0 \<le> r` `n' \<le> m` by auto
 10.2477 +
 10.2478 +    show "norm (X m - x) < r" using up down by auto
 10.2479 +  qed
 10.2480 +qed
 10.2481 +
 10.2482 +lemma Sup_countable_SUPR:
 10.2483 +  assumes "Sup A \<noteq> \<omega>" "A \<noteq> {}"
 10.2484 +  shows "\<exists> f::nat \<Rightarrow> pextreal. range f \<subseteq> A \<and> Sup A = SUPR UNIV f"
 10.2485 +proof -
 10.2486 +  have "\<And>n. 0 < 1 / (of_nat n :: pextreal)" by auto
 10.2487 +  from Sup_close[OF this assms]
 10.2488 +  have "\<forall>n. \<exists>x. x \<in> A \<and> Sup A < x + 1 / of_nat n" by blast
 10.2489 +  from choice[OF this] obtain f where "range f \<subseteq> A" and
 10.2490 +    epsilon: "\<And>n. Sup A < f n + 1 / of_nat n" by blast
 10.2491 +  have "SUPR UNIV f = Sup A"
 10.2492 +  proof (rule pextreal_SUPI)
 10.2493 +    fix i show "f i \<le> Sup A" using `range f \<subseteq> A`
 10.2494 +      by (auto intro!: complete_lattice_class.Sup_upper)
 10.2495 +  next
 10.2496 +    fix y assume bound: "\<And>i. i \<in> UNIV \<Longrightarrow> f i \<le> y"
 10.2497 +    show "Sup A \<le> y"
 10.2498 +    proof (rule pextreal_le_epsilon)
 10.2499 +      fix e :: pextreal assume "0 < e"
 10.2500 +      show "Sup A \<le> y + e"
 10.2501 +      proof (cases e)
 10.2502 +        case (preal r)
 10.2503 +        hence "0 < r" using `0 < e` by auto
 10.2504 +        then obtain n where *: "inverse (of_nat n) < r" "0 < n"
 10.2505 +          using ex_inverse_of_nat_less by auto
 10.2506 +        have "Sup A \<le> f n + 1 / of_nat n" using epsilon[of n] by auto
 10.2507 +        also have "1 / of_nat n \<le> e" using preal * by (auto simp: real_eq_of_nat)
 10.2508 +        with bound have "f n + 1 / of_nat n \<le> y + e" by (rule add_mono) simp
 10.2509 +        finally show "Sup A \<le> y + e" .
 10.2510 +      qed simp
 10.2511 +    qed
 10.2512 +  qed
 10.2513 +  with `range f \<subseteq> A` show ?thesis by (auto intro!: exI[of _ f])
 10.2514 +qed
 10.2515 +
 10.2516 +lemma SUPR_countable_SUPR:
 10.2517 +  assumes "SUPR A g \<noteq> \<omega>" "A \<noteq> {}"
 10.2518 +  shows "\<exists> f::nat \<Rightarrow> pextreal. range f \<subseteq> g`A \<and> SUPR A g = SUPR UNIV f"
 10.2519 +proof -
 10.2520 +  have "Sup (g`A) \<noteq> \<omega>" "g`A \<noteq> {}" using assms unfolding SUPR_def by auto
 10.2521 +  from Sup_countable_SUPR[OF this]
 10.2522 +  show ?thesis unfolding SUPR_def .
 10.2523 +qed
 10.2524 +
 10.2525 +lemma pextreal_setsum_subtractf:
 10.2526 +  assumes "\<And>i. i\<in>A \<Longrightarrow> g i \<le> f i" and "\<And>i. i\<in>A \<Longrightarrow> f i \<noteq> \<omega>"
 10.2527 +  shows "(\<Sum>i\<in>A. f i - g i) = (\<Sum>i\<in>A. f i) - (\<Sum>i\<in>A. g i)"
 10.2528 +proof cases
 10.2529 +  assume "finite A" from this assms show ?thesis
 10.2530 +  proof induct
 10.2531 +    case (insert x A)
 10.2532 +    hence hyp: "(\<Sum>i\<in>A. f i - g i) = (\<Sum>i\<in>A. f i) - (\<Sum>i\<in>A. g i)"
 10.2533 +      by auto
 10.2534 +    { fix i assume *: "i \<in> insert x A"
 10.2535 +      hence "g i \<le> f i" using insert by simp
 10.2536 +      also have "f i < \<omega>" using * insert by (simp add: pextreal_less_\<omega>)
 10.2537 +      finally have "g i \<noteq> \<omega>" by (simp add: pextreal_less_\<omega>) }
 10.2538 +    hence "setsum g A \<noteq> \<omega>" "g x \<noteq> \<omega>" by (auto simp: setsum_\<omega>)
 10.2539 +    moreover have "setsum f A \<noteq> \<omega>" "f x \<noteq> \<omega>" using insert by (auto simp: setsum_\<omega>)
 10.2540 +    moreover have "g x \<le> f x" using insert by auto
 10.2541 +    moreover have "(\<Sum>i\<in>A. g i) \<le> (\<Sum>i\<in>A. f i)" using insert by (auto intro!: setsum_mono)
 10.2542 +    ultimately show ?case using `finite A` `x \<notin> A` hyp
 10.2543 +      by (auto simp: pextreal_noteq_omega_Ex)
 10.2544 +  qed simp
 10.2545 +qed simp
 10.2546 +
 10.2547 +lemma real_of_pextreal_diff:
 10.2548 +  "y \<le> x \<Longrightarrow> x \<noteq> \<omega> \<Longrightarrow> real x - real y = real (x - y)"
 10.2549 +  by (cases x, cases y) auto
 10.2550 +
 10.2551 +lemma psuminf_minus:
 10.2552 +  assumes ord: "\<And>i. g i \<le> f i" and fin: "psuminf g \<noteq> \<omega>" "psuminf f \<noteq> \<omega>"
 10.2553 +  shows "(\<Sum>\<^isub>\<infinity> i. f i - g i) = psuminf f - psuminf g"
 10.2554 +proof -
 10.2555 +  have [simp]: "\<And>i. f i \<noteq> \<omega>" using fin by (auto intro: psuminf_\<omega>)
 10.2556 +  from fin have "(\<lambda>x. real (f x)) sums real (\<Sum>\<^isub>\<infinity>x. f x)"
 10.2557 +    and "(\<lambda>x. real (g x)) sums real (\<Sum>\<^isub>\<infinity>x. g x)"
 10.2558 +    by (auto intro: psuminf_imp_suminf)
 10.2559 +  from sums_diff[OF this]
 10.2560 +  have "(\<lambda>n. real (f n - g n)) sums (real ((\<Sum>\<^isub>\<infinity>x. f x) - (\<Sum>\<^isub>\<infinity>x. g x)))" using fin ord
 10.2561 +    by (subst (asm) (1 2) real_of_pextreal_diff) (auto simp: psuminf_\<omega> psuminf_le)
 10.2562 +  hence "(\<Sum>\<^isub>\<infinity> i. Real (real (f i - g i))) = Real (real ((\<Sum>\<^isub>\<infinity>x. f x) - (\<Sum>\<^isub>\<infinity>x. g x)))"
 10.2563 +    by (rule suminf_imp_psuminf) simp
 10.2564 +  thus ?thesis using fin by (simp add: Real_real psuminf_\<omega>)
 10.2565 +qed
 10.2566 +
 10.2567 +lemma INF_eq_LIMSEQ:
 10.2568 +  assumes "mono (\<lambda>i. - f i)" and "\<And>n. 0 \<le> f n" and "0 \<le> x"
 10.2569 +  shows "(INF n. Real (f n)) = Real x \<longleftrightarrow> f ----> x"
 10.2570 +proof
 10.2571 +  assume x: "(INF n. Real (f n)) = Real x"
 10.2572 +  { fix n
 10.2573 +    have "Real x \<le> Real (f n)" using x[symmetric] by (auto intro: INF_leI)
 10.2574 +    hence "x \<le> f n" using assms by simp
 10.2575 +    hence "\<bar>f n - x\<bar> = f n - x" by auto }
 10.2576 +  note abs_eq = this
 10.2577 +  show "f ----> x"
 10.2578 +  proof (rule LIMSEQ_I)
 10.2579 +    fix r :: real assume "0 < r"
 10.2580 +    show "\<exists>no. \<forall>n\<ge>no. norm (f n - x) < r"
 10.2581 +    proof (rule ccontr)
 10.2582 +      assume *: "\<not> ?thesis"
 10.2583 +      { fix N
 10.2584 +        from * obtain n where *: "N \<le> n" "r \<le> f n - x"
 10.2585 +          using abs_eq by (auto simp: not_less)
 10.2586 +        hence "x + r \<le> f n" by auto
 10.2587 +        also have "f n \<le> f N" using `mono (\<lambda>i. - f i)` * by (auto dest: monoD)
 10.2588 +        finally have "Real (x + r) \<le> Real (f N)" using `0 \<le> f N` by auto }
 10.2589 +      hence "Real x < Real (x + r)"
 10.2590 +        and "Real (x + r) \<le> (INF n. Real (f n))" using `0 < r` `0 \<le> x` by (auto intro: le_INFI)
 10.2591 +      hence "Real x < (INF n. Real (f n))" by (rule less_le_trans)
 10.2592 +      thus False using x by auto
 10.2593 +    qed
 10.2594 +  qed
 10.2595 +next
 10.2596 +  assume "f ----> x"
 10.2597 +  show "(INF n. Real (f n)) = Real x"
 10.2598 +  proof (rule pextreal_INFI)
 10.2599 +    fix n
 10.2600 +    from decseq_le[OF _ `f ----> x`] assms
 10.2601 +    show "Real x \<le> Real (f n)" unfolding decseq_eq_incseq incseq_mono by auto
 10.2602 +  next
 10.2603 +    fix y assume *: "\<And>n. n\<in>UNIV \<Longrightarrow> y \<le> Real (f n)"
 10.2604 +    thus "y \<le> Real x"
 10.2605 +    proof (cases y)
 10.2606 +      case (preal r)
 10.2607 +      with * have "\<exists>N. \<forall>n\<ge>N. r \<le> f n" using assms by fastsimp
 10.2608 +      from LIMSEQ_le_const[OF `f ----> x` this]
 10.2609 +      show "y \<le> Real x" using `0 \<le> x` preal by auto
 10.2610 +    qed simp
 10.2611 +  qed
 10.2612 +qed
 10.2613 +
 10.2614 +lemma INFI_bound:
 10.2615 +  assumes "\<forall>N. x \<le> f N"
 10.2616 +  shows "x \<le> (INF n. f n)"
 10.2617 +  using assms by (simp add: INFI_def le_Inf_iff)
 10.2618 +
 10.2619 +lemma LIMSEQ_imp_lim_INF:
 10.2620 +  assumes pos: "\<And>i. 0 \<le> X i" and lim: "X ----> x"
 10.2621 +  shows "(SUP n. INF m. Real (X (n + m))) = Real x"
 10.2622 +proof -
 10.2623 +  have "0 \<le> x" using assms by (auto intro!: LIMSEQ_le_const)
 10.2624 +
 10.2625 +  have "\<And>n. (INF m. Real (X (n + m))) \<le> Real (X (n + 0))" by (rule INF_leI) simp
 10.2626 +  also have "\<And>n. Real (X (n + 0)) < \<omega>" by simp
 10.2627 +  finally have "\<forall>n. \<exists>r\<ge>0. (INF m. Real (X (n + m))) = Real r"
 10.2628 +    by (auto simp: pextreal_less_\<omega> pextreal_noteq_omega_Ex)
 10.2629 +  from choice[OF this] obtain r where r: "\<And>n. (INF m. Real (X (n + m))) = Real (r n)" "\<And>n. 0 \<le> r n"
 10.2630 +    by auto
 10.2631 +
 10.2632 +  show ?thesis unfolding r
 10.2633 +  proof (subst SUP_eq_LIMSEQ)
 10.2634 +    show "mono r" unfolding mono_def
 10.2635 +    proof safe
 10.2636 +      fix x y :: nat assume "x \<le> y"
 10.2637 +      have "Real (r x) \<le> Real (r y)" unfolding r(1)[symmetric] using pos
 10.2638 +      proof (safe intro!: INF_mono bexI)
 10.2639 +        fix m have "x + (m + y - x) = y + m"
 10.2640 +          using `x \<le> y` by auto
 10.2641 +        thus "Real (X (x + (m + y - x))) \<le> Real (X (y + m))" by simp
 10.2642 +      qed simp
 10.2643 +      thus "r x \<le> r y" using r by auto
 10.2644 +    qed
 10.2645 +    show "\<And>n. 0 \<le> r n" by fact
 10.2646 +    show "0 \<le> x" by fact
 10.2647 +    show "r ----> x"
 10.2648 +    proof (rule LIMSEQ_I)
 10.2649 +      fix e :: real assume "0 < e"
 10.2650 +      hence "0 < e/2" by auto
 10.2651 +      from LIMSEQ_D[OF lim this] obtain N where *: "\<And>n. N \<le> n \<Longrightarrow> \<bar>X n - x\<bar> < e/2"
 10.2652 +        by auto
 10.2653 +      show "\<exists>N. \<forall>n\<ge>N. norm (r n - x) < e"
 10.2654 +      proof (safe intro!: exI[of _ N])
 10.2655 +        fix n assume "N \<le> n"
 10.2656 +        show "norm (r n - x) < e"
 10.2657 +        proof cases
 10.2658 +          assume "r n < x"
 10.2659 +          have "x - r n \<le> e/2"
 10.2660 +          proof cases
 10.2661 +            assume e: "e/2 \<le> x"
 10.2662 +            have "Real (x - e/2) \<le> Real (r n)" unfolding r(1)[symmetric]
 10.2663 +            proof (rule le_INFI)
 10.2664 +              fix m show "Real (x - e / 2) \<le> Real (X (n + m))"
 10.2665 +                using *[of "n + m"] `N \<le> n`
 10.2666 +                using pos by (auto simp: field_simps abs_real_def split: split_if_asm)
 10.2667 +            qed
 10.2668 +            with e show ?thesis using pos `0 \<le> x` r(2) by auto
 10.2669 +          next
 10.2670 +            assume "\<not> e/2 \<le> x" hence "x - e/2 < 0" by auto
 10.2671 +            with `0 \<le> r n` show ?thesis by auto
 10.2672 +          qed
 10.2673 +          with `r n < x` show ?thesis by simp
 10.2674 +        next
 10.2675 +          assume e: "\<not> r n < x"
 10.2676 +          have "Real (r n) \<le> Real (X (n + 0))" unfolding r(1)[symmetric]
 10.2677 +            by (rule INF_leI) simp
 10.2678 +          hence "r n - x \<le> X n - x" using r pos by auto
 10.2679 +          also have "\<dots> < e/2" using *[OF `N \<le> n`] by (auto simp: field_simps abs_real_def split: split_if_asm)
 10.2680 +          finally have "r n - x < e" using `0 < e` by auto
 10.2681 +          with e show ?thesis by auto
 10.2682 +        qed
 10.2683 +      qed
 10.2684 +    qed
 10.2685 +  qed
 10.2686 +qed
 10.2687 +
 10.2688 +lemma real_of_pextreal_strict_mono_iff:
 10.2689 +  "real a < real b \<longleftrightarrow> (b \<noteq> \<omega> \<and> ((a = \<omega> \<and> 0 < b) \<or> (a < b)))"
 10.2690 +proof (cases a)
 10.2691 +  case infinite thus ?thesis by (cases b) auto
 10.2692 +next
 10.2693 +  case preal thus ?thesis by (cases b) auto
 10.2694 +qed
 10.2695 +
 10.2696 +lemma real_of_pextreal_mono_iff:
 10.2697 +  "real a \<le> real b \<longleftrightarrow> (a = \<omega> \<or> (b \<noteq> \<omega> \<and> a \<le> b) \<or> (b = \<omega> \<and> a = 0))"
 10.2698 +proof (cases a)
 10.2699 +  case infinite thus ?thesis by (cases b) auto
 10.2700 +next
 10.2701 +  case preal thus ?thesis by (cases b)  auto
 10.2702 +qed
 10.2703 +
 10.2704 +lemma ex_pextreal_inverse_of_nat_Suc_less:
 10.2705 +  fixes e :: pextreal assumes "0 < e" shows "\<exists>n. inverse (of_nat (Suc n)) < e"
 10.2706 +proof (cases e)
 10.2707 +  case (preal r)
 10.2708 +  with `0 < e` ex_inverse_of_nat_Suc_less[of r]
 10.2709 +  obtain n where "inverse (of_nat (Suc n)) < r" by auto
 10.2710 +  with preal show ?thesis
 10.2711 +    by (auto simp: real_eq_of_nat[symmetric])
 10.2712 +qed auto
 10.2713 +
 10.2714 +lemma Lim_eq_Sup_mono:
 10.2715 +  fixes u :: "nat \<Rightarrow> pextreal" assumes "mono u"
 10.2716 +  shows "u ----> (SUP i. u i)"
 10.2717 +proof -
 10.2718 +  from lim_pextreal_increasing[of u] `mono u`
 10.2719 +  obtain l where l: "u ----> l" unfolding mono_def by auto
 10.2720 +  from SUP_Lim_pextreal[OF _ this] `mono u`
 10.2721 +  have "(SUP i. u i) = l" unfolding mono_def by auto
 10.2722 +  with l show ?thesis by simp
 10.2723 +qed
 10.2724 +
 10.2725 +lemma isotone_Lim:
 10.2726 +  fixes x :: pextreal assumes "u \<up> x"
 10.2727 +  shows "u ----> x" (is ?lim) and "mono u" (is ?mono)
 10.2728 +proof -
 10.2729 +  show ?mono using assms unfolding mono_iff_le_Suc isoton_def by auto
 10.2730 +  from Lim_eq_Sup_mono[OF this] `u \<up> x`
 10.2731 +  show ?lim unfolding isoton_def by simp
 10.2732 +qed
 10.2733 +
 10.2734 +lemma isoton_iff_Lim_mono:
 10.2735 +  fixes u :: "nat \<Rightarrow> pextreal"
 10.2736 +  shows "u \<up> x \<longleftrightarrow> (mono u \<and> u ----> x)"
 10.2737 +proof safe
 10.2738 +  assume "mono u" and x: "u ----> x"
 10.2739 +  with SUP_Lim_pextreal[OF _ x]
 10.2740 +  show "u \<up> x" unfolding isoton_def
 10.2741 +    using `mono u`[unfolded mono_def]
 10.2742 +    using `mono u`[unfolded mono_iff_le_Suc]
 10.2743 +    by auto
 10.2744 +qed (auto dest: isotone_Lim)
 10.2745 +
 10.2746 +lemma pextreal_inverse_inverse[simp]:
 10.2747 +  fixes x :: pextreal
 10.2748 +  shows "inverse (inverse x) = x"
 10.2749 +  by (cases x) auto
 10.2750 +
 10.2751 +lemma atLeastAtMost_omega_eq_atLeast:
 10.2752 +  shows "{a .. \<omega>} = {a ..}"
 10.2753 +by auto
 10.2754 +
 10.2755 +lemma atLeast0AtMost_eq_atMost: "{0 :: pextreal .. a} = {.. a}" by auto
 10.2756 +
 10.2757 +lemma greaterThan_omega_Empty: "{\<omega> <..} = {}" by auto
 10.2758 +
 10.2759 +lemma lessThan_0_Empty: "{..< 0 :: pextreal} = {}" by auto
 10.2760 +
 10.2761 +lemma real_of_pextreal_inverse[simp]:
 10.2762 +  fixes X :: pextreal
 10.2763 +  shows "real (inverse X) = 1 / real X"
 10.2764 +  by (cases X) (auto simp: inverse_eq_divide)
 10.2765 +
 10.2766 +lemma real_of_pextreal_le_0[simp]: "real (X :: pextreal) \<le> 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
 10.2767 +  by (cases X) auto
 10.2768 +
 10.2769 +lemma real_of_pextreal_less_0[simp]: "\<not> (real (X :: pextreal) < 0)"
 10.2770 +  by (cases X) auto
 10.2771 +
 10.2772 +lemma abs_real_of_pextreal[simp]: "\<bar>real (X :: pextreal)\<bar> = real X"
 10.2773 +  by simp
 10.2774 +
 10.2775 +lemma zero_less_real_of_pextreal: "0 < real (X :: pextreal) \<longleftrightarrow> X \<noteq> 0 \<and> X \<noteq> \<omega>"
 10.2776 +  by (cases X) auto
 10.2777 +
 10.2778 +end
    11.1 --- a/src/HOL/Probability/Positive_Infinite_Real.thy	Mon Dec 06 19:18:02 2010 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,2775 +0,0 @@
    11.4 -(* Author: Johannes Hoelzl, TU Muenchen *)
    11.5 -
    11.6 -header {* A type for positive real numbers with infinity *}
    11.7 -
    11.8 -theory Positive_Infinite_Real
    11.9 -  imports Complex_Main Nat_Bijection Multivariate_Analysis
   11.10 -begin
   11.11 -
   11.12 -lemma (in complete_lattice) Sup_start:
   11.13 -  assumes *: "\<And>x. f x \<le> f 0"
   11.14 -  shows "(SUP n. f n) = f 0"
   11.15 -proof (rule antisym)
   11.16 -  show "f 0 \<le> (SUP n. f n)" by (rule le_SUPI) auto
   11.17 -  show "(SUP n. f n) \<le> f 0" by (rule SUP_leI[OF *])
   11.18 -qed
   11.19 -
   11.20 -lemma (in complete_lattice) Inf_start:
   11.21 -  assumes *: "\<And>x. f 0 \<le> f x"
   11.22 -  shows "(INF n. f n) = f 0"
   11.23 -proof (rule antisym)
   11.24 -  show "(INF n. f n) \<le> f 0" by (rule INF_leI) simp
   11.25 -  show "f 0 \<le> (INF n. f n)" by (rule le_INFI[OF *])
   11.26 -qed
   11.27 -
   11.28 -lemma (in complete_lattice) Sup_mono_offset:
   11.29 -  fixes f :: "'b :: {ordered_ab_semigroup_add,monoid_add} \<Rightarrow> 'a"
   11.30 -  assumes *: "\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y" and "0 \<le> k"
   11.31 -  shows "(SUP n . f (k + n)) = (SUP n. f n)"
   11.32 -proof (rule antisym)
   11.33 -  show "(SUP n. f (k + n)) \<le> (SUP n. f n)"
   11.34 -    by (auto intro!: Sup_mono simp: SUPR_def)
   11.35 -  { fix n :: 'b
   11.36 -    have "0 + n \<le> k + n" using `0 \<le> k` by (rule add_right_mono)
   11.37 -    with * have "f n \<le> f (k + n)" by simp }
   11.38 -  thus "(SUP n. f n) \<le> (SUP n. f (k + n))"
   11.39 -    by (auto intro!: Sup_mono exI simp: SUPR_def)
   11.40 -qed
   11.41 -
   11.42 -lemma (in complete_lattice) Sup_mono_offset_Suc:
   11.43 -  assumes *: "\<And>x. f x \<le> f (Suc x)"
   11.44 -  shows "(SUP n . f (Suc n)) = (SUP n. f n)"
   11.45 -  unfolding Suc_eq_plus1
   11.46 -  apply (subst add_commute)
   11.47 -  apply (rule Sup_mono_offset)
   11.48 -  by (auto intro!: order.lift_Suc_mono_le[of "op \<le>" "op <" f, OF _ *]) default
   11.49 -
   11.50 -lemma (in complete_lattice) Inf_mono_offset:
   11.51 -  fixes f :: "'b :: {ordered_ab_semigroup_add,monoid_add} \<Rightarrow> 'a"
   11.52 -  assumes *: "\<And>x y. x \<le> y \<Longrightarrow> f y \<le> f x" and "0 \<le> k"
   11.53 -  shows "(INF n . f (k + n)) = (INF n. f n)"
   11.54 -proof (rule antisym)
   11.55 -  show "(INF n. f n) \<le> (INF n. f (k + n))"
   11.56 -    by (auto intro!: Inf_mono simp: INFI_def)
   11.57 -  { fix n :: 'b
   11.58 -    have "0 + n \<le> k + n" using `0 \<le> k` by (rule add_right_mono)
   11.59 -    with * have "f (k + n) \<le> f n" by simp }
   11.60 -  thus "(INF n. f (k + n)) \<le> (INF n. f n)"
   11.61 -    by (auto intro!: Inf_mono exI simp: INFI_def)
   11.62 -qed
   11.63 -
   11.64 -lemma (in complete_lattice) isotone_converge:
   11.65 -  fixes f :: "nat \<Rightarrow> 'a" assumes "\<And>x y. x \<le> y \<Longrightarrow> f x \<le> f y "
   11.66 -  shows "(INF n. SUP m. f (n + m)) = (SUP n. INF m. f (n + m))"
   11.67 -proof -
   11.68 -  have "\<And>n. (SUP m. f (n + m)) = (SUP n. f n)"
   11.69 -    apply (rule Sup_mono_offset)
   11.70 -    apply (rule assms)
   11.71 -    by simp_all
   11.72 -  moreover
   11.73 -  { fix n have "(INF m. f (n + m)) = f n"
   11.74 -      using Inf_start[of "\<lambda>m. f (n + m)"] assms by simp }
   11.75 -  ultimately show ?thesis by simp
   11.76 -qed
   11.77 -
   11.78 -lemma (in complete_lattice) antitone_converges:
   11.79 -  fixes f :: "nat \<Rightarrow> 'a" assumes "\<And>x y. x \<le> y \<Longrightarrow> f y \<le> f x"
   11.80 -  shows "(INF n. SUP m. f (n + m)) = (SUP n. INF m. f (n + m))"
   11.81 -proof -
   11.82 -  have "\<And>n. (INF m. f (n + m)) = (INF n. f n)"
   11.83 -    apply (rule Inf_mono_offset)
   11.84 -    apply (rule assms)
   11.85 -    by simp_all
   11.86 -  moreover
   11.87 -  { fix n have "(SUP m. f (n + m)) = f n"
   11.88 -      using Sup_start[of "\<lambda>m. f (n + m)"] assms by simp }
   11.89 -  ultimately show ?thesis by simp
   11.90 -qed
   11.91 -
   11.92 -lemma (in complete_lattice) lim_INF_le_lim_SUP:
   11.93 -  fixes f :: "nat \<Rightarrow> 'a"
   11.94 -  shows "(SUP n. INF m. f (n + m)) \<le> (INF n. SUP m. f (n + m))"
   11.95 -proof (rule SUP_leI, rule le_INFI)
   11.96 -  fix i j show "(INF m. f (i + m)) \<le> (SUP m. f (j + m))"
   11.97 -  proof (cases rule: le_cases)
   11.98 -    assume "i \<le> j"
   11.99 -    have "(INF m. f (i + m)) \<le> f (i + (j - i))" by (rule INF_leI) simp
  11.100 -    also have "\<dots> = f (j + 0)" using `i \<le> j` by auto
  11.101 -    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
  11.102 -    finally show ?thesis .
  11.103 -  next
  11.104 -    assume "j \<le> i"
  11.105 -    have "(INF m. f (i + m)) \<le> f (i + 0)" by (rule INF_leI) simp
  11.106 -    also have "\<dots> = f (j + (i - j))" using `j \<le> i` by auto
  11.107 -    also have "\<dots> \<le> (SUP m. f (j + m))" by (rule le_SUPI) simp
  11.108 -    finally show ?thesis .
  11.109 -  qed
  11.110 -qed
  11.111 -
  11.112 -text {*
  11.113 -
  11.114 -We introduce the the positive real numbers as needed for measure theory.
  11.115 -
  11.116 -*}
  11.117 -
  11.118 -typedef pinfreal = "(Some ` {0::real..}) \<union> {None}"
  11.119 -  by (rule exI[of _ None]) simp
  11.120 -
  11.121 -subsection "Introduce @{typ pinfreal} similar to a datatype"
  11.122 -
  11.123 -definition "Real x = Abs_pinfreal (Some (sup 0 x))"
  11.124 -definition "\<omega> = Abs_pinfreal None"
  11.125 -
  11.126 -definition "pinfreal_case f i x = (if x = \<omega> then i else f (THE r. 0 \<le> r \<and> x = Real r))"
  11.127 -
  11.128 -definition "of_pinfreal = pinfreal_case (\<lambda>x. x) 0"
  11.129 -
  11.130 -defs (overloaded)
  11.131 -  real_of_pinfreal_def [code_unfold]: "real == of_pinfreal"
  11.132 -
  11.133 -lemma pinfreal_Some[simp]: "0 \<le> x \<Longrightarrow> Some x \<in> pinfreal"
  11.134 -  unfolding pinfreal_def by simp
  11.135 -
  11.136 -lemma pinfreal_Some_sup[simp]: "Some (sup 0 x) \<in> pinfreal"
  11.137 -  by (simp add: sup_ge1)
  11.138 -
  11.139 -lemma pinfreal_None[simp]: "None \<in> pinfreal"
  11.140 -  unfolding pinfreal_def by simp
  11.141 -
  11.142 -lemma Real_inj[simp]:
  11.143 -  assumes  "0 \<le> x" and "0 \<le> y"
  11.144 -  shows "Real x = Real y \<longleftrightarrow> x = y"
  11.145 -  unfolding Real_def assms[THEN sup_absorb2]
  11.146 -  using assms by (simp add: Abs_pinfreal_inject)
  11.147 -
  11.148 -lemma Real_neq_\<omega>[simp]:
  11.149 -  "Real x = \<omega> \<longleftrightarrow> False"
  11.150 -  "\<omega> = Real x \<longleftrightarrow> False"
  11.151 -  by (simp_all add: Abs_pinfreal_inject \<omega>_def Real_def)
  11.152 -
  11.153 -lemma Real_neg: "x < 0 \<Longrightarrow> Real x = Real 0"
  11.154 -  unfolding Real_def by (auto simp add: Abs_pinfreal_inject intro!: sup_absorb1)
  11.155 -
  11.156 -lemma pinfreal_cases[case_names preal infinite, cases type: pinfreal]:
  11.157 -  assumes preal: "\<And>r. x = Real r \<Longrightarrow> 0 \<le> r \<Longrightarrow> P" and inf: "x = \<omega> \<Longrightarrow> P"
  11.158 -  shows P
  11.159 -proof (cases x rule: pinfreal.Abs_pinfreal_cases)
  11.160 -  case (Abs_pinfreal y)
  11.161 -  hence "y = None \<or> (\<exists>x \<ge> 0. y = Some x)"
  11.162 -    unfolding pinfreal_def by auto
  11.163 -  thus P
  11.164 -  proof (rule disjE)
  11.165 -    assume "\<exists>x\<ge>0. y = Some x" then guess x ..
  11.166 -    thus P by (simp add: preal[of x] Real_def Abs_pinfreal(1) sup_absorb2)
  11.167 -  qed (simp add: \<omega>_def Abs_pinfreal(1) inf)
  11.168 -qed
  11.169 -
  11.170 -lemma pinfreal_case_\<omega>[simp]: "pinfreal_case f i \<omega> = i"
  11.171 -  unfolding pinfreal_case_def by simp
  11.172 -
  11.173 -lemma pinfreal_case_Real[simp]: "pinfreal_case f i (Real x) = (if 0 \<le> x then f x else f 0)"
  11.174 -proof (cases "0 \<le> x")
  11.175 -  case True thus ?thesis unfolding pinfreal_case_def by (auto intro: theI2)
  11.176 -next
  11.177 -  case False
  11.178 -  moreover have "(THE r. 0 \<le> r \<and> Real 0 = Real r) = 0"
  11.179 -    by (auto intro!: the_equality)
  11.180 -  ultimately show ?thesis unfolding pinfreal_case_def by (simp add: Real_neg)
  11.181 -qed
  11.182 -
  11.183 -lemma pinfreal_case_cancel[simp]: "pinfreal_case (\<lambda>c. i) i x = i"
  11.184 -  by (cases x) simp_all
  11.185 -
  11.186 -lemma pinfreal_case_split:
  11.187 -  "P (pinfreal_case f i x) = ((x = \<omega> \<longrightarrow> P i) \<and> (\<forall>r\<ge>0. x = Real r \<longrightarrow> P (f r)))"
  11.188 -  by (cases x) simp_all
  11.189 -
  11.190 -lemma pinfreal_case_split_asm:
  11.191 -  "P (pinfreal_case f i x) = (\<not> (x = \<omega> \<and> \<not> P i \<or> (\<exists>r. r \<ge> 0 \<and> x = Real r \<and> \<not> P (f r))))"
  11.192 -  by (cases x) auto
  11.193 -
  11.194 -lemma pinfreal_case_cong[cong]:
  11.195 -  assumes eq: "x = x'" "i = i'" and cong: "\<And>r. 0 \<le> r \<Longrightarrow> f r = f' r"
  11.196 -  shows "pinfreal_case f i x = pinfreal_case f' i' x'"
  11.197 -  unfolding eq using cong by (cases x') simp_all
  11.198 -
  11.199 -lemma real_Real[simp]: "real (Real x) = (if 0 \<le> x then x else 0)"
  11.200 -  unfolding real_of_pinfreal_def of_pinfreal_def by simp
  11.201 -
  11.202 -lemma Real_real_image:
  11.203 -  assumes "\<omega> \<notin> A" shows "Real ` real ` A = A"
  11.204 -proof safe
  11.205 -  fix x assume "x \<in> A"
  11.206 -  hence *: "x = Real (real x)"
  11.207 -    using `\<omega> \<notin> A` by (cases x) auto
  11.208 -  show "x \<in> Real ` real ` A"
  11.209 -    using `x \<in> A` by (subst *) (auto intro!: imageI)
  11.210 -next
  11.211 -  fix x assume "x \<in> A"
  11.212 -  thus "Real (real x) \<in> A"
  11.213 -    using `\<omega> \<notin> A` by (cases x) auto
  11.214 -qed
  11.215 -
  11.216 -lemma real_pinfreal_nonneg[simp, intro]: "0 \<le> real (x :: pinfreal)"
  11.217 -  unfolding real_of_pinfreal_def of_pinfreal_def
  11.218 -  by (cases x) auto
  11.219 -
  11.220 -lemma real_\<omega>[simp]: "real \<omega> = 0"
  11.221 -  unfolding real_of_pinfreal_def of_pinfreal_def by simp
  11.222 -
  11.223 -lemma pinfreal_noteq_omega_Ex: "X \<noteq> \<omega> \<longleftrightarrow> (\<exists>r\<ge>0. X = Real r)" by (cases X) auto
  11.224 -
  11.225 -subsection "@{typ pinfreal} is a monoid for addition"
  11.226 -
  11.227 -instantiation pinfreal :: comm_monoid_add
  11.228 -begin
  11.229 -
  11.230 -definition "0 = Real 0"
  11.231 -definition "x + y = pinfreal_case (\<lambda>r. pinfreal_case (\<lambda>p. Real (r + p)) \<omega> y) \<omega> x"
  11.232 -
  11.233 -lemma pinfreal_plus[simp]:
  11.234 -  "Real r + Real p = (if 0 \<le> r then if 0 \<le> p then Real (r + p) else Real r else Real p)"
  11.235 -  "x + 0 = x"
  11.236 -  "0 + x = x"
  11.237 -  "x + \<omega> = \<omega>"
  11.238 -  "\<omega> + x = \<omega>"
  11.239 -  by (simp_all add: plus_pinfreal_def Real_neg zero_pinfreal_def split: pinfreal_case_split)
  11.240 -
  11.241 -lemma \<omega>_neq_0[simp]:
  11.242 -  "\<omega> = 0 \<longleftrightarrow> False"
  11.243 -  "0 = \<omega> \<longleftrightarrow> False"
  11.244 -  by (simp_all add: zero_pinfreal_def)
  11.245 -
  11.246 -lemma Real_eq_0[simp]:
  11.247 -  "Real r = 0 \<longleftrightarrow> r \<le> 0"
  11.248 -  "0 = Real r \<longleftrightarrow> r \<le> 0"
  11.249 -  by (auto simp add: Abs_pinfreal_inject zero_pinfreal_def Real_def sup_real_def)
  11.250 -
  11.251 -lemma Real_0[simp]: "Real 0 = 0" by (simp add: zero_pinfreal_def)
  11.252 -
  11.253 -instance
  11.254 -proof
  11.255 -  fix a :: pinfreal
  11.256 -  show "0 + a = a" by (cases a) simp_all
  11.257 -
  11.258 -  fix b show "a + b = b + a"
  11.259 -    by (cases a, cases b) simp_all
  11.260 -
  11.261 -  fix c show "a + b + c = a + (b + c)"
  11.262 -    by (cases a, cases b, cases c) simp_all
  11.263 -qed
  11.264 -end
  11.265 -
  11.266 -lemma pinfreal_plus_eq_\<omega>[simp]: "(a :: pinfreal) + b = \<omega> \<longleftrightarrow> a = \<omega> \<or> b = \<omega>"
  11.267 -  by (cases a, cases b) auto
  11.268 -
  11.269 -lemma pinfreal_add_cancel_left:
  11.270 -  "a + b = a + c \<longleftrightarrow> (a = \<omega> \<or> b = c)"
  11.271 -  by (cases a, cases b, cases c, simp_all, cases c, simp_all)
  11.272 -
  11.273 -lemma pinfreal_add_cancel_right:
  11.274 -  "b + a = c + a \<longleftrightarrow> (a = \<omega> \<or> b = c)"
  11.275 -  by (cases a, cases b, cases c, simp_all, cases c, simp_all)
  11.276 -
  11.277 -lemma Real_eq_Real:
  11.278 -  "Real a = Real b \<longleftrightarrow> (a = b \<or> (a \<le> 0 \<and> b \<le> 0))"
  11.279 -proof (cases "a \<le> 0 \<or> b \<le> 0")
  11.280 -  case False with Real_inj[of a b] show ?thesis by auto
  11.281 -next
  11.282 -  case True
  11.283 -  thus ?thesis
  11.284 -  proof
  11.285 -    assume "a \<le> 0"
  11.286 -    hence *: "Real a = 0" by simp
  11.287 -    show ?thesis using `a \<le> 0` unfolding * by auto
  11.288 -  next
  11.289 -    assume "b \<le> 0"
  11.290 -    hence *: "Real b = 0" by simp
  11.291 -    show ?thesis using `b \<le> 0` unfolding * by auto
  11.292 -  qed
  11.293 -qed
  11.294 -
  11.295 -lemma real_pinfreal_0[simp]: "real (0 :: pinfreal) = 0"
  11.296 -  unfolding zero_pinfreal_def real_Real by simp
  11.297 -
  11.298 -lemma real_of_pinfreal_eq_0: "real X = 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
  11.299 -  by (cases X) auto
  11.300 -
  11.301 -lemma real_of_pinfreal_eq: "real X = real Y \<longleftrightarrow>
  11.302 -    (X = Y \<or> (X = 0 \<and> Y = \<omega>) \<or> (Y = 0 \<and> X = \<omega>))"
  11.303 -  by (cases X, cases Y) (auto simp add: real_of_pinfreal_eq_0)
  11.304 -
  11.305 -lemma real_of_pinfreal_add: "real X + real Y =
  11.306 -    (if X = \<omega> then real Y else if Y = \<omega> then real X else real (X + Y))"
  11.307 -  by (auto simp: pinfreal_noteq_omega_Ex)
  11.308 -
  11.309 -subsection "@{typ pinfreal} is a monoid for multiplication"
  11.310 -
  11.311 -instantiation pinfreal :: comm_monoid_mult
  11.312 -begin
  11.313 -
  11.314 -definition "1 = Real 1"
  11.315 -definition "x * y = (if x = 0 \<or> y = 0 then 0 else
  11.316 -  pinfreal_case (\<lambda>r. pinfreal_case (\<lambda>p. Real (r * p)) \<omega> y) \<omega> x)"
  11.317 -
  11.318 -lemma pinfreal_times[simp]:
  11.319 -  "Real r * Real p = (if 0 \<le> r \<and> 0 \<le> p then Real (r * p) else 0)"
  11.320 -  "\<omega> * x = (if x = 0 then 0 else \<omega>)"
  11.321 -  "x * \<omega> = (if x = 0 then 0 else \<omega>)"
  11.322 -  "0 * x = 0"
  11.323 -  "x * 0 = 0"
  11.324 -  "1 = \<omega> \<longleftrightarrow> False"
  11.325 -  "\<omega> = 1 \<longleftrightarrow> False"
  11.326 -  by (auto simp add: times_pinfreal_def one_pinfreal_def)
  11.327 -
  11.328 -lemma pinfreal_one_mult[simp]:
  11.329 -  "Real x + 1 = (if 0 \<le> x then Real (x + 1) else 1)"
  11.330 -  "1 + Real x = (if 0 \<le> x then Real (1 + x) else 1)"
  11.331 -  unfolding one_pinfreal_def by simp_all
  11.332 -
  11.333 -instance
  11.334 -proof
  11.335 -  fix a :: pinfreal show "1 * a = a"
  11.336 -    by (cases a) (simp_all add: one_pinfreal_def)
  11.337 -
  11.338 -  fix b show "a * b = b * a"
  11.339 -    by (cases a, cases b) (simp_all add: mult_nonneg_nonneg)
  11.340 -
  11.341 -  fix c show "a * b * c = a * (b * c)"
  11.342 -    apply (cases a, cases b, cases c)
  11.343 -    apply (simp_all add: mult_nonneg_nonneg not_le mult_pos_pos)
  11.344 -    apply (cases b, cases c)
  11.345 -    apply (simp_all add: mult_nonneg_nonneg not_le mult_pos_pos)
  11.346 -    done
  11.347 -qed
  11.348 -end
  11.349 -
  11.350 -lemma pinfreal_mult_cancel_left:
  11.351 -  "a * b = a * c \<longleftrightarrow> (a = 0 \<or> b = c \<or> (a = \<omega> \<and> b \<noteq> 0 \<and> c \<noteq> 0))"
  11.352 -  by (cases a, cases b, cases c, auto simp: Real_eq_Real mult_le_0_iff, cases c, auto)
  11.353 -
  11.354 -lemma pinfreal_mult_cancel_right:
  11.355 -  "b * a = c * a \<longleftrightarrow> (a = 0 \<or> b = c \<or> (a = \<omega> \<and> b \<noteq> 0 \<and> c \<noteq> 0))"
  11.356 -  by (cases a, cases b, cases c, auto simp: Real_eq_Real mult_le_0_iff, cases c, auto)
  11.357 -
  11.358 -lemma Real_1[simp]: "Real 1 = 1" by (simp add: one_pinfreal_def)
  11.359 -
  11.360 -lemma real_pinfreal_1[simp]: "real (1 :: pinfreal) = 1"
  11.361 -  unfolding one_pinfreal_def real_Real by simp
  11.362 -
  11.363 -lemma real_of_pinfreal_mult: "real X * real Y = real (X * Y :: pinfreal)"
  11.364 -  by (cases X, cases Y) (auto simp: zero_le_mult_iff)
  11.365 -
  11.366 -lemma Real_mult_nonneg: assumes "x \<ge> 0" "y \<ge> 0"
  11.367 -  shows "Real (x * y) = Real x * Real y" using assms by auto
  11.368 -
  11.369 -lemma Real_setprod: assumes "\<forall>x\<in>A. f x \<ge> 0" shows "Real (setprod f A) = setprod (\<lambda>x. Real (f x)) A"
  11.370 -proof(cases "finite A")
  11.371 -  case True thus ?thesis using assms
  11.372 -  proof(induct A) case (insert x A)
  11.373 -    have "0 \<le> setprod f A" apply(rule setprod_nonneg) using insert by auto
  11.374 -    thus ?case unfolding setprod_insert[OF insert(1-2)] apply-
  11.375 -      apply(subst Real_mult_nonneg) prefer 3 apply(subst insert(3)[THEN sym])
  11.376 -      using insert by auto
  11.377 -  qed auto
  11.378 -qed auto
  11.379 -
  11.380 -subsection "@{typ pinfreal} is a linear order"
  11.381 -
  11.382 -instantiation pinfreal :: linorder
  11.383 -begin
  11.384 -
  11.385 -definition "x < y \<longleftrightarrow> pinfreal_case (\<lambda>i. pinfreal_case (\<lambda>j. i < j) True y) False x"
  11.386 -definition "x \<le> y \<longleftrightarrow> pinfreal_case (\<lambda>j. pinfreal_case (\<lambda>i. i \<le> j) False x) True y"
  11.387 -
  11.388 -lemma pinfreal_less[simp]:
  11.389 -  "Real r < \<omega>"
  11.390 -  "Real r < Real p \<longleftrightarrow> (if 0 \<le> r \<and> 0 \<le> p then r < p else 0 < p)"
  11.391 -  "\<omega> < x \<longleftrightarrow> False"
  11.392 -  "0 < \<omega>"
  11.393 -  "0 < Real r \<longleftrightarrow> 0 < r"
  11.394 -  "x < 0 \<longleftrightarrow> False"
  11.395 -  "0 < (1::pinfreal)"
  11.396 -  by (simp_all add: less_pinfreal_def zero_pinfreal_def one_pinfreal_def del: Real_0 Real_1)
  11.397 -
  11.398 -lemma pinfreal_less_eq[simp]:
  11.399 -  "x \<le> \<omega>"
  11.400 -  "Real r \<le> Real p \<longleftrightarrow> (if 0 \<le> r \<and> 0 \<le> p then r \<le> p else r \<le> 0)"
  11.401 -  "0 \<le> x"
  11.402 -  by (simp_all add: less_eq_pinfreal_def zero_pinfreal_def del: Real_0)
  11.403 -
  11.404 -lemma pinfreal_\<omega>_less_eq[simp]:
  11.405 -  "\<omega> \<le> x \<longleftrightarrow> x = \<omega>"
  11.406 -  by (cases x) (simp_all add: not_le less_eq_pinfreal_def)
  11.407 -
  11.408 -lemma pinfreal_less_eq_zero[simp]:
  11.409 -  "(x::pinfreal) \<le> 0 \<longleftrightarrow> x = 0"
  11.410 -  by (cases x) (simp_all add: zero_pinfreal_def del: Real_0)
  11.411 -
  11.412 -instance
  11.413 -proof
  11.414 -  fix x :: pinfreal
  11.415 -  show "x \<le> x" by (cases x) simp_all
  11.416 -  fix y
  11.417 -  show "(x < y) = (x \<le> y \<and> \<not> y \<le> x)"
  11.418 -    by (cases x, cases y) auto
  11.419 -  show "x \<le> y \<or> y \<le> x "
  11.420 -    by (cases x, cases y) auto
  11.421 -  { assume "x \<le> y" "y \<le> x" thus "x = y"
  11.422 -      by (cases x, cases y) auto }
  11.423 -  { fix z assume "x \<le> y" "y \<le> z"
  11.424 -    thus "x \<le> z" by (cases x, cases y, cases z) auto }
  11.425 -qed
  11.426 -end
  11.427 -
  11.428 -lemma pinfreal_zero_lessI[intro]:
  11.429 -  "(a :: pinfreal) \<noteq> 0 \<Longrightarrow> 0 < a"
  11.430 -  by (cases a) auto
  11.431 -
  11.432 -lemma pinfreal_less_omegaI[intro, simp]:
  11.433 -  "a \<noteq> \<omega> \<Longrightarrow> a < \<omega>"
  11.434 -  by (cases a) auto
  11.435 -
  11.436 -lemma pinfreal_plus_eq_0[simp]: "(a :: pinfreal) + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
  11.437 -  by (cases a, cases b) auto
  11.438 -
  11.439 -lemma pinfreal_le_add1[simp, intro]: "n \<le> n + (m::pinfreal)"
  11.440 -  by (cases n, cases m) simp_all
  11.441 -
  11.442 -lemma pinfreal_le_add2: "(n::pinfreal) + m \<le> k \<Longrightarrow> m \<le> k"
  11.443 -  by (cases n, cases m, cases k) simp_all
  11.444 -
  11.445 -lemma pinfreal_le_add3: "(n::pinfreal) + m \<le> k \<Longrightarrow> n \<le> k"
  11.446 -  by (cases n, cases m, cases k) simp_all
  11.447 -
  11.448 -lemma pinfreal_less_\<omega>: "x < \<omega> \<longleftrightarrow> x \<noteq> \<omega>"
  11.449 -  by (cases x) auto
  11.450 -
  11.451 -lemma pinfreal_0_less_mult_iff[simp]:
  11.452 -  fixes x y :: pinfreal shows "0 < x * y \<longleftrightarrow> 0 < x \<and> 0 < y"
  11.453 -  by (cases x, cases y) (auto simp: zero_less_mult_iff)
  11.454 -
  11.455 -lemma pinfreal_ord_one[simp]:
  11.456 -  "Real p < 1 \<longleftrightarrow> p < 1"
  11.457 -  "Real p \<le> 1 \<longleftrightarrow> p \<le> 1"
  11.458 -  "1 < Real p \<longleftrightarrow> 1 < p"
  11.459 -  "1 \<le> Real p \<longleftrightarrow> 1 \<le> p"
  11.460 -  by (simp_all add: one_pinfreal_def del: Real_1)
  11.461 -
  11.462 -subsection {* @{text "x - y"} on @{typ pinfreal} *}
  11.463 -
  11.464 -instantiation pinfreal :: minus
  11.465 -begin
  11.466 -definition "x - y = (if y < x then THE d. x = y + d else 0 :: pinfreal)"
  11.467 -
  11.468 -lemma minus_pinfreal_eq:
  11.469 -  "(x - y = (z :: pinfreal)) \<longleftrightarrow> (if y < x then x = y + z else z = 0)"
  11.470 -  (is "?diff \<longleftrightarrow> ?if")
  11.471 -proof
  11.472 -  assume ?diff
  11.473 -  thus ?if
  11.474 -  proof (cases "y < x")
  11.475 -    case True
  11.476 -    then obtain p where p: "y = Real p" "0 \<le> p" by (cases y) auto
  11.477 -
  11.478 -    show ?thesis unfolding `?diff`[symmetric] if_P[OF True] minus_pinfreal_def
  11.479 -    proof (rule theI2[where Q="\<lambda>d. x = y + d"])
  11.480 -      show "x = y + pinfreal_case (\<lambda>r. Real (r - real y)) \<omega> x" (is "x = y + ?d")
  11.481 -        using `y < x` p by (cases x) simp_all
  11.482 -
  11.483 -      fix d assume "x = y + d"
  11.484 -      thus "d = ?d" using `y < x` p by (cases d, cases x) simp_all
  11.485 -    qed simp
  11.486 -  qed (simp add: minus_pinfreal_def)
  11.487 -next
  11.488 -  assume ?if
  11.489 -  thus ?diff
  11.490 -  proof (cases "y < x")
  11.491 -    case True
  11.492 -    then obtain p where p: "y = Real p" "0 \<le> p" by (cases y) auto
  11.493 -
  11.494 -    from True `?if` have "x = y + z" by simp
  11.495 -
  11.496 -    show ?thesis unfolding minus_pinfreal_def if_P[OF True] unfolding `x = y + z`
  11.497 -    proof (rule the_equality)
  11.498 -      fix d :: pinfreal assume "y + z = y + d"
  11.499 -      thus "d = z" using `y < x` p
  11.500 -        by (cases d, cases z) simp_all
  11.501 -    qed simp
  11.502 -  qed (simp add: minus_pinfreal_def)
  11.503 -qed
  11.504 -
  11.505 -instance ..
  11.506 -end
  11.507 -
  11.508 -lemma pinfreal_minus[simp]:
  11.509 -  "Real r - Real p = (if 0 \<le> r \<and> p < r then if 0 \<le> p then Real (r - p) else Real r else 0)"
  11.510 -  "(A::pinfreal) - A = 0"
  11.511 -  "\<omega> - Real r = \<omega>"
  11.512 -  "Real r - \<omega> = 0"
  11.513 -  "A - 0 = A"
  11.514 -  "0 - A = 0"
  11.515 -  by (auto simp: minus_pinfreal_eq not_less)
  11.516 -
  11.517 -lemma pinfreal_le_epsilon:
  11.518 -  fixes x y :: pinfreal
  11.519 -  assumes "\<And>e. 0 < e \<Longrightarrow> x \<le> y + e"
  11.520 -  shows "x \<le> y"
  11.521 -proof (cases y)
  11.522 -  case (preal r)
  11.523 -  then obtain p where x: "x = Real p" "0 \<le> p"
  11.524 -    using assms[of 1] by (cases x) auto
  11.525 -  { fix e have "0 < e \<Longrightarrow> p \<le> r + e"
  11.526 -      using assms[of "Real e"] preal x by auto }
  11.527 -  hence "p \<le> r" by (rule field_le_epsilon)
  11.528 -  thus ?thesis using preal x by auto
  11.529 -qed simp
  11.530 -
  11.531 -instance pinfreal :: "{ordered_comm_semiring, comm_semiring_1}"
  11.532 -proof
  11.533 -  show "0 \<noteq> (1::pinfreal)" unfolding zero_pinfreal_def one_pinfreal_def
  11.534 -    by (simp del: Real_1 Real_0)
  11.535 -
  11.536 -  fix a :: pinfreal
  11.537 -  show "0 * a = 0" "a * 0 = 0" by simp_all
  11.538 -
  11.539 -  fix b c :: pinfreal
  11.540 -  show "(a + b) * c = a * c + b * c"
  11.541 -    by (cases c, cases a, cases b)
  11.542 -       (auto intro!: arg_cong[where f=Real] simp: field_simps not_le mult_le_0_iff mult_less_0_iff)
  11.543 -
  11.544 -  { assume "a \<le> b" thus "c + a \<le> c + b"
  11.545 -     by (cases c, cases a, cases b) auto }
  11.546 -
  11.547 -  assume "a \<le> b" "0 \<le> c"
  11.548 -  thus "c * a \<le> c * b"
  11.549 -    apply (cases c, cases a, cases b)
  11.550 -    by (auto simp: mult_left_mono mult_le_0_iff mult_less_0_iff not_le)
  11.551 -qed
  11.552 -
  11.553 -lemma mult_\<omega>[simp]: "x * y = \<omega> \<longleftrightarrow> (x = \<omega> \<or> y = \<omega>) \<and> x \<noteq> 0 \<and> y \<noteq> 0"
  11.554 -  by (cases x, cases y) auto
  11.555 -
  11.556 -lemma \<omega>_mult[simp]: "(\<omega> = x * y) = ((x = \<omega> \<or> y = \<omega>) \<and> x \<noteq> 0 \<and> y \<noteq> 0)"
  11.557 -  by (cases x, cases y) auto
  11.558 -
  11.559 -lemma pinfreal_mult_0[simp]: "x * y = 0 \<longleftrightarrow> x = 0 \<or> (y::pinfreal) = 0"
  11.560 -  by (cases x, cases y) (auto simp: mult_le_0_iff)
  11.561 -
  11.562 -lemma pinfreal_mult_cancel:
  11.563 -  fixes x y z :: pinfreal
  11.564 -  assumes "y \<le> z"
  11.565 -  shows "x * y \<le> x * z"
  11.566 -  using assms
  11.567 -  by (cases x, cases y, cases z)
  11.568 -     (auto simp: mult_le_cancel_left mult_le_0_iff mult_less_0_iff not_le)
  11.569 -
  11.570 -lemma Real_power[simp]:
  11.571 -  "Real x ^ n = (if x \<le> 0 then (if n = 0 then 1 else 0) else Real (x ^ n))"
  11.572 -  by (induct n) auto
  11.573 -
  11.574 -lemma Real_power_\<omega>[simp]:
  11.575 -  "\<omega> ^ n = (if n = 0 then 1 else \<omega>)"
  11.576 -  by (induct n) auto
  11.577 -
  11.578 -lemma pinfreal_of_nat[simp]: "of_nat m = Real (real m)"
  11.579 -  by (induct m) (auto simp: real_of_nat_Suc one_pinfreal_def simp del: Real_1)
  11.580 -
  11.581 -lemma less_\<omega>_Ex_of_nat: "x < \<omega> \<longleftrightarrow> (\<exists>n. x < of_nat n)"
  11.582 -proof safe
  11.583 -  assume "x < \<omega>"
  11.584 -  then obtain r where "0 \<le> r" "x = Real r" by (cases x) auto
  11.585 -  moreover obtain n where "r < of_nat n" using ex_less_of_nat by auto
  11.586 -  ultimately show "\<exists>n. x < of_nat n" by (auto simp: real_eq_of_nat)
  11.587 -qed auto
  11.588 -
  11.589 -lemma real_of_pinfreal_mono:
  11.590 -  fixes a b :: pinfreal
  11.591 -  assumes "b \<noteq> \<omega>" "a \<le> b"
  11.592 -  shows "real a \<le> real b"
  11.593 -using assms by (cases b, cases a) auto
  11.594 -
  11.595 -lemma setprod_pinfreal_0:
  11.596 -  "(\<Prod>i\<in>I. f i) = (0::pinfreal) \<longleftrightarrow> finite I \<and> (\<exists>i\<in>I. f i = 0)"
  11.597 -proof cases
  11.598 -  assume "finite I" then show ?thesis
  11.599 -  proof (induct I)
  11.600 -    case (insert i I)
  11.601 -    then show ?case by simp
  11.602 -  qed simp
  11.603 -qed simp
  11.604 -
  11.605 -lemma setprod_\<omega>:
  11.606 -  "(\<Prod>i\<in>I. f i) = \<omega> \<longleftrightarrow> finite I \<and> (\<exists>i\<in>I. f i = \<omega>) \<and> (\<forall>i\<in>I. f i \<noteq> 0)"
  11.607 -proof cases
  11.608 -  assume "finite I" then show ?thesis
  11.609 -  proof (induct I)
  11.610 -    case (insert i I) then show ?case
  11.611 -      by (auto simp: setprod_pinfreal_0)
  11.612 -  qed simp
  11.613 -qed simp
  11.614 -
  11.615 -instance pinfreal :: "semiring_char_0"
  11.616 -proof
  11.617 -  fix m n
  11.618 -  show "inj (of_nat::nat\<Rightarrow>pinfreal)" by (auto intro!: inj_onI)
  11.619 -qed
  11.620 -
  11.621 -subsection "@{typ pinfreal} is a complete lattice"
  11.622 -
  11.623 -instantiation pinfreal :: lattice
  11.624 -begin
  11.625 -definition [simp]: "sup x y = (max x y :: pinfreal)"
  11.626 -definition [simp]: "inf x y = (min x y :: pinfreal)"
  11.627 -instance proof qed simp_all
  11.628 -end
  11.629 -
  11.630 -instantiation pinfreal :: complete_lattice
  11.631 -begin
  11.632 -
  11.633 -definition "bot = Real 0"
  11.634 -definition "top = \<omega>"
  11.635 -
  11.636 -definition "Sup S = (LEAST z. \<forall>x\<in>S. x \<le> z :: pinfreal)"
  11.637 -definition "Inf S = (GREATEST z. \<forall>x\<in>S. z \<le> x :: pinfreal)"
  11.638 -
  11.639 -lemma pinfreal_complete_Sup:
  11.640 -  fixes S :: "pinfreal set" assumes "S \<noteq> {}"
  11.641 -  shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>S. y \<le> z) \<longrightarrow> x \<le> z)"
  11.642 -proof (cases "\<exists>x\<ge>0. \<forall>a\<in>S. a \<le> Real x")
  11.643 -  case False
  11.644 -  hence *: "\<And>x. x\<ge>0 \<Longrightarrow> \<exists>a\<in>S. \<not>a \<le> Real x" by simp
  11.645 -  show ?thesis
  11.646 -  proof (safe intro!: exI[of _ \<omega>])
  11.647 -    fix y assume **: "\<forall>z\<in>S. z \<le> y"
  11.648 -    show "\<omega> \<le> y" unfolding pinfreal_\<omega>_less_eq
  11.649 -    proof (rule ccontr)
  11.650 -      assume "y \<noteq> \<omega>"
  11.651 -      then obtain x where [simp]: "y = Real x" and "0 \<le> x" by (cases y) auto
  11.652 -      from *[OF `0 \<le> x`] show False using ** by auto
  11.653 -    qed
  11.654 -  qed simp
  11.655 -next
  11.656 -  case True then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> Real y" and "0 \<le> y" by auto
  11.657 -  from y[of \<omega>] have "\<omega> \<notin> S" by auto
  11.658 -
  11.659 -  with `S \<noteq> {}` obtain x where "x \<in> S" and "x \<noteq> \<omega>" by auto
  11.660 -
  11.661 -  have bound: "\<forall>x\<in>real ` S. x \<le> y"
  11.662 -  proof
  11.663 -    fix z assume "z \<in> real ` S" then guess a ..
  11.664 -    with y[of a] `\<omega> \<notin> S` `0 \<le> y` show "z \<le> y" by (cases a) auto
  11.665 -  qed
  11.666 -  with reals_complete2[of "real ` S"] `x \<in> S`
  11.667 -  obtain s where s: "\<forall>y\<in>S. real y \<le> s" "\<forall>z. ((\<forall>y\<in>S. real y \<le> z) \<longrightarrow> s \<le> z)"
  11.668 -    by auto
  11.669 -
  11.670 -  show ?thesis
  11.671 -  proof (safe intro!: exI[of _ "Real s"])
  11.672 -    fix z assume "z \<in> S" thus "z \<le> Real s"
  11.673 -      using s `\<omega> \<notin> S` by (cases z) auto
  11.674 -  next
  11.675 -    fix z assume *: "\<forall>y\<in>S. y \<le> z"
  11.676 -    show "Real s \<le> z"
  11.677 -    proof (cases z)
  11.678 -      case (preal u)
  11.679 -      { fix v assume "v \<in> S"
  11.680 -        hence "v \<le> Real u" using * preal by auto
  11.681 -        hence "real v \<le> u" using `\<omega> \<notin> S` `0 \<le> u` by (cases v) auto }
  11.682 -      hence "s \<le> u" using s(2) by auto
  11.683 -      thus "Real s \<le> z" using preal by simp
  11.684 -    qed simp
  11.685 -  qed
  11.686 -qed
  11.687 -
  11.688 -lemma pinfreal_complete_Inf:
  11.689 -  fixes S :: "pinfreal set" assumes "S \<noteq> {}"
  11.690 -  shows "\<exists>x. (\<forall>y\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> x)"
  11.691 -proof (cases "S = {\<omega>}")
  11.692 -  case True thus ?thesis by (auto intro!: exI[of _ \<omega>])
  11.693 -next
  11.694 -  case False with `S \<noteq> {}` have "S - {\<omega>} \<noteq> {}" by auto
  11.695 -  hence not_empty: "\<exists>x. x \<in> uminus ` real ` (S - {\<omega>})" by auto
  11.696 -  have bounds: "\<exists>x. \<forall>y\<in>uminus ` real ` (S - {\<omega>}). y \<le> x" by (auto intro!: exI[of _ 0])
  11.697 -  from reals_complete2[OF not_empty bounds]
  11.698 -  obtain s where s: "\<And>y. y\<in>S - {\<omega>} \<Longrightarrow> - real y \<le> s" "\<forall>z. ((\<forall>y\<in>S - {\<omega>}. - real y \<le> z) \<longrightarrow> s \<le> z)"
  11.699 -    by auto
  11.700 -
  11.701 -  show ?thesis
  11.702 -  proof (safe intro!: exI[of _ "Real (-s)"])
  11.703 -    fix z assume "z \<in> S"
  11.704 -    show "Real (-s) \<le> z"
  11.705 -    proof (cases z)
  11.706 -      case (preal r)
  11.707 -      with s `z \<in> S` have "z \<in> S - {\<omega>}" by simp
  11.708 -      hence "- r \<le> s" using preal s(1)[of z] by auto
  11.709 -      hence "- s \<le> r" by (subst neg_le_iff_le[symmetric]) simp
  11.710 -      thus ?thesis using preal by simp
  11.711 -    qed simp
  11.712 -  next
  11.713 -    fix z assume *: "\<forall>y\<in>S. z \<le> y"
  11.714 -    show "z \<le> Real (-s)"
  11.715 -    proof (cases z)
  11.716 -      case (preal u)
  11.717 -      { fix v assume "v \<in> S-{\<omega>}"
  11.718 -        hence "Real u \<le> v" using * preal by auto
  11.719 -        hence "- real v \<le> - u" using `0 \<le> u` `v \<in> S - {\<omega>}` by (cases v) auto }
  11.720 -      hence "u \<le> - s" using s(2) by (subst neg_le_iff_le[symmetric]) auto
  11.721 -      thus "z \<le> Real (-s)" using preal by simp
  11.722 -    next
  11.723 -      case infinite
  11.724 -      with * have "S = {\<omega>}" using `S \<noteq> {}` by auto
  11.725 -      with `S - {\<omega>} \<noteq> {}` show ?thesis by simp
  11.726 -    qed
  11.727 -  qed
  11.728 -qed
  11.729 -
  11.730 -instance
  11.731 -proof
  11.732 -  fix x :: pinfreal and A
  11.733 -
  11.734 -  show "bot \<le> x" by (cases x) (simp_all add: bot_pinfreal_def)
  11.735 -  show "x \<le> top" by (simp add: top_pinfreal_def)
  11.736 -
  11.737 -  { assume "x \<in> A"
  11.738 -    with pinfreal_complete_Sup[of A]
  11.739 -    obtain s where s: "\<forall>y\<in>A. y \<le> s" "\<forall>z. (\<forall>y\<in>A. y \<le> z) \<longrightarrow> s \<le> z" by auto
  11.740 -    hence "x \<le> s" using `x \<in> A` by auto
  11.741 -    also have "... = Sup A" using s unfolding Sup_pinfreal_def
  11.742 -      by (auto intro!: Least_equality[symmetric])
  11.743 -    finally show "x \<le> Sup A" . }
  11.744 -
  11.745 -  { assume "x \<in> A"
  11.746 -    with pinfreal_complete_Inf[of A]
  11.747 -    obtain i where i: "\<forall>y\<in>A. i \<le> y" "\<forall>z. (\<forall>y\<in>A. z \<le> y) \<longrightarrow> z \<le> i" by auto
  11.748 -    hence "Inf A = i" unfolding Inf_pinfreal_def
  11.749 -      by (auto intro!: Greatest_equality)
  11.750 -    also have "i \<le> x" using i `x \<in> A` by auto
  11.751 -    finally show "Inf A \<le> x" . }
  11.752 -
  11.753 -  { assume *: "\<And>z. z \<in> A \<Longrightarrow> z \<le> x"
  11.754 -    show "Sup A \<le> x"
  11.755 -    proof (cases "A = {}")
  11.756 -      case True
  11.757 -      hence "Sup A = 0" unfolding Sup_pinfreal_def
  11.758 -        by (auto intro!: Least_equality)
  11.759 -      thus "Sup A \<le> x" by simp
  11.760 -    next
  11.761 -      case False
  11.762 -      with pinfreal_complete_Sup[of A]
  11.763 -      obtain s where s: "\<forall>y\<in>A. y \<le> s" "\<forall>z. (\<forall>y\<in>A. y \<le> z) \<longrightarrow> s \<le> z" by auto
  11.764 -      hence "Sup A = s"
  11.765 -        unfolding Sup_pinfreal_def by (auto intro!: Least_equality)
  11.766 -      also have "s \<le> x" using * s by auto
  11.767 -      finally show "Sup A \<le> x" .
  11.768 -    qed }
  11.769 -
  11.770 -  { assume *: "\<And>z. z \<in> A \<Longrightarrow> x \<le> z"
  11.771 -    show "x \<le> Inf A"
  11.772 -    proof (cases "A = {}")
  11.773 -      case True
  11.774 -      hence "Inf A = \<omega>" unfolding Inf_pinfreal_def
  11.775 -        by (auto intro!: Greatest_equality)
  11.776 -      thus "x \<le> Inf A" by simp
  11.777 -    next
  11.778 -      case False
  11.779 -      with pinfreal_complete_Inf[of A]
  11.780 -      obtain i where i: "\<forall>y\<in>A. i \<le> y" "\<forall>z. (\<forall>y\<in>A. z \<le> y) \<longrightarrow> z \<le> i" by auto
  11.781 -      have "x \<le> i" using * i by auto
  11.782 -      also have "i = Inf A" using i
  11.783 -        unfolding Inf_pinfreal_def by (auto intro!: Greatest_equality[symmetric])
  11.784 -      finally show "x \<le> Inf A" .
  11.785 -    qed }
  11.786 -qed
  11.787 -end
  11.788 -
  11.789 -lemma Inf_pinfreal_iff:
  11.790 -  fixes z :: pinfreal
  11.791 -  shows "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> (\<exists>x\<in>X. x<y) \<longleftrightarrow> Inf X < y"
  11.792 -  by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower less_le_not_le linear
  11.793 -            order_less_le_trans)
  11.794 -
  11.795 -lemma Inf_greater:
  11.796 -  fixes z :: pinfreal assumes "Inf X < z"
  11.797 -  shows "\<exists>x \<in> X. x < z"
  11.798 -proof -
  11.799 -  have "X \<noteq> {}" using assms by (auto simp: Inf_empty top_pinfreal_def)
  11.800 -  with assms show ?thesis
  11.801 -    by (metis Inf_pinfreal_iff mem_def not_leE)
  11.802 -qed
  11.803 -
  11.804 -lemma Inf_close:
  11.805 -  fixes e :: pinfreal assumes "Inf X \<noteq> \<omega>" "0 < e"
  11.806 -  shows "\<exists>x \<in> X. x < Inf X + e"
  11.807 -proof (rule Inf_greater)
  11.808 -  show "Inf X < Inf X + e" using assms
  11.809 -    by (cases "Inf X", cases e) auto
  11.810 -qed
  11.811 -
  11.812 -lemma pinfreal_SUPI:
  11.813 -  fixes x :: pinfreal
  11.814 -  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<le> x"
  11.815 -  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> f i \<le> y) \<Longrightarrow> x \<le> y"
  11.816 -  shows "(SUP i:A. f i) = x"
  11.817 -  unfolding SUPR_def Sup_pinfreal_def
  11.818 -  using assms by (auto intro!: Least_equality)
  11.819 -
  11.820 -lemma Sup_pinfreal_iff:
  11.821 -  fixes z :: pinfreal
  11.822 -  shows "(\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> (\<exists>x\<in>X. y<x) \<longleftrightarrow> y < Sup X"
  11.823 -  by (metis complete_lattice_class.Sup_least complete_lattice_class.Sup_upper less_le_not_le linear
  11.824 -            order_less_le_trans)
  11.825 -
  11.826 -lemma Sup_lesser:
  11.827 -  fixes z :: pinfreal assumes "z < Sup X"
  11.828 -  shows "\<exists>x \<in> X. z < x"
  11.829 -proof -
  11.830 -  have "X \<noteq> {}" using assms by (auto simp: Sup_empty bot_pinfreal_def)
  11.831 -  with assms show ?thesis
  11.832 -    by (metis Sup_pinfreal_iff mem_def not_leE)
  11.833 -qed
  11.834 -
  11.835 -lemma Sup_eq_\<omega>: "\<omega> \<in> S \<Longrightarrow> Sup S = \<omega>"
  11.836 -  unfolding Sup_pinfreal_def
  11.837 -  by (auto intro!: Least_equality)
  11.838 -
  11.839 -lemma Sup_close:
  11.840 -  assumes "0 < e" and S: "Sup S \<noteq> \<omega>" "S \<noteq> {}"
  11.841 -  shows "\<exists>X\<in>S. Sup S < X + e"
  11.842 -proof cases
  11.843 -  assume "Sup S = 0"
  11.844 -  moreover obtain X where "X \<in> S" using `S \<noteq> {}` by auto
  11.845 -  ultimately show ?thesis using `0 < e` by (auto intro!: bexI[OF _ `X\<in>S`])
  11.846 -next
  11.847 -  assume "Sup S \<noteq> 0"
  11.848 -  have "\<exists>X\<in>S. Sup S - e < X"
  11.849 -  proof (rule Sup_lesser)
  11.850 -    show "Sup S - e < Sup S" using `0 < e` `Sup S \<noteq> 0` `Sup S \<noteq> \<omega>`
  11.851 -      by (cases e) (auto simp: pinfreal_noteq_omega_Ex)
  11.852 -  qed
  11.853 -  then guess X .. note X = this
  11.854 -  with `Sup S \<noteq> \<omega>` Sup_eq_\<omega> have "X \<noteq> \<omega>" by auto
  11.855 -  thus ?thesis using `Sup S \<noteq> \<omega>` X unfolding pinfreal_noteq_omega_Ex
  11.856 -    by (cases e) (auto intro!: bexI[OF _ `X\<in>S`] simp: split: split_if_asm)
  11.857 -qed
  11.858 -
  11.859 -lemma Sup_\<omega>: "(SUP i::nat. Real (real i)) = \<omega>"
  11.860 -proof (rule pinfreal_SUPI)
  11.861 -  fix y assume *: "\<And>i::nat. i \<in> UNIV \<Longrightarrow> Real (real i) \<le> y"
  11.862 -  thus "\<omega> \<le> y"
  11.863 -  proof (cases y)
  11.864 -    case (preal r)
  11.865 -    then obtain k :: nat where "r < real k"
  11.866 -      using ex_less_of_nat by (auto simp: real_eq_of_nat)
  11.867 -    with *[of k] preal show ?thesis by auto
  11.868 -  qed simp
  11.869 -qed simp
  11.870 -
  11.871 -lemma SUP_\<omega>: "(SUP i:A. f i) = \<omega> \<longleftrightarrow> (\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)"
  11.872 -proof
  11.873 -  assume *: "(SUP i:A. f i) = \<omega>"
  11.874 -  show "(\<forall>x<\<omega>. \<exists>i\<in>A. x < f i)" unfolding *[symmetric]
  11.875 -  proof (intro allI impI)
  11.876 -    fix x assume "x < SUPR A f" then show "\<exists>i\<in>A. x < f i"
  11.877 -      unfolding less_SUP_iff by auto
  11.878 -  qed
  11.879 -next
  11.880 -  assume *: "\<forall>x<\<omega>. \<exists>i\<in>A. x < f i"
  11.881 -  show "(SUP i:A. f i) = \<omega>"
  11.882 -  proof (rule pinfreal_SUPI)
  11.883 -    fix y assume **: "\<And>i. i \<in> A \<Longrightarrow> f i \<le> y"
  11.884 -    show "\<omega> \<le> y"
  11.885 -    proof cases
  11.886 -      assume "y < \<omega>"
  11.887 -      from *[THEN spec, THEN mp, OF this]
  11.888 -      obtain i where "i \<in> A" "\<not> (f i \<le> y)" by auto
  11.889 -      with ** show ?thesis by auto
  11.890 -    qed auto
  11.891 -  qed auto
  11.892 -qed
  11.893 -
  11.894 -subsubsection {* Equivalence between @{text "f ----> x"} and @{text SUP} on @{typ pinfreal} *}
  11.895 -
  11.896 -lemma monoseq_monoI: "mono f \<Longrightarrow> monoseq f"
  11.897 -  unfolding mono_def monoseq_def by auto
  11.898 -
  11.899 -lemma incseq_mono: "mono f \<longleftrightarrow> incseq f"
  11.900 -  unfolding mono_def incseq_def by auto
  11.901 -
  11.902 -lemma SUP_eq_LIMSEQ:
  11.903 -  assumes "mono f" and "\<And>n. 0 \<le> f n" and "0 \<le> x"
  11.904 -  shows "(SUP n. Real (f n)) = Real x \<longleftrightarrow> f ----> x"
  11.905 -proof
  11.906 -  assume x: "(SUP n. Real (f n)) = Real x"
  11.907 -  { fix n
  11.908 -    have "Real (f n) \<le> Real x" using x[symmetric] by (auto intro: le_SUPI)
  11.909 -    hence "f n \<le> x" using assms by simp }
  11.910 -  show "f ----> x"
  11.911 -  proof (rule LIMSEQ_I)
  11.912 -    fix r :: real assume "0 < r"
  11.913 -    show "\<exists>no. \<forall>n\<ge>no. norm (f n - x) < r"
  11.914 -    proof (rule ccontr)
  11.915 -      assume *: "\<not> ?thesis"
  11.916 -      { fix N
  11.917 -        from * obtain n where "N \<le> n" "r \<le> x - f n"
  11.918 -          using `\<And>n. f n \<le> x` by (auto simp: not_less)
  11.919 -        hence "f N \<le> f n" using `mono f` by (auto dest: monoD)
  11.920 -        hence "f N \<le> x - r" using `r \<le> x - f n` by auto
  11.921 -        hence "Real (f N) \<le> Real (x - r)" and "r \<le> x" using `0 \<le> f N` by auto }
  11.922 -      hence "(SUP n. Real (f n)) \<le> Real (x - r)"
  11.923 -        and "Real (x - r) < Real x" using `0 < r` by (auto intro: SUP_leI)
  11.924 -      hence "(SUP n. Real (f n)) < Real x" by (rule le_less_trans)
  11.925 -      thus False using x by auto
  11.926 -    qed
  11.927 -  qed
  11.928 -next
  11.929 -  assume "f ----> x"
  11.930 -  show "(SUP n. Real (f n)) = Real x"
  11.931 -  proof (rule pinfreal_SUPI)
  11.932 -    fix n
  11.933 -    from incseq_le[of f x] `mono f` `f ----> x`
  11.934 -    show "Real (f n) \<le> Real x" using assms incseq_mono by auto
  11.935 -  next
  11.936 -    fix y assume *: "\<And>n. n\<in>UNIV \<Longrightarrow> Real (f n) \<le> y"
  11.937 -    show "Real x \<le> y"
  11.938 -    proof (cases y)
  11.939 -      case (preal r)
  11.940 -      with * have "\<exists>N. \<forall>n\<ge>N. f n \<le> r" using assms by fastsimp
  11.941 -      from LIMSEQ_le_const2[OF `f ----> x` this]
  11.942 -      show "Real x \<le> y" using `0 \<le> x` preal by auto
  11.943 -    qed simp
  11.944 -  qed
  11.945 -qed
  11.946 -
  11.947 -lemma SUPR_bound:
  11.948 -  assumes "\<forall>N. f N \<le> x"
  11.949 -  shows "(SUP n. f n) \<le> x"
  11.950 -  using assms by (simp add: SUPR_def Sup_le_iff)
  11.951 -
  11.952 -lemma pinfreal_less_eq_diff_eq_sum:
  11.953 -  fixes x y z :: pinfreal
  11.954 -  assumes "y \<le> x" and "x \<noteq> \<omega>"
  11.955 -  shows "z \<le> x - y \<longleftrightarrow> z + y \<le> x"
  11.956 -  using assms
  11.957 -  apply (cases z, cases y, cases x)
  11.958 -  by (simp_all add: field_simps minus_pinfreal_eq)
  11.959 -
  11.960 -lemma Real_diff_less_omega: "Real r - x < \<omega>" by (cases x) auto
  11.961 -
  11.962 -subsubsection {* Numbers on @{typ pinfreal} *}
  11.963 -
  11.964 -instantiation pinfreal :: number
  11.965 -begin
  11.966 -definition [simp]: "number_of x = Real (number_of x)"
  11.967 -instance proof qed
  11.968 -end
  11.969 -
  11.970 -subsubsection {* Division on @{typ pinfreal} *}
  11.971 -
  11.972 -instantiation pinfreal :: inverse
  11.973 -begin
  11.974 -
  11.975 -definition "inverse x = pinfreal_case (\<lambda>x. if x = 0 then \<omega> else Real (inverse x)) 0 x"
  11.976 -definition [simp]: "x / y = x * inverse (y :: pinfreal)"
  11.977 -
  11.978 -instance proof qed
  11.979 -end
  11.980 -
  11.981 -lemma pinfreal_inverse[simp]:
  11.982 -  "inverse 0 = \<omega>"
  11.983 -  "inverse (Real x) = (if x \<le> 0 then \<omega> else Real (inverse x))"
  11.984 -  "inverse \<omega> = 0"
  11.985 -  "inverse (1::pinfreal) = 1"
  11.986 -  "inverse (inverse x) = x"
  11.987 -  by (simp_all add: inverse_pinfreal_def one_pinfreal_def split: pinfreal_case_split del: Real_1)
  11.988 -
  11.989 -lemma pinfreal_inverse_le_eq:
  11.990 -  assumes "x \<noteq> 0" "x \<noteq> \<omega>"
  11.991 -  shows "y \<le> z / x \<longleftrightarrow> x * y \<le> (z :: pinfreal)"
  11.992 -proof -
  11.993 -  from assms obtain r where r: "x = Real r" "0 < r" by (cases x) auto
  11.994 -  { fix p q :: real assume "0 \<le> p" "0 \<le> q"
  11.995 -    have "p \<le> q * inverse r \<longleftrightarrow> p \<le> q / r" by (simp add: divide_inverse)
  11.996 -    also have "... \<longleftrightarrow> p * r \<le> q" using `0 < r` by (auto simp: field_simps)
  11.997 -    finally have "p \<le> q * inverse r \<longleftrightarrow> p * r \<le> q" . }
  11.998 -  with r show ?thesis
  11.999 -    by (cases y, cases z, auto simp: zero_le_mult_iff field_simps)
 11.1000 -qed
 11.1001 -
 11.1002 -lemma inverse_antimono_strict:
 11.1003 -  fixes x y :: pinfreal
 11.1004 -  assumes "x < y" shows "inverse y < inverse x"
 11.1005 -  using assms by (cases x, cases y) auto
 11.1006 -
 11.1007 -lemma inverse_antimono:
 11.1008 -  fixes x y :: pinfreal
 11.1009 -  assumes "x \<le> y" shows "inverse y \<le> inverse x"
 11.1010 -  using assms by (cases x, cases y) auto
 11.1011 -
 11.1012 -lemma pinfreal_inverse_\<omega>_iff[simp]: "inverse x = \<omega> \<longleftrightarrow> x = 0"
 11.1013 -  by (cases x) auto
 11.1014 -
 11.1015 -subsection "Infinite sum over @{typ pinfreal}"
 11.1016 -
 11.1017 -text {*
 11.1018 -
 11.1019 -The infinite sum over @{typ pinfreal} has the nice property that it is always
 11.1020 -defined.
 11.1021 -
 11.1022 -*}
 11.1023 -
 11.1024 -definition psuminf :: "(nat \<Rightarrow> pinfreal) \<Rightarrow> pinfreal" (binder "\<Sum>\<^isub>\<infinity>" 10) where
 11.1025 -  "(\<Sum>\<^isub>\<infinity> x. f x) = (SUP n. \<Sum>i<n. f i)"
 11.1026 -
 11.1027 -subsubsection {* Equivalence between @{text "\<Sum> n. f n"} and @{text "\<Sum>\<^isub>\<infinity> n. f n"} *}
 11.1028 -
 11.1029 -lemma setsum_Real:
 11.1030 -  assumes "\<forall>x\<in>A. 0 \<le> f x"
 11.1031 -  shows "(\<Sum>x\<in>A. Real (f x)) = Real (\<Sum>x\<in>A. f x)"
 11.1032 -proof (cases "finite A")
 11.1033 -  case True
 11.1034 -  thus ?thesis using assms
 11.1035 -  proof induct case (insert x s)
 11.1036 -    hence "0 \<le> setsum f s" apply-apply(rule setsum_nonneg) by auto
 11.1037 -    thus ?case using insert by auto
 11.1038 -  qed auto
 11.1039 -qed simp
 11.1040 -
 11.1041 -lemma setsum_Real':
 11.1042 -  assumes "\<forall>x. 0 \<le> f x"
 11.1043 -  shows "(\<Sum>x\<in>A. Real (f x)) = Real (\<Sum>x\<in>A. f x)"
 11.1044 -  apply(rule setsum_Real) using assms by auto
 11.1045 -
 11.1046 -lemma setsum_\<omega>:
 11.1047 -  "(\<Sum>x\<in>P. f x) = \<omega> \<longleftrightarrow> (finite P \<and> (\<exists>i\<in>P. f i = \<omega>))"
 11.1048 -proof safe
 11.1049 -  assume *: "setsum f P = \<omega>"
 11.1050 -  show "finite P"
 11.1051 -  proof (rule ccontr) assume "infinite P" with * show False by auto qed
 11.1052 -  show "\<exists>i\<in>P. f i = \<omega>"
 11.1053 -  proof (rule ccontr)
 11.1054 -    assume "\<not> ?thesis" hence "\<And>i. i\<in>P \<Longrightarrow> f i \<noteq> \<omega>" by auto
 11.1055 -    from `finite P` this have "setsum f P \<noteq> \<omega>"
 11.1056 -      by induct auto
 11.1057 -    with * show False by auto
 11.1058 -  qed
 11.1059 -next
 11.1060 -  fix i assume "finite P" "i \<in> P" "f i = \<omega>"
 11.1061 -  thus "setsum f P = \<omega>"
 11.1062 -  proof induct
 11.1063 -    case (insert x A)
 11.1064 -    show ?case using insert by (cases "x = i") auto
 11.1065 -  qed simp
 11.1066 -qed
 11.1067 -
 11.1068 -lemma real_of_pinfreal_setsum:
 11.1069 -  assumes "\<And>x. x \<in> S \<Longrightarrow> f x \<noteq> \<omega>"
 11.1070 -  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
 11.1071 -proof cases
 11.1072 -  assume "finite S"
 11.1073 -  from this assms show ?thesis
 11.1074 -    by induct (simp_all add: real_of_pinfreal_add setsum_\<omega>)
 11.1075 -qed simp
 11.1076 -
 11.1077 -lemma setsum_0:
 11.1078 -  fixes f :: "'a \<Rightarrow> pinfreal" assumes "finite A"
 11.1079 -  shows "(\<Sum>x\<in>A. f x) = 0 \<longleftrightarrow> (\<forall>i\<in>A. f i = 0)"
 11.1080 -  using assms by induct auto
 11.1081 -
 11.1082 -lemma suminf_imp_psuminf:
 11.1083 -  assumes "f sums x" and "\<forall>n. 0 \<le> f n"
 11.1084 -  shows "(\<Sum>\<^isub>\<infinity> x. Real (f x)) = Real x"
 11.1085 -  unfolding psuminf_def setsum_Real'[OF assms(2)]
 11.1086 -proof (rule SUP_eq_LIMSEQ[THEN iffD2])
 11.1087 -  show "mono (\<lambda>n. setsum f {..<n})" (is "mono ?S")
 11.1088 -    unfolding mono_iff_le_Suc using assms by simp
 11.1089 -
 11.1090 -  { fix n show "0 \<le> ?S n"
 11.1091 -      using setsum_nonneg[of "{..<n}" f] assms by auto }
 11.1092 -
 11.1093 -  thus "0 \<le> x" "?S ----> x"
 11.1094 -    using `f sums x` LIMSEQ_le_const
 11.1095 -    by (auto simp: atLeast0LessThan sums_def)
 11.1096 -qed
 11.1097 -
 11.1098 -lemma psuminf_equality:
 11.1099 -  assumes "\<And>n. setsum f {..<n} \<le> x"
 11.1100 -  and "\<And>y. y \<noteq> \<omega> \<Longrightarrow> (\<And>n. setsum f {..<n} \<le> y) \<Longrightarrow> x \<le> y"
 11.1101 -  shows "psuminf f = x"
 11.1102 -  unfolding psuminf_def
 11.1103 -proof (safe intro!: pinfreal_SUPI)
 11.1104 -  fix n show "setsum f {..<n} \<le> x" using assms(1) .
 11.1105 -next
 11.1106 -  fix y assume *: "\<forall>n. n \<in> UNIV \<longrightarrow> setsum f {..<n} \<le> y"
 11.1107 -  show "x \<le> y"
 11.1108 -  proof (cases "y = \<omega>")
 11.1109 -    assume "y \<noteq> \<omega>" from assms(2)[OF this] *
 11.1110 -    show "x \<le> y" by auto
 11.1111 -  qed simp
 11.1112 -qed
 11.1113 -
 11.1114 -lemma psuminf_\<omega>:
 11.1115 -  assumes "f i = \<omega>"
 11.1116 -  shows "(\<Sum>\<^isub>\<infinity> x. f x) = \<omega>"
 11.1117 -proof (rule psuminf_equality)
 11.1118 -  fix y assume *: "\<And>n. setsum f {..<n} \<le> y"
 11.1119 -  have "setsum f {..<Suc i} = \<omega>" 
 11.1120 -    using assms by (simp add: setsum_\<omega>)
 11.1121 -  thus "\<omega> \<le> y" using *[of "Suc i"] by auto
 11.1122 -qed simp
 11.1123 -
 11.1124 -lemma psuminf_imp_suminf:
 11.1125 -  assumes "(\<Sum>\<^isub>\<infinity> x. f x) \<noteq> \<omega>"
 11.1126 -  shows "(\<lambda>x. real (f x)) sums real (\<Sum>\<^isub>\<infinity> x. f x)"
 11.1127 -proof -
 11.1128 -  have "\<forall>i. \<exists>r. f i = Real r \<and> 0 \<le> r"
 11.1129 -  proof
 11.1130 -    fix i show "\<exists>r. f i = Real r \<and> 0 \<le> r" using psuminf_\<omega> assms by (cases "f i") auto
 11.1131 -  qed
 11.1132 -  from choice[OF this] obtain r where f: "f = (\<lambda>i. Real (r i))"
 11.1133 -    and pos: "\<forall>i. 0 \<le> r i"
 11.1134 -    by (auto simp: fun_eq_iff)
 11.1135 -  hence [simp]: "\<And>i. real (f i) = r i" by auto
 11.1136 -
 11.1137 -  have "mono (\<lambda>n. setsum r {..<n})" (is "mono ?S")
 11.1138 -    unfolding mono_iff_le_Suc using pos by simp
 11.1139 -
 11.1140 -  { fix n have "0 \<le> ?S n"
 11.1141 -      using setsum_nonneg[of "{..<n}" r] pos by auto }
 11.1142 -
 11.1143 -  from assms obtain p where *: "(\<Sum>\<^isub>\<infinity> x. f x) = Real p" and "0 \<le> p"
 11.1144 -    by (cases "(\<Sum>\<^isub>\<infinity> x. f x)") auto
 11.1145 -  show ?thesis unfolding * using * pos `0 \<le> p` SUP_eq_LIMSEQ[OF `mono ?S` `\<And>n. 0 \<le> ?S n` `0 \<le> p`]
 11.1146 -    by (simp add: f atLeast0LessThan sums_def psuminf_def setsum_Real'[OF pos] f)
 11.1147 -qed
 11.1148 -
 11.1149 -lemma psuminf_bound:
 11.1150 -  assumes "\<forall>N. (\<Sum>n<N. f n) \<le> x"
 11.1151 -  shows "(\<Sum>\<^isub>\<infinity> n. f n) \<le> x"
 11.1152 -  using assms by (simp add: psuminf_def SUPR_def Sup_le_iff)
 11.1153 -
 11.1154 -lemma psuminf_bound_add:
 11.1155 -  assumes "\<forall>N. (\<Sum>n<N. f n) + y \<le> x"
 11.1156 -  shows "(\<Sum>\<^isub>\<infinity> n. f n) + y \<le> x"
 11.1157 -proof (cases "x = \<omega>")
 11.1158 -  have "y \<le> x" using assms by (auto intro: pinfreal_le_add2)
 11.1159 -  assume "x \<noteq> \<omega>"
 11.1160 -  note move_y = pinfreal_less_eq_diff_eq_sum[OF `y \<le> x` this]
 11.1161 -
 11.1162 -  have "\<forall>N. (\<Sum>n<N. f n) \<le> x - y" using assms by (simp add: move_y)
 11.1163 -  hence "(\<Sum>\<^isub>\<infinity> n. f n) \<le> x - y" by (rule psuminf_bound)
 11.1164 -  thus ?thesis by (simp add: move_y)
 11.1165 -qed simp
 11.1166 -
 11.1167 -lemma psuminf_finite:
 11.1168 -  assumes "\<forall>N\<ge>n. f N = 0"
 11.1169 -  shows "(\<Sum>\<^isub>\<infinity> n. f n) = (\<Sum>N<n. f N)"
 11.1170 -proof (rule psuminf_equality)
 11.1171 -  fix N
 11.1172 -  show "setsum f {..<N} \<le> setsum f {..<n}"
 11.1173 -  proof (cases rule: linorder_cases)
 11.1174 -    assume "N < n" thus ?thesis by (auto intro!: setsum_mono3)
 11.1175 -  next
 11.1176 -    assume "n < N"
 11.1177 -    hence *: "{..<N} = {..<n} \<union> {n..<N}" by auto
 11.1178 -    moreover have "setsum f {n..<N} = 0"
 11.1179 -      using assms by (auto intro!: setsum_0')
 11.1180 -    ultimately show ?thesis unfolding *
 11.1181 -      by (subst setsum_Un_disjoint) auto
 11.1182 -  qed simp
 11.1183 -qed simp
 11.1184 -
 11.1185 -lemma psuminf_upper:
 11.1186 -  shows "(\<Sum>n<N. f n) \<le> (\<Sum>\<^isub>\<infinity> n. f n)"
 11.1187 -  unfolding psuminf_def SUPR_def
 11.1188 -  by (auto intro: complete_lattice_class.Sup_upper image_eqI)
 11.1189 -
 11.1190 -lemma psuminf_le:
 11.1191 -  assumes "\<And>N. f N \<le> g N"
 11.1192 -  shows "psuminf f \<le> psuminf g"
 11.1193 -proof (safe intro!: psuminf_bound)
 11.1194 -  fix n
 11.1195 -  have "setsum f {..<n} \<le> setsum g {..<n}" using assms by (auto intro: setsum_mono)
 11.1196 -  also have "... \<le> psuminf g" by (rule psuminf_upper)
 11.1197 -  finally show "setsum f {..<n} \<le> psuminf g" .
 11.1198 -qed
 11.1199 -
 11.1200 -lemma psuminf_const[simp]: "psuminf (\<lambda>n. c) = (if c = 0 then 0 else \<omega>)" (is "_ = ?if")
 11.1201 -proof (rule psuminf_equality)
 11.1202 -  fix y assume *: "\<And>n :: nat. (\<Sum>n<n. c) \<le> y" and "y \<noteq> \<omega>"
 11.1203 -  then obtain r p where
 11.1204 -    y: "y = Real r" "0 \<le> r" and
 11.1205 -    c: "c = Real p" "0 \<le> p"
 11.1206 -      using *[of 1] by (cases c, cases y) auto
 11.1207 -  show "(if c = 0 then 0 else \<omega>) \<le> y"
 11.1208 -  proof (cases "p = 0")
 11.1209 -    assume "p = 0" with c show ?thesis by simp
 11.1210 -  next
 11.1211 -    assume "p \<noteq> 0"
 11.1212 -    with * c y have **: "\<And>n :: nat. real n \<le> r / p"
 11.1213 -      by (auto simp: zero_le_mult_iff field_simps)
 11.1214 -    from ex_less_of_nat[of "r / p"] guess n ..
 11.1215 -    with **[of n] show ?thesis by (simp add: real_eq_of_nat)
 11.1216 -  qed
 11.1217 -qed (cases "c = 0", simp_all)
 11.1218 -
 11.1219 -lemma psuminf_add[simp]: "psuminf (\<lambda>n. f n + g n) = psuminf f + psuminf g"
 11.1220 -proof (rule psuminf_equality)
 11.1221 -  fix n
 11.1222 -  from psuminf_upper[of f n] psuminf_upper[of g n]
 11.1223 -  show "(\<Sum>n<n. f n + g n) \<le> psuminf f + psuminf g"
 11.1224 -    by (auto simp add: setsum_addf intro!: add_mono)
 11.1225 -next
 11.1226 -  fix y assume *: "\<And>n. (\<Sum>n<n. f n + g n) \<le> y" and "y \<noteq> \<omega>"
 11.1227 -  { fix n m
 11.1228 -    have **: "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> y"
 11.1229 -    proof (cases rule: linorder_le_cases)
 11.1230 -      assume "n \<le> m"
 11.1231 -      hence "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> (\<Sum>n<m. f n) + (\<Sum>n<m. g n)"
 11.1232 -        by (auto intro!: add_right_mono setsum_mono3)
 11.1233 -      also have "... \<le> y"
 11.1234 -        using * by (simp add: setsum_addf)
 11.1235 -      finally show ?thesis .
 11.1236 -    next
 11.1237 -      assume "m \<le> n"
 11.1238 -      hence "(\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> (\<Sum>n<n. f n) + (\<Sum>n<n. g n)"
 11.1239 -        by (auto intro!: add_left_mono setsum_mono3)
 11.1240 -      also have "... \<le> y"
 11.1241 -        using * by (simp add: setsum_addf)
 11.1242 -      finally show ?thesis .
 11.1243 -    qed }
 11.1244 -  hence "\<And>m. \<forall>n. (\<Sum>n<n. f n) + (\<Sum>n<m. g n) \<le> y" by simp
 11.1245 -  from psuminf_bound_add[OF this]
 11.1246 -  have "\<forall>m. (\<Sum>n<m. g n) + psuminf f \<le> y" by (simp add: ac_simps)
 11.1247 -  from psuminf_bound_add[OF this]
 11.1248 -  show "psuminf f + psuminf g \<le> y" by (simp add: ac_simps)
 11.1249 -qed
 11.1250 -
 11.1251 -lemma psuminf_0: "psuminf f = 0 \<longleftrightarrow> (\<forall>i. f i = 0)"
 11.1252 -proof safe
 11.1253 -  assume "\<forall>i. f i = 0"
 11.1254 -  hence "f = (\<lambda>i. 0)" by (simp add: fun_eq_iff)
 11.1255 -  thus "psuminf f = 0" using psuminf_const by simp
 11.1256 -next
 11.1257 -  fix i assume "psuminf f = 0"
 11.1258 -  hence "(\<Sum>n<Suc i. f n) = 0" using psuminf_upper[of f "Suc i"] by simp
 11.1259 -  thus "f i = 0" by simp
 11.1260 -qed
 11.1261 -
 11.1262 -lemma psuminf_cmult_right[simp]: "psuminf (\<lambda>n. c * f n) = c * psuminf f"
 11.1263 -proof (rule psuminf_equality)
 11.1264 -  fix n show "(\<Sum>n<n. c * f n) \<le> c * psuminf f"
 11.1265 -   by (auto simp: setsum_right_distrib[symmetric] intro: mult_left_mono psuminf_upper)
 11.1266 -next
 11.1267 -  fix y
 11.1268 -  assume "\<And>n. (\<Sum>n<n. c * f n) \<le> y"
 11.1269 -  hence *: "\<And>n. c * (\<Sum>n<n. f n) \<le> y" by (auto simp add: setsum_right_distrib)
 11.1270 -  thus "c * psuminf f \<le> y"
 11.1271 -  proof (cases "c = \<omega> \<or> c = 0")
 11.1272 -    assume "c = \<omega> \<or> c = 0"
 11.1273 -    thus ?thesis
 11.1274 -      using * by (fastsimp simp add: psuminf_0 setsum_0 split: split_if_asm)
 11.1275 -  next
 11.1276 -    assume "\<not> (c = \<omega> \<or> c = 0)"
 11.1277 -    hence "c \<noteq> 0" "c \<noteq> \<omega>" by auto
 11.1278 -    note rewrite_div = pinfreal_inverse_le_eq[OF this, of _ y]
 11.1279 -    hence "\<forall>n. (\<Sum>n<n. f n) \<le> y / c" using * by simp
 11.1280 -    hence "psuminf f \<le> y / c" by (rule psuminf_bound)
 11.1281 -    thus ?thesis using rewrite_div by simp
 11.1282 -  qed
 11.1283 -qed
 11.1284 -
 11.1285 -lemma psuminf_cmult_left[simp]: "psuminf (\<lambda>n. f n * c) = psuminf f * c"
 11.1286 -  using psuminf_cmult_right[of c f] by (simp add: ac_simps)
 11.1287 -
 11.1288 -lemma psuminf_half_series: "psuminf (\<lambda>n. (1/2)^Suc n) = 1"
 11.1289 -  using suminf_imp_psuminf[OF power_half_series] by auto
 11.1290 -
 11.1291 -lemma setsum_pinfsum: "(\<Sum>\<^isub>\<infinity> n. \<Sum>m\<in>A. f n m) = (\<Sum>m\<in>A. (\<Sum>\<^isub>\<infinity> n. f n m))"
 11.1292 -proof (cases "finite A")
 11.1293 -  assume "finite A"
 11.1294 -  thus ?thesis by induct simp_all
 11.1295 -qed simp
 11.1296 -
 11.1297 -lemma psuminf_reindex:
 11.1298 -  fixes f:: "nat \<Rightarrow> nat" assumes "bij f"
 11.1299 -  shows "psuminf (g \<circ> f) = psuminf g"
 11.1300 -proof -
 11.1301 -  have [intro, simp]: "\<And>A. inj_on f A" using `bij f` unfolding bij_def by (auto intro: subset_inj_on)
 11.1302 -  have f[intro, simp]: "\<And>x. f (inv f x) = x"
 11.1303 -    using `bij f` unfolding bij_def by (auto intro: surj_f_inv_f)
 11.1304 -  show ?thesis
 11.1305 -  proof (rule psuminf_equality)
 11.1306 -    fix n
 11.1307 -    have "setsum (g \<circ> f) {..<n} = setsum g (f ` {..<n})"
 11.1308 -      by (simp add: setsum_reindex)
 11.1309 -    also have "\<dots> \<le> setsum g {..Max (f ` {..<n})}"
 11.1310 -      by (rule setsum_mono3) auto
 11.1311 -    also have "\<dots> \<le> psuminf g" unfolding lessThan_Suc_atMost[symmetric] by (rule psuminf_upper)
 11.1312 -    finally show "setsum (g \<circ> f) {..<n} \<le> psuminf g" .
 11.1313 -  next
 11.1314 -    fix y assume *: "\<And>n. setsum (g \<circ> f) {..<n} \<le> y"
 11.1315 -    show "psuminf g \<le> y"
 11.1316 -    proof (safe intro!: psuminf_bound)
 11.1317 -      fix N
 11.1318 -      have "setsum g {..<N} \<le> setsum g (f ` {..Max (inv f ` {..<N})})"
 11.1319 -        by (rule setsum_mono3) (auto intro!: image_eqI[where f="f", OF f[symmetric]])
 11.1320 -      also have "\<dots> = setsum (g \<circ> f) {..Max (inv f ` {..<N})}"
 11.1321 -        by (simp add: setsum_reindex)
 11.1322 -      also have "\<dots> \<le> y" unfolding lessThan_Suc_atMost[symmetric] by (rule *)
 11.1323 -      finally show "setsum g {..<N} \<le> y" .
 11.1324 -    qed
 11.1325 -  qed
 11.1326 -qed
 11.1327 -
 11.1328 -lemma pinfreal_mult_less_right:
 11.1329 -  assumes "b * a < c * a" "0 < a" "a < \<omega>"
 11.1330 -  shows "b < c"
 11.1331 -  using assms
 11.1332 -  by (cases a, cases b, cases c) (auto split: split_if_asm simp: zero_less_mult_iff zero_le_mult_iff)
 11.1333 -
 11.1334 -lemma pinfreal_\<omega>_eq_plus[simp]: "\<omega> = a + b \<longleftrightarrow> (a = \<omega> \<or> b = \<omega>)"
 11.1335 -  by (cases a, cases b) auto
 11.1336 -
 11.1337 -lemma pinfreal_of_nat_le_iff:
 11.1338 -  "(of_nat k :: pinfreal) \<le> of_nat m \<longleftrightarrow> k \<le> m" by auto
 11.1339 -
 11.1340 -lemma pinfreal_of_nat_less_iff:
 11.1341 -  "(of_nat k :: pinfreal) < of_nat m \<longleftrightarrow> k < m" by auto
 11.1342 -
 11.1343 -lemma pinfreal_bound_add:
 11.1344 -  assumes "\<forall>N. f N + y \<le> (x::pinfreal)"
 11.1345 -  shows "(SUP n. f n) + y \<le> x"
 11.1346 -proof (cases "x = \<omega>")
 11.1347 -  have "y \<le> x" using assms by (auto intro: pinfreal_le_add2)
 11.1348 -  assume "x \<noteq> \<omega>"
 11.1349 -  note move_y = pinfreal_less_eq_diff_eq_sum[OF `y \<le> x` this]
 11.1350 -
 11.1351 -  have "\<forall>N. f N \<le> x - y" using assms by (simp add: move_y)
 11.1352 -  hence "(SUP n. f n) \<le> x - y" by (rule SUPR_bound)
 11.1353 -  thus ?thesis by (simp add: move_y)
 11.1354 -qed simp
 11.1355 -
 11.1356 -lemma SUPR_pinfreal_add:
 11.1357 -  fixes f g :: "nat \<Rightarrow> pinfreal"
 11.1358 -  assumes f: "\<forall>n. f n \<le> f (Suc n)" and g: "\<forall>n. g n \<le> g (Suc n)"
 11.1359 -  shows "(SUP n. f n + g n) = (SUP n. f n) + (SUP n. g n)"
 11.1360 -proof (rule pinfreal_SUPI)
 11.1361 -  fix n :: nat from le_SUPI[of n UNIV f] le_SUPI[of n UNIV g]
 11.1362 -  show "f n + g n \<le> (SUP n. f n) + (SUP n. g n)"
 11.1363 -    by (auto intro!: add_mono)
 11.1364 -next
 11.1365 -  fix y assume *: "\<And>n. n \<in> UNIV \<Longrightarrow> f n + g n \<le> y"
 11.1366 -  { fix n m
 11.1367 -    have "f n + g m \<le> y"
 11.1368 -    proof (cases rule: linorder_le_cases)
 11.1369 -      assume "n \<le> m"
 11.1370 -      hence "f n + g m \<le> f m + g m"
 11.1371 -        using f lift_Suc_mono_le by (auto intro!: add_right_mono)
 11.1372 -      also have "\<dots> \<le> y" using * by simp
 11.1373 -      finally show ?thesis .
 11.1374 -    next
 11.1375 -      assume "m \<le> n"
 11.1376 -      hence "f n + g m \<le> f n + g n"
 11.1377 -        using g lift_Suc_mono_le by (auto intro!: add_left_mono)
 11.1378 -      also have "\<dots> \<le> y" using * by simp
 11.1379 -      finally show ?thesis .
 11.1380 -    qed }
 11.1381 -  hence "\<And>m. \<forall>n. f n + g m \<le> y" by simp
 11.1382 -  from pinfreal_bound_add[OF this]
 11.1383 -  have "\<forall>m. (g m) + (SUP n. f n) \<le> y" by (simp add: ac_simps)
 11.1384 -  from pinfreal_bound_add[OF this]
 11.1385 -  show "SUPR UNIV f + SUPR UNIV g \<le> y" by (simp add: ac_simps)
 11.1386 -qed
 11.1387 -
 11.1388 -lemma SUPR_pinfreal_setsum:
 11.1389 -  fixes f :: "'x \<Rightarrow> nat \<Rightarrow> pinfreal"
 11.1390 -  assumes "\<And>i. i \<in> P \<Longrightarrow> \<forall>n. f i n \<le> f i (Suc n)"
 11.1391 -  shows "(SUP n. \<Sum>i\<in>P. f i n) = (\<Sum>i\<in>P. SUP n. f i n)"
 11.1392 -proof cases
 11.1393 -  assume "finite P" from this assms show ?thesis
 11.1394 -  proof induct
 11.1395 -    case (insert i P)
 11.1396 -    thus ?case
 11.1397 -      apply simp
 11.1398 -      apply (subst SUPR_pinfreal_add)
 11.1399 -      by (auto intro!: setsum_mono)
 11.1400 -  qed simp
 11.1401 -qed simp
 11.1402 -
 11.1403 -lemma psuminf_SUP_eq:
 11.1404 -  assumes "\<And>n i. f n i \<le> f (Suc n) i"
 11.1405 -  shows "(\<Sum>\<^isub>\<infinity> i. SUP n::nat. f n i) = (SUP n::nat. \<Sum>\<^isub>\<infinity> i. f n i)"
 11.1406 -proof -
 11.1407 -  { fix n :: nat
 11.1408 -    have "(\<Sum>i<n. SUP k. f k i) = (SUP k. \<Sum>i<n. f k i)"
 11.1409 -      using assms by (auto intro!: SUPR_pinfreal_setsum[symmetric]) }
 11.1410 -  note * = this
 11.1411 -  show ?thesis
 11.1412 -    unfolding psuminf_def
 11.1413 -    unfolding *
 11.1414 -    apply (subst SUP_commute) ..
 11.1415 -qed
 11.1416 -
 11.1417 -lemma psuminf_commute:
 11.1418 -  shows "(\<Sum>\<^isub>\<infinity> i j. f i j) = (\<Sum>\<^isub>\<infinity> j i. f i j)"
 11.1419 -proof -
 11.1420 -  have "(SUP n. \<Sum> i < n. SUP m. \<Sum> j < m. f i j) = (SUP n. SUP m. \<Sum> i < n. \<Sum> j < m. f i j)"
 11.1421 -    apply (subst SUPR_pinfreal_setsum)
 11.1422 -    by auto
 11.1423 -  also have "\<dots> = (SUP m n. \<Sum> j < m. \<Sum> i < n. f i j)"
 11.1424 -    apply (subst SUP_commute)
 11.1425 -    apply (subst setsum_commute)
 11.1426 -    by auto
 11.1427 -  also have "\<dots> = (SUP m. \<Sum> j < m. SUP n. \<Sum> i < n. f i j)"
 11.1428 -    apply (subst SUPR_pinfreal_setsum)
 11.1429 -    by auto
 11.1430 -  finally show ?thesis
 11.1431 -    unfolding psuminf_def by auto
 11.1432 -qed
 11.1433 -
 11.1434 -lemma psuminf_2dimen:
 11.1435 -  fixes f:: "nat * nat \<Rightarrow> pinfreal"
 11.1436 -  assumes fsums: "\<And>m. g m = (\<Sum>\<^isub>\<infinity> n. f (m,n))"
 11.1437 -  shows "psuminf (f \<circ> prod_decode) = psuminf g"
 11.1438 -proof (rule psuminf_equality)
 11.1439 -  fix n :: nat
 11.1440 -  let ?P = "prod_decode ` {..<n}"
 11.1441 -  have "setsum (f \<circ> prod_decode) {..<n} = setsum f ?P"
 11.1442 -    by (auto simp: setsum_reindex inj_prod_decode)
 11.1443 -  also have "\<dots> \<le> setsum f ({..Max (fst ` ?P)} \<times> {..Max (snd ` ?P)})"
 11.1444 -  proof (safe intro!: setsum_mono3 Max_ge image_eqI)
 11.1445 -    fix a b x assume "(a, b) = prod_decode x"
 11.1446 -    from this[symmetric] show "a = fst (prod_decode x)" "b = snd (prod_decode x)"
 11.1447 -      by simp_all
 11.1448 -  qed simp_all
 11.1449 -  also have "\<dots> = (\<Sum>m\<le>Max (fst ` ?P). (\<Sum>n\<le>Max (snd ` ?P). f (m,n)))"
 11.1450 -    unfolding setsum_cartesian_product by simp
 11.1451 -  also have "\<dots> \<le> (\<Sum>m\<le>Max (fst ` ?P). g m)"
 11.1452 -    by (auto intro!: setsum_mono psuminf_upper simp del: setsum_lessThan_Suc
 11.1453 -        simp: fsums lessThan_Suc_atMost[symmetric])
 11.1454 -  also have "\<dots> \<le> psuminf g"
 11.1455 -    by (auto intro!: psuminf_upper simp del: setsum_lessThan_Suc
 11.1456 -        simp: lessThan_Suc_atMost[symmetric])
 11.1457 -  finally show "setsum (f \<circ> prod_decode) {..<n} \<le> psuminf g" .
 11.1458 -next
 11.1459 -  fix y assume *: "\<And>n. setsum (f \<circ> prod_decode) {..<n} \<le> y"
 11.1460 -  have g: "g = (\<lambda>m. \<Sum>\<^isub>\<infinity> n. f (m,n))" unfolding fsums[symmetric] ..
 11.1461 -  show "psuminf g \<le> y" unfolding g
 11.1462 -  proof (rule psuminf_bound, unfold setsum_pinfsum[symmetric], safe intro!: psuminf_bound)
 11.1463 -    fix N M :: nat
 11.1464 -    let ?P = "{..<N} \<times> {..<M}"
 11.1465 -    let ?M = "Max (prod_encode ` ?P)"
 11.1466 -    have "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> (\<Sum>(m, n)\<in>?P. f (m, n))"
 11.1467 -      unfolding setsum_commute[of _ _ "{..<M}"] unfolding setsum_cartesian_product ..
 11.1468 -    also have "\<dots> \<le> (\<Sum>(m,n)\<in>(prod_decode ` {..?M}). f (m, n))"
 11.1469 -      by (auto intro!: setsum_mono3 image_eqI[where f=prod_decode, OF prod_encode_inverse[symmetric]])
 11.1470 -    also have "\<dots> \<le> y" using *[of "Suc ?M"]
 11.1471 -      by (simp add: lessThan_Suc_atMost[symmetric] setsum_reindex
 11.1472 -               inj_prod_decode del: setsum_lessThan_Suc)
 11.1473 -    finally show "(\<Sum>n<M. \<Sum>m<N. f (m, n)) \<le> y" .
 11.1474 -  qed
 11.1475 -qed
 11.1476 -
 11.1477 -lemma Real_max:
 11.1478 -  assumes "x \<ge> 0" "y \<ge> 0"
 11.1479 -  shows "Real (max x y) = max (Real x) (Real y)"
 11.1480 -  using assms unfolding max_def by (auto simp add:not_le)
 11.1481 -
 11.1482 -lemma Real_real: "Real (real x) = (if x = \<omega> then 0 else x)"
 11.1483 -  using assms by (cases x) auto
 11.1484 -
 11.1485 -lemma inj_on_real: "inj_on real (UNIV - {\<omega>})"
 11.1486 -proof (rule inj_onI)
 11.1487 -  fix x y assume mem: "x \<in> UNIV - {\<omega>}" "y \<in> UNIV - {\<omega>}" and "real x = real y"
 11.1488 -  thus "x = y" by (cases x, cases y) auto
 11.1489 -qed
 11.1490 -
 11.1491 -lemma inj_on_Real: "inj_on Real {0..}"
 11.1492 -  by (auto intro!: inj_onI)
 11.1493 -
 11.1494 -lemma range_Real[simp]: "range Real = UNIV - {\<omega>}"
 11.1495 -proof safe
 11.1496 -  fix x assume "x \<notin> range Real"
 11.1497 -  thus "x = \<omega>" by (cases x) auto
 11.1498 -qed auto
 11.1499 -
 11.1500 -lemma image_Real[simp]: "Real ` {0..} = UNIV - {\<omega>}"
 11.1501 -proof safe
 11.1502 -  fix x assume "x \<notin> Real ` {0..}"
 11.1503 -  thus "x = \<omega>" by (cases x) auto
 11.1504 -qed auto
 11.1505 -
 11.1506 -lemma pinfreal_SUP_cmult:
 11.1507 -  fixes f :: "'a \<Rightarrow> pinfreal"
 11.1508 -  shows "(SUP i : R. z * f i) = z * (SUP i : R. f i)"
 11.1509 -proof (rule pinfreal_SUPI)
 11.1510 -  fix i assume "i \<in> R"
 11.1511 -  from le_SUPI[OF this]
 11.1512 -  show "z * f i \<le> z * (SUP i:R. f i)" by (rule pinfreal_mult_cancel)
 11.1513 -next
 11.1514 -  fix y assume "\<And>i. i\<in>R \<Longrightarrow> z * f i \<le> y"
 11.1515 -  hence *: "\<And>i. i\<in>R \<Longrightarrow> z * f i \<le> y" by auto
 11.1516 -  show "z * (SUP i:R. f i) \<le> y"
 11.1517 -  proof (cases "\<forall>i\<in>R. f i = 0")
 11.1518 -    case True
 11.1519 -    show ?thesis
 11.1520 -    proof cases
 11.1521 -      assume "R \<noteq> {}" hence "f ` R = {0}" using True by auto
 11.1522 -      thus ?thesis by (simp add: SUPR_def)
 11.1523 -    qed (simp add: SUPR_def Sup_empty bot_pinfreal_def)
 11.1524 -  next
 11.1525 -    case False then obtain i where i: "i \<in> R" and f0: "f i \<noteq> 0" by auto
 11.1526 -    show ?thesis
 11.1527 -    proof (cases "z = 0 \<or> z = \<omega>")
 11.1528 -      case True with f0 *[OF i] show ?thesis by auto
 11.1529 -    next
 11.1530 -      case False hence z: "z \<noteq> 0" "z \<noteq> \<omega>" by auto
 11.1531 -      note div = pinfreal_inverse_le_eq[OF this, symmetric]
 11.1532 -      hence "\<And>i. i\<in>R \<Longrightarrow> f i \<le> y / z" using * by auto
 11.1533 -      thus ?thesis unfolding div SUP_le_iff by simp
 11.1534 -    qed
 11.1535 -  qed
 11.1536 -qed
 11.1537 -
 11.1538 -instantiation pinfreal :: topological_space
 11.1539 -begin
 11.1540 -
 11.1541 -definition "open A \<longleftrightarrow>
 11.1542 -  (\<exists>T. open T \<and> (Real ` (T\<inter>{0..}) = A - {\<omega>})) \<and> (\<omega> \<in> A \<longrightarrow> (\<exists>x\<ge>0. {Real x <..} \<subseteq> A))"
 11.1543 -
 11.1544 -lemma open_omega: "open A \<Longrightarrow> \<omega> \<in> A \<Longrightarrow> (\<exists>x\<ge>0. {Real x<..} \<subseteq> A)"
 11.1545 -  unfolding open_pinfreal_def by auto
 11.1546 -
 11.1547 -lemma open_omegaD: assumes "open A" "\<omega> \<in> A" obtains x where "x\<ge>0" "{Real x<..} \<subseteq> A"
 11.1548 -  using open_omega[OF assms] by auto
 11.1549 -
 11.1550 -lemma pinfreal_openE: assumes "open A" obtains A' x where
 11.1551 -  "open A'" "Real ` (A' \<inter> {0..}) = A - {\<omega>}"
 11.1552 -  "x \<ge> 0" "\<omega> \<in> A \<Longrightarrow> {Real x<..} \<subseteq> A"
 11.1553 -  using assms open_pinfreal_def by auto
 11.1554 -
 11.1555 -instance
 11.1556 -proof
 11.1557 -  let ?U = "UNIV::pinfreal set"
 11.1558 -  show "open ?U" unfolding open_pinfreal_def
 11.1559 -    by (auto intro!: exI[of _ "UNIV"] exI[of _ 0])
 11.1560 -next
 11.1561 -  fix S T::"pinfreal set" assume "open S" and "open T"
 11.1562 -  from `open S`[THEN pinfreal_openE] guess S' xS . note S' = this
 11.1563 -  from `open T`[THEN pinfreal_openE] guess T' xT . note T' = this
 11.1564 -
 11.1565 -  from S'(1-3) T'(1-3)
 11.1566 -  show "open (S \<inter> T)" unfolding open_pinfreal_def
 11.1567 -  proof (safe intro!: exI[of _ "S' \<inter> T'"] exI[of _ "max xS xT"])
 11.1568 -    fix x assume *: "Real (max xS xT) < x" and "\<omega> \<in> S" "\<omega> \<in> T"
 11.1569 -    from `\<omega> \<in> S`[THEN S'(4)] * show "x \<in> S"
 11.1570 -      by (cases x, auto simp: max_def split: split_if_asm)
 11.1571 -    from `\<omega> \<in> T`[THEN T'(4)] * show "x \<in> T"
 11.1572 -      by (cases x, auto simp: max_def split: split_if_asm)
 11.1573 -  next
 11.1574 -    fix x assume x: "x \<notin> Real ` (S' \<inter> T' \<inter> {0..})"
 11.1575 -    have *: "S' \<inter> T' \<inter> {0..} = (S' \<inter> {0..}) \<inter> (T' \<inter> {0..})" by auto
 11.1576 -    assume "x \<in> T" "x \<in> S"
 11.1577 -    with S'(2) T'(2) show "x = \<omega>"
 11.1578 -      using x[unfolded *] inj_on_image_Int[OF inj_on_Real] by auto
 11.1579 -  qed auto
 11.1580 -next
 11.1581 -  fix K assume openK: "\<forall>S \<in> K. open (S:: pinfreal set)"
 11.1582 -  hence "\<forall>S\<in>K. \<exists>T. open T \<and> Real ` (T \<inter> {0..}) = S - {\<omega>}" by (auto simp: open_pinfreal_def)
 11.1583 -  from bchoice[OF this] guess T .. note T = this[rule_format]
 11.1584 -
 11.1585 -  show "open (\<Union>K)" unfolding open_pinfreal_def
 11.1586 -  proof (safe intro!: exI[of _ "\<Union>(T ` K)"])
 11.1587 -    fix x S assume "0 \<le> x" "x \<in> T S" "S \<in> K"
 11.1588 -    with T[OF `S \<in> K`] show "Real x \<in> \<Union>K" by auto
 11.1589 -  next
 11.1590 -    fix x S assume x: "x \<notin> Real ` (\<Union>T ` K \<inter> {0..})" "S \<in> K" "x \<in> S"
 11.1591 -    hence "x \<notin> Real ` (T S \<inter> {0..})"
 11.1592 -      by (auto simp: image_UN UN_simps[symmetric] simp del: UN_simps)
 11.1593 -    thus "x = \<omega>" using T[OF `S \<in> K`] `x \<in> S` by auto
 11.1594 -  next
 11.1595 -    fix S assume "\<omega> \<in> S" "S \<in> K"
 11.1596 -    from openK[rule_format, OF `S \<in> K`, THEN pinfreal_openE] guess S' x .
 11.1597 -    from this(3, 4) `\<omega> \<in> S`
 11.1598 -    show "\<exists>x\<ge>0. {Real x<..} \<subseteq> \<Union>K"
 11.1599 -      by (auto intro!: exI[of _ x] bexI[OF _ `S \<in> K`])
 11.1600 -  next
 11.1601 -    from T[THEN conjunct1] show "open (\<Union>T`K)" by auto
 11.1602 -  qed auto
 11.1603 -qed
 11.1604 -end
 11.1605 -
 11.1606 -lemma open_pinfreal_lessThan[simp]:
 11.1607 -  "open {..< a :: pinfreal}"
 11.1608 -proof (cases a)
 11.1609 -  case (preal x) thus ?thesis unfolding open_pinfreal_def
 11.1610 -  proof (safe intro!: exI[of _ "{..< x}"])
 11.1611 -    fix y assume "y < Real x"
 11.1612 -    moreover assume "y \<notin> Real ` ({..<x} \<inter> {0..})"
 11.1613 -    ultimately have "y \<noteq> Real (real y)" using preal by (cases y) auto
 11.1614 -    thus "y = \<omega>" by (auto simp: Real_real split: split_if_asm)
 11.1615 -  qed auto
 11.1616 -next
 11.1617 -  case infinite thus ?thesis
 11.1618 -    unfolding open_pinfreal_def by (auto intro!: exI[of _ UNIV])
 11.1619 -qed
 11.1620 -
 11.1621 -lemma open_pinfreal_greaterThan[simp]:
 11.1622 -  "open {a :: pinfreal <..}"
 11.1623 -proof (cases a)
 11.1624 -  case (preal x) thus ?thesis unfolding open_pinfreal_def
 11.1625 -  proof (safe intro!: exI[of _ "{x <..}"])
 11.1626 -    fix y assume "Real x < y"
 11.1627 -    moreover assume "y \<notin> Real ` ({x<..} \<inter> {0..})"
 11.1628 -    ultimately have "y \<noteq> Real (real y)" using preal by (cases y) auto
 11.1629 -    thus "y = \<omega>" by (auto simp: Real_real split: split_if_asm)
 11.1630 -  qed auto
 11.1631 -next
 11.1632 -  case infinite thus ?thesis
 11.1633 -    unfolding open_pinfreal_def by (auto intro!: exI[of _ "{}"])
 11.1634 -qed
 11.1635 -
 11.1636 -lemma pinfreal_open_greaterThanLessThan[simp]: "open {a::pinfreal <..< b}"
 11.1637 -  unfolding greaterThanLessThan_def by auto
 11.1638 -
 11.1639 -lemma closed_pinfreal_atLeast[simp, intro]: "closed {a :: pinfreal ..}"
 11.1640 -proof -
 11.1641 -  have "- {a ..} = {..< a}" by auto
 11.1642 -  then show "closed {a ..}"
 11.1643 -    unfolding closed_def using open_pinfreal_lessThan by auto
 11.1644 -qed
 11.1645 -
 11.1646 -lemma closed_pinfreal_atMost[simp, intro]: "closed {.. b :: pinfreal}"
 11.1647 -proof -
 11.1648 -  have "- {.. b} = {b <..}" by auto
 11.1649 -  then show "closed {.. b}" 
 11.1650 -    unfolding closed_def using open_pinfreal_greaterThan by auto
 11.1651 -qed
 11.1652 -
 11.1653 -lemma closed_pinfreal_atLeastAtMost[simp, intro]:
 11.1654 -  shows "closed {a :: pinfreal .. b}"
 11.1655 -  unfolding atLeastAtMost_def by auto
 11.1656 -
 11.1657 -lemma pinfreal_dense:
 11.1658 -  fixes x y :: pinfreal assumes "x < y"
 11.1659 -  shows "\<exists>z. x < z \<and> z < y"
 11.1660 -proof -
 11.1661 -  from `x < y` obtain p where p: "x = Real p" "0 \<le> p" by (cases x) auto
 11.1662 -  show ?thesis
 11.1663 -  proof (cases y)
 11.1664 -    case (preal r) with p `x < y` have "p < r" by auto
 11.1665 -    with dense obtain z where "p < z" "z < r" by auto
 11.1666 -    thus ?thesis using preal p by (auto intro!: exI[of _ "Real z"])
 11.1667 -  next
 11.1668 -    case infinite thus ?thesis using `x < y` p
 11.1669 -      by (auto intro!: exI[of _ "Real p + 1"])
 11.1670 -  qed
 11.1671 -qed
 11.1672 -
 11.1673 -instance pinfreal :: t2_space
 11.1674 -proof
 11.1675 -  fix x y :: pinfreal assume "x \<noteq> y"
 11.1676 -  let "?P x (y::pinfreal)" = "\<exists> U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
 11.1677 -
 11.1678 -  { fix x y :: pinfreal assume "x < y"
 11.1679 -    from pinfreal_dense[OF this] obtain z where z: "x < z" "z < y" by auto
 11.1680 -    have "?P x y"
 11.1681 -      apply (rule exI[of _ "{..<z}"])
 11.1682 -      apply (rule exI[of _ "{z<..}"])
 11.1683 -      using z by auto }
 11.1684 -  note * = this
 11.1685 -
 11.1686 -  from `x \<noteq> y`
 11.1687 -  show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
 11.1688 -  proof (cases rule: linorder_cases)
 11.1689 -    assume "x = y" with `x \<noteq> y` show ?thesis by simp
 11.1690 -  next assume "x < y" from *[OF this] show ?thesis by auto
 11.1691 -  next assume "y < x" from *[OF this] show ?thesis by auto
 11.1692 -  qed
 11.1693 -qed
 11.1694 -
 11.1695 -definition (in complete_lattice) isoton :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<up>" 50) where
 11.1696 -  "A \<up> X \<longleftrightarrow> (\<forall>i. A i \<le> A (Suc i)) \<and> (SUP i. A i) = X"
 11.1697 -
 11.1698 -definition (in complete_lattice) antiton (infix "\<down>" 50) where
 11.1699 -  "A \<down> X \<longleftrightarrow> (\<forall>i. A i \<ge> A (Suc i)) \<and> (INF i. A i) = X"
 11.1700 -
 11.1701 -lemma isotoneI[intro?]: "\<lbrakk> \<And>i. f i \<le> f (Suc i) ; (SUP i. f i) = F \<rbrakk> \<Longrightarrow> f \<up> F"
 11.1702 -  unfolding isoton_def by auto
 11.1703 -
 11.1704 -lemma (in complete_lattice) isotonD[dest]:
 11.1705 -  assumes "A \<up> X" shows "A i \<le> A (Suc i)" "(SUP i. A i) = X"
 11.1706 -  using assms unfolding isoton_def by auto
 11.1707 -
 11.1708 -lemma isotonD'[dest]:
 11.1709 -  assumes "(A::_=>_) \<up> X" shows "A i x \<le> A (Suc i) x" "(SUP i. A i) = X"
 11.1710 -  using assms unfolding isoton_def le_fun_def by auto
 11.1711 -
 11.1712 -lemma isoton_mono_le:
 11.1713 -  assumes "f \<up> x" "i \<le> j"
 11.1714 -  shows "f i \<le> f j"
 11.1715 -  using `f \<up> x`[THEN isotonD(1)] lift_Suc_mono_le[of f, OF _ `i \<le> j`] by auto
 11.1716 -
 11.1717 -lemma isoton_const:
 11.1718 -  shows "(\<lambda> i. c) \<up> c"
 11.1719 -unfolding isoton_def by auto
 11.1720 -
 11.1721 -lemma isoton_cmult_right:
 11.1722 -  assumes "f \<up> (x::pinfreal)"
 11.1723 -  shows "(\<lambda>i. c * f i) \<up> (c * x)"
 11.1724 -  using assms unfolding isoton_def pinfreal_SUP_cmult
 11.1725 -  by (auto intro: pinfreal_mult_cancel)
 11.1726 -
 11.1727 -lemma isoton_cmult_left:
 11.1728 -  "f \<up> (x::pinfreal) \<Longrightarrow> (\<lambda>i. f i * c) \<up> (x * c)"
 11.1729 -  by (subst (1 2) mult_commute) (rule isoton_cmult_right)
 11.1730 -
 11.1731 -lemma isoton_add:
 11.1732 -  assumes "f \<up> (x::pinfreal)" and "g \<up> y"
 11.1733 -  shows "(\<lambda>i. f i + g i) \<up> (x + y)"
 11.1734 -  using assms unfolding isoton_def
 11.1735 -  by (auto intro: pinfreal_mult_cancel add_mono simp: SUPR_pinfreal_add)
 11.1736 -
 11.1737 -lemma isoton_fun_expand:
 11.1738 -  "f \<up> x \<longleftrightarrow> (\<forall>i. (\<lambda>j. f j i) \<up> (x i))"
 11.1739 -proof -
 11.1740 -  have "\<And>i. {y. \<exists>f'\<in>range f. y = f' i} = range (\<lambda>j. f j i)"
 11.1741 -    by auto
 11.1742 -  with assms show ?thesis
 11.1743 -    by (auto simp add: isoton_def le_fun_def Sup_fun_def SUPR_def)
 11.1744 -qed
 11.1745 -
 11.1746 -lemma isoton_indicator:
 11.1747 -  assumes "f \<up> g"
 11.1748 -  shows "(\<lambda>i x. f i x * indicator A x) \<up> (\<lambda>x. g x * indicator A x :: pinfreal)"
 11.1749 -  using assms unfolding isoton_fun_expand by (auto intro!: isoton_cmult_left)
 11.1750 -
 11.1751 -lemma isoton_setsum:
 11.1752 -  fixes f :: "'a \<Rightarrow> nat \<Rightarrow> pinfreal"
 11.1753 -  assumes "finite A" "A \<noteq> {}"
 11.1754 -  assumes "\<And> x. x \<in> A \<Longrightarrow> f x \<up> y x"
 11.1755 -  shows "(\<lambda> i. (\<Sum> x \<in> A. f x i)) \<up> (\<Sum> x \<in> A. y x)"
 11.1756 -using assms
 11.1757 -proof (induct A rule:finite_ne_induct)
 11.1758 -  case singleton thus ?case by auto
 11.1759 -next
 11.1760 -  case (insert a A) note asms = this
 11.1761 -  hence *: "(\<lambda> i. \<Sum> x \<in> A. f x i) \<up> (\<Sum> x \<in> A. y x)" by auto
 11.1762 -  have **: "(\<lambda> i. f a i) \<up> y a" using asms by simp
 11.1763 -  have "(\<lambda> i. f a i + (\<Sum> x \<in> A. f x i)) \<up> (y a + (\<Sum> x \<in> A. y x))"
 11.1764 -    using * ** isoton_add by auto
 11.1765 -  thus "(\<lambda> i. \<Sum> x \<in> insert a A. f x i) \<up> (\<Sum> x \<in> insert a A. y x)"
 11.1766 -    using asms by fastsimp
 11.1767 -qed
 11.1768 -
 11.1769 -lemma isoton_Sup:
 11.1770 -  assumes "f \<up> u"
 11.1771 -  shows "f i \<le> u"
 11.1772 -  using le_SUPI[of i UNIV f] assms
 11.1773 -  unfolding isoton_def by auto
 11.1774 -
 11.1775 -lemma isoton_mono:
 11.1776 -  assumes iso: "x \<up> a" "y \<up> b" and *: "\<And>n. x n \<le> y (N n)"
 11.1777 -  shows "a \<le> b"
 11.1778 -proof -
 11.1779 -  from iso have "a = (SUP n. x n)" "b = (SUP n. y n)"
 11.1780 -    unfolding isoton_def by auto
 11.1781 -  with * show ?thesis by (auto intro!: SUP_mono)
 11.1782 -qed
 11.1783 -
 11.1784 -lemma pinfreal_le_mult_one_interval:
 11.1785 -  fixes x y :: pinfreal
 11.1786 -  assumes "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
 11.1787 -  shows "x \<le> y"
 11.1788 -proof (cases x, cases y)
 11.1789 -  assume "x = \<omega>"
 11.1790 -  with assms[of "1 / 2"]
 11.1791 -  show "x \<le> y" by simp
 11.1792 -next
 11.1793 -  fix r p assume *: "y = Real p" "x = Real r" and **: "0 \<le> r" "0 \<le> p"
 11.1794 -  have "r \<le> p"
 11.1795 -  proof (rule field_le_mult_one_interval)
 11.1796 -    fix z :: real assume "0 < z" and "z < 1"
 11.1797 -    with assms[of "Real z"]
 11.1798 -    show "z * r \<le> p" using ** * by (auto simp: zero_le_mult_iff)
 11.1799 -  qed
 11.1800 -  thus "x \<le> y" using ** * by simp
 11.1801 -qed simp
 11.1802 -
 11.1803 -lemma pinfreal_greater_0[intro]:
 11.1804 -  fixes a :: pinfreal
 11.1805 -  assumes "a \<noteq> 0"
 11.1806 -  shows "a > 0"
 11.1807 -using assms apply (cases a) by auto
 11.1808 -
 11.1809 -lemma pinfreal_mult_strict_right_mono:
 11.1810 -  assumes "a < b" and "0 < c" "c < \<omega>"
 11.1811 -  shows "a * c < b * c"
 11.1812 -  using assms
 11.1813 -  by (cases a, cases b, cases c)
 11.1814 -     (auto simp: zero_le_mult_iff pinfreal_less_\<omega>)
 11.1815 -
 11.1816 -lemma minus_pinfreal_eq2:
 11.1817 -  fixes x y z :: pinfreal
 11.1818 -  assumes "y \<le> x" and "y \<noteq> \<omega>" shows "z = x - y \<longleftrightarrow> z + y = x"
 11.1819 -  using assms
 11.1820 -  apply (subst eq_commute)
 11.1821 -  apply (subst minus_pinfreal_eq)
 11.1822 -  by (cases x, cases z, auto simp add: ac_simps not_less)
 11.1823 -
 11.1824 -lemma pinfreal_diff_eq_diff_imp_eq:
 11.1825 -  assumes "a \<noteq> \<omega>" "b \<le> a" "c \<le> a"
 11.1826 -  assumes "a - b = a - c"
 11.1827 -  shows "b = c"
 11.1828 -  using assms
 11.1829 -  by (cases a, cases b, cases c) (auto split: split_if_asm)
 11.1830 -
 11.1831 -lemma pinfreal_inverse_eq_0: "inverse x = 0 \<longleftrightarrow> x = \<omega>"
 11.1832 -  by (cases x) auto
 11.1833 -
 11.1834 -lemma pinfreal_mult_inverse:
 11.1835 -  "\<lbrakk> x \<noteq> \<omega> ; x \<noteq> 0 \<rbrakk> \<Longrightarrow> x * inverse x = 1"
 11.1836 -  by (cases x) auto
 11.1837 -
 11.1838 -lemma pinfreal_zero_less_diff_iff:
 11.1839 -  fixes a b :: pinfreal shows "0 < a - b \<longleftrightarrow> b < a"
 11.1840 -  apply (cases a, cases b)
 11.1841 -  apply (auto simp: pinfreal_noteq_omega_Ex pinfreal_less_\<omega>)
 11.1842 -  apply (cases b)
 11.1843 -  by auto
 11.1844 -
 11.1845 -lemma pinfreal_less_Real_Ex:
 11.1846 -  fixes a b :: pinfreal shows "x < Real r \<longleftrightarrow> (\<exists>p\<ge>0. p < r \<and> x = Real p)"
 11.1847 -  by (cases x) auto
 11.1848 -
 11.1849 -lemma open_Real: assumes "open S" shows "open (Real ` ({0..} \<inter> S))"
 11.1850 -  unfolding open_pinfreal_def apply(rule,rule,rule,rule assms) by auto
 11.1851 -
 11.1852 -lemma pinfreal_zero_le_diff:
 11.1853 -  fixes a b :: pinfreal shows "a - b = 0 \<longleftrightarrow> a \<le> b"
 11.1854 -  by (cases a, cases b, simp_all, cases b, auto)
 11.1855 -
 11.1856 -lemma lim_Real[simp]: assumes "\<forall>n. f n \<ge> 0" "m\<ge>0"
 11.1857 -  shows "(\<lambda>n. Real (f n)) ----> Real m \<longleftrightarrow> (\<lambda>n. f n) ----> m" (is "?l = ?r")
 11.1858 -proof assume ?l show ?r unfolding Lim_sequentially
 11.1859 -  proof safe fix e::real assume e:"e>0"
 11.1860 -    note open_ball[of m e] note open_Real[OF this]
 11.1861 -    note * = `?l`[unfolded tendsto_def,rule_format,OF this]
 11.1862 -    have "eventually (\<lambda>x. Real (f x) \<in> Real ` ({0..} \<inter> ball m e)) sequentially"
 11.1863 -      apply(rule *) unfolding image_iff using assms(2) e by auto
 11.1864 -    thus "\<exists>N. \<forall>n\<ge>N. dist (f n) m < e" unfolding eventually_sequentially 
 11.1865 -      apply safe apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
 11.1866 -    proof- fix n x assume "Real (f n) = Real x" "0 \<le> x"
 11.1867 -      hence *:"f n = x" using assms(1) by auto
 11.1868 -      assume "x \<in> ball m e" thus "dist (f n) m < e" unfolding *
 11.1869 -        by (auto simp add:dist_commute)
 11.1870 -    qed qed
 11.1871 -next assume ?r show ?l unfolding tendsto_def eventually_sequentially 
 11.1872 -  proof safe fix S assume S:"open S" "Real m \<in> S"
 11.1873 -    guess T y using S(1) apply-apply(erule pinfreal_openE) . note T=this
 11.1874 -    have "m\<in>real ` (S - {\<omega>})" unfolding image_iff 
 11.1875 -      apply(rule_tac x="Real m" in bexI) using assms(2) S(2) by auto
 11.1876 -    hence "m \<in> T" unfolding T(2)[THEN sym] by auto 
 11.1877 -    from `?r`[unfolded tendsto_def eventually_sequentially,rule_format,OF T(1) this]
 11.1878 -    guess N .. note N=this[rule_format]
 11.1879 -    show "\<exists>N. \<forall>n\<ge>N. Real (f n) \<in> S" apply(rule_tac x=N in exI) 
 11.1880 -    proof safe fix n assume n:"N\<le>n"
 11.1881 -      have "f n \<in> real ` (S - {\<omega>})" using N[OF n] assms unfolding T(2)[THEN sym] 
 11.1882 -        unfolding image_iff apply-apply(rule_tac x="Real (f n)" in bexI)
 11.1883 -        unfolding real_Real by auto
 11.1884 -      then guess x unfolding image_iff .. note x=this
 11.1885 -      show "Real (f n) \<in> S" unfolding x apply(subst Real_real) using x by auto
 11.1886 -    qed
 11.1887 -  qed
 11.1888 -qed
 11.1889 -
 11.1890 -lemma pinfreal_INFI:
 11.1891 -  fixes x :: pinfreal
 11.1892 -  assumes "\<And>i. i \<in> A \<Longrightarrow> x \<le> f i"
 11.1893 -  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> y \<le> f i) \<Longrightarrow> y \<le> x"
 11.1894 -  shows "(INF i:A. f i) = x"
 11.1895 -  unfolding INFI_def Inf_pinfreal_def
 11.1896 -  using assms by (auto intro!: Greatest_equality)
 11.1897 -
 11.1898 -lemma real_of_pinfreal_less:"x < y \<Longrightarrow> y\<noteq>\<omega> \<Longrightarrow> real x < real y"
 11.1899 -proof- case goal1
 11.1900 -  have *:"y = Real (real y)" "x = Real (real x)" using goal1 Real_real by auto
 11.1901 -  show ?case using goal1 apply- apply(subst(asm) *(1))apply(subst(asm) *(2))
 11.1902 -    unfolding pinfreal_less by auto
 11.1903 -qed
 11.1904 -
 11.1905 -lemma not_less_omega[simp]:"\<not> x < \<omega> \<longleftrightarrow> x = \<omega>"
 11.1906 -  by (metis antisym_conv3 pinfreal_less(3)) 
 11.1907 -
 11.1908 -lemma Real_real': assumes "x\<noteq>\<omega>" shows "Real (real x) = x"
 11.1909 -proof- have *:"(THE r. 0 \<le> r \<and> x = Real r) = real x"
 11.1910 -    apply(rule the_equality) using assms unfolding Real_real by auto
 11.1911 -  have "Real (THE r. 0 \<le> r \<and> x = Real r) = x" unfolding *
 11.1912 -    using assms unfolding Real_real by auto
 11.1913 -  thus ?thesis unfolding real_of_pinfreal_def of_pinfreal_def
 11.1914 -    unfolding pinfreal_case_def using assms by auto
 11.1915 -qed 
 11.1916 -
 11.1917 -lemma Real_less_plus_one:"Real x < Real (max (x + 1) 1)" 
 11.1918 -  unfolding pinfreal_less by auto
 11.1919 -
 11.1920 -lemma Lim_omega: "f ----> \<omega> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n \<ge> Real B)" (is "?l = ?r")
 11.1921 -proof assume ?r show ?l apply(rule topological_tendstoI)
 11.1922 -    unfolding eventually_sequentially
 11.1923 -  proof- fix S assume "open S" "\<omega> \<in> S"
 11.1924 -    from open_omega[OF this] guess B .. note B=this
 11.1925 -    from `?r`[rule_format,of "(max B 0)+1"] guess N .. note N=this
 11.1926 -    show "\<exists>N. \<forall>n\<ge>N. f n \<in> S" apply(rule_tac x=N in exI)
 11.1927 -    proof safe case goal1 
 11.1928 -      have "Real B < Real ((max B 0) + 1)" by auto
 11.1929 -      also have "... \<le> f n" using goal1 N by auto
 11.1930 -      finally show ?case using B by fastsimp
 11.1931 -    qed
 11.1932 -  qed
 11.1933 -next assume ?l show ?r
 11.1934 -  proof fix B::real have "open {Real B<..}" "\<omega> \<in> {Real B<..}" by auto
 11.1935 -    from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially]
 11.1936 -    guess N .. note N=this
 11.1937 -    show "\<exists>N. \<forall>n\<ge>N. Real B \<le> f n" apply(rule_tac x=N in exI) using N by auto
 11.1938 -  qed
 11.1939 -qed
 11.1940 -
 11.1941 -lemma Lim_bounded_omgea: assumes lim:"f ----> l" and "\<And>n. f n \<le> Real B" shows "l \<noteq> \<omega>"
 11.1942 -proof(rule ccontr,unfold not_not) let ?B = "max (B + 1) 1" assume as:"l=\<omega>"
 11.1943 -  from lim[unfolded this Lim_omega,rule_format,of "?B"]
 11.1944 -  guess N .. note N=this[rule_format,OF le_refl]
 11.1945 -  hence "Real ?B \<le> Real B" using assms(2)[of N] by(rule order_trans) 
 11.1946 -  hence "Real ?B < Real ?B" using Real_less_plus_one[of B] by(rule le_less_trans)
 11.1947 -  thus False by auto
 11.1948 -qed
 11.1949 -
 11.1950 -lemma incseq_le_pinfreal: assumes inc: "\<And>n m. n\<ge>m \<Longrightarrow> X n \<ge> X m"
 11.1951 -  and lim: "X ----> (L::pinfreal)" shows "X n \<le> L"
 11.1952 -proof(cases "L = \<omega>")
 11.1953 -  case False have "\<forall>n. X n \<noteq> \<omega>"
 11.1954 -  proof(rule ccontr,unfold not_all not_not,safe)
 11.1955 -    case goal1 hence "\<forall>n\<ge>x. X n = \<omega>" using inc[of x] by auto
 11.1956 -    hence "X ----> \<omega>" unfolding tendsto_def eventually_sequentially
 11.1957 -      apply safe apply(rule_tac x=x in exI) by auto
 11.1958 -    note Lim_unique[OF trivial_limit_sequentially this lim]
 11.1959 -    with False show False by auto
 11.1960 -  qed note * =this[rule_format]
 11.1961 -
 11.1962 -  have **:"\<forall>m n. m \<le> n \<longrightarrow> Real (real (X m)) \<le> Real (real (X n))"
 11.1963 -    unfolding Real_real using * inc by auto
 11.1964 -  have "real (X n) \<le> real L" apply-apply(rule incseq_le) defer
 11.1965 -    apply(subst lim_Real[THEN sym]) apply(rule,rule,rule)
 11.1966 -    unfolding Real_real'[OF *] Real_real'[OF False] 
 11.1967 -    unfolding incseq_def using ** lim by auto
 11.1968 -  hence "Real (real (X n)) \<le> Real (real L)" by auto
 11.1969 -  thus ?thesis unfolding Real_real using * False by auto
 11.1970 -qed auto
 11.1971 -
 11.1972 -lemma SUP_Lim_pinfreal: assumes "\<And>n m. n\<ge>m \<Longrightarrow> f n \<ge> f m" "f ----> l"
 11.1973 -  shows "(SUP n. f n) = (l::pinfreal)" unfolding SUPR_def Sup_pinfreal_def
 11.1974 -proof (safe intro!: Least_equality)
 11.1975 -  fix n::nat show "f n \<le> l" apply(rule incseq_le_pinfreal)
 11.1976 -    using assms by auto
 11.1977 -next fix y assume y:"\<forall>x\<in>range f. x \<le> y" show "l \<le> y"
 11.1978 -  proof(rule ccontr,cases "y=\<omega>",unfold not_le)
 11.1979 -    case False assume as:"y < l"
 11.1980 -    have l:"l \<noteq> \<omega>" apply(rule Lim_bounded_omgea[OF assms(2), of "real y"])
 11.1981 -      using False y unfolding Real_real by auto
 11.1982 -
 11.1983 -    have yl:"real y < real l" using as apply-
 11.1984 -      apply(subst(asm) Real_real'[THEN sym,OF `y\<noteq>\<omega>`])
 11.1985 -      apply(subst(asm) Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) 
 11.1986 -      unfolding pinfreal_less apply(subst(asm) if_P) by auto
 11.1987 -    hence "y + (y - l) * Real (1 / 2) < l" apply-
 11.1988 -      apply(subst Real_real'[THEN sym,OF `y\<noteq>\<omega>`]) apply(subst(2) Real_real'[THEN sym,OF `y\<noteq>\<omega>`])
 11.1989 -      apply(subst Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) apply(subst(2) Real_real'[THEN sym,OF `l\<noteq>\<omega>`]) by auto
 11.1990 -    hence *:"l \<in> {y + (y - l) / 2<..}" by auto
 11.1991 -    have "open {y + (y-l)/2 <..}" by auto
 11.1992 -    note topological_tendstoD[OF assms(2) this *]
 11.1993 -    from this[unfolded eventually_sequentially] guess N .. note this[rule_format, of N]
 11.1994 -    hence "y + (y - l) * Real (1 / 2) < y" using y[rule_format,of "f N"] by auto
 11.1995 -    hence "Real (real y) + (Real (real y) - Real (real l)) * Real (1 / 2) < Real (real y)"
 11.1996 -      unfolding Real_real using `y\<noteq>\<omega>` `l\<noteq>\<omega>` by auto
 11.1997 -    thus False using yl by auto
 11.1998 -  qed auto
 11.1999 -qed
 11.2000 -
 11.2001 -lemma Real_max':"Real x = Real (max x 0)" 
 11.2002 -proof(cases "x < 0") case True
 11.2003 -  hence *:"max x 0 = 0" by auto
 11.2004 -  show ?thesis unfolding * using True by auto
 11.2005 -qed auto
 11.2006 -
 11.2007 -lemma lim_pinfreal_increasing: assumes "\<forall>n m. n\<ge>m \<longrightarrow> f n \<ge> f m"
 11.2008 -  obtains l where "f ----> (l::pinfreal)"
 11.2009 -proof(cases "\<exists>B. \<forall>n. f n < Real B")
 11.2010 -  case False thus thesis apply- apply(rule that[of \<omega>]) unfolding Lim_omega not_ex not_all
 11.2011 -    apply safe apply(erule_tac x=B in allE,safe) apply(rule_tac x=x in exI,safe)
 11.2012 -    apply(rule order_trans[OF _ assms[rule_format]]) by auto
 11.2013 -next case True then guess B .. note B = this[rule_format]
 11.2014 -  hence *:"\<And>n. f n < \<omega>" apply-apply(rule less_le_trans,assumption) by auto
 11.2015 -  have *:"\<And>n. f n \<noteq> \<omega>" proof- case goal1 show ?case using *[of n] by auto qed
 11.2016 -  have B':"\<And>n. real (f n) \<le> max 0 B" proof- case goal1 thus ?case
 11.2017 -      using B[of n] apply-apply(subst(asm) Real_real'[THEN sym]) defer
 11.2018 -      apply(subst(asm)(2) Real_max') unfolding pinfreal_less apply(subst(asm) if_P) using *[of n] by auto
 11.2019 -  qed
 11.2020 -  have "\<exists>l. (\<lambda>n. real (f n)) ----> l" apply(rule Topology_Euclidean_Space.bounded_increasing_convergent)
 11.2021 -  proof safe show "bounded {real (f n) |n. True}"
 11.2022 -      unfolding bounded_def apply(rule_tac x=0 in exI,rule_tac x="max 0 B" in exI)
 11.2023 -      using B' unfolding dist_norm by auto
 11.2024 -    fix n::nat have "Real (real (f n)) \<le> Real (real (f (Suc n)))"
 11.2025 -      using assms[rule_format,of n "Suc n"] apply(subst Real_real)+
 11.2026 -      using *[of n] *[of "Suc n"] by fastsimp
 11.2027 -    thus "real (f n) \<le> real (f (Suc n))" by auto
 11.2028 -  qed then guess l .. note l=this
 11.2029 -  have "0 \<le> l" apply(rule LIMSEQ_le_const[OF l])
 11.2030 -    by(rule_tac x=0 in exI,auto)
 11.2031 -
 11.2032 -  thus ?thesis apply-apply(rule that[of "Real l"])
 11.2033 -    using l apply-apply(subst(asm) lim_Real[THEN sym]) prefer 3
 11.2034 -    unfolding Real_real using * by auto
 11.2035 -qed
 11.2036 -
 11.2037 -lemma setsum_neq_omega: assumes "finite s" "\<And>x. x \<in> s \<Longrightarrow> f x \<noteq> \<omega>"
 11.2038 -  shows "setsum f s \<noteq> \<omega>" using assms
 11.2039 -proof induct case (insert x s)
 11.2040 -  show ?case unfolding setsum.insert[OF insert(1-2)] 
 11.2041 -    using insert by auto
 11.2042 -qed auto
 11.2043 -
 11.2044 -
 11.2045 -lemma real_Real': "0 \<le> x \<Longrightarrow> real (Real x) = x"
 11.2046 -  unfolding real_Real by auto
 11.2047 -
 11.2048 -lemma real_pinfreal_pos[intro]:
 11.2049 -  assumes "x \<noteq> 0" "x \<noteq> \<omega>"
 11.2050 -  shows "real x > 0"
 11.2051 -  apply(subst real_Real'[THEN sym,of 0]) defer
 11.2052 -  apply(rule real_of_pinfreal_less) using assms by auto
 11.2053 -
 11.2054 -lemma Lim_omega_gt: "f ----> \<omega> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n > Real B)" (is "?l = ?r")
 11.2055 -proof assume ?l thus ?r unfolding Lim_omega apply safe
 11.2056 -    apply(erule_tac x="max B 0 +1" in allE,safe)
 11.2057 -    apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
 11.2058 -    apply(rule_tac y="Real (max B 0 + 1)" in less_le_trans) by auto
 11.2059 -next assume ?r thus ?l unfolding Lim_omega apply safe
 11.2060 -    apply(erule_tac x=B in allE,safe) apply(rule_tac x=N in exI,safe) by auto
 11.2061 -qed
 11.2062 -
 11.2063 -lemma pinfreal_minus_le_cancel:
 11.2064 -  fixes a b c :: pinfreal
 11.2065 -  assumes "b \<le> a"
 11.2066 -  shows "c - a \<le> c - b"
 11.2067 -  using assms by (cases a, cases b, cases c, simp, simp, simp, cases b, cases c, simp_all)
 11.2068 -
 11.2069 -lemma pinfreal_minus_\<omega>[simp]: "x - \<omega> = 0" by (cases x) simp_all
 11.2070 -
 11.2071 -lemma pinfreal_minus_mono[intro]: "a - x \<le> (a::pinfreal)"
 11.2072 -proof- have "a - x \<le> a - 0"
 11.2073 -    apply(rule pinfreal_minus_le_cancel) by auto
 11.2074 -  thus ?thesis by auto
 11.2075 -qed
 11.2076 -
 11.2077 -lemma pinfreal_minus_eq_\<omega>[simp]: "x - y = \<omega> \<longleftrightarrow> (x = \<omega> \<and> y \<noteq> \<omega>)"
 11.2078 -  by (cases x, cases y) (auto, cases y, auto)
 11.2079 -
 11.2080 -lemma pinfreal_less_minus_iff:
 11.2081 -  fixes a b c :: pinfreal
 11.2082 -  shows "a < b - c \<longleftrightarrow> c + a < b"
 11.2083 -  by (cases c, cases a, cases b, auto)
 11.2084 -
 11.2085 -lemma pinfreal_minus_less_iff:
 11.2086 -  fixes a b c :: pinfreal shows "a - c < b \<longleftrightarrow> (0 < b \<and> (c \<noteq> \<omega> \<longrightarrow> a < b + c))"
 11.2087 -  by (cases c, cases a, cases b, auto)
 11.2088 -
 11.2089 -lemma pinfreal_le_minus_iff:
 11.2090 -  fixes a b c :: pinfreal
 11.2091 -  shows "a \<le> c - b \<longleftrightarrow> ((c \<le> b \<longrightarrow> a = 0) \<and> (b < c \<longrightarrow> a + b \<le> c))"
 11.2092 -  by (cases a, cases c, cases b, auto simp: pinfreal_noteq_omega_Ex)
 11.2093 -
 11.2094 -lemma pinfreal_minus_le_iff:
 11.2095 -  fixes a b c :: pinfreal
 11.2096 -  shows "a - c \<le> b \<longleftrightarrow> (c \<le> a \<longrightarrow> a \<le> b + c)"
 11.2097 -  by (cases a, cases c, cases b, auto simp: pinfreal_noteq_omega_Ex)
 11.2098 -
 11.2099 -lemmas pinfreal_minus_order = pinfreal_minus_le_iff pinfreal_minus_less_iff pinfreal_le_minus_iff pinfreal_less_minus_iff
 11.2100 -
 11.2101 -lemma pinfreal_minus_strict_mono:
 11.2102 -  assumes "a > 0" "x > 0" "a\<noteq>\<omega>"
 11.2103 -  shows "a - x < (a::pinfreal)"
 11.2104 -  using assms by(cases x, cases a, auto)
 11.2105 -
 11.2106 -lemma pinfreal_minus':
 11.2107 -  "Real r - Real p = (if 0 \<le> r \<and> p \<le> r then if 0 \<le> p then Real (r - p) else Real r else 0)"
 11.2108 -  by (auto simp: minus_pinfreal_eq not_less)
 11.2109 -
 11.2110 -lemma pinfreal_minus_plus:
 11.2111 -  "x \<le> (a::pinfreal) \<Longrightarrow> a - x + x = a"
 11.2112 -  by (cases a, cases x) auto
 11.2113 -
 11.2114 -lemma pinfreal_cancel_plus_minus: "b \<noteq> \<omega> \<Longrightarrow> a + b - b = a"
 11.2115 -  by (cases a, cases b) auto
 11.2116 -
 11.2117 -lemma pinfreal_minus_le_cancel_right:
 11.2118 -  fixes a b c :: pinfreal
 11.2119 -  assumes "a \<le> b" "c \<le> a"
 11.2120 -  shows "a - c \<le> b - c"
 11.2121 -  using assms by (cases a, cases b, cases c, auto, cases c, auto)
 11.2122 -
 11.2123 -lemma real_of_pinfreal_setsum':
 11.2124 -  assumes "\<forall>x \<in> S. f x \<noteq> \<omega>"
 11.2125 -  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
 11.2126 -proof cases
 11.2127 -  assume "finite S"
 11.2128 -  from this assms show ?thesis
 11.2129 -    by induct (simp_all add: real_of_pinfreal_add setsum_\<omega>)
 11.2130 -qed simp
 11.2131 -
 11.2132 -lemma Lim_omega_pos: "f ----> \<omega> \<longleftrightarrow> (\<forall>B>0. \<exists>N. \<forall>n\<ge>N. f n \<ge> Real B)" (is "?l = ?r")
 11.2133 -  unfolding Lim_omega apply safe defer
 11.2134 -  apply(erule_tac x="max 1 B" in allE) apply safe defer
 11.2135 -  apply(rule_tac x=N in exI,safe) apply(erule_tac x=n in allE,safe)
 11.2136 -  apply(rule_tac y="Real (max 1 B)" in order_trans) by auto
 11.2137 -
 11.2138 -lemma pinfreal_LimI_finite:
 11.2139 -  assumes "x \<noteq> \<omega>" "\<And>r. 0 < r \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r"
 11.2140 -  shows "u ----> x"
 11.2141 -proof (rule topological_tendstoI, unfold eventually_sequentially)
 11.2142 -  fix S assume "open S" "x \<in> S"
 11.2143 -  then obtain A where "open A" and A_eq: "Real ` (A \<inter> {0..}) = S - {\<omega>}" by (auto elim!: pinfreal_openE)
 11.2144 -  then have "x \<in> Real ` (A \<inter> {0..})" using `x \<in> S` `x \<noteq> \<omega>` by auto
 11.2145 -  then have "real x \<in> A" by auto
 11.2146 -  then obtain r where "0 < r" and dist: "\<And>y. dist y (real x) < r \<Longrightarrow> y \<in> A"
 11.2147 -    using `open A` unfolding open_real_def by auto
 11.2148 -  then obtain n where
 11.2149 -    upper: "\<And>N. n \<le> N \<Longrightarrow> u N < x + Real r" and
 11.2150 -    lower: "\<And>N. n \<le> N \<Longrightarrow> x < u N + Real r" using assms(2)[of "Real r"] by auto
 11.2151 -  show "\<exists>N. \<forall>n\<ge>N. u n \<in> S"
 11.2152 -  proof (safe intro!: exI[of _ n])
 11.2153 -    fix N assume "n \<le> N"
 11.2154 -    from upper[OF this] `x \<noteq> \<omega>` `0 < r`
 11.2155 -    have "u N \<noteq> \<omega>" by (force simp: pinfreal_noteq_omega_Ex)
 11.2156 -    with `x \<noteq> \<omega>` `0 < r` lower[OF `n \<le> N`] upper[OF `n \<le> N`]
 11.2157 -    have "dist (real (u N)) (real x) < r" "u N \<noteq> \<omega>"
 11.2158 -      by (auto simp: pinfreal_noteq_omega_Ex dist_real_def abs_diff_less_iff field_simps)
 11.2159 -    from dist[OF this(1)]
 11.2160 -    have "u N \<in> Real ` (A \<inter> {0..})" using `u N \<noteq> \<omega>`
 11.2161 -      by (auto intro!: image_eqI[of _ _ "real (u N)"] simp: pinfreal_noteq_omega_Ex Real_real)
 11.2162 -    thus "u N \<in> S" using A_eq by simp
 11.2163 -  qed
 11.2164 -qed
 11.2165 -
 11.2166 -lemma real_Real_max:"real (Real x) = max x 0"
 11.2167 -  unfolding real_Real by auto
 11.2168 -
 11.2169 -lemma Sup_lim:
 11.2170 -  assumes "\<forall>n. b n \<in> s" "b ----> (a::pinfreal)"
 11.2171 -  shows "a \<le> Sup s"
 11.2172 -proof(rule ccontr,unfold not_le)
 11.2173 -  assume as:"Sup s < a" hence om:"Sup s \<noteq> \<omega>" by auto
 11.2174 -  have s:"s \<noteq> {}" using assms by auto
 11.2175 -  { presume *:"\<forall>n. b n < a \<Longrightarrow> False"
 11.2176 -    show False apply(cases,rule *,assumption,unfold not_all not_less)
 11.2177 -    proof- case goal1 then guess n .. note n=this
 11.2178 -      thus False using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of n]]
 11.2179 -        using as by auto
 11.2180 -    qed
 11.2181 -  } assume b:"\<forall>n. b n < a"
 11.2182 -  show False
 11.2183 -  proof(cases "a = \<omega>")
 11.2184 -    case False have *:"a - Sup s > 0" 
 11.2185 -      using False as by(auto simp: pinfreal_zero_le_diff)
 11.2186 -    have "(a - Sup s) / 2 \<le> a / 2" unfolding divide_pinfreal_def
 11.2187 -      apply(rule mult_right_mono) by auto
 11.2188 -    also have "... = Real (real (a / 2))" apply(rule Real_real'[THEN sym])
 11.2189 -      using False by auto
 11.2190 -    also have "... < Real (real a)" unfolding pinfreal_less using as False
 11.2191 -      by(auto simp add: real_of_pinfreal_mult[THEN sym])
 11.2192 -    also have "... = a" apply(rule Real_real') using False by auto
 11.2193 -    finally have asup:"a > (a - Sup s) / 2" .
 11.2194 -    have "\<exists>n. a - b n < (a - Sup s) / 2"
 11.2195 -    proof(rule ccontr,unfold not_ex not_less)
 11.2196 -      case goal1
 11.2197 -      have "(a - Sup s) * Real (1 / 2)  > 0" 
 11.2198 -        using * by auto
 11.2199 -      hence "a - (a - Sup s) * Real (1 / 2) < a"
 11.2200 -        apply-apply(rule pinfreal_minus_strict_mono)
 11.2201 -        using False * by auto
 11.2202 -      hence *:"a \<in> {a - (a - Sup s) / 2<..}"using asup by auto 
 11.2203 -      note topological_tendstoD[OF assms(2) open_pinfreal_greaterThan,OF *]
 11.2204 -      from this[unfolded eventually_sequentially] guess n .. 
 11.2205 -      note n = this[rule_format,of n] 
 11.2206 -      have "b n + (a - Sup s) / 2 \<le> a" 
 11.2207 -        using add_right_mono[OF goal1[rule_format,of n],of "b n"]
 11.2208 -        unfolding pinfreal_minus_plus[OF less_imp_le[OF b[rule_format]]]
 11.2209 -        by(auto simp: add_commute)
 11.2210 -      hence "b n \<le> a - (a - Sup s) / 2" unfolding pinfreal_le_minus_iff
 11.2211 -        using asup by auto
 11.2212 -      hence "b n \<notin> {a - (a - Sup s) / 2<..}" by auto
 11.2213 -      thus False using n by auto
 11.2214 -    qed
 11.2215 -    then guess n .. note n = this
 11.2216 -    have "Sup s < a - (a - Sup s) / 2"
 11.2217 -      using False as om by (cases a) (auto simp: pinfreal_noteq_omega_Ex field_simps)
 11.2218 -    also have "... \<le> b n"
 11.2219 -    proof- note add_right_mono[OF less_imp_le[OF n],of "b n"]
 11.2220 -      note this[unfolded pinfreal_minus_plus[OF less_imp_le[OF b[rule_format]]]]
 11.2221 -      hence "a - (a - Sup s) / 2 \<le> (a - Sup s) / 2 + b n - (a - Sup s) / 2"
 11.2222 -        apply(rule pinfreal_minus_le_cancel_right) using asup by auto
 11.2223 -      also have "... = b n + (a - Sup s) / 2 - (a - Sup s) / 2" 
 11.2224 -        by(auto simp add: add_commute)
 11.2225 -      also have "... = b n" apply(subst pinfreal_cancel_plus_minus)
 11.2226 -      proof(rule ccontr,unfold not_not) case goal1
 11.2227 -        show ?case using asup unfolding goal1 by auto 
 11.2228 -      qed auto
 11.2229 -      finally show ?thesis .
 11.2230 -    qed     
 11.2231 -    finally show False
 11.2232 -      using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of n]] by auto  
 11.2233 -  next case True
 11.2234 -    from assms(2)[unfolded True Lim_omega_gt,rule_format,of "real (Sup s)"]
 11.2235 -    guess N .. note N = this[rule_format,of N]
 11.2236 -    thus False using complete_lattice_class.Sup_upper[OF assms(1)[rule_format,of N]] 
 11.2237 -      unfolding Real_real using om by auto
 11.2238 -  qed qed
 11.2239 -
 11.2240 -lemma Sup_mono_lim:
 11.2241 -  assumes "\<forall>a\<in>A. \<exists>b. \<forall>n. b n \<in> B \<and> b ----> (a::pinfreal)"
 11.2242 -  shows "Sup A \<le> Sup B"
 11.2243 -  unfolding Sup_le_iff apply(rule) apply(drule assms[rule_format]) apply safe
 11.2244 -  apply(rule_tac b=b in Sup_lim) by auto
 11.2245 -
 11.2246 -lemma pinfreal_less_add:
 11.2247 -  assumes "x \<noteq> \<omega>" "a < b"
 11.2248 -  shows "x + a < x + b"
 11.2249 -  using assms by (cases a, cases b, cases x) auto
 11.2250 -
 11.2251 -lemma SUPR_lim:
 11.2252 -  assumes "\<forall>n. b n \<in> B" "(\<lambda>n. f (b n)) ----> (f a::pinfreal)"
 11.2253 -  shows "f a \<le> SUPR B f"
 11.2254 -  unfolding SUPR_def apply(rule Sup_lim[of "\<lambda>n. f (b n)"])
 11.2255 -  using assms by auto
 11.2256 -
 11.2257 -lemma SUP_\<omega>_imp:
 11.2258 -  assumes "(SUP i. f i) = \<omega>"
 11.2259 -  shows "\<exists>i. Real x < f i"
 11.2260 -proof (rule ccontr)
 11.2261 -  assume "\<not> ?thesis" hence "\<And>i. f i \<le> Real x" by (simp add: not_less)
 11.2262 -  hence "(SUP i. f i) \<le> Real x" unfolding SUP_le_iff by auto
 11.2263 -  with assms show False by auto
 11.2264 -qed
 11.2265 -
 11.2266 -lemma SUPR_mono_lim:
 11.2267 -  assumes "\<forall>a\<in>A. \<exists>b. \<forall>n. b n \<in> B \<and> (\<lambda>n. f (b n)) ----> (f a::pinfreal)"
 11.2268 -  shows "SUPR A f \<le> SUPR B f"
 11.2269 -  unfolding SUPR_def apply(rule Sup_mono_lim)
 11.2270 -  apply safe apply(drule assms[rule_format],safe)
 11.2271 -  apply(rule_tac x="\<lambda>n. f (b n)" in exI) by auto
 11.2272 -
 11.2273 -lemma real_0_imp_eq_0:
 11.2274 -  assumes "x \<noteq> \<omega>" "real x = 0"
 11.2275 -  shows "x = 0"
 11.2276 -using assms by (cases x) auto
 11.2277 -
 11.2278 -lemma SUPR_mono:
 11.2279 -  assumes "\<forall>a\<in>A. \<exists>b\<in>B. f b \<ge> f a"
 11.2280 -  shows "SUPR A f \<le> SUPR B f"
 11.2281 -  unfolding SUPR_def apply(rule Sup_mono)
 11.2282 -  using assms by auto
 11.2283 -
 11.2284 -lemma less_add_Real:
 11.2285 -  fixes x :: real
 11.2286 -  fixes a b :: pinfreal
 11.2287 -  assumes "x \<ge> 0" "a < b"
 11.2288 -  shows "a + Real x < b + Real x"
 11.2289 -using assms by (cases a, cases b) auto
 11.2290 -
 11.2291 -lemma le_add_Real:
 11.2292 -  fixes x :: real
 11.2293 -  fixes a b :: pinfreal
 11.2294 -  assumes "x \<ge> 0" "a \<le> b"
 11.2295 -  shows "a + Real x \<le> b + Real x"
 11.2296 -using assms by (cases a, cases b) auto
 11.2297 -
 11.2298 -lemma le_imp_less_pinfreal:
 11.2299 -  fixes x :: pinfreal
 11.2300 -  assumes "x > 0" "a + x \<le> b" "a \<noteq> \<omega>"
 11.2301 -  shows "a < b"
 11.2302 -using assms by (cases x, cases a, cases b) auto
 11.2303 -
 11.2304 -lemma pinfreal_INF_minus:
 11.2305 -  fixes f :: "nat \<Rightarrow> pinfreal"
 11.2306 -  assumes "c \<noteq> \<omega>"
 11.2307 -  shows "(INF i. c - f i) = c - (SUP i. f i)"
 11.2308 -proof (cases "SUP i. f i")
 11.2309 -  case infinite
 11.2310 -  from `c \<noteq> \<omega>` obtain x where [simp]: "c = Real x" by (cases c) auto
 11.2311 -  from SUP_\<omega>_imp[OF infinite] obtain i where "Real x < f i" by auto
 11.2312 -  have "(INF i. c - f i) \<le> c - f i"
 11.2313 -    by (auto intro!: complete_lattice_class.INF_leI)
 11.2314 -  also have "\<dots> = 0" using `Real x < f i` by (auto simp: minus_pinfreal_eq)
 11.2315 -  finally show ?thesis using infinite by auto
 11.2316 -next
 11.2317 -  case (preal r)
 11.2318 -  from `c \<noteq> \<omega>` obtain x where c: "c = Real x" by (cases c) auto
 11.2319 -
 11.2320 -  show ?thesis unfolding c
 11.2321 -  proof (rule pinfreal_INFI)
 11.2322 -    fix i have "f i \<le> (SUP i. f i)" by (rule le_SUPI) simp
 11.2323 -    thus "Real x - (SUP i. f i) \<le> Real x - f i" by (rule pinfreal_minus_le_cancel)
 11.2324 -  next
 11.2325 -    fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> y \<le> Real x - f i"
 11.2326 -    from this[of 0] obtain p where p: "y = Real p" "0 \<le> p"
 11.2327 -      by (cases "f 0", cases y, auto split: split_if_asm)
 11.2328 -    hence "\<And>i. Real p \<le> Real x - f i" using * by auto
 11.2329 -    hence *: "\<And>i. Real x \<le> f i \<Longrightarrow> Real p = 0"
 11.2330 -      "\<And>i. f i < Real x \<Longrightarrow> Real p + f i \<le> Real x"
 11.2331 -      unfolding pinfreal_le_minus_iff by auto
 11.2332 -    show "y \<le> Real x - (SUP i. f i)" unfolding p pinfreal_le_minus_iff
 11.2333 -    proof safe
 11.2334 -      assume x_less: "Real x \<le> (SUP i. f i)"
 11.2335 -      show "Real p = 0"
 11.2336 -      proof (rule ccontr)
 11.2337 -        assume "Real p \<noteq> 0"
 11.2338 -        hence "0 < Real p" by auto
 11.2339 -        from Sup_close[OF this, of "range f"]
 11.2340 -        obtain i where e: "(SUP i. f i) < f i + Real p"
 11.2341 -          using preal unfolding SUPR_def by auto
 11.2342 -        hence "Real x \<le> f i + Real p" using x_less by auto
 11.2343 -        show False
 11.2344 -        proof cases
 11.2345 -          assume "\<forall>i. f i < Real x"
 11.2346 -          hence "Real p + f i \<le> Real x" using * by auto
 11.2347 -          hence "f i + Real p \<le> (SUP i. f i)" using x_less by (auto simp: field_simps)
 11.2348 -          thus False using e by auto
 11.2349 -        next
 11.2350 -          assume "\<not> (\<forall>i. f i < Real x)"
 11.2351 -          then obtain i where "Real x \<le> f i" by (auto simp: not_less)
 11.2352 -          from *(1)[OF this] show False using `Real p \<noteq> 0` by auto
 11.2353 -        qed
 11.2354 -      qed
 11.2355 -    next
 11.2356 -      have "\<And>i. f i \<le> (SUP i. f i)" by (rule complete_lattice_class.le_SUPI) auto
 11.2357 -      also assume "(SUP i. f i) < Real x"
 11.2358 -      finally have "\<And>i. f i < Real x" by auto
 11.2359 -      hence *: "\<And>i. Real p + f i \<le> Real x" using * by auto
 11.2360 -      have "Real p \<le> Real x" using *[of 0] by (cases "f 0") (auto split: split_if_asm)
 11.2361 -
 11.2362 -      have SUP_eq: "(SUP i. f i) \<le> Real x - Real p"
 11.2363 -      proof (rule SUP_leI)
 11.2364 -        fix i show "f i \<le> Real x - Real p" unfolding pinfreal_le_minus_iff
 11.2365 -        proof safe
 11.2366 -          assume "Real x \<le> Real p"
 11.2367 -          with *[of i] show "f i = 0"
 11.2368 -            by (cases "f i") (auto split: split_if_asm)
 11.2369 -        next
 11.2370 -          assume "Real p < Real x"
 11.2371 -          show "f i + Real p \<le> Real x" using * by (auto simp: field_simps)
 11.2372 -        qed
 11.2373 -      qed
 11.2374 -
 11.2375 -      show "Real p + (SUP i. f i) \<le> Real x"
 11.2376 -      proof cases
 11.2377 -        assume "Real x \<le> Real p"
 11.2378 -        with `Real p \<le> Real x` have [simp]: "Real p = Real x" by (rule antisym)
 11.2379 -        { fix i have "f i = 0" using *[of i] by (cases "f i") (auto split: split_if_asm) }
 11.2380 -        hence "(SUP i. f i) \<le> 0" by (auto intro!: SUP_leI)
 11.2381 -        thus ?thesis by simp
 11.2382 -      next
 11.2383 -        assume "\<not> Real x \<le> Real p" hence "Real p < Real x" unfolding not_le .
 11.2384 -        with SUP_eq show ?thesis unfolding pinfreal_le_minus_iff by (auto simp: field_simps)
 11.2385 -      qed
 11.2386 -    qed
 11.2387 -  qed
 11.2388 -qed
 11.2389 -
 11.2390 -lemma pinfreal_SUP_minus:
 11.2391 -  fixes f :: "nat \<Rightarrow> pinfreal"
 11.2392 -  shows "(SUP i. c - f i) = c - (INF i. f i)"
 11.2393 -proof (rule pinfreal_SUPI)
 11.2394 -  fix i have "(INF i. f i) \<le> f i" by (rule INF_leI) simp
 11.2395 -  thus "c - f i \<le> c - (INF i. f i)" by (rule pinfreal_minus_le_cancel)
 11.2396 -next
 11.2397 -  fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> c - f i \<le> y"
 11.2398 -  show "c - (INF i. f i) \<le> y"
 11.2399 -  proof (cases y)
 11.2400 -    case (preal p)
 11.2401 -
 11.2402 -    show ?thesis unfolding pinfreal_minus_le_iff preal
 11.2403 -    proof safe
 11.2404 -      assume INF_le_x: "(INF i. f i) \<le> c"
 11.2405 -      from * have *: "\<And>i. f i \<le> c \<Longrightarrow> c \<le> Real p + f i"
 11.2406 -        unfolding pinfreal_minus_le_iff preal by auto
 11.2407 -
 11.2408 -      have INF_eq: "c - Real p \<le> (INF i. f i)"
 11.2409 -      proof (rule le_INFI)
 11.2410 -        fix i show "c - Real p \<le> f i" unfolding pinfreal_minus_le_iff
 11.2411 -        proof safe
 11.2412 -          assume "Real p \<le> c"
 11.2413 -          show "c \<le> f i + Real p"
 11.2414 -          proof cases
 11.2415 -            assume "f i \<le> c" from *[OF this]
 11.2416 -            show ?thesis by (simp add: field_simps)
 11.2417 -          next
 11.2418 -            assume "\<not> f i \<le> c"
 11.2419 -            hence "c \<le> f i" by auto
 11.2420 -            also have "\<dots> \<le> f i + Real p" by auto
 11.2421 -            finally show ?thesis .
 11.2422 -          qed
 11.2423 -        qed
 11.2424 -      qed
 11.2425 -
 11.2426 -      show "c \<le> Real p + (INF i. f i)"
 11.2427 -      proof cases
 11.2428 -        assume "Real p \<le> c"
 11.2429 -        with INF_eq show ?thesis unfolding pinfreal_minus_le_iff by (auto simp: field_simps)
 11.2430 -      next
 11.2431 -        assume "\<not> Real p \<le> c"
 11.2432 -        hence "c \<le> Real p" by auto
 11.2433 -        also have "Real p \<le> Real p + (INF i. f i)" by auto
 11.2434 -        finally show ?thesis .
 11.2435 -      qed
 11.2436 -    qed
 11.2437 -  qed simp
 11.2438 -qed
 11.2439 -
 11.2440 -lemma pinfreal_le_minus_imp_0:
 11.2441 -  fixes a b :: pinfreal
 11.2442 -  shows "a \<le> a - b \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> a \<noteq> \<omega> \<Longrightarrow> b = 0"
 11.2443 -  by (cases a, cases b, auto split: split_if_asm)
 11.2444 -
 11.2445 -lemma lim_INF_eq_lim_SUP:
 11.2446 -  fixes X :: "nat \<Rightarrow> real"
 11.2447 -  assumes "\<And>i. 0 \<le> X i" and "0 \<le> x"
 11.2448 -  and lim_INF: "(SUP n. INF m. Real (X (n + m))) = Real x" (is "(SUP n. ?INF n) = _")
 11.2449 -  and lim_SUP: "(INF n. SUP m. Real (X (n + m))) = Real x" (is "(INF n. ?SUP n) = _")
 11.2450 -  shows "X ----> x"
 11.2451 -proof (rule LIMSEQ_I)
 11.2452 -  fix r :: real assume "0 < r"
 11.2453 -  hence "0 \<le> r" by auto
 11.2454 -  from Sup_close[of "Real r" "range ?INF"]
 11.2455 -  obtain n where inf: "Real x < ?INF n + Real r"
 11.2456 -    unfolding SUPR_def lim_INF[unfolded SUPR_def] using `0 < r` by auto
 11.2457 -
 11.2458 -  from Inf_close[of "range ?SUP" "Real r"]
 11.2459 -  obtain n' where sup: "?SUP n' < Real x + Real r"
 11.2460 -    unfolding INFI_def lim_SUP[unfolded INFI_def] using `0 < r` by auto
 11.2461 -
 11.2462 -  show "\<exists>N. \<forall>n\<ge>N. norm (X n - x) < r"
 11.2463 -  proof (safe intro!: exI[of _ "max n n'"])
 11.2464 -    fix m assume "max n n' \<le> m" hence "n \<le> m" "n' \<le> m" by auto
 11.2465 -
 11.2466 -    note inf
 11.2467 -    also have "?INF n + Real r \<le> Real (X (n + (m - n))) + Real r"
 11.2468 -      by (rule le_add_Real, auto simp: `0 \<le> r` intro: INF_leI)
 11.2469 -    finally have up: "x < X m + r"
 11.2470 -      using `0 \<le> X m` `0 \<le> x` `0 \<le> r` `n \<le> m` by auto
 11.2471 -
 11.2472 -    have "Real (X (n' + (m - n'))) \<le> ?SUP n'"
 11.2473 -      by (auto simp: `0 \<le> r` intro: le_SUPI)
 11.2474 -    also note sup
 11.2475 -    finally have down: "X m < x + r"
 11.2476 -      using `0 \<le> X m` `0 \<le> x` `0 \<le> r` `n' \<le> m` by auto
 11.2477 -
 11.2478 -    show "norm (X m - x) < r" using up down by auto
 11.2479 -  qed
 11.2480 -qed
 11.2481 -
 11.2482 -lemma Sup_countable_SUPR:
 11.2483 -  assumes "Sup A \<noteq> \<omega>" "A \<noteq> {}"
 11.2484 -  shows "\<exists> f::nat \<Rightarrow> pinfreal. range f \<subseteq> A \<and> Sup A = SUPR UNIV f"
 11.2485 -proof -
 11.2486 -  have "\<And>n. 0 < 1 / (of_nat n :: pinfreal)" by auto
 11.2487 -  from Sup_close[OF this assms]
 11.2488 -  have "\<forall>n. \<exists>x. x \<in> A \<and> Sup A < x + 1 / of_nat n" by blast
 11.2489 -  from choice[OF this] obtain f where "range f \<subseteq> A" and
 11.2490 -    epsilon: "\<And>n. Sup A < f n + 1 / of_nat n" by blast
 11.2491 -  have "SUPR UNIV f = Sup A"
 11.2492 -  proof (rule pinfreal_SUPI)
 11.2493 -    fix i show "f i \<le> Sup A" using `range f \<subseteq> A`
 11.2494 -      by (auto intro!: complete_lattice_class.Sup_upper)
 11.2495 -  next
 11.2496 -    fix y assume bound: "\<And>i. i \<in> UNIV \<Longrightarrow> f i \<le> y"
 11.2497 -    show "Sup A \<le> y"
 11.2498 -    proof (rule pinfreal_le_epsilon)
 11.2499 -      fix e :: pinfreal assume "0 < e"
 11.2500 -      show "Sup A \<le> y + e"
 11.2501 -      proof (cases e)
 11.2502 -        case (preal r)
 11.2503 -        hence "0 < r" using `0 < e` by auto
 11.2504 -        then obtain n where *: "inverse (of_nat n) < r" "0 < n"
 11.2505 -          using ex_inverse_of_nat_less by auto
 11.2506 -        have "Sup A \<le> f n + 1 / of_nat n" using epsilon[of n] by auto
 11.2507 -        also have "1 / of_nat n \<le> e" using preal * by (auto simp: real_eq_of_nat)
 11.2508 -        with bound have "f n + 1 / of_nat n \<le> y + e" by (rule add_mono) simp
 11.2509 -        finally show "Sup A \<le> y + e" .
 11.2510 -      qed simp
 11.2511 -    qed
 11.2512 -  qed
 11.2513 -  with `range f \<subseteq> A` show ?thesis by (auto intro!: exI[of _ f])
 11.2514 -qed
 11.2515 -
 11.2516 -lemma SUPR_countable_SUPR:
 11.2517 -  assumes "SUPR A g \<noteq> \<omega>" "A \<noteq> {}"
 11.2518 -  shows "\<exists> f::nat \<Rightarrow> pinfreal. range f \<subseteq> g`A \<and> SUPR A g = SUPR UNIV f"
 11.2519 -proof -
 11.2520 -  have "Sup (g`A) \<noteq> \<omega>" "g`A \<noteq> {}" using assms unfolding SUPR_def by auto
 11.2521 -  from Sup_countable_SUPR[OF this]
 11.2522 -  show ?thesis unfolding SUPR_def .
 11.2523 -qed
 11.2524 -
 11.2525 -lemma pinfreal_setsum_subtractf:
 11.2526 -  assumes "\<And>i. i\<in>A \<Longrightarrow> g i \<le> f i" and "\<And>i. i\<in>A \<Longrightarrow> f i \<noteq> \<omega>"
 11.2527 -  shows "(\<Sum>i\<in>A. f i - g i) = (\<Sum>i\<in>A. f i) - (\<Sum>i\<in>A. g i)"
 11.2528 -proof cases
 11.2529 -  assume "finite A" from this assms show ?thesis
 11.2530 -  proof induct
 11.2531 -    case (insert x A)
 11.2532 -    hence hyp: "(\<Sum>i\<in>A. f i - g i) = (\<Sum>i\<in>A. f i) - (\<Sum>i\<in>A. g i)"
 11.2533 -      by auto
 11.2534 -    { fix i assume *: "i \<in> insert x A"
 11.2535 -      hence "g i \<le> f i" using insert by simp
 11.2536 -      also have "f i < \<omega>" using * insert by (simp add: pinfreal_less_\<omega>)
 11.2537 -      finally have "g i \<noteq> \<omega>" by (simp add: pinfreal_less_\<omega>) }
 11.2538 -    hence "setsum g A \<noteq> \<omega>" "g x \<noteq> \<omega>" by (auto simp: setsum_\<omega>)
 11.2539 -    moreover have "setsum f A \<noteq> \<omega>" "f x \<noteq> \<omega>" using insert by (auto simp: setsum_\<omega>)
 11.2540 -    moreover have "g x \<le> f x" using insert by auto
 11.2541 -    moreover have "(\<Sum>i\<in>A. g i) \<le> (\<Sum>i\<in>A. f i)" using insert by (auto intro!: setsum_mono)
 11.2542 -    ultimately show ?case using `finite A` `x \<notin> A` hyp
 11.2543 -      by (auto simp: pinfreal_noteq_omega_Ex)
 11.2544 -  qed simp
 11.2545 -qed simp
 11.2546 -
 11.2547 -lemma real_of_pinfreal_diff:
 11.2548 -  "y \<le> x \<Longrightarrow> x \<noteq> \<omega> \<Longrightarrow> real x - real y = real (x - y)"
 11.2549 -  by (cases x, cases y) auto
 11.2550 -
 11.2551 -lemma psuminf_minus:
 11.2552 -  assumes ord: "\<And>i. g i \<le> f i" and fin: "psuminf g \<noteq> \<omega>" "psuminf f \<noteq> \<omega>"
 11.2553 -  shows "(\<Sum>\<^isub>\<infinity> i. f i - g i) = psuminf f - psuminf g"
 11.2554 -proof -
 11.2555 -  have [simp]: "\<And>i. f i \<noteq> \<omega>" using fin by (auto intro: psuminf_\<omega>)
 11.2556 -  from fin have "(\<lambda>x. real (f x)) sums real (\<Sum>\<^isub>\<infinity>x. f x)"
 11.2557 -    and "(\<lambda>x. real (g x)) sums real (\<Sum>\<^isub>\<infinity>x. g x)"
 11.2558 -    by (auto intro: psuminf_imp_suminf)
 11.2559 -  from sums_diff[OF this]
 11.2560 -  have "(\<lambda>n. real (f n - g n)) sums (real ((\<Sum>\<^isub>\<infinity>x. f x) - (\<Sum>\<^isub>\<infinity>x. g x)))" using fin ord
 11.2561 -    by (subst (asm) (1 2) real_of_pinfreal_diff) (auto simp: psuminf_\<omega> psuminf_le)
 11.2562 -  hence "(\<Sum>\<^isub>\<infinity> i. Real (real (f i - g i))) = Real (real ((\<Sum>\<^isub>\<infinity>x. f x) - (\<Sum>\<^isub>\<infinity>x. g x)))"
 11.2563 -    by (rule suminf_imp_psuminf) simp
 11.2564 -  thus ?thesis using fin by (simp add: Real_real psuminf_\<omega>)
 11.2565 -qed
 11.2566 -
 11.2567 -lemma INF_eq_LIMSEQ:
 11.2568 -  assumes "mono (\<lambda>i. - f i)" and "\<And>n. 0 \<le> f n" and "0 \<le> x"
 11.2569 -  shows "(INF n. Real (f n)) = Real x \<longleftrightarrow> f ----> x"
 11.2570 -proof
 11.2571 -  assume x: "(INF n. Real (f n)) = Real x"
 11.2572 -  { fix n
 11.2573 -    have "Real x \<le> Real (f n)" using x[symmetric] by (auto intro: INF_leI)
 11.2574 -    hence "x \<le> f n" using assms by simp
 11.2575 -    hence "\<bar>f n - x\<bar> = f n - x" by auto }
 11.2576 -  note abs_eq = this
 11.2577 -  show "f ----> x"
 11.2578 -  proof (rule LIMSEQ_I)
 11.2579 -    fix r :: real assume "0 < r"
 11.2580 -    show "\<exists>no. \<forall>n\<ge>no. norm (f n - x) < r"
 11.2581 -    proof (rule ccontr)
 11.2582 -      assume *: "\<not> ?thesis"
 11.2583 -      { fix N
 11.2584 -        from * obtain n where *: "N \<le> n" "r \<le> f n - x"
 11.2585 -          using abs_eq by (auto simp: not_less)
 11.2586 -        hence "x + r \<le> f n" by auto
 11.2587 -        also have "f n \<le> f N" using `mono (\<lambda>i. - f i)` * by (auto dest: monoD)
 11.2588 -        finally have "Real (x + r) \<le> Real (f N)" using `0 \<le> f N` by auto }
 11.2589 -      hence "Real x < Real (x + r)"
 11.2590 -        and "Real (x + r) \<le> (INF n. Real (f n))" using `0 < r` `0 \<le> x` by (auto intro: le_INFI)
 11.2591 -      hence "Real x < (INF n. Real (f n))" by (rule less_le_trans)
 11.2592 -      thus False using x by auto
 11.2593 -    qed
 11.2594 -  qed
 11.2595 -next
 11.2596 -  assume "f ----> x"
 11.2597 -  show "(INF n. Real (f n)) = Real x"
 11.2598 -  proof (rule pinfreal_INFI)
 11.2599 -    fix n
 11.2600 -    from decseq_le[OF _ `f ----> x`] assms
 11.2601 -    show "Real x \<le> Real (f n)" unfolding decseq_eq_incseq incseq_mono by auto
 11.2602 -  next
 11.2603 -    fix y assume *: "\<And>n. n\<in>UNIV \<Longrightarrow> y \<le> Real (f n)"
 11.2604 -    thus "y \<le> Real x"
 11.2605 -    proof (cases y)
 11.2606 -      case (preal r)
 11.2607 -      with * have "\<exists>N. \<forall>n\<ge>N. r \<le> f n" using assms by fastsimp
 11.2608 -      from LIMSEQ_le_const[OF `f ----> x` this]
 11.2609 -      show "y \<le> Real x" using `0 \<le> x` preal by auto
 11.2610 -    qed simp
 11.2611 -  qed
 11.2612 -qed
 11.2613 -
 11.2614 -lemma INFI_bound:
 11.2615 -  assumes "\<forall>N. x \<le> f N"
 11.2616 -  shows "x \<le> (INF n. f n)"
 11.2617 -  using assms by (simp add: INFI_def le_Inf_iff)
 11.2618 -
 11.2619 -lemma LIMSEQ_imp_lim_INF:
 11.2620 -  assumes pos: "\<And>i. 0 \<le> X i" and lim: "X ----> x"
 11.2621 -  shows "(SUP n. INF m. Real (X (n + m))) = Real x"
 11.2622 -proof -
 11.2623 -  have "0 \<le> x" using assms by (auto intro!: LIMSEQ_le_const)
 11.2624 -
 11.2625 -  have "\<And>n. (INF m. Real (X (n + m))) \<le> Real (X (n + 0))" by (rule INF_leI) simp
 11.2626 -  also have "\<And>n. Real (X (n + 0)) < \<omega>" by simp
 11.2627 -  finally have "\<forall>n. \<exists>r\<ge>0. (INF m. Real (X (n + m))) = Real r"
 11.2628 -    by (auto simp: pinfreal_less_\<omega> pinfreal_noteq_omega_Ex)
 11.2629 -  from choice[OF this] obtain r where r: "\<And>n. (INF m. Real (X (n + m))) = Real (r n)" "\<And>n. 0 \<le> r n"
 11.2630 -    by auto
 11.2631 -
 11.2632 -  show ?thesis unfolding r
 11.2633 -  proof (subst SUP_eq_LIMSEQ)
 11.2634 -    show "mono r" unfolding mono_def
 11.2635 -    proof safe
 11.2636 -      fix x y :: nat assume "x \<le> y"
 11.2637 -      have "Real (r x) \<le> Real (r y)" unfolding r(1)[symmetric] using pos
 11.2638 -      proof (safe intro!: INF_mono bexI)
 11.2639 -        fix m have "x + (m + y - x) = y + m"
 11.2640 -          using `x \<le> y` by auto
 11.2641 -        thus "Real (X (x + (m + y - x))) \<le> Real (X (y + m))" by simp
 11.2642 -      qed simp
 11.2643 -      thus "r x \<le> r y" using r by auto
 11.2644 -    qed
 11.2645 -    show "\<And>n. 0 \<le> r n" by fact
 11.2646 -    show "0 \<le> x" by fact
 11.2647 -    show "r ----> x"
 11.2648 -    proof (rule LIMSEQ_I)
 11.2649 -      fix e :: real assume "0 < e"
 11.2650 -      hence "0 < e/2" by auto
 11.2651 -      from LIMSEQ_D[OF lim this] obtain N where *: "\<And>n. N \<le> n \<Longrightarrow> \<bar>X n - x\<bar> < e/2"
 11.2652 -        by auto
 11.2653 -      show "\<exists>N. \<forall>n\<ge>N. norm (r n - x) < e"
 11.2654 -      proof (safe intro!: exI[of _ N])
 11.2655 -        fix n assume "N \<le> n"
 11.2656 -        show "norm (r n - x) < e"
 11.2657 -        proof cases
 11.2658 -          assume "r n < x"
 11.2659 -          have "x - r n \<le> e/2"
 11.2660 -          proof cases
 11.2661 -            assume e: "e/2 \<le> x"
 11.2662 -            have "Real (x - e/2) \<le> Real (r n)" unfolding r(1)[symmetric]
 11.2663 -            proof (rule le_INFI)
 11.2664 -              fix m show "Real (x - e / 2) \<le> Real (X (n + m))"
 11.2665 -                using *[of "n + m"] `N \<le> n`
 11.2666 -                using pos by (auto simp: field_simps abs_real_def split: split_if_asm)
 11.2667 -            qed
 11.2668 -            with e show ?thesis using pos `0 \<le> x` r(2) by auto
 11.2669 -          next
 11.2670 -            assume "\<not> e/2 \<le> x" hence "x - e/2 < 0" by auto
 11.2671 -            with `0 \<le> r n` show ?thesis by auto
 11.2672 -          qed
 11.2673 -          with `r n < x` show ?thesis by simp
 11.2674 -        next
 11.2675 -          assume e: "\<not> r n < x"
 11.2676 -          have "Real (r n) \<le> Real (X (n + 0))" unfolding r(1)[symmetric]
 11.2677 -            by (rule INF_leI) simp
 11.2678 -          hence "r n - x \<le> X n - x" using r pos by auto
 11.2679 -          also have "\<dots> < e/2" using *[OF `N \<le> n`] by (auto simp: field_simps abs_real_def split: split_if_asm)
 11.2680 -          finally have "r n - x < e" using `0 < e` by auto
 11.2681 -          with e show ?thesis by auto
 11.2682 -        qed
 11.2683 -      qed
 11.2684 -    qed
 11.2685 -  qed
 11.2686 -qed
 11.2687 -
 11.2688 -lemma real_of_pinfreal_strict_mono_iff:
 11.2689 -  "real a < real b \<longleftrightarrow> (b \<noteq> \<omega> \<and> ((a = \<omega> \<and> 0 < b) \<or> (a < b)))"
 11.2690 -proof (cases a)
 11.2691 -  case infinite thus ?thesis by (cases b) auto
 11.2692 -next
 11.2693 -  case preal thus ?thesis by (cases b) auto
 11.2694 -qed
 11.2695 -
 11.2696 -lemma real_of_pinfreal_mono_iff:
 11.2697 -  "real a \<le> real b \<longleftrightarrow> (a = \<omega> \<or> (b \<noteq> \<omega> \<and> a \<le> b) \<or> (b = \<omega> \<and> a = 0))"
 11.2698 -proof (cases a)
 11.2699 -  case infinite thus ?thesis by (cases b) auto
 11.2700 -next
 11.2701 -  case preal thus ?thesis by (cases b)  auto
 11.2702 -qed
 11.2703 -
 11.2704 -lemma ex_pinfreal_inverse_of_nat_Suc_less:
 11.2705 -  fixes e :: pinfreal assumes "0 < e" shows "\<exists>n. inverse (of_nat (Suc n)) < e"
 11.2706 -proof (cases e)
 11.2707 -  case (preal r)
 11.2708 -  with `0 < e` ex_inverse_of_nat_Suc_less[of r]
 11.2709 -  obtain n where "inverse (of_nat (Suc n)) < r" by auto
 11.2710 -  with preal show ?thesis
 11.2711 -    by (auto simp: real_eq_of_nat[symmetric])
 11.2712 -qed auto
 11.2713 -
 11.2714 -lemma Lim_eq_Sup_mono:
 11.2715 -  fixes u :: "nat \<Rightarrow> pinfreal" assumes "mono u"
 11.2716 -  shows "u ----> (SUP i. u i)"
 11.2717 -proof -
 11.2718 -  from lim_pinfreal_increasing[of u] `mono u`
 11.2719 -  obtain l where l: "u ----> l" unfolding mono_def by auto
 11.2720 -  from SUP_Lim_pinfreal[OF _ this] `mono u`
 11.2721 -  have "(SUP i. u i) = l" unfolding mono_def by auto
 11.2722 -  with l show ?thesis by simp
 11.2723 -qed
 11.2724 -
 11.2725 -lemma isotone_Lim:
 11.2726 -  fixes x :: pinfreal assumes "u \<up> x"
 11.2727 -  shows "u ----> x" (is ?lim) and "mono u" (is ?mono)
 11.2728 -proof -
 11.2729 -  show ?mono using assms unfolding mono_iff_le_Suc isoton_def by auto
 11.2730 -  from Lim_eq_Sup_mono[OF this] `u \<up> x`
 11.2731 -  show ?lim unfolding isoton_def by simp
 11.2732 -qed
 11.2733 -
 11.2734 -lemma isoton_iff_Lim_mono:
 11.2735 -  fixes u :: "nat \<Rightarrow> pinfreal"
 11.2736 -  shows "u \<up> x \<longleftrightarrow> (mono u \<and> u ----> x)"
 11.2737 -proof safe
 11.2738 -  assume "mono u" and x: "u ----> x"
 11.2739 -  with SUP_Lim_pinfreal[OF _ x]
 11.2740 -  show "u \<up> x" unfolding isoton_def
 11.2741 -    using `mono u`[unfolded mono_def]
 11.2742 -    using `mono u`[unfolded mono_iff_le_Suc]
 11.2743 -    by auto
 11.2744 -qed (auto dest: isotone_Lim)
 11.2745 -
 11.2746 -lemma pinfreal_inverse_inverse[simp]:
 11.2747 -  fixes x :: pinfreal
 11.2748 -  shows "inverse (inverse x) = x"
 11.2749 -  by (cases x) auto
 11.2750 -
 11.2751 -lemma atLeastAtMost_omega_eq_atLeast:
 11.2752 -  shows "{a .. \<omega>} = {a ..}"
 11.2753 -by auto
 11.2754 -
 11.2755 -lemma atLeast0AtMost_eq_atMost: "{0 :: pinfreal .. a} = {.. a}" by auto
 11.2756 -
 11.2757 -lemma greaterThan_omega_Empty: "{\<omega> <..} = {}" by auto
 11.2758 -
 11.2759 -lemma lessThan_0_Empty: "{..< 0 :: pinfreal} = {}" by auto
 11.2760 -
 11.2761 -lemma real_of_pinfreal_inverse[simp]:
 11.2762 -  fixes X :: pinfreal
 11.2763 -  shows "real (inverse X) = 1 / real X"
 11.2764 -  by (cases X) (auto simp: inverse_eq_divide)
 11.2765 -
 11.2766 -lemma real_of_pinfreal_le_0[simp]: "real (X :: pinfreal) \<le> 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
 11.2767 -  by (cases X) auto
 11.2768 -
 11.2769 -lemma real_of_pinfreal_less_0[simp]: "\<not> (real (X :: pinfreal) < 0)"
 11.2770 -  by (cases X) auto
 11.2771 -
 11.2772 -lemma abs_real_of_pinfreal[simp]: "\<bar>real (X :: pinfreal)\<bar> = real X"
 11.2773 -  by simp
 11.2774 -
 11.2775 -lemma zero_less_real_of_pinfreal: "0 < real (X :: pinfreal) \<longleftrightarrow> X \<noteq> 0 \<and> X \<noteq> \<omega>"
 11.2776 -  by (cases X) auto
 11.2777 -
 11.2778 -end
    12.1 --- a/src/HOL/Probability/Probability_Space.thy	Mon Dec 06 19:18:02 2010 +0100
    12.2 +++ b/src/HOL/Probability/Probability_Space.thy	Fri Dec 03 15:25:14 2010 +0100
    12.3 @@ -2,24 +2,24 @@
    12.4  imports Lebesgue_Integration Radon_Nikodym Product_Measure
    12.5  begin
    12.6  
    12.7 -lemma real_of_pinfreal_inverse[simp]:
    12.8 -  fixes X :: pinfreal
    12.9 +lemma real_of_pextreal_inverse[simp]:
   12.10 +  fixes X :: pextreal
   12.11    shows "real (inverse X) = 1 / real X"
   12.12    by (cases X) (auto simp: inverse_eq_divide)
   12.13  
   12.14 -lemma real_of_pinfreal_le_0[simp]: "real (X :: pinfreal) \<le> 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
   12.15 +lemma real_of_pextreal_le_0[simp]: "real (X :: pextreal) \<le> 0 \<longleftrightarrow> (X = 0 \<or> X = \<omega>)"
   12.16    by (cases X) auto
   12.17  
   12.18 -lemma real_of_pinfreal_less_0[simp]: "\<not> (real (X :: pinfreal) < 0)"
   12.19 +lemma real_of_pextreal_less_0[simp]: "\<not> (real (X :: pextreal) < 0)"
   12.20    by (cases X) auto
   12.21  
   12.22  locale prob_space = measure_space +
   12.23    assumes measure_space_1: "\<mu> (space M) = 1"
   12.24  
   12.25 -lemma abs_real_of_pinfreal[simp]: "\<bar>real (X :: pinfreal)\<bar> = real X"
   12.26 +lemma abs_real_of_pextreal[simp]: "\<bar>real (X :: pextreal)\<bar> = real X"
   12.27    by simp
   12.28  
   12.29 -lemma zero_less_real_of_pinfreal: "0 < real (X :: pinfreal) \<longleftrightarrow> X \<noteq> 0 \<and> X \<noteq> \<omega>"
   12.30 +lemma zero_less_real_of_pextreal: "0 < real (X :: pextreal) \<longleftrightarrow> X \<noteq> 0 \<and> X \<noteq> \<omega>"
   12.31    by (cases X) auto
   12.32  
   12.33  sublocale prob_space < finite_measure
   12.34 @@ -141,7 +141,7 @@
   12.35    show "prob (\<Union> i :: nat. c i) \<le> 0"
   12.36      using real_finite_measure_countably_subadditive[OF assms(1)]
   12.37      by (simp add: assms(2) suminf_zero summable_zero)
   12.38 -  show "0 \<le> prob (\<Union> i :: nat. c i)" by (rule real_pinfreal_nonneg)
   12.39 +  show "0 \<le> prob (\<Union> i :: nat. c i)" by (rule real_pextreal_nonneg)
   12.40  qed
   12.41  
   12.42  lemma (in prob_space) indep_sym:
   12.43 @@ -606,7 +606,7 @@
   12.44    show ?thesis
   12.45      unfolding setsum_joint_distribution[OF assms, symmetric]
   12.46      using distribution_finite[OF random_variable_pairI[OF finite_random_variableD[OF X] Y(1)]] Y(2)
   12.47 -    by (simp add: space_pair_algebra in_sigma pair_algebraI MX.sets_eq_Pow real_of_pinfreal_setsum)
   12.48 +    by (simp add: space_pair_algebra in_sigma pair_algebraI MX.sets_eq_Pow real_of_pextreal_setsum)
   12.49  qed
   12.50  
   12.51  lemma (in prob_space) setsum_real_joint_distribution_singleton:
   12.52 @@ -721,7 +721,7 @@
   12.53  
   12.54  lemma (in finite_prob_space) finite_sum_over_space_eq_1:
   12.55    "(\<Sum>x\<in>space M. real (\<mu> {x})) = 1"
   12.56 -  using sum_over_space_eq_1 finite_measure by (simp add: real_of_pinfreal_setsum sets_eq_Pow)
   12.57 +  using sum_over_space_eq_1 finite_measure by (simp add: real_of_pextreal_setsum sets_eq_Pow)
   12.58  
   12.59  lemma (in finite_prob_space) distribution_finite:
   12.60    "distribution X A \<noteq> \<omega>"
   12.61 @@ -730,27 +730,27 @@
   12.62  
   12.63  lemma (in finite_prob_space) real_distribution_gt_0[simp]:
   12.64    "0 < real (distribution Y y) \<longleftrightarrow>  0 < distribution Y y"
   12.65 -  using assms by (auto intro!: real_pinfreal_pos distribution_finite)
   12.66 +  using assms by (auto intro!: real_pextreal_pos distribution_finite)
   12.67  
   12.68  lemma (in finite_prob_space) real_distribution_mult_pos_pos:
   12.69    assumes "0 < distribution Y y"
   12.70    and "0 < distribution X x"
   12.71    shows "0 < real (distribution Y y * distribution X x)"
   12.72 -  unfolding real_of_pinfreal_mult[symmetric]
   12.73 +  unfolding real_of_pextreal_mult[symmetric]
   12.74    using assms by (auto intro!: mult_pos_pos)
   12.75  
   12.76  lemma (in finite_prob_space) real_distribution_divide_pos_pos:
   12.77    assumes "0 < distribution Y y"
   12.78    and "0 < distribution X x"
   12.79    shows "0 < real (distribution Y y / distribution X x)"
   12.80 -  unfolding divide_pinfreal_def real_of_pinfreal_mult[symmetric]
   12.81 +  unfolding divide_pextreal_def real_of_pextreal_mult[symmetric]
   12.82    using assms distribution_finite[of X x] by (cases "distribution X x") (auto intro!: mult_pos_pos)
   12.83  
   12.84  lemma (in finite_prob_space) real_distribution_mult_inverse_pos_pos:
   12.85    assumes "0 < distribution Y y"
   12.86    and "0 < distribution X x"
   12.87    shows "0 < real (distribution Y y * inverse (distribution X x))"
   12.88 -  unfolding divide_pinfreal_def real_of_pinfreal_mult[symmetric]
   12.89 +  unfolding divide_pextreal_def real_of_pextreal_mult[symmetric]
   12.90    using assms distribution_finite[of X x] by (cases "distribution X x") (auto intro!: mult_pos_pos)
   12.91  
   12.92  lemma (in prob_space) distribution_remove_const:
   12.93 @@ -805,9 +805,9 @@
   12.94    and "r < real (joint_distribution X Y {(x, y)}) \<Longrightarrow> r < real (distribution Y {y})"
   12.95    and "distribution X {x} = 0 \<Longrightarrow> real (joint_distribution X Y {(x, y)}) = 0"
   12.96    and "distribution Y {y} = 0 \<Longrightarrow> real (joint_distribution X Y {(x, y)}) = 0"
   12.97 -  using real_of_pinfreal_mono[OF distribution_finite joint_distribution_restriction_fst, of X Y "{(x, y)}"]
   12.98 -  using real_of_pinfreal_mono[OF distribution_finite joint_distribution_restriction_snd, of X Y "{(x, y)}"]
   12.99 -  using real_pinfreal_nonneg[of "joint_distribution X Y {(x, y)}"]
  12.100 +  using real_of_pextreal_mono[OF distribution_finite joint_distribution_restriction_fst, of X Y "{(x, y)}"]
  12.101 +  using real_of_pextreal_mono[OF distribution_finite joint_distribution_restriction_snd, of X Y "{(x, y)}"]
  12.102 +  using real_pextreal_nonneg[of "joint_distribution X Y {(x, y)}"]
  12.103    by auto
  12.104  
  12.105  lemma (in prob_space) joint_distribution_remove[simp]:
  12.106 @@ -821,8 +821,8 @@
  12.107  
  12.108  lemma (in finite_prob_space) real_distribution_1:
  12.109    "real (distribution X A) \<le> 1"
  12.110 -  unfolding real_pinfreal_1[symmetric]
  12.111 -  by (rule real_of_pinfreal_mono[OF _ distribution_1]) simp
  12.112 +  unfolding real_pextreal_1[symmetric]
  12.113 +  by (rule real_of_pextreal_mono[OF _ distribution_1]) simp
  12.114  
  12.115  lemma (in finite_prob_space) uniform_prob:
  12.116    assumes "x \<in> space M"
  12.117 @@ -865,7 +865,7 @@
  12.118    unfolding prob_space_def prob_space_axioms_def
  12.119  proof
  12.120    show "\<mu> (space (restricted_space A)) / \<mu> A = 1"
  12.121 -    using `\<mu> A \<noteq> 0` `\<mu> A \<noteq> \<omega>` by (auto simp: pinfreal_noteq_omega_Ex)
  12.122 +    using `\<mu> A \<noteq> 0` `\<mu> A \<noteq> \<omega>` by (auto simp: pextreal_noteq_omega_Ex)
  12.123    have *: "\<And>S. \<mu> S / \<mu> A = inverse (\<mu> A) * \<mu> S" by (simp add: mult_commute)
  12.124    interpret A: measure_space "restricted_space A" \<mu>
  12.125      using `A \<in> sets M` by (rule restricted_measure_space)
  12.126 @@ -910,9 +910,9 @@
  12.127  lemma (in finite_prob_space) real_distribution_order':
  12.128    shows "real (distribution X {x}) = 0 \<Longrightarrow> real (joint_distribution X Y {(x, y)}) = 0"
  12.129    and "real (distribution Y {y}) = 0 \<Longrightarrow> real (joint_distribution X Y {(x, y)}) = 0"
  12.130 -  using real_of_pinfreal_mono[OF distribution_finite joint_distribution_restriction_fst, of X Y "{(x, y)}"]
  12.131 -  using real_of_pinfreal_mono[OF distribution_finite joint_distribution_restriction_snd, of X Y "{(x, y)}"]
  12.132 -  using real_pinfreal_nonneg[of "joint_distribution X Y {(x, y)}"]
  12.133 +  using real_of_pextreal_mono[OF distribution_finite joint_distribution_restriction_fst, of X Y "{(x, y)}"]
  12.134 +  using real_of_pextreal_mono[OF distribution_finite joint_distribution_restriction_snd, of X Y "{(x, y)}"]
  12.135 +  using real_pextreal_nonneg[of "joint_distribution X Y {(x, y)}"]
  12.136    by auto
  12.137  
  12.138  lemma (in finite_prob_space) finite_product_measure_space:
  12.139 @@ -952,7 +952,7 @@
  12.140  section "Conditional Expectation and Probability"
  12.141  
  12.142  lemma (in prob_space) conditional_expectation_exists:
  12.143 -  fixes X :: "'a \<Rightarrow> pinfreal"
  12.144 +  fixes X :: "'a \<Rightarrow> pextreal"
  12.145    assumes borel: "X \<in> borel_measurable M"
  12.146    and N_subalgebra: "N \<subseteq> sets M" "sigma_algebra (M\<lparr> sets := N \<rparr>)"
  12.147    shows "\<exists>Y\<in>borel_measurable (M\<lparr> sets := N \<rparr>). \<forall>C\<in>N.
  12.148 @@ -999,7 +999,7 @@
  12.149    "conditional_prob N A \<equiv> conditional_expectation N (indicator A)"
  12.150  
  12.151  lemma (in prob_space)
  12.152 -  fixes X :: "'a \<Rightarrow> pinfreal"
  12.153 +  fixes X :: "'a \<Rightarrow> pextreal"
  12.154    assumes borel: "X \<in> borel_measurable M"
  12.155    and N_subalgebra: "N \<subseteq> sets M" "sigma_algebra (M\<lparr> sets := N \<rparr>)"
  12.156    shows borel_measurable_conditional_expectation:
  12.157 @@ -1018,7 +1018,7 @@
  12.158  qed
  12.159  
  12.160  lemma (in sigma_algebra) factorize_measurable_function:
  12.161 -  fixes Z :: "'a \<Rightarrow> pinfreal" and Y :: "'a \<Rightarrow> 'c"
  12.162 +  fixes Z :: "'a \<Rightarrow> pextreal" and Y :: "'a \<Rightarrow> 'c"
  12.163    assumes "sigma_algebra M'" and "Y \<in> measurable M M'" "Z \<in> borel_measurable M"
  12.164    shows "Z \<in> borel_measurable (sigma_algebra.vimage_algebra M' (space M) Y)
  12.165      \<longleftrightarrow> (\<exists>g\<in>borel_measurable M'. \<forall>x\<in>space M. Z x = g (Y x))"
  12.166 @@ -1028,7 +1028,7 @@
  12.167    from M'.sigma_algebra_vimage[OF this]
  12.168    interpret va: sigma_algebra "M'.vimage_algebra (space M) Y" .
  12.169  
  12.170 -  { fix g :: "'c \<Rightarrow> pinfreal" assume "g \<in> borel_measurable M'"
  12.171 +  { fix g :: "'c \<Rightarrow> pextreal" assume "g \<in> borel_measurable M'"
  12.172      with M'.measurable_vimage_algebra[OF Y]
  12.173      have "g \<circ> Y \<in> borel_measurable (M'.vimage_algebra (space M) Y)"
  12.174        by (rule measurable_comp)
  12.175 @@ -1058,7 +1058,7 @@
  12.176        show "M'.simple_function ?g" using B by auto
  12.177  
  12.178        fix x assume "x \<in> space M"
  12.179 -      then have "\<And>z. z \<in> f i`space M \<Longrightarrow> indicator (B z) (Y x) = (indicator (f i -` {z} \<inter> space M) x::pinfreal)"
  12.180 +      then have "\<And>z. z \<in> f i`space M \<Longrightarrow> indicator (B z) (Y x) = (indicator (f i -` {z} \<inter> space M) x::pextreal)"
  12.181          unfolding indicator_def using B by auto
  12.182        then show "f i x = ?g (Y x)" using `x \<in> space M` f[of i]
  12.183          by (subst va.simple_function_indicator_representation) auto
    13.1 --- a/src/HOL/Probability/Product_Measure.thy	Mon Dec 06 19:18:02 2010 +0100
    13.2 +++ b/src/HOL/Probability/Product_Measure.thy	Fri Dec 03 15:25:14 2010 +0100
    13.3 @@ -379,7 +379,7 @@
    13.4        by (auto intro!: M2.finite_measure_compl measurable_cut_fst
    13.5                 simp: vimage_Diff)
    13.6      with `A \<in> sets ?D` top show "space ?D - A \<in> sets ?D"
    13.7 -      by (auto intro!: Diff M1.measurable_If M1.borel_measurable_pinfreal_diff)
    13.8 +      by (auto intro!: Diff M1.measurable_If M1.borel_measurable_pextreal_diff)
    13.9    next
   13.10      fix F :: "nat \<Rightarrow> ('a\<times>'b) set" assume "disjoint_family F" "range F \<subseteq> sets ?D"
   13.11      moreover then have "\<And>x. \<mu>2 (\<Union>i. Pair x -` F i) = (\<Sum>\<^isub>\<infinity> i. ?s (F i) x)"
   13.12 @@ -505,7 +505,7 @@
   13.13    unfolding pair_measure_def
   13.14  proof (rule M1.positive_integral_cong)
   13.15    fix x assume "x \<in> space M1"
   13.16 -  have *: "\<And>y. indicator A (x, y) = (indicator (Pair x -` A) y :: pinfreal)"
   13.17 +  have *: "\<And>y. indicator A (x, y) = (indicator (Pair x -` A) y :: pextreal)"
   13.18      unfolding indicator_def by auto
   13.19    show "M2.positive_integral (\<lambda>y. indicator A (x, y)) = \<mu>2 (Pair x -` A)"
   13.20      unfolding *
   13.21 @@ -703,7 +703,7 @@
   13.22      and "M1.positive_integral (\<lambda>x. M2.positive_integral (\<lambda>y. f (x, y)))
   13.23      = positive_integral f"
   13.24      by (auto simp del: vimage_Int cong: measurable_cong
   13.25 -             intro!: M1.borel_measurable_pinfreal_setsum
   13.26 +             intro!: M1.borel_measurable_pextreal_setsum
   13.27               simp add: M1.positive_integral_setsum simple_integral_def
   13.28                         M1.positive_integral_cmult
   13.29                         M1.positive_integral_cong[OF eq]
   13.30 @@ -805,7 +805,7 @@
   13.31      show "\<mu>1 {x\<in>space M1. \<mu>2 (Pair x -` N) \<noteq> 0} = 0"
   13.32        by (simp add: M1.positive_integral_0_iff pair_measure_alt vimage_def)
   13.33      show "{x \<in> space M1. \<mu>2 (Pair x -` N) \<noteq> 0} \<in> sets M1"
   13.34 -      by (intro M1.borel_measurable_pinfreal_neq_const measure_cut_measurable_fst N)
   13.35 +      by (intro M1.borel_measurable_pextreal_neq_const measure_cut_measurable_fst N)
   13.36      { fix x assume "x \<in> space M1" "\<mu>2 (Pair x -` N) = 0"
   13.37        have "M2.almost_everywhere (\<lambda>y. Q (x, y))"
   13.38        proof (rule M2.AE_I)
   13.39 @@ -1201,7 +1201,7 @@
   13.40  qed
   13.41  
   13.42  locale product_sigma_finite =
   13.43 -  fixes M :: "'i \<Rightarrow> 'a algebra" and \<mu> :: "'i \<Rightarrow> 'a set \<Rightarrow> pinfreal"
   13.44 +  fixes M :: "'i \<Rightarrow> 'a algebra" and \<mu> :: "'i \<Rightarrow> 'a set \<Rightarrow> pextreal"
   13.45    assumes sigma_finite_measures: "\<And>i. sigma_finite_measure (M i) (\<mu> i)"
   13.46  
   13.47  locale finite_product_sigma_finite = product_sigma_finite M \<mu> for M :: "'i \<Rightarrow> 'a algebra" and \<mu> +
   13.48 @@ -1319,7 +1319,7 @@
   13.49  qed
   13.50  
   13.51  definition (in finite_product_sigma_finite)
   13.52 -  measure :: "('i \<Rightarrow> 'a) set \<Rightarrow> pinfreal" where
   13.53 +  measure :: "('i \<Rightarrow> 'a) set \<Rightarrow> pextreal" where
   13.54    "measure = (SOME \<nu>.
   13.55       (\<forall>A\<in>\<Pi> i\<in>I. sets (M i). \<nu> (Pi\<^isub>E I A) = (\<Prod>i\<in>I. \<mu> i (A i))) \<and>
   13.56       sigma_finite_measure P \<nu>)"
    14.1 --- a/src/HOL/Probability/Radon_Nikodym.thy	Mon Dec 06 19:18:02 2010 +0100
    14.2 +++ b/src/HOL/Probability/Radon_Nikodym.thy	Fri Dec 03 15:25:14 2010 +0100
    14.3 @@ -29,10 +29,10 @@
    14.4      next
    14.5        assume not_0: "\<mu> (A i) \<noteq> 0"
    14.6        then have "?B i \<noteq> \<omega>" using measure[of i] by auto
    14.7 -      then have "inverse (?B i) \<noteq> 0" unfolding pinfreal_inverse_eq_0 by simp
    14.8 +      then have "inverse (?B i) \<noteq> 0" unfolding pextreal_inverse_eq_0 by simp
    14.9        then show ?thesis using measure[of i] not_0
   14.10          by (auto intro!: exI[of _ "inverse (?B i) / 2"]
   14.11 -                 simp: pinfreal_noteq_omega_Ex zero_le_mult_iff zero_less_mult_iff mult_le_0_iff power_le_zero_eq)
   14.12 +                 simp: pextreal_noteq_omega_Ex zero_le_mult_iff zero_less_mult_iff mult_le_0_iff power_le_zero_eq)
   14.13      qed
   14.14    qed
   14.15    from choice[OF this] obtain n where n: "\<And>i. 0 < n i"
   14.16 @@ -49,7 +49,7 @@
   14.17        fix N show "n N * \<mu> (A N) \<le> Real ((1 / 2) ^ Suc N)"
   14.18          using measure[of N] n[of N]
   14.19          by (cases "n N")
   14.20 -           (auto simp: pinfreal_noteq_omega_Ex field_simps zero_le_mult_iff
   14.21 +           (auto simp: pextreal_noteq_omega_Ex field_simps zero_le_mult_iff
   14.22                         mult_le_0_iff mult_less_0_iff power_less_zero_eq
   14.23                         power_le_zero_eq inverse_eq_divide less_divide_eq
   14.24                         power_divide split: split_if_asm)
   14.25 @@ -65,14 +65,14 @@
   14.26      then show "0 < ?h x" and "?h x < \<omega>" using n[of i] by auto
   14.27    next
   14.28      show "?h \<in> borel_measurable M" using range
   14.29 -      by (auto intro!: borel_measurable_psuminf borel_measurable_pinfreal_times)
   14.30 +      by (auto intro!: borel_measurable_psuminf borel_measurable_pextreal_times)
   14.31    qed
   14.32  qed
   14.33  
   14.34  subsection "Absolutely continuous"
   14.35  
   14.36  definition (in measure_space)
   14.37 -  "absolutely_continuous \<nu> = (\<forall>N\<in>null_sets. \<nu> N = (0 :: pinfreal))"
   14.38 +  "absolutely_continuous \<nu> = (\<forall>N\<in>null_sets. \<nu> N = (0 :: pextreal))"
   14.39  
   14.40  lemma (in sigma_finite_measure) absolutely_continuous_AE:
   14.41    assumes "measure_space M \<nu>" "absolutely_continuous \<nu>" "AE x. P x"
   14.42 @@ -409,9 +409,9 @@
   14.43        moreover {
   14.44          have "positive_integral (\<lambda>x. f x * indicator (\<Union>i. A i) x) \<le> \<nu> (\<Union>i. A i)"
   14.45            using A `f \<in> G` unfolding G_def by (auto simp: countable_UN)
   14.46 -        also have "\<nu> (\<Union>i. A i) < \<omega>" using v_fin by (simp add: pinfreal_less_\<omega>)
   14.47 +        also have "\<nu> (\<Union>i. A i) < \<omega>" using v_fin by (simp add: pextreal_less_\<omega>)
   14.48          finally have "positive_integral (\<lambda>x. f x * indicator (\<Union>i. A i) x) \<noteq> \<omega>"
   14.49 -          by (simp add: pinfreal_less_\<omega>) }
   14.50 +          by (simp add: pextreal_less_\<omega>) }
   14.51        ultimately
   14.52        show "(\<Sum>\<^isub>\<infinity> n. ?t (A n)) = ?t (\<Union>i. A i)"
   14.53          apply (subst psuminf_minus) by simp_all
   14.54 @@ -440,7 +440,7 @@
   14.55      def b \<equiv> "?t (space M) / \<mu> (space M) / 2"
   14.56      ultimately have b: "b \<noteq> 0" "b \<noteq> \<omega>"
   14.57        using M'.finite_measure_of_space
   14.58 -      by (auto simp: pinfreal_inverse_eq_0 finite_measure_of_space)
   14.59 +      by (auto simp: pextreal_inverse_eq_0 finite_measure_of_space)
   14.60      have "finite_measure M (\<lambda>A. b * \<mu> A)" (is "finite_measure M ?b")
   14.61      proof
   14.62        show "?b {} = 0" by simp
   14.63 @@ -486,7 +486,7 @@
   14.64          by (cases "positive_integral (\<lambda>x. f x * indicator A x)", cases "\<nu> A", auto)
   14.65        finally have "positive_integral (\<lambda>x. ?f0 x * indicator A x) \<le> \<nu> A" . }
   14.66      hence "?f0 \<in> G" using `A0 \<in> sets M` unfolding G_def
   14.67 -      by (auto intro!: borel_measurable_indicator borel_measurable_pinfreal_add borel_measurable_pinfreal_times)
   14.68 +      by (auto intro!: borel_measurable_indicator borel_measurable_pextreal_add borel_measurable_pextreal_times)
   14.69      have real: "?t (space M) \<noteq> \<omega>" "?t A0 \<noteq> \<omega>"
   14.70        "b * \<mu> (space M) \<noteq> \<omega>" "b * \<mu> A0 \<noteq> \<omega>"
   14.71        using `A0 \<in> sets M` b
   14.72 @@ -494,27 +494,27 @@
   14.73          finite_measure_of_space M.finite_measure_of_space
   14.74        by auto
   14.75      have int_f_finite: "positive_integral f \<noteq> \<omega>"
   14.76 -      using M'.finite_measure_of_space pos_t unfolding pinfreal_zero_less_diff_iff
   14.77 +      using M'.finite_measure_of_space pos_t unfolding pextreal_zero_less_diff_iff
   14.78        by (auto cong: positive_integral_cong)
   14.79      have "?t (space M) > b * \<mu> (space M)" unfolding b_def
   14.80        apply (simp add: field_simps)
   14.81        apply (subst mult_assoc[symmetric])
   14.82 -      apply (subst pinfreal_mult_inverse)
   14.83 +      apply (subst pextreal_mult_inverse)
   14.84        using finite_measure_of_space M'.finite_measure_of_space pos_t pos_M
   14.85 -      using pinfreal_mult_strict_right_mono[of "Real (1/2)" 1 "?t (space M)"]
   14.86 +      using pextreal_mult_strict_right_mono[of "Real (1/2)" 1 "?t (space M)"]
   14.87        by simp_all
   14.88      hence  "0 < ?t (space M) - b * \<mu> (space M)"
   14.89 -      by (simp add: pinfreal_zero_less_diff_iff)
   14.90 +      by (simp add: pextreal_zero_less_diff_iff)
   14.91      also have "\<dots> \<le> ?t A0 - b * \<mu> A0"
   14.92 -      using space_less_A0 pos_M pos_t b real[unfolded pinfreal_noteq_omega_Ex] by auto
   14.93 -    finally have "b * \<mu> A0 < ?t A0" unfolding pinfreal_zero_less_diff_iff .
   14.94 +      using space_less_A0 pos_M pos_t b real[unfolded pextreal_noteq_omega_Ex] by auto
   14.95 +    finally have "b * \<mu> A0 < ?t A0" unfolding pextreal_zero_less_diff_iff .
   14.96      hence "0 < ?t A0" by auto
   14.97      hence "0 < \<mu> A0" using ac unfolding absolutely_continuous_def
   14.98        using `A0 \<in> sets M` by auto
   14.99      hence "0 < b * \<mu> A0" using b by auto
  14.100      from int_f_finite this
  14.101      have "?y + 0 < positive_integral f + b * \<mu> A0" unfolding int_f_eq_y
  14.102 -      by (rule pinfreal_less_add)
  14.103 +      by (rule pextreal_less_add)
  14.104      also have "\<dots> = positive_integral ?f0" using f0_eq[OF top] `A0 \<in> sets M` sets_into_space
  14.105        by (simp cong: positive_integral_cong)
  14.106      finally have "?y < positive_integral ?f0" by simp
  14.107 @@ -530,7 +530,7 @@
  14.108          using `f \<in> G` `A \<in> sets M` unfolding G_def by auto
  14.109        show "\<nu> A \<le> positive_integral (\<lambda>x. f x * indicator A x)"
  14.110          using upper_bound[THEN bspec, OF `A \<in> sets M`]
  14.111 -         by (simp add: pinfreal_zero_le_diff)
  14.112 +         by (simp add: pextreal_zero_le_diff)
  14.113      qed
  14.114    qed simp
  14.115  qed
  14.116 @@ -573,8 +573,8 @@
  14.117        using Q' by (auto intro: finite_UN)
  14.118      with v.measure_finitely_subadditive[of "{.. i}" Q']
  14.119      have "\<nu> (?O i) \<le> (\<Sum>i\<le>i. \<nu> (Q' i))" by auto
  14.120 -    also have "\<dots> < \<omega>" unfolding setsum_\<omega> pinfreal_less_\<omega> using Q' by auto
  14.121 -    finally show "\<nu> (?O i) \<noteq> \<omega>" unfolding pinfreal_less_\<omega> by auto
  14.122 +    also have "\<dots> < \<omega>" unfolding setsum_\<omega> pextreal_less_\<omega> using Q' by auto
  14.123 +    finally show "\<nu> (?O i) \<noteq> \<omega>" unfolding pextreal_less_\<omega> by auto
  14.124    qed auto
  14.125    have O_mono: "\<And>n. ?O n \<subseteq> ?O (Suc n)" by fastsimp
  14.126    have a_eq: "?a = \<mu> (\<Union>i. ?O i)" unfolding Union[symmetric]
  14.127 @@ -634,7 +634,7 @@
  14.128              then show "\<mu> (?O i \<union> A) \<le> ?a" by (rule le_SUPI)
  14.129            qed
  14.130            finally have "\<mu> A = 0" unfolding a_eq using finite_measure[OF `?O_0 \<in> sets M`]
  14.131 -            by (cases "\<mu> A") (auto simp: pinfreal_noteq_omega_Ex)
  14.132 +            by (cases "\<mu> A") (auto simp: pextreal_noteq_omega_Ex)
  14.133            with `\<mu> A \<noteq> 0` show ?thesis by auto
  14.134          qed
  14.135        qed }
  14.136 @@ -682,7 +682,7 @@
  14.137      \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f x * indicator (Q i \<inter> A) x))"
  14.138    proof
  14.139      fix i
  14.140 -    have indicator_eq: "\<And>f x A. (f x :: pinfreal) * indicator (Q i \<inter> A) x * indicator (Q i) x
  14.141 +    have indicator_eq: "\<And>f x A. (f x :: pextreal) * indicator (Q i \<inter> A) x * indicator (Q i) x
  14.142        = (f x * indicator (Q i) x) * indicator A x"
  14.143        unfolding indicator_def by auto
  14.144      have fm: "finite_measure (restricted_space (Q i)) \<mu>"
  14.145 @@ -718,19 +718,19 @@
  14.146    show ?thesis
  14.147    proof (safe intro!: bexI[of _ ?f])
  14.148      show "?f \<in> borel_measurable M"
  14.149 -      by (safe intro!: borel_measurable_psuminf borel_measurable_pinfreal_times
  14.150 -        borel_measurable_pinfreal_add borel_measurable_indicator
  14.151 +      by (safe intro!: borel_measurable_psuminf borel_measurable_pextreal_times
  14.152 +        borel_measurable_pextreal_add borel_measurable_indicator
  14.153          borel_measurable_const borel Q_sets Q0 Diff countable_UN)
  14.154      fix A assume "A \<in> sets M"
  14.155      have *:
  14.156        "\<And>x i. indicator A x * (f i x * indicator (Q i) x) =
  14.157          f i x * indicator (Q i \<inter> A) x"
  14.158 -      "\<And>x i. (indicator A x * indicator Q0 x :: pinfreal) =
  14.159 +      "\<And>x i. (indicator A x * indicator Q0 x :: pextreal) =
  14.160          indicator (Q0 \<inter> A) x" by (auto simp: indicator_def)
  14.161      have "positive_integral (\<lambda>x. ?f x * indicator A x) =
  14.162        (\<Sum>\<^isub>\<infinity> i. \<nu> (Q i \<inter> A)) + \<omega> * \<mu> (Q0 \<inter> A)"
  14.163        unfolding f[OF `A \<in> sets M`]
  14.164 -      apply (simp del: pinfreal_times(2) add: field_simps *)
  14.165 +      apply (simp del: pextreal_times(2) add: field_simps *)
  14.166        apply (subst positive_integral_add)
  14.167        apply (fastsimp intro: Q0 `A \<in> sets M`)
  14.168        apply (fastsimp intro: Q_sets `A \<in> sets M` borel_measurable_psuminf borel)
  14.169 @@ -775,7 +775,7 @@
  14.170    interpret T: finite_measure M ?T
  14.171      unfolding finite_measure_def finite_measure_axioms_def
  14.172      by (simp cong: positive_integral_cong)
  14.173 -  have "\<And>N. N \<in> sets M \<Longrightarrow> {x \<in> space M. h x \<noteq> 0 \<and> indicator N x \<noteq> (0::pinfreal)} = N"
  14.174 +  have "\<And>N. N \<in> sets M \<Longrightarrow> {x \<in> space M. h x \<noteq> 0 \<and> indicator N x \<noteq> (0::pextreal)} = N"
  14.175      using sets_into_space pos by (force simp: indicator_def)
  14.176    then have "T.absolutely_continuous \<nu>" using assms(2) borel
  14.177      unfolding T.absolutely_continuous_def absolutely_continuous_def
  14.178 @@ -786,10 +786,10 @@
  14.179    show ?thesis
  14.180    proof (safe intro!: bexI[of _ "\<lambda>x. h x * f x"])
  14.181      show "(\<lambda>x. h x * f x) \<in> borel_measurable M"
  14.182 -      using borel f_borel by (auto intro: borel_measurable_pinfreal_times)
  14.183 +      using borel f_borel by (auto intro: borel_measurable_pextreal_times)
  14.184      fix A assume "A \<in> sets M"
  14.185      then have "(\<lambda>x. f x * indicator A x) \<in> borel_measurable M"
  14.186 -      using f_borel by (auto intro: borel_measurable_pinfreal_times borel_measurable_indicator)
  14.187 +      using f_borel by (auto intro: borel_measurable_pextreal_times borel_measurable_indicator)
  14.188      from positive_integral_translated_density[OF borel this]
  14.189      show "\<nu> A = positive_integral (\<lambda>x. h x * f x * indicator A x)"
  14.190        unfolding fT[OF `A \<in> sets M`] by (simp add: field_simps)
  14.191 @@ -834,7 +834,7 @@
  14.192      finally have "\<mu> {x\<in>space M. (f x - g x) * indicator ?N x \<noteq> 0} = 0"
  14.193        using borel N by (subst (asm) positive_integral_0_iff) auto
  14.194      moreover have "{x\<in>space M. (f x - g x) * indicator ?N x \<noteq> 0} = ?N"
  14.195 -      by (auto simp: pinfreal_zero_le_diff)
  14.196 +      by (auto simp: pextreal_zero_le_diff)
  14.197      ultimately have "?N \<in> null_sets" using N by simp }
  14.198    from this[OF borel g_fin eq] this[OF borel(2,1) fin]
  14.199    have "{x\<in>space M. g x < f x} \<union> {x\<in>space M. f x < g x} \<in> null_sets"
  14.200 @@ -866,15 +866,15 @@
  14.201    from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
  14.202    let ?N = "{x\<in>space M. f x \<noteq> f' x}"
  14.203    have "?N \<in> sets M" using borel by auto
  14.204 -  have *: "\<And>i x A. \<And>y::pinfreal. y * indicator (Q i) x * indicator A x = y * indicator (Q i \<inter> A) x"
  14.205 +  have *: "\<And>i x A. \<And>y::pextreal. y * indicator (Q i) x * indicator A x = y * indicator (Q i \<inter> A) x"
  14.206      unfolding indicator_def by auto
  14.207    have 1: "\<forall>i. AE x. ?f (Q i) x = ?f' (Q i) x"
  14.208      using borel Q_fin Q
  14.209      by (intro finite_density_unique[THEN iffD1] allI)
  14.210 -       (auto intro!: borel_measurable_pinfreal_times f Int simp: *)
  14.211 +       (auto intro!: borel_measurable_pextreal_times f Int simp: *)
  14.212    have 2: "AE x. ?f Q0 x = ?f' Q0 x"
  14.213    proof (rule AE_I')
  14.214 -    { fix f :: "'a \<Rightarrow> pinfreal" assume borel: "f \<in> borel_measurable M"
  14.215 +    { fix f :: "'a \<Rightarrow> pextreal" assume borel: "f \<in> borel_measurable M"
  14.216          and eq: "\<And>A. A \<in> sets M \<Longrightarrow> ?\<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
  14.217        let "?A i" = "Q0 \<inter> {x \<in> space M. f x < of_nat i}"
  14.218        have "(\<Union>i. ?A i) \<in> null_sets"
  14.219 @@ -893,7 +893,7 @@
  14.220        qed
  14.221        also have "(\<Union>i. ?A i) = Q0 \<inter> {x\<in>space M. f x < \<omega>}"
  14.222          by (auto simp: less_\<omega>_Ex_of_nat)
  14.223 -      finally have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>} \<in> null_sets" by (simp add: pinfreal_less_\<omega>) }
  14.224 +      finally have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>} \<in> null_sets" by (simp add: pextreal_less_\<omega>) }
  14.225      from this[OF borel(1) refl] this[OF borel(2) f]
  14.226      have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>} \<in> null_sets" "Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>} \<in> null_sets" by simp_all
  14.227      then show "(Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>}) \<union> (Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>}) \<in> null_sets" by (rule null_sets_Un)
  14.228 @@ -927,7 +927,7 @@
  14.229    interpret f': measure_space M "\<lambda>A. positive_integral (\<lambda>x. f' x * indicator A x)"
  14.230      using borel(2) by (rule measure_space_density)
  14.231    { fix A assume "A \<in> sets M"
  14.232 -    then have " {x \<in> space M. h x \<noteq> 0 \<and> indicator A x \<noteq> (0::pinfreal)} = A"
  14.233 +    then have " {x \<in> space M. h x \<noteq> 0 \<and> indicator A x \<noteq> (0::pextreal)} = A"
  14.234        using pos sets_into_space by (force simp: indicator_def)
  14.235      then have "positive_integral (\<lambda>xa. h xa * indicator A xa) = 0 \<longleftrightarrow> A \<in> null_sets"
  14.236        using h_borel `A \<in> sets M` by (simp add: positive_integral_0_iff) }
  14.237 @@ -1027,7 +1027,7 @@
  14.238          apply (subst positive_integral_0_iff)
  14.239          apply fast
  14.240          apply (subst (asm) AE_iff_null_set)
  14.241 -        apply (intro borel_measurable_pinfreal_neq_const)
  14.242 +        apply (intro borel_measurable_pextreal_neq_const)
  14.243          apply fast
  14.244          by simp
  14.245        then show ?thesis by simp
  14.246 @@ -1130,7 +1130,7 @@
  14.247      using sf.RN_deriv(1)[OF \<nu>' ac]
  14.248      unfolding measurable_vimage_iff_inv[OF f] comp_def .
  14.249    fix A assume "A \<in> sets M"
  14.250 -  then have *: "\<And>x. x \<in> space M \<Longrightarrow> indicator (f -` A \<inter> S) (the_inv_into S f x) = (indicator A x :: pinfreal)"
  14.251 +  then have *: "\<And>x. x \<in> space M \<Longrightarrow> indicator (f -` A \<inter> S) (the_inv_into S f x) = (indicator A x :: pextreal)"
  14.252      using f[unfolded bij_betw_def]
  14.253      unfolding indicator_def by (auto simp: f_the_inv_into_f the_inv_into_in)
  14.254    have "\<nu> (f ` (f -` A \<inter> S)) = sf.positive_integral (\<lambda>x. sf.RN_deriv (\<lambda>A. \<nu> (f ` A)) x * indicator (f -` A \<inter> S) x)"
  14.255 @@ -1160,7 +1160,7 @@
  14.256  proof -
  14.257    interpret \<nu>: sigma_finite_measure M \<nu> by fact
  14.258    have ms: "measure_space M \<nu>" by default
  14.259 -  have minus_cong: "\<And>A B A' B'::pinfreal. A = A' \<Longrightarrow> B = B' \<Longrightarrow> real A - real B = real A' - real B'" by simp
  14.260 +  have minus_cong: "\<And>A B A' B'::pextreal. A = A' \<Longrightarrow> B = B' \<Longrightarrow> real A - real B = real A' - real B'" by simp
  14.261    have f': "(\<lambda>x. - f x) \<in> borel_measurable M" using f by auto
  14.262    { fix f :: "'a \<Rightarrow> real" assume "f \<in> borel_measurable M"
  14.263      { fix x assume *: "RN_deriv \<nu> x \<noteq> \<omega>"
    15.1 --- a/src/HOL/Probability/ex/Dining_Cryptographers.thy	Mon Dec 06 19:18:02 2010 +0100
    15.2 +++ b/src/HOL/Probability/ex/Dining_Cryptographers.thy	Fri Dec 03 15:25:14 2010 +0100
    15.3 @@ -8,7 +8,7 @@
    15.4    and not_empty[simp]: "S \<noteq> {}"
    15.5  
    15.6  definition (in finite_space) "M = \<lparr> space = S, sets = Pow S \<rparr>"
    15.7 -definition (in finite_space) \<mu>_def[simp]: "\<mu> A = (of_nat (card A) / of_nat (card S) :: pinfreal)"
    15.8 +definition (in finite_space) \<mu>_def[simp]: "\<mu> A = (of_nat (card A) / of_nat (card S) :: pextreal)"
    15.9  
   15.10  lemma (in finite_space)
   15.11    shows space_M[simp]: "space M = S"
    16.1 --- a/src/HOL/Probability/ex/Koepf_Duermuth_Countermeasure.thy	Mon Dec 06 19:18:02 2010 +0100
    16.2 +++ b/src/HOL/Probability/ex/Koepf_Duermuth_Countermeasure.thy	Fri Dec 03 15:25:14 2010 +0100
    16.3 @@ -274,7 +274,7 @@
    16.4    "snd ` (SIGMA x:f`X. f -` {x} \<inter> X) = X"
    16.5    by (auto simp: image_iff)
    16.6  
    16.7 -lemma zero_le_eq_True: "0 \<le> (x::pinfreal) \<longleftrightarrow> True" by simp
    16.8 +lemma zero_le_eq_True: "0 \<le> (x::pextreal) \<longleftrightarrow> True" by simp
    16.9  
   16.10  lemma Real_setprod:
   16.11    assumes"\<And>i. i\<in>X \<Longrightarrow> 0 \<le> f i"