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