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