src/HOL/Probability/Radon_Nikodym.thy
author hoelzl
Wed Dec 08 19:32:11 2010 +0100 (2010-12-08)
changeset 41097 a1abfa4e2b44
parent 41095 c335d880ff82
child 41544 c3b977fee8a3
permissions -rw-r--r--
use SUPR_ and INFI_apply instead of SUPR_, INFI_fun_expand
hoelzl@38656
     1
theory Radon_Nikodym
hoelzl@38656
     2
imports Lebesgue_Integration
hoelzl@38656
     3
begin
hoelzl@38656
     4
hoelzl@40859
     5
lemma less_\<omega>_Ex_of_nat: "x < \<omega> \<longleftrightarrow> (\<exists>n. x < of_nat n)"
hoelzl@40859
     6
proof safe
hoelzl@40859
     7
  assume "x < \<omega>"
hoelzl@40859
     8
  then obtain r where "0 \<le> r" "x = Real r" by (cases x) auto
hoelzl@40859
     9
  moreover obtain n where "r < of_nat n" using ex_less_of_nat by auto
hoelzl@40859
    10
  ultimately show "\<exists>n. x < of_nat n" by (auto simp: real_eq_of_nat)
hoelzl@40859
    11
qed auto
hoelzl@40859
    12
hoelzl@38656
    13
lemma (in sigma_finite_measure) Ex_finite_integrable_function:
hoelzl@38656
    14
  shows "\<exists>h\<in>borel_measurable M. positive_integral h \<noteq> \<omega> \<and> (\<forall>x\<in>space M. 0 < h x \<and> h x < \<omega>)"
hoelzl@38656
    15
proof -
hoelzl@38656
    16
  obtain A :: "nat \<Rightarrow> 'a set" where
hoelzl@38656
    17
    range: "range A \<subseteq> sets M" and
hoelzl@38656
    18
    space: "(\<Union>i. A i) = space M" and
hoelzl@38656
    19
    measure: "\<And>i. \<mu> (A i) \<noteq> \<omega>" and
hoelzl@38656
    20
    disjoint: "disjoint_family A"
hoelzl@38656
    21
    using disjoint_sigma_finite by auto
hoelzl@38656
    22
  let "?B i" = "2^Suc i * \<mu> (A i)"
hoelzl@38656
    23
  have "\<forall>i. \<exists>x. 0 < x \<and> x < inverse (?B i)"
hoelzl@38656
    24
  proof
hoelzl@38656
    25
    fix i show "\<exists>x. 0 < x \<and> x < inverse (?B i)"
hoelzl@38656
    26
    proof cases
hoelzl@38656
    27
      assume "\<mu> (A i) = 0"
hoelzl@38656
    28
      then show ?thesis by (auto intro!: exI[of _ 1])
hoelzl@38656
    29
    next
hoelzl@38656
    30
      assume not_0: "\<mu> (A i) \<noteq> 0"
hoelzl@38656
    31
      then have "?B i \<noteq> \<omega>" using measure[of i] by auto
hoelzl@41023
    32
      then have "inverse (?B i) \<noteq> 0" unfolding pextreal_inverse_eq_0 by simp
hoelzl@38656
    33
      then show ?thesis using measure[of i] not_0
hoelzl@38656
    34
        by (auto intro!: exI[of _ "inverse (?B i) / 2"]
hoelzl@41023
    35
                 simp: pextreal_noteq_omega_Ex zero_le_mult_iff zero_less_mult_iff mult_le_0_iff power_le_zero_eq)
hoelzl@38656
    36
    qed
hoelzl@38656
    37
  qed
hoelzl@38656
    38
  from choice[OF this] obtain n where n: "\<And>i. 0 < n i"
hoelzl@38656
    39
    "\<And>i. n i < inverse (2^Suc i * \<mu> (A i))" by auto
hoelzl@38656
    40
  let "?h x" = "\<Sum>\<^isub>\<infinity> i. n i * indicator (A i) x"
hoelzl@38656
    41
  show ?thesis
hoelzl@38656
    42
  proof (safe intro!: bexI[of _ ?h] del: notI)
hoelzl@39092
    43
    have "\<And>i. A i \<in> sets M"
hoelzl@39092
    44
      using range by fastsimp+
hoelzl@39092
    45
    then have "positive_integral ?h = (\<Sum>\<^isub>\<infinity> i. n i * \<mu> (A i))"
hoelzl@39092
    46
      by (simp add: positive_integral_psuminf positive_integral_cmult_indicator)
hoelzl@38656
    47
    also have "\<dots> \<le> (\<Sum>\<^isub>\<infinity> i. Real ((1 / 2)^Suc i))"
hoelzl@38656
    48
    proof (rule psuminf_le)
hoelzl@38656
    49
      fix N show "n N * \<mu> (A N) \<le> Real ((1 / 2) ^ Suc N)"
hoelzl@38656
    50
        using measure[of N] n[of N]
hoelzl@39092
    51
        by (cases "n N")
hoelzl@41023
    52
           (auto simp: pextreal_noteq_omega_Ex field_simps zero_le_mult_iff
hoelzl@39092
    53
                       mult_le_0_iff mult_less_0_iff power_less_zero_eq
hoelzl@39092
    54
                       power_le_zero_eq inverse_eq_divide less_divide_eq
hoelzl@39092
    55
                       power_divide split: split_if_asm)
hoelzl@38656
    56
    qed
hoelzl@38656
    57
    also have "\<dots> = Real 1"
hoelzl@38656
    58
      by (rule suminf_imp_psuminf, rule power_half_series, auto)
hoelzl@38656
    59
    finally show "positive_integral ?h \<noteq> \<omega>" by auto
hoelzl@38656
    60
  next
hoelzl@38656
    61
    fix x assume "x \<in> space M"
hoelzl@38656
    62
    then obtain i where "x \<in> A i" using space[symmetric] by auto
hoelzl@38656
    63
    from psuminf_cmult_indicator[OF disjoint, OF this]
hoelzl@38656
    64
    have "?h x = n i" by simp
hoelzl@38656
    65
    then show "0 < ?h x" and "?h x < \<omega>" using n[of i] by auto
hoelzl@38656
    66
  next
hoelzl@38656
    67
    show "?h \<in> borel_measurable M" using range
hoelzl@41023
    68
      by (auto intro!: borel_measurable_psuminf borel_measurable_pextreal_times)
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@41023
    75
  "absolutely_continuous \<nu> = (\<forall>N\<in>null_sets. \<nu> N = (0 :: pextreal))"
hoelzl@38656
    76
hoelzl@40859
    77
lemma (in sigma_finite_measure) absolutely_continuous_AE:
hoelzl@40859
    78
  assumes "measure_space M \<nu>" "absolutely_continuous \<nu>" "AE x. P x"
hoelzl@40859
    79
  shows "measure_space.almost_everywhere M \<nu> P"
hoelzl@40859
    80
proof -
hoelzl@40859
    81
  interpret \<nu>: measure_space M \<nu> by fact
hoelzl@40859
    82
  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
    83
    unfolding almost_everywhere_def by auto
hoelzl@40859
    84
  show "\<nu>.almost_everywhere P"
hoelzl@40859
    85
  proof (rule \<nu>.AE_I')
hoelzl@40859
    86
    show "{x\<in>space M. \<not> P x} \<subseteq> N" by fact
hoelzl@40859
    87
    from `absolutely_continuous \<nu>` show "N \<in> \<nu>.null_sets"
hoelzl@40859
    88
      using N unfolding absolutely_continuous_def by auto
hoelzl@40859
    89
  qed
hoelzl@40859
    90
qed
hoelzl@40859
    91
hoelzl@39097
    92
lemma (in finite_measure_space) absolutely_continuousI:
hoelzl@39097
    93
  assumes "finite_measure_space M \<nu>"
hoelzl@39097
    94
  assumes v: "\<And>x. \<lbrakk> x \<in> space M ; \<mu> {x} = 0 \<rbrakk> \<Longrightarrow> \<nu> {x} = 0"
hoelzl@39097
    95
  shows "absolutely_continuous \<nu>"
hoelzl@39097
    96
proof (unfold absolutely_continuous_def sets_eq_Pow, safe)
hoelzl@39097
    97
  fix N assume "\<mu> N = 0" "N \<subseteq> space M"
hoelzl@39097
    98
  interpret v: finite_measure_space M \<nu> by fact
hoelzl@39097
    99
  have "\<nu> N = \<nu> (\<Union>x\<in>N. {x})" by simp
hoelzl@39097
   100
  also have "\<dots> = (\<Sum>x\<in>N. \<nu> {x})"
hoelzl@39097
   101
  proof (rule v.measure_finitely_additive''[symmetric])
hoelzl@39097
   102
    show "finite N" using `N \<subseteq> space M` finite_space by (auto intro: finite_subset)
hoelzl@39097
   103
    show "disjoint_family_on (\<lambda>i. {i}) N" unfolding disjoint_family_on_def by auto
hoelzl@39097
   104
    fix x assume "x \<in> N" thus "{x} \<in> sets M" using `N \<subseteq> space M` sets_eq_Pow by auto
hoelzl@39097
   105
  qed
hoelzl@39097
   106
  also have "\<dots> = 0"
hoelzl@39097
   107
  proof (safe intro!: setsum_0')
hoelzl@39097
   108
    fix x assume "x \<in> N"
hoelzl@39097
   109
    hence "\<mu> {x} \<le> \<mu> N" using sets_eq_Pow `N \<subseteq> space M` by (auto intro!: measure_mono)
hoelzl@39097
   110
    hence "\<mu> {x} = 0" using `\<mu> N = 0` by simp
hoelzl@39097
   111
    thus "\<nu> {x} = 0" using v[of x] `x \<in> N` `N \<subseteq> space M` by auto
hoelzl@39097
   112
  qed
hoelzl@39097
   113
  finally show "\<nu> N = 0" .
hoelzl@39097
   114
qed
hoelzl@39097
   115
hoelzl@40871
   116
lemma (in measure_space) density_is_absolutely_continuous:
hoelzl@40871
   117
  assumes "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@40871
   118
  shows "absolutely_continuous \<nu>"
hoelzl@40871
   119
  using assms unfolding absolutely_continuous_def
hoelzl@40871
   120
  by (simp add: positive_integral_null_set)
hoelzl@40871
   121
hoelzl@40871
   122
subsection "Existence of the Radon-Nikodym derivative"
hoelzl@40871
   123
hoelzl@38656
   124
lemma (in finite_measure) Radon_Nikodym_aux_epsilon:
hoelzl@38656
   125
  fixes e :: real assumes "0 < e"
hoelzl@38656
   126
  assumes "finite_measure M s"
hoelzl@38656
   127
  shows "\<exists>A\<in>sets M. real (\<mu> (space M)) - real (s (space M)) \<le>
hoelzl@38656
   128
                    real (\<mu> A) - real (s A) \<and>
hoelzl@38656
   129
                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> - e < real (\<mu> B) - real (s B))"
hoelzl@38656
   130
proof -
hoelzl@38656
   131
  let "?d A" = "real (\<mu> A) - real (s A)"
hoelzl@38656
   132
  interpret M': finite_measure M s by fact
hoelzl@38656
   133
  let "?A A" = "if (\<forall>B\<in>sets M. B \<subseteq> space M - A \<longrightarrow> -e < ?d B)
hoelzl@38656
   134
    then {}
hoelzl@38656
   135
    else (SOME B. B \<in> sets M \<and> B \<subseteq> space M - A \<and> ?d B \<le> -e)"
hoelzl@38656
   136
  def A \<equiv> "\<lambda>n. ((\<lambda>B. B \<union> ?A B) ^^ n) {}"
hoelzl@38656
   137
  have A_simps[simp]:
hoelzl@38656
   138
    "A 0 = {}"
hoelzl@38656
   139
    "\<And>n. A (Suc n) = (A n \<union> ?A (A n))" unfolding A_def by simp_all
hoelzl@38656
   140
  { fix A assume "A \<in> sets M"
hoelzl@38656
   141
    have "?A A \<in> sets M"
hoelzl@38656
   142
      by (auto intro!: someI2[of _ _ "\<lambda>A. A \<in> sets M"] simp: not_less) }
hoelzl@38656
   143
  note A'_in_sets = this
hoelzl@38656
   144
  { fix n have "A n \<in> sets M"
hoelzl@38656
   145
    proof (induct n)
hoelzl@38656
   146
      case (Suc n) thus "A (Suc n) \<in> sets M"
hoelzl@38656
   147
        using A'_in_sets[of "A n"] by (auto split: split_if_asm)
hoelzl@38656
   148
    qed (simp add: A_def) }
hoelzl@38656
   149
  note A_in_sets = this
hoelzl@38656
   150
  hence "range A \<subseteq> sets M" by auto
hoelzl@38656
   151
  { fix n B
hoelzl@38656
   152
    assume Ex: "\<exists>B. B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> -e"
hoelzl@38656
   153
    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
   154
    have "?d (A (Suc n)) \<le> ?d (A n) - e" unfolding A_simps if_not_P[OF False]
hoelzl@38656
   155
    proof (rule someI2_ex[OF Ex])
hoelzl@38656
   156
      fix B assume "B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e"
hoelzl@38656
   157
      hence "A n \<inter> B = {}" "B \<in> sets M" and dB: "?d B \<le> -e" by auto
hoelzl@38656
   158
      hence "?d (A n \<union> B) = ?d (A n) + ?d B"
hoelzl@38656
   159
        using `A n \<in> sets M` real_finite_measure_Union M'.real_finite_measure_Union by simp
hoelzl@38656
   160
      also have "\<dots> \<le> ?d (A n) - e" using dB by simp
hoelzl@38656
   161
      finally show "?d (A n \<union> B) \<le> ?d (A n) - e" .
hoelzl@38656
   162
    qed }
hoelzl@38656
   163
  note dA_epsilon = this
hoelzl@38656
   164
  { fix n have "?d (A (Suc n)) \<le> ?d (A n)"
hoelzl@38656
   165
    proof (cases "\<exists>B. B\<in>sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e")
hoelzl@38656
   166
      case True from dA_epsilon[OF this] show ?thesis using `0 < e` by simp
hoelzl@38656
   167
    next
hoelzl@38656
   168
      case False
hoelzl@38656
   169
      hence "\<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B" by (auto simp: not_le)
hoelzl@38656
   170
      thus ?thesis by simp
hoelzl@38656
   171
    qed }
hoelzl@38656
   172
  note dA_mono = this
hoelzl@38656
   173
  show ?thesis
hoelzl@38656
   174
  proof (cases "\<exists>n. \<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B")
hoelzl@38656
   175
    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
   176
    show ?thesis
hoelzl@38656
   177
    proof (safe intro!: bexI[of _ "space M - A n"])
hoelzl@38656
   178
      fix B assume "B \<in> sets M" "B \<subseteq> space M - A n"
hoelzl@38656
   179
      from B[OF this] show "-e < ?d B" .
hoelzl@38656
   180
    next
hoelzl@38656
   181
      show "space M - A n \<in> sets M" by (rule compl_sets) fact
hoelzl@38656
   182
    next
hoelzl@38656
   183
      show "?d (space M) \<le> ?d (space M - A n)"
hoelzl@38656
   184
      proof (induct n)
hoelzl@38656
   185
        fix n assume "?d (space M) \<le> ?d (space M - A n)"
hoelzl@38656
   186
        also have "\<dots> \<le> ?d (space M - A (Suc n))"
hoelzl@38656
   187
          using A_in_sets sets_into_space dA_mono[of n]
hoelzl@38656
   188
            real_finite_measure_Diff[of "space M"]
hoelzl@38656
   189
            real_finite_measure_Diff[of "space M"]
hoelzl@38656
   190
            M'.real_finite_measure_Diff[of "space M"]
hoelzl@38656
   191
            M'.real_finite_measure_Diff[of "space M"]
hoelzl@38656
   192
          by (simp del: A_simps)
hoelzl@38656
   193
        finally show "?d (space M) \<le> ?d (space M - A (Suc n))" .
hoelzl@38656
   194
      qed simp
hoelzl@38656
   195
    qed
hoelzl@38656
   196
  next
hoelzl@38656
   197
    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
   198
      by (auto simp add: not_less)
hoelzl@38656
   199
    { fix n have "?d (A n) \<le> - real n * e"
hoelzl@38656
   200
      proof (induct n)
hoelzl@38656
   201
        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@38656
   202
      qed simp } note dA_less = this
hoelzl@38656
   203
    have decseq: "decseq (\<lambda>n. ?d (A n))" unfolding decseq_eq_incseq
hoelzl@38656
   204
    proof (rule incseq_SucI)
hoelzl@38656
   205
      fix n show "- ?d (A n) \<le> - ?d (A (Suc n))" using dA_mono[of n] by auto
hoelzl@38656
   206
    qed
hoelzl@38656
   207
    from real_finite_continuity_from_below[of A] `range A \<subseteq> sets M`
hoelzl@38656
   208
      M'.real_finite_continuity_from_below[of A]
hoelzl@38656
   209
    have convergent: "(\<lambda>i. ?d (A i)) ----> ?d (\<Union>i. A i)"
hoelzl@38656
   210
      by (auto intro!: LIMSEQ_diff)
hoelzl@38656
   211
    obtain n :: nat where "- ?d (\<Union>i. A i) / e < real n" using reals_Archimedean2 by auto
hoelzl@38656
   212
    moreover from order_trans[OF decseq_le[OF decseq convergent] dA_less]
hoelzl@38656
   213
    have "real n \<le> - ?d (\<Union>i. A i) / e" using `0<e` by (simp add: field_simps)
hoelzl@38656
   214
    ultimately show ?thesis by auto
hoelzl@38656
   215
  qed
hoelzl@38656
   216
qed
hoelzl@38656
   217
hoelzl@38656
   218
lemma (in finite_measure) Radon_Nikodym_aux:
hoelzl@38656
   219
  assumes "finite_measure M s"
hoelzl@38656
   220
  shows "\<exists>A\<in>sets M. real (\<mu> (space M)) - real (s (space M)) \<le>
hoelzl@38656
   221
                    real (\<mu> A) - real (s A) \<and>
hoelzl@38656
   222
                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> 0 \<le> real (\<mu> B) - real (s B))"
