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