src/HOL/Library/Extended_Real.thy
author noschinl
Tue Dec 20 11:40:56 2011 +0100 (2011-12-20)
changeset 45934 9321cd2572fe
parent 45769 2d5b1af2426a
child 47082 737d7bc8e50f
permissions -rw-r--r--
add simp rules for enat and ereal
hoelzl@43920
     1
(*  Title:      HOL/Library/Extended_Real.thy
wenzelm@41983
     2
    Author:     Johannes Hölzl, TU München
wenzelm@41983
     3
    Author:     Robert Himmelmann, TU München
wenzelm@41983
     4
    Author:     Armin Heller, TU München
wenzelm@41983
     5
    Author:     Bogdan Grechuk, University of Edinburgh
wenzelm@41983
     6
*)
hoelzl@41973
     7
hoelzl@41973
     8
header {* Extended real number line *}
hoelzl@41973
     9
hoelzl@43920
    10
theory Extended_Real
haftmann@43941
    11
imports Complex_Main Extended_Nat
hoelzl@41973
    12
begin
hoelzl@41973
    13
hoelzl@41980
    14
text {*
hoelzl@41980
    15
hoelzl@41980
    16
For more lemmas about the extended real numbers go to
bulwahn@42600
    17
  @{text "src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy"}
hoelzl@41980
    18
hoelzl@41980
    19
*}
hoelzl@41980
    20
hoelzl@41979
    21
lemma (in complete_lattice) atLeast_eq_UNIV_iff: "{x..} = UNIV \<longleftrightarrow> x = bot"
hoelzl@41979
    22
proof
hoelzl@41979
    23
  assume "{x..} = UNIV"
hoelzl@41979
    24
  show "x = bot"
hoelzl@41979
    25
  proof (rule ccontr)
hoelzl@41979
    26
    assume "x \<noteq> bot" then have "bot \<notin> {x..}" by (simp add: le_less)
hoelzl@41979
    27
    then show False using `{x..} = UNIV` by simp
hoelzl@41979
    28
  qed
hoelzl@41979
    29
qed auto
hoelzl@41979
    30
hoelzl@41979
    31
lemma SUPR_pair:
hoelzl@41979
    32
  "(SUP i : A. SUP j : B. f i j) = (SUP p : A \<times> B. f (fst p) (snd p))"
hoelzl@44928
    33
  by (rule antisym) (auto intro!: SUP_least SUP_upper2)
hoelzl@41979
    34
hoelzl@41979
    35
lemma INFI_pair:
hoelzl@41979
    36
  "(INF i : A. INF j : B. f i j) = (INF p : A \<times> B. f (fst p) (snd p))"
hoelzl@44928
    37
  by (rule antisym) (auto intro!: INF_greatest INF_lower2)
hoelzl@41979
    38
hoelzl@41973
    39
subsection {* Definition and basic properties *}
hoelzl@41973
    40
hoelzl@43920
    41
datatype ereal = ereal real | PInfty | MInfty
hoelzl@41973
    42
hoelzl@43920
    43
instantiation ereal :: uminus
hoelzl@41973
    44
begin
hoelzl@43920
    45
  fun uminus_ereal where
hoelzl@43920
    46
    "- (ereal r) = ereal (- r)"
hoelzl@43923
    47
  | "- PInfty = MInfty"
hoelzl@43923
    48
  | "- MInfty = PInfty"
hoelzl@41973
    49
  instance ..
hoelzl@41973
    50
end
hoelzl@41973
    51
hoelzl@43923
    52
instantiation ereal :: infinity
hoelzl@43923
    53
begin
hoelzl@43923
    54
  definition "(\<infinity>::ereal) = PInfty"
hoelzl@43923
    55
  instance ..
hoelzl@43923
    56
end
hoelzl@41973
    57
hoelzl@43923
    58
declare [[coercion "ereal :: real \<Rightarrow> ereal"]]
hoelzl@41973
    59
hoelzl@43920
    60
lemma ereal_uminus_uminus[simp]:
hoelzl@43920
    61
  fixes a :: ereal shows "- (- a) = a"
hoelzl@41973
    62
  by (cases a) simp_all
hoelzl@41973
    63
hoelzl@43923
    64
lemma
hoelzl@43923
    65
  shows PInfty_eq_infinity[simp]: "PInfty = \<infinity>"
hoelzl@43923
    66
    and MInfty_eq_minfinity[simp]: "MInfty = - \<infinity>"
hoelzl@43923
    67
    and MInfty_neq_PInfty[simp]: "\<infinity> \<noteq> - (\<infinity>::ereal)" "- \<infinity> \<noteq> (\<infinity>::ereal)"
hoelzl@43923
    68
    and MInfty_neq_ereal[simp]: "ereal r \<noteq> - \<infinity>" "- \<infinity> \<noteq> ereal r"
hoelzl@43923
    69
    and PInfty_neq_ereal[simp]: "ereal r \<noteq> \<infinity>" "\<infinity> \<noteq> ereal r"
hoelzl@43923
    70
    and PInfty_cases[simp]: "(case \<infinity> of ereal r \<Rightarrow> f r | PInfty \<Rightarrow> y | MInfty \<Rightarrow> z) = y"
hoelzl@43923
    71
    and MInfty_cases[simp]: "(case - \<infinity> of ereal r \<Rightarrow> f r | PInfty \<Rightarrow> y | MInfty \<Rightarrow> z) = z"
hoelzl@43923
    72
  by (simp_all add: infinity_ereal_def)
hoelzl@41973
    73
hoelzl@43933
    74
declare
hoelzl@43933
    75
  PInfty_eq_infinity[code_post]
hoelzl@43933
    76
  MInfty_eq_minfinity[code_post]
hoelzl@43933
    77
hoelzl@43933
    78
lemma [code_unfold]:
hoelzl@43933
    79
  "\<infinity> = PInfty"
hoelzl@43933
    80
  "-PInfty = MInfty"
hoelzl@43933
    81
  by simp_all
hoelzl@43933
    82
hoelzl@43923
    83
lemma inj_ereal[simp]: "inj_on ereal A"
hoelzl@43923
    84
  unfolding inj_on_def by auto
hoelzl@41973
    85
hoelzl@43920
    86
lemma ereal_cases[case_names real PInf MInf, cases type: ereal]:
hoelzl@43920
    87
  assumes "\<And>r. x = ereal r \<Longrightarrow> P"
hoelzl@41973
    88
  assumes "x = \<infinity> \<Longrightarrow> P"
hoelzl@41973
    89
  assumes "x = -\<infinity> \<Longrightarrow> P"
hoelzl@41973
    90
  shows P
hoelzl@41973
    91
  using assms by (cases x) auto
hoelzl@41973
    92
hoelzl@43920
    93
lemmas ereal2_cases = ereal_cases[case_product ereal_cases]
hoelzl@43920
    94
lemmas ereal3_cases = ereal2_cases[case_product ereal_cases]
hoelzl@41973
    95
hoelzl@43920
    96
lemma ereal_uminus_eq_iff[simp]:
hoelzl@43920
    97
  fixes a b :: ereal shows "-a = -b \<longleftrightarrow> a = b"
hoelzl@43920
    98
  by (cases rule: ereal2_cases[of a b]) simp_all
hoelzl@41973
    99
hoelzl@43920
   100
function of_ereal :: "ereal \<Rightarrow> real" where
hoelzl@43920
   101
"of_ereal (ereal r) = r" |
hoelzl@43920
   102
"of_ereal \<infinity> = 0" |
hoelzl@43920
   103
"of_ereal (-\<infinity>) = 0"
hoelzl@43920
   104
  by (auto intro: ereal_cases)
hoelzl@41973
   105
termination proof qed (rule wf_empty)
hoelzl@41973
   106
hoelzl@41973
   107
defs (overloaded)
hoelzl@43920
   108
  real_of_ereal_def [code_unfold]: "real \<equiv> of_ereal"
hoelzl@41973
   109
hoelzl@43920
   110
lemma real_of_ereal[simp]:
hoelzl@43920
   111
    "real (- x :: ereal) = - (real x)"
hoelzl@43920
   112
    "real (ereal r) = r"
hoelzl@43923
   113
    "real (\<infinity>::ereal) = 0"
hoelzl@43920
   114
  by (cases x) (simp_all add: real_of_ereal_def)
hoelzl@41973
   115
hoelzl@43920
   116
lemma range_ereal[simp]: "range ereal = UNIV - {\<infinity>, -\<infinity>}"
hoelzl@41973
   117
proof safe
hoelzl@43920
   118
  fix x assume "x \<notin> range ereal" "x \<noteq> \<infinity>"
hoelzl@41973
   119
  then show "x = -\<infinity>" by (cases x) auto
hoelzl@41973
   120
qed auto
hoelzl@41973
   121
hoelzl@43920
   122
lemma ereal_range_uminus[simp]: "range uminus = (UNIV::ereal set)"
hoelzl@41979
   123
proof safe
hoelzl@43920
   124
  fix x :: ereal show "x \<in> range uminus" by (intro image_eqI[of _ _ "-x"]) auto
hoelzl@41979
   125
qed auto
hoelzl@41979
   126
hoelzl@43920
   127
instantiation ereal :: number
hoelzl@41973
   128
begin
hoelzl@43920
   129
definition [simp]: "number_of x = ereal (number_of x)"
hoelzl@41973
   130
instance proof qed
hoelzl@41973
   131
end
hoelzl@41973
   132
hoelzl@43920
   133
instantiation ereal :: abs
hoelzl@41976
   134
begin
hoelzl@43920
   135
  function abs_ereal where
hoelzl@43920
   136
    "\<bar>ereal r\<bar> = ereal \<bar>r\<bar>"
hoelzl@43923
   137
  | "\<bar>-\<infinity>\<bar> = (\<infinity>::ereal)"
hoelzl@43923
   138
  | "\<bar>\<infinity>\<bar> = (\<infinity>::ereal)"
hoelzl@43920
   139
  by (auto intro: ereal_cases)
hoelzl@41976
   140
  termination proof qed (rule wf_empty)
hoelzl@41976
   141
  instance ..
hoelzl@41976
   142
end
hoelzl@41976
   143
hoelzl@43923
   144
lemma abs_eq_infinity_cases[elim!]: "\<lbrakk> \<bar>x :: ereal\<bar> = \<infinity> ; x = \<infinity> \<Longrightarrow> P ; x = -\<infinity> \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P"
hoelzl@41976
   145
  by (cases x) auto
hoelzl@41976
   146
hoelzl@43923
   147
lemma abs_neq_infinity_cases[elim!]: "\<lbrakk> \<bar>x :: ereal\<bar> \<noteq> \<infinity> ; \<And>r. x = ereal r \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P"
hoelzl@41976
   148
  by (cases x) auto
hoelzl@41976
   149
hoelzl@43920
   150
lemma abs_ereal_uminus[simp]: "\<bar>- x\<bar> = \<bar>x::ereal\<bar>"
hoelzl@41976
   151
  by (cases x) auto
hoelzl@41976
   152
hoelzl@41973
   153
subsubsection "Addition"
hoelzl@41973
   154
hoelzl@43920
   155
instantiation ereal :: comm_monoid_add
hoelzl@41973
   156
begin
hoelzl@41973
   157
hoelzl@43920
   158
definition "0 = ereal 0"
hoelzl@41973
   159
hoelzl@43920
   160
function plus_ereal where
hoelzl@43920
   161
"ereal r + ereal p = ereal (r + p)" |
hoelzl@43923
   162
"\<infinity> + a = (\<infinity>::ereal)" |
hoelzl@43923
   163
"a + \<infinity> = (\<infinity>::ereal)" |
hoelzl@43920
   164
"ereal r + -\<infinity> = - \<infinity>" |
hoelzl@43923
   165
"-\<infinity> + ereal p = -(\<infinity>::ereal)" |
hoelzl@43923
   166
"-\<infinity> + -\<infinity> = -(\<infinity>::ereal)"
hoelzl@41973
   167
proof -
hoelzl@41973
   168
  case (goal1 P x)
hoelzl@41973
   169
  moreover then obtain a b where "x = (a, b)" by (cases x) auto
hoelzl@41973
   170
  ultimately show P
hoelzl@43920
   171
   by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   172
qed auto
hoelzl@41973
   173
termination proof qed (rule wf_empty)
hoelzl@41973
   174
hoelzl@41973
   175
lemma Infty_neq_0[simp]:
hoelzl@43923
   176
  "(\<infinity>::ereal) \<noteq> 0" "0 \<noteq> (\<infinity>::ereal)"
hoelzl@43923
   177
  "-(\<infinity>::ereal) \<noteq> 0" "0 \<noteq> -(\<infinity>::ereal)"
hoelzl@43920
   178
  by (simp_all add: zero_ereal_def)
hoelzl@41973
   179
hoelzl@43920
   180
lemma ereal_eq_0[simp]:
hoelzl@43920
   181
  "ereal r = 0 \<longleftrightarrow> r = 0"
hoelzl@43920
   182
  "0 = ereal r \<longleftrightarrow> r = 0"
hoelzl@43920
   183
  unfolding zero_ereal_def by simp_all
hoelzl@41973
   184
hoelzl@41973
   185
instance
hoelzl@41973
   186
proof
hoelzl@43920
   187
  fix a :: ereal show "0 + a = a"
hoelzl@43920
   188
    by (cases a) (simp_all add: zero_ereal_def)
hoelzl@43920
   189
  fix b :: ereal show "a + b = b + a"
hoelzl@43920
   190
    by (cases rule: ereal2_cases[of a b]) simp_all
hoelzl@43920
   191
  fix c :: ereal show "a + b + c = a + (b + c)"
hoelzl@43920
   192
    by (cases rule: ereal3_cases[of a b c]) simp_all
hoelzl@41973
   193
qed
hoelzl@41973
   194
end
hoelzl@41973
   195
hoelzl@43920
   196
lemma real_of_ereal_0[simp]: "real (0::ereal) = 0"
hoelzl@43920
   197
  unfolding real_of_ereal_def zero_ereal_def by simp
hoelzl@42950
   198
hoelzl@43920
   199
lemma abs_ereal_zero[simp]: "\<bar>0\<bar> = (0::ereal)"
hoelzl@43920
   200
  unfolding zero_ereal_def abs_ereal.simps by simp
hoelzl@41976
   201
hoelzl@43920
   202
lemma ereal_uminus_zero[simp]:
hoelzl@43920
   203
  "- 0 = (0::ereal)"
hoelzl@43920
   204
  by (simp add: zero_ereal_def)
hoelzl@41973
   205
hoelzl@43920
   206
lemma ereal_uminus_zero_iff[simp]:
hoelzl@43920
   207
  fixes a :: ereal shows "-a = 0 \<longleftrightarrow> a = 0"
hoelzl@41973
   208
  by (cases a) simp_all
hoelzl@41973
   209
hoelzl@43920
   210
lemma ereal_plus_eq_PInfty[simp]:
hoelzl@43923
   211
  fixes a b :: ereal shows "a + b = \<infinity> \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>"
hoelzl@43920
   212
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   213
hoelzl@43920
   214
lemma ereal_plus_eq_MInfty[simp]:
hoelzl@43923
   215
  fixes a b :: ereal shows "a + b = -\<infinity> \<longleftrightarrow>
hoelzl@41973
   216
    (a = -\<infinity> \<or> b = -\<infinity>) \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>"
hoelzl@43920
   217
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   218
hoelzl@43920
   219
lemma ereal_add_cancel_left:
hoelzl@43923
   220
  fixes a b :: ereal assumes "a \<noteq> -\<infinity>"
hoelzl@41973
   221
  shows "a + b = a + c \<longleftrightarrow> (a = \<infinity> \<or> b = c)"
hoelzl@43920
   222
  using assms by (cases rule: ereal3_cases[of a b c]) auto
hoelzl@41973
   223
hoelzl@43920
   224
lemma ereal_add_cancel_right:
hoelzl@43923
   225
  fixes a b :: ereal assumes "a \<noteq> -\<infinity>"
hoelzl@41973
   226
  shows "b + a = c + a \<longleftrightarrow> (a = \<infinity> \<or> b = c)"
hoelzl@43920
   227
  using assms by (cases rule: ereal3_cases[of a b c]) auto
hoelzl@41973
   228
hoelzl@43920
   229
lemma ereal_real:
hoelzl@43920
   230
  "ereal (real x) = (if \<bar>x\<bar> = \<infinity> then 0 else x)"
hoelzl@41973
   231
  by (cases x) simp_all
hoelzl@41973
   232
hoelzl@43920
   233
lemma real_of_ereal_add:
hoelzl@43920
   234
  fixes a b :: ereal
hoelzl@41979
   235
  shows "real (a + b) = (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)"
hoelzl@43920
   236
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41979
   237
hoelzl@43920
   238
subsubsection "Linear order on @{typ ereal}"
hoelzl@41973
   239
hoelzl@43920
   240
instantiation ereal :: linorder
hoelzl@41973
   241
begin
hoelzl@41973
   242
hoelzl@43920
   243
function less_ereal where
hoelzl@43923
   244
"   ereal x < ereal y     \<longleftrightarrow> x < y" |
hoelzl@43923
   245
"(\<infinity>::ereal) < a           \<longleftrightarrow> False" |
hoelzl@43923
   246
"         a < -(\<infinity>::ereal) \<longleftrightarrow> False" |
hoelzl@43923
   247
"ereal x    < \<infinity>           \<longleftrightarrow> True" |
hoelzl@43923
   248
"        -\<infinity> < ereal r     \<longleftrightarrow> True" |
hoelzl@43923
   249
"        -\<infinity> < (\<infinity>::ereal) \<longleftrightarrow> True"
hoelzl@41973
   250
proof -
hoelzl@41973
   251
  case (goal1 P x)
hoelzl@41973
   252
  moreover then obtain a b where "x = (a,b)" by (cases x) auto
hoelzl@43920
   253
  ultimately show P by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   254
qed simp_all
hoelzl@41973
   255
termination by (relation "{}") simp
hoelzl@41973
   256
hoelzl@43920
   257
definition "x \<le> (y::ereal) \<longleftrightarrow> x < y \<or> x = y"
hoelzl@41973
   258
hoelzl@43920
   259
lemma ereal_infty_less[simp]:
hoelzl@43923
   260
  fixes x :: ereal
hoelzl@43923
   261
  shows "x < \<infinity> \<longleftrightarrow> (x \<noteq> \<infinity>)"
hoelzl@43923
   262
    "-\<infinity> < x \<longleftrightarrow> (x \<noteq> -\<infinity>)"
hoelzl@41973
   263
  by (cases x, simp_all) (cases x, simp_all)
hoelzl@41973
   264
hoelzl@43920
   265
lemma ereal_infty_less_eq[simp]:
hoelzl@43923
   266
  fixes x :: ereal
hoelzl@43923
   267
  shows "\<infinity> \<le> x \<longleftrightarrow> x = \<infinity>"
hoelzl@41973
   268
  "x \<le> -\<infinity> \<longleftrightarrow> x = -\<infinity>"
hoelzl@43920
   269
  by (auto simp add: less_eq_ereal_def)
hoelzl@41973
   270
hoelzl@43920
   271
lemma ereal_less[simp]:
hoelzl@43920
   272
  "ereal r < 0 \<longleftrightarrow> (r < 0)"
hoelzl@43920
   273
  "0 < ereal r \<longleftrightarrow> (0 < r)"
hoelzl@43923
   274
  "0 < (\<infinity>::ereal)"
hoelzl@43923
   275
  "-(\<infinity>::ereal) < 0"
hoelzl@43920
   276
  by (simp_all add: zero_ereal_def)
hoelzl@41973
   277
hoelzl@43920
   278
lemma ereal_less_eq[simp]:
hoelzl@43923
   279
  "x \<le> (\<infinity>::ereal)"
hoelzl@43923
   280
  "-(\<infinity>::ereal) \<le> x"
hoelzl@43920
   281
  "ereal r \<le> ereal p \<longleftrightarrow> r \<le> p"
hoelzl@43920
   282
  "ereal r \<le> 0 \<longleftrightarrow> r \<le> 0"
hoelzl@43920
   283
  "0 \<le> ereal r \<longleftrightarrow> 0 \<le> r"
hoelzl@43920
   284
  by (auto simp add: less_eq_ereal_def zero_ereal_def)
hoelzl@41973
   285
hoelzl@43920
   286
lemma ereal_infty_less_eq2:
hoelzl@43923
   287
  "a \<le> b \<Longrightarrow> a = \<infinity> \<Longrightarrow> b = (\<infinity>::ereal)"
hoelzl@43923
   288
  "a \<le> b \<Longrightarrow> b = -\<infinity> \<Longrightarrow> a = -(\<infinity>::ereal)"
hoelzl@41973
   289
  by simp_all
hoelzl@41973
   290
hoelzl@41973
   291
instance
hoelzl@41973
   292
proof
hoelzl@43920
   293
  fix x :: ereal show "x \<le> x"
hoelzl@41973
   294
    by (cases x) simp_all
hoelzl@43920
   295
  fix y :: ereal show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
hoelzl@43920
   296
    by (cases rule: ereal2_cases[of x y]) auto
hoelzl@41973
   297
  show "x \<le> y \<or> y \<le> x "
hoelzl@43920
   298
    by (cases rule: ereal2_cases[of x y]) auto
hoelzl@41973
   299
  { assume "x \<le> y" "y \<le> x" then show "x = y"
hoelzl@43920
   300
    by (cases rule: ereal2_cases[of x y]) auto }
hoelzl@41973
   301
  { fix z assume "x \<le> y" "y \<le> z" then show "x \<le> z"
hoelzl@43920
   302
    by (cases rule: ereal3_cases[of x y z]) auto }
hoelzl@41973
   303
qed
hoelzl@41973
   304
end
hoelzl@41973
   305
hoelzl@43920
   306
instance ereal :: ordered_ab_semigroup_add
hoelzl@41978
   307
proof
hoelzl@43920
   308
  fix a b c :: ereal assume "a \<le> b" then show "c + a \<le> c + b"
hoelzl@43920
   309
    by (cases rule: ereal3_cases[of a b c]) auto
hoelzl@41978
   310
qed
hoelzl@41978
   311
hoelzl@43920
   312
lemma real_of_ereal_positive_mono:
hoelzl@43923
   313
  fixes x y :: ereal shows "\<lbrakk>0 \<le> x; x \<le> y; y \<noteq> \<infinity>\<rbrakk> \<Longrightarrow> real x \<le> real y"
hoelzl@43920
   314
  by (cases rule: ereal2_cases[of x y]) auto
hoelzl@42950
   315
hoelzl@43920
   316
lemma ereal_MInfty_lessI[intro, simp]:
hoelzl@43923
   317
  fixes a :: ereal shows "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a"
hoelzl@41973
   318
  by (cases a) auto
hoelzl@41973
   319
hoelzl@43920
   320
lemma ereal_less_PInfty[intro, simp]:
hoelzl@43923
   321
  fixes a :: ereal shows "a \<noteq> \<infinity> \<Longrightarrow> a < \<infinity>"
hoelzl@41973
   322
  by (cases a) auto
hoelzl@41973
   323
hoelzl@43920
   324
lemma ereal_less_ereal_Ex:
hoelzl@43920
   325
  fixes a b :: ereal
hoelzl@43920
   326
  shows "x < ereal r \<longleftrightarrow> x = -\<infinity> \<or> (\<exists>p. p < r \<and> x = ereal p)"
hoelzl@41973
   327
  by (cases x) auto
hoelzl@41973
   328
hoelzl@43920
   329
lemma less_PInf_Ex_of_nat: "x \<noteq> \<infinity> \<longleftrightarrow> (\<exists>n::nat. x < ereal (real n))"
hoelzl@41979
   330