hoelzl@38656
   223
proof -
hoelzl@38656
   224
  let "?d A" = "real (\<mu> A) - real (s A)"
hoelzl@38656
   225
  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@38656
   226
  interpret M': finite_measure M s by fact
hoelzl@39092
   227
  let "?r S" = "restricted_space S"
hoelzl@38656
   228
  { fix S n
hoelzl@38656
   229
    assume S: "S \<in> sets M"
hoelzl@38656
   230
    hence **: "\<And>X. X \<in> op \<inter> S ` sets M \<longleftrightarrow> X \<in> sets M \<and> X \<subseteq> S" by auto
hoelzl@38656
   231
    from M'.restricted_finite_measure[of S] restricted_finite_measure[of S] S
hoelzl@38656
   232
    have "finite_measure (?r S) \<mu>" "0 < 1 / real (Suc n)"
hoelzl@38656
   233
      "finite_measure (?r S) s" by auto
hoelzl@38656
   234
    from finite_measure.Radon_Nikodym_aux_epsilon[OF this] guess X ..
hoelzl@38656
   235
    hence "?P X S n"
hoelzl@38656
   236
    proof (simp add: **, safe)
hoelzl@38656
   237
      fix C assume C: "C \<in> sets M" "C \<subseteq> X" "X \<subseteq> S" and
hoelzl@38656
   238
        *: "\<forall>B\<in>sets M. S \<inter> B \<subseteq> X \<longrightarrow> - (1 / real (Suc n)) < ?d (S \<inter> B)"
hoelzl@38656
   239
      hence "C \<subseteq> S" "C \<subseteq> X" "S \<inter> C = C" by auto
hoelzl@38656
   240
      with *[THEN bspec, OF `C \<in> sets M`]
hoelzl@38656
   241
      show "- (1 / real (Suc n)) < ?d C" by auto
hoelzl@38656
   242
    qed
hoelzl@38656
   243
    hence "\<exists>A. ?P A S n" by auto }
hoelzl@38656
   244
  note Ex_P = this
hoelzl@38656
   245
  def A \<equiv> "nat_rec (space M) (\<lambda>n A. SOME B. ?P B A n)"
hoelzl@38656
   246
  have A_Suc: "\<And>n. A (Suc n) = (SOME B. ?P B (A n) n)" by (simp add: A_def)
hoelzl@38656
   247
  have A_0[simp]: "A 0 = space M" unfolding A_def by simp
hoelzl@38656
   248
  { fix i have "A i \<in> sets M" unfolding A_def
hoelzl@38656
   249
    proof (induct i)
hoelzl@38656
   250
      case (Suc i)
hoelzl@38656
   251
      from Ex_P[OF this, of i] show ?case unfolding nat_rec_Suc
hoelzl@38656
   252
        by (rule someI2_ex) simp
hoelzl@38656
   253
    qed simp }
hoelzl@38656
   254
  note A_in_sets = this
hoelzl@38656
   255
  { fix n have "?P (A (Suc n)) (A n) n"
hoelzl@38656
   256
      using Ex_P[OF A_in_sets] unfolding A_Suc
hoelzl@38656
   257
      by (rule someI2_ex) simp }
hoelzl@38656
   258
  note P_A = this
hoelzl@38656
   259
  have "range A \<subseteq> sets M" using A_in_sets by auto
hoelzl@38656
   260
  have A_mono: "\<And>i. A (Suc i) \<subseteq> A i" using P_A by simp
hoelzl@38656
   261
  have mono_dA: "mono (\<lambda>i. ?d (A i))" using P_A by (simp add: mono_iff_le_Suc)
hoelzl@38656
   262
  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
   263
      using P_A by auto
hoelzl@38656
   264
  show ?thesis
hoelzl@38656
   265
  proof (safe intro!: bexI[of _ "\<Inter>i. A i"])
hoelzl@38656
   266
    show "(\<Inter>i. A i) \<in> sets M" using A_in_sets by auto
hoelzl@38656
   267
    from `range A \<subseteq> sets M` A_mono
hoelzl@38656
   268
      real_finite_continuity_from_above[of A]
hoelzl@38656
   269
      M'.real_finite_continuity_from_above[of A]
hoelzl@38656
   270
    have "(\<lambda>i. ?d (A i)) ----> ?d (\<Inter>i. A i)" by (auto intro!: LIMSEQ_diff)
hoelzl@38656
   271
    thus "?d (space M) \<le> ?d (\<Inter>i. A i)" using mono_dA[THEN monoD, of 0 _]
hoelzl@38656
   272
      by (rule_tac LIMSEQ_le_const) (auto intro!: exI)
hoelzl@38656
   273
  next
hoelzl@38656
   274
    fix B assume B: "B \<in> sets M" "B \<subseteq> (\<Inter>i. A i)"
hoelzl@38656
   275
    show "0 \<le> ?d B"
hoelzl@38656
   276
    proof (rule ccontr)
hoelzl@38656
   277
      assume "\<not> 0 \<le> ?d B"
hoelzl@38656
   278
      hence "0 < - ?d B" by auto
hoelzl@38656
   279
      from ex_inverse_of_nat_Suc_less[OF this]
hoelzl@38656
   280
      obtain n where *: "?d B < - 1 / real (Suc n)"
hoelzl@38656
   281
        by (auto simp: real_eq_of_nat inverse_eq_divide field_simps)
hoelzl@38656
   282
      have "B \<subseteq> A (Suc n)" using B by (auto simp del: nat_rec_Suc)
hoelzl@38656
   283
      from epsilon[OF B(1) this] *
hoelzl@38656
   284
      show False by auto
hoelzl@38656
   285
    qed
hoelzl@38656
   286
  qed
hoelzl@38656
   287
qed
hoelzl@38656
   288
hoelzl@38656
   289
lemma (in finite_measure) Radon_Nikodym_finite_measure:
hoelzl@38656
   290
  assumes "finite_measure M \<nu>"
hoelzl@38656
   291
  assumes "absolutely_continuous \<nu>"
hoelzl@38656
   292
  shows "\<exists>f \<in> borel_measurable M. \<forall>A\<in>sets M. \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   293
proof -
hoelzl@38656
   294
  interpret M': finite_measure M \<nu> using assms(1) .
hoelzl@38656
   295
  def G \<equiv> "{g \<in> borel_measurable M. \<forall>A\<in>sets M. positive_integral (\<lambda>x. g x * indicator A x) \<le> \<nu> A}"
hoelzl@38656
   296
  have "(\<lambda>x. 0) \<in> G" unfolding G_def by auto
hoelzl@38656
   297
  hence "G \<noteq> {}" by auto
hoelzl@38656
   298
  { fix f g assume f: "f \<in> G" and g: "g \<in> G"
hoelzl@38656
   299
    have "(\<lambda>x. max (g x) (f x)) \<in> G" (is "?max \<in> G") unfolding G_def
hoelzl@38656
   300
    proof safe
hoelzl@38656
   301
      show "?max \<in> borel_measurable M" using f g unfolding G_def by auto
hoelzl@38656
   302
      let ?A = "{x \<in> space M. f x \<le> g x}"
hoelzl@38656
   303
      have "?A \<in> sets M" using f g unfolding G_def by auto
hoelzl@38656
   304
      fix A assume "A \<in> sets M"
hoelzl@38656
   305
      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
   306
      have union: "((?A \<inter> A) \<union> ((space M - ?A) \<inter> A)) = A"
hoelzl@38656
   307
        using sets_into_space[OF `A \<in> sets M`] by auto
hoelzl@38656
   308
      have "\<And>x. x \<in> space M \<Longrightarrow> max (g x) (f x) * indicator A x =
hoelzl@38656
   309
        g x * indicator (?A \<inter> A) x + f x * indicator ((space M - ?A) \<inter> A) x"
hoelzl@38656
   310
        by (auto simp: indicator_def max_def)
hoelzl@38656
   311
      hence "positive_integral (\<lambda>x. max (g x) (f x) * indicator A x) =
hoelzl@38656
   312
        positive_integral (\<lambda>x. g x * indicator (?A \<inter> A) x) +
hoelzl@38656
   313
        positive_integral (\<lambda>x. f x * indicator ((space M - ?A) \<inter> A) x)"
hoelzl@38656
   314
        using f g sets unfolding G_def
hoelzl@38656
   315
        by (auto cong: positive_integral_cong intro!: positive_integral_add borel_measurable_indicator)
hoelzl@38656
   316
      also have "\<dots> \<le> \<nu> (?A \<inter> A) + \<nu> ((space M - ?A) \<inter> A)"
hoelzl@38656
   317
        using f g sets unfolding G_def by (auto intro!: add_mono)
hoelzl@38656
   318
      also have "\<dots> = \<nu> A"
hoelzl@38656
   319
        using M'.measure_additive[OF sets] union by auto
hoelzl@38656
   320
      finally show "positive_integral (\<lambda>x. max (g x) (f x) * indicator A x) \<le> \<nu> A" .
hoelzl@38656
   321
    qed }
hoelzl@38656
   322
  note max_in_G = this
