src/HOL/Library/Extended_Reals.thy
author hoelzl
Mon Mar 14 14:37:40 2011 +0100 (2011-03-14)
changeset 41974 6e691abef08f
parent 41973 15927c040731
child 41975 d47eabd80e59
permissions -rw-r--r--
use case_product for extrel[2,3]_cases
hoelzl@41973
     1
 (* Title: Extended_Reals.thy
hoelzl@41973
     2
   Author: Johannes Hölzl, Robert Himmelmann, Armin Heller; TU München
hoelzl@41973
     3
   Author: Bogdan Grechuk; University of Edinburgh *)
hoelzl@41973
     4
hoelzl@41973
     5
header {* Extended real number line *}
hoelzl@41973
     6
hoelzl@41973
     7
theory Extended_Reals
hoelzl@41973
     8
  imports Topology_Euclidean_Space
hoelzl@41973
     9
begin
hoelzl@41973
    10
hoelzl@41973
    11
subsection {* Definition and basic properties *}
hoelzl@41973
    12
hoelzl@41973
    13
datatype extreal = extreal real | PInfty | MInfty
hoelzl@41973
    14
hoelzl@41973
    15
notation (xsymbols)
hoelzl@41973
    16
  PInfty  ("\<infinity>")
hoelzl@41973
    17
hoelzl@41973
    18
notation (HTML output)
hoelzl@41973
    19
  PInfty  ("\<infinity>")
hoelzl@41973
    20
hoelzl@41973
    21
instantiation extreal :: uminus
hoelzl@41973
    22
begin
hoelzl@41973
    23
  fun uminus_extreal where
hoelzl@41973
    24
    "- (extreal r) = extreal (- r)"
hoelzl@41973
    25
  | "- \<infinity> = MInfty"
hoelzl@41973
    26
  | "- MInfty = \<infinity>"
hoelzl@41973
    27
  instance ..
hoelzl@41973
    28
end
hoelzl@41973
    29
hoelzl@41973
    30
lemma MInfty_neq_PInfty[simp]:
hoelzl@41973
    31
  "\<infinity> \<noteq> - \<infinity>" "- \<infinity> \<noteq> \<infinity>" by simp_all
hoelzl@41973
    32
hoelzl@41973
    33
lemma MInfty_neq_extreal[simp]:
hoelzl@41973
    34
  "extreal r \<noteq> - \<infinity>" "- \<infinity> \<noteq> extreal r" by simp_all
hoelzl@41973
    35
hoelzl@41973
    36
lemma MInfinity_cases[simp]:
hoelzl@41973
    37
  "(case - \<infinity> of extreal r \<Rightarrow> f r | \<infinity> \<Rightarrow> y | MInfinity \<Rightarrow> z) = z"
hoelzl@41973
    38
  by simp
hoelzl@41973
    39
hoelzl@41973
    40
lemma extreal_uminus_uminus[simp]:
hoelzl@41973
    41
  fixes a :: extreal shows "- (- a) = a"
hoelzl@41973
    42
  by (cases a) simp_all
hoelzl@41973
    43
hoelzl@41973
    44
lemma MInfty_eq[simp]:
hoelzl@41973
    45
  "MInfty = - \<infinity>" by simp
hoelzl@41973
    46
hoelzl@41973
    47
declare uminus_extreal.simps(2)[simp del]
hoelzl@41973
    48
hoelzl@41973
    49
lemma extreal_cases[case_names real PInf MInf, cases type: extreal]:
hoelzl@41973
    50
  assumes "\<And>r. x = extreal r \<Longrightarrow> P"
hoelzl@41973
    51
  assumes "x = \<infinity> \<Longrightarrow> P"
hoelzl@41973
    52
  assumes "x = -\<infinity> \<Longrightarrow> P"
hoelzl@41973
    53
  shows P
hoelzl@41973
    54
  using assms by (cases x) auto
hoelzl@41973
    55
hoelzl@41974
    56
lemmas extreal2_cases = extreal_cases[case_product extreal_cases]
hoelzl@41974
    57
lemmas extreal3_cases = extreal2_cases[case_product extreal_cases]
hoelzl@41973
    58
hoelzl@41973
    59
lemma extreal_uminus_eq_iff[simp]:
hoelzl@41973
    60
  fixes a b :: extreal shows "-a = -b \<longleftrightarrow> a = b"
hoelzl@41973
    61
  by (cases rule: extreal2_cases[of a b]) simp_all
hoelzl@41973
    62
hoelzl@41973
    63
function of_extreal :: "extreal \<Rightarrow> real" where
hoelzl@41973
    64
"of_extreal (extreal r) = r" |
hoelzl@41973
    65
"of_extreal \<infinity> = 0" |
hoelzl@41973
    66
"of_extreal (-\<infinity>) = 0"
hoelzl@41973
    67
  by (auto intro: extreal_cases)
hoelzl@41973
    68
termination proof qed (rule wf_empty)
hoelzl@41973
    69
hoelzl@41973
    70
defs (overloaded)
hoelzl@41973
    71
  real_of_extreal_def [code_unfold]: "real \<equiv> of_extreal"
hoelzl@41973
    72
hoelzl@41973
    73
lemma real_of_extreal[simp]:
hoelzl@41973
    74
    "real (- x :: extreal) = - (real x)"
hoelzl@41973
    75
    "real (extreal r) = r"
hoelzl@41973
    76
    "real \<infinity> = 0"
hoelzl@41973
    77
  by (cases x) (simp_all add: real_of_extreal_def)
hoelzl@41973
    78
hoelzl@41973
    79
lemma range_extreal[simp]: "range extreal = UNIV - {\<infinity>, -\<infinity>}"
hoelzl@41973
    80
proof safe
hoelzl@41973
    81
  fix x assume "x \<notin> range extreal" "x \<noteq> \<infinity>"
hoelzl@41973
    82
  then show "x = -\<infinity>" by (cases x) auto
hoelzl@41973
    83
qed auto
hoelzl@41973
    84
hoelzl@41973
    85
instantiation extreal :: number
hoelzl@41973
    86
begin
hoelzl@41973
    87
definition [simp]: "number_of x = extreal (number_of x)"
hoelzl@41973
    88
instance proof qed
hoelzl@41973
    89
end
hoelzl@41973
    90
hoelzl@41973
    91
subsubsection "Addition"
hoelzl@41973
    92
hoelzl@41973
    93
instantiation extreal :: comm_monoid_add
hoelzl@41973
    94
begin
hoelzl@41973
    95
hoelzl@41973
    96
definition "0 = extreal 0"
hoelzl@41973
    97
hoelzl@41973
    98
function plus_extreal where
hoelzl@41973
    99
"extreal r + extreal p = extreal (r + p)" |
hoelzl@41973
   100
"\<infinity> + a = \<infinity>" |
hoelzl@41973
   101
"a + \<infinity> = \<infinity>" |
hoelzl@41973
   102
"extreal r + -\<infinity> = - \<infinity>" |
hoelzl@41973
   103
"-\<infinity> + extreal p = -\<infinity>" |
hoelzl@41973
   104
"-\<infinity> + -\<infinity> = -\<infinity>"
hoelzl@41973
   105
proof -
hoelzl@41973
   106
  case (goal1 P x)
hoelzl@41973
   107
  moreover then obtain a b where "x = (a, b)" by (cases x) auto
hoelzl@41973
   108
  ultimately show P
hoelzl@41973
   109
   by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   110
qed auto
hoelzl@41973
   111
termination proof qed (rule wf_empty)
hoelzl@41973
   112
hoelzl@41973
   113
lemma Infty_neq_0[simp]:
hoelzl@41973
   114
  "\<infinity> \<noteq> 0" "0 \<noteq> \<infinity>"
hoelzl@41973
   115
  "-\<infinity> \<noteq> 0" "0 \<noteq> -\<infinity>"
hoelzl@41973
   116
  by (simp_all add: zero_extreal_def)
hoelzl@41973
   117
hoelzl@41973
   118
lemma extreal_eq_0[simp]:
hoelzl@41973
   119
  "extreal r = 0 \<longleftrightarrow> r = 0"
hoelzl@41973
   120
  "0 = extreal r \<longleftrightarrow> r = 0"
hoelzl@41973
   121
  unfolding zero_extreal_def by simp_all
hoelzl@41973
   122
hoelzl@41973
   123
instance
hoelzl@41973
   124
proof
hoelzl@41973
   125
  fix a :: extreal show "0 + a = a"
hoelzl@41973
   126
    by (cases a) (simp_all add: zero_extreal_def)
hoelzl@41973
   127
  fix b :: extreal show "a + b = b + a"
hoelzl@41973
   128
    by (cases rule: extreal2_cases[of a b]) simp_all
hoelzl@41973
   129
  fix c :: extreal show "a + b + c = a + (b + c)"
hoelzl@41973
   130
    by (cases rule: extreal3_cases[of a b c]) simp_all
hoelzl@41973
   131
qed
hoelzl@41973
   132
end
hoelzl@41973
   133
hoelzl@41973
   134
lemma extreal_uminus_zero[simp]:
hoelzl@41973
   135
  "- 0 = (0::extreal)"
hoelzl@41973
   136
  by (simp add: zero_extreal_def)
hoelzl@41973
   137
hoelzl@41973
   138
lemma extreal_uminus_zero_iff[simp]:
hoelzl@41973
   139
  fixes a :: extreal shows "-a = 0 \<longleftrightarrow> a = 0"
hoelzl@41973
   140
  by (cases a) simp_all
hoelzl@41973
   141
hoelzl@41973
   142
lemma extreal_plus_eq_PInfty[simp]:
hoelzl@41973
   143
  shows "a + b = \<infinity> \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>"
hoelzl@41973
   144
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   145
hoelzl@41973
   146
lemma extreal_plus_eq_MInfty[simp]:
hoelzl@41973
   147
  shows "a + b = -\<infinity> \<longleftrightarrow>
hoelzl@41973
   148
    (a = -\<infinity> \<or> b = -\<infinity>) \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>"
hoelzl@41973
   149
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   150
hoelzl@41973
   151
lemma extreal_add_cancel_left:
hoelzl@41973
   152
  assumes "a \<noteq> -\<infinity>"
hoelzl@41973
   153
  shows "a + b = a + c \<longleftrightarrow> (a = \<infinity> \<or> b = c)"
hoelzl@41973
   154
  using assms by (cases rule: extreal3_cases[of a b c]) auto
hoelzl@41973
   155
hoelzl@41973
   156
lemma extreal_add_cancel_right:
hoelzl@41973
   157
  assumes "a \<noteq> -\<infinity>"
hoelzl@41973
   158
  shows "b + a = c + a \<longleftrightarrow> (a = \<infinity> \<or> b = c)"
hoelzl@41973
   159
  using assms by (cases rule: extreal3_cases[of a b c]) auto
hoelzl@41973
   160
hoelzl@41973
   161
lemma extreal_real:
hoelzl@41973
   162
  "extreal (real x) = (if x = \<infinity> \<or> x = -\<infinity> then 0 else x)"
hoelzl@41973
   163
  by (cases x) simp_all
hoelzl@41973
   164
hoelzl@41973
   165
subsubsection "Linear order on @{typ extreal}"
hoelzl@41973
   166
hoelzl@41973
   167
instantiation extreal :: linorder
hoelzl@41973
   168
begin
hoelzl@41973
   169
hoelzl@41973
   170
function less_extreal where
hoelzl@41973
   171
"extreal x < extreal y \<longleftrightarrow> x < y" |
hoelzl@41973
   172
"        \<infinity> < a         \<longleftrightarrow> False" |
hoelzl@41973
   173
"        a < -\<infinity>        \<longleftrightarrow> False" |
hoelzl@41973
   174
"extreal x < \<infinity>         \<longleftrightarrow> True" |
hoelzl@41973
   175
"       -\<infinity> < extreal r \<longleftrightarrow> True" |
hoelzl@41973
   176
"       -\<infinity> < \<infinity>         \<longleftrightarrow> True"
hoelzl@41973
   177
proof -
hoelzl@41973
   178
  case (goal1 P x)
hoelzl@41973
   179
  moreover then obtain a b where "x = (a,b)" by (cases x) auto
hoelzl@41973
   180
  ultimately show P by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   181
qed simp_all
hoelzl@41973
   182
termination by (relation "{}") simp
hoelzl@41973
   183
hoelzl@41973
   184
definition "x \<le> (y::extreal) \<longleftrightarrow> x < y \<or> x = y"
hoelzl@41973
   185
hoelzl@41973
   186
lemma extreal_infty_less[simp]:
hoelzl@41973
   187
  "x < \<infinity> \<longleftrightarrow> (x \<noteq> \<infinity>)"
hoelzl@41973
   188
  "-\<infinity> < x \<longleftrightarrow> (x \<noteq> -\<infinity>)"
hoelzl@41973
   189
  by (cases x, simp_all) (cases x, simp_all)
hoelzl@41973
   190
hoelzl@41973
   191
lemma extreal_infty_less_eq[simp]:
hoelzl@41973
   192
  "\<infinity> \<le> x \<longleftrightarrow> x = \<infinity>"
hoelzl@41973
   193
  "x \<le> -\<infinity> \<longleftrightarrow> x = -\<infinity>"
hoelzl@41973
   194
  by (auto simp add: less_eq_extreal_def)
hoelzl@41973
   195
hoelzl@41973
   196
lemma extreal_less[simp]:
hoelzl@41973
   197
  "extreal r < 0 \<longleftrightarrow> (r < 0)"
hoelzl@41973
   198
  "0 < extreal r \<longleftrightarrow> (0 < r)"
hoelzl@41973
   199
  "0 < \<infinity>"
hoelzl@41973
   200
  "-\<infinity> < 0"
hoelzl@41973
   201
  by (simp_all add: zero_extreal_def)
hoelzl@41973
   202
hoelzl@41973
   203
lemma extreal_less_eq[simp]:
hoelzl@41973
   204
  "x \<le> \<infinity>"
hoelzl@41973
   205
  "-\<infinity> \<le> x"
hoelzl@41973
   206
  "extreal r \<le> extreal p \<longleftrightarrow> r \<le> p"
hoelzl@41973
   207
  "extreal r \<le> 0 \<longleftrightarrow> r \<le> 0"
hoelzl@41973
   208
  "0 \<le> extreal r \<longleftrightarrow> 0 \<le> r"
hoelzl@41973
   209
  by (auto simp add: less_eq_extreal_def zero_extreal_def)
hoelzl@41973
   210
hoelzl@41973
   211
lemma extreal_infty_less_eq2:
hoelzl@41973
   212
  "a \<le> b \<Longrightarrow> a = \<infinity> \<Longrightarrow> b = \<infinity>"
hoelzl@41973
   213
  "a \<le> b \<Longrightarrow> b = -\<infinity> \<Longrightarrow> a = -\<infinity>"
hoelzl@41973
   214
  by simp_all
hoelzl@41973
   215
hoelzl@41973
   216
instance
hoelzl@41973
   217
proof
hoelzl@41973
   218
  fix x :: extreal show "x \<le> x"
hoelzl@41973
   219
    by (cases x) simp_all
hoelzl@41973
   220
  fix y :: extreal show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
hoelzl@41973
   221
    by (cases rule: extreal2_cases[of x y]) auto
hoelzl@41973
   222
  show "x \<le> y \<or> y \<le> x "
hoelzl@41973
   223
    by (cases rule: extreal2_cases[of x y]) auto
hoelzl@41973
   224
  { assume "x \<le> y" "y \<le> x" then show "x = y"
hoelzl@41973
   225
    by (cases rule: extreal2_cases[of x y]) auto }
hoelzl@41973
   226
  { fix z assume "x \<le> y" "y \<le> z" then show "x \<le> z"
hoelzl@41973
   227
    by (cases rule: extreal3_cases[of x y z]) auto }
hoelzl@41973
   228
qed
hoelzl@41973
   229
end
hoelzl@41973
   230
hoelzl@41973
   231
lemma extreal_MInfty_lessI[intro, simp]:
hoelzl@41973
   232
  "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a"
hoelzl@41973
   233
  by (cases a) auto
hoelzl@41973
   234
hoelzl@41973
   235
lemma extreal_less_PInfty[intro, simp]:
hoelzl@41973
   236
  "a \<noteq> \<infinity> \<Longrightarrow> a < \<infinity>"
hoelzl@41973
   237
  by (cases a) auto
hoelzl@41973
   238
hoelzl@41973
   239
lemma extreal_less_extreal_Ex:
hoelzl@41973
   240
  fixes a b :: extreal
hoelzl@41973
   241
  shows "x < extreal r \<longleftrightarrow> x = -\<infinity> \<or> (\<exists>p. p < r \<and> x = extreal p)"
hoelzl@41973
   242
  by (cases x) auto
hoelzl@41973
   243
hoelzl@41973
   244
lemma extreal_add_mono:
hoelzl@41973
   245
  fixes a b c d :: extreal assumes "a \<le> b" "c \<le> d" shows "a + c \<le> b + d"
hoelzl@41973
   246
  using assms
hoelzl@41973
   247
  apply (cases a)
hoelzl@41973
   248
  apply (cases rule: extreal3_cases[of b c d], auto)
hoelzl@41973
   249
  apply (cases rule: extreal3_cases[of b c d], auto)
hoelzl@41973
   250
  done
hoelzl@41973
   251
hoelzl@41973
   252
lemma extreal_minus_le_minus[simp]:
hoelzl@41973
   253
  fixes a b :: extreal shows "- a \<le> - b \<longleftrightarrow> b \<le> a"
hoelzl@41973
   254
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   255
hoelzl@41973
   256
lemma extreal_minus_less_minus[simp]:
hoelzl@41973
   257
  fixes a b :: extreal shows "- a < - b \<longleftrightarrow> b < a"
hoelzl@41973
   258
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   259
hoelzl@41973
   260
lemma extreal_le_real_iff:
hoelzl@41973
   261
  "x \<le> real y \<longleftrightarrow> ((y \<noteq> -\<infinity> \<and> y \<noteq> \<infinity> \<longrightarrow> extreal x \<le> y) \<and> (y = -\<infinity> \<or> y = \<infinity> \<longrightarrow> x \<le> 0))"
hoelzl@41973
   262
  by (cases y) auto
hoelzl@41973
   263
hoelzl@41973
   264
lemma real_le_extreal_iff:
hoelzl@41973
   265
  "real y \<le> x \<longleftrightarrow> ((y \<noteq> -\<infinity> \<and> y \<noteq> \<infinity> \<longrightarrow> y \<le> extreal x) \<and> (y = -\<infinity> \<or> y = \<infinity> \<longrightarrow> 0 \<le> x))"
hoelzl@41973
   266
  by (cases y) auto
hoelzl@41973
   267
hoelzl@41973
   268
lemma extreal_less_real_iff:
hoelzl@41973
   269
  "x < real y \<longleftrightarrow> ((y \<noteq> -\<infinity> \<and> y \<noteq> \<infinity> \<longrightarrow> extreal x < y) \<and> (y = -\<infinity> \<or> y = \<infinity> \<longrightarrow> x < 0))"
hoelzl@41973
   270
  by (cases y) auto
hoelzl@41973
   271
hoelzl@41973
   272
lemma real_less_extreal_iff:
hoelzl@41973
   273
  "real y < x \<longleftrightarrow> ((y \<noteq> -\<infinity> \<and> y \<noteq> \<infinity> \<longrightarrow> y < extreal x) \<and> (y = -\<infinity> \<or> y = \<infinity> \<longrightarrow> 0 < x))"
hoelzl@41973
   274
  by (cases y) auto
hoelzl@41973
   275
hoelzl@41973
   276
lemmas real_of_extreal_ord_simps =
hoelzl@41973
   277
  extreal_le_real_iff real_le_extreal_iff extreal_less_real_iff real_less_extreal_iff
hoelzl@41973
   278
hoelzl@41973
   279
lemma extreal_dense:
hoelzl@41973
   280
  fixes x y :: extreal assumes "x < y"
hoelzl@41973
   281
  shows "EX z. x < z & z < y"
hoelzl@41973
   282
proof -
hoelzl@41973
   283
{ assume a: "x = (-\<infinity>)"
hoelzl@41973
   284
  { assume "y = \<infinity>" hence ?thesis using a by (auto intro!: exI[of _ "0"]) }
hoelzl@41973
   285
  moreover
hoelzl@41973
   286
  { assume "y ~= \<infinity>"
hoelzl@41973
   287
    with `x < y` obtain r where r: "y = extreal r" by (cases y) auto
hoelzl@41973
   288
    hence ?thesis using `x < y` a by (auto intro!: exI[of _ "extreal (r - 1)"])
hoelzl@41973
   289
  } ultimately have ?thesis by auto
hoelzl@41973
   290
}
hoelzl@41973
   291
moreover
hoelzl@41973
   292
{ assume "x ~= (-\<infinity>)"
hoelzl@41973
   293
  with `x < y` obtain p where p: "x = extreal p" by (cases x) auto
hoelzl@41973
   294
  { assume "y = \<infinity>" hence ?thesis using `x < y` p
hoelzl@41973
   295
       by (auto intro!: exI[of _ "extreal (p + 1)"]) }
hoelzl@41973
   296
  moreover
hoelzl@41973
   297
  { assume "y ~= \<infinity>"
hoelzl@41973
   298
    with `x < y` obtain r where r: "y = extreal r" by (cases y) auto
hoelzl@41973
   299
    with p `x < y` have "p < r" by auto
hoelzl@41973
   300
    with dense obtain z where "p < z" "z < r" by auto
hoelzl@41973
   301
    hence ?thesis using r p by (auto intro!: exI[of _ "extreal z"])
hoelzl@41973
   302
  } ultimately have ?thesis by auto
hoelzl@41973
   303
} ultimately show ?thesis by auto
hoelzl@41973
   304
qed
hoelzl@41973
   305
hoelzl@41973
   306
lemma extreal_dense2:
hoelzl@41973
   307
  fixes x y :: extreal assumes "x < y"
hoelzl@41973
   308
  shows "EX z. x < extreal z & extreal z < y"
hoelzl@41973
   309
  by (metis extreal_dense[OF `x < y`] extreal_cases less_extreal.simps(2,3))
hoelzl@41973
   310
hoelzl@41973
   311
subsubsection "Multiplication"
hoelzl@41973
   312
hoelzl@41973
   313
instantiation extreal :: comm_monoid_mult
hoelzl@41973
   314
begin
hoelzl@41973
   315
hoelzl@41973
   316
definition "1 = extreal 1"
hoelzl@41973
   317
hoelzl@41973
   318
function times_extreal where
hoelzl@41973
   319
"extreal r * extreal p = extreal (r * p)" |
hoelzl@41973
   320
"extreal r * \<infinity> = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" |
hoelzl@41973
   321
"\<infinity> * extreal r = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)" |
hoelzl@41973
   322
"extreal r * -\<infinity> = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" |
hoelzl@41973
   323
"-\<infinity> * extreal r = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)" |
hoelzl@41973
   324
"\<infinity> * \<infinity> = \<infinity>" |
hoelzl@41973
   325
"-\<infinity> * \<infinity> = -\<infinity>" |
hoelzl@41973
   326
"\<infinity> * -\<infinity> = -\<infinity>" |
hoelzl@41973
   327
"-\<infinity> * -\<infinity> = \<infinity>"
hoelzl@41973
   328
proof -
hoelzl@41973
   329
  case (goal1 P x)
hoelzl@41973
   330
  moreover then obtain a b where "x = (a, b)" by (cases x) auto
hoelzl@41973
   331
  ultimately show P by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   332
qed simp_all
hoelzl@41973
   333
termination by (relation "{}") simp
hoelzl@41973
   334
hoelzl@41973
   335
instance
hoelzl@41973
   336