proof (cases x)
hoelzl@41979
   331
  case (real r) then show ?thesis
hoelzl@41980
   332
    using reals_Archimedean2[of r] by simp
hoelzl@41979
   333
qed simp_all
hoelzl@41979
   334
hoelzl@43920
   335
lemma ereal_add_mono:
hoelzl@43920
   336
  fixes a b c d :: ereal assumes "a \<le> b" "c \<le> d" shows "a + c \<le> b + d"
hoelzl@41973
   337
  using assms
hoelzl@41973
   338
  apply (cases a)
hoelzl@43920
   339
  apply (cases rule: ereal3_cases[of b c d], auto)
hoelzl@43920
   340
  apply (cases rule: ereal3_cases[of b c d], auto)
hoelzl@41973
   341
  done
hoelzl@41973
   342
hoelzl@43920
   343
lemma ereal_minus_le_minus[simp]:
hoelzl@43920
   344
  fixes a b :: ereal shows "- a \<le> - b \<longleftrightarrow> b \<le> a"
hoelzl@43920
   345
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   346
hoelzl@43920
   347
lemma ereal_minus_less_minus[simp]:
hoelzl@43920
   348
  fixes a b :: ereal shows "- a < - b \<longleftrightarrow> b < a"
hoelzl@43920
   349
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   350
hoelzl@43920
   351
lemma ereal_le_real_iff:
hoelzl@43920
   352
  "x \<le> real y \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x \<le> y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x \<le> 0))"
hoelzl@41973
   353
  by (cases y) auto
hoelzl@41973
   354
hoelzl@43920
   355
lemma real_le_ereal_iff:
hoelzl@43920
   356
  "real y \<le> x \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y \<le> ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 \<le> x))"
hoelzl@41973
   357
  by (cases y) auto
hoelzl@41973
   358
hoelzl@43920
   359
lemma ereal_less_real_iff:
hoelzl@43920
   360
  "x < real y \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x < y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x < 0))"
hoelzl@41973
   361
  by (cases y) auto
hoelzl@41973
   362
hoelzl@43920
   363
lemma real_less_ereal_iff:
hoelzl@43920
   364
  "real y < x \<longleftrightarrow> ((\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y < ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 < x))"
hoelzl@41973
   365
  by (cases y) auto
hoelzl@41973
   366
hoelzl@43920
   367
lemma real_of_ereal_pos:
hoelzl@43920
   368
  fixes x :: ereal shows "0 \<le> x \<Longrightarrow> 0 \<le> real x" by (cases x) auto
hoelzl@41979
   369
hoelzl@43920
   370
lemmas real_of_ereal_ord_simps =
hoelzl@43920
   371
  ereal_le_real_iff real_le_ereal_iff ereal_less_real_iff real_less_ereal_iff
hoelzl@41973
   372
hoelzl@43920
   373
lemma abs_ereal_ge0[simp]: "0 \<le> x \<Longrightarrow> \<bar>x :: ereal\<bar> = x"
hoelzl@42950
   374
  by (cases x) auto
hoelzl@42950
   375
hoelzl@43920
   376
lemma abs_ereal_less0[simp]: "x < 0 \<Longrightarrow> \<bar>x :: ereal\<bar> = -x"
hoelzl@42950
   377
  by (cases x) auto
hoelzl@42950
   378
hoelzl@43920
   379
lemma abs_ereal_pos[simp]: "0 \<le> \<bar>x :: ereal\<bar>"
hoelzl@42950
   380
  by (cases x) auto
hoelzl@42950
   381
hoelzl@43923
   382
lemma real_of_ereal_le_0[simp]: "real (x :: ereal) \<le> 0 \<longleftrightarrow> (x \<le> 0 \<or> x = \<infinity>)"
hoelzl@43923
   383
  by (cases x) auto
hoelzl@42950
   384
hoelzl@43923
   385
lemma abs_real_of_ereal[simp]: "\<bar>real (x :: ereal)\<bar> = real \<bar>x\<bar>"
hoelzl@43923
   386
  by (cases x) auto
hoelzl@42950
   387
hoelzl@43923
   388
lemma zero_less_real_of_ereal:
hoelzl@43923
   389
  fixes x :: ereal shows "0 < real x \<longleftrightarrow> (0 < x \<and> x \<noteq> \<infinity>)"
hoelzl@43923
   390
  by (cases x) auto
hoelzl@42950
   391
hoelzl@43920
   392
lemma ereal_0_le_uminus_iff[simp]:
hoelzl@43920
   393
  fixes a :: ereal shows "0 \<le> -a \<longleftrightarrow> a \<le> 0"
hoelzl@43920
   394
  by (cases rule: ereal2_cases[of a]) auto
hoelzl@42950
   395
hoelzl@43920
   396
lemma ereal_uminus_le_0_iff[simp]:
hoelzl@43920
   397
  fixes a :: ereal shows "-a \<le> 0 \<longleftrightarrow> 0 \<le> a"
hoelzl@43920
   398
  by (cases rule: ereal2_cases[of a]) auto
hoelzl@42950
   399
hoelzl@43923
   400
lemma ereal_dense2: "x < y \<Longrightarrow> \<exists>z. x < ereal z \<and> ereal z < y"
hoelzl@43923
   401
  using lt_ex gt_ex dense by (cases x y rule: ereal2_cases) auto
hoelzl@43923
   402
hoelzl@43920
   403
lemma ereal_dense:
hoelzl@43920
   404
  fixes x y :: ereal assumes "x < y"
hoelzl@43923
   405
  shows "\<exists>z. x < z \<and> z < y"
hoelzl@43923
   406
  using ereal_dense2[OF `x < y`] by blast
hoelzl@41973
   407
hoelzl@43920
   408
lemma ereal_add_strict_mono:
hoelzl@43920
   409
  fixes a b c d :: ereal
hoelzl@41979
   410
  assumes "a = b" "0 \<le> a" "a \<noteq> \<infinity>" "c < d"
hoelzl@41979
   411
  shows "a + c < b + d"
hoelzl@43920
   412
  using assms by (cases rule: ereal3_cases[case_product ereal_cases, of a b c d]) auto
hoelzl@41979
   413
hoelzl@43923
   414
lemma ereal_less_add: 
hoelzl@43923
   415
  fixes a b c :: ereal shows "\<bar>a\<bar> \<noteq> \<infinity> \<Longrightarrow> c < b \<Longrightarrow> a + c < a + b"
hoelzl@43920
   416
  by (cases rule: ereal2_cases[of b c]) auto
hoelzl@41979
   417
hoelzl@43920
   418
lemma ereal_uminus_eq_reorder: "- a = b \<longleftrightarrow> a = (-b::ereal)" by auto
hoelzl@41979
   419
hoelzl@43920
   420
lemma ereal_uminus_less_reorder: "- a < b \<longleftrightarrow> -b < (a::ereal)"
hoelzl@43920
   421
  by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_less_minus)
hoelzl@41979
   422
hoelzl@43920
   423
lemma ereal_uminus_le_reorder: "- a \<le> b \<longleftrightarrow> -b \<le> (a::ereal)"
hoelzl@43920
   424
  by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_le_minus)
hoelzl@41979
   425
hoelzl@43920
   426
lemmas ereal_uminus_reorder =
hoelzl@43920
   427
  ereal_uminus_eq_reorder ereal_uminus_less_reorder ereal_uminus_le_reorder
hoelzl@41979
   428
hoelzl@43920
   429
lemma ereal_bot:
hoelzl@43920
   430
  fixes x :: ereal assumes "\<And>B. x \<le> ereal B" shows "x = - \<infinity>"
hoelzl@41979
   431
proof (cases x)
hoelzl@41979
   432
  case (real r) with assms[of "r - 1"] show ?thesis by auto
hoelzl@41979
   433
next case PInf with assms[of 0] show ?thesis by auto
hoelzl@41979
   434
next case MInf then show ?thesis by simp
hoelzl@41979
   435
qed
hoelzl@41979
   436
hoelzl@43920
   437
lemma ereal_top:
hoelzl@43920
   438
  fixes x :: ereal assumes "\<And>B. x \<ge> ereal B" shows "x = \<infinity>"
hoelzl@41979
   439
proof (cases x)
hoelzl@41979
   440
  case (real r) with assms[of "r + 1"] show ?thesis by auto
hoelzl@41979
   441
next case MInf with assms[of 0] show ?thesis by auto
hoelzl@41979
   442
next case PInf then show ?thesis by simp
hoelzl@41979
   443
qed
hoelzl@41979
   444
hoelzl@41979
   445
lemma
hoelzl@43920
   446
  shows ereal_max[simp]: "ereal (max x y) = max (ereal x) (ereal y)"
hoelzl@43920
   447
    and ereal_min[simp]: "ereal (min x y) = min (ereal x) (ereal y)"
hoelzl@41979
   448
  by (simp_all add: min_def max_def)
hoelzl@41979
   449
hoelzl@43920
   450
lemma ereal_max_0: "max 0 (ereal r) = ereal (max 0 r)"
hoelzl@43920
   451
  by (auto simp: zero_ereal_def)
hoelzl@41979
   452
hoelzl@41978
   453
lemma
hoelzl@43920
   454
  fixes f :: "nat \<Rightarrow> ereal"
hoelzl@41978
   455
  shows incseq_uminus[simp]: "incseq (\<lambda>x. - f x) \<longleftrightarrow> decseq f"
hoelzl@41978
   456
  and decseq_uminus[simp]: "decseq (\<lambda>x. - f x) \<longleftrightarrow> incseq f"
hoelzl@41978
   457
  unfolding decseq_def incseq_def by auto
hoelzl@41978
   458
hoelzl@43920
   459
lemma incseq_ereal: "incseq f \<Longrightarrow> incseq (\<lambda>x. ereal (f x))"
hoelzl@42950
   460
  unfolding incseq_def by auto
hoelzl@42950
   461
hoelzl@43920
   462
lemma ereal_add_nonneg_nonneg:
hoelzl@43920
   463
  fixes a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a + b"
hoelzl@41978
   464
  using add_mono[of 0 a 0 b] by simp
hoelzl@41978
   465
hoelzl@41978
   466
lemma image_eqD: "f ` A = B \<Longrightarrow> (\<forall>x\<in>A. f x \<in> B)"
hoelzl@41978
   467
  by auto
hoelzl@41978
   468
hoelzl@41978
   469
lemma incseq_setsumI:
hoelzl@41979
   470
  fixes f :: "nat \<Rightarrow> 'a::{comm_monoid_add, ordered_ab_semigroup_add}"
hoelzl@41978
   471
  assumes "\<And>i. 0 \<le> f i"
hoelzl@41978
   472
  shows "incseq (\<lambda>i. setsum f {..< i})"
hoelzl@41978
   473
proof (intro incseq_SucI)
hoelzl@41978
   474
  fix n have "setsum f {..< n} + 0 \<le> setsum f {..<n} + f n"
hoelzl@41978
   475
    using assms by (rule add_left_mono)
hoelzl@41978
   476
  then show "setsum f {..< n} \<le> setsum f {..< Suc n}"
hoelzl@41978
   477
    by auto
hoelzl@41978
   478
qed
hoelzl@41978
   479
hoelzl@41979
   480
lemma incseq_setsumI2:
hoelzl@41979
   481
  fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::{comm_monoid_add, ordered_ab_semigroup_add}"
hoelzl@41979
   482
  assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)"
hoelzl@41979
   483
  shows "incseq (\<lambda>i. \<Sum>n\<in>A. f n i)"
hoelzl@41979
   484
  using assms unfolding incseq_def by (auto intro: setsum_mono)
hoelzl@41979
   485
hoelzl@41973
   486
subsubsection "Multiplication"
hoelzl@41973
   487
hoelzl@43920
   488
instantiation ereal :: "{comm_monoid_mult, sgn}"
hoelzl@41973
   489
begin
hoelzl@41973
   490
hoelzl@43920
   491
definition "1 = ereal 1"
hoelzl@41973
   492
hoelzl@43920
   493
function sgn_ereal where
hoelzl@43920
   494
  "sgn (ereal r) = ereal (sgn r)"
hoelzl@43923
   495
| "sgn (\<infinity>::ereal) = 1"
hoelzl@43923
   496
| "sgn (-\<infinity>::ereal) = -1"
hoelzl@43920
   497
by (auto intro: ereal_cases)
hoelzl@41976
   498
termination proof qed (rule wf_empty)
hoelzl@41976
   499
hoelzl@43920
   500
function times_ereal where
hoelzl@43920
   501
"ereal r * ereal p = ereal (r * p)" |
hoelzl@43920
   502
"ereal r * \<infinity> = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" |
hoelzl@43920
   503
"\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" |
hoelzl@43920
   504
"ereal r * -\<infinity> = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" |
hoelzl@43920
   505
"-\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" |
hoelzl@43923
   506
"(\<infinity>::ereal) * \<infinity> = \<infinity>" |
hoelzl@43923
   507
"-(\<infinity>::ereal) * \<infinity> = -\<infinity>" |
hoelzl@43923
   508
"(\<infinity>::ereal) * -\<infinity> = -\<infinity>" |
hoelzl@43923
   509
"-(\<infinity>::ereal) * -\<infinity> = \<infinity>"
hoelzl@41973
   510
proof -
hoelzl@41973
   511
  case (goal1 P x)
hoelzl@41973
   512
  moreover then obtain a b where "x = (a, b)" by (cases x) auto
hoelzl@43920
   513
  ultimately show P by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   514
qed simp_all
hoelzl@41973
   515
termination by (relation "{}") simp
hoelzl@41973
   516
hoelzl@41973
   517
instance
hoelzl@41973
   518
proof
hoelzl@43920
   519
  fix a :: ereal show "1 * a = a"
hoelzl@43920
   520
    by (cases a) (simp_all add: one_ereal_def)
hoelzl@43920
   521
  fix b :: ereal show "a * b = b * a"
hoelzl@43920
   522
    by (cases rule: ereal2_cases[of a b]) simp_all
hoelzl@43920
   523
  fix c :: ereal show "a * b * c = a * (b * c)"
hoelzl@43920
   524
    by (cases rule: ereal3_cases[of a b c])
hoelzl@43920
   525
       (simp_all add: zero_ereal_def zero_less_mult_iff)
hoelzl@41973
   526
qed
hoelzl@41973
   527
end
hoelzl@41973
   528
hoelzl@43920
   529
lemma real_of_ereal_le_1:
hoelzl@43920
   530
  fixes a :: ereal shows "a \<le> 1 \<Longrightarrow> real a \<le> 1"
hoelzl@43920
   531
  by (cases a) (auto simp: one_ereal_def)
hoelzl@42950
   532
hoelzl@43920
   533
lemma abs_ereal_one[simp]: "\<bar>1\<bar> = (1::ereal)"
hoelzl@43920
   534
  unfolding one_ereal_def by simp
hoelzl@41976
   535
hoelzl@43920
   536
lemma ereal_mult_zero[simp]:
hoelzl@43920
   537
  fixes a :: ereal shows "a * 0 = 0"
hoelzl@43920
   538
  by (cases a) (simp_all add: zero_ereal_def)
hoelzl@41973
   539
hoelzl@43920
   540
lemma ereal_zero_mult[simp]:
hoelzl@43920
   541
  fixes a :: ereal shows "0 * a = 0"
hoelzl@43920
   542
  by (cases a) (simp_all add: zero_ereal_def)
hoelzl@41973
   543
hoelzl@43920
   544
lemma ereal_m1_less_0[simp]:
hoelzl@43920
   545
  "-(1::ereal) < 0"
hoelzl@43920
   546
  by (simp add: zero_ereal_def one_ereal_def)
hoelzl@41973
   547
hoelzl@43920
   548
lemma ereal_zero_m1[simp]:
hoelzl@43920
   549
  "1 \<noteq> (0::ereal)"
hoelzl@43920
   550
  by (simp add: zero_ereal_def one_ereal_def)
hoelzl@41973
   551
hoelzl@43920
   552
lemma ereal_times_0[simp]:
hoelzl@43920
   553
  fixes x :: ereal shows "0 * x = 0"
hoelzl@43920
   554
  by (cases x) (auto simp: zero_ereal_def)
hoelzl@41973
   555
hoelzl@43920
   556
lemma ereal_times[simp]:
hoelzl@43923
   557
  "1 \<noteq> (\<infinity>::ereal)" "(\<infinity>::ereal) \<noteq> 1"
hoelzl@43923
   558
  "1 \<noteq> -(\<infinity>::ereal)" "-(\<infinity>::ereal) \<noteq> 1"
hoelzl@43920
   559
  by (auto simp add: times_ereal_def one_ereal_def)
hoelzl@41973
   560
hoelzl@43920
   561
lemma ereal_plus_1[simp]:
hoelzl@43920
   562
  "1 + ereal r = ereal (r + 1)" "ereal r + 1 = ereal (r + 1)"
hoelzl@43923
   563
  "1 + -(\<infinity>::ereal) = -\<infinity>" "-(\<infinity>::ereal) + 1 = -\<infinity>"
hoelzl@43920
   564
  unfolding one_ereal_def by auto
hoelzl@41973
   565
hoelzl@43920
   566
lemma ereal_zero_times[simp]:
hoelzl@43920
   567
  fixes a b :: ereal shows "a * b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
hoelzl@43920
   568
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   569
hoelzl@43920
   570
lemma ereal_mult_eq_PInfty[simp]:
hoelzl@43923
   571
  shows "a * b = (\<infinity>::ereal) \<longleftrightarrow>
hoelzl@41973
   572
    (a = \<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = -\<infinity>)"
hoelzl@43920
   573
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   574
hoelzl@43920
   575
lemma ereal_mult_eq_MInfty[simp]:
hoelzl@43923
   576
  shows "a * b = -(\<infinity>::ereal) \<longleftrightarrow>
hoelzl@41973
   577
    (a = \<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = -\<infinity>)"
hoelzl@43920
   578
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   579
hoelzl@43920
   580
lemma ereal_0_less_1[simp]: "0 < (1::ereal)"
hoelzl@43920
   581
  by (simp_all add: zero_ereal_def one_ereal_def)
hoelzl@41973
   582
hoelzl@43920
   583
lemma ereal_zero_one[simp]: "0 \<noteq> (1::ereal)"
hoelzl@43920
   584
  by (simp_all add: zero_ereal_def one_ereal_def)
hoelzl@41973
   585
hoelzl@43920
   586
lemma ereal_mult_minus_left[simp]:
hoelzl@43920
   587
  fixes a b :: ereal shows "-a * b = - (a * b)"
hoelzl@43920
   588
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   589
hoelzl@43920
   590
lemma ereal_mult_minus_right[simp]:
hoelzl@43920
   591
  fixes a b :: ereal shows "a * -b = - (a * b)"
hoelzl@43920
   592
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
   593
hoelzl@43920
   594
lemma ereal_mult_infty[simp]:
hoelzl@43923
   595
  "a * (\<infinity>::ereal) = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)"
hoelzl@41973
   596
  by (cases a) auto
hoelzl@41973
   597
hoelzl@43920
   598
lemma ereal_infty_mult[simp]:
hoelzl@43923
   599
  "(\<infinity>::ereal) * a = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)"
hoelzl@41973
   600
  by (cases a) auto
hoelzl@41973
   601
hoelzl@43920
   602
lemma ereal_mult_strict_right_mono:
hoelzl@43923
   603
  assumes "a < b" and "0 < c" "c < (\<infinity>::ereal)"
hoelzl@41973
   604
  shows "a * c < b * c"
hoelzl@41973
   605
  using assms
hoelzl@43920
   606
  by (cases rule: ereal3_cases[of a b c])
huffman@44142
   607
     (auto simp: zero_le_mult_iff)
hoelzl@41973
   608
hoelzl@43920
   609
lemma ereal_mult_strict_left_mono:
hoelzl@43923
   610
  "\<lbrakk> a < b ; 0 < c ; c < (\<infinity>::ereal)\<rbrakk> \<Longrightarrow> c * a < c * b"
hoelzl@43920
   611
  using ereal_mult_strict_right_mono by (simp add: mult_commute[of c])
hoelzl@41973
   612
hoelzl@43920
   613
lemma ereal_mult_right_mono:
hoelzl@43920
   614
  fixes a b c :: ereal shows "\<lbrakk>a \<le> b; 0 \<le> c\<rbrakk> \<Longrightarrow> a*c \<le> b*c"
hoelzl@41973
   615
  using assms
hoelzl@41973
   616
  apply (cases "c = 0") apply simp
hoelzl@43920
   617
  by (cases rule: ereal3_cases[of a b c])
huffman@44142
   618
     (auto simp: zero_le_mult_iff)
hoelzl@41973
   619
hoelzl@43920
   620
lemma ereal_mult_left_mono:
hoelzl@43920
   621
  fixes a b c :: ereal shows "\<lbrakk>a \<le> b; 0 \<le> c\<rbrakk> \<Longrightarrow> c * a \<le> c * b"
hoelzl@43920
   622
  using ereal_mult_right_mono by (simp add: mult_commute[of c])
hoelzl@41973
   623
hoelzl@43920
   624
lemma zero_less_one_ereal[simp]: "0 \<le> (1::ereal)"
hoelzl@43920
   625
  by (simp add: one_ereal_def zero_ereal_def)
hoelzl@41978
   626
hoelzl@43920
   627
lemma ereal_0_le_mult[simp]: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * (b :: ereal)"
hoelzl@43920
   628
  by (cases rule: ereal2_cases[of a b]) (auto simp: mult_nonneg_nonneg)
hoelzl@41979
   629
hoelzl@43920
   630
lemma ereal_right_distrib:
hoelzl@43920
   631
  fixes r a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> r * (a + b) = r * a + r * b"
hoelzl@43920
   632
  by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps)
hoelzl@41979
   633
hoelzl@43920
   634
lemma ereal_left_distrib:
hoelzl@43920
   635
  fixes r a b :: ereal shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> (a + b) * r = a * r + b * r"
hoelzl@43920
   636
  by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps)
hoelzl@41979
   637
hoelzl@43920
   638
lemma ereal_mult_le_0_iff:
hoelzl@43920
   639
  fixes a b :: ereal
hoelzl@41979
   640
  shows "a * b \<le> 0 \<longleftrightarrow> (0 \<le> a \<and> b \<le> 0) \<or> (a \<le> 0 \<and> 0 \<le> b)"
hoelzl@43920
   641
  by (cases rule: ereal2_cases[of a b]) (simp_all add: mult_le_0_iff)
hoelzl@41979
   642
hoelzl@43920
   643
lemma ereal_zero_le_0_iff:
hoelzl@43920
   644
  fixes a b :: ereal
hoelzl@41979
   645
  shows "0 \<le> a * b \<longleftrightarrow> (0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0)"
hoelzl@43920
   646
  by (cases rule: ereal2_cases[of a b]) (simp_all add: zero_le_mult_iff)
hoelzl@41979
   647
hoelzl@43920
   648
lemma ereal_mult_less_0_iff:
hoelzl@43920
   649
  fixes a b :: ereal
hoelzl@41979
   650
  shows "a * b < 0 \<longleftrightarrow> (0 < a \<and> b < 0) \<or> (a < 0 \<and> 0 < b)"
hoelzl@43920
   651
  by (cases rule: ereal2_cases[of a b]) (simp_all add: mult_less_0_iff)
hoelzl@41979
   652
hoelzl@43920
   653
lemma ereal_zero_less_0_iff:
hoelzl@43920
   654
  fixes a b :: ereal
hoelzl@41979
   655
  shows "0 < a * b \<longleftrightarrow> (0 < a \<and> 0 < b) \<or> (a < 0 \<and> b < 0)"
