src/HOL/Library/Extended_Real.thy
author hoelzl
Thu, 13 Nov 2014 17:19:52 +0100
changeset 59000 6eb0725503fc
parent 58881 b9556a055632
child 59002 2c8b2fb54b88
permissions -rw-r--r--
import general theorems from AFP/Markov_Models
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
     1
(*  Title:      HOL/Library/Extended_Real.thy
41983
2dc6e382a58b standardized headers;
wenzelm
parents: 41980
diff changeset
     2
    Author:     Johannes Hölzl, TU München
2dc6e382a58b standardized headers;
wenzelm
parents: 41980
diff changeset
     3
    Author:     Robert Himmelmann, TU München
2dc6e382a58b standardized headers;
wenzelm
parents: 41980
diff changeset
     4
    Author:     Armin Heller, TU München
2dc6e382a58b standardized headers;
wenzelm
parents: 41980
diff changeset
     5
    Author:     Bogdan Grechuk, University of Edinburgh
2dc6e382a58b standardized headers;
wenzelm
parents: 41980
diff changeset
     6
*)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
     7
58881
b9556a055632 modernized header;
wenzelm
parents: 58787
diff changeset
     8
section {* Extended real number line *}
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
     9
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
    10
theory Extended_Real
51340
5e6296afe08d move Liminf / Limsup lemmas on complete_lattices to its own file
hoelzl
parents: 51329
diff changeset
    11
imports Complex_Main Extended_Nat Liminf_Limsup
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    12
begin
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    13
51022
78de6c7e8a58 replace open_interval with the rule open_tendstoI; generalize Liminf/Limsup rules
hoelzl
parents: 51000
diff changeset
    14
text {*
78de6c7e8a58 replace open_interval with the rule open_tendstoI; generalize Liminf/Limsup rules
hoelzl
parents: 51000
diff changeset
    15
78de6c7e8a58 replace open_interval with the rule open_tendstoI; generalize Liminf/Limsup rules
hoelzl
parents: 51000
diff changeset
    16
For more lemmas about the extended real numbers go to
78de6c7e8a58 replace open_interval with the rule open_tendstoI; generalize Liminf/Limsup rules
hoelzl
parents: 51000
diff changeset
    17
  @{file "~~/src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy"}
78de6c7e8a58 replace open_interval with the rule open_tendstoI; generalize Liminf/Limsup rules
hoelzl
parents: 51000
diff changeset
    18
78de6c7e8a58 replace open_interval with the rule open_tendstoI; generalize Liminf/Limsup rules
hoelzl
parents: 51000
diff changeset
    19
*}
78de6c7e8a58 replace open_interval with the rule open_tendstoI; generalize Liminf/Limsup rules
hoelzl
parents: 51000
diff changeset
    20
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    21
subsection {* Definition and basic properties *}
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    22
58310
91ea607a34d8 updated news
blanchet
parents: 58249
diff changeset
    23
datatype ereal = ereal real | PInfty | MInfty
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    24
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
    25
instantiation ereal :: uminus
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    26
begin
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    27
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    28
fun uminus_ereal where
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    29
  "- (ereal r) = ereal (- r)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    30
| "- PInfty = MInfty"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    31
| "- MInfty = PInfty"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    32
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    33
instance ..
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    34
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    35
end
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    36
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    37
instantiation ereal :: infinity
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    38
begin
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    39
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    40
definition "(\<infinity>::ereal) = PInfty"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    41
instance ..
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    42
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    43
end
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    44
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    45
declare [[coercion "ereal :: real \<Rightarrow> ereal"]]
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    46
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
    47
