src/HOL/Probability/Radon_Nikodym.thy
changeset 41981 cdf7693bbe08
parent 41832 27cb9113b1a0
child 42067 66c8281349ec
     1.1 --- a/src/HOL/Probability/Radon_Nikodym.thy	Mon Mar 14 14:37:47 2011 +0100
     1.2 +++ b/src/HOL/Probability/Radon_Nikodym.thy	Mon Mar 14 14:37:49 2011 +0100
     1.3 @@ -2,87 +2,81 @@
     1.4  imports Lebesgue_Integration
     1.5  begin
     1.6  
     1.7 -lemma less_\<omega>_Ex_of_nat: "x < \<omega> \<longleftrightarrow> (\<exists>n. x < of_nat n)"
     1.8 -proof safe
     1.9 -  assume "x < \<omega>"
    1.10 -  then obtain r where "0 \<le> r" "x = Real r" by (cases x) auto
    1.11 -  moreover obtain n where "r < of_nat n" using ex_less_of_nat by auto
    1.12 -  ultimately show "\<exists>n. x < of_nat n" by (auto simp: real_eq_of_nat)
    1.13 -qed auto
    1.14 -
    1.15  lemma (in sigma_finite_measure) Ex_finite_integrable_function:
    1.16 -  shows "\<exists>h\<in>borel_measurable M. integral\<^isup>P M h \<noteq> \<omega> \<and> (\<forall>x\<in>space M. 0 < h x \<and> h x < \<omega>)"
    1.17 +  shows "\<exists>h\<in>borel_measurable M. integral\<^isup>P M h \<noteq> \<infinity> \<and> (\<forall>x\<in>space M. 0 < h x \<and> h x < \<infinity>) \<and> (\<forall>x. 0 \<le> h x)"
    1.18  proof -
    1.19    obtain A :: "nat \<Rightarrow> 'a set" where
    1.20      range: "range A \<subseteq> sets M" and
    1.21      space: "(\<Union>i. A i) = space M" and
    1.22 -    measure: "\<And>i. \<mu> (A i) \<noteq> \<omega>" and
    1.23 +    measure: "\<And>i. \<mu> (A i) \<noteq> \<infinity>" and
    1.24      disjoint: "disjoint_family A"
    1.25      using disjoint_sigma_finite by auto
    1.26    let "?B i" = "2^Suc i * \<mu> (A i)"
    1.27    have "\<forall>i. \<exists>x. 0 < x \<and> x < inverse (?B i)"
    1.28    proof
    1.29 -    fix i show "\<exists>x. 0 < x \<and> x < inverse (?B i)"
    1.30 -    proof cases
    1.31 -      assume "\<mu> (A i) = 0"
    1.32 -      then show ?thesis by (auto intro!: exI[of _ 1])
    1.33 -    next
    1.34 -      assume not_0: "\<mu> (A i) \<noteq> 0"
    1.35 -      then have "?B i \<noteq> \<omega>" using measure[of i] by auto
    1.36 -      then have "inverse (?B i) \<noteq> 0" unfolding pextreal_inverse_eq_0 by simp
    1.37 -      then show ?thesis using measure[of i] not_0
    1.38 -        by (auto intro!: exI[of _ "inverse (?B i) / 2"]
    1.39 -                 simp: pextreal_noteq_omega_Ex zero_le_mult_iff zero_less_mult_iff mult_le_0_iff power_le_zero_eq)
    1.40 -    qed
    1.41 +    fix i have Ai: "A i \<in> sets M" using range by auto
    1.42 +    from measure positive_measure[OF this]
    1.43 +    show "\<exists>x. 0 < x \<and> x < inverse (?B i)"
    1.44 +      by (auto intro!: extreal_dense simp: extreal_0_gt_inverse)
    1.45    qed
    1.46    from choice[OF this] obtain n where n: "\<And>i. 0 < n i"
    1.47      "\<And>i. n i < inverse (2^Suc i * \<mu> (A i))" by auto
    1.48 -  let "?h x" = "\<Sum>\<^isub>\<infinity> i. n i * indicator (A i) x"
    1.49 +  { fix i have "0 \<le> n i" using n(1)[of i] by auto } note pos = this
    1.50 +  let "?h x" = "\<Sum>i. n i * indicator (A i) x"
    1.51    show ?thesis
    1.52    proof (safe intro!: bexI[of _ ?h] del: notI)
    1.53      have "\<And>i. A i \<in> sets M"
    1.54        using range by fastsimp+
    1.55 -    then have "integral\<^isup>P M ?h = (\<Sum>\<^isub>\<infinity> i. n i * \<mu> (A i))"
    1.56 -      by (simp add: positive_integral_psuminf positive_integral_cmult_indicator)
    1.57 -    also have "\<dots> \<le> (\<Sum>\<^isub>\<infinity> i. Real ((1 / 2)^Suc i))"
    1.58 -    proof (rule psuminf_le)
    1.59 -      fix N show "n N * \<mu> (A N) \<le> Real ((1 / 2) ^ Suc N)"
    1.60 +    then have "integral\<^isup>P M ?h = (\<Sum>i. n i * \<mu> (A i))" using pos
    1.61 +      by (simp add: positive_integral_suminf positive_integral_cmult_indicator)
    1.62 +    also have "\<dots> \<le> (\<Sum>i. (1 / 2)^Suc i)"
    1.63 +    proof (rule suminf_le_pos)
    1.64 +      fix N
    1.65 +      have "n N * \<mu> (A N) \<le> inverse (2^Suc N * \<mu> (A N)) * \<mu> (A N)"
    1.66 +        using positive_measure[OF `A N \<in> sets M`] n[of N]
    1.67 +        by (intro extreal_mult_right_mono) auto
    1.68 +      also have "\<dots> \<le> (1 / 2) ^ Suc N"
    1.69          using measure[of N] n[of N]
    1.70 -        by (cases "n N")
    1.71 -           (auto simp: pextreal_noteq_omega_Ex field_simps zero_le_mult_iff
    1.72 -                       mult_le_0_iff mult_less_0_iff power_less_zero_eq
    1.73 -                       power_le_zero_eq inverse_eq_divide less_divide_eq
    1.74 -                       power_divide split: split_if_asm)
    1.75 +        by (cases rule: extreal2_cases[of "n N" "\<mu> (A N)"])
    1.76 +           (simp_all add: inverse_eq_divide power_divide one_extreal_def extreal_power_divide)
    1.77 +      finally show "n N * \<mu> (A N) \<le> (1 / 2) ^ Suc N" .
    1.78 +      show "0 \<le> n N * \<mu> (A N)" using n[of N] `A N \<in> sets M` by simp
    1.79      qed
    1.80 -    also have "\<dots> = Real 1"
    1.81 -      by (rule suminf_imp_psuminf, rule power_half_series, auto)
    1.82 -    finally show "integral\<^isup>P M ?h \<noteq> \<omega>" by auto
    1.83 +    finally show "integral\<^isup>P M ?h \<noteq> \<infinity>" unfolding suminf_half_series_extreal by auto
    1.84    next
    1.85 -    fix x assume "x \<in> space M"
    1.86 -    then obtain i where "x \<in> A i" using space[symmetric] by auto
    1.87 -    from psuminf_cmult_indicator[OF disjoint, OF this]
    1.88 -    have "?h x = n i" by simp
    1.89 -    then show "0 < ?h x" and "?h x < \<omega>" using n[of i] by auto
    1.90 +    { fix x assume "x \<in> space M"
    1.91 +      then obtain i where "x \<in> A i" using space[symmetric] by auto
    1.92 +      with disjoint n have "?h x = n i"
    1.93 +        by (auto intro!: suminf_cmult_indicator intro: less_imp_le)
    1.94 +      then show "0 < ?h x" and "?h x < \<infinity>" using n[of i] by auto }
    1.95 +    note pos = this
    1.96 +    fix x show "0 \<le> ?h x"
    1.97 +    proof cases
    1.98 +      assume "x \<in> space M" then show "0 \<le> ?h x" using pos by (auto intro: less_imp_le)
    1.99 +    next
   1.100 +      assume "x \<notin> space M" then have "\<And>i. x \<notin> A i" using space by auto
   1.101 +      then show "0 \<le> ?h x" by auto
   1.102 +    qed
   1.103    next
   1.104 -    show "?h \<in> borel_measurable M" using range
   1.105 -      by (auto intro!: borel_measurable_psuminf borel_measurable_pextreal_times)
   1.106 +    show "?h \<in> borel_measurable M" using range n
   1.107 +      by (auto intro!: borel_measurable_psuminf borel_measurable_extreal_times extreal_0_le_mult intro: less_imp_le)
   1.108    qed
   1.109  qed
   1.110  
   1.111  subsection "Absolutely continuous"
   1.112  
   1.113  definition (in measure_space)
   1.114 -  "absolutely_continuous \<nu> = (\<forall>N\<in>null_sets. \<nu> N = (0 :: pextreal))"
   1.115 +  "absolutely_continuous \<nu> = (\<forall>N\<in>null_sets. \<nu> N = (0 :: extreal))"
   1.116  
   1.117  lemma (in measure_space) absolutely_continuous_AE:
   1.118    assumes "measure_space M'" and [simp]: "sets M' = sets M" "space M' = space M"
   1.119      and "absolutely_continuous (measure M')" "AE x. P x"
   1.120 -  shows "measure_space.almost_everywhere M' P"
   1.121 +   shows "AE x in M'. P x"
   1.122  proof -
   1.123    interpret \<nu>: measure_space M' by fact
   1.124    from `AE x. P x` obtain N where N: "N \<in> null_sets" and "{x\<in>space M. \<not> P x} \<subseteq> N"
   1.125      unfolding almost_everywhere_def by auto
   1.126 -  show "\<nu>.almost_everywhere P"
   1.127 +  show "AE x in M'. P x"
   1.128    proof (rule \<nu>.AE_I')
   1.129      show "{x\<in>space M'. \<not> P x} \<subseteq> N" by simp fact
   1.130      from `absolutely_continuous (measure M')` show "N \<in> \<nu>.null_sets"
   1.131 @@ -99,7 +93,7 @@
   1.132    interpret v: finite_measure_space ?\<nu> by fact
   1.133    have "\<nu> N = measure ?\<nu> (\<Union>x\<in>N. {x})" by simp
   1.134    also have "\<dots> = (\<Sum>x\<in>N. measure ?\<nu> {x})"
   1.135 -  proof (rule v.measure_finitely_additive''[symmetric])
   1.136 +  proof (rule v.measure_setsum[symmetric])
   1.137      show "finite N" using `N \<subseteq> space M` finite_space by (auto intro: finite_subset)
   1.138      show "disjoint_family_on (\<lambda>i. {i}) N" unfolding disjoint_family_on_def by auto
   1.139      fix x assume "x \<in> N" thus "{x} \<in> sets ?\<nu>" using `N \<subseteq> space M` sets_eq_Pow by auto
   1.140 @@ -107,8 +101,10 @@
   1.141    also have "\<dots> = 0"
   1.142    proof (safe intro!: setsum_0')
   1.143      fix x assume "x \<in> N"
   1.144 -    hence "\<mu> {x} \<le> \<mu> N" using sets_eq_Pow `N \<subseteq> space M` by (auto intro!: measure_mono)
   1.145 -    hence "\<mu> {x} = 0" using `\<mu> N = 0` by simp
   1.146 +    hence "\<mu> {x} \<le> \<mu> N" "0 \<le> \<mu> {x}"
   1.147 +      using sets_eq_Pow `N \<subseteq> space M` positive_measure[of "{x}"]
   1.148 +      by (auto intro!: measure_mono)
   1.149 +    then have "\<mu> {x} = 0" using `\<mu> N = 0` by simp
   1.150      thus "measure ?\<nu> {x} = 0" using v[of x] `x \<in> N` `N \<subseteq> space M` by auto
   1.151    qed
   1.152    finally show "\<nu> N = 0" by simp
   1.153 @@ -125,12 +121,12 @@
   1.154  lemma (in finite_measure) Radon_Nikodym_aux_epsilon:
   1.155    fixes e :: real assumes "0 < e"
   1.156    assumes "finite_measure (M\<lparr>measure := \<nu>\<rparr>)"
   1.157 -  shows "\<exists>A\<in>sets M. real (\<mu> (space M)) - real (\<nu> (space M)) \<le>
   1.158 -                    real (\<mu> A) - real (\<nu> A) \<and>
   1.159 -                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> - e < real (\<mu> B) - real (\<nu> B))"
   1.160 +  shows "\<exists>A\<in>sets M. \<mu>' (space M) - finite_measure.\<mu>' (M\<lparr>measure := \<nu>\<rparr>) (space M) \<le>
   1.161 +                    \<mu>' A - finite_measure.\<mu>' (M\<lparr>measure := \<nu>\<rparr>) A \<and>
   1.162 +                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> - e < \<mu>' B - finite_measure.\<mu>' (M\<lparr>measure := \<nu>\<rparr>) B)"
   1.163  proof -
   1.164 -  let "?d A" = "real (\<mu> A) - real (\<nu> A)"
   1.165    interpret M': finite_measure "M\<lparr>measure := \<nu>\<rparr>" by fact
   1.166 +  let "?d A" = "\<mu>' A - M'.\<mu>' A"
   1.167    let "?A A" = "if (\<forall>B\<in>sets M. B \<subseteq> space M - A \<longrightarrow> -e < ?d B)
   1.168      then {}
   1.169      else (SOME B. B \<in> sets M \<and> B \<subseteq> space M - A \<and> ?d B \<le> -e)"
   1.170 @@ -157,7 +153,7 @@
   1.171        fix B assume "B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e"
   1.172        hence "A n \<inter> B = {}" "B \<in> sets M" and dB: "?d B \<le> -e" by auto
   1.173        hence "?d (A n \<union> B) = ?d (A n) + ?d B"
   1.174 -        using `A n \<in> sets M` real_finite_measure_Union M'.real_finite_measure_Union by simp
   1.175 +        using `A n \<in> sets M` finite_measure_Union M'.finite_measure_Union by simp
   1.176        also have "\<dots> \<le> ?d (A n) - e" using dB by simp
   1.177        finally show "?d (A n \<union> B) \<le> ?d (A n) - e" .
   1.178      qed }
   1.179 @@ -186,11 +182,7 @@
   1.180          fix n assume "?d (space M) \<le> ?d (space M - A n)"
   1.181          also have "\<dots> \<le> ?d (space M - A (Suc n))"
   1.182            using A_in_sets sets_into_space dA_mono[of n]
   1.183 -            real_finite_measure_Diff[of "space M"]
   1.184 -            real_finite_measure_Diff[of "space M"]
   1.185 -            M'.real_finite_measure_Diff[of "space M"]
   1.186 -            M'.real_finite_measure_Diff[of "space M"]
   1.187 -          by (simp del: A_simps)
   1.188 +          by (simp del: A_simps add: finite_measure_Diff M'.finite_measure_Diff)
   1.189          finally show "?d (space M) \<le> ?d (space M - A (Suc n))" .
   1.190        qed simp
   1.191      qed
   1.192 @@ -200,13 +192,16 @@
   1.193      { fix n have "?d (A n) \<le> - real n * e"
   1.194        proof (induct n)
   1.195          case (Suc n) with dA_epsilon[of n, OF B] show ?case by (simp del: A_simps add: real_of_nat_Suc field_simps)
   1.196 -      qed simp } note dA_less = this
   1.197 +      next
   1.198 +        case 0 with M'.empty_measure show ?case by (simp add: zero_extreal_def)
   1.199 +      qed } note dA_less = this
   1.200      have decseq: "decseq (\<lambda>n. ?d (A n))" unfolding decseq_eq_incseq
   1.201      proof (rule incseq_SucI)
   1.202        fix n show "- ?d (A n) \<le> - ?d (A (Suc n))" using dA_mono[of n] by auto
   1.203      qed
   1.204 -    from real_finite_continuity_from_below[of A] `range A \<subseteq> sets M`
   1.205 -      M'.real_finite_continuity_from_below[of A]
   1.206 +    have A: "incseq A" by (auto intro!: incseq_SucI)
   1.207 +    from finite_continuity_from_below[OF _ A] `range A \<subseteq> sets M`
   1.208 +      M'.finite_continuity_from_below[OF _ A]
   1.209      have convergent: "(\<lambda>i. ?d (A i)) ----> ?d (\<Union>i. A i)"
   1.210        by (auto intro!: LIMSEQ_diff)
   1.211      obtain n :: nat where "- ?d (\<Union>i. A i) / e < real n" using reals_Archimedean2 by auto
   1.212 @@ -216,33 +211,55 @@
   1.213    qed
   1.214  qed
   1.215  
   1.216 +lemma (in finite_measure) restricted_measure_subset:
   1.217 +  assumes S: "S \<in> sets M" and X: "X \<subseteq> S"
   1.218 +  shows "finite_measure.\<mu>' (restricted_space S) X = \<mu>' X"
   1.219 +proof cases
   1.220 +  note r = restricted_finite_measure[OF S]
   1.221 +  { assume "X \<in> sets M" with S X show ?thesis
   1.222 +      unfolding finite_measure.\<mu>'_def[OF r] \<mu>'_def by auto }
   1.223 +  { assume "X \<notin> sets M"
   1.224 +    moreover then have "S \<inter> X \<notin> sets M"
   1.225 +      using X by (simp add: Int_absorb1)
   1.226 +    ultimately show ?thesis
   1.227 +      unfolding finite_measure.\<mu>'_def[OF r] \<mu>'_def using S by auto }
   1.228 +qed
   1.229 +
   1.230 +lemma (in finite_measure) restricted_measure:
   1.231 +  assumes X: "S \<in> sets M" "X \<in> sets (restricted_space S)"
   1.232 +  shows "finite_measure.\<mu>' (restricted_space S) X = \<mu>' X"
   1.233 +proof -
   1.234 +  from X have "S \<in> sets M" "X \<subseteq> S" by auto
   1.235 +  from restricted_measure_subset[OF this] show ?thesis .
   1.236 +qed
   1.237 +
   1.238  lemma (in finite_measure) Radon_Nikodym_aux:
   1.239    assumes "finite_measure (M\<lparr>measure := \<nu>\<rparr>)" (is "finite_measure ?M'")
   1.240 -  shows "\<exists>A\<in>sets M. real (\<mu> (space M)) - real (\<nu> (space M)) \<le>
   1.241 -                    real (\<mu> A) - real (\<nu> A) \<and>
   1.242 -                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> 0 \<le> real (\<mu> B) - real (\<nu> B))"
   1.243 +  shows "\<exists>A\<in>sets M. \<mu>' (space M) - finite_measure.\<mu>' (M\<lparr>measure := \<nu>\<rparr>) (space M) \<le>
   1.244 +                    \<mu>' A - finite_measure.\<mu>' (M\<lparr>measure := \<nu>\<rparr>) A \<and>
   1.245 +                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> 0 \<le> \<mu>' B - finite_measure.\<mu>' (M\<lparr>measure := \<nu>\<rparr>) B)"
   1.246  proof -
   1.247 -  let "?d A" = "real (\<mu> A) - real (\<nu> A)"
   1.248 -  let "?P A B n" = "A \<in> sets M \<and> A \<subseteq> B \<and> ?d B \<le> ?d A \<and> (\<forall>C\<in>sets M. C \<subseteq> A \<longrightarrow> - 1 / real (Suc n) < ?d C)"
   1.249    interpret M': finite_measure ?M' where
   1.250      "space ?M' = space M" and "sets ?M' = sets M" and "measure ?M' = \<nu>" by fact auto
   1.251 +  let "?d A" = "\<mu>' A - M'.\<mu>' A"
   1.252 +  let "?P A B n" = "A \<in> sets M \<and> A \<subseteq> B \<and> ?d B \<le> ?d A \<and> (\<forall>C\<in>sets M. C \<subseteq> A \<longrightarrow> - 1 / real (Suc n) < ?d C)"
   1.253    let "?r S" = "restricted_space S"
   1.254 -  { fix S n
   1.255 -    assume S: "S \<in> sets M"
   1.256 -    hence **: "\<And>X. X \<in> op \<inter> S ` sets M \<longleftrightarrow> X \<in> sets M \<and> X \<subseteq> S" by auto
   1.257 -    have [simp]: "(restricted_space S\<lparr>measure := \<nu>\<rparr>) = M'.restricted_space S"
   1.258 -      by (cases M) simp
   1.259 -    from M'.restricted_finite_measure[of S] restricted_finite_measure[OF S] S
   1.260 -    have "finite_measure (?r S)" "0 < 1 / real (Suc n)"
   1.261 +  { fix S n assume S: "S \<in> sets M"
   1.262 +    note r = M'.restricted_finite_measure[of S] restricted_finite_measure[OF S] S
   1.263 +    then have "finite_measure (?r S)" "0 < 1 / real (Suc n)"
   1.264        "finite_measure (?r S\<lparr>measure := \<nu>\<rparr>)" by auto
   1.265 -    from finite_measure.Radon_Nikodym_aux_epsilon[OF this] guess X ..
   1.266 -    hence "?P X S n"
   1.267 -    proof (simp add: **, safe)
   1.268 -      fix C assume C: "C \<in> sets M" "C \<subseteq> X" "X \<subseteq> S" and
   1.269 -        *: "\<forall>B\<in>sets M. S \<inter> B \<subseteq> X \<longrightarrow> - (1 / real (Suc n)) < ?d (S \<inter> B)"
   1.270 -      hence "C \<subseteq> S" "C \<subseteq> X" "S \<inter> C = C" by auto
   1.271 -      with *[THEN bspec, OF `C \<in> sets M`]
   1.272 -      show "- (1 / real (Suc n)) < ?d C" by auto
   1.273 +    from finite_measure.Radon_Nikodym_aux_epsilon[OF this] guess X .. note X = this
   1.274 +    have "?P X S n"
   1.275 +    proof (intro conjI ballI impI)
   1.276 +      show "X \<in> sets M" "X \<subseteq> S" using X(1) `S \<in> sets M` by auto
   1.277 +      have "S \<in> op \<inter> S ` sets M" using `S \<in> sets M` by auto
   1.278 +      then show "?d S \<le> ?d X"
   1.279 +        using S X restricted_measure[OF S] M'.restricted_measure[OF S] by simp
   1.280 +      fix C assume "C \<in> sets M" "C \<subseteq> X"
   1.281 +      then have "C \<in> sets (restricted_space S)" "C \<subseteq> X"
   1.282 +        using `S \<in> sets M` `X \<subseteq> S` by auto
   1.283 +      with X(2) show "- 1 / real (Suc n) < ?d C"
   1.284 +        using S X restricted_measure[OF S] M'.restricted_measure[OF S] by auto
   1.285      qed
   1.286      hence "\<exists>A. ?P A S n" by auto }
   1.287    note Ex_P = this
   1.288 @@ -268,10 +285,11 @@
   1.289    show ?thesis
   1.290    proof (safe intro!: bexI[of _ "\<Inter>i. A i"])
   1.291      show "(\<Inter>i. A i) \<in> sets M" using A_in_sets by auto
   1.292 -    from `range A \<subseteq> sets M` A_mono
   1.293 -      real_finite_continuity_from_above[of A]
   1.294 -      M'.real_finite_continuity_from_above[of A]
   1.295 -    have "(\<lambda>i. ?d (A i)) ----> ?d (\<Inter>i. A i)" by (auto intro!: LIMSEQ_diff)
   1.296 +    have A: "decseq A" using A_mono by (auto intro!: decseq_SucI)
   1.297 +    from
   1.298 +      finite_continuity_from_above[OF `range A \<subseteq> sets M` A]
   1.299 +      M'.finite_continuity_from_above[OF `range A \<subseteq> sets M` A]
   1.300 +    have "(\<lambda>i. ?d (A i)) ----> ?d (\<Inter>i. A i)" by (intro LIMSEQ_diff)
   1.301      thus "?d (space M) \<le> ?d (\<Inter>i. A i)" using mono_dA[THEN monoD, of 0 _]
   1.302        by (rule_tac LIMSEQ_le_const) (auto intro!: exI)
   1.303    next
   1.304 @@ -290,6 +308,10 @@
   1.305    qed
   1.306  qed
   1.307  
   1.308 +lemma (in finite_measure) real_measure:
   1.309 +  assumes A: "A \<in> sets M" shows "\<exists>r. 0 \<le> r \<and> \<mu> A = extreal r"
   1.310 +  using finite_measure[OF A] positive_measure[OF A] by (cases "\<mu> A") auto
   1.311 +
   1.312  lemma (in finite_measure) Radon_Nikodym_finite_measure:
   1.313    assumes "finite_measure (M\<lparr> measure := \<nu>\<rparr>)" (is "finite_measure ?M'")
   1.314    assumes "absolutely_continuous \<nu>"
   1.315 @@ -298,7 +320,7 @@
   1.316    interpret M': finite_measure ?M'
   1.317      where "space ?M' = space M" and "sets ?M' = sets M" and "measure ?M' = \<nu>"
   1.318      using assms(1) by auto
   1.319 -  def G \<equiv> "{g \<in> borel_measurable M. \<forall>A\<in>sets M. (\<integral>\<^isup>+x. g x * indicator A x \<partial>M) \<le> \<nu> A}"
   1.320 +  def G \<equiv> "{g \<in> borel_measurable M. (\<forall>x. 0 \<le> g x) \<and> (\<forall>A\<in>sets M. (\<integral>\<^isup>+x. g x * indicator A x \<partial>M) \<le> \<nu> A)}"
   1.321    have "(\<lambda>x. 0) \<in> G" unfolding G_def by auto
   1.322    hence "G \<noteq> {}" by auto
   1.323    { fix f g assume f: "f \<in> G" and g: "g \<in> G"
   1.324 @@ -324,24 +346,28 @@
   1.325        also have "\<dots> = \<nu> A"
   1.326          using M'.measure_additive[OF sets] union by auto
   1.327        finally show "(\<integral>\<^isup>+x. max (g x) (f x) * indicator A x \<partial>M) \<le> \<nu> A" .
   1.328 +    next
   1.329 +      fix x show "0 \<le> max (g x) (f x)" using f g by (auto simp: G_def split: split_max)
   1.330      qed }
   1.331    note max_in_G = this
   1.332 -  { fix f g assume  "f \<up> g" and f: "\<And>i. f i \<in> G"
   1.333 -    have "g \<in> G" unfolding G_def
   1.334 +  { fix f assume  "incseq f" and f: "\<And>i. f i \<in> G"
   1.335 +    have "(\<lambda>x. SUP i. f i x) \<in> G" unfolding G_def
   1.336      proof safe
   1.337 -      from `f \<up> g` have [simp]: "g = (\<lambda>x. SUP i. f i x)"
   1.338 -        unfolding isoton_def fun_eq_iff SUPR_apply by simp
   1.339 -      have f_borel: "\<And>i. f i \<in> borel_measurable M" using f unfolding G_def by simp
   1.340 -      thus "g \<in> borel_measurable M" by auto
   1.341 +      show "(\<lambda>x. SUP i. f i x) \<in> borel_measurable M"
   1.342 +        using f by (auto simp: G_def)
   1.343 +      { fix x show "0 \<le> (SUP i. f i x)"
   1.344 +          using f by (auto simp: G_def intro: le_SUPI2) }
   1.345 +    next
   1.346        fix A assume "A \<in> sets M"
   1.347 -      hence "\<And>i. (\<lambda>x. f i x * indicator A x) \<in> borel_measurable M"
   1.348 -        using f_borel by (auto intro!: borel_measurable_indicator)
   1.349 -      from positive_integral_isoton[OF isoton_indicator[OF `f \<up> g`] this]
   1.350 -      have SUP: "(\<integral>\<^isup>+x. g x * indicator A x \<partial>M) =
   1.351 -          (SUP i. (\<integral>\<^isup>+x. f i x * indicator A x \<partial>M))"
   1.352 -        unfolding isoton_def by simp
   1.353 -      show "(\<integral>\<^isup>+x. g x * indicator A x \<partial>M) \<le> \<nu> A" unfolding SUP
   1.354 -        using f `A \<in> sets M` unfolding G_def by (auto intro!: SUP_leI)
   1.355 +      have "(\<integral>\<^isup>+x. (SUP i. f i x) * indicator A x \<partial>M) =
   1.356 +        (\<integral>\<^isup>+x. (SUP i. f i x * indicator A x) \<partial>M)"
   1.357 +        by (intro positive_integral_cong) (simp split: split_indicator)
   1.358 +      also have "\<dots> = (SUP i. (\<integral>\<^isup>+x. f i x * indicator A x \<partial>M))"
   1.359 +        using `incseq f` f `A \<in> sets M`
   1.360 +        by (intro positive_integral_monotone_convergence_SUP)
   1.361 +           (auto simp: G_def incseq_Suc_iff le_fun_def split: split_indicator)
   1.362 +      finally show "(\<integral>\<^isup>+x. (SUP i. f i x) * indicator A x \<partial>M) \<le> \<nu> A"
   1.363 +        using f `A \<in> sets M` by (auto intro!: SUP_leI simp: G_def)
   1.364      qed }
   1.365    note SUP_in_G = this
   1.366    let ?y = "SUP g : G. integral\<^isup>P M g"
   1.367 @@ -351,9 +377,8 @@
   1.368      from this[THEN bspec, OF top] show "integral\<^isup>P M g \<le> \<nu> (space M)"
   1.369        by (simp cong: positive_integral_cong)
   1.370    qed
   1.371 -  hence "?y \<noteq> \<omega>" using M'.finite_measure_of_space by auto
   1.372 -  from SUPR_countable_SUPR[OF this `G \<noteq> {}`] guess ys .. note ys = this
   1.373 -  hence "\<forall>n. \<exists>g. g\<in>G \<and> integral\<^isup>P M g = ys n"
   1.374 +  from SUPR_countable_SUPR[OF `G \<noteq> {}`, of "integral\<^isup>P M"] guess ys .. note ys = this
   1.375 +  then have "\<forall>n. \<exists>g. g\<in>G \<and> integral\<^isup>P M g = ys n"
   1.376    proof safe
   1.377      fix n assume "range ys \<subseteq> integral\<^isup>P M ` G"
   1.378      hence "ys n \<in> integral\<^isup>P M ` G" by auto
   1.379 @@ -362,8 +387,9 @@
   1.380    from choice[OF this] obtain gs where "\<And>i. gs i \<in> G" "\<And>n. integral\<^isup>P M (gs n) = ys n" by auto
   1.381    hence y_eq: "?y = (SUP i. integral\<^isup>P M (gs i))" using ys by auto
   1.382    let "?g i x" = "Max ((\<lambda>n. gs n x) ` {..i})"
   1.383 -  def f \<equiv> "SUP i. ?g i"
   1.384 -  have gs_not_empty: "\<And>i. (\<lambda>n. gs n x) ` {..i} \<noteq> {}" by auto
   1.385 +  def f \<equiv> "\<lambda>x. SUP i. ?g i x"
   1.386 +  let "?F A x" = "f x * indicator A x"
   1.387 +  have gs_not_empty: "\<And>i x. (\<lambda>n. gs n x) ` {..i} \<noteq> {}" by auto
   1.388    { fix i have "?g i \<in> G"
   1.389      proof (induct i)
   1.390        case 0 thus ?case by simp fact
   1.391 @@ -373,15 +399,13 @@
   1.392          by (auto simp add: atMost_Suc intro!: max_in_G)
   1.393      qed }
   1.394    note g_in_G = this
   1.395 -  have "\<And>x. \<forall>i. ?g i x \<le> ?g (Suc i) x"
   1.396 -    using gs_not_empty by (simp add: atMost_Suc)
   1.397 -  hence isoton_g: "?g \<up> f" by (simp add: isoton_def le_fun_def f_def)
   1.398 -  from SUP_in_G[OF this g_in_G] have "f \<in> G" .
   1.399 -  hence [simp, intro]: "f \<in> borel_measurable M" unfolding G_def by auto
   1.400 -  have "(\<lambda>i. integral\<^isup>P M (?g i)) \<up> integral\<^isup>P M f"
   1.401 -    using isoton_g g_in_G by (auto intro!: positive_integral_isoton simp: G_def f_def)
   1.402 -  hence "integral\<^isup>P M f = (SUP i. integral\<^isup>P M (?g i))"
   1.403 -    unfolding isoton_def by simp
   1.404 +  have "incseq ?g" using gs_not_empty
   1.405 +    by (auto intro!: incseq_SucI le_funI simp add: atMost_Suc)
   1.406 +  from SUP_in_G[OF this g_in_G] have "f \<in> G" unfolding f_def .
   1.407 +  then have [simp, intro]: "f \<in> borel_measurable M" unfolding G_def by auto
   1.408 +  have "integral\<^isup>P M f = (SUP i. integral\<^isup>P M (?g i))" unfolding f_def
   1.409 +    using g_in_G `incseq ?g`
   1.410 +    by (auto intro!: positive_integral_monotone_convergence_SUP simp: G_def)
   1.411    also have "\<dots> = ?y"
   1.412    proof (rule antisym)
   1.413      show "(SUP i. integral\<^isup>P M (?g i)) \<le> ?y"
   1.414 @@ -390,42 +414,57 @@
   1.415        by (auto intro!: SUP_mono positive_integral_mono Max_ge)
   1.416    qed
   1.417    finally have int_f_eq_y: "integral\<^isup>P M f = ?y" .
   1.418 -  let "?t A" = "\<nu> A - (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
   1.419 +  have "\<And>x. 0 \<le> f x"
   1.420 +    unfolding f_def using `\<And>i. gs i \<in> G`
   1.421 +    by (auto intro!: le_SUPI2 Max_ge_iff[THEN iffD2] simp: G_def)
   1.422 +  let "?t A" = "\<nu> A - (\<integral>\<^isup>+x. ?F A x \<partial>M)"
   1.423    let ?M = "M\<lparr> measure := ?t\<rparr>"
   1.424    interpret M: sigma_algebra ?M
   1.425      by (intro sigma_algebra_cong) auto
   1.426 +  have f_le_\<nu>: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+x. ?F A x \<partial>M) \<le> \<nu> A"
   1.427 +    using `f \<in> G` unfolding G_def by auto
   1.428    have fmM: "finite_measure ?M"
   1.429 -  proof (default, simp_all add: countably_additive_def, safe)
   1.430 +  proof (default, simp_all add: countably_additive_def positive_def, safe del: notI)
   1.431      fix A :: "nat \<Rightarrow> 'a set"  assume A: "range A \<subseteq> sets M" "disjoint_family A"
   1.432 -    have "(\<Sum>\<^isub>\<infinity> n. (\<integral>\<^isup>+x. f x * indicator (A n) x \<partial>M))
   1.433 -      = (\<integral>\<^isup>+x. (\<Sum>\<^isub>\<infinity>n. f x * indicator (A n) x) \<partial>M)"
   1.434 -      using `range A \<subseteq> sets M`
   1.435 -      by (rule_tac positive_integral_psuminf[symmetric]) (auto intro!: borel_measurable_indicator)
   1.436 -    also have "\<dots> = (\<integral>\<^isup>+x. f x * indicator (\<Union>n. A n) x \<partial>M)"
   1.437 -      apply (rule positive_integral_cong)
   1.438 -      apply (subst psuminf_cmult_right)
   1.439 -      unfolding psuminf_indicator[OF `disjoint_family A`] ..
   1.440 -    finally have "(\<Sum>\<^isub>\<infinity> n. (\<integral>\<^isup>+x. f x * indicator (A n) x \<partial>M))
   1.441 -      = (\<integral>\<^isup>+x. f x * indicator (\<Union>n. A n) x \<partial>M)" .
   1.442 -    moreover have "(\<Sum>\<^isub>\<infinity>n. \<nu> (A n)) = \<nu> (\<Union>n. A n)"
   1.443 +    have "(\<Sum>n. (\<integral>\<^isup>+x. ?F (A n) x \<partial>M)) = (\<integral>\<^isup>+x. (\<Sum>n. ?F (A n) x) \<partial>M)"
   1.444 +      using `range A \<subseteq> sets M` `\<And>x. 0 \<le> f x`
   1.445 +      by (intro positive_integral_suminf[symmetric]) auto
   1.446 +    also have "\<dots> = (\<integral>\<^isup>+x. ?F (\<Union>n. A n) x \<partial>M)"
   1.447 +      using `\<And>x. 0 \<le> f x`
   1.448 +      by (intro positive_integral_cong) (simp add: suminf_cmult_extreal suminf_indicator[OF `disjoint_family A`])
   1.449 +    finally have "(\<Sum>n. (\<integral>\<^isup>+x. ?F (A n) x \<partial>M)) = (\<integral>\<^isup>+x. ?F (\<Union>n. A n) x \<partial>M)" .
   1.450 +    moreover have "(\<Sum>n. \<nu> (A n)) = \<nu> (\<Union>n. A n)"
   1.451        using M'.measure_countably_additive A by (simp add: comp_def)
   1.452 -    moreover have "\<And>i. (\<integral>\<^isup>+x. f x * indicator (A i) x \<partial>M) \<le> \<nu> (A i)"
   1.453 -        using A `f \<in> G` unfolding G_def by auto
   1.454 -    moreover have v_fin: "\<nu> (\<Union>i. A i) \<noteq> \<omega>" using M'.finite_measure A by (simp add: countable_UN)
   1.455 +    moreover have v_fin: "\<nu> (\<Union>i. A i) \<noteq> \<infinity>" using M'.finite_measure A by (simp add: countable_UN)
   1.456      moreover {
   1.457 -      have "(\<integral>\<^isup>+x. f x * indicator (\<Union>i. A i) x \<partial>M) \<le> \<nu> (\<Union>i. A i)"
   1.458 +      have "(\<integral>\<^isup>+x. ?F (\<Union>i. A i) x \<partial>M) \<le> \<nu> (\<Union>i. A i)"
   1.459          using A `f \<in> G` unfolding G_def by (auto simp: countable_UN)
   1.460 -      also have "\<nu> (\<Union>i. A i) < \<omega>" using v_fin by (simp add: pextreal_less_\<omega>)
   1.461 -      finally have "(\<integral>\<^isup>+x. f x * indicator (\<Union>i. A i) x \<partial>M) \<noteq> \<omega>"
   1.462 -        by (simp add: pextreal_less_\<omega>) }
   1.463 +      also have "\<nu> (\<Union>i. A i) < \<infinity>" using v_fin by simp
   1.464 +      finally have "(\<integral>\<^isup>+x. ?F (\<Union>i. A i) x \<partial>M) \<noteq> \<infinity>" by simp }
   1.465 +    moreover have "\<And>i. (\<integral>\<^isup>+x. ?F (A i) x \<partial>M) \<le> \<nu> (A i)"
   1.466 +      using A by (intro f_le_\<nu>) auto
   1.467      ultimately
   1.468 -    show "(\<Sum>\<^isub>\<infinity> n. ?t (A n)) = ?t (\<Union>i. A i)"
   1.469 -      apply (subst psuminf_minus) by simp_all
   1.470 +    show "(\<Sum>n. ?t (A n)) = ?t (\<Union>i. A i)"
   1.471 +      by (subst suminf_extreal_minus) (simp_all add: positive_integral_positive)
   1.472 +  next
   1.473 +    fix A assume A: "A \<in> sets M" show "0 \<le> \<nu> A - \<integral>\<^isup>+ x. ?F A x \<partial>M"
   1.474 +      using f_le_\<nu>[OF A] `f \<in> G` M'.finite_measure[OF A] by (auto simp: G_def extreal_le_minus_iff)
   1.475 +  next
   1.476 +    show "\<nu> (space M) - (\<integral>\<^isup>+ x. ?F (space M) x \<partial>M) \<noteq> \<infinity>" (is "?a - ?b \<noteq> _")
   1.477 +      using positive_integral_positive[of "?F (space M)"]
   1.478 +      by (cases rule: extreal2_cases[of ?a ?b]) auto
   1.479    qed
   1.480    then interpret M: finite_measure ?M
   1.481      where "space ?M = space M" and "sets ?M = sets M" and "measure ?M = ?t"
   1.482      by (simp_all add: fmM)
   1.483 -  have ac: "absolutely_continuous ?t" using `absolutely_continuous \<nu>` unfolding absolutely_continuous_def by auto
   1.484 +  have ac: "absolutely_continuous ?t" unfolding absolutely_continuous_def
   1.485 +  proof
   1.486 +    fix N assume N: "N \<in> null_sets"
   1.487 +    with `absolutely_continuous \<nu>` have "\<nu> N = 0" unfolding absolutely_continuous_def by auto
   1.488 +    moreover with N have "(\<integral>\<^isup>+ x. ?F N x \<partial>M) \<le> \<nu> N" using `f \<in> G` by (auto simp: G_def)
   1.489 +    ultimately show "\<nu> N - (\<integral>\<^isup>+ x. ?F N x \<partial>M) = 0"
   1.490 +      using positive_integral_positive by (auto intro!: antisym)
   1.491 +  qed
   1.492    have upper_bound: "\<forall>A\<in>sets M. ?t A \<le> 0"
   1.493    proof (rule ccontr)
   1.494      assume "\<not> ?thesis"
   1.495 @@ -436,43 +475,54 @@
   1.496        using M.measure_mono[of A "space M"] A sets_into_space by simp
   1.497      finally have pos_t: "0 < ?t (space M)" by simp
   1.498      moreover
   1.499 -    hence pos_M: "0 < \<mu> (space M)"
   1.500 -      using ac top unfolding absolutely_continuous_def by auto
   1.501 +    then have "\<mu> (space M) \<noteq> 0"
   1.502 +      using ac unfolding absolutely_continuous_def by auto
   1.503 +    then have pos_M: "0 < \<mu> (space M)"
   1.504 +      using positive_measure[OF top] by (simp add: le_less)
   1.505      moreover
   1.506      have "(\<integral>\<^isup>+x. f x * indicator (space M) x \<partial>M) \<le> \<nu> (space M)"
   1.507        using `f \<in> G` unfolding G_def by auto
   1.508 -    hence "(\<integral>\<^isup>+x. f x * indicator (space M) x \<partial>M) \<noteq> \<omega>"
   1.509 +    hence "(\<integral>\<^isup>+x. f x * indicator (space M) x \<partial>M) \<noteq> \<infinity>"
   1.510        using M'.finite_measure_of_space by auto
   1.511      moreover
   1.512      def b \<equiv> "?t (space M) / \<mu> (space M) / 2"
   1.513 -    ultimately have b: "b \<noteq> 0" "b \<noteq> \<omega>"
   1.514 -      using M'.finite_measure_of_space
   1.515 -      by (auto simp: pextreal_inverse_eq_0 finite_measure_of_space)
   1.516 +    ultimately have b: "b \<noteq> 0 \<and> 0 \<le> b \<and> b \<noteq> \<infinity>"
   1.517 +      using M'.finite_measure_of_space positive_integral_positive[of "?F (space M)"]
   1.518 +      by (cases rule: extreal3_cases[of "integral\<^isup>P M (?F (space M))" "\<nu> (space M)" "\<mu> (space M)"])
   1.519 +         (simp_all add: field_simps)
   1.520 +    then have b: "b \<noteq> 0" "0 \<le> b" "0 < b"  "b \<noteq> \<infinity>" by auto
   1.521      let ?Mb = "?M\<lparr>measure := \<lambda>A. b * \<mu> A\<rparr>"
   1.522      interpret b: sigma_algebra ?Mb by (intro sigma_algebra_cong) auto
   1.523 -    have "finite_measure ?Mb"
   1.524 -      by default
   1.525 -         (insert finite_measure_of_space b measure_countably_additive,
   1.526 -          auto simp: psuminf_cmult_right countably_additive_def)
   1.527 +    have Mb: "finite_measure ?Mb"
   1.528 +    proof
   1.529 +      show "positive ?Mb (measure ?Mb)"
   1.530 +        using `0 \<le> b` by (auto simp: positive_def)
   1.531 +      show "countably_additive ?Mb (measure ?Mb)"
   1.532 +        using `0 \<le> b` measure_countably_additive
   1.533 +        by (auto simp: countably_additive_def suminf_cmult_extreal subset_eq)
   1.534 +      show "measure ?Mb (space ?Mb) \<noteq> \<infinity>"
   1.535 +        using b by auto
   1.536 +    qed
   1.537      from M.Radon_Nikodym_aux[OF this]
   1.538      obtain A0 where "A0 \<in> sets M" and
   1.539        space_less_A0: "real (?t (space M)) - real (b * \<mu> (space M)) \<le> real (?t A0) - real (b * \<mu> A0)" and
   1.540 -      *: "\<And>B. \<lbrakk> B \<in> sets M ; B \<subseteq> A0 \<rbrakk> \<Longrightarrow> 0 \<le> real (?t B) - real (b * \<mu> B)" by auto
   1.541 -    { fix B assume "B \<in> sets M" "B \<subseteq> A0"
   1.542 +      *: "\<And>B. \<lbrakk> B \<in> sets M ; B \<subseteq> A0 \<rbrakk> \<Longrightarrow> 0 \<le> real (?t B) - real (b * \<mu> B)"
   1.543 +      unfolding M.\<mu>'_def finite_measure.\<mu>'_def[OF Mb] by auto
   1.544 +    { fix B assume B: "B \<in> sets M" "B \<subseteq> A0"
   1.545        with *[OF this] have "b * \<mu> B \<le> ?t B"
   1.546 -        using M'.finite_measure b finite_measure
   1.547 -        by (cases "b * \<mu> B", cases "?t B") (auto simp: field_simps) }
   1.548 +        using M'.finite_measure b finite_measure M.positive_measure[OF B(1)]
   1.549 +        by (cases rule: extreal2_cases[of "?t B" "b * \<mu> B"]) auto }
   1.550      note bM_le_t = this
   1.551      let "?f0 x" = "f x + b * indicator A0 x"
   1.552      { fix A assume A: "A \<in> sets M"
   1.553        hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
   1.554        have "(\<integral>\<^isup>+x. ?f0 x  * indicator A x \<partial>M) =
   1.555          (\<integral>\<^isup>+x. f x * indicator A x + b * indicator (A \<inter> A0) x \<partial>M)"
   1.556 -        by (auto intro!: positive_integral_cong simp: field_simps indicator_inter_arith)
   1.557 +        by (auto intro!: positive_integral_cong split: split_indicator)
   1.558        hence "(\<integral>\<^isup>+x. ?f0 x * indicator A x \<partial>M) =
   1.559            (\<integral>\<^isup>+x. f x * indicator A x \<partial>M) + b * \<mu> (A \<inter> A0)"
   1.560 -        using `A0 \<in> sets M` `A \<inter> A0 \<in> sets M` A
   1.561 -        by (simp add: borel_measurable_indicator positive_integral_add positive_integral_cmult_indicator) }
   1.562 +        using `A0 \<in> sets M` `A \<inter> A0 \<in> sets M` A b `f \<in> G`
   1.563 +        by (simp add: G_def positive_integral_add positive_integral_cmult_indicator) }
   1.564      note f0_eq = this
   1.565      { fix A assume A: "A \<in> sets M"
   1.566        hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
   1.567 @@ -487,39 +537,57 @@
   1.568          using M.measure_mono[simplified, OF _ `A \<inter> A0 \<in> sets M` `A \<in> sets M`]
   1.569          by (auto intro!: add_left_mono)
   1.570        also have "\<dots> \<le> \<nu> A"
   1.571 -        using f_le_v M'.finite_measure[simplified, OF `A \<in> sets M`]
   1.572 -        by (cases "(\<integral>\<^isup>+x. f x * indicator A x \<partial>M)", cases "\<nu> A", auto)
   1.573 +        using f_le_v M'.finite_measure[simplified, OF `A \<in> sets M`] positive_integral_positive[of "?F A"]
   1.574 +        by (cases "\<integral>\<^isup>+x. ?F A x \<partial>M", cases "\<nu> A") auto
   1.575        finally have "(\<integral>\<^isup>+x. ?f0 x * indicator A x \<partial>M) \<le> \<nu> A" . }
   1.576 -    hence "?f0 \<in> G" using `A0 \<in> sets M` unfolding G_def
   1.577 -      by (auto intro!: borel_measurable_indicator borel_measurable_pextreal_add borel_measurable_pextreal_times)
   1.578 -    have real: "?t (space M) \<noteq> \<omega>" "?t A0 \<noteq> \<omega>"
   1.579 -      "b * \<mu> (space M) \<noteq> \<omega>" "b * \<mu> A0 \<noteq> \<omega>"
   1.580 +    hence "?f0 \<in> G" using `A0 \<in> sets M` b `f \<in> G` unfolding G_def
   1.581 +      by (auto intro!: borel_measurable_indicator borel_measurable_extreal_add
   1.582 +                       borel_measurable_extreal_times extreal_add_nonneg_nonneg)
   1.583 +    have real: "?t (space M) \<noteq> \<infinity>" "?t A0 \<noteq> \<infinity>"
   1.584 +      "b * \<mu> (space M) \<noteq> \<infinity>" "b * \<mu> A0 \<noteq> \<infinity>"
   1.585        using `A0 \<in> sets M` b
   1.586          finite_measure[of A0] M.finite_measure[of A0]
   1.587          finite_measure_of_space M.finite_measure_of_space
   1.588        by auto
   1.589 -    have int_f_finite: "integral\<^isup>P M f \<noteq> \<omega>"
   1.590 -      using M'.finite_measure_of_space pos_t unfolding pextreal_zero_less_diff_iff
   1.591 +    have int_f_finite: "integral\<^isup>P M f \<noteq> \<infinity>"
   1.592 +      using M'.finite_measure_of_space pos_t unfolding extreal_less_minus_iff
   1.593        by (auto cong: positive_integral_cong)
   1.594 -    have "?t (space M) > b * \<mu> (space M)" unfolding b_def
   1.595 -      apply (simp add: field_simps)
   1.596 -      apply (subst mult_assoc[symmetric])
   1.597 -      apply (subst pextreal_mult_inverse)
   1.598 +    have  "0 < ?t (space M) - b * \<mu> (space M)" unfolding b_def
   1.599        using finite_measure_of_space M'.finite_measure_of_space pos_t pos_M
   1.600 -      using pextreal_mult_strict_right_mono[of "Real (1/2)" 1 "?t (space M)"]
   1.601 -      by simp_all
   1.602 -    hence  "0 < ?t (space M) - b * \<mu> (space M)"
   1.603 -      by (simp add: pextreal_zero_less_diff_iff)
   1.604 +      using positive_integral_positive[of "?F (space M)"]
   1.605 +      by (cases rule: extreal3_cases[of "\<mu> (space M)" "\<nu> (space M)" "integral\<^isup>P M (?F (space M))"])
   1.606 +         (auto simp: field_simps mult_less_cancel_left)
   1.607      also have "\<dots> \<le> ?t A0 - b * \<mu> A0"
   1.608 -      using space_less_A0 pos_M pos_t b real[unfolded pextreal_noteq_omega_Ex] by auto
   1.609 -    finally have "b * \<mu> A0 < ?t A0" unfolding pextreal_zero_less_diff_iff .
   1.610 -    hence "0 < ?t A0" by auto
   1.611 -    hence "0 < \<mu> A0" using ac unfolding absolutely_continuous_def
   1.612 +      using space_less_A0 b
   1.613 +      using
   1.614 +        `A0 \<in> sets M`[THEN M.real_measure]
   1.615 +        top[THEN M.real_measure]
   1.616 +      apply safe
   1.617 +      apply simp
   1.618 +      using
   1.619 +        `A0 \<in> sets M`[THEN real_measure]
   1.620 +        `A0 \<in> sets M`[THEN M'.real_measure]
   1.621 +        top[THEN real_measure]
   1.622 +        top[THEN M'.real_measure]
   1.623 +      by (cases b) auto
   1.624 +    finally have 1: "b * \<mu> A0 < ?t A0"
   1.625 +      using
   1.626 +        `A0 \<in> sets M`[THEN M.real_measure]
   1.627 +      apply safe
   1.628 +      apply simp
   1.629 +      using
   1.630 +        `A0 \<in> sets M`[THEN real_measure]
   1.631 +        `A0 \<in> sets M`[THEN M'.real_measure]
   1.632 +      by (cases b) auto
   1.633 +    have "0 < ?t A0"
   1.634 +      using b `A0 \<in> sets M` by (auto intro!: le_less_trans[OF _ 1])
   1.635 +    then have "\<mu> A0 \<noteq> 0" using ac unfolding absolutely_continuous_def
   1.636        using `A0 \<in> sets M` by auto
   1.637 -    hence "0 < b * \<mu> A0" using b by auto
   1.638 -    from int_f_finite this
   1.639 -    have "?y + 0 < integral\<^isup>P M f + b * \<mu> A0" unfolding int_f_eq_y
   1.640 -      by (rule pextreal_less_add)
   1.641 +    then have "0 < \<mu> A0" using positive_measure[OF `A0 \<in> sets M`] by auto
   1.642 +    hence "0 < b * \<mu> A0" using b by (auto simp: extreal_zero_less_0_iff)
   1.643 +    with int_f_finite have "?y + 0 < integral\<^isup>P M f + b * \<mu> A0" unfolding int_f_eq_y
   1.644 +      using `f \<in> G`
   1.645 +      by (intro extreal_add_strict_mono) (auto intro!: le_SUPI2 positive_integral_positive)
   1.646      also have "\<dots> = integral\<^isup>P M ?f0" using f0_eq[OF top] `A0 \<in> sets M` sets_into_space
   1.647        by (simp cong: positive_integral_cong)
   1.648      finally have "?y < integral\<^isup>P M ?f0" by simp
   1.649 @@ -528,14 +596,15 @@
   1.650    qed
   1.651    show ?thesis
   1.652    proof (safe intro!: bexI[of _ f])
   1.653 -    fix A assume "A\<in>sets M"
   1.654 +    fix A assume A: "A\<in>sets M"
   1.655      show "\<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
   1.656      proof (rule antisym)
   1.657        show "(\<integral>\<^isup>+x. f x * indicator A x \<partial>M) \<le> \<nu> A"
   1.658          using `f \<in> G` `A \<in> sets M` unfolding G_def by auto
   1.659        show "\<nu> A \<le> (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
   1.660          using upper_bound[THEN bspec, OF `A \<in> sets M`]
   1.661 -         by (simp add: pextreal_zero_le_diff)
   1.662 +        using M'.real_measure[OF A]
   1.663 +        by (cases "integral\<^isup>P M (?F A)") auto
   1.664      qed
   1.665    qed simp
   1.666  qed
   1.667 @@ -543,22 +612,22 @@
   1.668  lemma (in finite_measure) split_space_into_finite_sets_and_rest:
   1.669    assumes "measure_space (M\<lparr>measure := \<nu>\<rparr>)" (is "measure_space ?N")
   1.670    assumes ac: "absolutely_continuous \<nu>"
   1.671 -  shows "\<exists>\<Omega>0\<in>sets M. \<exists>\<Omega>::nat\<Rightarrow>'a set. disjoint_family \<Omega> \<and> range \<Omega> \<subseteq> sets M \<and> \<Omega>0 = space M - (\<Union>i. \<Omega> i) \<and>
   1.672 -    (\<forall>A\<in>sets M. A \<subseteq> \<Omega>0 \<longrightarrow> (\<mu> A = 0 \<and> \<nu> A = 0) \<or> (\<mu> A > 0 \<and> \<nu> A = \<omega>)) \<and>
   1.673 -    (\<forall>i. \<nu> (\<Omega> i) \<noteq> \<omega>)"
   1.674 +  shows "\<exists>A0\<in>sets M. \<exists>B::nat\<Rightarrow>'a set. disjoint_family B \<and> range B \<subseteq> sets M \<and> A0 = space M - (\<Union>i. B i) \<and>
   1.675 +    (\<forall>A\<in>sets M. A \<subseteq> A0 \<longrightarrow> (\<mu> A = 0 \<and> \<nu> A = 0) \<or> (\<mu> A > 0 \<and> \<nu> A = \<infinity>)) \<and>
   1.676 +    (\<forall>i. \<nu> (B i) \<noteq> \<infinity>)"
   1.677  proof -
   1.678    interpret v: measure_space ?N
   1.679      where "space ?N = space M" and "sets ?N = sets M" and "measure ?N = \<nu>"
   1.680      by fact auto
   1.681 -  let ?Q = "{Q\<in>sets M. \<nu> Q \<noteq> \<omega>}"
   1.682 +  let ?Q = "{Q\<in>sets M. \<nu> Q \<noteq> \<infinity>}"
   1.683    let ?a = "SUP Q:?Q. \<mu> Q"
   1.684    have "{} \<in> ?Q" using v.empty_measure by auto
   1.685    then have Q_not_empty: "?Q \<noteq> {}" by blast
   1.686    have "?a \<le> \<mu> (space M)" using sets_into_space
   1.687      by (auto intro!: SUP_leI measure_mono top)
   1.688 -  then have "?a \<noteq> \<omega>" using finite_measure_of_space
   1.689 +  then have "?a \<noteq> \<infinity>" using finite_measure_of_space
   1.690      by auto
   1.691 -  from SUPR_countable_SUPR[OF this Q_not_empty]
   1.692 +  from SUPR_countable_SUPR[OF Q_not_empty, of \<mu>]
   1.693    obtain Q'' where "range Q'' \<subseteq> \<mu> ` ?Q" and a: "?a = (SUP i::nat. Q'' i)"
   1.694      by auto
   1.695    then have "\<forall>i. \<exists>Q'. Q'' i = \<mu> Q' \<and> Q' \<in> ?Q" by auto
   1.696 @@ -569,7 +638,7 @@
   1.697    have Union: "(SUP i. \<mu> (?O i)) = \<mu> (\<Union>i. ?O i)"
   1.698    proof (rule continuity_from_below[of ?O])
   1.699      show "range ?O \<subseteq> sets M" using Q' by (auto intro!: finite_UN)
   1.700 -    show "\<And>i. ?O i \<subseteq> ?O (Suc i)" by fastsimp
   1.701 +    show "incseq ?O" by (fastsimp intro!: incseq_SucI)
   1.702    qed
   1.703    have Q'_sets: "\<And>i. Q' i \<in> sets M" using Q' by auto
   1.704    have O_sets: "\<And>i. ?O i \<in> sets M"
   1.705 @@ -580,8 +649,8 @@
   1.706        using Q' by (auto intro: finite_UN)
   1.707      with v.measure_finitely_subadditive[of "{.. i}" Q']
   1.708      have "\<nu> (?O i) \<le> (\<Sum>i\<le>i. \<nu> (Q' i))" by auto
   1.709 -    also have "\<dots> < \<omega>" unfolding setsum_\<omega> pextreal_less_\<omega> using Q' by auto
   1.710 -    finally show "\<nu> (?O i) \<noteq> \<omega>" unfolding pextreal_less_\<omega> by auto
   1.711 +    also have "\<dots> < \<infinity>" using Q' by (simp add: setsum_Pinfty)
   1.712 +    finally show "\<nu> (?O i) \<noteq> \<infinity>" by simp
   1.713    qed auto
   1.714    have O_mono: "\<And>n. ?O n \<subseteq> ?O (Suc n)" by fastsimp
   1.715    have a_eq: "?a = \<mu> (\<Union>i. ?O i)" unfolding Union[symmetric]
   1.716 @@ -592,7 +661,7 @@
   1.717      proof (safe intro!: Sup_mono, unfold bex_simps)
   1.718        fix i
   1.719        have *: "(\<Union>Q' ` {..i}) = ?O i" by auto
   1.720 -      then show "\<exists>x. (x \<in> sets M \<and> \<nu> x \<noteq> \<omega>) \<and>
   1.721 +      then show "\<exists>x. (x \<in> sets M \<and> \<nu> x \<noteq> \<infinity>) \<and>
   1.722          \<mu> (\<Union>Q' ` {..i}) \<le> \<mu> x"
   1.723          using O_in_G[of i] by (auto intro!: exI[of _ "?O i"])
   1.724      qed
   1.725 @@ -610,50 +679,52 @@
   1.726      show "range Q \<subseteq> sets M"
   1.727        using Q_sets by auto
   1.728      { fix A assume A: "A \<in> sets M" "A \<subseteq> space M - ?O_0"
   1.729 -      show "\<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<omega>"
   1.730 +      show "\<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<infinity>"
   1.731        proof (rule disjCI, simp)
   1.732 -        assume *: "0 < \<mu> A \<longrightarrow> \<nu> A \<noteq> \<omega>"
   1.733 +        assume *: "0 < \<mu> A \<longrightarrow> \<nu> A \<noteq> \<infinity>"
   1.734          show "\<mu> A = 0 \<and> \<nu> A = 0"
   1.735          proof cases
   1.736            assume "\<mu> A = 0" moreover with ac A have "\<nu> A = 0"
   1.737              unfolding absolutely_continuous_def by auto
   1.738            ultimately show ?thesis by simp
   1.739          next
   1.740 -          assume "\<mu> A \<noteq> 0" with * have "\<nu> A \<noteq> \<omega>" by auto
   1.741 +          assume "\<mu> A \<noteq> 0" with * have "\<nu> A \<noteq> \<infinity>" using positive_measure[OF A(1)] by auto
   1.742            with A have "\<mu> ?O_0 + \<mu> A = \<mu> (?O_0 \<union> A)"
   1.743              using Q' by (auto intro!: measure_additive countable_UN)
   1.744            also have "\<dots> = (SUP i. \<mu> (?O i \<union> A))"
   1.745            proof (rule continuity_from_below[of "\<lambda>i. ?O i \<union> A", symmetric, simplified])
   1.746              show "range (\<lambda>i. ?O i \<union> A) \<subseteq> sets M"
   1.747 -              using `\<nu> A \<noteq> \<omega>` O_sets A by auto
   1.748 -          qed fastsimp
   1.749 +              using `\<nu> A \<noteq> \<infinity>` O_sets A by auto
   1.750 +          qed (fastsimp intro!: incseq_SucI)
   1.751            also have "\<dots> \<le> ?a"
   1.752 -          proof (safe intro!: SUPR_bound)
   1.753 +          proof (safe intro!: SUP_leI)
   1.754              fix i have "?O i \<union> A \<in> ?Q"
   1.755              proof (safe del: notI)
   1.756                show "?O i \<union> A \<in> sets M" using O_sets A by auto
   1.757                from O_in_G[of i]
   1.758                moreover have "\<nu> (?O i \<union> A) \<le> \<nu> (?O i) + \<nu> A"
   1.759                  using v.measure_subadditive[of "?O i" A] A O_sets by auto
   1.760 -              ultimately show "\<nu> (?O i \<union> A) \<noteq> \<omega>"
   1.761 -                using `\<nu> A \<noteq> \<omega>` by auto
   1.762 +              ultimately show "\<nu> (?O i \<union> A) \<noteq> \<infinity>"
   1.763 +                using `\<nu> A \<noteq> \<infinity>` by auto
   1.764              qed
   1.765              then show "\<mu> (?O i \<union> A) \<le> ?a" by (rule le_SUPI)
   1.766            qed
   1.767 -          finally have "\<mu> A = 0" unfolding a_eq using finite_measure[OF `?O_0 \<in> sets M`]
   1.768 -            by (cases "\<mu> A") (auto simp: pextreal_noteq_omega_Ex)
   1.769 +          finally have "\<mu> A = 0"
   1.770 +            unfolding a_eq using real_measure[OF `?O_0 \<in> sets M`] real_measure[OF A(1)] by auto
   1.771            with `\<mu> A \<noteq> 0` show ?thesis by auto
   1.772          qed
   1.773        qed }
   1.774 -    { fix i show "\<nu> (Q i) \<noteq> \<omega>"
   1.775 +    { fix i show "\<nu> (Q i) \<noteq> \<infinity>"
   1.776        proof (cases i)
   1.777          case 0 then show ?thesis
   1.778            unfolding Q_def using Q'[of 0] by simp
   1.779        next
   1.780          case (Suc n)
   1.781          then show ?thesis unfolding Q_def
   1.782 -          using `?O n \<in> ?Q` `?O (Suc n) \<in> ?Q` O_mono
   1.783 -          using v.measure_Diff[of "?O n" "?O (Suc n)"] by auto
   1.784 +          using `?O n \<in> ?Q` `?O (Suc n) \<in> ?Q`
   1.785 +          using v.measure_mono[OF O_mono, of n] v.positive_measure[of "?O n"] v.positive_measure[of "?O (Suc n)"]
   1.786 +          using v.measure_Diff[of "?O n" "?O (Suc n)", OF _ _ _ O_mono]
   1.787 +          by (cases rule: extreal2_cases[of "\<nu> (\<Union> x\<le>Suc n. Q' x)" "\<nu> (\<Union> i\<le>n. Q' i)"]) auto
   1.788        qed }
   1.789      show "space M - ?O_0 \<in> sets M" using Q'_sets by auto
   1.790      { fix j have "(\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q i)"
   1.791 @@ -675,7 +746,7 @@
   1.792  lemma (in finite_measure) Radon_Nikodym_finite_measure_infinite:
   1.793    assumes "measure_space (M\<lparr>measure := \<nu>\<rparr>)" (is "measure_space ?N")
   1.794    assumes "absolutely_continuous \<nu>"
   1.795 -  shows "\<exists>f \<in> borel_measurable M. \<forall>A\<in>sets M. \<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
   1.796 +  shows "\<exists>f \<in> borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> (\<forall>A\<in>sets M. \<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M))"
   1.797  proof -
   1.798    interpret v: measure_space ?N
   1.799      where "space ?N = space M" and "sets ?N = sets M" and "measure ?N = \<nu>"
   1.800 @@ -684,14 +755,14 @@
   1.801    obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
   1.802      where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
   1.803      and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
   1.804 -    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> \<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<omega>"
   1.805 -    and Q_fin: "\<And>i. \<nu> (Q i) \<noteq> \<omega>" by force
   1.806 +    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> \<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<infinity>"
   1.807 +    and Q_fin: "\<And>i. \<nu> (Q i) \<noteq> \<infinity>" by force
   1.808    from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
   1.809 -  have "\<forall>i. \<exists>f. f\<in>borel_measurable M \<and> (\<forall>A\<in>sets M.
   1.810 +  have "\<forall>i. \<exists>f. f\<in>borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> (\<forall>A\<in>sets M.
   1.811      \<nu> (Q i \<inter> A) = (\<integral>\<^isup>+x. f x * indicator (Q i \<inter> A) x \<partial>M))"
   1.812    proof
   1.813      fix i
   1.814 -    have indicator_eq: "\<And>f x A. (f x :: pextreal) * indicator (Q i \<inter> A) x * indicator (Q i) x
   1.815 +    have indicator_eq: "\<And>f x A. (f x :: extreal) * indicator (Q i \<inter> A) x * indicator (Q i) x
   1.816        = (f x * indicator (Q i) x) * indicator A x"
   1.817        unfolding indicator_def by auto
   1.818      have fm: "finite_measure (restricted_space (Q i))"
   1.819 @@ -702,7 +773,7 @@
   1.820      proof
   1.821        show "measure_space ?Q"
   1.822          using v.restricted_measure_space Q_sets[of i] by auto
   1.823 -      show "measure ?Q (space ?Q) \<noteq> \<omega>" using Q_fin by simp
   1.824 +      show "measure ?Q (space ?Q) \<noteq> \<infinity>" using Q_fin by simp
   1.825      qed
   1.826      have "R.absolutely_continuous \<nu>"
   1.827        using `absolutely_continuous \<nu>` `Q i \<in> sets M`
   1.828 @@ -712,48 +783,40 @@
   1.829        and f_int: "\<And>A. A\<in>sets M \<Longrightarrow> \<nu> (Q i \<inter> A) = (\<integral>\<^isup>+x. (f x * indicator (Q i) x) * indicator A x \<partial>M)"
   1.830        unfolding Bex_def borel_measurable_restricted[OF `Q i \<in> sets M`]
   1.831          positive_integral_restricted[OF `Q i \<in> sets M`] by (auto simp: indicator_eq)
   1.832 -    then show "\<exists>f. f\<in>borel_measurable M \<and> (\<forall>A\<in>sets M.
   1.833 +    then show "\<exists>f. f\<in>borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> (\<forall>A\<in>sets M.
   1.834        \<nu> (Q i \<inter> A) = (\<integral>\<^isup>+x. f x * indicator (Q i \<inter> A) x \<partial>M))"
   1.835 -      by (fastsimp intro!: exI[of _ "\<lambda>x. f x * indicator (Q i) x"] positive_integral_cong
   1.836 -          simp: indicator_def)
   1.837 +      by (auto intro!: exI[of _ "\<lambda>x. max 0 (f x * indicator (Q i) x)"] positive_integral_cong_pos
   1.838 +        split: split_indicator split_if_asm simp: max_def)
   1.839    qed
   1.840 -  from choice[OF this] obtain f where borel: "\<And>i. f i \<in> borel_measurable M"
   1.841 +  from choice[OF this] obtain f where borel: "\<And>i. f i \<in> borel_measurable M" "\<And>i x. 0 \<le> f i x"
   1.842      and f: "\<And>A i. A \<in> sets M \<Longrightarrow>
   1.843        \<nu> (Q i \<inter> A) = (\<integral>\<^isup>+x. f i x * indicator (Q i \<inter> A) x \<partial>M)"
   1.844      by auto
   1.845 -  let "?f x" =
   1.846 -    "(\<Sum>\<^isub>\<infinity> i. f i x * indicator (Q i) x) + \<omega> * indicator Q0 x"
   1.847 +  let "?f x" = "(\<Sum>i. f i x * indicator (Q i) x) + \<infinity> * indicator Q0 x"
   1.848    show ?thesis
   1.849    proof (safe intro!: bexI[of _ ?f])
   1.850 -    show "?f \<in> borel_measurable M"
   1.851 -      by (safe intro!: borel_measurable_psuminf borel_measurable_pextreal_times
   1.852 -        borel_measurable_pextreal_add borel_measurable_indicator
   1.853 -        borel_measurable_const borel Q_sets Q0 Diff countable_UN)
   1.854 +    show "?f \<in> borel_measurable M" using Q0 borel Q_sets
   1.855 +      by (auto intro!: measurable_If)
   1.856 +    show "\<And>x. 0 \<le> ?f x" using borel by (auto intro!: suminf_0_le simp: indicator_def)
   1.857      fix A assume "A \<in> sets M"
   1.858 -    have *:
   1.859 -      "\<And>x i. indicator A x * (f i x * indicator (Q i) x) =
   1.860 -        f i x * indicator (Q i \<inter> A) x"
   1.861 -      "\<And>x i. (indicator A x * indicator Q0 x :: pextreal) =
   1.862 -        indicator (Q0 \<inter> A) x" by (auto simp: indicator_def)
   1.863 -    have "(\<integral>\<^isup>+x. ?f x * indicator A x \<partial>M) =
   1.864 -      (\<Sum>\<^isub>\<infinity> i. \<nu> (Q i \<inter> A)) + \<omega> * \<mu> (Q0 \<inter> A)"
   1.865 -      unfolding f[OF `A \<in> sets M`]
   1.866 -      apply (simp del: pextreal_times(2) add: field_simps *)
   1.867 -      apply (subst positive_integral_add)
   1.868 -      apply (fastsimp intro: Q0 `A \<in> sets M`)
   1.869 -      apply (fastsimp intro: Q_sets `A \<in> sets M` borel_measurable_psuminf borel)
   1.870 -      apply (subst positive_integral_cmult_indicator)
   1.871 -      apply (fastsimp intro: Q0 `A \<in> sets M`)
   1.872 -      unfolding psuminf_cmult_right[symmetric]
   1.873 -      apply (subst positive_integral_psuminf)
   1.874 -      apply (fastsimp intro: `A \<in> sets M` Q_sets borel)
   1.875 -      apply (simp add: *)
   1.876 -      done
   1.877 -    moreover have "(\<Sum>\<^isub>\<infinity>i. \<nu> (Q i \<inter> A)) = \<nu> ((\<Union>i. Q i) \<inter> A)"
   1.878 +    have Qi: "\<And>i. Q i \<in> sets M" using Q by auto
   1.879 +    have [intro,simp]: "\<And>i. (\<lambda>x. f i x * indicator (Q i \<inter> A) x) \<in> borel_measurable M"
   1.880 +      "\<And>i. AE x. 0 \<le> f i x * indicator (Q i \<inter> A) x"
   1.881 +      using borel Qi Q0(1) `A \<in> sets M` by (auto intro!: borel_measurable_extreal_times)
   1.882 +    have "(\<integral>\<^isup>+x. ?f x * indicator A x \<partial>M) = (\<integral>\<^isup>+x. (\<Sum>i. f i x * indicator (Q i \<inter> A) x) + \<infinity> * indicator (Q0 \<inter> A) x \<partial>M)"
   1.883 +      using borel by (intro positive_integral_cong) (auto simp: indicator_def)
   1.884 +    also have "\<dots> = (\<integral>\<^isup>+x. (\<Sum>i. f i x * indicator (Q i \<inter> A) x) \<partial>M) + \<infinity> * \<mu> (Q0 \<inter> A)"
   1.885 +      using borel Qi Q0(1) `A \<in> sets M`
   1.886 +      by (subst positive_integral_add) (auto simp del: extreal_infty_mult
   1.887 +          simp add: positive_integral_cmult_indicator Int intro!: suminf_0_le)
   1.888 +    also have "\<dots> = (\<Sum>i. \<nu> (Q i \<inter> A)) + \<infinity> * \<mu> (Q0 \<inter> A)"
   1.889 +      by (subst f[OF `A \<in> sets M`], subst positive_integral_suminf) auto
   1.890 +    finally have "(\<integral>\<^isup>+x. ?f x * indicator A x \<partial>M) = (\<Sum>i. \<nu> (Q i \<inter> A)) + \<infinity> * \<mu> (Q0 \<inter> A)" .
   1.891 +    moreover have "(\<Sum>i. \<nu> (Q i \<inter> A)) = \<nu> ((\<Union>i. Q i) \<inter> A)"
   1.892        using Q Q_sets `A \<in> sets M`
   1.893        by (intro v.measure_countably_additive[of "\<lambda>i. Q i \<inter> A", unfolded comp_def, simplified])
   1.894           (auto simp: disjoint_family_on_def)
   1.895 -    moreover have "\<omega> * \<mu> (Q0 \<inter> A) = \<nu> (Q0 \<inter> A)"
   1.896 +    moreover have "\<infinity> * \<mu> (Q0 \<inter> A) = \<nu> (Q0 \<inter> A)"
   1.897      proof -
   1.898        have "Q0 \<inter> A \<in> sets M" using Q0(1) `A \<in> sets M` by blast
   1.899        from in_Q0[OF this] show ?thesis by auto
   1.900 @@ -770,40 +833,43 @@
   1.901  
   1.902  lemma (in sigma_finite_measure) Radon_Nikodym:
   1.903    assumes "measure_space (M\<lparr>measure := \<nu>\<rparr>)" (is "measure_space ?N")
   1.904 -  assumes "absolutely_continuous \<nu>"
   1.905 -  shows "\<exists>f \<in> borel_measurable M. \<forall>A\<in>sets M. \<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
   1.906 +  assumes ac: "absolutely_continuous \<nu>"
   1.907 +  shows "\<exists>f \<in> borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> (\<forall>A\<in>sets M. \<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M))"
   1.908  proof -
   1.909    from Ex_finite_integrable_function
   1.910 -  obtain h where finite: "integral\<^isup>P M h \<noteq> \<omega>" and
   1.911 +  obtain h where finite: "integral\<^isup>P M h \<noteq> \<infinity>" and
   1.912      borel: "h \<in> borel_measurable M" and
   1.913 +    nn: "\<And>x. 0 \<le> h x" and
   1.914      pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x" and
   1.915 -    "\<And>x. x \<in> space M \<Longrightarrow> h x < \<omega>" by auto
   1.916 +    "\<And>x. x \<in> space M \<Longrightarrow> h x < \<infinity>" by auto
   1.917    let "?T A" = "(\<integral>\<^isup>+x. h x * indicator A x \<partial>M)"
   1.918    let ?MT = "M\<lparr> measure := ?T \<rparr>"
   1.919 -  from measure_space_density[OF borel] finite
   1.920    interpret T: finite_measure ?MT
   1.921      where "space ?MT = space M" and "sets ?MT = sets M" and "measure ?MT = ?T"
   1.922 -    unfolding finite_measure_def finite_measure_axioms_def
   1.923 -    by (simp_all cong: positive_integral_cong)
   1.924 -  have "\<And>N. N \<in> sets M \<Longrightarrow> {x \<in> space M. h x \<noteq> 0 \<and> indicator N x \<noteq> (0::pextreal)} = N"
   1.925 -    using sets_into_space pos by (force simp: indicator_def)
   1.926 -  then have "T.absolutely_continuous \<nu>" using assms(2) borel
   1.927 -    unfolding T.absolutely_continuous_def absolutely_continuous_def
   1.928 -    by (fastsimp simp: borel_measurable_indicator positive_integral_0_iff)
   1.929 +    unfolding finite_measure_def finite_measure_axioms_def using borel finite nn
   1.930 +    by (auto intro!: measure_space_density cong: positive_integral_cong)
   1.931 +  have "T.absolutely_continuous \<nu>"
   1.932 +  proof (unfold T.absolutely_continuous_def, safe)
   1.933 +    fix N assume "N \<in> sets M" "(\<integral>\<^isup>+x. h x * indicator N x \<partial>M) = 0"
   1.934 +    with borel ac pos have "AE x. x \<notin> N"
   1.935 +      by (subst (asm) positive_integral_0_iff_AE) (auto split: split_indicator simp: not_le)
   1.936 +    then have "N \<in> null_sets" using `N \<in> sets M` sets_into_space
   1.937 +      by (subst (asm) AE_iff_measurable[OF `N \<in> sets M`]) auto
   1.938 +    then show "\<nu> N = 0" using ac by (auto simp: absolutely_continuous_def)
   1.939 +  qed
   1.940    from T.Radon_Nikodym_finite_measure_infinite[simplified, OF assms(1) this]
   1.941 -  obtain f where f_borel: "f \<in> borel_measurable M" and
   1.942 +  obtain f where f_borel: "f \<in> borel_measurable M" "\<And>x. 0 \<le> f x" and
   1.943      fT: "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = (\<integral>\<^isup>+ x. f x * indicator A x \<partial>?MT)"
   1.944      by (auto simp: measurable_def)
   1.945    show ?thesis
   1.946    proof (safe intro!: bexI[of _ "\<lambda>x. h x * f x"])
   1.947      show "(\<lambda>x. h x * f x) \<in> borel_measurable M"
   1.948 -      using borel f_borel by (auto intro: borel_measurable_pextreal_times)
   1.949 +      using borel f_borel by (auto intro: borel_measurable_extreal_times)
   1.950 +    show "\<And>x. 0 \<le> h x * f x" using nn f_borel by auto
   1.951      fix A assume "A \<in> sets M"
   1.952 -    then have "(\<lambda>x. f x * indicator A x) \<in> borel_measurable M"
   1.953 -      using f_borel by (auto intro: borel_measurable_pextreal_times borel_measurable_indicator)
   1.954 -    from positive_integral_translated_density[OF borel this]
   1.955 -    show "\<nu> A = (\<integral>\<^isup>+x. h x * f x * indicator A x \<partial>M)"
   1.956 -      unfolding fT[OF `A \<in> sets M`] by (simp add: field_simps)
   1.957 +    then show "\<nu> A = (\<integral>\<^isup>+x. h x * f x * indicator A x \<partial>M)"
   1.958 +      unfolding fT[OF `A \<in> sets M`] mult_assoc using nn borel f_borel
   1.959 +      by (intro positive_integral_translated_density) auto
   1.960    qed
   1.961  qed
   1.962  
   1.963 @@ -811,7 +877,8 @@
   1.964  
   1.965  lemma (in measure_space) finite_density_unique:
   1.966    assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
   1.967 -  and fin: "integral\<^isup>P M f < \<omega>"
   1.968 +  assumes pos: "AE x. 0 \<le> f x" "AE x. 0 \<le> g x"
   1.969 +  and fin: "integral\<^isup>P M f \<noteq> \<infinity>"
   1.970    shows "(\<forall>A\<in>sets M. (\<integral>\<^isup>+x. f x * indicator A x \<partial>M) = (\<integral>\<^isup>+x. g x * indicator A x \<partial>M))
   1.971      \<longleftrightarrow> (AE x. f x = g x)"
   1.972      (is "(\<forall>A\<in>sets M. ?P f A = ?P g A) \<longleftrightarrow> _")
   1.973 @@ -822,42 +889,38 @@
   1.974  next
   1.975    assume eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
   1.976    from this[THEN bspec, OF top] fin
   1.977 -  have g_fin: "integral\<^isup>P M g < \<omega>" by (simp cong: positive_integral_cong)
   1.978 +  have g_fin: "integral\<^isup>P M g \<noteq> \<infinity>" by (simp cong: positive_integral_cong)
   1.979    { fix f g assume borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
   1.980 -      and g_fin: "integral\<^isup>P M g < \<omega>" and eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
   1.981 +      and pos: "AE x. 0 \<le> f x" "AE x. 0 \<le> g x"
   1.982 +      and g_fin: "integral\<^isup>P M g \<noteq> \<infinity>" and eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
   1.983      let ?N = "{x\<in>space M. g x < f x}"
   1.984      have N: "?N \<in> sets M" using borel by simp
   1.985 +    have "?P g ?N \<le> integral\<^isup>P M g" using pos
   1.986 +      by (intro positive_integral_mono_AE) (auto split: split_indicator)
   1.987 +    then have Pg_fin: "?P g ?N \<noteq> \<infinity>" using g_fin by auto
   1.988      have "?P (\<lambda>x. (f x - g x)) ?N = (\<integral>\<^isup>+x. f x * indicator ?N x - g x * indicator ?N x \<partial>M)"
   1.989        by (auto intro!: positive_integral_cong simp: indicator_def)
   1.990      also have "\<dots> = ?P f ?N - ?P g ?N"
   1.991      proof (rule positive_integral_diff)
   1.992        show "(\<lambda>x. f x * indicator ?N x) \<in> borel_measurable M" "(\<lambda>x. g x * indicator ?N x) \<in> borel_measurable M"
   1.993          using borel N by auto
   1.994 -      have "?P g ?N \<le> integral\<^isup>P M g"
   1.995 -        by (auto intro!: positive_integral_mono simp: indicator_def)
   1.996 -      then show "?P g ?N \<noteq> \<omega>" using g_fin by auto
   1.997 -      fix x assume "x \<in> space M"
   1.998 -      show "g x * indicator ?N x \<le> f x * indicator ?N x"
   1.999 -        by (auto simp: indicator_def)
  1.1000 -    qed
  1.1001 +      show "AE x. g x * indicator ?N x \<le> f x * indicator ?N x"
  1.1002 +           "AE x. 0 \<le> g x * indicator ?N x"
  1.1003 +        using pos by (auto split: split_indicator)
  1.1004 +    qed fact
  1.1005      also have "\<dots> = 0"
  1.1006 -      using eq[THEN bspec, OF N] by simp
  1.1007 -    finally have "\<mu> {x\<in>space M. (f x - g x) * indicator ?N x \<noteq> 0} = 0"
  1.1008 -      using borel N by (subst (asm) positive_integral_0_iff) auto
  1.1009 -    moreover have "{x\<in>space M. (f x - g x) * indicator ?N x \<noteq> 0} = ?N"
  1.1010 -      by (auto simp: pextreal_zero_le_diff)
  1.1011 -    ultimately have "?N \<in> null_sets" using N by simp }
  1.1012 -  from this[OF borel g_fin eq] this[OF borel(2,1) fin]
  1.1013 -  have "{x\<in>space M. g x < f x} \<union> {x\<in>space M. f x < g x} \<in> null_sets"
  1.1014 -    using eq by (intro null_sets_Un) auto
  1.1015 -  also have "{x\<in>space M. g x < f x} \<union> {x\<in>space M. f x < g x} = {x\<in>space M. f x \<noteq> g x}"
  1.1016 -    by auto
  1.1017 -  finally show "AE x. f x = g x"
  1.1018 -    unfolding almost_everywhere_def by auto
  1.1019 +      unfolding eq[THEN bspec, OF N] using positive_integral_positive Pg_fin by auto
  1.1020 +    finally have "AE x. f x \<le> g x"
  1.1021 +      using pos borel positive_integral_PInf_AE[OF borel(2) g_fin]
  1.1022 +      by (subst (asm) positive_integral_0_iff_AE)
  1.1023 +         (auto split: split_indicator simp: not_less extreal_minus_le_iff) }
  1.1024 +  from this[OF borel pos g_fin eq] this[OF borel(2,1) pos(2,1) fin] eq
  1.1025 +  show "AE x. f x = g x" by auto
  1.1026  qed
  1.1027  
  1.1028  lemma (in finite_measure) density_unique_finite_measure:
  1.1029    assumes borel: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
  1.1030 +  assumes pos: "AE x. 0 \<le> f x" "AE x. 0 \<le> f' x"
  1.1031    assumes f: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+x. f x * indicator A x \<partial>M) = (\<integral>\<^isup>+x. f' x * indicator A x \<partial>M)"
  1.1032      (is "\<And>A. A \<in> sets M \<Longrightarrow> ?P f A = ?P f' A")
  1.1033    shows "AE x. f x = f' x"
  1.1034 @@ -865,26 +928,26 @@
  1.1035    let "?\<nu> A" = "?P f A" and "?\<nu>' A" = "?P f' A"
  1.1036    let "?f A x" = "f x * indicator A x" and "?f' A x" = "f' x * indicator A x"
  1.1037    interpret M: measure_space "M\<lparr> measure := ?\<nu>\<rparr>"
  1.1038 -    using borel(1) by (rule measure_space_density) simp
  1.1039 +    using borel(1) pos(1) by (rule measure_space_density) simp
  1.1040    have ac: "absolutely_continuous ?\<nu>"
  1.1041      using f by (rule density_is_absolutely_continuous)
  1.1042    from split_space_into_finite_sets_and_rest[OF `measure_space (M\<lparr> measure := ?\<nu>\<rparr>)` ac]
  1.1043    obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
  1.1044      where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
  1.1045      and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
  1.1046 -    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> \<mu> A = 0 \<and> ?\<nu> A = 0 \<or> 0 < \<mu> A \<and> ?\<nu> A = \<omega>"
  1.1047 -    and Q_fin: "\<And>i. ?\<nu> (Q i) \<noteq> \<omega>" by force
  1.1048 +    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> \<mu> A = 0 \<and> ?\<nu> A = 0 \<or> 0 < \<mu> A \<and> ?\<nu> A = \<infinity>"
  1.1049 +    and Q_fin: "\<And>i. ?\<nu> (Q i) \<noteq> \<infinity>" by force
  1.1050    from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
  1.1051    let ?N = "{x\<in>space M. f x \<noteq> f' x}"
  1.1052    have "?N \<in> sets M" using borel by auto
  1.1053 -  have *: "\<And>i x A. \<And>y::pextreal. y * indicator (Q i) x * indicator A x = y * indicator (Q i \<inter> A) x"
  1.1054 +  have *: "\<And>i x A. \<And>y::extreal. y * indicator (Q i) x * indicator A x = y * indicator (Q i \<inter> A) x"
  1.1055      unfolding indicator_def by auto
  1.1056 -  have "\<forall>i. AE x. ?f (Q i) x = ?f' (Q i) x" using borel Q_fin Q
  1.1057 +  have "\<forall>i. AE x. ?f (Q i) x = ?f' (Q i) x" using borel Q_fin Q pos
  1.1058      by (intro finite_density_unique[THEN iffD1] allI)
  1.1059 -       (auto intro!: borel_measurable_pextreal_times f Int simp: *)
  1.1060 +       (auto intro!: borel_measurable_extreal_times f Int simp: *)
  1.1061    moreover have "AE x. ?f Q0 x = ?f' Q0 x"
  1.1062    proof (rule AE_I')
  1.1063 -    { fix f :: "'a \<Rightarrow> pextreal" assume borel: "f \<in> borel_measurable M"
  1.1064 +    { fix f :: "'a \<Rightarrow> extreal" assume borel: "f \<in> borel_measurable M"
  1.1065          and eq: "\<And>A. A \<in> sets M \<Longrightarrow> ?\<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
  1.1066        let "?A i" = "Q0 \<inter> {x \<in> space M. f x < of_nat i}"
  1.1067        have "(\<Union>i. ?A i) \<in> null_sets"
  1.1068 @@ -896,69 +959,74 @@
  1.1069            by (auto intro!: positive_integral_mono simp: indicator_def)
  1.1070          also have "\<dots> = of_nat i * \<mu> (?A i)"
  1.1071            using `?A i \<in> sets M` by (auto intro!: positive_integral_cmult_indicator)
  1.1072 -        also have "\<dots> < \<omega>"
  1.1073 +        also have "\<dots> < \<infinity>"
  1.1074            using `?A i \<in> sets M`[THEN finite_measure] by auto
  1.1075 -        finally have "?\<nu> (?A i) \<noteq> \<omega>" by simp
  1.1076 +        finally have "?\<nu> (?A i) \<noteq> \<infinity>" by simp
  1.1077          then show "?A i \<in> null_sets" using in_Q0[OF `?A i \<in> sets M`] `?A i \<in> sets M` by auto
  1.1078        qed
  1.1079 -      also have "(\<Union>i. ?A i) = Q0 \<inter> {x\<in>space M. f x < \<omega>}"
  1.1080 -        by (auto simp: less_\<omega>_Ex_of_nat)
  1.1081 -      finally have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>} \<in> null_sets" by (simp add: pextreal_less_\<omega>) }
  1.1082 +      also have "(\<Union>i. ?A i) = Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>}"
  1.1083 +        by (auto simp: less_PInf_Ex_of_nat real_eq_of_nat)
  1.1084 +      finally have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>} \<in> null_sets" by simp }
  1.1085      from this[OF borel(1) refl] this[OF borel(2) f]
  1.1086 -    have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>} \<in> null_sets" "Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>} \<in> null_sets" by simp_all
  1.1087 -    then show "(Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>}) \<union> (Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>}) \<in> null_sets" by (rule null_sets_Un)
  1.1088 +    have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>} \<in> null_sets" "Q0 \<inter> {x\<in>space M. f' x \<noteq> \<infinity>} \<in> null_sets" by simp_all
  1.1089 +    then show "(Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>}) \<union> (Q0 \<inter> {x\<in>space M. f' x \<noteq> \<infinity>}) \<in> null_sets" by (rule null_sets_Un)
  1.1090      show "{x \<in> space M. ?f Q0 x \<noteq> ?f' Q0 x} \<subseteq>
  1.1091 -      (Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>}) \<union> (Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>})" by (auto simp: indicator_def)
  1.1092 +      (Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>}) \<union> (Q0 \<inter> {x\<in>space M. f' x \<noteq> \<infinity>})" by (auto simp: indicator_def)
  1.1093    qed
  1.1094    moreover have "\<And>x. (?f Q0 x = ?f' Q0 x) \<longrightarrow> (\<forall>i. ?f (Q i) x = ?f' (Q i) x) \<longrightarrow>
  1.1095      ?f (space M) x = ?f' (space M) x"
  1.1096      by (auto simp: indicator_def Q0)
  1.1097    ultimately have "AE x. ?f (space M) x = ?f' (space M) x"
  1.1098 -    by (auto simp: all_AE_countable)
  1.1099 +    by (auto simp: AE_all_countable[symmetric])
  1.1100    then show "AE x. f x = f' x" by auto
  1.1101  qed
  1.1102  
  1.1103  lemma (in sigma_finite_measure) density_unique:
  1.1104 -  assumes borel: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
  1.1105 -  assumes f: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+x. f x * indicator A x \<partial>M) = (\<integral>\<^isup>+x. f' x * indicator A x \<partial>M)"
  1.1106 +  assumes f: "f \<in> borel_measurable M" "AE x. 0 \<le> f x"
  1.1107 +  assumes f': "f' \<in> borel_measurable M" "AE x. 0 \<le> f' x"
  1.1108 +  assumes eq: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+x. f x * indicator A x \<partial>M) = (\<integral>\<^isup>+x. f' x * indicator A x \<partial>M)"
  1.1109      (is "\<And>A. A \<in> sets M \<Longrightarrow> ?P f A = ?P f' A")
  1.1110    shows "AE x. f x = f' x"
  1.1111  proof -
  1.1112    obtain h where h_borel: "h \<in> borel_measurable M"
  1.1113 -    and fin: "integral\<^isup>P M h \<noteq> \<omega>" and pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x \<and> h x < \<omega>"
  1.1114 +    and fin: "integral\<^isup>P M h \<noteq> \<infinity>" and pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x \<and> h x < \<infinity>" "\<And>x. 0 \<le> h x"
  1.1115      using Ex_finite_integrable_function by auto
  1.1116 -  interpret h: measure_space "M\<lparr> measure := \<lambda>A. (\<integral>\<^isup>+x. h x * indicator A x \<partial>M) \<rparr>"
  1.1117 -    using h_borel by (rule measure_space_density) simp
  1.1118 +  then have h_nn: "AE x. 0 \<le> h x" by auto
  1.1119 +  let ?H = "M\<lparr> measure := \<lambda>A. (\<integral>\<^isup>+x. h x * indicator A x \<partial>M) \<rparr>"
  1.1120 +  have H: "measure_space ?H"
  1.1121 +    using h_borel h_nn by (rule measure_space_density) simp
  1.1122 +  then interpret h: measure_space ?H .
  1.1123    interpret h: finite_measure "M\<lparr> measure := \<lambda>A. (\<integral>\<^isup>+x. h x * indicator A x \<partial>M) \<rparr>"
  1.1124      by default (simp cong: positive_integral_cong add: fin)
  1.1125    let ?fM = "M\<lparr>measure := \<lambda>A. (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)\<rparr>"
  1.1126    interpret f: measure_space ?fM
  1.1127 -    using borel(1) by (rule measure_space_density) simp
  1.1128 +    using f by (rule measure_space_density) simp
  1.1129    let ?f'M = "M\<lparr>measure := \<lambda>A. (\<integral>\<^isup>+x. f' x * indicator A x \<partial>M)\<rparr>"
  1.1130    interpret f': measure_space ?f'M
  1.1131 -    using borel(2) by (rule measure_space_density) simp
  1.1132 +    using f' by (rule measure_space_density) simp
  1.1133    { fix A assume "A \<in> sets M"
  1.1134 -    then have " {x \<in> space M. h x \<noteq> 0 \<and> indicator A x \<noteq> (0::pextreal)} = A"
  1.1135 -      using pos sets_into_space by (force simp: indicator_def)
  1.1136 +    then have "{x \<in> space M. h x * indicator A x \<noteq> 0} = A"
  1.1137 +      using pos(1) sets_into_space by (force simp: indicator_def)
  1.1138      then have "(\<integral>\<^isup>+x. h x * indicator A x \<partial>M) = 0 \<longleftrightarrow> A \<in> null_sets"
  1.1139 -      using h_borel `A \<in> sets M` by (simp add: positive_integral_0_iff) }
  1.1140 +      using h_borel `A \<in> sets M` h_nn by (subst positive_integral_0_iff) auto }
  1.1141    note h_null_sets = this
  1.1142    { fix A assume "A \<in> sets M"
  1.1143 -    have "(\<integral>\<^isup>+x. h x * (f x * indicator A x) \<partial>M) = (\<integral>\<^isup>+x. h x * indicator A x \<partial>?fM)"
  1.1144 -      using `A \<in> sets M` h_borel borel
  1.1145 -      by (simp add: positive_integral_translated_density ac_simps cong: positive_integral_cong)
  1.1146 +    have "(\<integral>\<^isup>+x. f x * (h x * indicator A x) \<partial>M) = (\<integral>\<^isup>+x. h x * indicator A x \<partial>?fM)"
  1.1147 +      using `A \<in> sets M` h_borel h_nn f f'
  1.1148 +      by (intro positive_integral_translated_density[symmetric]) auto
  1.1149      also have "\<dots> = (\<integral>\<^isup>+x. h x * indicator A x \<partial>?f'M)"
  1.1150 -      by (rule f'.positive_integral_cong_measure) (simp_all add: f)
  1.1151 -    also have "\<dots> = (\<integral>\<^isup>+x. h x * (f' x * indicator A x) \<partial>M)"
  1.1152 -      using `A \<in> sets M` h_borel borel
  1.1153 -      by (simp add: positive_integral_translated_density ac_simps cong: positive_integral_cong)
  1.1154 -    finally have "(\<integral>\<^isup>+x. h x * (f x * indicator A x) \<partial>M) = (\<integral>\<^isup>+x. h x * (f' x * indicator A x) \<partial>M)" . }
  1.1155 -  then have "h.almost_everywhere (\<lambda>x. f x = f' x)"
  1.1156 -    using h_borel borel
  1.1157 -    apply (intro h.density_unique_finite_measure)
  1.1158 -    apply (simp add: measurable_def)
  1.1159 -    apply (simp add: measurable_def)
  1.1160 -    by (simp add: positive_integral_translated_density)
  1.1161 +      by (rule f'.positive_integral_cong_measure) (simp_all add: eq)
  1.1162 +    also have "\<dots> = (\<integral>\<^isup>+x. f' x * (h x * indicator A x) \<partial>M)"
  1.1163 +      using `A \<in> sets M` h_borel h_nn f f'
  1.1164 +      by (intro positive_integral_translated_density) auto
  1.1165 +    finally have "(\<integral>\<^isup>+x. h x * (f x * indicator A x) \<partial>M) = (\<integral>\<^isup>+x. h x * (f' x * indicator A x) \<partial>M)"
  1.1166 +      by (simp add: ac_simps)
  1.1167 +    then have "(\<integral>\<^isup>+x. (f x * indicator A x) \<partial>?H) = (\<integral>\<^isup>+x. (f' x * indicator A x) \<partial>?H)"
  1.1168 +      using `A \<in> sets M` h_borel h_nn f f'
  1.1169 +      by (subst (asm) (1 2) positive_integral_translated_density[symmetric]) auto }
  1.1170 +  then have "AE x in ?H. f x = f' x" using h_borel h_nn f f'
  1.1171 +    by (intro h.density_unique_finite_measure absolutely_continuous_AE[OF H] density_is_absolutely_continuous)
  1.1172 +       simp_all
  1.1173    then show "AE x. f x = f' x"
  1.1174      unfolding h.almost_everywhere_def almost_everywhere_def
  1.1175      by (auto simp add: h_null_sets)
  1.1176 @@ -966,41 +1034,42 @@
  1.1177  
  1.1178  lemma (in sigma_finite_measure) sigma_finite_iff_density_finite:
  1.1179    assumes \<nu>: "measure_space (M\<lparr>measure := \<nu>\<rparr>)" (is "measure_space ?N")
  1.1180 -    and f: "f \<in> borel_measurable M"
  1.1181 +    and f: "f \<in> borel_measurable M" "AE x. 0 \<le> f x"
  1.1182      and eq: "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
  1.1183 -  shows "sigma_finite_measure (M\<lparr>measure := \<nu>\<rparr>) \<longleftrightarrow> (AE x. f x \<noteq> \<omega>)"
  1.1184 +  shows "sigma_finite_measure (M\<lparr>measure := \<nu>\<rparr>) \<longleftrightarrow> (AE x. f x \<noteq> \<infinity>)"
  1.1185  proof
  1.1186    assume "sigma_finite_measure ?N"
  1.1187    then interpret \<nu>: sigma_finite_measure ?N
  1.1188      where "borel_measurable ?N = borel_measurable M" and "measure ?N = \<nu>"
  1.1189      and "sets ?N = sets M" and "space ?N = space M" by (auto simp: measurable_def)
  1.1190    from \<nu>.Ex_finite_integrable_function obtain h where
  1.1191 -    h: "h \<in> borel_measurable M" "integral\<^isup>P ?N h \<noteq> \<omega>"
  1.1192 -    and fin: "\<forall>x\<in>space M. 0 < h x \<and> h x < \<omega>" by auto
  1.1193 -  have "AE x. f x * h x \<noteq> \<omega>"
  1.1194 +    h: "h \<in> borel_measurable M" "integral\<^isup>P ?N h \<noteq> \<infinity>" and
  1.1195 +    h_nn: "\<And>x. 0 \<le> h x" and
  1.1196 +    fin: "\<forall>x\<in>space M. 0 < h x \<and> h x < \<infinity>" by auto
  1.1197 +  have "AE x. f x * h x \<noteq> \<infinity>"
  1.1198    proof (rule AE_I')
  1.1199 -    have "integral\<^isup>P ?N h = (\<integral>\<^isup>+x. f x * h x \<partial>M)" using f h
  1.1200 +    have "integral\<^isup>P ?N h = (\<integral>\<^isup>+x. f x * h x \<partial>M)" using f h h_nn
  1.1201        by (subst \<nu>.positive_integral_cong_measure[symmetric,
  1.1202            of "M\<lparr> measure := \<lambda> A. \<integral>\<^isup>+x. f x * indicator A x \<partial>M \<rparr>"])
  1.1203           (auto intro!: positive_integral_translated_density simp: eq)
  1.1204 -    then have "(\<integral>\<^isup>+x. f x * h x \<partial>M) \<noteq> \<omega>"
  1.1205 +    then have "(\<integral>\<^isup>+x. f x * h x \<partial>M) \<noteq> \<infinity>"
  1.1206        using h(2) by simp
  1.1207 -    then show "(\<lambda>x. f x * h x) -` {\<omega>} \<inter> space M \<in> null_sets"
  1.1208 -      using f h(1) by (auto intro!: positive_integral_omega borel_measurable_vimage)
  1.1209 +    then show "(\<lambda>x. f x * h x) -` {\<infinity>} \<inter> space M \<in> null_sets"
  1.1210 +      using f h(1) by (auto intro!: positive_integral_PInf borel_measurable_vimage)
  1.1211    qed auto
  1.1212 -  then show "AE x. f x \<noteq> \<omega>"
  1.1213 +  then show "AE x. f x \<noteq> \<infinity>"
  1.1214      using fin by (auto elim!: AE_Ball_mp)
  1.1215  next
  1.1216 -  assume AE: "AE x. f x \<noteq> \<omega>"
  1.1217 +  assume AE: "AE x. f x \<noteq> \<infinity>"
  1.1218    from sigma_finite guess Q .. note Q = this
  1.1219    interpret \<nu>: measure_space ?N
  1.1220      where "borel_measurable ?N = borel_measurable M" and "measure ?N = \<nu>"
  1.1221      and "sets ?N = sets M" and "space ?N = space M" using \<nu> by (auto simp: measurable_def)
  1.1222 -  def A \<equiv> "\<lambda>i. f -` (case i of 0 \<Rightarrow> {\<omega>} | Suc n \<Rightarrow> {.. of_nat (Suc n)}) \<inter> space M"
  1.1223 +  def A \<equiv> "\<lambda>i. f -` (case i of 0 \<Rightarrow> {\<infinity>} | Suc n \<Rightarrow> {.. of_nat (Suc n)}) \<inter> space M"
  1.1224    { fix i j have "A i \<inter> Q j \<in> sets M"
  1.1225      unfolding A_def using f Q
  1.1226      apply (rule_tac Int)
  1.1227 -    by (cases i) (auto intro: measurable_sets[OF f]) }
  1.1228 +    by (cases i) (auto intro: measurable_sets[OF f(1)]) }
  1.1229    note A_in_sets = this
  1.1230    let "?A n" = "case prod_decode n of (i,j) \<Rightarrow> A i \<inter> Q j"
  1.1231    show "sigma_finite_measure ?N"
  1.1232 @@ -1021,18 +1090,21 @@
  1.1233        fix x assume x: "x \<in> space M"
  1.1234        show "x \<in> (\<Union>i. A i)"
  1.1235        proof (cases "f x")
  1.1236 -        case infinite then show ?thesis using x unfolding A_def by (auto intro: exI[of _ 0])
  1.1237 +        case PInf with x show ?thesis unfolding A_def by (auto intro: exI[of _ 0])
  1.1238        next
  1.1239 -        case (preal r)
  1.1240 -        with less_\<omega>_Ex_of_nat[of "f x"] obtain n where "f x < of_nat n" by auto
  1.1241 -        then show ?thesis using x preal unfolding A_def by (auto intro!: exI[of _ "Suc n"])
  1.1242 +        case (real r)
  1.1243 +        with less_PInf_Ex_of_nat[of "f x"] obtain n where "f x < of_nat n" by (auto simp: real_eq_of_nat)
  1.1244 +        then show ?thesis using x real unfolding A_def by (auto intro!: exI[of _ "Suc n"])
  1.1245 +      next
  1.1246 +        case MInf with x show ?thesis
  1.1247 +          unfolding A_def by (auto intro!: exI[of _ "Suc 0"])
  1.1248        qed
  1.1249      qed (auto simp: A_def)
  1.1250      finally show "(\<Union>i. ?A i) = space ?N" by simp
  1.1251    next
  1.1252      fix n obtain i j where
  1.1253        [simp]: "prod_decode n = (i, j)" by (cases "prod_decode n") auto
  1.1254 -    have "(\<integral>\<^isup>+x. f x * indicator (A i \<inter> Q j) x \<partial>M) \<noteq> \<omega>"
  1.1255 +    have "(\<integral>\<^isup>+x. f x * indicator (A i \<inter> Q j) x \<partial>M) \<noteq> \<infinity>"
  1.1256      proof (cases i)
  1.1257        case 0
  1.1258        have "AE x. f x * indicator (A i \<inter> Q j) x = 0"
  1.1259 @@ -1045,11 +1117,11 @@
  1.1260          by (auto intro!: positive_integral_mono simp: indicator_def A_def)
  1.1261        also have "\<dots> = of_nat (Suc n) * \<mu> (Q j)"
  1.1262          using Q by (auto intro!: positive_integral_cmult_indicator)
  1.1263 -      also have "\<dots> < \<omega>"
  1.1264 -        using Q by auto
  1.1265 +      also have "\<dots> < \<infinity>"
  1.1266 +        using Q by (auto simp: real_eq_of_nat[symmetric])
  1.1267        finally show ?thesis by simp
  1.1268      qed
  1.1269 -    then show "measure ?N (?A n) \<noteq> \<omega>"
  1.1270 +    then show "measure ?N (?A n) \<noteq> \<infinity>"
  1.1271        using A_in_sets Q eq by auto
  1.1272    qed
  1.1273  qed
  1.1274 @@ -1057,7 +1129,7 @@
  1.1275  section "Radon-Nikodym derivative"
  1.1276  
  1.1277  definition
  1.1278 -  "RN_deriv M \<nu> \<equiv> SOME f. f \<in> borel_measurable M \<and>
  1.1279 +  "RN_deriv M \<nu> \<equiv> SOME f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and>
  1.1280      (\<forall>A \<in> sets M. \<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M))"
  1.1281  
  1.1282  lemma (in sigma_finite_measure) RN_deriv_cong:
  1.1283 @@ -1078,9 +1150,12 @@
  1.1284    shows "RN_deriv M \<nu> \<in> borel_measurable M" (is ?borel)
  1.1285    and "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = (\<integral>\<^isup>+x. RN_deriv M \<nu> x * indicator A x \<partial>M)"
  1.1286      (is "\<And>A. _ \<Longrightarrow> ?int A")
  1.1287 +  and "0 \<le> RN_deriv M \<nu> x"
  1.1288  proof -
  1.1289    note Ex = Radon_Nikodym[OF assms, unfolded Bex_def]
  1.1290 -  thus ?borel unfolding RN_deriv_def by (rule someI2_ex) auto
  1.1291 +  then show ?borel unfolding RN_deriv_def by (rule someI2_ex) auto
  1.1292 +  from Ex show "0 \<le> RN_deriv M \<nu> x" unfolding RN_deriv_def
  1.1293 +    by (rule someI2_ex) simp
  1.1294    fix A assume "A \<in> sets M"
  1.1295    from Ex show "?int A" unfolding RN_deriv_def
  1.1296      by (rule someI2_ex) (simp add: `A \<in> sets M`)
  1.1297 @@ -1092,22 +1167,28 @@
  1.1298    shows "integral\<^isup>P (M\<lparr>measure := \<nu>\<rparr>) f = (\<integral>\<^isup>+x. RN_deriv M \<nu> x * f x \<partial>M)"
  1.1299  proof -
  1.1300    interpret \<nu>: measure_space "M\<lparr>measure := \<nu>\<rparr>" by fact
  1.1301 -  have "integral\<^isup>P (M\<lparr>measure := \<nu>\<rparr>) f =
  1.1302 -    integral\<^isup>P (M\<lparr>measure := \<lambda>A. (\<integral>\<^isup>+x. RN_deriv M \<nu> x * indicator A x \<partial>M)\<rparr>) f"
  1.1303 -    by (intro \<nu>.positive_integral_cong_measure[symmetric])
  1.1304 -       (simp_all add:  RN_deriv(2)[OF \<nu>, symmetric])
  1.1305 +  note RN = RN_deriv[OF \<nu>]
  1.1306 +  have "integral\<^isup>P (M\<lparr>measure := \<nu>\<rparr>) f = (\<integral>\<^isup>+x. max 0 (f x) \<partial>M\<lparr>measure := \<nu>\<rparr>)"
  1.1307 +    unfolding positive_integral_max_0 ..
  1.1308 +  also have "(\<integral>\<^isup>+x. max 0 (f x) \<partial>M\<lparr>measure := \<nu>\<rparr>) =
  1.1309 +    (\<integral>\<^isup>+x. max 0 (f x) \<partial>M\<lparr>measure := \<lambda>A. (\<integral>\<^isup>+x. RN_deriv M \<nu> x * indicator A x \<partial>M)\<rparr>)"
  1.1310 +    by (intro \<nu>.positive_integral_cong_measure[symmetric]) (simp_all add: RN(2))
  1.1311 +  also have "\<dots> = (\<integral>\<^isup>+x. RN_deriv M \<nu> x * max 0 (f x) \<partial>M)"
  1.1312 +    by (intro positive_integral_translated_density) (auto simp add: RN f)
  1.1313    also have "\<dots> = (\<integral>\<^isup>+x. RN_deriv M \<nu> x * f x \<partial>M)"
  1.1314 -    by (intro positive_integral_translated_density)
  1.1315 -       (simp_all add: RN_deriv[OF \<nu>] f)
  1.1316 +    using RN_deriv(3)[OF \<nu>]
  1.1317 +    by (auto intro!: positive_integral_cong_pos split: split_if_asm
  1.1318 +             simp: max_def extreal_mult_le_0_iff)
  1.1319    finally show ?thesis .
  1.1320  qed
  1.1321  
  1.1322  lemma (in sigma_finite_measure) RN_deriv_unique:
  1.1323    assumes \<nu>: "measure_space (M\<lparr>measure := \<nu>\<rparr>)" "absolutely_continuous \<nu>"
  1.1324 -  and f: "f \<in> borel_measurable M"
  1.1325 +  and f: "f \<in> borel_measurable M" "AE x. 0 \<le> f x"
  1.1326    and eq: "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = (\<integral>\<^isup>+x. f x * indicator A x \<partial>M)"
  1.1327    shows "AE x. f x = RN_deriv M \<nu> x"
  1.1328  proof (rule density_unique[OF f RN_deriv(1)[OF \<nu>]])
  1.1329 +  show "AE x. 0 \<le> RN_deriv M \<nu> x" using RN_deriv[OF \<nu>] by auto
  1.1330    fix A assume A: "A \<in> sets M"
  1.1331    show "(\<integral>\<^isup>+x. f x * indicator A x \<partial>M) = (\<integral>\<^isup>+x. RN_deriv M \<nu> x * indicator A x \<partial>M)"
  1.1332      unfolding eq[OF A, symmetric] RN_deriv(2)[OF \<nu> A, symmetric] ..
  1.1333 @@ -1143,7 +1224,7 @@
  1.1334    interpret M': sigma_finite_measure M'
  1.1335    proof
  1.1336      from sigma_finite guess F .. note F = this
  1.1337 -    show "\<exists>A::nat \<Rightarrow> 'c set. range A \<subseteq> sets M' \<and> (\<Union>i. A i) = space M' \<and> (\<forall>i. M'.\<mu> (A i) \<noteq> \<omega>)"
  1.1338 +    show "\<exists>A::nat \<Rightarrow> 'c set. range A \<subseteq> sets M' \<and> (\<Union>i. A i) = space M' \<and> (\<forall>i. M'.\<mu> (A i) \<noteq> \<infinity>)"
  1.1339      proof (intro exI conjI allI)
  1.1340        show *: "range (\<lambda>i. T' -` F i \<inter> space M') \<subseteq> sets M'"
  1.1341          using F T' by (auto simp: measurable_def measure_preserving_def)
  1.1342 @@ -1157,7 +1238,7 @@
  1.1343        then have "T -` (T' -` F i \<inter> space M') \<inter> space M = F i"
  1.1344          using T inv sets_into_space[OF Fi]
  1.1345          by (auto simp: measurable_def measure_preserving_def)
  1.1346 -      ultimately show "measure M' (T' -` F i \<inter> space M') \<noteq> \<omega>"
  1.1347 +      ultimately show "measure M' (T' -` F i \<inter> space M') \<noteq> \<infinity>"
  1.1348          using F by simp
  1.1349      qed
  1.1350    qed
  1.1351 @@ -1165,6 +1246,7 @@
  1.1352      by (intro measurable_comp[where b=M'] M'.RN_deriv(1) measure_preservingD2[OF T]) fact+
  1.1353    then show "(\<lambda>x. RN_deriv M' \<nu>' (T x)) \<in> borel_measurable M"
  1.1354      by (simp add: comp_def)
  1.1355 +  show "AE x. 0 \<le> RN_deriv M' \<nu>' (T x)" using M'.RN_deriv(3)[OF \<nu>'] by auto
  1.1356    fix A let ?A = "T' -` A \<inter> space M'"
  1.1357    assume A: "A \<in> sets M"
  1.1358    then have A': "?A \<in> sets M'" using T' unfolding measurable_def measure_preserving_def
  1.1359 @@ -1185,12 +1267,12 @@
  1.1360  
  1.1361  lemma (in sigma_finite_measure) RN_deriv_finite:
  1.1362    assumes sfm: "sigma_finite_measure (M\<lparr>measure := \<nu>\<rparr>)" and ac: "absolutely_continuous \<nu>"
  1.1363 -  shows "AE x. RN_deriv M \<nu> x \<noteq> \<omega>"
  1.1364 +  shows "AE x. RN_deriv M \<nu> x \<noteq> \<infinity>"
  1.1365  proof -
  1.1366    interpret \<nu>: sigma_finite_measure "M\<lparr>measure := \<nu>\<rparr>" by fact
  1.1367    have \<nu>: "measure_space (M\<lparr>measure := \<nu>\<rparr>)" by default
  1.1368    from sfm show ?thesis
  1.1369 -    using sigma_finite_iff_density_finite[OF \<nu> RN_deriv[OF \<nu> ac]] by simp
  1.1370 +    using sigma_finite_iff_density_finite[OF \<nu> RN_deriv(1)[OF \<nu> ac]] RN_deriv(2,3)[OF \<nu> ac] by simp
  1.1371  qed
  1.1372  
  1.1373  lemma (in sigma_finite_measure)
  1.1374 @@ -1203,22 +1285,24 @@
  1.1375  proof -
  1.1376    interpret \<nu>: sigma_finite_measure "M\<lparr>measure := \<nu>\<rparr>" by fact
  1.1377    have ms: "measure_space (M\<lparr>measure := \<nu>\<rparr>)" by default
  1.1378 -  have minus_cong: "\<And>A B A' B'::pextreal. A = A' \<Longrightarrow> B = B' \<Longrightarrow> real A - real B = real A' - real B'" by simp
  1.1379 +  have minus_cong: "\<And>A B A' B'::extreal. A = A' \<Longrightarrow> B = B' \<Longrightarrow> real A - real B = real A' - real B'" by simp
  1.1380    have f': "(\<lambda>x. - f x) \<in> borel_measurable M" using f by auto
  1.1381 -  have Nf: "f \<in> borel_measurable (M\<lparr>measure := \<nu>\<rparr>)" using f unfolding measurable_def by auto
  1.1382 +  have Nf: "f \<in> borel_measurable (M\<lparr>measure := \<nu>\<rparr>)" using f by simp
  1.1383    { fix f :: "'a \<Rightarrow> real"
  1.1384 -    { fix x assume *: "RN_deriv M \<nu> x \<noteq> \<omega>"
  1.1385 -      have "Real (real (RN_deriv M \<nu> x)) * Real (f x) = Real (real (RN_deriv M \<nu> x) * f x)"
  1.1386 +    { fix x assume *: "RN_deriv M \<nu> x \<noteq> \<infinity>"
  1.1387 +      have "extreal (real (RN_deriv M \<nu> x)) * extreal (f x) = extreal (real (RN_deriv M \<nu> x) * f x)"
  1.1388          by (simp add: mult_le_0_iff)
  1.1389 -      then have "RN_deriv M \<nu> x * Real (f x) = Real (real (RN_deriv M \<nu> x) * f x)"
  1.1390 -        using * by (simp add: Real_real) }
  1.1391 -    then have "(\<integral>\<^isup>+x. RN_deriv M \<nu> x * Real (f x) \<partial>M) = (\<integral>\<^isup>+x. Real (real (RN_deriv M \<nu> x) * f x) \<partial>M)"
  1.1392 -      using RN_deriv_finite[OF \<nu>] by (auto intro: positive_integral_cong_AE) }
  1.1393 -  with this this f f' Nf
  1.1394 +      then have "RN_deriv M \<nu> x * extreal (f x) = extreal (real (RN_deriv M \<nu> x) * f x)"
  1.1395 +        using RN_deriv(3)[OF ms \<nu>(2)] * by (auto simp add: extreal_real split: split_if_asm) }
  1.1396 +    then have "(\<integral>\<^isup>+x. extreal (real (RN_deriv M \<nu> x) * f x) \<partial>M) = (\<integral>\<^isup>+x. RN_deriv M \<nu> x * extreal (f x) \<partial>M)"
  1.1397 +              "(\<integral>\<^isup>+x. extreal (- (real (RN_deriv M \<nu> x) * f x)) \<partial>M) = (\<integral>\<^isup>+x. RN_deriv M \<nu> x * extreal (- f x) \<partial>M)"
  1.1398 +      using RN_deriv_finite[OF \<nu>] unfolding extreal_mult_minus_right uminus_extreal.simps(1)[symmetric]
  1.1399 +      by (auto intro!: positive_integral_cong_AE) }
  1.1400 +  note * = this
  1.1401    show ?integral ?integrable
  1.1402 -    unfolding lebesgue_integral_def integrable_def
  1.1403 -    by (auto intro!: RN_deriv(1)[OF ms \<nu>(2)] minus_cong
  1.1404 -             simp: RN_deriv_positive_integral[OF ms \<nu>(2)])
  1.1405 +    unfolding lebesgue_integral_def integrable_def *
  1.1406 +    using f RN_deriv(1)[OF ms \<nu>(2)]
  1.1407 +    by (auto simp: RN_deriv_positive_integral[OF ms \<nu>(2)])
  1.1408  qed
  1.1409  
  1.1410  lemma (in sigma_finite_measure) RN_deriv_singleton:
  1.1411 @@ -1231,7 +1315,7 @@
  1.1412    from deriv(2)[OF `{x} \<in> sets M`]
  1.1413    have "\<nu> {x} = (\<integral>\<^isup>+w. RN_deriv M \<nu> x * indicator {x} w \<partial>M)"
  1.1414      by (auto simp: indicator_def intro!: positive_integral_cong)
  1.1415 -  thus ?thesis using positive_integral_cmult_indicator[OF `{x} \<in> sets M`]
  1.1416 +  thus ?thesis using positive_integral_cmult_indicator[OF _ `{x} \<in> sets M`] deriv(3)
  1.1417      by auto
  1.1418  qed
  1.1419