hoelzl@38656
   323
  { fix f g assume  "f \<up> g" and f: "\<And>i. f i \<in> G"
hoelzl@38656
   324
    have "g \<in> G" unfolding G_def
hoelzl@38656
   325
    proof safe
hoelzl@41097
   326
      from `f \<up> g` have [simp]: "g = (\<lambda>x. SUP i. f i x)"
hoelzl@41097
   327
        unfolding isoton_def fun_eq_iff SUPR_apply by simp
hoelzl@38656
   328
      have f_borel: "\<And>i. f i \<in> borel_measurable M" using f unfolding G_def by simp
hoelzl@41097
   329
      thus "g \<in> borel_measurable M" by auto
hoelzl@38656
   330
      fix A assume "A \<in> sets M"
hoelzl@38656
   331
      hence "\<And>i. (\<lambda>x. f i x * indicator A x) \<in> borel_measurable M"
hoelzl@38656
   332
        using f_borel by (auto intro!: borel_measurable_indicator)
hoelzl@38656
   333
      from positive_integral_isoton[OF isoton_indicator[OF `f \<up> g`] this]
hoelzl@38656
   334
      have SUP: "positive_integral (\<lambda>x. g x * indicator A x) =
hoelzl@38656
   335
          (SUP i. positive_integral (\<lambda>x. f i x * indicator A x))"
hoelzl@38656
   336
        unfolding isoton_def by simp
hoelzl@38656
   337
      show "positive_integral (\<lambda>x. g x * indicator A x) \<le> \<nu> A" unfolding SUP
hoelzl@38656
   338
        using f `A \<in> sets M` unfolding G_def by (auto intro!: SUP_leI)
hoelzl@38656
   339
    qed }
hoelzl@38656
   340
  note SUP_in_G = this
hoelzl@38656
   341
  let ?y = "SUP g : G. positive_integral g"
hoelzl@38656
   342
  have "?y \<le> \<nu> (space M)" unfolding G_def
hoelzl@38656
   343
  proof (safe intro!: SUP_leI)
hoelzl@38656
   344
    fix g assume "\<forall>A\<in>sets M. positive_integral (\<lambda>x. g x * indicator A x) \<le> \<nu> A"
hoelzl@38656
   345
    from this[THEN bspec, OF top] show "positive_integral g \<le> \<nu> (space M)"
hoelzl@38656
   346
      by (simp cong: positive_integral_cong)
hoelzl@38656
   347
  qed
hoelzl@38656
   348
  hence "?y \<noteq> \<omega>" using M'.finite_measure_of_space by auto
hoelzl@38656
   349
  from SUPR_countable_SUPR[OF this `G \<noteq> {}`] guess ys .. note ys = this
hoelzl@38656
   350
  hence "\<forall>n. \<exists>g. g\<in>G \<and> positive_integral g = ys n"
hoelzl@38656
   351
  proof safe
hoelzl@38656
   352
    fix n assume "range ys \<subseteq> positive_integral ` G"
hoelzl@38656
   353
    hence "ys n \<in> positive_integral ` G" by auto
hoelzl@38656
   354
    thus "\<exists>g. g\<in>G \<and> positive_integral g = ys n" by auto
hoelzl@38656
   355
  qed
hoelzl@38656
   356
  from choice[OF this] obtain gs where "\<And>i. gs i \<in> G" "\<And>n. positive_integral (gs n) = ys n" by auto
hoelzl@38656
   357
  hence y_eq: "?y = (SUP i. positive_integral (gs i))" using ys by auto
hoelzl@38656
   358
  let "?g i x" = "Max ((\<lambda>n. gs n x) ` {..i})"
hoelzl@38656
   359
  def f \<equiv> "SUP i. ?g i"
hoelzl@38656
   360
  have gs_not_empty: "\<And>i. (\<lambda>n. gs n x) ` {..i} \<noteq> {}" by auto
hoelzl@38656
   361
  { fix i have "?g i \<in> G"
hoelzl@38656
   362
    proof (induct i)
hoelzl@38656
   363
      case 0 thus ?case by simp fact
hoelzl@38656
   364
    next
hoelzl@38656
   365
      case (Suc i)
hoelzl@38656
   366
      with Suc gs_not_empty `gs (Suc i) \<in> G` show ?case
hoelzl@38656
   367
        by (auto simp add: atMost_Suc intro!: max_in_G)
hoelzl@38656
   368
    qed }
hoelzl@38656
   369
  note g_in_G = this
hoelzl@38656
   370
  have "\<And>x. \<forall>i. ?g i x \<le> ?g (Suc i) x"
hoelzl@38656
   371
    using gs_not_empty by (simp add: atMost_Suc)
hoelzl@38656
   372
  hence isoton_g: "?g \<up> f" by (simp add: isoton_def le_fun_def f_def)
hoelzl@38656
   373
  from SUP_in_G[OF this g_in_G] have "f \<in> G" .
hoelzl@38656
   374
  hence [simp, intro]: "f \<in> borel_measurable M" unfolding G_def by auto
hoelzl@38656
   375
  have "(\<lambda>i. positive_integral (?g i)) \<up> positive_integral f"
hoelzl@38656
   376
    using isoton_g g_in_G by (auto intro!: positive_integral_isoton simp: G_def f_def)
hoelzl@38656
   377
  hence "positive_integral f = (SUP i. positive_integral (?g i))"
hoelzl@38656
   378
    unfolding isoton_def by simp
hoelzl@38656
   379
  also have "\<dots> = ?y"
hoelzl@38656
   380
  proof (rule antisym)
hoelzl@38656
   381
    show "(SUP i. positive_integral (?g i)) \<le> ?y"
hoelzl@38656
   382
      using g_in_G by (auto intro!: exI Sup_mono simp: SUPR_def)
hoelzl@38656
   383
    show "?y \<le> (SUP i. positive_integral (?g i))" unfolding y_eq
hoelzl@38656
   384
      by (auto intro!: SUP_mono positive_integral_mono Max_ge)
hoelzl@38656
   385
  qed
hoelzl@38656
   386
  finally have int_f_eq_y: "positive_integral f = ?y" .
hoelzl@38656
   387
  let "?t A" = "\<nu> A - positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   388
  have "finite_measure M ?t"
hoelzl@38656
   389
  proof
hoelzl@38656
   390
    show "?t {} = 0" by simp
hoelzl@38656
   391
    show "?t (space M) \<noteq> \<omega>" using M'.finite_measure by simp
hoelzl@38656
   392
    show "countably_additive M ?t" unfolding countably_additive_def
hoelzl@38656
   393
    proof safe
hoelzl@38656
   394
      fix A :: "nat \<Rightarrow> 'a set"  assume A: "range A \<subseteq> sets M" "disjoint_family A"
hoelzl@38656
   395
      have "(\<Sum>\<^isub>\<infinity> n. positive_integral (\<lambda>x. f x * indicator (A n) x))
hoelzl@38656
   396
        = positive_integral (\<lambda>x. (\<Sum>\<^isub>\<infinity>n. f x * indicator (A n) x))"
hoelzl@38656
   397
        using `range A \<subseteq> sets M`
hoelzl@38656
   398
        by (rule_tac positive_integral_psuminf[symmetric]) (auto intro!: borel_measurable_indicator)
hoelzl@38656
   399
      also have "\<dots> = positive_integral (\<lambda>x. f x * indicator (\<Union>n. A n) x)"
hoelzl@38656
   400
        apply (rule positive_integral_cong)
hoelzl@38656
   401
        apply (subst psuminf_cmult_right)
hoelzl@38656
   402
        unfolding psuminf_indicator[OF `disjoint_family A`] ..
hoelzl@38656
   403
      finally have "(\<Sum>\<^isub>\<infinity> n. positive_integral (\<lambda>x. f x * indicator (A n) x))
hoelzl@38656
   404
        = positive_integral (\<lambda>x. f x * indicator (\<Union>n. A n) x)" .
hoelzl@38656
   405
      moreover have "(\<Sum>\<^isub>\<infinity>n. \<nu> (A n)) = \<nu> (\<Union>n. A n)"
hoelzl@38656
   406
        using M'.measure_countably_additive A by (simp add: comp_def)
hoelzl@38656
   407
      moreover have "\<And>i. positive_integral (\<lambda>x. f x * indicator (A i) x) \<le> \<nu> (A i)"
hoelzl@38656
   408
          using A `f \<in> G` unfolding G_def by auto
hoelzl@38656
   409
      moreover have v_fin: "\<nu> (\<Union>i. A i) \<noteq> \<omega>" using M'.finite_measure A by (simp add: countable_UN)
hoelzl@38656
   410
      moreover {
hoelzl@38656
   411
        have "positive_integral (\<lambda>x. f x * indicator (\<Union>i. A i) x) \<le> \<nu> (\<Union>i. A i)"
hoelzl@38656
   412
          using A `f \<in> G` unfolding G_def by (auto simp: countable_UN)
hoelzl@41023
   413
        also have "\<nu> (\<Union>i. A i) < \<omega>" using v_fin by (simp add: pextreal_less_\<omega>)
hoelzl@38656
   414
        finally have "positive_integral (\<lambda>x. f x * indicator (\<Union>i. A i) x) \<noteq> \<omega>"
hoelzl@41023
   415
          by (simp add: pextreal_less_\<omega>) }
hoelzl@38656
   416
      ultimately
hoelzl@38656
   417
      show "(\<Sum>\<^isub>\<infinity> n. ?t (A n)) = ?t (\<Union>i. A i)"
hoelzl@38656
   418
        apply (subst psuminf_minus) by simp_all
hoelzl@38656
   419
    qed
hoelzl@38656
   420
  qed
hoelzl@38656
   421
  then interpret M: finite_measure M ?t .
hoelzl@38656
   422
  have ac: "absolutely_continuous ?t" using `absolutely_continuous \<nu>` unfolding absolutely_continuous_def by auto
hoelzl@38656
   423
  have upper_bound: "\<forall>A\<in>sets M. ?t A \<le> 0"
hoelzl@38656
   424
  proof (rule ccontr)
hoelzl@38656
   425
    assume "\<not> ?thesis"
hoelzl@38656
   426
    then obtain A where A: "A \<in> sets M" and pos: "0 < ?t A"
hoelzl@38656
   427
      by (auto simp: not_le)
hoelzl@38656
   428
    note pos
hoelzl@38656
   429
    also have "?t A \<le> ?t (space M)"
hoelzl@38656
   430
      using M.measure_mono[of A "space M"] A sets_into_space by simp
hoelzl@38656
   431
    finally have pos_t: "0 < ?t (space M)" by simp
hoelzl@38656
   432
    moreover
hoelzl@38656
   433
    hence pos_M: "0 < \<mu> (space M)"
hoelzl@38656
   434
      using ac top unfolding absolutely_continuous_def by auto
hoelzl@38656
   435
    moreover
hoelzl@38656
   436
    have "positive_integral (\<lambda>x. f x * indicator (space M) x) \<le> \<nu> (space M)"
hoelzl@38656
   437
      using `f \<in> G` unfolding G_def by auto
hoelzl@38656
   438
    hence "positive_integral (\<lambda>x. f x * indicator (space M) x) \<noteq> \<omega>"
hoelzl@38656
   439
      using M'.finite_measure_of_space by auto
hoelzl@38656
   440
    moreover
hoelzl@38656
   441
    def b \<equiv> "?t (space M) / \<mu> (space M) / 2"
hoelzl@38656
   442
    ultimately have b: "b \<noteq> 0" "b \<noteq> \<omega>"
hoelzl@38656
   443
      using M'.finite_measure_of_space
hoelzl@41023
   444
      by (auto simp: pextreal_inverse_eq_0 finite_measure_of_space)
hoelzl@38656
   445
    have "finite_measure M (\<lambda>A. b * \<mu> A)" (is "finite_measure M ?b")
hoelzl@38656
   446
    proof
hoelzl@38656
   447
      show "?b {} = 0" by simp
hoelzl@38656
   448
      show "?b (space M) \<noteq> \<omega>" using finite_measure_of_space b by auto
hoelzl@38656
   449
      show "countably_additive M ?b"
hoelzl@38656
   450
        unfolding countably_additive_def psuminf_cmult_right
hoelzl@38656
   451
        using measure_countably_additive by auto
hoelzl@38656
   452
    qed
hoelzl@38656
   453
    from M.Radon_Nikodym_aux[OF this]
hoelzl@38656
   454
    obtain A0 where "A0 \<in> sets M" and
hoelzl@38656
   455
      space_less_A0: "real (?t (space M)) - real (b * \<mu> (space M)) \<le> real (?t A0) - real (b * \<mu> A0)" and
hoelzl@38656
   456
      *: "\<And>B. \<lbrakk> B \<in> sets M ; B \<subseteq> A0 \<rbrakk> \<Longrightarrow> 0 \<le> real (?t B) - real (b * \<mu> B)" by auto
hoelzl@38656
   457
    { fix B assume "B \<in> sets M" "B \<subseteq> A0"
hoelzl@38656
   458
      with *[OF this] have "b * \<mu> B \<le> ?t B"
hoelzl@38656
   459
        using M'.finite_measure b finite_measure
hoelzl@38656
   460
        by (cases "b * \<mu> B", cases "?t B") (auto simp: field_simps) }
hoelzl@38656
   461
    note bM_le_t = this
hoelzl@38656
   462
    let "?f0 x" = "f x + b * indicator A0 x"
hoelzl@38656
   463
    { fix A assume A: "A \<in> sets M"
hoelzl@38656
   464
      hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
hoelzl@38656
   465
      have "positive_integral (\<lambda>x. ?f0 x  * indicator A x) =
hoelzl@38656
   466
        positive_integral (\<lambda>x. f x * indicator A x + b * indicator (A \<inter> A0) x)"
hoelzl@38656
   467
        by (auto intro!: positive_integral_cong simp: field_simps indicator_inter_arith)
hoelzl@38656
   468
      hence "positive_integral (\<lambda>x. ?f0 x * indicator A x) =
hoelzl@38656
   469
          positive_integral (\<lambda>x. f x * indicator A x) + b * \<mu> (A \<inter> A0)"
hoelzl@38656
   470
        using `A0 \<in> sets M` `A \<inter> A0 \<in> sets M` A
hoelzl@38656
   471
        by (simp add: borel_measurable_indicator positive_integral_add positive_integral_cmult_indicator) }
