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