hoelzl@43920
   656
  by (cases rule: ereal2_cases[of a b]) (simp_all add: zero_less_mult_iff)
hoelzl@41979
   657
hoelzl@43920
   658
lemma ereal_distrib:
hoelzl@43920
   659
  fixes a b c :: ereal
hoelzl@41979
   660
  assumes "a \<noteq> \<infinity> \<or> b \<noteq> -\<infinity>" "a \<noteq> -\<infinity> \<or> b \<noteq> \<infinity>" "\<bar>c\<bar> \<noteq> \<infinity>"
hoelzl@41979
   661
  shows "(a + b) * c = a * c + b * c"
hoelzl@41979
   662
  using assms
hoelzl@43920
   663
  by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps)
hoelzl@41979
   664
hoelzl@43920
   665
lemma ereal_le_epsilon:
hoelzl@43920
   666
  fixes x y :: ereal
hoelzl@41979
   667
  assumes "ALL e. 0 < e --> x <= y + e"
hoelzl@41979
   668
  shows "x <= y"
hoelzl@41979
   669
proof-
hoelzl@43920
   670
{ assume a: "EX r. y = ereal r"
hoelzl@43920
   671
  from this obtain r where r_def: "y = ereal r" by auto
hoelzl@41979
   672
  { assume "x=(-\<infinity>)" hence ?thesis by auto }
hoelzl@41979
   673
  moreover
hoelzl@41979
   674
  { assume "~(x=(-\<infinity>))"
hoelzl@43920
   675
    from this obtain p where p_def: "x = ereal p"
hoelzl@41979
   676
    using a assms[rule_format, of 1] by (cases x) auto
hoelzl@41979
   677
    { fix e have "0 < e --> p <= r + e"
hoelzl@43920
   678
      using assms[rule_format, of "ereal e"] p_def r_def by auto }
hoelzl@41979
   679
    hence "p <= r" apply (subst field_le_epsilon) by auto
hoelzl@41979
   680
    hence ?thesis using r_def p_def by auto
hoelzl@41979
   681
  } ultimately have ?thesis by blast
hoelzl@41979
   682
}
hoelzl@41979
   683
moreover
hoelzl@41979
   684
{ assume "y=(-\<infinity>) | y=\<infinity>" hence ?thesis
hoelzl@41979
   685
    using assms[rule_format, of 1] by (cases x) auto
hoelzl@41979
   686
} ultimately show ?thesis by (cases y) auto
hoelzl@41979
   687
qed
hoelzl@41979
   688
hoelzl@41979
   689
hoelzl@43920
   690
lemma ereal_le_epsilon2:
hoelzl@43920
   691
  fixes x y :: ereal
hoelzl@43920
   692
  assumes "ALL e. 0 < e --> x <= y + ereal e"
hoelzl@41979
   693
  shows "x <= y"
hoelzl@41979
   694
proof-
hoelzl@43920
   695
{ fix e :: ereal assume "e>0"
hoelzl@41979
   696
  { assume "e=\<infinity>" hence "x<=y+e" by auto }
hoelzl@41979
   697
  moreover
hoelzl@41979
   698
  { assume "e~=\<infinity>"
hoelzl@43920
   699
    from this obtain r where "e = ereal r" using `e>0` apply (cases e) by auto
hoelzl@41979
   700
    hence "x<=y+e" using assms[rule_format, of r] `e>0` by auto
hoelzl@41979
   701
  } ultimately have "x<=y+e" by blast
hoelzl@43920
   702
} from this show ?thesis using ereal_le_epsilon by auto
hoelzl@41979
   703
qed
hoelzl@41979
   704
hoelzl@43920
   705
lemma ereal_le_real:
hoelzl@43920
   706
  fixes x y :: ereal
hoelzl@43920
   707
  assumes "ALL z. x <= ereal z --> y <= ereal z"
hoelzl@41979
   708
  shows "y <= x"
huffman@44142
   709
by (metis assms ereal_bot ereal_cases ereal_infty_less_eq(2) ereal_less_eq(1) linorder_le_cases)
hoelzl@41979
   710
hoelzl@43920
   711
lemma ereal_le_ereal:
hoelzl@43920
   712
  fixes x y :: ereal
hoelzl@41979
   713
  assumes "\<And>B. B < x \<Longrightarrow> B <= y"
hoelzl@41979
   714
  shows "x <= y"
hoelzl@43920
   715
by (metis assms ereal_dense leD linorder_le_less_linear)
hoelzl@41979
   716
hoelzl@43920
   717
lemma ereal_ge_ereal:
hoelzl@43920
   718
  fixes x y :: ereal
hoelzl@41979
   719
  assumes "ALL B. B>x --> B >= y"
hoelzl@41979
   720
  shows "x >= y"
hoelzl@43920
   721
by (metis assms ereal_dense leD linorder_le_less_linear)
hoelzl@41978
   722
hoelzl@43920
   723
lemma setprod_ereal_0:
hoelzl@43920
   724
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@42950
   725
  shows "(\<Prod>i\<in>A. f i) = 0 \<longleftrightarrow> (finite A \<and> (\<exists>i\<in>A. f i = 0))"
hoelzl@42950
   726
proof cases
hoelzl@42950
   727
  assume "finite A"
hoelzl@42950
   728
  then show ?thesis by (induct A) auto
hoelzl@42950
   729
qed auto
hoelzl@42950
   730
hoelzl@43920
   731
lemma setprod_ereal_pos:
hoelzl@43920
   732
  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)"
hoelzl@42950
   733
proof cases
hoelzl@42950
   734
  assume "finite I" from this pos show ?thesis by induct auto
hoelzl@42950
   735
qed simp
hoelzl@42950
   736
hoelzl@42950
   737
lemma setprod_PInf:
hoelzl@43923
   738
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@42950
   739
  assumes "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
hoelzl@42950
   740
  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)"
hoelzl@42950
   741
proof cases
hoelzl@42950
   742
  assume "finite I" from this assms show ?thesis
hoelzl@42950
   743
  proof (induct I)
hoelzl@42950
   744
    case (insert i I)
hoelzl@43920
   745
    then have pos: "0 \<le> f i" "0 \<le> setprod f I" by (auto intro!: setprod_ereal_pos)
hoelzl@42950
   746
    from insert have "(\<Prod>j\<in>insert i I. f j) = \<infinity> \<longleftrightarrow> setprod f I * f i = \<infinity>" by auto
hoelzl@42950
   747
    also have "\<dots> \<longleftrightarrow> (setprod f I = \<infinity> \<or> f i = \<infinity>) \<and> f i \<noteq> 0 \<and> setprod f I \<noteq> 0"
hoelzl@43920
   748
      using setprod_ereal_pos[of I f] pos
hoelzl@43920
   749
      by (cases rule: ereal2_cases[of "f i" "setprod f I"]) auto
hoelzl@42950
   750
    also have "\<dots> \<longleftrightarrow> finite (insert i I) \<and> (\<exists>j\<in>insert i I. f j = \<infinity>) \<and> (\<forall>j\<in>insert i I. f j \<noteq> 0)"
hoelzl@43920
   751
      using insert by (auto simp: setprod_ereal_0)
hoelzl@42950
   752
    finally show ?case .
hoelzl@42950
   753
  qed simp
hoelzl@42950
   754
qed simp
hoelzl@42950
   755
hoelzl@43920
   756
lemma setprod_ereal: "(\<Prod>i\<in>A. ereal (f i)) = ereal (setprod f A)"
hoelzl@42950
   757
proof cases
hoelzl@42950
   758
  assume "finite A" then show ?thesis
hoelzl@43920
   759
    by induct (auto simp: one_ereal_def)
hoelzl@43920
   760
qed (simp add: one_ereal_def)
hoelzl@42950
   761
hoelzl@41978
   762
subsubsection {* Power *}
hoelzl@41978
   763
hoelzl@43920
   764
lemma ereal_power[simp]: "(ereal x) ^ n = ereal (x^n)"
hoelzl@43920
   765
  by (induct n) (auto simp: one_ereal_def)
hoelzl@41978
   766
hoelzl@43923
   767
lemma ereal_power_PInf[simp]: "(\<infinity>::ereal) ^ n = (if n = 0 then 1 else \<infinity>)"
hoelzl@43920
   768
  by (induct n) (auto simp: one_ereal_def)
hoelzl@41978
   769
hoelzl@43920
   770
lemma ereal_power_uminus[simp]:
hoelzl@43920
   771
  fixes x :: ereal
hoelzl@41978
   772
  shows "(- x) ^ n = (if even n then x ^ n else - (x^n))"
hoelzl@43920
   773
  by (induct n) (auto simp: one_ereal_def)
hoelzl@41978
   774
hoelzl@43920
   775
lemma ereal_power_number_of[simp]:
hoelzl@43920
   776
  "(number_of num :: ereal) ^ n = ereal (number_of num ^ n)"
hoelzl@43920
   777
  by (induct n) (auto simp: one_ereal_def)
hoelzl@41979
   778
hoelzl@43920
   779
lemma zero_le_power_ereal[simp]:
hoelzl@43920
   780
  fixes a :: ereal assumes "0 \<le> a"
hoelzl@41979
   781
  shows "0 \<le> a ^ n"
hoelzl@43920
   782
  using assms by (induct n) (auto simp: ereal_zero_le_0_iff)
hoelzl@41979
   783
hoelzl@41973
   784
subsubsection {* Subtraction *}
hoelzl@41973
   785
hoelzl@43920
   786
lemma ereal_minus_minus_image[simp]:
hoelzl@43920
   787
  fixes S :: "ereal set"
hoelzl@41973
   788
  shows "uminus ` uminus ` S = S"
hoelzl@41973
   789
  by (auto simp: image_iff)
hoelzl@41973
   790
hoelzl@43920
   791
lemma ereal_uminus_lessThan[simp]:
hoelzl@43920
   792
  fixes a :: ereal shows "uminus ` {..<a} = {-a<..}"
hoelzl@41973
   793
proof (safe intro!: image_eqI)
hoelzl@41973
   794
  fix x assume "-a < x"
hoelzl@43920
   795
  then have "- x < - (- a)" by (simp del: ereal_uminus_uminus)
hoelzl@41973
   796
  then show "- x < a" by simp
hoelzl@41973
   797
qed auto
hoelzl@41973
   798
hoelzl@43920
   799
lemma ereal_uminus_greaterThan[simp]:
hoelzl@43920
   800
  "uminus ` {(a::ereal)<..} = {..<-a}"
hoelzl@43920
   801
  by (metis ereal_uminus_lessThan ereal_uminus_uminus
hoelzl@43920
   802
            ereal_minus_minus_image)
hoelzl@41973
   803
hoelzl@43920
   804
instantiation ereal :: minus
hoelzl@41973
   805
begin
hoelzl@43920
   806
definition "x - y = x + -(y::ereal)"
hoelzl@41973
   807
instance ..
hoelzl@41973
   808
end
hoelzl@41973
   809
hoelzl@43920
   810
lemma ereal_minus[simp]:
hoelzl@43920
   811
  "ereal r - ereal p = ereal (r - p)"
hoelzl@43920
   812
  "-\<infinity> - ereal r = -\<infinity>"
hoelzl@43920
   813
  "ereal r - \<infinity> = -\<infinity>"
hoelzl@43923
   814
  "(\<infinity>::ereal) - x = \<infinity>"
hoelzl@43923
   815
  "-(\<infinity>::ereal) - \<infinity> = -\<infinity>"
hoelzl@41973
   816
  "x - -y = x + y"
hoelzl@41973
   817
  "x - 0 = x"
hoelzl@41973
   818
  "0 - x = -x"
hoelzl@43920
   819
  by (simp_all add: minus_ereal_def)
hoelzl@41973
   820
hoelzl@43920
   821
lemma ereal_x_minus_x[simp]:
hoelzl@43923
   822
  "x - x = (if \<bar>x\<bar> = \<infinity> then \<infinity> else 0::ereal)"
hoelzl@41973
   823
  by (cases x) simp_all
hoelzl@41973
   824
hoelzl@43920
   825
lemma ereal_eq_minus_iff:
hoelzl@43920
   826
  fixes x y z :: ereal
hoelzl@41973
   827
  shows "x = z - y \<longleftrightarrow>
hoelzl@41976
   828
    (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x + y = z) \<and>
hoelzl@41973
   829
    (y = -\<infinity> \<longrightarrow> x = \<infinity>) \<and>
hoelzl@41973
   830
    (y = \<infinity> \<longrightarrow> z = \<infinity> \<longrightarrow> x = \<infinity>) \<and>
hoelzl@41973
   831
    (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>)"
hoelzl@43920
   832
  by (cases rule: ereal3_cases[of x y z]) auto
hoelzl@41973
   833
hoelzl@43920
   834
lemma ereal_eq_minus:
hoelzl@43920
   835
  fixes x y z :: ereal
hoelzl@41976
   836
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x = z - y \<longleftrightarrow> x + y = z"
hoelzl@43920
   837
  by (auto simp: ereal_eq_minus_iff)
hoelzl@41973
   838
hoelzl@43920
   839
lemma ereal_less_minus_iff:
hoelzl@43920
   840
  fixes x y z :: ereal
hoelzl@41973
   841
  shows "x < z - y \<longleftrightarrow>
hoelzl@41973
   842
    (y = \<infinity> \<longrightarrow> z = \<infinity> \<and> x \<noteq> \<infinity>) \<and>
hoelzl@41973
   843
    (y = -\<infinity> \<longrightarrow> x \<noteq> \<infinity>) \<and>
hoelzl@41976
   844
    (\<bar>y\<bar> \<noteq> \<infinity>\<longrightarrow> x + y < z)"
hoelzl@43920
   845
  by (cases rule: ereal3_cases[of x y z]) auto
hoelzl@41973
   846
hoelzl@43920
   847
lemma ereal_less_minus:
hoelzl@43920
   848
  fixes x y z :: ereal
hoelzl@41976
   849
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x < z - y \<longleftrightarrow> x + y < z"
hoelzl@43920
   850
  by (auto simp: ereal_less_minus_iff)
hoelzl@41973
   851
hoelzl@43920
   852
lemma ereal_le_minus_iff:
hoelzl@43920
   853
  fixes x y z :: ereal
hoelzl@41973
   854
  shows "x \<le> z - y \<longleftrightarrow>
hoelzl@41973
   855
    (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>) \<and>
hoelzl@41976
   856
    (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x + y \<le> z)"
hoelzl@43920
   857
  by (cases rule: ereal3_cases[of x y z]) auto
hoelzl@41973
   858
hoelzl@43920
   859
lemma ereal_le_minus:
hoelzl@43920
   860
  fixes x y z :: ereal
hoelzl@41976
   861
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x \<le> z - y \<longleftrightarrow> x + y \<le> z"
hoelzl@43920
   862
  by (auto simp: ereal_le_minus_iff)
hoelzl@41973
   863
hoelzl@43920
   864
lemma ereal_minus_less_iff:
hoelzl@43920
   865
  fixes x y z :: ereal
hoelzl@41973
   866
  shows "x - y < z \<longleftrightarrow>
hoelzl@41973
   867
    y \<noteq> -\<infinity> \<and> (y = \<infinity> \<longrightarrow> x \<noteq> \<infinity> \<and> z \<noteq> -\<infinity>) \<and>
hoelzl@41973
   868
    (y \<noteq> \<infinity> \<longrightarrow> x < z + y)"
hoelzl@43920
   869
  by (cases rule: ereal3_cases[of x y z]) auto
hoelzl@41973
   870
hoelzl@43920
   871
lemma ereal_minus_less:
hoelzl@43920
   872
  fixes x y z :: ereal
hoelzl@41976
   873
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x - y < z \<longleftrightarrow> x < z + y"
hoelzl@43920
   874
  by (auto simp: ereal_minus_less_iff)
hoelzl@41973
   875
hoelzl@43920
   876
lemma ereal_minus_le_iff:
hoelzl@43920
   877
  fixes x y z :: ereal
hoelzl@41973
   878
  shows "x - y \<le> z \<longleftrightarrow>
hoelzl@41973
   879
    (y = -\<infinity> \<longrightarrow> z = \<infinity>) \<and>
hoelzl@41973
   880
    (y = \<infinity> \<longrightarrow> x = \<infinity> \<longrightarrow> z = \<infinity>) \<and>
hoelzl@41976
   881
    (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x \<le> z + y)"
hoelzl@43920
   882
  by (cases rule: ereal3_cases[of x y z]) auto
hoelzl@41973
   883
hoelzl@43920
   884
lemma ereal_minus_le:
hoelzl@43920
   885
  fixes x y z :: ereal
hoelzl@41976
   886
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x - y \<le> z \<longleftrightarrow> x \<le> z + y"
hoelzl@43920
   887
  by (auto simp: ereal_minus_le_iff)
hoelzl@41973
   888
hoelzl@43920
   889
lemma ereal_minus_eq_minus_iff:
hoelzl@43920
   890
  fixes a b c :: ereal
hoelzl@41973
   891
  shows "a - b = a - c \<longleftrightarrow>
hoelzl@41973
   892
    b = c \<or> a = \<infinity> \<or> (a = -\<infinity> \<and> b \<noteq> -\<infinity> \<and> c \<noteq> -\<infinity>)"
hoelzl@43920
   893
  by (cases rule: ereal3_cases[of a b c]) auto
hoelzl@41973
   894
hoelzl@43920
   895
lemma ereal_add_le_add_iff:
hoelzl@43923
   896
  fixes a b c :: ereal
hoelzl@43923
   897
  shows "c + a \<le> c + b \<longleftrightarrow>
hoelzl@41973
   898
    a \<le> b \<or> c = \<infinity> \<or> (c = -\<infinity> \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>)"
hoelzl@43920
   899
  by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps)
hoelzl@41973
   900
hoelzl@43920
   901
lemma ereal_mult_le_mult_iff:
hoelzl@43923
   902
  fixes a b c :: ereal
hoelzl@43923
   903
  shows "\<bar>c\<bar> \<noteq> \<infinity> \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow> (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
hoelzl@43920
   904
  by (cases rule: ereal3_cases[of a b c]) (simp_all add: mult_le_cancel_left)
hoelzl@41973
   905
hoelzl@43920
   906
lemma ereal_minus_mono:
hoelzl@43920
   907
  fixes A B C D :: ereal assumes "A \<le> B" "D \<le> C"
hoelzl@41979
   908
  shows "A - C \<le> B - D"
hoelzl@41979
   909
  using assms
hoelzl@43920
   910
  by (cases rule: ereal3_cases[case_product ereal_cases, of A B C D]) simp_all
hoelzl@41979
   911
hoelzl@43920
   912
lemma real_of_ereal_minus:
hoelzl@43923
   913
  fixes a b :: ereal
hoelzl@43923
   914
  shows "real (a - b) = (if \<bar>a\<bar> = \<infinity> \<or> \<bar>b\<bar> = \<infinity> then 0 else real a - real b)"
hoelzl@43920
   915
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41979
   916
hoelzl@43920
   917
lemma ereal_diff_positive:
hoelzl@43920
   918
  fixes a b :: ereal shows "a \<le> b \<Longrightarrow> 0 \<le> b - a"
hoelzl@43920
   919
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41979
   920
hoelzl@43920
   921
lemma ereal_between:
hoelzl@43920
   922
  fixes x e :: ereal
hoelzl@41976
   923
  assumes "\<bar>x\<bar> \<noteq> \<infinity>" "0 < e"
hoelzl@41973
   924
  shows "x - e < x" "x < x + e"
hoelzl@41973
   925
using assms apply (cases x, cases e) apply auto
hoelzl@41973
   926
using assms by (cases x, cases e) auto
hoelzl@41973
   927
hoelzl@41973
   928
subsubsection {* Division *}
hoelzl@41973
   929
hoelzl@43920
   930
instantiation ereal :: inverse
hoelzl@41973
   931
begin
hoelzl@41973
   932
hoelzl@43920
   933
function inverse_ereal where
hoelzl@43920
   934
"inverse (ereal r) = (if r = 0 then \<infinity> else ereal (inverse r))" |
hoelzl@43923
   935
"inverse (\<infinity>::ereal) = 0" |
hoelzl@43923
   936
"inverse (-\<infinity>::ereal) = 0"
hoelzl@43920
   937
  by (auto intro: ereal_cases)
hoelzl@41973
   938
termination by (relation "{}") simp
hoelzl@41973
   939
hoelzl@43920
   940
definition "x / y = x * inverse (y :: ereal)"
hoelzl@41973
   941
hoelzl@41973
   942
instance proof qed
hoelzl@41973
   943
end
hoelzl@41973
   944
hoelzl@43920
   945
lemma real_of_ereal_inverse[simp]:
hoelzl@43920
   946
  fixes a :: ereal
hoelzl@42950
   947
  shows "real (inverse a) = 1 / real a"
hoelzl@42950
   948
  by (cases a) (auto simp: inverse_eq_divide)
hoelzl@42950
   949
hoelzl@43920
   950
lemma ereal_inverse[simp]:
hoelzl@43923
   951
  "inverse (0::ereal) = \<infinity>"
hoelzl@43920
   952
  "inverse (1::ereal) = 1"
hoelzl@43920
   953
  by (simp_all add: one_ereal_def zero_ereal_def)
hoelzl@41973
   954
hoelzl@43920
   955
lemma ereal_divide[simp]:
hoelzl@43920
   956
  "ereal r / ereal p = (if p = 0 then ereal r * \<infinity> else ereal (r / p))"
hoelzl@43920
   957
  unfolding divide_ereal_def by (auto simp: divide_real_def)
hoelzl@41973
   958
hoelzl@43920
   959
lemma ereal_divide_same[simp]:
hoelzl@43923
   960
  fixes x :: ereal shows "x / x = (if \<bar>x\<bar> = \<infinity> \<or> x = 0 then 0 else 1)"
hoelzl@41973
   961
  by (cases x)
hoelzl@43920
   962
     (simp_all add: divide_real_def divide_ereal_def one_ereal_def)
hoelzl@41973
   963
hoelzl@43920
   964
lemma ereal_inv_inv[simp]:
hoelzl@43923
   965
  fixes x :: ereal shows "inverse (inverse x) = (if x \<noteq> -\<infinity> then x else \<infinity>)"
hoelzl@41973
   966
  by (cases x) auto
hoelzl@41973
   967
hoelzl@43920
   968
lemma ereal_inverse_minus[simp]:
hoelzl@43923
   969
  fixes x :: ereal shows "inverse (- x) = (if x = 0 then \<infinity> else -inverse x)"
hoelzl@41973
   970
  by (cases x) simp_all
hoelzl@41973
   971
hoelzl@43920
   972
lemma ereal_uminus_divide[simp]:
hoelzl@43920
   973
  fixes x y :: ereal shows "- x / y = - (x / y)"
hoelzl@43920
   974
  unfolding divide_ereal_def by simp
hoelzl@41973
   975
hoelzl@43920
   976
lemma ereal_divide_Infty[simp]:
hoelzl@43923
   977
  fixes x :: ereal shows "x / \<infinity> = 0" "x / -\<infinity> = 0"
hoelzl@43920
   978
  unfolding divide_ereal_def by simp_all
hoelzl@41973
   979
hoelzl@43920
   980
lemma ereal_divide_one[simp]:
hoelzl@43920
   981
  "x / 1 = (x::ereal)"
hoelzl@43920
   982
  unfolding divide_ereal_def by simp
hoelzl@41973
   983
hoelzl@43920
   984
lemma ereal_divide_ereal[simp]:
hoelzl@43920
   985
  "\<infinity> / ereal r = (if 0 \<le> r then \<infinity> else -\<infinity>)"
