src/HOL/Probability/Radon_Nikodym.thy
author hoelzl
Fri Feb 19 13:40:50 2016 +0100 (2016-02-19)
changeset 62378 85ed00c1fe7c
parent 62343 24106dc44def
child 62390 842917225d56
permissions -rw-r--r--
generalize more theorems to support enat and ennreal
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
wenzelm@61808
     5
section \<open>Radon-Nikod{\'y}m derivative\<close>
hoelzl@42067
     6
hoelzl@38656
     7
theory Radon_Nikodym
hoelzl@56993
     8
imports Bochner_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
lp15@61609
    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:
hoelzl@56996
    47
  shows "\<exists>h\<in>borel_measurable M. integral\<^sup>N 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"
haftmann@62343
    54
    using sigma_finite_disjoint by blast
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+
hoelzl@56996
    70
    then have "integral\<^sup>N M ?h = (\<Sum>i. n i * emeasure M (A i))" using pos
hoelzl@56996
    71
      by (simp add: nn_integral_suminf nn_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" .
wenzelm@61808
    83
      show "0 \<le> n N * emeasure M (A N)" using n[of N] \<open>A N \<in> sets M\<close> by (simp add: emeasure_nonneg)
hoelzl@38656
    84
    qed
hoelzl@56996
    85
    finally show "integral\<^sup>N 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 -
wenzelm@61808
   124
  from \<open>AE x in M. P x\<close> 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
wenzelm@61808
   129
    from \<open>absolutely_continuous M M'\<close> 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"
wenzelm@61808
   170
        using \<open>A n \<in> sets M\<close> 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")
wenzelm@61808
   177
      case True from dA_epsilon[OF this] show ?thesis using \<open>0 < e\<close> 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)
lp15@61609
   208
        case (Suc n) with dA_epsilon[of n, OF B] show ?case by (simp del: A_simps add: 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)
wenzelm@61808
   217
    from finite_Lim_measure_incseq[OF _ A] \<open>range A \<subseteq> sets M\<close>
hoelzl@47694
   218
      M'.finite_Lim_measure_incseq[OF _ A]
wenzelm@61969
   219
    have convergent: "(\<lambda>i. ?d (A i)) \<longlonglongrightarrow> ?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]
wenzelm@61808
   223
    have "real n \<le> - ?d (\<Union>i. A i) / e" using \<open>0<e\<close> 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"
hoelzl@58184
   236
  let ?P = "\<lambda>A n. if n = 0 then A = space M else (\<forall>C\<in>sets M. C \<subseteq> A \<longrightarrow> - 1 / real (Suc n) < ?d C)"
hoelzl@58184
   237
  let ?Q = "\<lambda>A B. A \<subseteq> B \<and> ?d B \<le> ?d A"
hoelzl@58184
   238
hoelzl@58184
   239
  have "\<exists>A. \<forall>n. (A n \<in> sets M \<and> ?P (A n) n) \<and> ?Q (A (Suc n)) (A n)"
hoelzl@58184
   240
  proof (rule dependent_nat_choice)
hoelzl@58184
   241
    show "\<exists>A. A \<in> sets M \<and> ?P A 0"
hoelzl@58184
   242
      by auto
hoelzl@58184
   243
  next
hoelzl@58184
   244
    fix A n assume "A \<in> sets M \<and> ?P A n"
hoelzl@58184
   245
    then have A: "A \<in> sets M" by auto
hoelzl@58184
   246
    then have "finite_measure (density M (indicator A))" "0 < 1 / real (Suc (Suc n))"
hoelzl@58184
   247
         "finite_measure (density N (indicator A))" "sets (density N (indicator A)) = sets (density M (indicator A))"
hoelzl@47694
   248
      by (auto simp: finite_measure_restricted N.finite_measure_restricted sets_eq)
hoelzl@41981
   249
    from finite_measure.Radon_Nikodym_aux_epsilon[OF this] guess X .. note X = this
hoelzl@58184
   250
    with A have "A \<inter> X \<in> sets M \<and> ?P (A \<inter> X) (Suc n) \<and> ?Q (A \<inter> X) A"
hoelzl@56479
   251
      by (simp add: measure_restricted sets_eq sets.Int) (metis inf_absorb2)
hoelzl@58184
   252
    then show "\<exists>B. (B \<in> sets M \<and> ?P B (Suc n)) \<and> ?Q B A"
hoelzl@58184
   253
      by blast
hoelzl@58184
   254
  qed
hoelzl@58184
   255
  then obtain A where A: "\<And>n. A n \<in> sets M" "\<And>n. ?P (A n) n" "\<And>n. ?Q (A (Suc n)) (A n)"
hoelzl@58184
   256
    by metis
hoelzl@58184
   257
  then have mono_dA: "mono (\<lambda>i. ?d (A i))" and A_0[simp]: "A 0 = space M"
hoelzl@58184
   258
    by (auto simp add: mono_iff_le_Suc)
hoelzl@38656
   259
  show ?thesis
hoelzl@38656
   260
  proof (safe intro!: bexI[of _ "\<Inter>i. A i"])
wenzelm@61808
   261
    show "(\<Inter>i. A i) \<in> sets M" using \<open>\<And>n. A n \<in> sets M\<close> by auto
hoelzl@58184
   262
    have "decseq A" using A by (auto intro!: decseq_SucI)
hoelzl@58184
   263
    from A(1) finite_Lim_measure_decseq[OF _ this] N.finite_Lim_measure_decseq[OF _ this]
wenzelm@61969
   264
    have "(\<lambda>i. ?d (A i)) \<longlonglongrightarrow> ?d (\<Inter>i. A i)" by (auto intro!: tendsto_diff simp: sets_eq)
hoelzl@38656
   265
    thus "?d (space M) \<le> ?d (\<Inter>i. A i)" using mono_dA[THEN monoD, of 0 _]
hoelzl@47694
   266
      by (rule_tac LIMSEQ_le_const) auto
hoelzl@38656
   267
  next
hoelzl@38656
   268
    fix B assume B: "B \<in> sets M" "B \<subseteq> (\<Inter>i. A i)"
hoelzl@38656
   269
    show "0 \<le> ?d B"
hoelzl@38656
   270
    proof (rule ccontr)
hoelzl@38656
   271
      assume "\<not> 0 \<le> ?d B"
hoelzl@38656
   272
      hence "0 < - ?d B" by auto
hoelzl@38656
   273
      from ex_inverse_of_nat_Suc_less[OF this]
hoelzl@38656
   274
      obtain n where *: "?d B < - 1 / real (Suc n)"
lp15@61609
   275
        by (auto simp: field_simps)
hoelzl@58184
   276
      also have "\<dots> \<le> - 1 / real (Suc (Suc n))"
hoelzl@58184
   277
        by (auto simp: field_simps)
hoelzl@58184
   278
      finally show False
hoelzl@58184
   279
        using * A(2)[of "Suc n"] B by (auto elim!: ballE[of _ _ B])
hoelzl@38656
   280
    qed
hoelzl@38656
   281
  qed
hoelzl@38656
   282
qed
hoelzl@38656
   283
hoelzl@38656
   284
lemma (in finite_measure) Radon_Nikodym_finite_measure:
hoelzl@47694
   285
  assumes "finite_measure N" and sets_eq: "sets N = sets M"
hoelzl@47694
   286
  assumes "absolutely_continuous M N"
hoelzl@47694
   287
  shows "\<exists>f \<in> borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@38656
   288
proof -
hoelzl@47694
   289
  interpret N: finite_measure N by fact
wenzelm@53015
   290
  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
   291
  { fix f have "f \<in> G \<Longrightarrow> f \<in> borel_measurable M" by (auto simp: G_def) }
hoelzl@50003
   292
  note this[measurable_dest]
hoelzl@38656
   293
  have "(\<lambda>x. 0) \<in> G" unfolding G_def by auto
hoelzl@38656
   294
  hence "G \<noteq> {}" by auto
hoelzl@38656
   295
  { fix f g assume f: "f \<in> G" and g: "g \<in> G"
hoelzl@38656
   296
    have "(\<lambda>x. max (g x) (f x)) \<in> G" (is "?max \<in> G") unfolding G_def
hoelzl@38656
   297
    proof safe
hoelzl@38656
   298
      show "?max \<in> borel_measurable M" using f g unfolding G_def by auto
hoelzl@38656
   299
      let ?A = "{x \<in> space M. f x \<le> g x}"
hoelzl@38656
   300
      have "?A \<in> sets M" using f g unfolding G_def by auto
hoelzl@38656
   301
      fix A assume "A \<in> sets M"
wenzelm@61808
   302
      hence sets: "?A \<inter> A \<in> sets M" "(space M - ?A) \<inter> A \<in> sets M" using \<open>?A \<in> sets M\<close> by auto
hoelzl@47694
   303
      hence sets': "?A \<inter> A \<in> sets N" "(space M - ?A) \<inter> A \<in> sets N" by (auto simp: sets_eq)
hoelzl@38656
   304
      have union: "((?A \<inter> A) \<union> ((space M - ?A) \<inter> A)) = A"
wenzelm@61808
   305
        using sets.sets_into_space[OF \<open>A \<in> sets M\<close>] by auto
hoelzl@38656
   306
      have "\<And>x. x \<in> space M \<Longrightarrow> max (g x) (f x) * indicator A x =
hoelzl@38656
   307
        g x * indicator (?A \<inter> A) x + f x * indicator ((space M - ?A) \<inter> A) x"
hoelzl@38656
   308
        by (auto simp: indicator_def max_def)
wenzelm@53015
   309
      hence "(\<integral>\<^sup>+x. max (g x) (f x) * indicator A x \<partial>M) =
wenzelm@53015
   310
        (\<integral>\<^sup>+x. g x * indicator (?A \<inter> A) x \<partial>M) +
wenzelm@53015
   311
        (\<integral>\<^sup>+x. f x * indicator ((space M - ?A) \<inter> A) x \<partial>M)"
hoelzl@38656
   312
        using f g sets unfolding G_def
hoelzl@56996
   313
        by (auto cong: nn_integral_cong intro!: nn_integral_add)
hoelzl@47694
   314
      also have "\<dots> \<le> N (?A \<inter> A) + N ((space M - ?A) \<inter> A)"
hoelzl@38656
   315
        using f g sets unfolding G_def by (auto intro!: add_mono)
hoelzl@47694
   316
      also have "\<dots> = N A"
hoelzl@47694
   317
        using plus_emeasure[OF sets'] union by auto
wenzelm@53015
   318
      finally show "(\<integral>\<^sup>+x. max (g x) (f x) * indicator A x \<partial>M) \<le> N A" .
hoelzl@41981
   319
    next
hoelzl@41981
   320
      fix x show "0 \<le> max (g x) (f x)" using f g by (auto simp: G_def split: split_max)
hoelzl@38656
   321
    qed }
hoelzl@38656
   322
  note max_in_G = this
hoelzl@41981
   323
  { fix f assume  "incseq f" and f: "\<And>i. f i \<in> G"
hoelzl@50003
   324
    then have [measurable]: "\<And>i. f i \<in> borel_measurable M" by (auto simp: G_def)
hoelzl@41981
   325
    have "(\<lambda>x. SUP i. f i x) \<in> G" unfolding G_def
hoelzl@38656
   326
    proof safe
hoelzl@50003
   327
      show "(\<lambda>x. SUP i. f i x) \<in> borel_measurable M" by measurable
hoelzl@41981
   328
      { fix x show "0 \<le> (SUP i. f i x)"
hoelzl@44928
   329
          using f by (auto simp: G_def intro: SUP_upper2) }
hoelzl@41981
   330
    next
hoelzl@38656
   331
      fix A assume "A \<in> sets M"
wenzelm@53015
   332
      have "(\<integral>\<^sup>+x. (SUP i. f i x) * indicator A x \<partial>M) =
wenzelm@53015
   333
        (\<integral>\<^sup>+x. (SUP i. f i x * indicator A x) \<partial>M)"
hoelzl@56996
   334
        by (intro nn_integral_cong) (simp split: split_indicator)
wenzelm@53015
   335
      also have "\<dots> = (SUP i. (\<integral>\<^sup>+x. f i x * indicator A x \<partial>M))"
wenzelm@61808
   336
        using \<open>incseq f\<close> f \<open>A \<in> sets M\<close>
hoelzl@56996
   337
        by (intro nn_integral_monotone_convergence_SUP)
hoelzl@41981
   338
           (auto simp: G_def incseq_Suc_iff le_fun_def split: split_indicator)
wenzelm@53015
   339
      finally show "(\<integral>\<^sup>+x. (SUP i. f i x) * indicator A x \<partial>M) \<le> N A"
wenzelm@61808
   340
        using f \<open>A \<in> sets M\<close> by (auto intro!: SUP_least simp: G_def)
hoelzl@38656
   341
    qed }
hoelzl@38656
   342
  note SUP_in_G = this
hoelzl@56996
   343
  let ?y = "SUP g : G. integral\<^sup>N M g"
hoelzl@47694
   344
  have y_le: "?y \<le> N (space M)" unfolding G_def
hoelzl@44928
   345
  proof (safe intro!: SUP_least)
wenzelm@53015
   346
    fix g assume "\<forall>A\<in>sets M. (\<integral>\<^sup>+x. g x * indicator A x \<partial>M) \<le> N A"
hoelzl@56996
   347
    from this[THEN bspec, OF sets.top] show "integral\<^sup>N M g \<le> N (space M)"
hoelzl@56996
   348
      by (simp cong: nn_integral_cong)
hoelzl@38656
   349
  qed
wenzelm@61808
   350
  from SUP_countable_SUP [OF \<open>G \<noteq> {}\<close>, of "integral\<^sup>N M"] guess ys .. note ys = this
hoelzl@56996
   351
  then have "\<forall>n. \<exists>g. g\<in>G \<and> integral\<^sup>N M g = ys n"
hoelzl@38656
   352
  proof safe
hoelzl@56996
   353
    fix n assume "range ys \<subseteq> integral\<^sup>N M ` G"
hoelzl@56996
   354
    hence "ys n \<in> integral\<^sup>N M ` G" by auto
hoelzl@56996
   355
    thus "\<exists>g. g\<in>G \<and> integral\<^sup>N M g = ys n" by auto
hoelzl@38656
   356
  qed
hoelzl@56996
   357
  from choice[OF this] obtain gs where "\<And>i. gs i \<in> G" "\<And>n. integral\<^sup>N M (gs n) = ys n" by auto
hoelzl@56996
   358
  hence y_eq: "?y = (SUP i. integral\<^sup>N M (gs i))" using ys by auto
wenzelm@46731
   359
  let ?g = "\<lambda>i x. Max ((\<lambda>n. gs n x) ` {..i})"
hoelzl@41981
   360
  def f \<equiv> "\<lambda>x. SUP i. ?g i x"
wenzelm@46731
   361
  let ?F = "\<lambda>A x. f x * indicator A x"
hoelzl@41981
   362
  have gs_not_empty: "\<And>i x. (\<lambda>n. gs n x) ` {..i} \<noteq> {}" by auto
hoelzl@38656
   363
  { fix i have "?g i \<in> G"
hoelzl@38656
   364
    proof (induct i)
hoelzl@38656
   365
      case 0 thus ?case by simp fact
hoelzl@38656
   366
    next
hoelzl@38656
   367
      case (Suc i)
wenzelm@61808
   368
      with Suc gs_not_empty \<open>gs (Suc i) \<in> G\<close> show ?case
hoelzl@38656
   369
        by (auto simp add: atMost_Suc intro!: max_in_G)
hoelzl@38656
   370
    qed }
hoelzl@38656
   371
  note g_in_G = this
hoelzl@41981
   372
  have "incseq ?g" using gs_not_empty
hoelzl@41981
   373
    by (auto intro!: incseq_SucI le_funI simp add: atMost_Suc)
hoelzl@50003
   374
  from SUP_in_G[OF this g_in_G] have [measurable]: "f \<in> G" unfolding f_def .
hoelzl@41981
   375
  then have [simp, intro]: "f \<in> borel_measurable M" unfolding G_def by auto
hoelzl@56996
   376
  have "integral\<^sup>N M f = (SUP i. integral\<^sup>N M (?g i))" unfolding f_def
wenzelm@61808
   377
    using g_in_G \<open>incseq ?g\<close>
hoelzl@56996
   378
    by (auto intro!: nn_integral_monotone_convergence_SUP simp: G_def)
hoelzl@38656
   379
  also have "\<dots> = ?y"
hoelzl@38656
   380
  proof (rule antisym)
hoelzl@56996
   381
    show "(SUP i. integral\<^sup>N M (?g i)) \<le> ?y"
haftmann@56166
   382
      using g_in_G by (auto intro: SUP_mono)
hoelzl@56996
   383
    show "?y \<le> (SUP i. integral\<^sup>N M (?g i))" unfolding y_eq
hoelzl@56996
   384
      by (auto intro!: SUP_mono nn_integral_mono Max_ge)
hoelzl@38656
   385
  qed
hoelzl@56996
   386
  finally have int_f_eq_y: "integral\<^sup>N M f = ?y" .
hoelzl@41981
   387
  have "\<And>x. 0 \<le> f x"
wenzelm@61808
   388
    unfolding f_def using \<open>\<And>i. gs i \<in> G\<close>
hoelzl@44928
   389
    by (auto intro!: SUP_upper2 Max_ge_iff[THEN iffD2] simp: G_def)
wenzelm@53015
   390
  let ?t = "\<lambda>A. N A - (\<integral>\<^sup>+x. ?F A x \<partial>M)"
hoelzl@47694
   391
  let ?M = "diff_measure N (density M f)"
wenzelm@53015
   392
  have f_le_N: "\<And>A. A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+x. ?F A x \<partial>M) \<le> N A"
wenzelm@61808
   393
    using \<open>f \<in> G\<close> unfolding G_def by auto
hoelzl@47694
   394
  have emeasure_M: "\<And>A. A \<in> sets M \<Longrightarrow> emeasure ?M A = ?t A"
hoelzl@47694
   395
  proof (subst emeasure_diff_measure)
hoelzl@47694
   396
    from f_le_N[of "space M"] show "finite_measure N" "finite_measure (density M f)"
hoelzl@56996
   397
      by (auto intro!: finite_measureI simp: emeasure_density cong: nn_integral_cong)
hoelzl@47694
   398
  next
hoelzl@47694
   399
    fix B assume "B \<in> sets N" with f_le_N[of B] show "emeasure (density M f) B \<le> emeasure N B"
hoelzl@56996
   400
      by (auto simp: sets_eq emeasure_density cong: nn_integral_cong)
hoelzl@47694
   401
  qed (auto simp: sets_eq emeasure_density)
hoelzl@56996
   402
  from emeasure_M[of "space M"] N.finite_emeasure_space nn_integral_nonneg[of M "?F (space M)"]
hoelzl@47694
   403
  interpret M': finite_measure ?M
hoelzl@47694
   404
    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
   405
hoelzl@47694
   406
  have ac: "absolutely_continuous M ?M" unfolding absolutely_continuous_def
hoelzl@45777
   407
  proof
wenzelm@53374
   408
    fix A assume A_M: "A \<in> null_sets M"
wenzelm@61808
   409
    with \<open>absolutely_continuous M N\<close> have A_N: "A \<in> null_sets N"
hoelzl@47694
   410
      unfolding absolutely_continuous_def by auto
wenzelm@61808
   411
    moreover from A_M A_N have "(\<integral>\<^sup>+ x. ?F A x \<partial>M) \<le> N A" using \<open>f \<in> G\<close> by (auto simp: G_def)
wenzelm@53015
   412
    ultimately have "N A - (\<integral>\<^sup>+ x. ?F A x \<partial>M) = 0"
hoelzl@56996
   413
      using nn_integral_nonneg[of M] by (auto intro!: antisym)
hoelzl@47694
   414
    then show "A \<in> null_sets ?M"
wenzelm@53374
   415
      using A_M by (simp add: emeasure_M null_sets_def sets_eq)
hoelzl@38656
   416
  qed
hoelzl@47694
   417
  have upper_bound: "\<forall>A\<in>sets M. ?M A \<le> 0"
hoelzl@38656
   418
  proof (rule ccontr)
hoelzl@38656
   419
    assume "\<not> ?thesis"
hoelzl@47694
   420
    then obtain A where A: "A \<in> sets M" and pos: "0 < ?M A"
hoelzl@38656
   421
      by (auto simp: not_le)
hoelzl@38656
   422
    note pos
hoelzl@47694
   423
    also have "?M A \<le> ?M (space M)"
hoelzl@47694
   424
      using emeasure_space[of ?M A] by (simp add: sets_eq[THEN sets_eq_imp_space_eq])
hoelzl@47694
   425
    finally have pos_t: "0 < ?M (space M)" by simp
hoelzl@38656
   426
    moreover
wenzelm@53374
   427
    from pos_t have "emeasure M (space M) \<noteq> 0"
hoelzl@47694
   428
      using ac unfolding absolutely_continuous_def by (auto simp: null_sets_def)
hoelzl@47694
   429
    then have pos_M: "0 < emeasure M (space M)"
hoelzl@47694
   430
      using emeasure_nonneg[of M "space M"] by (simp add: le_less)
hoelzl@38656
   431
    moreover
wenzelm@53015
   432
    have "(\<integral>\<^sup>+x. f x * indicator (space M) x \<partial>M) \<le> N (space M)"
wenzelm@61808
   433
      using \<open>f \<in> G\<close> unfolding G_def by auto
wenzelm@53015
   434
    hence "(\<integral>\<^sup>+x. f x * indicator (space M) x \<partial>M) \<noteq> \<infinity>"
hoelzl@47694
   435
      using M'.finite_emeasure_space by auto
hoelzl@38656
   436
    moreover
hoelzl@47694
   437
    def b \<equiv> "?M (space M) / emeasure M (space M) / 2"
hoelzl@41981
   438
    ultimately have b: "b \<noteq> 0 \<and> 0 \<le> b \<and> b \<noteq> \<infinity>"
hoelzl@47694
   439
      by (auto simp: ereal_divide_eq)
hoelzl@41981
   440
    then have b: "b \<noteq> 0" "0 \<le> b" "0 < b"  "b \<noteq> \<infinity>" by auto
hoelzl@47694
   441
    let ?Mb = "density M (\<lambda>_. b)"
hoelzl@47694
   442
    have Mb: "finite_measure ?Mb" "sets ?Mb = sets ?M"
hoelzl@47694
   443
        using b by (auto simp: emeasure_density_const sets_eq intro!: finite_measureI)
hoelzl@47694
   444
    from M'.Radon_Nikodym_aux[OF this] guess A0 ..
hoelzl@47694
   445
    then have "A0 \<in> sets M"
lp15@61609
   446
      and space_less_A0: "measure ?M (space M) - real_of_ereal b * measure M (space M) \<le> measure ?M A0 - real_of_ereal b * measure M A0"
lp15@61609
   447
      and *: "\<And>B. B \<in> sets M \<Longrightarrow> B \<subseteq> A0 \<Longrightarrow> 0 \<le> measure ?M B - real_of_ereal b * measure M B"
hoelzl@47694
   448
      using b by (simp_all add: measure_density_const sets_eq_imp_space_eq[OF sets_eq] sets_eq)
hoelzl@41981
   449
    { fix B assume B: "B \<in> sets M" "B \<subseteq> A0"
hoelzl@47694
   450
      with *[OF this] have "b * emeasure M B \<le> ?M B"
hoelzl@47694
   451
        using b unfolding M'.emeasure_eq_measure emeasure_eq_measure by (cases b) auto }
hoelzl@38656
   452
    note bM_le_t = this
wenzelm@46731
   453
    let ?f0 = "\<lambda>x. f x + b * indicator A0 x"
hoelzl@38656
   454
    { fix A assume A: "A \<in> sets M"
wenzelm@61808
   455
      hence "A \<inter> A0 \<in> sets M" using \<open>A0 \<in> sets M\<close> by auto
wenzelm@53015
   456
      have "(\<integral>\<^sup>+x. ?f0 x  * indicator A x \<partial>M) =
wenzelm@53015
   457
        (\<integral>\<^sup>+x. f x * indicator A x + b * indicator (A \<inter> A0) x \<partial>M)"
hoelzl@56996
   458
        by (auto intro!: nn_integral_cong split: split_indicator)
wenzelm@53015
   459
      hence "(\<integral>\<^sup>+x. ?f0 x * indicator A x \<partial>M) =
wenzelm@53015
   460
          (\<integral>\<^sup>+x. f x * indicator A x \<partial>M) + b * emeasure M (A \<inter> A0)"
wenzelm@61808
   461
        using \<open>A0 \<in> sets M\<close> \<open>A \<inter> A0 \<in> sets M\<close> A b \<open>f \<in> G\<close>
hoelzl@56996
   462
        by (simp add: nn_integral_add nn_integral_cmult_indicator G_def) }
hoelzl@38656
   463
    note f0_eq = this
hoelzl@38656
   464
    { fix A assume A: "A \<in> sets M"
wenzelm@61808
   465
      hence "A \<inter> A0 \<in> sets M" using \<open>A0 \<in> sets M\<close> by auto
wenzelm@61808
   466
      have f_le_v: "(\<integral>\<^sup>+x. ?F A x \<partial>M) \<le> N A" using \<open>f \<in> G\<close> A unfolding G_def by auto
hoelzl@38656
   467
      note f0_eq[OF A]
wenzelm@53015
   468
      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)"
wenzelm@61808
   469
        using bM_le_t[OF \<open>A \<inter> A0 \<in> sets M\<close>] \<open>A \<in> sets M\<close> \<open>A0 \<in> sets M\<close>
hoelzl@38656
   470
        by (auto intro!: add_left_mono)
wenzelm@53015
   471
      also have "\<dots> \<le> (\<integral>\<^sup>+x. f x * indicator A x \<partial>M) + ?M A"
wenzelm@61808
   472
        using emeasure_mono[of "A \<inter> A0" A ?M] \<open>A \<in> sets M\<close> \<open>A0 \<in> sets M\<close>
hoelzl@47694
   473
        by (auto intro!: add_left_mono simp: sets_eq)
hoelzl@47694
   474
      also have "\<dots> \<le> N A"
wenzelm@61808
   475
        unfolding emeasure_M[OF \<open>A \<in> sets M\<close>]
hoelzl@56996
   476
        using f_le_v N.emeasure_eq_measure[of A] nn_integral_nonneg[of M "?F A"]
wenzelm@53015
   477
        by (cases "\<integral>\<^sup>+x. ?F A x \<partial>M", cases "N A") auto
wenzelm@53015
   478
      finally have "(\<integral>\<^sup>+x. ?f0 x * indicator A x \<partial>M) \<le> N A" . }
wenzelm@61808
   479
    hence "?f0 \<in> G" using \<open>A0 \<in> sets M\<close> b \<open>f \<in> G\<close> by (auto simp: G_def)
hoelzl@56996
   480
    have int_f_finite: "integral\<^sup>N M f \<noteq> \<infinity>"
hoelzl@47694
   481
      by (metis N.emeasure_finite ereal_infty_less_eq2(1) int_f_eq_y y_le)
hoelzl@47694
   482
    have  "0 < ?M (space M) - emeasure ?Mb (space M)"
hoelzl@47694
   483
      using pos_t
hoelzl@47694
   484
      by (simp add: b emeasure_density_const)
hoelzl@47694
   485
         (simp add: M'.emeasure_eq_measure emeasure_eq_measure pos_M b_def)
hoelzl@47694
   486
    also have "\<dots> \<le> ?M A0 - b * emeasure M A0"
wenzelm@61808
   487
      using space_less_A0 \<open>A0 \<in> sets M\<close> b
hoelzl@47694
   488
      by (cases b) (auto simp add: b emeasure_density_const sets_eq M'.emeasure_eq_measure emeasure_eq_measure)
hoelzl@47694
   489
    finally have 1: "b * emeasure M A0 < ?M A0"
wenzelm@61808
   490
      by (metis M'.emeasure_real \<open>A0 \<in> sets M\<close> bM_le_t diff_self ereal_less(1) ereal_minus(1)
hoelzl@47694
   491
                less_eq_ereal_def mult_zero_left not_square_less_zero subset_refl zero_ereal_def)
hoelzl@47694
   492
    with b have "0 < ?M A0"
hoelzl@47694
   493
      by (metis M'.emeasure_real MInfty_neq_PInfty(1) emeasure_real ereal_less_eq(5) ereal_zero_times
hoelzl@47694
   494
               ereal_mult_eq_MInfty ereal_mult_eq_PInfty ereal_zero_less_0_iff less_eq_ereal_def)
wenzelm@61808
   495
    then have "emeasure M A0 \<noteq> 0" using ac \<open>A0 \<in> sets M\<close>
hoelzl@47694
   496
      by (auto simp: absolutely_continuous_def null_sets_def)
hoelzl@47694
   497
    then have "0 < emeasure M A0" using emeasure_nonneg[of M A0] by auto
hoelzl@47694
   498
    hence "0 < b * emeasure M A0" using b by (auto simp: ereal_zero_less_0_iff)
hoelzl@56996
   499
    with int_f_finite have "?y + 0 < integral\<^sup>N M f + b * emeasure M A0" unfolding int_f_eq_y
wenzelm@61808
   500
      using \<open>f \<in> G\<close>
hoelzl@56996
   501
      by (intro ereal_add_strict_mono) (auto intro!: SUP_upper2 nn_integral_nonneg)
wenzelm@61808
   502
    also have "\<dots> = integral\<^sup>N M ?f0" using f0_eq[OF sets.top] \<open>A0 \<in> sets M\<close> sets.sets_into_space
hoelzl@56996
   503
      by (simp cong: nn_integral_cong)
hoelzl@56996
   504
    finally have "?y < integral\<^sup>N M ?f0" by simp
wenzelm@61808
   505
    moreover from \<open>?f0 \<in> G\<close> have "integral\<^sup>N M ?f0 \<le> ?y" by (auto intro!: SUP_upper)
hoelzl@38656
   506
    ultimately show False by auto
hoelzl@38656
   507
  qed
hoelzl@47694
   508
  let ?f = "\<lambda>x. max 0 (f x)"
hoelzl@38656
   509
  show ?thesis
hoelzl@47694
   510
  proof (intro bexI[of _ ?f] measure_eqI conjI)
hoelzl@47694
   511
    show "sets (density M ?f) = sets N"
hoelzl@47694
   512
      by (simp add: sets_eq)
hoelzl@47694
   513
    fix A assume A: "A\<in>sets (density M ?f)"
hoelzl@47694
   514
    then show "emeasure (density M ?f) A = emeasure N A"
wenzelm@61808
   515
      using \<open>f \<in> G\<close> A upper_bound[THEN bspec, of A] N.emeasure_eq_measure[of A]
hoelzl@56996
   516
      by (cases "integral\<^sup>N M (?F A)")
hoelzl@47694
   517
         (auto intro!: antisym simp add: emeasure_density G_def emeasure_M density_max_0[symmetric])
hoelzl@47694
   518
  qed auto
hoelzl@38656
   519
qed
hoelzl@38656
   520
hoelzl@40859
   521
lemma (in finite_measure) split_space_into_finite_sets_and_rest:
hoelzl@47694
   522
  assumes ac: "absolutely_continuous M N" and sets_eq: "sets N = sets M"
hoelzl@41981
   523
  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
   524
    (\<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
   525
    (\<forall>i. N (B i) \<noteq> \<infinity>)"
hoelzl@38656
   526
proof -
hoelzl@47694
   527
  let ?Q = "{Q\<in>sets M. N Q \<noteq> \<infinity>}"
hoelzl@47694
   528
  let ?a = "SUP Q:?Q. emeasure M Q"
hoelzl@47694
   529
  have "{} \<in> ?Q" by auto
hoelzl@38656
   530
  then have Q_not_empty: "?Q \<noteq> {}" by blast
immler@50244
   531
  have "?a \<le> emeasure M (space M)" using sets.sets_into_space
hoelzl@47694
   532
    by (auto intro!: SUP_least emeasure_mono)
hoelzl@47694
   533
  then have "?a \<noteq> \<infinity>" using finite_emeasure_space
hoelzl@38656
   534
    by auto
haftmann@56212
   535
  from SUP_countable_SUP [OF Q_not_empty, of "emeasure M"]
hoelzl@47694
   536
  obtain Q'' where "range Q'' \<subseteq> emeasure M ` ?Q" and a: "?a = (SUP i::nat. Q'' i)"
hoelzl@38656
   537
    by auto
hoelzl@47694
   538
  then have "\<forall>i. \<exists>Q'. Q'' i = emeasure M Q' \<and> Q' \<in> ?Q" by auto
hoelzl@47694
   539
  from choice[OF this] obtain Q' where Q': "\<And>i. Q'' i = emeasure M (Q' i)" "\<And>i. Q' i \<in> ?Q"
hoelzl@38656
   540
    by auto
hoelzl@47694
   541
  then have a_Lim: "?a = (SUP i::nat. emeasure M (Q' i))" using a by simp
wenzelm@46731
   542
  let ?O = "\<lambda>n. \<Union>i\<le>n. Q' i"
hoelzl@47694
   543
  have Union: "(SUP i. emeasure M (?O i)) = emeasure M (\<Union>i. ?O i)"
hoelzl@47694
   544
  proof (rule SUP_emeasure_incseq[of ?O])
hoelzl@47694
   545
    show "range ?O \<subseteq> sets M" using Q' by auto
nipkow@44890
   546
    show "incseq ?O" by (fastforce intro!: incseq_SucI)
hoelzl@38656
   547
  qed
hoelzl@38656
   548
  have Q'_sets: "\<And>i. Q' i \<in> sets M" using Q' by auto
hoelzl@47694
   549
  have O_sets: "\<And>i. ?O i \<in> sets M" using Q' by auto
hoelzl@38656
   550
  then have O_in_G: "\<And>i. ?O i \<in> ?Q"
hoelzl@38656
   551
  proof (safe del: notI)
hoelzl@47694
   552
    fix i have "Q' ` {..i} \<subseteq> sets M" using Q' by auto
hoelzl@47694
   553
    then have "N (?O i) \<le> (\<Sum>i\<le>i. N (Q' i))"
hoelzl@47694
   554
      by (simp add: sets_eq emeasure_subadditive_finite)
hoelzl@41981
   555
    also have "\<dots> < \<infinity>" using Q' by (simp add: setsum_Pinfty)
hoelzl@47694
   556
    finally show "N (?O i) \<noteq> \<infinity>" by simp
hoelzl@38656
   557
  qed auto
nipkow@44890
   558
  have O_mono: "\<And>n. ?O n \<subseteq> ?O (Suc n)" by fastforce
hoelzl@47694
   559
  have a_eq: "?a = emeasure M (\<Union>i. ?O i)" unfolding Union[symmetric]
hoelzl@38656
   560
  proof (rule antisym)
hoelzl@47694
   561
    show "?a \<le> (SUP i. emeasure M (?O i))" unfolding a_Lim
hoelzl@47694
   562
      using Q' by (auto intro!: SUP_mono emeasure_mono)
haftmann@62343
   563
    show "(SUP i. emeasure M (?O i)) \<le> ?a"
hoelzl@38656
   564
    proof (safe intro!: Sup_mono, unfold bex_simps)
hoelzl@38656
   565
      fix i
haftmann@52141
   566
      have *: "(\<Union>(Q' ` {..i})) = ?O i" by auto
hoelzl@47694
   567
      then show "\<exists>x. (x \<in> sets M \<and> N x \<noteq> \<infinity>) \<and>
haftmann@52141
   568
        emeasure M (\<Union>(Q' ` {..i})) \<le> emeasure M x"
hoelzl@38656
   569
        using O_in_G[of i] by (auto intro!: exI[of _ "?O i"])
hoelzl@38656
   570
    qed
hoelzl@38656
   571
  qed
wenzelm@46731
   572
  let ?O_0 = "(\<Union>i. ?O i)"
hoelzl@38656
   573
  have "?O_0 \<in> sets M" using Q' by auto
hoelzl@40859
   574
  def Q \<equiv> "\<lambda>i. case i of 0 \<Rightarrow> Q' 0 | Suc n \<Rightarrow> ?O (Suc n) - ?O n"
hoelzl@38656
   575
  { fix i have "Q i \<in> sets M" unfolding Q_def using Q'[of 0] by (cases i) (auto intro: O_sets) }
hoelzl@38656
   576
  note Q_sets = this
hoelzl@40859
   577
  show ?thesis
hoelzl@40859
   578
  proof (intro bexI exI conjI ballI impI allI)
hoelzl@40859
   579
    show "disjoint_family Q"
nipkow@44890
   580
      by (fastforce simp: disjoint_family_on_def Q_def
hoelzl@40859
   581
        split: nat.split_asm)
hoelzl@40859
   582
    show "range Q \<subseteq> sets M"
hoelzl@40859
   583
      using Q_sets by auto
hoelzl@40859
   584
    { fix A assume A: "A \<in> sets M" "A \<subseteq> space M - ?O_0"
hoelzl@47694
   585
      show "emeasure M A = 0 \<and> N A = 0 \<or> 0 < emeasure M A \<and> N A = \<infinity>"
hoelzl@40859
   586
      proof (rule disjCI, simp)
hoelzl@47694
   587
        assume *: "0 < emeasure M A \<longrightarrow> N A \<noteq> \<infinity>"
hoelzl@47694
   588
        show "emeasure M A = 0 \<and> N A = 0"
wenzelm@53374
   589
        proof (cases "emeasure M A = 0")
wenzelm@53374
   590
          case True
wenzelm@53374
   591
          with ac A have "N A = 0"
hoelzl@40859
   592
            unfolding absolutely_continuous_def by auto
wenzelm@53374
   593
          with True show ?thesis by simp
hoelzl@40859
   594
        next
wenzelm@53374
   595
          case False
wenzelm@53374
   596
          with * have "N A \<noteq> \<infinity>" using emeasure_nonneg[of M A] by auto
hoelzl@47694
   597
          with A have "emeasure M ?O_0 + emeasure M A = emeasure M (?O_0 \<union> A)"
immler@50244
   598
            using Q' by (auto intro!: plus_emeasure sets.countable_UN)
hoelzl@47694
   599
          also have "\<dots> = (SUP i. emeasure M (?O i \<union> A))"
hoelzl@47694
   600
          proof (rule SUP_emeasure_incseq[of "\<lambda>i. ?O i \<union> A", symmetric, simplified])
hoelzl@40859
   601
            show "range (\<lambda>i. ?O i \<union> A) \<subseteq> sets M"
wenzelm@61808
   602
              using \<open>N A \<noteq> \<infinity>\<close> O_sets A by auto
nipkow@44890
   603
          qed (fastforce intro!: incseq_SucI)
hoelzl@40859
   604
          also have "\<dots> \<le> ?a"
hoelzl@44928
   605
          proof (safe intro!: SUP_least)
hoelzl@40859
   606
            fix i have "?O i \<union> A \<in> ?Q"
hoelzl@40859
   607
            proof (safe del: notI)
hoelzl@40859
   608
              show "?O i \<union> A \<in> sets M" using O_sets A by auto
hoelzl@47694
   609
              from O_in_G[of i] have "N (?O i \<union> A) \<le> N (?O i) + N A"
hoelzl@47694
   610
                using emeasure_subadditive[of "?O i" N A] A O_sets by (auto simp: sets_eq)
hoelzl@47694
   611
              with O_in_G[of i] show "N (?O i \<union> A) \<noteq> \<infinity>"
wenzelm@61808
   612
                using \<open>N A \<noteq> \<infinity>\<close> by auto
hoelzl@40859
   613
            qed
hoelzl@47694
   614
            then show "emeasure M (?O i \<union> A) \<le> ?a" by (rule SUP_upper)
hoelzl@40859
   615
          qed
hoelzl@47694
   616
          finally have "emeasure M A = 0"
hoelzl@47694
   617
            unfolding a_eq using measure_nonneg[of M A] by (simp add: emeasure_eq_measure)
wenzelm@61808
   618
          with \<open>emeasure M A \<noteq> 0\<close> show ?thesis by auto
hoelzl@40859
   619
        qed
hoelzl@40859
   620
      qed }
hoelzl@47694
   621
    { fix i show "N (Q i) \<noteq> \<infinity>"
hoelzl@40859
   622
      proof (cases i)
hoelzl@40859
   623
        case 0 then show ?thesis
hoelzl@40859
   624
          unfolding Q_def using Q'[of 0] by simp
hoelzl@40859
   625
      next
hoelzl@40859
   626
        case (Suc n)
wenzelm@61808
   627
        with \<open>?O n \<in> ?Q\<close> \<open>?O (Suc n) \<in> ?Q\<close>
wenzelm@60585
   628
            emeasure_Diff[OF _ _ _ O_mono, of N n] emeasure_nonneg[of N "(\<Union>x\<le>n. Q' x)"]
hoelzl@47694
   629
        show ?thesis
hoelzl@47694
   630
          by (auto simp: sets_eq ereal_minus_eq_PInfty_iff Q_def)
hoelzl@40859
   631
      qed }
hoelzl@40859
   632
    show "space M - ?O_0 \<in> sets M" using Q'_sets by auto
hoelzl@40859
   633
    { fix j have "(\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q i)"
hoelzl@40859
   634
      proof (induct j)
hoelzl@40859
   635
        case 0 then show ?case by (simp add: Q_def)
hoelzl@40859
   636
      next
hoelzl@40859
   637
        case (Suc j)
nipkow@44890
   638
        have eq: "\<And>j. (\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q' i)" by fastforce
hoelzl@40859
   639
        have "{..j} \<union> {..Suc j} = {..Suc j}" by auto
hoelzl@40859
   640
        then have "(\<Union>i\<le>Suc j. Q' i) = (\<Union>i\<le>j. Q' i) \<union> Q (Suc j)"
hoelzl@40859
   641
          by (simp add: UN_Un[symmetric] Q_def del: UN_Un)
hoelzl@40859
   642
        then show ?case using Suc by (auto simp add: eq atMost_Suc)
hoelzl@40859
   643
      qed }
hoelzl@40859
   644
    then have "(\<Union>j. (\<Union>i\<le>j. ?O i)) = (\<Union>j. (\<Union>i\<le>j. Q i))" by simp
nipkow@44890
   645
    then show "space M - ?O_0 = space M - (\<Union>i. Q i)" by fastforce
hoelzl@40859
   646
  qed
hoelzl@40859
   647
qed
hoelzl@40859
   648
hoelzl@40859
   649
lemma (in finite_measure) Radon_Nikodym_finite_measure_infinite:
hoelzl@47694
   650
  assumes "absolutely_continuous M N" and sets_eq: "sets N = sets M"
hoelzl@47694
   651
  shows "\<exists>f\<in>borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@40859
   652
proof -
hoelzl@40859
   653
  from split_space_into_finite_sets_and_rest[OF assms]
hoelzl@40859
   654
  obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
hoelzl@40859
   655
    where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
hoelzl@40859
   656
    and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
hoelzl@47694
   657
    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
   658
    and Q_fin: "\<And>i. N (Q i) \<noteq> \<infinity>" by force
hoelzl@40859
   659
  from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
hoelzl@47694
   660
  let ?N = "\<lambda>i. density N (indicator (Q i))" and ?M = "\<lambda>i. density M (indicator (Q i))"
hoelzl@47694
   661
  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
   662
  proof (intro allI finite_measure.Radon_Nikodym_finite_measure)
hoelzl@38656
   663
    fix i
hoelzl@47694
   664
    from Q show "finite_measure (?M i)"
hoelzl@56996
   665
      by (auto intro!: finite_measureI cong: nn_integral_cong
hoelzl@47694
   666
               simp add: emeasure_density subset_eq sets_eq)
hoelzl@47694
   667
    from Q have "emeasure (?N i) (space N) = emeasure N (Q i)"
hoelzl@56996
   668
      by (simp add: sets_eq[symmetric] emeasure_density subset_eq cong: nn_integral_cong)
hoelzl@47694
   669
    with Q_fin show "finite_measure (?N i)"
hoelzl@47694
   670
      by (auto intro!: finite_measureI)
hoelzl@47694
   671
    show "sets (?N i) = sets (?M i)" by (simp add: sets_eq)
hoelzl@50003
   672
    have [measurable]: "\<And>A. A \<in> sets M \<Longrightarrow> A \<in> sets N" by (simp add: sets_eq)
hoelzl@47694
   673
    show "absolutely_continuous (?M i) (?N i)"
wenzelm@61808
   674
      using \<open>absolutely_continuous M N\<close> \<open>Q i \<in> sets M\<close>
hoelzl@47694
   675
      by (auto simp: absolutely_continuous_def null_sets_density_iff sets_eq
hoelzl@47694
   676
               intro!: absolutely_continuous_AE[OF sets_eq])
hoelzl@38656
   677
  qed
hoelzl@47694
   678
  from choice[OF this[unfolded Bex_def]]
hoelzl@47694
   679
  obtain f where borel: "\<And>i. f i \<in> borel_measurable M" "\<And>i x. 0 \<le> f i x"
hoelzl@47694
   680
    and f_density: "\<And>i. density (?M i) (f i) = ?N i"
immler@54776
   681
    by force
hoelzl@47694
   682
  { fix A i assume A: "A \<in> sets M"
wenzelm@53015
   683
    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@56996
   684
      by (auto simp add: emeasure_density nn_integral_density subset_eq
hoelzl@56996
   685
               intro!: nn_integral_cong split: split_indicator)
hoelzl@47694
   686
    also have "\<dots> = emeasure N (Q i \<inter> A)"
hoelzl@47694
   687
      using A Q by (simp add: f_density emeasure_restricted subset_eq sets_eq)
wenzelm@53015
   688
    finally have "emeasure N (Q i \<inter> A) = (\<integral>\<^sup>+x. f i x * indicator (Q i \<inter> A) x \<partial>M)" .. }
hoelzl@47694
   689
  note integral_eq = this
wenzelm@46731
   690
  let ?f = "\<lambda>x. (\<Sum>i. f i x * indicator (Q i) x) + \<infinity> * indicator Q0 x"
hoelzl@38656
   691
  show ?thesis
hoelzl@38656
   692
  proof (safe intro!: bexI[of _ ?f])
hoelzl@41981
   693
    show "?f \<in> borel_measurable M" using Q0 borel Q_sets
hoelzl@41981
   694
      by (auto intro!: measurable_If)
hoelzl@41981
   695
    show "\<And>x. 0 \<le> ?f x" using borel by (auto intro!: suminf_0_le simp: indicator_def)
hoelzl@47694
   696
    show "density M ?f = N"
hoelzl@47694
   697
    proof (rule measure_eqI)
hoelzl@47694
   698
      fix A assume "A \<in> sets (density M ?f)"
hoelzl@47694
   699
      then have "A \<in> sets M" by simp
hoelzl@47694
   700
      have Qi: "\<And>i. Q i \<in> sets M" using Q by auto
hoelzl@47694
   701
      have [intro,simp]: "\<And>i. (\<lambda>x. f i x * indicator (Q i \<inter> A) x) \<in> borel_measurable M"
hoelzl@47694
   702
        "\<And>i. AE x in M. 0 \<le> f i x * indicator (Q i \<inter> A) x"
wenzelm@61808
   703
        using borel Qi Q0(1) \<open>A \<in> sets M\<close> by (auto intro!: borel_measurable_ereal_times)
wenzelm@53015
   704
      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@56996
   705
        using borel by (intro nn_integral_cong) (auto simp: indicator_def)
wenzelm@53015
   706
      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)"
wenzelm@61808
   707
        using borel Qi Q0(1) \<open>A \<in> sets M\<close>
hoelzl@56996
   708
        by (subst nn_integral_add) (auto simp del: ereal_infty_mult
hoelzl@56996
   709
            simp add: nn_integral_cmult_indicator sets.Int intro!: suminf_0_le)
hoelzl@47694
   710
      also have "\<dots> = (\<Sum>i. N (Q i \<inter> A)) + \<infinity> * emeasure M (Q0 \<inter> A)"
wenzelm@61808
   711
        by (subst integral_eq[OF \<open>A \<in> sets M\<close>], subst nn_integral_suminf) auto
wenzelm@53015
   712
      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
   713
      moreover have "(\<Sum>i. N (Q i \<inter> A)) = N ((\<Union>i. Q i) \<inter> A)"
wenzelm@61808
   714
        using Q Q_sets \<open>A \<in> sets M\<close>
hoelzl@47694
   715
        by (subst suminf_emeasure) (auto simp: disjoint_family_on_def sets_eq)
hoelzl@47694
   716
      moreover have "\<infinity> * emeasure M (Q0 \<inter> A) = N (Q0 \<inter> A)"
hoelzl@47694
   717
      proof -
wenzelm@61808
   718
        have "Q0 \<inter> A \<in> sets M" using Q0(1) \<open>A \<in> sets M\<close> by blast
hoelzl@47694
   719
        from in_Q0[OF this] show ?thesis by auto
hoelzl@47694
   720
      qed
hoelzl@47694
   721
      moreover have "Q0 \<inter> A \<in> sets M" "((\<Union>i. Q i) \<inter> A) \<in> sets M"
wenzelm@61808
   722
        using Q_sets \<open>A \<in> sets M\<close> Q0(1) by auto
hoelzl@47694
   723
      moreover have "((\<Union>i. Q i) \<inter> A) \<union> (Q0 \<inter> A) = A" "((\<Union>i. Q i) \<inter> A) \<inter> (Q0 \<inter> A) = {}"
wenzelm@61808
   724
        using \<open>A \<in> sets M\<close> sets.sets_into_space Q0 by auto
wenzelm@53015
   725
      ultimately have "N A = (\<integral>\<^sup>+x. ?f x * indicator A x \<partial>M)"
hoelzl@47694
   726
        using plus_emeasure[of "(\<Union>i. Q i) \<inter> A" N "Q0 \<inter> A"] by (simp add: sets_eq)
wenzelm@61808
   727
      with \<open>A \<in> sets M\<close> borel Q Q0(1) show "emeasure (density M ?f) A = N A"
hoelzl@50003
   728
        by (auto simp: subset_eq emeasure_density)
hoelzl@47694
   729
    qed (simp add: sets_eq)
hoelzl@38656
   730
  qed
hoelzl@38656
   731
qed
hoelzl@38656
   732
hoelzl@38656
   733
lemma (in sigma_finite_measure) Radon_Nikodym:
hoelzl@47694
   734
  assumes ac: "absolutely_continuous M N" assumes sets_eq: "sets N = sets M"
hoelzl@47694
   735
  shows "\<exists>f \<in> borel_measurable M. (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@38656
   736
proof -
hoelzl@38656
   737
  from Ex_finite_integrable_function
hoelzl@56996
   738
  obtain h where finite: "integral\<^sup>N M h \<noteq> \<infinity>" and
hoelzl@38656
   739
    borel: "h \<in> borel_measurable M" and
hoelzl@41981
   740
    nn: "\<And>x. 0 \<le> h x" and
hoelzl@38656
   741
    pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x" and
hoelzl@41981
   742
    "\<And>x. x \<in> space M \<Longrightarrow> h x < \<infinity>" by auto
wenzelm@53015
   743
  let ?T = "\<lambda>A. (\<integral>\<^sup>+x. h x * indicator A x \<partial>M)"
hoelzl@47694
   744
  let ?MT = "density M h"
hoelzl@47694
   745
  from borel finite nn interpret T: finite_measure ?MT
hoelzl@56996
   746
    by (auto intro!: finite_measureI cong: nn_integral_cong simp: emeasure_density)
hoelzl@47694
   747
  have "absolutely_continuous ?MT N" "sets N = sets ?MT"
hoelzl@47694
   748
  proof (unfold absolutely_continuous_def, safe)
hoelzl@47694
   749
    fix A assume "A \<in> null_sets ?MT"
hoelzl@47694
   750
    with borel have "A \<in> sets M" "AE x in M. x \<in> A \<longrightarrow> h x \<le> 0"
hoelzl@47694
   751
      by (auto simp add: null_sets_density_iff)
immler@50244
   752
    with pos sets.sets_into_space have "AE x in M. x \<notin> A"
lp15@61810
   753
      by (elim eventually_mono) (auto simp: not_le[symmetric])
hoelzl@47694
   754
    then have "A \<in> null_sets M"
wenzelm@61808
   755
      using \<open>A \<in> sets M\<close> by (simp add: AE_iff_null_sets)
hoelzl@47694
   756
    with ac show "A \<in> null_sets N"
hoelzl@47694
   757
      by (auto simp: absolutely_continuous_def)
hoelzl@47694
   758
  qed (auto simp add: sets_eq)
hoelzl@47694
   759
  from T.Radon_Nikodym_finite_measure_infinite[OF this]
hoelzl@47694
   760
  obtain f where f_borel: "f \<in> borel_measurable M" "\<And>x. 0 \<le> f x" "density ?MT f = N" by auto
hoelzl@47694
   761
  with nn borel show ?thesis
hoelzl@47694
   762
    by (auto intro!: bexI[of _ "\<lambda>x. h x * f x"] simp: density_density_eq)
hoelzl@38656
   763
qed
hoelzl@38656
   764
wenzelm@61808
   765
subsection \<open>Uniqueness of densities\<close>
hoelzl@40859
   766
hoelzl@47694
   767
lemma finite_density_unique:
hoelzl@40859
   768
  assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@47694
   769
  assumes pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> g x"
hoelzl@56996
   770
  and fin: "integral\<^sup>N M f \<noteq> \<infinity>"
hoelzl@49785
   771
  shows "density M f = density M g \<longleftrightarrow> (AE x in M. f x = g x)"
hoelzl@40859
   772
proof (intro iffI ballI)
hoelzl@47694
   773
  fix A assume eq: "AE x in M. f x = g x"
hoelzl@49785
   774
  with borel show "density M f = density M g"
hoelzl@49785
   775
    by (auto intro: density_cong)
hoelzl@40859
   776
next
wenzelm@53015
   777
  let ?P = "\<lambda>f A. \<integral>\<^sup>+ x. f x * indicator A x \<partial>M"
hoelzl@49785
   778
  assume "density M f = density M g"
hoelzl@49785
   779
  with borel have eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
hoelzl@49785
   780
    by (simp add: emeasure_density[symmetric])
immler@50244
   781
  from this[THEN bspec, OF sets.top] fin
hoelzl@56996
   782
  have g_fin: "integral\<^sup>N M g \<noteq> \<infinity>" by (simp cong: nn_integral_cong)
hoelzl@40859
   783
  { fix f g assume borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@47694
   784
      and pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> g x"
hoelzl@56996
   785
      and g_fin: "integral\<^sup>N M g \<noteq> \<infinity>" and eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
hoelzl@40859
   786
    let ?N = "{x\<in>space M. g x < f x}"
hoelzl@40859
   787
    have N: "?N \<in> sets M" using borel by simp
hoelzl@56996
   788
    have "?P g ?N \<le> integral\<^sup>N M g" using pos
hoelzl@56996
   789
      by (intro nn_integral_mono_AE) (auto split: split_indicator)
hoelzl@41981
   790
    then have Pg_fin: "?P g ?N \<noteq> \<infinity>" using g_fin by auto
wenzelm@53015
   791
    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@56996
   792
      by (auto intro!: nn_integral_cong simp: indicator_def)
hoelzl@40859
   793
    also have "\<dots> = ?P f ?N - ?P g ?N"
hoelzl@56996
   794
    proof (rule nn_integral_diff)
hoelzl@40859
   795
      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
   796
        using borel N by auto
hoelzl@47694
   797
      show "AE x in M. g x * indicator ?N x \<le> f x * indicator ?N x"
hoelzl@47694
   798
           "AE x in M. 0 \<le> g x * indicator ?N x"
hoelzl@41981
   799
        using pos by (auto split: split_indicator)
hoelzl@41981
   800
    qed fact
hoelzl@40859
   801
    also have "\<dots> = 0"
hoelzl@56996
   802
      unfolding eq[THEN bspec, OF N] using nn_integral_nonneg[of M] Pg_fin by auto
hoelzl@47694
   803
    finally have "AE x in M. f x \<le> g x"
hoelzl@56996
   804
      using pos borel nn_integral_PInf_AE[OF borel(2) g_fin]
hoelzl@56996
   805
      by (subst (asm) nn_integral_0_iff_AE)
hoelzl@43920
   806
         (auto split: split_indicator simp: not_less ereal_minus_le_iff) }
hoelzl@41981
   807
  from this[OF borel pos g_fin eq] this[OF borel(2,1) pos(2,1) fin] eq
hoelzl@47694
   808
  show "AE x in M. f x = g x" by auto
hoelzl@40859
   809
qed
hoelzl@40859
   810
hoelzl@40859
   811
lemma (in finite_measure) density_unique_finite_measure:
hoelzl@40859
   812
  assumes borel: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
hoelzl@47694
   813
  assumes pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> f' x"
wenzelm@53015
   814
  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
   815
    (is "\<And>A. A \<in> sets M \<Longrightarrow> ?P f A = ?P f' A")
hoelzl@47694
   816
  shows "AE x in M. f x = f' x"
hoelzl@40859
   817
proof -
hoelzl@47694
   818
  let ?D = "\<lambda>f. density M f"
hoelzl@47694
   819
  let ?N = "\<lambda>A. ?P f A" and ?N' = "\<lambda>A. ?P f' A"
wenzelm@46731
   820
  let ?f = "\<lambda>A x. f x * indicator A x" and ?f' = "\<lambda>A x. f' x * indicator A x"
hoelzl@47694
   821
hoelzl@47694
   822
  have ac: "absolutely_continuous M (density M f)" "sets (density M f) = sets M"
lp15@61609
   823
    using borel by (auto intro!: absolutely_continuousI_density)
hoelzl@47694
   824
  from split_space_into_finite_sets_and_rest[OF this]
hoelzl@40859
   825
  obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
hoelzl@40859
   826
    where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
hoelzl@40859
   827
    and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
hoelzl@47694
   828
    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
   829
    and Q_fin: "\<And>i. ?D f (Q i) \<noteq> \<infinity>" by force
hoelzl@47694
   830
  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
   831
    and Q_fin: "\<And>i. ?N (Q i) \<noteq> \<infinity>" by (auto simp: emeasure_density subset_eq)
hoelzl@47694
   832
hoelzl@40859
   833
  from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
hoelzl@47694
   834
  let ?D = "{x\<in>space M. f x \<noteq> f' x}"
hoelzl@47694
   835
  have "?D \<in> sets M" using borel by auto
hoelzl@43920
   836
  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
   837
    unfolding indicator_def by auto
hoelzl@47694
   838
  have "\<forall>i. AE x in M. ?f (Q i) x = ?f' (Q i) x" using borel Q_fin Q pos
hoelzl@40859
   839
    by (intro finite_density_unique[THEN iffD1] allI)
hoelzl@50003
   840
       (auto intro!: f measure_eqI simp: emeasure_density * subset_eq)
hoelzl@47694
   841
  moreover have "AE x in M. ?f Q0 x = ?f' Q0 x"
hoelzl@40859
   842
  proof (rule AE_I')
hoelzl@43920
   843
    { fix f :: "'a \<Rightarrow> ereal" assume borel: "f \<in> borel_measurable M"
wenzelm@53015
   844
        and eq: "\<And>A. A \<in> sets M \<Longrightarrow> ?N A = (\<integral>\<^sup>+x. f x * indicator A x \<partial>M)"
wenzelm@46731
   845
      let ?A = "\<lambda>i. Q0 \<inter> {x \<in> space M. f x < (i::nat)}"
hoelzl@47694
   846
      have "(\<Union>i. ?A i) \<in> null_sets M"
hoelzl@40859
   847
      proof (rule null_sets_UN)
hoelzl@43923
   848
        fix i ::nat have "?A i \<in> sets M"
hoelzl@40859
   849
          using borel Q0(1) by auto
wenzelm@53015
   850
        have "?N (?A i) \<le> (\<integral>\<^sup>+x. (i::ereal) * indicator (?A i) x \<partial>M)"
wenzelm@61808
   851
          unfolding eq[OF \<open>?A i \<in> sets M\<close>]
hoelzl@56996
   852
          by (auto intro!: nn_integral_mono simp: indicator_def)
hoelzl@47694
   853
        also have "\<dots> = i * emeasure M (?A i)"
wenzelm@61808
   854
          using \<open>?A i \<in> sets M\<close> by (auto intro!: nn_integral_cmult_indicator)
hoelzl@47694
   855
        also have "\<dots> < \<infinity>" using emeasure_real[of "?A i"] by simp
hoelzl@47694
   856
        finally have "?N (?A i) \<noteq> \<infinity>" by simp
wenzelm@61808
   857
        then show "?A i \<in> null_sets M" using in_Q0[OF \<open>?A i \<in> sets M\<close>] \<open>?A i \<in> sets M\<close> by auto
hoelzl@40859
   858
      qed
hoelzl@41981
   859
      also have "(\<Union>i. ?A i) = Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>}"
lp15@61609
   860
        by (auto simp: less_PInf_Ex_of_nat)
hoelzl@47694
   861
      finally have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<infinity>} \<in> null_sets M" by simp }
hoelzl@40859
   862
    from this[OF borel(1) refl] this[OF borel(2) f]
hoelzl@47694
   863
    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
   864
    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
   865
    show "{x \<in> space M. ?f Q0 x \<noteq> ?f' Q0 x} \<subseteq>
hoelzl@41981
   866
      (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
   867
  qed
hoelzl@47694
   868
  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
   869
    ?f (space M) x = ?f' (space M) x"
hoelzl@40859
   870
    by (auto simp: indicator_def Q0)
hoelzl@47694
   871
  ultimately have "AE x in M. ?f (space M) x = ?f' (space M) x"
hoelzl@47694
   872
    unfolding AE_all_countable[symmetric]
hoelzl@47694
   873
    by eventually_elim (auto intro!: AE_I2 split: split_if_asm simp: indicator_def)
hoelzl@47694
   874
  then show "AE x in M. f x = f' x" by auto
hoelzl@40859
   875
qed
hoelzl@40859
   876
hoelzl@40859
   877
lemma (in sigma_finite_measure) density_unique:
hoelzl@47694
   878
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
   879
  assumes f': "f' \<in> borel_measurable M" "AE x in M. 0 \<le> f' x"
hoelzl@47694
   880
  assumes density_eq: "density M f = density M f'"
hoelzl@47694
   881
  shows "AE x in M. f x = f' x"
hoelzl@40859
   882
proof -
hoelzl@40859
   883
  obtain h where h_borel: "h \<in> borel_measurable M"
hoelzl@56996
   884
    and fin: "integral\<^sup>N 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
   885
    using Ex_finite_integrable_function by auto
hoelzl@47694
   886
  then have h_nn: "AE x in M. 0 \<le> h x" by auto
hoelzl@47694
   887
  let ?H = "density M h"
hoelzl@47694
   888
  interpret h: finite_measure ?H
hoelzl@47694
   889
    using fin h_borel pos
hoelzl@56996
   890
    by (intro finite_measureI) (simp cong: nn_integral_cong emeasure_density add: fin)
hoelzl@47694
   891
  let ?fM = "density M f"
hoelzl@47694
   892
  let ?f'M = "density M f'"
hoelzl@40859
   893
  { fix A assume "A \<in> sets M"
hoelzl@41981
   894
    then have "{x \<in> space M. h x * indicator A x \<noteq> 0} = A"
immler@50244
   895
      using pos(1) sets.sets_into_space by (force simp: indicator_def)
wenzelm@53015
   896
    then have "(\<integral>\<^sup>+x. h x * indicator A x \<partial>M) = 0 \<longleftrightarrow> A \<in> null_sets M"
wenzelm@61808
   897
      using h_borel \<open>A \<in> sets M\<close> h_nn by (subst nn_integral_0_iff) auto }
hoelzl@40859
   898
  note h_null_sets = this
hoelzl@40859
   899
  { fix A assume "A \<in> sets M"
wenzelm@53015
   900
    have "(\<integral>\<^sup>+x. f x * (h x * indicator A x) \<partial>M) = (\<integral>\<^sup>+x. h x * indicator A x \<partial>?fM)"
wenzelm@61808
   901
      using \<open>A \<in> sets M\<close> h_borel h_nn f f'
hoelzl@56996
   902
      by (intro nn_integral_density[symmetric]) auto
wenzelm@53015
   903
    also have "\<dots> = (\<integral>\<^sup>+x. h x * indicator A x \<partial>?f'M)"
hoelzl@47694
   904
      by (simp_all add: density_eq)
wenzelm@53015
   905
    also have "\<dots> = (\<integral>\<^sup>+x. f' x * (h x * indicator A x) \<partial>M)"
wenzelm@61808
   906
      using \<open>A \<in> sets M\<close> h_borel h_nn f f'
hoelzl@56996
   907
      by (intro nn_integral_density) auto
wenzelm@53015
   908
    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
   909
      by (simp add: ac_simps)
wenzelm@53015
   910
    then have "(\<integral>\<^sup>+x. (f x * indicator A x) \<partial>?H) = (\<integral>\<^sup>+x. (f' x * indicator A x) \<partial>?H)"
wenzelm@61808
   911
      using \<open>A \<in> sets M\<close> h_borel h_nn f f'
hoelzl@56996
   912
      by (subst (asm) (1 2) nn_integral_density[symmetric]) auto }
hoelzl@41981
   913
  then have "AE x in ?H. f x = f' x" using h_borel h_nn f f'
hoelzl@47694
   914
    by (intro h.density_unique_finite_measure absolutely_continuous_AE[of M])
hoelzl@47694
   915
       (auto simp add: AE_density)
hoelzl@47694
   916
  then show "AE x in M. f x = f' x"
hoelzl@47694
   917
    unfolding eventually_ae_filter using h_borel pos
hoelzl@47694
   918
    by (auto simp add: h_null_sets null_sets_density_iff not_less[symmetric]
hoelzl@50021
   919
                          AE_iff_null_sets[symmetric]) blast
hoelzl@40859
   920
qed
hoelzl@40859
   921
hoelzl@47694
   922
lemma (in sigma_finite_measure) density_unique_iff:
hoelzl@47694
   923
  assumes f: "f \<in> borel_measurable M" and "AE x in M. 0 \<le> f x"
hoelzl@47694
   924
  assumes f': "f' \<in> borel_measurable M" and "AE x in M. 0 \<le> f' x"
hoelzl@47694
   925
  shows "density M f = density M f' \<longleftrightarrow> (AE x in M. f x = f' x)"
hoelzl@47694
   926
  using density_unique[OF assms] density_cong[OF f f'] by auto
hoelzl@47694
   927
hoelzl@49785
   928
lemma sigma_finite_density_unique:
hoelzl@49785
   929
  assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@49785
   930
  assumes pos: "AE x in M. 0 \<le> f x" "AE x in M. 0 \<le> g x"
hoelzl@49785
   931
  and fin: "sigma_finite_measure (density M f)"
hoelzl@49785
   932
  shows "density M f = density M g \<longleftrightarrow> (AE x in M. f x = g x)"
hoelzl@49785
   933
proof
lp15@61609
   934
  assume "AE x in M. f x = g x" with borel show "density M f = density M g"
hoelzl@49785
   935
    by (auto intro: density_cong)
hoelzl@49785
   936
next
hoelzl@49785
   937
  assume eq: "density M f = density M g"
wenzelm@61605
   938
  interpret f: sigma_finite_measure "density M f" by fact
hoelzl@49785
   939
  from f.sigma_finite_incseq guess A . note cover = this
hoelzl@49785
   940
hoelzl@49785
   941
  have "AE x in M. \<forall>i. x \<in> A i \<longrightarrow> f x = g x"
hoelzl@49785
   942
    unfolding AE_all_countable
hoelzl@49785
   943
  proof
hoelzl@49785
   944
    fix i
hoelzl@49785
   945
    have "density (density M f) (indicator (A i)) = density (density M g) (indicator (A i))"
hoelzl@49785
   946
      unfolding eq ..
wenzelm@53015
   947
    moreover have "(\<integral>\<^sup>+x. f x * indicator (A i) x \<partial>M) \<noteq> \<infinity>"
hoelzl@49785
   948
      using cover(1) cover(3)[of i] borel by (auto simp: emeasure_density subset_eq)
hoelzl@49785
   949
    ultimately have "AE x in M. f x * indicator (A i) x = g x * indicator (A i) x"
hoelzl@49785
   950
      using borel pos cover(1) pos
hoelzl@49785
   951
      by (intro finite_density_unique[THEN iffD1])
hoelzl@49785
   952
         (auto simp: density_density_eq subset_eq)
hoelzl@49785
   953
    then show "AE x in M. x \<in> A i \<longrightarrow> f x = g x"
hoelzl@49785
   954
      by auto
hoelzl@49785
   955
  qed
hoelzl@49785
   956
  with AE_space show "AE x in M. f x = g x"
hoelzl@49785
   957
    apply eventually_elim
hoelzl@49785
   958
    using cover(2)[symmetric]
hoelzl@49785
   959
    apply auto
hoelzl@49785
   960
    done
hoelzl@49785
   961
qed
hoelzl@49785
   962
hoelzl@49778
   963
lemma (in sigma_finite_measure) sigma_finite_iff_density_finite':
hoelzl@47694
   964
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
   965
  shows "sigma_finite_measure (density M f) \<longleftrightarrow> (AE x in M. f x \<noteq> \<infinity>)"
hoelzl@47694
   966
    (is "sigma_finite_measure ?N \<longleftrightarrow> _")
hoelzl@40859
   967
proof
hoelzl@41689
   968
  assume "sigma_finite_measure ?N"
hoelzl@47694
   969
  then interpret N: sigma_finite_measure ?N .
hoelzl@47694
   970
  from N.Ex_finite_integrable_function obtain h where
hoelzl@56996
   971
    h: "h \<in> borel_measurable M" "integral\<^sup>N ?N h \<noteq> \<infinity>" and
hoelzl@41981
   972
    h_nn: "\<And>x. 0 \<le> h x" and
hoelzl@41981
   973
    fin: "\<forall>x\<in>space M. 0 < h x \<and> h x < \<infinity>" by auto
hoelzl@47694
   974
  have "AE x in M. f x * h x \<noteq> \<infinity>"
hoelzl@40859
   975
  proof (rule AE_I')
hoelzl@56996
   976
    have "integral\<^sup>N ?N h = (\<integral>\<^sup>+x. f x * h x \<partial>M)" using f h h_nn
hoelzl@56996
   977
      by (auto intro!: nn_integral_density)
wenzelm@53015
   978
    then have "(\<integral>\<^sup>+x. f x * h x \<partial>M) \<noteq> \<infinity>"
hoelzl@40859
   979
      using h(2) by simp
hoelzl@47694
   980
    then show "(\<lambda>x. f x * h x) -` {\<infinity>} \<inter> space M \<in> null_sets M"
hoelzl@56996
   981
      using f h(1) by (auto intro!: nn_integral_PInf borel_measurable_vimage)
hoelzl@40859
   982
  qed auto
hoelzl@47694
   983
  then show "AE x in M. f x \<noteq> \<infinity>"
hoelzl@41705
   984
    using fin by (auto elim!: AE_Ball_mp)
hoelzl@40859
   985
next
hoelzl@47694
   986
  assume AE: "AE x in M. f x \<noteq> \<infinity>"
hoelzl@57447
   987
  from sigma_finite guess Q . note Q = this
hoelzl@43923
   988
  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
   989
  { fix i j have "A i \<inter> Q j \<in> sets M"
hoelzl@40859
   990
    unfolding A_def using f Q
immler@50244
   991
    apply (rule_tac sets.Int)
hoelzl@41981
   992
    by (cases i) (auto intro: measurable_sets[OF f(1)]) }
hoelzl@40859
   993
  note A_in_sets = this
hoelzl@57447
   994
hoelzl@41689
   995
  show "sigma_finite_measure ?N"
wenzelm@61169
   996
  proof (standard, intro exI conjI ballI)
hoelzl@57447
   997
    show "countable (range (\<lambda>(i, j). A i \<inter> Q j))"
hoelzl@57447
   998
      by auto
hoelzl@57447
   999
    show "range (\<lambda>(i, j). A i \<inter> Q j) \<subseteq> sets (density M f)"
hoelzl@57447
  1000
      using A_in_sets by auto
hoelzl@40859
  1001
  next
hoelzl@57447
  1002
    have "\<Union>range (\<lambda>(i, j). A i \<inter> Q j) = (\<Union>i j. A i \<inter> Q j)"
hoelzl@57447
  1003
      by auto
hoelzl@40859
  1004
    also have "\<dots> = (\<Union>i. A i) \<inter> space M" using Q by auto
hoelzl@40859
  1005
    also have "(\<Union>i. A i) = space M"
hoelzl@40859
  1006
    proof safe
hoelzl@40859
  1007
      fix x assume x: "x \<in> space M"
hoelzl@40859
  1008
      show "x \<in> (\<Union>i. A i)"
hoelzl@40859
  1009
      proof (cases "f x")
hoelzl@41981
  1010
        case PInf with x show ?thesis unfolding A_def by (auto intro: exI[of _ 0])
hoelzl@40859
  1011
      next
hoelzl@41981
  1012
        case (real r)
lp15@61609
  1013
        with less_PInf_Ex_of_nat[of "f x"] obtain n :: nat where "f x < n" by auto
lp15@61609
  1014
        then show ?thesis using x real unfolding A_def by (auto intro!: exI[of _ "Suc n"])
hoelzl@41981
  1015
      next
hoelzl@41981
  1016
        case MInf with x show ?thesis
hoelzl@41981
  1017
          unfolding A_def by (auto intro!: exI[of _ "Suc 0"])
hoelzl@40859
  1018
      qed
hoelzl@40859
  1019
    qed (auto simp: A_def)
hoelzl@57447
  1020
    finally show "\<Union>range (\<lambda>(i, j). A i \<inter> Q j) = space ?N" by simp
hoelzl@40859
  1021
  next
hoelzl@57447
  1022
    fix X assume "X \<in> range (\<lambda>(i, j). A i \<inter> Q j)"
hoelzl@57447
  1023
    then obtain i j where [simp]:"X = A i \<inter> Q j" by auto
wenzelm@53015
  1024
    have "(\<integral>\<^sup>+x. f x * indicator (A i \<inter> Q j) x \<partial>M) \<noteq> \<infinity>"
hoelzl@40859
  1025
    proof (cases i)
hoelzl@40859
  1026
      case 0
hoelzl@47694
  1027
      have "AE x in M. f x * indicator (A i \<inter> Q j) x = 0"
wenzelm@61808
  1028
        using AE by (auto simp: A_def \<open>i = 0\<close>)
hoelzl@56996
  1029
      from nn_integral_cong_AE[OF this] show ?thesis by simp
hoelzl@40859
  1030
    next
hoelzl@40859
  1031
      case (Suc n)
wenzelm@53015
  1032
      then have "(\<integral>\<^sup>+x. f x * indicator (A i \<inter> Q j) x \<partial>M) \<le>
wenzelm@53015
  1033
        (\<integral>\<^sup>+x. (Suc n :: ereal) * indicator (Q j) x \<partial>M)"
lp15@61609
  1034
        by (auto intro!: nn_integral_mono simp: indicator_def A_def)
hoelzl@47694
  1035
      also have "\<dots> = Suc n * emeasure M (Q j)"
hoelzl@56996
  1036
        using Q by (auto intro!: nn_integral_cmult_indicator)
hoelzl@41981
  1037
      also have "\<dots> < \<infinity>"
lp15@61609
  1038
        using Q by auto
hoelzl@40859
  1039
      finally show ?thesis by simp
hoelzl@40859
  1040
    qed
hoelzl@57447
  1041
    then show "emeasure ?N X \<noteq> \<infinity>"
hoelzl@47694
  1042
      using A_in_sets Q f by (auto simp: emeasure_density)
hoelzl@40859
  1043
  qed
hoelzl@40859
  1044
qed
hoelzl@40859
  1045
hoelzl@49778
  1046
lemma (in sigma_finite_measure) sigma_finite_iff_density_finite:
hoelzl@49778
  1047
  "f \<in> borel_measurable M \<Longrightarrow> sigma_finite_measure (density M f) \<longleftrightarrow> (AE x in M. f x \<noteq> \<infinity>)"
hoelzl@49778
  1048
  apply (subst density_max_0)
hoelzl@49778
  1049
  apply (subst sigma_finite_iff_density_finite')
hoelzl@49778
  1050
  apply (auto simp: max_def intro!: measurable_If)
hoelzl@49778
  1051
  done
hoelzl@49778
  1052
wenzelm@61808
  1053
subsection \<open>Radon-Nikodym derivative\<close>
hoelzl@38656
  1054
hoelzl@56993
  1055
definition RN_deriv :: "'a measure \<Rightarrow> 'a measure \<Rightarrow> 'a \<Rightarrow> ereal" where
hoelzl@56993
  1056
  "RN_deriv M N =
hoelzl@56993
  1057
    (if \<exists>f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N
hoelzl@56993
  1058
       then SOME f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N
hoelzl@56993
  1059
       else (\<lambda>_. 0))"
hoelzl@38656
  1060
lp15@61609
  1061
lemma RN_derivI:
hoelzl@56993
  1062
  assumes "f \<in> borel_measurable M" "\<And>x. 0 \<le> f x" "density M f = N"
hoelzl@56993
  1063
  shows "density M (RN_deriv M N) = N"
hoelzl@40859
  1064
proof -
hoelzl@56993
  1065
  have "\<exists>f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@56993
  1066
    using assms by auto
hoelzl@56993
  1067
  moreover then have "density M (SOME f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N) = N"
hoelzl@56993
  1068
    by (rule someI2_ex) auto
hoelzl@56993
  1069
  ultimately show ?thesis
hoelzl@56993
  1070
    by (auto simp: RN_deriv_def)
hoelzl@40859
  1071
qed
hoelzl@40859
  1072
lp15@61609
  1073
lemma
hoelzl@56993
  1074
  shows borel_measurable_RN_deriv[measurable]: "RN_deriv M N \<in> borel_measurable M" (is ?m)
hoelzl@56993
  1075
    and RN_deriv_nonneg: "0 \<le> RN_deriv M N x" (is ?nn)
hoelzl@38656
  1076
proof -
hoelzl@56993
  1077
  { assume ex: "\<exists>f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N"
hoelzl@56993
  1078
    have 1: "(SOME f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N) \<in> borel_measurable M"
hoelzl@56993
  1079
      using ex by (rule someI2_ex) auto
hoelzl@56993
  1080
    moreover
hoelzl@56993
  1081
    have 2: "0 \<le> (SOME f. f \<in> borel_measurable M \<and> (\<forall>x. 0 \<le> f x) \<and> density M f = N) x"
hoelzl@56993
  1082
      using ex by (rule someI2_ex) auto
hoelzl@56993
  1083
    note 1 2 }
hoelzl@56993
  1084
  from this show ?m ?nn
hoelzl@56993
  1085
    by (auto simp: RN_deriv_def)
hoelzl@38656
  1086
qed
hoelzl@38656
  1087
hoelzl@56993
  1088
lemma density_RN_deriv_density:
hoelzl@56993
  1089
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@56993
  1090
  shows "density M (RN_deriv M (density M f)) = density M f"
hoelzl@56993
  1091
proof (rule RN_derivI)
hoelzl@56993
  1092
  show "(\<lambda>x. max 0 (f x)) \<in> borel_measurable M" "\<And>x. 0 \<le> max 0 (f x)"
hoelzl@56993
  1093
    using f by auto
hoelzl@56993
  1094
  show "density M (\<lambda>x. max 0 (f x)) = density M f"
hoelzl@56993
  1095
    using f by (intro density_cong) (auto simp: max_def)
hoelzl@56993
  1096
qed
hoelzl@56993
  1097
hoelzl@56993
  1098
lemma (in sigma_finite_measure) density_RN_deriv:
hoelzl@56993
  1099
  "absolutely_continuous M N \<Longrightarrow> sets N = sets M \<Longrightarrow> density M (RN_deriv M N) = N"
hoelzl@56993
  1100
  by (metis RN_derivI Radon_Nikodym)
hoelzl@56993
  1101
hoelzl@56996
  1102
lemma (in sigma_finite_measure) RN_deriv_nn_integral:
hoelzl@47694
  1103
  assumes N: "absolutely_continuous M N" "sets N = sets M"
hoelzl@40859
  1104
    and f: "f \<in> borel_measurable M"
hoelzl@56996
  1105
  shows "integral\<^sup>N N f = (\<integral>\<^sup>+x. RN_deriv M N x * f x \<partial>M)"
hoelzl@40859
  1106
proof -
hoelzl@56996
  1107
  have "integral\<^sup>N N f = integral\<^sup>N (density M (RN_deriv M N)) f"
hoelzl@47694
  1108
    using N by (simp add: density_RN_deriv)
wenzelm@53015
  1109
  also have "\<dots> = (\<integral>\<^sup>+x. RN_deriv M N x * f x \<partial>M)"
hoelzl@56996
  1110
    using f by (simp add: nn_integral_density RN_deriv_nonneg)
hoelzl@47694
  1111
  finally show ?thesis by simp
hoelzl@40859
  1112
qed
hoelzl@40859
  1113
hoelzl@47694
  1114
lemma null_setsD_AE: "N \<in> null_sets M \<Longrightarrow> AE x in M. x \<notin> N"
hoelzl@47694
  1115
  using AE_iff_null_sets[of N M] by auto
hoelzl@47694
  1116
hoelzl@47694
  1117
lemma (in sigma_finite_measure) RN_deriv_unique:
hoelzl@47694
  1118
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
  1119
  and eq: "density M f = N"
hoelzl@47694
  1120
  shows "AE x in M. f x = RN_deriv M N x"
hoelzl@49785
  1121
  unfolding eq[symmetric]
hoelzl@56993
  1122
  by (intro density_unique_iff[THEN iffD1] f borel_measurable_RN_deriv
hoelzl@56993
  1123
            RN_deriv_nonneg[THEN AE_I2] density_RN_deriv_density[symmetric])
hoelzl@49785
  1124
hoelzl@49785
  1125
lemma RN_deriv_unique_sigma_finite:
hoelzl@49785
  1126
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@49785
  1127
  and eq: "density M f = N" and fin: "sigma_finite_measure N"
hoelzl@49785
  1128
  shows "AE x in M. f x = RN_deriv M N x"
hoelzl@49785
  1129
  using fin unfolding eq[symmetric]
hoelzl@56993
  1130
  by (intro sigma_finite_density_unique[THEN iffD1] f borel_measurable_RN_deriv
hoelzl@56993
  1131
            RN_deriv_nonneg[THEN AE_I2] density_RN_deriv_density[symmetric])
hoelzl@47694
  1132
hoelzl@47694
  1133
lemma (in sigma_finite_measure) RN_deriv_distr:
hoelzl@47694
  1134
  fixes T :: "'a \<Rightarrow> 'b"
hoelzl@47694
  1135
  assumes T: "T \<in> measurable M M'" and T': "T' \<in> measurable M' M"
hoelzl@47694
  1136
    and inv: "\<forall>x\<in>space M. T' (T x) = x"
hoelzl@50021
  1137
  and ac[simp]: "absolutely_continuous (distr M M' T) (distr N M' T)"
hoelzl@47694
  1138
  and N: "sets N = sets M"
hoelzl@47694
  1139
  shows "AE x in M. RN_deriv (distr M M' T) (distr N M' T) (T x) = RN_deriv M N x"
hoelzl@41832
  1140
proof (rule RN_deriv_unique)
hoelzl@47694
  1141
  have [simp]: "sets N = sets M" by fact
hoelzl@47694
  1142
  note sets_eq_imp_space_eq[OF N, simp]
hoelzl@47694
  1143
  have measurable_N[simp]: "\<And>M'. measurable N M' = measurable M M'" by (auto simp: measurable_def)
hoelzl@47694
  1144
  { fix A assume "A \<in> sets M"
immler@50244
  1145
    with inv T T' sets.sets_into_space[OF this]
hoelzl@47694
  1146
    have "T -` T' -` A \<inter> T -` space M' \<inter> space M = A"
hoelzl@47694
  1147
      by (auto simp: measurable_def) }
hoelzl@47694
  1148
  note eq = this[simp]
hoelzl@47694
  1149
  { fix A assume "A \<in> sets M"
immler@50244
  1150
    with inv T T' sets.sets_into_space[OF this]
hoelzl@47694
  1151
    have "(T' \<circ> T) -` A \<inter> space M = A"
hoelzl@47694
  1152
      by (auto simp: measurable_def) }
hoelzl@47694
  1153
  note eq2 = this[simp]
hoelzl@47694
  1154
  let ?M' = "distr M M' T" and ?N' = "distr N M' T"
hoelzl@47694
  1155
  interpret M': sigma_finite_measure ?M'
hoelzl@41832
  1156
  proof
hoelzl@57447
  1157
    from sigma_finite_countable guess F .. note F = this
hoelzl@57447
  1158
    show "\<exists>A. countable A \<and> A \<subseteq> sets (distr M M' T) \<and> \<Union>A = space (distr M M' T) \<and> (\<forall>a\<in>A. emeasure (distr M M' T) a \<noteq> \<infinity>)"
hoelzl@57447
  1159
    proof (intro exI conjI ballI)
hoelzl@57447
  1160
      show *: "(\<lambda>A. T' -` A \<inter> space ?M') ` F \<subseteq> sets ?M'"
hoelzl@47694
  1161
        using F T' by (auto simp: measurable_def)
hoelzl@57447
  1162
      show "\<Union>((\<lambda>A. T' -` A \<inter> space ?M')`F) = space ?M'"
hoelzl@57447
  1163
        using F T'[THEN measurable_space] by (auto simp: set_eq_iff)
hoelzl@57447
  1164
    next
hoelzl@57447
  1165
      fix X assume "X \<in> (\<lambda>A. T' -` A \<inter> space ?M')`F"
hoelzl@57447
  1166
      then obtain A where [simp]: "X = T' -` A \<inter> space ?M'" and "A \<in> F" by auto
wenzelm@61808
  1167
      have "X \<in> sets M'" using F T' \<open>A\<in>F\<close> by auto
hoelzl@41832
  1168
      moreover
wenzelm@61808
  1169
      have Fi: "A \<in> sets M" using F \<open>A\<in>F\<close> by auto
hoelzl@57447
  1170
      ultimately show "emeasure ?M' X \<noteq> \<infinity>"
wenzelm@61808
  1171
        using F T T' \<open>A\<in>F\<close> by (simp add: emeasure_distr)
hoelzl@57447
  1172
    qed (insert F, auto)
hoelzl@41832
  1173
  qed
hoelzl@47694
  1174
  have "(RN_deriv ?M' ?N') \<circ> T \<in> borel_measurable M"
hoelzl@50021
  1175
    using T ac by measurable
hoelzl@47694
  1176
  then show "(\<lambda>x. RN_deriv ?M' ?N' (T x)) \<in> borel_measurable M"
hoelzl@41832
  1177
    by (simp add: comp_def)
hoelzl@56993
  1178
  show "AE x in M. 0 \<le> RN_deriv ?M' ?N' (T x)" by (auto intro: RN_deriv_nonneg)
hoelzl@47694
  1179
hoelzl@47694
  1180
  have "N = distr N M (T' \<circ> T)"
hoelzl@47694
  1181
    by (subst measure_of_of_measure[of N, symmetric])
immler@50244
  1182
       (auto simp add: distr_def sets.sigma_sets_eq intro!: measure_of_eq sets.space_closed)
hoelzl@47694
  1183
  also have "\<dots> = distr (distr N M' T) M T'"
hoelzl@47694
  1184
    using T T' by (simp add: distr_distr)
hoelzl@47694
  1185
  also have "\<dots> = distr (density (distr M M' T) (RN_deriv (distr M M' T) (distr N M' T))) M T'"
hoelzl@47694
  1186
    using ac by (simp add: M'.density_RN_deriv)
hoelzl@47694
  1187
  also have "\<dots> = density M (RN_deriv (distr M M' T) (distr N M' T) \<circ> T)"
hoelzl@56993
  1188
    by (simp add: distr_density_distr[OF T T', OF inv])
hoelzl@47694
  1189
  finally show "density M (\<lambda>x. RN_deriv (distr M M' T) (distr N M' T) (T x)) = N"
hoelzl@47694
  1190
    by (simp add: comp_def)
hoelzl@41832
  1191
qed
hoelzl@41832
  1192
hoelzl@40859
  1193
lemma (in sigma_finite_measure) RN_deriv_finite:
hoelzl@47694
  1194
  assumes N: "sigma_finite_measure N" and ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@47694
  1195
  shows "AE x in M. RN_deriv M N x \<noteq> \<infinity>"
hoelzl@40859
  1196
proof -
hoelzl@47694
  1197
  interpret N: sigma_finite_measure N by fact
hoelzl@47694
  1198
  from N show ?thesis
hoelzl@56993
  1199
    using sigma_finite_iff_density_finite[OF borel_measurable_RN_deriv, of N]
hoelzl@56993
  1200
      density_RN_deriv[OF ac]
hoelzl@56993
  1201
    by (simp add: RN_deriv_nonneg)
hoelzl@40859
  1202
qed
hoelzl@40859
  1203
hoelzl@40859
  1204
lemma (in sigma_finite_measure)
hoelzl@47694
  1205
  assumes N: "sigma_finite_measure N" and ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@40859
  1206
    and f: "f \<in> borel_measurable M"
hoelzl@47694
  1207
  shows RN_deriv_integrable: "integrable N f \<longleftrightarrow>
lp15@61609
  1208
      integrable M (\<lambda>x. real_of_ereal (RN_deriv M N x) * f x)" (is ?integrable)
lp15@61609
  1209
    and RN_deriv_integral: "integral\<^sup>L N f = (\<integral>x. real_of_ereal (RN_deriv M N x) * f x \<partial>M)" (is ?integral)
hoelzl@40859
  1210
proof -
hoelzl@47694
  1211
  note ac(2)[simp] and sets_eq_imp_space_eq[OF ac(2), simp]
hoelzl@47694
  1212
  interpret N: sigma_finite_measure N by fact
hoelzl@56993
  1213
lp15@61609
  1214
  have eq: "density M (RN_deriv M N) = density M (\<lambda>x. real_of_ereal (RN_deriv M N x))"
hoelzl@56993
  1215
  proof (rule density_cong)
hoelzl@56993
  1216
    from RN_deriv_finite[OF assms(1,2,3)]
lp15@61609
  1217
    show "AE x in M. RN_deriv M N x = ereal (real_of_ereal (RN_deriv M N x))"
hoelzl@56993
  1218
      by eventually_elim (insert RN_deriv_nonneg[of M N], auto simp: ereal_real)
hoelzl@56993
  1219
  qed (insert ac, auto)
hoelzl@56993
  1220
hoelzl@56993
  1221
  show ?integrable
hoelzl@56993
  1222
    apply (subst density_RN_deriv[OF ac, symmetric])
hoelzl@56993
  1223
    unfolding eq
hoelzl@56993
  1224
    apply (intro integrable_real_density f AE_I2 real_of_ereal_pos RN_deriv_nonneg)
hoelzl@56993
  1225
    apply (insert ac, auto)
hoelzl@56993
  1226
    done
hoelzl@56993
  1227
hoelzl@56993
  1228
  show ?integral
hoelzl@56993
  1229
    apply (subst density_RN_deriv[OF ac, symmetric])
hoelzl@56993
  1230
    unfolding eq
hoelzl@56993
  1231
    apply (intro integral_real_density f AE_I2 real_of_ereal_pos RN_deriv_nonneg)
hoelzl@56993
  1232
    apply (insert ac, auto)
hoelzl@56993
  1233
    done
hoelzl@40859
  1234
qed
hoelzl@40859
  1235
hoelzl@43340
  1236
lemma (in sigma_finite_measure) real_RN_deriv:
hoelzl@47694
  1237
  assumes "finite_measure N"
hoelzl@47694
  1238
  assumes ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@43340
  1239
  obtains D where "D \<in> borel_measurable M"
hoelzl@47694
  1240
    and "AE x in M. RN_deriv M N x = ereal (D x)"
hoelzl@47694
  1241
    and "AE x in N. 0 < D x"
hoelzl@43340
  1242
    and "\<And>x. 0 \<le> D x"
hoelzl@43340
  1243
proof
hoelzl@47694
  1244
  interpret N: finite_measure N by fact
lp15@61609
  1245
hoelzl@56993
  1246
  note RN = borel_measurable_RN_deriv density_RN_deriv[OF ac] RN_deriv_nonneg[of M N]
hoelzl@43340
  1247
hoelzl@47694
  1248
  let ?RN = "\<lambda>t. {x \<in> space M. RN_deriv M N x = t}"
hoelzl@43340
  1249
lp15@61609
  1250
  show "(\<lambda>x. real_of_ereal (RN_deriv M N x)) \<in> borel_measurable M"
hoelzl@43340
  1251
    using RN by auto
hoelzl@43340
  1252
wenzelm@53015
  1253
  have "N (?RN \<infinity>) = (\<integral>\<^sup>+ x. RN_deriv M N x * indicator (?RN \<infinity>) x \<partial>M)"
hoelzl@47694
  1254
    using RN(1,3) by (subst RN(2)[symmetric]) (auto simp: emeasure_density)
wenzelm@53015
  1255
  also have "\<dots> = (\<integral>\<^sup>+ x. \<infinity> * indicator (?RN \<infinity>) x \<partial>M)"
hoelzl@56996
  1256
    by (intro nn_integral_cong) (auto simp: indicator_def)
hoelzl@47694
  1257
  also have "\<dots> = \<infinity> * emeasure M (?RN \<infinity>)"
hoelzl@56996
  1258
    using RN by (intro nn_integral_cmult_indicator) auto
hoelzl@47694
  1259
  finally have eq: "N (?RN \<infinity>) = \<infinity> * emeasure M (?RN \<infinity>)" .
hoelzl@43340
  1260
  moreover
hoelzl@47694
  1261
  have "emeasure M (?RN \<infinity>) = 0"
hoelzl@43340
  1262
  proof (rule ccontr)
hoelzl@47694
  1263
    assume "emeasure M {x \<in> space M. RN_deriv M N x = \<infinity>} \<noteq> 0"
hoelzl@47694
  1264
    moreover from RN have "0 \<le> emeasure M {x \<in> space M. RN_deriv M N x = \<infinity>}" by auto
hoelzl@47694
  1265
    ultimately have "0 < emeasure M {x \<in> space M. RN_deriv M N x = \<infinity>}" by auto
hoelzl@47694
  1266
    with eq have "N (?RN \<infinity>) = \<infinity>" by simp
hoelzl@47694
  1267
    with N.emeasure_finite[of "?RN \<infinity>"] RN show False by auto
hoelzl@43340
  1268
  qed
hoelzl@47694
  1269
  ultimately have "AE x in M. RN_deriv M N x < \<infinity>"
hoelzl@43340
  1270
    using RN by (intro AE_iff_measurable[THEN iffD2]) auto
lp15@61609
  1271
  then show "AE x in M. RN_deriv M N x = ereal (real_of_ereal (RN_deriv M N x))"
hoelzl@43920
  1272
    using RN(3) by (auto simp: ereal_real)
lp15@61609
  1273
  then have eq: "AE x in N. RN_deriv M N x = ereal (real_of_ereal (RN_deriv M N x))"
hoelzl@47694
  1274
    using ac absolutely_continuous_AE by auto
hoelzl@43340
  1275
lp15@61609
  1276
  show "\<And>x. 0 \<le> real_of_ereal (RN_deriv M N x)"
hoelzl@43920
  1277
    using RN by (auto intro: real_of_ereal_pos)
hoelzl@43340
  1278
wenzelm@53015
  1279
  have "N (?RN 0) = (\<integral>\<^sup>+ x. RN_deriv M N x * indicator (?RN 0) x \<partial>M)"
hoelzl@47694
  1280
    using RN(1,3) by (subst RN(2)[symmetric]) (auto simp: emeasure_density)
wenzelm@53015
  1281
  also have "\<dots> = (\<integral>\<^sup>+ x. 0 \<partial>M)"
hoelzl@56996
  1282
    by (intro nn_integral_cong) (auto simp: indicator_def)
hoelzl@47694
  1283
  finally have "AE x in N. RN_deriv M N x \<noteq> 0"
hoelzl@47694
  1284
    using RN by (subst AE_iff_measurable[OF _ refl]) (auto simp: ac cong: sets_eq_imp_space_eq)
lp15@61609
  1285
  with RN(3) eq show "AE x in N. 0 < real_of_ereal (RN_deriv M N x)"
hoelzl@43920
  1286
    by (auto simp: zero_less_real_of_ereal le_less)
hoelzl@43340
  1287
qed
hoelzl@43340
  1288
hoelzl@38656
  1289
lemma (in sigma_finite_measure) RN_deriv_singleton:
hoelzl@47694
  1290
  assumes ac: "absolutely_continuous M N" "sets N = sets M"
hoelzl@47694
  1291
  and x: "{x} \<in> sets M"
hoelzl@47694
  1292
  shows "N {x} = RN_deriv M N x * emeasure M {x}"
hoelzl@38656
  1293
proof -
wenzelm@61808
  1294
  from \<open>{x} \<in> sets M\<close>
wenzelm@53015
  1295
  have "density M (RN_deriv M N) {x} = (\<integral>\<^sup>+w. RN_deriv M N x * indicator {x} w \<partial>M)"
hoelzl@56996
  1296
    by (auto simp: indicator_def emeasure_density intro!: nn_integral_cong)
hoelzl@56993
  1297
  with x density_RN_deriv[OF ac] RN_deriv_nonneg[of M N] show ?thesis
hoelzl@62083
  1298
    by (auto simp: max_def)
hoelzl@38656
  1299
qed
hoelzl@38656
  1300
hoelzl@38656
  1301
end