src/HOL/Probability/Radon_Nikodym.thy
author wenzelm
Tue Aug 13 16:25:47 2013 +0200 (2013-08-13)
changeset 53015 a1119cf551e8
parent 52141 eff000cab70f
child 53374 a14d2a854c02
permissions -rw-r--r--
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
hoelzl@42067
     1
(*  Title:      HOL/Probability/Radon_Nikodym.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
*)
hoelzl@42067
     4
hoelzl@42067
     5
header {*Radon-Nikod{\'y}m derivative*}
hoelzl@42067
     6
hoelzl@38656
     7
theory Radon_Nikodym
hoelzl@38656
     8
imports Lebesgue_Integration
hoelzl@38656
     9
begin
hoelzl@38656
    10
hoelzl@47694
    11
definition "diff_measure M N =
hoelzl@47694
    12
  measure_of (space M) (sets M) (\<lambda>A. emeasure M A - emeasure N A)"
hoelzl@47694
    13
hoelzl@47694
    14
lemma 
hoelzl@47694
    15
  shows space_diff_measure[simp]: "space (diff_measure M N) = space M"
hoelzl@47694
    16
    and sets_diff_measure[simp]: "sets (diff_measure M N) = sets M"
hoelzl@47694
    17
  by (auto simp: diff_measure_def)
hoelzl@47694
    18
hoelzl@47694
    19
lemma emeasure_diff_measure:
hoelzl@47694
    20
  assumes fin: "finite_measure M" "finite_measure N" and sets_eq: "sets M = sets N"
hoelzl@47694
    21
  assumes pos: "\<And>A. A \<in> sets M \<Longrightarrow> emeasure N A \<le> emeasure M A" and A: "A \<in> sets M"
hoelzl@47694
    22
  shows "emeasure (diff_measure M N) A = emeasure M A - emeasure N A" (is "_ = ?\<mu> A")
hoelzl@47694
    23
  unfolding diff_measure_def
hoelzl@47694
    24
proof (rule emeasure_measure_of_sigma)
hoelzl@47694
    25
  show "sigma_algebra (space M) (sets M)" ..
hoelzl@47694
    26
  show "positive (sets M) ?\<mu>"
hoelzl@47694
    27
    using pos by (simp add: positive_def ereal_diff_positive)
hoelzl@47694
    28
  show "countably_additive (sets M) ?\<mu>"
hoelzl@47694
    29
  proof (rule countably_additiveI)
hoelzl@47694
    30
    fix A :: "nat \<Rightarrow> _"  assume A: "range A \<subseteq> sets M" and "disjoint_family A"
hoelzl@47694
    31
    then have suminf:
hoelzl@47694
    32
      "(\<Sum>i. emeasure M (A i)) = emeasure M (\<Union>i. A i)"
hoelzl@47694
    33
      "(\<Sum>i. emeasure N (A i)) = emeasure N (\<Union>i. A i)"
hoelzl@47694
    34
      by (simp_all add: suminf_emeasure sets_eq)
hoelzl@47694
    35
    with A have "(\<Sum>i. emeasure M (A i) - emeasure N (A i)) =
hoelzl@47694
    36
      (\<Sum>i. emeasure M (A i)) - (\<Sum>i. emeasure N (A i))"
hoelzl@47694
    37
      using fin
hoelzl@47694
    38
      by (intro suminf_ereal_minus pos emeasure_nonneg)
hoelzl@47694
    39
         (auto simp: sets_eq finite_measure.emeasure_eq_measure suminf_emeasure)
hoelzl@47694
    40
    then show "(\<Sum>i. emeasure M (A i) - emeasure N (A i)) =
hoelzl@47694
    41
      emeasure M (\<Union>i. A i) - emeasure N (\<Union>i. A i) "
hoelzl@47694
    42
      by (simp add: suminf)
hoelzl@47694
    43
  qed
hoelzl@47694
    44
qed fact
hoelzl@47694
    45
hoelzl@38656
    46
lemma (in sigma_finite_measure) Ex_finite_integrable_function:
wenzelm@53015
    47
  shows "\<exists>h\<in>borel_measurable M. integral\<^sup>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)"
hoelzl@38656
    48
proof -
hoelzl@38656
    49
  obtain A :: "nat \<Rightarrow> 'a set" where
hoelzl@50003
    50
    range[measurable]: "range A \<subseteq> sets M" and
hoelzl@38656
    51
    space: "(\<Union>i. A i) = space M" and
hoelzl@47694
    52
    measure: "\<And>i. emeasure M (A i) \<noteq> \<infinity>" and
hoelzl@38656
    53
    disjoint: "disjoint_family A"
hoelzl@47694
    54
    using sigma_finite_disjoint by auto
hoelzl@47694
    55
  let ?B = "\<lambda>i. 2^Suc i * emeasure M (A i)"
hoelzl@38656
    56
  have "\<forall>i. \<exists>x. 0 < x \<and> x < inverse (?B i)"
hoelzl@38656
    57
  proof
hoelzl@47694
    58
    fix i show "\<exists>x. 0 < x \<and> x < inverse (?B i)"
hoelzl@47694
    59
      using measure[of i] emeasure_nonneg[of M "A i"]
hoelzl@51329
    60
      by (auto intro!: dense simp: ereal_0_gt_inverse ereal_zero_le_0_iff)
hoelzl@38656
    61
  qed
hoelzl@38656
    62
  from choice[OF this] obtain n where n: "\<And>i. 0 < n i"
hoelzl@47694
    63
    "\<And>i. n i < inverse (2^Suc i * emeasure M (A i))" by auto
hoelzl@41981
    64
  { fix i have "0 \<le> n i" using n(1)[of i] by auto } note pos = this
wenzelm@46731
    65
  let ?h = "\<lambda>x. \<Sum>i. n i * indicator (A i) x"
hoelzl@38656
    66
  show ?thesis
hoelzl@38656
    67
  proof (safe intro!: bexI[of _ ?h] del: notI)
hoelzl@39092
    68
    have "\<And>i. A i \<in> sets M"
nipkow@44890
    69
      using range by fastforce+
wenzelm@53015
    70
    then have "integral\<^sup>P M ?h = (\<Sum>i. n i * emeasure M (A i))" using pos
hoelzl@41981
    71
      by (simp add: positive_integral_suminf positive_integral_cmult_indicator)
hoelzl@41981
    72
    also have "\<dots> \<le> (\<Sum>i. (1 / 2)^Suc i)"
hoelzl@41981
    73
    proof (rule suminf_le_pos)
hoelzl@41981
    74
      fix N
hoelzl@47694
    75
      have "n N * emeasure M (A N) \<le> inverse (2^Suc N * emeasure M (A N)) * emeasure M (A N)"
hoelzl@47694
    76
        using n[of N]
hoelzl@43920
    77
        by (intro ereal_mult_right_mono) auto
hoelzl@41981
    78
      also have "\<dots> \<le> (1 / 2) ^ Suc N"
hoelzl@38656
    79
        using measure[of N] n[of N]
hoelzl@47694
    80
        by (cases rule: ereal2_cases[of "n N" "emeasure M (A N)"])
hoelzl@43920
    81
           (simp_all add: inverse_eq_divide power_divide one_ereal_def ereal_power_divide)
hoelzl@47694
    82
      finally show "n N * emeasure M (A N) \<le> (1 / 2) ^ Suc N" .
hoelzl@47694
    83
      show "0 \<le> n N * emeasure M (A N)" using n[of N] `A N \<in> sets M` by (simp add: emeasure_nonneg)
hoelzl@38656
    84
    qed
wenzelm@53015
    85
    finally show "integral\<^sup>P M ?h \<noteq> \<infinity>" unfolding suminf_half_series_ereal by auto
hoelzl@38656
    86
  next
hoelzl@41981
    87
    { fix x assume "x \<in> space M"
hoelzl@41981
    88
      then obtain i where "x \<in> A i" using space[symmetric] by auto
hoelzl@41981
    89
      with disjoint n have "?h x = n i"
hoelzl@41981
    90
        by (auto intro!: suminf_cmult_indicator intro: less_imp_le)
hoelzl@41981
    91
      then show "0 < ?h x" and "?h x < \<infinity>" using n[of i] by auto }
hoelzl@41981
    92
    note pos = this
hoelzl@41981
    93
    fix x show "0 \<le> ?h x"
hoelzl@41981
    94
    proof cases
hoelzl@41981
    95
      assume "x \<in> space M" then show "0 \<le> ?h x" using pos by (auto intro: less_imp_le)
hoelzl@41981
    96
    next
hoelzl@41981
    97
      assume "x \<notin> space M" then have "\<And>i. x \<notin> A i" using space by auto
hoelzl@41981
    98
      then show "0 \<le> ?h x" by auto
hoelzl@41981
    99
    qed
hoelzl@50003
   100
  qed measurable
hoelzl@38656
   101
qed
hoelzl@38656
   102
hoelzl@40871
   103
subsection "Absolutely continuous"
hoelzl@40871
   104
hoelzl@47694
   105
definition absolutely_continuous :: "'a measure \<Rightarrow> 'a measure \<Rightarrow> bool" where
hoelzl@47694
   106
  "absolutely_continuous M N \<longleftrightarrow> null_sets M \<subseteq> null_sets N"
hoelzl@47694
   107
hoelzl@47694
   108
lemma absolutely_continuousI_count_space: "absolutely_continuous (count_space A) M"
hoelzl@47694
   109
  unfolding absolutely_continuous_def by (auto simp: null_sets_count_space)
hoelzl@38656
   110
hoelzl@47694
   111
lemma absolutely_continuousI_density:
hoelzl@47694
   112
  "f \<in> borel_measurable M \<Longrightarrow> absolutely_continuous M (density M f)"
hoelzl@47694
   113
  by (force simp add: absolutely_continuous_def null_sets_density_iff dest: AE_not_in)
hoelzl@47694
   114
hoelzl@47694
   115
lemma absolutely_continuousI_point_measure_finite:
hoelzl@47694
   116
  "(\<And>x. \<lbrakk> x \<in> A ; f x \<le> 0 \<rbrakk> \<Longrightarrow> g x \<le> 0) \<Longrightarrow> absolutely_continuous (point_measure A f) (point_measure A g)"
hoelzl@47694
   117
  unfolding absolutely_continuous_def by (force simp: null_sets_point_measure_iff)
hoelzl@47694
   118
hoelzl@47694
   119
lemma absolutely_continuous_AE:
hoelzl@47694
   120
  assumes sets_eq: "sets M' = sets M"
hoelzl@47694
   121
    and "absolutely_continuous M M'" "AE x in M. P x"
hoelzl@41981
   122
   shows "AE x in M'. P x"
hoelzl@40859
   123
proof -
hoelzl@47694
   124
  from `AE x in M. P x` obtain N where N: "N \<in> null_sets M" "{x\<in>space M. \<not> P x} \<subseteq> N"
hoelzl@47694
   125
    unfolding eventually_ae_filter by auto
hoelzl@41981
   126
  show "AE x in M'. P x"
hoelzl@47694
   127
  proof (rule AE_I')
hoelzl@47694
   128
    show "{x\<in>space M'. \<not> P x} \<subseteq> N" using sets_eq_imp_space_eq[OF sets_eq] N(2) by simp
hoelzl@47694
   129
    from `absolutely_continuous M M'` show "N \<in> null_sets M'"
hoelzl@47694
   130
      using N unfolding absolutely_continuous_def sets_eq null_sets_def by auto
hoelzl@40859
   131
  qed
hoelzl@40859
   132
qed
hoelzl@40859
   133
hoelzl@40871
   134
subsection "Existence of the Radon-Nikodym derivative"
hoelzl@40871
   135
hoelzl@38656
   136
lemma (in finite_measure) Radon_Nikodym_aux_epsilon:
hoelzl@38656
   137
  fixes e :: real assumes "0 < e"
hoelzl@47694
   138
  assumes "finite_measure N" and sets_eq: "sets N = sets M"
hoelzl@47694
   139
  shows "\<exists>A\<in>sets M. measure M (space M) - measure N (space M) \<le> measure M A - measure N A \<and>
hoelzl@47694
   140
                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> - e < measure M B - measure N B)"
hoelzl@38656
   141
proof -
hoelzl@47694
   142
  interpret M': finite_measure N by fact
hoelzl@47694
   143
  let ?d = "\<lambda>A. measure M A - measure N A"
wenzelm@46731
   144
  let ?A = "\<lambda>A. if (\<forall>B\<in>sets M. B \<subseteq> space M - A \<longrightarrow> -e < ?d B)
hoelzl@38656
   145
    then {}
hoelzl@38656
   146
    else (SOME B. B \<in> sets M \<and> B \<subseteq> space M - A \<and> ?d B \<le> -e)"
hoelzl@38656
   147
  def A \<equiv> "\<lambda>n. ((\<lambda>B. B \<union> ?A B) ^^ n) {}"
hoelzl@38656
   148
  have A_simps[simp]:
hoelzl@38656
   149
    "A 0 = {}"
hoelzl@38656
   150
    "\<And>n. A (Suc n) = (A n \<union> ?A (A n))" unfolding A_def by simp_all
hoelzl@38656
   151
  { fix A assume "A \<in> sets M"
hoelzl@38656
   152
    have "?A A \<in> sets M"
hoelzl@38656
   153
      by (auto intro!: someI2[of _ _ "\<lambda>A. A \<in> sets M"] simp: not_less) }
hoelzl@38656
   154
  note A'_in_sets = this
hoelzl@38656
   155
  { fix n have "A n \<in> sets M"
hoelzl@38656
   156
    proof (induct n)
hoelzl@38656
   157
      case (Suc n) thus "A (Suc n) \<in> sets M"
hoelzl@38656
   158
        using A'_in_sets[of "A n"] by (auto split: split_if_asm)
hoelzl@38656
   159
    qed (simp add: A_def) }
hoelzl@38656
   160
  note A_in_sets = this
hoelzl@38656
   161
  hence "range A \<subseteq> sets M" by auto
hoelzl@38656
   162
  { fix n B
hoelzl@38656
   163
    assume Ex: "\<exists>B. B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> -e"
hoelzl@38656
   164
    hence False: "\<not> (\<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B)" by (auto simp: not_less)
hoelzl@38656
   165
    have "?d (A (Suc n)) \<le> ?d (A n) - e" unfolding A_simps if_not_P[OF False]
hoelzl@38656
   166
    proof (rule someI2_ex[OF Ex])
hoelzl@38656
   167
      fix B assume "B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e"
hoelzl@38656
   168
      hence "A n \<inter> B = {}" "B \<in> sets M" and dB: "?d B \<le> -e" by auto
hoelzl@38656
   169
      hence "?d (A n \<union> B) = ?d (A n) + ?d B"
hoelzl@47694
   170
        using `A n \<in> sets M` finite_measure_Union M'.finite_measure_Union by (simp add: sets_eq)
hoelzl@38656
   171
      also have "\<dots> \<le> ?d (A n) - e" using dB by simp
hoelzl@38656
   172
      finally show "?d (A n \<union> B) \<le> ?d (A n) - e" .
hoelzl@38656
   173
    qed }
hoelzl@38656
   174
  note dA_epsilon = this
hoelzl@38656
   175
  { fix n have "?d (A (Suc n)) \<le> ?d (A n)"
hoelzl@38656
   176
    proof (cases "\<exists>B. B\<in>sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e")
hoelzl@38656
   177
      case True from dA_epsilon[OF this] show ?thesis using `0 < e` by simp
hoelzl@38656
   178
    next
hoelzl@38656
   179
      case False
hoelzl@38656
   180
      hence "\<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B" by (auto simp: not_le)
hoelzl@38656
   181
      thus ?thesis by simp
hoelzl@38656
   182
    qed }
hoelzl@38656
   183
  note dA_mono = this
hoelzl@38656
   184
  show ?thesis
hoelzl@38656
   185
  proof (cases "\<exists>n. \<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B")
hoelzl@38656
   186
    case True then obtain n where B: "\<And>B. \<lbrakk> B \<in> sets M; B \<subseteq> space M - A n\<rbrakk> \<Longrightarrow> -e < ?d B" by blast
hoelzl@38656
   187
    show ?thesis
hoelzl@38656
   188
    proof (safe intro!: bexI[of _ "space M - A n"])
hoelzl@38656
   189
      fix B assume "B \<in> sets M" "B \<subseteq> space M - A n"
hoelzl@38656
   190
      from B[OF this] show "-e < ?d B" .
hoelzl@38656
   191
    next
immler@50244
   192
      show "space M - A n \<in> sets M" by (rule sets.compl_sets) fact
hoelzl@38656
   193
    next
hoelzl@38656
   194
      show "?d (space M) \<le> ?d (space M - A n)"
hoelzl@38656
   195
      proof (induct n)
hoelzl@38656
   196
        fix n assume "?d (space M) \<le> ?d (space M - A n)"
hoelzl@38656
   197
        also have "\<dots> \<le> ?d (space M - A (Suc n))"
immler@50244
   198
          using A_in_sets sets.sets_into_space dA_mono[of n] finite_measure_compl M'.finite_measure_compl
hoelzl@47694
   199
          by (simp del: A_simps add: sets_eq sets_eq_imp_space_eq[OF sets_eq])
hoelzl@38656
   200
        finally show "?d (space M) \<le> ?d (space M - A (Suc n))" .
hoelzl@38656
   201
      qed simp
hoelzl@38656
   202
    qed
hoelzl@38656
   203
  next
hoelzl@38656
   204
    case False hence B: "\<And>n. \<exists>B. B\<in>sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e"
hoelzl@38656
   205
      by (auto simp add: not_less)
hoelzl@38656
   206
    { fix n have "?d (A n) \<le> - real n * e"
hoelzl@38656
   207
      proof (induct n)
hoelzl@38656
   208
        case (Suc n) with dA_epsilon[of n, OF B] show ?case by (simp del: A_simps add: real_of_nat_Suc field_simps)
hoelzl@41981
   209
      next
hoelzl@47694
   210
        case 0 with measure_empty show ?case by (simp add: zero_ereal_def)
hoelzl@41981
   211
      qed } note dA_less = this
hoelzl@38656
   212
    have decseq: "decseq (\<lambda>n. ?d (A n))" unfolding decseq_eq_incseq
hoelzl@38656
   213
    proof (rule incseq_SucI)
hoelzl@38656
   214
      fix n show "- ?d (A n) \<le> - ?d (A (Suc n))" using dA_mono[of n] by auto
hoelzl@38656
   215
    qed
hoelzl@41981
   216
    have A: "incseq A" by (auto intro!: incseq_SucI)
hoelzl@47694
   217
    from finite_Lim_measure_incseq[OF _ A] `range A \<subseteq> sets M`
hoelzl@47694
   218
      M'.finite_Lim_measure_incseq[OF _ A]
hoelzl@38656
   219
    have convergent: "(\<lambda>i. ?d (A i)) ----> ?d (\<Union>i. A i)"
hoelzl@47694
   220
      by (auto intro!: tendsto_diff simp: sets_eq)
hoelzl@38656
   221
    obtain n :: nat where "- ?d (\<Union>i. A i) / e < real n" using reals_Archimedean2 by auto
hoelzl@38656
   222
    moreover from order_trans[OF decseq_le[OF decseq convergent] dA_less]
hoelzl@38656
   223
    have "real n \<le> - ?d (\<Union>i. A i) / e" using `0<e` by (simp add: field_simps)
hoelzl@38656
   224
    ultimately show ?thesis by auto
hoelzl@38656
   225
  qed
hoelzl@38656
   226
qed
hoelzl@38656
   227
hoelzl@47694
   228
lemma (in finite_measure) Radon_Nikodym_aux:
hoelzl@47694
   229
  assumes "finite_measure N" and sets_eq: "sets N = sets M"
hoelzl@47694
   230
  shows "\<exists>A\<in>sets M. measure M (space M) - measure N (space M) \<le>
hoelzl@47694
   231
                    measure M A - measure N A \<and>
hoelzl@47694
   232
                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> 0 \<le> measure M B - measure N B)"
hoelzl@41981
   233
proof -
hoelzl@47694
   234
  interpret N: finite_measure N by fact
hoelzl@47694
   235
  let ?d = "\<lambda>A. measure M A - measure N A"
wenzelm@46731
   236
  let ?P = "\<lambda>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)"
wenzelm@46731
   237
  let ?r = "\<lambda>S. restricted_space S"
hoelzl@41981
   238
  { fix S n assume S: "S \<in> sets M"
hoelzl@47694
   239
    then have "finite_measure (density M (indicator S))" "0 < 1 / real (Suc n)"
hoelzl@47694
   240
         "finite_measure (density N (indicator S))" "sets (density N (indicator S)) = sets (density M (indicator S))"
hoelzl@47694
   241
      by (auto simp: finite_measure_restricted N.finite_measure_restricted sets_eq)
hoelzl@41981
   242
    from finite_measure.Radon_Nikodym_aux_epsilon[OF this] guess X .. note X = this
hoelzl@47694
   243
    with S have "?P (S \<inter> X) S n"
immler@50244
   244
      by (simp add: measure_restricted sets_eq sets.Int) (metis inf_absorb2)
hoelzl@47694
   245
    hence "\<exists>A. ?P A S n" .. }
hoelzl@38656
   246
  note Ex_P = this
hoelzl@38656
   247
  def A \<equiv> "nat_rec (space M) (\<lambda>n A. SOME B. ?P B A n)"
hoelzl@38656
   248
  have A_Suc: "\<And>n. A (Suc n) = (SOME B. ?P B (A n) n)" by (simp add: A_def)
hoelzl@38656
   249
  have A_0[simp]: "A 0 = space M" unfolding A_def by simp
hoelzl@38656
   250
  { fix i have "A i \<in> sets M" unfolding A_def
hoelzl@38656
   251
    proof (induct i)
hoelzl@38656
   252
      case (Suc i)
hoelzl@38656
   253
      from Ex_P[OF this, of i] show ?case unfolding nat_rec_Suc
hoelzl@38656
   254
        by (rule someI2_ex) simp
hoelzl@38656
   255
    qed simp }
hoelzl@38656
   256
  note A_in_sets = this
hoelzl@38656
   257
  { fix n have "?P (A (Suc n)) (A n) n"
hoelzl@38656
   258
      using Ex_P[OF A_in_sets] unfolding A_Suc
hoelzl@38656
   259
      by (rule someI2_ex) simp }
hoelzl@38656
   260
  note P_A = this
hoelzl@38656
   261
  have "range A \<subseteq> sets M" using A_in_sets by auto
hoelzl@38656
   262
  have A_mono: "\<And>i. A (Suc i) \<subseteq> A i" using P_A by simp
hoelzl@38656
   263
  have mono_dA: "mono (\<lambda>i. ?d (A i))" using P_A by (simp add: mono_iff_le_Suc)
hoelzl@38656
   264
  have epsilon: "\<And>C i. \<lbrakk> C \<in> sets M; C \<subseteq> A (Suc i) \<rbrakk> \<Longrightarrow> - 1 / real (Suc i) < ?d C"
hoelzl@38656
   265
      using P_A by auto
hoelzl@38656
   266
  show ?thesis
hoelzl@38656
   267
  proof (safe intro!: bexI[of _ "\<Inter>i. A i"])
hoelzl@38656
   268
    show "(\<Inter>i. A i) \<in> sets M" using A_in_sets by auto
hoelzl@41981
   269
    have A: "decseq A" using A_mono by (auto intro!: decseq_SucI)
hoelzl@47694
   270
    from `range A \<subseteq> sets M`
hoelzl@47694
   271
      finite_Lim_measure_decseq[OF _ A] N.finite_Lim_measure_decseq[OF _ A]
hoelzl@47694
   272
    have "(\<lambda>i. ?d (A i)) ----> ?d (\<Inter>i. A i)" by (auto intro!: tendsto_diff simp: sets_eq)
hoelzl@38656
   273
    thus "?d (space M) \<le> ?d (\<Inter>i. A i)" using mono_dA[THEN monoD, of 0 _]
hoelzl@47694
   274
      by (rule_tac LIMSEQ_le_const) auto
hoelzl@38656
   275
  next
hoelzl@38656
   276
    fix B assume B: "B \<in> sets M" "B \<subseteq> (\<Inter>i. A i)"
hoelzl@38656
   277
    show "0 \<le> ?d B"
hoelzl@38656
   278
    proof (rule ccontr)
hoelzl@38656
   279
      assume "\<not> 0 \<le> ?d B"
hoelzl@38656
   280
      hence "0 < - ?d B" by auto
hoelzl@38656
   281
      from ex_inverse_of_nat_Suc_less[OF this]
hoelzl@38656
   282
      obtain n where *: "?d B < - 1 / real (Suc n)"
hoelzl@38656
   283
        by (auto simp: real_eq_of_nat inverse_eq_divide field_simps)
hoelzl@38656
   284
      have "B \<subseteq> A (Suc n)" using B by (auto simp del: nat_rec_Suc)
hoelzl@38656
   285
      from epsilon[OF B(1) this] *
hoelzl@38656
   286
      show False by auto
hoelzl@38656
   287
    qed
hoelzl@38656
   288
  qed
hoelzl@38656
   289
qed
hoelzl@38656
   290
hoelzl@38656
   291
lemma (in finite_measure) Radon_Nikodym_finite_measure:
hoelzl@47694
   292
  assumes "finite_measure N" and sets_eq: "sets N = sets M"
hoelzl@47694
   293
  assumes "absolutely_continuous M N"
hoelzl@47694
   294
  shows "\<exists>f \<in> borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@38656
   295
proof -
hoelzl@47694
   296
  interpret N: finite_measure N by fact
wenzelm@53015
   297
  def G \<equiv> "{g \<in> borel_measurable M. (\<forall>x. 0 \<le> g x) \<and> (\<forall>A\<in>sets M. (\<integral>\<^sup>+x. g x * indicator A x \<partial>M) \<le> N A)}"
hoelzl@50003
   298
  { fix f have "f \<in> G \<Longrightarrow> f \<in> borel_measurable M" by (auto simp: G_def) }
hoelzl@50003
   299
  note this[measurable_dest]
hoelzl@38656
   300
  have "(\<lambda>x. 0) \<in> G" unfolding G_def by auto
hoelzl@38656
   301
  hence "G \<noteq> {}" by auto
hoelzl@38656
   302
  { fix f g assume f: "f \<in> G" and g: "g \<in> G"
hoelzl@38656
   303
    have "(\<lambda>x. max (g x) (f x)) \<in> G" (is "?max \<in> G") unfolding G_def
hoelzl@38656
   304
    proof safe
hoelzl@38656
   305
      show "?max \<in> borel_measurable M" using f g unfolding G_def by auto
hoelzl@38656
   306
      let ?A = "{x \<in> space M. f x \<le> g x}"
hoelzl@38656
   307
      have "?A \<in> sets M" using f g unfolding G_def by auto
hoelzl@38656
   308
      fix A assume "A \<in> sets M"
hoelzl@38656
   309
      hence sets: "?A \<inter> A \<in> sets M" "(space M - ?A) \<inter> A \<in> sets M" using `?A \<in> sets M` by auto
hoelzl@47694
   310
      hence sets': "?A \<inter> A \<in> sets N" "(space M - ?A) \<inter> A \<in> sets N" by (auto simp: sets_eq)
hoelzl@38656
   311
      have union: "((?A \<inter> A) \<union> ((space M - ?A) \<inter> A)) = A"
immler@50244
   312
        using sets.sets_into_space[OF `A \<in> sets M`] by auto
hoelzl@38656
   313
      have "\<And>x. x \<in> space M \<Longrightarrow> max (g x) (f x) * indicator A x =
hoelzl@38656
   314
        g x * indicator (?A \<inter> A) x + f x * indicator ((space M - ?A) \<inter> A) x"
hoelzl@38656
   315
        by (auto simp: indicator_def max_def)
wenzelm@53015
   316
      hence "(\<integral>\<^sup>+x. max (g x) (f x) * indicator A x \<partial>M) =
wenzelm@53015
   317
        (\<integral>\<^sup>+x. g x * indicator (?A \<inter> A) x \<partial>M) +
wenzelm@53015
   318
        (\<integral>\<^sup>+x. f x * indicator ((space M - ?A) \<inter> A) x \<partial>M)"
hoelzl@38656
   319
        using f g sets unfolding G_def
wenzelm@46731
   320
        by (auto cong: positive_integral_cong intro!: positive_integral_add)
hoelzl@47694
   321
      also have "\<dots> \<le> N (?A \<inter> A) + N ((space M - ?A) \<inter> A)"
hoelzl@38656
   322
        using f g sets unfolding G_def by (auto intro!: add_mono)
hoelzl@47694
   323
      also have "\<dots> = N A"
hoelzl@47694
   324
        using plus_emeasure[OF sets'] union by auto
wenzelm@53015
   325
      finally show "(\<integral>\<^sup>+x. max (g x) (f x) * indicator A x \<partial>M) \<le> N A" .
hoelzl@41981
   326
    next
hoelzl@41981
   327
      fix x show "0 \<le> max (g x) (f x)" using f g by (auto simp: G_def split: split_max)
hoelzl@38656
   328
    qed }
hoelzl@38656
   329
  note max_in_G = this
hoelzl@41981
   330
  { fix f assume  "incseq f" and f: "\<And>i. f i \<in> G"
hoelzl@50003
   331
    then have [measurable]: "\<And>i. f i \<in> borel_measurable M" by (auto simp: G_def)
hoelzl@41981
   332
    have "(\<lambda>x. SUP i. f i x) \<in> G" unfolding G_def
hoelzl@38656
   333
    proof safe
hoelzl@50003
   334
      show "(\<lambda>x. SUP i. f i x) \<in> borel_measurable M" by measurable
hoelzl@41981
   335
      { fix x show "0 \<le> (SUP i. f i x)"
hoelzl@44928
   336
          using f by (auto simp: G_def intro: SUP_upper2) }
hoelzl@41981
   337
    next
hoelzl@38656
   338
      fix A assume "A \<in> sets M"
wenzelm@53015
   339
      have "(\<integral>\<^sup>+x. (SUP i. f i x) * indicator A x \<partial>M) =
wenzelm@53015
   340
        (\<integral>\<^sup>+x. (SUP i. f i x * indicator A x) \<partial>M)"
hoelzl@41981
   341
        by (intro positive_integral_cong) (simp split: split_indicator)
wenzelm@53015
   342
      also have "\<dots> = (SUP i. (\<integral>\<^sup>+x. f i x * indicator A x \<partial>M))"
hoelzl@41981
   343
        using `incseq f` f `A \<in> sets M`
hoelzl@41981
   344
        by (intro positive_integral_monotone_convergence_SUP)
hoelzl@41981
   345
           (auto simp: G_def incseq_Suc_iff le_fun_def split: split_indicator)
wenzelm@53015
   346
      finally show "(\<integral>\<^sup>+x. (SUP i. f i x) * indicator A x \<partial>M) \<le> N A"
hoelzl@44928
   347
        using f `A \<in> sets M` by (auto intro!: SUP_least simp: G_def)
hoelzl@38656
   348
    qed }
hoelzl@38656
   349
  note SUP_in_G = this
wenzelm@53015
   350
  let ?y = "SUP g : G. integral\<^sup>P M g"
hoelzl@47694
   351
  have y_le: "?y \<le> N (space M)" unfolding G_def
hoelzl@44928
   352
  proof (safe intro!: SUP_least)
wenzelm@53015
   353
    fix g assume "\<forall>A\<in>sets M. (\<integral>\<^sup>+x. g x * indicator A x \<partial>M) \<le> N A"
wenzelm@53015
   354
    from this[THEN bspec, OF sets.top] show "integral\<^sup>P M g \<le> N (space M)"
hoelzl@38656
   355
      by (simp cong: positive_integral_cong)
hoelzl@38656
   356
  qed
wenzelm@53015
   357
  from SUPR_countable_SUPR[OF `G \<noteq> {}`, of "integral\<^sup>P M"] guess ys .. note ys = this
wenzelm@53015
   358
  then have "\<forall>n. \<exists>g. g\<in>G \<and> integral\<^sup>P M g = ys n"
hoelzl@38656
   359
  proof safe
wenzelm@53015
   360
    fix n assume "range ys \<subseteq> integral\<^sup>P M ` G"
wenzelm@53015
   361
    hence "ys n \<in> integral\<^sup>P M ` G" by auto
wenzelm@53015
   362
    thus "\<exists>g. g\<in>G \<and> integral\<^sup>P M g = ys n" by auto
hoelzl@38656
   363
  qed
wenzelm@53015
   364
  from choice[OF this] obtain gs where "\<And>i. gs i \<in> G" "\<And>n. integral\<^sup>P M (gs n) = ys n" by auto
wenzelm@53015
   365
  hence y_eq: "?y = (SUP i. integral\<^sup>P M (gs i))" using ys by auto
wenzelm@46731
   366
  let ?g = "\<lambda>i x. Max ((\<lambda>n. gs n x) ` {..i})"
hoelzl@41981
   367
  def f \<equiv> "\<lambda>x. SUP i. ?g i x"
wenzelm@46731
   368
  let ?F = "\<lambda>A x. f x * indicator A x"
hoelzl@41981
   369
  have gs_not_empty: "\<And>i x. (\<lambda>n. gs n x) ` {..i} \<noteq> {}" by auto
hoelzl@38656
   370
  { fix i have "?g i \<in> G"
hoelzl@38656
   371
    proof (induct i)
hoelzl@38656
   372
      case 0 thus ?case by simp fact
hoelzl@38656
   373
    next
hoelzl@38656
   374
      case (Suc i)
hoelzl@38656
   375
      with Suc gs_not_empty `gs (Suc i) \<in> G` show ?case
hoelzl@38656
   376
        by (auto simp add: atMost_Suc intro!: max_in_G)
hoelzl@38656
   377
    qed }
hoelzl@38656
   378
  note g_in_G = this
hoelzl@41981
   379
  have "incseq ?g" using gs_not_empty
hoelzl@41981
   380
    by (auto intro!: incseq_SucI le_funI simp add: atMost_Suc)
hoelzl@50003
   381
  from SUP_in_G[OF this g_in_G] have [measurable]: "f \<in> G" unfolding f_def .
hoelzl@41981
   382
  then have [simp, intro]: "f \<in> borel_measurable M" unfolding G_def by auto
wenzelm@53015
   383
  have "integral\<^sup>P M f = (SUP i. integral\<^sup>P M (?g i))" unfolding f_def
hoelzl@41981
   384
    using g_in_G `incseq ?g`
hoelzl@41981
   385
    by (auto intro!: positive_integral_monotone_convergence_SUP simp: G_def)
hoelzl@38656
   386
  also have "\<dots> = ?y"
hoelzl@38656
   387
  proof (rule antisym)
wenzelm@53015
   388
    show "(SUP i. integral\<^sup>P M (?g i)) \<le> ?y"
hoelzl@47694
   389
      using g_in_G by (auto intro: Sup_mono simp: SUP_def)
wenzelm@53015
   390
    show "?y \<le> (SUP i. integral\<^sup>P M (?g i))" unfolding y_eq
hoelzl@38656
   391
      by (auto intro!: SUP_mono positive_integral_mono Max_ge)
hoelzl@38656
   392
  qed
wenzelm@53015
   393
  finally have int_f_eq_y: "integral\<^sup>P M f = ?y" .
hoelzl@41981
   394
  have "\<And>x. 0 \<le> f x"
hoelzl@41981
   395
    unfolding f_def using `\<And>i. gs i \<in> G`
hoelzl@44928
   396
    by (auto intro!: SUP_upper2 Max_ge_iff[THEN iffD2] simp: G_def)
wenzelm@53015
   397
  let ?t = "\<lambda>A. N A - (\<integral>\<^sup>+x. ?F A x \<partial>M)"
hoelzl@47694
   398
  let ?M = "diff_measure N (density M f)"
wenzelm@53015
   399
  have f_le_N: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+x. ?F A x \<partial>M) \<le> N A"
hoelzl@41981
   400
    using `f \<in> G` unfolding G_def by auto
hoelzl@47694
   401
  have emeasure_M: "\<And>A. A \<in> sets M \<Longrightarrow> emeasure ?M A = ?t A"
hoelzl@47694
   402
  proof (subst emeasure_diff_measure)
hoelzl@47694
   403
    from f_le_N[of "space M"] show "finite_measure N" "finite_measure (density M f)"
hoelzl@47694
   404
      by (auto intro!: finite_measureI simp: emeasure_density cong: positive_integral_cong)
hoelzl@47694
   405
  next
hoelzl@47694
   406
    fix B assume "B \<in> sets N" with f_le_N[of B] show "emeasure (density M f) B \<le> emeasure N B"
hoelzl@47694
   407
      by (auto simp: sets_eq emeasure_density cong: positive_integral_cong)
hoelzl@47694
   408
  qed (auto simp: sets_eq emeasure_density)
hoelzl@47694
   409
  from emeasure_M[of "space M"] N.finite_emeasure_space positive_integral_positive[of M "?F (space M)"]
hoelzl@47694
   410
  interpret M': finite_measure ?M
hoelzl@47694
   411
    by (auto intro!: finite_measureI simp: sets_eq_imp_space_eq[OF sets_eq] N.emeasure_eq_measure ereal_minus_eq_PInfty_iff)
hoelzl@47694
   412
hoelzl@47694
   413
  have ac: "absolutely_continuous M ?M" unfolding absolutely_continuous_def
hoelzl@45777
   414
  proof
hoelzl@47694
   415
    fix A assume A: "A \<in> null_sets M"
hoelzl@47694
   416
    with `absolutely_continuous M N` have "A \<in> null_sets N"
hoelzl@47694
   417
      unfolding absolutely_continuous_def by auto
wenzelm@53015
   418
    moreover with A have "(\<integral>\<^sup>+ x. ?F A x \<partial>M) \<le> N A" using `f \<in> G` by (auto simp: G_def)
wenzelm@53015
   419
    ultimately have "N A - (\<integral>\<^sup>+ x. ?F A x \<partial>M) = 0"
hoelzl@47694
   420
      using positive_integral_positive[of M] by (auto intro!: antisym)
hoelzl@47694
   421
    then show "A \<in> null_sets ?M"
hoelzl@47694
   422
      using A by (simp add: emeasure_M null_sets_def sets_eq)
hoelzl@38656
   423
  qed
hoelzl@47694
   424
  have upper_bound: "\<forall>A\<in>sets M. ?M A \<le> 0"
hoelzl@38656
   425
  proof (rule ccontr)
hoelzl@38656
   426
    assume "\<not> ?thesis"
hoelzl@47694
   427
    then obtain A where A: "A \<in> sets M" and pos: "0 < ?M A"
hoelzl@38656
   428
      by (auto simp: not_le)
hoelzl@38656
   429
    note pos
hoelzl@47694
   430
    also have "?M A \<le> ?M (space M)"
hoelzl@47694
   431
      using emeasure_space[of ?M A] by (simp add: sets_eq[THEN sets_eq_imp_space_eq])
hoelzl@47694
   432
    finally have pos_t: "0 < ?M (space M)" by simp
hoelzl@38656
   433
    moreover
hoelzl@47694
   434
    then have "emeasure M (space M) \<noteq> 0"
hoelzl@47694
   435
      using ac unfolding absolutely_continuous_def by (auto simp: null_sets_def)
hoelzl@47694
   436
    then have pos_M: "0 < emeasure M (space M)"
hoelzl@47694
   437
      using emeasure_nonneg[of M "space M"] by (simp add: le_less)
hoelzl@38656
   438
    moreover
wenzelm@53015
   439
    have "(\<integral>\<^sup>+x. f x * indicator (space M) x \<partial>M) \<le> N (space M)"
hoelzl@38656
   440
      using `f \<in> G` unfolding G_def by auto
wenzelm@53015
   441
    hence "(\<integral>\<^sup>+x. f x * indicator (space M) x \<partial>M) \<noteq> \<infinity>"
hoelzl@47694
   442
      using M'.finite_emeasure_space by auto
hoelzl@38656
   443
    moreover
hoelzl@47694
   444
    def b \<equiv> "?M (space M) / emeasure M (space M) / 2"
hoelzl@41981
   445
    ultimately have b: "b \<noteq> 0 \<and> 0 \<le> b \<and> b \<noteq> \<infinity>"
hoelzl@47694
   446
      by (auto simp: ereal_divide_eq)
hoelzl@41981
   447
    then have b: "b \<noteq> 0" "0 \<le> b" "0 < b"  "b \<noteq> \<infinity>" by auto
hoelzl@47694
   448
    let ?Mb = "density M (\<lambda>_. b)"
hoelzl@47694
   449
    have Mb: "finite_measure ?Mb" "sets ?Mb = sets ?M"
hoelzl@47694
   450
        using b by (auto simp: emeasure_density_const sets_eq intro!: finite_measureI)
hoelzl@47694
   451
    from M'.Radon_Nikodym_aux[OF this] guess A0 ..
hoelzl@47694
   452
    then have "A0 \<in> sets M"
hoelzl@47694
   453
      and space_less_A0: "measure ?M (space M) - real b * measure M (space M) \<le> measure ?M A0 - real b * measure M A0"
hoelzl@47694
   454
      and *: "\<And>B. B \<in> sets M \<Longrightarrow> B \<subseteq> A0 \<Longrightarrow> 0 \<le> measure ?M B - real b * measure M B"
hoelzl@47694
   455
      using b by (simp_all add: measure_density_const sets_eq_imp_space_eq[OF sets_eq] sets_eq)
hoelzl@41981
   456
    { fix B assume B: "B \<in> sets M" "B \<subseteq> A0"
hoelzl@47694
   457
      with *[OF this] have "b * emeasure M B \<le> ?M B"
hoelzl@47694
   458
        using b unfolding M'.emeasure_eq_measure emeasure_eq_measure by (cases b) auto }
hoelzl@38656
   459
    note bM_le_t = this
wenzelm@46731
   460
    let ?f0 = "\<lambda>x. f x + b * indicator A0 x"
hoelzl@38656
   461
    { fix A assume A: "A \<in> sets M"
hoelzl@38656
   462
      hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
wenzelm@53015
   463
      have "(\<integral>\<^sup>+x. ?f0 x  * indicator A x \<partial>M) =
wenzelm@53015
   464
        (\<integral>\<^sup>+x. f x * indicator A x + b * indicator (A \<inter> A0) x \<partial>M)"
hoelzl@41981
   465
        by (auto intro!: positive_integral_cong split: split_indicator)
wenzelm@53015
   466
      hence "(\<integral>\<^sup>+x. ?f0 x * indicator A x \<partial>M) =
wenzelm@53015
   467
          (\<integral>\<^sup>+x. f x * indicator A x \<partial>M) + b * emeasure M (A \<inter> A0)"
hoelzl@41981
   468
        using `A0 \<in> sets M` `A \<inter> A0 \<in> sets M` A b `f \<in> G`
hoelzl@50003
   469
        by (simp add: positive_integral_add positive_integral_cmult_indicator G_def) }
hoelzl@38656
   470
    note f0_eq = this
hoelzl@38656
   471
    { fix A assume A: "A \<in> sets M"
hoelzl@38656
   472
      hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
wenzelm@53015
   473
      have f_le_v: "(\<integral>\<^sup>+x. ?F A x \<partial>M) \<le> N A" using `f \<in> G` A unfolding G_def by auto
hoelzl@38656
   474
      note f0_eq[OF A]
wenzelm@53015
   475
      also have "(\<integral>\<^sup>+x. ?F A x \<partial>M) + b * emeasure M (A \<inter> A0) \<le> (\<integral>\<^sup>+x. ?F A x \<partial>M) + ?M (A \<inter> A0)"
hoelzl@38656
   476
        using bM_le_t[OF `A \<inter> A0 \<in> sets M`] `A \<in> sets M` `A0 \<in> sets M`
hoelzl@38656
   477
        by (auto intro!: add_left_mono)
wenzelm@53015
   478
      also have "\<dots> \<le> (\<integral>\<^sup>+x. f x * indicator A x \<partial>M) + ?M A"
hoelzl@47694
   479
        using emeasure_mono[of "A \<inter> A0" A ?M] `A \<in> sets M` `A0 \<in> sets M`
hoelzl@47694
   480
        by (auto intro!: add_left_mono simp: sets_eq)
hoelzl@47694
   481
      also have "\<dots> \<le> N A"
hoelzl@47694
   482
        unfolding emeasure_M[OF `A \<in> sets M`]
hoelzl@47694
   483
        using f_le_v N.emeasure_eq_measure[of A] positive_integral_positive[of M "?F A"]
wenzelm@53015
   484
        by (cases "\<integral>\<^sup>+x. ?F A x \<partial>M", cases "N A") auto
wenzelm@53015
   485
      finally have "(\<integral>\<^sup>+x. ?f0 x * indicator A x \<partial>M) \<le> N A" . }
hoelzl@50003
   486
    hence "?f0 \<in> G" using `A0 \<in> sets M` b `f \<in> G`
hoelzl@50003
   487
      by (auto intro!: ereal_add_nonneg_nonneg simp: G_def)
wenzelm@53015
   488
    have int_f_finite: "integral\<^sup>P M f \<noteq> \<infinity>"
hoelzl@47694
   489
      by (metis N.emeasure_finite ereal_infty_less_eq2(1) int_f_eq_y y_le)
hoelzl@47694
   490
    have  "0 < ?M (space M) - emeasure ?Mb (space M)"
hoelzl@47694
   491
      using pos_t
hoelzl@47694
   492
      by (simp add: b emeasure_density_const)
hoelzl@47694
   493
         (simp add: M'.emeasure_eq_measure emeasure_eq_measure pos_M b_def)
hoelzl@47694
   494
    also have "\<dots> \<le> ?M A0 - b * emeasure M A0"
hoelzl@47694
   495
      using space_less_A0 `A0 \<in> sets M` b
hoelzl@47694
   496
      by (cases b) (auto simp add: b emeasure_density_const sets_eq M'.emeasure_eq_measure emeasure_eq_measure)
hoelzl@47694
   497
    finally have 1: "b * emeasure M A0 < ?M A0"
hoelzl@47694
   498
      by (metis M'.emeasure_real `A0 \<in> sets M` bM_le_t diff_self ereal_less(1) ereal_minus(1)
hoelzl@47694
   499
                less_eq_ereal_def mult_zero_left not_square_less_zero subset_refl zero_ereal_def)
hoelzl@47694
   500
    with b have "0 < ?M A0"
hoelzl@47694
   501
      by (metis M'.emeasure_real MInfty_neq_PInfty(1) emeasure_real ereal_less_eq(5) ereal_zero_times
hoelzl@47694
   502
               ereal_mult_eq_MInfty ereal_mult_eq_PInfty ereal_zero_less_0_iff less_eq_ereal_def)
hoelzl@47694
   503
    then have "emeasure M A0 \<noteq> 0" using ac `A0 \<in> sets M`
hoelzl@47694
   504
      by (auto simp: absolutely_continuous_def null_sets_def)
hoelzl@47694
   505
    then have "0 < emeasure M A0" using emeasure_nonneg[of M A0] by auto
hoelzl@47694
   506
    hence "0 < b * emeasure M A0" using b by (auto simp: ereal_zero_less_0_iff)
wenzelm@53015
   507
    with int_f_finite have "?y + 0 < integral\<^sup>P M f + b * emeasure M A0" unfolding int_f_eq_y
hoelzl@41981
   508
      using `f \<in> G`
hoelzl@44928
   509
      by (intro ereal_add_strict_mono) (auto intro!: SUP_upper2 positive_integral_positive)
wenzelm@53015
   510
    also have "\<dots> = integral\<^sup>P M ?f0" using f0_eq[OF sets.top] `A0 \<in> sets M` sets.sets_into_space
hoelzl@38656
   511
      by (simp cong: positive_integral_cong)
wenzelm@53015
   512
    finally have "?y < integral\<^sup>P M ?f0" by simp
wenzelm@53015
   513
    moreover from `?f0 \<in> G` have "integral\<^sup>P M ?f0 \<le> ?y" by (auto intro!: SUP_upper)
hoelzl@38656
   514
    ultimately show False by auto
hoelzl@38656
   515
  qed
hoelzl@47694
   516
  let ?f = "\<lambda>x. max 0 (f x)"
hoelzl@38656
   517
  show ?thesis
hoelzl@47694
   518
  proof (intro bexI[of _ ?f] measure_eqI conjI)
hoelzl@47694
   519
    show "sets (density M ?f) = sets N"
hoelzl@47694
   520
      by (simp add: sets_eq)
hoelzl@47694
   521
    fix A assume A: "A\<in>sets (density M ?f)"
hoelzl@47694
   522
    then show "emeasure (density M ?f) A = emeasure N A"
hoelzl@47694
   523
      using `f \<in> G` A upper_bound[THEN bspec, of A] N.emeasure_eq_measure[of A]
wenzelm@53015
   524
      by (cases "integral\<^sup>P M (?F A)")
hoelzl@47694
   525
         (auto intro!: antisym simp add: emeasure_density G_def emeasure_M density_max_0[symmetric])
hoelzl@47694
   526
  qed auto
hoelzl@38656
   527
qed
hoelzl@38656
   528
hoelzl@40859
   529
lemma (in finite_measure) split_space_into_finite_sets_and_rest:
hoelzl@47694
   530
  assumes ac: "absolutely_continuous M N" and sets_eq: "sets N = sets M"
hoelzl@41981
   531
  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>
hoelzl@47694
   532
    (\<forall>A\<in>sets M. A \<subseteq> A0 \<longrightarrow> (emeasure M A = 0 \<and> N A = 0) \<or> (emeasure M A > 0 \<and> N A = \<infinity>)) \<and>
hoelzl@47694
   533
    (\<forall>i. N (B i) \<noteq> \<infinity>)"
hoelzl@38656
   534
proof -
hoelzl@47694
   535
  let ?Q = "{Q\<in>sets M. N Q \<noteq> \<infinity>}"
hoelzl@47694
   536
  let ?a = "SUP Q:?Q. emeasure M Q"
hoelzl@47694
   537
  have "{} \<in> ?Q" by auto
hoelzl@38656
   538
  then have Q_not_empty: "?Q \<noteq> {}" by blast
immler@50244
   539
  have "?a \<le> emeasure M (space M)" using sets.sets_into_space
hoelzl@47694
   540
    by (auto intro!: SUP_least emeasure_mono)
hoelzl@47694
   541
  then have "?a \<noteq> \<infinity>" using finite_emeasure_space
hoelzl@38656
   542
    by auto
hoelzl@47694
   543
  from SUPR_countable_SUPR[OF Q_not_empty, of "emeasure M"]
hoelzl@47694
   544
  obtain Q'' where "range Q'' \<subseteq> emeasure M ` ?Q" and a: "?a = (SUP i::nat. Q'' i)"
hoelzl@38656
   545
    by auto
hoelzl@47694
   546
  then have "\<forall>i. \<exists>Q'. Q'' i = emeasure M Q' \<and> Q' \<in> ?Q" by auto
hoelzl@47694
   547
  from choice[OF this] obtain Q' where Q': "\<And>i. Q'' i = emeasure M (Q' i)" "\<And>i. Q' i \<in> ?Q"
hoelzl@38656
   548
    by auto
hoelzl@47694
   549
  then have a_Lim: "?a = (SUP i::nat. emeasure M (Q' i))" using a by simp
wenzelm@46731
   550
  let ?O = "\<lambda>n. \<Union>i\<le>n. Q' i"
hoelzl@47694
   551
  have Union: "(SUP i. emeasure M (?O i)) = emeasure M (\<Union>i. ?O i)"
hoelzl@47694
   552
  proof (rule SUP_emeasure_incseq[of ?O])
hoelzl@47694
   553
    show "range ?O \<subseteq> sets M" using Q' by auto
nipkow@44890
   554
    show "incseq ?O" by (fastforce intro!: incseq_SucI)
hoelzl@38656
   555
  qed
hoelzl@38656
   556
  have Q'_sets: "\<And>i. Q' i \<in> sets M" using Q' by auto
hoelzl@47694
   557
  have O_sets: "\<And>i. ?O i \<in> sets M" using Q' by auto
hoelzl@38656
   558
  then have O_in_G: "\<And>i. ?O i \<in> ?Q"
hoelzl@38656
   559
  proof (safe del: notI)
hoelzl@47694
   560
    fix i have "Q' ` {..i} \<subseteq> sets M" using Q' by auto
hoelzl@47694
   561
    then have "N (?O i) \<le> (\<Sum>i\<le>i. N (Q' i))"
hoelzl@47694
   562
      by (simp add: sets_eq emeasure_subadditive_finite)
hoelzl@41981
   563
    also have "\<dots> < \<infinity>" using Q' by (simp add: setsum_Pinfty)
hoelzl@47694
   564
    finally show "N (?O i) \<noteq> \<infinity>" by simp
hoelzl@38656
   565
  qed auto
nipkow@44890
   566
  have O_mono: "\<And>n. ?O n \<subseteq> ?O (Suc n)" by fastforce
hoelzl@47694
   567
  have a_eq: "?a = emeasure M (\<Union>i. ?O i)" unfolding Union[symmetric]
hoelzl@38656
   568
  proof (rule antisym)
hoelzl@47694
   569
    show "?a \<le> (SUP i. emeasure M (?O i))" unfolding a_Lim
hoelzl@47694
   570
      using Q' by (auto intro!: SUP_mono emeasure_mono)
hoelzl@47694
   571
    show "(SUP i. emeasure M (?O i)) \<le> ?a" unfolding SUP_def
hoelzl@38656
   572
    proof (safe intro!: Sup_mono, unfold bex_simps)
hoelzl@38656
   573
      fix i
haftmann@52141
   574
      have *: "(\<Union>(Q' ` {..i})) = ?O i" by auto
hoelzl@47694
   575
      then show "\<exists>x. (x \<in> sets M \<and> N x \<noteq> \<infinity>) \<and>
haftmann@52141
   576
        emeasure M (\<Union>(Q' ` {..i})) \<le> emeasure M x"
hoelzl@38656
   577
        using O_in_G[of i] by (auto intro!: exI[of _ "?O i"])
hoelzl@38656
   578
    qed
hoelzl@38656
   579
  qed
wenzelm@46731
   580
  let ?O_0 = "(\<Union>i. ?O i)"
hoelzl@38656
   581
  have "?O_0 \<in> sets M" using Q' by auto
hoelzl@40859
   582
  def Q \<equiv> "\<lambda>i. case i of 0 \<Rightarrow> Q' 0 | Suc n \<Rightarrow> ?O (Suc n) - ?O n"
hoelzl@38656
   583
  { fix i have "Q i \<in> sets M" unfolding Q_def using Q'[of 0] by (cases i) (auto intro: O_sets) }
hoelzl@38656
   584
  note Q_sets = this
hoelzl@40859
   585
  show ?thesis
hoelzl@40859
   586
  proof (intro bexI exI conjI ballI impI allI)
hoelzl@40859
   587
    show "disjoint_family Q"
nipkow@44890
   588
      by (fastforce simp: disjoint_family_on_def Q_def
hoelzl@40859
   589
        split: nat.split_asm)
hoelzl@40859
   590
    show "range Q \<subseteq> sets M"
hoelzl@40859
   591
      using Q_sets by auto
hoelzl@40859
   592
    { fix A assume A: "A \<in> sets M" "A \<subseteq> space M - ?O_0"
hoelzl@47694
   593
      show "emeasure M A = 0 \<and> N A = 0 \<or> 0 < emeasure M A \<and> N A = \<infinity>"
hoelzl@40859
   594
      proof (rule disjCI, simp)
hoelzl@47694
   595
        assume *: "0 < emeasure M A \<longrightarrow> N A \<noteq> \<infinity>"
hoelzl@47694
   596
        show "emeasure M A = 0 \<and> N A = 0"
hoelzl@40859
   597
        proof cases
hoelzl@47694
   598
          assume "emeasure M A = 0" moreover with ac A have "N A = 0"
hoelzl@40859
   599
            unfolding absolutely_continuous_def by auto
hoelzl@40859
   600
          ultimately show ?thesis by simp
hoelzl@40859
   601
        next
hoelzl@47694
   602
          assume "emeasure M A \<noteq> 0" with * have "N A \<noteq> \<infinity>" using emeasure_nonneg[of M A] by auto
hoelzl@47694
   603
          with A have "emeasure M ?O_0 + emeasure M A = emeasure M (?O_0 \<union> A)"
immler@50244
   604
            using Q' by (auto intro!: plus_emeasure sets.countable_UN)
hoelzl@47694
   605
          also have "\<dots> = (SUP i. emeasure M (?O i \<union> A))"
hoelzl@47694
   606
          proof (rule SUP_emeasure_incseq[of "\<lambda>i. ?O i \<union> A", symmetric, simplified])
hoelzl@40859
   607
            show "range (\<lambda>i. ?O i \<union> A) \<subseteq> sets M"
hoelzl@47694
   608
              using `N A \<noteq> \<infinity>` O_sets A by auto
nipkow@44890
   609
          qed (fastforce intro!: incseq_SucI)
hoelzl@40859
   610
          also have "\<dots> \<le> ?a"
hoelzl@44928
   611
          proof (safe intro!: SUP_least)
hoelzl@40859
   612
            fix i have "?O i \<union> A \<in> ?Q"
hoelzl@40859
   613
            proof (safe del: notI)
hoelzl@40859
   614
              show "?O i \<union> A \<in> sets M" using O_sets A by auto
hoelzl@47694
   615
              from O_in_G[of i] have "N (?O i \<union> A) \<le> N (?O i) + N A"
hoelzl@47694
   616
                using emeasure_subadditive[of "?O i" N A] A O_sets by (auto simp: sets_eq)
hoelzl@47694
   617
              with O_in_G[of i] show "N (?O i \<union> A) \<noteq> \<infinity>"
hoelzl@47694
   618
                using `N A \<noteq> \<infinity>` by auto
hoelzl@40859
   619
            qed
hoelzl@47694
   620
            then show "emeasure M (?O i \<union> A) \<le> ?a" by (rule SUP_upper)
hoelzl@40859
   621
          qed
hoelzl@47694
   622
          finally have "emeasure M A = 0"
hoelzl@47694
   623
            unfolding a_eq using measure_nonneg[of M A] by (simp add: emeasure_eq_measure)
hoelzl@47694
   624
          with `emeasure M A \<noteq> 0` show ?thesis by auto
hoelzl@40859
   625
        qed
hoelzl@40859
   626
      qed }
hoelzl@47694
   627
    { fix i show "N (Q i) \<noteq> \<infinity>"
hoelzl@40859
   628
      proof (cases i)
hoelzl@40859
   629
        case 0 then show ?thesis
hoelzl@40859
   630
          unfolding Q_def using Q'[of 0] by simp
hoelzl@40859
   631
      next
hoelzl@40859
   632
        case (Suc n)
hoelzl@47694
   633
        with `?O n \<in> ?Q` `?O (Suc n) \<in> ?Q`
hoelzl@47694
   634
            emeasure_Diff[OF _ _ _ O_mono, of N n] emeasure_nonneg[of N "(\<Union> x\<le>n. Q' x)"]
hoelzl@47694
   635
        show ?thesis
hoelzl@47694
   636
          by (auto simp: sets_eq ereal_minus_eq_PInfty_iff Q_def)
hoelzl@40859
   637
      qed }
hoelzl@40859
   638
    show "space M - ?O_0 \<in> sets M" using Q'_sets by auto
hoelzl@40859
   639
    { fix j have "(\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q i)"
hoelzl@40859
   640
      proof (induct j)
hoelzl@40859
   641
        case 0 then show ?case by (simp add: Q_def)
hoelzl@40859
   642
      next
hoelzl@40859
   643
        case (Suc j)
nipkow@44890
   644
        have eq: "\<And>j. (\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q' i)" by fastforce
hoelzl@40859
   645
        have "{..j} \<union> {..Suc j} = {..Suc j}" by auto
hoelzl@40859
   646
        then have "(\<Union>i\<le>Suc j. Q' i) = (\<Union>i\<le>j. Q' i) \<union> Q (Suc j)"
hoelzl@40859
   647
          by (simp add: UN_Un[symmetric] Q_def del: UN_Un)
hoelzl@40859
   648
        then show ?case using Suc by (auto simp add: eq atMost_Suc)
hoelzl@40859
   649
      qed }
hoelzl@40859
   650
    then have "(\<Union>j. (\<Union>i\<le>j. ?O i)) = (\<Union>j. (\<Union>i\<le>j. Q i))" by simp
nipkow@44890
   651
    then show "space M - ?O_0 = space M - (\<Union>i. Q i)" by fastforce
hoelzl@40859
   652
  qed
hoelzl@40859
   653
qed
hoelzl@40859
   654
hoelzl@40859
   655
lemma (in finite_measure) Radon_Nikodym_finite_measure_infinite:
hoelzl@47694
   656
  assumes "absolutely_continuous M N" and sets_eq: "sets N = sets M"
hoelzl@47694
   657
  shows "\<exists>f\<in>borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@40859
   658
proof -
hoelzl@40859
   659
  from split_space_into_finite_sets_and_rest[OF assms]
hoelzl@40859
   660
  obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
hoelzl@40859
   661
    where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
hoelzl@40859
   662
    and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
hoelzl@47694
   663
    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> emeasure M A = 0 \<and> N A = 0 \<or> 0 < emeasure M A \<and> N A = \<infinity>"
hoelzl@47694
   664
    and Q_fin: "\<And>i. N (Q i) \<noteq> \<infinity>" by force
hoelzl@40859
   665
  from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
hoelzl@47694
   666
  let ?N = "\<lambda>i. density N (indicator (Q i))" and ?M = "\<lambda>i. density M (indicator (Q i))"
hoelzl@47694
   667
  have "\<forall>i. \<exists>f\<in>borel_measurable (?M i). (\<forall>x. 0 \<le> f x) \<and> density (?M i) f = ?N i"
hoelzl@47694
   668
  proof (intro allI finite_measure.Radon_Nikodym_finite_measure)
hoelzl@38656
   669
    fix i
hoelzl@47694
   670
    from Q show "finite_measure (?M i)"
hoelzl@47694
   671
      by (auto intro!: finite_measureI cong: positive_integral_cong
hoelzl@47694
   672
               simp add: emeasure_density subset_eq sets_eq)
hoelzl@47694
   673
    from Q have "emeasure (?N i) (space N) = emeasure N (Q i)"
hoelzl@47694
   674
      by (simp add: sets_eq[symmetric] emeasure_density subset_eq cong: positive_integral_cong)
hoelzl@47694
   675
    with Q_fin show "finite_measure (?N i)"
hoelzl@47694
   676
      by (auto intro!: finite_measureI)
hoelzl@47694
   677
    show "sets (?N i) = sets (?M i)" by (simp add: sets_eq)
hoelzl@50003
   678
    have [measurable]: "\<And>A. A \<in> sets M \<Longrightarrow> A \<in> sets N" by (simp add: sets_eq)
hoelzl@47694
   679
    show "absolutely_continuous (?M i) (?N i)"
hoelzl@47694
   680
      using `absolutely_continuous M N` `Q i \<in> sets M`
hoelzl@47694
   681
      by (auto simp: absolutely_continuous_def null_sets_density_iff sets_eq
hoelzl@47694
   682
               intro!: absolutely_continuous_AE[OF sets_eq])
hoelzl@38656
   683
  qed
hoelzl@47694
   684
  from choice[OF this[unfolded Bex_def]]
hoelzl@47694
   685
  obtain f where borel: "\<And>i. f i \<in> borel_measurable M" "\<And>i x. 0 \<le> f i x"
hoelzl@47694
   686
    and f_density: "\<And>i. density (?M i) (f i) = ?N i"
hoelzl@38656
   687
    by auto
hoelzl@47694
   688
  { fix A i assume A: "A \<in> sets M"
wenzelm@53015
   689
    with Q borel have "(\<integral>\<^sup>+x. f i x * indicator (Q i \<inter> A) x \<partial>M) = emeasure (density (?M i) (f i)) A"
hoelzl@47694
   690
      by (auto simp add: emeasure_density positive_integral_density subset_eq
hoelzl@47694
   691
               intro!: positive_integral_cong split: split_indicator)
hoelzl@47694
   692
    also have "\<dots> = emeasure N (Q i \<inter> A)"
hoelzl@47694
   693
      using A Q by (simp add: f_density emeasure_restricted subset_eq sets_eq)
wenzelm@53015
   694
    finally have "emeasure N (Q i \<inter> A) = (\<integral>\<^sup>+x. f i x * indicator (Q i \<inter> A) x \<partial>M)" .. }
hoelzl@47694
   695
  note integral_eq = this
wenzelm@46731
   696
  let ?f = "\<lambda>x. (\<Sum>i. f i x * indicator (Q i) x) + \<infinity> * indicator Q0 x"
hoelzl@38656
   697
  show ?thesis
hoelzl@38656
   698
  proof (safe intro!: bexI[of _ ?f])
hoelzl@41981
   699
    show "?f \<in> borel_measurable M" using Q0 borel Q_sets
hoelzl@41981
   700
      by (auto intro!: measurable_If)
hoelzl@41981
   701
    show "\<And>x. 0 \<le> ?f x" using borel by (auto intro!: suminf_0_le simp: indicator_def)
hoelzl@47694
   702
    show "density M ?f = N"
hoelzl@47694
   703
    proof (rule measure_eqI)
hoelzl@47694
   704
      fix A assume "A \<in> sets (density M ?f)"
hoelzl@47694
   705
      then have "A \<in> sets M" by simp
hoelzl@47694
   706
      have Qi: "\<And>i. Q i \<in> sets M" using Q by auto
hoelzl@47694
   707
      have [intro,simp]: "\<And>i. (\<lambda>x. f i x * indicator (Q i \<inter> A) x) \<in> borel_measurable M"
hoelzl@47694
   708
        "\<And>i. AE x in M. 0 \<le> f i x * indicator (Q i \<inter> A) x"
hoelzl@47694
   709
        using borel Qi Q0(1) `A \<in> sets M` by (auto intro!: borel_measurable_ereal_times)
wenzelm@53015
   710
      have "(\<integral>\<^sup>+x. ?f x * indicator A x \<partial>M) = (\<integral>\<^sup>+x. (\<Sum>i. f i x * indicator (Q i \<inter> A) x) + \<infinity> * indicator (Q0 \<inter> A) x \<partial>M)"
hoelzl@47694
   711
        using borel by (intro positive_integral_cong) (auto simp: indicator_def)
wenzelm@53015
   712
      also have "\<dots> = (\<integral>\<^sup>+x. (\<Sum>i. f i x * indicator (Q i \<inter> A) x) \<partial>M) + \<infinity> * emeasure M (Q0 \<inter> A)"
hoelzl@47694
   713
        using borel Qi Q0(1) `A \<in> sets M`
hoelzl@47694
   714
        by (subst positive_integral_add) (auto simp del: ereal_infty_mult
immler@50244
   715
            simp add: positive_integral_cmult_indicator sets.Int intro!: suminf_0_le)
hoelzl@47694
   716
      also have "\<dots> = (\<Sum>i. N (Q i \<inter> A)) + \<infinity> * emeasure M (Q0 \<inter> A)"
hoelzl@47694
   717
        by (subst integral_eq[OF `A \<in> sets M`], subst positive_integral_suminf) auto
wenzelm@53015
   718
      finally have "(\<integral>\<^sup>+x. ?f x * indicator A x \<partial>M) = (\<Sum>i. N (Q i \<inter> A)) + \<infinity> * emeasure M (Q0 \<inter> A)" .
hoelzl@47694
   719
      moreover have "(\<Sum>i. N (Q i \<inter> A)) = N ((\<Union>i. Q i) \<inter> A)"
hoelzl@47694
   720
        using Q Q_sets `A \<in> sets M`
hoelzl@47694
   721
        by (subst suminf_emeasure) (auto simp: disjoint_family_on_def sets_eq)
hoelzl@47694
   722
      moreover have "\<infinity> * emeasure M (Q0 \<inter> A) = N (Q0 \<inter> A)"
hoelzl@47694
   723
      proof -
hoelzl@47694
   724
        have "Q0 \<inter> A \<in> sets M" using Q0(1) `A \<in> sets M` by blast
hoelzl@47694
   725
        from in_Q0[OF this] show ?thesis by auto
hoelzl@47694
   726
      qed
hoelzl@47694
   727
      moreover have "Q0 \<inter> A \<in> sets M" "((\<Union>i. Q i) \<inter> A) \<in> sets M"
hoelzl@47694
   728
        using Q_sets `A \<in> sets M` Q0(1) by auto
hoelzl@47694
   729
      moreover have "((\<Union>i. Q i) \<inter> A) \<union> (Q0 \<inter> A) = A" "((\<Union>i. Q i) \<inter> A) \<inter> (Q0 \<inter> A) = {}"
immler@50244
   730
        using `A \<in> sets M` sets.sets_into_space Q0 by auto
wenzelm@53015
   731
      ultimately have "N A = (\<integral>\<^sup>+x. ?f x * indicator A x \<partial>M)"
hoelzl@47694
   732
        using plus_emeasure[of "(\<Union>i. Q i) \<inter> A" N "Q0 \<inter> A"] by (simp add: sets_eq)
hoelzl@47694
   733
      with `A \<in> sets M` borel Q Q0(1) show "emeasure (density M ?f) A = N A"
hoelzl@50003
   734
        by (auto simp: subset_eq emeasure_density)
hoelzl@47694
   735
    qed (simp add: sets_eq)
hoelzl@38656
   736
  qed
hoelzl@38656
   737
qed
hoelzl@38656
   738
hoelzl@38656
   739
lemma (in sigma_finite_measure) Radon_Nikodym:
hoelzl@47694
   740
  assumes ac: "absolutely_continuous M N" assumes sets_eq: "sets N = sets M"
hoelzl@47694
   741
  shows "\<exists>f \<in> borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@38656
   742
proof -
hoelzl@38656
   743
  from Ex_finite_integrable_function
wenzelm@53015
   744
  obtain h where finite: "integral\<^sup>P M h \<noteq> \<infinity>" and
hoelzl@38656
   745
    borel: "h \<in> borel_measurable M" and
hoelzl@41981
   746
    nn: "\<And>x. 0 \<le> h x" and
hoelzl@38656
   747
    pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x" and
hoelzl@41981
   748
    "\<And>x. x \<in> space M \<Longrightarrow> h x < \<infinity>" by auto
wenzelm@53015
   749
  let ?T = "\<lambda>A. (\<integral>\<^sup>+x. h x * indicator A x \<partial>M)"
hoelzl@47694
   750
  let ?MT = "density M h"
hoelzl@47694
   751
  from borel finite nn interpret T: finite_measure ?MT
hoelzl@47694
   752
    by (auto intro!: finite_measureI cong: positive_integral_cong simp: emeasure_density)
hoelzl@47694
   753
  have "absolutely_continuous ?MT N" "sets N = sets ?MT"
hoelzl@47694
   754
  proof (unfold absolutely_continuous_def, safe)
hoelzl@47694
   755
    fix A assume "A \<in> null_sets ?MT"
hoelzl@47694
   756
    with borel have "A \<in> sets M" "AE x in M. x \<in> A \<longrightarrow> h x \<le> 0"
hoelzl@47694
   757
      by (auto simp add: null_sets_density_iff)
immler@50244
   758
    with pos sets.sets_into_space have "AE x in M. x \<notin> A"
hoelzl@47694
   759
      by (elim eventually_elim1) (auto simp: not_le[symmetric])
hoelzl@47694
   760
    then have "A \<in> null_sets M"
hoelzl@47694
   761
      using `A \<in> sets M` by (simp add: AE_iff_null_sets)
hoelzl@47694
   762
    with ac show "A \<in> null_sets N"
hoelzl@47694
   763
      by (auto simp: absolutely_continuous_def)
hoelzl@47694
   764
  qed (auto simp add: sets_eq)
hoelzl@47694
   765
  from T.Radon_Nikodym_finite_measure_infinite[OF this]
hoelzl@47694
   766
  obtain f where f_borel: "f \<in> borel_measurable M" "\<And>x. 0 \<le> f x" "density ?MT f = N" by auto
hoelzl@47694
   767
  with nn borel show ?thesis
hoelzl@47694
   768
    by (auto intro!: bexI[of _ "\<lambda>x. h x * f x"] simp: density_density_eq)
hoelzl@38656
   769
qed
hoelzl@38656
   770
hoelzl@40859
   771
section "Uniqueness of densities"
hoelzl@40859
   772
hoelzl@47694
   773
lemma finite_density_unique:
hoelzl@40859
   774
  assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@47694
   775
  assumes pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> g x"
wenzelm@53015
   776
  and fin: "integral\<^sup>P M f \<noteq> \<infinity>"
hoelzl@49785
   777
  shows "density M f = density M g \<longleftrightarrow> (AE x in M. f x = g x)"
hoelzl@40859
   778
proof (intro iffI ballI)
hoelzl@47694
   779
  fix A assume eq: "AE x in M. f x = g x"
hoelzl@49785
   780
  with borel show "density M f = density M g"
hoelzl@49785
   781
    by (auto intro: density_cong)
hoelzl@40859
   782
next
wenzelm@53015
   783
  let ?P = "\<lambda>f A. \<integral>\<^sup>+ x. f x * indicator A x \<partial>M"
hoelzl@49785
   784
  assume "density M f = density M g"
hoelzl@49785
   785
  with borel have eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
hoelzl@49785
   786
    by (simp add: emeasure_density[symmetric])
immler@50244
   787
  from this[THEN bspec, OF sets.top] fin
wenzelm@53015
   788
  have g_fin: "integral\<^sup>P M g \<noteq> \<infinity>" by (simp cong: positive_integral_cong)
hoelzl@40859
   789
  { fix f g assume borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@47694
   790
      and pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> g x"
wenzelm@53015
   791
      and g_fin: "integral\<^sup>P M g \<noteq> \<infinity>" and eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
hoelzl@40859
   792
    let ?N = "{x\<in>space M. g x < f x}"
hoelzl@40859
   793
    have N: "?N \<in> sets M" using borel by simp
wenzelm@53015
   794
    have "?P g ?N \<le> integral\<^sup>P M g" using pos
hoelzl@41981
   795
      by (intro positive_integral_mono_AE) (auto split: split_indicator)
hoelzl@41981
   796
    then have Pg_fin: "?P g ?N \<noteq> \<infinity>" using g_fin by auto
wenzelm@53015
   797
    have "?P (\<lambda>x. (f x - g x)) ?N = (\<integral>\<^sup>+x. f x * indicator ?N x - g x * indicator ?N x \<partial>M)"
hoelzl@40859
   798
      by (auto intro!: positive_integral_cong simp: indicator_def)
hoelzl@40859
   799
    also have "\<dots> = ?P f ?N - ?P g ?N"
hoelzl@40859
   800
    proof (rule positive_integral_diff)
hoelzl@40859
   801
      show "(\<lambda>x. f x * indicator ?N x) \<in> borel_measurable M" "(\<lambda>x. g x * indicator ?N x) \<in> borel_measurable M"
hoelzl@40859
   802
        using borel N by auto
hoelzl@47694
   803
      show "AE x in M. g x * indicator ?N x \<le> f x * indicator ?N x"
hoelzl@47694
   804
           "AE x in M. 0 \<le> g x * indicator ?N x"
hoelzl@41981
   805
        using pos by (auto split: split_indicator)
hoelzl@41981
   806
    qed fact
hoelzl@40859
   807
    also have "\<dots> = 0"
hoelzl@47694
   808
      unfolding eq[THEN bspec, OF N] using positive_integral_positive[of M] Pg_fin by auto
hoelzl@47694
   809
    finally have "AE x in M. f x \<le> g x"
hoelzl@41981
   810
      using pos borel positive_integral_PInf_AE[OF borel(2) g_fin]
hoelzl@41981
   811
      by (subst (asm) positive_integral_0_iff_AE)
hoelzl@43920
   812
         (auto split: split_indicator simp: not_less ereal_minus_le_iff) }
hoelzl@41981
   813
  from this[OF borel pos g_fin eq] this[OF borel(2,1) pos(2,1) fin] eq
hoelzl@47694
   814
  show "AE x in M. f x = g x" by auto
hoelzl@40859
   815
qed
hoelzl@40859
   816
hoelzl@40859
   817
lemma (in finite_measure) density_unique_finite_measure:
hoelzl@40859
   818
  assumes borel: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
hoelzl@47694
   819
  assumes pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> f' x"
wenzelm@53015
   820
  assumes f: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+x. f x * indicator A x \<partial>M) = (\<integral>\<^sup>+x. f' x * indicator A x \<partial>M)"
hoelzl@40859
   821
    (is "\<And>A. A \<in> sets M \<Longrightarrow> ?P f A = ?P f' A")
hoelzl@47694
   822
  shows "AE x in M. f x = f' x"
hoelzl@40859
   823
proof -
hoelzl@47694
   824
  let ?D = "\<lambda>f. density M f"
hoelzl@47694
   825
  let ?N = "\<lambda>A. ?P f A" and ?N' = "\<lambda>A. ?P f' A"
wenzelm@46731
   826
  let ?f = "\<lambda>A x. f x * indicator A x" and ?f' = "\<lambda>A x. f' x * indicator A x"
hoelzl@47694
   827
hoelzl@47694
   828
  have ac: "absolutely_continuous M (density M f)" "sets (density M f) = sets M"
hoelzl@47694
   829
    using borel by (auto intro!: absolutely_continuousI_density) 
hoelzl@47694
   830
  from split_space_into_finite_sets_and_rest[OF this]
hoelzl@40859
   831
  obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
hoelzl@40859
   832
    where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
hoelzl@40859
   833
    and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
hoelzl@47694
   834
    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> emeasure M A = 0 \<and> ?D f A = 0 \<or> 0 < emeasure M A \<and> ?D f A = \<infinity>"
hoelzl@47694
   835
    and Q_fin: "\<And>i. ?D f (Q i) \<noteq> \<infinity>" by force
hoelzl@47694
   836
  with borel pos have in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> emeasure M A = 0 \<and> ?N A = 0 \<or> 0 < emeasure M A \<and> ?N A = \<infinity>"
hoelzl@47694
   837
    and Q_fin: "\<And>i. ?N (Q i) \<noteq> \<infinity>" by (auto simp: emeasure_density subset_eq)
hoelzl@47694
   838
hoelzl@40859
   839
  from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
hoelzl@47694
   840
  let ?D = "{x\<in>space M. f x \<noteq> f' x}"
hoelzl@47694
   841
  have "?D \<in> sets M" using borel by auto
hoelzl@43920
   842
  have *: "\<And>i x A. \<And>y::ereal. y * indicator (Q i) x * indicator A x = y * indicator (Q i \<inter> A) x"
hoelzl@40859
   843
    unfolding indicator_def by auto
hoelzl@47694
   844
  have "\<forall>i. AE x in M. ?f (Q i) x = ?f' (Q i) x" using borel Q_fin Q pos
hoelzl@40859
   845
    by (intro finite_density_unique[THEN iffD1] allI)
hoelzl@50003
   846
       (auto intro!: f measure_eqI simp: emeasure_density * subset_eq)
hoelzl@47694
   847
  moreover have "AE x in M. ?f Q0 x = ?f' Q0 x"
hoelzl@40859
   848
  proof (rule AE_I')
hoelzl@43920
   849
    { fix f :: "'a \<Rightarrow> ereal" assume borel: "f \<in> borel_measurable M"
wenzelm@53015
   850
        and eq: "\<And>A. A \<in> sets M \<Longrightarrow> ?N A = (\<integral>\<^sup>+x. f x * indicator A x \<partial>M)"
wenzelm@46731
   851
      let ?A = "\<lambda>i. Q0 \<inter> {x \<in> space M. f x < (i::nat)}"
hoelzl@47694
   852
      have "(\<Union>i. ?A i) \<in> null_sets M"
hoelzl@40859
   853
      proof (rule null_sets_UN)
hoelzl@43923
   854
        fix i ::nat have "?A i \<in> sets M"
hoelzl@40859
   855
          using borel Q0(1) by auto
wenzelm@53015
   856
        have "?N (?A i) \<le> (\<integral>\<^sup>+x. (i::ereal) * indicator (?A i) x \<partial>M)"
hoelzl@40859
   857
          unfolding eq[OF `?A i \<in> sets M`]
hoelzl@40859
   858
          by (auto intro!: positive_integral_mono simp: indicator_def)
hoelzl@47694
   859
        also have "\<dots> = i * emeasure M (?A i)"
hoelzl@40859
   860
          using `?A i \<in> sets M` by (auto intro!: positive_integral_cmult_indicator)
hoelzl@47694
   861
        also have "\<dots> < \<infinity>" using emeasure_real[of "?A i"] by simp
hoelzl@47694
   862
        finally have "?N (?A i) \<noteq> \<infinity>" by simp
hoelzl@47694
   863
        then show "?A i \<in> null_sets M" using in_Q0[OF `?A i \<in> sets M`] `?A i \<in> sets M` by auto
hoelzl@40859
   864
      qed
hoelzl@41981
   865
      also have "(\<Union>i. ?A i) = Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>}"
hoelzl@41981
   866
        by (auto simp: less_PInf_Ex_of_nat real_eq_of_nat)
hoelzl@47694
   867
      finally have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>} \<in> null_sets M" by simp }
hoelzl@40859
   868
    from this[OF borel(1) refl] this[OF borel(2) f]
hoelzl@47694
   869
    have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>} \<in> null_sets M" "Q0 \<inter> {x\<in>space M. f' x \<noteq> \<infinity>} \<in> null_sets M" by simp_all
hoelzl@47694
   870
    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 M" by (rule null_sets.Un)
hoelzl@40859
   871
    show "{x \<in> space M. ?f Q0 x \<noteq> ?f' Q0 x} \<subseteq>
hoelzl@41981
   872
      (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)
hoelzl@40859
   873
  qed
hoelzl@47694
   874
  moreover have "AE x in M. (?f Q0 x = ?f' Q0 x) \<longrightarrow> (\<forall>i. ?f (Q i) x = ?f' (Q i) x) \<longrightarrow>
hoelzl@40859
   875
    ?f (space M) x = ?f' (space M) x"
hoelzl@40859
   876
    by (auto simp: indicator_def Q0)
hoelzl@47694
   877
  ultimately have "AE x in M. ?f (space M) x = ?f' (space M) x"
hoelzl@47694
   878
    unfolding AE_all_countable[symmetric]
hoelzl@47694
   879
    by eventually_elim (auto intro!: AE_I2 split: split_if_asm simp: indicator_def)
hoelzl@47694
   880
  then show "AE x in M. f x = f' x" by auto
hoelzl@40859
   881
qed
hoelzl@40859
   882
hoelzl@40859
   883
lemma (in sigma_finite_measure) density_unique:
hoelzl@47694
   884
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
   885
  assumes f': "f' \<in> borel_measurable M" "AE x in M. 0 \<le> f' x"
hoelzl@47694
   886
  assumes density_eq: "density M f = density M f'"
hoelzl@47694
   887
  shows "AE x in M. f x = f' x"
hoelzl@40859
   888
proof -
hoelzl@40859
   889
  obtain h where h_borel: "h \<in> borel_measurable M"
wenzelm@53015
   890
    and fin: "integral\<^sup>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"
hoelzl@40859
   891
    using Ex_finite_integrable_function by auto
hoelzl@47694
   892
  then have h_nn: "AE x in M. 0 \<le> h x" by auto
hoelzl@47694
   893
  let ?H = "density M h"
hoelzl@47694
   894
  interpret h: finite_measure ?H
hoelzl@47694
   895
    using fin h_borel pos
hoelzl@47694
   896
    by (intro finite_measureI) (simp cong: positive_integral_cong emeasure_density add: fin)
hoelzl@47694
   897
  let ?fM = "density M f"
hoelzl@47694
   898
  let ?f'M = "density M f'"
hoelzl@40859
   899
  { fix A assume "A \<in> sets M"
hoelzl@41981
   900
    then have "{x \<in> space M. h x * indicator A x \<noteq> 0} = A"
immler@50244
   901
      using pos(1) sets.sets_into_space by (force simp: indicator_def)
wenzelm@53015
   902
    then have "(\<integral>\<^sup>+x. h x * indicator A x \<partial>M) = 0 \<longleftrightarrow> A \<in> null_sets M"
hoelzl@41981
   903
      using h_borel `A \<in> sets M` h_nn by (subst positive_integral_0_iff) auto }
hoelzl@40859
   904
  note h_null_sets = this
hoelzl@40859
   905
  { fix A assume "A \<in> sets M"
wenzelm@53015
   906
    have "(\<integral>\<^sup>+x. f x * (h x * indicator A x) \<partial>M) = (\<integral>\<^sup>+x. h x * indicator A x \<partial>?fM)"
hoelzl@41981
   907
      using `A \<in> sets M` h_borel h_nn f f'
hoelzl@47694
   908
      by (intro positive_integral_density[symmetric]) auto
wenzelm@53015
   909
    also have "\<dots> = (\<integral>\<^sup>+x. h x * indicator A x \<partial>?f'M)"
hoelzl@47694
   910
      by (simp_all add: density_eq)
wenzelm@53015
   911
    also have "\<dots> = (\<integral>\<^sup>+x. f' x * (h x * indicator A x) \<partial>M)"
hoelzl@41981
   912
      using `A \<in> sets M` h_borel h_nn f f'
hoelzl@47694
   913
      by (intro positive_integral_density) auto
wenzelm@53015
   914
    finally have "(\<integral>\<^sup>+x. h x * (f x * indicator A x) \<partial>M) = (\<integral>\<^sup>+x. h x * (f' x * indicator A x) \<partial>M)"
hoelzl@41981
   915
      by (simp add: ac_simps)
wenzelm@53015
   916
    then have "(\<integral>\<^sup>+x. (f x * indicator A x) \<partial>?H) = (\<integral>\<^sup>+x. (f' x * indicator A x) \<partial>?H)"
hoelzl@41981
   917
      using `A \<in> sets M` h_borel h_nn f f'
hoelzl@47694
   918
      by (subst (asm) (1 2) positive_integral_density[symmetric]) auto }
hoelzl@41981
   919
  then have "AE x in ?H. f x = f' x" using h_borel h_nn f f'
hoelzl@47694
   920
    by (intro h.density_unique_finite_measure absolutely_continuous_AE[of M])
hoelzl@47694
   921
       (auto simp add: AE_density)
hoelzl@47694
   922
  then show "AE x in M. f x = f' x"
hoelzl@47694
   923
    unfolding eventually_ae_filter using h_borel pos
hoelzl@47694
   924
    by (auto simp add: h_null_sets null_sets_density_iff not_less[symmetric]
hoelzl@50021
   925
                          AE_iff_null_sets[symmetric]) blast
hoelzl@40859
   926
qed
hoelzl@40859
   927
hoelzl@47694
   928
lemma (in sigma_finite_measure) density_unique_iff:
hoelzl@47694
   929
  assumes f: "f \<in> borel_measurable M" and "AE x in M. 0 \<le> f x"
hoelzl@47694
   930
  assumes f': "f' \<in> borel_measurable M" and "AE x in M. 0 \<le> f' x"
hoelzl@47694
   931
  shows "density M f = density M f' \<longleftrightarrow> (AE x in M. f x = f' x)"
hoelzl@47694
   932
  using density_unique[OF assms] density_cong[OF f f'] by auto
hoelzl@47694
   933
hoelzl@49785
   934
lemma sigma_finite_density_unique:
hoelzl@49785
   935
  assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@49785
   936
  assumes pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> g x"
hoelzl@49785
   937
  and fin: "sigma_finite_measure (density M f)"
hoelzl@49785
   938
  shows "density M f = density M g \<longleftrightarrow> (AE x in M. f x = g x)"
hoelzl@49785
   939
proof
hoelzl@49785
   940
  assume "AE x in M. f x = g x" with borel show "density M f = density M g" 
hoelzl@49785
   941
    by (auto intro: density_cong)
hoelzl@49785
   942
next
hoelzl@49785
   943
  assume eq: "density M f = density M g"
hoelzl@49785
   944
  interpret f!: sigma_finite_measure "density M f" by fact
hoelzl@49785
   945
  from f.sigma_finite_incseq guess A . note cover = this
hoelzl@49785
   946
hoelzl@49785
   947
  have "AE x in M. \<forall>i. x \<in> A i \<longrightarrow> f x = g x"
hoelzl@49785
   948
    unfolding AE_all_countable
hoelzl@49785
   949
  proof
hoelzl@49785
   950
    fix i
hoelzl@49785
   951
    have "density (density M f) (indicator (A i)) = density (density M g) (indicator (A i))"
hoelzl@49785
   952
      unfolding eq ..
wenzelm@53015
   953
    moreover have "(\<integral>\<^sup>+x. f x * indicator (A i) x \<partial>M) \<noteq> \<infinity>"
hoelzl@49785
   954
      using cover(1) cover(3)[of i] borel by (auto simp: emeasure_density subset_eq)
hoelzl@49785
   955
    ultimately have "AE x in M. f x * indicator (A i) x = g x * indicator (A i) x"
hoelzl@49785
   956
      using borel pos cover(1) pos
hoelzl@49785
   957
      by (intro finite_density_unique[THEN iffD1])
hoelzl@49785
   958
         (auto simp: density_density_eq subset_eq)
hoelzl@49785
   959
    then show "AE x in M. x \<in> A i \<longrightarrow> f x = g x"
hoelzl@49785
   960
      by auto
hoelzl@49785
   961
  qed
hoelzl@49785
   962
  with AE_space show "AE x in M. f x = g x"
hoelzl@49785
   963
    apply eventually_elim
hoelzl@49785
   964
    using cover(2)[symmetric]
hoelzl@49785
   965
    apply auto
hoelzl@49785
   966
    done
hoelzl@49785
   967
qed
hoelzl@49785
   968
hoelzl@49778
   969
lemma (in sigma_finite_measure) sigma_finite_iff_density_finite':
hoelzl@47694
   970
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
   971
  shows "sigma_finite_measure (density M f) \<longleftrightarrow> (AE x in M. f x \<noteq> \<infinity>)"
hoelzl@47694
   972
    (is "sigma_finite_measure ?N \<longleftrightarrow> _")
hoelzl@40859
   973
proof
hoelzl@41689
   974
  assume "sigma_finite_measure ?N"
hoelzl@47694
   975
  then interpret N: sigma_finite_measure ?N .
hoelzl@47694
   976
  from N.Ex_finite_integrable_function obtain h where
wenzelm@53015
   977
    h: "h \<in> borel_measurable M" "integral\<^sup>P ?N h \<noteq> \<infinity>" and
hoelzl@41981
   978
    h_nn: "\<And>x. 0 \<le> h x" and
hoelzl@41981
   979
    fin: "\<forall>x\<in>space M. 0 < h x \<and> h x < \<infinity>" by auto
hoelzl@47694
   980
  have "AE x in M. f x * h x \<noteq> \<infinity>"
hoelzl@40859
   981
  proof (rule AE_I')
wenzelm@53015
   982
    have "integral\<^sup>P ?N h = (\<integral>\<^sup>+x. f x * h x \<partial>M)" using f h h_nn
hoelzl@47694
   983
      by (auto intro!: positive_integral_density)
wenzelm@53015
   984
    then have "(\<integral>\<^sup>+x. f x * h x \<partial>M) \<noteq> \<infinity>"
hoelzl@40859
   985
      using h(2) by simp
hoelzl@47694
   986
    then show "(\<lambda>x. f x * h x) -` {\<infinity>} \<inter> space M \<in> null_sets M"
hoelzl@41981
   987
      using f h(1) by (auto intro!: positive_integral_PInf borel_measurable_vimage)
hoelzl@40859
   988
  qed auto
hoelzl@47694
   989
  then show "AE x in M. f x \<noteq> \<infinity>"
hoelzl@41705
   990
    using fin by (auto elim!: AE_Ball_mp)
hoelzl@40859
   991
next
hoelzl@47694
   992
  assume AE: "AE x in M. f x \<noteq> \<infinity>"
hoelzl@40859
   993
  from sigma_finite guess Q .. note Q = this
hoelzl@43923
   994
  def A \<equiv> "\<lambda>i. f -` (case i of 0 \<Rightarrow> {\<infinity>} | Suc n \<Rightarrow> {.. ereal(of_nat (Suc n))}) \<inter> space M"
hoelzl@40859
   995
  { fix i j have "A i \<inter> Q j \<in> sets M"
hoelzl@40859
   996
    unfolding A_def using f Q
immler@50244
   997
    apply (rule_tac sets.Int)
hoelzl@41981
   998
    by (cases i) (auto intro: measurable_sets[OF f(1)]) }
hoelzl@40859
   999
  note A_in_sets = this
wenzelm@46731
  1000
  let ?A = "\<lambda>n. case prod_decode n of (i,j) \<Rightarrow> A i \<inter> Q j"
hoelzl@41689
  1001
  show "sigma_finite_measure ?N"
hoelzl@40859
  1002
  proof (default, intro exI conjI subsetI allI)
hoelzl@40859
  1003
    fix x assume "x \<in> range ?A"
hoelzl@40859
  1004
    then obtain n where n: "x = ?A n" by auto
hoelzl@41689
  1005
    then show "x \<in> sets ?N" using A_in_sets by (cases "prod_decode n") auto
hoelzl@40859
  1006
  next
hoelzl@40859
  1007
    have "(\<Union>i. ?A i) = (\<Union>i j. A i \<inter> Q j)"
hoelzl@40859
  1008
    proof safe
hoelzl@40859
  1009
      fix x i j assume "x \<in> A i" "x \<in> Q j"
hoelzl@40859
  1010
      then show "x \<in> (\<Union>i. case prod_decode i of (i, j) \<Rightarrow> A i \<inter> Q j)"
hoelzl@40859
  1011
        by (intro UN_I[of "prod_encode (i,j)"]) auto
hoelzl@40859
  1012
    qed auto
hoelzl@40859
  1013
    also have "\<dots> = (\<Union>i. A i) \<inter> space M" using Q by auto
hoelzl@40859
  1014
    also have "(\<Union>i. A i) = space M"
hoelzl@40859
  1015
    proof safe
hoelzl@40859
  1016
      fix x assume x: "x \<in> space M"
hoelzl@40859
  1017
      show "x \<in> (\<Union>i. A i)"
hoelzl@40859
  1018
      proof (cases "f x")
hoelzl@41981
  1019
        case PInf with x show ?thesis unfolding A_def by (auto intro: exI[of _ 0])
hoelzl@40859
  1020
      next
hoelzl@41981
  1021
        case (real r)
hoelzl@43923
  1022
        with less_PInf_Ex_of_nat[of "f x"] obtain n :: nat where "f x < n" by (auto simp: real_eq_of_nat)
hoelzl@45769
  1023
        then show ?thesis using x real unfolding A_def by (auto intro!: exI[of _ "Suc n"] simp: real_eq_of_nat)
hoelzl@41981
  1024
      next
hoelzl@41981
  1025
        case MInf with x show ?thesis
hoelzl@41981
  1026
          unfolding A_def by (auto intro!: exI[of _ "Suc 0"])
hoelzl@40859
  1027
      qed
hoelzl@40859
  1028
    qed (auto simp: A_def)
hoelzl@41689
  1029
    finally show "(\<Union>i. ?A i) = space ?N" by simp
hoelzl@40859
  1030
  next
hoelzl@40859
  1031
    fix n obtain i j where
hoelzl@40859
  1032
      [simp]: "prod_decode n = (i, j)" by (cases "prod_decode n") auto
wenzelm@53015
  1033
    have "(\<integral>\<^sup>+x. f x * indicator (A i \<inter> Q j) x \<partial>M) \<noteq> \<infinity>"
hoelzl@40859
  1034
    proof (cases i)
hoelzl@40859
  1035
      case 0
hoelzl@47694
  1036
      have "AE x in M. f x * indicator (A i \<inter> Q j) x = 0"
hoelzl@41705
  1037
        using AE by (auto simp: A_def `i = 0`)
hoelzl@41705
  1038
      from positive_integral_cong_AE[OF this] show ?thesis by simp
hoelzl@40859
  1039
    next
hoelzl@40859
  1040
      case (Suc n)
wenzelm@53015
  1041
      then have "(\<integral>\<^sup>+x. f x * indicator (A i \<inter> Q j) x \<partial>M) \<le>
wenzelm@53015
  1042
        (\<integral>\<^sup>+x. (Suc n :: ereal) * indicator (Q j) x \<partial>M)"
hoelzl@45769
  1043
        by (auto intro!: positive_integral_mono simp: indicator_def A_def real_eq_of_nat)
hoelzl@47694
  1044
      also have "\<dots> = Suc n * emeasure M (Q j)"
hoelzl@40859
  1045
        using Q by (auto intro!: positive_integral_cmult_indicator)
hoelzl@41981
  1046
      also have "\<dots> < \<infinity>"
hoelzl@41981
  1047
        using Q by (auto simp: real_eq_of_nat[symmetric])
hoelzl@40859
  1048
      finally show ?thesis by simp
hoelzl@40859
  1049
    qed
hoelzl@47694
  1050
    then show "emeasure ?N (?A n) \<noteq> \<infinity>"
hoelzl@47694
  1051
      using A_in_sets Q f by (auto simp: emeasure_density)
hoelzl@40859
  1052
  qed
hoelzl@40859
  1053
qed
hoelzl@40859
  1054
hoelzl@49778
  1055
lemma (in sigma_finite_measure) sigma_finite_iff_density_finite:
hoelzl@49778
  1056
  "f \<in> borel_measurable M \<Longrightarrow> sigma_finite_measure (density M f) \<longleftrightarrow> (AE x in M. f x \<noteq> \<infinity>)"
hoelzl@49778
  1057
  apply (subst density_max_0)
hoelzl@49778
  1058
  apply (subst sigma_finite_iff_density_finite')
hoelzl@49778
  1059
  apply (auto simp: max_def intro!: measurable_If)
hoelzl@49778
  1060
  done
hoelzl@49778
  1061
hoelzl@40871
  1062
section "Radon-Nikodym derivative"
hoelzl@38656
  1063
hoelzl@41689
  1064
definition
hoelzl@47694
  1065
  "RN_deriv M N \<equiv> SOME f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@38656
  1066
hoelzl@47694
  1067
lemma
hoelzl@47694
  1068
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
  1069
  shows borel_measurable_RN_deriv_density: "RN_deriv M (density M f) \<in> borel_measurable M" (is ?borel)
hoelzl@47694
  1070
    and density_RN_deriv_density: "density M (RN_deriv M (density M f)) = density M f" (is ?density)
hoelzl@47694
  1071
    and RN_deriv_density_nonneg: "0 \<le> RN_deriv M (density M f) x" (is ?pos)
hoelzl@40859
  1072
proof -
hoelzl@47694
  1073
  let ?f = "\<lambda>x. max 0 (f x)"
hoelzl@47694
  1074
  let ?P = "\<lambda>g. g \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> g x) \<and> density M g = density M f"
hoelzl@47694
  1075
  from f have "?P ?f" using f by (auto intro!: density_cong simp: split: split_max)
hoelzl@47694
  1076
  then have "?P (RN_deriv M (density M f))"
hoelzl@47694
  1077
    unfolding RN_deriv_def by (rule someI[where P="?P"])
hoelzl@47694
  1078
  then show ?borel ?density ?pos by auto
hoelzl@40859
  1079
qed
hoelzl@40859
  1080
hoelzl@38656
  1081
lemma (in sigma_finite_measure) RN_deriv:
hoelzl@47694
  1082
  assumes "absolutely_continuous M N" "sets N = sets M"
hoelzl@50003
  1083
  shows borel_measurable_RN_deriv[measurable]: "RN_deriv M N \<in> borel_measurable M" (is ?borel)
hoelzl@47694
  1084
    and density_RN_deriv: "density M (RN_deriv M N) = N" (is ?density)
hoelzl@47694
  1085
    and RN_deriv_nonneg: "0 \<le> RN_deriv M N x" (is ?pos)
hoelzl@38656
  1086
proof -
hoelzl@38656
  1087
  note Ex = Radon_Nikodym[OF assms, unfolded Bex_def]
hoelzl@47694
  1088
  from Ex show ?borel unfolding RN_deriv_def by (rule someI2_ex) simp
hoelzl@47694
  1089
  from Ex show ?density unfolding RN_deriv_def by (rule someI2_ex) simp
hoelzl@47694
  1090
  from Ex show ?pos unfolding RN_deriv_def by (rule someI2_ex) simp
hoelzl@38656
  1091
qed
hoelzl@38656
  1092
hoelzl@40859
  1093
lemma (in sigma_finite_measure) RN_deriv_positive_integral:
hoelzl@47694
  1094
  assumes N: "absolutely_continuous M N" "sets N = sets M"
hoelzl@40859
  1095
    and f: "f \<in> borel_measurable M"
wenzelm@53015
  1096
  shows "integral\<^sup>P N f = (\<integral>\<^sup>+x. RN_deriv M N x * f x \<partial>M)"
hoelzl@40859
  1097
proof -
wenzelm@53015
  1098
  have "integral\<^sup>P N f = integral\<^sup>P (density M (RN_deriv M N)) f"
hoelzl@47694
  1099
    using N by (simp add: density_RN_deriv)
wenzelm@53015
  1100
  also have "\<dots> = (\<integral>\<^sup>+x. RN_deriv M N x * f x \<partial>M)"
hoelzl@47694
  1101
    using RN_deriv(1,3)[OF N] f by (simp add: positive_integral_density)
hoelzl@47694
  1102
  finally show ?thesis by simp
hoelzl@40859
  1103
qed
hoelzl@40859
  1104
hoelzl@47694
  1105
lemma null_setsD_AE: "N \<in> null_sets M \<Longrightarrow> AE x in M. x \<notin> N"
hoelzl@47694
  1106
  using AE_iff_null_sets[of N M] by auto
hoelzl@47694
  1107
hoelzl@47694
  1108
lemma (in sigma_finite_measure) RN_deriv_unique:
hoelzl@47694
  1109
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
  1110
  and eq: "density M f = N"
hoelzl@47694
  1111
  shows "AE x in M. f x = RN_deriv M N x"
hoelzl@49785
  1112
  unfolding eq[symmetric]
hoelzl@49785
  1113
  by (intro density_unique_iff[THEN iffD1] f borel_measurable_RN_deriv_density
hoelzl@49785
  1114
            RN_deriv_density_nonneg[THEN AE_I2] density_RN_deriv_density[symmetric])
hoelzl@49785
  1115
hoelzl@49785
  1116
lemma RN_deriv_unique_sigma_finite:
hoelzl@49785
  1117
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@49785
  1118
  and eq: "density M f = N" and fin: "sigma_finite_measure N"
hoelzl@49785
  1119
  shows "AE x in M. f x = RN_deriv M N x"
hoelzl@49785
  1120
  using fin unfolding eq[symmetric]
hoelzl@49785
  1121
  by (intro sigma_finite_density_unique[THEN iffD1] f borel_measurable_RN_deriv_density
hoelzl@49785
  1122
            RN_deriv_density_nonneg[THEN AE_I2] density_RN_deriv_density[symmetric])
hoelzl@47694
  1123
hoelzl@47694
  1124
lemma (in sigma_finite_measure) RN_deriv_distr:
hoelzl@47694
  1125
  fixes T :: "'a \<Rightarrow> 'b"
hoelzl@47694
  1126
  assumes T: "T \<in> measurable M M'" and T': "T' \<in> measurable M' M"
hoelzl@47694
  1127
    and inv: "\<forall>x\<in>space M. T' (T x) = x"
hoelzl@50021
  1128
  and ac[simp]: "absolutely_continuous (distr M M' T) (distr N M' T)"
hoelzl@47694
  1129
  and N: "sets N = sets M"
hoelzl@47694
  1130
  shows "AE x in M. RN_deriv (distr M M' T) (distr N M' T) (T x) = RN_deriv M N x"
hoelzl@41832
  1131
proof (rule RN_deriv_unique)
hoelzl@47694
  1132
  have [simp]: "sets N = sets M" by fact
hoelzl@47694
  1133
  note sets_eq_imp_space_eq[OF N, simp]
hoelzl@47694
  1134
  have measurable_N[simp]: "\<And>M'. measurable N M' = measurable M M'" by (auto simp: measurable_def)
hoelzl@47694
  1135
  { fix A assume "A \<in> sets M"
immler@50244
  1136
    with inv T T' sets.sets_into_space[OF this]
hoelzl@47694
  1137
    have "T -` T' -` A \<inter> T -` space M' \<inter> space M = A"
hoelzl@47694
  1138
      by (auto simp: measurable_def) }
hoelzl@47694
  1139
  note eq = this[simp]
hoelzl@47694
  1140
  { fix A assume "A \<in> sets M"
immler@50244
  1141
    with inv T T' sets.sets_into_space[OF this]
hoelzl@47694
  1142
    have "(T' \<circ> T) -` A \<inter> space M = A"
hoelzl@47694
  1143
      by (auto simp: measurable_def) }
hoelzl@47694
  1144
  note eq2 = this[simp]
hoelzl@47694
  1145
  let ?M' = "distr M M' T" and ?N' = "distr N M' T"
hoelzl@47694
  1146
  interpret M': sigma_finite_measure ?M'
hoelzl@41832
  1147
  proof
hoelzl@41832
  1148
    from sigma_finite guess F .. note F = this
hoelzl@47694
  1149
    show "\<exists>A::nat \<Rightarrow> 'b set. range A \<subseteq> sets ?M' \<and> (\<Union>i. A i) = space ?M' \<and> (\<forall>i. emeasure ?M' (A i) \<noteq> \<infinity>)"
hoelzl@41832
  1150
    proof (intro exI conjI allI)
hoelzl@47694
  1151
      show *: "range (\<lambda>i. T' -` F i \<inter> space ?M') \<subseteq> sets ?M'"
hoelzl@47694
  1152
        using F T' by (auto simp: measurable_def)
hoelzl@47694
  1153
      show "(\<Union>i. T' -` F i \<inter> space ?M') = space ?M'"
hoelzl@47694
  1154
        using F T' by (force simp: measurable_def)
hoelzl@41832
  1155
      fix i
hoelzl@41832
  1156
      have "T' -` F i \<inter> space M' \<in> sets M'" using * by auto
hoelzl@41832
  1157
      moreover
hoelzl@41832
  1158
      have Fi: "F i \<in> sets M" using F by auto
hoelzl@47694
  1159
      ultimately show "emeasure ?M' (T' -` F i \<inter> space ?M') \<noteq> \<infinity>"
hoelzl@47694
  1160
        using F T T' by (simp add: emeasure_distr)
hoelzl@41832
  1161
    qed
hoelzl@41832
  1162
  qed
hoelzl@47694
  1163
  have "(RN_deriv ?M' ?N') \<circ> T \<in> borel_measurable M"
hoelzl@50021
  1164
    using T ac by measurable
hoelzl@47694
  1165
  then show "(\<lambda>x. RN_deriv ?M' ?N' (T x)) \<in> borel_measurable M"
hoelzl@41832
  1166
    by (simp add: comp_def)
hoelzl@47694
  1167
  show "AE x in M. 0 \<le> RN_deriv ?M' ?N' (T x)" using M'.RN_deriv_nonneg[OF ac] by auto
hoelzl@47694
  1168
hoelzl@47694
  1169
  have "N = distr N M (T' \<circ> T)"
hoelzl@47694
  1170
    by (subst measure_of_of_measure[of N, symmetric])
immler@50244
  1171
       (auto simp add: distr_def sets.sigma_sets_eq intro!: measure_of_eq sets.space_closed)
hoelzl@47694
  1172
  also have "\<dots> = distr (distr N M' T) M T'"
hoelzl@47694
  1173
    using T T' by (simp add: distr_distr)
hoelzl@47694
  1174
  also have "\<dots> = distr (density (distr M M' T) (RN_deriv (distr M M' T) (distr N M' T))) M T'"
hoelzl@47694
  1175
    using ac by (simp add: M'.density_RN_deriv)
hoelzl@47694
  1176
  also have "\<dots> = density M (RN_deriv (distr M M' T) (distr N M' T) \<circ> T)"
hoelzl@47694
  1177
    using M'.borel_measurable_RN_deriv[OF ac] by (simp add: distr_density_distr[OF T T', OF inv])
hoelzl@47694
  1178
  finally show "density M (\<lambda>x. RN_deriv (distr M M' T) (distr N M' T) (T x)) = N"
hoelzl@47694
  1179
    by (simp add: comp_def)
hoelzl@41832
  1180
qed
hoelzl@41832
  1181
hoelzl@40859
  1182
lemma (in sigma_finite_measure) RN_deriv_finite:
hoelzl@47694
  1183
  assumes N: "sigma_finite_measure N" and ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@47694
  1184
  shows "AE x in M. RN_deriv M N x \<noteq> \<infinity>"
hoelzl@40859
  1185
proof -
hoelzl@47694
  1186
  interpret N: sigma_finite_measure N by fact
hoelzl@47694
  1187
  from N show ?thesis
hoelzl@47694
  1188
    using sigma_finite_iff_density_finite[OF RN_deriv(1)[OF ac]] RN_deriv(2,3)[OF ac] by simp
hoelzl@40859
  1189
qed
hoelzl@40859
  1190
hoelzl@40859
  1191
lemma (in sigma_finite_measure)
hoelzl@47694
  1192
  assumes N: "sigma_finite_measure N" and ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@40859
  1193
    and f: "f \<in> borel_measurable M"
hoelzl@47694
  1194
  shows RN_deriv_integrable: "integrable N f \<longleftrightarrow>
hoelzl@47694
  1195
      integrable M (\<lambda>x. real (RN_deriv M N x) * f x)" (is ?integrable)
wenzelm@53015
  1196
    and RN_deriv_integral: "integral\<^sup>L N f =
hoelzl@47694
  1197
      (\<integral>x. real (RN_deriv M N x) * f x \<partial>M)" (is ?integral)
hoelzl@40859
  1198
proof -
hoelzl@47694
  1199
  note ac(2)[simp] and sets_eq_imp_space_eq[OF ac(2), simp]
hoelzl@47694
  1200
  interpret N: sigma_finite_measure N by fact
hoelzl@43920
  1201
  have minus_cong: "\<And>A B A' B'::ereal. A = A' \<Longrightarrow> B = B' \<Longrightarrow> real A - real B = real A' - real B'" by simp
hoelzl@40859
  1202
  have f': "(\<lambda>x. - f x) \<in> borel_measurable M" using f by auto
hoelzl@47694
  1203
  have Nf: "f \<in> borel_measurable N" using f by (simp add: measurable_def)
hoelzl@41689
  1204
  { fix f :: "'a \<Rightarrow> real"
hoelzl@47694
  1205
    { fix x assume *: "RN_deriv M N x \<noteq> \<infinity>"
hoelzl@47694
  1206
      have "ereal (real (RN_deriv M N x)) * ereal (f x) = ereal (real (RN_deriv M N x) * f x)"
hoelzl@40859
  1207
        by (simp add: mult_le_0_iff)
hoelzl@47694
  1208
      then have "RN_deriv M N x * ereal (f x) = ereal (real (RN_deriv M N x) * f x)"
hoelzl@47694
  1209
        using RN_deriv(3)[OF ac] * by (auto simp add: ereal_real split: split_if_asm) }
wenzelm@53015
  1210
    then have "(\<integral>\<^sup>+x. ereal (real (RN_deriv M N x) * f x) \<partial>M) = (\<integral>\<^sup>+x. RN_deriv M N x * ereal (f x) \<partial>M)"
wenzelm@53015
  1211
              "(\<integral>\<^sup>+x. ereal (- (real (RN_deriv M N x) * f x)) \<partial>M) = (\<integral>\<^sup>+x. RN_deriv M N x * ereal (- f x) \<partial>M)"
hoelzl@47694
  1212
      using RN_deriv_finite[OF N ac] unfolding ereal_mult_minus_right uminus_ereal.simps(1)[symmetric]
hoelzl@41981
  1213
      by (auto intro!: positive_integral_cong_AE) }
hoelzl@41981
  1214
  note * = this
hoelzl@40859
  1215
  show ?integral ?integrable
hoelzl@41981
  1216
    unfolding lebesgue_integral_def integrable_def *
hoelzl@47694
  1217
    using Nf f RN_deriv(1)[OF ac]
hoelzl@47694
  1218
    by (auto simp: RN_deriv_positive_integral[OF ac])
hoelzl@40859
  1219
qed
hoelzl@40859
  1220
hoelzl@43340
  1221
lemma (in sigma_finite_measure) real_RN_deriv:
hoelzl@47694
  1222
  assumes "finite_measure N"
hoelzl@47694
  1223
  assumes ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@43340
  1224
  obtains D where "D \<in> borel_measurable M"
hoelzl@47694
  1225
    and "AE x in M. RN_deriv M N x = ereal (D x)"
hoelzl@47694
  1226
    and "AE x in N. 0 < D x"
hoelzl@43340
  1227
    and "\<And>x. 0 \<le> D x"
hoelzl@43340
  1228
proof
hoelzl@47694
  1229
  interpret N: finite_measure N by fact
hoelzl@47694
  1230
  
hoelzl@47694
  1231
  note RN = RN_deriv[OF ac]
hoelzl@43340
  1232
hoelzl@47694
  1233
  let ?RN = "\<lambda>t. {x \<in> space M. RN_deriv M N x = t}"
hoelzl@43340
  1234
hoelzl@47694
  1235
  show "(\<lambda>x. real (RN_deriv M N x)) \<in> borel_measurable M"
hoelzl@43340
  1236
    using RN by auto
hoelzl@43340
  1237
wenzelm@53015
  1238
  have "N (?RN \<infinity>) = (\<integral>\<^sup>+ x. RN_deriv M N x * indicator (?RN \<infinity>) x \<partial>M)"
hoelzl@47694
  1239
    using RN(1,3) by (subst RN(2)[symmetric]) (auto simp: emeasure_density)
wenzelm@53015
  1240
  also have "\<dots> = (\<integral>\<^sup>+ x. \<infinity> * indicator (?RN \<infinity>) x \<partial>M)"
hoelzl@43340
  1241
    by (intro positive_integral_cong) (auto simp: indicator_def)
hoelzl@47694
  1242
  also have "\<dots> = \<infinity> * emeasure M (?RN \<infinity>)"
hoelzl@43340
  1243
    using RN by (intro positive_integral_cmult_indicator) auto
hoelzl@47694
  1244
  finally have eq: "N (?RN \<infinity>) = \<infinity> * emeasure M (?RN \<infinity>)" .
hoelzl@43340
  1245
  moreover
hoelzl@47694
  1246
  have "emeasure M (?RN \<infinity>) = 0"
hoelzl@43340
  1247
  proof (rule ccontr)
hoelzl@47694
  1248
    assume "emeasure M {x \<in> space M. RN_deriv M N x = \<infinity>} \<noteq> 0"
hoelzl@47694
  1249
    moreover from RN have "0 \<le> emeasure M {x \<in> space M. RN_deriv M N x = \<infinity>}" by auto
hoelzl@47694
  1250
    ultimately have "0 < emeasure M {x \<in> space M. RN_deriv M N x = \<infinity>}" by auto
hoelzl@47694
  1251
    with eq have "N (?RN \<infinity>) = \<infinity>" by simp
hoelzl@47694
  1252
    with N.emeasure_finite[of "?RN \<infinity>"] RN show False by auto
hoelzl@43340
  1253
  qed
hoelzl@47694
  1254
  ultimately have "AE x in M. RN_deriv M N x < \<infinity>"
hoelzl@43340
  1255
    using RN by (intro AE_iff_measurable[THEN iffD2]) auto
hoelzl@47694
  1256
  then show "AE x in M. RN_deriv M N x = ereal (real (RN_deriv M N x))"
hoelzl@43920
  1257
    using RN(3) by (auto simp: ereal_real)
hoelzl@47694
  1258
  then have eq: "AE x in N. RN_deriv M N x = ereal (real (RN_deriv M N x))"
hoelzl@47694
  1259
    using ac absolutely_continuous_AE by auto
hoelzl@43340
  1260
hoelzl@47694
  1261
  show "\<And>x. 0 \<le> real (RN_deriv M N x)"
hoelzl@43920
  1262
    using RN by (auto intro: real_of_ereal_pos)
hoelzl@43340
  1263
wenzelm@53015
  1264
  have "N (?RN 0) = (\<integral>\<^sup>+ x. RN_deriv M N x * indicator (?RN 0) x \<partial>M)"
hoelzl@47694
  1265
    using RN(1,3) by (subst RN(2)[symmetric]) (auto simp: emeasure_density)
wenzelm@53015
  1266
  also have "\<dots> = (\<integral>\<^sup>+ x. 0 \<partial>M)"
hoelzl@43340
  1267
    by (intro positive_integral_cong) (auto simp: indicator_def)
hoelzl@47694
  1268
  finally have "AE x in N. RN_deriv M N x \<noteq> 0"
hoelzl@47694
  1269
    using RN by (subst AE_iff_measurable[OF _ refl]) (auto simp: ac cong: sets_eq_imp_space_eq)
hoelzl@47694
  1270
  with RN(3) eq show "AE x in N. 0 < real (RN_deriv M N x)"
hoelzl@43920
  1271
    by (auto simp: zero_less_real_of_ereal le_less)
hoelzl@43340
  1272
qed
hoelzl@43340
  1273
hoelzl@38656
  1274
lemma (in sigma_finite_measure) RN_deriv_singleton:
hoelzl@47694
  1275
  assumes ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@47694
  1276
  and x: "{x} \<in> sets M"
hoelzl@47694
  1277
  shows "N {x} = RN_deriv M N x * emeasure M {x}"
hoelzl@38656
  1278
proof -
hoelzl@47694
  1279
  note deriv = RN_deriv[OF ac]
hoelzl@47694
  1280
  from deriv(1,3) `{x} \<in> sets M`
wenzelm@53015
  1281
  have "density M (RN_deriv M N) {x} = (\<integral>\<^sup>+w. RN_deriv M N x * indicator {x} w \<partial>M)"
hoelzl@47694
  1282
    by (auto simp: indicator_def emeasure_density intro!: positive_integral_cong)
hoelzl@47694
  1283
  with x deriv show ?thesis
hoelzl@47694
  1284
    by (auto simp: positive_integral_cmult_indicator)
hoelzl@38656
  1285
qed
hoelzl@38656
  1286
hoelzl@38656
  1287
end