hoelzl@43920
   986
  unfolding divide_ereal_def by simp
hoelzl@41973
   987
hoelzl@43920
   988
lemma zero_le_divide_ereal[simp]:
hoelzl@43920
   989
  fixes a :: ereal assumes "0 \<le> a" "0 \<le> b"
hoelzl@41978
   990
  shows "0 \<le> a / b"
hoelzl@43920
   991
  using assms by (cases rule: ereal2_cases[of a b]) (auto simp: zero_le_divide_iff)
hoelzl@41978
   992
hoelzl@43920
   993
lemma ereal_le_divide_pos:
hoelzl@43923
   994
  fixes x y z :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> x * y \<le> z"
hoelzl@43920
   995
  by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
   996
hoelzl@43920
   997
lemma ereal_divide_le_pos:
hoelzl@43923
   998
  fixes x y z :: ereal shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> z \<le> x * y"
hoelzl@43920
   999
  by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
  1000
hoelzl@43920
  1001
lemma ereal_le_divide_neg:
hoelzl@43923
  1002
  fixes x y z :: ereal shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> z \<le> x * y"
hoelzl@43920
  1003
  by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
  1004
hoelzl@43920
  1005
lemma ereal_divide_le_neg:
hoelzl@43923
  1006
  fixes x y z :: ereal shows "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> x * y \<le> z"
hoelzl@43920
  1007
  by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
  1008
hoelzl@43920
  1009
lemma ereal_inverse_antimono_strict:
hoelzl@43920
  1010
  fixes x y :: ereal
hoelzl@41973
  1011
  shows "0 \<le> x \<Longrightarrow> x < y \<Longrightarrow> inverse y < inverse x"
hoelzl@43920
  1012
  by (cases rule: ereal2_cases[of x y]) auto
hoelzl@41973
  1013
hoelzl@43920
  1014
lemma ereal_inverse_antimono:
hoelzl@43920
  1015
  fixes x y :: ereal
hoelzl@41973
  1016
  shows "0 \<le> x \<Longrightarrow> x <= y \<Longrightarrow> inverse y <= inverse x"
hoelzl@43920
  1017
  by (cases rule: ereal2_cases[of x y]) auto
hoelzl@41973
  1018
hoelzl@41973
  1019
lemma inverse_inverse_Pinfty_iff[simp]:
hoelzl@43923
  1020
  fixes x :: ereal shows "inverse x = \<infinity> \<longleftrightarrow> x = 0"
hoelzl@41973
  1021
  by (cases x) auto
hoelzl@41973
  1022
hoelzl@43920
  1023
lemma ereal_inverse_eq_0:
hoelzl@43923
  1024
  fixes x :: ereal shows "inverse x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity>"
hoelzl@41973
  1025
  by (cases x) auto
hoelzl@41973
  1026
hoelzl@43920
  1027
lemma ereal_0_gt_inverse:
hoelzl@43920
  1028
  fixes x :: ereal shows "0 < inverse x \<longleftrightarrow> x \<noteq> \<infinity> \<and> 0 \<le> x"
hoelzl@41979
  1029
  by (cases x) auto
hoelzl@41979
  1030
hoelzl@43920
  1031
lemma ereal_mult_less_right:
hoelzl@43923
  1032
  fixes a b c :: ereal
hoelzl@41973
  1033
  assumes "b * a < c * a" "0 < a" "a < \<infinity>"
hoelzl@41973
  1034
  shows "b < c"
hoelzl@41973
  1035
  using assms
hoelzl@43920
  1036
  by (cases rule: ereal3_cases[of a b c])
hoelzl@41973
  1037
     (auto split: split_if_asm simp: zero_less_mult_iff zero_le_mult_iff)
hoelzl@41973
  1038
hoelzl@43920
  1039
lemma ereal_power_divide:
hoelzl@43923
  1040
  fixes x y :: ereal shows "y \<noteq> 0 \<Longrightarrow> (x / y) ^ n = x^n / y^n"
hoelzl@43920
  1041
  by (cases rule: ereal2_cases[of x y])
hoelzl@43920
  1042
     (auto simp: one_ereal_def zero_ereal_def power_divide not_le
hoelzl@41979
  1043
                 power_less_zero_eq zero_le_power_iff)
hoelzl@41979
  1044
hoelzl@43920
  1045
lemma ereal_le_mult_one_interval:
hoelzl@43920
  1046
  fixes x y :: ereal
hoelzl@41979
  1047
  assumes y: "y \<noteq> -\<infinity>"
hoelzl@41979
  1048
  assumes z: "\<And>z. \<lbrakk> 0 < z ; z < 1 \<rbrakk> \<Longrightarrow> z * x \<le> y"
hoelzl@41979
  1049
  shows "x \<le> y"
hoelzl@41979
  1050
proof (cases x)
hoelzl@43920
  1051
  case PInf with z[of "1 / 2"] show "x \<le> y" by (simp add: one_ereal_def)
hoelzl@41979
  1052
next
hoelzl@41979
  1053
  case (real r) note r = this
hoelzl@41979
  1054
  show "x \<le> y"
hoelzl@41979
  1055
  proof (cases y)
hoelzl@41979
  1056
    case (real p) note p = this
hoelzl@41979
  1057
    have "r \<le> p"
hoelzl@41979
  1058
    proof (rule field_le_mult_one_interval)
hoelzl@41979
  1059
      fix z :: real assume "0 < z" and "z < 1"
hoelzl@43920
  1060
      with z[of "ereal z"]
hoelzl@43920
  1061
      show "z * r \<le> p" using p r by (auto simp: zero_le_mult_iff one_ereal_def)
hoelzl@41979
  1062
    qed
hoelzl@41979
  1063
    then show "x \<le> y" using p r by simp
hoelzl@41979
  1064
  qed (insert y, simp_all)
hoelzl@41979
  1065
qed simp
hoelzl@41978
  1066
noschinl@45934
  1067
lemma ereal_divide_right_mono[simp]:
noschinl@45934
  1068
  fixes x y z :: ereal
noschinl@45934
  1069
  assumes "x \<le> y" "0 < z" shows "x / z \<le> y / z"
noschinl@45934
  1070
using assms by (cases x y z rule: ereal3_cases) (auto intro: divide_right_mono)
noschinl@45934
  1071
noschinl@45934
  1072
lemma ereal_divide_left_mono[simp]:
noschinl@45934
  1073
  fixes x y z :: ereal
noschinl@45934
  1074
  assumes "y \<le> x" "0 < z" "0 < x * y"
noschinl@45934
  1075
  shows "z / x \<le> z / y"
noschinl@45934
  1076
using assms by (cases x y z rule: ereal3_cases)
noschinl@45934
  1077
  (auto intro: divide_left_mono simp: field_simps sign_simps split: split_if_asm)
noschinl@45934
  1078
noschinl@45934
  1079
lemma ereal_divide_zero_left[simp]:
noschinl@45934
  1080
  fixes a :: ereal
noschinl@45934
  1081
  shows "0 / a = 0"
noschinl@45934
  1082
  by (cases a) (auto simp: zero_ereal_def)
noschinl@45934
  1083
noschinl@45934
  1084
lemma ereal_times_divide_eq_left[simp]:
noschinl@45934
  1085
  fixes a b c :: ereal
noschinl@45934
  1086
  shows "b / c * a = b * a / c"
noschinl@45934
  1087
  by (cases a b c rule: ereal3_cases) (auto simp: field_simps sign_simps)
noschinl@45934
  1088
hoelzl@41973
  1089
subsection "Complete lattice"
hoelzl@41973
  1090
hoelzl@43920
  1091
instantiation ereal :: lattice
hoelzl@41973
  1092
begin
hoelzl@43920
  1093
definition [simp]: "sup x y = (max x y :: ereal)"
hoelzl@43920
  1094
definition [simp]: "inf x y = (min x y :: ereal)"
hoelzl@41973
  1095
instance proof qed simp_all
hoelzl@41973
  1096
end
hoelzl@41973
  1097
hoelzl@43920
  1098
instantiation ereal :: complete_lattice
hoelzl@41973
  1099
begin
hoelzl@41973
  1100
hoelzl@43923
  1101
definition "bot = (-\<infinity>::ereal)"
hoelzl@43923
  1102
definition "top = (\<infinity>::ereal)"
hoelzl@41973
  1103
hoelzl@43923
  1104
definition "Sup S = (LEAST z. \<forall>x\<in>S. x \<le> z :: ereal)"
hoelzl@43923
  1105
definition "Inf S = (GREATEST z. \<forall>x\<in>S. z \<le> x :: ereal)"
hoelzl@41973
  1106
hoelzl@43920
  1107
lemma ereal_complete_Sup:
hoelzl@43920
  1108
  fixes S :: "ereal set" assumes "S \<noteq> {}"
hoelzl@41973
  1109
  shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>S. y \<le> z) \<longrightarrow> x \<le> z)"
hoelzl@41973
  1110
proof cases
hoelzl@43920
  1111
  assume "\<exists>x. \<forall>a\<in>S. a \<le> ereal x"
hoelzl@43920
  1112
  then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> ereal y" by auto
hoelzl@41973
  1113
  then have "\<infinity> \<notin> S" by force
hoelzl@41973
  1114
  show ?thesis
hoelzl@41973
  1115
  proof cases
hoelzl@41973
  1116
    assume "S = {-\<infinity>}"
hoelzl@41973
  1117
    then show ?thesis by (auto intro!: exI[of _ "-\<infinity>"])
hoelzl@41973
  1118
  next
hoelzl@41973
  1119
    assume "S \<noteq> {-\<infinity>}"
hoelzl@41973
  1120
    with `S \<noteq> {}` `\<infinity> \<notin> S` obtain x where "x \<in> S - {-\<infinity>}" "x \<noteq> \<infinity>" by auto
hoelzl@41973
  1121
    with y `\<infinity> \<notin> S` have "\<forall>z\<in>real ` (S - {-\<infinity>}). z \<le> y"
hoelzl@43920
  1122
      by (auto simp: real_of_ereal_ord_simps)
huffman@44669
  1123
    with complete_real[of "real ` (S - {-\<infinity>})"] `x \<in> S - {-\<infinity>}`
hoelzl@41973
  1124
    obtain s where s:
hoelzl@41973
  1125
       "\<forall>y\<in>S - {-\<infinity>}. real y \<le> s" "\<And>z. (\<forall>y\<in>S - {-\<infinity>}. real y \<le> z) \<Longrightarrow> s \<le> z"
hoelzl@41973
  1126
       by auto
hoelzl@41973
  1127
    show ?thesis
hoelzl@43920
  1128
    proof (safe intro!: exI[of _ "ereal s"])
hoelzl@43920
  1129
      fix z assume "z \<in> S" with `\<infinity> \<notin> S` show "z \<le> ereal s"
hoelzl@41973
  1130
      proof (cases z)
hoelzl@41973
  1131
        case (real r)
hoelzl@41973
  1132
        then show ?thesis
hoelzl@43920
  1133
          using s(1)[rule_format, of z] `z \<in> S` `z = ereal r` by auto
hoelzl@41973
  1134
      qed auto
hoelzl@41973
  1135
    next
hoelzl@41973
  1136
      fix z assume *: "\<forall>y\<in>S. y \<le> z"
hoelzl@43920
  1137
      with `S \<noteq> {-\<infinity>}` `S \<noteq> {}` show "ereal s \<le> z"
hoelzl@41973
  1138
      proof (cases z)
hoelzl@41973
  1139
        case (real u)
hoelzl@41973
  1140
        with * have "s \<le> u"
hoelzl@43920
  1141
          by (intro s(2)[of u]) (auto simp: real_of_ereal_ord_simps)
hoelzl@41973
  1142
        then show ?thesis using real by simp
hoelzl@41973
  1143
      qed auto
hoelzl@41973
  1144
    qed
hoelzl@41973
  1145
  qed
hoelzl@41973
  1146
next
hoelzl@43920
  1147
  assume *: "\<not> (\<exists>x. \<forall>a\<in>S. a \<le> ereal x)"
hoelzl@41973
  1148
  show ?thesis
hoelzl@41973
  1149
  proof (safe intro!: exI[of _ \<infinity>])
hoelzl@41973
  1150
    fix y assume **: "\<forall>z\<in>S. z \<le> y"
hoelzl@41973
  1151
    with * show "\<infinity> \<le> y"
hoelzl@41973
  1152
    proof (cases y)
hoelzl@41973
  1153
      case MInf with * ** show ?thesis by (force simp: not_le)
hoelzl@41973
  1154
    qed auto
hoelzl@41973
  1155
  qed simp
hoelzl@41973
  1156
qed
hoelzl@41973
  1157
hoelzl@43920
  1158
lemma ereal_complete_Inf:
hoelzl@43920
  1159
  fixes S :: "ereal set" assumes "S ~= {}"
hoelzl@41973
  1160
  shows "EX x. (ALL y:S. x <= y) & (ALL z. (ALL y:S. z <= y) --> z <= x)"
hoelzl@41973
  1161
proof-
hoelzl@41973
  1162
def S1 == "uminus ` S"
hoelzl@41973
  1163
hence "S1 ~= {}" using assms by auto
hoelzl@41973
  1164
from this obtain x where x_def: "(ALL y:S1. y <= x) & (ALL z. (ALL y:S1. y <= z) --> x <= z)"
hoelzl@43920
  1165
   using ereal_complete_Sup[of S1] by auto
hoelzl@41973
  1166
{ fix z assume "ALL y:S. z <= y"
hoelzl@41973
  1167
  hence "ALL y:S1. y <= -z" unfolding S1_def by auto
hoelzl@41973
  1168
  hence "x <= -z" using x_def by auto
hoelzl@41973
  1169
  hence "z <= -x"
hoelzl@43920
  1170
    apply (subst ereal_uminus_uminus[symmetric])
hoelzl@43920
  1171
    unfolding ereal_minus_le_minus . }
hoelzl@41973
  1172
moreover have "(ALL y:S. -x <= y)"
hoelzl@41973
  1173
   using x_def unfolding S1_def
hoelzl@41973
  1174
   apply simp
hoelzl@43920
  1175
   apply (subst (3) ereal_uminus_uminus[symmetric])
hoelzl@43920
  1176
   unfolding ereal_minus_le_minus by simp
hoelzl@41973
  1177
ultimately show ?thesis by auto
hoelzl@41973
  1178
qed
hoelzl@41973
  1179
hoelzl@43920
  1180
lemma ereal_complete_uminus_eq:
hoelzl@43920
  1181
  fixes S :: "ereal set"
hoelzl@41973
  1182
  shows "(\<forall>y\<in>uminus`S. y \<le> x) \<and> (\<forall>z. (\<forall>y\<in>uminus`S. y \<le> z) \<longrightarrow> x \<le> z)
hoelzl@41973
  1183
     \<longleftrightarrow> (\<forall>y\<in>S. -x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> -x)"
hoelzl@43920
  1184
  by simp (metis ereal_minus_le_minus ereal_uminus_uminus)
hoelzl@41973
  1185
hoelzl@43920
  1186
lemma ereal_Sup_uminus_image_eq:
hoelzl@43920
  1187
  fixes S :: "ereal set"
hoelzl@41973
  1188
  shows "Sup (uminus ` S) = - Inf S"
hoelzl@41973
  1189
proof cases
hoelzl@41973
  1190
  assume "S = {}"
hoelzl@43920
  1191
  moreover have "(THE x. All (op \<le> x)) = (-\<infinity>::ereal)"
hoelzl@43920
  1192
    by (rule the_equality) (auto intro!: ereal_bot)
hoelzl@43920
  1193
  moreover have "(SOME x. \<forall>y. y \<le> x) = (\<infinity>::ereal)"
hoelzl@43920
  1194
    by (rule some_equality) (auto intro!: ereal_top)
hoelzl@43920
  1195
  ultimately show ?thesis unfolding Inf_ereal_def Sup_ereal_def
hoelzl@41973
  1196
    Least_def Greatest_def GreatestM_def by simp
hoelzl@41973
  1197
next
hoelzl@41973
  1198
  assume "S \<noteq> {}"
hoelzl@43920
  1199
  with ereal_complete_Sup[of "uminus`S"]
hoelzl@41973
  1200
  obtain x where x: "(\<forall>y\<in>S. -x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> -x)"
hoelzl@43920
  1201
    unfolding ereal_complete_uminus_eq by auto
hoelzl@41973
  1202
  show "Sup (uminus ` S) = - Inf S"
hoelzl@43920
  1203
    unfolding Inf_ereal_def Greatest_def GreatestM_def
hoelzl@41973
  1204
  proof (intro someI2[of _ _ "\<lambda>x. Sup (uminus`S) = - x"])
hoelzl@41973
  1205
    show "(\<forall>y\<in>S. -x \<le> y) \<and> (\<forall>y. (\<forall>z\<in>S. y \<le> z) \<longrightarrow> y \<le> -x)"
hoelzl@41973
  1206
      using x .
hoelzl@41973
  1207
    fix x' assume "(\<forall>y\<in>S. x' \<le> y) \<and> (\<forall>y. (\<forall>z\<in>S. y \<le> z) \<longrightarrow> y \<le> x')"
hoelzl@41973
  1208
    then have "(\<forall>y\<in>uminus`S. y \<le> - x') \<and> (\<forall>y. (\<forall>z\<in>uminus`S. z \<le> y) \<longrightarrow> - x' \<le> y)"
hoelzl@43920
  1209
      unfolding ereal_complete_uminus_eq by simp
hoelzl@41973
  1210
    then show "Sup (uminus ` S) = -x'"
hoelzl@43920
  1211
      unfolding Sup_ereal_def ereal_uminus_eq_iff
hoelzl@41973
  1212
      by (intro Least_equality) auto
hoelzl@41973
  1213
  qed
hoelzl@41973
  1214
qed
hoelzl@41973
  1215
hoelzl@41973
  1216
instance
hoelzl@41973
  1217
proof
hoelzl@43920
  1218
  { fix x :: ereal and A
hoelzl@43920
  1219
    show "bot <= x" by (cases x) (simp_all add: bot_ereal_def)
hoelzl@43920
  1220
    show "x <= top" by (simp add: top_ereal_def) }
hoelzl@41973
  1221
hoelzl@43920
  1222
  { fix x :: ereal and A assume "x : A"
hoelzl@43920
  1223
    with ereal_complete_Sup[of A]
hoelzl@41973
  1224
    obtain s where s: "\<forall>y\<in>A. y <= s" "\<forall>z. (\<forall>y\<in>A. y <= z) \<longrightarrow> s <= z" by auto
hoelzl@41973
  1225
    hence "x <= s" using `x : A` by auto
hoelzl@43920
  1226
    also have "... = Sup A" using s unfolding Sup_ereal_def
hoelzl@41973
  1227
      by (auto intro!: Least_equality[symmetric])
hoelzl@41973
  1228
    finally show "x <= Sup A" . }
hoelzl@41973
  1229
  note le_Sup = this
hoelzl@41973
  1230
hoelzl@43920
  1231
  { fix x :: ereal and A assume *: "!!z. (z : A ==> z <= x)"
hoelzl@41973
  1232
    show "Sup A <= x"
hoelzl@41973
  1233
    proof (cases "A = {}")
hoelzl@41973
  1234
      case True
hoelzl@43920
  1235
      hence "Sup A = -\<infinity>" unfolding Sup_ereal_def
hoelzl@41973
  1236
        by (auto intro!: Least_equality)
hoelzl@41973
  1237
      thus "Sup A <= x" by simp
hoelzl@41973
  1238
    next
hoelzl@41973
  1239
      case False
hoelzl@43920
  1240
      with ereal_complete_Sup[of A]
hoelzl@41973
  1241
      obtain s where s: "\<forall>y\<in>A. y <= s" "\<forall>z. (\<forall>y\<in>A. y <= z) \<longrightarrow> s <= z" by auto
hoelzl@41973
  1242
      hence "Sup A = s"
hoelzl@43920
  1243
        unfolding Sup_ereal_def by (auto intro!: Least_equality)
hoelzl@41973
  1244
      also have "s <= x" using * s by auto
hoelzl@41973
  1245
      finally show "Sup A <= x" .
hoelzl@41973
  1246
    qed }
hoelzl@41973
  1247
  note Sup_le = this
hoelzl@41973
  1248
hoelzl@43920
  1249
  { fix x :: ereal and A assume "x \<in> A"
hoelzl@41973
  1250
    with le_Sup[of "-x" "uminus`A"] show "Inf A \<le> x"
hoelzl@43920
  1251
      unfolding ereal_Sup_uminus_image_eq by simp }
hoelzl@41973
  1252
hoelzl@43920
  1253
  { fix x :: ereal and A assume *: "!!z. (z : A ==> x <= z)"
hoelzl@41973
  1254
    with Sup_le[of "uminus`A" "-x"] show "x \<le> Inf A"
hoelzl@43920
  1255
      unfolding ereal_Sup_uminus_image_eq by force }
hoelzl@41973
  1256
qed
haftmann@43941
  1257
hoelzl@41973
  1258
end
hoelzl@41973
  1259
haftmann@43941
  1260
instance ereal :: complete_linorder ..
haftmann@43941
  1261
hoelzl@43920
  1262
lemma ereal_SUPR_uminus:
hoelzl@43920
  1263
  fixes f :: "'a => ereal"
hoelzl@41973
  1264
  shows "(SUP i : R. -(f i)) = -(INF i : R. f i)"
hoelzl@44928
  1265
  unfolding SUP_def INF_def
hoelzl@43920
  1266
  using ereal_Sup_uminus_image_eq[of "f`R"]
hoelzl@41973
  1267
  by (simp add: image_image)
hoelzl@41973
  1268
hoelzl@43920
  1269
lemma ereal_INFI_uminus:
hoelzl@43920
  1270
  fixes f :: "'a => ereal"
hoelzl@41973
  1271
  shows "(INF i : R. -(f i)) = -(SUP i : R. f i)"
hoelzl@43920
  1272
  using ereal_SUPR_uminus[of _ "\<lambda>x. - f x"] by simp
hoelzl@41973
  1273
hoelzl@43920
  1274
lemma ereal_Inf_uminus_image_eq: "Inf (uminus ` S) = - Sup (S::ereal set)"
hoelzl@43920
  1275
  using ereal_Sup_uminus_image_eq[of "uminus ` S"] by (simp add: image_image)
hoelzl@41979
  1276
hoelzl@43920
  1277
lemma ereal_inj_on_uminus[intro, simp]: "inj_on uminus (A :: ereal set)"
hoelzl@41973
  1278
  by (auto intro!: inj_onI)
hoelzl@41973
  1279
hoelzl@43920
  1280
lemma ereal_image_uminus_shift:
hoelzl@43920
  1281
  fixes X Y :: "ereal set" shows "uminus ` X = Y \<longleftrightarrow> X = uminus ` Y"
hoelzl@41973
  1282
proof
hoelzl@41973
  1283
  assume "uminus ` X = Y"
hoelzl@41973
  1284
  then have "uminus ` uminus ` X = uminus ` Y"
hoelzl@41973
  1285
    by (simp add: inj_image_eq_iff)
hoelzl@41973
  1286
  then show "X = uminus ` Y" by (simp add: image_image)
hoelzl@41973
  1287
qed (simp add: image_image)
hoelzl@41973
  1288
hoelzl@43920
  1289
lemma Inf_ereal_iff:
hoelzl@43920
  1290
  fixes z :: ereal
hoelzl@41973
  1291
  shows "(!!x. x:X ==> z <= x) ==> (EX x:X. x<y) <-> Inf X < y"
hoelzl@41973
  1292
  by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower less_le_not_le linear
hoelzl@41973
  1293
            order_less_le_trans)
