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