src/HOL/Probability/Lebesgue_Measure.thy
changeset 41981 cdf7693bbe08
parent 41831 91a2b435dd7a
child 42067 66c8281349ec
     1.1 --- a/src/HOL/Probability/Lebesgue_Measure.thy	Mon Mar 14 14:37:47 2011 +0100
     1.2 +++ b/src/HOL/Probability/Lebesgue_Measure.thy	Mon Mar 14 14:37:49 2011 +0100
     1.3 @@ -48,12 +48,12 @@
     1.4  lemma Pi_iff: "f \<in> Pi I X \<longleftrightarrow> (\<forall>i\<in>I. f i \<in> X i)"
     1.5    unfolding Pi_def by auto
     1.6  
     1.7 -subsection {* Lebesgue measure *}
     1.8 +subsection {* Lebesgue measure *} 
     1.9  
    1.10  definition lebesgue :: "'a::ordered_euclidean_space measure_space" where
    1.11    "lebesgue = \<lparr> space = UNIV,
    1.12      sets = {A. \<forall>n. (indicator A :: 'a \<Rightarrow> real) integrable_on cube n},
    1.13 -    measure = \<lambda>A. SUP n. Real (integral (cube n) (indicator A)) \<rparr>"
    1.14 +    measure = \<lambda>A. SUP n. extreal (integral (cube n) (indicator A)) \<rparr>"
    1.15  
    1.16  lemma space_lebesgue[simp]: "space lebesgue = UNIV"
    1.17    unfolding lebesgue_def by simp
    1.18 @@ -114,10 +114,33 @@
    1.19    qed (auto intro: LIMSEQ_indicator_UN simp: cube_def)
    1.20  qed simp
    1.21  
    1.22 +lemma suminf_SUP_eq:
    1.23 +  fixes f :: "nat \<Rightarrow> nat \<Rightarrow> extreal"
    1.24 +  assumes "\<And>i. incseq (\<lambda>n. f n i)" "\<And>n i. 0 \<le> f n i"
    1.25 +  shows "(\<Sum>i. SUP n. f n i) = (SUP n. \<Sum>i. f n i)"
    1.26 +proof -
    1.27 +  { fix n :: nat
    1.28 +    have "(\<Sum>i<n. SUP k. f k i) = (SUP k. \<Sum>i<n. f k i)"
    1.29 +      using assms by (auto intro!: SUPR_extreal_setsum[symmetric]) }
    1.30 +  note * = this
    1.31 +  show ?thesis using assms
    1.32 +    apply (subst (1 2) suminf_extreal_eq_SUPR)
    1.33 +    unfolding *
    1.34 +    apply (auto intro!: le_SUPI2)
    1.35 +    apply (subst SUP_commute) ..
    1.36 +qed
    1.37 +
    1.38  interpretation lebesgue: measure_space lebesgue
    1.39  proof
    1.40    have *: "indicator {} = (\<lambda>x. 0 :: real)" by (simp add: fun_eq_iff)
    1.41 -  show "measure lebesgue {} = 0" by (simp add: integral_0 * lebesgue_def)
    1.42 +  show "positive lebesgue (measure lebesgue)"
    1.43 +  proof (unfold positive_def, safe)
    1.44 +    show "measure lebesgue {} = 0" by (simp add: integral_0 * lebesgue_def)
    1.45 +    fix A assume "A \<in> sets lebesgue"
    1.46 +    then show "0 \<le> measure lebesgue A"
    1.47 +      unfolding lebesgue_def
    1.48 +      by (auto intro!: le_SUPI2 integral_nonneg)
    1.49 +  qed
    1.50  next
    1.51    show "countably_additive lebesgue (measure lebesgue)"
    1.52    proof (intro countably_additive_def[THEN iffD2] allI impI)
    1.53 @@ -130,23 +153,17 @@
    1.54      assume "(\<Union>i. A i) \<in> sets lebesgue"
    1.55      then have UN_A[simp, intro]: "\<And>i n. (indicator (\<Union>i. A i) :: _ \<Rightarrow> real) integrable_on cube n"
    1.56        by (auto dest: lebesgueD)
    1.57 -    show "(\<Sum>\<^isub>\<infinity>n. measure lebesgue (A n)) = measure lebesgue (\<Union>i. A i)"
    1.58 -    proof (simp add: lebesgue_def, subst psuminf_SUP_eq)
    1.59 -      fix n i show "Real (?m n i) \<le> Real (?m (Suc n) i)"
    1.60 -        using cube_subset[of n "Suc n"] by (auto intro!: integral_subset_le)
    1.61 +    show "(\<Sum>n. measure lebesgue (A n)) = measure lebesgue (\<Union>i. A i)"
    1.62 +    proof (simp add: lebesgue_def, subst suminf_SUP_eq, safe intro!: incseq_SucI)
    1.63 +      fix i n show "extreal (?m n i) \<le> extreal (?m (Suc n) i)"
    1.64 +        using cube_subset[of n "Suc n"] by (auto intro!: integral_subset_le incseq_SucI)
    1.65      next
    1.66 -      show "(SUP n. \<Sum>\<^isub>\<infinity>i. Real (?m n i)) = (SUP n. Real (?M n UNIV))"
    1.67 -        unfolding psuminf_def
    1.68 -      proof (subst setsum_Real, (intro arg_cong[where f="SUPR UNIV"] ext ballI nn SUP_eq_LIMSEQ[THEN iffD2])+)
    1.69 -        fix n :: nat show "mono (\<lambda>m. \<Sum>x<m. ?m n x)"
    1.70 -        proof (intro mono_iff_le_Suc[THEN iffD2] allI)
    1.71 -          fix m show "(\<Sum>x<m. ?m n x) \<le> (\<Sum>x<Suc m. ?m n x)"
    1.72 -            using nn[of n m] by auto
    1.73 -        qed
    1.74 -        show "0 \<le> ?M n UNIV"
    1.75 -          using UN_A by (auto intro!: integral_nonneg)
    1.76 -        fix m show "0 \<le> (\<Sum>x<m. ?m n x)" by (auto intro!: setsum_nonneg)
    1.77 -      next
    1.78 +      fix i n show "0 \<le> extreal (?m n i)"
    1.79 +        using rA unfolding lebesgue_def
    1.80 +        by (auto intro!: le_SUPI2 integral_nonneg)
    1.81 +    next
    1.82 +      show "(SUP n. \<Sum>i. extreal (?m n i)) = (SUP n. extreal (?M n UNIV))"
    1.83 +      proof (intro arg_cong[where f="SUPR UNIV"] ext sums_unique[symmetric] sums_extreal[THEN iffD2] sums_def[THEN iffD2])
    1.84          fix n
    1.85          have "\<And>m. (UNION {..<m} A) \<in> sets lebesgue" using rA by auto
    1.86          from lebesgueD[OF this]
    1.87 @@ -171,8 +188,8 @@
    1.88              ultimately show ?case
    1.89                using Suc A by (simp add: integral_add[symmetric])
    1.90            qed auto }
    1.91 -        ultimately show "(\<lambda>m. \<Sum>x<m. ?m n x) ----> ?M n UNIV"
    1.92 -          by simp
    1.93 +        ultimately show "(\<lambda>m. \<Sum>x = 0..<m. ?m n x) ----> ?M n UNIV"
    1.94 +          by (simp add: atLeast0LessThan)
    1.95        qed
    1.96      qed
    1.97    qed
    1.98 @@ -232,13 +249,11 @@
    1.99  
   1.100  lemma lmeasure_iff_LIMSEQ:
   1.101    assumes "A \<in> sets lebesgue" "0 \<le> m"
   1.102 -  shows "lebesgue.\<mu> A = Real m \<longleftrightarrow> (\<lambda>n. integral (cube n) (indicator A :: _ \<Rightarrow> real)) ----> m"
   1.103 +  shows "lebesgue.\<mu> A = extreal m \<longleftrightarrow> (\<lambda>n. integral (cube n) (indicator A :: _ \<Rightarrow> real)) ----> m"
   1.104  proof (simp add: lebesgue_def, intro SUP_eq_LIMSEQ)
   1.105    show "mono (\<lambda>n. integral (cube n) (indicator A::_=>real))"
   1.106      using cube_subset assms by (intro monoI integral_subset_le) (auto dest!: lebesgueD)
   1.107 -  fix n show "0 \<le> integral (cube n) (indicator A::_=>real)"
   1.108 -    using assms by (auto dest!: lebesgueD intro!: integral_nonneg)
   1.109 -qed fact
   1.110 +qed
   1.111  
   1.112  lemma has_integral_indicator_UNIV:
   1.113    fixes s A :: "'a::ordered_euclidean_space set" and x :: real
   1.114 @@ -260,7 +275,7 @@
   1.115  
   1.116  lemma lmeasure_finite_has_integral:
   1.117    fixes s :: "'a::ordered_euclidean_space set"
   1.118 -  assumes "s \<in> sets lebesgue" "lebesgue.\<mu> s = Real m" "0 \<le> m"
   1.119 +  assumes "s \<in> sets lebesgue" "lebesgue.\<mu> s = extreal m" "0 \<le> m"
   1.120    shows "(indicator s has_integral m) UNIV"
   1.121  proof -
   1.122    let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
   1.123 @@ -302,12 +317,14 @@
   1.124      unfolding m by (intro integrable_integral **)
   1.125  qed
   1.126  
   1.127 -lemma lmeasure_finite_integrable: assumes "s \<in> sets lebesgue" "lebesgue.\<mu> s \<noteq> \<omega>"
   1.128 +lemma lmeasure_finite_integrable: assumes s: "s \<in> sets lebesgue" and "lebesgue.\<mu> s \<noteq> \<infinity>"
   1.129    shows "(indicator s :: _ \<Rightarrow> real) integrable_on UNIV"
   1.130  proof (cases "lebesgue.\<mu> s")
   1.131 -  case (preal m) from lmeasure_finite_has_integral[OF `s \<in> sets lebesgue` this]
   1.132 +  case (real m)
   1.133 +  with lmeasure_finite_has_integral[OF `s \<in> sets lebesgue` this]
   1.134 +    lebesgue.positive_measure[OF s]
   1.135    show ?thesis unfolding integrable_on_def by auto
   1.136 -qed (insert assms, auto)
   1.137 +qed (insert assms lebesgue.positive_measure[OF s], auto)
   1.138  
   1.139  lemma has_integral_lebesgue: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
   1.140    shows "s \<in> sets lebesgue"
   1.141 @@ -321,7 +338,7 @@
   1.142  qed
   1.143  
   1.144  lemma has_integral_lmeasure: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
   1.145 -  shows "lebesgue.\<mu> s = Real m"
   1.146 +  shows "lebesgue.\<mu> s = extreal m"
   1.147  proof (intro lmeasure_iff_LIMSEQ[THEN iffD2])
   1.148    let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
   1.149    show "s \<in> sets lebesgue" using has_integral_lebesgue[OF assms] .
   1.150 @@ -346,28 +363,28 @@
   1.151  qed
   1.152  
   1.153  lemma has_integral_iff_lmeasure:
   1.154 -  "(indicator A has_integral m) UNIV \<longleftrightarrow> (A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = Real m)"
   1.155 +  "(indicator A has_integral m) UNIV \<longleftrightarrow> (A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = extreal m)"
   1.156  proof
   1.157    assume "(indicator A has_integral m) UNIV"
   1.158    with has_integral_lmeasure[OF this] has_integral_lebesgue[OF this]
   1.159 -  show "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = Real m"
   1.160 +  show "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = extreal m"
   1.161      by (auto intro: has_integral_nonneg)
   1.162  next
   1.163 -  assume "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = Real m"
   1.164 +  assume "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = extreal m"
   1.165    then show "(indicator A has_integral m) UNIV" by (intro lmeasure_finite_has_integral) auto
   1.166  qed
   1.167  
   1.168  lemma lmeasure_eq_integral: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV"
   1.169 -  shows "lebesgue.\<mu> s = Real (integral UNIV (indicator s))"
   1.170 +  shows "lebesgue.\<mu> s = extreal (integral UNIV (indicator s))"
   1.171    using assms unfolding integrable_on_def
   1.172  proof safe
   1.173    fix y :: real assume "(indicator s has_integral y) UNIV"
   1.174    from this[unfolded has_integral_iff_lmeasure] integral_unique[OF this]
   1.175 -  show "lebesgue.\<mu> s = Real (integral UNIV (indicator s))" by simp
   1.176 +  show "lebesgue.\<mu> s = extreal (integral UNIV (indicator s))" by simp
   1.177  qed
   1.178  
   1.179  lemma lebesgue_simple_function_indicator:
   1.180 -  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
   1.181 +  fixes f::"'a::ordered_euclidean_space \<Rightarrow> extreal"
   1.182    assumes f:"simple_function lebesgue f"
   1.183    shows "f = (\<lambda>x. (\<Sum>y \<in> f ` UNIV. y * indicator (f -` {y}) x))"
   1.184    by (rule, subst lebesgue.simple_function_indicator_representation[OF f]) auto
   1.185 @@ -376,7 +393,7 @@
   1.186    "(indicator s::_\<Rightarrow>real) integrable_on UNIV \<Longrightarrow> integral UNIV (indicator s) = real (lebesgue.\<mu> s)"
   1.187    by (subst lmeasure_eq_integral) (auto intro!: integral_nonneg)
   1.188  
   1.189 -lemma lmeasure_finite: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV" shows "lebesgue.\<mu> s \<noteq> \<omega>"
   1.190 +lemma lmeasure_finite: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV" shows "lebesgue.\<mu> s \<noteq> \<infinity>"
   1.191    using lmeasure_eq_integral[OF assms] by auto
   1.192  
   1.193  lemma negligible_iff_lebesgue_null_sets:
   1.194 @@ -409,37 +426,29 @@
   1.195    shows "integral {a .. b} (\<lambda>x. c) = content {a .. b} *\<^sub>R c"
   1.196    by (rule integral_unique) (rule has_integral_const)
   1.197  
   1.198 -lemma lmeasure_UNIV[intro]: "lebesgue.\<mu> (UNIV::'a::ordered_euclidean_space set) = \<omega>"
   1.199 -proof (simp add: lebesgue_def SUP_\<omega>, intro allI impI)
   1.200 -  fix x assume "x < \<omega>"
   1.201 -  then obtain r where r: "x = Real r" "0 \<le> r" by (cases x) auto
   1.202 -  then obtain n where n: "r < of_nat n" using ex_less_of_nat by auto
   1.203 -  show "\<exists>i. x < Real (integral (cube i) (indicator UNIV::'a\<Rightarrow>real))"
   1.204 -  proof (intro exI[of _ n])
   1.205 -    have [simp]: "indicator UNIV = (\<lambda>x. 1)" by (auto simp: fun_eq_iff)
   1.206 -    { fix m :: nat assume "0 < m" then have "real n \<le> (\<Prod>x<m. 2 * real n)"
   1.207 -      proof (induct m)
   1.208 -        case (Suc m)
   1.209 -        show ?case
   1.210 -        proof cases
   1.211 -          assume "m = 0" then show ?thesis by (simp add: lessThan_Suc)
   1.212 -        next
   1.213 -          assume "m \<noteq> 0" then have "real n \<le> (\<Prod>x<m. 2 * real n)" using Suc by auto
   1.214 -          then show ?thesis
   1.215 -            by (auto simp: lessThan_Suc field_simps mult_le_cancel_left1)
   1.216 -        qed
   1.217 -      qed auto } note this[OF DIM_positive[where 'a='a], simp]
   1.218 -    then have [simp]: "0 \<le> (\<Prod>x<DIM('a). 2 * real n)" using real_of_nat_ge_zero by arith
   1.219 -    have "x < Real (of_nat n)" using n r by auto
   1.220 -    also have "Real (of_nat n) \<le> Real (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))"
   1.221 -      by (auto simp: real_eq_of_nat[symmetric] cube_def content_closed_interval_cases)
   1.222 -    finally show "x < Real (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))" .
   1.223 -  qed
   1.224 -qed
   1.225 +lemma lmeasure_UNIV[intro]: "lebesgue.\<mu> (UNIV::'a::ordered_euclidean_space set) = \<infinity>"
   1.226 +proof (simp add: lebesgue_def, intro SUP_PInfty bexI)
   1.227 +  fix n :: nat
   1.228 +  have "indicator UNIV = (\<lambda>x::'a. 1 :: real)" by auto
   1.229 +  moreover
   1.230 +  { have "real n \<le> (2 * real n) ^ DIM('a)"
   1.231 +    proof (cases n)
   1.232 +      case 0 then show ?thesis by auto
   1.233 +    next
   1.234 +      case (Suc n')
   1.235 +      have "real n \<le> (2 * real n)^1" by auto
   1.236 +      also have "(2 * real n)^1 \<le> (2 * real n) ^ DIM('a)"
   1.237 +        using Suc DIM_positive[where 'a='a] by (intro power_increasing) (auto simp: real_of_nat_Suc)
   1.238 +      finally show ?thesis .
   1.239 +    qed }
   1.240 +  ultimately show "extreal (real n) \<le> extreal (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))"
   1.241 +    using integral_const DIM_positive[where 'a='a]
   1.242 +    by (auto simp: cube_def content_closed_interval_cases setprod_constant)
   1.243 +qed simp
   1.244  
   1.245  lemma
   1.246    fixes a b ::"'a::ordered_euclidean_space"
   1.247 -  shows lmeasure_atLeastAtMost[simp]: "lebesgue.\<mu> {a..b} = Real (content {a..b})"
   1.248 +  shows lmeasure_atLeastAtMost[simp]: "lebesgue.\<mu> {a..b} = extreal (content {a..b})"
   1.249  proof -
   1.250    have "(indicator (UNIV \<inter> {a..b})::_\<Rightarrow>real) integrable_on UNIV"
   1.251      unfolding integrable_indicator_UNIV by (simp add: integrable_const indicator_def_raw)
   1.252 @@ -467,7 +476,7 @@
   1.253  lemma
   1.254    fixes a b :: real
   1.255    shows lmeasure_real_greaterThanAtMost[simp]:
   1.256 -    "lebesgue.\<mu> {a <.. b} = Real (if a \<le> b then b - a else 0)"
   1.257 +    "lebesgue.\<mu> {a <.. b} = extreal (if a \<le> b then b - a else 0)"
   1.258  proof cases
   1.259    assume "a < b"
   1.260    then have "lebesgue.\<mu> {a <.. b} = lebesgue.\<mu> {a .. b} - lebesgue.\<mu> {a}"
   1.261 @@ -479,7 +488,7 @@
   1.262  lemma
   1.263    fixes a b :: real
   1.264    shows lmeasure_real_atLeastLessThan[simp]:
   1.265 -    "lebesgue.\<mu> {a ..< b} = Real (if a \<le> b then b - a else 0)"
   1.266 +    "lebesgue.\<mu> {a ..< b} = extreal (if a \<le> b then b - a else 0)"
   1.267  proof cases
   1.268    assume "a < b"
   1.269    then have "lebesgue.\<mu> {a ..< b} = lebesgue.\<mu> {a .. b} - lebesgue.\<mu> {b}"
   1.270 @@ -491,7 +500,7 @@
   1.271  lemma
   1.272    fixes a b :: real
   1.273    shows lmeasure_real_greaterThanLessThan[simp]:
   1.274 -    "lebesgue.\<mu> {a <..< b} = Real (if a \<le> b then b - a else 0)"
   1.275 +    "lebesgue.\<mu> {a <..< b} = extreal (if a \<le> b then b - a else 0)"
   1.276  proof cases
   1.277    assume "a < b"
   1.278    then have "lebesgue.\<mu> {a <..< b} = lebesgue.\<mu> {a <.. b} - lebesgue.\<mu> {b}"
   1.279 @@ -511,19 +520,16 @@
   1.280    and measurable_lborel[simp]: "measurable lborel = measurable borel"
   1.281    by (simp_all add: measurable_def_raw lborel_def)
   1.282  
   1.283 -interpretation lborel: measure_space lborel
   1.284 +interpretation lborel: measure_space "lborel :: ('a::ordered_euclidean_space) measure_space"
   1.285    where "space lborel = UNIV"
   1.286    and "sets lborel = sets borel"
   1.287    and "measure lborel = lebesgue.\<mu>"
   1.288    and "measurable lborel = measurable borel"
   1.289 -proof -
   1.290 -  show "measure_space lborel"
   1.291 -  proof
   1.292 -    show "countably_additive lborel (measure lborel)"
   1.293 -      using lebesgue.ca unfolding countably_additive_def lborel_def
   1.294 -      apply safe apply (erule_tac x=A in allE) by auto
   1.295 -  qed (auto simp: lborel_def)
   1.296 -qed simp_all
   1.297 +proof (rule lebesgue.measure_space_subalgebra)
   1.298 +  have "sigma_algebra (lborel::'a measure_space) \<longleftrightarrow> sigma_algebra (borel::'a algebra)"
   1.299 +    unfolding sigma_algebra_iff2 lborel_def by simp
   1.300 +  then show "sigma_algebra (lborel::'a measure_space)" by simp default
   1.301 +qed auto
   1.302  
   1.303  interpretation lborel: sigma_finite_measure lborel
   1.304    where "space lborel = UNIV"
   1.305 @@ -536,7 +542,7 @@
   1.306      show "range cube \<subseteq> sets lborel" by (auto intro: borel_closed)
   1.307      { fix x have "\<exists>n. x\<in>cube n" using mem_big_cube by auto }
   1.308      thus "(\<Union>i. cube i) = space lborel" by auto
   1.309 -    show "\<forall>i. measure lborel (cube i) \<noteq> \<omega>" by (simp add: cube_def)
   1.310 +    show "\<forall>i. measure lborel (cube i) \<noteq> \<infinity>" by (simp add: cube_def)
   1.311    qed
   1.312  qed simp_all
   1.313  
   1.314 @@ -544,171 +550,221 @@
   1.315  proof
   1.316    from lborel.sigma_finite guess A ..
   1.317    moreover then have "range A \<subseteq> sets lebesgue" using lebesgueI_borel by blast
   1.318 -  ultimately show "\<exists>A::nat \<Rightarrow> 'b set. range A \<subseteq> sets lebesgue \<and> (\<Union>i. A i) = space lebesgue \<and> (\<forall>i. lebesgue.\<mu> (A i) \<noteq> \<omega>)"
   1.319 +  ultimately show "\<exists>A::nat \<Rightarrow> 'b set. range A \<subseteq> sets lebesgue \<and> (\<Union>i. A i) = space lebesgue \<and> (\<forall>i. lebesgue.\<mu> (A i) \<noteq> \<infinity>)"
   1.320      by auto
   1.321  qed
   1.322  
   1.323  subsection {* Lebesgue integrable implies Gauge integrable *}
   1.324  
   1.325 +lemma positive_not_Inf:
   1.326 +  "0 \<le> x \<Longrightarrow> x \<noteq> \<infinity> \<Longrightarrow> \<bar>x\<bar> \<noteq> \<infinity>"
   1.327 +  by (cases x) auto
   1.328 +
   1.329 +lemma has_integral_cmult_real:
   1.330 +  fixes c :: real
   1.331 +  assumes "c \<noteq> 0 \<Longrightarrow> (f has_integral x) A"
   1.332 +  shows "((\<lambda>x. c * f x) has_integral c * x) A"
   1.333 +proof cases
   1.334 +  assume "c \<noteq> 0"
   1.335 +  from has_integral_cmul[OF assms[OF this], of c] show ?thesis
   1.336 +    unfolding real_scaleR_def .
   1.337 +qed simp
   1.338 +
   1.339  lemma simple_function_has_integral:
   1.340 -  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
   1.341 +  fixes f::"'a::ordered_euclidean_space \<Rightarrow> extreal"
   1.342    assumes f:"simple_function lebesgue f"
   1.343 -  and f':"\<forall>x. f x \<noteq> \<omega>"
   1.344 -  and om:"\<forall>x\<in>range f. lebesgue.\<mu> (f -` {x} \<inter> UNIV) = \<omega> \<longrightarrow> x = 0"
   1.345 +  and f':"range f \<subseteq> {0..<\<infinity>}"
   1.346 +  and om:"\<And>x. x \<in> range f \<Longrightarrow> lebesgue.\<mu> (f -` {x} \<inter> UNIV) = \<infinity> \<Longrightarrow> x = 0"
   1.347    shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>S lebesgue f))) UNIV"
   1.348 -  unfolding simple_integral_def
   1.349 -  apply(subst lebesgue_simple_function_indicator[OF f])
   1.350 -proof -
   1.351 -  case goal1
   1.352 -  have *:"\<And>x. \<forall>y\<in>range f. y * indicator (f -` {y}) x \<noteq> \<omega>"
   1.353 -    "\<forall>x\<in>range f. x * lebesgue.\<mu> (f -` {x} \<inter> UNIV) \<noteq> \<omega>"
   1.354 -    using f' om unfolding indicator_def by auto
   1.355 -  show ?case unfolding space_lebesgue real_of_pextreal_setsum'[OF *(1),THEN sym]
   1.356 -    unfolding real_of_pextreal_setsum'[OF *(2),THEN sym]
   1.357 -    unfolding real_of_pextreal_setsum space_lebesgue
   1.358 -    apply(rule has_integral_setsum)
   1.359 -  proof safe show "finite (range f)" using f by (auto dest: lebesgue.simple_functionD)
   1.360 -    fix y::'a show "((\<lambda>x. real (f y * indicator (f -` {f y}) x)) has_integral
   1.361 -      real (f y * lebesgue.\<mu> (f -` {f y} \<inter> UNIV))) UNIV"
   1.362 -    proof(cases "f y = 0") case False
   1.363 -      have mea:"(indicator (f -` {f y}) ::_\<Rightarrow>real) integrable_on UNIV"
   1.364 -        apply(rule lmeasure_finite_integrable)
   1.365 -        using assms unfolding simple_function_def using False by auto
   1.366 -      have *:"\<And>x. real (indicator (f -` {f y}) x::pextreal) = (indicator (f -` {f y}) x)"
   1.367 -        by (auto simp: indicator_def)
   1.368 -      show ?thesis unfolding real_of_pextreal_mult[THEN sym]
   1.369 -        apply(rule has_integral_cmul[where 'b=real, unfolded real_scaleR_def])
   1.370 -        unfolding Int_UNIV_right lmeasure_eq_integral[OF mea,THEN sym]
   1.371 -        unfolding integral_eq_lmeasure[OF mea, symmetric] *
   1.372 -        apply(rule integrable_integral) using mea .
   1.373 -    qed auto
   1.374 +  unfolding simple_integral_def space_lebesgue
   1.375 +proof (subst lebesgue_simple_function_indicator)
   1.376 +  let "?M x" = "lebesgue.\<mu> (f -` {x} \<inter> UNIV)"
   1.377 +  let "?F x" = "indicator (f -` {x})"
   1.378 +  { fix x y assume "y \<in> range f"
   1.379 +    from subsetD[OF f' this] have "y * ?F y x = extreal (real y * ?F y x)"
   1.380 +      by (cases rule: extreal2_cases[of y "?F y x"])
   1.381 +         (auto simp: indicator_def one_extreal_def split: split_if_asm) }
   1.382 +  moreover
   1.383 +  { fix x assume x: "x\<in>range f"
   1.384 +    have "x * ?M x = real x * real (?M x)"
   1.385 +    proof cases
   1.386 +      assume "x \<noteq> 0" with om[OF x] have "?M x \<noteq> \<infinity>" by auto
   1.387 +      with subsetD[OF f' x] f[THEN lebesgue.simple_functionD(2)] show ?thesis
   1.388 +        by (cases rule: extreal2_cases[of x "?M x"]) auto
   1.389 +    qed simp }
   1.390 +  ultimately
   1.391 +  have "((\<lambda>x. real (\<Sum>y\<in>range f. y * ?F y x)) has_integral real (\<Sum>x\<in>range f. x * ?M x)) UNIV \<longleftrightarrow>
   1.392 +    ((\<lambda>x. \<Sum>y\<in>range f. real y * ?F y x) has_integral (\<Sum>x\<in>range f. real x * real (?M x))) UNIV"
   1.393 +    by simp
   1.394 +  also have \<dots>
   1.395 +  proof (intro has_integral_setsum has_integral_cmult_real lmeasure_finite_has_integral
   1.396 +               real_of_extreal_pos lebesgue.positive_measure ballI)
   1.397 +    show *: "finite (range f)" "\<And>y. f -` {y} \<in> sets lebesgue" "\<And>y. f -` {y} \<inter> UNIV \<in> sets lebesgue"
   1.398 +      using lebesgue.simple_functionD[OF f] by auto
   1.399 +    fix y assume "real y \<noteq> 0" "y \<in> range f"
   1.400 +    with * om[OF this(2)] show "lebesgue.\<mu> (f -` {y}) = extreal (real (?M y))"
   1.401 +      by (auto simp: extreal_real)
   1.402    qed
   1.403 -qed
   1.404 +  finally show "((\<lambda>x. real (\<Sum>y\<in>range f. y * ?F y x)) has_integral real (\<Sum>x\<in>range f. x * ?M x)) UNIV" .
   1.405 +qed fact
   1.406  
   1.407  lemma bounded_realI: assumes "\<forall>x\<in>s. abs (x::real) \<le> B" shows "bounded s"
   1.408    unfolding bounded_def dist_real_def apply(rule_tac x=0 in exI)
   1.409    using assms by auto
   1.410  
   1.411  lemma simple_function_has_integral':
   1.412 -  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
   1.413 -  assumes f:"simple_function lebesgue f"
   1.414 -  and i: "integral\<^isup>S lebesgue f \<noteq> \<omega>"
   1.415 +  fixes f::"'a::ordered_euclidean_space \<Rightarrow> extreal"
   1.416 +  assumes f: "simple_function lebesgue f" "\<And>x. 0 \<le> f x"
   1.417 +  and i: "integral\<^isup>S lebesgue f \<noteq> \<infinity>"
   1.418    shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>S lebesgue f))) UNIV"
   1.419 -proof- let ?f = "\<lambda>x. if f x = \<omega> then 0 else f x"
   1.420 -  { fix x have "real (f x) = real (?f x)" by (cases "f x") auto } note * = this
   1.421 -  have **:"{x. f x \<noteq> ?f x} = f -` {\<omega>}" by auto
   1.422 -  have **:"lebesgue.\<mu> {x\<in>space lebesgue. f x \<noteq> ?f x} = 0"
   1.423 -    using lebesgue.simple_integral_omega[OF assms] by(auto simp add:**)
   1.424 -  show ?thesis apply(subst lebesgue.simple_integral_cong'[OF f _ **])
   1.425 -    apply(rule lebesgue.simple_function_compose1[OF f])
   1.426 -    unfolding * defer apply(rule simple_function_has_integral)
   1.427 -  proof-
   1.428 -    show "simple_function lebesgue ?f"
   1.429 -      using lebesgue.simple_function_compose1[OF f] .
   1.430 -    show "\<forall>x. ?f x \<noteq> \<omega>" by auto
   1.431 -    show "\<forall>x\<in>range ?f. lebesgue.\<mu> (?f -` {x} \<inter> UNIV) = \<omega> \<longrightarrow> x = 0"
   1.432 -    proof (safe, simp, safe, rule ccontr)
   1.433 -      fix y assume "f y \<noteq> \<omega>" "f y \<noteq> 0"
   1.434 -      hence "(\<lambda>x. if f x = \<omega> then 0 else f x) -` {if f y = \<omega> then 0 else f y} = f -` {f y}"
   1.435 -        by (auto split: split_if_asm)
   1.436 -      moreover assume "lebesgue.\<mu> ((\<lambda>x. if f x = \<omega> then 0 else f x) -` {if f y = \<omega> then 0 else f y}) = \<omega>"
   1.437 -      ultimately have "lebesgue.\<mu> (f -` {f y}) = \<omega>" by simp
   1.438 -      moreover
   1.439 -      have "f y * lebesgue.\<mu> (f -` {f y}) \<noteq> \<omega>" using i f
   1.440 -        unfolding simple_integral_def setsum_\<omega> simple_function_def
   1.441 -        by auto
   1.442 -      ultimately have "f y = 0" by (auto split: split_if_asm)
   1.443 -      then show False using `f y \<noteq> 0` by simp
   1.444 -    qed
   1.445 +proof -
   1.446 +  let ?f = "\<lambda>x. if x \<in> f -` {\<infinity>} then 0 else f x"
   1.447 +  note f(1)[THEN lebesgue.simple_functionD(2)]
   1.448 +  then have [simp, intro]: "\<And>X. f -` X \<in> sets lebesgue" by auto
   1.449 +  have f': "simple_function lebesgue ?f"
   1.450 +    using f by (intro lebesgue.simple_function_If_set) auto
   1.451 +  have rng: "range ?f \<subseteq> {0..<\<infinity>}" using f by auto
   1.452 +  have "AE x in lebesgue. f x = ?f x"
   1.453 +    using lebesgue.simple_integral_PInf[OF f i]
   1.454 +    by (intro lebesgue.AE_I[where N="f -` {\<infinity>} \<inter> space lebesgue"]) auto
   1.455 +  from f(1) f' this have eq: "integral\<^isup>S lebesgue f = integral\<^isup>S lebesgue ?f"
   1.456 +    by (rule lebesgue.simple_integral_cong_AE)
   1.457 +  have real_eq: "\<And>x. real (f x) = real (?f x)" by auto
   1.458 +
   1.459 +  show ?thesis
   1.460 +    unfolding eq real_eq
   1.461 +  proof (rule simple_function_has_integral[OF f' rng])
   1.462 +    fix x assume x: "x \<in> range ?f" and inf: "lebesgue.\<mu> (?f -` {x} \<inter> UNIV) = \<infinity>"
   1.463 +    have "x * lebesgue.\<mu> (?f -` {x} \<inter> UNIV) = (\<integral>\<^isup>S y. x * indicator (?f -` {x}) y \<partial>lebesgue)"
   1.464 +      using f'[THEN lebesgue.simple_functionD(2)]
   1.465 +      by (simp add: lebesgue.simple_integral_cmult_indicator)
   1.466 +    also have "\<dots> \<le> integral\<^isup>S lebesgue f"
   1.467 +      using f'[THEN lebesgue.simple_functionD(2)] f
   1.468 +      by (intro lebesgue.simple_integral_mono lebesgue.simple_function_mult lebesgue.simple_function_indicator)
   1.469 +         (auto split: split_indicator)
   1.470 +    finally show "x = 0" unfolding inf using i subsetD[OF rng x] by (auto split: split_if_asm)
   1.471    qed
   1.472  qed
   1.473  
   1.474 -lemma (in measure_space) positive_integral_monotone_convergence:
   1.475 -  fixes f::"nat \<Rightarrow> 'a \<Rightarrow> pextreal"
   1.476 -  assumes i: "\<And>i. f i \<in> borel_measurable M" and mono: "\<And>x. mono (\<lambda>n. f n x)"
   1.477 -  and lim: "\<And>x. (\<lambda>i. f i x) ----> u x"
   1.478 -  shows "u \<in> borel_measurable M"
   1.479 -  and "(\<lambda>i. integral\<^isup>P M (f i)) ----> integral\<^isup>P M u" (is ?ilim)
   1.480 -proof -
   1.481 -  from positive_integral_isoton[unfolded isoton_fun_expand isoton_iff_Lim_mono, of f u]
   1.482 -  show ?ilim using mono lim i by auto
   1.483 -  have "\<And>x. (SUP i. f i x) = u x" using mono lim SUP_Lim_pextreal
   1.484 -    unfolding fun_eq_iff mono_def by auto
   1.485 -  moreover have "(\<lambda>x. SUP i. f i x) \<in> borel_measurable M"
   1.486 -    using i by auto
   1.487 -  ultimately show "u \<in> borel_measurable M" by simp
   1.488 -qed
   1.489 +lemma real_of_extreal_positive_mono:
   1.490 +  "\<lbrakk>0 \<le> x; x \<le> y; y \<noteq> \<infinity>\<rbrakk> \<Longrightarrow> real x \<le> real y"
   1.491 +  by (cases rule: extreal2_cases[of x y]) auto
   1.492  
   1.493  lemma positive_integral_has_integral:
   1.494 -  fixes f::"'a::ordered_euclidean_space => pextreal"
   1.495 -  assumes f:"f \<in> borel_measurable lebesgue"
   1.496 -  and int_om:"integral\<^isup>P lebesgue f \<noteq> \<omega>"
   1.497 -  and f_om:"\<forall>x. f x \<noteq> \<omega>" (* TODO: remove this *)
   1.498 +  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> extreal"
   1.499 +  assumes f: "f \<in> borel_measurable lebesgue" "range f \<subseteq> {0..<\<infinity>}" "integral\<^isup>P lebesgue f \<noteq> \<infinity>"
   1.500    shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>P lebesgue f))) UNIV"
   1.501 -proof- let ?i = "integral\<^isup>P lebesgue f"
   1.502 -  from lebesgue.borel_measurable_implies_simple_function_sequence[OF f]
   1.503 -  guess u .. note conjunctD2[OF this,rule_format] note u = conjunctD2[OF this(1)] this(2)
   1.504 -  let ?u = "\<lambda>i x. real (u i x)" and ?f = "\<lambda>x. real (f x)"
   1.505 -  have u_simple:"\<And>k. integral\<^isup>S lebesgue (u k) = integral\<^isup>P lebesgue (u k)"
   1.506 -    apply(subst lebesgue.positive_integral_eq_simple_integral[THEN sym,OF u(1)]) ..
   1.507 -  have int_u_le:"\<And>k. integral\<^isup>S lebesgue (u k) \<le> integral\<^isup>P lebesgue f"
   1.508 -    unfolding u_simple apply(rule lebesgue.positive_integral_mono)
   1.509 -    using isoton_Sup[OF u(3)] unfolding le_fun_def by auto
   1.510 -  have u_int_om:"\<And>i. integral\<^isup>S lebesgue (u i) \<noteq> \<omega>"
   1.511 -  proof- case goal1 thus ?case using int_u_le[of i] int_om by auto qed
   1.512 +proof -
   1.513 +  from lebesgue.borel_measurable_implies_simple_function_sequence'[OF f(1)]
   1.514 +  guess u . note u = this
   1.515 +  have SUP_eq: "\<And>x. (SUP i. u i x) = f x"
   1.516 +    using u(4) f(2)[THEN subsetD] by (auto split: split_max)
   1.517 +  let "?u i x" = "real (u i x)"
   1.518 +  note u_eq = lebesgue.positive_integral_eq_simple_integral[OF u(1,5), symmetric]
   1.519 +  { fix i
   1.520 +    note u_eq
   1.521 +    also have "integral\<^isup>P lebesgue (u i) \<le> (\<integral>\<^isup>+x. max 0 (f x) \<partial>lebesgue)"
   1.522 +      by (intro lebesgue.positive_integral_mono) (auto intro: le_SUPI simp: u(4)[symmetric])
   1.523 +    finally have "integral\<^isup>S lebesgue (u i) \<noteq> \<infinity>"
   1.524 +      unfolding positive_integral_max_0 using f by auto }
   1.525 +  note u_fin = this
   1.526 +  then have u_int: "\<And>i. (?u i has_integral real (integral\<^isup>S lebesgue (u i))) UNIV"
   1.527 +    by (rule simple_function_has_integral'[OF u(1,5)])
   1.528 +  have "\<forall>x. \<exists>r\<ge>0. f x = extreal r"
   1.529 +  proof
   1.530 +    fix x from f(2) have "0 \<le> f x" "f x \<noteq> \<infinity>" by (auto simp: subset_eq)
   1.531 +    then show "\<exists>r\<ge>0. f x = extreal r" by (cases "f x") auto
   1.532 +  qed
   1.533 +  from choice[OF this] obtain f' where f': "f = (\<lambda>x. extreal (f' x))" "\<And>x. 0 \<le> f' x" by auto
   1.534 +
   1.535 +  have "\<forall>i. \<exists>r. \<forall>x. 0 \<le> r x \<and> u i x = extreal (r x)"
   1.536 +  proof
   1.537 +    fix i show "\<exists>r. \<forall>x. 0 \<le> r x \<and> u i x = extreal (r x)"
   1.538 +    proof (intro choice allI)
   1.539 +      fix i x have "u i x \<noteq> \<infinity>" using u(3)[of i] by (auto simp: image_iff) metis
   1.540 +      then show "\<exists>r\<ge>0. u i x = extreal r" using u(5)[of i x] by (cases "u i x") auto
   1.541 +    qed
   1.542 +  qed
   1.543 +  from choice[OF this] obtain u' where
   1.544 +      u': "u = (\<lambda>i x. extreal (u' i x))" "\<And>i x. 0 \<le> u' i x" by (auto simp: fun_eq_iff)
   1.545  
   1.546 -  note u_int = simple_function_has_integral'[OF u(1) this]
   1.547 -  have "(\<lambda>x. real (f x)) integrable_on UNIV \<and>
   1.548 -    (\<lambda>k. Integration.integral UNIV (\<lambda>x. real (u k x))) ----> Integration.integral UNIV (\<lambda>x. real (f x))"
   1.549 -    apply(rule monotone_convergence_increasing) apply(rule,rule,rule u_int)
   1.550 -  proof safe case goal1 show ?case apply(rule real_of_pextreal_mono) using u(2,3) by auto
   1.551 -  next case goal2 show ?case using u(3) apply(subst lim_Real[THEN sym])
   1.552 -      prefer 3 apply(subst Real_real') defer apply(subst Real_real')
   1.553 -      using isotone_Lim[OF u(3)[unfolded isoton_fun_expand, THEN spec]] using f_om u by auto
   1.554 -  next case goal3
   1.555 -    show ?case apply(rule bounded_realI[where B="real (integral\<^isup>P lebesgue f)"])
   1.556 -      apply safe apply(subst abs_of_nonneg) apply(rule integral_nonneg,rule) apply(rule u_int)
   1.557 -      unfolding integral_unique[OF u_int] defer apply(rule real_of_pextreal_mono[OF _ int_u_le])
   1.558 -      using u int_om by auto
   1.559 -  qed note int = conjunctD2[OF this]
   1.560 +  have convergent: "f' integrable_on UNIV \<and>
   1.561 +    (\<lambda>k. integral UNIV (u' k)) ----> integral UNIV f'"
   1.562 +  proof (intro monotone_convergence_increasing allI ballI)
   1.563 +    show int: "\<And>k. (u' k) integrable_on UNIV"
   1.564 +      using u_int unfolding integrable_on_def u' by auto
   1.565 +    show "\<And>k x. u' k x \<le> u' (Suc k) x" using u(2,3,5)
   1.566 +      by (auto simp: incseq_Suc_iff le_fun_def image_iff u' intro!: real_of_extreal_positive_mono)
   1.567 +    show "\<And>x. (\<lambda>k. u' k x) ----> f' x"
   1.568 +      using SUP_eq u(2)
   1.569 +      by (intro SUP_eq_LIMSEQ[THEN iffD1]) (auto simp: u' f' incseq_mono incseq_Suc_iff le_fun_def)
   1.570 +    show "bounded {integral UNIV (u' k)|k. True}"
   1.571 +    proof (safe intro!: bounded_realI)
   1.572 +      fix k
   1.573 +      have "\<bar>integral UNIV (u' k)\<bar> = integral UNIV (u' k)"
   1.574 +        by (intro abs_of_nonneg integral_nonneg int ballI u')
   1.575 +      also have "\<dots> = real (integral\<^isup>S lebesgue (u k))"
   1.576 +        using u_int[THEN integral_unique] by (simp add: u')
   1.577 +      also have "\<dots> = real (integral\<^isup>P lebesgue (u k))"
   1.578 +        using lebesgue.positive_integral_eq_simple_integral[OF u(1,5)] by simp
   1.579 +      also have "\<dots> \<le> real (integral\<^isup>P lebesgue f)" using f
   1.580 +        by (auto intro!: real_of_extreal_positive_mono lebesgue.positive_integral_positive
   1.581 +             lebesgue.positive_integral_mono le_SUPI simp: SUP_eq[symmetric])
   1.582 +      finally show "\<bar>integral UNIV (u' k)\<bar> \<le> real (integral\<^isup>P lebesgue f)" .
   1.583 +    qed
   1.584 +  qed
   1.585  
   1.586 -  have "(\<lambda>i. integral\<^isup>S lebesgue (u i)) ----> ?i" unfolding u_simple
   1.587 -    apply(rule lebesgue.positive_integral_monotone_convergence(2))
   1.588 -    apply(rule lebesgue.borel_measurable_simple_function[OF u(1)])
   1.589 -    using isotone_Lim[OF u(3)[unfolded isoton_fun_expand, THEN spec]] by auto
   1.590 -  hence "(\<lambda>i. real (integral\<^isup>S lebesgue (u i))) ----> real ?i" apply-
   1.591 -    apply(subst lim_Real[THEN sym]) prefer 3
   1.592 -    apply(subst Real_real') defer apply(subst Real_real')
   1.593 -    using u f_om int_om u_int_om by auto
   1.594 -  note * = LIMSEQ_unique[OF this int(2)[unfolded integral_unique[OF u_int]]]
   1.595 -  show ?thesis unfolding * by(rule integrable_integral[OF int(1)])
   1.596 +  have "integral\<^isup>P lebesgue f = extreal (integral UNIV f')"
   1.597 +  proof (rule tendsto_unique[OF trivial_limit_sequentially])
   1.598 +    have "(\<lambda>i. integral\<^isup>S lebesgue (u i)) ----> (SUP i. integral\<^isup>P lebesgue (u i))"
   1.599 +      unfolding u_eq by (intro LIMSEQ_extreal_SUPR lebesgue.incseq_positive_integral u)
   1.600 +    also note lebesgue.positive_integral_monotone_convergence_SUP
   1.601 +      [OF u(2)  lebesgue.borel_measurable_simple_function[OF u(1)] u(5), symmetric]
   1.602 +    finally show "(\<lambda>k. integral\<^isup>S lebesgue (u k)) ----> integral\<^isup>P lebesgue f"
   1.603 +      unfolding SUP_eq .
   1.604 +
   1.605 +    { fix k
   1.606 +      have "0 \<le> integral\<^isup>S lebesgue (u k)"
   1.607 +        using u by (auto intro!: lebesgue.simple_integral_positive)
   1.608 +      then have "integral\<^isup>S lebesgue (u k) = extreal (real (integral\<^isup>S lebesgue (u k)))"
   1.609 +        using u_fin by (auto simp: extreal_real) }
   1.610 +    note * = this
   1.611 +    show "(\<lambda>k. integral\<^isup>S lebesgue (u k)) ----> extreal (integral UNIV f')"
   1.612 +      using convergent using u_int[THEN integral_unique, symmetric]
   1.613 +      by (subst *) (simp add: lim_extreal u')
   1.614 +  qed
   1.615 +  then show ?thesis using convergent by (simp add: f' integrable_integral)
   1.616  qed
   1.617  
   1.618  lemma lebesgue_integral_has_integral:
   1.619 -  fixes f::"'a::ordered_euclidean_space => real"
   1.620 -  assumes f:"integrable lebesgue f"
   1.621 +  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   1.622 +  assumes f: "integrable lebesgue f"
   1.623    shows "(f has_integral (integral\<^isup>L lebesgue f)) UNIV"
   1.624 -proof- let ?n = "\<lambda>x. - min (f x) 0" and ?p = "\<lambda>x. max (f x) 0"
   1.625 -  have *:"f = (\<lambda>x. ?p x - ?n x)" apply rule by auto
   1.626 -  note f = integrableD[OF f]
   1.627 -  show ?thesis unfolding lebesgue_integral_def apply(subst *)
   1.628 -  proof(rule has_integral_sub) case goal1
   1.629 -    have *:"\<forall>x. Real (f x) \<noteq> \<omega>" by auto
   1.630 -    note lebesgue.borel_measurable_Real[OF f(1)]
   1.631 -    from positive_integral_has_integral[OF this f(2) *]
   1.632 -    show ?case unfolding real_Real_max .
   1.633 -  next case goal2
   1.634 -    have *:"\<forall>x. Real (- f x) \<noteq> \<omega>" by auto
   1.635 -    note lebesgue.borel_measurable_uminus[OF f(1)]
   1.636 -    note lebesgue.borel_measurable_Real[OF this]
   1.637 -    from positive_integral_has_integral[OF this f(3) *]
   1.638 -    show ?case unfolding real_Real_max minus_min_eq_max by auto
   1.639 -  qed
   1.640 +proof -
   1.641 +  let ?n = "\<lambda>x. real (extreal (max 0 (- f x)))" and ?p = "\<lambda>x. real (extreal (max 0 (f x)))"
   1.642 +  have *: "f = (\<lambda>x. ?p x - ?n x)" by (auto simp del: extreal_max)
   1.643 +  { fix f have "(\<integral>\<^isup>+ x. extreal (f x) \<partial>lebesgue) = (\<integral>\<^isup>+ x. extreal (max 0 (f x)) \<partial>lebesgue)"
   1.644 +      by (intro lebesgue.positive_integral_cong_pos) (auto split: split_max) }
   1.645 +  note eq = this
   1.646 +  show ?thesis
   1.647 +    unfolding lebesgue_integral_def
   1.648 +    apply (subst *)
   1.649 +    apply (rule has_integral_sub)
   1.650 +    unfolding eq[of f] eq[of "\<lambda>x. - f x"]
   1.651 +    apply (safe intro!: positive_integral_has_integral)
   1.652 +    using integrableD[OF f]
   1.653 +    by (auto simp: zero_extreal_def[symmetric] positive_integral_max_0  split: split_max
   1.654 +             intro!: lebesgue.measurable_If lebesgue.borel_measurable_extreal)
   1.655  qed
   1.656  
   1.657  lemma lebesgue_positive_integral_eq_borel:
   1.658 -  "f \<in> borel_measurable borel \<Longrightarrow> integral\<^isup>P lebesgue f = integral\<^isup>P lborel f"
   1.659 -  by (auto intro!: lebesgue.positive_integral_subalgebra[symmetric]) default
   1.660 +  assumes f: "f \<in> borel_measurable borel"
   1.661 +  shows "integral\<^isup>P lebesgue f = integral\<^isup>P lborel f"
   1.662 +proof -
   1.663 +  from f have "integral\<^isup>P lebesgue (\<lambda>x. max 0 (f x)) = integral\<^isup>P lborel (\<lambda>x. max 0 (f x))"
   1.664 +    by (auto intro!: lebesgue.positive_integral_subalgebra[symmetric]) default
   1.665 +  then show ?thesis unfolding positive_integral_max_0 .
   1.666 +qed
   1.667  
   1.668  lemma lebesgue_integral_eq_borel:
   1.669    assumes "f \<in> borel_measurable borel"
   1.670 @@ -771,7 +827,7 @@
   1.671    have "sets ?G = sets (\<Pi>\<^isub>M i\<in>I.
   1.672         sigma \<lparr> space = UNIV::real set, sets = range lessThan, measure = lebesgue.\<mu> \<rparr>)"
   1.673      by (subst sigma_product_algebra_sigma_eq[of I "\<lambda>_ i. {..<real i}" ])
   1.674 -       (auto intro!: measurable_sigma_sigma isotoneI real_arch_lt
   1.675 +       (auto intro!: measurable_sigma_sigma incseq_SucI real_arch_lt
   1.676               simp: product_algebra_def)
   1.677    then show ?thesis
   1.678      unfolding lborel_def borel_eq_lessThan lebesgue_def sigma_def by simp
   1.679 @@ -838,9 +894,10 @@
   1.680    let ?E = "\<lparr> space = UNIV :: 'a set, sets = range (\<lambda>(a,b). {a..b}) \<rparr>"
   1.681    show "Int_stable ?E" using Int_stable_cuboids .
   1.682    show "range cube \<subseteq> sets ?E" unfolding cube_def_raw by auto
   1.683 +  show "incseq cube" using cube_subset_Suc by (auto intro!: incseq_SucI)
   1.684    { fix x have "\<exists>n. x \<in> cube n" using mem_big_cube[of x] by fastsimp }
   1.685 -  then show "cube \<up> space ?E" by (intro isotoneI cube_subset_Suc) auto
   1.686 -  { fix i show "lborel.\<mu> (cube i) \<noteq> \<omega>" unfolding cube_def by auto }
   1.687 +  then show "(\<Union>i. cube i) = space ?E" by auto
   1.688 +  { fix i show "lborel.\<mu> (cube i) \<noteq> \<infinity>" unfolding cube_def by auto }
   1.689    show "A \<in> sets (sigma ?E)" "sets (sigma ?E) = sets lborel" "space ?E = space lborel"
   1.690      using assms by (simp_all add: borel_eq_atLeastAtMost)
   1.691  
   1.692 @@ -857,7 +914,7 @@
   1.693          by (simp add: interval_ne_empty eucl_le[where 'a='a])
   1.694        then have "lborel.\<mu> X = (\<Prod>x<DIM('a). lborel.\<mu> {a $$ x .. b $$ x})"
   1.695          by (auto simp: content_closed_interval eucl_le[where 'a='a]
   1.696 -                 intro!: Real_setprod )
   1.697 +                 intro!: setprod_extreal[symmetric])
   1.698        also have "\<dots> = measure ?P (?T X)"
   1.699          unfolding * by (subst lborel_space.measure_times) auto
   1.700        finally show ?thesis .
   1.701 @@ -882,7 +939,7 @@
   1.702    using lborel_eq_lborel_space[OF A] by simp
   1.703  
   1.704  lemma borel_fubini_positiv_integral:
   1.705 -  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> pextreal"
   1.706 +  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> extreal"
   1.707    assumes f: "f \<in> borel_measurable borel"
   1.708    shows "integral\<^isup>P lborel f = \<integral>\<^isup>+x. f (p2e x) \<partial>(lborel_space.P DIM('a))"
   1.709  proof (rule lborel_space.positive_integral_vimage[OF _ measure_preserving_p2e _])