hoelzl@41973
  1294
hoelzl@41973
  1295
lemma Sup_eq_MInfty:
hoelzl@43920
  1296
  fixes S :: "ereal set" shows "Sup S = -\<infinity> \<longleftrightarrow> S = {} \<or> S = {-\<infinity>}"
hoelzl@41973
  1297
proof
hoelzl@41973
  1298
  assume a: "Sup S = -\<infinity>"
hoelzl@41973
  1299
  with complete_lattice_class.Sup_upper[of _ S]
hoelzl@41973
  1300
  show "S={} \<or> S={-\<infinity>}" by auto
hoelzl@41973
  1301
next
hoelzl@41973
  1302
  assume "S={} \<or> S={-\<infinity>}" then show "Sup S = -\<infinity>"
hoelzl@43920
  1303
    unfolding Sup_ereal_def by (auto intro!: Least_equality)
hoelzl@41973
  1304
qed
hoelzl@41973
  1305
hoelzl@41973
  1306
lemma Inf_eq_PInfty:
hoelzl@43920
  1307
  fixes S :: "ereal set" shows "Inf S = \<infinity> \<longleftrightarrow> S = {} \<or> S = {\<infinity>}"
hoelzl@41973
  1308
  using Sup_eq_MInfty[of "uminus`S"]
hoelzl@43920
  1309
  unfolding ereal_Sup_uminus_image_eq ereal_image_uminus_shift by simp
hoelzl@41973
  1310
hoelzl@43923
  1311
lemma Inf_eq_MInfty: 
hoelzl@43923
  1312
  fixes S :: "ereal set" shows "-\<infinity> \<in> S \<Longrightarrow> Inf S = -\<infinity>"
hoelzl@43920
  1313
  unfolding Inf_ereal_def
hoelzl@41973
  1314
  by (auto intro!: Greatest_equality)
hoelzl@41973
  1315
hoelzl@43923
  1316
lemma Sup_eq_PInfty:
hoelzl@43923
  1317
  fixes S :: "ereal set" shows "\<infinity> \<in> S \<Longrightarrow> Sup S = \<infinity>"
hoelzl@43920
  1318
  unfolding Sup_ereal_def
hoelzl@41973
  1319
  by (auto intro!: Least_equality)
hoelzl@41973
  1320
hoelzl@43920
  1321
lemma ereal_SUPI:
hoelzl@43920
  1322
  fixes x :: ereal
hoelzl@41973
  1323
  assumes "!!i. i : A ==> f i <= x"
hoelzl@41973
  1324
  assumes "!!y. (!!i. i : A ==> f i <= y) ==> x <= y"
hoelzl@41973
  1325
  shows "(SUP i:A. f i) = x"
hoelzl@44928
  1326
  unfolding SUP_def Sup_ereal_def
hoelzl@41973
  1327
  using assms by (auto intro!: Least_equality)
hoelzl@41973
  1328
hoelzl@43920
  1329
lemma ereal_INFI:
hoelzl@43920
  1330
  fixes x :: ereal
hoelzl@41973
  1331
  assumes "!!i. i : A ==> f i >= x"
hoelzl@41973
  1332
  assumes "!!y. (!!i. i : A ==> f i >= y) ==> x >= y"
hoelzl@41973
  1333
  shows "(INF i:A. f i) = x"
hoelzl@44928
  1334
  unfolding INF_def Inf_ereal_def
hoelzl@41973
  1335
  using assms by (auto intro!: Greatest_equality)
hoelzl@41973
  1336
hoelzl@43920
  1337
lemma Sup_ereal_close:
hoelzl@43920
  1338
  fixes e :: ereal
hoelzl@41976
  1339
  assumes "0 < e" and S: "\<bar>Sup S\<bar> \<noteq> \<infinity>" "S \<noteq> {}"
hoelzl@41973
  1340
  shows "\<exists>x\<in>S. Sup S - e < x"
hoelzl@41976
  1341
  using assms by (cases e) (auto intro!: less_Sup_iff[THEN iffD1])
hoelzl@41973
  1342
hoelzl@43920
  1343
lemma Inf_ereal_close:
hoelzl@43920
  1344
  fixes e :: ereal assumes "\<bar>Inf X\<bar> \<noteq> \<infinity>" "0 < e"
hoelzl@41973
  1345
  shows "\<exists>x\<in>X. x < Inf X + e"
hoelzl@41973
  1346
proof (rule Inf_less_iff[THEN iffD1])
hoelzl@41973
  1347
  show "Inf X < Inf X + e" using assms
hoelzl@41976
  1348
    by (cases e) auto
hoelzl@41973
  1349
qed
hoelzl@41973
  1350
hoelzl@43920
  1351
lemma SUP_nat_Infty: "(SUP i::nat. ereal (real i)) = \<infinity>"
hoelzl@41973
  1352
proof -
hoelzl@43923
  1353
  { fix x ::ereal assume "x \<noteq> \<infinity>"
hoelzl@43920
  1354
    then have "\<exists>k::nat. x < ereal (real k)"
hoelzl@41973
  1355
    proof (cases x)
hoelzl@41973
  1356
      case MInf then show ?thesis by (intro exI[of _ 0]) auto
hoelzl@41973
  1357
    next
hoelzl@41973
  1358
      case (real r)
hoelzl@41973
  1359
      moreover obtain k :: nat where "r < real k"
hoelzl@41973
  1360
        using ex_less_of_nat by (auto simp: real_eq_of_nat)
hoelzl@41973
  1361
      ultimately show ?thesis by auto
hoelzl@41973
  1362
    qed simp }
hoelzl@41973
  1363
  then show ?thesis
hoelzl@43920
  1364
    using SUP_eq_top_iff[of UNIV "\<lambda>n::nat. ereal (real n)"]
hoelzl@43920
  1365
    by (auto simp: top_ereal_def)
hoelzl@41973
  1366
qed
hoelzl@41973
  1367
hoelzl@43920
  1368
lemma ereal_le_Sup:
hoelzl@43920
  1369
  fixes x :: ereal
hoelzl@41973
  1370
  shows "(x <= (SUP i:A. f i)) <-> (ALL y. y < x --> (EX i. i : A & y <= f i))"
hoelzl@41973
  1371
(is "?lhs <-> ?rhs")
hoelzl@41973
  1372
proof-
hoelzl@41973
  1373
{ assume "?rhs"
hoelzl@41973
  1374
  { assume "~(x <= (SUP i:A. f i))" hence "(SUP i:A. f i)<x" by (simp add: not_le)
hoelzl@43920
  1375
    from this obtain y where y_def: "(SUP i:A. f i)<y & y<x" using ereal_dense by auto
hoelzl@41973
  1376
    from this obtain i where "i : A & y <= f i" using `?rhs` by auto
hoelzl@44928
  1377
    hence "y <= (SUP i:A. f i)" using SUP_upper[of i A f] by auto
hoelzl@41973
  1378
    hence False using y_def by auto
hoelzl@41973
  1379
  } hence "?lhs" by auto
hoelzl@41973
  1380
}
hoelzl@41973
  1381
moreover
hoelzl@41973
  1382
{ assume "?lhs" hence "?rhs"
bulwahn@45236
  1383
  by (metis less_SUP_iff order_less_imp_le order_less_le_trans)
hoelzl@41973
  1384
} ultimately show ?thesis by auto
hoelzl@41973
  1385
qed
hoelzl@41973
  1386
hoelzl@43920
  1387
lemma ereal_Inf_le:
hoelzl@43920
  1388
  fixes x :: ereal
hoelzl@41973
  1389
  shows "((INF i:A. f i) <= x) <-> (ALL y. x < y --> (EX i. i : A & f i <= y))"
hoelzl@41973
  1390
(is "?lhs <-> ?rhs")
hoelzl@41973
  1391
proof-
hoelzl@41973
  1392
{ assume "?rhs"
hoelzl@41973
  1393
  { assume "~((INF i:A. f i) <= x)" hence "x < (INF i:A. f i)" by (simp add: not_le)
hoelzl@43920
  1394
    from this obtain y where y_def: "x<y & y<(INF i:A. f i)" using ereal_dense by auto
hoelzl@41973
  1395
    from this obtain i where "i : A & f i <= y" using `?rhs` by auto
hoelzl@44928
  1396
    hence "(INF i:A. f i) <= y" using INF_lower[of i A f] by auto
hoelzl@41973
  1397
    hence False using y_def by auto
hoelzl@41973
  1398
  } hence "?lhs" by auto
hoelzl@41973
  1399
}
hoelzl@41973
  1400
moreover
hoelzl@41973
  1401
{ assume "?lhs" hence "?rhs"
bulwahn@45236
  1402
  by (metis INF_less_iff order_le_less order_less_le_trans)
hoelzl@41973
  1403
} ultimately show ?thesis by auto
hoelzl@41973
  1404
qed
hoelzl@41973
  1405
hoelzl@41973
  1406
lemma Inf_less:
hoelzl@43920
  1407
  fixes x :: ereal
hoelzl@41973
  1408
  assumes "(INF i:A. f i) < x"
hoelzl@41973
  1409
  shows "EX i. i : A & f i <= x"
hoelzl@41973
  1410
proof(rule ccontr)
hoelzl@41973
  1411
  assume "~ (EX i. i : A & f i <= x)"
hoelzl@41973
  1412
  hence "ALL i:A. f i > x" by auto
hoelzl@44928
  1413
  hence "(INF i:A. f i) >= x" apply (subst INF_greatest) by auto
hoelzl@41973
  1414
  thus False using assms by auto
hoelzl@41973
  1415
qed
hoelzl@41973
  1416
hoelzl@41973
  1417
lemma same_INF:
hoelzl@41973
  1418
  assumes "ALL e:A. f e = g e"
hoelzl@41973
  1419
  shows "(INF e:A. f e) = (INF e:A. g e)"
hoelzl@41973
  1420
proof-
hoelzl@41973
  1421
have "f ` A = g ` A" unfolding image_def using assms by auto
hoelzl@44928
  1422
thus ?thesis unfolding INF_def by auto
hoelzl@41973
  1423
qed
hoelzl@41973
  1424
hoelzl@41973
  1425
lemma same_SUP:
hoelzl@41973
  1426
  assumes "ALL e:A. f e = g e"
hoelzl@41973
  1427
  shows "(SUP e:A. f e) = (SUP e:A. g e)"
hoelzl@41973
  1428
proof-
hoelzl@41973
  1429
have "f ` A = g ` A" unfolding image_def using assms by auto
hoelzl@44928
  1430
thus ?thesis unfolding SUP_def by auto
hoelzl@41973
  1431
qed
hoelzl@41973
  1432
hoelzl@41979
  1433
lemma SUPR_eq:
hoelzl@41979
  1434
  assumes "\<forall>i\<in>A. \<exists>j\<in>B. f i \<le> g j"
hoelzl@41979
  1435
  assumes "\<forall>j\<in>B. \<exists>i\<in>A. g j \<le> f i"
hoelzl@41979
  1436
  shows "(SUP i:A. f i) = (SUP j:B. g j)"
hoelzl@41979
  1437
proof (intro antisym)
hoelzl@41979
  1438
  show "(SUP i:A. f i) \<le> (SUP j:B. g j)"
hoelzl@44928
  1439
    using assms by (metis SUP_least SUP_upper2)
hoelzl@41979
  1440
  show "(SUP i:B. g i) \<le> (SUP j:A. f j)"
hoelzl@44928
  1441
    using assms by (metis SUP_least SUP_upper2)
hoelzl@41979
  1442
qed
hoelzl@41979
  1443
hoelzl@43920
  1444
lemma SUP_ereal_le_addI:
hoelzl@43923
  1445
  fixes f :: "'i \<Rightarrow> ereal"
hoelzl@41978
  1446
  assumes "\<And>i. f i + y \<le> z" and "y \<noteq> -\<infinity>"
hoelzl@41978
  1447
  shows "SUPR UNIV f + y \<le> z"
hoelzl@41978
  1448
proof (cases y)
hoelzl@41978
  1449
  case (real r)
hoelzl@43920
  1450
  then have "\<And>i. f i \<le> z - y" using assms by (simp add: ereal_le_minus_iff)
hoelzl@44928
  1451
  then have "SUPR UNIV f \<le> z - y" by (rule SUP_least)
hoelzl@43920
  1452
  then show ?thesis using real by (simp add: ereal_le_minus_iff)
hoelzl@41978
  1453
qed (insert assms, auto)
hoelzl@41978
  1454
hoelzl@43920
  1455
lemma SUPR_ereal_add:
hoelzl@43920
  1456
  fixes f g :: "nat \<Rightarrow> ereal"
hoelzl@41979
  1457
  assumes "incseq f" "incseq g" and pos: "\<And>i. f i \<noteq> -\<infinity>" "\<And>i. g i \<noteq> -\<infinity>"
hoelzl@41978
  1458
  shows "(SUP i. f i + g i) = SUPR UNIV f + SUPR UNIV g"
hoelzl@43920
  1459
proof (rule ereal_SUPI)
hoelzl@41978
  1460
  fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> f i + g i \<le> y"
hoelzl@41978
  1461
  have f: "SUPR UNIV f \<noteq> -\<infinity>" using pos
hoelzl@44928
  1462
    unfolding SUP_def Sup_eq_MInfty by (auto dest: image_eqD)
hoelzl@41978
  1463
  { fix j
hoelzl@41978
  1464
    { fix i
hoelzl@41978
  1465
      have "f i + g j \<le> f i + g (max i j)"
hoelzl@41978
  1466
        using `incseq g`[THEN incseqD] by (rule add_left_mono) auto
hoelzl@41978
  1467
      also have "\<dots> \<le> f (max i j) + g (max i j)"
hoelzl@41978
  1468
        using `incseq f`[THEN incseqD] by (rule add_right_mono) auto
hoelzl@41978
  1469
      also have "\<dots> \<le> y" using * by auto
hoelzl@41978
  1470
      finally have "f i + g j \<le> y" . }
hoelzl@41978
  1471
    then have "SUPR UNIV f + g j \<le> y"
hoelzl@43920
  1472
      using assms(4)[of j] by (intro SUP_ereal_le_addI) auto
hoelzl@41978
  1473
    then have "g j + SUPR UNIV f \<le> y" by (simp add: ac_simps) }
hoelzl@41978
  1474
  then have "SUPR UNIV g + SUPR UNIV f \<le> y"
hoelzl@43920
  1475
    using f by (rule SUP_ereal_le_addI)
hoelzl@41978
  1476
  then show "SUPR UNIV f + SUPR UNIV g \<le> y" by (simp add: ac_simps)
hoelzl@44928
  1477
qed (auto intro!: add_mono SUP_upper)
hoelzl@41978
  1478
hoelzl@43920
  1479
lemma SUPR_ereal_add_pos:
hoelzl@43920
  1480
  fixes f g :: "nat \<Rightarrow> ereal"
hoelzl@41979
  1481
  assumes inc: "incseq f" "incseq g" and pos: "\<And>i. 0 \<le> f i" "\<And>i. 0 \<le> g i"
hoelzl@41979
  1482
  shows "(SUP i. f i + g i) = SUPR UNIV f + SUPR UNIV g"
hoelzl@43920
  1483
proof (intro SUPR_ereal_add inc)
hoelzl@41979
  1484
  fix i show "f i \<noteq> -\<infinity>" "g i \<noteq> -\<infinity>" using pos[of i] by auto
hoelzl@41979
  1485
qed
hoelzl@41979
  1486
hoelzl@43920
  1487
lemma SUPR_ereal_setsum:
hoelzl@43920
  1488
  fixes f g :: "'a \<Rightarrow> nat \<Rightarrow> ereal"
hoelzl@41979
  1489
  assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)" and pos: "\<And>n i. n \<in> A \<Longrightarrow> 0 \<le> f n i"
hoelzl@41979
  1490
  shows "(SUP i. \<Sum>n\<in>A. f n i) = (\<Sum>n\<in>A. SUPR UNIV (f n))"
hoelzl@41979
  1491
proof cases
hoelzl@41979
  1492
  assume "finite A" then show ?thesis using assms
hoelzl@43920
  1493
    by induct (auto simp: incseq_setsumI2 setsum_nonneg SUPR_ereal_add_pos)
hoelzl@41979
  1494
qed simp
hoelzl@41979
  1495
hoelzl@43920
  1496
lemma SUPR_ereal_cmult:
hoelzl@43920
  1497
  fixes f :: "nat \<Rightarrow> ereal" assumes "\<And>i. 0 \<le> f i" "0 \<le> c"
hoelzl@41978
  1498
  shows "(SUP i. c * f i) = c * SUPR UNIV f"
hoelzl@43920
  1499
proof (rule ereal_SUPI)
hoelzl@44928
  1500
  fix i have "f i \<le> SUPR UNIV f" by (rule SUP_upper) auto
hoelzl@41978
  1501
  then show "c * f i \<le> c * SUPR UNIV f"
hoelzl@43920
  1502
    using `0 \<le> c` by (rule ereal_mult_left_mono)
hoelzl@41978
  1503
next
hoelzl@41978
  1504
  fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> c * f i \<le> y"
hoelzl@41978
  1505
  show "c * SUPR UNIV f \<le> y"
hoelzl@41978
  1506
  proof cases
hoelzl@41978
  1507
    assume c: "0 < c \<and> c \<noteq> \<infinity>"
hoelzl@41978
  1508
    with * have "SUPR UNIV f \<le> y / c"
hoelzl@44928
  1509
      by (intro SUP_least) (auto simp: ereal_le_divide_pos)
hoelzl@41978
  1510
    with c show ?thesis
hoelzl@43920
  1511
      by (auto simp: ereal_le_divide_pos)
hoelzl@41978
  1512
  next
hoelzl@41978
  1513
    { assume "c = \<infinity>" have ?thesis
hoelzl@41978
  1514
      proof cases
hoelzl@41978
  1515
        assume "\<forall>i. f i = 0"
hoelzl@41978
  1516
        moreover then have "range f = {0}" by auto
noschinl@44918
  1517
        ultimately show "c * SUPR UNIV f \<le> y" using *
hoelzl@44928
  1518
          by (auto simp: SUP_def min_max.sup_absorb1)
hoelzl@41978
  1519
      next
hoelzl@41978
  1520
        assume "\<not> (\<forall>i. f i = 0)"
hoelzl@41978
  1521
        then obtain i where "f i \<noteq> 0" by auto
hoelzl@41978
  1522
        with *[of i] `c = \<infinity>` `0 \<le> f i` show ?thesis by (auto split: split_if_asm)
hoelzl@41978
  1523
      qed }
hoelzl@41978
  1524
    moreover assume "\<not> (0 < c \<and> c \<noteq> \<infinity>)"
hoelzl@41978
  1525
    ultimately show ?thesis using * `0 \<le> c` by auto
hoelzl@41978
  1526
  qed
hoelzl@41978
  1527
qed
hoelzl@41978
  1528
hoelzl@41979
  1529
lemma SUP_PInfty:
hoelzl@43920
  1530
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43920
  1531
  assumes "\<And>n::nat. \<exists>i\<in>A. ereal (real n) \<le> f i"
hoelzl@41979
  1532
  shows "(SUP i:A. f i) = \<infinity>"
