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