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