hoelzl@38656
   472
    note f0_eq = this
hoelzl@38656
   473
    { fix A assume A: "A \<in> sets M"
hoelzl@38656
   474
      hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
hoelzl@38656
   475
      have f_le_v: "positive_integral (\<lambda>x. f x * indicator A x) \<le> \<nu> A"
hoelzl@38656
   476
        using `f \<in> G` A unfolding G_def by auto
hoelzl@38656
   477
      note f0_eq[OF A]
hoelzl@38656
   478
      also have "positive_integral (\<lambda>x. f x * indicator A x) + b * \<mu> (A \<inter> A0) \<le>
hoelzl@38656
   479
          positive_integral (\<lambda>x. f x * indicator A x) + ?t (A \<inter> A0)"
hoelzl@38656
   480
        using bM_le_t[OF `A \<inter> A0 \<in> sets M`] `A \<in> sets M` `A0 \<in> sets M`
hoelzl@38656
   481
        by (auto intro!: add_left_mono)
hoelzl@38656
   482
      also have "\<dots> \<le> positive_integral (\<lambda>x. f x * indicator A x) + ?t A"
hoelzl@38656
   483
        using M.measure_mono[simplified, OF _ `A \<inter> A0 \<in> sets M` `A \<in> sets M`]
hoelzl@38656
   484
        by (auto intro!: add_left_mono)
hoelzl@38656
   485
      also have "\<dots> \<le> \<nu> A"
hoelzl@38656
   486
        using f_le_v M'.finite_measure[simplified, OF `A \<in> sets M`]
hoelzl@38656
   487
        by (cases "positive_integral (\<lambda>x. f x * indicator A x)", cases "\<nu> A", auto)
hoelzl@38656
   488
      finally have "positive_integral (\<lambda>x. ?f0 x * indicator A x) \<le> \<nu> A" . }
hoelzl@38656
   489
    hence "?f0 \<in> G" using `A0 \<in> sets M` unfolding G_def
hoelzl@41023
   490
      by (auto intro!: borel_measurable_indicator borel_measurable_pextreal_add borel_measurable_pextreal_times)
hoelzl@38656
   491
    have real: "?t (space M) \<noteq> \<omega>" "?t A0 \<noteq> \<omega>"
hoelzl@38656
   492
      "b * \<mu> (space M) \<noteq> \<omega>" "b * \<mu> A0 \<noteq> \<omega>"
hoelzl@38656
   493
      using `A0 \<in> sets M` b
hoelzl@38656
   494
        finite_measure[of A0] M.finite_measure[of A0]
hoelzl@38656
   495
        finite_measure_of_space M.finite_measure_of_space
hoelzl@38656
   496
      by auto
hoelzl@38656
   497
    have int_f_finite: "positive_integral f \<noteq> \<omega>"
hoelzl@41023
   498
      using M'.finite_measure_of_space pos_t unfolding pextreal_zero_less_diff_iff
hoelzl@38656
   499
      by (auto cong: positive_integral_cong)
hoelzl@38656
   500
    have "?t (space M) > b * \<mu> (space M)" unfolding b_def
hoelzl@38656
   501
      apply (simp add: field_simps)
hoelzl@38656
   502
      apply (subst mult_assoc[symmetric])
hoelzl@41023
   503
      apply (subst pextreal_mult_inverse)
hoelzl@38656
   504
      using finite_measure_of_space M'.finite_measure_of_space pos_t pos_M
hoelzl@41023
   505
      using pextreal_mult_strict_right_mono[of "Real (1/2)" 1 "?t (space M)"]
hoelzl@38656
   506
      by simp_all
hoelzl@38656
   507
    hence  "0 < ?t (space M) - b * \<mu> (space M)"
hoelzl@41023
   508
      by (simp add: pextreal_zero_less_diff_iff)
hoelzl@38656
   509
    also have "\<dots> \<le> ?t A0 - b * \<mu> A0"
hoelzl@41023
   510
      using space_less_A0 pos_M pos_t b real[unfolded pextreal_noteq_omega_Ex] by auto
hoelzl@41023
   511
    finally have "b * \<mu> A0 < ?t A0" unfolding pextreal_zero_less_diff_iff .
hoelzl@38656
   512
    hence "0 < ?t A0" by auto
hoelzl@38656
   513
    hence "0 < \<mu> A0" using ac unfolding absolutely_continuous_def
hoelzl@38656
   514
      using `A0 \<in> sets M` by auto
hoelzl@38656
   515
    hence "0 < b * \<mu> A0" using b by auto
hoelzl@38656
   516
    from int_f_finite this
hoelzl@38656
   517
    have "?y + 0 < positive_integral f + b * \<mu> A0" unfolding int_f_eq_y
hoelzl@41023
   518
      by (rule pextreal_less_add)
hoelzl@38656
   519
    also have "\<dots> = positive_integral ?f0" using f0_eq[OF top] `A0 \<in> sets M` sets_into_space
hoelzl@38656
   520
      by (simp cong: positive_integral_cong)
hoelzl@38656
   521
    finally have "?y < positive_integral ?f0" by simp
hoelzl@38656
   522
    moreover from `?f0 \<in> G` have "positive_integral ?f0 \<le> ?y" by (auto intro!: le_SUPI)
hoelzl@38656
   523
    ultimately show False by auto
hoelzl@38656
   524
  qed
hoelzl@38656
   525
  show ?thesis
hoelzl@38656
   526
  proof (safe intro!: bexI[of _ f])
hoelzl@38656
   527
    fix A assume "A\<in>sets M"
hoelzl@38656
   528
    show "\<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   529
    proof (rule antisym)
hoelzl@38656
   530
      show "positive_integral (\<lambda>x. f x * indicator A x) \<le> \<nu> A"
hoelzl@38656
   531
        using `f \<in> G` `A \<in> sets M` unfolding G_def by auto
hoelzl@38656
   532
      show "\<nu> A \<le> positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   533
        using upper_bound[THEN bspec, OF `A \<in> sets M`]
hoelzl@41023
   534
         by (simp add: pextreal_zero_le_diff)
hoelzl@38656
   535
    qed
hoelzl@38656
   536
  qed simp
hoelzl@38656
   537
qed
hoelzl@38656
   538
hoelzl@40859
   539
lemma (in finite_measure) split_space_into_finite_sets_and_rest:
hoelzl@38656
   540
  assumes "measure_space M \<nu>"
hoelzl@40859
   541
  assumes ac: "absolutely_continuous \<nu>"
hoelzl@40859
   542
  shows "\<exists>\<Omega>0\<in>sets M. \<exists>\<Omega>::nat\<Rightarrow>'a set. disjoint_family \<Omega> \<and> range \<Omega> \<subseteq> sets M \<and> \<Omega>0 = space M - (\<Union>i. \<Omega> i) \<and>
hoelzl@40859
   543
    (\<forall>A\<in>sets M. A \<subseteq> \<Omega>0 \<longrightarrow> (\<mu> A = 0 \<and> \<nu> A = 0) \<or> (\<mu> A > 0 \<and> \<nu> A = \<omega>)) \<and>
hoelzl@40859
   544
    (\<forall>i. \<nu> (\<Omega> i) \<noteq> \<omega>)"
hoelzl@38656
   545
proof -
hoelzl@38656
   546
  interpret v: measure_space M \<nu> by fact
hoelzl@38656
   547
  let ?Q = "{Q\<in>sets M. \<nu> Q \<noteq> \<omega>}"
hoelzl@38656
   548
  let ?a = "SUP Q:?Q. \<mu> Q"
hoelzl@38656
   549
  have "{} \<in> ?Q" using v.empty_measure by auto
hoelzl@38656
   550
  then have Q_not_empty: "?Q \<noteq> {}" by blast
hoelzl@38656
   551
  have "?a \<le> \<mu> (space M)" using sets_into_space
hoelzl@38656
   552
    by (auto intro!: SUP_leI measure_mono top)
hoelzl@38656
   553
  then have "?a \<noteq> \<omega>" using finite_measure_of_space
hoelzl@38656
   554
    by auto
hoelzl@38656
   555
  from SUPR_countable_SUPR[OF this Q_not_empty]
hoelzl@38656
   556
  obtain Q'' where "range Q'' \<subseteq> \<mu> ` ?Q" and a: "?a = (SUP i::nat. Q'' i)"
hoelzl@38656
   557
    by auto
hoelzl@38656
   558
  then have "\<forall>i. \<exists>Q'. Q'' i = \<mu> Q' \<and> Q' \<in> ?Q" by auto
hoelzl@38656
   559
  from choice[OF this] obtain Q' where Q': "\<And>i. Q'' i = \<mu> (Q' i)" "\<And>i. Q' i \<in> ?Q"
hoelzl@38656
   560
    by auto
hoelzl@38656
   561
  then have a_Lim: "?a = (SUP i::nat. \<mu> (Q' i))" using a by simp
hoelzl@38656
   562
  let "?O n" = "\<Union>i\<le>n. Q' i"
hoelzl@38656
   563
  have Union: "(SUP i. \<mu> (?O i)) = \<mu> (\<Union>i. ?O i)"
hoelzl@38656
   564
  proof (rule continuity_from_below[of ?O])
hoelzl@38656
   565
    show "range ?O \<subseteq> sets M" using Q' by (auto intro!: finite_UN)
hoelzl@38656
   566
    show "\<And>i. ?O i \<subseteq> ?O (Suc i)" by fastsimp
hoelzl@38656
   567
  qed
hoelzl@38656
   568
  have Q'_sets: "\<And>i. Q' i \<in> sets M" using Q' by auto
hoelzl@38656
   569
  have O_sets: "\<And>i. ?O i \<in> sets M"
hoelzl@38656
   570
     using Q' by (auto intro!: finite_UN Un)
hoelzl@38656
   571
  then have O_in_G: "\<And>i. ?O i \<in> ?Q"
hoelzl@38656
   572
  proof (safe del: notI)
hoelzl@38656
   573
    fix i have "Q' ` {..i} \<subseteq> sets M"
hoelzl@38656
   574
      using Q' by (auto intro: finite_UN)
