author wenzelm Wed Sep 25 12:42:56 2013 +0200 (2013-09-25) changeset 53873 08594daabcd9 parent 53872 6e69f9ca8f1c child 53874 7cec5a4d5532
tuned proofs;
```     1.1 --- a/src/HOL/Library/Extended_Real.thy	Wed Sep 25 11:12:59 2013 +0200
1.2 +++ b/src/HOL/Library/Extended_Real.thy	Wed Sep 25 12:42:56 2013 +0200
1.3 @@ -24,23 +24,29 @@
1.4
1.5  instantiation ereal :: uminus
1.6  begin
1.7 -  fun uminus_ereal where
1.8 -    "- (ereal r) = ereal (- r)"
1.9 -  | "- PInfty = MInfty"
1.10 -  | "- MInfty = PInfty"
1.11 -  instance ..
1.12 +
1.13 +fun uminus_ereal where
1.14 +  "- (ereal r) = ereal (- r)"
1.15 +| "- PInfty = MInfty"
1.16 +| "- MInfty = PInfty"
1.17 +
1.18 +instance ..
1.19 +
1.20  end
1.21
1.22  instantiation ereal :: infinity
1.23  begin
1.24 -  definition "(\<infinity>::ereal) = PInfty"
1.25 -  instance ..
1.26 +
1.27 +definition "(\<infinity>::ereal) = PInfty"
1.28 +instance ..
1.29 +
1.30  end
1.31
1.32  declare [[coercion "ereal :: real \<Rightarrow> ereal"]]
1.33
1.34  lemma ereal_uminus_uminus[simp]:
1.35 -  fixes a :: ereal shows "- (- a) = a"
1.36 +  fixes a :: ereal
1.37 +  shows "- (- a) = a"
1.38    by (cases a) simp_all
1.39
1.40  lemma
1.41 @@ -59,7 +65,7 @@
1.42
1.43  lemma [code_unfold]:
1.44    "\<infinity> = PInfty"
1.45 -  "-PInfty = MInfty"
1.46 +  "- PInfty = MInfty"
1.47    by simp_all
1.48
1.49  lemma inj_ereal[simp]: "inj_on ereal A"
1.50 @@ -76,77 +82,97 @@
1.51  lemmas ereal3_cases = ereal2_cases[case_product ereal_cases]
1.52
1.53  lemma ereal_uminus_eq_iff[simp]:
1.54 -  fixes a b :: ereal shows "-a = -b \<longleftrightarrow> a = b"
1.55 +  fixes a b :: ereal
1.56 +  shows "-a = -b \<longleftrightarrow> a = b"
1.57    by (cases rule: ereal2_cases[of a b]) simp_all
1.58
1.59  function of_ereal :: "ereal \<Rightarrow> real" where
1.60 -"of_ereal (ereal r) = r" |
1.61 -"of_ereal \<infinity> = 0" |
1.62 -"of_ereal (-\<infinity>) = 0"
1.63 +  "of_ereal (ereal r) = r"
1.64 +| "of_ereal \<infinity> = 0"
1.65 +| "of_ereal (-\<infinity>) = 0"
1.66    by (auto intro: ereal_cases)
1.67 -termination proof qed (rule wf_empty)
1.68 +termination by default (rule wf_empty)
1.69
1.71    real_of_ereal_def [code_unfold]: "real \<equiv> of_ereal"
1.72
1.73  lemma real_of_ereal[simp]:
1.74 -    "real (- x :: ereal) = - (real x)"
1.75 -    "real (ereal r) = r"
1.76 -    "real (\<infinity>::ereal) = 0"
1.77 +  "real (- x :: ereal) = - (real x)"
1.78 +  "real (ereal r) = r"
1.79 +  "real (\<infinity>::ereal) = 0"
1.80    by (cases x) (simp_all add: real_of_ereal_def)
1.81
1.82  lemma range_ereal[simp]: "range ereal = UNIV - {\<infinity>, -\<infinity>}"
1.83  proof safe
1.84 -  fix x assume "x \<notin> range ereal" "x \<noteq> \<infinity>"
1.85 -  then show "x = -\<infinity>" by (cases x) auto
1.86 +  fix x
1.87 +  assume "x \<notin> range ereal" "x \<noteq> \<infinity>"
1.88 +  then show "x = -\<infinity>"
1.89 +    by (cases x) auto
1.90  qed auto
1.91
1.92  lemma ereal_range_uminus[simp]: "range uminus = (UNIV::ereal set)"
1.93  proof safe
1.94 -  fix x :: ereal show "x \<in> range uminus" by (intro image_eqI[of _ _ "-x"]) auto
1.95 +  fix x :: ereal
1.96 +  show "x \<in> range uminus"
1.97 +    by (intro image_eqI[of _ _ "-x"]) auto
1.98  qed auto
1.99
1.100  instantiation ereal :: abs
1.101  begin
1.102 -  function abs_ereal where
1.103 -    "\<bar>ereal r\<bar> = ereal \<bar>r\<bar>"
1.104 -  | "\<bar>-\<infinity>\<bar> = (\<infinity>::ereal)"
1.105 -  | "\<bar>\<infinity>\<bar> = (\<infinity>::ereal)"
1.106 -  by (auto intro: ereal_cases)
1.107 -  termination proof qed (rule wf_empty)
1.108 -  instance ..
1.109 +
1.110 +function abs_ereal where
1.111 +  "\<bar>ereal r\<bar> = ereal \<bar>r\<bar>"
1.112 +| "\<bar>-\<infinity>\<bar> = (\<infinity>::ereal)"
1.113 +| "\<bar>\<infinity>\<bar> = (\<infinity>::ereal)"
1.114 +by (auto intro: ereal_cases)
1.115 +termination proof qed (rule wf_empty)
1.116 +
1.117 +instance ..
1.118 +
1.119  end
1.120
1.121 -lemma abs_eq_infinity_cases[elim!]: "\<lbrakk> \<bar>x :: ereal\<bar> = \<infinity> ; x = \<infinity> \<Longrightarrow> P ; x = -\<infinity> \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P"
1.122 -  by (cases x) auto
1.123 +lemma abs_eq_infinity_cases[elim!]:
1.124 +  fixes x :: ereal
1.125 +  assumes "\<bar>x\<bar> = \<infinity>"
1.126 +  obtains "x = \<infinity>" | "x = -\<infinity>"
1.127 +  using assms by (cases x) auto
1.128
1.129 -lemma abs_neq_infinity_cases[elim!]: "\<lbrakk> \<bar>x :: ereal\<bar> \<noteq> \<infinity> ; \<And>r. x = ereal r \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P"
1.130 +lemma abs_neq_infinity_cases[elim!]:
1.131 +  fixes x :: ereal
1.132 +  assumes "\<bar>x\<bar> \<noteq> \<infinity>"
1.133 +  obtains r where "x = ereal r"
1.134 +  using assms by (cases x) auto
1.135 +
1.136 +lemma abs_ereal_uminus[simp]:
1.137 +  fixes x :: ereal
1.138 +  shows "\<bar>- x\<bar> = \<bar>x\<bar>"
1.139    by (cases x) auto
1.140
1.141 -lemma abs_ereal_uminus[simp]: "\<bar>- x\<bar> = \<bar>x::ereal\<bar>"
1.142 -  by (cases x) auto
1.143 +lemma ereal_infinity_cases:
1.144 +  fixes a :: ereal
1.145 +  shows "a \<noteq> \<infinity> \<Longrightarrow> a \<noteq> -\<infinity> \<Longrightarrow> \<bar>a\<bar> \<noteq> \<infinity>"
1.146 +  by auto
1.147
1.148 -lemma ereal_infinity_cases: "(a::ereal) \<noteq> \<infinity> \<Longrightarrow> a \<noteq> -\<infinity> \<Longrightarrow> \<bar>a\<bar> \<noteq> \<infinity>"
1.149 -  by auto
1.150
1.152
1.153 -instantiation ereal :: "{one, comm_monoid_add}"
1.155  begin
1.156
1.157  definition "0 = ereal 0"
1.158  definition "1 = ereal 1"
1.159
1.160  function plus_ereal where
1.161 -"ereal r + ereal p = ereal (r + p)" |
1.162 -"\<infinity> + a = (\<infinity>::ereal)" |
1.163 -"a + \<infinity> = (\<infinity>::ereal)" |
1.164 -"ereal r + -\<infinity> = - \<infinity>" |
1.165 -"-\<infinity> + ereal p = -(\<infinity>::ereal)" |
1.166 -"-\<infinity> + -\<infinity> = -(\<infinity>::ereal)"
1.167 +  "ereal r + ereal p = ereal (r + p)"
1.168 +| "\<infinity> + a = (\<infinity>::ereal)"
1.169 +| "a + \<infinity> = (\<infinity>::ereal)"
1.170 +| "ereal r + -\<infinity> = - \<infinity>"
1.171 +| "-\<infinity> + ereal p = -(\<infinity>::ereal)"
1.172 +| "-\<infinity> + -\<infinity> = -(\<infinity>::ereal)"
1.173  proof -
1.174    case (goal1 P x)
1.175 -  then obtain a b where "x = (a, b)" by (cases x) auto
1.176 +  then obtain a b where "x = (a, b)"
1.177 +    by (cases x) auto
1.178    with goal1 show P
1.179     by (cases rule: ereal2_cases[of a b]) auto
1.180  qed auto
1.181 @@ -172,6 +198,7 @@
1.182    show "a + b + c = a + (b + c)"
1.183      by (cases rule: ereal3_cases[of a b c]) simp_all
1.184  qed
1.185 +
1.186  end
1.187
1.188  instance ereal :: numeral ..
1.189 @@ -182,35 +209,37 @@
1.190  lemma abs_ereal_zero[simp]: "\<bar>0\<bar> = (0::ereal)"
1.191    unfolding zero_ereal_def abs_ereal.simps by simp
1.192
1.193 -lemma ereal_uminus_zero[simp]:
1.194 -  "- 0 = (0::ereal)"
1.195 +lemma ereal_uminus_zero[simp]: "- 0 = (0::ereal)"
1.197
1.198  lemma ereal_uminus_zero_iff[simp]:
1.199 -  fixes a :: ereal shows "-a = 0 \<longleftrightarrow> a = 0"
1.200 +  fixes a :: ereal
1.201 +  shows "-a = 0 \<longleftrightarrow> a = 0"
1.202    by (cases a) simp_all
1.203
1.204  lemma ereal_plus_eq_PInfty[simp]:
1.205 -  fixes a b :: ereal shows "a + b = \<infinity> \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>"
1.206 +  fixes a b :: ereal
1.207 +  shows "a + b = \<infinity> \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>"
1.208    by (cases rule: ereal2_cases[of a b]) auto
1.209
1.210  lemma ereal_plus_eq_MInfty[simp]:
1.211 -  fixes a b :: ereal shows "a + b = -\<infinity> \<longleftrightarrow>
1.212 -    (a = -\<infinity> \<or> b = -\<infinity>) \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>"
1.213 +  fixes a b :: ereal
1.214 +  shows "a + b = -\<infinity> \<longleftrightarrow> (a = -\<infinity> \<or> b = -\<infinity>) \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>"
1.215    by (cases rule: ereal2_cases[of a b]) auto
1.216
1.218 -  fixes a b :: ereal assumes "a \<noteq> -\<infinity>"
1.219 -  shows "a + b = a + c \<longleftrightarrow> (a = \<infinity> \<or> b = c)"
1.220 +  fixes a b :: ereal
1.221 +  assumes "a \<noteq> -\<infinity>"
1.222 +  shows "a + b = a + c \<longleftrightarrow> a = \<infinity> \<or> b = c"
1.223    using assms by (cases rule: ereal3_cases[of a b c]) auto
1.224
1.226 -  fixes a b :: ereal assumes "a \<noteq> -\<infinity>"
1.227 -  shows "b + a = c + a \<longleftrightarrow> (a = \<infinity> \<or> b = c)"
1.228 +  fixes a b :: ereal
1.229 +  assumes "a \<noteq> -\<infinity>"
1.230 +  shows "b + a = c + a \<longleftrightarrow> a = \<infinity> \<or> b = c"
1.231    using assms by (cases rule: ereal3_cases[of a b c]) auto
1.232
1.233 -lemma ereal_real:
1.234 -  "ereal (real x) = (if \<bar>x\<bar> = \<infinity> then 0 else x)"
1.235 +lemma ereal_real: "ereal (real x) = (if \<bar>x\<bar> = \<infinity> then 0 else x)"
1.236    by (cases x) simp_all
1.237
1.239 @@ -219,6 +248,7 @@
1.240      (if (\<bar>a\<bar> = \<infinity>) \<and> (\<bar>b\<bar> = \<infinity>) \<or> (\<bar>a\<bar> \<noteq> \<infinity>) \<and> (\<bar>b\<bar> \<noteq> \<infinity>) then real a + real b else 0)"
1.241    by (cases rule: ereal2_cases[of a b]) auto
1.242
1.243 +
1.244  subsubsection "Linear order on @{typ ereal}"
1.245
1.246  instantiation ereal :: linorder
1.247 @@ -250,7 +280,7 @@
1.248  lemma ereal_infty_less_eq[simp]:
1.249    fixes x :: ereal
1.250    shows "\<infinity> \<le> x \<longleftrightarrow> x = \<infinity>"
1.251 -  "x \<le> -\<infinity> \<longleftrightarrow> x = -\<infinity>"
1.252 +    and "x \<le> -\<infinity> \<longleftrightarrow> x = -\<infinity>"
1.253    by (auto simp add: less_eq_ereal_def)
1.254
1.255  lemma ereal_less[simp]:
1.256 @@ -282,10 +312,16 @@
1.257      by (cases rule: ereal2_cases[of x y]) auto
1.258    show "x \<le> y \<or> y \<le> x "
1.259      by (cases rule: ereal2_cases[of x y]) auto
1.260 -  { assume "x \<le> y" "y \<le> x" then show "x = y"
1.261 -    by (cases rule: ereal2_cases[of x y]) auto }
1.262 -  { assume "x \<le> y" "y \<le> z" then show "x \<le> z"
1.263 -    by (cases rule: ereal3_cases[of x y z]) auto }
1.264 +  {
1.265 +    assume "x \<le> y" "y \<le> x"
1.266 +    then show "x = y"
1.267 +      by (cases rule: ereal2_cases[of x y]) auto
1.268 +  }
1.269 +  {
1.270 +    assume "x \<le> y" "y \<le> z"
1.271 +    then show "x \<le> z"
1.272 +      by (cases rule: ereal3_cases[of x y z]) auto
1.273 +  }
1.274  qed
1.275
1.276  end
1.277 @@ -298,20 +334,25 @@
1.278
1.280  proof
1.281 -  fix a b c :: ereal assume "a \<le> b" then show "c + a \<le> c + b"
1.282 +  fix a b c :: ereal
1.283 +  assume "a \<le> b"
1.284 +  then show "c + a \<le> c + b"
1.285      by (cases rule: ereal3_cases[of a b c]) auto
1.286  qed
1.287
1.288  lemma real_of_ereal_positive_mono:
1.289 -  fixes x y :: ereal shows "\<lbrakk>0 \<le> x; x \<le> y; y \<noteq> \<infinity>\<rbrakk> \<Longrightarrow> real x \<le> real y"
1.290 +  fixes x y :: ereal
1.291 +  shows "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<noteq> \<infinity> \<Longrightarrow> real x \<le> real y"
1.292    by (cases rule: ereal2_cases[of x y]) auto
1.293
1.294  lemma ereal_MInfty_lessI[intro, simp]:
1.295 -  fixes a :: ereal shows "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a"
1.296 +  fixes a :: ereal
1.297 +  shows "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a"
1.298    by (cases a) auto
1.299
1.300  lemma ereal_less_PInfty[intro, simp]:
1.301 -  fixes a :: ereal shows "a \<noteq> \<infinity> \<Longrightarrow> a < \<infinity>"
1.302 +  fixes a :: ereal
1.303 +  shows "a \<noteq> \<infinity> \<Longrightarrow> a < \<infinity>"
1.304    by (cases a) auto
1.305
1.306  lemma ereal_less_ereal_Ex:
1.307 @@ -321,12 +362,16 @@
1.308
1.309  lemma less_PInf_Ex_of_nat: "x \<noteq> \<infinity> \<longleftrightarrow> (\<exists>n::nat. x < ereal (real n))"
1.310  proof (cases x)
1.311 -  case (real r) then show ?thesis
1.312 +  case (real r)
1.313 +  then show ?thesis
1.314      using reals_Archimedean2[of r] by simp
1.315  qed simp_all
1.316
1.318 -  fixes a b c d :: ereal assumes "a \<le> b" "c \<le> d" shows "a + c \<le> b + d"
1.319 +  fixes a b c d :: ereal
1.320 +  assumes "a \<le> b"
1.321 +    and "c \<le> d"
1.322 +  shows "a + c \<le> b + d"
1.323    using assms
1.324    apply (cases a)
1.325    apply (cases rule: ereal3_cases[of b c d], auto)
1.326 @@ -334,31 +379,34 @@
1.327    done
1.328
1.329  lemma ereal_minus_le_minus[simp]:
1.330 -  fixes a b :: ereal shows "- a \<le> - b \<longleftrightarrow> b \<le> a"
1.331 +  fixes a b :: ereal
1.332 +  shows "- a \<le> - b \<longleftrightarrow> b \<le> a"
1.333    by (cases rule: ereal2_cases[of a b]) auto
1.334
1.335  lemma ereal_minus_less_minus[simp]:
1.336 -  fixes a b :: ereal shows "- a < - b \<longleftrightarrow> b < a"
1.337 +  fixes a b :: ereal
1.338 +  shows "- a < - b \<longleftrightarrow> b < a"
1.339    by (cases rule: ereal2_cases[of a b]) auto
1.340
1.341  lemma ereal_le_real_iff:
1.342 -  "x \<le> real y \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x \<le> y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x \<le> 0))"
1.343 +  "x \<le> real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x \<le> y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x \<le> 0)"
1.344    by (cases y) auto
1.345
1.346  lemma real_le_ereal_iff:
1.347 -  "real y \<le> x \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y \<le> ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 \<le> x))"
1.348 +  "real y \<le> x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y \<le> ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 \<le> x)"
1.349    by (cases y) auto
1.350
1.351  lemma ereal_less_real_iff:
1.352 -  "x < real y \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x < y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x < 0))"
1.353 +  "x < real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x < y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x < 0)"
1.354    by (cases y) auto
1.355
1.356  lemma real_less_ereal_iff:
1.357 -  "real y < x \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y < ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 < x))"
1.358 +  "real y < x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y < ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 < x)"
1.359    by (cases y) auto
1.360
1.361  lemma real_of_ereal_pos:
1.362 -  fixes x :: ereal shows "0 \<le> x \<Longrightarrow> 0 \<le> real x" by (cases x) auto
1.363 +  fixes x :: ereal
1.364 +  shows "0 \<le> x \<Longrightarrow> 0 \<le> real x" by (cases x) auto
1.365
1.366  lemmas real_of_ereal_ord_simps =
1.367    ereal_le_real_iff real_le_ereal_iff ereal_less_real_iff real_less_ereal_iff
1.368 @@ -372,35 +420,44 @@
1.369  lemma abs_ereal_pos[simp]: "0 \<le> \<bar>x :: ereal\<bar>"
1.370    by (cases x) auto
1.371
1.372 -lemma real_of_ereal_le_0[simp]: "real (x :: ereal) \<le> 0 \<longleftrightarrow> (x \<le> 0 \<or> x = \<infinity>)"
1.373 +lemma real_of_ereal_le_0[simp]: "real (x :: ereal) \<le> 0 \<longleftrightarrow> x \<le> 0 \<or> x = \<infinity>"
1.374    by (cases x) auto
1.375
1.376  lemma abs_real_of_ereal[simp]: "\<bar>real (x :: ereal)\<bar> = real \<bar>x\<bar>"
1.377    by (cases x) auto
1.378
1.379  lemma zero_less_real_of_ereal:
1.380 -  fixes x :: ereal shows "0 < real x \<longleftrightarrow> (0 < x \<and> x \<noteq> \<infinity>)"
1.381 +  fixes x :: ereal
1.382 +  shows "0 < real x \<longleftrightarrow> 0 < x \<and> x \<noteq> \<infinity>"
1.383    by (cases x) auto
1.384
1.385  lemma ereal_0_le_uminus_iff[simp]:
1.386 -  fixes a :: ereal shows "0 \<le> -a \<longleftrightarrow> a \<le> 0"
1.387 +  fixes a :: ereal
1.388 +  shows "0 \<le> - a \<longleftrightarrow> a \<le> 0"
1.389    by (cases rule: ereal2_cases[of a]) auto
1.390
1.391  lemma ereal_uminus_le_0_iff[simp]:
1.392 -  fixes a :: ereal shows "-a \<le> 0 \<longleftrightarrow> 0 \<le> a"
1.393 +  fixes a :: ereal
1.394 +  shows "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
1.395    by (cases rule: ereal2_cases[of a]) auto
1.396
1.398    fixes a b c d :: ereal
1.399 -  assumes "a = b" "0 \<le> a" "a \<noteq> \<infinity>" "c < d"
1.400 +  assumes "a = b"
1.401 +    and "0 \<le> a"
1.402 +    and "a \<noteq> \<infinity>"
1.403 +    and "c < d"
1.404    shows "a + c < b + d"
1.405 -  using assms by (cases rule: ereal3_cases[case_product ereal_cases, of a b c d]) auto
1.406 +  using assms
1.407 +  by (cases rule: ereal3_cases[case_product ereal_cases, of a b c d]) auto
1.408
1.410 -  fixes a b c :: ereal shows "\<bar>a\<bar> \<noteq> \<infinity> \<Longrightarrow> c < b \<Longrightarrow> a + c < a + b"
1.412 +  fixes a b c :: ereal
1.413 +  shows "\<bar>a\<bar> \<noteq> \<infinity> \<Longrightarrow> c < b \<Longrightarrow> a + c < a + b"
1.414    by (cases rule: ereal2_cases[of b c]) auto
1.415
1.416 -lemma ereal_uminus_eq_reorder: "- a = b \<longleftrightarrow> a = (-b::ereal)" by auto
1.417 +lemma ereal_uminus_eq_reorder: "- a = b \<longleftrightarrow> a = (-b::ereal)"
1.418 +  by auto
1.419
1.420  lemma ereal_uminus_less_reorder: "- a < b \<longleftrightarrow> -b < (a::ereal)"
1.421    by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_less_minus)
1.422 @@ -412,23 +469,39 @@
1.423    ereal_uminus_eq_reorder ereal_uminus_less_reorder ereal_uminus_le_reorder
1.424
1.425  lemma ereal_bot:
1.426 -  fixes x :: ereal assumes "\<And>B. x \<le> ereal B" shows "x = - \<infinity>"
1.427 +  fixes x :: ereal
1.428 +  assumes "\<And>B. x \<le> ereal B"
1.429 +  shows "x = - \<infinity>"
1.430  proof (cases x)
1.431 -  case (real r) with assms[of "r - 1"] show ?thesis by auto
1.432 +  case (real r)
1.433 +  with assms[of "r - 1"] show ?thesis
1.434 +    by auto
1.435  next
1.436 -  case PInf with assms[of 0] show ?thesis by auto
1.437 +  case PInf
1.438 +  with assms[of 0] show ?thesis
1.439 +    by auto
1.440  next
1.441 -  case MInf then show ?thesis by simp
1.442 +  case MInf
1.443 +  then show ?thesis
1.444 +    by simp
1.445  qed
1.446
1.447  lemma ereal_top:
1.448 -  fixes x :: ereal assumes "\<And>B. x \<ge> ereal B" shows "x = \<infinity>"
1.449 +  fixes x :: ereal
1.450 +  assumes "\<And>B. x \<ge> ereal B"
1.451 +  shows "x = \<infinity>"
1.452  proof (cases x)
1.453 -  case (real r) with assms[of "r + 1"] show ?thesis by auto
1.454 +  case (real r)
1.455 +  with assms[of "r + 1"] show ?thesis
1.456 +    by auto
1.457  next
1.458 -  case MInf with assms[of 0] show ?thesis by auto
1.459 +  case MInf
1.460 +  with assms[of 0] show ?thesis
1.461 +    by auto
1.462  next
1.463 -  case PInf then show ?thesis by simp
1.464 +  case PInf
1.465 +  then show ?thesis
1.466 +    by simp
1.467  qed
1.468
1.469  lemma
1.470 @@ -449,32 +522,36 @@
1.471    unfolding incseq_def by auto
1.472
1.474 -  fixes a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a + b"
1.475 +  fixes a b :: ereal
1.476 +  shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a + b"
1.477    using add_mono[of 0 a 0 b] by simp
1.478
1.479 -lemma image_eqD: "f ` A = B \<Longrightarrow> (\<forall>x\<in>A. f x \<in> B)"
1.480 +lemma image_eqD: "f ` A = B \<Longrightarrow> \<forall>x\<in>A. f x \<in> B"
1.481    by auto
1.482
1.483  lemma incseq_setsumI:
1.486    assumes "\<And>i. 0 \<le> f i"
1.487    shows "incseq (\<lambda>i. setsum f {..< i})"
1.488  proof (intro incseq_SucI)
1.489 -  fix n have "setsum f {..< n} + 0 \<le> setsum f {..<n} + f n"
1.490 +  fix n
1.491 +  have "setsum f {..< n} + 0 \<le> setsum f {..<n} + f n"
1.492      using assms by (rule add_left_mono)
1.493    then show "setsum f {..< n} \<le> setsum f {..< Suc n}"
1.494      by auto
1.495  qed
1.496
1.497  lemma incseq_setsumI2:
1.500    assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)"
1.501    shows "incseq (\<lambda>i. \<Sum>n\<in>A. f n i)"
1.502 -  using assms unfolding incseq_def by (auto intro: setsum_mono)
1.503 +  using assms
1.504 +  unfolding incseq_def by (auto intro: setsum_mono)
1.505 +
1.506
1.507  subsubsection "Multiplication"
1.508
1.509 -instantiation ereal :: "{comm_monoid_mult, sgn}"
1.510 +instantiation ereal :: "{comm_monoid_mult,sgn}"
1.511  begin
1.512
1.513  function sgn_ereal :: "ereal \<Rightarrow> ereal" where
1.514 @@ -482,28 +559,31 @@
1.515  | "sgn (\<infinity>::ereal) = 1"
1.516  | "sgn (-\<infinity>::ereal) = -1"
1.517  by (auto intro: ereal_cases)
1.518 -termination proof qed (rule wf_empty)
1.519 +termination by default (rule wf_empty)
1.520
1.521  function times_ereal where
1.522 -"ereal r * ereal p = ereal (r * p)" |
1.523 -"ereal r * \<infinity> = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" |
1.524 -"\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" |
1.525 -"ereal r * -\<infinity> = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" |
1.526 -"-\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" |
1.527 -"(\<infinity>::ereal) * \<infinity> = \<infinity>" |
1.528 -"-(\<infinity>::ereal) * \<infinity> = -\<infinity>" |
1.529 -"(\<infinity>::ereal) * -\<infinity> = -\<infinity>" |
1.530 -"-(\<infinity>::ereal) * -\<infinity> = \<infinity>"
1.531 +  "ereal r * ereal p = ereal (r * p)"
1.532 +| "ereal r * \<infinity> = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)"
1.533 +| "\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)"
1.534 +| "ereal r * -\<infinity> = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)"
1.535 +| "-\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)"
1.536 +| "(\<infinity>::ereal) * \<infinity> = \<infinity>"
1.537 +| "-(\<infinity>::ereal) * \<infinity> = -\<infinity>"
1.538 +| "(\<infinity>::ereal) * -\<infinity> = -\<infinity>"
1.539 +| "-(\<infinity>::ereal) * -\<infinity> = \<infinity>"
1.540  proof -
1.541    case (goal1 P x)
1.542 -  then obtain a b where "x = (a, b)" by (cases x) auto
1.543 -  with goal1 show P by (cases rule: ereal2_cases[of a b]) auto
1.544 +  then obtain a b where "x = (a, b)"
1.545 +    by (cases x) auto
1.546 +  with goal1 show P
1.547 +    by (cases rule: ereal2_cases[of a b]) auto
1.548  qed simp_all
1.549  termination by (relation "{}") simp
1.550
1.551  instance
1.552  proof
1.553 -  fix a b c :: ereal show "1 * a = a"
1.554 +  fix a b c :: ereal
1.555 +  show "1 * a = a"
1.556      by (cases a) (simp_all add: one_ereal_def)
1.557    show "a * b = b * a"
1.558      by (cases rule: ereal2_cases[of a b]) simp_all
1.559 @@ -511,36 +591,39 @@
1.560      by (cases rule: ereal3_cases[of a b c])
1.562  qed
1.563 +
1.564  end
1.565
1.566  lemma real_ereal_1[simp]: "real (1::ereal) = 1"
1.567    unfolding one_ereal_def by simp
1.568
1.569  lemma real_of_ereal_le_1:
1.570 -  fixes a :: ereal shows "a \<le> 1 \<Longrightarrow> real a \<le> 1"
1.571 +  fixes a :: ereal
1.572 +  shows "a \<le> 1 \<Longrightarrow> real a \<le> 1"
1.573    by (cases a) (auto simp: one_ereal_def)
1.574
1.575  lemma abs_ereal_one[simp]: "\<bar>1\<bar> = (1::ereal)"
1.576    unfolding one_ereal_def by simp
1.577
1.578  lemma ereal_mult_zero[simp]:
1.579 -  fixes a :: ereal shows "a * 0 = 0"
1.580 +  fixes a :: ereal
1.581 +  shows "a * 0 = 0"
1.582    by (cases a) (simp_all add: zero_ereal_def)
1.583
1.584  lemma ereal_zero_mult[simp]:
1.585 -  fixes a :: ereal shows "0 * a = 0"
1.586 +  fixes a :: ereal
1.587 +  shows "0 * a = 0"
1.588    by (cases a) (simp_all add: zero_ereal_def)
1.589
1.590 -lemma ereal_m1_less_0[simp]:
1.591 -  "-(1::ereal) < 0"
1.592 +lemma ereal_m1_less_0[simp]: "-(1::ereal) < 0"
1.593    by (simp add: zero_ereal_def one_ereal_def)
1.594
1.595 -lemma ereal_zero_m1[simp]:
1.596 -  "1 \<noteq> (0::ereal)"
1.597 +lemma ereal_zero_m1[simp]: "1 \<noteq> (0::ereal)"
1.598    by (simp add: zero_ereal_def one_ereal_def)
1.599
1.600  lemma ereal_times_0[simp]:
1.601 -  fixes x :: ereal shows "0 * x = 0"
1.602 +  fixes x :: ereal
1.603 +  shows "0 * x = 0"
1.604    by (cases x) (auto simp: zero_ereal_def)
1.605
1.606  lemma ereal_times[simp]:
1.607 @@ -549,21 +632,24 @@
1.608    by (auto simp add: times_ereal_def one_ereal_def)
1.609
1.610  lemma ereal_plus_1[simp]:
1.611 -  "1 + ereal r = ereal (r + 1)" "ereal r + 1 = ereal (r + 1)"
1.612 -  "1 + -(\<infinity>::ereal) = -\<infinity>" "-(\<infinity>::ereal) + 1 = -\<infinity>"
1.613 +  "1 + ereal r = ereal (r + 1)"
1.614 +  "ereal r + 1 = ereal (r + 1)"
1.615 +  "1 + -(\<infinity>::ereal) = -\<infinity>"
1.616 +  "-(\<infinity>::ereal) + 1 = -\<infinity>"
1.617    unfolding one_ereal_def by auto
1.618
1.619  lemma ereal_zero_times[simp]:
1.620 -  fixes a b :: ereal shows "a * b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
1.621 +  fixes a b :: ereal
1.622 +  shows "a * b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
1.623    by (cases rule: ereal2_cases[of a b]) auto
1.624
1.625  lemma ereal_mult_eq_PInfty[simp]:
1.626 -  shows "a * b = (\<infinity>::ereal) \<longleftrightarrow>
1.627 +  "a * b = (\<infinity>::ereal) \<longleftrightarrow>
1.628      (a = \<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = -\<infinity>)"
1.629    by (cases rule: ereal2_cases[of a b]) auto
1.630
1.631  lemma ereal_mult_eq_MInfty[simp]:
1.632 -  shows "a * b = -(\<infinity>::ereal) \<longleftrightarrow>
1.633 +  "a * b = -(\<infinity>::ereal) \<longleftrightarrow>
1.634      (a = \<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = -\<infinity>)"
1.635    by (cases rule: ereal2_cases[of a b]) auto
1.636
1.637 @@ -574,11 +660,13 @@
1.638    by (simp_all add: zero_ereal_def one_ereal_def)
1.639
1.640  lemma ereal_mult_minus_left[simp]:
1.641 -  fixes a b :: ereal shows "-a * b = - (a * b)"
1.642 +  fixes a b :: ereal
1.643 +  shows "-a * b = - (a * b)"
1.644    by (cases rule: ereal2_cases[of a b]) auto
1.645
1.646  lemma ereal_mult_minus_right[simp]:
1.647 -  fixes a b :: ereal shows "a * -b = - (a * b)"
1.648 +  fixes a b :: ereal
1.649 +  shows "a * -b = - (a * b)"
1.650    by (cases rule: ereal2_cases[of a b]) auto
1.651
1.652  lemma ereal_mult_infty[simp]:
1.653 @@ -590,26 +678,33 @@
1.654    by (cases a) auto
1.655
1.656  lemma ereal_mult_strict_right_mono:
1.657 -  assumes "a < b" and "0 < c" "c < (\<infinity>::ereal)"
1.658 +  assumes "a < b"
1.659 +    and "0 < c"
1.660 +    and "c < (\<infinity>::ereal)"
1.661    shows "a * c < b * c"
1.662    using assms
1.663 -  by (cases rule: ereal3_cases[of a b c])
1.664 -     (auto simp: zero_le_mult_iff)
1.665 +  by (cases rule: ereal3_cases[of a b c]) (auto simp: zero_le_mult_iff)
1.666
1.667  lemma ereal_mult_strict_left_mono:
1.668 -  "\<lbrakk> a < b ; 0 < c ; c < (\<infinity>::ereal)\<rbrakk> \<Longrightarrow> c * a < c * b"
1.669 -  using ereal_mult_strict_right_mono by (simp add: mult_commute[of c])
1.670 +  "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c < (\<infinity>::ereal) \<Longrightarrow> c * a < c * b"
1.671 +  using ereal_mult_strict_right_mono
1.672 +  by (simp add: mult_commute[of c])
1.673
1.674  lemma ereal_mult_right_mono:
1.675 -  fixes a b c :: ereal shows "\<lbrakk>a \<le> b; 0 \<le> c\<rbrakk> \<Longrightarrow> a*c \<le> b*c"
1.676 +  fixes a b c :: ereal
1.677 +  shows "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
1.678    using assms
1.679 -  apply (cases "c = 0") apply simp
1.680 -  by (cases rule: ereal3_cases[of a b c])
1.681 -     (auto simp: zero_le_mult_iff)
1.682 +  apply (cases "c = 0")
1.683 +  apply simp
1.684 +  apply (cases rule: ereal3_cases[of a b c])
1.685 +  apply (auto simp: zero_le_mult_iff)
1.686 +  done
1.687
1.688  lemma ereal_mult_left_mono:
1.689 -  fixes a b c :: ereal shows "\<lbrakk>a \<le> b; 0 \<le> c\<rbrakk> \<Longrightarrow> c * a \<le> c * b"
1.690 -  using ereal_mult_right_mono by (simp add: mult_commute[of c])
1.691 +  fixes a b c :: ereal
1.692 +  shows "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
1.693 +  using ereal_mult_right_mono
1.694 +  by (simp add: mult_commute[of c])
1.695
1.696  lemma zero_less_one_ereal[simp]: "0 \<le> (1::ereal)"
1.697    by (simp add: one_ereal_def zero_ereal_def)
1.698 @@ -618,11 +713,13 @@
1.699    by (cases rule: ereal2_cases[of a b]) (auto simp: mult_nonneg_nonneg)
1.700
1.701  lemma ereal_right_distrib:
1.702 -  fixes r a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> r * (a + b) = r * a + r * b"
1.703 +  fixes r a b :: ereal
1.704 +  shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> r * (a + b) = r * a + r * b"
1.705    by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps)
1.706
1.707  lemma ereal_left_distrib:
1.708 -  fixes r a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> (a + b) * r = a * r + b * r"
1.709 +  fixes r a b :: ereal
1.710 +  shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> (a + b) * r = a * r + b * r"
1.711    by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps)
1.712
1.713  lemma ereal_mult_le_0_iff:
1.714 @@ -657,7 +754,9 @@
1.715
1.716  lemma ereal_distrib:
1.717    fixes a b c :: ereal
1.718 -  assumes "a \<noteq> \<infinity> \<or> b \<noteq> -\<infinity>" "a \<noteq> -\<infinity> \<or> b \<noteq> \<infinity>" "\<bar>c\<bar> \<noteq> \<infinity>"
1.719 +  assumes "a \<noteq> \<infinity> \<or> b \<noteq> -\<infinity>"
1.720 +    and "a \<noteq> -\<infinity> \<or> b \<noteq> \<infinity>"
1.721 +    and "\<bar>c\<bar> \<noteq> \<infinity>"
1.722    shows "(a + b) * c = a * c + b * c"
1.723    using assms
1.724    by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps)
1.725 @@ -670,74 +769,119 @@
1.726
1.727  lemma ereal_le_epsilon:
1.728    fixes x y :: ereal
1.729 -  assumes "ALL e. 0 < e --> x <= y + e"
1.730 -  shows "x <= y"
1.731 -proof-
1.732 -{ assume a: "EX r. y = ereal r"
1.733 -  then obtain r where r_def: "y = ereal r" by auto
1.734 -  { assume "x=(-\<infinity>)" hence ?thesis by auto }
1.735 +  assumes "\<forall>e. 0 < e \<longrightarrow> x \<le> y + e"
1.736 +  shows "x \<le> y"
1.737 +proof -
1.738 +  {
1.739 +    assume a: "\<exists>r. y = ereal r"
1.740 +    then obtain r where r_def: "y = ereal r"
1.741 +      by auto
1.742 +    {
1.743 +      assume "x = -\<infinity>"
1.744 +      then have ?thesis by auto
1.745 +    }
1.746 +    moreover
1.747 +    {
1.748 +      assume "x \<noteq> -\<infinity>"
1.749 +      then obtain p where p_def: "x = ereal p"
1.750 +      using a assms[rule_format, of 1]
1.751 +        by (cases x) auto
1.752 +      {
1.753 +        fix e
1.754 +        have "0 < e \<longrightarrow> p \<le> r + e"
1.755 +          using assms[rule_format, of "ereal e"] p_def r_def by auto
1.756 +      }
1.757 +      then have "p \<le> r"
1.758 +        apply (subst field_le_epsilon)
1.759 +        apply auto
1.760 +        done
1.761 +      then have ?thesis
1.762 +        using r_def p_def by auto
1.763 +    }
1.764 +    ultimately have ?thesis
1.765 +      by blast
1.766 +  }
1.767    moreover
1.768 -  { assume "~(x=(-\<infinity>))"
1.769 -    then obtain p where p_def: "x = ereal p"
1.770 -    using a assms[rule_format, of 1] by (cases x) auto
1.771 -    { fix e have "0 < e --> p <= r + e"
1.772 -      using assms[rule_format, of "ereal e"] p_def r_def by auto }
1.773 -    hence "p <= r" apply (subst field_le_epsilon) by auto
1.774 -    hence ?thesis using r_def p_def by auto
1.775 -  } ultimately have ?thesis by blast
1.776 -}
1.777 -moreover
1.778 -{ assume "y=(-\<infinity>) | y=\<infinity>" hence ?thesis
1.779 -    using assms[rule_format, of 1] by (cases x) auto
1.780 -} ultimately show ?thesis by (cases y) auto
1.781 +  {
1.782 +    assume "y = -\<infinity> | y = \<infinity>"
1.783 +    then have ?thesis
1.784 +      using assms[rule_format, of 1] by (cases x) auto
1.785 +  }
1.786 +  ultimately show ?thesis
1.787 +    by (cases y) auto
1.788  qed
1.789
1.790 -
1.791  lemma ereal_le_epsilon2:
1.792    fixes x y :: ereal
1.793 -  assumes "ALL e. 0 < e --> x <= y + ereal e"
1.794 -  shows "x <= y"
1.795 -proof-
1.796 -{ fix e :: ereal assume "e>0"
1.797 -  { assume "e=\<infinity>" hence "x<=y+e" by auto }
1.798 -  moreover
1.799 -  { assume "e~=\<infinity>"
1.800 -    then obtain r where "e = ereal r" using `e>0` apply (cases e) by auto
1.801 -    hence "x<=y+e" using assms[rule_format, of r] `e>0` by auto
1.802 -  } ultimately have "x<=y+e" by blast
1.803 -} then show ?thesis using ereal_le_epsilon by auto
1.804 +  assumes "\<forall>e. 0 < e \<longrightarrow> x \<le> y + ereal e"
1.805 +  shows "x \<le> y"
1.806 +proof -
1.807 +  {
1.808 +    fix e :: ereal
1.809 +    assume "e > 0"
1.810 +    {
1.811 +      assume "e = \<infinity>"
1.812 +      then have "x \<le> y + e"
1.813 +        by auto
1.814 +    }
1.815 +    moreover
1.816 +    {
1.817 +      assume "e \<noteq> \<infinity>"
1.818 +      then obtain r where "e = ereal r"
1.819 +        using `e > 0` by (cases e) auto
1.820 +      then have "x \<le> y + e"
1.821 +        using assms[rule_format, of r] `e>0` by auto
1.822 +    }
1.823 +    ultimately have "x \<le> y + e"
1.824 +      by blast
1.825 +  }
1.826 +  then show ?thesis
1.827 +    using ereal_le_epsilon by auto
1.828  qed
1.829
1.830  lemma ereal_le_real:
1.831    fixes x y :: ereal
1.832 -  assumes "ALL z. x <= ereal z --> y <= ereal z"
1.833 -  shows "y <= x"
1.834 -by (metis assms ereal_bot ereal_cases ereal_infty_less_eq(2) ereal_less_eq(1) linorder_le_cases)
1.835 +  assumes "\<forall>z. x \<le> ereal z \<longrightarrow> y \<le> ereal z"
1.836 +  shows "y \<le> x"
1.837 +  by (metis assms ereal_bot ereal_cases ereal_infty_less_eq(2) ereal_less_eq(1) linorder_le_cases)
1.838
1.839  lemma setprod_ereal_0:
1.840    fixes f :: "'a \<Rightarrow> ereal"
1.841 -  shows "(\<Prod>i\<in>A. f i) = 0 \<longleftrightarrow> (finite A \<and> (\<exists>i\<in>A. f i = 0))"
1.842 -proof cases
1.843 -  assume "finite A"
1.844 +  shows "(\<Prod>i\<in>A. f i) = 0 \<longleftrightarrow> finite A \<and> (\<exists>i\<in>A. f i = 0)"
1.845 +proof (cases "finite A")
1.846 +  case True
1.847    then show ?thesis by (induct A) auto
1.848 -qed auto
1.849 +next
1.850 +  case False
1.851 +  then show ?thesis by auto
1.852 +qed
1.853
1.854  lemma setprod_ereal_pos:
1.855 -  fixes f :: "'a \<Rightarrow> ereal" assumes pos: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" shows "0 \<le> (\<Prod>i\<in>I. f i)"
1.856 -proof cases
1.857 -  assume "finite I" from this pos show ?thesis by induct auto
1.858 -qed simp
1.859 +  fixes f :: "'a \<Rightarrow> ereal"
1.860 +  assumes pos: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
1.861 +  shows "0 \<le> (\<Prod>i\<in>I. f i)"
1.862 +proof (cases "finite I")
1.863 +  case True
1.864 +  from this pos show ?thesis
1.865 +    by induct auto
1.866 +next
1.867 +  case False
1.868 +  then show ?thesis by simp
1.869 +qed
1.870
1.871  lemma setprod_PInf:
1.872    fixes f :: "'a \<Rightarrow> ereal"
1.873    assumes "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
1.874    shows "(\<Prod>i\<in>I. f i) = \<infinity> \<longleftrightarrow> finite I \<and> (\<exists>i\<in>I. f i = \<infinity>) \<and> (\<forall>i\<in>I. f i \<noteq> 0)"
1.875 -proof cases
1.876 -  assume "finite I" from this assms show ?thesis
1.877 +proof (cases "finite I")
1.878 +  case True
1.879 +  from this assms show ?thesis
1.880    proof (induct I)
1.881      case (insert i I)
1.882 -    then have pos: "0 \<le> f i" "0 \<le> setprod f I" by (auto intro!: setprod_ereal_pos)
1.883 -    from insert have "(\<Prod>j\<in>insert i I. f j) = \<infinity> \<longleftrightarrow> setprod f I * f i = \<infinity>" by auto
1.884 +    then have pos: "0 \<le> f i" "0 \<le> setprod f I"
1.885 +      by (auto intro!: setprod_ereal_pos)
1.886 +    from insert have "(\<Prod>j\<in>insert i I. f j) = \<infinity> \<longleftrightarrow> setprod f I * f i = \<infinity>"
1.887 +      by auto
1.888      also have "\<dots> \<longleftrightarrow> (setprod f I = \<infinity> \<or> f i = \<infinity>) \<and> f i \<noteq> 0 \<and> setprod f I \<noteq> 0"
1.889        using setprod_ereal_pos[of I f] pos
1.890        by (cases rule: ereal2_cases[of "f i" "setprod f I"]) auto
1.891 @@ -745,13 +889,22 @@
1.892        using insert by (auto simp: setprod_ereal_0)
1.893      finally show ?case .
1.894    qed simp
1.895 -qed simp
1.896 +next
1.897 +  case False
1.898 +  then show ?thesis by simp
1.899 +qed
1.900
1.901  lemma setprod_ereal: "(\<Prod>i\<in>A. ereal (f i)) = ereal (setprod f A)"
1.902 -proof cases
1.903 -  assume "finite A" then show ?thesis
1.904 +proof (cases "finite A")
1.905 +  case True
1.906 +  then show ?thesis
1.907      by induct (auto simp: one_ereal_def)
1.909 +next
1.910 +  case False
1.911 +  then show ?thesis
1.912 +    by (simp add: one_ereal_def)
1.913 +qed
1.914 +
1.915
1.916  subsubsection {* Power *}
1.917
1.918 @@ -771,10 +924,12 @@
1.919    by (induct n) (auto simp: one_ereal_def)
1.920
1.921  lemma zero_le_power_ereal[simp]:
1.922 -  fixes a :: ereal assumes "0 \<le> a"
1.923 +  fixes a :: ereal
1.924 +  assumes "0 \<le> a"
1.925    shows "0 \<le> a ^ n"
1.926    using assms by (induct n) (auto simp: ereal_zero_le_0_iff)
1.927
1.928 +
1.929  subsubsection {* Subtraction *}
1.930
1.931  lemma ereal_minus_minus_image[simp]:
1.932 @@ -783,25 +938,30 @@
1.933    by (auto simp: image_iff)
1.934
1.935  lemma ereal_uminus_lessThan[simp]:
1.936 -  fixes a :: ereal shows "uminus ` {..<a} = {-a<..}"
1.937 +  fixes a :: ereal
1.938 +  shows "uminus ` {..<a} = {-a<..}"
1.939  proof -
1.940    {
1.941 -    fix x assume "-a < x"
1.942 -    then have "- x < - (- a)" by (simp del: ereal_uminus_uminus)
1.943 -    then have "- x < a" by simp
1.944 +    fix x
1.945 +    assume "-a < x"
1.946 +    then have "- x < - (- a)"
1.947 +      by (simp del: ereal_uminus_uminus)
1.948 +    then have "- x < a"
1.949 +      by simp
1.950    }
1.951 -  then show ?thesis by (auto intro!: image_eqI)
1.952 +  then show ?thesis
1.953 +    by (auto intro!: image_eqI)
1.954  qed
1.955
1.956 -lemma ereal_uminus_greaterThan[simp]:
1.957 -  "uminus ` {(a::ereal)<..} = {..<-a}"
1.958 -  by (metis ereal_uminus_lessThan ereal_uminus_uminus
1.959 -            ereal_minus_minus_image)
1.960 +lemma ereal_uminus_greaterThan[simp]: "uminus ` {(a::ereal)<..} = {..<-a}"
1.961 +  by (metis ereal_uminus_lessThan ereal_uminus_uminus ereal_minus_minus_image)
1.962
1.963  instantiation ereal :: minus
1.964  begin
1.965 +
1.966  definition "x - y = x + -(y::ereal)"
1.967  instance ..
1.968 +
1.969  end
1.970
1.971  lemma ereal_minus[simp]:
1.972 @@ -815,8 +975,7 @@
1.973    "0 - x = -x"
1.975
1.976 -lemma ereal_x_minus_x[simp]:
1.977 -  "x - x = (if \<bar>x\<bar> = \<infinity> then \<infinity> else 0::ereal)"
1.978 +lemma ereal_x_minus_x[simp]: "x - x = (if \<bar>x\<bar> = \<infinity> then \<infinity> else 0::ereal)"
1.979    by (cases x) simp_all
1.980
1.981  lemma ereal_eq_minus_iff:
1.982 @@ -848,9 +1007,7 @@
1.983
1.984  lemma ereal_le_minus_iff:
1.985    fixes x y z :: ereal
1.986 -  shows "x \<le> z - y \<longleftrightarrow>
1.987 -    (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>) \<and>
1.988 -    (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x + y \<le> z)"
1.989 +  shows "x \<le> z - y \<longleftrightarrow> (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>) \<and> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x + y \<le> z)"
1.990    by (cases rule: ereal3_cases[of x y z]) auto
1.991
1.992  lemma ereal_le_minus:
1.993 @@ -860,9 +1017,7 @@
1.994
1.995  lemma ereal_minus_less_iff:
1.996    fixes x y z :: ereal
1.997 -  shows "x - y < z \<longleftrightarrow>
1.998 -    y \<noteq> -\<infinity> \<and> (y = \<infinity> \<longrightarrow> x \<noteq> \<infinity> \<and> z \<noteq> -\<infinity>) \<and>
1.999 -    (y \<noteq> \<infinity> \<longrightarrow> x < z + y)"
1.1000 +  shows "x - y < z \<longleftrightarrow> y \<noteq> -\<infinity> \<and> (y = \<infinity> \<longrightarrow> x \<noteq> \<infinity> \<and> z \<noteq> -\<infinity>) \<and> (y \<noteq> \<infinity> \<longrightarrow> x < z + y)"
1.1001    by (cases rule: ereal3_cases[of x y z]) auto
1.1002
1.1003  lemma ereal_minus_less:
1.1004 @@ -917,31 +1072,40 @@
1.1005
1.1006  lemma ereal_between:
1.1007    fixes x e :: ereal
1.1008 -  assumes "\<bar>x\<bar> \<noteq> \<infinity>" "0 < e"
1.1009 -  shows "x - e < x" "x < x + e"
1.1010 -using assms apply (cases x, cases e) apply auto
1.1011 -using assms apply (cases x, cases e) apply auto
1.1012 -done
1.1013 +  assumes "\<bar>x\<bar> \<noteq> \<infinity>"
1.1014 +    and "0 < e"
1.1015 +  shows "x - e < x"
1.1016 +    and "x < x + e"
1.1017 +  using assms
1.1018 +  apply (cases x, cases e)
1.1019 +  apply auto
1.1020 +  using assms
1.1021 +  apply (cases x, cases e)
1.1022 +  apply auto
1.1023 +  done
1.1024
1.1025  lemma ereal_minus_eq_PInfty_iff:
1.1026 -  fixes x y :: ereal shows "x - y = \<infinity> \<longleftrightarrow> y = -\<infinity> \<or> x = \<infinity>"
1.1027 +  fixes x y :: ereal
1.1028 +  shows "x - y = \<infinity> \<longleftrightarrow> y = -\<infinity> \<or> x = \<infinity>"
1.1029    by (cases x y rule: ereal2_cases) simp_all
1.1030
1.1031 +
1.1032  subsubsection {* Division *}
1.1033
1.1034  instantiation ereal :: inverse
1.1035  begin
1.1036
1.1037  function inverse_ereal where
1.1038 -"inverse (ereal r) = (if r = 0 then \<infinity> else ereal (inverse r))" |
1.1039 -"inverse (\<infinity>::ereal) = 0" |
1.1040 -"inverse (-\<infinity>::ereal) = 0"
1.1041 +  "inverse (ereal r) = (if r = 0 then \<infinity> else ereal (inverse r))"
1.1042 +| "inverse (\<infinity>::ereal) = 0"
1.1043 +| "inverse (-\<infinity>::ereal) = 0"
1.1044    by (auto intro: ereal_cases)
1.1045  termination by (relation "{}") simp
1.1046
1.1047  definition "x / y = x * inverse (y :: ereal)"
1.1048
1.1049  instance ..
1.1050 +
1.1051  end
1.1052
1.1053  lemma real_of_ereal_inverse[simp]:
1.1054 @@ -959,53 +1123,61 @@
1.1055    unfolding divide_ereal_def by (auto simp: divide_real_def)
1.1056
1.1057  lemma ereal_divide_same[simp]:
1.1058 -  fixes x :: ereal shows "x / x = (if \<bar>x\<bar> = \<infinity> \<or> x = 0 then 0 else 1)"
1.1059 -  by (cases x)
1.1060 -     (simp_all add: divide_real_def divide_ereal_def one_ereal_def)
1.1061 +  fixes x :: ereal
1.1062 +  shows "x / x = (if \<bar>x\<bar> = \<infinity> \<or> x = 0 then 0 else 1)"
1.1063 +  by (cases x) (simp_all add: divide_real_def divide_ereal_def one_ereal_def)
1.1064
1.1065  lemma ereal_inv_inv[simp]:
1.1066 -  fixes x :: ereal shows "inverse (inverse x) = (if x \<noteq> -\<infinity> then x else \<infinity>)"
1.1067 +  fixes x :: ereal
1.1068 +  shows "inverse (inverse x) = (if x \<noteq> -\<infinity> then x else \<infinity>)"
1.1069    by (cases x) auto
1.1070
1.1071  lemma ereal_inverse_minus[simp]:
1.1072 -  fixes x :: ereal shows "inverse (- x) = (if x = 0 then \<infinity> else -inverse x)"
1.1073 +  fixes x :: ereal
1.1074 +  shows "inverse (- x) = (if x = 0 then \<infinity> else -inverse x)"
1.1075    by (cases x) simp_all
1.1076
1.1077  lemma ereal_uminus_divide[simp]:
1.1078 -  fixes x y :: ereal shows "- x / y = - (x / y)"
1.1079 +  fixes x y :: ereal
1.1080 +  shows "- x / y = - (x / y)"
1.1081    unfolding divide_ereal_def by simp
1.1082
1.1083  lemma ereal_divide_Infty[simp]:
1.1084 -  fixes x :: ereal shows "x / \<infinity> = 0" "x / -\<infinity> = 0"
1.1085 +  fixes x :: ereal
1.1086 +  shows "x / \<infinity> = 0" "x / -\<infinity> = 0"
1.1087    unfolding divide_ereal_def by simp_all
1.1088
1.1089 -lemma ereal_divide_one[simp]:
1.1090 -  "x / 1 = (x::ereal)"
1.1091 +lemma ereal_divide_one[simp]: "x / 1 = (x::ereal)"
1.1092    unfolding divide_ereal_def by simp
1.1093
1.1094 -lemma ereal_divide_ereal[simp]:
1.1095 -  "\<infinity> / ereal r = (if 0 \<le> r then \<infinity> else -\<infinity>)"
1.1096 +lemma ereal_divide_ereal[simp]: "\<infinity> / ereal r = (if 0 \<le> r then \<infinity> else -\<infinity>)"
1.1097    unfolding divide_ereal_def by simp
1.1098
1.1099  lemma zero_le_divide_ereal[simp]:
1.1100 -  fixes a :: ereal assumes "0 \<le> a" "0 \<le> b"
1.1101 +  fixes a :: ereal
1.1102 +  assumes "0 \<le> a"
1.1103 +    and "0 \<le> b"
1.1104    shows "0 \<le> a / b"
1.1105    using assms by (cases rule: ereal2_cases[of a b]) (auto simp: zero_le_divide_iff)
1.1106
1.1107  lemma ereal_le_divide_pos:
1.1108 -  fixes x y z :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> x * y \<le> z"
1.1109 +  fixes x y z :: ereal
1.1110 +  shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> x * y \<le> z"
1.1111    by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
1.1112
1.1113  lemma ereal_divide_le_pos:
1.1114 -  fixes x y z :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> z \<le> x * y"
1.1115 +  fixes x y z :: ereal
1.1116 +  shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> z \<le> x * y"
1.1117    by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
1.1118
1.1119  lemma ereal_le_divide_neg:
1.1120 -  fixes x y z :: ereal shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> z \<le> x * y"
1.1121 +  fixes x y z :: ereal
1.1122 +  shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> z \<le> x * y"
1.1123    by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
1.1124
1.1125  lemma ereal_divide_le_neg:
1.1126 -  fixes x y z :: ereal shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> x * y \<le> z"
1.1127 +  fixes x y z :: ereal
1.1128 +  shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> x * y \<le> z"
1.1129    by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
1.1130
1.1131  lemma ereal_inverse_antimono_strict:
1.1132 @@ -1015,31 +1187,37 @@
1.1133
1.1134  lemma ereal_inverse_antimono:
1.1135    fixes x y :: ereal
1.1136 -  shows "0 \<le> x \<Longrightarrow> x <= y \<Longrightarrow> inverse y <= inverse x"
1.1137 +  shows "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> inverse y \<le> inverse x"
1.1138    by (cases rule: ereal2_cases[of x y]) auto
1.1139
1.1140  lemma inverse_inverse_Pinfty_iff[simp]:
1.1141 -  fixes x :: ereal shows "inverse x = \<infinity> \<longleftrightarrow> x = 0"
1.1142 +  fixes x :: ereal
1.1143 +  shows "inverse x = \<infinity> \<longleftrightarrow> x = 0"
1.1144    by (cases x) auto
1.1145
1.1146  lemma ereal_inverse_eq_0:
1.1147 -  fixes x :: ereal shows "inverse x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity>"
1.1148 +  fixes x :: ereal
1.1149 +  shows "inverse x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity>"
1.1150    by (cases x) auto
1.1151
1.1152  lemma ereal_0_gt_inverse:
1.1153 -  fixes x :: ereal shows "0 < inverse x \<longleftrightarrow> x \<noteq> \<infinity> \<and> 0 \<le> x"
1.1154 +  fixes x :: ereal
1.1155 +  shows "0 < inverse x \<longleftrightarrow> x \<noteq> \<infinity> \<and> 0 \<le> x"
1.1156    by (cases x) auto
1.1157
1.1158  lemma ereal_mult_less_right:
1.1159    fixes a b c :: ereal
1.1160 -  assumes "b * a < c * a" "0 < a" "a < \<infinity>"
1.1161 +  assumes "b * a < c * a"
1.1162 +    and "0 < a"
1.1163 +    and "a < \<infinity>"
1.1164    shows "b < c"
1.1165    using assms
1.1166    by (cases rule: ereal3_cases[of a b c])
1.1167       (auto split: split_if_asm simp: zero_less_mult_iff zero_le_mult_iff)
1.1168
1.1169  lemma ereal_power_divide:
1.1170 -  fixes x y :: ereal shows "y \<noteq> 0 \<Longrightarrow> (x / y) ^ n = x^n / y^n"
1.1171 +  fixes x y :: ereal
1.1172 +  shows "y \<noteq> 0 \<Longrightarrow> (x / y) ^ n = x^n / y^n"
1.1173    by (cases rule: ereal2_cases[of x y])
1.1174       (auto simp: one_ereal_def zero_ereal_def power_divide not_le
1.1175                   power_less_zero_eq zero_le_power_iff)
1.1176 @@ -1047,36 +1225,47 @@
1.1177  lemma ereal_le_mult_one_interval:
1.1178    fixes x y :: ereal
1.1179    assumes y: "y \<noteq> -\<infinity>"
1.1180 -  assumes z: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
1.1181 +  assumes z: "\<And>z. 0 < z \<Longrightarrow> z < 1 \<Longrightarrow> z * x \<le> y"
1.1182    shows "x \<le> y"
1.1183  proof (cases x)
1.1184 -  case PInf with z[of "1 / 2"] show "x \<le> y" by (simp add: one_ereal_def)
1.1185 +  case PInf
1.1186 +  with z[of "1 / 2"] show "x \<le> y"
1.1187 +    by (simp add: one_ereal_def)
1.1188  next
1.1189 -  case (real r) note r = this
1.1190 +  case (real r)
1.1191 +  note r = this
1.1192    show "x \<le> y"
1.1193    proof (cases y)
1.1194 -    case (real p) note p = this
1.1195 +    case (real p)
1.1196 +    note p = this
1.1197      have "r \<le> p"
1.1198      proof (rule field_le_mult_one_interval)
1.1199 -      fix z :: real assume "0 < z" and "z < 1"
1.1200 -      with z[of "ereal z"]
1.1201 -      show "z * r \<le> p" using p r by (auto simp: zero_le_mult_iff one_ereal_def)
1.1202 +      fix z :: real
1.1203 +      assume "0 < z" and "z < 1"
1.1204 +      with z[of "ereal z"] show "z * r \<le> p"
1.1205 +        using p r by (auto simp: zero_le_mult_iff one_ereal_def)
1.1206      qed
1.1207 -    then show "x \<le> y" using p r by simp
1.1208 +    then show "x \<le> y"
1.1209 +      using p r by simp
1.1210    qed (insert y, simp_all)
1.1211  qed simp
1.1212
1.1213  lemma ereal_divide_right_mono[simp]:
1.1214    fixes x y z :: ereal
1.1215 -  assumes "x \<le> y" "0 < z" shows "x / z \<le> y / z"
1.1216 -using assms by (cases x y z rule: ereal3_cases) (auto intro: divide_right_mono)
1.1217 +  assumes "x \<le> y"
1.1218 +    and "0 < z"
1.1219 +  shows "x / z \<le> y / z"
1.1220 +  using assms by (cases x y z rule: ereal3_cases) (auto intro: divide_right_mono)
1.1221
1.1222  lemma ereal_divide_left_mono[simp]:
1.1223    fixes x y z :: ereal
1.1224 -  assumes "y \<le> x" "0 < z" "0 < x * y"
1.1225 +  assumes "y \<le> x"
1.1226 +    and "0 < z"
1.1227 +    and "0 < x * y"
1.1228    shows "z / x \<le> z / y"
1.1229 -using assms by (cases x y z rule: ereal3_cases)
1.1230 -  (auto intro: divide_left_mono simp: field_simps sign_simps split: split_if_asm)
1.1231 +  using assms
1.1232 +  by (cases x y z rule: ereal3_cases)
1.1233 +    (auto intro: divide_left_mono simp: field_simps sign_simps split: split_if_asm)
1.1234
1.1235  lemma ereal_divide_zero_left[simp]:
1.1236    fixes a :: ereal
1.1237 @@ -1088,13 +1277,16 @@
1.1238    shows "b / c * a = b * a / c"
1.1239    by (cases a b c rule: ereal3_cases) (auto simp: field_simps sign_simps)
1.1240
1.1241 +
1.1242  subsection "Complete lattice"
1.1243
1.1244  instantiation ereal :: lattice
1.1245  begin
1.1246 +
1.1247  definition [simp]: "sup x y = (max x y :: ereal)"
1.1248  definition [simp]: "inf x y = (min x y :: ereal)"
1.1249  instance by default simp_all
1.1250 +
1.1251  end
1.1252
1.1253  instantiation ereal :: complete_lattice
1.1254 @@ -1109,29 +1301,46 @@
1.1255  lemma ereal_complete_Sup:
1.1256    fixes S :: "ereal set"
1.1257    shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>S. y \<le> z) \<longrightarrow> x \<le> z)"
1.1258 -proof cases
1.1259 -  assume "\<exists>x. \<forall>a\<in>S. a \<le> ereal x"
1.1260 -  then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> ereal y" by auto
1.1261 -  then have "\<infinity> \<notin> S" by force
1.1262 +proof (cases "\<exists>x. \<forall>a\<in>S. a \<le> ereal x")
1.1263 +  case True
1.1264 +  then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> ereal y"
1.1265 +    by auto
1.1266 +  then have "\<infinity> \<notin> S"
1.1267 +    by force
1.1268    show ?thesis
1.1269 -  proof cases
1.1270 -    assume "S \<noteq> {-\<infinity>} \<and> S \<noteq> {}"
1.1271 -    with `\<infinity> \<notin> S` obtain x where x: "x \<in> S" "\<bar>x\<bar> \<noteq> \<infinity>" by auto
1.1272 +  proof (cases "S \<noteq> {-\<infinity>} \<and> S \<noteq> {}")
1.1273 +    case True
1.1274 +    with `\<infinity> \<notin> S` obtain x where x: "x \<in> S" "\<bar>x\<bar> \<noteq> \<infinity>"
1.1275 +      by auto
1.1276      obtain s where s: "\<forall>x\<in>ereal -` S. x \<le> s" "\<And>z. (\<forall>x\<in>ereal -` S. x \<le> z) \<Longrightarrow> s \<le> z"
1.1277      proof (atomize_elim, rule complete_real)
1.1278 -      show "\<exists>x. x \<in> ereal -` S" using x by auto
1.1279 -      show "\<exists>z. \<forall>x\<in>ereal -` S. x \<le> z" by (auto dest: y intro!: exI[of _ y])
1.1280 +      show "\<exists>x. x \<in> ereal -` S"
1.1281 +        using x by auto
1.1282 +      show "\<exists>z. \<forall>x\<in>ereal -` S. x \<le> z"
1.1283 +        by (auto dest: y intro!: exI[of _ y])
1.1284      qed
1.1285      show ?thesis
1.1286      proof (safe intro!: exI[of _ "ereal s"])
1.1287 -      fix y assume "y \<in> S" with s `\<infinity> \<notin> S` show "y \<le> ereal s"
1.1288 +      fix y
1.1289 +      assume "y \<in> S"
1.1290 +      with s `\<infinity> \<notin> S` show "y \<le> ereal s"
1.1291          by (cases y) auto
1.1292      next
1.1293 -      fix z assume "\<forall>y\<in>S. y \<le> z" with `S \<noteq> {-\<infinity>} \<and> S \<noteq> {}` show "ereal s \<le> z"
1.1294 +      fix z
1.1295 +      assume "\<forall>y\<in>S. y \<le> z"
1.1296 +      with `S \<noteq> {-\<infinity>} \<and> S \<noteq> {}` show "ereal s \<le> z"
1.1297          by (cases z) (auto intro!: s)
1.1298      qed
1.1299 -  qed (auto intro!: exI[of _ "-\<infinity>"])
1.1300 -qed (fastforce intro!: exI[of _ \<infinity>] ereal_top intro: order_trans dest: less_imp_le simp: not_le)
1.1301 +  next
1.1302 +    case False
1.1303 +    then show ?thesis
1.1304 +      by (auto intro!: exI[of _ "-\<infinity>"])
1.1305 +  qed
1.1306 +next
1.1307 +  case False
1.1308 +  then show ?thesis
1.1309 +    by (fastforce intro!: exI[of _ \<infinity>] ereal_top intro: order_trans dest: less_imp_le simp: not_le)
1.1310 +qed
1.1311
1.1312  lemma ereal_complete_uminus_eq:
1.1313    fixes S :: "ereal set"
1.1314 @@ -1141,23 +1350,24 @@
1.1315
1.1316  lemma ereal_complete_Inf:
1.1317    "\<exists>x. (\<forall>y\<in>S::ereal set. x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> x)"
1.1318 -  using ereal_complete_Sup[of "uminus ` S"] unfolding ereal_complete_uminus_eq by auto
1.1319 +  using ereal_complete_Sup[of "uminus ` S"]
1.1320 +  unfolding ereal_complete_uminus_eq
1.1321 +  by auto
1.1322
1.1323  instance
1.1324  proof
1.1325    show "Sup {} = (bot::ereal)"
1.1326 -  apply (auto simp: bot_ereal_def Sup_ereal_def)
1.1327 -  apply (rule some1_equality)
1.1328 -  apply (metis ereal_bot ereal_less_eq(2))
1.1329 -  apply (metis ereal_less_eq(2))
1.1330 -  done
1.1331 -next
1.1332 +    apply (auto simp: bot_ereal_def Sup_ereal_def)
1.1333 +    apply (rule some1_equality)
1.1334 +    apply (metis ereal_bot ereal_less_eq(2))
1.1335 +    apply (metis ereal_less_eq(2))
1.1336 +    done
1.1337    show "Inf {} = (top::ereal)"
1.1338 -  apply (auto simp: top_ereal_def Inf_ereal_def)
1.1339 -  apply (rule some1_equality)
1.1340 -  apply (metis ereal_top ereal_less_eq(1))
1.1341 -  apply (metis ereal_less_eq(1))
1.1342 -  done
1.1343 +    apply (auto simp: top_ereal_def Inf_ereal_def)
1.1344 +    apply (rule some1_equality)
1.1345 +    apply (metis ereal_top ereal_less_eq(1))
1.1346 +    apply (metis ereal_less_eq(1))
1.1347 +    done
1.1348  qed (auto intro: someI2_ex ereal_complete_Sup ereal_complete_Inf
1.1349    simp: Sup_ereal_def Inf_ereal_def bot_ereal_def top_ereal_def)
1.1350
1.1351 @@ -1183,74 +1393,89 @@
1.1352    using ereal_Sup_uminus_image_eq[of "uminus ` S"] by simp
1.1353
1.1354  lemma ereal_SUPR_uminus:
1.1355 -  fixes f :: "'a => ereal"
1.1356 +  fixes f :: "'a \<Rightarrow> ereal"
1.1357    shows "(SUP i : R. -(f i)) = -(INF i : R. f i)"
1.1358    using ereal_Sup_uminus_image_eq[of "f`R"]
1.1359    by (simp add: SUP_def INF_def image_image)
1.1360
1.1361  lemma ereal_INFI_uminus:
1.1362 -  fixes f :: "'a => ereal"
1.1363 -  shows "(INF i : R. -(f i)) = -(SUP i : R. f i)"
1.1364 +  fixes f :: "'a \<Rightarrow> ereal"
1.1365 +  shows "(INF i : R. - f i) = - (SUP i : R. f i)"
1.1366    using ereal_SUPR_uminus[of _ "\<lambda>x. - f x"] by simp
1.1367
1.1368  lemma ereal_image_uminus_shift:
1.1369 -  fixes X Y :: "ereal set" shows "uminus ` X = Y \<longleftrightarrow> X = uminus ` Y"
1.1370 +  fixes X Y :: "ereal set"
1.1371 +  shows "uminus ` X = Y \<longleftrightarrow> X = uminus ` Y"
1.1372  proof
1.1373    assume "uminus ` X = Y"
1.1374    then have "uminus ` uminus ` X = uminus ` Y"
1.1376 -  then show "X = uminus ` Y" by (simp add: image_image)
1.1377 +  then show "X = uminus ` Y"
1.1378 +    by (simp add: image_image)
1.1380
1.1381  lemma Inf_ereal_iff:
1.1382    fixes z :: ereal
1.1383 -  shows "(!!x. x:X ==> z <= x) ==> (EX x:X. x<y) <-> Inf X < y"
1.1384 -  by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower less_le_not_le linear
1.1385 -            order_less_le_trans)
1.1386 +  shows "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> (\<exists>x\<in>X. x < y) \<longleftrightarrow> Inf X < y"
1.1387 +  by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower
1.1388 +      less_le_not_le linear order_less_le_trans)
1.1389
1.1390  lemma Sup_eq_MInfty:
1.1391 -  fixes S :: "ereal set" shows "Sup S = -\<infinity> \<longleftrightarrow> S = {} \<or> S = {-\<infinity>}"
1.1392 +  fixes S :: "ereal set"
1.1393 +  shows "Sup S = -\<infinity> \<longleftrightarrow> S = {} \<or> S = {-\<infinity>}"
1.1394    unfolding bot_ereal_def[symmetric] by auto
1.1395
1.1396  lemma Inf_eq_PInfty:
1.1397 -  fixes S :: "ereal set" shows "Inf S = \<infinity> \<longleftrightarrow> S = {} \<or> S = {\<infinity>}"
1.1398 +  fixes S :: "ereal set"
1.1399 +  shows "Inf S = \<infinity> \<longleftrightarrow> S = {} \<or> S = {\<infinity>}"
1.1400    using Sup_eq_MInfty[of "uminus`S"]
1.1401    unfolding ereal_Sup_uminus_image_eq ereal_image_uminus_shift by simp
1.1402
1.1403 -lemma Inf_eq_MInfty:
1.1404 -  fixes S :: "ereal set" shows "-\<infinity> \<in> S \<Longrightarrow> Inf S = -\<infinity>"
1.1405 +lemma Inf_eq_MInfty:
1.1406 +  fixes S :: "ereal set"
1.1407 +  shows "-\<infinity> \<in> S \<Longrightarrow> Inf S = -\<infinity>"
1.1408    unfolding bot_ereal_def[symmetric] by auto
1.1409
1.1410  lemma Sup_eq_PInfty:
1.1411 -  fixes S :: "ereal set" shows "\<infinity> \<in> S \<Longrightarrow> Sup S = \<infinity>"
1.1412 +  fixes S :: "ereal set"
1.1413 +  shows "\<infinity> \<in> S \<Longrightarrow> Sup S = \<infinity>"
1.1414    unfolding top_ereal_def[symmetric] by auto
1.1415
1.1416  lemma Sup_ereal_close:
1.1417    fixes e :: ereal
1.1418 -  assumes "0 < e" and S: "\<bar>Sup S\<bar> \<noteq> \<infinity>" "S \<noteq> {}"
1.1419 +  assumes "0 < e"
1.1420 +    and S: "\<bar>Sup S\<bar> \<noteq> \<infinity>" "S \<noteq> {}"
1.1421    shows "\<exists>x\<in>S. Sup S - e < x"
1.1422    using assms by (cases e) (auto intro!: less_Sup_iff[THEN iffD1])
1.1423
1.1424  lemma Inf_ereal_close:
1.1425 -  fixes e :: ereal assumes "\<bar>Inf X\<bar> \<noteq> \<infinity>" "0 < e"
1.1426 +  fixes e :: ereal
1.1427 +  assumes "\<bar>Inf X\<bar> \<noteq> \<infinity>"
1.1428 +    and "0 < e"
1.1429    shows "\<exists>x\<in>X. x < Inf X + e"
1.1430  proof (rule Inf_less_iff[THEN iffD1])
1.1431 -  show "Inf X < Inf X + e" using assms
1.1432 -    by (cases e) auto
1.1433 +  show "Inf X < Inf X + e"
1.1434 +    using assms by (cases e) auto
1.1435  qed
1.1436
1.1437  lemma SUP_nat_Infty: "(SUP i::nat. ereal (real i)) = \<infinity>"
1.1438  proof -
1.1439 -  { fix x ::ereal assume "x \<noteq> \<infinity>"
1.1440 +  {
1.1441 +    fix x :: ereal
1.1442 +    assume "x \<noteq> \<infinity>"
1.1443      then have "\<exists>k::nat. x < ereal (real k)"
1.1444      proof (cases x)
1.1445 -      case MInf then show ?thesis by (intro exI[of _ 0]) auto
1.1446 +      case MInf
1.1447 +      then show ?thesis
1.1448 +        by (intro exI[of _ 0]) auto
1.1449      next
1.1450        case (real r)
1.1451        moreover obtain k :: nat where "r < real k"
1.1452          using ex_less_of_nat by (auto simp: real_eq_of_nat)
1.1453 -      ultimately show ?thesis by auto
1.1454 -    qed simp }
1.1455 +      ultimately show ?thesis
1.1456 +        by auto
1.1457 +    qed simp
1.1458 +  }
1.1459    then show ?thesis
1.1460      using SUP_eq_top_iff[of UNIV "\<lambda>n::nat. ereal (real n)"]
1.1461      by (auto simp: top_ereal_def)
1.1462 @@ -1259,96 +1484,136 @@
1.1463  lemma Inf_less:
1.1464    fixes x :: ereal
1.1465    assumes "(INF i:A. f i) < x"
1.1466 -  shows "EX i. i : A & f i <= x"
1.1467 -proof(rule ccontr)
1.1468 -  assume "~ (EX i. i : A & f i <= x)"
1.1469 -  hence "ALL i:A. f i > x" by auto
1.1470 -  hence "(INF i:A. f i) >= x" apply (subst INF_greatest) by auto
1.1471 -  thus False using assms by auto
1.1472 +  shows "\<exists>i. i \<in> A \<and> f i \<le> x"
1.1473 +proof (rule ccontr)
1.1474 +  assume "\<not> ?thesis"
1.1475 +  then have "\<forall>i\<in>A. f i > x"
1.1476 +    by auto
1.1477 +  then have "(INF i:A. f i) \<ge> x"
1.1478 +    by (subst INF_greatest) auto
1.1479 +  then show False
1.1480 +    using assms by auto
1.1481  qed
1.1482
1.1484    fixes f :: "'i \<Rightarrow> ereal"
1.1485 -  assumes "\<And>i. f i + y \<le> z" and "y \<noteq> -\<infinity>"
1.1486 +  assumes "\<And>i. f i + y \<le> z"
1.1487 +    and "y \<noteq> -\<infinity>"
1.1488    shows "SUPR UNIV f + y \<le> z"
1.1489  proof (cases y)
1.1490    case (real r)
1.1491 -  then have "\<And>i. f i \<le> z - y" using assms by (simp add: ereal_le_minus_iff)
1.1492 -  then have "SUPR UNIV f \<le> z - y" by (rule SUP_least)
1.1493 -  then show ?thesis using real by (simp add: ereal_le_minus_iff)
1.1494 +  then have "\<And>i. f i \<le> z - y"
1.1495 +    using assms by (simp add: ereal_le_minus_iff)
1.1496 +  then have "SUPR UNIV f \<le> z - y"
1.1497 +    by (rule SUP_least)
1.1498 +  then show ?thesis
1.1499 +    using real by (simp add: ereal_le_minus_iff)
1.1500  qed (insert assms, auto)
1.1501
1.1503    fixes f g :: "nat \<Rightarrow> ereal"
1.1504 -  assumes "incseq f" "incseq g" and pos: "\<And>i. f i \<noteq> -\<infinity>" "\<And>i. g i \<noteq> -\<infinity>"
1.1505 +  assumes "incseq f"
1.1506 +    and "incseq g"
1.1507 +    and pos: "\<And>i. f i \<noteq> -\<infinity>" "\<And>i. g i \<noteq> -\<infinity>"
1.1508    shows "(SUP i. f i + g i) = SUPR UNIV f + SUPR UNIV g"
1.1509  proof (rule SUP_eqI)
1.1510 -  fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> f i + g i \<le> y"
1.1511 -  have f: "SUPR UNIV f \<noteq> -\<infinity>" using pos
1.1512 -    unfolding SUP_def Sup_eq_MInfty by (auto dest: image_eqD)
1.1513 -  { fix j
1.1514 -    { fix i
1.1515 +  fix y
1.1516 +  assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> f i + g i \<le> y"
1.1517 +  have f: "SUPR UNIV f \<noteq> -\<infinity>"
1.1518 +    using pos
1.1519 +    unfolding SUP_def Sup_eq_MInfty
1.1520 +    by (auto dest: image_eqD)
1.1521 +  {
1.1522 +    fix j
1.1523 +    {
1.1524 +      fix i
1.1525        have "f i + g j \<le> f i + g (max i j)"
1.1526 -        using `incseq g`[THEN incseqD] by (rule add_left_mono) auto
1.1527 +        using `incseq g`[THEN incseqD]
1.1528 +        by (rule add_left_mono) auto
1.1529        also have "\<dots> \<le> f (max i j) + g (max i j)"
1.1530 -        using `incseq f`[THEN incseqD] by (rule add_right_mono) auto
1.1531 +        using `incseq f`[THEN incseqD]
1.1532 +        by (rule add_right_mono) auto
1.1533        also have "\<dots> \<le> y" using * by auto
1.1534 -      finally have "f i + g j \<le> y" . }
1.1535 +      finally have "f i + g j \<le> y" .
1.1536 +    }
1.1537      then have "SUPR UNIV f + g j \<le> y"
1.1538        using assms(4)[of j] by (intro SUP_ereal_le_addI) auto
1.1539 -    then have "g j + SUPR UNIV f \<le> y" by (simp add: ac_simps) }
1.1540 +    then have "g j + SUPR UNIV f \<le> y" by (simp add: ac_simps)
1.1541 +  }
1.1542    then have "SUPR UNIV g + SUPR UNIV f \<le> y"
1.1543      using f by (rule SUP_ereal_le_addI)
1.1544 -  then show "SUPR UNIV f + SUPR UNIV g \<le> y" by (simp add: ac_simps)
1.1545 +  then show "SUPR UNIV f + SUPR UNIV g \<le> y"
1.1546 +    by (simp add: ac_simps)
1.1547  qed (auto intro!: add_mono SUP_upper)
1.1548
1.1550    fixes f g :: "nat \<Rightarrow> ereal"
1.1551 -  assumes inc: "incseq f" "incseq g" and pos: "\<And>i. 0 \<le> f i" "\<And>i. 0 \<le> g i"
1.1552 +  assumes inc: "incseq f" "incseq g"
1.1553 +    and pos: "\<And>i. 0 \<le> f i" "\<And>i. 0 \<le> g i"
1.1554    shows "(SUP i. f i + g i) = SUPR UNIV f + SUPR UNIV g"
1.1556 -  fix i show "f i \<noteq> -\<infinity>" "g i \<noteq> -\<infinity>" using pos[of i] by auto
1.1557 +  fix i
1.1558 +  show "f i \<noteq> -\<infinity>" "g i \<noteq> -\<infinity>"
1.1559 +    using pos[of i] by auto
1.1560  qed
1.1561
1.1562  lemma SUPR_ereal_setsum:
1.1563    fixes f g :: "'a \<Rightarrow> nat \<Rightarrow> ereal"
1.1564 -  assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)" and pos: "\<And>n i. n \<in> A \<Longrightarrow> 0 \<le> f n i"
1.1565 +  assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)"
1.1566 +    and pos: "\<And>n i. n \<in> A \<Longrightarrow> 0 \<le> f n i"
1.1567    shows "(SUP i. \<Sum>n\<in>A. f n i) = (\<Sum>n\<in>A. SUPR UNIV (f n))"
1.1568 -proof cases
1.1569 -  assume "finite A" then show ?thesis using assms
1.1570 +proof (cases "finite A")
1.1571 +  case True
1.1572 +  then show ?thesis using assms
1.1573      by induct (auto simp: incseq_setsumI2 setsum_nonneg SUPR_ereal_add_pos)
1.1574 -qed simp
1.1575 +next
1.1576 +  case False
1.1577 +  then show ?thesis by simp
1.1578 +qed
1.1579
1.1580  lemma SUPR_ereal_cmult:
1.1581 -  fixes f :: "nat \<Rightarrow> ereal" assumes "\<And>i. 0 \<le> f i" "0 \<le> c"
1.1582 +  fixes f :: "nat \<Rightarrow> ereal"
1.1583 +  assumes "\<And>i. 0 \<le> f i"
1.1584 +    and "0 \<le> c"
1.1585    shows "(SUP i. c * f i) = c * SUPR UNIV f"
1.1586  proof (rule SUP_eqI)
1.1587 -  fix i have "f i \<le> SUPR UNIV f" by (rule SUP_upper) auto
1.1588 +  fix i
1.1589 +  have "f i \<le> SUPR UNIV f"
1.1590 +    by (rule SUP_upper) auto
1.1591    then show "c * f i \<le> c * SUPR UNIV f"
1.1592      using `0 \<le> c` by (rule ereal_mult_left_mono)
1.1593  next
1.1594 -  fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> c * f i \<le> y"
1.1595 +  fix y
1.1596 +  assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> c * f i \<le> y"
1.1597    show "c * SUPR UNIV f \<le> y"
1.1598 -  proof cases
1.1599 -    assume c: "0 < c \<and> c \<noteq> \<infinity>"
1.1600 +  proof (cases "0 < c \<and> c \<noteq> \<infinity>")
1.1601 +    case True
1.1602      with * have "SUPR UNIV f \<le> y / c"
1.1603        by (intro SUP_least) (auto simp: ereal_le_divide_pos)
1.1604 -    with c show ?thesis
1.1605 +    with True show ?thesis
1.1606        by (auto simp: ereal_le_divide_pos)
1.1607    next
1.1608 -    { assume "c = \<infinity>" have ?thesis
1.1609 -      proof cases
1.1610 -        assume **: "\<forall>i. f i = 0"
1.1611 -        then have "range f = {0}" by auto
1.1612 -        with ** show "c * SUPR UNIV f \<le> y" using *
1.1613 -          by (auto simp: SUP_def min_max.sup_absorb1)
1.1614 +    case False
1.1615 +    {
1.1616 +      assume "c = \<infinity>"
1.1617 +      have ?thesis
1.1618 +      proof (cases "\<forall>i. f i = 0")
1.1619 +        case True
1.1620 +        then have "range f = {0}"
1.1621 +          by auto
1.1622 +        with True show "c * SUPR UNIV f \<le> y"
1.1623 +          using * by (auto simp: SUP_def min_max.sup_absorb1)
1.1624        next
1.1625 -        assume "\<not> (\<forall>i. f i = 0)"
1.1626 -        then obtain i where "f i \<noteq> 0" by auto
1.1627 -        with *[of i] `c = \<infinity>` `0 \<le> f i` show ?thesis by (auto split: split_if_asm)
1.1628 -      qed }
1.1629 -    moreover assume "\<not> (0 < c \<and> c \<noteq> \<infinity>)"
1.1630 -    ultimately show ?thesis using * `0 \<le> c` by auto
1.1631 +        case False
1.1632 +        then obtain i where "f i \<noteq> 0"
1.1633 +          by auto
1.1634 +        with *[of i] `c = \<infinity>` `0 \<le> f i` show ?thesis
1.1635 +          by (auto split: split_if_asm)
1.1636 +      qed
1.1637 +    }
1.1638 +    moreover note False
1.1639 +    ultimately show ?thesis
1.1640 +      using * `0 \<le> c` by auto
1.1641    qed
1.1642  qed
1.1643
1.1644 @@ -1359,15 +1624,21 @@
1.1645    unfolding SUP_def Sup_eq_top_iff[where 'a=ereal, unfolded top_ereal_def]
1.1646    apply simp
1.1647  proof safe
1.1648 -  fix x :: ereal assume "x \<noteq> \<infinity>"
1.1649 +  fix x :: ereal
1.1650 +  assume "x \<noteq> \<infinity>"
1.1651    show "\<exists>i\<in>A. x < f i"
1.1652    proof (cases x)
1.1653 -    case PInf with `x \<noteq> \<infinity>` show ?thesis by simp
1.1654 +    case PInf
1.1655 +    with `x \<noteq> \<infinity>` show ?thesis
1.1656 +      by simp
1.1657    next
1.1658 -    case MInf with assms[of "0"] show ?thesis by force
1.1659 +    case MInf
1.1660 +    with assms[of "0"] show ?thesis
1.1661 +      by force
1.1662    next
1.1663      case (real r)
1.1664 -    with less_PInf_Ex_of_nat[of x] obtain n :: nat where "x < ereal (real n)" by auto
1.1665 +    with less_PInf_Ex_of_nat[of x] obtain n :: nat where "x < ereal (real n)"
1.1666 +      by auto
1.1667      moreover obtain i where "i \<in> A" "ereal (real n) \<le> f i"
1.1668        using assms ..
1.1669      ultimately show ?thesis
1.1670 @@ -1382,7 +1653,8 @@
1.1671    case (real r)
1.1672    have "\<forall>n::nat. \<exists>x. x \<in> A \<and> Sup A < x + 1 / ereal (real n)"
1.1673    proof
1.1674 -    fix n ::nat have "\<exists>x\<in>A. Sup A - 1 / ereal (real n) < x"
1.1675 +    fix n :: nat
1.1676 +    have "\<exists>x\<in>A. Sup A - 1 / ereal (real n) < x"
1.1677        using assms real by (intro Sup_ereal_close) (auto simp: one_ereal_def)
1.1678      then obtain x where "x \<in> A" "Sup A - 1 / ereal (real n) < x" ..
1.1679      then show "\<exists>x. x \<in> A \<and> Sup A < x + 1 / ereal (real n)"
1.1680 @@ -1392,48 +1664,63 @@
1.1681      where f: "\<forall>x. f x \<in> A \<and> Sup A < f x + 1 / ereal (real x)" ..
1.1682    have "SUPR UNIV f = Sup A"
1.1683    proof (rule SUP_eqI)
1.1684 -    fix i show "f i \<le> Sup A" using f
1.1685 -      by (auto intro!: complete_lattice_class.Sup_upper)
1.1686 +    fix i
1.1687 +    show "f i \<le> Sup A"
1.1688 +      using f by (auto intro!: complete_lattice_class.Sup_upper)
1.1689    next
1.1690 -    fix y assume bound: "\<And>i. i \<in> UNIV \<Longrightarrow> f i \<le> y"
1.1691 +    fix y
1.1692 +    assume bound: "\<And>i. i \<in> UNIV \<Longrightarrow> f i \<le> y"
1.1693      show "Sup A \<le> y"
1.1694      proof (rule ereal_le_epsilon, intro allI impI)
1.1695 -      fix e :: ereal assume "0 < e"
1.1696 +      fix e :: ereal
1.1697 +      assume "0 < e"
1.1698        show "Sup A \<le> y + e"
1.1699        proof (cases e)
1.1700          case (real r)
1.1701 -        hence "0 < r" using `0 < e` by auto
1.1702 -        then obtain n ::nat where *: "1 / real n < r" "0 < n"
1.1703 -          using ex_inverse_of_nat_less by (auto simp: real_eq_of_nat inverse_eq_divide)
1.1704 -        have "Sup A \<le> f n + 1 / ereal (real n)" using f[THEN spec, of n]
1.1705 +        then have "0 < r"
1.1706 +          using `0 < e` by auto
1.1707 +        then obtain n :: nat where *: "1 / real n < r" "0 < n"
1.1708 +          using ex_inverse_of_nat_less
1.1709 +          by (auto simp: real_eq_of_nat inverse_eq_divide)
1.1710 +        have "Sup A \<le> f n + 1 / ereal (real n)"
1.1711 +          using f[THEN spec, of n]
1.1712            by auto
1.1713 -        also have "1 / ereal (real n) \<le> e" using real * by (auto simp: one_ereal_def )
1.1714 -        with bound have "f n + 1 / ereal (real n) \<le> y + e" by (rule add_mono) simp
1.1715 +        also have "1 / ereal (real n) \<le> e"
1.1716 +          using real *
1.1717 +          by (auto simp: one_ereal_def )
1.1718 +        with bound have "f n + 1 / ereal (real n) \<le> y + e"
1.1719 +          by (rule add_mono) simp
1.1720          finally show "Sup A \<le> y + e" .
1.1721        qed (insert `0 < e`, auto)
1.1722      qed
1.1723    qed
1.1724 -  with f show ?thesis by (auto intro!: exI[of _ f])
1.1725 +  with f show ?thesis
1.1726 +    by (auto intro!: exI[of _ f])
1.1727  next
1.1728    case PInf
1.1729 -  from `A \<noteq> {}` obtain x where "x \<in> A" by auto
1.1730 +  from `A \<noteq> {}` obtain x where "x \<in> A"
1.1731 +    by auto
1.1732    show ?thesis
1.1733 -  proof cases
1.1734 -    assume *: "\<infinity> \<in> A"
1.1735 -    then have "\<infinity> \<le> Sup A" by (intro complete_lattice_class.Sup_upper)
1.1736 -    with * show ?thesis by (auto intro!: exI[of _ "\<lambda>x. \<infinity>"])
1.1737 +  proof (cases "\<infinity> \<in> A")
1.1738 +    case True
1.1739 +    then have "\<infinity> \<le> Sup A"
1.1740 +      by (intro complete_lattice_class.Sup_upper)
1.1741 +    with True show ?thesis
1.1742 +      by (auto intro!: exI[of _ "\<lambda>x. \<infinity>"])
1.1743    next
1.1744 -    assume "\<infinity> \<notin> A"
1.1745 +    case False
1.1746      have "\<exists>x\<in>A. 0 \<le> x"
1.1747 -      by (metis Infty_neq_0 PInf complete_lattice_class.Sup_least ereal_infty_less_eq2 linorder_linear)
1.1748 -    then obtain x where "x \<in> A" "0 \<le> x" by auto
1.1749 +      by (metis Infty_neq_0 PInf complete_lattice_class.Sup_least
1.1750 +          ereal_infty_less_eq2 linorder_linear)
1.1751 +    then obtain x where "x \<in> A" and "0 \<le> x"
1.1752 +      by auto
1.1753      have "\<forall>n::nat. \<exists>f. f \<in> A \<and> x + ereal (real n) \<le> f"
1.1754      proof (rule ccontr)
1.1755        assume "\<not> ?thesis"
1.1756        then have "\<exists>n::nat. Sup A \<le> x + ereal (real n)"
1.1757          by (simp add: Sup_le_iff not_le less_imp_le Ball_def) (metis less_imp_le)
1.1758        then show False using `x \<in> A` `\<infinity> \<notin> A` PInf
1.1759 -        by(cases x) auto
1.1760 +        by (cases x) auto
1.1761      qed
1.1762      from choice[OF this] obtain f :: "nat \<Rightarrow> ereal"
1.1763        where f: "\<forall>z. f z \<in> A \<and> x + ereal (real z) \<le> f z" ..
1.1764 @@ -1444,20 +1731,26 @@
1.1765          using f[THEN spec, of n] `0 \<le> x`
1.1766          by (cases rule: ereal2_cases[of "f n" x]) (auto intro!: exI[of _ n])
1.1767      qed
1.1768 -    then show ?thesis using f PInf by (auto intro!: exI[of _ f])
1.1769 +    then show ?thesis
1.1770 +      using f PInf by (auto intro!: exI[of _ f])
1.1771    qed
1.1772  next
1.1773    case MInf
1.1774 -  with `A \<noteq> {}` have "A = {-\<infinity>}" by (auto simp: Sup_eq_MInfty)
1.1775 -  then show ?thesis using MInf by (auto intro!: exI[of _ "\<lambda>x. -\<infinity>"])
1.1776 +  with `A \<noteq> {}` have "A = {-\<infinity>}"
1.1777 +    by (auto simp: Sup_eq_MInfty)
1.1778 +  then show ?thesis
1.1779 +    using MInf by (auto intro!: exI[of _ "\<lambda>x. -\<infinity>"])
1.1780  qed
1.1781
1.1782  lemma SUPR_countable_SUPR:
1.1783    "A \<noteq> {} \<Longrightarrow> \<exists>f::nat \<Rightarrow> ereal. range f \<subseteq> g`A \<and> SUPR A g = SUPR UNIV f"
1.1784 -  using Sup_countable_SUPR[of "g`A"] by (auto simp: SUP_def)
1.1785 +  using Sup_countable_SUPR[of "g`A"]
1.1786 +  by (auto simp: SUP_def)
1.1787
1.1789 -  fixes A :: "ereal set" assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>"
1.1790 +  fixes A :: "ereal set"
1.1791 +  assumes "A \<noteq> {}"
1.1792 +    and "a \<noteq> -\<infinity>"
1.1793    shows "Sup ((\<lambda>x. a + x) ` A) = a + Sup A"
1.1794  proof (rule antisym)
1.1795    have *: "\<And>a::ereal. \<And>A. Sup ((\<lambda>x. a + x) ` A) \<le> a + Sup A"
1.1796 @@ -1465,37 +1758,46 @@
1.1797    then show "Sup ((\<lambda>x. a + x) ` A) \<le> a + Sup A" .
1.1798    show "a + Sup A \<le> Sup ((\<lambda>x. a + x) ` A)"
1.1799    proof (cases a)
1.1800 -    case PInf with `A \<noteq> {}` show ?thesis by (auto simp: image_constant min_max.sup_absorb1)
1.1801 +    case PInf with `A \<noteq> {}`
1.1802 +    show ?thesis
1.1803 +      by (auto simp: image_constant min_max.sup_absorb1)
1.1804    next
1.1805      case (real r)
1.1806      then have **: "op + (- a) ` op + a ` A = A"
1.1807        by (auto simp: image_iff ac_simps zero_ereal_def[symmetric])
1.1808 -    from *[of "-a" "(\<lambda>x. a + x) ` A"] real show ?thesis unfolding **
1.1809 +    from *[of "-a" "(\<lambda>x. a + x) ` A"] real show ?thesis
1.1810 +      unfolding **
1.1811        by (cases rule: ereal2_cases[of "Sup A" "Sup (op + a ` A)"]) auto
1.1812    qed (insert `a \<noteq> -\<infinity>`, auto)
1.1813  qed
1.1814
1.1815  lemma Sup_ereal_cminus:
1.1816 -  fixes A :: "ereal set" assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>"
1.1817 +  fixes A :: "ereal set"
1.1818 +  assumes "A \<noteq> {}"
1.1819 +    and "a \<noteq> -\<infinity>"
1.1820    shows "Sup ((\<lambda>x. a - x) ` A) = a - Inf A"
1.1821    using Sup_ereal_cadd[of "uminus ` A" a] assms
1.1822 -  by (simp add: comp_def image_image minus_ereal_def
1.1823 -                 ereal_Sup_uminus_image_eq)
1.1824 +  by (simp add: comp_def image_image minus_ereal_def ereal_Sup_uminus_image_eq)
1.1825
1.1826  lemma SUPR_ereal_cminus:
1.1827    fixes f :: "'i \<Rightarrow> ereal"
1.1828 -  fixes A assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>"
1.1829 +  fixes A
1.1830 +  assumes "A \<noteq> {}"
1.1831 +    and "a \<noteq> -\<infinity>"
1.1832    shows "(SUP x:A. a - f x) = a - (INF x:A. f x)"
1.1833    using Sup_ereal_cminus[of "f`A" a] assms
1.1834    unfolding SUP_def INF_def image_image by auto
1.1835
1.1836  lemma Inf_ereal_cminus:
1.1837 -  fixes A :: "ereal set" assumes "A \<noteq> {}" and "\<bar>a\<bar> \<noteq> \<infinity>"
1.1838 +  fixes A :: "ereal set"
1.1839 +  assumes "A \<noteq> {}"
1.1840 +    and "\<bar>a\<bar> \<noteq> \<infinity>"
1.1841    shows "Inf ((\<lambda>x. a - x) ` A) = a - Sup A"
1.1842  proof -
1.1843    {
1.1844      fix x
1.1845 -    have "-a - -x = -(a - x)" using assms by (cases x) auto
1.1846 +    have "-a - -x = -(a - x)"
1.1847 +      using assms by (cases x) auto
1.1848    } note * = this
1.1849    then have "(\<lambda>x. -a - x)`uminus`A = uminus ` (\<lambda>x. a - x) ` A"
1.1850      by (auto simp: image_image)
1.1851 @@ -1505,25 +1807,32 @@
1.1852  qed
1.1853
1.1854  lemma INFI_ereal_cminus:
1.1855 -  fixes a :: ereal assumes "A \<noteq> {}" and "\<bar>a\<bar> \<noteq> \<infinity>"
1.1856 +  fixes a :: ereal
1.1857 +  assumes "A \<noteq> {}"
1.1858 +    and "\<bar>a\<bar> \<noteq> \<infinity>"
1.1859    shows "(INF x:A. a - f x) = a - (SUP x:A. f x)"
1.1860    using Inf_ereal_cminus[of "f`A" a] assms
1.1861    unfolding SUP_def INF_def image_image
1.1862    by auto
1.1863
1.1865 -  fixes a b :: ereal shows "a \<noteq> \<infinity> \<Longrightarrow> b \<noteq> \<infinity> \<Longrightarrow> - (- a + - b) = a + b"
1.1866 +  fixes a b :: ereal
1.1867 +  shows "a \<noteq> \<infinity> \<Longrightarrow> b \<noteq> \<infinity> \<Longrightarrow> - (- a + - b) = a + b"
1.1868    by (cases rule: ereal2_cases[of a b]) auto
1.1869
1.1871    fixes f :: "nat \<Rightarrow> ereal"
1.1872 -  assumes "decseq f" "decseq g" and fin: "\<And>i. f i \<noteq> \<infinity>" "\<And>i. g i \<noteq> \<infinity>"
1.1873 +  assumes "decseq f" "decseq g"
1.1874 +    and fin: "\<And>i. f i \<noteq> \<infinity>" "\<And>i. g i \<noteq> \<infinity>"
1.1875    shows "(INF i. f i + g i) = INFI UNIV f + INFI UNIV g"
1.1876  proof -
1.1877    have INF_less: "(INF i. f i) < \<infinity>" "(INF i. g i) < \<infinity>"
1.1878      using assms unfolding INF_less_iff by auto
1.1879 -  { fix i from fin[of i] have "- ((- f i) + (- g i)) = f i + g i"
1.1880 -      by (rule uminus_ereal_add_uminus_uminus) }
1.1881 +  {
1.1882 +    fix i
1.1883 +    from fin[of i] have "- ((- f i) + (- g i)) = f i + g i"
1.1885 +  }
1.1886    then have "(INF i. f i + g i) = (INF i. - ((- f i) + (- g i)))"
1.1887      by simp
1.1888    also have "\<dots> = INFI UNIV f + INFI UNIV g"
1.1889 @@ -1534,6 +1843,7 @@
1.1890    finally show ?thesis .
1.1891  qed
1.1892
1.1893 +
1.1894  subsection "Relation to @{typ enat}"
1.1895
1.1896  definition "ereal_of_enat n = (case n of enat n \<Rightarrow> ereal (real n) | \<infinity> \<Rightarrow> \<infinity>)"
1.1897 @@ -1546,50 +1856,41 @@
1.1898    "ereal_of_enat \<infinity> = \<infinity>"
1.1900
1.1901 -lemma ereal_of_enat_le_iff[simp]:
1.1902 -  "ereal_of_enat m \<le> ereal_of_enat n \<longleftrightarrow> m \<le> n"
1.1903 -by (cases m n rule: enat2_cases) auto
1.1904 +lemma ereal_of_enat_le_iff[simp]: "ereal_of_enat m \<le> ereal_of_enat n \<longleftrightarrow> m \<le> n"
1.1905 +  by (cases m n rule: enat2_cases) auto
1.1906
1.1907 -lemma ereal_of_enat_less_iff[simp]:
1.1908 -  "ereal_of_enat m < ereal_of_enat n \<longleftrightarrow> m < n"
1.1909 -by (cases m n rule: enat2_cases) auto
1.1910 +lemma ereal_of_enat_less_iff[simp]: "ereal_of_enat m < ereal_of_enat n \<longleftrightarrow> m < n"
1.1911 +  by (cases m n rule: enat2_cases) auto
1.1912
1.1913 -lemma numeral_le_ereal_of_enat_iff[simp]:
1.1914 -  shows "numeral m \<le> ereal_of_enat n \<longleftrightarrow> numeral m \<le> n"
1.1915 -by (cases n) (auto dest: natceiling_le intro: natceiling_le_eq[THEN iffD1])
1.1916 +lemma numeral_le_ereal_of_enat_iff[simp]: "numeral m \<le> ereal_of_enat n \<longleftrightarrow> numeral m \<le> n"
1.1917 +  by (cases n) (auto dest: natceiling_le intro: natceiling_le_eq[THEN iffD1])
1.1918
1.1919 -lemma numeral_less_ereal_of_enat_iff[simp]:
1.1920 -  shows "numeral m < ereal_of_enat n \<longleftrightarrow> numeral m < n"
1.1921 -by (cases n) (auto simp: real_of_nat_less_iff[symmetric])
1.1922 +lemma numeral_less_ereal_of_enat_iff[simp]: "numeral m < ereal_of_enat n \<longleftrightarrow> numeral m < n"
1.1923 +  by (cases n) (auto simp: real_of_nat_less_iff[symmetric])
1.1924
1.1925 -lemma ereal_of_enat_ge_zero_cancel_iff[simp]:
1.1926 -  "0 \<le> ereal_of_enat n \<longleftrightarrow> 0 \<le> n"
1.1927 -by (cases n) (auto simp: enat_0[symmetric])
1.1928 +lemma ereal_of_enat_ge_zero_cancel_iff[simp]: "0 \<le> ereal_of_enat n \<longleftrightarrow> 0 \<le> n"
1.1929 +  by (cases n) (auto simp: enat_0[symmetric])
1.1930
1.1931 -lemma ereal_of_enat_gt_zero_cancel_iff[simp]:
1.1932 -  "0 < ereal_of_enat n \<longleftrightarrow> 0 < n"
1.1933 -by (cases n) (auto simp: enat_0[symmetric])
1.1934 +lemma ereal_of_enat_gt_zero_cancel_iff[simp]: "0 < ereal_of_enat n \<longleftrightarrow> 0 < n"
1.1935 +  by (cases n) (auto simp: enat_0[symmetric])
1.1936
1.1937 -lemma ereal_of_enat_zero[simp]:
1.1938 -  "ereal_of_enat 0 = 0"
1.1939 -by (auto simp: enat_0[symmetric])
1.1940 +lemma ereal_of_enat_zero[simp]: "ereal_of_enat 0 = 0"
1.1941 +  by (auto simp: enat_0[symmetric])
1.1942
1.1943 -lemma ereal_of_enat_inf[simp]:
1.1944 -  "ereal_of_enat n = \<infinity> \<longleftrightarrow> n = \<infinity>"
1.1945 +lemma ereal_of_enat_inf[simp]: "ereal_of_enat n = \<infinity> \<longleftrightarrow> n = \<infinity>"
1.1946    by (cases n) auto
1.1947
1.1948 -
1.1950 -  "ereal_of_enat (m + n) = ereal_of_enat m + ereal_of_enat n"
1.1951 -by (cases m n rule: enat2_cases) auto
1.1952 +lemma ereal_of_enat_add: "ereal_of_enat (m + n) = ereal_of_enat m + ereal_of_enat n"
1.1953 +  by (cases m n rule: enat2_cases) auto
1.1954
1.1955  lemma ereal_of_enat_sub:
1.1956 -  assumes "n \<le> m" shows "ereal_of_enat (m - n) = ereal_of_enat m - ereal_of_enat n "
1.1957 -using assms by (cases m n rule: enat2_cases) auto
1.1958 +  assumes "n \<le> m"
1.1959 +  shows "ereal_of_enat (m - n) = ereal_of_enat m - ereal_of_enat n "
1.1960 +  using assms by (cases m n rule: enat2_cases) auto
1.1961
1.1962  lemma ereal_of_enat_mult:
1.1963    "ereal_of_enat (m * n) = ereal_of_enat m * ereal_of_enat n"
1.1964 -by (cases m n rule: enat2_cases) auto
1.1965 +  by (cases m n rule: enat2_cases) auto
1.1966
1.1967  lemmas ereal_of_enat_pushin = ereal_of_enat_add ereal_of_enat_sub ereal_of_enat_mult
1.1968  lemmas ereal_of_enat_pushout = ereal_of_enat_pushin[symmetric]
1.1969 @@ -1607,6 +1908,7 @@
1.1970
1.1971  instance
1.1972    by default (simp add: open_ereal_generated)
1.1973 +
1.1974  end
1.1975
1.1976  lemma open_PInfty: "open A \<Longrightarrow> \<infinity> \<in> A \<Longrightarrow> (\<exists>x. {ereal x<..} \<subseteq> A)"
1.1977 @@ -1618,8 +1920,13 @@
1.1978    with Int show ?case
1.1979      by (intro exI[of _ "max x z"]) fastforce
1.1980  next
1.1981 -  { fix x have "x \<noteq> \<infinity> \<Longrightarrow> \<exists>t. x \<le> ereal t" by (cases x) auto }
1.1982 -  moreover case (Basis S)
1.1983 +  case (Basis S)
1.1984 +  {
1.1985 +    fix x
1.1986 +    have "x \<noteq> \<infinity> \<Longrightarrow> \<exists>t. x \<le> ereal t"
1.1987 +      by (cases x) auto
1.1988 +  }
1.1989 +  moreover note Basis
1.1990    ultimately show ?case
1.1991      by (auto split: ereal.split)
1.1992  qed (fastforce simp add: vimage_Union)+
1.1993 @@ -1633,8 +1940,13 @@
1.1994    with Int show ?case
1.1995      by (intro exI[of _ "min x z"]) fastforce
1.1996  next
1.1997 -  { fix x have "x \<noteq> - \<infinity> \<Longrightarrow> \<exists>t. ereal t \<le> x" by (cases x) auto }
1.1998 -  moreover case (Basis S)
1.1999 +  case (Basis S)
1.2000 +  {
1.2001 +    fix x
1.2002 +    have "x \<noteq> - \<infinity> \<Longrightarrow> \<exists>t. ereal t \<le> x"
1.2003 +      by (cases x) auto
1.2004 +  }
1.2005 +  moreover note Basis
1.2006    ultimately show ?case
1.2007      by (auto split: ereal.split)
1.2008  qed (fastforce simp add: vimage_Union)+
1.2009 @@ -1642,13 +1954,18 @@
1.2010  lemma open_ereal_vimage: "open S \<Longrightarrow> open (ereal -` S)"
1.2011    unfolding open_ereal_generated
1.2012  proof (induct rule: generate_topology.induct)
1.2013 -  case (Int A B) then show ?case by auto
1.2014 +  case (Int A B)
1.2015 +  then show ?case
1.2016 +    by auto
1.2017  next
1.2018 -  { fix x have
1.2019 +  case (Basis S)
1.2020 +  {
1.2021 +    fix x have
1.2022        "ereal -` {..<x} = (case x of PInfty \<Rightarrow> UNIV | MInfty \<Rightarrow> {} | ereal r \<Rightarrow> {..<r})"
1.2023        "ereal -` {x<..} = (case x of PInfty \<Rightarrow> {} | MInfty \<Rightarrow> UNIV | ereal r \<Rightarrow> {r<..})"
1.2024 -      by (induct x) auto }
1.2025 -  moreover case (Basis S)
1.2026 +      by (induct x) auto
1.2027 +  }
1.2028 +  moreover note Basis
1.2029    ultimately show ?case
1.2030      by (auto split: ereal.split)
1.2031  qed (fastforce simp add: vimage_Union)+
1.2032 @@ -1657,16 +1974,32 @@
1.2033    unfolding open_generated_order[where 'a=real]
1.2034  proof (induct rule: generate_topology.induct)
1.2035    case (Basis S)
1.2036 -  moreover { fix x have "ereal ` {..< x} = { -\<infinity> <..< ereal x }" by auto (case_tac xa, auto) }
1.2037 -  moreover { fix x have "ereal ` {x <..} = { ereal x <..< \<infinity> }" by auto (case_tac xa, auto) }
1.2038 +  moreover {
1.2039 +    fix x
1.2040 +    have "ereal ` {..< x} = { -\<infinity> <..< ereal x }"
1.2041 +      apply auto
1.2042 +      apply (case_tac xa)
1.2043 +      apply auto
1.2044 +      done
1.2045 +  }
1.2046 +  moreover {
1.2047 +    fix x
1.2048 +    have "ereal ` {x <..} = { ereal x <..< \<infinity> }"
1.2049 +      apply auto
1.2050 +      apply (case_tac xa)
1.2051 +      apply auto
1.2052 +      done
1.2053 +  }
1.2054    ultimately show ?case
1.2055       by auto
1.2056  qed (auto simp add: image_Union image_Int)
1.2057
1.2058 -lemma open_ereal_def: "open A \<longleftrightarrow> open (ereal -` A) \<and> (\<infinity> \<in> A \<longrightarrow> (\<exists>x. {ereal x <..} \<subseteq> A)) \<and> (-\<infinity> \<in> A \<longrightarrow> (\<exists>x. {..<ereal x} \<subseteq> A))"
1.2059 +lemma open_ereal_def:
1.2060 +  "open A \<longleftrightarrow> open (ereal -` A) \<and> (\<infinity> \<in> A \<longrightarrow> (\<exists>x. {ereal x <..} \<subseteq> A)) \<and> (-\<infinity> \<in> A \<longrightarrow> (\<exists>x. {..<ereal x} \<subseteq> A))"
1.2061    (is "open A \<longleftrightarrow> ?rhs")
1.2062  proof
1.2063 -  assume "open A" then show ?rhs
1.2064 +  assume "open A"
1.2065 +  then show ?rhs
1.2066      using open_PInfty open_MInfty open_ereal_vimage by auto
1.2067  next
1.2068    assume "?rhs"
1.2069 @@ -1678,14 +2011,23 @@
1.2070      by (subst *) (auto simp: open_Un)
1.2071  qed
1.2072
1.2073 -lemma open_PInfty2: assumes "open A" "\<infinity> \<in> A" obtains x where "{ereal x<..} \<subseteq> A"
1.2074 +lemma open_PInfty2:
1.2075 +  assumes "open A"
1.2076 +    and "\<infinity> \<in> A"
1.2077 +  obtains x where "{ereal x<..} \<subseteq> A"
1.2078    using open_PInfty[OF assms] by auto
1.2079
1.2080 -lemma open_MInfty2: assumes "open A" "-\<infinity> \<in> A" obtains x where "{..<ereal x} \<subseteq> A"
1.2081 +lemma open_MInfty2:
1.2082 +  assumes "open A"
1.2083 +    and "-\<infinity> \<in> A"
1.2084 +  obtains x where "{..<ereal x} \<subseteq> A"
1.2085    using open_MInfty[OF assms] by auto
1.2086
1.2087 -lemma ereal_openE: assumes "open A" obtains x y where
1.2088 -  "open (ereal -` A)" "\<infinity> \<in> A \<Longrightarrow> {ereal x<..} \<subseteq> A" "-\<infinity> \<in> A \<Longrightarrow> {..<ereal y} \<subseteq> A"
1.2089 +lemma ereal_openE:
1.2090 +  assumes "open A"
1.2091 +  obtains x y where "open (ereal -` A)"
1.2092 +    and "\<infinity> \<in> A \<Longrightarrow> {ereal x<..} \<subseteq> A"
1.2093 +    and "-\<infinity> \<in> A \<Longrightarrow> {..<ereal y} \<subseteq> A"
1.2094    using assms open_ereal_def by auto
1.2095
1.2096  lemmas open_ereal_lessThan = open_lessThan[where 'a=ereal]
1.2097 @@ -1695,60 +2037,76 @@
1.2098  lemmas closed_ereal_atMost = closed_atMost[where 'a=ereal]
1.2099  lemmas closed_ereal_atLeastAtMost = closed_atLeastAtMost[where 'a=ereal]
1.2100  lemmas closed_ereal_singleton = closed_singleton[where 'a=ereal]
1.2101 -
1.2102 +
1.2103  lemma ereal_open_cont_interval:
1.2104    fixes S :: "ereal set"
1.2105 -  assumes "open S" "x \<in> S" "\<bar>x\<bar> \<noteq> \<infinity>"
1.2106 -  obtains e where "e>0" "{x-e <..< x+e} \<subseteq> S"
1.2107 -proof-
1.2108 -  from `open S` have "open (ereal -` S)" by (rule ereal_openE)
1.2109 -  then obtain e where "0 < e" and e: "\<And>y. dist y (real x) < e \<Longrightarrow> ereal y \<in> S"
1.2110 +  assumes "open S"
1.2111 +    and "x \<in> S"
1.2112 +    and "\<bar>x\<bar> \<noteq> \<infinity>"
1.2113 +  obtains e where "e > 0" and "{x-e <..< x+e} \<subseteq> S"
1.2114 +proof -
1.2115 +  from `open S`
1.2116 +  have "open (ereal -` S)"
1.2117 +    by (rule ereal_openE)
1.2118 +  then obtain e where "e > 0" and e: "\<And>y. dist y (real x) < e \<Longrightarrow> ereal y \<in> S"
1.2119      using assms unfolding open_dist by force
1.2120    show thesis
1.2121    proof (intro that subsetI)
1.2122 -    show "0 < ereal e" using `0 < e` by auto
1.2123 -    fix y assume "y \<in> {x - ereal e<..<x + ereal e}"
1.2124 +    show "0 < ereal e"
1.2125 +      using `0 < e` by auto
1.2126 +    fix y
1.2127 +    assume "y \<in> {x - ereal e<..<x + ereal e}"
1.2128      with assms obtain t where "y = ereal t" "dist t (real x) < e"
1.2129 -      apply (cases y) by (auto simp: dist_real_def)
1.2130 -    then show "y \<in> S" using e[of t] by auto
1.2131 +      by (cases y) (auto simp: dist_real_def)
1.2132 +    then show "y \<in> S"
1.2133 +      using e[of t] by auto
1.2134    qed
1.2135  qed
1.2136
1.2137  lemma ereal_open_cont_interval2:
1.2138    fixes S :: "ereal set"
1.2139 -  assumes "open S" "x \<in> S" and x: "\<bar>x\<bar> \<noteq> \<infinity>"
1.2140 -  obtains a b where "a < x" "x < b" "{a <..< b} \<subseteq> S"
1.2141 +  assumes "open S"
1.2142 +    and "x \<in> S"
1.2143 +    and x: "\<bar>x\<bar> \<noteq> \<infinity>"
1.2144 +  obtains a b where "a < x" and "x < b" and "{a <..< b} \<subseteq> S"
1.2145  proof -
1.2146    obtain e where "0 < e" "{x - e<..<x + e} \<subseteq> S"
1.2147      using assms by (rule ereal_open_cont_interval)
1.2148 -  with that[of "x-e" "x+e"] ereal_between[OF x, of e]
1.2149 -  show thesis by auto
1.2150 +  with that[of "x - e" "x + e"] ereal_between[OF x, of e]
1.2151 +  show thesis
1.2152 +    by auto
1.2153  qed
1.2154
1.2155 +
1.2156  subsubsection {* Convergent sequences *}
1.2157
1.2158 -lemma lim_ereal[simp]:
1.2159 -  "((\<lambda>n. ereal (f n)) ---> ereal x) net \<longleftrightarrow> (f ---> x) net" (is "?l = ?r")
1.2160 +lemma lim_ereal[simp]: "((\<lambda>n. ereal (f n)) ---> ereal x) net \<longleftrightarrow> (f ---> x) net"
1.2161 +  (is "?l = ?r")
1.2162  proof (intro iffI topological_tendstoI)
1.2163 -  fix S assume "?l" "open S" "x \<in> S"
1.2164 +  fix S
1.2165 +  assume "?l" and "open S" and "x \<in> S"
1.2166    then show "eventually (\<lambda>x. f x \<in> S) net"
1.2167      using `?l`[THEN topological_tendstoD, OF open_ereal, OF `open S`]
1.2169  next
1.2170 -  fix S assume "?r" "open S" "ereal x \<in> S"
1.2171 +  fix S
1.2172 +  assume "?r" and "open S" and "ereal x \<in> S"
1.2173    show "eventually (\<lambda>x. ereal (f x) \<in> S) net"
1.2174      using `?r`[THEN topological_tendstoD, OF open_ereal_vimage, OF `open S`]
1.2175 -    using `ereal x \<in> S` by auto
1.2176 +    using `ereal x \<in> S`
1.2177 +    by auto
1.2178  qed
1.2179
1.2180  lemma lim_real_of_ereal[simp]:
1.2181    assumes lim: "(f ---> ereal x) net"
1.2182    shows "((\<lambda>x. real (f x)) ---> x) net"
1.2183  proof (intro topological_tendstoI)
1.2184 -  fix S assume "open S" "x \<in> S"
1.2185 +  fix S
1.2186 +  assume "open S" and "x \<in> S"
1.2187    then have S: "open S" "ereal x \<in> ereal ` S"
1.2189 -  have "\<forall>x. f x \<in> ereal ` S \<longrightarrow> real (f x) \<in> S" by auto
1.2190 +  have "\<forall>x. f x \<in> ereal ` S \<longrightarrow> real (f x) \<in> S"
1.2191 +    by auto
1.2192    from this lim[THEN topological_tendstoD, OF open_ereal, OF S]
1.2193    show "eventually (\<lambda>x. real (f x) \<in> S) net"
1.2194      by (rule eventually_mono)
1.2195 @@ -1756,10 +2114,12 @@
1.2196
1.2197  lemma tendsto_PInfty: "(f ---> \<infinity>) F \<longleftrightarrow> (\<forall>r. eventually (\<lambda>x. ereal r < f x) F)"
1.2198  proof -
1.2199 -  { fix l :: ereal assume "\<forall>r. eventually (\<lambda>x. ereal r < f x) F"
1.2200 -    from this[THEN spec, of "real l"]
1.2201 -    have "l \<noteq> \<infinity> \<Longrightarrow> eventually (\<lambda>x. l < f x) F"
1.2202 -      by (cases l) (auto elim: eventually_elim1) }
1.2203 +  {
1.2204 +    fix l :: ereal
1.2205 +    assume "\<forall>r. eventually (\<lambda>x. ereal r < f x) F"
1.2206 +    from this[THEN spec, of "real l"] have "l \<noteq> \<infinity> \<Longrightarrow> eventually (\<lambda>x. l < f x) F"
1.2207 +      by (cases l) (auto elim: eventually_elim1)
1.2208 +  }
1.2209    then show ?thesis
1.2210      by (auto simp: order_tendsto_iff)
1.2211  qed
1.2212 @@ -1772,20 +2132,26 @@
1.2213    from open_MInfty[OF this] obtain B where "{..<ereal B} \<subseteq> S" ..
1.2214    moreover
1.2215    assume "\<forall>r::real. eventually (\<lambda>z. f z < r) F"
1.2216 -  then have "eventually (\<lambda>z. f z \<in> {..< B}) F" by auto
1.2217 -  ultimately show "eventually (\<lambda>z. f z \<in> S) F" by (auto elim!: eventually_elim1)
1.2218 +  then have "eventually (\<lambda>z. f z \<in> {..< B}) F"
1.2219 +    by auto
1.2220 +  ultimately show "eventually (\<lambda>z. f z \<in> S) F"
1.2221 +    by (auto elim!: eventually_elim1)
1.2222  next
1.2223 -  fix x assume "\<forall>S. open S \<longrightarrow> -\<infinity> \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
1.2224 -  from this[rule_format, of "{..< ereal x}"]
1.2225 -  show "eventually (\<lambda>y. f y < ereal x) F" by auto
1.2226 +  fix x
1.2227 +  assume "\<forall>S. open S \<longrightarrow> -\<infinity> \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
1.2228 +  from this[rule_format, of "{..< ereal x}"] show "eventually (\<lambda>y. f y < ereal x) F"
1.2229 +    by auto
1.2230  qed
1.2231
1.2232  lemma Lim_PInfty: "f ----> \<infinity> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. f n \<ge> ereal B)"
1.2233    unfolding tendsto_PInfty eventually_sequentially
1.2234  proof safe
1.2235 -  fix r assume "\<forall>r. \<exists>N. \<forall>n\<ge>N. ereal r \<le> f n"
1.2236 -  then obtain N where "\<forall>n\<ge>N. ereal (r + 1) \<le> f n" by blast
1.2237 -  moreover have "ereal r < ereal (r + 1)" by auto
1.2238 +  fix r
1.2239 +  assume "\<forall>r. \<exists>N. \<forall>n\<ge>N. ereal r \<le> f n"
1.2240 +  then obtain N where "\<forall>n\<ge>N. ereal (r + 1) \<le> f n"
1.2241 +    by blast
1.2242 +  moreover have "ereal r < ereal (r + 1)"
1.2243 +    by auto
1.2244    ultimately show "\<exists>N. \<forall>n\<ge>N. ereal r < f n"
1.2245      by (blast intro: less_le_trans)
1.2246  qed (blast intro: less_imp_le)
1.2247 @@ -1793,9 +2159,12 @@
1.2248  lemma Lim_MInfty: "f ----> -\<infinity> \<longleftrightarrow> (\<forall>B. \<exists>N. \<forall>n\<ge>N. ereal B \<ge> f n)"
1.2249    unfolding tendsto_MInfty eventually_sequentially
1.2250  proof safe
1.2251 -  fix r assume "\<forall>r. \<exists>N. \<forall>n\<ge>N. f n \<le> ereal r"
1.2252 -  then obtain N where "\<forall>n\<ge>N. f n \<le> ereal (r - 1)" by blast
1.2253 -  moreover have "ereal (r - 1) < ereal r" by auto
1.2254 +  fix r
1.2255 +  assume "\<forall>r. \<exists>N. \<forall>n\<ge>N. f n \<le> ereal r"
1.2256 +  then obtain N where "\<forall>n\<ge>N. f n \<le> ereal (r - 1)"
1.2257 +    by blast
1.2258 +  moreover have "ereal (r - 1) < ereal r"
1.2259 +    by auto
1.2260    ultimately show "\<exists>N. \<forall>n\<ge>N. f n < ereal r"
1.2261      by (blast intro: le_less_trans)
1.2262  qed (blast intro: less_imp_le)
1.2263 @@ -1807,38 +2176,43 @@
1.2264    using LIMSEQ_le_const[of f l "ereal B"] by auto
1.2265
1.2266  lemma tendsto_explicit:
1.2267 -  "f ----> f0 <-> (ALL S. open S --> f0 : S --> (EX N. ALL n>=N. f n : S))"
1.2268 +  "f ----> f0 \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> f0 \<in> S \<longrightarrow> (\<exists>N. \<forall>n\<ge>N. f n \<in> S))"
1.2269    unfolding tendsto_def eventually_sequentially by auto
1.2270
1.2271 -lemma Lim_bounded_PInfty2:
1.2272 -  "f ----> l \<Longrightarrow> ALL n>=N. f n <= ereal B \<Longrightarrow> l ~= \<infinity>"
1.2273 +lemma Lim_bounded_PInfty2: "f ----> l \<Longrightarrow> \<forall>n\<ge>N. f n \<le> ereal B \<Longrightarrow> l \<noteq> \<infinity>"
1.2274    using LIMSEQ_le_const2[of f l "ereal B"] by fastforce
1.2275
1.2276 -lemma Lim_bounded_ereal: "f ----> (l :: 'a::linorder_topology) \<Longrightarrow> ALL n>=M. f n <= C \<Longrightarrow> l<=C"
1.2277 +lemma Lim_bounded_ereal: "f ----> (l :: 'a::linorder_topology) \<Longrightarrow> \<forall>n\<ge>M. f n \<le> C \<Longrightarrow> l \<le> C"
1.2278    by (intro LIMSEQ_le_const2) auto
1.2279
1.2280  lemma Lim_bounded2_ereal:
1.2281 -  assumes lim:"f ----> (l :: 'a::linorder_topology)" and ge: "ALL n>=N. f n >= C"
1.2282 -  shows "l>=C"
1.2283 +  assumes lim:"f ----> (l :: 'a::linorder_topology)"
1.2284 +    and ge: "\<forall>n\<ge>N. f n \<ge> C"
1.2285 +  shows "l \<ge> C"
1.2286    using ge
1.2287    by (intro tendsto_le[OF trivial_limit_sequentially lim tendsto_const])
1.2288       (auto simp: eventually_sequentially)
1.2289
1.2290  lemma real_of_ereal_mult[simp]:
1.2291 -  fixes a b :: ereal shows "real (a * b) = real a * real b"
1.2292 +  fixes a b :: ereal
1.2293 +  shows "real (a * b) = real a * real b"
1.2294    by (cases rule: ereal2_cases[of a b]) auto
1.2295
1.2296  lemma real_of_ereal_eq_0:
1.2297 -  fixes x :: ereal shows "real x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity> \<or> x = 0"
1.2298 +  fixes x :: ereal
1.2299 +  shows "real x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity> \<or> x = 0"
1.2300    by (cases x) auto
1.2301
1.2302  lemma tendsto_ereal_realD:
1.2303    fixes f :: "'a \<Rightarrow> ereal"
1.2304 -  assumes "x \<noteq> 0" and tendsto: "((\<lambda>x. ereal (real (f x))) ---> x) net"
1.2305 +  assumes "x \<noteq> 0"
1.2306 +    and tendsto: "((\<lambda>x. ereal (real (f x))) ---> x) net"
1.2307    shows "(f ---> x) net"
1.2308  proof (intro topological_tendstoI)
1.2309 -  fix S assume S: "open S" "x \<in> S"
1.2310 -  with `x \<noteq> 0` have "open (S - {0})" "x \<in> S - {0}" by auto
1.2311 +  fix S
1.2312 +  assume S: "open S" "x \<in> S"
1.2313 +  with `x \<noteq> 0` have "open (S - {0})" "x \<in> S - {0}"
1.2314 +    by auto
1.2315    from tendsto[THEN topological_tendstoD, OF this]
1.2316    show "eventually (\<lambda>x. f x \<in> S) net"
1.2317      by (rule eventually_rev_mp) (auto simp: ereal_real)
1.2318 @@ -1849,22 +2223,25 @@
1.2319    assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and tendsto: "(f ---> x) net"
1.2320    shows "((\<lambda>x. ereal (real (f x))) ---> x) net"
1.2321  proof (intro topological_tendstoI)
1.2322 -  fix S assume "open S" "x \<in> S"
1.2323 -  with x have "open (S - {\<infinity>, -\<infinity>})" "x \<in> S - {\<infinity>, -\<infinity>}" by auto
1.2324 +  fix S
1.2325 +  assume "open S" and "x \<in> S"
1.2326 +  with x have "open (S - {\<infinity>, -\<infinity>})" "x \<in> S - {\<infinity>, -\<infinity>}"
1.2327 +    by auto
1.2328    from tendsto[THEN topological_tendstoD, OF this]
1.2329    show "eventually (\<lambda>x. ereal (real (f x)) \<in> S) net"
1.2330      by (elim eventually_elim1) (auto simp: ereal_real)
1.2331  qed
1.2332
1.2333  lemma ereal_mult_cancel_left:
1.2334 -  fixes a b c :: ereal shows "a * b = a * c \<longleftrightarrow>
1.2335 -    ((\<bar>a\<bar> = \<infinity> \<and> 0 < b * c) \<or> a = 0 \<or> b = c)"
1.2336 -  by (cases rule: ereal3_cases[of a b c])
1.2338 +  fixes a b c :: ereal
1.2339 +  shows "a * b = a * c \<longleftrightarrow> (\<bar>a\<bar> = \<infinity> \<and> 0 < b * c) \<or> a = 0 \<or> b = c"
1.2340 +  by (cases rule: ereal3_cases[of a b c]) (simp_all add: zero_less_mult_iff)
1.2341
1.2342  lemma ereal_inj_affinity:
1.2343    fixes m t :: ereal
1.2344 -  assumes "\<bar>m\<bar> \<noteq> \<infinity>" "m \<noteq> 0" "\<bar>t\<bar> \<noteq> \<infinity>"
1.2345 +  assumes "\<bar>m\<bar> \<noteq> \<infinity>"
1.2346 +    and "m \<noteq> 0"
1.2347 +    and "\<bar>t\<bar> \<noteq> \<infinity>"
1.2348    shows "inj_on (\<lambda>x. m * x + t) A"
1.2349    using assms
1.2350    by (cases rule: ereal2_cases[of m t])
1.2351 @@ -1902,108 +2279,136 @@
1.2352  lemma ereal_mult_m1[simp]: "x * ereal (-1) = -x"
1.2353    by (cases x) auto
1.2354
1.2355 -lemma ereal_real': assumes "\<bar>x\<bar> \<noteq> \<infinity>" shows "ereal (real x) = x"
1.2356 +lemma ereal_real':
1.2357 +  assumes "\<bar>x\<bar> \<noteq> \<infinity>"
1.2358 +  shows "ereal (real x) = x"
1.2359    using assms by auto
1.2360
1.2361 -lemma real_ereal_id: "real o ereal = id"
1.2362 -proof-
1.2363 -  { fix x have "(real o ereal) x = id x" by auto }
1.2364 -  then show ?thesis using ext by blast
1.2365 +lemma real_ereal_id: "real \<circ> ereal = id"
1.2366 +proof -
1.2367 +  {
1.2368 +    fix x
1.2369 +    have "(real o ereal) x = id x"
1.2370 +      by auto
1.2371 +  }
1.2372 +  then show ?thesis
1.2373 +    using ext by blast
1.2374  qed
1.2375
1.2376  lemma open_image_ereal: "open(UNIV-{ \<infinity> , (-\<infinity> :: ereal)})"
1.2377 -by (metis range_ereal open_ereal open_UNIV)
1.2378 +  by (metis range_ereal open_ereal open_UNIV)
1.2379
1.2380  lemma ereal_le_distrib:
1.2381 -  fixes a b c :: ereal shows "c * (a + b) \<le> c * a + c * b"
1.2382 +  fixes a b c :: ereal
1.2383 +  shows "c * (a + b) \<le> c * a + c * b"
1.2384    by (cases rule: ereal3_cases[of a b c])
1.2385       (auto simp add: field_simps not_le mult_le_0_iff mult_less_0_iff)
1.2386
1.2387  lemma ereal_pos_distrib:
1.2388 -  fixes a b c :: ereal assumes "0 \<le> c" "c \<noteq> \<infinity>" shows "c * (a + b) = c * a + c * b"
1.2389 -  using assms by (cases rule: ereal3_cases[of a b c])
1.2390 -                 (auto simp add: field_simps not_le mult_le_0_iff mult_less_0_iff)
1.2391 +  fixes a b c :: ereal
1.2392 +  assumes "0 \<le> c"
1.2393 +    and "c \<noteq> \<infinity>"
1.2394 +  shows "c * (a + b) = c * a + c * b"
1.2395 +  using assms
1.2396 +  by (cases rule: ereal3_cases[of a b c])
1.2397 +    (auto simp add: field_simps not_le mult_le_0_iff mult_less_0_iff)
1.2398
1.2399  lemma ereal_pos_le_distrib:
1.2400 -fixes a b c :: ereal
1.2401 -assumes "c>=0"
1.2402 -shows "c * (a + b) <= c * a + c * b"
1.2403 -  using assms by (cases rule: ereal3_cases[of a b c])
1.2404 -                 (auto simp add: field_simps)
1.2405 +  fixes a b c :: ereal
1.2406 +  assumes "c \<ge> 0"
1.2407 +  shows "c * (a + b) \<le> c * a + c * b"
1.2408 +  using assms
1.2409 +  by (cases rule: ereal3_cases[of a b c]) (auto simp add: field_simps)
1.2410
1.2411 -lemma ereal_max_mono:
1.2412 -  "[| (a::ereal) <= b; c <= d |] ==> max a c <= max b d"
1.2413 +lemma ereal_max_mono: "(a::ereal) \<le> b \<Longrightarrow> c \<le> d \<Longrightarrow> max a c \<le> max b d"
1.2414    by (metis sup_ereal_def sup_mono)
1.2415
1.2416 -
1.2417 -lemma ereal_max_least:
1.2418 -  "[| (a::ereal) <= x; c <= x |] ==> max a c <= x"
1.2419 +lemma ereal_max_least: "(a::ereal) \<le> x \<Longrightarrow> c \<le> x \<Longrightarrow> max a c \<le> x"
1.2420    by (metis sup_ereal_def sup_least)
1.2421
1.2422  lemma ereal_LimI_finite:
1.2423    fixes x :: ereal
1.2424    assumes "\<bar>x\<bar> \<noteq> \<infinity>"
1.2425 -  assumes "!!r. 0 < r ==> EX N. ALL n>=N. u n < x + r & x < u n + r"
1.2426 +    and "\<And>r. 0 < r \<Longrightarrow> \<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r"
1.2427    shows "u ----> x"
1.2428  proof (rule topological_tendstoI, unfold eventually_sequentially)
1.2429 -  obtain rx where rx_def: "x=ereal rx" using assms by (cases x) auto
1.2430 -  fix S assume "open S" "x : S"
1.2431 -  then have "open (ereal -` S)" unfolding open_ereal_def by auto
1.2432 -  with `x \<in> S` obtain r where "0 < r" and dist: "!!y. dist y rx < r ==> ereal y \<in> S"
1.2433 -    unfolding open_real_def rx_def by auto
1.2434 +  obtain rx where rx: "x = ereal rx"
1.2435 +    using assms by (cases x) auto
1.2436 +  fix S
1.2437 +  assume "open S" and "x \<in> S"
1.2438 +  then have "open (ereal -` S)"
1.2439 +    unfolding open_ereal_def by auto
1.2440 +  with `x \<in> S` obtain r where "0 < r" and dist: "\<And>y. dist y rx < r \<Longrightarrow> ereal y \<in> S"
1.2441 +    unfolding open_real_def rx by auto
1.2442    then obtain n where
1.2443 -    upper: "!!N. n <= N ==> u N < x + ereal r" and
1.2444 -    lower: "!!N. n <= N ==> x < u N + ereal r" using assms(2)[of "ereal r"] by auto
1.2445 -  show "EX N. ALL n>=N. u n : S"
1.2446 +    upper: "\<And>N. n \<le> N \<Longrightarrow> u N < x + ereal r" and
1.2447 +    lower: "\<And>N. n \<le> N \<Longrightarrow> x < u N + ereal r"
1.2448 +    using assms(2)[of "ereal r"] by auto
1.2449 +  show "\<exists>N. \<forall>n\<ge>N. u n \<in> S"
1.2450    proof (safe intro!: exI[of _ n])
1.2451 -    fix N assume "n <= N"
1.2452 +    fix N
1.2453 +    assume "n \<le> N"
1.2454      from upper[OF this] lower[OF this] assms `0 < r`
1.2455 -    have "u N ~: {\<infinity>,(-\<infinity>)}" by auto
1.2456 -    then obtain ra where ra_def: "(u N) = ereal ra" by (cases "u N") auto
1.2457 -    hence "rx < ra + r" and "ra < rx + r"
1.2458 -       using rx_def assms `0 < r` lower[OF `n <= N`] upper[OF `n <= N`] by auto
1.2459 -    hence "dist (real (u N)) rx < r"
1.2460 -      using rx_def ra_def
1.2461 +    have "u N \<notin> {\<infinity>,(-\<infinity>)}"
1.2462 +      by auto
1.2463 +    then obtain ra where ra_def: "(u N) = ereal ra"
1.2464 +      by (cases "u N") auto
1.2465 +    then have "rx < ra + r" and "ra < rx + r"
1.2466 +      using rx assms `0 < r` lower[OF `n \<le> N`] upper[OF `n \<le> N`]
1.2467 +      by auto
1.2468 +    then have "dist (real (u N)) rx < r"
1.2469 +      using rx ra_def
1.2470        by (auto simp: dist_real_def abs_diff_less_iff field_simps)
1.2471 -    from dist[OF this] show "u N : S" using `u N  ~: {\<infinity>, -\<infinity>}`
1.2472 +    from dist[OF this] show "u N \<in> S"
1.2473 +      using `u N  \<notin> {\<infinity>, -\<infinity>}`
1.2474        by (auto simp: ereal_real split: split_if_asm)
1.2475    qed
1.2476  qed
1.2477
1.2478  lemma tendsto_obtains_N:
1.2479    assumes "f ----> f0"
1.2480 -  assumes "open S" "f0 : S"
1.2481 -  obtains N where "ALL n>=N. f n : S"
1.2482 +  assumes "open S"
1.2483 +    and "f0 \<in> S"
1.2484 +  obtains N where "\<forall>n\<ge>N. f n \<in> S"
1.2485    using assms using tendsto_def
1.2486    using tendsto_explicit[of f f0] assms by auto
1.2487
1.2488  lemma ereal_LimI_finite_iff:
1.2489    fixes x :: ereal
1.2490    assumes "\<bar>x\<bar> \<noteq> \<infinity>"
1.2491 -  shows "u ----> x <-> (ALL r. 0 < r --> (EX N. ALL n>=N. u n < x + r & x < u n + r))"
1.2492 -  (is "?lhs <-> ?rhs")
1.2493 +  shows "u ----> x \<longleftrightarrow> (\<forall>r. 0 < r \<longrightarrow> (\<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r))"
1.2494 +  (is "?lhs \<longleftrightarrow> ?rhs")
1.2495  proof
1.2496    assume lim: "u ----> x"
1.2497 -  { fix r assume "(r::ereal)>0"
1.2498 -    then obtain N where N_def: "ALL n>=N. u n : {x - r <..< x + r}"
1.2499 +  {
1.2500 +    fix r :: ereal
1.2501 +    assume "r > 0"
1.2502 +    then obtain N where "\<forall>n\<ge>N. u n \<in> {x - r <..< x + r}"
1.2503         apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"])
1.2504 -       using lim ereal_between[of x r] assms `r>0` by auto
1.2505 -    hence "EX N. ALL n>=N. u n < x + r & x < u n + r"
1.2506 -      using ereal_minus_less[of r x] by (cases r) auto
1.2507 -  } then show "?rhs" by auto
1.2508 +       using lim ereal_between[of x r] assms `r > 0`
1.2509 +       apply auto
1.2510 +       done
1.2511 +    then have "\<exists>N. \<forall>n\<ge>N. u n < x + r \<and> x < u n + r"
1.2512 +      using ereal_minus_less[of r x]
1.2513 +      by (cases r) auto
1.2514 +  }
1.2515 +  then show ?rhs
1.2516 +    by auto
1.2517  next
1.2518 -  assume ?rhs then show "u ----> x"
1.2519 +  assume ?rhs
1.2520 +  then show "u ----> x"
1.2521      using ereal_LimI_finite[of x] assms by auto
1.2522  qed
1.2523
1.2524  lemma ereal_Limsup_uminus:
1.2525 -  fixes f :: "'a => ereal"
1.2526 -  shows "Limsup net (\<lambda>x. - (f x)) = -(Liminf net f)"
1.2527 +  fixes f :: "'a \<Rightarrow> ereal"
1.2528 +  shows "Limsup net (\<lambda>x. - (f x)) = - Liminf net f"
1.2529    unfolding Limsup_def Liminf_def ereal_SUPR_uminus ereal_INFI_uminus ..
1.2530
1.2531  lemma liminf_bounded_iff:
1.2532    fixes x :: "nat \<Rightarrow> ereal"
1.2533 -  shows "C \<le> liminf x \<longleftrightarrow> (\<forall>B<C. \<exists>N. \<forall>n\<ge>N. B < x n)" (is "?lhs <-> ?rhs")
1.2534 +  shows "C \<le> liminf x \<longleftrightarrow> (\<forall>B<C. \<exists>N. \<forall>n\<ge>N. B < x n)"
1.2535 +  (is "?lhs \<longleftrightarrow> ?rhs")
1.2536    unfolding le_Liminf_iff eventually_sequentially ..
1.2537
1.2538  lemma
1.2539 @@ -2012,6 +2417,7 @@
1.2540      and ereal_decseq_uminus[simp]: "decseq (\<lambda>i. - X i) = incseq X"
1.2541    unfolding incseq_def decseq_def by auto
1.2542
1.2543 +
1.2544  subsubsection {* Tests for code generator *}
1.2545
1.2546  (* A small list of simple arithmetic expressions *)
```