hoelzl@44928
  1533
  unfolding SUP_def Sup_eq_top_iff[where 'a=ereal, unfolded top_ereal_def]
hoelzl@41979
  1534
  apply simp
hoelzl@41979
  1535
proof safe
hoelzl@43923
  1536
  fix x :: ereal assume "x \<noteq> \<infinity>"
hoelzl@41979
  1537
  show "\<exists>i\<in>A. x < f i"
hoelzl@41979
  1538
  proof (cases x)
hoelzl@41979
  1539
    case PInf with `x \<noteq> \<infinity>` show ?thesis by simp
hoelzl@41979
  1540
  next
hoelzl@41979
  1541
    case MInf with assms[of "0"] show ?thesis by force
hoelzl@41979
  1542
  next
hoelzl@41979
  1543
    case (real r)
hoelzl@43920
  1544
    with less_PInf_Ex_of_nat[of x] obtain n :: nat where "x < ereal (real n)" by auto
hoelzl@41979
  1545
    moreover from assms[of n] guess i ..
hoelzl@41979
  1546
    ultimately show ?thesis
hoelzl@41979
  1547
      by (auto intro!: bexI[of _ i])
hoelzl@41979
  1548
  qed
hoelzl@41979
  1549
qed
hoelzl@41979
  1550
hoelzl@41979
  1551
lemma Sup_countable_SUPR:
hoelzl@41979
  1552
  assumes "A \<noteq> {}"
hoelzl@43920
  1553
  shows "\<exists>f::nat \<Rightarrow> ereal. range f \<subseteq> A \<and> Sup A = SUPR UNIV f"
hoelzl@41979
  1554
proof (cases "Sup A")
hoelzl@41979
  1555
  case (real r)
hoelzl@43920
  1556
  have "\<forall>n::nat. \<exists>x. x \<in> A \<and> Sup A < x + 1 / ereal (real n)"
hoelzl@41979
  1557
  proof
hoelzl@43920
  1558
    fix n ::nat have "\<exists>x\<in>A. Sup A - 1 / ereal (real n) < x"
hoelzl@43920
  1559
      using assms real by (intro Sup_ereal_close) (auto simp: one_ereal_def)
hoelzl@41979
  1560
    then guess x ..
hoelzl@43920
  1561
    then show "\<exists>x. x \<in> A \<and> Sup A < x + 1 / ereal (real n)"
hoelzl@43920
  1562
      by (auto intro!: exI[of _ x] simp: ereal_minus_less_iff)
hoelzl@41979
  1563
  qed
hoelzl@41979
  1564
  from choice[OF this] guess f .. note f = this
hoelzl@41979
  1565
  have "SUPR UNIV f = Sup A"
hoelzl@43920
  1566
  proof (rule ereal_SUPI)
hoelzl@41979
  1567
    fix i show "f i \<le> Sup A" using f
hoelzl@41979
  1568
      by (auto intro!: complete_lattice_class.Sup_upper)
hoelzl@41979
  1569
  next
hoelzl@41979
  1570
    fix y assume bound: "\<And>i. i \<in> UNIV \<Longrightarrow> f i \<le> y"
hoelzl@41979
  1571
    show "Sup A \<le> y"
hoelzl@43920
  1572
    proof (rule ereal_le_epsilon, intro allI impI)
hoelzl@43920
  1573
      fix e :: ereal assume "0 < e"
hoelzl@41979
  1574
      show "Sup A \<le> y + e"
hoelzl@41979
  1575
      proof (cases e)
hoelzl@41979
  1576
        case (real r)
hoelzl@41979
  1577
        hence "0 < r" using `0 < e` by auto
hoelzl@41979
  1578
        then obtain n ::nat where *: "1 / real n < r" "0 < n"
hoelzl@41979
  1579
          using ex_inverse_of_nat_less by (auto simp: real_eq_of_nat inverse_eq_divide)
noschinl@44918
  1580
        have "Sup A \<le> f n + 1 / ereal (real n)" using f[THEN spec, of n]
noschinl@44918
  1581
          by auto
hoelzl@43920
  1582
        also have "1 / ereal (real n) \<le> e" using real * by (auto simp: one_ereal_def )
hoelzl@43920
  1583
        with bound have "f n + 1 / ereal (real n) \<le> y + e" by (rule add_mono) simp
hoelzl@41979
  1584
        finally show "Sup A \<le> y + e" .
hoelzl@41979
  1585
      qed (insert `0 < e`, auto)
hoelzl@41979
  1586
    qed
hoelzl@41979
  1587
  qed
hoelzl@41979
  1588
  with f show ?thesis by (auto intro!: exI[of _ f])
hoelzl@41979
  1589
next
hoelzl@41979
  1590
  case PInf
hoelzl@41979
  1591
  from `A \<noteq> {}` obtain x where "x \<in> A" by auto
hoelzl@41979
  1592
  show ?thesis
hoelzl@41979
  1593
  proof cases
hoelzl@41979
  1594
    assume "\<infinity> \<in> A"
hoelzl@41979
  1595
    moreover then have "\<infinity> \<le> Sup A" by (intro complete_lattice_class.Sup_upper)
hoelzl@41979
  1596
    ultimately show ?thesis by (auto intro!: exI[of _ "\<lambda>x. \<infinity>"])
hoelzl@41979
  1597
  next
hoelzl@41979
  1598
    assume "\<infinity> \<notin> A"
hoelzl@41979
  1599
    have "\<exists>x\<in>A. 0 \<le> x"
hoelzl@43920
  1600
      by (metis Infty_neq_0 PInf complete_lattice_class.Sup_least ereal_infty_less_eq2 linorder_linear)
hoelzl@41979
  1601
    then obtain x where "x \<in> A" "0 \<le> x" by auto
hoelzl@43920
  1602
    have "\<forall>n::nat. \<exists>f. f \<in> A \<and> x + ereal (real n) \<le> f"
hoelzl@41979
  1603
    proof (rule ccontr)
hoelzl@41979
  1604
      assume "\<not> ?thesis"
hoelzl@43920
  1605
      then have "\<exists>n::nat. Sup A \<le> x + ereal (real n)"
hoelzl@41979
  1606
        by (simp add: Sup_le_iff not_le less_imp_le Ball_def) (metis less_imp_le)
hoelzl@41979
  1607
      then show False using `x \<in> A` `\<infinity> \<notin> A` PInf
hoelzl@41979
  1608
        by(cases x) auto
hoelzl@41979
  1609
    qed
hoelzl@41979
  1610
    from choice[OF this] guess f .. note f = this
hoelzl@41979
  1611
    have "SUPR UNIV f = \<infinity>"
hoelzl@41979
  1612
    proof (rule SUP_PInfty)
hoelzl@43920
  1613
      fix n :: nat show "\<exists>i\<in>UNIV. ereal (real n) \<le> f i"
hoelzl@41979
  1614
        using f[THEN spec, of n] `0 \<le> x`
hoelzl@43920
  1615
        by (cases rule: ereal2_cases[of "f n" x]) (auto intro!: exI[of _ n])
hoelzl@41979
  1616
    qed
hoelzl@41979
  1617
    then show ?thesis using f PInf by (auto intro!: exI[of _ f])
hoelzl@41979
  1618
  qed
hoelzl@41979
  1619
next
hoelzl@41979
  1620
  case MInf
hoelzl@41979
  1621
  with `A \<noteq> {}` have "A = {-\<infinity>}" by (auto simp: Sup_eq_MInfty)
hoelzl@41979
  1622
  then show ?thesis using MInf by (auto intro!: exI[of _ "\<lambda>x. -\<infinity>"])
hoelzl@41979
  1623
qed
hoelzl@41979
  1624
hoelzl@41979
  1625
lemma SUPR_countable_SUPR:
hoelzl@43920
  1626
  "A \<noteq> {} \<Longrightarrow> \<exists>f::nat \<Rightarrow> ereal. range f \<subseteq> g`A \<and> SUPR A g = SUPR UNIV f"
hoelzl@44928
  1627
  using Sup_countable_SUPR[of "g`A"] by (auto simp: SUP_def)
hoelzl@41979
  1628
hoelzl@43920
  1629
lemma Sup_ereal_cadd:
hoelzl@43920
  1630
  fixes A :: "ereal set" assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>"
hoelzl@41979
  1631
  shows "Sup ((\<lambda>x. a + x) ` A) = a + Sup A"
hoelzl@41979
  1632
proof (rule antisym)
hoelzl@43920
  1633
  have *: "\<And>a::ereal. \<And>A. Sup ((\<lambda>x. a + x) ` A) \<le> a + Sup A"
hoelzl@41979
  1634
    by (auto intro!: add_mono complete_lattice_class.Sup_least complete_lattice_class.Sup_upper)
hoelzl@41979
  1635
  then show "Sup ((\<lambda>x. a + x) ` A) \<le> a + Sup A" .
hoelzl@41979
  1636
  show "a + Sup A \<le> Sup ((\<lambda>x. a + x) ` A)"
hoelzl@41979
  1637
  proof (cases a)
noschinl@44918
  1638
    case PInf with `A \<noteq> {}` show ?thesis by (auto simp: image_constant min_max.sup_absorb1)
hoelzl@41979
  1639
  next
hoelzl@41979
  1640
    case (real r)
hoelzl@41979
  1641
    then have **: "op + (- a) ` op + a ` A = A"
hoelzl@43920
  1642
      by (auto simp: image_iff ac_simps zero_ereal_def[symmetric])
hoelzl@41979
  1643
    from *[of "-a" "(\<lambda>x. a + x) ` A"] real show ?thesis unfolding **
hoelzl@43920
  1644
      by (cases rule: ereal2_cases[of "Sup A" "Sup (op + a ` A)"]) auto
hoelzl@41979
  1645
  qed (insert `a \<noteq> -\<infinity>`, auto)
hoelzl@41979
  1646
qed
hoelzl@41979
  1647
hoelzl@43920
  1648
lemma Sup_ereal_cminus:
hoelzl@43920
  1649
  fixes A :: "ereal set" assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>"
hoelzl@41979
  1650
  shows "Sup ((\<lambda>x. a - x) ` A) = a - Inf A"
hoelzl@43920
  1651
  using Sup_ereal_cadd[of "uminus ` A" a] assms
hoelzl@43920
  1652
  by (simp add: comp_def image_image minus_ereal_def
hoelzl@43920
  1653
                 ereal_Sup_uminus_image_eq)
hoelzl@41979
  1654
hoelzl@43920
  1655
lemma SUPR_ereal_cminus:
hoelzl@43923
  1656
  fixes f :: "'i \<Rightarrow> ereal"
hoelzl@41979
  1657
  fixes A assumes "A \<noteq> {}" and "a \<noteq> -\<infinity>"
hoelzl@41979
  1658
  shows "(SUP x:A. a - f x) = a - (INF x:A. f x)"
hoelzl@43920
  1659
  using Sup_ereal_cminus[of "f`A" a] assms
hoelzl@44928
  1660
  unfolding SUP_def INF_def image_image by auto
hoelzl@41979
  1661
hoelzl@43920
  1662
lemma Inf_ereal_cminus:
hoelzl@43920
  1663
  fixes A :: "ereal set" assumes "A \<noteq> {}" and "\<bar>a\<bar> \<noteq> \<infinity>"
hoelzl@41979
  1664
  shows "Inf ((\<lambda>x. a - x) ` A) = a - Sup A"
hoelzl@41979
  1665
proof -
hoelzl@41979
  1666
  { fix x have "-a - -x = -(a - x)" using assms by (cases x) auto }
hoelzl@41979
  1667
  moreover then have "(\<lambda>x. -a - x)`uminus`A = uminus ` (\<lambda>x. a - x) ` A"
hoelzl@41979
  1668
    by (auto simp: image_image)
hoelzl@41979
  1669
  ultimately show ?thesis
hoelzl@43920
  1670
    using Sup_ereal_cminus[of "uminus ` A" "-a"] assms
hoelzl@43920
  1671
    by (auto simp add: ereal_Sup_uminus_image_eq ereal_Inf_uminus_image_eq)
hoelzl@41979
  1672
qed
hoelzl@41979
  1673
hoelzl@43920
  1674
lemma INFI_ereal_cminus:
hoelzl@43923
  1675
  fixes a :: ereal assumes "A \<noteq> {}" and "\<bar>a\<bar> \<noteq> \<infinity>"
hoelzl@41979
  1676
  shows "(INF x:A. a - f x) = a - (SUP x:A. f x)"
hoelzl@43920
  1677
  using Inf_ereal_cminus[of "f`A" a] assms
hoelzl@44928
  1678
  unfolding SUP_def INF_def image_image
hoelzl@41979
  1679
  by auto
hoelzl@41979
  1680
hoelzl@43920
  1681
lemma uminus_ereal_add_uminus_uminus:
hoelzl@43920
  1682
  fixes a b :: ereal shows "a \<noteq> \<infinity> \<Longrightarrow> b \<noteq> \<infinity> \<Longrightarrow> - (- a + - b) = a + b"
hoelzl@43920
  1683
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@42950
  1684
hoelzl@43920
  1685
lemma INFI_ereal_add:
hoelzl@43923
  1686
  fixes f :: "nat \<Rightarrow> ereal"
hoelzl@42950
  1687
  assumes "decseq f" "decseq g" and fin: "\<And>i. f i \<noteq> \<infinity>" "\<And>i. g i \<noteq> \<infinity>"
hoelzl@42950
  1688
  shows "(INF i. f i + g i) = INFI UNIV f + INFI UNIV g"
hoelzl@42950
  1689
proof -
hoelzl@42950
  1690
  have INF_less: "(INF i. f i) < \<infinity>" "(INF i. g i) < \<infinity>"
hoelzl@42950
  1691
    using assms unfolding INF_less_iff by auto
hoelzl@42950
  1692
  { fix i from fin[of i] have "- ((- f i) + (- g i)) = f i + g i"
hoelzl@43920
  1693
      by (rule uminus_ereal_add_uminus_uminus) }
hoelzl@42950
  1694
  then have "(INF i. f i + g i) = (INF i. - ((- f i) + (- g i)))"
hoelzl@42950
  1695
    by simp
hoelzl@42950
  1696
  also have "\<dots> = INFI UNIV f + INFI UNIV g"
hoelzl@43920
  1697
    unfolding ereal_INFI_uminus
hoelzl@42950
  1698
    using assms INF_less
hoelzl@43920
  1699
    by (subst SUPR_ereal_add)
hoelzl@43920
  1700
       (auto simp: ereal_SUPR_uminus intro!: uminus_ereal_add_uminus_uminus)
hoelzl@42950
  1701
  finally show ?thesis .
hoelzl@42950
  1702
qed
hoelzl@42950
  1703
noschinl@45934
  1704
subsection "Relation to @{typ enat}"
noschinl@45934
  1705
noschinl@45934
  1706
definition "ereal_of_enat n = (case n of enat n \<Rightarrow> ereal (real n) | \<infinity> \<Rightarrow> \<infinity>)"
noschinl@45934
  1707
noschinl@45934
  1708
declare [[coercion "ereal_of_enat :: enat \<Rightarrow> ereal"]]
noschinl@45934
  1709
declare [[coercion "(\<lambda>n. ereal (real n)) :: nat \<Rightarrow> ereal"]]
noschinl@45934
  1710
noschinl@45934
  1711
lemma ereal_of_enat_simps[simp]:
noschinl@45934
  1712
  "ereal_of_enat (enat n) = ereal n"
noschinl@45934
  1713
  "ereal_of_enat \<infinity> = \<infinity>"
noschinl@45934
  1714
  by (simp_all add: ereal_of_enat_def)
noschinl@45934
  1715
noschinl@45934
  1716
lemma ereal_of_enat_le_iff[simp]:
noschinl@45934
  1717
  "ereal_of_enat m \<le> ereal_of_enat n \<longleftrightarrow> m \<le> n"
noschinl@45934
  1718
by (cases m n rule: enat2_cases) auto
noschinl@45934
  1719
noschinl@45934
  1720
lemma number_of_le_ereal_of_enat_iff[simp]:
noschinl@45934
  1721
  shows "number_of m \<le> ereal_of_enat n \<longleftrightarrow> number_of m \<le> n"
noschinl@45934
  1722
by (cases n) (auto dest: natceiling_le intro: natceiling_le_eq[THEN iffD1])
noschinl@45934
  1723
noschinl@45934
  1724
lemma ereal_of_enat_ge_zero_cancel_iff[simp]:
noschinl@45934
  1725
  "0 \<le> ereal_of_enat n \<longleftrightarrow> 0 \<le> n"
noschinl@45934
  1726
by (cases n) (auto simp: enat_0[symmetric])
noschinl@45934
  1727
noschinl@45934
  1728
lemma ereal_of_enat_gt_zero_cancel_iff[simp]:
noschinl@45934
  1729
  "0 < ereal_of_enat n \<longleftrightarrow> 0 < n"
noschinl@45934
  1730
by (cases n) (auto simp: enat_0[symmetric])
noschinl@45934
  1731
noschinl@45934
  1732
lemma ereal_of_enat_zero[simp]:
noschinl@45934
  1733
  "ereal_of_enat 0 = 0"
noschinl@45934
  1734
by (auto simp: enat_0[symmetric])
noschinl@45934
  1735
noschinl@45934
  1736
lemma ereal_of_enat_add:
noschinl@45934
  1737
  "ereal_of_enat (m + n) = ereal_of_enat m + ereal_of_enat n"
noschinl@45934
  1738
by (cases m n rule: enat2_cases) auto
noschinl@45934
  1739
noschinl@45934
  1740
lemma ereal_of_enat_sub:
noschinl@45934
  1741
  assumes "n \<le> m" shows "ereal_of_enat (m - n) = ereal_of_enat m - ereal_of_enat n "
noschinl@45934
  1742
using assms by (cases m n rule: enat2_cases) auto
noschinl@45934
  1743
noschinl@45934
  1744
lemma ereal_of_enat_mult:
noschinl@45934
  1745
  "ereal_of_enat (m * n) = ereal_of_enat m * ereal_of_enat n"
noschinl@45934
  1746
by (cases m n rule: enat2_cases) auto
noschinl@45934
  1747
noschinl@45934
  1748
lemmas ereal_of_enat_pushin = ereal_of_enat_add ereal_of_enat_sub ereal_of_enat_mult
noschinl@45934
  1749
lemmas ereal_of_enat_pushout = ereal_of_enat_pushin[symmetric]
noschinl@45934
  1750
noschinl@45934
  1751
hoelzl@43920
  1752
subsection "Limits on @{typ ereal}"
hoelzl@41973
  1753
hoelzl@41973
  1754
subsubsection "Topological space"
hoelzl@41973
  1755
hoelzl@43920
  1756
instantiation ereal :: topological_space
hoelzl@41973
  1757
begin
hoelzl@41973
  1758
hoelzl@43920
  1759
definition "open A \<longleftrightarrow> open (ereal -` A)
hoelzl@43920
  1760
       \<and> (\<infinity> \<in> A \<longrightarrow> (\<exists>x. {ereal x <..} \<subseteq> A))
hoelzl@43920
  1761
       \<and> (-\<infinity> \<in> A \<longrightarrow> (\<exists>x. {..<ereal x} \<subseteq> A))"
hoelzl@41973
  1762
hoelzl@43920
  1763
lemma open_PInfty: "open A \<Longrightarrow> \<infinity> \<in> A \<Longrightarrow> (\<exists>x. {ereal x<..} \<subseteq> A)"
hoelzl@43920
  1764
  unfolding open_ereal_def by auto
hoelzl@41973
  1765
hoelzl@43920
  1766
lemma open_MInfty: "open A \<Longrightarrow> -\<infinity> \<in> A \<Longrightarrow> (\<exists>x. {..<ereal x} \<subseteq> A)"
hoelzl@43920
  1767
  unfolding open_ereal_def by auto
hoelzl@41973
  1768
hoelzl@43920
  1769
lemma open_PInfty2: assumes "open A" "\<infinity> \<in> A" obtains x where "{ereal x<..} \<subseteq> A"
hoelzl@41973
  1770
  using open_PInfty[OF assms] by auto
hoelzl@41973
  1771
hoelzl@43920
  1772
lemma open_MInfty2: assumes "open A" "-\<infinity> \<in> A" obtains x where "{..<ereal x} \<subseteq> A"
hoelzl@41973
  1773
  using open_MInfty[OF assms] by auto
hoelzl@41973
  1774
hoelzl@43920
  1775
lemma ereal_openE: assumes "open A" obtains x y where
hoelzl@43920
  1776
  "open (ereal -` A)"
hoelzl@43920
  1777
  "\<infinity> \<in> A \<Longrightarrow> {ereal x<..} \<subseteq> A"
hoelzl@43920
  1778
  "-\<infinity> \<in> A \<Longrightarrow> {..<ereal y} \<subseteq> A"
hoelzl@43920
  1779
  using assms open_ereal_def by auto
hoelzl@41973
  1780
hoelzl@41973
  1781
instance
hoelzl@41973
  1782
proof
hoelzl@43920
  1783
  let ?U = "UNIV::ereal set"
hoelzl@43920
  1784
  show "open ?U" unfolding open_ereal_def
hoelzl@41975
  1785
    by (auto intro!: exI[of _ 0])
hoelzl@41973
  1786
next
hoelzl@43920
  1787
  fix S T::"ereal set" assume "open S" and "open T"
hoelzl@43920
  1788
  from `open S`[THEN ereal_openE] guess xS yS .
hoelzl@43920
  1789
  moreover from `open T`[THEN ereal_openE] guess xT yT .
hoelzl@41975
  1790
  ultimately have
hoelzl@43920
  1791
    "open (ereal -` (S \<inter> T))"
hoelzl@43920
  1792
    "\<infinity> \<in> S \<inter> T \<Longrightarrow> {ereal (max xS xT) <..} \<subseteq> S \<inter> T"
hoelzl@43920
  1793
    "-\<infinity> \<in> S \<inter> T \<Longrightarrow> {..< ereal (min yS yT)} \<subseteq> S \<inter> T"
hoelzl@41975
  1794
    by auto
hoelzl@43920
  1795
  then show "open (S Int T)" unfolding open_ereal_def by blast
hoelzl@41973
  1796
next
hoelzl@43920
  1797
  fix K :: "ereal set set" assume "\<forall>S\<in>K. open S"
hoelzl@43920
  1798
  then have *: "\<forall>S. \<exists>x y. S \<in> K \<longrightarrow> open (ereal -` S) \<and>
hoelzl@43920
  1799
    (\<infinity> \<in> S \<longrightarrow> {ereal x <..} \<subseteq> S) \<and> (-\<infinity> \<in> S \<longrightarrow> {..< ereal y} \<subseteq> S)"
hoelzl@43920
  1800
    by (auto simp: open_ereal_def)
hoelzl@43920
  1801
  then show "open (Union K)" unfolding open_ereal_def
hoelzl@41975
  1802
  proof (intro conjI impI)
hoelzl@43920
  1803
    show "open (ereal -` \<Union>K)"
hoelzl@41980
  1804
      using *[THEN choice] by (auto simp: vimage_Union)
hoelzl@41975
  1805
  qed ((metis UnionE Union_upper subset_trans *)+)
hoelzl@41973
  1806
qed
hoelzl@41973
  1807
end
hoelzl@41973
  1808
hoelzl@43920
  1809
lemma open_ereal: "open S \<Longrightarrow> open (ereal ` S)"
hoelzl@43920
  1810
  by (auto simp: inj_vimage_image_eq open_ereal_def)
hoelzl@41976
  1811
hoelzl@43920
  1812
lemma open_ereal_vimage: "open S \<Longrightarrow> open (ereal -` S)"
hoelzl@43920
  1813
  unfolding open_ereal_def by auto
hoelzl@41976
  1814
hoelzl@43920
  1815
lemma open_ereal_lessThan[intro, simp]: "open {..< a :: ereal}"
hoelzl@41975
  1816
proof -
hoelzl@43920
  1817
  have "\<And>x. ereal -` {..<ereal x} = {..< x}"
hoelzl@43920
  1818
    "ereal -` {..< \<infinity>} = UNIV" "ereal -` {..< -\<infinity>} = {}" by auto
hoelzl@43920
  1819
  then show ?thesis by (cases a) (auto simp: open_ereal_def)
hoelzl@41975
  1820
qed
hoelzl@41975
  1821
hoelzl@43920
  1822
lemma open_ereal_greaterThan[intro, simp]:
hoelzl@43920
  1823
  "open {a :: ereal <..}"
hoelzl@41975
  1824
proof -
hoelzl@43920
  1825
  have "\<And>x. ereal -` {ereal x<..} = {x<..}"
hoelzl@43920
  1826
    "ereal -` {\<infinity><..} = {}" "ereal -` {-\<infinity><..} = UNIV" by auto
hoelzl@43920
  1827
  then show ?thesis by (cases a) (auto simp: open_ereal_def)
hoelzl@41975
  1828
qed
hoelzl@41975
  1829
hoelzl@43920
  1830
lemma ereal_open_greaterThanLessThan[intro, simp]: "open {a::ereal <..< b}"
hoelzl@41973
  1831
  unfolding greaterThanLessThan_def by auto
hoelzl@41973
  1832
hoelzl@43920
  1833
lemma closed_ereal_atLeast[simp, intro]: "closed {a :: ereal ..}"
hoelzl@41973
  1834
proof -
hoelzl@41973
  1835
  have "- {a ..} = {..< a}" by auto
hoelzl@41973
  1836
  then show "closed {a ..}"
hoelzl@43920
  1837
    unfolding closed_def using open_ereal_lessThan by auto
hoelzl@41973
  1838
qed
hoelzl@41973
  1839
hoelzl@43920
  1840
lemma closed_ereal_atMost[simp, intro]: "closed {.. b :: ereal}"
hoelzl@41973
  1841
proof -
hoelzl@41973
  1842
  have "- {.. b} = {b <..}" by auto
hoelzl@41973
  1843
  then show "closed {.. b}"
hoelzl@43920
  1844
    unfolding closed_def using open_ereal_greaterThan by auto
hoelzl@41973
  1845
qed
hoelzl@41973
  1846
hoelzl@43920
  1847
lemma closed_ereal_atLeastAtMost[simp, intro]:
hoelzl@43920
  1848
  shows "closed {a :: ereal .. b}"
hoelzl@41973
  1849
  unfolding atLeastAtMost_def by auto
hoelzl@41973
  1850
hoelzl@43920
  1851
lemma closed_ereal_singleton:
hoelzl@43920
  1852
  "closed {a :: ereal}"
hoelzl@43920
  1853
by (metis atLeastAtMost_singleton closed_ereal_atLeastAtMost)
hoelzl@41973
  1854
hoelzl@43920
  1855
lemma ereal_open_cont_interval:
hoelzl@43923
  1856
  fixes S :: "ereal set"
hoelzl@41976
  1857
  assumes "open S" "x \<in> S" "\<bar>x\<bar> \<noteq> \<infinity>"
hoelzl@41973
  1858
  obtains e where "e>0" "{x-e <..< x+e} \<subseteq> S"
hoelzl@41973
  1859
proof-
hoelzl@43920
  1860
  from `open S` have "open (ereal -` S)" by (rule ereal_openE)
hoelzl@43920
  1861
  then obtain e where "0 < e" and e: "\<And>y. dist y (real x) < e \<Longrightarrow> ereal y \<in> S"
hoelzl@41980
  1862
    using assms unfolding open_dist by force
hoelzl@41975
  1863
  show thesis
hoelzl@41975
  1864
  proof (intro that subsetI)
hoelzl@43920
  1865
    show "0 < ereal e" using `0 < e` by auto
hoelzl@43920
  1866
    fix y assume "y \<in> {x - ereal e<..<x + ereal e}"
hoelzl@43920
  1867
    with assms obtain t where "y = ereal t" "dist t (real x) < e"
hoelzl@41980
  1868
      apply (cases y) by (auto simp: dist_real_def)
hoelzl@41980
  1869
    then show "y \<in> S" using e[of t] by auto
hoelzl@41975
  1870
  qed
hoelzl@41973
  1871
qed
hoelzl@41973
  1872
hoelzl@43920
  1873
lemma ereal_open_cont_interval2:
hoelzl@43923
  1874
  fixes S :: "ereal set"
hoelzl@41976
  1875
  assumes "open S" "x \<in> S" and x: "\<bar>x\<bar> \<noteq> \<infinity>"
hoelzl@41973
  1876
  obtains a b where "a < x" "x < b" "{a <..< b} \<subseteq> S"
hoelzl@41973
  1877
proof-
hoelzl@43920
  1878
  guess e using ereal_open_cont_interval[OF assms] .
hoelzl@43920
  1879
  with that[of "x-e" "x+e"] ereal_between[OF x, of e]
hoelzl@41973
  1880
  show thesis by auto
hoelzl@41973
  1881
qed
hoelzl@41973
  1882
hoelzl@43920
  1883
instance ereal :: t2_space
hoelzl@41973
  1884
proof
hoelzl@43920
  1885
  fix x y :: ereal assume "x ~= y"
hoelzl@43920
  1886
  let "?P x (y::ereal)" = "EX U V. open U & open V & x : U & y : V & U Int V = {}"
hoelzl@41973
  1887
hoelzl@43920
  1888
  { fix x y :: ereal assume "x < y"
hoelzl@43920
  1889
    from ereal_dense[OF this] obtain z where z: "x < z" "z < y" by auto
hoelzl@41973
  1890
    have "?P x y"
hoelzl@41973
  1891
      apply (rule exI[of _ "{..<z}"])
hoelzl@41973
  1892
      apply (rule exI[of _ "{z<..}"])
hoelzl@41973
  1893
      using z by auto }
hoelzl@41973
  1894
  note * = this
hoelzl@41973
  1895
hoelzl@41973
  1896
  from `x ~= y`
hoelzl@41973
  1897
  show "EX U V. open U & open V & x : U & y : V & U Int V = {}"
hoelzl@41973
  1898
  proof (cases rule: linorder_cases)
hoelzl@41973
  1899
    assume "x = y" with `x ~= y` show ?thesis by simp
hoelzl@41973
  1900
  next assume "x < y" from *[OF this] show ?thesis by auto
hoelzl@41973
  1901
  next assume "y < x" from *[OF this] show ?thesis by auto
hoelzl@41973
  1902
  qed
hoelzl@41973
  1903
qed
hoelzl@41973
  1904
hoelzl@41973
  1905
subsubsection {* Convergent sequences *}
hoelzl@41973
  1906
hoelzl@43920
  1907
lemma lim_ereal[simp]:
hoelzl@43920
  1908
  "((\<lambda>n. ereal (f n)) ---> ereal x) net \<longleftrightarrow> (f ---> x) net" (is "?l = ?r")
hoelzl@41973
  1909
proof (intro iffI topological_tendstoI)
hoelzl@41973
  1910
  fix S assume "?l" "open S" "x \<in> S"
hoelzl@41973
  1911
  then show "eventually (\<lambda>x. f x \<in> S) net"
hoelzl@43920
  1912
    using `?l`[THEN topological_tendstoD, OF open_ereal, OF `open S`]
hoelzl@41973
  1913
    by (simp add: inj_image_mem_iff)
hoelzl@41973
  1914
next
hoelzl@43920
  1915
  fix S assume "?r" "open S" "ereal x \<in> S"
hoelzl@43920
  1916
  show "eventually (\<lambda>x. ereal (f x) \<in> S) net"
hoelzl@43920
  1917
    using `?r`[THEN topological_tendstoD, OF open_ereal_vimage, OF `open S`]
hoelzl@43920
  1918
    using `ereal x \<in> S` by auto
hoelzl@41973
  1919
qed
hoelzl@41973
  1920
hoelzl@43920
  1921
lemma lim_real_of_ereal[simp]:
hoelzl@43920
  1922
  assumes lim: "(f ---> ereal x) net"
hoelzl@41973
  1923
  shows "((\<lambda>x. real (f x)) ---> x) net"
hoelzl@41973
  1924
proof (intro topological_tendstoI)
hoelzl@41973
  1925
  fix S assume "open S" "x \<in> S"
hoelzl@43920
  1926
  then have S: "open S" "ereal x \<in> ereal ` S"
hoelzl@41973
  1927
    by (simp_all add: inj_image_mem_iff)
hoelzl@43920
  1928
  have "\<forall>x. f x \<in> ereal ` S \<longrightarrow> real (f x) \<in> S" by auto
hoelzl@43920
  1929
  from this lim[THEN topological_tendstoD, OF open_ereal, OF S]
hoelzl@41973
  1930
  show "eventually (\<lambda>x. real (f x) \<in> S) net"
hoelzl@41973
  1931
    by (rule eventually_mono)
hoelzl@41973
  1932
qed
hoelzl@41973
  1933
hoelzl@43920
  1934
lemma Lim_PInfty: "f ----> \<infinity> <-> (ALL B. EX N. ALL n>=N. f n >= ereal B)" (is "?l = ?r")
hoelzl@43923
  1935
proof
hoelzl@43923
  1936
  assume ?r
hoelzl@43923
  1937
  show ?l
hoelzl@43923
  1938
    apply(rule topological_tendstoI)
hoelzl@41973
  1939
    unfolding eventually_sequentially
hoelzl@43923
  1940
  proof-
hoelzl@43923
  1941
    fix S :: "ereal set" assume "open S" "\<infinity> : S"
hoelzl@41973
  1942
    from open_PInfty[OF this] guess B .. note B=this
hoelzl@41973
  1943
    from `?r`[rule_format,of "B+1"] guess N .. note N=this
hoelzl@41973
  1944
    show "EX N. ALL n>=N. f n : S" apply(rule_tac x=N in exI)
hoelzl@41973
  1945
    proof safe case goal1
hoelzl@43920
  1946
      have "ereal B < ereal (B + 1)" by auto
hoelzl@41973
  1947
      also have "... <= f n" using goal1 N by auto
nipkow@44890
  1948
      finally show ?case using B by fastforce
hoelzl@41973
  1949
    qed
hoelzl@41973
  1950
  qed
hoelzl@43923
  1951
next
hoelzl@43923
  1952
  assume ?l
hoelzl@43923
  1953
  show ?r
hoelzl@43920
  1954
  proof fix B::real have "open {ereal B<..}" "\<infinity> : {ereal B<..}" by auto
hoelzl@41973
  1955
    from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially]
