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