hoelzl@38656
   575
    with v.measure_finitely_subadditive[of "{.. i}" Q']
hoelzl@38656
   576
    have "\<nu> (?O i) \<le> (\<Sum>i\<le>i. \<nu> (Q' i))" by auto
hoelzl@41023
   577
    also have "\<dots> < \<omega>" unfolding setsum_\<omega> pextreal_less_\<omega> using Q' by auto
hoelzl@41023
   578
    finally show "\<nu> (?O i) \<noteq> \<omega>" unfolding pextreal_less_\<omega> by auto
hoelzl@38656
   579
  qed auto
hoelzl@38656
   580
  have O_mono: "\<And>n. ?O n \<subseteq> ?O (Suc n)" by fastsimp
hoelzl@38656
   581
  have a_eq: "?a = \<mu> (\<Union>i. ?O i)" unfolding Union[symmetric]
hoelzl@38656
   582
  proof (rule antisym)
hoelzl@38656
   583
    show "?a \<le> (SUP i. \<mu> (?O i))" unfolding a_Lim
hoelzl@38656
   584
      using Q' by (auto intro!: SUP_mono measure_mono finite_UN)
hoelzl@38656
   585
    show "(SUP i. \<mu> (?O i)) \<le> ?a" unfolding SUPR_def
hoelzl@38656
   586
    proof (safe intro!: Sup_mono, unfold bex_simps)
hoelzl@38656
   587
      fix i
hoelzl@38656
   588
      have *: "(\<Union>Q' ` {..i}) = ?O i" by auto
hoelzl@38656
   589
      then show "\<exists>x. (x \<in> sets M \<and> \<nu> x \<noteq> \<omega>) \<and>
hoelzl@38656
   590
        \<mu> (\<Union>Q' ` {..i}) \<le> \<mu> x"
hoelzl@38656
   591
        using O_in_G[of i] by (auto intro!: exI[of _ "?O i"])
hoelzl@38656
   592
    qed
hoelzl@38656
   593
  qed
hoelzl@38656
   594
  let "?O_0" = "(\<Union>i. ?O i)"
hoelzl@38656
   595
  have "?O_0 \<in> sets M" using Q' by auto
hoelzl@40859
   596
  def Q \<equiv> "\<lambda>i. case i of 0 \<Rightarrow> Q' 0 | Suc n \<Rightarrow> ?O (Suc n) - ?O n"
hoelzl@38656
   597
  { fix i have "Q i \<in> sets M" unfolding Q_def using Q'[of 0] by (cases i) (auto intro: O_sets) }
hoelzl@38656
   598
  note Q_sets = this
hoelzl@40859
   599
  show ?thesis
hoelzl@40859
   600
  proof (intro bexI exI conjI ballI impI allI)
hoelzl@40859
   601
    show "disjoint_family Q"
hoelzl@40859
   602
      by (fastsimp simp: disjoint_family_on_def Q_def
hoelzl@40859
   603
        split: nat.split_asm)
hoelzl@40859
   604
    show "range Q \<subseteq> sets M"
hoelzl@40859
   605
      using Q_sets by auto
hoelzl@40859
   606
    { fix A assume A: "A \<in> sets M" "A \<subseteq> space M - ?O_0"
hoelzl@40859
   607
      show "\<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<omega>"
hoelzl@40859
   608
      proof (rule disjCI, simp)
hoelzl@40859
   609
        assume *: "0 < \<mu> A \<longrightarrow> \<nu> A \<noteq> \<omega>"
hoelzl@40859
   610
        show "\<mu> A = 0 \<and> \<nu> A = 0"
hoelzl@40859
   611
        proof cases
hoelzl@40859
   612
          assume "\<mu> A = 0" moreover with ac A have "\<nu> A = 0"
hoelzl@40859
   613
            unfolding absolutely_continuous_def by auto
hoelzl@40859
   614
          ultimately show ?thesis by simp
hoelzl@40859
   615
        next
hoelzl@40859
   616
          assume "\<mu> A \<noteq> 0" with * have "\<nu> A \<noteq> \<omega>" by auto
hoelzl@40859
   617
          with A have "\<mu> ?O_0 + \<mu> A = \<mu> (?O_0 \<union> A)"
hoelzl@40859
   618
            using Q' by (auto intro!: measure_additive countable_UN)
hoelzl@40859
   619
          also have "\<dots> = (SUP i. \<mu> (?O i \<union> A))"
hoelzl@40859
   620
          proof (rule continuity_from_below[of "\<lambda>i. ?O i \<union> A", symmetric, simplified])
hoelzl@40859
   621
            show "range (\<lambda>i. ?O i \<union> A) \<subseteq> sets M"
hoelzl@40859
   622
              using `\<nu> A \<noteq> \<omega>` O_sets A by auto
hoelzl@40859
   623
          qed fastsimp
hoelzl@40859
   624
          also have "\<dots> \<le> ?a"
hoelzl@40859
   625
          proof (safe intro!: SUPR_bound)
hoelzl@40859
   626
            fix i have "?O i \<union> A \<in> ?Q"
hoelzl@40859
   627
            proof (safe del: notI)
hoelzl@40859
   628
              show "?O i \<union> A \<in> sets M" using O_sets A by auto
hoelzl@40859
   629
              from O_in_G[of i]
hoelzl@40859
   630
              moreover have "\<nu> (?O i \<union> A) \<le> \<nu> (?O i) + \<nu> A"
hoelzl@40859
   631
                using v.measure_subadditive[of "?O i" A] A O_sets by auto
hoelzl@40859
   632
              ultimately show "\<nu> (?O i \<union> A) \<noteq> \<omega>"
hoelzl@40859
   633
                using `\<nu> A \<noteq> \<omega>` by auto
hoelzl@40859
   634
            qed
hoelzl@40859
   635
            then show "\<mu> (?O i \<union> A) \<le> ?a" by (rule le_SUPI)
hoelzl@40859
   636
          qed
hoelzl@40859
   637
          finally have "\<mu> A = 0" unfolding a_eq using finite_measure[OF `?O_0 \<in> sets M`]
hoelzl@41023
   638
            by (cases "\<mu> A") (auto simp: pextreal_noteq_omega_Ex)
hoelzl@40859
   639
          with `\<mu> A \<noteq> 0` show ?thesis by auto
hoelzl@40859
   640
        qed
hoelzl@40859
   641
      qed }
hoelzl@40859
   642
    { fix i show "\<nu> (Q i) \<noteq> \<omega>"
hoelzl@40859
   643
      proof (cases i)
hoelzl@40859
   644
        case 0 then show ?thesis
hoelzl@40859
   645
          unfolding Q_def using Q'[of 0] by simp
hoelzl@40859
   646
      next
hoelzl@40859
   647
        case (Suc n)
hoelzl@40859
   648
        then show ?thesis unfolding Q_def
hoelzl@40859
   649
          using `?O n \<in> ?Q` `?O (Suc n) \<in> ?Q` O_mono
hoelzl@40859
   650
          using v.measure_Diff[of "?O n" "?O (Suc n)"] by auto
hoelzl@40859
   651
      qed }
hoelzl@40859
   652
    show "space M - ?O_0 \<in> sets M" using Q'_sets by auto
hoelzl@40859
   653
    { fix j have "(\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q i)"
hoelzl@40859
   654
      proof (induct j)
hoelzl@40859
   655
        case 0 then show ?case by (simp add: Q_def)
hoelzl@40859
   656
      next
hoelzl@40859
   657
        case (Suc j)
hoelzl@40859
   658
        have eq: "\<And>j. (\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q' i)" by fastsimp
hoelzl@40859
   659
        have "{..j} \<union> {..Suc j} = {..Suc j}" by auto
hoelzl@40859
   660
        then have "(\<Union>i\<le>Suc j. Q' i) = (\<Union>i\<le>j. Q' i) \<union> Q (Suc j)"
hoelzl@40859
   661
          by (simp add: UN_Un[symmetric] Q_def del: UN_Un)
hoelzl@40859
   662
        then show ?case using Suc by (auto simp add: eq atMost_Suc)
hoelzl@40859
   663
      qed }
hoelzl@40859
   664
    then have "(\<Union>j. (\<Union>i\<le>j. ?O i)) = (\<Union>j. (\<Union>i\<le>j. Q i))" by simp
hoelzl@40859
   665
    then show "space M - ?O_0 = space M - (\<Union>i. Q i)" by fastsimp
hoelzl@40859
   666
  qed
hoelzl@40859
   667
qed
hoelzl@40859
   668
hoelzl@40859
   669
lemma (in finite_measure) Radon_Nikodym_finite_measure_infinite:
hoelzl@40859
   670
  assumes "measure_space M \<nu>"
hoelzl@40859
   671
  assumes "absolutely_continuous \<nu>"
hoelzl@40859
   672
  shows "\<exists>f \<in> borel_measurable M. \<forall>A\<in>sets M. \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@40859
   673
proof -
hoelzl@40859
   674
  interpret v: measure_space M \<nu> by fact
hoelzl@40859
   675
  from split_space_into_finite_sets_and_rest[OF assms]
hoelzl@40859
   676
  obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
hoelzl@40859
   677
    where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
hoelzl@40859
   678
    and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
hoelzl@40859
   679
    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> \<mu> A = 0 \<and> \<nu> A = 0 \<or> 0 < \<mu> A \<and> \<nu> A = \<omega>"
hoelzl@40859
   680
    and Q_fin: "\<And>i. \<nu> (Q i) \<noteq> \<omega>" by force
hoelzl@40859
   681
  from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
hoelzl@38656
   682
  have "\<forall>i. \<exists>f. f\<in>borel_measurable M \<and> (\<forall>A\<in>sets M.
hoelzl@38656
   683
    \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f x * indicator (Q i \<inter> A) x))"
hoelzl@38656
   684
  proof
hoelzl@38656
   685
    fix i
hoelzl@41023
   686
    have indicator_eq: "\<And>f x A. (f x :: pextreal) * indicator (Q i \<inter> A) x * indicator (Q i) x
hoelzl@38656
   687
      = (f x * indicator (Q i) x) * indicator A x"
hoelzl@38656
   688
      unfolding indicator_def by auto
hoelzl@39092
   689
    have fm: "finite_measure (restricted_space (Q i)) \<mu>"
hoelzl@38656
   690
      (is "finite_measure ?R \<mu>") by (rule restricted_finite_measure[OF Q_sets[of i]])
hoelzl@38656
   691
    then interpret R: finite_measure ?R .
hoelzl@38656
   692
    have fmv: "finite_measure ?R \<nu>"
hoelzl@38656
   693
      unfolding finite_measure_def finite_measure_axioms_def
hoelzl@38656
   694
    proof
hoelzl@38656
   695
      show "measure_space ?R \<nu>"
hoelzl@38656
   696
        using v.restricted_measure_space Q_sets[of i] by auto
hoelzl@38656
   697
      show "\<nu>  (space ?R) \<noteq> \<omega>"
hoelzl@40859
   698
        using Q_fin by simp
hoelzl@38656
   699
    qed
hoelzl@38656
   700
    have "R.absolutely_continuous \<nu>"
hoelzl@38656
   701
      using `absolutely_continuous \<nu>` `Q i \<in> sets M`
hoelzl@38656
   702
      by (auto simp: R.absolutely_continuous_def absolutely_continuous_def)
hoelzl@38656
   703
    from finite_measure.Radon_Nikodym_finite_measure[OF fm fmv this]
hoelzl@38656
   704
    obtain f where f: "(\<lambda>x. f x * indicator (Q i) x) \<in> borel_measurable M"
hoelzl@38656
   705
      and f_int: "\<And>A. A\<in>sets M \<Longrightarrow> \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. (f x * indicator (Q i) x) * indicator A x)"
hoelzl@38656
   706
      unfolding Bex_def borel_measurable_restricted[OF `Q i \<in> sets M`]
hoelzl@38656
   707
        positive_integral_restricted[OF `Q i \<in> sets M`] by (auto simp: indicator_eq)
hoelzl@38656
   708
    then show "\<exists>f. f\<in>borel_measurable M \<and> (\<forall>A\<in>sets M.
hoelzl@38656
   709
      \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f x * indicator (Q i \<inter> A) x))"
hoelzl@38656
   710
      by (fastsimp intro!: exI[of _ "\<lambda>x. f x * indicator (Q i) x"] positive_integral_cong
hoelzl@38656
   711
          simp: indicator_def)
hoelzl@38656
   712
  qed
hoelzl@38656
   713
  from choice[OF this] obtain f where borel: "\<And>i. f i \<in> borel_measurable M"
hoelzl@38656
   714
    and f: "\<And>A i. A \<in> sets M \<Longrightarrow>
hoelzl@38656
   715
      \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f i x * indicator (Q i \<inter> A) x)"
hoelzl@38656
   716
    by auto
hoelzl@38656
   717
  let "?f x" =
hoelzl@40859
   718
    "(\<Sum>\<^isub>\<infinity> i. f i x * indicator (Q i) x) + \<omega> * indicator Q0 x"
hoelzl@38656
   719
  show ?thesis
hoelzl@38656
   720
  proof (safe intro!: bexI[of _ ?f])
hoelzl@38656
   721
    show "?f \<in> borel_measurable M"
hoelzl@41023
   722
      by (safe intro!: borel_measurable_psuminf borel_measurable_pextreal_times
hoelzl@41023
   723
        borel_measurable_pextreal_add borel_measurable_indicator
hoelzl@40859
   724
        borel_measurable_const borel Q_sets Q0 Diff countable_UN)
hoelzl@38656
   725
    fix A assume "A \<in> sets M"
hoelzl@40859
   726
    have *:
hoelzl@38656
   727
      "\<And>x i. indicator A x * (f i x * indicator (Q i) x) =
hoelzl@38656
   728
        f i x * indicator (Q i \<inter> A) x"
hoelzl@41023
   729
      "\<And>x i. (indicator A x * indicator Q0 x :: pextreal) =
hoelzl@40859
   730
        indicator (Q0 \<inter> A) x" by (auto simp: indicator_def)
hoelzl@38656
   731
    have "positive_integral (\<lambda>x. ?f x * indicator A x) =
hoelzl@40859
   732
      (\<Sum>\<^isub>\<infinity> i. \<nu> (Q i \<inter> A)) + \<omega> * \<mu> (Q0 \<inter> A)"
hoelzl@38656
   733
      unfolding f[OF `A \<in> sets M`]
hoelzl@41023
   734
      apply (simp del: pextreal_times(2) add: field_simps *)
hoelzl@38656
   735
      apply (subst positive_integral_add)
hoelzl@40859
   736
      apply (fastsimp intro: Q0 `A \<in> sets M`)
hoelzl@40859
   737
      apply (fastsimp intro: Q_sets `A \<in> sets M` borel_measurable_psuminf borel)
hoelzl@40859
   738
      apply (subst positive_integral_cmult_indicator)
hoelzl@40859
   739
      apply (fastsimp intro: Q0 `A \<in> sets M`)
hoelzl@38656
   740
      unfolding psuminf_cmult_right[symmetric]
hoelzl@38656
   741
      apply (subst positive_integral_psuminf)
hoelzl@40859
   742
      apply (fastsimp intro: `A \<in> sets M` Q_sets borel)
hoelzl@40859
   743
      apply (simp add: *)
hoelzl@40859
   744
      done
hoelzl@38656
   745
    moreover have "(\<Sum>\<^isub>\<infinity>i. \<nu> (Q i \<inter> A)) = \<nu> ((\<Union>i. Q i) \<inter> A)"
hoelzl@40859
   746
      using Q Q_sets `A \<in> sets M`
hoelzl@40859
   747
      by (intro v.measure_countably_additive[of "\<lambda>i. Q i \<inter> A", unfolded comp_def, simplified])
hoelzl@40859
   748
         (auto simp: disjoint_family_on_def)
hoelzl@40859
   749
    moreover have "\<omega> * \<mu> (Q0 \<inter> A) = \<nu> (Q0 \<inter> A)"
hoelzl@40859
   750
    proof -
hoelzl@40859
   751
      have "Q0 \<inter> A \<in> sets M" using Q0(1) `A \<in> sets M` by blast
hoelzl@40859
   752
      from in_Q0[OF this] show ?thesis by auto
hoelzl@38656
   753
    qed
hoelzl@40859
   754
    moreover have "Q0 \<inter> A \<in> sets M" "((\<Union>i. Q i) \<inter> A) \<in> sets M"
hoelzl@40859
   755
      using Q_sets `A \<in> sets M` Q0(1) by (auto intro!: countable_UN)
hoelzl@40859
   756
    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
   757
      using `A \<in> sets M` sets_into_space Q0 by auto
hoelzl@38656
   758
    ultimately show "\<nu> A = positive_integral (\<lambda>x. ?f x * indicator A x)"
hoelzl@40859
   759
      using v.measure_additive[simplified, of "(\<Union>i. Q i) \<inter> A" "Q0 \<inter> A"]
hoelzl@40859
   760
      by simp
hoelzl@38656
   761
  qed
hoelzl@38656
   762
qed
hoelzl@38656
   763
hoelzl@38656
   764
lemma (in sigma_finite_measure) Radon_Nikodym:
hoelzl@38656
   765
  assumes "measure_space M \<nu>"
