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