hoelzl@41973
  1956
    guess N .. note N=this
hoelzl@43920
  1957
    show "EX N. ALL n>=N. ereal B <= f n" apply(rule_tac x=N in exI) using N by auto
hoelzl@41973
  1958
  qed
hoelzl@41973
  1959
qed
hoelzl@41973
  1960
hoelzl@41973
  1961
hoelzl@43920
  1962
lemma Lim_MInfty: "f ----> (-\<infinity>) <-> (ALL B. EX N. ALL n>=N. f n <= ereal B)" (is "?l = ?r")
hoelzl@43923
  1963
proof
hoelzl@43923
  1964
  assume ?r
hoelzl@43923
  1965
  show ?l
hoelzl@43923
  1966
    apply(rule topological_tendstoI)
hoelzl@41973
  1967
    unfolding eventually_sequentially
hoelzl@43923
  1968
  proof-
hoelzl@43923
  1969
    fix S :: "ereal set"
hoelzl@43923
  1970
    assume "open S" "(-\<infinity>) : S"
hoelzl@41973
  1971
    from open_MInfty[OF this] guess B .. note B=this
hoelzl@41973
  1972
    from `?r`[rule_format,of "B-(1::real)"] guess N .. note N=this
hoelzl@41973
  1973
    show "EX N. ALL n>=N. f n : S" apply(rule_tac x=N in exI)
hoelzl@41973
  1974
    proof safe case goal1
hoelzl@43920
  1975
      have "ereal (B - 1) >= f n" using goal1 N by auto
hoelzl@43920
  1976
      also have "... < ereal B" by auto
nipkow@44890
  1977
      finally show ?case using B by fastforce
hoelzl@41973
  1978
    qed
hoelzl@41973
  1979
  qed
hoelzl@41973
  1980
next assume ?l show ?r
hoelzl@43920
  1981
  proof fix B::real have "open {..<ereal B}" "(-\<infinity>) : {..<ereal B}" by auto
hoelzl@41973
  1982
    from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially]
hoelzl@41973
  1983
    guess N .. note N=this
hoelzl@43920
  1984
    show "EX N. ALL n>=N. ereal B >= f n" apply(rule_tac x=N in exI) using N by auto
hoelzl@41973
  1985
  qed
hoelzl@41973
  1986
qed
hoelzl@41973
  1987
hoelzl@41973
  1988
hoelzl@43920
  1989
lemma Lim_bounded_PInfty: assumes lim:"f ----> l" and "!!n. f n <= ereal B" shows "l ~= \<infinity>"
hoelzl@41973
  1990
proof(rule ccontr,unfold not_not) let ?B = "B + 1" assume as:"l=\<infinity>"
hoelzl@41973
  1991
  from lim[unfolded this Lim_PInfty,rule_format,of "?B"]
hoelzl@41973
  1992
  guess N .. note N=this[rule_format,OF le_refl]
hoelzl@43920
  1993
  hence "ereal ?B <= ereal B" using assms(2)[of N] by(rule order_trans)
hoelzl@43920
  1994
  hence "ereal ?B < ereal ?B" apply (rule le_less_trans) by auto
hoelzl@41973
  1995
  thus False by auto
hoelzl@41973
  1996
qed
hoelzl@41973
  1997
hoelzl@41973
  1998
hoelzl@43920
  1999
lemma Lim_bounded_MInfty: assumes lim:"f ----> l" and "!!n. f n >= ereal B" shows "l ~= (-\<infinity>)"
hoelzl@41973
  2000
proof(rule ccontr,unfold not_not) let ?B = "B - 1" assume as:"l=(-\<infinity>)"
hoelzl@41973
  2001
  from lim[unfolded this Lim_MInfty,rule_format,of "?B"]
hoelzl@41973
  2002
  guess N .. note N=this[rule_format,OF le_refl]
hoelzl@43920
  2003
  hence "ereal B <= ereal ?B" using assms(2)[of N] order_trans[of "ereal B" "f N" "ereal(B - 1)"] by blast
hoelzl@41973
  2004
  thus False by auto
hoelzl@41973
  2005
qed
hoelzl@41973
  2006
hoelzl@41973
  2007
hoelzl@41973
  2008
lemma tendsto_explicit:
hoelzl@41973
  2009
  "f ----> f0 <-> (ALL S. open S --> f0 : S --> (EX N. ALL n>=N. f n : S))"
hoelzl@41973
  2010
  unfolding tendsto_def eventually_sequentially by auto
hoelzl@41973
  2011
hoelzl@41973
  2012
hoelzl@41973
  2013
lemma tendsto_obtains_N:
hoelzl@41973
  2014
  assumes "f ----> f0"
hoelzl@41973
  2015
  assumes "open S" "f0 : S"
hoelzl@41973
  2016
  obtains N where "ALL n>=N. f n : S"
hoelzl@41973
  2017
  using tendsto_explicit[of f f0] assms by auto
hoelzl@41973
  2018
hoelzl@41973
  2019
hoelzl@41973
  2020
lemma tail_same_limit:
hoelzl@41973
  2021
  fixes X Y N
hoelzl@41973
  2022
  assumes "X ----> L" "ALL n>=N. X n = Y n"
hoelzl@41973
  2023
  shows "Y ----> L"
hoelzl@41973
  2024
proof-
hoelzl@41973
  2025
{ fix S assume "open S" and "L:S"
hoelzl@41973
  2026
  from this obtain N1 where "ALL n>=N1. X n : S"
hoelzl@41973
  2027
     using assms unfolding tendsto_def eventually_sequentially by auto
hoelzl@41973
  2028
  hence "ALL n>=max N N1. Y n : S" using assms by auto
hoelzl@41973
  2029
  hence "EX N. ALL n>=N. Y n : S" apply(rule_tac x="max N N1" in exI) by auto
hoelzl@41973
  2030
}
hoelzl@41973
  2031
thus ?thesis using tendsto_explicit by auto
hoelzl@41973
  2032
qed
hoelzl@41973
  2033
hoelzl@41973
  2034
hoelzl@41973
  2035
lemma Lim_bounded_PInfty2:
hoelzl@43920
  2036
assumes lim:"f ----> l" and "ALL n>=N. f n <= ereal B"
hoelzl@41973
  2037
shows "l ~= \<infinity>"
hoelzl@41973
  2038
proof-
hoelzl@43920
  2039
  def g == "(%n. if n>=N then f n else ereal B)"
hoelzl@41973
  2040
  hence "g ----> l" using tail_same_limit[of f l N g] lim by auto
hoelzl@43920
  2041
  moreover have "!!n. g n <= ereal B" using g_def assms by auto
hoelzl@41973
  2042
  ultimately show ?thesis using  Lim_bounded_PInfty by auto
hoelzl@41973
  2043
qed
hoelzl@41973
  2044
hoelzl@43920
  2045
lemma Lim_bounded_ereal:
hoelzl@43920
  2046
  assumes lim:"f ----> (l :: ereal)"
hoelzl@41973
  2047
  and "ALL n>=M. f n <= C"
hoelzl@41973
  2048
  shows "l<=C"
hoelzl@41973
  2049
proof-
hoelzl@41973
  2050
{ assume "l=(-\<infinity>)" hence ?thesis by auto }
hoelzl@41973
  2051
moreover
hoelzl@41973
  2052
{ assume "~(l=(-\<infinity>))"
hoelzl@41973
  2053
  { assume "C=\<infinity>" hence ?thesis by auto }
hoelzl@41973
  2054
  moreover
hoelzl@41973
  2055
  { assume "C=(-\<infinity>)" hence "ALL n>=M. f n = (-\<infinity>)" using assms by auto
hoelzl@41973
  2056
    hence "l=(-\<infinity>)" using assms
hoelzl@41980
  2057
       tendsto_unique[OF trivial_limit_sequentially] tail_same_limit[of "\<lambda>n. -\<infinity>" "-\<infinity>" M f, OF tendsto_const] by auto
hoelzl@41973
  2058
    hence ?thesis by auto }
hoelzl@41973
  2059
  moreover
hoelzl@43920
  2060
  { assume "EX B. C = ereal B"
hoelzl@43920
  2061
    from this obtain B where B_def: "C=ereal B" by auto
hoelzl@41973
  2062
    hence "~(l=\<infinity>)" using Lim_bounded_PInfty2 assms by auto
hoelzl@43920
  2063
    from this obtain m where m_def: "ereal m=l" using `~(l=(-\<infinity>))` by (cases l) auto
hoelzl@43920
  2064
    from this obtain N where N_def: "ALL n>=N. f n : {ereal(m - 1) <..< ereal(m+1)}"
hoelzl@43920
  2065
       apply (subst tendsto_obtains_N[of f l "{ereal(m - 1) <..< ereal(m+1)}"]) using assms by auto
hoelzl@41973
  2066
    { fix n assume "n>=N"
hoelzl@43920
  2067
      hence "EX r. ereal r = f n" using N_def by (cases "f n") auto
hoelzl@43920
  2068
    } from this obtain g where g_def: "ALL n>=N. ereal (g n) = f n" by metis
hoelzl@43920
  2069
    hence "(%n. ereal (g n)) ----> l" using tail_same_limit[of f l N] assms by auto
hoelzl@41973
  2070
    hence *: "(%n. g n) ----> m" using m_def by auto
hoelzl@41973
  2071
    { fix n assume "n>=max N M"
hoelzl@43920
  2072
      hence "ereal (g n) <= ereal B" using assms g_def B_def by auto
hoelzl@41973
  2073
      hence "g n <= B" by auto
hoelzl@41973
  2074
    } hence "EX N. ALL n>=N. g n <= B" by blast
hoelzl@41973
  2075
    hence "m<=B" using * LIMSEQ_le_const2[of g m B] by auto
hoelzl@41973
  2076
    hence ?thesis using m_def B_def by auto
hoelzl@41973
  2077
  } ultimately have ?thesis by (cases C) auto
hoelzl@41973
  2078
} ultimately show ?thesis by blast
hoelzl@41973
  2079
qed
hoelzl@41973
  2080
hoelzl@43920
  2081
lemma real_of_ereal_mult[simp]:
hoelzl@43920
  2082
  fixes a b :: ereal shows "real (a * b) = real a * real b"
hoelzl@43920
  2083
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
  2084
hoelzl@43920
  2085
lemma real_of_ereal_eq_0:
hoelzl@43923
  2086
  fixes x :: ereal shows "real x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity> \<or> x = 0"
hoelzl@41973
  2087
  by (cases x) auto
hoelzl@41973
  2088
hoelzl@43920
  2089
lemma tendsto_ereal_realD:
hoelzl@43920
  2090
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43920
  2091
  assumes "x \<noteq> 0" and tendsto: "((\<lambda>x. ereal (real (f x))) ---> x) net"
hoelzl@41973
  2092
  shows "(f ---> x) net"
hoelzl@41973
  2093
proof (intro topological_tendstoI)
hoelzl@41973
  2094
  fix S assume S: "open S" "x \<in> S"
hoelzl@41973
  2095
  with `x \<noteq> 0` have "open (S - {0})" "x \<in> S - {0}" by auto
hoelzl@41973
  2096
  from tendsto[THEN topological_tendstoD, OF this]
hoelzl@41973
  2097
  show "eventually (\<lambda>x. f x \<in> S) net"
huffman@44142
  2098
    by (rule eventually_rev_mp) (auto simp: ereal_real)
hoelzl@41973
  2099
qed
hoelzl@41973
  2100
hoelzl@43920
  2101
lemma tendsto_ereal_realI:
hoelzl@43920
  2102
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@41976
  2103
  assumes x: "\<bar>x\<bar> \<noteq> \<infinity>" and tendsto: "(f ---> x) net"
hoelzl@43920
  2104
  shows "((\<lambda>x. ereal (real (f x))) ---> x) net"
hoelzl@41973
  2105
proof (intro topological_tendstoI)
hoelzl@41973
  2106
  fix S assume "open S" "x \<in> S"
hoelzl@41973
  2107
  with x have "open (S - {\<infinity>, -\<infinity>})" "x \<in> S - {\<infinity>, -\<infinity>}" by auto
hoelzl@41973
  2108
  from tendsto[THEN topological_tendstoD, OF this]
hoelzl@43920
  2109
  show "eventually (\<lambda>x. ereal (real (f x)) \<in> S) net"
hoelzl@43920
  2110
    by (elim eventually_elim1) (auto simp: ereal_real)
hoelzl@41973
  2111
qed
hoelzl@41973
  2112
hoelzl@43920
  2113
lemma ereal_mult_cancel_left:
hoelzl@43920
  2114
  fixes a b c :: ereal shows "a * b = a * c \<longleftrightarrow>
hoelzl@41976
  2115
    ((\<bar>a\<bar> = \<infinity> \<and> 0 < b * c) \<or> a = 0 \<or> b = c)"
hoelzl@43920
  2116
  by (cases rule: ereal3_cases[of a b c])
hoelzl@41973
  2117
     (simp_all add: zero_less_mult_iff)
hoelzl@41973
  2118
hoelzl@43920
  2119
lemma ereal_inj_affinity:
hoelzl@43923
  2120
  fixes m t :: ereal
hoelzl@41976
  2121
  assumes "\<bar>m\<bar> \<noteq> \<infinity>" "m \<noteq> 0" "\<bar>t\<bar> \<noteq> \<infinity>"
hoelzl@41973
  2122
  shows "inj_on (\<lambda>x. m * x + t) A"
hoelzl@41973
  2123
  using assms
hoelzl@43920
  2124
  by (cases rule: ereal2_cases[of m t])
hoelzl@43920
  2125
     (auto intro!: inj_onI simp: ereal_add_cancel_right ereal_mult_cancel_left)
hoelzl@41973
  2126
hoelzl@43920
  2127
lemma ereal_PInfty_eq_plus[simp]:
hoelzl@43923
  2128
  fixes a b :: ereal
hoelzl@41973
  2129
  shows "\<infinity> = a + b \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>"
hoelzl@43920
  2130
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
  2131
hoelzl@43920
  2132
lemma ereal_MInfty_eq_plus[simp]:
hoelzl@43923
  2133
  fixes a b :: ereal
hoelzl@41973
  2134
  shows "-\<infinity> = a + b \<longleftrightarrow> (a = -\<infinity> \<and> b \<noteq> \<infinity>) \<or> (b = -\<infinity> \<and> a \<noteq> \<infinity>)"
hoelzl@43920
  2135
  by (cases rule: ereal2_cases[of a b]) auto
hoelzl@41973
  2136
hoelzl@43920
  2137
lemma ereal_less_divide_pos:
hoelzl@43923
  2138
  fixes x y :: ereal
hoelzl@43923
  2139
  shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y < z / x \<longleftrightarrow> x * y < z"
hoelzl@43920
  2140
  by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
  2141
hoelzl@43920
  2142
lemma ereal_divide_less_pos:
hoelzl@43923
  2143
  fixes x y z :: ereal
hoelzl@43923
  2144
  shows "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y / x < z \<longleftrightarrow> y < x * z"