proof
hoelzl@41973
   337
  fix a :: extreal show "1 * a = a"
hoelzl@41973
   338
    by (cases a) (simp_all add: one_extreal_def)
hoelzl@41973
   339
  fix b :: extreal show "a * b = b * a"
hoelzl@41973
   340
    by (cases rule: extreal2_cases[of a b]) simp_all
hoelzl@41973
   341
  fix c :: extreal show "a * b * c = a * (b * c)"
hoelzl@41973
   342
    by (cases rule: extreal3_cases[of a b c])
hoelzl@41973
   343
       (simp_all add: zero_extreal_def zero_less_mult_iff)
hoelzl@41973
   344
qed
hoelzl@41973
   345
end
hoelzl@41973
   346
hoelzl@41973
   347
lemma extreal_mult_zero[simp]:
hoelzl@41973
   348
  fixes a :: extreal shows "a * 0 = 0"
hoelzl@41973
   349
  by (cases a) (simp_all add: zero_extreal_def)
hoelzl@41973
   350
hoelzl@41973
   351
lemma extreal_zero_mult[simp]:
hoelzl@41973
   352
  fixes a :: extreal shows "0 * a = 0"
hoelzl@41973
   353
  by (cases a) (simp_all add: zero_extreal_def)
hoelzl@41973
   354
hoelzl@41973
   355
lemma extreal_m1_less_0[simp]:
hoelzl@41973
   356
  "-(1::extreal) < 0"
hoelzl@41973
   357
  by (simp add: zero_extreal_def one_extreal_def)
hoelzl@41973
   358
hoelzl@41973
   359
lemma extreal_zero_m1[simp]:
hoelzl@41973
   360
  "1 \<noteq> (0::extreal)"
hoelzl@41973
   361
  by (simp add: zero_extreal_def one_extreal_def)
hoelzl@41973
   362
hoelzl@41973
   363
lemma extreal_times_0[simp]:
hoelzl@41973
   364
  fixes x :: extreal shows "0 * x = 0"
hoelzl@41973
   365
  by (cases x) (auto simp: zero_extreal_def)
hoelzl@41973
   366
hoelzl@41973
   367
lemma extreal_times[simp]:
hoelzl@41973
   368
  "1 \<noteq> \<infinity>" "\<infinity> \<noteq> 1"
hoelzl@41973
   369
  "1 \<noteq> -\<infinity>" "-\<infinity> \<noteq> 1"
hoelzl@41973
   370
  by (auto simp add: times_extreal_def one_extreal_def)
hoelzl@41973
   371
hoelzl@41973
   372
lemma extreal_plus_1[simp]:
hoelzl@41973
   373
  "1 + extreal r = extreal (r + 1)" "extreal r + 1 = extreal (r + 1)"
hoelzl@41973
   374
  "1 + -\<infinity> = -\<infinity>" "-\<infinity> + 1 = -\<infinity>"
hoelzl@41973
   375
  unfolding one_extreal_def by auto
hoelzl@41973
   376
hoelzl@41973
   377
lemma extreal_zero_times[simp]:
hoelzl@41973
   378
  fixes a b :: extreal shows "a * b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
hoelzl@41973
   379
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   380
hoelzl@41973
   381
lemma extreal_mult_eq_PInfty[simp]:
hoelzl@41973
   382
  shows "a * b = \<infinity> \<longleftrightarrow>
hoelzl@41973
   383
    (a = \<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = -\<infinity>)"
hoelzl@41973
   384
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   385
hoelzl@41973
   386
lemma extreal_mult_eq_MInfty[simp]:
hoelzl@41973
   387
  shows "a * b = -\<infinity> \<longleftrightarrow>
hoelzl@41973
   388
    (a = \<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = -\<infinity>)"
hoelzl@41973
   389
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   390
hoelzl@41973
   391
lemma extreal_0_less_1[simp]: "0 < (1::extreal)"
hoelzl@41973
   392
  by (simp_all add: zero_extreal_def one_extreal_def)
hoelzl@41973
   393
hoelzl@41973
   394
lemma extreal_zero_one[simp]: "0 \<noteq> (1::extreal)"
hoelzl@41973
   395
  by (simp_all add: zero_extreal_def one_extreal_def)
hoelzl@41973
   396
hoelzl@41973
   397
lemma extreal_mult_minus_left[simp]:
hoelzl@41973
   398
  fixes a b :: extreal shows "-a * b = - (a * b)"
hoelzl@41973
   399
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   400
hoelzl@41973
   401
lemma extreal_mult_minus_right[simp]:
hoelzl@41973
   402
  fixes a b :: extreal shows "a * -b = - (a * b)"
hoelzl@41973
   403
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
   404
hoelzl@41973
   405
lemma extreal_mult_infty[simp]:
hoelzl@41973
   406
  "a * \<infinity> = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)"
hoelzl@41973
   407
  by (cases a) auto
hoelzl@41973
   408
hoelzl@41973
   409
lemma extreal_infty_mult[simp]:
hoelzl@41973
   410
  "\<infinity> * a = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)"
hoelzl@41973
   411
  by (cases a) auto
hoelzl@41973
   412
hoelzl@41973
   413
lemma extreal_mult_strict_right_mono:
hoelzl@41973
   414
  assumes "a < b" and "0 < c" "c < \<infinity>"
hoelzl@41973
   415
  shows "a * c < b * c"
hoelzl@41973
   416
  using assms
hoelzl@41973
   417
  by (cases rule: extreal3_cases[of a b c])
hoelzl@41973
   418
     (auto simp: zero_le_mult_iff extreal_less_PInfty)
hoelzl@41973
   419
hoelzl@41973
   420
lemma extreal_mult_strict_left_mono:
hoelzl@41973
   421
  "\<lbrakk> a < b ; 0 < c ; c < \<infinity>\<rbrakk> \<Longrightarrow> c * a < c * b"
hoelzl@41973
   422
  using extreal_mult_strict_right_mono by (simp add: mult_commute[of c])
hoelzl@41973
   423
hoelzl@41973
   424
lemma extreal_mult_right_mono:
hoelzl@41973
   425
  fixes a b c :: extreal shows "\<lbrakk>a \<le> b; 0 \<le> c\<rbrakk> \<Longrightarrow> a*c \<le> b*c"
hoelzl@41973
   426
  using assms
hoelzl@41973
   427
  apply (cases "c = 0") apply simp
hoelzl@41973
   428
  by (cases rule: extreal3_cases[of a b c])
hoelzl@41973
   429
     (auto simp: zero_le_mult_iff extreal_less_PInfty)
hoelzl@41973
   430
hoelzl@41973
   431
lemma extreal_mult_left_mono:
hoelzl@41973
   432
  fixes a b c :: extreal shows "\<lbrakk>a \<le> b; 0 \<le> c\<rbrakk> \<Longrightarrow> c * a \<le> c * b"
hoelzl@41973
   433
  using extreal_mult_right_mono by (simp add: mult_commute[of c])
hoelzl@41973
   434
hoelzl@41973
   435
subsubsection {* Subtraction *}
hoelzl@41973
   436
hoelzl@41973
   437
lemma extreal_minus_minus_image[simp]:
hoelzl@41973
   438
  fixes S :: "extreal set"
hoelzl@41973
   439
  shows "uminus ` uminus ` S = S"
hoelzl@41973
   440
  by (auto simp: image_iff)
hoelzl@41973
   441
hoelzl@41973
   442
lemma extreal_uminus_lessThan[simp]:
hoelzl@41973
   443
  fixes a :: extreal shows "uminus ` {..<a} = {-a<..}"
hoelzl@41973
   444
proof (safe intro!: image_eqI)
hoelzl@41973
   445
  fix x assume "-a < x"
hoelzl@41973
   446
  then have "- x < - (- a)" by (simp del: extreal_uminus_uminus)
hoelzl@41973
   447
  then show "- x < a" by simp
hoelzl@41973
   448
qed auto
hoelzl@41973
   449
hoelzl@41973
   450
lemma extreal_uminus_greaterThan[simp]:
hoelzl@41973
   451
  "uminus ` {(a::extreal)<..} = {..<-a}"
hoelzl@41973
   452
  by (metis extreal_uminus_lessThan extreal_uminus_uminus
hoelzl@41973
   453
            extreal_minus_minus_image)
hoelzl@41973
   454
hoelzl@41973
   455
instantiation extreal :: minus
hoelzl@41973
   456
begin
hoelzl@41973
   457
definition "x - y = x + -(y::extreal)"
hoelzl@41973
   458
instance ..
hoelzl@41973
   459
end
hoelzl@41973
   460
hoelzl@41973
   461
lemma extreal_minus[simp]:
hoelzl@41973
   462
  "extreal r - extreal p = extreal (r - p)"
hoelzl@41973
   463
  "-\<infinity> - extreal r = -\<infinity>"
hoelzl@41973
   464
  "extreal r - \<infinity> = -\<infinity>"
hoelzl@41973
   465
  "\<infinity> - x = \<infinity>"
hoelzl@41973
   466
  "-\<infinity> - \<infinity> = -\<infinity>"
hoelzl@41973
   467
  "x - -y = x + y"
hoelzl@41973
   468
  "x - 0 = x"
hoelzl@41973
   469
  "0 - x = -x"
hoelzl@41973
   470
  by (simp_all add: minus_extreal_def)
hoelzl@41973
   471
hoelzl@41973
   472
lemma extreal_x_minus_x[simp]:
hoelzl@41973
   473
  "x - x = (if x = -\<infinity> \<or> x = \<infinity> then \<infinity> else 0)"
hoelzl@41973
   474
  by (cases x) simp_all
hoelzl@41973
   475
hoelzl@41973
   476
lemma extreal_eq_minus_iff:
hoelzl@41973
   477
  fixes x y z :: extreal
hoelzl@41973
   478
  shows "x = z - y \<longleftrightarrow>
hoelzl@41973
   479
    (y \<noteq> \<infinity> \<longrightarrow> y \<noteq> -\<infinity> \<longrightarrow> x + y = z) \<and>
hoelzl@41973
   480
    (y = -\<infinity> \<longrightarrow> x = \<infinity>) \<and>
hoelzl@41973
   481
    (y = \<infinity> \<longrightarrow> z = \<infinity> \<longrightarrow> x = \<infinity>) \<and>
hoelzl@41973
   482
    (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>)"
hoelzl@41973
   483
  by (cases rule: extreal3_cases[of x y z]) auto
hoelzl@41973
   484
hoelzl@41973
   485
lemma extreal_eq_minus:
hoelzl@41973
   486
  fixes x y z :: extreal
hoelzl@41973
   487
  shows "y \<noteq> \<infinity> \<Longrightarrow> y \<noteq> -\<infinity> \<Longrightarrow> x = z - y \<longleftrightarrow> x + y = z"
hoelzl@41973
   488
  by (simp add: extreal_eq_minus_iff)
hoelzl@41973
   489
hoelzl@41973
   490
lemma extreal_less_minus_iff:
hoelzl@41973
   491
  fixes x y z :: extreal
hoelzl@41973
   492
  shows "x < z - y \<longleftrightarrow>
hoelzl@41973
   493
    (y = \<infinity> \<longrightarrow> z = \<infinity> \<and> x \<noteq> \<infinity>) \<and>
hoelzl@41973
   494
    (y = -\<infinity> \<longrightarrow> x \<noteq> \<infinity>) \<and>
hoelzl@41973
   495
    (y \<noteq> \<infinity> \<longrightarrow> y \<noteq> -\<infinity> \<longrightarrow> x + y < z)"
hoelzl@41973
   496
  by (cases rule: extreal3_cases[of x y z]) auto
hoelzl@41973
   497
hoelzl@41973
   498
lemma extreal_less_minus:
hoelzl@41973
   499
  fixes x y z :: extreal
hoelzl@41973
   500
  shows "y \<noteq> \<infinity> \<Longrightarrow> y \<noteq> -\<infinity> \<Longrightarrow> x < z - y \<longleftrightarrow> x + y < z"
hoelzl@41973
   501
  by (simp add: extreal_less_minus_iff)
hoelzl@41973
   502
hoelzl@41973
   503
lemma extreal_le_minus_iff:
hoelzl@41973
   504
  fixes x y z :: extreal
hoelzl@41973
   505
  shows "x \<le> z - y \<longleftrightarrow>
hoelzl@41973
   506
    (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>) \<and>
hoelzl@41973
   507
    (y \<noteq> \<infinity> \<longrightarrow> y \<noteq> -\<infinity> \<longrightarrow> x + y \<le> z)"
hoelzl@41973
   508
  by (cases rule: extreal3_cases[of x y z]) auto
hoelzl@41973
   509
hoelzl@41973
   510
lemma extreal_le_minus:
hoelzl@41973
   511
  fixes x y z :: extreal
hoelzl@41973
   512
  shows "y \<noteq> \<infinity> \<Longrightarrow> y \<noteq> -\<infinity> \<Longrightarrow> x \<le> z - y \<longleftrightarrow> x + y \<le> z"
hoelzl@41973
   513
  by (simp add: extreal_le_minus_iff)
hoelzl@41973
   514
hoelzl@41973
   515
lemma extreal_minus_less_iff:
hoelzl@41973
   516
  fixes x y z :: extreal
hoelzl@41973
   517
  shows "x - y < z \<longleftrightarrow>
hoelzl@41973
   518
    y \<noteq> -\<infinity> \<and> (y = \<infinity> \<longrightarrow> x \<noteq> \<infinity> \<and> z \<noteq> -\<infinity>) \<and>
hoelzl@41973
   519
    (y \<noteq> \<infinity> \<longrightarrow> x < z + y)"
hoelzl@41973
   520
  by (cases rule: extreal3_cases[of x y z]) auto
hoelzl@41973
   521
hoelzl@41973
   522
lemma extreal_minus_less:
hoelzl@41973
   523
  fixes x y z :: extreal
hoelzl@41973
   524
  shows "y \<noteq> \<infinity> \<Longrightarrow> y \<noteq> -\<infinity> \<Longrightarrow> x - y < z \<longleftrightarrow> x < z + y"
hoelzl@41973
   525
  by (simp add: extreal_minus_less_iff)
hoelzl@41973
   526
hoelzl@41973
   527
lemma extreal_minus_le_iff:
hoelzl@41973
   528
  fixes x y z :: extreal
hoelzl@41973
   529
  shows "x - y \<le> z \<longleftrightarrow>
hoelzl@41973
   530
    (y = -\<infinity> \<longrightarrow> z = \<infinity>) \<and>
hoelzl@41973
   531
    (y = \<infinity> \<longrightarrow> x = \<infinity> \<longrightarrow> z = \<infinity>) \<and>
hoelzl@41973
   532
    (y \<noteq> \<infinity> \<longrightarrow> y \<noteq> -\<infinity> \<longrightarrow> x \<le> z + y)"
hoelzl@41973
   533
  by (cases rule: extreal3_cases[of x y z]) auto
hoelzl@41973
   534
hoelzl@41973
   535
lemma extreal_minus_le:
hoelzl@41973
   536
  fixes x y z :: extreal
hoelzl@41973
   537
  shows "y \<noteq> \<infinity> \<Longrightarrow> y \<noteq> -\<infinity> \<Longrightarrow> x - y \<le> z \<longleftrightarrow> x \<le> z + y"
hoelzl@41973
   538
  by (simp add: extreal_minus_le_iff)
hoelzl@41973
   539
hoelzl@41973
   540
lemma extreal_minus_eq_minus_iff:
hoelzl@41973
   541
  fixes a b c :: extreal
hoelzl@41973
   542
  shows "a - b = a - c \<longleftrightarrow>
hoelzl@41973
   543
    b = c \<or> a = \<infinity> \<or> (a = -\<infinity> \<and> b \<noteq> -\<infinity> \<and> c \<noteq> -\<infinity>)"
hoelzl@41973
   544
  by (cases rule: extreal3_cases[of a b c]) auto
hoelzl@41973
   545
hoelzl@41973
   546
lemma extreal_add_le_add_iff:
hoelzl@41973
   547
  "c + a \<le> c + b \<longleftrightarrow>
hoelzl@41973
   548
    a \<le> b \<or> c = \<infinity> \<or> (c = -\<infinity> \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>)"
hoelzl@41973
   549
  by (cases rule: extreal3_cases[of a b c]) (simp_all add: field_simps)
hoelzl@41973
   550
hoelzl@41973
   551
lemma extreal_mult_le_mult_iff:
hoelzl@41973
   552
  "c \<noteq> \<infinity> \<Longrightarrow> c \<noteq> -\<infinity> \<Longrightarrow> c * a \<le> c * b \<longleftrightarrow>
hoelzl@41973
   553
    (0 < c \<longrightarrow> a \<le> b) \<and> (c < 0 \<longrightarrow> b \<le> a)"
hoelzl@41973
   554
  by (cases rule: extreal3_cases[of a b c]) (simp_all add: mult_le_cancel_left)
hoelzl@41973
   555
hoelzl@41973
   556
lemma extreal_between:
hoelzl@41973
   557
  fixes x e :: extreal
hoelzl@41973
   558
  assumes "x \<noteq> \<infinity>" "x \<noteq> -\<infinity>" "0 < e"
hoelzl@41973
   559
  shows "x - e < x" "x < x + e"
hoelzl@41973
   560
using assms apply (cases x, cases e) apply auto
hoelzl@41973
   561
using assms by (cases x, cases e) auto
hoelzl@41973
   562
hoelzl@41973
   563
lemma extreal_distrib:
hoelzl@41973
   564
  fixes a b c :: extreal
hoelzl@41973
   565
  assumes "a \<noteq> \<infinity> \<or> b \<noteq> -\<infinity>" "a \<noteq> -\<infinity> \<or> b \<noteq> \<infinity>" "c \<noteq> \<infinity>" "c \<noteq> -\<infinity>"
hoelzl@41973
   566
  shows "(a + b) * c = a * c + b * c"
hoelzl@41973
   567
  using assms
hoelzl@41973
   568
  by (cases rule: extreal3_cases[of a b c]) (simp_all add: field_simps)
hoelzl@41973
   569
hoelzl@41973
   570
subsubsection {* Division *}
hoelzl@41973
   571
hoelzl@41973
   572
instantiation extreal :: inverse
hoelzl@41973
   573
begin
hoelzl@41973
   574
hoelzl@41973
   575
function inverse_extreal where
hoelzl@41973
   576
"inverse (extreal r) = (if r = 0 then \<infinity> else extreal (inverse r))" |
hoelzl@41973
   577
"inverse \<infinity> = 0" |
hoelzl@41973
   578
"inverse (-\<infinity>) = 0"
hoelzl@41973
   579
  by (auto intro: extreal_cases)
hoelzl@41973
   580
termination by (relation "{}") simp
hoelzl@41973
   581
hoelzl@41973
   582
definition "x / y = x * inverse (y :: extreal)"
hoelzl@41973
   583
hoelzl@41973
   584
instance proof qed
hoelzl@41973
   585
end
hoelzl@41973
   586
hoelzl@41973
   587
lemma extreal_inverse[simp]:
hoelzl@41973
   588
  "inverse 0 = \<infinity>"
hoelzl@41973
   589
  "inverse (1::extreal) = 1"
hoelzl@41973
   590
  by (simp_all add: one_extreal_def zero_extreal_def)
hoelzl@41973
   591
hoelzl@41973
   592
lemma extreal_divide[simp]:
hoelzl@41973
   593
  "extreal r / extreal p = (if p = 0 then extreal r * \<infinity> else extreal (r / p))"
hoelzl@41973
   594
  unfolding divide_extreal_def by (auto simp: divide_real_def)
hoelzl@41973
   595
hoelzl@41973
   596
lemma extreal_divide_same[simp]:
hoelzl@41973
   597
  "x / x = (if x = \<infinity> \<or> x = -\<infinity> \<or> x = 0 then 0 else 1)"
hoelzl@41973
   598
  by (cases x)
hoelzl@41973
   599
     (simp_all add: divide_real_def divide_extreal_def one_extreal_def)
hoelzl@41973
   600
hoelzl@41973
   601
lemma extreal_inv_inv[simp]:
hoelzl@41973
   602
  "inverse (inverse x) = (if x \<noteq> -\<infinity> then x else \<infinity>)"
hoelzl@41973
   603
  by (cases x) auto
hoelzl@41973
   604
hoelzl@41973
   605
lemma extreal_inverse_minus[simp]:
hoelzl@41973
   606
  "inverse (- x) = (if x = 0 then \<infinity> else -inverse x)"
hoelzl@41973
   607
  by (cases x) simp_all
hoelzl@41973
   608
hoelzl@41973
   609
lemma extreal_uminus_divide[simp]:
hoelzl@41973
   610
  fixes x y :: extreal shows "- x / y = - (x / y)"
hoelzl@41973
   611
  unfolding divide_extreal_def by simp
hoelzl@41973
   612
hoelzl@41973
   613
lemma extreal_divide_Infty[simp]:
hoelzl@41973
   614
  "x / \<infinity> = 0" "x / -\<infinity> = 0"
hoelzl@41973
   615
  unfolding divide_extreal_def by simp_all
hoelzl@41973
   616
hoelzl@41973
   617
lemma extreal_divide_one[simp]:
hoelzl@41973
   618
  "x / 1 = (x::extreal)"
hoelzl@41973
   619
  unfolding divide_extreal_def by simp
hoelzl@41973
   620
hoelzl@41973
   621
lemma extreal_divide_extreal[simp]:
hoelzl@41973
   622
  "\<infinity> / extreal r = (if 0 \<le> r then \<infinity> else -\<infinity>)"
hoelzl@41973
   623
  unfolding divide_extreal_def by simp
hoelzl@41973
   624
hoelzl@41973
   625
lemma extreal_mult_le_0_iff:
hoelzl@41973
   626
  fixes a b :: extreal
hoelzl@41973
   627
  shows "a * b \<le> 0 \<longleftrightarrow> (0 \<le> a \<and> b \<le> 0) \<or> (a \<le> 0 \<and> 0 \<le> b)"
hoelzl@41973
   628
  by (cases rule: extreal2_cases[of a b]) (simp_all add: mult_le_0_iff)
hoelzl@41973
   629
hoelzl@41973
   630
lemma extreal_zero_le_0_iff:
hoelzl@41973
   631
  fixes a b :: extreal
hoelzl@41973
   632
  shows "0 \<le> a * b \<longleftrightarrow> (0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0)"
hoelzl@41973
   633
  by (cases rule: extreal2_cases[of a b]) (simp_all add: zero_le_mult_iff)
hoelzl@41973
   634
hoelzl@41973
   635
lemma extreal_mult_less_0_iff:
hoelzl@41973
   636
  fixes a b :: extreal
hoelzl@41973
   637
  shows "a * b < 0 \<longleftrightarrow> (0 < a \<and> b < 0) \<or> (a < 0 \<and> 0 < b)"
hoelzl@41973
   638
  by (cases rule: extreal2_cases[of a b]) (simp_all add: mult_less_0_iff)
hoelzl@41973
   639
hoelzl@41973
   640
lemma extreal_zero_less_0_iff:
hoelzl@41973
   641
  fixes a b :: extreal
hoelzl@41973
   642
  shows "0 < a * b \<longleftrightarrow> (0 < a \<and> 0 < b) \<or> (a < 0 \<and> b < 0)"
hoelzl@41973
   643
  by (cases rule: extreal2_cases[of a b]) (simp_all add: zero_less_mult_iff)
hoelzl@41973
   644
hoelzl@41973
   645
lemma extreal_le_divide_pos:
hoelzl@41973
   646
  "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> x * y \<le> z"
