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