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