lemma ereal_uminus_uminus[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    48
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    49
  shows "- (- a) = a"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    50
  by (cases a) simp_all
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    51
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    52
lemma
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    53
  shows PInfty_eq_infinity[simp]: "PInfty = \<infinity>"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    54
    and MInfty_eq_minfinity[simp]: "MInfty = - \<infinity>"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    55
    and MInfty_neq_PInfty[simp]: "\<infinity> \<noteq> - (\<infinity>::ereal)" "- \<infinity> \<noteq> (\<infinity>::ereal)"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    56
    and MInfty_neq_ereal[simp]: "ereal r \<noteq> - \<infinity>" "- \<infinity> \<noteq> ereal r"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    57
    and PInfty_neq_ereal[simp]: "ereal r \<noteq> \<infinity>" "\<infinity> \<noteq> ereal r"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    58
    and PInfty_cases[simp]: "(case \<infinity> of ereal r \<Rightarrow> f r | PInfty \<Rightarrow> y | MInfty \<Rightarrow> z) = y"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    59
    and MInfty_cases[simp]: "(case - \<infinity> of ereal r \<Rightarrow> f r | PInfty \<Rightarrow> y | MInfty \<Rightarrow> z) = z"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    60
  by (simp_all add: infinity_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    61
43933
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    62
declare
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    63
  PInfty_eq_infinity[code_post]
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    64
  MInfty_eq_minfinity[code_post]
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    65
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    66
lemma [code_unfold]:
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    67
  "\<infinity> = PInfty"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    68
  "- PInfty = MInfty"
43933
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    69
  by simp_all
6cc1875cf35d add code generator setup and tests for ereal
hoelzl
parents: 43924
diff changeset
    70
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    71
lemma inj_ereal[simp]: "inj_on ereal A"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
    72
  unfolding inj_on_def by auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    73
55913
c1409c103b77 proper UTF-8;
wenzelm
parents: 54863
diff changeset
    74
lemma ereal_cases[cases type: ereal]:
c1409c103b77 proper UTF-8;
wenzelm
parents: 54863
diff changeset
    75
  obtains (real) r where "x = ereal r"
c1409c103b77 proper UTF-8;
wenzelm
parents: 54863
diff changeset
    76
    | (PInf) "x = \<infinity>"
c1409c103b77 proper UTF-8;
wenzelm
parents: 54863
diff changeset
    77
    | (MInf) "x = -\<infinity>"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    78
  using assms by (cases x) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    79
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
    80
lemmas ereal2_cases = ereal_cases[case_product ereal_cases]
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
    81
lemmas ereal3_cases = ereal2_cases[case_product ereal_cases]
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    82
57447
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57025
diff changeset
    83
lemma ereal_all_split: "\<And>P. (\<forall>x::ereal. P x) \<longleftrightarrow> P \<infinity> \<and> (\<forall>x. P (ereal x)) \<and> P (-\<infinity>)"
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57025
diff changeset
    84
  by (metis ereal_cases)
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57025
diff changeset
    85
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57025
diff changeset
    86
lemma ereal_ex_split: "\<And>P. (\<exists>x::ereal. P x) \<longleftrightarrow> P \<infinity> \<or> (\<exists>x. P (ereal x)) \<or> P (-\<infinity>)"
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57025
diff changeset
    87
  by (metis ereal_cases)
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57025
diff changeset
    88
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
    89
lemma ereal_uminus_eq_iff[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    90
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
    91
  shows "-a = -b \<longleftrightarrow> a = b"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
    92
  by (cases rule: ereal2_cases[of a b]) simp_all
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
    93
58042
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
    94
instantiation ereal :: real_of
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
    95
begin
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
    96
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
    97
function real_ereal :: "ereal \<Rightarrow> real" where
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
    98
  "real_ereal (ereal r) = r"
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
    99
| "real_ereal \<infinity> = 0"
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
   100
| "real_ereal (-\<infinity>) = 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   101
  by (auto intro: ereal_cases)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   102
termination by default (rule wf_empty)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   103
58042
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
   104
instance ..
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
   105
end
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   106
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   107
lemma real_of_ereal[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   108
  "real (- x :: ereal) = - (real x)"
58042
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
   109
  by (cases x) simp_all
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   110
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   111
lemma range_ereal[simp]: "range ereal = UNIV - {\<infinity>, -\<infinity>}"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   112
proof safe
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   113
  fix x
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   114
  assume "x \<notin> range ereal" "x \<noteq> \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   115
  then show "x = -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   116
    by (cases x) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   117
qed auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   118
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   119
lemma ereal_range_uminus[simp]: "range uminus = (UNIV::ereal set)"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   120
proof safe
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   121
  fix x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   122
  show "x \<in> range uminus"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   123
    by (intro image_eqI[of _ _ "-x"]) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   124
qed auto
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   125
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   126
instantiation ereal :: abs
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   127
begin
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   128
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   129
function abs_ereal where
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   130
  "\<bar>ereal r\<bar> = ereal \<bar>r\<bar>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   131
| "\<bar>-\<infinity>\<bar> = (\<infinity>::ereal)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   132
| "\<bar>\<infinity>\<bar> = (\<infinity>::ereal)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   133
by (auto intro: ereal_cases)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   134
termination proof qed (rule wf_empty)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   135
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   136
instance ..
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   137
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   138
end
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   139
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   140
lemma abs_eq_infinity_cases[elim!]:
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   141
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   142
  assumes "\<bar>x\<bar> = \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   143
  obtains "x = \<infinity>" | "x = -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   144
  using assms by (cases x) auto
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   145
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   146
lemma abs_neq_infinity_cases[elim!]:
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   147
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   148
  assumes "\<bar>x\<bar> \<noteq> \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   149
  obtains r where "x = ereal r"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   150
  using assms by (cases x) auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   151
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   152
lemma abs_ereal_uminus[simp]:
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   153
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   154
  shows "\<bar>- x\<bar> = \<bar>x\<bar>"
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   155
  by (cases x) auto
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   156
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   157
lemma ereal_infinity_cases:
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   158
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   159
  shows "a \<noteq> \<infinity> \<Longrightarrow> a \<noteq> -\<infinity> \<Longrightarrow> \<bar>a\<bar> \<noteq> \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   160
  by auto
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   161
50104
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   162
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   163
subsubsection "Addition"
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   164
54408
67dec4ccaabd equation when indicator function equals 0 or 1
hoelzl
parents: 53873
diff changeset
   165
instantiation ereal :: "{one,comm_monoid_add,zero_neq_one}"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   166
begin
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   167
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   168
definition "0 = ereal 0"
51351
dd1dd470690b generalized lemmas in Extended_Real_Limits
hoelzl
parents: 51340
diff changeset
   169
definition "1 = ereal 1"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   170
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   171
function plus_ereal where
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   172
  "ereal r + ereal p = ereal (r + p)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   173
| "\<infinity> + a = (\<infinity>::ereal)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   174
| "a + \<infinity> = (\<infinity>::ereal)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   175
| "ereal r + -\<infinity> = - \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   176
| "-\<infinity> + ereal p = -(\<infinity>::ereal)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   177
| "-\<infinity> + -\<infinity> = -(\<infinity>::ereal)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   178
proof -
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   179
  case (goal1 P x)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   180
  then obtain a b where "x = (a, b)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   181
    by (cases x) auto
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53216
diff changeset
   182
  with goal1 show P
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   183
   by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   184
qed auto
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53216
diff changeset
   185
termination by default (rule wf_empty)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   186
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   187
lemma Infty_neq_0[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   188
  "(\<infinity>::ereal) \<noteq> 0" "0 \<noteq> (\<infinity>::ereal)"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   189
  "-(\<infinity>::ereal) \<noteq> 0" "0 \<noteq> -(\<infinity>::ereal)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   190
  by (simp_all add: zero_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   191
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   192
lemma ereal_eq_0[simp]:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   193
  "ereal r = 0 \<longleftrightarrow> r = 0"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   194
  "0 = ereal r \<longleftrightarrow> r = 0"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   195
  unfolding zero_ereal_def by simp_all
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   196
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   197
lemma ereal_eq_1[simp]:
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   198
  "ereal r = 1 \<longleftrightarrow> r = 1"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   199
  "1 = ereal r \<longleftrightarrow> r = 1"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   200
  unfolding one_ereal_def by simp_all
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   201
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   202
instance
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   203
proof
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   204
  fix a b c :: ereal
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   205
  show "0 + a = a"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   206
    by (cases a) (simp_all add: zero_ereal_def)
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   207
  show "a + b = b + a"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   208
    by (cases rule: ereal2_cases[of a b]) simp_all
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   209
  show "a + b + c = a + (b + c)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   210
    by (cases rule: ereal3_cases[of a b c]) simp_all
54408
67dec4ccaabd equation when indicator function equals 0 or 1
hoelzl
parents: 53873
diff changeset
   211
  show "0 \<noteq> (1::ereal)"
67dec4ccaabd equation when indicator function equals 0 or 1
hoelzl
parents: 53873
diff changeset
   212
    by (simp add: one_ereal_def zero_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   213
qed
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   214
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   215
end
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   216
51351
dd1dd470690b generalized lemmas in Extended_Real_Limits
hoelzl
parents: 51340
diff changeset
   217
instance ereal :: numeral ..
dd1dd470690b generalized lemmas in Extended_Real_Limits
hoelzl
parents: 51340
diff changeset
   218
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   219
lemma real_of_ereal_0[simp]: "real (0::ereal) = 0"
58042
ffa9e39763e3 introduce real_of typeclass for real :: 'a => real
hoelzl
parents: 57512
diff changeset
   220
  unfolding zero_ereal_def by simp
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   221
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   222
lemma abs_ereal_zero[simp]: "\<bar>0\<bar> = (0::ereal)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   223
  unfolding zero_ereal_def abs_ereal.simps by simp
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   224
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   225
lemma ereal_uminus_zero[simp]: "- 0 = (0::ereal)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   226
  by (simp add: zero_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   227
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   228
lemma ereal_uminus_zero_iff[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   229
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   230
  shows "-a = 0 \<longleftrightarrow> a = 0"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   231
  by (cases a) simp_all
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   232
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   233
lemma ereal_plus_eq_PInfty[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   234
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   235
  shows "a + b = \<infinity> \<longleftrightarrow> a = \<infinity> \<or> b = \<infinity>"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   236
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   237
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   238
lemma ereal_plus_eq_MInfty[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   239
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   240
  shows "a + b = -\<infinity> \<longleftrightarrow> (a = -\<infinity> \<or> b = -\<infinity>) \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   241
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   242
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   243
lemma ereal_add_cancel_left:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   244
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   245
  assumes "a \<noteq> -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   246
  shows "a + b = a + c \<longleftrightarrow> a = \<infinity> \<or> b = c"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   247
  using assms by (cases rule: ereal3_cases[of a b c]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   248
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   249
lemma ereal_add_cancel_right:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   250
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   251
  assumes "a \<noteq> -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   252
  shows "b + a = c + a \<longleftrightarrow> a = \<infinity> \<or> b = c"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   253
  using assms by (cases rule: ereal3_cases[of a b c]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   254
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   255
lemma ereal_real: "ereal (real x) = (if \<bar>x\<bar> = \<infinity> then 0 else x)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   256
  by (cases x) simp_all
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   257
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   258
lemma real_of_ereal_add:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   259
  fixes a b :: ereal
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   260
  shows "real (a + b) =
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   261
    (if (\<bar>a\<bar> = \<infinity>) \<and> (\<bar>b\<bar> = \<infinity>) \<or> (\<bar>a\<bar> \<noteq> \<infinity>) \<and> (\<bar>b\<bar> \<noteq> \<infinity>) then real a + real b else 0)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   262
  by (cases rule: ereal2_cases[of a b]) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   263
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   264
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   265
subsubsection "Linear order on @{typ ereal}"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   266
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   267
instantiation ereal :: linorder
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   268
begin
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   269
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   270
function less_ereal
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   271
where
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   272
  "   ereal x < ereal y     \<longleftrightarrow> x < y"
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   273
| "(\<infinity>::ereal) < a           \<longleftrightarrow> False"
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   274
| "         a < -(\<infinity>::ereal) \<longleftrightarrow> False"
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   275
| "ereal x    < \<infinity>           \<longleftrightarrow> True"
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   276
| "        -\<infinity> < ereal r     \<longleftrightarrow> True"
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   277
| "        -\<infinity> < (\<infinity>::ereal) \<longleftrightarrow> True"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   278
proof -
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   279
  case (goal1 P x)
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53216
diff changeset
   280
  then obtain a b where "x = (a,b)" by (cases x) auto
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53216
diff changeset
   281
  with goal1 show P by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   282
qed simp_all
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   283
termination by (relation "{}") simp
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   284
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   285
definition "x \<le> (y::ereal) \<longleftrightarrow> x < y \<or> x = y"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   286
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   287
lemma ereal_infty_less[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   288
  fixes x :: ereal
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   289
  shows "x < \<infinity> \<longleftrightarrow> (x \<noteq> \<infinity>)"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   290
    "-\<infinity> < x \<longleftrightarrow> (x \<noteq> -\<infinity>)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   291
  by (cases x, simp_all) (cases x, simp_all)
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   292
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   293
lemma ereal_infty_less_eq[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   294
  fixes x :: ereal
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   295
  shows "\<infinity> \<le> x \<longleftrightarrow> x = \<infinity>"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   296
    and "x \<le> -\<infinity> \<longleftrightarrow> x = -\<infinity>"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   297
  by (auto simp add: less_eq_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   298
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   299
lemma ereal_less[simp]:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   300
  "ereal r < 0 \<longleftrightarrow> (r < 0)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   301
  "0 < ereal r \<longleftrightarrow> (0 < r)"
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   302
  "ereal r < 1 \<longleftrightarrow> (r < 1)"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   303
  "1 < ereal r \<longleftrightarrow> (1 < r)"
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   304
  "0 < (\<infinity>::ereal)"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   305
  "-(\<infinity>::ereal) < 0"
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   306
  by (simp_all add: zero_ereal_def one_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   307
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   308
lemma ereal_less_eq[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   309
  "x \<le> (\<infinity>::ereal)"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   310
  "-(\<infinity>::ereal) \<le> x"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   311
  "ereal r \<le> ereal p \<longleftrightarrow> r \<le> p"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   312
  "ereal r \<le> 0 \<longleftrightarrow> r \<le> 0"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   313
  "0 \<le> ereal r \<longleftrightarrow> 0 \<le> r"
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   314
  "ereal r \<le> 1 \<longleftrightarrow> r \<le> 1"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   315
  "1 \<le> ereal r \<longleftrightarrow> 1 \<le> r"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   316
  by (auto simp add: less_eq_ereal_def zero_ereal_def one_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   317
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   318
lemma ereal_infty_less_eq2:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   319
  "a \<le> b \<Longrightarrow> a = \<infinity> \<Longrightarrow> b = (\<infinity>::ereal)"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   320
  "a \<le> b \<Longrightarrow> b = -\<infinity> \<Longrightarrow> a = -(\<infinity>::ereal)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   321
  by simp_all
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   322
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   323
instance
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   324
proof
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   325
  fix x y z :: ereal
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   326
  show "x \<le> x"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   327
    by (cases x) simp_all
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   328
  show "x < y \<longleftrightarrow> x \<le> y \<and> \<not> y \<le> x"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   329
    by (cases rule: ereal2_cases[of x y]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   330
  show "x \<le> y \<or> y \<le> x "
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   331
    by (cases rule: ereal2_cases[of x y]) auto
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   332
  {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   333
    assume "x \<le> y" "y \<le> x"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   334
    then show "x = y"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   335
      by (cases rule: ereal2_cases[of x y]) auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   336
  }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   337
  {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   338
    assume "x \<le> y" "y \<le> z"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   339
    then show "x \<le> z"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   340
      by (cases rule: ereal3_cases[of x y z]) auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   341
  }
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   342
qed
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   343
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   344
end
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   345
51329
4a3c453f99a1 split dense into inner_dense_order and no_top/no_bot
hoelzl
parents: 51328
diff changeset
   346
lemma ereal_dense2: "x < y \<Longrightarrow> \<exists>z. x < ereal z \<and> ereal z < y"
4a3c453f99a1 split dense into inner_dense_order and no_top/no_bot
hoelzl
parents: 51328
diff changeset
   347
  using lt_ex gt_ex dense by (cases x y rule: ereal2_cases) auto
4a3c453f99a1 split dense into inner_dense_order and no_top/no_bot
hoelzl
parents: 51328
diff changeset
   348
53216
ad2e09c30aa8 renamed inner_dense_linorder to dense_linorder
hoelzl
parents: 52729
diff changeset
   349
instance ereal :: dense_linorder
51329
4a3c453f99a1 split dense into inner_dense_order and no_top/no_bot
hoelzl
parents: 51328
diff changeset
   350
  by default (blast dest: ereal_dense2)
4a3c453f99a1 split dense into inner_dense_order and no_top/no_bot
hoelzl
parents: 51328
diff changeset
   351
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   352
instance ereal :: ordered_ab_semigroup_add
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   353
proof
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   354
  fix a b c :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   355
  assume "a \<le> b"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   356
  then show "c + a \<le> c + b"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   357
    by (cases rule: ereal3_cases[of a b c]) auto
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   358
qed
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   359
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   360
lemma real_of_ereal_positive_mono:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   361
  fixes x y :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   362
  shows "0 \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<noteq> \<infinity> \<Longrightarrow> real x \<le> real y"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   363
  by (cases rule: ereal2_cases[of x y]) auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   364
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   365
lemma ereal_MInfty_lessI[intro, simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   366
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   367
  shows "a \<noteq> -\<infinity> \<Longrightarrow> -\<infinity> < a"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   368
  by (cases a) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   369
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   370
lemma ereal_less_PInfty[intro, simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   371
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   372
  shows "a \<noteq> \<infinity> \<Longrightarrow> a < \<infinity>"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   373
  by (cases a) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   374
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   375
lemma ereal_less_ereal_Ex:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   376
  fixes a b :: ereal
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   377
  shows "x < ereal r \<longleftrightarrow> x = -\<infinity> \<or> (\<exists>p. p < r \<and> x = ereal p)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   378
  by (cases x) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   379
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   380
lemma less_PInf_Ex_of_nat: "x \<noteq> \<infinity> \<longleftrightarrow> (\<exists>n::nat. x < ereal (real n))"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   381
proof (cases x)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   382
  case (real r)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   383
  then show ?thesis
41980
28b51effc5ed split Extended_Reals into parts for Library and Multivariate_Analysis
hoelzl
parents: 41979
diff changeset
   384
    using reals_Archimedean2[of r] by simp
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   385
qed simp_all
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   386
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   387
lemma ereal_add_mono:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   388
  fixes a b c d :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   389
  assumes "a \<le> b"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   390
    and "c \<le> d"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   391
  shows "a + c \<le> b + d"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   392
  using assms
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   393
  apply (cases a)
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   394
  apply (cases rule: ereal3_cases[of b c d], auto)
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   395
  apply (cases rule: ereal3_cases[of b c d], auto)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   396
  done
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   397
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   398
lemma ereal_minus_le_minus[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   399
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   400
  shows "- a \<le> - b \<longleftrightarrow> b \<le> a"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   401
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   402
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   403
lemma ereal_minus_less_minus[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   404
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   405
  shows "- a < - b \<longleftrightarrow> b < a"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   406
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   407
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   408
lemma ereal_le_real_iff:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   409
  "x \<le> real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x \<le> y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x \<le> 0)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   410
  by (cases y) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   411
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   412
lemma real_le_ereal_iff:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   413
  "real y \<le> x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y \<le> ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 \<le> x)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   414
  by (cases y) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   415
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   416
lemma ereal_less_real_iff:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   417
  "x < real y \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> ereal x < y) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> x < 0)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   418
  by (cases y) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   419
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   420
lemma real_less_ereal_iff:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   421
  "real y < x \<longleftrightarrow> (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> y < ereal x) \<and> (\<bar>y\<bar> = \<infinity> \<longrightarrow> 0 < x)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   422
  by (cases y) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   423
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   424
lemma real_of_ereal_pos:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   425
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   426
  shows "0 \<le> x \<Longrightarrow> 0 \<le> real x" by (cases x) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   427
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   428
lemmas real_of_ereal_ord_simps =
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   429
  ereal_le_real_iff real_le_ereal_iff ereal_less_real_iff real_less_ereal_iff
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   430
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   431
lemma abs_ereal_ge0[simp]: "0 \<le> x \<Longrightarrow> \<bar>x :: ereal\<bar> = x"
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   432
  by (cases x) auto
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   433
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   434
lemma abs_ereal_less0[simp]: "x < 0 \<Longrightarrow> \<bar>x :: ereal\<bar> = -x"
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   435
  by (cases x) auto
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   436
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   437
lemma abs_ereal_pos[simp]: "0 \<le> \<bar>x :: ereal\<bar>"
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   438
  by (cases x) auto
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   439
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   440
lemma real_of_ereal_le_0[simp]: "real (x :: ereal) \<le> 0 \<longleftrightarrow> x \<le> 0 \<or> x = \<infinity>"
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   441
  by (cases x) auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   442
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   443
lemma abs_real_of_ereal[simp]: "\<bar>real (x :: ereal)\<bar> = real \<bar>x\<bar>"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   444
  by (cases x) auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   445
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   446
lemma zero_less_real_of_ereal:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   447
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   448
  shows "0 < real x \<longleftrightarrow> 0 < x \<and> x \<noteq> \<infinity>"
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   449
  by (cases x) auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   450
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   451
lemma ereal_0_le_uminus_iff[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   452
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   453
  shows "0 \<le> - a \<longleftrightarrow> a \<le> 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   454
  by (cases rule: ereal2_cases[of a]) auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   455
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   456
lemma ereal_uminus_le_0_iff[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   457
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   458
  shows "- a \<le> 0 \<longleftrightarrow> 0 \<le> a"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   459
  by (cases rule: ereal2_cases[of a]) auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   460
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   461
lemma ereal_add_strict_mono:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   462
  fixes a b c d :: ereal
56993
e5366291d6aa introduce Bochner integral: generalizes Lebesgue integral from real-valued function to functions on real-normed vector spaces
hoelzl
parents: 56927
diff changeset
   463
  assumes "a \<le> b"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   464
    and "0 \<le> a"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   465
    and "a \<noteq> \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   466
    and "c < d"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   467
  shows "a + c < b + d"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   468
  using assms
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   469
  by (cases rule: ereal3_cases[case_product ereal_cases, of a b c d]) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   470
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   471
lemma ereal_less_add:
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   472
  fixes a b c :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   473
  shows "\<bar>a\<bar> \<noteq> \<infinity> \<Longrightarrow> c < b \<Longrightarrow> a + c < a + b"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   474
  by (cases rule: ereal2_cases[of b c]) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   475
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   476
lemma ereal_add_nonneg_eq_0_iff:
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   477
  fixes a b :: ereal
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   478
  shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> a + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   479
  by (cases a b rule: ereal2_cases) auto
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   480
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   481
lemma ereal_uminus_eq_reorder: "- a = b \<longleftrightarrow> a = (-b::ereal)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   482
  by auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   483
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   484
lemma ereal_uminus_less_reorder: "- a < b \<longleftrightarrow> -b < (a::ereal)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   485
  by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_less_minus)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   486
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   487
lemma ereal_uminus_le_reorder: "- a \<le> b \<longleftrightarrow> -b \<le> (a::ereal)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   488
  by (subst (3) ereal_uminus_uminus[symmetric]) (simp only: ereal_minus_le_minus)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   489
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   490
lemmas ereal_uminus_reorder =
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   491
  ereal_uminus_eq_reorder ereal_uminus_less_reorder ereal_uminus_le_reorder
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   492
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   493
lemma ereal_bot:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   494
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   495
  assumes "\<And>B. x \<le> ereal B"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   496
  shows "x = - \<infinity>"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   497
proof (cases x)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   498
  case (real r)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   499
  with assms[of "r - 1"] show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   500
    by auto
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   501
next
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   502
  case PInf
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   503
  with assms[of 0] show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   504
    by auto
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   505
next
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   506
  case MInf
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   507
  then show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   508
    by simp
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   509
qed
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   510
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   511
lemma ereal_top:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   512
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   513
  assumes "\<And>B. x \<ge> ereal B"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   514
  shows "x = \<infinity>"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   515
proof (cases x)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   516
  case (real r)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   517
  with assms[of "r + 1"] show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   518
    by auto
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   519
next
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   520
  case MInf
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   521
  with assms[of 0] show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   522
    by auto
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   523
next
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   524
  case PInf
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   525
  then show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   526
    by simp
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   527
qed
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   528
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   529
lemma
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   530
  shows ereal_max[simp]: "ereal (max x y) = max (ereal x) (ereal y)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   531
    and ereal_min[simp]: "ereal (min x y) = min (ereal x) (ereal y)"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   532
  by (simp_all add: min_def max_def)
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   533
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   534
lemma ereal_max_0: "max 0 (ereal r) = ereal (max 0 r)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   535
  by (auto simp: zero_ereal_def)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   536
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   537
lemma
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   538
  fixes f :: "nat \<Rightarrow> ereal"
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   539
  shows ereal_incseq_uminus[simp]: "incseq (\<lambda>x. - f x) \<longleftrightarrow> decseq f"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   540
    and ereal_decseq_uminus[simp]: "decseq (\<lambda>x. - f x) \<longleftrightarrow> incseq f"
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   541
  unfolding decseq_def incseq_def by auto
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   542
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   543
lemma incseq_ereal: "incseq f \<Longrightarrow> incseq (\<lambda>x. ereal (f x))"
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   544
  unfolding incseq_def by auto
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   545
56537
01caba82e1d2 made ereal_add_nonneg_nonneg a simp rule
nipkow
parents: 56536
diff changeset
   546
lemma ereal_add_nonneg_nonneg[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   547
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   548
  shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a + b"
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   549
  using add_mono[of 0 a 0 b] by simp
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   550
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   551
lemma image_eqD: "f ` A = B \<Longrightarrow> \<forall>x\<in>A. f x \<in> B"
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   552
  by auto
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   553
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   554
lemma incseq_setsumI:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   555
  fixes f :: "nat \<Rightarrow> 'a::{comm_monoid_add,ordered_ab_semigroup_add}"
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   556
  assumes "\<And>i. 0 \<le> f i"
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   557
  shows "incseq (\<lambda>i. setsum f {..< i})"
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   558
proof (intro incseq_SucI)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   559
  fix n
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   560
  have "setsum f {..< n} + 0 \<le> setsum f {..<n} + f n"
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   561
    using assms by (rule add_left_mono)
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   562
  then show "setsum f {..< n} \<le> setsum f {..< Suc n}"
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   563
    by auto
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   564
qed
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   565
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   566
lemma incseq_setsumI2:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   567
  fixes f :: "'i \<Rightarrow> nat \<Rightarrow> 'a::{comm_monoid_add,ordered_ab_semigroup_add}"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   568
  assumes "\<And>n. n \<in> A \<Longrightarrow> incseq (f n)"
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   569
  shows "incseq (\<lambda>i. \<Sum>n\<in>A. f n i)"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   570
  using assms
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   571
  unfolding incseq_def by (auto intro: setsum_mono)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   572
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   573
lemma setsum_ereal[simp]: "(\<Sum>x\<in>A. ereal (f x)) = ereal (\<Sum>x\<in>A. f x)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   574
proof (cases "finite A")
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   575
  case True
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   576
  then show ?thesis by induct auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   577
next
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   578
  case False
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   579
  then show ?thesis by simp
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   580
qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   581
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   582
lemma setsum_Pinfty:
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   583
  fixes f :: "'a \<Rightarrow> ereal"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   584
  shows "(\<Sum>x\<in>P. f x) = \<infinity> \<longleftrightarrow> finite P \<and> (\<exists>i\<in>P. f i = \<infinity>)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   585
proof safe
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   586
  assume *: "setsum f P = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   587
  show "finite P"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   588
  proof (rule ccontr)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   589
    assume "\<not> finite P"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   590
    with * show False
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   591
      by auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   592
  qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   593
  show "\<exists>i\<in>P. f i = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   594
  proof (rule ccontr)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   595
    assume "\<not> ?thesis"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   596
    then have "\<And>i. i \<in> P \<Longrightarrow> f i \<noteq> \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   597
      by auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   598
    with `finite P` have "setsum f P \<noteq> \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   599
      by induct auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   600
    with * show False
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   601
      by auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   602
  qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   603
next
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   604
  fix i
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   605
  assume "finite P" and "i \<in> P" and "f i = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   606
  then show "setsum f P = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   607
  proof induct
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   608
    case (insert x A)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   609
    show ?case using insert by (cases "x = i") auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   610
  qed simp
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   611
qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   612
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   613
lemma setsum_Inf:
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   614
  fixes f :: "'a \<Rightarrow> ereal"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   615
  shows "\<bar>setsum f A\<bar> = \<infinity> \<longleftrightarrow> finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   616
proof
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   617
  assume *: "\<bar>setsum f A\<bar> = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   618
  have "finite A"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   619
    by (rule ccontr) (insert *, auto)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   620
  moreover have "\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   621
  proof (rule ccontr)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   622
    assume "\<not> ?thesis"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   623
    then have "\<forall>i\<in>A. \<exists>r. f i = ereal r"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   624
      by auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   625
    from bchoice[OF this] obtain r where "\<forall>x\<in>A. f x = ereal (r x)" ..
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   626
    with * show False
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   627
      by auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   628
  qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   629
  ultimately show "finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   630
    by auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   631
next
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   632
  assume "finite A \<and> (\<exists>i\<in>A. \<bar>f i\<bar> = \<infinity>)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   633
  then obtain i where "finite A" "i \<in> A" and "\<bar>f i\<bar> = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   634
    by auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   635
  then show "\<bar>setsum f A\<bar> = \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   636
  proof induct
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   637
    case (insert j A)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   638
    then show ?case
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   639
      by (cases rule: ereal3_cases[of "f i" "f j" "setsum f A"]) auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   640
  qed simp
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   641
qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   642
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   643
lemma setsum_real_of_ereal:
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   644
  fixes f :: "'i \<Rightarrow> ereal"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   645
  assumes "\<And>x. x \<in> S \<Longrightarrow> \<bar>f x\<bar> \<noteq> \<infinity>"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   646
  shows "(\<Sum>x\<in>S. real (f x)) = real (setsum f S)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   647
proof -
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   648
  have "\<forall>x\<in>S. \<exists>r. f x = ereal r"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   649
  proof
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   650
    fix x
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   651
    assume "x \<in> S"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   652
    from assms[OF this] show "\<exists>r. f x = ereal r"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   653
      by (cases "f x") auto
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   654
  qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   655
  from bchoice[OF this] obtain r where "\<forall>x\<in>S. f x = ereal (r x)" ..
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   656
  then show ?thesis
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   657
    by simp
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   658
qed
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   659
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   660
lemma setsum_ereal_0:
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   661
  fixes f :: "'a \<Rightarrow> ereal"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   662
  assumes "finite A"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   663
    and "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   664
  shows "(\<Sum>x\<in>A. f x) = 0 \<longleftrightarrow> (\<forall>i\<in>A. f i = 0)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   665
proof
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   666
  assume "setsum f A = 0" with assms show "\<forall>i\<in>A. f i = 0"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   667
  proof (induction A)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   668
    case (insert a A)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   669
    then have "f a = 0 \<and> (\<Sum>a\<in>A. f a) = 0"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   670
      by (subst ereal_add_nonneg_eq_0_iff[symmetric]) (simp_all add: setsum_nonneg)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   671
    with insert show ?case
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   672
      by simp
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   673
  qed simp
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   674
qed auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   675
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   676
subsubsection "Multiplication"
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   677
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   678
instantiation ereal :: "{comm_monoid_mult,sgn}"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   679
begin
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   680
51351
dd1dd470690b generalized lemmas in Extended_Real_Limits
hoelzl
parents: 51340
diff changeset
   681
function sgn_ereal :: "ereal \<Rightarrow> ereal" where
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   682
  "sgn (ereal r) = ereal (sgn r)"
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   683
| "sgn (\<infinity>::ereal) = 1"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   684
| "sgn (-\<infinity>::ereal) = -1"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   685
by (auto intro: ereal_cases)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   686
termination by default (rule wf_empty)
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   687
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   688
function times_ereal where
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   689
  "ereal r * ereal p = ereal (r * p)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   690
| "ereal r * \<infinity> = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   691
| "\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then \<infinity> else -\<infinity>)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   692
| "ereal r * -\<infinity> = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   693
| "-\<infinity> * ereal r = (if r = 0 then 0 else if r > 0 then -\<infinity> else \<infinity>)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   694
| "(\<infinity>::ereal) * \<infinity> = \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   695
| "-(\<infinity>::ereal) * \<infinity> = -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   696
| "(\<infinity>::ereal) * -\<infinity> = -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   697
| "-(\<infinity>::ereal) * -\<infinity> = \<infinity>"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   698
proof -
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   699
  case (goal1 P x)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   700
  then obtain a b where "x = (a, b)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   701
    by (cases x) auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   702
  with goal1 show P
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   703
    by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   704
qed simp_all
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   705
termination by (relation "{}") simp
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   706
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   707
instance
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   708
proof
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   709
  fix a b c :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   710
  show "1 * a = a"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   711
    by (cases a) (simp_all add: one_ereal_def)
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   712
  show "a * b = b * a"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   713
    by (cases rule: ereal2_cases[of a b]) simp_all
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
   714
  show "a * b * c = a * (b * c)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   715
    by (cases rule: ereal3_cases[of a b c])
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   716
       (simp_all add: zero_ereal_def zero_less_mult_iff)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   717
qed
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   718
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   719
end
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   720
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   721
lemma one_not_le_zero_ereal[simp]: "\<not> (1 \<le> (0::ereal))"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   722
  by (simp add: one_ereal_def zero_ereal_def)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   723
50104
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   724
lemma real_ereal_1[simp]: "real (1::ereal) = 1"
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   725
  unfolding one_ereal_def by simp
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   726
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   727
lemma real_of_ereal_le_1:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   728
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   729
  shows "a \<le> 1 \<Longrightarrow> real a \<le> 1"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   730
  by (cases a) (auto simp: one_ereal_def)
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   731
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   732
lemma abs_ereal_one[simp]: "\<bar>1\<bar> = (1::ereal)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   733
  unfolding one_ereal_def by simp
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
   734
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   735
lemma ereal_mult_zero[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   736
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   737
  shows "a * 0 = 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   738
  by (cases a) (simp_all add: zero_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   739
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   740
lemma ereal_zero_mult[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   741
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   742
  shows "0 * a = 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   743
  by (cases a) (simp_all add: zero_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   744
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   745
lemma ereal_m1_less_0[simp]: "-(1::ereal) < 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   746
  by (simp add: zero_ereal_def one_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   747
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   748
lemma ereal_times[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   749
  "1 \<noteq> (\<infinity>::ereal)" "(\<infinity>::ereal) \<noteq> 1"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   750
  "1 \<noteq> -(\<infinity>::ereal)" "-(\<infinity>::ereal) \<noteq> 1"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   751
  by (auto simp add: times_ereal_def one_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   752
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   753
lemma ereal_plus_1[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   754
  "1 + ereal r = ereal (r + 1)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   755
  "ereal r + 1 = ereal (r + 1)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   756
  "1 + -(\<infinity>::ereal) = -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   757
  "-(\<infinity>::ereal) + 1 = -\<infinity>"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   758
  unfolding one_ereal_def by auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   759
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   760
lemma ereal_zero_times[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   761
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   762
  shows "a * b = 0 \<longleftrightarrow> a = 0 \<or> b = 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   763
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   764
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   765
lemma ereal_mult_eq_PInfty[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   766
  "a * b = (\<infinity>::ereal) \<longleftrightarrow>
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   767
    (a = \<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = -\<infinity>)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   768
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   769
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   770
lemma ereal_mult_eq_MInfty[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   771
  "a * b = -(\<infinity>::ereal) \<longleftrightarrow>
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   772
    (a = \<infinity> \<and> b < 0) \<or> (a < 0 \<and> b = \<infinity>) \<or> (a = -\<infinity> \<and> b > 0) \<or> (a > 0 \<and> b = -\<infinity>)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   773
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   774
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   775
lemma ereal_abs_mult: "\<bar>x * y :: ereal\<bar> = \<bar>x\<bar> * \<bar>y\<bar>"
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   776
  by (cases x y rule: ereal2_cases) (auto simp: abs_mult)
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
   777
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   778
lemma ereal_0_less_1[simp]: "0 < (1::ereal)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   779
  by (simp_all add: zero_ereal_def one_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   780
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   781
lemma ereal_mult_minus_left[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   782
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   783
  shows "-a * b = - (a * b)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   784
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   785
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   786
lemma ereal_mult_minus_right[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   787
  fixes a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   788
  shows "a * -b = - (a * b)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   789
  by (cases rule: ereal2_cases[of a b]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   790
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   791
lemma ereal_mult_infty[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   792
  "a * (\<infinity>::ereal) = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   793
  by (cases a) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   794
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   795
lemma ereal_infty_mult[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   796
  "(\<infinity>::ereal) * a = (if a = 0 then 0 else if 0 < a then \<infinity> else - \<infinity>)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   797
  by (cases a) auto
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   798
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   799
lemma ereal_mult_strict_right_mono:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   800
  assumes "a < b"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   801
    and "0 < c"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   802
    and "c < (\<infinity>::ereal)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   803
  shows "a * c < b * c"
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   804
  using assms
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   805
  by (cases rule: ereal3_cases[of a b c]) (auto simp: zero_le_mult_iff)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   806
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   807
lemma ereal_mult_strict_left_mono:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   808
  "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c < (\<infinity>::ereal) \<Longrightarrow> c * a < c * b"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   809
  using ereal_mult_strict_right_mono
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57447
diff changeset
   810
  by (simp add: mult.commute[of c])
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   811
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   812
lemma ereal_mult_right_mono:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   813
  fixes a b c :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   814
  shows "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> a * c \<le> b * c"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   815
  using assms
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   816
  apply (cases "c = 0")
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   817
  apply simp
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   818
  apply (cases rule: ereal3_cases[of a b c])
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   819
  apply (auto simp: zero_le_mult_iff)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   820
  done
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   821
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   822
lemma ereal_mult_left_mono:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   823
  fixes a b c :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   824
  shows "a \<le> b \<Longrightarrow> 0 \<le> c \<Longrightarrow> c * a \<le> c * b"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   825
  using ereal_mult_right_mono
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57447
diff changeset
   826
  by (simp add: mult.commute[of c])
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
   827
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   828
lemma zero_less_one_ereal[simp]: "0 \<le> (1::ereal)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   829
  by (simp add: one_ereal_def zero_ereal_def)
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
   830
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   831
lemma ereal_0_le_mult[simp]: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> a * (b :: ereal)"
56536
aefb4a8da31f made mult_nonneg_nonneg a simp rule
nipkow
parents: 56248
diff changeset
   832
  by (cases rule: ereal2_cases[of a b]) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   833
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   834
lemma ereal_right_distrib:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   835
  fixes r a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   836
  shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> r * (a + b) = r * a + r * b"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   837
  by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   838
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   839
lemma ereal_left_distrib:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   840
  fixes r a b :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   841
  shows "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> (a + b) * r = a * r + b * r"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   842
  by (cases rule: ereal3_cases[of r a b]) (simp_all add: field_simps)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   843
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   844
lemma ereal_mult_le_0_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   845
  fixes a b :: ereal
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   846
  shows "a * b \<le> 0 \<longleftrightarrow> (0 \<le> a \<and> b \<le> 0) \<or> (a \<le> 0 \<and> 0 \<le> b)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   847
  by (cases rule: ereal2_cases[of a b]) (simp_all add: mult_le_0_iff)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   848
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   849
lemma ereal_zero_le_0_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   850
  fixes a b :: ereal
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   851
  shows "0 \<le> a * b \<longleftrightarrow> (0 \<le> a \<and> 0 \<le> b) \<or> (a \<le> 0 \<and> b \<le> 0)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   852
  by (cases rule: ereal2_cases[of a b]) (simp_all add: zero_le_mult_iff)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   853
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   854
lemma ereal_mult_less_0_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   855
  fixes a b :: ereal
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   856
  shows "a * b < 0 \<longleftrightarrow> (0 < a \<and> b < 0) \<or> (a < 0 \<and> 0 < b)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   857
  by (cases rule: ereal2_cases[of a b]) (simp_all add: mult_less_0_iff)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   858
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   859
lemma ereal_zero_less_0_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   860
  fixes a b :: ereal
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   861
  shows "0 < a * b \<longleftrightarrow> (0 < a \<and> 0 < b) \<or> (a < 0 \<and> b < 0)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   862
  by (cases rule: ereal2_cases[of a b]) (simp_all add: zero_less_mult_iff)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   863
50104
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   864
lemma ereal_left_mult_cong:
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   865
  fixes a b c :: ereal
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   866
  shows "(c \<noteq> 0 \<Longrightarrow> a = b) \<Longrightarrow> c * a = c * b"
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   867
  by (cases "c = 0") simp_all
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   868
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   869
lemma ereal_right_mult_cong: 
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   870
  fixes a b c d :: ereal
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   871
  shows "c = d \<Longrightarrow> (d \<noteq> 0 \<Longrightarrow> a = b) \<Longrightarrow> c * a = d * b"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   872
  by (cases "d = 0") simp_all
50104
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
   873
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   874
lemma ereal_distrib:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   875
  fixes a b c :: ereal
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   876
  assumes "a \<noteq> \<infinity> \<or> b \<noteq> -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   877
    and "a \<noteq> -\<infinity> \<or> b \<noteq> \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   878
    and "\<bar>c\<bar> \<noteq> \<infinity>"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   879
  shows "(a + b) * c = a * c + b * c"
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   880
  using assms
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   881
  by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   882
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
   883
lemma numeral_eq_ereal [simp]: "numeral w = ereal (numeral w)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
   884
  apply (induct w rule: num_induct)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
   885
  apply (simp only: numeral_One one_ereal_def)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
   886
  apply (simp only: numeral_inc ereal_plus_1)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
   887
  done
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
   888
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   889
lemma setsum_ereal_right_distrib:
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   890
  fixes f :: "'a \<Rightarrow> ereal"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   891
  shows "(\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> r * setsum f A = (\<Sum>n\<in>A. r * f n)"
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   892
  by (induct A rule: infinite_finite_induct)  (auto simp: ereal_right_distrib setsum_nonneg)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58881
diff changeset
   893
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   894
lemma ereal_le_epsilon:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   895
  fixes x y :: ereal
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   896
  assumes "\<forall>e. 0 < e \<longrightarrow> x \<le> y + e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   897
  shows "x \<le> y"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   898
proof -
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   899
  {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   900
    assume a: "\<exists>r. y = ereal r"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   901
    then obtain r where r_def: "y = ereal r"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   902
      by auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   903
    {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   904
      assume "x = -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   905
      then have ?thesis by auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   906
    }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   907
    moreover
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   908
    {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   909
      assume "x \<noteq> -\<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   910
      then obtain p where p_def: "x = ereal p"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   911
      using a assms[rule_format, of 1]
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   912
        by (cases x) auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   913
      {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   914
        fix e
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   915
        have "0 < e \<longrightarrow> p \<le> r + e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   916
          using assms[rule_format, of "ereal e"] p_def r_def by auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   917
      }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   918
      then have "p \<le> r"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   919
        apply (subst field_le_epsilon)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   920
        apply auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   921
        done
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   922
      then have ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   923
        using r_def p_def by auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   924
    }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   925
    ultimately have ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   926
      by blast
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   927
  }
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   928
  moreover
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   929
  {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   930
    assume "y = -\<infinity> | y = \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   931
    then have ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   932
      using assms[rule_format, of 1] by (cases x) auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   933
  }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   934
  ultimately show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   935
    by (cases y) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   936
qed
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   937
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   938
lemma ereal_le_epsilon2:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   939
  fixes x y :: ereal
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   940
  assumes "\<forall>e. 0 < e \<longrightarrow> x \<le> y + ereal e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   941
  shows "x \<le> y"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   942
proof -
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   943
  {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   944
    fix e :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   945
    assume "e > 0"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   946
    {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   947
      assume "e = \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   948
      then have "x \<le> y + e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   949
        by auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   950
    }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   951
    moreover
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   952
    {
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   953
      assume "e \<noteq> \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   954
      then obtain r where "e = ereal r"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   955
        using `e > 0` by (cases e) auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   956
      then have "x \<le> y + e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   957
        using assms[rule_format, of r] `e>0` by auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   958
    }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   959
    ultimately have "x \<le> y + e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   960
      by blast
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   961
  }
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   962
  then show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   963
    using ereal_le_epsilon by auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   964
qed
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   965
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   966
lemma ereal_le_real:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   967
  fixes x y :: ereal
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   968
  assumes "\<forall>z. x \<le> ereal z \<longrightarrow> y \<le> ereal z"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   969
  shows "y \<le> x"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   970
  by (metis assms ereal_bot ereal_cases ereal_infty_less_eq(2) ereal_less_eq(1) linorder_le_cases)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
   971
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   972
lemma setprod_ereal_0:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   973
  fixes f :: "'a \<Rightarrow> ereal"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   974
  shows "(\<Prod>i\<in>A. f i) = 0 \<longleftrightarrow> finite A \<and> (\<exists>i\<in>A. f i = 0)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   975
proof (cases "finite A")
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   976
  case True
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   977
  then show ?thesis by (induct A) auto
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   978
next
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   979
  case False
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   980
  then show ?thesis by auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   981
qed
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   982
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
   983
lemma setprod_ereal_pos:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   984
  fixes f :: "'a \<Rightarrow> ereal"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   985
  assumes pos: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   986
  shows "0 \<le> (\<Prod>i\<in>I. f i)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   987
proof (cases "finite I")
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   988
  case True
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   989
  from this pos show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   990
    by induct auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   991
next
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   992
  case False
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   993
  then show ?thesis by simp
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
   994
qed
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   995
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   996
lemma setprod_PInf:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
   997
  fixes f :: "'a \<Rightarrow> ereal"
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   998
  assumes "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
   999
  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)"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1000
proof (cases "finite I")
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1001
  case True
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1002
  from this assms show ?thesis
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1003
  proof (induct I)
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1004
    case (insert i I)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1005
    then have pos: "0 \<le> f i" "0 \<le> setprod f I"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1006
      by (auto intro!: setprod_ereal_pos)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1007
    from insert have "(\<Prod>j\<in>insert i I. f j) = \<infinity> \<longleftrightarrow> setprod f I * f i = \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1008
      by auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1009
    also have "\<dots> \<longleftrightarrow> (setprod f I = \<infinity> \<or> f i = \<infinity>) \<and> f i \<noteq> 0 \<and> setprod f I \<noteq> 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1010
      using setprod_ereal_pos[of I f] pos
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1011
      by (cases rule: ereal2_cases[of "f i" "setprod f I"]) auto
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1012
    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)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1013
      using insert by (auto simp: setprod_ereal_0)
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1014
    finally show ?case .
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1015
  qed simp
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1016
next
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1017
  case False
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1018
  then show ?thesis by simp
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1019
qed
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1020
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1021
lemma setprod_ereal: "(\<Prod>i\<in>A. ereal (f i)) = ereal (setprod f A)"
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1022
proof (cases "finite A")
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1023
  case True
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1024
  then show ?thesis
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1025
    by induct (auto simp: one_ereal_def)
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1026
next
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1027
  case False
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1028
  then show ?thesis
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1029
    by (simp add: one_ereal_def)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1030
qed
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1031
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1032
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
  1033
subsubsection {* Power *}
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
  1034
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1035
lemma ereal_power[simp]: "(ereal x) ^ n = ereal (x^n)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1036
  by (induct n) (auto simp: one_ereal_def)
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
  1037
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1038
lemma ereal_power_PInf[simp]: "(\<infinity>::ereal) ^ n = (if n = 0 then 1 else \<infinity>)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1039
  by (induct n) (auto simp: one_ereal_def)
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
  1040
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1041
lemma ereal_power_uminus[simp]:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1042
  fixes x :: ereal
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
  1043
  shows "(- x) ^ n = (if even n then x ^ n else - (x^n))"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1044
  by (induct n) (auto simp: one_ereal_def)
41978
656298577a33 add infinite sums and power on extreal
hoelzl
parents: 41977
diff changeset
  1045
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
  1046
lemma ereal_power_numeral[simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 47082
diff changeset
  1047
  "(numeral num :: ereal) ^ n = ereal (numeral num ^ n)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1048
  by (induct n) (auto simp: one_ereal_def)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1049
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1050
lemma zero_le_power_ereal[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1051
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1052
  assumes "0 \<le> a"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1053
  shows "0 \<le> a ^ n"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1054
  using assms by (induct n) (auto simp: ereal_zero_le_0_iff)
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1055
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1056
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1057
subsubsection {* Subtraction *}
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1058
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1059
lemma ereal_minus_minus_image[simp]:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1060
  fixes S :: "ereal set"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1061
  shows "uminus ` uminus ` S = S"
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1062
  by (auto simp: image_iff)
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1063
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1064
lemma ereal_uminus_lessThan[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1065
  fixes a :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1066
  shows "uminus ` {..<a} = {-a<..}"
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
  1067
proof -
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
  1068
  {
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1069
    fix x
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1070
    assume "-a < x"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1071
    then have "- x < - (- a)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1072
      by (simp del: ereal_uminus_uminus)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1073
    then have "- x < a"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1074
      by simp
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
  1075
  }
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1076
  then show ?thesis
54416
7fb88ed6ff3c better support for enat and ereal conversions
hoelzl
parents: 54408
diff changeset
  1077
    by force
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
  1078
qed
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1079
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1080
lemma ereal_uminus_greaterThan[simp]: "uminus ` {(a::ereal)<..} = {..<-a}"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1081
  by (metis ereal_uminus_lessThan ereal_uminus_uminus ereal_minus_minus_image)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1082
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1083
instantiation ereal :: minus
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1084
begin
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1085
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1086
definition "x - y = x + -(y::ereal)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1087
instance ..
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1088
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1089
end
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1090
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1091
lemma ereal_minus[simp]:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1092
  "ereal r - ereal p = ereal (r - p)"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1093
  "-\<infinity> - ereal r = -\<infinity>"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1094
  "ereal r - \<infinity> = -\<infinity>"
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1095
  "(\<infinity>::ereal) - x = \<infinity>"
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1096
  "-(\<infinity>::ereal) - \<infinity> = -\<infinity>"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1097
  "x - -y = x + y"
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1098
  "x - 0 = x"
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1099
  "0 - x = -x"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1100
  by (simp_all add: minus_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1101
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1102
lemma ereal_x_minus_x[simp]: "x - x = (if \<bar>x\<bar> = \<infinity> then \<infinity> else 0::ereal)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1103
  by (cases x) simp_all
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1104
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1105
lemma ereal_eq_minus_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1106
  fixes x y z :: ereal
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1107
  shows "x = z - y \<longleftrightarrow>
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1108
    (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x + y = z) \<and>
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1109
    (y = -\<infinity> \<longrightarrow> x = \<infinity>) \<and>
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1110
    (y = \<infinity> \<longrightarrow> z = \<infinity> \<longrightarrow> x = \<infinity>) \<and>
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1111
    (y = \<infinity> \<longrightarrow> z \<noteq> \<infinity> \<longrightarrow> x = -\<infinity>)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1112
  by (cases rule: ereal3_cases[of x y z]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1113
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1114
lemma ereal_eq_minus:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1115
  fixes x y z :: ereal
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1116
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x = z - y \<longleftrightarrow> x + y = z"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1117
  by (auto simp: ereal_eq_minus_iff)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1118
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1119
lemma ereal_less_minus_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1120
  fixes x y z :: ereal
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1121
  shows "x < z - y \<longleftrightarrow>
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1122
    (y = \<infinity> \<longrightarrow> z = \<infinity> \<and> x \<noteq> \<infinity>) \<and>
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1123
    (y = -\<infinity> \<longrightarrow> x \<noteq> \<infinity>) \<and>
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1124
    (\<bar>y\<bar> \<noteq> \<infinity>\<longrightarrow> x + y < z)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1125
  by (cases rule: ereal3_cases[of x y z]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1126
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1127
lemma ereal_less_minus:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1128
  fixes x y z :: ereal
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1129
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x < z - y \<longleftrightarrow> x + y < z"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1130
  by (auto simp: ereal_less_minus_iff)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1131
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1132
lemma ereal_le_minus_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1133
  fixes x y z :: ereal
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1134
  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)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1135
  by (cases rule: ereal3_cases[of x y z]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1136
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1137
lemma ereal_le_minus:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1138
  fixes x y z :: ereal
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1139
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x \<le> z - y \<longleftrightarrow> x + y \<le> z"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1140
  by (auto simp: ereal_le_minus_iff)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1141
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1142
lemma ereal_minus_less_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1143
  fixes x y z :: ereal
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1144
  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)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1145
  by (cases rule: ereal3_cases[of x y z]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1146
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1147
lemma ereal_minus_less:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1148
  fixes x y z :: ereal
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1149
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x - y < z \<longleftrightarrow> x < z + y"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1150
  by (auto simp: ereal_minus_less_iff)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1151
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1152
lemma ereal_minus_le_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1153
  fixes x y z :: ereal
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1154
  shows "x - y \<le> z \<longleftrightarrow>
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1155
    (y = -\<infinity> \<longrightarrow> z = \<infinity>) \<and>
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1156
    (y = \<infinity> \<longrightarrow> x = \<infinity> \<longrightarrow> z = \<infinity>) \<and>
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1157
    (\<bar>y\<bar> \<noteq> \<infinity> \<longrightarrow> x \<le> z + y)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1158
  by (cases rule: ereal3_cases[of x y z]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1159
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1160
lemma ereal_minus_le:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1161
  fixes x y z :: ereal
41976
3fdbc7d5b525 use abs_extreal
hoelzl
parents: 41975
diff changeset
  1162
  shows "\<bar>y\<bar> \<noteq> \<infinity> \<Longrightarrow> x - y \<le> z \<longleftrightarrow> x \<le> z + y"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1163
  by (auto simp: ereal_minus_le_iff)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1164
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1165
lemma ereal_minus_eq_minus_iff:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1166
  fixes a b c :: ereal
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1167
  shows "a - b = a - c \<longleftrightarrow>
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1168
    b = c \<or> a = \<infinity> \<or> (a = -\<infinity> \<and> b \<noteq> -\<infinity> \<and> c \<noteq> -\<infinity>)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1169
  by (cases rule: ereal3_cases[of a b c]) auto
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1170
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1171
lemma ereal_add_le_add_iff:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1172
  fixes a b c :: ereal
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1173
  shows "c + a \<le> c + b \<longleftrightarrow>
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1174
    a \<le> b \<or> c = \<infinity> \<or> (c = -\<infinity> \<and> a \<noteq> \<infinity> \<and> b \<noteq> \<infinity>)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1175
  by (cases rule: ereal3_cases[of a b c]) (simp_all add: field_simps)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1176
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1177
lemma ereal_mult_le_mult_iff:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1178
  fixes a b c :: ereal
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1179
  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)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1180
  by (cases rule: ereal3_cases[of a b c]) (simp_all add: mult_le_cancel_left)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1181
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1182
lemma ereal_minus_mono:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1183
  fixes A B C D :: ereal assumes "A \<le> B" "D \<le> C"
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1184
  shows "A - C \<le> B - D"
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1185
  using assms
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1186
  by (cases rule: ereal3_cases[case_product ereal_cases, of A B C D]) simp_all
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1187
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1188
lemma real_of_ereal_minus:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1189
  fixes a b :: ereal
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1190
  shows "real (a - b) = (if \<bar>a\<bar> = \<infinity> \<or> \<bar>b\<bar> = \<infinity> then 0 else real a - real b)"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1191
  by (cases rule: ereal2_cases[of a b]) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1192
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1193
lemma ereal_diff_positive:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1194
  fixes a b :: ereal shows "a \<le> b \<Longrightarrow> 0 \<le> b - a"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1195
  by (cases rule: ereal2_cases[of a b]) auto
41979
b10ec1f5e9d5 lemmas about addition, SUP on countable sets and infinite sums for extreal
hoelzl
parents: 41978
diff changeset
  1196
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1197
lemma ereal_between:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1198
  fixes x e :: ereal
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1199
  assumes "\<bar>x\<bar> \<noteq> \<infinity>"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1200
    and "0 < e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1201
  shows "x - e < x"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1202
    and "x < x + e"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1203
  using assms
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1204
  apply (cases x, cases e)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1205
  apply auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1206
  using assms
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1207
  apply (cases x, cases e)
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1208
  apply auto
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1209
  done
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1210
50104
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
  1211
lemma ereal_minus_eq_PInfty_iff:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1212
  fixes x y :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1213
  shows "x - y = \<infinity> \<longleftrightarrow> y = -\<infinity> \<or> x = \<infinity>"
50104
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
  1214
  by (cases x y rule: ereal2_cases) simp_all
de19856feb54 move theorems to be more generally useable
hoelzl
parents: 47108
diff changeset
  1215
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1216
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1217
subsubsection {* Division *}
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1218
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1219
instantiation ereal :: inverse
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1220
begin
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1221
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1222
function inverse_ereal where
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1223
  "inverse (ereal r) = (if r = 0 then \<infinity> else ereal (inverse r))"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1224
| "inverse (\<infinity>::ereal) = 0"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1225
| "inverse (-\<infinity>::ereal) = 0"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1226
  by (auto intro: ereal_cases)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1227
termination by (relation "{}") simp
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1228
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1229
definition "x / y = x * inverse (y :: ereal)"
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1230
47082
737d7bc8e50f tuned proofs;
wenzelm
parents: 45934
diff changeset
  1231
instance ..
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1232
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1233
end
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1234
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1235
lemma real_of_ereal_inverse[simp]:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1236
  fixes a :: ereal
42950
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1237
  shows "real (inverse a) = 1 / real a"
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1238
  by (cases a) (auto simp: inverse_eq_divide)
6e5c2a3c69da move lemmas to Extended_Reals and Extended_Real_Limits
hoelzl
parents: 42600
diff changeset
  1239
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1240
lemma ereal_inverse[simp]:
43923
ab93d0190a5d add ereal to typeclass infinity
hoelzl
parents: 43920
diff changeset
  1241
  "inverse (0::ereal) = \<infinity>"
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1242
  "inverse (1::ereal) = 1"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1243
  by (simp_all add: one_ereal_def zero_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1244
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1245
lemma ereal_divide[simp]:
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1246
  "ereal r / ereal p = (if p = 0 then ereal r * \<infinity> else ereal (r / p))"
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1247
  unfolding divide_ereal_def by (auto simp: divide_real_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1248
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1249
lemma ereal_divide_same[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1250
  fixes x :: ereal
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1251
  shows "x / x = (if \<bar>x\<bar> = \<infinity> \<or> x = 0 then 0 else 1)"
08594daabcd9 tuned proofs;
wenzelm
parents: 53381
diff changeset
  1252
  by (cases x) (simp_all add: divide_real_def divide_ereal_def one_ereal_def)
41973
15927c040731 add Extended_Reals from AFP/Lower_Semicontinuous
hoelzl
parents:
diff changeset
  1253
43920
cedb5cb948fd Rename extreal => ereal
hoelzl
parents: 43138
diff changeset
  1254
lemma ereal_inv_inv[simp]:
53873
08594daabcd9 tuned proofs;
wenzelm
parents: 53381