hoelzl@41973
   647
  by (cases rule: extreal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
   648
hoelzl@41973
   649
lemma extreal_divide_le_pos:
hoelzl@41973
   650
  "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> z \<le> x * y"
hoelzl@41973
   651
  by (cases rule: extreal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
   652
hoelzl@41973
   653
lemma extreal_le_divide_neg:
hoelzl@41973
   654
  "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> y \<le> z / x \<longleftrightarrow> z \<le> x * y"
hoelzl@41973
   655
  by (cases rule: extreal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
   656
hoelzl@41973
   657
lemma extreal_divide_le_neg:
hoelzl@41973
   658
  "x < 0 \<Longrightarrow> x \<noteq> -\<infinity> \<Longrightarrow> z / x \<le> y \<longleftrightarrow> x * y \<le> z"
hoelzl@41973
   659
  by (cases rule: extreal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
   660
hoelzl@41973
   661
lemma extreal_inverse_antimono_strict:
hoelzl@41973
   662
  fixes x y :: extreal
hoelzl@41973
   663
  shows "0 \<le> x \<Longrightarrow> x < y \<Longrightarrow> inverse y < inverse x"
hoelzl@41973
   664
  by (cases rule: extreal2_cases[of x y]) auto
hoelzl@41973
   665
hoelzl@41973
   666
lemma extreal_inverse_antimono:
hoelzl@41973
   667
  fixes x y :: extreal
hoelzl@41973
   668
  shows "0 \<le> x \<Longrightarrow> x <= y \<Longrightarrow> inverse y <= inverse x"
hoelzl@41973
   669
  by (cases rule: extreal2_cases[of x y]) auto
hoelzl@41973
   670
hoelzl@41973
   671
lemma inverse_inverse_Pinfty_iff[simp]:
hoelzl@41973
   672
  "inverse x = \<infinity> \<longleftrightarrow> x = 0"
hoelzl@41973
   673
  by (cases x) auto
hoelzl@41973
   674
hoelzl@41973
   675
lemma extreal_inverse_eq_0:
hoelzl@41973
   676
  "inverse x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity>"
hoelzl@41973
   677
  by (cases x) auto
hoelzl@41973
   678
hoelzl@41973
   679
lemma extreal_mult_less_right:
hoelzl@41973
   680
  assumes "b * a < c * a" "0 < a" "a < \<infinity>"
hoelzl@41973
   681
  shows "b < c"
hoelzl@41973
   682
  using assms
hoelzl@41973
   683
  by (cases rule: extreal3_cases[of a b c])
hoelzl@41973
   684
     (auto split: split_if_asm simp: zero_less_mult_iff zero_le_mult_iff)
hoelzl@41973
   685
hoelzl@41973
   686
subsection "Complete lattice"
hoelzl@41973
   687
hoelzl@41973
   688
lemma extreal_bot:
hoelzl@41973
   689
  fixes x :: extreal assumes "\<And>B. x \<le> extreal B" shows "x = - \<infinity>"
hoelzl@41973
   690
proof (cases x)
hoelzl@41973
   691
  case (real r) with assms[of "r - 1"] show ?thesis by auto
hoelzl@41973
   692
next case PInf with assms[of 0] show ?thesis by auto
hoelzl@41973
   693
next case MInf then show ?thesis by simp
hoelzl@41973
   694
qed
hoelzl@41973
   695
hoelzl@41973
   696
lemma extreal_top:
hoelzl@41973
   697
  fixes x :: extreal assumes "\<And>B. x \<ge> extreal B" shows "x = \<infinity>"
hoelzl@41973
   698
proof (cases x)
hoelzl@41973
   699
  case (real r) with assms[of "r + 1"] show ?thesis by auto
hoelzl@41973
   700
next case MInf with assms[of 0] show ?thesis by auto
hoelzl@41973
   701
next case PInf then show ?thesis by simp
hoelzl@41973
   702
qed
hoelzl@41973
   703
hoelzl@41973
   704
instantiation extreal :: lattice
hoelzl@41973
   705
begin
hoelzl@41973
   706
definition [simp]: "sup x y = (max x y :: extreal)"
hoelzl@41973
   707
definition [simp]: "inf x y = (min x y :: extreal)"
hoelzl@41973
   708
instance proof qed simp_all
hoelzl@41973
   709
end
hoelzl@41973
   710
hoelzl@41973
   711
instantiation extreal :: complete_lattice
hoelzl@41973
   712
begin
hoelzl@41973
   713
hoelzl@41973
   714
definition "bot = (-\<infinity>)"
hoelzl@41973
   715
definition "top = \<infinity>"
hoelzl@41973
   716
hoelzl@41973
   717
definition "Sup S = (LEAST z. ALL x:S. x <= z :: extreal)"
hoelzl@41973
   718
definition "Inf S = (GREATEST z. ALL x:S. z <= x :: extreal)"
hoelzl@41973
   719
hoelzl@41973
   720
lemma extreal_complete_Sup:
hoelzl@41973
   721
  fixes S :: "extreal set" assumes "S \<noteq> {}"
hoelzl@41973
   722
  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
   723
proof cases
hoelzl@41973
   724
  assume "\<exists>x. \<forall>a\<in>S. a \<le> extreal x"
hoelzl@41973
   725
  then obtain y where y: "\<And>a. a\<in>S \<Longrightarrow> a \<le> extreal y" by auto
hoelzl@41973
   726
  then have "\<infinity> \<notin> S" by force
hoelzl@41973
   727
  show ?thesis
hoelzl@41973
   728
  proof cases
hoelzl@41973
   729
    assume "S = {-\<infinity>}"
hoelzl@41973
   730
    then show ?thesis by (auto intro!: exI[of _ "-\<infinity>"])
hoelzl@41973
   731
  next
hoelzl@41973
   732
    assume "S \<noteq> {-\<infinity>}"
hoelzl@41973
   733
    with `S \<noteq> {}` `\<infinity> \<notin> S` obtain x where "x \<in> S - {-\<infinity>}" "x \<noteq> \<infinity>" by auto
hoelzl@41973
   734
    with y `\<infinity> \<notin> S` have "\<forall>z\<in>real ` (S - {-\<infinity>}). z \<le> y"
hoelzl@41973
   735
      by (auto simp: real_of_extreal_ord_simps)
hoelzl@41973
   736
    with reals_complete2[of "real ` (S - {-\<infinity>})"] `x \<in> S - {-\<infinity>}`
hoelzl@41973
   737
    obtain s where s:
hoelzl@41973
   738
       "\<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
   739
       by auto
hoelzl@41973
   740
    show ?thesis
hoelzl@41973
   741
    proof (safe intro!: exI[of _ "extreal s"])
hoelzl@41973
   742
      fix z assume "z \<in> S" with `\<infinity> \<notin> S` show "z \<le> extreal s"
hoelzl@41973
   743
      proof (cases z)
hoelzl@41973
   744
        case (real r)
hoelzl@41973
   745
        then show ?thesis
hoelzl@41973
   746
          using s(1)[rule_format, of z] `z \<in> S` `z = extreal r` by auto
hoelzl@41973
   747
      qed auto
hoelzl@41973
   748
    next
hoelzl@41973
   749
      fix z assume *: "\<forall>y\<in>S. y \<le> z"
hoelzl@41973
   750
      with `S \<noteq> {-\<infinity>}` `S \<noteq> {}` show "extreal s \<le> z"
hoelzl@41973
   751
      proof (cases z)
hoelzl@41973
   752
        case (real u)
hoelzl@41973
   753
        with * have "s \<le> u"
hoelzl@41973
   754
          by (intro s(2)[of u]) (auto simp: real_of_extreal_ord_simps)
hoelzl@41973
   755
        then show ?thesis using real by simp
hoelzl@41973
   756
      qed auto
hoelzl@41973
   757
    qed
hoelzl@41973
   758
  qed
hoelzl@41973
   759
next
hoelzl@41973
   760
  assume *: "\<not> (\<exists>x. \<forall>a\<in>S. a \<le> extreal x)"
hoelzl@41973
   761
  show ?thesis
hoelzl@41973
   762
  proof (safe intro!: exI[of _ \<infinity>])
hoelzl@41973
   763
    fix y assume **: "\<forall>z\<in>S. z \<le> y"
hoelzl@41973
   764
    with * show "\<infinity> \<le> y"
hoelzl@41973
   765
    proof (cases y)
hoelzl@41973
   766
      case MInf with * ** show ?thesis by (force simp: not_le)
hoelzl@41973
   767
    qed auto
hoelzl@41973
   768
  qed simp
hoelzl@41973
   769
qed
hoelzl@41973
   770
hoelzl@41973
   771
lemma extreal_complete_Inf:
hoelzl@41973
   772
  fixes S :: "extreal set" assumes "S ~= {}"
hoelzl@41973
   773
  shows "EX x. (ALL y:S. x <= y) & (ALL z. (ALL y:S. z <= y) --> z <= x)"
hoelzl@41973
   774
proof-
hoelzl@41973
   775
def S1 == "uminus ` S"
hoelzl@41973
   776
hence "S1 ~= {}" using assms by auto
hoelzl@41973
   777
from this obtain x where x_def: "(ALL y:S1. y <= x) & (ALL z. (ALL y:S1. y <= z) --> x <= z)"
hoelzl@41973
   778
   using extreal_complete_Sup[of S1] by auto
hoelzl@41973
   779
{ fix z assume "ALL y:S. z <= y"
hoelzl@41973
   780
  hence "ALL y:S1. y <= -z" unfolding S1_def by auto
hoelzl@41973
   781
  hence "x <= -z" using x_def by auto
hoelzl@41973
   782
  hence "z <= -x"
hoelzl@41973
   783
    apply (subst extreal_uminus_uminus[symmetric])
hoelzl@41973
   784
    unfolding extreal_minus_le_minus . }
hoelzl@41973
   785
moreover have "(ALL y:S. -x <= y)"
hoelzl@41973
   786
   using x_def unfolding S1_def
hoelzl@41973
   787
   apply simp
hoelzl@41973
   788
   apply (subst (3) extreal_uminus_uminus[symmetric])
hoelzl@41973
   789
   unfolding extreal_minus_le_minus by simp
hoelzl@41973
   790
ultimately show ?thesis by auto
hoelzl@41973
   791
qed
hoelzl@41973
   792
hoelzl@41973
   793
lemma extreal_complete_uminus_eq:
hoelzl@41973
   794
  fixes S :: "extreal set"
hoelzl@41973
   795
  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
   796
     \<longleftrightarrow> (\<forall>y\<in>S. -x \<le> y) \<and> (\<forall>z. (\<forall>y\<in>S. z \<le> y) \<longrightarrow> z \<le> -x)"
hoelzl@41973
   797
  by simp (metis extreal_minus_le_minus extreal_uminus_uminus)
hoelzl@41973
   798
hoelzl@41973
   799
lemma extreal_Sup_uminus_image_eq:
hoelzl@41973
   800
  fixes S :: "extreal set"
hoelzl@41973
   801
  shows "Sup (uminus ` S) = - Inf S"
hoelzl@41973
   802
proof cases
hoelzl@41973
   803
  assume "S = {}"
hoelzl@41973
   804
  moreover have "(THE x. All (op \<le> x)) = (-\<infinity>::extreal)"
hoelzl@41973
   805
    by (rule the_equality) (auto intro!: extreal_bot)
hoelzl@41973
   806
  moreover have "(SOME x. \<forall>y. y \<le> x) = (\<infinity>::extreal)"
hoelzl@41973
   807
    by (rule some_equality) (auto intro!: extreal_top)
hoelzl@41973
   808
  ultimately show ?thesis unfolding Inf_extreal_def Sup_extreal_def
hoelzl@41973
   809
    Least_def Greatest_def GreatestM_def by simp
hoelzl@41973
   810
next
hoelzl@41973
   811
  assume "S \<noteq> {}"
hoelzl@41973
   812
  with extreal_complete_Sup[of "uminus`S"]
hoelzl@41973
   813
  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@41973
   814
    unfolding extreal_complete_uminus_eq by auto
hoelzl@41973
   815
  show "Sup (uminus ` S) = - Inf S"
hoelzl@41973
   816
    unfolding Inf_extreal_def Greatest_def GreatestM_def
hoelzl@41973
   817
  proof (intro someI2[of _ _ "\<lambda>x. Sup (uminus`S) = - x"])
hoelzl@41973
   818
    show "(\<forall>y\<in>S. -x \<le> y) \<and> (\<forall>y. (\<forall>z\<in>S. y \<le> z) \<longrightarrow> y \<le> -x)"
hoelzl@41973
   819
      using x .
hoelzl@41973
   820
    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
   821
    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@41973
   822
      unfolding extreal_complete_uminus_eq by simp
hoelzl@41973
   823
    then show "Sup (uminus ` S) = -x'"
hoelzl@41973
   824
      unfolding Sup_extreal_def extreal_uminus_eq_iff
hoelzl@41973
   825
      by (intro Least_equality) auto
hoelzl@41973
   826
  qed
hoelzl@41973
   827
qed
hoelzl@41973
   828
hoelzl@41973
   829
instance
hoelzl@41973
   830
proof
hoelzl@41973
   831
  { fix x :: extreal and A
hoelzl@41973
   832
    show "bot <= x" by (cases x) (simp_all add: bot_extreal_def)
hoelzl@41973
   833
    show "x <= top" by (simp add: top_extreal_def) }
hoelzl@41973
   834
hoelzl@41973
   835
  { fix x :: extreal and A assume "x : A"
hoelzl@41973
   836
    with extreal_complete_Sup[of A]
hoelzl@41973
   837
    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
   838
    hence "x <= s" using `x : A` by auto
hoelzl@41973
   839
    also have "... = Sup A" using s unfolding Sup_extreal_def
hoelzl@41973
   840
      by (auto intro!: Least_equality[symmetric])
hoelzl@41973
   841
    finally show "x <= Sup A" . }
hoelzl@41973
   842
  note le_Sup = this
hoelzl@41973
   843
hoelzl@41973
   844
  { fix x :: extreal and A assume *: "!!z. (z : A ==> z <= x)"
hoelzl@41973
   845
    show "Sup A <= x"
hoelzl@41973
   846
    proof (cases "A = {}")
hoelzl@41973
   847
      case True
hoelzl@41973
   848
      hence "Sup A = -\<infinity>" unfolding Sup_extreal_def
hoelzl@41973
   849
        by (auto intro!: Least_equality)
hoelzl@41973
   850
      thus "Sup A <= x" by simp
hoelzl@41973
   851
    next
hoelzl@41973
   852
      case False
hoelzl@41973
   853
      with extreal_complete_Sup[of A]
hoelzl@41973
   854
      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
   855
      hence "Sup A = s"
hoelzl@41973
   856
        unfolding Sup_extreal_def by (auto intro!: Least_equality)
hoelzl@41973
   857
      also have "s <= x" using * s by auto
hoelzl@41973
   858
      finally show "Sup A <= x" .
hoelzl@41973
   859
    qed }
hoelzl@41973
   860
  note Sup_le = this
hoelzl@41973
   861
hoelzl@41973
   862
  { fix x :: extreal and A assume "x \<in> A"
hoelzl@41973
   863
    with le_Sup[of "-x" "uminus`A"] show "Inf A \<le> x"
hoelzl@41973
   864
      unfolding extreal_Sup_uminus_image_eq by simp }
hoelzl@41973
   865
hoelzl@41973
   866
  { fix x :: extreal and A assume *: "!!z. (z : A ==> x <= z)"
hoelzl@41973
   867
    with Sup_le[of "uminus`A" "-x"] show "x \<le> Inf A"
hoelzl@41973
   868
      unfolding extreal_Sup_uminus_image_eq by force }
hoelzl@41973
   869
qed
hoelzl@41973
   870
end
hoelzl@41973
   871
hoelzl@41973
   872
lemma extreal_SUPR_uminus:
hoelzl@41973
   873
  fixes f :: "'a => extreal"
hoelzl@41973
   874
  shows "(SUP i : R. -(f i)) = -(INF i : R. f i)"
hoelzl@41973
   875
  unfolding SUPR_def INFI_def
hoelzl@41973
   876
  using extreal_Sup_uminus_image_eq[of "f`R"]
hoelzl@41973
   877
  by (simp add: image_image)
hoelzl@41973
   878
hoelzl@41973
   879
lemma extreal_INFI_uminus:
hoelzl@41973
   880
  fixes f :: "'a => extreal"
hoelzl@41973
   881
  shows "(INF i : R. -(f i)) = -(SUP i : R. f i)"
hoelzl@41973
   882
  using extreal_SUPR_uminus[of _ "\<lambda>x. - f x"] by simp
hoelzl@41973
   883
hoelzl@41973
   884
lemma extreal_inj_on_uminus[intro, simp]: "inj_on uminus (A :: extreal set)"
hoelzl@41973
   885
  by (auto intro!: inj_onI)
hoelzl@41973
   886
hoelzl@41973
   887
lemma extreal_image_uminus_shift:
hoelzl@41973
   888
  fixes X Y :: "extreal set" shows "uminus ` X = Y \<longleftrightarrow> X = uminus ` Y"
hoelzl@41973
   889
proof
hoelzl@41973
   890
  assume "uminus ` X = Y"
hoelzl@41973
   891
  then have "uminus ` uminus ` X = uminus ` Y"
hoelzl@41973
   892
    by (simp add: inj_image_eq_iff)
hoelzl@41973
   893
  then show "X = uminus ` Y" by (simp add: image_image)
hoelzl@41973
   894
qed (simp add: image_image)
hoelzl@41973
   895
hoelzl@41973
   896
lemma Inf_extreal_iff:
hoelzl@41973
   897
  fixes z :: extreal
hoelzl@41973
   898
  shows "(!!x. x:X ==> z <= x) ==> (EX x:X. x<y) <-> Inf X < y"
hoelzl@41973
   899
  by (metis complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower less_le_not_le linear
hoelzl@41973
   900
            order_less_le_trans)
hoelzl@41973
   901
hoelzl@41973
   902
lemma Sup_eq_MInfty:
hoelzl@41973
   903
  fixes S :: "extreal set" shows "Sup S = -\<infinity> \<longleftrightarrow> S = {} \<or> S = {-\<infinity>}"
hoelzl@41973
   904
proof
hoelzl@41973
   905
  assume a: "Sup S = -\<infinity>"
hoelzl@41973
   906
  with complete_lattice_class.Sup_upper[of _ S]
hoelzl@41973
   907
  show "S={} \<or> S={-\<infinity>}" by auto
hoelzl@41973
   908
next
hoelzl@41973
   909
  assume "S={} \<or> S={-\<infinity>}" then show "Sup S = -\<infinity>"
hoelzl@41973
   910
    unfolding Sup_extreal_def by (auto intro!: Least_equality)
hoelzl@41973
   911
qed
hoelzl@41973
   912
hoelzl@41973
   913
lemma Inf_eq_PInfty:
hoelzl@41973
   914
  fixes S :: "extreal set" shows "Inf S = \<infinity> \<longleftrightarrow> S = {} \<or> S = {\<infinity>}"
hoelzl@41973
   915
  using Sup_eq_MInfty[of "uminus`S"]
hoelzl@41973
   916
  unfolding extreal_Sup_uminus_image_eq extreal_image_uminus_shift by simp
hoelzl@41973
   917
hoelzl@41973
   918
lemma Inf_eq_MInfty: "-\<infinity> : S ==> Inf S = -\<infinity>"
hoelzl@41973
   919
  unfolding Inf_extreal_def
hoelzl@41973
   920
  by (auto intro!: Greatest_equality)
hoelzl@41973
   921
hoelzl@41973
   922
lemma Sup_eq_PInfty: "\<infinity> : S ==> Sup S = \<infinity>"
hoelzl@41973
   923
  unfolding Sup_extreal_def
hoelzl@41973
   924
  by (auto intro!: Least_equality)
hoelzl@41973
   925
hoelzl@41973
   926
lemma extreal_SUPI:
hoelzl@41973
   927
  fixes x :: extreal
hoelzl@41973
   928
  assumes "!!i. i : A ==> f i <= x"
hoelzl@41973
   929
  assumes "!!y. (!!i. i : A ==> f i <= y) ==> x <= y"
hoelzl@41973
   930
  shows "(SUP i:A. f i) = x"
hoelzl@41973
   931
  unfolding SUPR_def Sup_extreal_def
hoelzl@41973
   932
  using assms by (auto intro!: Least_equality)
hoelzl@41973
   933
hoelzl@41973
   934
lemma extreal_INFI:
hoelzl@41973
   935
  fixes x :: extreal
hoelzl@41973
   936
  assumes "!!i. i : A ==> f i >= x"
hoelzl@41973
   937
  assumes "!!y. (!!i. i : A ==> f i >= y) ==> x >= y"
hoelzl@41973
   938
  shows "(INF i:A. f i) = x"
hoelzl@41973
   939
  unfolding INFI_def Inf_extreal_def
hoelzl@41973
   940
  using assms by (auto intro!: Greatest_equality)
hoelzl@41973
   941
hoelzl@41973
   942
lemma Sup_extreal_close:
hoelzl@41973
   943
  fixes e :: extreal
hoelzl@41973
   944
  assumes "0 < e" and S: "Sup S \<noteq> \<infinity>" "Sup S \<noteq> -\<infinity>" "S \<noteq> {}"
hoelzl@41973
   945
  shows "\<exists>x\<in>S. Sup S - e < x"
hoelzl@41973
   946
proof (rule less_Sup_iff[THEN iffD1])
hoelzl@41973
   947
  show "Sup S - e < Sup S " using assms
hoelzl@41973
   948
    by (cases "Sup S", cases e) auto
hoelzl@41973
   949
qed
hoelzl@41973
   950
hoelzl@41973
   951
lemma Inf_extreal_close:
hoelzl@41973
   952
  fixes e :: extreal assumes "Inf X \<noteq> \<infinity>" "Inf X \<noteq> -\<infinity>" "0 < e"
hoelzl@41973
   953
  shows "\<exists>x\<in>X. x < Inf X + e"
hoelzl@41973
   954
proof (rule Inf_less_iff[THEN iffD1])
hoelzl@41973
   955
  show "Inf X < Inf X + e" using assms
hoelzl@41973
   956
    by (cases "Inf X", cases e) auto
hoelzl@41973
   957
qed
hoelzl@41973
   958
hoelzl@41973
   959
lemma (in complete_lattice) top_le:
hoelzl@41973
   960
  "top \<le> x \<Longrightarrow> x = top"
hoelzl@41973
   961
  by (rule antisym) auto
hoelzl@41973
   962
hoelzl@41973
   963
lemma Sup_eq_top_iff:
hoelzl@41973
   964
  fixes A :: "'a::{complete_lattice, linorder} set"
hoelzl@41973
   965
  shows "Sup A = top \<longleftrightarrow> (\<forall>x<top. \<exists>i\<in>A. x < i)"
hoelzl@41973
   966
proof
hoelzl@41973
   967
  assume *: "Sup A = top"
hoelzl@41973
   968
  show "(\<forall>x<top. \<exists>i\<in>A. x < i)" unfolding *[symmetric]
hoelzl@41973
   969
  proof (intro allI impI)
hoelzl@41973
   970
    fix x assume "x < Sup A" then show "\<exists>i\<in>A. x < i"
hoelzl@41973
   971
      unfolding less_Sup_iff by auto
hoelzl@41973
   972
  qed
hoelzl@41973
   973
next
hoelzl@41973
   974
  assume *: "\<forall>x<top. \<exists>i\<in>A. x < i"
hoelzl@41973
   975
  show "Sup A = top"
hoelzl@41973
   976
  proof (rule ccontr)
hoelzl@41973
   977
    assume "Sup A \<noteq> top"
hoelzl@41973
   978
    with top_greatest[of "Sup A"]
hoelzl@41973
   979
    have "Sup A < top" unfolding le_less by auto
hoelzl@41973
   980
    then have "Sup A < Sup A"
hoelzl@41973
   981
      using * unfolding less_Sup_iff by auto
hoelzl@41973
   982
    then show False by auto
hoelzl@41973
   983
  qed
hoelzl@41973
   984
qed
hoelzl@41973
   985
hoelzl@41973
   986
lemma SUP_eq_top_iff:
hoelzl@41973
   987
  fixes f :: "'a \<Rightarrow> 'b::{complete_lattice, linorder}"
hoelzl@41973
   988
  shows "(SUP i:A. f i) = top \<longleftrightarrow> (\<forall>x<top. \<exists>i\<in>A. x < f i)"
hoelzl@41973
   989
  unfolding SUPR_def Sup_eq_top_iff by auto
hoelzl@41973
   990
hoelzl@41973
   991
lemma SUP_nat_Infty: "(SUP i::nat. extreal (real i)) = \<infinity>"
hoelzl@41973
   992
proof -
hoelzl@41973
   993
  { fix x assume "x \<noteq> \<infinity>"
hoelzl@41973
   994
    then have "\<exists>k::nat. x < extreal (real k)"
hoelzl@41973
   995
    proof (cases x)
hoelzl@41973
   996
      case MInf then show ?thesis by (intro exI[of _ 0]) auto
hoelzl@41973
   997
    next
hoelzl@41973
   998
      case (real r)
hoelzl@41973
   999
      moreover obtain k :: nat where "r < real k"
hoelzl@41973
  1000
        using ex_less_of_nat by (auto simp: real_eq_of_nat)
hoelzl@41973
  1001
      ultimately show ?thesis by auto
hoelzl@41973
  1002
    qed simp }
hoelzl@41973
  1003
  then show ?thesis
hoelzl@41973
  1004
    using SUP_eq_top_iff[of UNIV "\<lambda>n::nat. extreal (real n)"]
hoelzl@41973
  1005
    by (auto simp: top_extreal_def)
hoelzl@41973
  1006
qed
hoelzl@41973
  1007
hoelzl@41973
  1008
lemma infeal_le_Sup:
hoelzl@41973
  1009
  fixes x :: extreal
hoelzl@41973
  1010
  shows "(x <= (SUP i:A. f i)) <-> (ALL y. y < x --> (EX i. i : A & y <= f i))"
hoelzl@41973
  1011
(is "?lhs <-> ?rhs")
hoelzl@41973
  1012
proof-
hoelzl@41973
  1013
{ assume "?rhs"
hoelzl@41973
  1014
  { assume "~(x <= (SUP i:A. f i))" hence "(SUP i:A. f i)<x" by (simp add: not_le)
hoelzl@41973
  1015
    from this obtain y where y_def: "(SUP i:A. f i)<y & y<x" using extreal_dense by auto
hoelzl@41973
  1016
    from this obtain i where "i : A & y <= f i" using `?rhs` by auto
hoelzl@41973
  1017
    hence "y <= (SUP i:A. f i)" using le_SUPI[of i A f] by auto
hoelzl@41973
  1018
    hence False using y_def by auto
hoelzl@41973
  1019
  } hence "?lhs" by auto
hoelzl@41973
  1020
}
hoelzl@41973
  1021
moreover
hoelzl@41973
  1022
{ assume "?lhs" hence "?rhs"
hoelzl@41973
  1023
  by (metis Collect_def Collect_mem_eq SUP_leI assms atLeastatMost_empty atLeastatMost_empty_iff
hoelzl@41973
  1024
      inf_sup_ord(4) linorder_le_cases sup_absorb1 xt1(8))
hoelzl@41973
  1025
} ultimately show ?thesis by auto
hoelzl@41973
  1026
qed
hoelzl@41973
  1027
hoelzl@41973
  1028
lemma infeal_Inf_le:
hoelzl@41973
  1029
  fixes x :: extreal
hoelzl@41973
  1030
  shows "((INF i:A. f i) <= x) <-> (ALL y. x < y --> (EX i. i : A & f i <= y))"
hoelzl@41973
  1031
(is "?lhs <-> ?rhs")
hoelzl@41973
  1032
proof-
hoelzl@41973
  1033
{ assume "?rhs"
hoelzl@41973
  1034
  { assume "~((INF i:A. f i) <= x)" hence "x < (INF i:A. f i)" by (simp add: not_le)
hoelzl@41973
  1035
    from this obtain y where y_def: "x<y & y<(INF i:A. f i)" using extreal_dense by auto
hoelzl@41973
  1036
    from this obtain i where "i : A & f i <= y" using `?rhs` by auto
hoelzl@41973
  1037
    hence "(INF i:A. f i) <= y" using INF_leI[of i A f] by auto
hoelzl@41973
  1038
    hence False using y_def by auto
hoelzl@41973
  1039
  } hence "?lhs" by auto
hoelzl@41973
  1040
}
hoelzl@41973
  1041
moreover
hoelzl@41973
  1042
{ assume "?lhs" hence "?rhs"
hoelzl@41973
  1043
  by (metis Collect_def Collect_mem_eq le_INFI assms atLeastatMost_empty atLeastatMost_empty_iff
hoelzl@41973
  1044
      inf_sup_ord(4) linorder_le_cases sup_absorb1 xt1(8))
hoelzl@41973
  1045
} ultimately show ?thesis by auto
hoelzl@41973
  1046
qed
hoelzl@41973
  1047
hoelzl@41973
  1048
lemma Inf_less:
hoelzl@41973
  1049
  fixes x :: extreal
hoelzl@41973
  1050
  assumes "(INF i:A. f i) < x"
hoelzl@41973
  1051
  shows "EX i. i : A & f i <= x"
hoelzl@41973
  1052
proof(rule ccontr)
hoelzl@41973
  1053
  assume "~ (EX i. i : A & f i <= x)"
hoelzl@41973
  1054
  hence "ALL i:A. f i > x" by auto
hoelzl@41973
  1055
  hence "(INF i:A. f i) >= x" apply (subst le_INFI) by auto
hoelzl@41973
  1056
  thus False using assms by auto
hoelzl@41973
  1057
qed
hoelzl@41973
  1058
hoelzl@41973
  1059
lemma same_INF:
hoelzl@41973
  1060
  assumes "ALL e:A. f e = g e"
hoelzl@41973
  1061
  shows "(INF e:A. f e) = (INF e:A. g e)"
hoelzl@41973
  1062
proof-
hoelzl@41973
  1063
have "f ` A = g ` A" unfolding image_def using assms by auto
hoelzl@41973
  1064
thus ?thesis unfolding INFI_def by auto
hoelzl@41973
  1065
qed
hoelzl@41973
  1066
hoelzl@41973
  1067
lemma same_SUP:
hoelzl@41973
  1068
  assumes "ALL e:A. f e = g e"
hoelzl@41973
  1069
  shows "(SUP e:A. f e) = (SUP e:A. g e)"
hoelzl@41973
  1070
proof-
hoelzl@41973
  1071
have "f ` A = g ` A" unfolding image_def using assms by auto
hoelzl@41973
  1072
thus ?thesis unfolding SUPR_def by auto
hoelzl@41973
  1073
qed
hoelzl@41973
  1074
hoelzl@41973
  1075
subsection "Limits on @{typ extreal}"
hoelzl@41973
  1076
hoelzl@41973
  1077
subsubsection "Topological space"
hoelzl@41973
  1078
hoelzl@41973
  1079
instantiation extreal :: topological_space
hoelzl@41973
  1080
begin
hoelzl@41973
  1081
hoelzl@41973
  1082
definition "open A \<longleftrightarrow>
hoelzl@41973
  1083
  (\<exists>T. open T \<and> extreal ` T = A - {\<infinity>, -\<infinity>})
hoelzl@41973
  1084
       \<and> (\<infinity> \<in> A \<longrightarrow> (\<exists>x. {extreal x <..} \<subseteq> A))
hoelzl@41973
  1085
       \<and> (-\<infinity> \<in> A \<longrightarrow> (\<exists>x. {..<extreal x} \<subseteq> A))"
hoelzl@41973
  1086
hoelzl@41973
  1087
lemma open_PInfty: "open A ==> \<infinity> : A ==> (EX x. {extreal x<..} <= A)"
hoelzl@41973
  1088
  unfolding open_extreal_def by auto
hoelzl@41973
  1089
hoelzl@41973
  1090
lemma open_MInfty: "open A ==> (-\<infinity>) : A ==> (EX x. {..<extreal x} <= A)"
hoelzl@41973
  1091
  unfolding open_extreal_def by auto
hoelzl@41973
  1092
hoelzl@41973
  1093
lemma open_PInfty2: assumes "open A" "\<infinity> : A" obtains x where "{extreal x<..} <= A"
hoelzl@41973
  1094
  using open_PInfty[OF assms] by auto
hoelzl@41973
  1095
hoelzl@41973
  1096
lemma open_MInfty2: assumes "open A" "(-\<infinity>) : A" obtains x where "{..<extreal x} <= A"
hoelzl@41973
  1097
  using open_MInfty[OF assms] by auto
hoelzl@41973
  1098
hoelzl@41973
  1099
lemma extreal_openE: assumes "open A" obtains A' x y where
hoelzl@41973
  1100
  "open A'" "extreal ` A' = A - {\<infinity>, (-\<infinity>)}"
hoelzl@41973
  1101
  "\<infinity> : A ==> {extreal x<..} <= A"
hoelzl@41973
  1102
  "(-\<infinity>) : A ==> {..<extreal y} <= A"
hoelzl@41973
  1103
  using assms open_extreal_def by auto
hoelzl@41973
  1104
hoelzl@41973
  1105
instance
hoelzl@41973
  1106
proof
hoelzl@41973
  1107
  let ?U = "UNIV::extreal set"
hoelzl@41973
  1108
  show "open ?U" unfolding open_extreal_def
hoelzl@41973
  1109
    by (auto intro!: exI[of _ "UNIV"] exI[of _ 0])
hoelzl@41973
  1110
next
hoelzl@41973
  1111
  fix S T::"extreal set" assume "open S" and "open T"
hoelzl@41973
  1112
  from `open S`[THEN extreal_openE] guess S' xS yS . note S' = this
hoelzl@41973
  1113
  from `open T`[THEN extreal_openE] guess T' xT yT . note T' = this
hoelzl@41973
  1114
hoelzl@41973
  1115
  have "extreal ` (S' Int T') = (extreal ` S') Int (extreal ` T')" by auto
hoelzl@41973
  1116
  also have "... = S Int T - {\<infinity>, (-\<infinity>)}" using S' T' by auto
hoelzl@41973
  1117
  finally have "extreal ` (S' Int T') =  S Int T - {\<infinity>, (-\<infinity>)}" by auto
hoelzl@41973
  1118
  moreover have "open (S' Int T')" using S' T' by auto
hoelzl@41973
  1119
  moreover
hoelzl@41973
  1120
  { assume a: "\<infinity> : S Int T"
hoelzl@41973
  1121
    hence "EX x. {extreal x<..} <= S Int T"
hoelzl@41973
  1122
    apply(rule_tac x="max xS xT" in exI)
hoelzl@41973
  1123
    proof-
hoelzl@41973
  1124
    { fix x assume *: "extreal (max xS xT) < x"
hoelzl@41973
  1125
      hence "x : S Int T" apply (cases x, auto simp: max_def split: split_if_asm)
hoelzl@41973
  1126
      using a S' T' by auto
hoelzl@41973
  1127
    } thus "{extreal (max xS xT)<..} <= S Int T" by auto
hoelzl@41973
  1128
    qed }
hoelzl@41973
  1129
  moreover
hoelzl@41973
  1130
  { assume a: "(-\<infinity>) : S Int T"
hoelzl@41973
  1131
    hence "EX x. {..<extreal x} <= S Int T"
hoelzl@41973
  1132
    apply(rule_tac x="min yS yT" in exI)
hoelzl@41973
  1133
    proof-
hoelzl@41973
  1134
    { fix x assume *: "extreal (min yS yT) > x"
hoelzl@41973
  1135
      hence "x<extreal yS & x<extreal yT" by (cases x) auto
hoelzl@41973
  1136
      hence "x : S Int T" using a S' T' by auto
hoelzl@41973
  1137
    } thus "{..<extreal (min yS yT)} <= S Int T" by auto
hoelzl@41973
  1138
    qed }
hoelzl@41973
  1139
  ultimately show "open (S Int T)" unfolding open_extreal_def by auto
hoelzl@41973
  1140
next
hoelzl@41973
  1141
  fix K assume openK: "ALL S : K. open (S:: extreal set)"
hoelzl@41973
  1142
  hence "ALL S:K. EX T. open T & extreal ` T = S - {\<infinity>, (-\<infinity>)}" by (auto simp: open_extreal_def)
hoelzl@41973
  1143
  from bchoice[OF this] guess T .. note T = this[rule_format]
hoelzl@41973
  1144
hoelzl@41973
  1145
  show "open (Union K)" unfolding open_extreal_def
hoelzl@41973
  1146
  proof (safe intro!: exI[of _ "Union (T ` K)"])
hoelzl@41973
  1147
    fix x S assume "x : T S" "S : K"
hoelzl@41973
  1148
    with T[OF `S : K`] show "extreal x : Union K" by auto
hoelzl@41973
  1149
  next
hoelzl@41973
  1150
    fix x S assume x: "x ~: extreal ` (Union (T ` K))" "S : K" "x : S" "x ~= \<infinity>"
hoelzl@41973
  1151
    hence "x ~: extreal ` (T S)"
hoelzl@41973
  1152
      by (auto simp: image_UN UN_simps[symmetric] simp del: UN_simps)
hoelzl@41973
  1153
    thus "x=(-\<infinity>)" using T[OF `S : K`] `x : S` `x ~= \<infinity>` by auto
hoelzl@41973
  1154
  next
hoelzl@41973
  1155
    fix S assume "\<infinity> : S" "S : K"
hoelzl@41973
  1156
    from openK[rule_format, OF `S : K`, THEN extreal_openE] guess S' x .
hoelzl@41973
  1157
    from this(3) `\<infinity> : S`
hoelzl@41973
  1158
    show "EX x. {extreal x<..} <= Union K"
hoelzl@41973
  1159
      by (auto intro!: exI[of _ x] bexI[OF _ `S : K`])
hoelzl@41973
  1160
  next
hoelzl@41973
  1161
    fix S assume "(-\<infinity>) : S" "S : K"
hoelzl@41973
  1162
    from openK[rule_format, OF `S : K`, THEN extreal_openE] guess S' x y .
hoelzl@41973
  1163
    from this(4) `(-\<infinity>) : S`
hoelzl@41973
  1164
    show "EX y. {..<extreal y} <= Union K"
hoelzl@41973
  1165
      by (auto intro!: exI[of _ y] bexI[OF _ `S : K`])
hoelzl@41973
  1166
  next
hoelzl@41973
  1167
    from T[THEN conjunct1] show "open (Union (T`K))" by auto
hoelzl@41973
  1168
  qed auto
hoelzl@41973
  1169
qed
hoelzl@41973
  1170
end
hoelzl@41973
  1171
hoelzl@41973
  1172
lemma open_extreal_lessThan[simp]:
hoelzl@41973
  1173
  "open {..< a :: extreal}"
hoelzl@41973
  1174
proof (cases a)
hoelzl@41973
  1175
  case (real x)
hoelzl@41973
  1176
  then show ?thesis unfolding open_extreal_def
hoelzl@41973
  1177
  proof (safe intro!: exI[of _ "{..< x}"])
hoelzl@41973
  1178
    fix y assume "y < extreal x"
hoelzl@41973
  1179
    moreover assume "y ~: (extreal ` {..<x})"
hoelzl@41973
  1180
    ultimately have "y ~= extreal (real y)" using real by (cases y) auto
hoelzl@41973
  1181
    thus "y = (-\<infinity>)" apply (cases y) using `y < extreal x` by auto
hoelzl@41973
  1182
  qed auto
hoelzl@41973
  1183
qed (auto simp: open_extreal_def)
hoelzl@41973
  1184
hoelzl@41973
  1185
lemma open_extreal_greaterThan[simp]:
hoelzl@41973
  1186
  "open {a :: extreal <..}"
hoelzl@41973
  1187
proof (cases a)
hoelzl@41973
  1188
  case (real x)
hoelzl@41973
  1189
  then show ?thesis unfolding open_extreal_def
hoelzl@41973
  1190
  proof (safe intro!: exI[of _ "{x<..}"])
hoelzl@41973
  1191
    fix y assume "extreal x < y"
hoelzl@41973
  1192
    moreover assume "y ~: (extreal ` {x<..})"
hoelzl@41973
  1193
    moreover assume "y ~= \<infinity>"
hoelzl@41973
  1194
    ultimately have "y ~= extreal (real y)" using real by (cases y) auto
hoelzl@41973
  1195
    hence False apply (cases y) using `extreal x < y` `y ~= \<infinity>` by auto
hoelzl@41973
  1196
    thus "y = (-\<infinity>)" by auto
hoelzl@41973
  1197
  qed auto
hoelzl@41973
  1198
qed (auto simp: open_extreal_def)
hoelzl@41973
  1199
hoelzl@41973
  1200
lemma extreal_open_greaterThanLessThan[simp]: "open {a::extreal <..< b}"
hoelzl@41973
  1201
  unfolding greaterThanLessThan_def by auto
hoelzl@41973
  1202
hoelzl@41973
  1203
lemma closed_extreal_atLeast[simp, intro]: "closed {a :: extreal ..}"
hoelzl@41973
  1204
proof -
hoelzl@41973
  1205
  have "- {a ..} = {..< a}" by auto
hoelzl@41973
  1206
  then show "closed {a ..}"
hoelzl@41973
  1207
    unfolding closed_def using open_extreal_lessThan by auto
hoelzl@41973
  1208
qed
hoelzl@41973
  1209
hoelzl@41973
  1210
lemma closed_extreal_atMost[simp, intro]: "closed {.. b :: extreal}"
hoelzl@41973
  1211
proof -
hoelzl@41973
  1212
  have "- {.. b} = {b <..}" by auto
hoelzl@41973
  1213
  then show "closed {.. b}"
hoelzl@41973
  1214
    unfolding closed_def using open_extreal_greaterThan by auto
hoelzl@41973
  1215
qed
hoelzl@41973
  1216
hoelzl@41973
  1217
lemma closed_extreal_atLeastAtMost[simp, intro]:
hoelzl@41973
  1218
  shows "closed {a :: extreal .. b}"
hoelzl@41973
  1219
  unfolding atLeastAtMost_def by auto
hoelzl@41973
  1220
hoelzl@41973
  1221
lemma closed_extreal_singleton:
hoelzl@41973
  1222
  "closed {a :: extreal}"
hoelzl@41973
  1223
by (metis atLeastAtMost_singleton closed_extreal_atLeastAtMost)
hoelzl@41973
  1224
hoelzl@41973
  1225
lemma extreal_open_cont_interval:
hoelzl@41973
  1226
  assumes "open S" "x \<in> S" and "x \<noteq> \<infinity>" "x \<noteq> - \<infinity>"
hoelzl@41973
  1227
  obtains e where "e>0" "{x-e <..< x+e} \<subseteq> S"
hoelzl@41973
  1228
proof-
hoelzl@41973
  1229
  obtain m where m_def: "x = extreal m" using assms by (cases x) auto
hoelzl@41973
  1230
  obtain A where "open A" and A_def: "extreal ` A = S - {\<infinity>,(-\<infinity>)}"
hoelzl@41973
  1231
    using assms by (auto elim!: extreal_openE)
hoelzl@41973
  1232
  hence "m : A" using m_def assms by auto
hoelzl@41973
  1233
  from this obtain e where e_def: "e>0 & ball m e <= A"
hoelzl@41973
  1234
    using open_contains_ball[of A] `open A` by auto
hoelzl@41973
  1235
  moreover have "ball m e = {m-e <..< m+e}" unfolding ball_def dist_norm by auto
hoelzl@41973
  1236
  ultimately have *: "{m-e <..< m+e} <= A" using e_def by auto
hoelzl@41973
  1237
  { fix y assume y_def: "y:{x-extreal e <..< x+extreal e}"
hoelzl@41973
  1238
    from this obtain z where z_def: "y = extreal z" by (cases y) auto
hoelzl@41973
  1239
    hence "z:A" using y_def m_def * by auto
hoelzl@41973
  1240
    hence "y:S" using z_def A_def by auto
hoelzl@41973
  1241
  } hence "{x-extreal e <..< x+extreal e} <= S" by auto
hoelzl@41973
  1242
  thus thesis apply- apply(rule that[of "extreal e"]) using e_def by auto
hoelzl@41973
  1243
qed
hoelzl@41973
  1244
hoelzl@41973
  1245
lemma extreal_open_cont_interval2:
hoelzl@41973
  1246
  assumes "open S" "x \<in> S" and x: "x \<noteq> \<infinity>" "x \<noteq> -\<infinity>"
hoelzl@41973
  1247
  obtains a b where "a < x" "x < b" "{a <..< b} \<subseteq> S"
hoelzl@41973
  1248
proof-
hoelzl@41973
  1249
  guess e using extreal_open_cont_interval[OF assms] .
hoelzl@41973
  1250
  with that[of "x-e" "x+e"] extreal_between[OF x, of e]
hoelzl@41973
  1251
  show thesis by auto
hoelzl@41973
  1252
qed
hoelzl@41973
  1253
hoelzl@41973
  1254
lemma extreal_uminus_eq_reorder: "- a = b \<longleftrightarrow> a = (-b::extreal)" by auto
hoelzl@41973
  1255
hoelzl@41973
  1256
lemma extreal_uminus_less_reorder: "- a < b \<longleftrightarrow> -b < (a::extreal)"
hoelzl@41973
  1257
  by (subst (3) extreal_uminus_uminus[symmetric]) (simp only: extreal_minus_less_minus)
hoelzl@41973
  1258
hoelzl@41973
  1259
lemma extreal_uminus_le_reorder: "- a \<le> b \<longleftrightarrow> -b \<le> (a::extreal)"
hoelzl@41973
  1260
  by (subst (3) extreal_uminus_uminus[symmetric]) (simp only: extreal_minus_le_minus)
hoelzl@41973
  1261
hoelzl@41973
  1262
lemmas extreal_uminus_reorder =
hoelzl@41973
  1263
  extreal_uminus_eq_reorder extreal_uminus_less_reorder extreal_uminus_le_reorder
hoelzl@41973
  1264
hoelzl@41973
  1265
lemma extreal_open_uminus:
hoelzl@41973
  1266
  fixes S :: "extreal set"
hoelzl@41973
  1267
  assumes "open S"
hoelzl@41973
  1268
  shows "open (uminus ` S)"
hoelzl@41973
  1269
proof-
hoelzl@41973
  1270
  obtain T x y where T_def: "open T & extreal ` T = S - {\<infinity>, (-\<infinity>)} &
hoelzl@41973
  1271
     (\<infinity> : S --> {extreal x<..} <= S) & ((-\<infinity>) : S --> {..<extreal y} <= S)"
hoelzl@41973
  1272
     using assms extreal_openE[of S] by metis
hoelzl@41973
  1273
  have "extreal ` uminus ` T = uminus ` extreal ` T" apply auto
hoelzl@41973
  1274
     by (metis imageI extreal_uminus_uminus uminus_extreal.simps)
hoelzl@41973
  1275
  also have "...=uminus ` (S - {\<infinity>, (-\<infinity>)})" using T_def by auto
hoelzl@41973
  1276
  finally have "extreal ` uminus ` T = uminus ` S - {\<infinity>, (-\<infinity>)}" by (auto simp: extreal_uminus_reorder)
hoelzl@41973
  1277
  moreover have "open (uminus ` T)" using T_def open_negations[of T] by auto
hoelzl@41973
  1278
  ultimately have "EX T. open T & extreal ` T = uminus ` S - {\<infinity>, (-\<infinity>)}" by auto
hoelzl@41973
  1279
  moreover
hoelzl@41973
  1280
  { assume "\<infinity>: uminus ` S"
hoelzl@41973
  1281
    hence "(-\<infinity>) : S" by (metis image_iff extreal_uminus_uminus)
hoelzl@41973
  1282
    hence "uminus ` {..<extreal y} <= uminus ` S" using T_def by (intro image_mono) auto
hoelzl@41973
  1283
    hence "EX x. {extreal x<..} <= uminus ` S" using extreal_uminus_lessThan by auto
hoelzl@41973
  1284
  } moreover
hoelzl@41973
  1285
  { assume "(-\<infinity>): uminus ` S"
hoelzl@41973
  1286
    hence "\<infinity> : S" by (metis image_iff extreal_uminus_uminus)
hoelzl@41973
  1287
    hence "uminus ` {extreal x<..} <= uminus ` S" using T_def by (intro image_mono) auto
hoelzl@41973
  1288
    hence "EX y. {..<extreal y} <= uminus ` S" using extreal_uminus_greaterThan by auto
hoelzl@41973
  1289
  }
hoelzl@41973
  1290
  ultimately show ?thesis unfolding open_extreal_def by auto
hoelzl@41973
  1291
qed
hoelzl@41973
  1292
hoelzl@41973
  1293
lemma extreal_uminus_complement:
hoelzl@41973
  1294
  fixes S :: "extreal set"
hoelzl@41973
  1295
  shows "(uminus ` (- S)) = (- uminus ` S)"
hoelzl@41973
  1296
proof-
hoelzl@41973
  1297
{ fix x
hoelzl@41973
  1298
  have "x:uminus ` (- S) <-> -x:(- S)" by (metis image_iff extreal_uminus_uminus)
hoelzl@41973
  1299
  also have "... <-> x:(- uminus ` S)"
hoelzl@41973
  1300
     by (metis ComplI Compl_iff image_eqI extreal_uminus_uminus extreal_minus_minus_image)
hoelzl@41973
  1301
  finally have "x:uminus ` (- S) <-> x:(- uminus ` S)" by auto
hoelzl@41973
  1302
} thus ?thesis by auto
hoelzl@41973
  1303
qed
hoelzl@41973
  1304
hoelzl@41973
  1305
lemma extreal_closed_uminus:
hoelzl@41973
  1306
  fixes S :: "extreal set"
hoelzl@41973
  1307
  assumes "closed S"
hoelzl@41973
  1308
  shows "closed (uminus ` S)"
hoelzl@41973
  1309
using assms unfolding closed_def
hoelzl@41973
  1310
using extreal_open_uminus[of "- S"] extreal_uminus_complement by auto
hoelzl@41973
  1311
hoelzl@41973
  1312
hoelzl@41973
  1313
lemma not_open_extreal_singleton:
hoelzl@41973
  1314
  "~(open {a :: extreal})"
hoelzl@41973
  1315
proof(rule ccontr)
hoelzl@41973
  1316
  assume "~ ~ open {a}" hence a: "open {a}" by auto
hoelzl@41973
  1317
  { assume "a=(-\<infinity>)"
hoelzl@41973
  1318
    then obtain y where "{..<extreal y} <= {a}" using a open_MInfty2[of "{a}"] by auto
hoelzl@41973
  1319
    hence "extreal(y - 1):{a}" apply (subst subsetD[of "{..<extreal y}"]) by auto
hoelzl@41973
  1320
    hence False using `a=(-\<infinity>)` by auto
hoelzl@41973
  1321
  } moreover
hoelzl@41973
  1322
  { assume "a=\<infinity>"
hoelzl@41973
  1323
    then obtain y where "{extreal y<..} <= {a}" using a open_PInfty2[of "{a}"] by auto
hoelzl@41973
  1324
    hence "extreal(y+1):{a}" apply (subst subsetD[of "{extreal y<..}"]) by auto
hoelzl@41973
  1325
    hence False using `a=\<infinity>` by auto
hoelzl@41973
  1326
  } moreover
hoelzl@41973
  1327
  { assume fin: "a~=(-\<infinity>)" "a~=\<infinity>"
hoelzl@41973
  1328
    from extreal_open_cont_interval[OF a singletonI this(2,1)] guess e . note e = this
hoelzl@41973
  1329
    then obtain b where b_def: "a<b & b<a+e"
hoelzl@41973
  1330
      using fin extreal_between extreal_dense[of a "a+e"] by auto
hoelzl@41973
  1331
    then have "b: {a-e <..< a+e}" using fin extreal_between[of a e] e by auto
hoelzl@41973
  1332
    then have False using b_def e by auto
hoelzl@41973
  1333
  } ultimately show False by auto
hoelzl@41973
  1334
qed
hoelzl@41973
  1335
hoelzl@41973
  1336
lemma extreal_closed_contains_Inf:
hoelzl@41973
  1337
  fixes S :: "extreal set"
hoelzl@41973
  1338
  assumes "closed S" "S ~= {}"
hoelzl@41973
  1339
  shows "Inf S : S"
hoelzl@41973
  1340
proof(rule ccontr)
hoelzl@41973
  1341
assume "~(Inf S:S)" hence a: "open (-S)" "Inf S:(- S)" using assms by auto
hoelzl@41973
  1342
{ assume minf: "Inf S=(-\<infinity>)" hence "(-\<infinity>) : - S" using a by auto
hoelzl@41973
  1343
  then obtain y where "{..<extreal y} <= (-S)" using a open_MInfty2[of "- S"] by auto
hoelzl@41973
  1344
  hence "extreal y <= Inf S" by (metis Compl_anti_mono Compl_lessThan atLeast_iff
hoelzl@41973
  1345
     complete_lattice_class.Inf_greatest double_complement set_rev_mp)
hoelzl@41973
  1346
  hence False using minf by auto
hoelzl@41973
  1347
} moreover
hoelzl@41973
  1348
{ assume pinf: "Inf S=\<infinity>" hence "S={\<infinity>}" by (metis Inf_eq_PInfty assms(2))
hoelzl@41973
  1349
  hence False by (metis `Inf S ~: S` insert_code mem_def pinf)
hoelzl@41973
  1350
} moreover
hoelzl@41973
  1351
{ assume fin: "Inf S ~= \<infinity>" "Inf S ~= (-\<infinity>)"
hoelzl@41973
  1352
  from extreal_open_cont_interval[OF a this] guess e . note e = this
hoelzl@41973
  1353
  { fix x assume "x:S" hence "x>=Inf S" by (rule complete_lattice_class.Inf_lower)
hoelzl@41973
  1354
    hence *: "x>Inf S-e" using e by (metis fin extreal_between(1) order_less_le_trans)
hoelzl@41973
  1355
    { assume "x<Inf S+e" hence "x:{Inf S-e <..< Inf S+e}" using * by auto
hoelzl@41973
  1356
      hence False using e `x:S` by auto
hoelzl@41973
  1357
    } hence "x>=Inf S+e" by (metis linorder_le_less_linear)
hoelzl@41973
  1358
  } hence "Inf S + e <= Inf S" by (metis le_Inf_iff)
hoelzl@41973
  1359
  hence False by (metis calculation(1) calculation(2) e extreal_between(2) leD)
hoelzl@41973
  1360
} ultimately show False by auto
hoelzl@41973
  1361
qed
hoelzl@41973
  1362
hoelzl@41973
  1363
lemma extreal_closed_contains_Sup:
hoelzl@41973
  1364
  fixes S :: "extreal set"
hoelzl@41973
  1365
  assumes "closed S" "S ~= {}"
hoelzl@41973
  1366
  shows "Sup S : S"
hoelzl@41973
  1367
proof-
hoelzl@41973
  1368
  have "closed (uminus ` S)" by (metis assms(1) extreal_closed_uminus)
hoelzl@41973
  1369
  hence "Inf (uminus ` S) : uminus ` S" using assms extreal_closed_contains_Inf[of "uminus ` S"] by auto
hoelzl@41973
  1370
  hence "- Sup S : uminus ` S" using extreal_Sup_uminus_image_eq[of "uminus ` S"] by (auto simp: image_image)
hoelzl@41973
  1371
  thus ?thesis by (metis imageI extreal_uminus_uminus extreal_minus_minus_image)
hoelzl@41973
  1372
qed
hoelzl@41973
  1373
hoelzl@41973
  1374
lemma extreal_open_closed_aux:
hoelzl@41973
  1375
  fixes S :: "extreal set"
hoelzl@41973
  1376
  assumes "open S" "closed S"
hoelzl@41973
  1377
  assumes S: "(-\<infinity>) ~: S"
hoelzl@41973
  1378
  shows "S = {}"
hoelzl@41973
  1379
proof(rule ccontr)
hoelzl@41973
  1380
  assume "S ~= {}"
hoelzl@41973
  1381
  hence *: "(Inf S):S" by (metis assms(2) extreal_closed_contains_Inf)
hoelzl@41973
  1382
  { assume "Inf S=(-\<infinity>)" hence False using * assms(3) by auto }
hoelzl@41973
  1383
  moreover
hoelzl@41973
  1384
  { assume "Inf S=\<infinity>" hence "S={\<infinity>}" by (metis Inf_eq_PInfty `S ~= {}`)
hoelzl@41973
  1385
    hence False by (metis assms(1) not_open_extreal_singleton) }
hoelzl@41973
  1386
  moreover
hoelzl@41973
  1387
  { assume fin: "~(Inf S=\<infinity>)" "~(Inf S=(-\<infinity>))"
hoelzl@41973
  1388
    from extreal_open_cont_interval[OF assms(1) * fin] guess e . note e = this
hoelzl@41973
  1389
    then obtain b where b_def: "Inf S-e<b & b<Inf S"
hoelzl@41973
  1390
      using fin extreal_between[of "Inf S" e] extreal_dense[of "Inf S-e"] by auto
hoelzl@41973
  1391
    hence "b: {Inf S-e <..< Inf S+e}" using e fin extreal_between[of "Inf S" e] by auto
hoelzl@41973
  1392
    hence "b:S" using e by auto
hoelzl@41973
  1393
    hence False using b_def by (metis complete_lattice_class.Inf_lower leD)
hoelzl@41973
  1394
  } ultimately show False by auto
hoelzl@41973
  1395
qed
hoelzl@41973
  1396
hoelzl@41973
  1397
hoelzl@41973
  1398
lemma extreal_open_closed:
hoelzl@41973
  1399
  fixes S :: "extreal set"
hoelzl@41973
  1400
  shows "(open S & closed S) <-> (S = {} | S = UNIV)"
hoelzl@41973
  1401
proof-
hoelzl@41973
  1402
{ assume lhs: "open S & closed S"
hoelzl@41973
  1403
  { assume "(-\<infinity>) ~: S" hence "S={}" using lhs extreal_open_closed_aux by auto }
hoelzl@41973
  1404
  moreover
hoelzl@41973
  1405
  { assume "(-\<infinity>) : S" hence "(- S)={}" using lhs extreal_open_closed_aux[of "-S"] by auto }
hoelzl@41973
  1406
  ultimately have "S = {} | S = UNIV" by auto
hoelzl@41973
  1407
} thus ?thesis by auto
hoelzl@41973
  1408
qed
hoelzl@41973
  1409
hoelzl@41973
  1410
hoelzl@41973
  1411
lemma extreal_le_epsilon:
hoelzl@41973
  1412
  fixes x y :: extreal
hoelzl@41973
  1413
  assumes "ALL e. 0 < e --> x <= y + e"
hoelzl@41973
  1414
  shows "x <= y"
hoelzl@41973
  1415
proof-
hoelzl@41973
  1416
{ assume a: "EX r. y = extreal r"
hoelzl@41973
  1417
  from this obtain r where r_def: "y = extreal r" by auto
hoelzl@41973
  1418
  { assume "x=(-\<infinity>)" hence ?thesis by auto }
hoelzl@41973
  1419
  moreover
hoelzl@41973
  1420
  { assume "~(x=(-\<infinity>))"
hoelzl@41973
  1421
    from this obtain p where p_def: "x = extreal p"
hoelzl@41973
  1422
    using a assms[rule_format, of 1] by (cases x) auto
hoelzl@41973
  1423
    { fix e have "0 < e --> p <= r + e"
hoelzl@41973
  1424
      using assms[rule_format, of "extreal e"] p_def r_def by auto }
hoelzl@41973
  1425
    hence "p <= r" apply (subst field_le_epsilon) by auto
hoelzl@41973
  1426
    hence ?thesis using r_def p_def by auto
hoelzl@41973
  1427
  } ultimately have ?thesis by blast
hoelzl@41973
  1428
}
hoelzl@41973
  1429
moreover
hoelzl@41973
  1430
{ assume "y=(-\<infinity>) | y=\<infinity>" hence ?thesis
hoelzl@41973
  1431
    using assms[rule_format, of 1] by (cases x) auto
hoelzl@41973
  1432
} ultimately show ?thesis by (cases y) auto
hoelzl@41973
  1433
qed
hoelzl@41973
  1434
hoelzl@41973
  1435
hoelzl@41973
  1436
lemma extreal_le_epsilon2:
hoelzl@41973
  1437
  fixes x y :: extreal
hoelzl@41973
  1438
  assumes "ALL e. 0 < e --> x <= y + extreal e"
hoelzl@41973
  1439
  shows "x <= y"
hoelzl@41973
  1440
proof-
hoelzl@41973
  1441
{ fix e :: extreal assume "e>0"
hoelzl@41973
  1442
  { assume "e=\<infinity>" hence "x<=y+e" by auto }
hoelzl@41973
  1443
  moreover
hoelzl@41973
  1444
  { assume "e~=\<infinity>"
hoelzl@41973
  1445
    from this obtain r where "e = extreal r" using `e>0` apply (cases e) by auto
hoelzl@41973
  1446
    hence "x<=y+e" using assms[rule_format, of r] `e>0` by auto
hoelzl@41973
  1447
  } ultimately have "x<=y+e" by blast
hoelzl@41973
  1448
} from this show ?thesis using extreal_le_epsilon by auto
hoelzl@41973
  1449
qed
hoelzl@41973
  1450
hoelzl@41973
  1451
lemma extreal_le_real:
hoelzl@41973
  1452
  fixes x y :: extreal
hoelzl@41973
  1453
  assumes "ALL z. x <= extreal z --> y <= extreal z"
hoelzl@41973
  1454
  shows "y <= x"
hoelzl@41973
  1455
by (metis assms extreal.exhaust extreal_bot extreal_less_eq(1)
hoelzl@41973
  1456
          extreal_less_eq(2) order_refl uminus_extreal.simps(2))
hoelzl@41973
  1457
hoelzl@41973
  1458
lemma extreal_le_extreal:
hoelzl@41973
  1459
  fixes x y :: extreal
hoelzl@41973
  1460
  assumes "\<And>B. B < x \<Longrightarrow> B <= y"
hoelzl@41973
  1461
  shows "x <= y"
hoelzl@41973
  1462
by (metis assms extreal_dense leD linorder_le_less_linear)
hoelzl@41973
  1463
hoelzl@41973
  1464
hoelzl@41973
  1465
lemma extreal_ge_extreal:
hoelzl@41973
  1466
  fixes x y :: extreal
hoelzl@41973
  1467
  assumes "ALL B. B>x --> B >= y"
hoelzl@41973
  1468
  shows "x >= y"
hoelzl@41973
  1469
by (metis assms extreal_dense leD linorder_le_less_linear)
hoelzl@41973
  1470
hoelzl@41973
  1471
hoelzl@41973
  1472
instance extreal :: t2_space
hoelzl@41973
  1473
proof
hoelzl@41973
  1474
  fix x y :: extreal assume "x ~= y"
hoelzl@41973
  1475
  let "?P x (y::extreal)" = "EX U V. open U & open V & x : U & y : V & U Int V = {}"
hoelzl@41973
  1476
hoelzl@41973
  1477
  { fix x y :: extreal assume "x < y"
hoelzl@41973
  1478
    from extreal_dense[OF this] obtain z where z: "x < z" "z < y" by auto
hoelzl@41973
  1479
    have "?P x y"
hoelzl@41973
  1480
      apply (rule exI[of _ "{..<z}"])
hoelzl@41973
  1481
      apply (rule exI[of _ "{z<..}"])
hoelzl@41973
  1482
      using z by auto }
hoelzl@41973
  1483
  note * = this
hoelzl@41973
  1484
hoelzl@41973
  1485
  from `x ~= y`
hoelzl@41973
  1486
  show "EX U V. open U & open V & x : U & y : V & U Int V = {}"
hoelzl@41973
  1487
  proof (cases rule: linorder_cases)
hoelzl@41973
  1488
    assume "x = y" with `x ~= y` show ?thesis by simp
hoelzl@41973
  1489
  next assume "x < y" from *[OF this] show ?thesis by auto
hoelzl@41973
  1490
  next assume "y < x" from *[OF this] show ?thesis by auto
hoelzl@41973
  1491
  qed
hoelzl@41973
  1492
qed
hoelzl@41973
  1493
hoelzl@41973
  1494
lemma open_extreal: assumes "open S" shows "open (extreal ` S)"
hoelzl@41973
  1495
  unfolding open_extreal_def apply(rule,rule,rule,rule assms) by auto
hoelzl@41973
  1496
hoelzl@41973
  1497
lemma open_real_of_extreal:
hoelzl@41973
  1498
  fixes S :: "extreal set" assumes "open S"
hoelzl@41973
  1499
  shows "open (real ` (S - {\<infinity>, -\<infinity>}))"
hoelzl@41973
  1500
proof -
hoelzl@41973
  1501
  from `open S` obtain T where T: "open T" "S - {\<infinity>, -\<infinity>} = extreal ` T"
hoelzl@41973
  1502
    unfolding open_extreal_def by auto
hoelzl@41973
  1503
  show ?thesis using T by (simp add: image_image)
hoelzl@41973
  1504
qed
hoelzl@41973
  1505
hoelzl@41973
  1506
subsubsection {* Convergent sequences *}
hoelzl@41973
  1507
hoelzl@41973
  1508
lemma inj_extreal[simp, intro]: "inj_on extreal A" by (auto intro: inj_onI)
hoelzl@41973
  1509
hoelzl@41973
  1510
lemma lim_extreal[simp]:
hoelzl@41973
  1511
  "((\<lambda>n. extreal (f n)) ---> extreal x) net \<longleftrightarrow> (f ---> x) net" (is "?l = ?r")
hoelzl@41973
  1512
proof (intro iffI topological_tendstoI)
hoelzl@41973
  1513
  fix S assume "?l" "open S" "x \<in> S"
hoelzl@41973
  1514
  then show "eventually (\<lambda>x. f x \<in> S) net"
hoelzl@41973
  1515
    using `?l`[THEN topological_tendstoD, OF open_extreal, OF `open S`]
hoelzl@41973
  1516
    by (simp add: inj_image_mem_iff)
hoelzl@41973
  1517
next
hoelzl@41973
  1518
  fix S assume "?r" "open S" "extreal x \<in> S"
hoelzl@41973
  1519
  have *: "\<And>x. x \<in> real ` (S - {\<infinity>, - \<infinity>}) \<longleftrightarrow> extreal x \<in> S"
hoelzl@41973
  1520
    apply (safe intro!: rev_image_eqI)
hoelzl@41973
  1521
    by (case_tac xa) auto
hoelzl@41973
  1522
  show "eventually (\<lambda>x. extreal (f x) \<in> S) net"
hoelzl@41973
  1523
    using `?r`[THEN topological_tendstoD, OF open_real_of_extreal, OF `open S`]
hoelzl@41973
  1524
    using `extreal x \<in> S` by (simp add: *)
hoelzl@41973
  1525
qed
hoelzl@41973
  1526
hoelzl@41973
  1527
lemma lim_real_of_extreal[simp]:
hoelzl@41973
  1528
  assumes lim: "(f ---> extreal x) net"
hoelzl@41973
  1529
  shows "((\<lambda>x. real (f x)) ---> x) net"
hoelzl@41973
  1530
proof (intro topological_tendstoI)
hoelzl@41973
  1531
  fix S assume "open S" "x \<in> S"
hoelzl@41973
  1532
  then have S: "open S" "extreal x \<in> extreal ` S"
hoelzl@41973
  1533
    by (simp_all add: inj_image_mem_iff)
hoelzl@41973
  1534
  have "\<forall>x. f x \<in> extreal ` S \<longrightarrow> real (f x) \<in> S" by auto
hoelzl@41973
  1535
  from this lim[THEN topological_tendstoD, OF open_extreal, OF S]
hoelzl@41973
  1536
  show "eventually (\<lambda>x. real (f x) \<in> S) net"
hoelzl@41973
  1537
    by (rule eventually_mono)
hoelzl@41973
  1538
qed
hoelzl@41973
  1539
hoelzl@41973
  1540
lemma Lim_PInfty: "f ----> \<infinity> <-> (ALL B. EX N. ALL n>=N. f n >= extreal B)" (is "?l = ?r")
hoelzl@41973
  1541
proof assume ?r show ?l apply(rule topological_tendstoI)
hoelzl@41973
  1542
    unfolding eventually_sequentially
hoelzl@41973
  1543
  proof- fix S assume "open S" "\<infinity> : S"
hoelzl@41973
  1544
    from open_PInfty[OF this] guess B .. note B=this
hoelzl@41973
  1545
    from `?r`[rule_format,of "B+1"] guess N .. note N=this
hoelzl@41973
  1546
    show "EX N. ALL n>=N. f n : S" apply(rule_tac x=N in exI)
hoelzl@41973
  1547
    proof safe case goal1
hoelzl@41973
  1548
      have "extreal B < extreal (B + 1)" by auto
hoelzl@41973
  1549
      also have "... <= f n" using goal1 N by auto
hoelzl@41973
  1550
      finally show ?case using B by fastsimp
hoelzl@41973
  1551
    qed
hoelzl@41973
  1552
  qed
hoelzl@41973
  1553
next assume ?l show ?r
hoelzl@41973
  1554
  proof fix B::real have "open {extreal B<..}" "\<infinity> : {extreal B<..}" by auto
hoelzl@41973
  1555
    from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially]
hoelzl@41973
  1556
    guess N .. note N=this
hoelzl@41973
  1557
    show "EX N. ALL n>=N. extreal B <= f n" apply(rule_tac x=N in exI) using N by auto
hoelzl@41973
  1558
  qed
hoelzl@41973
  1559
qed
hoelzl@41973
  1560
hoelzl@41973
  1561
hoelzl@41973
  1562
lemma Lim_MInfty: "f ----> (-\<infinity>) <-> (ALL B. EX N. ALL n>=N. f n <= extreal B)" (is "?l = ?r")
hoelzl@41973
  1563
proof assume ?r show ?l apply(rule topological_tendstoI)
hoelzl@41973
  1564
    unfolding eventually_sequentially
hoelzl@41973
  1565
  proof- fix S assume "open S" "(-\<infinity>) : S"
hoelzl@41973
  1566
    from open_MInfty[OF this] guess B .. note B=this
hoelzl@41973
  1567
    from `?r`[rule_format,of "B-(1::real)"] guess N .. note N=this
hoelzl@41973
  1568
    show "EX N. ALL n>=N. f n : S" apply(rule_tac x=N in exI)
hoelzl@41973
  1569
    proof safe case goal1
hoelzl@41973
  1570
      have "extreal (B - 1) >= f n" using goal1 N by auto
hoelzl@41973
  1571
      also have "... < extreal B" by auto
hoelzl@41973
  1572
      finally show ?case using B by fastsimp
hoelzl@41973
  1573
    qed
hoelzl@41973
  1574
  qed
hoelzl@41973
  1575
next assume ?l show ?r
hoelzl@41973
  1576
  proof fix B::real have "open {..<extreal B}" "(-\<infinity>) : {..<extreal B}" by auto
hoelzl@41973
  1577
    from topological_tendstoD[OF `?l` this,unfolded eventually_sequentially]
hoelzl@41973
  1578
    guess N .. note N=this
hoelzl@41973
  1579
    show "EX N. ALL n>=N. extreal B >= f n" apply(rule_tac x=N in exI) using N by auto
hoelzl@41973
  1580
  qed
hoelzl@41973
  1581
qed
hoelzl@41973
  1582
hoelzl@41973
  1583
hoelzl@41973
  1584
lemma Lim_bounded_PInfty: assumes lim:"f ----> l" and "!!n. f n <= extreal B" shows "l ~= \<infinity>"
hoelzl@41973
  1585
proof(rule ccontr,unfold not_not) let ?B = "B + 1" assume as:"l=\<infinity>"
hoelzl@41973
  1586
  from lim[unfolded this Lim_PInfty,rule_format,of "?B"]
hoelzl@41973
  1587
  guess N .. note N=this[rule_format,OF le_refl]
hoelzl@41973
  1588
  hence "extreal ?B <= extreal B" using assms(2)[of N] by(rule order_trans)
hoelzl@41973
  1589
  hence "extreal ?B < extreal ?B" apply (rule le_less_trans) by auto
hoelzl@41973
  1590
  thus False by auto
hoelzl@41973
  1591
qed
hoelzl@41973
  1592
hoelzl@41973
  1593
hoelzl@41973
  1594
lemma Lim_bounded_MInfty: assumes lim:"f ----> l" and "!!n. f n >= extreal B" shows "l ~= (-\<infinity>)"
hoelzl@41973
  1595
proof(rule ccontr,unfold not_not) let ?B = "B - 1" assume as:"l=(-\<infinity>)"
hoelzl@41973
  1596
  from lim[unfolded this Lim_MInfty,rule_format,of "?B"]
hoelzl@41973
  1597
  guess N .. note N=this[rule_format,OF le_refl]
hoelzl@41973
  1598
  hence "extreal B <= extreal ?B" using assms(2)[of N] order_trans[of "extreal B" "f N" "extreal(B - 1)"] by blast
hoelzl@41973
  1599
  thus False by auto
hoelzl@41973
  1600
qed
hoelzl@41973
  1601
hoelzl@41973
  1602
hoelzl@41973
  1603
lemma tendsto_explicit:
hoelzl@41973
  1604
  "f ----> f0 <-> (ALL S. open S --> f0 : S --> (EX N. ALL n>=N. f n : S))"
hoelzl@41973
  1605
  unfolding tendsto_def eventually_sequentially by auto
hoelzl@41973
  1606
hoelzl@41973
  1607
hoelzl@41973
  1608
lemma tendsto_obtains_N:
hoelzl@41973
  1609
  assumes "f ----> f0"
hoelzl@41973
  1610
  assumes "open S" "f0 : S"
hoelzl@41973
  1611
  obtains N where "ALL n>=N. f n : S"
hoelzl@41973
  1612
  using tendsto_explicit[of f f0] assms by auto
hoelzl@41973
  1613
hoelzl@41973
  1614
hoelzl@41973
  1615
lemma tail_same_limit:
hoelzl@41973
  1616
  fixes X Y N
hoelzl@41973
  1617
  assumes "X ----> L" "ALL n>=N. X n = Y n"
hoelzl@41973
  1618
  shows "Y ----> L"
hoelzl@41973
  1619
proof-
hoelzl@41973
  1620
{ fix S assume "open S" and "L:S"
hoelzl@41973
  1621
  from this obtain N1 where "ALL n>=N1. X n : S"
hoelzl@41973
  1622
     using assms unfolding tendsto_def eventually_sequentially by auto
hoelzl@41973
  1623
  hence "ALL n>=max N N1. Y n : S" using assms by auto
hoelzl@41973
  1624
  hence "EX N. ALL n>=N. Y n : S" apply(rule_tac x="max N N1" in exI) by auto
hoelzl@41973
  1625
}
hoelzl@41973
  1626
thus ?thesis using tendsto_explicit by auto
hoelzl@41973
  1627
qed
hoelzl@41973
  1628
hoelzl@41973
  1629
hoelzl@41973
  1630
lemma Lim_bounded_PInfty2:
hoelzl@41973
  1631
assumes lim:"f ----> l" and "ALL n>=N. f n <= extreal B"
hoelzl@41973
  1632
shows "l ~= \<infinity>"
hoelzl@41973
  1633
proof-
hoelzl@41973
  1634
  def g == "(%n. if n>=N then f n else extreal B)"
hoelzl@41973
  1635
  hence "g ----> l" using tail_same_limit[of f l N g] lim by auto
hoelzl@41973
  1636
  moreover have "!!n. g n <= extreal B" using g_def assms by auto
hoelzl@41973
  1637
  ultimately show ?thesis using  Lim_bounded_PInfty by auto
hoelzl@41973
  1638
qed
hoelzl@41973
  1639
hoelzl@41973
  1640
lemma Lim_bounded_extreal:
hoelzl@41973
  1641
  assumes lim:"f ----> (l :: extreal)"
hoelzl@41973
  1642
  and "ALL n>=M. f n <= C"
hoelzl@41973
  1643
  shows "l<=C"
hoelzl@41973
  1644
proof-
hoelzl@41973
  1645
{ assume "l=(-\<infinity>)" hence ?thesis by auto }
hoelzl@41973
  1646
moreover
hoelzl@41973
  1647
{ assume "~(l=(-\<infinity>))"
hoelzl@41973
  1648
  { assume "C=\<infinity>" hence ?thesis by auto }
hoelzl@41973
  1649
  moreover
hoelzl@41973
  1650
  { assume "C=(-\<infinity>)" hence "ALL n>=M. f n = (-\<infinity>)" using assms by auto
hoelzl@41973
  1651
    hence "l=(-\<infinity>)" using assms
hoelzl@41973
  1652
       Lim_unique[OF trivial_limit_sequentially] tail_same_limit[of "\<lambda>n. -\<infinity>" "-\<infinity>" M f, OF tendsto_const] by auto
hoelzl@41973
  1653
    hence ?thesis by auto }
hoelzl@41973
  1654
  moreover
hoelzl@41973
  1655
  { assume "EX B. C = extreal B"
hoelzl@41973
  1656
    from this obtain B where B_def: "C=extreal B" by auto
hoelzl@41973
  1657
    hence "~(l=\<infinity>)" using Lim_bounded_PInfty2 assms by auto
hoelzl@41973
  1658
    from this obtain m where m_def: "extreal m=l" using `~(l=(-\<infinity>))` by (cases l) auto
hoelzl@41973
  1659
    from this obtain N where N_def: "ALL n>=N. f n : {extreal(m - 1) <..< extreal(m+1)}"
hoelzl@41973
  1660
       apply (subst tendsto_obtains_N[of f l "{extreal(m - 1) <..< extreal(m+1)}"]) using assms by auto
hoelzl@41973
  1661
    { fix n assume "n>=N"
hoelzl@41973
  1662
      hence "EX r. extreal r = f n" using N_def by (cases "f n") auto
hoelzl@41973
  1663
    } from this obtain g where g_def: "ALL n>=N. extreal (g n) = f n" by metis
hoelzl@41973
  1664
    hence "(%n. extreal (g n)) ----> l" using tail_same_limit[of f l N] assms by auto
hoelzl@41973
  1665
    hence *: "(%n. g n) ----> m" using m_def by auto
hoelzl@41973
  1666
    { fix n assume "n>=max N M"
hoelzl@41973
  1667
      hence "extreal (g n) <= extreal B" using assms g_def B_def by auto
hoelzl@41973
  1668
      hence "g n <= B" by auto
hoelzl@41973
  1669
    } hence "EX N. ALL n>=N. g n <= B" by blast
hoelzl@41973
  1670
    hence "m<=B" using * LIMSEQ_le_const2[of g m B] by auto
hoelzl@41973
  1671
    hence ?thesis using m_def B_def by auto
hoelzl@41973
  1672
  } ultimately have ?thesis by (cases C) auto
hoelzl@41973
  1673
} ultimately show ?thesis by blast
hoelzl@41973
  1674
qed
hoelzl@41973
  1675
hoelzl@41973
  1676
lemma real_of_extreal_0[simp]: "real (0::extreal) = 0"
hoelzl@41973
  1677
  unfolding real_of_extreal_def zero_extreal_def by simp
hoelzl@41973
  1678
hoelzl@41973
  1679
lemma real_of_extreal_mult[simp]:
hoelzl@41973
  1680
  fixes a b :: extreal shows "real (a * b) = real a * real b"
hoelzl@41973
  1681
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
  1682
hoelzl@41973
  1683
lemma real_of_extreal_eq_0:
hoelzl@41973
  1684
  "real x = 0 \<longleftrightarrow> x = \<infinity> \<or> x = -\<infinity> \<or> x = 0"
hoelzl@41973
  1685
  by (cases x) auto
hoelzl@41973
  1686
hoelzl@41973
  1687
lemma tendsto_extreal_realD:
hoelzl@41973
  1688
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  1689
  assumes "x \<noteq> 0" and tendsto: "((\<lambda>x. extreal (real (f x))) ---> x) net"
hoelzl@41973
  1690
  shows "(f ---> x) net"
hoelzl@41973
  1691
proof (intro topological_tendstoI)
hoelzl@41973
  1692
  fix S assume S: "open S" "x \<in> S"
hoelzl@41973
  1693
  with `x \<noteq> 0` have "open (S - {0})" "x \<in> S - {0}" by auto
hoelzl@41973
  1694
  from tendsto[THEN topological_tendstoD, OF this]
hoelzl@41973
  1695
  show "eventually (\<lambda>x. f x \<in> S) net"
hoelzl@41973
  1696
    by (rule eventually_rev_mp) (auto simp: extreal_real real_of_extreal_0)
hoelzl@41973
  1697
qed
hoelzl@41973
  1698
hoelzl@41973
  1699
lemma tendsto_extreal_realI:
hoelzl@41973
  1700
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  1701
  assumes x: "x \<noteq> \<infinity>" "x \<noteq> -\<infinity>" and tendsto: "(f ---> x) net"
hoelzl@41973
  1702
  shows "((\<lambda>x. extreal (real (f x))) ---> x) net"
hoelzl@41973
  1703
proof (intro topological_tendstoI)
hoelzl@41973
  1704
  fix S assume "open S" "x \<in> S"
hoelzl@41973
  1705
  with x have "open (S - {\<infinity>, -\<infinity>})" "x \<in> S - {\<infinity>, -\<infinity>}" by auto
hoelzl@41973
  1706
  from tendsto[THEN topological_tendstoD, OF this]
hoelzl@41973
  1707
  show "eventually (\<lambda>x. extreal (real (f x)) \<in> S) net"
hoelzl@41973
  1708
    by (elim eventually_elim1) (auto simp: extreal_real)
hoelzl@41973
  1709
qed
hoelzl@41973
  1710
hoelzl@41973
  1711
lemma extreal_mult_cancel_left:
hoelzl@41973
  1712
  fixes a b c :: extreal shows "a * b = a * c \<longleftrightarrow>
hoelzl@41973
  1713
    (((a = \<infinity> \<or> a = -\<infinity>) \<and> 0 < b * c) \<or> a = 0 \<or> b = c)"
hoelzl@41973
  1714
  by (cases rule: extreal3_cases[of a b c])
hoelzl@41973
  1715
     (simp_all add: zero_less_mult_iff)
hoelzl@41973
  1716
hoelzl@41973
  1717
lemma extreal_inj_affinity:
hoelzl@41973
  1718
  assumes "m \<noteq> \<infinity>" "m \<noteq> -\<infinity>" "m \<noteq> 0" "t \<noteq> \<infinity>" "t \<noteq> -\<infinity>"
hoelzl@41973
  1719
  shows "inj_on (\<lambda>x. m * x + t) A"
hoelzl@41973
  1720
  using assms
hoelzl@41973
  1721
  by (cases rule: extreal2_cases[of m t])
hoelzl@41973
  1722
     (auto intro!: inj_onI simp: extreal_add_cancel_right extreal_mult_cancel_left)
hoelzl@41973
  1723
hoelzl@41973
  1724
lemma extreal_PInfty_eq_plus[simp]:
hoelzl@41973
  1725
  shows "\<infinity> = a + b \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>"
hoelzl@41973
  1726
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
  1727
hoelzl@41973
  1728
lemma extreal_MInfty_eq_plus[simp]:
hoelzl@41973
  1729
  shows "-\<infinity> = a + b \<longleftrightarrow> (a = -\<infinity> \<and> b \<noteq> \<infinity>) \<or> (b = -\<infinity> \<and> a \<noteq> \<infinity>)"
hoelzl@41973
  1730
  by (cases rule: extreal2_cases[of a b]) auto
hoelzl@41973
  1731
hoelzl@41973
  1732
lemma extreal_less_divide_pos:
hoelzl@41973
  1733
  "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y < z / x \<longleftrightarrow> x * y < z"
hoelzl@41973
  1734
  by (cases rule: extreal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
  1735
hoelzl@41973
  1736
lemma extreal_divide_less_pos:
hoelzl@41973
  1737
  "x > 0 \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> y / x < z \<longleftrightarrow> y < x * z"
hoelzl@41973
  1738
  by (cases rule: extreal3_cases[of x y z]) (auto simp: field_simps)
hoelzl@41973
  1739
hoelzl@41973
  1740
lemma extreal_open_affinity_pos:
hoelzl@41973
  1741
  assumes "open S" and m: "m \<noteq> \<infinity>" "0 < m" and t: "t \<noteq> \<infinity>" "t \<noteq> -\<infinity>"
hoelzl@41973
  1742
  shows "open ((\<lambda>x. m * x + t) ` S)"
hoelzl@41973
  1743
proof -
hoelzl@41973
  1744
  obtain r where r[simp]: "m = extreal r" using m by (cases m) auto
hoelzl@41973
  1745
  obtain p where p[simp]: "t = extreal p" using t by (cases t) auto
hoelzl@41973
  1746
  have "r \<noteq> 0" "0 < r" and m': "m \<noteq> \<infinity>" "m \<noteq> -\<infinity>" "m \<noteq> 0" using m by auto
hoelzl@41973
  1747
  from `open S`[THEN extreal_openE] guess T l u . note T = this
hoelzl@41973
  1748
  let ?f = "(\<lambda>x. m * x + t)"
hoelzl@41973
  1749
  show ?thesis unfolding open_extreal_def
hoelzl@41973
  1750
  proof (intro conjI impI exI subsetI)
hoelzl@41973
  1751
    show "open ((\<lambda>x. r*x + p)`T)"
hoelzl@41973
  1752
      using open_affinity[OF `open T` `r \<noteq> 0`] by (auto simp: ac_simps)
hoelzl@41973
  1753
    have affine_infy: "?f ` {\<infinity>, - \<infinity>} = {\<infinity>, -\<infinity>}"
hoelzl@41973
  1754
      using `r \<noteq> 0` by auto
hoelzl@41973
  1755
    have "extreal ` (\<lambda>x. r * x + p) ` T = ?f ` (extreal ` T)"
hoelzl@41973
  1756
      by (simp add: image_image)
hoelzl@41973
  1757
    also have "\<dots> = ?f ` (S - {\<infinity>, -\<infinity>})"
hoelzl@41973
  1758
      using T(2) by simp
hoelzl@41973
  1759
    also have "\<dots> = ?f ` S - {\<infinity>, -\<infinity>}"
hoelzl@41973
  1760
      using extreal_inj_affinity[OF m' t] by (simp only: image_set_diff affine_infy)
hoelzl@41973
  1761
    finally show "extreal ` (\<lambda>x. r * x + p) ` T = ?f ` S - {\<infinity>, -\<infinity>}" .
hoelzl@41973
  1762
  next
hoelzl@41973
  1763
    assume "\<infinity> \<in> ?f`S" with `0 < r` have "\<infinity> \<in> S" by auto
hoelzl@41973
  1764
    fix x assume "x \<in> {extreal (r * l + p)<..}"
hoelzl@41973
  1765
    then have [simp]: "extreal (r * l + p) < x" by auto
hoelzl@41973
  1766
    show "x \<in> ?f`S"
hoelzl@41973
  1767
    proof (rule image_eqI)
hoelzl@41973
  1768
      show "x = m * ((x - t) / m) + t"
hoelzl@41973
  1769
        using m t by (cases rule: extreal3_cases[of m x t]) auto
hoelzl@41973
  1770
      have "extreal l < (x - t)/m"
hoelzl@41973
  1771
        using m t by (simp add: extreal_less_divide_pos extreal_less_minus)
hoelzl@41973
  1772
      then show "(x - t)/m \<in> S" using T(3)[OF `\<infinity> \<in> S`] by auto
hoelzl@41973
  1773
    qed
hoelzl@41973
  1774
  next
hoelzl@41973
  1775
    assume "-\<infinity> \<in> ?f`S" with `0 < r` have "-\<infinity> \<in> S" by auto
hoelzl@41973
  1776
    fix x assume "x \<in> {..<extreal (r * u + p)}"
hoelzl@41973
  1777
    then have [simp]: "x < extreal (r * u + p)" by auto
hoelzl@41973
  1778
    show "x \<in> ?f`S"
hoelzl@41973
  1779
    proof (rule image_eqI)
hoelzl@41973
  1780
      show "x = m * ((x - t) / m) + t"
hoelzl@41973
  1781
        using m t by (cases rule: extreal3_cases[of m x t]) auto
hoelzl@41973
  1782
      have "(x - t)/m < extreal u"
hoelzl@41973
  1783
        using m t by (simp add: extreal_divide_less_pos extreal_minus_less)
hoelzl@41973
  1784
      then show "(x - t)/m \<in> S" using T(4)[OF `-\<infinity> \<in> S`] by auto
hoelzl@41973
  1785
    qed
hoelzl@41973
  1786
  qed
hoelzl@41973
  1787
qed
hoelzl@41973
  1788
hoelzl@41973
  1789
lemma extreal_open_affinity:
hoelzl@41973
  1790
  assumes "open S" and m: "m \<noteq> \<infinity>" "m \<noteq> -\<infinity>" "m \<noteq> 0" and t: "t \<noteq> \<infinity>" "t \<noteq> -\<infinity>"
hoelzl@41973
  1791
  shows "open ((\<lambda>x. m * x + t) ` S)"
hoelzl@41973
  1792
proof cases
hoelzl@41973
  1793
  assume "0 < m" then show ?thesis
hoelzl@41973
  1794
    using extreal_open_affinity_pos[OF `open S` `m \<noteq> \<infinity>` _ t] by auto
hoelzl@41973
  1795
next
hoelzl@41973
  1796
  assume "\<not> 0 < m" then
hoelzl@41973
  1797
  have "0 < -m" using `m \<noteq> 0` by (cases m) auto
hoelzl@41973
  1798
  then have m: "-m \<noteq> \<infinity>" "0 < -m" using `m \<noteq> -\<infinity>`
hoelzl@41973
  1799
    by (simp_all add: extreal_uminus_eq_reorder)
hoelzl@41973
  1800
  from extreal_open_affinity_pos[OF extreal_open_uminus[OF `open S`] m t]
hoelzl@41973
  1801
  show ?thesis unfolding image_image by simp
hoelzl@41973
  1802
qed
hoelzl@41973
  1803
hoelzl@41973
  1804
lemma extreal_divide_eq:
hoelzl@41973
  1805
  "b \<noteq> 0 \<Longrightarrow> b \<noteq> \<infinity> \<Longrightarrow> b \<noteq> -\<infinity> \<Longrightarrow> a / b = c \<longleftrightarrow> a = b * c"
hoelzl@41973
  1806
  by (cases rule: extreal3_cases[of a b c])
hoelzl@41973
  1807
     (simp_all add: field_simps)
hoelzl@41973
  1808
hoelzl@41973
  1809
lemma extreal_inverse_not_MInfty[simp]: "inverse a \<noteq> -\<infinity>"
hoelzl@41973
  1810
  by (cases a) auto
hoelzl@41973
  1811
hoelzl@41973
  1812
lemma extreal_lim_mult:
hoelzl@41973
  1813
  fixes X :: "'a \<Rightarrow> extreal"
hoelzl@41973
  1814
  assumes lim: "(X ---> L) net" and a: "a \<noteq> \<infinity>" "a \<noteq> -\<infinity>"
hoelzl@41973
  1815
  shows "((\<lambda>i. a * X i) ---> a * L) net"
hoelzl@41973
  1816
proof cases
hoelzl@41973
  1817
  assume "a \<noteq> 0"
hoelzl@41973
  1818
  show ?thesis
hoelzl@41973
  1819
  proof (rule topological_tendstoI)
hoelzl@41973
  1820
    fix S assume "open S" "a * L \<in> S"
hoelzl@41973
  1821
    have "a * L / a = L"
hoelzl@41973
  1822
      using `a \<noteq> 0` a by (cases rule: extreal2_cases[of a L]) auto
hoelzl@41973
  1823
    then have L: "L \<in> ((\<lambda>x. x / a) ` S)"
hoelzl@41973
  1824
      using `a * L \<in> S` by (force simp: image_iff)
hoelzl@41973
  1825
    moreover have "open ((\<lambda>x. x / a) ` S)"
hoelzl@41973
  1826
      using extreal_open_affinity[OF `open S`, of "inverse a" 0] `a \<noteq> 0` a
hoelzl@41973
  1827
      by (simp add: extreal_divide_eq extreal_inverse_eq_0 divide_extreal_def ac_simps)
hoelzl@41973
  1828
    note * = lim[THEN topological_tendstoD, OF this L]
hoelzl@41973
  1829
    { fix x from a `a \<noteq> 0` have "a * (x / a) = x"
hoelzl@41973
  1830
        by (cases rule: extreal2_cases[of a x]) auto }
hoelzl@41973
  1831
    note this[simp]
hoelzl@41973
  1832
    show "eventually (\<lambda>x. a * X x \<in> S) net"
hoelzl@41973
  1833
      by (rule eventually_mono[OF _ *]) auto
hoelzl@41973
  1834
  qed
hoelzl@41973
  1835
qed auto
hoelzl@41973
  1836
hoelzl@41973
  1837
lemma extreal_mult_m1[simp]: "x * extreal (-1) = -x"
hoelzl@41973
  1838
  by (cases x) auto
hoelzl@41973
  1839
hoelzl@41973
  1840
lemma extreal_lim_uminus:
hoelzl@41973
  1841
  fixes X :: "'a \<Rightarrow> extreal" shows "((\<lambda>i. - X i) ---> -L) net \<longleftrightarrow> (X ---> L) net"
hoelzl@41973
  1842
  using extreal_lim_mult[of X L net "extreal (-1)"]
hoelzl@41973
  1843
        extreal_lim_mult[of "(\<lambda>i. - X i)" "-L" net "extreal (-1)"]
hoelzl@41973
  1844
  by (auto simp add: algebra_simps)
hoelzl@41973
  1845
hoelzl@41973
  1846
lemma Lim_bounded2_extreal:
hoelzl@41973
  1847
  assumes lim:"f ----> (l :: extreal)"
hoelzl@41973
  1848
  and ge: "ALL n>=N. f n >= C"
hoelzl@41973
  1849
  shows "l>=C"
hoelzl@41973
  1850
proof-
hoelzl@41973
  1851
def g == "(%i. -(f i))"
hoelzl@41973
  1852
{ fix n assume "n>=N" hence "g n <= -C" using assms extreal_minus_le_minus g_def by auto }
hoelzl@41973
  1853
hence "ALL n>=N. g n <= -C" by auto
hoelzl@41973
  1854
moreover have limg: "g ----> (-l)" using g_def extreal_lim_uminus lim by auto
hoelzl@41973
  1855
ultimately have "-l <= -C" using Lim_bounded_extreal[of g "-l" _ "-C"] by auto
hoelzl@41973
  1856
from this show ?thesis using extreal_minus_le_minus by auto
hoelzl@41973
  1857
qed
hoelzl@41973
  1858
hoelzl@41973
  1859
hoelzl@41973
  1860
lemma extreal_LimI_finite:
hoelzl@41973
  1861
  assumes "x ~= \<infinity>" "x ~= (-\<infinity>)"
hoelzl@41973
  1862
  assumes "!!r. 0 < r ==> EX N. ALL n>=N. u n < x + r & x < u n + r"
hoelzl@41973
  1863
  shows "u ----> x"
hoelzl@41973
  1864
proof (rule topological_tendstoI, unfold eventually_sequentially)
hoelzl@41973
  1865
  obtain rx where rx_def: "x=extreal rx" using assms by (cases x) auto
hoelzl@41973
  1866
  fix S assume "open S" "x : S"
hoelzl@41973
  1867
  then obtain A where "open A" and A_eq: "extreal ` A = S - {\<infinity>,(-\<infinity>)}"
hoelzl@41973
  1868
     by (auto elim!: extreal_openE)
hoelzl@41973
  1869
  then have "x : extreal ` A" using `x : S` assms by auto
hoelzl@41973
  1870
  then have "rx : A" using rx_def by auto
hoelzl@41973
  1871
  then obtain r where "0 < r" and dist: "!!y. dist y (real x) < r ==> y : A"
hoelzl@41973
  1872
    using `open A` unfolding open_real_def rx_def by auto
hoelzl@41973
  1873
  then obtain n where
hoelzl@41973
  1874
    upper: "!!N. n <= N ==> u N < x + extreal r" and
hoelzl@41973
  1875
    lower: "!!N. n <= N ==> x < u N + extreal r" using assms(3)[of "extreal r"] by auto
hoelzl@41973
  1876
  show "EX N. ALL n>=N. u n : S"
hoelzl@41973
  1877
  proof (safe intro!: exI[of _ n])
hoelzl@41973
  1878
    fix N assume "n <= N"
hoelzl@41973
  1879
    from upper[OF this] lower[OF this] assms `0 < r`
hoelzl@41973
  1880
    have "u N ~: {\<infinity>,(-\<infinity>)}" by auto
hoelzl@41973
  1881
    from this obtain ra where ra_def: "(u N) = extreal ra" by (cases "u N") auto
hoelzl@41973
  1882
    hence "rx < ra + r" and "ra < rx + r"
hoelzl@41973
  1883
       using rx_def assms `0 < r` lower[OF `n <= N`] upper[OF `n <= N`] by auto
hoelzl@41973
  1884
    hence "dist (real (u N)) (real x) < r"
hoelzl@41973
  1885
      using rx_def ra_def
hoelzl@41973
  1886
      by (auto simp: dist_real_def abs_diff_less_iff field_simps)
hoelzl@41973
  1887
    from dist[OF this]
hoelzl@41973
  1888
    have "u N : extreal ` A" using `u N  ~: {\<infinity>,(-\<infinity>)}`
hoelzl@41973
  1889
      by (auto intro!: image_eqI[of _ _ "real (u N)"] simp: extreal_real)
hoelzl@41973
  1890
    thus "u N : S" using A_eq by simp
hoelzl@41973
  1891
  qed
hoelzl@41973
  1892
qed
hoelzl@41973
  1893
hoelzl@41973
  1894
lemma extreal_LimI_finite_iff:
hoelzl@41973
  1895
  assumes "x ~= \<infinity>" "x ~= (-\<infinity>)"
hoelzl@41973
  1896
  shows "u ----> x <-> (ALL r. 0 < r --> (EX N. ALL n>=N. u n < x + r & x < u n + r))"
hoelzl@41973
  1897
  (is "?lhs <-> ?rhs")
hoelzl@41973
  1898
proof-
hoelzl@41973
  1899
{ assume lim: "u ----> x"
hoelzl@41973
  1900
  { fix r assume "(r::extreal)>0"
hoelzl@41973
  1901
    from this obtain N where N_def: "ALL n>=N. u n : {x - r <..< x + r}"
hoelzl@41973
  1902
       apply (subst tendsto_obtains_N[of u x "{x - r <..< x + r}"])
hoelzl@41973
  1903
       using lim extreal_between[of x r] assms `r>0` by auto
hoelzl@41973
  1904
    hence "EX N. ALL n>=N. u n < x + r & x < u n + r"
hoelzl@41973
  1905
      using extreal_minus_less[of r x] by (cases r) auto
hoelzl@41973
  1906
  } hence "?rhs" by auto
hoelzl@41973
  1907
} from this show ?thesis using extreal_LimI_finite assms by blast
hoelzl@41973
  1908
qed
hoelzl@41973
  1909
hoelzl@41973
  1910
hoelzl@41973
  1911
subsubsection {* @{text Liminf} and @{text Limsup} *}
hoelzl@41973
  1912
hoelzl@41973
  1913
definition
hoelzl@41973
  1914
  "Liminf net f = (GREATEST l. \<forall>y<l. eventually (\<lambda>x. y < f x) net)"
hoelzl@41973
  1915
hoelzl@41973
  1916
definition
hoelzl@41973
  1917
  "Limsup net f = (LEAST l. \<forall>y>l. eventually (\<lambda>x. f x < y) net)"
hoelzl@41973
  1918
hoelzl@41973
  1919
lemma Liminf_Sup:
hoelzl@41973
  1920
  fixes f :: "'a => 'b::{complete_lattice, linorder}"
hoelzl@41973
  1921
  shows "Liminf net f = Sup {l. \<forall>y<l. eventually (\<lambda>x. y < f x) net}"
hoelzl@41973
  1922
  by (auto intro!: Greatest_equality complete_lattice_class.Sup_upper simp: less_Sup_iff Liminf_def)
hoelzl@41973
  1923
hoelzl@41973
  1924
lemma Limsup_Inf:
hoelzl@41973
  1925
  fixes f :: "'a => 'b::{complete_lattice, linorder}"
hoelzl@41973
  1926
  shows "Limsup net f = Inf {l. \<forall>y>l. eventually (\<lambda>x. f x < y) net}"
hoelzl@41973
  1927
  by (auto intro!: Least_equality complete_lattice_class.Inf_lower simp: Inf_less_iff Limsup_def)
hoelzl@41973
  1928
hoelzl@41973
  1929
lemma extreal_SupI:
hoelzl@41973
  1930
  fixes x :: extreal
hoelzl@41973
  1931
  assumes "\<And>y. y \<in> A \<Longrightarrow> y \<le> x"
hoelzl@41973
  1932
  assumes "\<And>y. (\<And>z. z \<in> A \<Longrightarrow> z \<le> y) \<Longrightarrow> x \<le> y"
hoelzl@41973
  1933
  shows "Sup A = x"
hoelzl@41973
  1934
  unfolding Sup_extreal_def
hoelzl@41973
  1935
  using assms by (auto intro!: Least_equality)
hoelzl@41973
  1936
hoelzl@41973
  1937
lemma extreal_InfI:
hoelzl@41973
  1938
  fixes x :: extreal
hoelzl@41973
  1939
  assumes "\<And>i. i \<in> A \<Longrightarrow> x \<le> i"
hoelzl@41973
  1940
  assumes "\<And>y. (\<And>i. i \<in> A \<Longrightarrow> y \<le> i) \<Longrightarrow> y \<le> x"
hoelzl@41973
  1941
  shows "Inf A = x"
hoelzl@41973
  1942
  unfolding Inf_extreal_def
hoelzl@41973
  1943
  using assms by (auto intro!: Greatest_equality)
hoelzl@41973
  1944
hoelzl@41973
  1945
lemma Limsup_const:
hoelzl@41973
  1946
  fixes c :: "'a::{complete_lattice, linorder}"
hoelzl@41973
  1947
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  1948
  shows "Limsup net (\<lambda>x. c) = c"
hoelzl@41973
  1949
  unfolding Limsup_Inf
hoelzl@41973
  1950
proof (safe intro!: antisym complete_lattice_class.Inf_greatest complete_lattice_class.Inf_lower)
hoelzl@41973
  1951
  fix x assume *: "\<forall>y>x. eventually (\<lambda>_. c < y) net"
hoelzl@41973
  1952
  show "c \<le> x"
hoelzl@41973
  1953
  proof (rule ccontr)
hoelzl@41973
  1954
    assume "\<not> c \<le> x" then have "x < c" by auto
hoelzl@41973
  1955
    then show False using ntriv * by (auto simp: trivial_limit_def)
hoelzl@41973
  1956
  qed
hoelzl@41973
  1957
qed auto
hoelzl@41973
  1958
hoelzl@41973
  1959
lemma Liminf_const:
hoelzl@41973
  1960
  fixes c :: "'a::{complete_lattice, linorder}"
hoelzl@41973
  1961
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  1962
  shows "Liminf net (\<lambda>x. c) = c"
hoelzl@41973
  1963
  unfolding Liminf_Sup
hoelzl@41973
  1964
proof (safe intro!: antisym complete_lattice_class.Sup_least complete_lattice_class.Sup_upper)
hoelzl@41973
  1965
  fix x assume *: "\<forall>y<x. eventually (\<lambda>_. y < c) net"
hoelzl@41973
  1966
  show "x \<le> c"
hoelzl@41973
  1967
  proof (rule ccontr)
hoelzl@41973
  1968
    assume "\<not> x \<le> c" then have "c < x" by auto
hoelzl@41973
  1969
    then show False using ntriv * by (auto simp: trivial_limit_def)
hoelzl@41973
  1970
  qed
hoelzl@41973
  1971
qed auto
hoelzl@41973
  1972
hoelzl@41973
  1973
lemma mono_set:
hoelzl@41973
  1974
  fixes S :: "('a::order) set"
hoelzl@41973
  1975
  shows "mono S \<longleftrightarrow> (\<forall>x y. x \<le> y \<longrightarrow> x \<in> S \<longrightarrow> y \<in> S)"
hoelzl@41973
  1976
  by (auto simp: mono_def mem_def)
hoelzl@41973
  1977
hoelzl@41973
  1978
lemma mono_greaterThan[intro, simp]: "mono {B<..}" unfolding mono_set by auto
hoelzl@41973
  1979
lemma mono_atLeast[intro, simp]: "mono {B..}" unfolding mono_set by auto
hoelzl@41973
  1980
lemma mono_UNIV[intro, simp]: "mono UNIV" unfolding mono_set by auto
hoelzl@41973
  1981
lemma mono_empty[intro, simp]: "mono {}" unfolding mono_set by auto
hoelzl@41973
  1982
hoelzl@41973
  1983
lemma mono_set_iff:
hoelzl@41973
  1984
  fixes S :: "'a::{linorder,complete_lattice} set"
hoelzl@41973
  1985
  defines "a \<equiv> Inf S"
hoelzl@41973
  1986
  shows "mono S \<longleftrightarrow> (S = {a <..} \<or> S = {a..})" (is "_ = ?c")
hoelzl@41973
  1987
proof
hoelzl@41973
  1988
  assume "mono S"
hoelzl@41973
  1989
  then have mono: "\<And>x y. x \<le> y \<Longrightarrow> x \<in> S \<Longrightarrow> y \<in> S" by (auto simp: mono_set)
hoelzl@41973
  1990
  show ?c
hoelzl@41973
  1991
  proof cases
hoelzl@41973
  1992
    assume "a \<in> S"
hoelzl@41973
  1993
    show ?c
hoelzl@41973
  1994
      using mono[OF _ `a \<in> S`]
hoelzl@41973
  1995
      by (auto intro: complete_lattice_class.Inf_lower simp: a_def)
hoelzl@41973
  1996
  next
hoelzl@41973
  1997
    assume "a \<notin> S"
hoelzl@41973
  1998
    have "S = {a <..}"
hoelzl@41973
  1999
    proof safe
hoelzl@41973
  2000
      fix x assume "x \<in> S"
hoelzl@41973
  2001
      then have "a \<le> x" unfolding a_def by (rule complete_lattice_class.Inf_lower)
hoelzl@41973
  2002
      then show "a < x" using `x \<in> S` `a \<notin> S` by (cases "a = x") auto
hoelzl@41973
  2003
    next
hoelzl@41973
  2004
      fix x assume "a < x"
hoelzl@41973
  2005
      then obtain y where "y < x" "y \<in> S" unfolding a_def Inf_less_iff ..
hoelzl@41973
  2006
      with mono[of y x] show "x \<in> S" by auto
hoelzl@41973
  2007
    qed
hoelzl@41973
  2008
    then show ?c ..
hoelzl@41973
  2009
  qed
hoelzl@41973
  2010
qed auto
hoelzl@41973
  2011
hoelzl@41973
  2012
lemma (in complete_lattice) not_less_bot[simp]: "\<not> (x < bot)"
hoelzl@41973
  2013
proof
hoelzl@41973
  2014
  assume "x < bot"
hoelzl@41973
  2015
  with bot_least[of x] show False by (auto simp: le_less)
hoelzl@41973
  2016
qed
hoelzl@41973
  2017
hoelzl@41973
  2018
lemma (in complete_lattice) atLeast_eq_UNIV_iff: "{x..} = UNIV \<longleftrightarrow> x = bot"
hoelzl@41973
  2019
proof
hoelzl@41973
  2020
  assume "{x..} = UNIV"
hoelzl@41973
  2021
  show "x = bot"
hoelzl@41973
  2022
  proof (rule ccontr)
hoelzl@41973
  2023
    assume "x \<noteq> bot" then have "bot \<notin> {x..}" by (simp add: le_less)
hoelzl@41973
  2024
    then show False using `{x..} = UNIV` by simp
hoelzl@41973
  2025
  qed
hoelzl@41973
  2026
qed auto
hoelzl@41973
  2027
hoelzl@41973
  2028
hoelzl@41973
  2029
lemma extreal_open_atLeast: "open {x..} \<longleftrightarrow> x = -\<infinity>"
hoelzl@41973
  2030
proof
hoelzl@41973
  2031
  assume "x = -\<infinity>" then have "{x..} = UNIV" by auto
hoelzl@41973
  2032
  then show "open {x..}" by auto
hoelzl@41973
  2033
next
hoelzl@41973
  2034
  assume "open {x..}"
hoelzl@41973
  2035
  then have "open {x..} \<and> closed {x..}" by auto
hoelzl@41973
  2036
  then have "{x..} = UNIV" unfolding extreal_open_closed by auto
hoelzl@41973
  2037
  then show "x = -\<infinity>" by (simp add: bot_extreal_def atLeast_eq_UNIV_iff)
hoelzl@41973
  2038
qed
hoelzl@41973
  2039
hoelzl@41973
  2040
lemma extreal_open_mono_set:
hoelzl@41973
  2041
  fixes S :: "extreal set"
hoelzl@41973
  2042
  defines "a \<equiv> Inf S"
hoelzl@41973
  2043
  shows "(open S \<and> mono S) \<longleftrightarrow> (S = UNIV \<or> S = {a <..})"
hoelzl@41973
  2044
  by (metis Inf_UNIV a_def atLeast_eq_UNIV_iff extreal_open_atLeast
hoelzl@41973
  2045
            extreal_open_closed mono_set_iff open_extreal_greaterThan)
hoelzl@41973
  2046
hoelzl@41973
  2047
lemma extreal_closed_mono_set:
hoelzl@41973
  2048
  fixes S :: "extreal set"
hoelzl@41973
  2049
  shows "(closed S \<and> mono S) \<longleftrightarrow> (S = {} \<or> S = {Inf S ..})"
hoelzl@41973
  2050
  by (metis Inf_UNIV atLeast_eq_UNIV_iff closed_extreal_atLeast
hoelzl@41973
  2051
            extreal_open_closed mono_empty mono_set_iff open_extreal_greaterThan)
hoelzl@41973
  2052
hoelzl@41973
  2053
lemma extreal_Liminf_Sup_monoset:
hoelzl@41973
  2054
  fixes f :: "'a => extreal"
hoelzl@41973
  2055
  shows "Liminf net f = Sup {l. \<forall>S. open S \<longrightarrow> mono S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net}"
hoelzl@41973
  2056
  unfolding Liminf_Sup
hoelzl@41973
  2057
proof (intro arg_cong[where f="\<lambda>P. Sup (Collect P)"] ext iffI allI impI)
hoelzl@41973
  2058
  fix l S assume ev: "\<forall>y<l. eventually (\<lambda>x. y < f x) net" and "open S" "mono S" "l \<in> S"
hoelzl@41973
  2059
  then have "S = UNIV \<or> S = {Inf S <..}"
hoelzl@41973
  2060
    using extreal_open_mono_set[of S] by auto
hoelzl@41973
  2061
  then show "eventually (\<lambda>x. f x \<in> S) net"
hoelzl@41973
  2062
  proof
hoelzl@41973
  2063
    assume S: "S = {Inf S<..}"
hoelzl@41973
  2064
    then have "Inf S < l" using `l \<in> S` by auto
hoelzl@41973
  2065
    then have "eventually (\<lambda>x. Inf S < f x) net" using ev by auto
hoelzl@41973
  2066
    then show "eventually (\<lambda>x. f x \<in> S) net"  by (subst S) auto
hoelzl@41973
  2067
  qed auto
hoelzl@41973
  2068
next
hoelzl@41973
  2069
  fix l y assume S: "\<forall>S. open S \<longrightarrow> mono S \<longrightarrow> l \<in> S \<longrightarrow> eventually  (\<lambda>x. f x \<in> S) net" "y < l"
hoelzl@41973
  2070
  have "eventually  (\<lambda>x. f x \<in> {y <..}) net"
hoelzl@41973
  2071
    using `y < l` by (intro S[rule_format]) auto
hoelzl@41973
  2072
  then show "eventually (\<lambda>x. y < f x) net" by auto
hoelzl@41973
  2073
qed
hoelzl@41973
  2074
hoelzl@41973
  2075
lemma extreal_Inf_uminus_image_eq: "Inf (uminus ` S) = - Sup (S::extreal set)"
hoelzl@41973
  2076
  using extreal_Sup_uminus_image_eq[of "uminus ` S"] by (simp add: image_image)
hoelzl@41973
  2077
hoelzl@41973
  2078
lemma extreal_range_uminus[simp]: "range uminus = (UNIV::extreal set)"
hoelzl@41973
  2079
proof safe
hoelzl@41973
  2080
  fix x :: extreal show "x \<in> range uminus" by (intro image_eqI[of _ _ "-x"]) auto
hoelzl@41973
  2081
qed auto
hoelzl@41973
  2082
hoelzl@41973
  2083
lemma extreal_Limsup_Inf_monoset:
hoelzl@41973
  2084
  fixes f :: "'a => extreal"
hoelzl@41973
  2085
  shows "Limsup net f = Inf {l. \<forall>S. open S \<longrightarrow> mono (uminus ` S) \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) net}"
hoelzl@41973
  2086
  unfolding Limsup_Inf
hoelzl@41973
  2087
proof (intro arg_cong[where f="\<lambda>P. Inf (Collect P)"] ext iffI allI impI)
hoelzl@41973
  2088
  fix l S assume ev: "\<forall>y>l. eventually (\<lambda>x. f x < y) net" and "open S" "mono (uminus`S)" "l \<in> S"
hoelzl@41973
  2089
  then have "open (uminus`S) \<and> mono (uminus`S)" by (simp add: extreal_open_uminus)
hoelzl@41973
  2090
  then have "S = UNIV \<or> S = {..< Sup S}"
hoelzl@41973
  2091
    unfolding extreal_open_mono_set extreal_Inf_uminus_image_eq extreal_image_uminus_shift by simp
hoelzl@41973
  2092
  then show "eventually (\<lambda>x. f x \<in> S) net"
hoelzl@41973
  2093
  proof
hoelzl@41973
  2094
    assume S: "S = {..< Sup S}"
hoelzl@41973
  2095
    then have "l < Sup S" using `l \<in> S` by auto
hoelzl@41973
  2096
    then have "eventually (\<lambda>x. f x < Sup S) net" using ev by auto
hoelzl@41973
  2097
    then show "eventually (\<lambda>x. f x \<in> S) net"  by (subst S) auto
hoelzl@41973
  2098
  qed auto
hoelzl@41973
  2099
next
hoelzl@41973
  2100
  fix l y assume S: "\<forall>S. open S \<longrightarrow> mono (uminus`S) \<longrightarrow> l \<in> S \<longrightarrow> eventually  (\<lambda>x. f x \<in> S) net" "l < y"
hoelzl@41973
  2101
  have "eventually  (\<lambda>x. f x \<in> {..< y}) net"
hoelzl@41973
  2102
    using `l < y` by (intro S[rule_format]) auto
hoelzl@41973
  2103
  then show "eventually (\<lambda>x. f x < y) net" by auto
hoelzl@41973
  2104
qed
hoelzl@41973
  2105
hoelzl@41973
  2106
lemma open_uminus_iff: "open (uminus ` S) \<longleftrightarrow> open (S::extreal set)"
hoelzl@41973
  2107
  using extreal_open_uminus[of S] extreal_open_uminus[of "uminus`S"] by auto
hoelzl@41973
  2108
hoelzl@41973
  2109
lemma extreal_Limsup_uminus:
hoelzl@41973
  2110
  fixes f :: "'a => extreal"
hoelzl@41973
  2111
  shows "Limsup net (\<lambda>x. - (f x)) = -(Liminf net f)"
hoelzl@41973
  2112
proof -
hoelzl@41973
  2113
  { fix P l have "(\<exists>x. (l::extreal) = -x \<and> P x) \<longleftrightarrow> P (-l)" by (auto intro!: exI[of _ "-l"]) }
hoelzl@41973
  2114
  note Ex_cancel = this
hoelzl@41973
  2115
  { fix P :: "extreal set \<Rightarrow> bool" have "(\<forall>S. P S) \<longleftrightarrow> (\<forall>S. P (uminus`S))"
hoelzl@41973
  2116
      apply auto by (erule_tac x="uminus`S" in allE) (auto simp: image_image) }
hoelzl@41973
  2117
  note add_uminus_image = this
hoelzl@41973
  2118
  { fix x S have "(x::extreal) \<in> uminus`S \<longleftrightarrow> -x\<in>S" by (auto intro!: image_eqI[of _ _ "-x"]) }
hoelzl@41973
  2119
  note remove_uminus_image = this
hoelzl@41973
  2120
  show ?thesis
hoelzl@41973
  2121
    unfolding extreal_Limsup_Inf_monoset extreal_Liminf_Sup_monoset
hoelzl@41973
  2122
    unfolding extreal_Inf_uminus_image_eq[symmetric] image_Collect Ex_cancel
hoelzl@41973
  2123
    by (subst add_uminus_image) (simp add: open_uminus_iff remove_uminus_image)
hoelzl@41973
  2124
qed
hoelzl@41973
  2125
hoelzl@41973
  2126
lemma extreal_Liminf_uminus:
hoelzl@41973
  2127
  fixes f :: "'a => extreal"
hoelzl@41973
  2128
  shows "Liminf net (\<lambda>x. - (f x)) = -(Limsup net f)"
hoelzl@41973
  2129
  using extreal_Limsup_uminus[of _ "(\<lambda>x. - (f x))"] by auto
hoelzl@41973
  2130
hoelzl@41973
  2131
lemma extreal_Lim_uminus:
hoelzl@41973
  2132
  fixes f :: "'a \<Rightarrow> extreal" shows "(f ---> f0) net \<longleftrightarrow> ((\<lambda>x. - f x) ---> - f0) net"
hoelzl@41973
  2133
  using
hoelzl@41973
  2134
    extreal_lim_mult[of f f0 net "- 1"]
hoelzl@41973
  2135
    extreal_lim_mult[of "\<lambda>x. - (f x)" "-f0" net "- 1"]
hoelzl@41973
  2136
  by (auto simp: extreal_uminus_reorder)
hoelzl@41973
  2137
hoelzl@41973
  2138
lemma lim_imp_Liminf:
hoelzl@41973
  2139
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2140
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  2141
  assumes lim: "(f ---> f0) net"
hoelzl@41973
  2142
  shows "Liminf net f = f0"
hoelzl@41973
  2143
  unfolding Liminf_Sup
hoelzl@41973
  2144
proof (safe intro!: extreal_SupI)
hoelzl@41973
  2145
  fix y assume *: "\<forall>y'<y. eventually (\<lambda>x. y' < f x) net"
hoelzl@41973
  2146
  show "y \<le> f0"
hoelzl@41973
  2147
  proof (rule extreal_le_extreal)
hoelzl@41973
  2148
    fix B assume "B < y"
hoelzl@41973
  2149
    { assume "f0 < B"
hoelzl@41973
  2150
      then have "eventually (\<lambda>x. f x < B \<and> B < f x) net"
hoelzl@41973
  2151
         using topological_tendstoD[OF lim, of "{..<B}"] *[rule_format, OF `B < y`]
hoelzl@41973
  2152
         by (auto intro: eventually_conj)
hoelzl@41973
  2153
      also have "(\<lambda>x. f x < B \<and> B < f x) = (\<lambda>x. False)" by (auto simp: fun_eq_iff)
hoelzl@41973
  2154
      finally have False using ntriv[unfolded trivial_limit_def] by auto
hoelzl@41973
  2155
    } then show "B \<le> f0" by (metis linorder_le_less_linear)
hoelzl@41973
  2156
  qed
hoelzl@41973
  2157
next
hoelzl@41973
  2158
  fix y assume *: "\<forall>z. z \<in> {l. \<forall>y<l. eventually (\<lambda>x. y < f x) net} \<longrightarrow> z \<le> y"
hoelzl@41973
  2159
  show "f0 \<le> y"
hoelzl@41973
  2160
  proof (safe intro!: *[rule_format])
hoelzl@41973
  2161
    fix y assume "y < f0" then show "eventually (\<lambda>x. y < f x) net"
hoelzl@41973
  2162
      using lim[THEN topological_tendstoD, of "{y <..}"] by auto
hoelzl@41973
  2163
  qed
hoelzl@41973
  2164
qed
hoelzl@41973
  2165
hoelzl@41973
  2166
lemma lim_imp_Limsup:
hoelzl@41973
  2167
  fixes f :: "'a => extreal"
hoelzl@41973
  2168
  assumes "\<not> trivial_limit net"
hoelzl@41973
  2169
  assumes lim: "(f ---> f0) net"
hoelzl@41973
  2170
  shows "Limsup net f = f0"
hoelzl@41973
  2171
  using extreal_Lim_uminus[of f f0] lim_imp_Liminf[of net "(%x. -(f x))" "-f0"]
hoelzl@41973
  2172
     extreal_Liminf_uminus[of net f] assms by simp
hoelzl@41973
  2173
hoelzl@41973
  2174
lemma extreal_Liminf_le_Limsup:
hoelzl@41973
  2175
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2176
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  2177
  shows "Liminf net f \<le> Limsup net f"
hoelzl@41973
  2178
  unfolding Limsup_Inf Liminf_Sup
hoelzl@41973
  2179
proof (safe intro!: complete_lattice_class.Inf_greatest  complete_lattice_class.Sup_least)
hoelzl@41973
  2180
  fix u v assume *: "\<forall>y<u. eventually (\<lambda>x. y < f x) net" "\<forall>y>v. eventually (\<lambda>x. f x < y) net"
hoelzl@41973
  2181
  show "u \<le> v"
hoelzl@41973
  2182
  proof (rule ccontr)
hoelzl@41973
  2183
    assume "\<not> u \<le> v"
hoelzl@41973
  2184
    then obtain t where "t < u" "v < t"
hoelzl@41973
  2185
      using extreal_dense[of v u] by (auto simp: not_le)
hoelzl@41973
  2186
    then have "eventually (\<lambda>x. t < f x \<and> f x < t) net"
hoelzl@41973
  2187
      using * by (auto intro: eventually_conj)
hoelzl@41973
  2188
    also have "(\<lambda>x. t < f x \<and> f x < t) = (\<lambda>x. False)" by (auto simp: fun_eq_iff)
hoelzl@41973
  2189
    finally show False using ntriv by (auto simp: trivial_limit_def)
hoelzl@41973
  2190
  qed
hoelzl@41973
  2191
qed
hoelzl@41973
  2192
hoelzl@41973
  2193
lemma Liminf_PInfty:
hoelzl@41973
  2194
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2195
  assumes "\<not> trivial_limit net"
hoelzl@41973
  2196
  shows "(f ---> \<infinity>) net \<longleftrightarrow> Liminf net f = \<infinity>"
hoelzl@41973
  2197
proof (intro lim_imp_Liminf iffI assms)
hoelzl@41973
  2198
  assume rhs: "Liminf net f = \<infinity>"
hoelzl@41973
  2199
  { fix S assume "open S & \<infinity> : S"
hoelzl@41973
  2200
    then obtain m where "{extreal m<..} <= S" using open_PInfty2 by auto
hoelzl@41973
  2201
    moreover have "eventually (\<lambda>x. f x \<in> {extreal m<..}) net"
hoelzl@41973
  2202
      using rhs unfolding Liminf_Sup top_extreal_def[symmetric] Sup_eq_top_iff
hoelzl@41973
  2203
      by (auto elim!: allE[where x="extreal m"] simp: top_extreal_def)
hoelzl@41973
  2204
    ultimately have "eventually (%x. f x : S) net" apply (subst eventually_mono) by auto
hoelzl@41973
  2205
  } then show "(f ---> \<infinity>) net" unfolding tendsto_def by auto
hoelzl@41973
  2206
qed
hoelzl@41973
  2207
hoelzl@41973
  2208
lemma Limsup_MInfty:
hoelzl@41973
  2209
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2210
  assumes "\<not> trivial_limit net"
hoelzl@41973
  2211
  shows "(f ---> -\<infinity>) net \<longleftrightarrow> Limsup net f = -\<infinity>"
hoelzl@41973
  2212
  using assms extreal_Lim_uminus[of f "-\<infinity>"] Liminf_PInfty[of _ "\<lambda>x. - (f x)"]
hoelzl@41973
  2213
        extreal_Liminf_uminus[of _ f] by (auto simp: extreal_uminus_eq_reorder)
hoelzl@41973
  2214
hoelzl@41973
  2215
lemma extreal_Liminf_eq_Limsup:
hoelzl@41973
  2216
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2217
  assumes ntriv: "\<not> trivial_limit net"
hoelzl@41973
  2218
  assumes lim: "Liminf net f = f0" "Limsup net f = f0"
hoelzl@41973
  2219
  shows "(f ---> f0) net"
hoelzl@41973
  2220
proof (cases f0)
hoelzl@41973
  2221
  case PInf then show ?thesis using Liminf_PInfty[OF ntriv] lim by auto
hoelzl@41973
  2222
next
hoelzl@41973
  2223
  case MInf then show ?thesis using Limsup_MInfty[OF ntriv] lim by auto
hoelzl@41973
  2224
next
hoelzl@41973
  2225
  case (real r)
hoelzl@41973
  2226
  show "(f ---> f0) net"
hoelzl@41973
  2227
  proof (rule topological_tendstoI)
hoelzl@41973
  2228
    fix S assume "open S""f0 \<in> S"
hoelzl@41973
  2229
    then obtain a b where "a < Liminf net f" "Limsup net f < b" "{a<..<b} \<subseteq> S"
hoelzl@41973
  2230
      using extreal_open_cont_interval2[of S f0] real lim by auto
hoelzl@41973
  2231
    then have "eventually (\<lambda>x. f x \<in> {a<..<b}) net"
hoelzl@41973
  2232
      unfolding Liminf_Sup Limsup_Inf less_Sup_iff Inf_less_iff
hoelzl@41973
  2233
      by (auto intro!: eventually_conj simp add: greaterThanLessThan_iff)
hoelzl@41973
  2234
    with `{a<..<b} \<subseteq> S` show "eventually (%x. f x : S) net"
hoelzl@41973
  2235
      by (rule_tac eventually_mono) auto
hoelzl@41973
  2236
  qed
hoelzl@41973
  2237
qed
hoelzl@41973
  2238
hoelzl@41973
  2239
lemma extreal_Liminf_eq_Limsup_iff:
hoelzl@41973
  2240
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2241
  assumes "\<not> trivial_limit net"
hoelzl@41973
  2242
  shows "(f ---> f0) net \<longleftrightarrow> Liminf net f = f0 \<and> Limsup net f = f0"
hoelzl@41973
  2243
  by (metis assms extreal_Liminf_eq_Limsup lim_imp_Liminf lim_imp_Limsup)
hoelzl@41973
  2244
hoelzl@41973
  2245
hoelzl@41973
  2246
lemma Liminf_mono:
hoelzl@41973
  2247
  fixes f g :: "'a => extreal"
hoelzl@41973
  2248
  assumes ev: "eventually (\<lambda>x. f x \<le> g x) net"
hoelzl@41973
  2249
  shows "Liminf net f \<le> Liminf net g"
hoelzl@41973
  2250
  unfolding Liminf_Sup
hoelzl@41973
  2251
proof (safe intro!: Sup_mono bexI)
hoelzl@41973
  2252
  fix a y assume "\<forall>y<a. eventually (\<lambda>x. y < f x) net" and "y < a"
hoelzl@41973
  2253
  then have "eventually (\<lambda>x. y < f x) net" by auto
hoelzl@41973
  2254
  then show "eventually (\<lambda>x. y < g x) net"
hoelzl@41973
  2255
    by (rule eventually_rev_mp) (rule eventually_mono[OF _ ev], auto)
hoelzl@41973
  2256
qed simp
hoelzl@41973
  2257
hoelzl@41973
  2258
lemma Liminf_eq:
hoelzl@41973
  2259
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2260
  assumes "eventually (\<lambda>x. f x = g x) net"
hoelzl@41973
  2261
  shows "Liminf net f = Liminf net g"
hoelzl@41973
  2262
  by (intro antisym Liminf_mono eventually_mono[OF _ assms]) auto
hoelzl@41973
  2263
hoelzl@41973
  2264
lemma Liminf_mono_all:
hoelzl@41973
  2265
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2266
  assumes "\<And>x. f x \<le> g x"
hoelzl@41973
  2267
  shows "Liminf net f \<le> Liminf net g"
hoelzl@41973
  2268
  using assms by (intro Liminf_mono always_eventually) auto
hoelzl@41973
  2269
hoelzl@41973
  2270
lemma Limsup_mono:
hoelzl@41973
  2271
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2272
  assumes ev: "eventually (\<lambda>x. f x \<le> g x) net"
hoelzl@41973
  2273
  shows "Limsup net f \<le> Limsup net g"
hoelzl@41973
  2274
  unfolding Limsup_Inf
hoelzl@41973
  2275
proof (safe intro!: Inf_mono bexI)
hoelzl@41973
  2276
  fix a y assume "\<forall>y>a. eventually (\<lambda>x. g x < y) net" and "a < y"
hoelzl@41973
  2277
  then have "eventually (\<lambda>x. g x < y) net" by auto
hoelzl@41973
  2278
  then show "eventually (\<lambda>x. f x < y) net"
hoelzl@41973
  2279
    by (rule eventually_rev_mp) (rule eventually_mono[OF _ ev], auto)
hoelzl@41973
  2280
qed simp
hoelzl@41973
  2281
hoelzl@41973
  2282
lemma Limsup_mono_all:
hoelzl@41973
  2283
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2284
  assumes "\<And>x. f x \<le> g x"
hoelzl@41973
  2285
  shows "Limsup net f \<le> Limsup net g"
hoelzl@41973
  2286
  using assms by (intro Limsup_mono always_eventually) auto
hoelzl@41973
  2287
hoelzl@41973
  2288
lemma Limsup_eq:
hoelzl@41973
  2289
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@41973
  2290
  assumes "eventually (\<lambda>x. f x = g x) net"
hoelzl@41973
  2291
  shows "Limsup net f = Limsup net g"
hoelzl@41973
  2292
  by (intro antisym Limsup_mono eventually_mono[OF _ assms]) auto
hoelzl@41973
  2293
hoelzl@41973
  2294
abbreviation "liminf \<equiv> Liminf sequentially"
hoelzl@41973
  2295
hoelzl@41973
  2296
abbreviation "limsup \<equiv> Limsup sequentially"
hoelzl@41973
  2297
hoelzl@41973
  2298
lemma (in complete_lattice) less_INFD:
hoelzl@41973
  2299
  assumes "y < INFI A f"" i \<in> A" shows "y < f i"
hoelzl@41973
  2300
proof -
hoelzl@41973
  2301
  note `y < INFI A f`
hoelzl@41973
  2302
  also have "INFI A f \<le> f i" using `i \<in> A` by (rule INF_leI)
hoelzl@41973
  2303
  finally show "y < f i" .
hoelzl@41973
  2304
qed
hoelzl@41973
  2305
hoelzl@41973
  2306
lemma liminf_SUPR_INFI:
hoelzl@41973
  2307
  fixes f :: "nat \<Rightarrow> extreal"
hoelzl@41973
  2308
  shows "liminf f = (SUP n. INF m:{n..}. f m)"
hoelzl@41973
  2309
  unfolding Liminf_Sup eventually_sequentially
hoelzl@41973
  2310
proof (safe intro!: antisym complete_lattice_class.Sup_least)
hoelzl@41973
  2311
  fix x assume *: "\<forall>y<x. \<exists>N. \<forall>n\<ge>N. y < f n" show "x \<le> (SUP n. INF m:{n..}. f m)"
hoelzl@41973
  2312
  proof (rule extreal_le_extreal)
hoelzl@41973
  2313
    fix y assume "y < x"
hoelzl@41973
  2314
    with * obtain N where "\<And>n. N \<le> n \<Longrightarrow> y < f n" by auto
hoelzl@41973
  2315
    then have "y \<le> (INF m:{N..}. f m)" by (force simp: le_INF_iff)
hoelzl@41973
  2316
    also have "\<dots> \<le> (SUP n. INF m:{n..}. f m)" by (intro le_SUPI) auto
hoelzl@41973
  2317
    finally show "y \<le> (SUP n. INF m:{n..}. f m)" .
hoelzl@41973
  2318
  qed
hoelzl@41973
  2319
next
hoelzl@41973
  2320
  show "(SUP n. INF m:{n..}. f m) \<le> Sup {l. \<forall>y<l. \<exists>N. \<forall>n\<ge>N. y < f n}"
hoelzl@41973
  2321
  proof (unfold SUPR_def, safe intro!: Sup_mono bexI)
hoelzl@41973
  2322
    fix y n assume "y < INFI {n..} f"
hoelzl@41973
  2323
    from less_INFD[OF this] show "\<exists>N. \<forall>n\<ge>N. y < f n" by (intro exI[of _ n]) auto
hoelzl@41973
  2324
  qed (rule order_refl)
hoelzl@41973
  2325
qed
hoelzl@41973
  2326
hoelzl@41973
  2327
lemma limsup_INFI_SUPR:
hoelzl@41973
  2328
  fixes f :: "nat \<Rightarrow> extreal"
hoelzl@41973
  2329
  shows "limsup f = (INF n. SUP m:{n..}. f m)"
hoelzl@41973
  2330
  using extreal_Limsup_uminus[of sequentially "\<lambda>x. - f x"]
hoelzl@41973
  2331
  by (simp add: liminf_SUPR_INFI extreal_INFI_uminus extreal_SUPR_uminus)
hoelzl@41973
  2332
hoelzl@41973
  2333
lemma liminf_PInfty:
hoelzl@41973
  2334
  fixes X :: "nat => extreal"
hoelzl@41973
  2335
  shows "X ----> \<infinity> <-> liminf X = \<infinity>"
hoelzl@41973
  2336
by (metis Liminf_PInfty trivial_limit_sequentially)
hoelzl@41973
  2337
hoelzl@41973
  2338
lemma limsup_MInfty:
hoelzl@41973
  2339
  fixes X :: "nat => extreal"
hoelzl@41973
  2340
  shows "X ----> (-\<infinity>) <-> limsup X = (-\<infinity>)"
hoelzl@41973
  2341
by (metis Limsup_MInfty trivial_limit_sequentially)
hoelzl@41973
  2342
hoelzl@41973
  2343
lemma tail_same_limsup:
hoelzl@41973
  2344
  fixes X Y :: "nat => extreal"
hoelzl@41973
  2345
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n = Y n"
hoelzl@41973
  2346
  shows "limsup X = limsup Y"
hoelzl@41973
  2347
  using Limsup_eq[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2348
hoelzl@41973
  2349
lemma tail_same_liminf:
hoelzl@41973
  2350
  fixes X Y :: "nat => extreal"
hoelzl@41973
  2351
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n = Y n"
hoelzl@41973
  2352
  shows "liminf X = liminf Y"
hoelzl@41973
  2353
  using Liminf_eq[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2354
hoelzl@41973
  2355
lemma liminf_mono:
hoelzl@41973
  2356
  fixes X Y :: "nat \<Rightarrow> extreal"
hoelzl@41973
  2357
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n <= Y n"
hoelzl@41973
  2358
  shows "liminf X \<le> liminf Y"
hoelzl@41973
  2359
  using Liminf_mono[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2360
hoelzl@41973
  2361
lemma limsup_mono:
hoelzl@41973
  2362
  fixes X Y :: "nat => extreal"
hoelzl@41973
  2363
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n <= Y n"
hoelzl@41973
  2364
  shows "limsup X \<le> limsup Y"
hoelzl@41973
  2365
  using Limsup_mono[of X Y sequentially] eventually_sequentially assms by auto
hoelzl@41973
  2366
hoelzl@41973
  2367
declare trivial_limit_sequentially[simp]
hoelzl@41973
  2368
hoelzl@41973
  2369
lemma liminf_bounded:
hoelzl@41973
  2370
  fixes X Y :: "nat \<Rightarrow> extreal"
hoelzl@41973
  2371
  assumes "\<And>n. N \<le> n \<Longrightarrow> C \<le> X n"
hoelzl@41973
  2372
  shows "C \<le> liminf X"
hoelzl@41973
  2373
  using liminf_mono[of N "\<lambda>n. C" X] assms Liminf_const[of sequentially C] by simp
hoelzl@41973
  2374
hoelzl@41973
  2375
lemma limsup_bounded:
hoelzl@41973
  2376
  fixes X Y :: "nat => extreal"
hoelzl@41973
  2377
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n <= C"
hoelzl@41973
  2378
  shows "limsup X \<le> C"
hoelzl@41973
  2379
  using limsup_mono[of N X "\<lambda>n. C"] assms Limsup_const[of sequentially C] by simp
hoelzl@41973
  2380
hoelzl@41973
  2381
lemma liminf_bounded_iff:
hoelzl@41973
  2382
  fixes x :: "nat \<Rightarrow> extreal"
hoelzl@41973
  2383
  shows "C \<le> liminf x \<longleftrightarrow> (\<forall>B<C. \<exists>N. \<forall>n\<ge>N. B < x n)" (is "?lhs <-> ?rhs")
hoelzl@41973
  2384
proof safe
hoelzl@41973
  2385
  fix B assume "B < C" "C \<le> liminf x"
hoelzl@41973
  2386
  then have "B < liminf x" by auto
hoelzl@41973
  2387
  then obtain N where "B < (INF m:{N..}. x m)"
hoelzl@41973
  2388
    unfolding liminf_SUPR_INFI SUPR_def less_Sup_iff by auto
hoelzl@41973
  2389
  from less_INFD[OF this] show "\<exists>N. \<forall>n\<ge>N. B < x n" by auto
hoelzl@41973
  2390
next
hoelzl@41973
  2391
  assume *: "\<forall>B<C. \<exists>N. \<forall>n\<ge>N. B < x n"
hoelzl@41973
  2392
  { fix B assume "B<C"
hoelzl@41973
  2393
    then obtain N where "\<forall>n\<ge>N. B < x n" using `?rhs` by auto
hoelzl@41973
  2394
    hence "B \<le> (INF m:{N..}. x m)" by (intro le_INFI) auto
hoelzl@41973
  2395
    also have "... \<le> liminf x" unfolding liminf_SUPR_INFI by (intro le_SUPI) simp
hoelzl@41973
  2396
    finally have "B \<le> liminf x" .
hoelzl@41973
  2397
  } then show "?lhs" by (metis * leD liminf_bounded linorder_le_less_linear)
hoelzl@41973
  2398
qed
hoelzl@41973
  2399
hoelzl@41973
  2400
lemma liminf_bounded_open:
hoelzl@41973
  2401
  fixes x :: "nat \<Rightarrow> extreal"
hoelzl@41973
  2402
  shows "x0 \<le> liminf x \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> mono S \<longrightarrow> x0 \<in> S \<longrightarrow> (\<exists>N. \<forall>n\<ge>N. x n \<in> S))" 
hoelzl@41973
  2403
  (is "_ \<longleftrightarrow> ?P x0")
hoelzl@41973
  2404
proof
hoelzl@41973
  2405
  assume "?P x0" then show "x0 \<le> liminf x"
hoelzl@41973
  2406
    unfolding extreal_Liminf_Sup_monoset eventually_sequentially
hoelzl@41973
  2407
    by (intro complete_lattice_class.Sup_upper) auto
hoelzl@41973
  2408
next
hoelzl@41973
  2409
  assume "x0 \<le> liminf x"
hoelzl@41973
  2410
  { fix S :: "extreal set" assume om: "open S & mono S & x0:S"
hoelzl@41973
  2411
    { assume "S = UNIV" hence "EX N. (ALL n>=N. x n : S)" by auto }
hoelzl@41973
  2412
    moreover
hoelzl@41973
  2413
    { assume "~(S=UNIV)"
hoelzl@41973
  2414
      then obtain B where B_def: "S = {B<..}" using om extreal_open_mono_set by auto
hoelzl@41973
  2415
      hence "B<x0" using om by auto
hoelzl@41973
  2416
      hence "EX N. ALL n>=N. x n : S" unfolding B_def using `x0 \<le> liminf x` liminf_bounded_iff by auto
hoelzl@41973
  2417
    } ultimately have "EX N. (ALL n>=N. x n : S)" by auto
hoelzl@41973
  2418
  } then show "?P x0" by auto
hoelzl@41973
  2419
qed
hoelzl@41973
  2420
hoelzl@41973
  2421
hoelzl@41973
  2422
lemma extreal_lim_mono:
hoelzl@41973
  2423
  fixes X Y :: "nat => extreal"
hoelzl@41973
  2424
  assumes "\<And>n. N \<le> n \<Longrightarrow> X n <= Y n"
hoelzl@41973
  2425
  assumes "X ----> x" "Y ----> y"
hoelzl@41973
  2426
  shows "x <= y"
hoelzl@41973
  2427
  by (metis extreal_Liminf_eq_Limsup_iff[OF trivial_limit_sequentially] assms liminf_mono)
hoelzl@41973
  2428
hoelzl@41973
  2429
lemma liminf_subseq_mono:
hoelzl@41973
  2430
  fixes X :: "nat \<Rightarrow> extreal"