hoelzl@43920
  2145
  by (cases rule: ereal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
  2146
hoelzl@43920
  2147
lemma ereal_divide_eq:
hoelzl@43923
  2148
  fixes a b c :: ereal
hoelzl@43923
  2149
  shows "b \<noteq> 0 \<Longrightarrow> \<bar>b\<bar> \<noteq> \<infinity> \<Longrightarrow> a / b = c \<longleftrightarrow> a = b * c"
hoelzl@43920
  2150
  by (cases rule: ereal3_cases[of a b c])
hoelzl@41973
  2151
     (simp_all add: field_simps)
hoelzl@41973
  2152
hoelzl@43923
  2153
lemma ereal_inverse_not_MInfty[simp]: "inverse (a::ereal) \<noteq> -\<infinity>"
hoelzl@41973
  2154
  by (cases a) auto
hoelzl@41973
  2155
hoelzl@43920
  2156
lemma ereal_mult_m1[simp]: "x * ereal (-1) = -x"
hoelzl@41973
  2157
  by (cases x) auto
hoelzl@41973
  2158
hoelzl@43920
  2159
lemma ereal_LimI_finite:
hoelzl@43923
  2160
  fixes x :: ereal
hoelzl@41976
  2161
  assumes "\<bar>x\<bar> \<noteq> \<infinity>"
hoelzl@41973
  2162
  assumes "!!r. 0 < r ==> EX N. ALL n>=N. u n < x + r & x < u n + r"
hoelzl@41973
  2163
  shows "u ----> x"
hoelzl@41973
  2164
proof (rule topological_tendstoI, unfold eventually_sequentially)
hoelzl@43920
  2165
  obtain rx where rx_def: "x=ereal rx" using assms by (cases x) auto
hoelzl@41973
  2166
  fix S assume "open S" "x : S"
hoelzl@43920
  2167
  then have "open (ereal -` S)" unfolding open_ereal_def by auto
hoelzl@43920
  2168
  with `x \<in> S` obtain r where "0 < r" and dist: "!!y. dist y rx < r ==> ereal y \<in> S"
hoelzl@41975
  2169
    unfolding open_real_def rx_def by auto
hoelzl@41973
  2170
  then obtain n where
hoelzl@43920
  2171
    upper: "!!N. n <= N ==> u N < x + ereal r" and
hoelzl@43920
  2172
    lower: "!!N. n <= N ==> x < u N + ereal r" using assms(2)[of "ereal r"] by auto
hoelzl@41973
  2173
  show "EX N. ALL n>=N. u n : S"
hoelzl@41973
  2174
  proof (safe intro!: exI[of _ n])
hoelzl@41973
  2175
    fix N assume "n <= N"
hoelzl@41973
  2176
    from upper[OF this] lower[OF this] assms `0 < r`
hoelzl@41973
  2177
    have "u N ~: {\<infinity>,(-\<infinity>)}" by auto
hoelzl@43920
  2178
    from this obtain ra where ra_def: "(u N) = ereal ra" by (cases "u N") auto
hoelzl@41973
  2179
    hence "rx < ra + r" and "ra < rx + r"
hoelzl@41973
  2180
       using rx_def assms `0 < r` lower[OF `n <= N`] upper[OF `n <= N`] by auto
hoelzl@41975
  2181
    hence "dist (real (u N)) rx < r"
hoelzl@41973
  2182
      using rx_def ra_def
hoelzl@41973
  2183
      by (auto simp: dist_real_def abs_diff_less_iff field_simps)
hoelzl@41976
  2184
    from dist[OF this] show "u N : S" using `u N  ~: {\<infinity>, -\<infinity>}`
hoelzl@43920
  2185
      by (auto simp: ereal_real split: split_if_asm)
hoelzl@41973
  2186
  qed
hoelzl@41973
  2187
qed
hoelzl@41973
  2188
hoelzl@43920
  2189
lemma ereal_LimI_finite_iff:
hoelzl@43923
  2190
  fixes x :: ereal
hoelzl@41976
  2191
  assumes "\<bar>x\<bar> \<noteq> \<infinity>"
hoelzl@41973
  2192
  shows "u ----> x <-> (ALL r. 0 < r --> (EX N. ALL n>=N. u n < x + r & x < u n + r))"
hoelzl@41973
  2193
  (is "?lhs <-> ?rhs")
hoelzl@41976
  2194
proof
hoelzl@41976
  2195
  assume lim: "u ----> x"
hoelzl@43920
  2196
  { fix r assume "(r::ereal)>0"
hoelzl@41973
  2197
    from this obtain N where N_def: "ALL n>=N. u n : {x - r <..< x + r}"
hoelzl@41973
  2198
       apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"])
hoelzl@43920
  2199
       using lim ereal_between[of x r] assms `r>0` by auto
hoelzl@41973
  2200
    hence "EX N. ALL n>=N. u n < x + r & x < u n + r"
hoelzl@43920
  2201
      using ereal_minus_less[of r x] by (cases r) auto
hoelzl@41976
  2202
  } then show "?rhs" by auto
hoelzl@41976
  2203
next
hoelzl@41976
  2204
  assume ?rhs then show "u ----> x"
hoelzl@43920
  2205
    using ereal_LimI_finite[of x] assms by auto
hoelzl@41973
  2206
qed
hoelzl@41973
  2207
hoelzl@41973
  2208
hoelzl@41973
  2209
subsubsection {* @{text Liminf} and @{text Limsup} *}
hoelzl@41973
  2210
hoelzl@41973
  2211
definition
hoelzl@41973
  2212
  "Liminf net f = (GREATEST l. \<forall>y<l. eventually (\<lambda>x. y < f x) net)"
hoelzl@41973
  2213
hoelzl@41973
  2214
definition
hoelzl@41973
  2215
  "Limsup net f = (LEAST l. \<forall>y>l. eventually (\<lambda>x. f x < y) net)"
hoelzl@41973
  2216
hoelzl@41973
  2217
lemma Liminf_Sup:
haftmann@43941
  2218
  fixes f :: "'a => 'b::complete_linorder"
hoelzl@41973
  2219
  shows "Liminf net f = Sup {l. \<forall>y<l. eventually (\<lambda>x. y < f x) net}"
hoelzl@41973
  2220
  by (auto intro!: Greatest_equality complete_lattice_class.Sup_upper simp: less_Sup_iff Liminf_def)
hoelzl@41973
  2221
hoelzl@41973
  2222
lemma Limsup_Inf:
haftmann@43941
  2223
  fixes f :: "'a => 'b::complete_linorder"
hoelzl@41973
  2224
  shows "Limsup net f = Inf {l. \<forall>y>l. eventually (\<lambda>x. f x < y) net}"
hoelzl@41973
  2225
  by (auto intro!: Least_equality complete_lattice_class.Inf_lower simp: Inf_less_iff Limsup_def)
hoelzl@41973
  2226
hoelzl@43920
  2227
lemma ereal_SupI:
hoelzl@43920
  2228
  fixes x :: ereal
hoelzl@41973
  2229
  assumes "\<And>y. y \<in> A \<Longrightarrow> y \<le> x"
hoelzl@41973
  2230
  assumes "\<And>y. (\<And>z. z \<in> A \<Longrightarrow> z \<le> y) \<Longrightarrow> x \<le> y"
hoelzl@41973
  2231
  shows "Sup A = x"
hoelzl@43920
  2232
  unfolding Sup_ereal_def
hoelzl@41973
  2233
  using assms by (auto intro!: Least_equality)
hoelzl@41973
  2234
hoelzl@43920
  2235
lemma ereal_InfI:
hoelzl@43920
  2236
  fixes x :: ereal
hoelzl@41973
  2237
  assumes "\<And>i. i \<in> A \<Longrightarrow> x \<le> i"
hoelzl@41973
  2238
  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> y \<le> i) \<Longrightarrow> y \<le> x"
hoelzl@41973
  2239
  shows "Inf A = x"
hoelzl@43920
  2240
  unfolding Inf_ereal_def
hoelzl@41973
  2241
  using assms by (auto intro!: Greatest_equality)
hoelzl@41973
  2242
hoelzl@41973
  2243
lemma Limsup_const:
haftmann@43941
  2244
  fixes c :: "'a::complete_linorder"
hoelzl@41973
  2245
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  2246
  shows "Limsup net (\<lambda>x. c) = c"
hoelzl@41973
  2247
  unfolding Limsup_Inf
hoelzl@41973
  2248
proof (safe intro!: antisym complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower)
hoelzl@41973
  2249
  fix x assume *: "\<forall>y>x. eventually (\<lambda>_. c < y) net"
hoelzl@41973
  2250
  show "c \<le> x"
hoelzl@41973
  2251
  proof (rule ccontr)
hoelzl@41973
  2252
    assume "\<not> c \<le> x" then have "x < c" by auto
hoelzl@41973
  2253
    then show False using ntriv * by (auto simp: trivial_limit_def)
hoelzl@41973
  2254
  qed
hoelzl@41973
  2255
qed auto
hoelzl@41973
  2256
hoelzl@41973
  2257
lemma Liminf_const:
haftmann@43941
  2258
  fixes c :: "'a::complete_linorder"
hoelzl@41973
  2259
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  2260
  shows "Liminf net (\<lambda>x. c) = c"
hoelzl@41973
  2261
  unfolding Liminf_Sup
hoelzl@41973
  2262
proof (safe intro!: antisym complete_lattice_class.Sup_least complete_lattice_class.Sup_upper)
hoelzl@41973
  2263
  fix x assume *: "\<forall>y<x. eventually (\<lambda>_. y < c) net"
hoelzl@41973
  2264
  show "x \<le> c"
hoelzl@41973
  2265
  proof (rule ccontr)
hoelzl@41973
  2266
    assume "\<not> x \<le> c" then have "c < x" by auto
hoelzl@41973
  2267
    then show False using ntriv * by (auto simp: trivial_limit_def)
hoelzl@41973
  2268
  qed
hoelzl@41973
  2269
qed auto
hoelzl@41973
  2270
huffman@44170
  2271
definition (in order) mono_set:
huffman@44170
  2272
  "mono_set S \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> x \<in> S \<longrightarrow> y \<in> S)"
hoelzl@41973
  2273
huffman@44170
  2274
lemma (in order) mono_greaterThan [intro, simp]: "mono_set {B<..}" unfolding mono_set by auto
huffman@44170
  2275
lemma (in order) mono_atLeast [intro, simp]: "mono_set {B..}" unfolding mono_set by auto
huffman@44170
  2276
lemma (in order) mono_UNIV [intro, simp]: "mono_set UNIV" unfolding mono_set by auto
huffman@44170
  2277
lemma (in order) mono_empty [intro, simp]: "mono_set {}" unfolding mono_set by auto
hoelzl@41973
  2278
haftmann@43941
  2279
lemma (in complete_linorder) mono_set_iff:
haftmann@43941
  2280
  fixes S :: "'a set"
hoelzl@41973
  2281
  defines "a \<equiv> Inf S"
huffman@44170
  2282
  shows "mono_set S \<longleftrightarrow> (S = {a <..} \<or> S = {a..})" (is "_ = ?c")
hoelzl@41973
  2283
proof
huffman@44170
  2284
  assume "mono_set S"
hoelzl@41973
  2285
  then have mono: "\<And>x y. x \<le> y \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S" by (auto simp: mono_set)
hoelzl@41973
  2286
  show ?c
hoelzl@41973
  2287
  proof cases
hoelzl@41973
  2288
    assume "a \<in> S"
hoelzl@41973
  2289
    show ?c
hoelzl@41973
  2290
      using mono[OF _ `a \<in> S`]
haftmann@43941
  2291
      by (auto intro: Inf_lower simp: a_def)
hoelzl@41973
  2292
  next
hoelzl@41973
  2293
    assume "a \<notin> S"
hoelzl@41973
  2294
    have "S = {a <..}"
hoelzl@41973
  2295
    proof safe
hoelzl@41973
  2296
      fix x assume "x \<in> S"
haftmann@43941
  2297
      then have "a \<le> x" unfolding a_def by (rule Inf_lower)
hoelzl@41973
  2298
      then show "a < x" using `x \<in> S` `a \<notin> S` by (cases "a = x") auto
hoelzl@41973
  2299
    next
hoelzl@41973
  2300
      fix x assume "a < x"
hoelzl@41973
  2301
      then obtain y where "y < x" "y \<in> S" unfolding a_def Inf_less_iff ..
hoelzl@41973
  2302
      with mono[of y x] show "x \<in> S" by auto
hoelzl@41973
  2303
    qed
hoelzl@41973
  2304
    then show ?c ..
hoelzl@41973
  2305
  qed
hoelzl@41973
  2306
qed auto
hoelzl@41973
  2307
hoelzl@41973
  2308
lemma lim_imp_Liminf:
hoelzl@43920
  2309
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@41973
  2310
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  2311
  assumes lim: "(f ---> f0) net"
hoelzl@41973
  2312
  shows "Liminf net f = f0"
hoelzl@41973
  2313
  unfolding Liminf_Sup
hoelzl@43920
  2314
proof (safe intro!: ereal_SupI)
hoelzl@41973
  2315
  fix y assume *: "\<forall>y'<y. eventually (\<lambda>x. y' < f x) net"
hoelzl@41973
  2316
  show "y \<le> f0"
hoelzl@43920
  2317
  proof (rule ereal_le_ereal)
hoelzl@41973
  2318
    fix B assume "B < y"
hoelzl@41973
  2319
    { assume "f0 < B"
hoelzl@41973
  2320
      then have "eventually (\<lambda>x. f x < B \<and> B < f x) net"
hoelzl@41973
  2321
         using topological_tendstoD[OF lim, of "{..<B}"] *[rule_format, OF `B < y`]
hoelzl@41973
  2322
         by (auto intro: eventually_conj)
hoelzl@41973
  2323
      also have "(\<lambda>x. f x < B \<and> B < f x) = (\<lambda>x. False)" by (auto simp: fun_eq_iff)
hoelzl@41973
  2324
      finally have False using ntriv[unfolded trivial_limit_def] by auto
hoelzl@41973
  2325
    } then show "B \<le> f0" by (metis linorder_le_less_linear)
hoelzl@41973
  2326
  qed
hoelzl@41973
  2327
next
hoelzl@41973
  2328
  fix y assume *: "\<forall>z. z \<in> {l. \<forall>y<l. eventually (\<lambda>x. y < f x) net} \<longrightarrow> z \<le> y"
hoelzl@41973
  2329
  show "f0 \<le> y"
hoelzl@41973
  2330
  proof (safe intro!: *[rule_format])
hoelzl@41973
  2331
    fix y assume "y < f0" then show "eventually (\<lambda>x. y < f x) net"
hoelzl@41973
  2332
      using lim[THEN topological_tendstoD, of "{y <..}"] by auto
hoelzl@41973
  2333
  qed
hoelzl@41973
  2334
qed
hoelzl@41973
  2335
hoelzl@43920
  2336
lemma ereal_Liminf_le_Limsup:
hoelzl@43920
  2337
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@41973
  2338
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  2339
  shows "Liminf net f \<le> Limsup net f"
hoelzl@41973
  2340
  unfolding Limsup_Inf Liminf_Sup
hoelzl@41973
  2341
proof (safe intro!: complete_lattice_class.Inf_greatest  complete_lattice_class.Sup_least)
hoelzl@41973
  2342
  fix u v assume *: "\<forall>y<u. eventually (\<lambda>x. y < f x) net" "\<forall>y>v. eventually (\<lambda>x. f x < y) net"
hoelzl@41973
  2343
  show "u \<le> v"
hoelzl@41973
  2344
  proof (rule ccontr)
hoelzl@41973
  2345
    assume "\<not> u \<le> v"
hoelzl@41973
  2346
    then obtain t where "t < u" "v < t"
hoelzl@43920
  2347
      using ereal_dense[of v u] by (auto simp: not_le)
hoelzl@41973
  2348
    then have "eventually (\<lambda>x. t < f x \<and> f x < t) net"
hoelzl@41973
  2349
      using * by (auto intro: eventually_conj)
hoelzl@41973
  2350
    also have "(\<lambda>x. t < f x \<and> f x < t) = (\<lambda>x. False)" by (auto simp: fun_eq_iff)
hoelzl@41973
  2351
    finally show False using ntriv by (auto simp: trivial_limit_def)
hoelzl@41973
  2352
  qed
hoelzl@41973
  2353
qed
hoelzl@41973
  2354
hoelzl@41973
  2355
lemma Liminf_mono:
hoelzl@43920
  2356
  fixes f g :: "'a => ereal"
hoelzl@41973
  2357
  assumes ev: "eventually (\<lambda>x. f x \<le> g x) net"
hoelzl@41973
  2358
  shows "Liminf net f \<le> Liminf net g"
hoelzl@41973
  2359
  unfolding Liminf_Sup
hoelzl@41973
  2360
proof (safe intro!: Sup_mono bexI)
hoelzl@41973
  2361
  fix a y assume "\<forall>y<a. eventually (\<lambda>x. y < f x) net" and "y < a"
hoelzl@41973
  2362
  then have "eventually (\<lambda>x. y < f x) net" by auto
hoelzl@41973
  2363
  then show "eventually (\<lambda>x. y < g x) net"
hoelzl@41973
  2364
    by (rule eventually_rev_mp) (rule eventually_mono[OF _ ev], auto)
hoelzl@41973
  2365
qed simp
hoelzl@41973
  2366
hoelzl@41973
  2367
lemma Liminf_eq:
hoelzl@43920
  2368
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@41973
  2369
  assumes "eventually (\<lambda>x. f x = g x) net"
hoelzl@41973
  2370
  shows "Liminf net f = Liminf net g"
hoelzl@41973
  2371
  by (intro antisym Liminf_mono eventually_mono[OF _ assms]) auto
hoelzl@41973
  2372
hoelzl@41973
  2373
lemma Liminf_mono_all:
hoelzl@43920
  2374
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@41973
  2375
  assumes "\<And>x. f x \<le> g x"
hoelzl@41973
  2376
  shows "Liminf net f \<le> Liminf net g"
hoelzl@41973
  2377
  using assms by (intro Liminf_mono always_eventually) auto
hoelzl@41973
  2378
hoelzl@41973
  2379
lemma Limsup_mono:
hoelzl@43920
  2380
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@41973
  2381
  assumes ev: "eventually (\<lambda>x. f x \<le> g x) net"
hoelzl@41973
  2382
  shows "Limsup net f \<le> Limsup net g"
hoelzl@41973
  2383
  unfolding Limsup_Inf
hoelzl@41973
  2384
proof (safe intro!: Inf_mono bexI)
hoelzl@41973
  2385
  fix a y assume "\<forall>y>a. eventually (\<lambda>x. g x < y) net" and "a < y"
hoelzl@41973
  2386
  then have "eventually (\<lambda>x. g x < y) net" by auto
hoelzl@41973
  2387
  then show "eventually (\<lambda>x. f x < y) net"
hoelzl@41973
  2388
    by (rule eventually_rev_mp) (rule eventually_mono[OF _ ev], auto)
hoelzl@41973
  2389
qed simp
hoelzl@41973
  2390
hoelzl@41973
  2391
lemma Limsup_mono_all:
hoelzl@43920
  2392
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@41973
  2393
  assumes "\<And>x. f x \<le> g x"
hoelzl@41973
  2394
  shows "Limsup net f \<le> Limsup net g"
hoelzl@41973
  2395
  using assms by (intro Limsup_mono always_eventually) auto
hoelzl@41973
  2396
hoelzl@41973
  2397
lemma Limsup_eq:
hoelzl@43920
  2398
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@41973
  2399
  assumes "eventually (\<lambda>x. f x = g x) net"
hoelzl@41973
  2400
  shows "Limsup net f = Limsup net g"
hoelzl@41973
  2401
  by (intro antisym Limsup_mono eventually_mono[OF _ assms]) auto
hoelzl@41973
  2402
hoelzl@41973
  2403
abbreviation "liminf \<equiv> Liminf sequentially"
hoelzl@41973
  2404
hoelzl@41973
  2405
abbreviation "limsup \<equiv> Limsup sequentially"
hoelzl@41973
  2406
hoelzl@41973
  2407
lemma liminf_SUPR_INFI:
hoelzl@43920
  2408
  fixes f :: "nat \<Rightarrow> ereal"
hoelzl@41973
  2409
  shows "liminf f = (SUP n. INF m:{n..}. f m)"
hoelzl@41973
  2410
  unfolding Liminf_Sup eventually_sequentially
hoelzl@41973
  2411
proof (safe intro!: antisym complete_lattice_class.Sup_least)
hoelzl@41973
  2412
  fix x assume *: "\<forall>y<x. \<exists>N. \<forall>n\<ge>N. y < f n" show "x \<le> (SUP n. INF m:{n..}. f m)"
hoelzl@43920
  2413
  proof (rule ereal_le_ereal)
hoelzl@41973
  2414
    fix y assume "y < x"
hoelzl@41973
  2415
    with * obtain N where "\<And>n. N \<le> n \<Longrightarrow> y < f n" by auto
hoelzl@41973
  2416
    then have "y \<le> (INF m:{N..}. f m)" by (force simp: le_INF_iff)
hoelzl@44928
  2417
    also have "\<dots> \<le> (SUP n. INF m:{n..}. f m)" by (intro SUP_upper) auto
hoelzl@41973
  2418
    finally show "y \<le> (SUP n. INF m:{n..}. f m)" .
hoelzl@41973
  2419
  qed
hoelzl@41973
  2420
next
hoelzl@41973
  2421
  show "(SUP n. INF m:{n..}. f m) \<le> Sup {l. \<forall>y<l. \<exists>N. \<forall>n\<ge>N. y < f n}"
hoelzl@44928
  2422
  proof (unfold SUP_def, safe intro!: Sup_mono bexI)
hoelzl@41973
  2423
    fix y n assume "y < INFI {n..} f"
hoelzl@44928
  2424
    from less_INF_D[OF this] show "\<exists>N. \<forall>n\<ge>N. y < f n" by (intro exI[of _ n]) auto
hoelzl@41973
  2425
  qed (rule order_refl)
hoelzl@41973
  2426
qed
hoelzl@41973
  2427
hoelzl@41973
  2428
lemma tail_same_limsup:
hoelzl@43920
  2429
  fixes X Y :: "nat => ereal"
hoelzl@41973
  2430
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n = Y n"
hoelzl@41973
  2431
  shows "limsup X = limsup Y"
hoelzl@41973
  2432
  using Limsup_eq[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2433
hoelzl@41973
  2434
lemma tail_same_liminf:
hoelzl@43920
  2435
  fixes X Y :: "nat => ereal"
hoelzl@41973
  2436
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n = Y n"
hoelzl@41973
  2437
  shows "liminf X = liminf Y"
hoelzl@41973
  2438
  using Liminf_eq[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2439
hoelzl@41973
  2440
lemma liminf_mono:
hoelzl@43920
  2441
  fixes X Y :: "nat \<Rightarrow> ereal"
hoelzl@41973
  2442
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n <= Y n"
hoelzl@41973
  2443
  shows "liminf X \<le> liminf Y"
hoelzl@41973
  2444
  using Liminf_mono[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2445
hoelzl@41973
  2446
lemma limsup_mono:
hoelzl@43920
  2447
  fixes X Y :: "nat => ereal"
hoelzl@41973
  2448
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n <= Y n"
hoelzl@41973
  2449
  shows "limsup X \<le> limsup Y"
hoelzl@41973
  2450
  using Limsup_mono[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2451
hoelzl@41978
  2452
lemma
hoelzl@43920
  2453
  fixes X :: "nat \<Rightarrow> ereal"
hoelzl@43920
  2454
  shows ereal_incseq_uminus[simp]: "incseq (\<lambda>i. - X i) = decseq X"
hoelzl@43920
  2455
    and ereal_decseq_uminus[simp]: "decseq (\<lambda>i. - X i) = incseq X"
hoelzl@41978
  2456
  unfolding incseq_def decseq_def by auto
hoelzl@41978
  2457
hoelzl@41973
  2458
lemma liminf_bounded:
hoelzl@43920
  2459
  fixes X Y :: "nat \<Rightarrow> ereal"
hoelzl@41973
  2460
  assumes "\<And>n. N \<le> n \<Longrightarrow> C \<le> X n"
hoelzl@41973
  2461
  shows "C \<le> liminf X"
hoelzl@41973
  2462
  using liminf_mono[of N "\<lambda>n. C" X] assms Liminf_const[of sequentially C] by simp
hoelzl@41973
  2463
hoelzl@41973
  2464
lemma limsup_bounded:
hoelzl@43920
  2465
  fixes X Y :: "nat => ereal"
hoelzl@41973
  2466
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n <= C"
hoelzl@41973
  2467
  shows "limsup X \<le> C"
hoelzl@41973
  2468
  using limsup_mono[of N X "\<lambda>n. C"] assms Limsup_const[of sequentially C] by simp
hoelzl@41973
  2469
hoelzl@41973
  2470
lemma liminf_bounded_iff:
hoelzl@43920
  2471
  fixes x :: "nat \<Rightarrow> ereal"
hoelzl@41973
  2472
  shows "C \<le> liminf x \<longleftrightarrow> (\<forall>B<C. \<exists>N. \<forall>n\<ge>N. B < x n)" (is "?lhs <-> ?rhs")
hoelzl@41973
  2473
proof safe
hoelzl@41973
  2474
  fix B assume "B < C" "C \<le> liminf x"
hoelzl@41973
  2475
  then have "B < liminf x" by auto
hoelzl@41973
  2476
  then obtain N where "B < (INF m:{N..}. x m)"
hoelzl@44928
  2477
    unfolding liminf_SUPR_INFI SUP_def less_Sup_iff by auto
hoelzl@44928
  2478
  from less_INF_D[OF this] show "\<exists>N. \<forall>n\<ge>N. B < x n" by auto
hoelzl@41973
  2479
next
hoelzl@41973
  2480
  assume *: "\<forall>B<C. \<exists>N. \<forall>n\<ge>N. B < x n"