hoelzl@38656
   766
  assumes "absolutely_continuous \<nu>"
hoelzl@38656
   767
  shows "\<exists>f \<in> borel_measurable M. \<forall>A\<in>sets M. \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   768
proof -
hoelzl@38656
   769
  from Ex_finite_integrable_function
hoelzl@38656
   770
  obtain h where finite: "positive_integral h \<noteq> \<omega>" and
hoelzl@38656
   771
    borel: "h \<in> borel_measurable M" and
hoelzl@38656
   772
    pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x" and
hoelzl@38656
   773
    "\<And>x. x \<in> space M \<Longrightarrow> h x < \<omega>" by auto
hoelzl@38656
   774
  let "?T A" = "positive_integral (\<lambda>x. h x * indicator A x)"
hoelzl@38656
   775
  from measure_space_density[OF borel] finite
hoelzl@38656
   776
  interpret T: finite_measure M ?T
hoelzl@38656
   777
    unfolding finite_measure_def finite_measure_axioms_def
hoelzl@38656
   778
    by (simp cong: positive_integral_cong)
hoelzl@41023
   779
  have "\<And>N. N \<in> sets M \<Longrightarrow> {x \<in> space M. h x \<noteq> 0 \<and> indicator N x \<noteq> (0::pextreal)} = N"
hoelzl@38656
   780
    using sets_into_space pos by (force simp: indicator_def)
hoelzl@38656
   781
  then have "T.absolutely_continuous \<nu>" using assms(2) borel
hoelzl@38656
   782
    unfolding T.absolutely_continuous_def absolutely_continuous_def
hoelzl@38656
   783
    by (fastsimp simp: borel_measurable_indicator positive_integral_0_iff)
hoelzl@38656
   784
  from T.Radon_Nikodym_finite_measure_infinite[simplified, OF assms(1) this]
hoelzl@38656
   785
  obtain f where f_borel: "f \<in> borel_measurable M" and
hoelzl@38656
   786
    fT: "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = T.positive_integral (\<lambda>x. f x * indicator A x)" by auto
hoelzl@38656
   787
  show ?thesis
hoelzl@38656
   788
  proof (safe intro!: bexI[of _ "\<lambda>x. h x * f x"])
hoelzl@38656
   789
    show "(\<lambda>x. h x * f x) \<in> borel_measurable M"
hoelzl@41023
   790
      using borel f_borel by (auto intro: borel_measurable_pextreal_times)
hoelzl@38656
   791
    fix A assume "A \<in> sets M"
hoelzl@38656
   792
    then have "(\<lambda>x. f x * indicator A x) \<in> borel_measurable M"
hoelzl@41023
   793
      using f_borel by (auto intro: borel_measurable_pextreal_times borel_measurable_indicator)
hoelzl@38656
   794
    from positive_integral_translated_density[OF borel this]
hoelzl@38656
   795
    show "\<nu> A = positive_integral (\<lambda>x. h x * f x * indicator A x)"
hoelzl@38656
   796
      unfolding fT[OF `A \<in> sets M`] by (simp add: field_simps)
hoelzl@38656
   797
  qed
hoelzl@38656
   798
qed
hoelzl@38656
   799
hoelzl@40859
   800
section "Uniqueness of densities"
hoelzl@40859
   801
hoelzl@40859
   802
lemma (in measure_space) finite_density_unique:
hoelzl@40859
   803
  assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@40859
   804
  and fin: "positive_integral f < \<omega>"
hoelzl@40859
   805
  shows "(\<forall>A\<in>sets M. positive_integral (\<lambda>x. f x * indicator A x) = positive_integral (\<lambda>x. g x * indicator A x))
hoelzl@40859
   806
    \<longleftrightarrow> (AE x. f x = g x)"
hoelzl@40859
   807
    (is "(\<forall>A\<in>sets M. ?P f A = ?P g A) \<longleftrightarrow> _")
hoelzl@40859
   808
proof (intro iffI ballI)
hoelzl@40859
   809
  fix A assume eq: "AE x. f x = g x"
hoelzl@40859
   810
  show "?P f A = ?P g A"
hoelzl@40859
   811
    by (rule positive_integral_cong_AE[OF AE_mp[OF eq]]) simp
hoelzl@40859
   812
next
hoelzl@40859
   813
  assume eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
hoelzl@40859
   814
  from this[THEN bspec, OF top] fin
hoelzl@40859
   815
  have g_fin: "positive_integral g < \<omega>" by (simp cong: positive_integral_cong)
hoelzl@40859
   816
  { fix f g assume borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@40859
   817
      and g_fin: "positive_integral g < \<omega>" and eq: "\<forall>A\<in>sets M. ?P f A = ?P g A"
hoelzl@40859
   818
    let ?N = "{x\<in>space M. g x < f x}"
hoelzl@40859
   819
    have N: "?N \<in> sets M" using borel by simp
hoelzl@40859
   820
    have "?P (\<lambda>x. (f x - g x)) ?N = positive_integral (\<lambda>x. f x * indicator ?N x - g x * indicator ?N x)"
hoelzl@40859
   821
      by (auto intro!: positive_integral_cong simp: indicator_def)
hoelzl@40859
   822
    also have "\<dots> = ?P f ?N - ?P g ?N"
hoelzl@40859
   823
    proof (rule positive_integral_diff)
hoelzl@40859
   824
      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
   825
        using borel N by auto
hoelzl@40859
   826
      have "?P g ?N \<le> positive_integral g"
hoelzl@40859
   827
        by (auto intro!: positive_integral_mono simp: indicator_def)
hoelzl@40859
   828
      then show "?P g ?N \<noteq> \<omega>" using g_fin by auto
hoelzl@40859
   829
      fix x assume "x \<in> space M"
hoelzl@40859
   830
      show "g x * indicator ?N x \<le> f x * indicator ?N x"
hoelzl@40859
   831
        by (auto simp: indicator_def)
hoelzl@40859
   832
    qed
hoelzl@40859
   833
    also have "\<dots> = 0"
hoelzl@40859
   834
      using eq[THEN bspec, OF N] by simp
hoelzl@40859
   835
    finally have "\<mu> {x\<in>space M. (f x - g x) * indicator ?N x \<noteq> 0} = 0"
hoelzl@40859
   836
      using borel N by (subst (asm) positive_integral_0_iff) auto
hoelzl@40859
   837
    moreover have "{x\<in>space M. (f x - g x) * indicator ?N x \<noteq> 0} = ?N"
hoelzl@41023
   838
      by (auto simp: pextreal_zero_le_diff)
hoelzl@40859
   839
    ultimately have "?N \<in> null_sets" using N by simp }
hoelzl@40859
   840
  from this[OF borel g_fin eq] this[OF borel(2,1) fin]
hoelzl@40859
   841
  have "{x\<in>space M. g x < f x} \<union> {x\<in>space M. f x < g x} \<in> null_sets"
hoelzl@40859
   842
    using eq by (intro null_sets_Un) auto
hoelzl@40859
   843
  also have "{x\<in>space M. g x < f x} \<union> {x\<in>space M. f x < g x} = {x\<in>space M. f x \<noteq> g x}"
hoelzl@40859
   844
    by auto
hoelzl@40859
   845
  finally show "AE x. f x = g x"
hoelzl@40859
   846
    unfolding almost_everywhere_def by auto
hoelzl@40859
   847
qed
hoelzl@40859
   848
hoelzl@40859
   849
lemma (in finite_measure) density_unique_finite_measure:
hoelzl@40859
   850
  assumes borel: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
hoelzl@40859
   851
  assumes f: "\<And>A. A \<in> sets M \<Longrightarrow> positive_integral (\<lambda>x. f x * indicator A x) = positive_integral (\<lambda>x. f' x * indicator A x)"
hoelzl@40859
   852
    (is "\<And>A. A \<in> sets M \<Longrightarrow> ?P f A = ?P f' A")
hoelzl@40859
   853
  shows "AE x. f x = f' x"
hoelzl@40859
   854
proof -
hoelzl@40859
   855
  let "?\<nu> A" = "?P f A" and "?\<nu>' A" = "?P f' A"
hoelzl@40859
   856
  let "?f A x" = "f x * indicator A x" and "?f' A x" = "f' x * indicator A x"
hoelzl@40859
   857
  interpret M: measure_space M ?\<nu>
hoelzl@40859
   858
    using borel(1) by (rule measure_space_density)
hoelzl@40859
   859
  have ac: "absolutely_continuous ?\<nu>"
hoelzl@40859
   860
    using f by (rule density_is_absolutely_continuous)
hoelzl@40859
   861
  from split_space_into_finite_sets_and_rest[OF `measure_space M ?\<nu>` ac]
hoelzl@40859
   862
  obtain Q0 and Q :: "nat \<Rightarrow> 'a set"
hoelzl@40859
   863
    where Q: "disjoint_family Q" "range Q \<subseteq> sets M"
hoelzl@40859
   864
    and Q0: "Q0 \<in> sets M" "Q0 = space M - (\<Union>i. Q i)"
hoelzl@40859
   865
    and in_Q0: "\<And>A. A \<in> sets M \<Longrightarrow> A \<subseteq> Q0 \<Longrightarrow> \<mu> A = 0 \<and> ?\<nu> A = 0 \<or> 0 < \<mu> A \<and> ?\<nu> A = \<omega>"
hoelzl@40859
   866
    and Q_fin: "\<And>i. ?\<nu> (Q i) \<noteq> \<omega>" by force
hoelzl@40859
   867
  from Q have Q_sets: "\<And>i. Q i \<in> sets M" by auto
hoelzl@40859
   868
  let ?N = "{x\<in>space M. f x \<noteq> f' x}"
hoelzl@40859
   869
  have "?N \<in> sets M" using borel by auto
hoelzl@41023
   870
  have *: "\<And>i x A. \<And>y::pextreal. y * indicator (Q i) x * indicator A x = y * indicator (Q i \<inter> A) x"
hoelzl@40859
   871
    unfolding indicator_def by auto
hoelzl@40859
   872
  have 1: "\<forall>i. AE x. ?f (Q i) x = ?f' (Q i) x"
hoelzl@40859
   873
    using borel Q_fin Q
hoelzl@40859
   874
    by (intro finite_density_unique[THEN iffD1] allI)
hoelzl@41023
   875
       (auto intro!: borel_measurable_pextreal_times f Int simp: *)
hoelzl@40859
   876
  have 2: "AE x. ?f Q0 x = ?f' Q0 x"
