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