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