hoelzl@40859
   877
  proof (rule AE_I')
hoelzl@41023
   878
    { fix f :: "'a \<Rightarrow> pextreal" assume borel: "f \<in> borel_measurable M"
hoelzl@40859
   879
        and eq: "\<And>A. A \<in> sets M \<Longrightarrow> ?\<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@40859
   880
      let "?A i" = "Q0 \<inter> {x \<in> space M. f x < of_nat i}"
hoelzl@40859
   881
      have "(\<Union>i. ?A i) \<in> null_sets"
hoelzl@40859
   882
      proof (rule null_sets_UN)
hoelzl@40859
   883
        fix i have "?A i \<in> sets M"
hoelzl@40859
   884
          using borel Q0(1) by auto
hoelzl@40859
   885
        have "?\<nu> (?A i) \<le> positive_integral (\<lambda>x. of_nat i * indicator (?A i) x)"
hoelzl@40859
   886
          unfolding eq[OF `?A i \<in> sets M`]
hoelzl@40859
   887
          by (auto intro!: positive_integral_mono simp: indicator_def)
hoelzl@40859
   888
        also have "\<dots> = of_nat i * \<mu> (?A i)"
hoelzl@40859
   889
          using `?A i \<in> sets M` by (auto intro!: positive_integral_cmult_indicator)
hoelzl@40859
   890
        also have "\<dots> < \<omega>"
hoelzl@40859
   891
          using `?A i \<in> sets M`[THEN finite_measure] by auto
hoelzl@40859
   892
        finally have "?\<nu> (?A i) \<noteq> \<omega>" by simp
hoelzl@40859
   893
        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
   894
      qed
hoelzl@40859
   895
      also have "(\<Union>i. ?A i) = Q0 \<inter> {x\<in>space M. f x < \<omega>}"
hoelzl@40859
   896
        by (auto simp: less_\<omega>_Ex_of_nat)
hoelzl@41023
   897
      finally have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>} \<in> null_sets" by (simp add: pextreal_less_\<omega>) }
hoelzl@40859
   898
    from this[OF borel(1) refl] this[OF borel(2) f]
hoelzl@40859
   899
    have "Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>} \<in> null_sets" "Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>} \<in> null_sets" by simp_all
hoelzl@40859
   900
    then show "(Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>}) \<union> (Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>}) \<in> null_sets" by (rule null_sets_Un)
hoelzl@40859
   901
    show "{x \<in> space M. ?f Q0 x \<noteq> ?f' Q0 x} \<subseteq>
hoelzl@40859
   902
      (Q0 \<inter> {x\<in>space M. f x \<noteq> \<omega>}) \<union> (Q0 \<inter> {x\<in>space M. f' x \<noteq> \<omega>})" by (auto simp: indicator_def)
hoelzl@40859
   903
  qed
hoelzl@40859
   904
  have **: "\<And>x. (?f Q0 x = ?f' Q0 x) \<longrightarrow> (\<forall>i. ?f (Q i) x = ?f' (Q i) x) \<longrightarrow>
hoelzl@40859
   905
    ?f (space M) x = ?f' (space M) x"
hoelzl@40859
   906
    by (auto simp: indicator_def Q0)
hoelzl@40859
   907
  have 3: "AE x. ?f (space M) x = ?f' (space M) x"
hoelzl@40859
   908
    by (rule AE_mp[OF 1[unfolded all_AE_countable] AE_mp[OF 2]]) (simp add: **)
hoelzl@40859
   909
  then show "AE x. f x = f' x"
hoelzl@40859
   910
    by (rule AE_mp) (auto intro!: AE_cong simp: indicator_def)
hoelzl@40859
   911
qed
hoelzl@40859
   912
hoelzl@40859
   913
lemma (in sigma_finite_measure) density_unique:
hoelzl@40859
   914
  assumes borel: "f \<in> borel_measurable M" "f' \<in> borel_measurable M"
hoelzl@40859
   915
  assumes f: "\<And>A. A \<in> sets M \<Longrightarrow> positive_integral (\<lambda>x. f x * indicator A x) = positive_integral (\<lambda>x. f' x * indicator A x)"
hoelzl@40859
   916
    (is "\<And>A. A \<in> sets M \<Longrightarrow> ?P f A = ?P f' A")
hoelzl@40859
   917
  shows "AE x. f x = f' x"
hoelzl@40859
   918
proof -
hoelzl@40859
   919
  obtain h where h_borel: "h \<in> borel_measurable M"
hoelzl@40859
   920
    and fin: "positive_integral h \<noteq> \<omega>" and pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x \<and> h x < \<omega>"
hoelzl@40859
   921
    using Ex_finite_integrable_function by auto
hoelzl@40859
   922
  interpret h: measure_space M "\<lambda>A. positive_integral (\<lambda>x. h x * indicator A x)"
hoelzl@40859
   923
    using h_borel by (rule measure_space_density)
hoelzl@40859
   924
  interpret h: finite_measure M "\<lambda>A. positive_integral (\<lambda>x. h x * indicator A x)"
hoelzl@40859
   925
    by default (simp cong: positive_integral_cong add: fin)
hoelzl@40859
   926
  interpret f: measure_space M "\<lambda>A. positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@40859
   927
    using borel(1) by (rule measure_space_density)
hoelzl@40859
   928
  interpret f': measure_space M "\<lambda>A. positive_integral (\<lambda>x. f' x * indicator A x)"
hoelzl@40859
   929
    using borel(2) by (rule measure_space_density)
hoelzl@40859
   930
  { fix A assume "A \<in> sets M"
hoelzl@41023
   931
    then have " {x \<in> space M. h x \<noteq> 0 \<and> indicator A x \<noteq> (0::pextreal)} = A"
hoelzl@40859
   932
      using pos sets_into_space by (force simp: indicator_def)
hoelzl@40859
   933
    then have "positive_integral (\<lambda>xa. h xa * indicator A xa) = 0 \<longleftrightarrow> A \<in> null_sets"
hoelzl@40859
   934
      using h_borel `A \<in> sets M` by (simp add: positive_integral_0_iff) }
hoelzl@40859
   935
  note h_null_sets = this
hoelzl@40859
   936
  { fix A assume "A \<in> sets M"
hoelzl@40859
   937
    have "positive_integral (\<lambda>x. h x * (f x * indicator A x)) =
hoelzl@40859
   938
      f.positive_integral (\<lambda>x. h x * indicator A x)"
hoelzl@40859
   939
      using `A \<in> sets M` h_borel borel
hoelzl@40859
   940
      by (simp add: positive_integral_translated_density ac_simps cong: positive_integral_cong)
hoelzl@40859
   941
    also have "\<dots> = f'.positive_integral (\<lambda>x. h x * indicator A x)"
hoelzl@40859
   942
      by (rule f'.positive_integral_cong_measure) (rule f)
hoelzl@40859
   943
    also have "\<dots> = positive_integral (\<lambda>x. h x * (f' x * indicator A x))"
hoelzl@40859
   944
      using `A \<in> sets M` h_borel borel
hoelzl@40859
   945
      by (simp add: positive_integral_translated_density ac_simps cong: positive_integral_cong)
hoelzl@40859
   946
    finally have "positive_integral (\<lambda>x. h x * (f x * indicator A x)) = positive_integral (\<lambda>x. h x * (f' x * indicator A x))" . }
hoelzl@40859
   947
  then have "h.almost_everywhere (\<lambda>x. f x = f' x)"
hoelzl@40859
   948
    using h_borel borel
hoelzl@40859
   949
    by (intro h.density_unique_finite_measure[OF borel])
hoelzl@40859
   950
       (simp add: positive_integral_translated_density)
hoelzl@40859
   951
  then show "AE x. f x = f' x"
hoelzl@40859
   952
    unfolding h.almost_everywhere_def almost_everywhere_def
hoelzl@40859
   953
    by (auto simp add: h_null_sets)
hoelzl@40859
   954
qed
hoelzl@40859
   955
hoelzl@40859
   956
lemma (in sigma_finite_measure) sigma_finite_iff_density_finite:
hoelzl@40859
   957
  assumes \<nu>: "measure_space M \<nu>" and f: "f \<in> borel_measurable M"
hoelzl@40859
   958
    and eq: "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@40859
   959
  shows "sigma_finite_measure M \<nu> \<longleftrightarrow> (AE x. f x \<noteq> \<omega>)"
hoelzl@40859
   960
proof
hoelzl@40859
   961
  assume "sigma_finite_measure M \<nu>"
hoelzl@40859
   962
  then interpret \<nu>: sigma_finite_measure M \<nu> .
hoelzl@40859
   963
  from \<nu>.Ex_finite_integrable_function obtain h where
hoelzl@40859
   964
    h: "h \<in> borel_measurable M" "\<nu>.positive_integral h \<noteq> \<omega>"
hoelzl@40859
   965
    and fin: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x \<and> h x < \<omega>" by auto
hoelzl@40859
   966
  have "AE x. f x * h x \<noteq> \<omega>"
hoelzl@40859
   967
  proof (rule AE_I')
hoelzl@40859
   968
    have "\<nu>.positive_integral h = positive_integral (\<lambda>x. f x * h x)"
hoelzl@40859
   969
      by (simp add: \<nu>.positive_integral_cong_measure[symmetric, OF eq[symmetric]])
hoelzl@40859
   970
         (intro positive_integral_translated_density f h)
hoelzl@40859
   971
    then have "positive_integral (\<lambda>x. f x * h x) \<noteq> \<omega>"
hoelzl@40859
   972
      using h(2) by simp
hoelzl@40859
   973
    then show "(\<lambda>x. f x * h x) -` {\<omega>} \<inter> space M \<in> null_sets"
hoelzl@40859
   974
      using f h(1) by (auto intro!: positive_integral_omega borel_measurable_vimage)
hoelzl@40859
   975
  qed auto
hoelzl@40859
   976
  then show "AE x. f x \<noteq> \<omega>"
hoelzl@40859
   977
  proof (rule AE_mp, intro AE_cong)
hoelzl@40859
   978
    fix x assume "x \<in> space M" from this[THEN fin]
hoelzl@40859
   979
    show "f x * h x \<noteq> \<omega> \<longrightarrow> f x \<noteq> \<omega>" by auto
hoelzl@40859
   980
  qed
hoelzl@40859
   981
next
hoelzl@40859
   982
  assume AE: "AE x. f x \<noteq> \<omega>"
hoelzl@40859
   983
  from sigma_finite guess Q .. note Q = this
hoelzl@40859
   984
  interpret \<nu>: measure_space M \<nu> by fact
hoelzl@40859
   985
  def A \<equiv> "\<lambda>i. f -` (case i of 0 \<Rightarrow> {\<omega>} | Suc n \<Rightarrow> {.. of_nat (Suc n)}) \<inter> space M"
hoelzl@40859
   986
  { fix i j have "A i \<inter> Q j \<in> sets M"
hoelzl@40859
   987
    unfolding A_def using f Q
hoelzl@40859
   988
    apply (rule_tac Int)
hoelzl@40859
   989
    by (cases i) (auto intro: measurable_sets[OF f]) }
hoelzl@40859
   990
  note A_in_sets = this
hoelzl@40859
   991
  let "?A n" = "case prod_decode n of (i,j) \<Rightarrow> A i \<inter> Q j"
hoelzl@40859
   992
  show "sigma_finite_measure M \<nu>"
hoelzl@40859
   993
  proof (default, intro exI conjI subsetI allI)
hoelzl@40859
   994
    fix x assume "x \<in> range ?A"
hoelzl@40859
   995
    then obtain n where n: "x = ?A n" by auto
hoelzl@40859
   996
    then show "x \<in> sets M" using A_in_sets by (cases "prod_decode n") auto
hoelzl@40859
   997
  next
hoelzl@40859
   998
    have "(\<Union>i. ?A i) = (\<Union>i j. A i \<inter> Q j)"
hoelzl@40859
   999
    proof safe
hoelzl@40859
  1000
      fix x i j assume "x \<in> A i" "x \<in> Q j"
hoelzl@40859
  1001
      then show "x \<in> (\<Union>i. case prod_decode i of (i, j) \<Rightarrow> A i \<inter> Q j)"
hoelzl@40859
  1002
        by (intro UN_I[of "prod_encode (i,j)"]) auto
hoelzl@40859
  1003
    qed auto
hoelzl@40859
  1004
    also have "\<dots> = (\<Union>i. A i) \<inter> space M" using Q by auto
hoelzl@40859
  1005
    also have "(\<Union>i. A i) = space M"
hoelzl@40859
  1006
    proof safe
hoelzl@40859
  1007
      fix x assume x: "x \<in> space M"
hoelzl@40859
  1008
      show "x \<in> (\<Union>i. A i)"
hoelzl@40859
  1009
      proof (cases "f x")
hoelzl@40859
  1010
        case infinite then show ?thesis using x unfolding A_def by (auto intro: exI[of _ 0])
hoelzl@40859
  1011
      next
hoelzl@40859
  1012
        case (preal r)
hoelzl@40859
  1013
        with less_\<omega>_Ex_of_nat[of "f x"] obtain n where "f x < of_nat n" by auto
hoelzl@40859
  1014
        then show ?thesis using x preal unfolding A_def by (auto intro!: exI[of _ "Suc n"])
hoelzl@40859
  1015
      qed
hoelzl@40859
  1016
    qed (auto simp: A_def)
hoelzl@40859
  1017
    finally show "(\<Union>i. ?A i) = space M" by simp
hoelzl@40859
  1018
  next
hoelzl@40859
  1019
    fix n obtain i j where
hoelzl@40859
  1020
      [simp]: "prod_decode n = (i, j)" by (cases "prod_decode n") auto
hoelzl@40859
  1021
    have "positive_integral (\<lambda>x. f x * indicator (A i \<inter> Q j) x) \<noteq> \<omega>"
hoelzl@40859
  1022
    proof (cases i)
hoelzl@40859
  1023
      case 0
hoelzl@40859
  1024
      have "AE x. f x * indicator (A i \<inter> Q j) x = 0"
hoelzl@40859
  1025
        using AE by (rule AE_mp) (auto intro!: AE_cong simp: A_def `i = 0`)
hoelzl@40859
  1026
      then have "positive_integral (\<lambda>x. f x * indicator (A i \<inter> Q j) x) = 0"
hoelzl@40859
  1027
        using A_in_sets f
hoelzl@40859
  1028
        apply (subst positive_integral_0_iff)
hoelzl@40859
  1029
        apply fast
hoelzl@40859
  1030
        apply (subst (asm) AE_iff_null_set)
hoelzl@41023
  1031
        apply (intro borel_measurable_pextreal_neq_const)
hoelzl@40859
  1032
        apply fast
hoelzl@40859
  1033
        by simp
hoelzl@40859
  1034
      then show ?thesis by simp
hoelzl@40859
  1035
    next
hoelzl@40859
  1036
      case (Suc n)
hoelzl@40859
  1037
      then have "positive_integral (\<lambda>x. f x * indicator (A i \<inter> Q j) x) \<le>
hoelzl@40859
  1038
        positive_integral (\<lambda>x. of_nat (Suc n) * indicator (Q j) x)"
hoelzl@40859
  1039
        by (auto intro!: positive_integral_mono simp: indicator_def A_def)
hoelzl@40859
  1040
      also have "\<dots> = of_nat (Suc n) * \<mu> (Q j)"
hoelzl@40859
  1041
        using Q by (auto intro!: positive_integral_cmult_indicator)
hoelzl@40859
  1042
      also have "\<dots> < \<omega>"
hoelzl@40859
  1043
        using Q by auto
hoelzl@40859
  1044
      finally show ?thesis by simp
hoelzl@40859
  1045
    qed
hoelzl@40859
  1046
    then show "\<nu> (?A n) \<noteq> \<omega>"
hoelzl@40859
  1047
      using A_in_sets Q eq by auto
hoelzl@40859
  1048
  qed
hoelzl@40859
  1049
qed
hoelzl@40859
  1050
hoelzl@40871
  1051
section "Radon-Nikodym derivative"
hoelzl@38656
  1052
hoelzl@38656
  1053
definition (in sigma_finite_measure)
hoelzl@38656
  1054
  "RN_deriv \<nu> \<equiv> SOME f. f \<in> borel_measurable M \<and>
hoelzl@38656
  1055
    (\<forall>A \<in> sets M. \<nu> A = positive_integral (\<lambda>x. f x * indicator A x))"
hoelzl@38656
  1056
hoelzl@40859
  1057
lemma (in sigma_finite_measure) RN_deriv_cong:
hoelzl@40859
  1058
  assumes cong: "\<And>A. A \<in> sets M \<Longrightarrow> \<mu>' A = \<mu> A" "\<And>A. A \<in> sets M \<Longrightarrow> \<nu>' A = \<nu> A"
hoelzl@40859
  1059
  shows "sigma_finite_measure.RN_deriv M \<mu>' \<nu>' x = RN_deriv \<nu> x"
hoelzl@40859
  1060
proof -
hoelzl@40859
  1061
  interpret \<mu>': sigma_finite_measure M \<mu>'
hoelzl@40859
  1062
    using cong(1) by (rule sigma_finite_measure_cong)
hoelzl@40859
  1063
  show ?thesis
hoelzl@40859
  1064
    unfolding RN_deriv_def \<mu>'.RN_deriv_def
hoelzl@40859
  1065
    by (simp add: cong positive_integral_cong_measure[OF cong(1)])
hoelzl@40859
  1066
qed
hoelzl@40859
  1067
hoelzl@38656
  1068
lemma (in sigma_finite_measure) RN_deriv:
hoelzl@38656
  1069
  assumes "measure_space M \<nu>"
hoelzl@38656
  1070
  assumes "absolutely_continuous \<nu>"
hoelzl@38656
  1071
  shows "RN_deriv \<nu> \<in> borel_measurable M" (is ?borel)
hoelzl@38656
  1072
  and "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = positive_integral (\<lambda>x. RN_deriv \<nu> x * indicator A x)"
hoelzl@38656
  1073
    (is "\<And>A. _ \<Longrightarrow> ?int A")
hoelzl@38656
  1074
proof -
hoelzl@38656
  1075
  note Ex = Radon_Nikodym[OF assms, unfolded Bex_def]
hoelzl@38656
  1076
  thus ?borel unfolding RN_deriv_def by (rule someI2_ex) auto
hoelzl@38656
  1077
  fix A assume "A \<in> sets M"
hoelzl@38656
  1078
  from Ex show "?int A" unfolding RN_deriv_def
hoelzl@38656
  1079
    by (rule someI2_ex) (simp add: `A \<in> sets M`)
hoelzl@38656
  1080
qed
hoelzl@38656
  1081
hoelzl@40859
  1082
lemma (in sigma_finite_measure) RN_deriv_positive_integral:
hoelzl@40859
  1083
  assumes \<nu>: "measure_space M \<nu>" "absolutely_continuous \<nu>"
hoelzl@40859
  1084
    and f: "f \<in> borel_measurable M"
hoelzl@40859
  1085
  shows "measure_space.positive_integral M \<nu> f = positive_integral (\<lambda>x. RN_deriv \<nu> x * f x)"
hoelzl@40859
  1086
proof -
hoelzl@40859
  1087
  interpret \<nu>: measure_space M \<nu> by fact
hoelzl@40859
  1088
  have "\<nu>.positive_integral f =
hoelzl@40859
  1089
    measure_space.positive_integral M (\<lambda>A. positive_integral (\<lambda>x. RN_deriv \<nu> x * indicator A x)) f"
hoelzl@40859
  1090
    by (intro \<nu>.positive_integral_cong_measure[symmetric] RN_deriv(2)[OF \<nu>, symmetric])
hoelzl@40859
  1091
  also have "\<dots> = positive_integral (\<lambda>x. RN_deriv \<nu> x * f x)"
hoelzl@40859
  1092
    by (intro positive_integral_translated_density RN_deriv[OF \<nu>] f)
hoelzl@40859
  1093
  finally show ?thesis .
hoelzl@40859
  1094
qed
hoelzl@40859
  1095
hoelzl@40859
  1096
lemma (in sigma_finite_measure) RN_deriv_unique:
hoelzl@40859
  1097
  assumes \<nu>: "measure_space M \<nu>" "absolutely_continuous \<nu>"
hoelzl@40859
  1098
  and f: "f \<in> borel_measurable M"
hoelzl@40859
  1099
  and eq: "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@40859
  1100
  shows "AE x. f x = RN_deriv \<nu> x"
hoelzl@40859
  1101
proof (rule density_unique[OF f RN_deriv(1)[OF \<nu>]])
hoelzl@40859
  1102
  fix A assume A: "A \<in> sets M"
hoelzl@40859
  1103
  show "positive_integral (\<lambda>x. f x * indicator A x) = positive_integral (\<lambda>x. RN_deriv \<nu> x * indicator A x)"
hoelzl@40859
  1104
    unfolding eq[OF A, symmetric] RN_deriv(2)[OF \<nu> A, symmetric] ..
hoelzl@40859
  1105
qed
hoelzl@40859
  1106
hoelzl@40859
  1107
lemma (in sigma_finite_measure) RN_deriv_vimage:
hoelzl@40859
  1108
  fixes f :: "'b \<Rightarrow> 'a"
hoelzl@41095
  1109
  assumes f: "bij_inv S (space M) f g"
hoelzl@40859
  1110
  assumes \<nu>: "measure_space M \<nu>" "absolutely_continuous \<nu>"
hoelzl@40859
  1111
  shows "AE x.
hoelzl@41095
  1112
    sigma_finite_measure.RN_deriv (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A)) (\<lambda>A. \<nu> (f ` A)) (g x) = RN_deriv \<nu> x"
hoelzl@40859
  1113
proof (rule RN_deriv_unique[OF \<nu>])
hoelzl@40859
  1114
  interpret sf: sigma_finite_measure "vimage_algebra S f" "\<lambda>A. \<mu> (f ` A)"
hoelzl@41095
  1115
    using f by (rule sigma_finite_measure_isomorphic[OF bij_inv_bij_betw(1)])
hoelzl@40859
  1116
  interpret \<nu>: measure_space M \<nu> using \<nu>(1) .
hoelzl@40859
  1117
  have \<nu>': "measure_space (vimage_algebra S f) (\<lambda>A. \<nu> (f ` A))"
hoelzl@41095
  1118
    using f by (rule \<nu>.measure_space_isomorphic[OF bij_inv_bij_betw(1)])
hoelzl@40859
  1119
  { fix A assume "A \<in> sets M" then have "f ` (f -` A \<inter> S) = A"
hoelzl@41095
  1120
      using sets_into_space f[THEN bij_inv_bij_betw(1), unfolded bij_betw_def]
hoelzl@40859
  1121
      by (intro image_vimage_inter_eq[where T="space M"]) auto }
hoelzl@40859
  1122
  note A_f = this
hoelzl@40859
  1123
  then have ac: "sf.absolutely_continuous (\<lambda>A. \<nu> (f ` A))"
hoelzl@40859
  1124
    using \<nu>(2) by (auto simp: sf.absolutely_continuous_def absolutely_continuous_def)
hoelzl@41095
  1125
  show "(\<lambda>x. sf.RN_deriv (\<lambda>A. \<nu> (f ` A)) (g x)) \<in> borel_measurable M"
hoelzl@40859
  1126
    using sf.RN_deriv(1)[OF \<nu>' ac]
hoelzl@40859
  1127
    unfolding measurable_vimage_iff_inv[OF f] comp_def .
hoelzl@40859
  1128
  fix A assume "A \<in> sets M"
hoelzl@41095
  1129
  then have *: "\<And>x. x \<in> space M \<Longrightarrow> indicator (f -` A \<inter> S) (g x) = (indicator A x :: pextreal)"
hoelzl@41095
  1130
    using f by (auto simp: bij_inv_def indicator_def)
hoelzl@40859
  1131
  have "\<nu> (f ` (f -` A \<inter> S)) = sf.positive_integral (\<lambda>x. sf.RN_deriv (\<lambda>A. \<nu> (f ` A)) x * indicator (f -` A \<inter> S) x)"
hoelzl@40859
  1132
    using `A \<in> sets M` by (force intro!: sf.RN_deriv(2)[OF \<nu>' ac])
hoelzl@41095
  1133
  also have "\<dots> = positive_integral (\<lambda>x. sf.RN_deriv (\<lambda>A. \<nu> (f ` A)) (g x) * indicator A x)"
hoelzl@40859
  1134
    unfolding positive_integral_vimage_inv[OF f]
hoelzl@40859
  1135
    by (simp add: * cong: positive_integral_cong)
hoelzl@41095
  1136
  finally show "\<nu> A = positive_integral (\<lambda>x. sf.RN_deriv (\<lambda>A. \<nu> (f ` A)) (g x) * indicator A x)"
hoelzl@40859
  1137
    unfolding A_f[OF `A \<in> sets M`] .
hoelzl@40859
  1138
qed
hoelzl@40859
  1139
hoelzl@40859
  1140
lemma (in sigma_finite_measure) RN_deriv_finite:
hoelzl@40859
  1141
  assumes sfm: "sigma_finite_measure M \<nu>" and ac: "absolutely_continuous \<nu>"
hoelzl@40859
  1142
  shows "AE x. RN_deriv \<nu> x \<noteq> \<omega>"
hoelzl@40859
  1143
proof -
hoelzl@40859
  1144
  interpret \<nu>: sigma_finite_measure M \<nu> by fact
hoelzl@40859
  1145
  have \<nu>: "measure_space M \<nu>" by default
hoelzl@40859
  1146
  from sfm show ?thesis
hoelzl@40859
  1147
    using sigma_finite_iff_density_finite[OF \<nu> RN_deriv[OF \<nu> ac]] by simp
hoelzl@40859
  1148
qed
hoelzl@40859
  1149
hoelzl@40859
  1150
lemma (in sigma_finite_measure)
hoelzl@40859
  1151
  assumes \<nu>: "sigma_finite_measure M \<nu>" "absolutely_continuous \<nu>"
hoelzl@40859
  1152
    and f: "f \<in> borel_measurable M"
hoelzl@40859
  1153
  shows RN_deriv_integral: "measure_space.integral M \<nu> f = integral (\<lambda>x. real (RN_deriv \<nu> x) * f x)" (is ?integral)
hoelzl@40859
  1154
    and RN_deriv_integrable: "measure_space.integrable M \<nu> f \<longleftrightarrow> integrable (\<lambda>x. real (RN_deriv \<nu> x) * f x)" (is ?integrable)
hoelzl@40859
  1155
proof -
hoelzl@40859
  1156
  interpret \<nu>: sigma_finite_measure M \<nu> by fact
hoelzl@40859
  1157
  have ms: "measure_space M \<nu>" by default
hoelzl@41023
  1158
  have minus_cong: "\<And>A B A' B'::pextreal. A = A' \<Longrightarrow> B = B' \<Longrightarrow> real A - real B = real A' - real B'" by simp
hoelzl@40859
  1159
  have f': "(\<lambda>x. - f x) \<in> borel_measurable M" using f by auto
hoelzl@40859
  1160
  { fix f :: "'a \<Rightarrow> real" assume "f \<in> borel_measurable M"
hoelzl@40859
  1161
    { fix x assume *: "RN_deriv \<nu> x \<noteq> \<omega>"
hoelzl@40859
  1162
      have "Real (real (RN_deriv \<nu> x)) * Real (f x) = Real (real (RN_deriv \<nu> x) * f x)"
hoelzl@40859
  1163
        by (simp add: mult_le_0_iff)
hoelzl@40859
  1164
      then have "RN_deriv \<nu> x * Real (f x) = Real (real (RN_deriv \<nu> x) * f x)"
hoelzl@40859
  1165
        using * by (simp add: Real_real) }
hoelzl@40859
  1166
    note * = this
hoelzl@40859
  1167
    have "positive_integral (\<lambda>x. RN_deriv \<nu> x * Real (f x)) = positive_integral (\<lambda>x. Real (real (RN_deriv \<nu> x) * f x))"
hoelzl@40859
  1168
      apply (rule positive_integral_cong_AE)
hoelzl@40859
  1169
      apply (rule AE_mp[OF RN_deriv_finite[OF \<nu>]])
hoelzl@40859
  1170
      by (auto intro!: AE_cong simp: *) }
hoelzl@40859
  1171
  with this[OF f] this[OF f'] f f'
hoelzl@40859
  1172
  show ?integral ?integrable
hoelzl@40859
  1173
    unfolding \<nu>.integral_def integral_def \<nu>.integrable_def integrable_def
hoelzl@40859
  1174
    by (auto intro!: RN_deriv(1)[OF ms \<nu>(2)] minus_cong simp: RN_deriv_positive_integral[OF ms \<nu>(2)])
hoelzl@40859
  1175
qed
hoelzl@40859
  1176
hoelzl@38656
  1177
lemma (in sigma_finite_measure) RN_deriv_singleton:
hoelzl@38656
  1178
  assumes "measure_space M \<nu>"
hoelzl@38656
  1179
  and ac: "absolutely_continuous \<nu>"
hoelzl@38656
  1180
  and "{x} \<in> sets M"
hoelzl@38656
  1181
  shows "\<nu> {x} = RN_deriv \<nu> x * \<mu> {x}"
hoelzl@38656
  1182
proof -
hoelzl@38656
  1183
  note deriv = RN_deriv[OF assms(1, 2)]
hoelzl@38656
  1184
  from deriv(2)[OF `{x} \<in> sets M`]
hoelzl@38656
  1185
  have "\<nu> {x} = positive_integral (\<lambda>w. RN_deriv \<nu> x * indicator {x} w)"
hoelzl@38656
  1186
    by (auto simp: indicator_def intro!: positive_integral_cong)
hoelzl@38656
  1187
  thus ?thesis using positive_integral_cmult_indicator[OF `{x} \<in> sets M`]
hoelzl@38656
  1188
    by auto
hoelzl@38656
  1189
qed
hoelzl@38656
  1190
hoelzl@38656
  1191
theorem (in finite_measure_space) RN_deriv_finite_measure:
hoelzl@38656
  1192
  assumes "measure_space M \<nu>"
hoelzl@38656
  1193
  and ac: "absolutely_continuous \<nu>"
hoelzl@38656
  1194
  and "x \<in> space M"
hoelzl@38656
  1195
  shows "\<nu> {x} = RN_deriv \<nu> x * \<mu> {x}"
hoelzl@38656
  1196
proof -
hoelzl@38656
  1197
  have "{x} \<in> sets M" using sets_eq_Pow `x \<in> space M` by auto
hoelzl@38656
  1198
  from RN_deriv_singleton[OF assms(1,2) this] show ?thesis .
hoelzl@38656
  1199
qed
hoelzl@38656
  1200
hoelzl@38656
  1201
end