src/HOL/Probability/Radon_Nikodym.thy
author hoelzl
Thu Sep 02 17:12:40 2010 +0200 (2010-09-02)
changeset 39092 98de40859858
parent 38656 d5d342611edb
child 39097 943c7b348524
permissions -rw-r--r--
move lemmas to correct theory files
hoelzl@38656
     1
theory Radon_Nikodym
hoelzl@38656
     2
imports Lebesgue_Integration
hoelzl@38656
     3
begin
hoelzl@38656
     4
hoelzl@38656
     5
lemma (in sigma_finite_measure) Ex_finite_integrable_function:
hoelzl@38656
     6
  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
     7
proof -
hoelzl@38656
     8
  obtain A :: "nat \<Rightarrow> 'a set" where
hoelzl@38656
     9
    range: "range A \<subseteq> sets M" and
hoelzl@38656
    10
    space: "(\<Union>i. A i) = space M" and
hoelzl@38656
    11
    measure: "\<And>i. \<mu> (A i) \<noteq> \<omega>" and
hoelzl@38656
    12
    disjoint: "disjoint_family A"
hoelzl@38656
    13
    using disjoint_sigma_finite by auto
hoelzl@38656
    14
  let "?B i" = "2^Suc i * \<mu> (A i)"
hoelzl@38656
    15
  have "\<forall>i. \<exists>x. 0 < x \<and> x < inverse (?B i)"
hoelzl@38656
    16
  proof
hoelzl@38656
    17
    fix i show "\<exists>x. 0 < x \<and> x < inverse (?B i)"
hoelzl@38656
    18
    proof cases
hoelzl@38656
    19
      assume "\<mu> (A i) = 0"
hoelzl@38656
    20
      then show ?thesis by (auto intro!: exI[of _ 1])
hoelzl@38656
    21
    next
hoelzl@38656
    22
      assume not_0: "\<mu> (A i) \<noteq> 0"
hoelzl@38656
    23
      then have "?B i \<noteq> \<omega>" using measure[of i] by auto
hoelzl@38656
    24
      then have "inverse (?B i) \<noteq> 0" unfolding pinfreal_inverse_eq_0 by simp
hoelzl@38656
    25
      then show ?thesis using measure[of i] not_0
hoelzl@38656
    26
        by (auto intro!: exI[of _ "inverse (?B i) / 2"]
hoelzl@38656
    27
                 simp: pinfreal_noteq_omega_Ex zero_le_mult_iff zero_less_mult_iff mult_le_0_iff power_le_zero_eq)
hoelzl@38656
    28
    qed
hoelzl@38656
    29
  qed
hoelzl@38656
    30
  from choice[OF this] obtain n where n: "\<And>i. 0 < n i"
hoelzl@38656
    31
    "\<And>i. n i < inverse (2^Suc i * \<mu> (A i))" by auto
hoelzl@38656
    32
  let "?h x" = "\<Sum>\<^isub>\<infinity> i. n i * indicator (A i) x"
hoelzl@38656
    33
  show ?thesis
hoelzl@38656
    34
  proof (safe intro!: bexI[of _ ?h] del: notI)
hoelzl@39092
    35
    have "\<And>i. A i \<in> sets M"
hoelzl@39092
    36
      using range by fastsimp+
hoelzl@39092
    37
    then have "positive_integral ?h = (\<Sum>\<^isub>\<infinity> i. n i * \<mu> (A i))"
hoelzl@39092
    38
      by (simp add: positive_integral_psuminf positive_integral_cmult_indicator)
hoelzl@38656
    39
    also have "\<dots> \<le> (\<Sum>\<^isub>\<infinity> i. Real ((1 / 2)^Suc i))"
hoelzl@38656
    40
    proof (rule psuminf_le)
hoelzl@38656
    41
      fix N show "n N * \<mu> (A N) \<le> Real ((1 / 2) ^ Suc N)"
hoelzl@38656
    42
        using measure[of N] n[of N]
hoelzl@39092
    43
        by (cases "n N")
hoelzl@39092
    44
           (auto simp: pinfreal_noteq_omega_Ex field_simps zero_le_mult_iff
hoelzl@39092
    45
                       mult_le_0_iff mult_less_0_iff power_less_zero_eq
hoelzl@39092
    46
                       power_le_zero_eq inverse_eq_divide less_divide_eq
hoelzl@39092
    47
                       power_divide split: split_if_asm)
hoelzl@38656
    48
    qed
hoelzl@38656
    49
    also have "\<dots> = Real 1"
hoelzl@38656
    50
      by (rule suminf_imp_psuminf, rule power_half_series, auto)
hoelzl@38656
    51
    finally show "positive_integral ?h \<noteq> \<omega>" by auto
hoelzl@38656
    52
  next
hoelzl@38656
    53
    fix x assume "x \<in> space M"
hoelzl@38656
    54
    then obtain i where "x \<in> A i" using space[symmetric] by auto
hoelzl@38656
    55
    from psuminf_cmult_indicator[OF disjoint, OF this]
hoelzl@38656
    56
    have "?h x = n i" by simp
hoelzl@38656
    57
    then show "0 < ?h x" and "?h x < \<omega>" using n[of i] by auto
hoelzl@38656
    58
  next
hoelzl@38656
    59
    show "?h \<in> borel_measurable M" using range
hoelzl@39092
    60
      by (auto intro!: borel_measurable_psuminf borel_measurable_pinfreal_times)
hoelzl@38656
    61
  qed
hoelzl@38656
    62
qed
hoelzl@38656
    63
hoelzl@38656
    64
definition (in measure_space)
hoelzl@38656
    65
  "absolutely_continuous \<nu> = (\<forall>N\<in>null_sets. \<nu> N = (0 :: pinfreal))"
hoelzl@38656
    66
hoelzl@38656
    67
lemma (in finite_measure) Radon_Nikodym_aux_epsilon:
hoelzl@38656
    68
  fixes e :: real assumes "0 < e"
hoelzl@38656
    69
  assumes "finite_measure M s"
hoelzl@38656
    70
  shows "\<exists>A\<in>sets M. real (\<mu> (space M)) - real (s (space M)) \<le>
hoelzl@38656
    71
                    real (\<mu> A) - real (s A) \<and>
hoelzl@38656
    72
                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> - e < real (\<mu> B) - real (s B))"
hoelzl@38656
    73
proof -
hoelzl@38656
    74
  let "?d A" = "real (\<mu> A) - real (s A)"
hoelzl@38656
    75
  interpret M': finite_measure M s by fact
hoelzl@38656
    76
hoelzl@38656
    77
  let "?A A" = "if (\<forall>B\<in>sets M. B \<subseteq> space M - A \<longrightarrow> -e < ?d B)
hoelzl@38656
    78
    then {}
hoelzl@38656
    79
    else (SOME B. B \<in> sets M \<and> B \<subseteq> space M - A \<and> ?d B \<le> -e)"
hoelzl@38656
    80
  def A \<equiv> "\<lambda>n. ((\<lambda>B. B \<union> ?A B) ^^ n) {}"
hoelzl@38656
    81
hoelzl@38656
    82
  have A_simps[simp]:
hoelzl@38656
    83
    "A 0 = {}"
hoelzl@38656
    84
    "\<And>n. A (Suc n) = (A n \<union> ?A (A n))" unfolding A_def by simp_all
hoelzl@38656
    85
hoelzl@38656
    86
  { fix A assume "A \<in> sets M"
hoelzl@38656
    87
    have "?A A \<in> sets M"
hoelzl@38656
    88
      by (auto intro!: someI2[of _ _ "\<lambda>A. A \<in> sets M"] simp: not_less) }
hoelzl@38656
    89
  note A'_in_sets = this
hoelzl@38656
    90
hoelzl@38656
    91
  { fix n have "A n \<in> sets M"
hoelzl@38656
    92
    proof (induct n)
hoelzl@38656
    93
      case (Suc n) thus "A (Suc n) \<in> sets M"
hoelzl@38656
    94
        using A'_in_sets[of "A n"] by (auto split: split_if_asm)
hoelzl@38656
    95
    qed (simp add: A_def) }
hoelzl@38656
    96
  note A_in_sets = this
hoelzl@38656
    97
  hence "range A \<subseteq> sets M" by auto
hoelzl@38656
    98
hoelzl@38656
    99
  { fix n B
hoelzl@38656
   100
    assume Ex: "\<exists>B. B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> -e"
hoelzl@38656
   101
    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
   102
    have "?d (A (Suc n)) \<le> ?d (A n) - e" unfolding A_simps if_not_P[OF False]
hoelzl@38656
   103
    proof (rule someI2_ex[OF Ex])
hoelzl@38656
   104
      fix B assume "B \<in> sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e"
hoelzl@38656
   105
      hence "A n \<inter> B = {}" "B \<in> sets M" and dB: "?d B \<le> -e" by auto
hoelzl@38656
   106
      hence "?d (A n \<union> B) = ?d (A n) + ?d B"
hoelzl@38656
   107
        using `A n \<in> sets M` real_finite_measure_Union M'.real_finite_measure_Union by simp
hoelzl@38656
   108
      also have "\<dots> \<le> ?d (A n) - e" using dB by simp
hoelzl@38656
   109
      finally show "?d (A n \<union> B) \<le> ?d (A n) - e" .
hoelzl@38656
   110
    qed }
hoelzl@38656
   111
  note dA_epsilon = this
hoelzl@38656
   112
hoelzl@38656
   113
  { fix n have "?d (A (Suc n)) \<le> ?d (A n)"
hoelzl@38656
   114
    proof (cases "\<exists>B. B\<in>sets M \<and> B \<subseteq> space M - A n \<and> ?d B \<le> - e")
hoelzl@38656
   115
      case True from dA_epsilon[OF this] show ?thesis using `0 < e` by simp
hoelzl@38656
   116
    next
hoelzl@38656
   117
      case False
hoelzl@38656
   118
      hence "\<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B" by (auto simp: not_le)
hoelzl@38656
   119
      thus ?thesis by simp
hoelzl@38656
   120
    qed }
hoelzl@38656
   121
  note dA_mono = this
hoelzl@38656
   122
hoelzl@38656
   123
  show ?thesis
hoelzl@38656
   124
  proof (cases "\<exists>n. \<forall>B\<in>sets M. B \<subseteq> space M - A n \<longrightarrow> -e < ?d B")
hoelzl@38656
   125
    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
   126
    show ?thesis
hoelzl@38656
   127
    proof (safe intro!: bexI[of _ "space M - A n"])
hoelzl@38656
   128
      fix B assume "B \<in> sets M" "B \<subseteq> space M - A n"
hoelzl@38656
   129
      from B[OF this] show "-e < ?d B" .
hoelzl@38656
   130
    next
hoelzl@38656
   131
      show "space M - A n \<in> sets M" by (rule compl_sets) fact
hoelzl@38656
   132
    next
hoelzl@38656
   133
      show "?d (space M) \<le> ?d (space M - A n)"
hoelzl@38656
   134
      proof (induct n)
hoelzl@38656
   135
        fix n assume "?d (space M) \<le> ?d (space M - A n)"
hoelzl@38656
   136
        also have "\<dots> \<le> ?d (space M - A (Suc n))"
hoelzl@38656
   137
          using A_in_sets sets_into_space dA_mono[of n]
hoelzl@38656
   138
            real_finite_measure_Diff[of "space M"]
hoelzl@38656
   139
            real_finite_measure_Diff[of "space M"]
hoelzl@38656
   140
            M'.real_finite_measure_Diff[of "space M"]
hoelzl@38656
   141
            M'.real_finite_measure_Diff[of "space M"]
hoelzl@38656
   142
          by (simp del: A_simps)
hoelzl@38656
   143
        finally show "?d (space M) \<le> ?d (space M - A (Suc n))" .
hoelzl@38656
   144
      qed simp
hoelzl@38656
   145
    qed
hoelzl@38656
   146
  next
hoelzl@38656
   147
    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
   148
      by (auto simp add: not_less)
hoelzl@38656
   149
    { fix n have "?d (A n) \<le> - real n * e"
hoelzl@38656
   150
      proof (induct n)
hoelzl@38656
   151
        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
   152
      qed simp } note dA_less = this
hoelzl@38656
   153
    have decseq: "decseq (\<lambda>n. ?d (A n))" unfolding decseq_eq_incseq
hoelzl@38656
   154
    proof (rule incseq_SucI)
hoelzl@38656
   155
      fix n show "- ?d (A n) \<le> - ?d (A (Suc n))" using dA_mono[of n] by auto
hoelzl@38656
   156
    qed
hoelzl@38656
   157
    from real_finite_continuity_from_below[of A] `range A \<subseteq> sets M`
hoelzl@38656
   158
      M'.real_finite_continuity_from_below[of A]
hoelzl@38656
   159
    have convergent: "(\<lambda>i. ?d (A i)) ----> ?d (\<Union>i. A i)"
hoelzl@38656
   160
      by (auto intro!: LIMSEQ_diff)
hoelzl@38656
   161
    obtain n :: nat where "- ?d (\<Union>i. A i) / e < real n" using reals_Archimedean2 by auto
hoelzl@38656
   162
    moreover from order_trans[OF decseq_le[OF decseq convergent] dA_less]
hoelzl@38656
   163
    have "real n \<le> - ?d (\<Union>i. A i) / e" using `0<e` by (simp add: field_simps)
hoelzl@38656
   164
    ultimately show ?thesis by auto
hoelzl@38656
   165
  qed
hoelzl@38656
   166
qed
hoelzl@38656
   167
hoelzl@38656
   168
lemma (in finite_measure) Radon_Nikodym_aux:
hoelzl@38656
   169
  assumes "finite_measure M s"
hoelzl@38656
   170
  shows "\<exists>A\<in>sets M. real (\<mu> (space M)) - real (s (space M)) \<le>
hoelzl@38656
   171
                    real (\<mu> A) - real (s A) \<and>
hoelzl@38656
   172
                    (\<forall>B\<in>sets M. B \<subseteq> A \<longrightarrow> 0 \<le> real (\<mu> B) - real (s B))"
hoelzl@38656
   173
proof -
hoelzl@38656
   174
  let "?d A" = "real (\<mu> A) - real (s A)"
hoelzl@38656
   175
  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
   176
hoelzl@38656
   177
  interpret M': finite_measure M s by fact
hoelzl@38656
   178
hoelzl@39092
   179
  let "?r S" = "restricted_space S"
hoelzl@38656
   180
hoelzl@38656
   181
  { fix S n
hoelzl@38656
   182
    assume S: "S \<in> sets M"
hoelzl@38656
   183
    hence **: "\<And>X. X \<in> op \<inter> S ` sets M \<longleftrightarrow> X \<in> sets M \<and> X \<subseteq> S" by auto
hoelzl@38656
   184
    from M'.restricted_finite_measure[of S] restricted_finite_measure[of S] S
hoelzl@38656
   185
    have "finite_measure (?r S) \<mu>" "0 < 1 / real (Suc n)"
hoelzl@38656
   186
      "finite_measure (?r S) s" by auto
hoelzl@38656
   187
    from finite_measure.Radon_Nikodym_aux_epsilon[OF this] guess X ..
hoelzl@38656
   188
    hence "?P X S n"
hoelzl@38656
   189
    proof (simp add: **, safe)
hoelzl@38656
   190
      fix C assume C: "C \<in> sets M" "C \<subseteq> X" "X \<subseteq> S" and
hoelzl@38656
   191
        *: "\<forall>B\<in>sets M. S \<inter> B \<subseteq> X \<longrightarrow> - (1 / real (Suc n)) < ?d (S \<inter> B)"
hoelzl@38656
   192
      hence "C \<subseteq> S" "C \<subseteq> X" "S \<inter> C = C" by auto
hoelzl@38656
   193
      with *[THEN bspec, OF `C \<in> sets M`]
hoelzl@38656
   194
      show "- (1 / real (Suc n)) < ?d C" by auto
hoelzl@38656
   195
    qed
hoelzl@38656
   196
    hence "\<exists>A. ?P A S n" by auto }
hoelzl@38656
   197
  note Ex_P = this
hoelzl@38656
   198
hoelzl@38656
   199
  def A \<equiv> "nat_rec (space M) (\<lambda>n A. SOME B. ?P B A n)"
hoelzl@38656
   200
  have A_Suc: "\<And>n. A (Suc n) = (SOME B. ?P B (A n) n)" by (simp add: A_def)
hoelzl@38656
   201
  have A_0[simp]: "A 0 = space M" unfolding A_def by simp
hoelzl@38656
   202
hoelzl@38656
   203
  { fix i have "A i \<in> sets M" unfolding A_def
hoelzl@38656
   204
    proof (induct i)
hoelzl@38656
   205
      case (Suc i)
hoelzl@38656
   206
      from Ex_P[OF this, of i] show ?case unfolding nat_rec_Suc
hoelzl@38656
   207
        by (rule someI2_ex) simp
hoelzl@38656
   208
    qed simp }
hoelzl@38656
   209
  note A_in_sets = this
hoelzl@38656
   210
hoelzl@38656
   211
  { fix n have "?P (A (Suc n)) (A n) n"
hoelzl@38656
   212
      using Ex_P[OF A_in_sets] unfolding A_Suc
hoelzl@38656
   213
      by (rule someI2_ex) simp }
hoelzl@38656
   214
  note P_A = this
hoelzl@38656
   215
hoelzl@38656
   216
  have "range A \<subseteq> sets M" using A_in_sets by auto
hoelzl@38656
   217
hoelzl@38656
   218
  have A_mono: "\<And>i. A (Suc i) \<subseteq> A i" using P_A by simp
hoelzl@38656
   219
  have mono_dA: "mono (\<lambda>i. ?d (A i))" using P_A by (simp add: mono_iff_le_Suc)
hoelzl@38656
   220
  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
   221
      using P_A by auto
hoelzl@38656
   222
hoelzl@38656
   223
  show ?thesis
hoelzl@38656
   224
  proof (safe intro!: bexI[of _ "\<Inter>i. A i"])
hoelzl@38656
   225
    show "(\<Inter>i. A i) \<in> sets M" using A_in_sets by auto
hoelzl@38656
   226
    from `range A \<subseteq> sets M` A_mono
hoelzl@38656
   227
      real_finite_continuity_from_above[of A]
hoelzl@38656
   228
      M'.real_finite_continuity_from_above[of A]
hoelzl@38656
   229
    have "(\<lambda>i. ?d (A i)) ----> ?d (\<Inter>i. A i)" by (auto intro!: LIMSEQ_diff)
hoelzl@38656
   230
    thus "?d (space M) \<le> ?d (\<Inter>i. A i)" using mono_dA[THEN monoD, of 0 _]
hoelzl@38656
   231
      by (rule_tac LIMSEQ_le_const) (auto intro!: exI)
hoelzl@38656
   232
  next
hoelzl@38656
   233
    fix B assume B: "B \<in> sets M" "B \<subseteq> (\<Inter>i. A i)"
hoelzl@38656
   234
    show "0 \<le> ?d B"
hoelzl@38656
   235
    proof (rule ccontr)
hoelzl@38656
   236
      assume "\<not> 0 \<le> ?d B"
hoelzl@38656
   237
      hence "0 < - ?d B" by auto
hoelzl@38656
   238
      from ex_inverse_of_nat_Suc_less[OF this]
hoelzl@38656
   239
      obtain n where *: "?d B < - 1 / real (Suc n)"
hoelzl@38656
   240
        by (auto simp: real_eq_of_nat inverse_eq_divide field_simps)
hoelzl@38656
   241
      have "B \<subseteq> A (Suc n)" using B by (auto simp del: nat_rec_Suc)
hoelzl@38656
   242
      from epsilon[OF B(1) this] *
hoelzl@38656
   243
      show False by auto
hoelzl@38656
   244
    qed
hoelzl@38656
   245
  qed
hoelzl@38656
   246
qed
hoelzl@38656
   247
hoelzl@38656
   248
lemma (in finite_measure) Radon_Nikodym_finite_measure:
hoelzl@38656
   249
  assumes "finite_measure M \<nu>"
hoelzl@38656
   250
  assumes "absolutely_continuous \<nu>"
hoelzl@38656
   251
  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
   252
proof -
hoelzl@38656
   253
  interpret M': finite_measure M \<nu> using assms(1) .
hoelzl@38656
   254
hoelzl@38656
   255
  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
   256
  have "(\<lambda>x. 0) \<in> G" unfolding G_def by auto
hoelzl@38656
   257
  hence "G \<noteq> {}" by auto
hoelzl@38656
   258
hoelzl@38656
   259
  { fix f g assume f: "f \<in> G" and g: "g \<in> G"
hoelzl@38656
   260
    have "(\<lambda>x. max (g x) (f x)) \<in> G" (is "?max \<in> G") unfolding G_def
hoelzl@38656
   261
    proof safe
hoelzl@38656
   262
      show "?max \<in> borel_measurable M" using f g unfolding G_def by auto
hoelzl@38656
   263
hoelzl@38656
   264
      let ?A = "{x \<in> space M. f x \<le> g x}"
hoelzl@38656
   265
      have "?A \<in> sets M" using f g unfolding G_def by auto
hoelzl@38656
   266
hoelzl@38656
   267
      fix A assume "A \<in> sets M"
hoelzl@38656
   268
      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
   269
      have union: "((?A \<inter> A) \<union> ((space M - ?A) \<inter> A)) = A"
hoelzl@38656
   270
        using sets_into_space[OF `A \<in> sets M`] by auto
hoelzl@38656
   271
hoelzl@38656
   272
      have "\<And>x. x \<in> space M \<Longrightarrow> max (g x) (f x) * indicator A x =
hoelzl@38656
   273
        g x * indicator (?A \<inter> A) x + f x * indicator ((space M - ?A) \<inter> A) x"
hoelzl@38656
   274
        by (auto simp: indicator_def max_def)
hoelzl@38656
   275
      hence "positive_integral (\<lambda>x. max (g x) (f x) * indicator A x) =
hoelzl@38656
   276
        positive_integral (\<lambda>x. g x * indicator (?A \<inter> A) x) +
hoelzl@38656
   277
        positive_integral (\<lambda>x. f x * indicator ((space M - ?A) \<inter> A) x)"
hoelzl@38656
   278
        using f g sets unfolding G_def
hoelzl@38656
   279
        by (auto cong: positive_integral_cong intro!: positive_integral_add borel_measurable_indicator)
hoelzl@38656
   280
      also have "\<dots> \<le> \<nu> (?A \<inter> A) + \<nu> ((space M - ?A) \<inter> A)"
hoelzl@38656
   281
        using f g sets unfolding G_def by (auto intro!: add_mono)
hoelzl@38656
   282
      also have "\<dots> = \<nu> A"
hoelzl@38656
   283
        using M'.measure_additive[OF sets] union by auto
hoelzl@38656
   284
      finally show "positive_integral (\<lambda>x. max (g x) (f x) * indicator A x) \<le> \<nu> A" .
hoelzl@38656
   285
    qed }
hoelzl@38656
   286
  note max_in_G = this
hoelzl@38656
   287
hoelzl@38656
   288
  { fix f g assume  "f \<up> g" and f: "\<And>i. f i \<in> G"
hoelzl@38656
   289
    have "g \<in> G" unfolding G_def
hoelzl@38656
   290
    proof safe
hoelzl@38656
   291
      from `f \<up> g` have [simp]: "g = (SUP i. f i)" unfolding isoton_def by simp
hoelzl@38656
   292
      have f_borel: "\<And>i. f i \<in> borel_measurable M" using f unfolding G_def by simp
hoelzl@38656
   293
      thus "g \<in> borel_measurable M" by (auto intro!: borel_measurable_SUP)
hoelzl@38656
   294
hoelzl@38656
   295
      fix A assume "A \<in> sets M"
hoelzl@38656
   296
      hence "\<And>i. (\<lambda>x. f i x * indicator A x) \<in> borel_measurable M"
hoelzl@38656
   297
        using f_borel by (auto intro!: borel_measurable_indicator)
hoelzl@38656
   298
      from positive_integral_isoton[OF isoton_indicator[OF `f \<up> g`] this]
hoelzl@38656
   299
      have SUP: "positive_integral (\<lambda>x. g x * indicator A x) =
hoelzl@38656
   300
          (SUP i. positive_integral (\<lambda>x. f i x * indicator A x))"
hoelzl@38656
   301
        unfolding isoton_def by simp
hoelzl@38656
   302
      show "positive_integral (\<lambda>x. g x * indicator A x) \<le> \<nu> A" unfolding SUP
hoelzl@38656
   303
        using f `A \<in> sets M` unfolding G_def by (auto intro!: SUP_leI)
hoelzl@38656
   304
    qed }
hoelzl@38656
   305
  note SUP_in_G = this
hoelzl@38656
   306
hoelzl@38656
   307
  let ?y = "SUP g : G. positive_integral g"
hoelzl@38656
   308
  have "?y \<le> \<nu> (space M)" unfolding G_def
hoelzl@38656
   309
  proof (safe intro!: SUP_leI)
hoelzl@38656
   310
    fix g assume "\<forall>A\<in>sets M. positive_integral (\<lambda>x. g x * indicator A x) \<le> \<nu> A"
hoelzl@38656
   311
    from this[THEN bspec, OF top] show "positive_integral g \<le> \<nu> (space M)"
hoelzl@38656
   312
      by (simp cong: positive_integral_cong)
hoelzl@38656
   313
  qed
hoelzl@38656
   314
  hence "?y \<noteq> \<omega>" using M'.finite_measure_of_space by auto
hoelzl@38656
   315
  from SUPR_countable_SUPR[OF this `G \<noteq> {}`] guess ys .. note ys = this
hoelzl@38656
   316
  hence "\<forall>n. \<exists>g. g\<in>G \<and> positive_integral g = ys n"
hoelzl@38656
   317
  proof safe
hoelzl@38656
   318
    fix n assume "range ys \<subseteq> positive_integral ` G"
hoelzl@38656
   319
    hence "ys n \<in> positive_integral ` G" by auto
hoelzl@38656
   320
    thus "\<exists>g. g\<in>G \<and> positive_integral g = ys n" by auto
hoelzl@38656
   321
  qed
hoelzl@38656
   322
  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
   323
  hence y_eq: "?y = (SUP i. positive_integral (gs i))" using ys by auto
hoelzl@38656
   324
  let "?g i x" = "Max ((\<lambda>n. gs n x) ` {..i})"
hoelzl@38656
   325
  def f \<equiv> "SUP i. ?g i"
hoelzl@38656
   326
  have gs_not_empty: "\<And>i. (\<lambda>n. gs n x) ` {..i} \<noteq> {}" by auto
hoelzl@38656
   327
  { fix i have "?g i \<in> G"
hoelzl@38656
   328
    proof (induct i)
hoelzl@38656
   329
      case 0 thus ?case by simp fact
hoelzl@38656
   330
    next
hoelzl@38656
   331
      case (Suc i)
hoelzl@38656
   332
      with Suc gs_not_empty `gs (Suc i) \<in> G` show ?case
hoelzl@38656
   333
        by (auto simp add: atMost_Suc intro!: max_in_G)
hoelzl@38656
   334
    qed }
hoelzl@38656
   335
  note g_in_G = this
hoelzl@38656
   336
  have "\<And>x. \<forall>i. ?g i x \<le> ?g (Suc i) x"
hoelzl@38656
   337
    using gs_not_empty by (simp add: atMost_Suc)
hoelzl@38656
   338
  hence isoton_g: "?g \<up> f" by (simp add: isoton_def le_fun_def f_def)
hoelzl@38656
   339
  from SUP_in_G[OF this g_in_G] have "f \<in> G" .
hoelzl@38656
   340
  hence [simp, intro]: "f \<in> borel_measurable M" unfolding G_def by auto
hoelzl@38656
   341
hoelzl@38656
   342
  have "(\<lambda>i. positive_integral (?g i)) \<up> positive_integral f"
hoelzl@38656
   343
    using isoton_g g_in_G by (auto intro!: positive_integral_isoton simp: G_def f_def)
hoelzl@38656
   344
  hence "positive_integral f = (SUP i. positive_integral (?g i))"
hoelzl@38656
   345
    unfolding isoton_def by simp
hoelzl@38656
   346
  also have "\<dots> = ?y"
hoelzl@38656
   347
  proof (rule antisym)
hoelzl@38656
   348
    show "(SUP i. positive_integral (?g i)) \<le> ?y"
hoelzl@38656
   349
      using g_in_G by (auto intro!: exI Sup_mono simp: SUPR_def)
hoelzl@38656
   350
    show "?y \<le> (SUP i. positive_integral (?g i))" unfolding y_eq
hoelzl@38656
   351
      by (auto intro!: SUP_mono positive_integral_mono Max_ge)
hoelzl@38656
   352
  qed
hoelzl@38656
   353
  finally have int_f_eq_y: "positive_integral f = ?y" .
hoelzl@38656
   354
hoelzl@38656
   355
  let "?t A" = "\<nu> A - positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   356
hoelzl@38656
   357
  have "finite_measure M ?t"
hoelzl@38656
   358
  proof
hoelzl@38656
   359
    show "?t {} = 0" by simp
hoelzl@38656
   360
    show "?t (space M) \<noteq> \<omega>" using M'.finite_measure by simp
hoelzl@38656
   361
    show "countably_additive M ?t" unfolding countably_additive_def
hoelzl@38656
   362
    proof safe
hoelzl@38656
   363
      fix A :: "nat \<Rightarrow> 'a set"  assume A: "range A \<subseteq> sets M" "disjoint_family A"
hoelzl@38656
   364
      have "(\<Sum>\<^isub>\<infinity> n. positive_integral (\<lambda>x. f x * indicator (A n) x))
hoelzl@38656
   365
        = positive_integral (\<lambda>x. (\<Sum>\<^isub>\<infinity>n. f x * indicator (A n) x))"
hoelzl@38656
   366
        using `range A \<subseteq> sets M`
hoelzl@38656
   367
        by (rule_tac positive_integral_psuminf[symmetric]) (auto intro!: borel_measurable_indicator)
hoelzl@38656
   368
      also have "\<dots> = positive_integral (\<lambda>x. f x * indicator (\<Union>n. A n) x)"
hoelzl@38656
   369
        apply (rule positive_integral_cong)
hoelzl@38656
   370
        apply (subst psuminf_cmult_right)
hoelzl@38656
   371
        unfolding psuminf_indicator[OF `disjoint_family A`] ..
hoelzl@38656
   372
      finally have "(\<Sum>\<^isub>\<infinity> n. positive_integral (\<lambda>x. f x * indicator (A n) x))
hoelzl@38656
   373
        = positive_integral (\<lambda>x. f x * indicator (\<Union>n. A n) x)" .
hoelzl@38656
   374
      moreover have "(\<Sum>\<^isub>\<infinity>n. \<nu> (A n)) = \<nu> (\<Union>n. A n)"
hoelzl@38656
   375
        using M'.measure_countably_additive A by (simp add: comp_def)
hoelzl@38656
   376
      moreover have "\<And>i. positive_integral (\<lambda>x. f x * indicator (A i) x) \<le> \<nu> (A i)"
hoelzl@38656
   377
          using A `f \<in> G` unfolding G_def by auto
hoelzl@38656
   378
      moreover have v_fin: "\<nu> (\<Union>i. A i) \<noteq> \<omega>" using M'.finite_measure A by (simp add: countable_UN)
hoelzl@38656
   379
      moreover {
hoelzl@38656
   380
        have "positive_integral (\<lambda>x. f x * indicator (\<Union>i. A i) x) \<le> \<nu> (\<Union>i. A i)"
hoelzl@38656
   381
          using A `f \<in> G` unfolding G_def by (auto simp: countable_UN)
hoelzl@38656
   382
        also have "\<nu> (\<Union>i. A i) < \<omega>" using v_fin by (simp add: pinfreal_less_\<omega>)
hoelzl@38656
   383
        finally have "positive_integral (\<lambda>x. f x * indicator (\<Union>i. A i) x) \<noteq> \<omega>"
hoelzl@38656
   384
          by (simp add: pinfreal_less_\<omega>) }
hoelzl@38656
   385
      ultimately
hoelzl@38656
   386
      show "(\<Sum>\<^isub>\<infinity> n. ?t (A n)) = ?t (\<Union>i. A i)"
hoelzl@38656
   387
        apply (subst psuminf_minus) by simp_all
hoelzl@38656
   388
    qed
hoelzl@38656
   389
  qed
hoelzl@38656
   390
  then interpret M: finite_measure M ?t .
hoelzl@38656
   391
hoelzl@38656
   392
  have ac: "absolutely_continuous ?t" using `absolutely_continuous \<nu>` unfolding absolutely_continuous_def by auto
hoelzl@38656
   393
hoelzl@38656
   394
  have upper_bound: "\<forall>A\<in>sets M. ?t A \<le> 0"
hoelzl@38656
   395
  proof (rule ccontr)
hoelzl@38656
   396
    assume "\<not> ?thesis"
hoelzl@38656
   397
    then obtain A where A: "A \<in> sets M" and pos: "0 < ?t A"
hoelzl@38656
   398
      by (auto simp: not_le)
hoelzl@38656
   399
    note pos
hoelzl@38656
   400
    also have "?t A \<le> ?t (space M)"
hoelzl@38656
   401
      using M.measure_mono[of A "space M"] A sets_into_space by simp
hoelzl@38656
   402
    finally have pos_t: "0 < ?t (space M)" by simp
hoelzl@38656
   403
    moreover
hoelzl@38656
   404
    hence pos_M: "0 < \<mu> (space M)"
hoelzl@38656
   405
      using ac top unfolding absolutely_continuous_def by auto
hoelzl@38656
   406
    moreover
hoelzl@38656
   407
    have "positive_integral (\<lambda>x. f x * indicator (space M) x) \<le> \<nu> (space M)"
hoelzl@38656
   408
      using `f \<in> G` unfolding G_def by auto
hoelzl@38656
   409
    hence "positive_integral (\<lambda>x. f x * indicator (space M) x) \<noteq> \<omega>"
hoelzl@38656
   410
      using M'.finite_measure_of_space by auto
hoelzl@38656
   411
    moreover
hoelzl@38656
   412
    def b \<equiv> "?t (space M) / \<mu> (space M) / 2"
hoelzl@38656
   413
    ultimately have b: "b \<noteq> 0" "b \<noteq> \<omega>"
hoelzl@38656
   414
      using M'.finite_measure_of_space
hoelzl@38656
   415
      by (auto simp: pinfreal_inverse_eq_0 finite_measure_of_space)
hoelzl@38656
   416
hoelzl@38656
   417
    have "finite_measure M (\<lambda>A. b * \<mu> A)" (is "finite_measure M ?b")
hoelzl@38656
   418
    proof
hoelzl@38656
   419
      show "?b {} = 0" by simp
hoelzl@38656
   420
      show "?b (space M) \<noteq> \<omega>" using finite_measure_of_space b by auto
hoelzl@38656
   421
      show "countably_additive M ?b"
hoelzl@38656
   422
        unfolding countably_additive_def psuminf_cmult_right
hoelzl@38656
   423
        using measure_countably_additive by auto
hoelzl@38656
   424
    qed
hoelzl@38656
   425
hoelzl@38656
   426
    from M.Radon_Nikodym_aux[OF this]
hoelzl@38656
   427
    obtain A0 where "A0 \<in> sets M" and
hoelzl@38656
   428
      space_less_A0: "real (?t (space M)) - real (b * \<mu> (space M)) \<le> real (?t A0) - real (b * \<mu> A0)" and
hoelzl@38656
   429
      *: "\<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
   430
    { fix B assume "B \<in> sets M" "B \<subseteq> A0"
hoelzl@38656
   431
      with *[OF this] have "b * \<mu> B \<le> ?t B"
hoelzl@38656
   432
        using M'.finite_measure b finite_measure
hoelzl@38656
   433
        by (cases "b * \<mu> B", cases "?t B") (auto simp: field_simps) }
hoelzl@38656
   434
    note bM_le_t = this
hoelzl@38656
   435
hoelzl@38656
   436
    let "?f0 x" = "f x + b * indicator A0 x"
hoelzl@38656
   437
hoelzl@38656
   438
    { fix A assume A: "A \<in> sets M"
hoelzl@38656
   439
      hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
hoelzl@38656
   440
      have "positive_integral (\<lambda>x. ?f0 x  * indicator A x) =
hoelzl@38656
   441
        positive_integral (\<lambda>x. f x * indicator A x + b * indicator (A \<inter> A0) x)"
hoelzl@38656
   442
        by (auto intro!: positive_integral_cong simp: field_simps indicator_inter_arith)
hoelzl@38656
   443
      hence "positive_integral (\<lambda>x. ?f0 x * indicator A x) =
hoelzl@38656
   444
          positive_integral (\<lambda>x. f x * indicator A x) + b * \<mu> (A \<inter> A0)"
hoelzl@38656
   445
        using `A0 \<in> sets M` `A \<inter> A0 \<in> sets M` A
hoelzl@38656
   446
        by (simp add: borel_measurable_indicator positive_integral_add positive_integral_cmult_indicator) }
hoelzl@38656
   447
    note f0_eq = this
hoelzl@38656
   448
hoelzl@38656
   449
    { fix A assume A: "A \<in> sets M"
hoelzl@38656
   450
      hence "A \<inter> A0 \<in> sets M" using `A0 \<in> sets M` by auto
hoelzl@38656
   451
      have f_le_v: "positive_integral (\<lambda>x. f x * indicator A x) \<le> \<nu> A"
hoelzl@38656
   452
        using `f \<in> G` A unfolding G_def by auto
hoelzl@38656
   453
      note f0_eq[OF A]
hoelzl@38656
   454
      also have "positive_integral (\<lambda>x. f x * indicator A x) + b * \<mu> (A \<inter> A0) \<le>
hoelzl@38656
   455
          positive_integral (\<lambda>x. f x * indicator A x) + ?t (A \<inter> A0)"
hoelzl@38656
   456
        using bM_le_t[OF `A \<inter> A0 \<in> sets M`] `A \<in> sets M` `A0 \<in> sets M`
hoelzl@38656
   457
        by (auto intro!: add_left_mono)
hoelzl@38656
   458
      also have "\<dots> \<le> positive_integral (\<lambda>x. f x * indicator A x) + ?t A"
hoelzl@38656
   459
        using M.measure_mono[simplified, OF _ `A \<inter> A0 \<in> sets M` `A \<in> sets M`]
hoelzl@38656
   460
        by (auto intro!: add_left_mono)
hoelzl@38656
   461
      also have "\<dots> \<le> \<nu> A"
hoelzl@38656
   462
        using f_le_v M'.finite_measure[simplified, OF `A \<in> sets M`]
hoelzl@38656
   463
        by (cases "positive_integral (\<lambda>x. f x * indicator A x)", cases "\<nu> A", auto)
hoelzl@38656
   464
      finally have "positive_integral (\<lambda>x. ?f0 x * indicator A x) \<le> \<nu> A" . }
hoelzl@38656
   465
    hence "?f0 \<in> G" using `A0 \<in> sets M` unfolding G_def
hoelzl@38656
   466
      by (auto intro!: borel_measurable_indicator borel_measurable_pinfreal_add borel_measurable_pinfreal_times)
hoelzl@38656
   467
hoelzl@38656
   468
    have real: "?t (space M) \<noteq> \<omega>" "?t A0 \<noteq> \<omega>"
hoelzl@38656
   469
      "b * \<mu> (space M) \<noteq> \<omega>" "b * \<mu> A0 \<noteq> \<omega>"
hoelzl@38656
   470
      using `A0 \<in> sets M` b
hoelzl@38656
   471
        finite_measure[of A0] M.finite_measure[of A0]
hoelzl@38656
   472
        finite_measure_of_space M.finite_measure_of_space
hoelzl@38656
   473
      by auto
hoelzl@38656
   474
hoelzl@38656
   475
    have int_f_finite: "positive_integral f \<noteq> \<omega>"
hoelzl@38656
   476
      using M'.finite_measure_of_space pos_t unfolding pinfreal_zero_less_diff_iff
hoelzl@38656
   477
      by (auto cong: positive_integral_cong)
hoelzl@38656
   478
hoelzl@38656
   479
    have "?t (space M) > b * \<mu> (space M)" unfolding b_def
hoelzl@38656
   480
      apply (simp add: field_simps)
hoelzl@38656
   481
      apply (subst mult_assoc[symmetric])
hoelzl@38656
   482
      apply (subst pinfreal_mult_inverse)
hoelzl@38656
   483
      using finite_measure_of_space M'.finite_measure_of_space pos_t pos_M
hoelzl@38656
   484
      using pinfreal_mult_strict_right_mono[of "Real (1/2)" 1 "?t (space M)"]
hoelzl@38656
   485
      by simp_all
hoelzl@38656
   486
    hence  "0 < ?t (space M) - b * \<mu> (space M)"
hoelzl@38656
   487
      by (simp add: pinfreal_zero_less_diff_iff)
hoelzl@38656
   488
    also have "\<dots> \<le> ?t A0 - b * \<mu> A0"
hoelzl@38656
   489
      using space_less_A0 pos_M pos_t b real[unfolded pinfreal_noteq_omega_Ex] by auto
hoelzl@38656
   490
    finally have "b * \<mu> A0 < ?t A0" unfolding pinfreal_zero_less_diff_iff .
hoelzl@38656
   491
    hence "0 < ?t A0" by auto
hoelzl@38656
   492
    hence "0 < \<mu> A0" using ac unfolding absolutely_continuous_def
hoelzl@38656
   493
      using `A0 \<in> sets M` by auto
hoelzl@38656
   494
    hence "0 < b * \<mu> A0" using b by auto
hoelzl@38656
   495
hoelzl@38656
   496
    from int_f_finite this
hoelzl@38656
   497
    have "?y + 0 < positive_integral f + b * \<mu> A0" unfolding int_f_eq_y
hoelzl@38656
   498
      by (rule pinfreal_less_add)
hoelzl@38656
   499
    also have "\<dots> = positive_integral ?f0" using f0_eq[OF top] `A0 \<in> sets M` sets_into_space
hoelzl@38656
   500
      by (simp cong: positive_integral_cong)
hoelzl@38656
   501
    finally have "?y < positive_integral ?f0" by simp
hoelzl@38656
   502
hoelzl@38656
   503
    moreover from `?f0 \<in> G` have "positive_integral ?f0 \<le> ?y" by (auto intro!: le_SUPI)
hoelzl@38656
   504
    ultimately show False by auto
hoelzl@38656
   505
  qed
hoelzl@38656
   506
hoelzl@38656
   507
  show ?thesis
hoelzl@38656
   508
  proof (safe intro!: bexI[of _ f])
hoelzl@38656
   509
    fix A assume "A\<in>sets M"
hoelzl@38656
   510
    show "\<nu> A = positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   511
    proof (rule antisym)
hoelzl@38656
   512
      show "positive_integral (\<lambda>x. f x * indicator A x) \<le> \<nu> A"
hoelzl@38656
   513
        using `f \<in> G` `A \<in> sets M` unfolding G_def by auto
hoelzl@38656
   514
      show "\<nu> A \<le> positive_integral (\<lambda>x. f x * indicator A x)"
hoelzl@38656
   515
        using upper_bound[THEN bspec, OF `A \<in> sets M`]
hoelzl@38656
   516
         by (simp add: pinfreal_zero_le_diff)
hoelzl@38656
   517
    qed
hoelzl@38656
   518
  qed simp
hoelzl@38656
   519
qed
hoelzl@38656
   520
hoelzl@38656
   521
lemma (in finite_measure) Radon_Nikodym_finite_measure_infinite:
hoelzl@38656
   522
  assumes "measure_space M \<nu>"
hoelzl@38656
   523
  assumes "absolutely_continuous \<nu>"
hoelzl@38656
   524
  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
   525
proof -
hoelzl@38656
   526
  interpret v: measure_space M \<nu> by fact
hoelzl@38656
   527
  let ?Q = "{Q\<in>sets M. \<nu> Q \<noteq> \<omega>}"
hoelzl@38656
   528
  let ?a = "SUP Q:?Q. \<mu> Q"
hoelzl@38656
   529
hoelzl@38656
   530
  have "{} \<in> ?Q" using v.empty_measure by auto
hoelzl@38656
   531
  then have Q_not_empty: "?Q \<noteq> {}" by blast
hoelzl@38656
   532
hoelzl@38656
   533
  have "?a \<le> \<mu> (space M)" using sets_into_space
hoelzl@38656
   534
    by (auto intro!: SUP_leI measure_mono top)
hoelzl@38656
   535
  then have "?a \<noteq> \<omega>" using finite_measure_of_space
hoelzl@38656
   536
    by auto
hoelzl@38656
   537
  from SUPR_countable_SUPR[OF this Q_not_empty]
hoelzl@38656
   538
  obtain Q'' where "range Q'' \<subseteq> \<mu> ` ?Q" and a: "?a = (SUP i::nat. Q'' i)"
hoelzl@38656
   539
    by auto
hoelzl@38656
   540
  then have "\<forall>i. \<exists>Q'. Q'' i = \<mu> Q' \<and> Q' \<in> ?Q" by auto
hoelzl@38656
   541
  from choice[OF this] obtain Q' where Q': "\<And>i. Q'' i = \<mu> (Q' i)" "\<And>i. Q' i \<in> ?Q"
hoelzl@38656
   542
    by auto
hoelzl@38656
   543
  then have a_Lim: "?a = (SUP i::nat. \<mu> (Q' i))" using a by simp
hoelzl@38656
   544
  let "?O n" = "\<Union>i\<le>n. Q' i"
hoelzl@38656
   545
  have Union: "(SUP i. \<mu> (?O i)) = \<mu> (\<Union>i. ?O i)"
hoelzl@38656
   546
  proof (rule continuity_from_below[of ?O])
hoelzl@38656
   547
    show "range ?O \<subseteq> sets M" using Q' by (auto intro!: finite_UN)
hoelzl@38656
   548
    show "\<And>i. ?O i \<subseteq> ?O (Suc i)" by fastsimp
hoelzl@38656
   549
  qed
hoelzl@38656
   550
hoelzl@38656
   551
  have Q'_sets: "\<And>i. Q' i \<in> sets M" using Q' by auto
hoelzl@38656
   552
hoelzl@38656
   553
  have O_sets: "\<And>i. ?O i \<in> sets M"
hoelzl@38656
   554
     using Q' by (auto intro!: finite_UN Un)
hoelzl@38656
   555
  then have O_in_G: "\<And>i. ?O i \<in> ?Q"
hoelzl@38656
   556
  proof (safe del: notI)
hoelzl@38656
   557
    fix i have "Q' ` {..i} \<subseteq> sets M"
hoelzl@38656
   558
      using Q' by (auto intro: finite_UN)
hoelzl@38656
   559
    with v.measure_finitely_subadditive[of "{.. i}" Q']
hoelzl@38656
   560
    have "\<nu> (?O i) \<le> (\<Sum>i\<le>i. \<nu> (Q' i))" by auto
hoelzl@38656
   561
    also have "\<dots> < \<omega>" unfolding setsum_\<omega> pinfreal_less_\<omega> using Q' by auto
hoelzl@38656
   562
    finally show "\<nu> (?O i) \<noteq> \<omega>" unfolding pinfreal_less_\<omega> by auto
hoelzl@38656
   563
  qed auto
hoelzl@38656
   564
  have O_mono: "\<And>n. ?O n \<subseteq> ?O (Suc n)" by fastsimp
hoelzl@38656
   565
hoelzl@38656
   566
  have a_eq: "?a = \<mu> (\<Union>i. ?O i)" unfolding Union[symmetric]
hoelzl@38656
   567
  proof (rule antisym)
hoelzl@38656
   568
    show "?a \<le> (SUP i. \<mu> (?O i))" unfolding a_Lim
hoelzl@38656
   569
      using Q' by (auto intro!: SUP_mono measure_mono finite_UN)
hoelzl@38656
   570
    show "(SUP i. \<mu> (?O i)) \<le> ?a" unfolding SUPR_def
hoelzl@38656
   571
    proof (safe intro!: Sup_mono, unfold bex_simps)
hoelzl@38656
   572
      fix i
hoelzl@38656
   573
      have *: "(\<Union>Q' ` {..i}) = ?O i" by auto
hoelzl@38656
   574
      then show "\<exists>x. (x \<in> sets M \<and> \<nu> x \<noteq> \<omega>) \<and>
hoelzl@38656
   575
        \<mu> (\<Union>Q' ` {..i}) \<le> \<mu> x"
hoelzl@38656
   576
        using O_in_G[of i] by (auto intro!: exI[of _ "?O i"])
hoelzl@38656
   577
    qed
hoelzl@38656
   578
  qed
hoelzl@38656
   579
hoelzl@38656
   580
  let "?O_0" = "(\<Union>i. ?O i)"
hoelzl@38656
   581
  have "?O_0 \<in> sets M" using Q' by auto
hoelzl@38656
   582
hoelzl@38656
   583
  { fix A assume *: "A \<in> ?Q" "A \<subseteq> space M - ?O_0"
hoelzl@38656
   584
    then have "\<mu> ?O_0 + \<mu> A = \<mu> (?O_0 \<union> A)"
hoelzl@38656
   585
      using Q' by (auto intro!: measure_additive countable_UN)
hoelzl@38656
   586
    also have "\<dots> = (SUP i. \<mu> (?O i \<union> A))"
hoelzl@38656
   587
    proof (rule continuity_from_below[of "\<lambda>i. ?O i \<union> A", symmetric, simplified])
hoelzl@38656
   588
      show "range (\<lambda>i. ?O i \<union> A) \<subseteq> sets M"
hoelzl@38656
   589
        using * O_sets by auto
hoelzl@38656
   590
    qed fastsimp
hoelzl@38656
   591
    also have "\<dots> \<le> ?a"
hoelzl@38656
   592
    proof (safe intro!: SUPR_bound)
hoelzl@38656
   593
      fix i have "?O i \<union> A \<in> ?Q"
hoelzl@38656
   594
      proof (safe del: notI)
hoelzl@38656
   595
        show "?O i \<union> A \<in> sets M" using O_sets * by auto
hoelzl@38656
   596
        from O_in_G[of i]
hoelzl@38656
   597
        moreover have "\<nu> (?O i \<union> A) \<le> \<nu> (?O i) + \<nu> A"
hoelzl@38656
   598
          using v.measure_subadditive[of "?O i" A] * O_sets by auto
hoelzl@38656
   599
        ultimately show "\<nu> (?O i \<union> A) \<noteq> \<omega>"
hoelzl@38656
   600
          using * by auto
hoelzl@38656
   601
      qed
hoelzl@38656
   602
      then show "\<mu> (?O i \<union> A) \<le> ?a" by (rule le_SUPI)
hoelzl@38656
   603
    qed
hoelzl@38656
   604
    finally have "\<mu> A = 0" unfolding a_eq using finite_measure[OF `?O_0 \<in> sets M`]
hoelzl@38656
   605
      by (cases "\<mu> A") (auto simp: pinfreal_noteq_omega_Ex) }
hoelzl@38656
   606
  note stetic = this
hoelzl@38656
   607
hoelzl@38656
   608
  def Q \<equiv> "\<lambda>i. case i of 0 \<Rightarrow> ?O 0 | Suc n \<Rightarrow> ?O (Suc n) - ?O n"
hoelzl@38656
   609
hoelzl@38656
   610
  { fix i have "Q i \<in> sets M" unfolding Q_def using Q'[of 0] by (cases i) (auto intro: O_sets) }
hoelzl@38656
   611
  note Q_sets = this
hoelzl@38656
   612
hoelzl@38656
   613
  { fix i have "\<nu> (Q i) \<noteq> \<omega>"
hoelzl@38656
   614
    proof (cases i)
hoelzl@38656
   615
      case 0 then show ?thesis
hoelzl@38656
   616
        unfolding Q_def using Q'[of 0] by simp
hoelzl@38656
   617
    next
hoelzl@38656
   618
      case (Suc n)
hoelzl@38656
   619
      then show ?thesis unfolding Q_def
hoelzl@38656
   620
        using `?O n \<in> ?Q` `?O (Suc n) \<in> ?Q` O_mono
hoelzl@38656
   621
        using v.measure_Diff[of "?O n" "?O (Suc n)"] by auto
hoelzl@38656
   622
    qed }
hoelzl@38656
   623
  note Q_omega = this
hoelzl@38656
   624
hoelzl@38656
   625
  { fix j have "(\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q i)"
hoelzl@38656
   626
    proof (induct j)
hoelzl@38656
   627
      case 0 then show ?case by (simp add: Q_def)
hoelzl@38656
   628
    next
hoelzl@38656
   629
      case (Suc j)
hoelzl@38656
   630
      have eq: "\<And>j. (\<Union>i\<le>j. ?O i) = (\<Union>i\<le>j. Q' i)" by fastsimp
hoelzl@38656
   631
      have "{..j} \<union> {..Suc j} = {..Suc j}" by auto
hoelzl@38656
   632
      then have "(\<Union>i\<le>Suc j. Q' i) = (\<Union>i\<le>j. Q' i) \<union> Q (Suc j)"
hoelzl@38656
   633
        by (simp add: UN_Un[symmetric] Q_def del: UN_Un)
hoelzl@38656
   634
      then show ?case using Suc by (auto simp add: eq atMost_Suc)
hoelzl@38656
   635
    qed }
hoelzl@38656
   636
  then have "(\<Union>j. (\<Union>i\<le>j. ?O i)) = (\<Union>j. (\<Union>i\<le>j. Q i))" by simp
hoelzl@38656
   637
  then have O_0_eq_Q: "?O_0 = (\<Union>j. Q j)" by fastsimp
hoelzl@38656
   638
hoelzl@38656
   639
  have "\<forall>i. \<exists>f. f\<in>borel_measurable M \<and> (\<forall>A\<in>sets M.
hoelzl@38656
   640
    \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f x * indicator (Q i \<inter> A) x))"
hoelzl@38656
   641
  proof
hoelzl@38656
   642
    fix i
hoelzl@38656
   643
    have indicator_eq: "\<And>f x A. (f x :: pinfreal) * indicator (Q i \<inter> A) x * indicator (Q i) x
hoelzl@38656
   644
      = (f x * indicator (Q i) x) * indicator A x"
hoelzl@38656
   645
      unfolding indicator_def by auto
hoelzl@38656
   646
hoelzl@39092
   647
    have fm: "finite_measure (restricted_space (Q i)) \<mu>"
hoelzl@38656
   648
      (is "finite_measure ?R \<mu>") by (rule restricted_finite_measure[OF Q_sets[of i]])
hoelzl@38656
   649
    then interpret R: finite_measure ?R .
hoelzl@38656
   650
    have fmv: "finite_measure ?R \<nu>"
hoelzl@38656
   651
      unfolding finite_measure_def finite_measure_axioms_def
hoelzl@38656
   652
    proof
hoelzl@38656
   653
      show "measure_space ?R \<nu>"
hoelzl@38656
   654
        using v.restricted_measure_space Q_sets[of i] by auto
hoelzl@38656
   655
      show "\<nu>  (space ?R) \<noteq> \<omega>"
hoelzl@38656
   656
        using Q_omega by simp
hoelzl@38656
   657
    qed
hoelzl@38656
   658
    have "R.absolutely_continuous \<nu>"
hoelzl@38656
   659
      using `absolutely_continuous \<nu>` `Q i \<in> sets M`
hoelzl@38656
   660
      by (auto simp: R.absolutely_continuous_def absolutely_continuous_def)
hoelzl@38656
   661
    from finite_measure.Radon_Nikodym_finite_measure[OF fm fmv this]
hoelzl@38656
   662
    obtain f where f: "(\<lambda>x. f x * indicator (Q i) x) \<in> borel_measurable M"
hoelzl@38656
   663
      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
   664
      unfolding Bex_def borel_measurable_restricted[OF `Q i \<in> sets M`]
hoelzl@38656
   665
        positive_integral_restricted[OF `Q i \<in> sets M`] by (auto simp: indicator_eq)
hoelzl@38656
   666
    then show "\<exists>f. f\<in>borel_measurable M \<and> (\<forall>A\<in>sets M.
hoelzl@38656
   667
      \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f x * indicator (Q i \<inter> A) x))"
hoelzl@38656
   668
      by (fastsimp intro!: exI[of _ "\<lambda>x. f x * indicator (Q i) x"] positive_integral_cong
hoelzl@38656
   669
          simp: indicator_def)
hoelzl@38656
   670
  qed
hoelzl@38656
   671
  from choice[OF this] obtain f where borel: "\<And>i. f i \<in> borel_measurable M"
hoelzl@38656
   672
    and f: "\<And>A i. A \<in> sets M \<Longrightarrow>
hoelzl@38656
   673
      \<nu> (Q i \<inter> A) = positive_integral (\<lambda>x. f i x * indicator (Q i \<inter> A) x)"
hoelzl@38656
   674
    by auto
hoelzl@38656
   675
  let "?f x" =
hoelzl@38656
   676
    "(\<Sum>\<^isub>\<infinity> i. f i x * indicator (Q i) x) + \<omega> * indicator (space M - ?O_0) x"
hoelzl@38656
   677
  show ?thesis
hoelzl@38656
   678
  proof (safe intro!: bexI[of _ ?f])
hoelzl@38656
   679
    show "?f \<in> borel_measurable M"
hoelzl@38656
   680
      by (safe intro!: borel_measurable_psuminf borel_measurable_pinfreal_times
hoelzl@38656
   681
        borel_measurable_pinfreal_add borel_measurable_indicator
hoelzl@38656
   682
        borel_measurable_const borel Q_sets O_sets Diff countable_UN)
hoelzl@38656
   683
    fix A assume "A \<in> sets M"
hoelzl@38656
   684
    let ?C = "(space M - (\<Union>i. Q i)) \<inter> A"
hoelzl@38656
   685
    have *: 
hoelzl@38656
   686
      "\<And>x i. indicator A x * (f i x * indicator (Q i) x) =
hoelzl@38656
   687
        f i x * indicator (Q i \<inter> A) x"
hoelzl@38656
   688
      "\<And>x i. (indicator A x * indicator (space M - (\<Union>i. UNION {..i} Q')) x :: pinfreal) =
hoelzl@38656
   689
        indicator ?C x" unfolding O_0_eq_Q by (auto simp: indicator_def)
hoelzl@38656
   690
    have "positive_integral (\<lambda>x. ?f x * indicator A x) =
hoelzl@38656
   691
      (\<Sum>\<^isub>\<infinity> i. \<nu> (Q i \<inter> A)) + \<omega> * \<mu> ?C"
hoelzl@38656
   692
      unfolding f[OF `A \<in> sets M`]
hoelzl@38656
   693
      apply (simp del: pinfreal_times(2) add: field_simps)
hoelzl@38656
   694
      apply (subst positive_integral_add)
hoelzl@38656
   695
      apply (safe intro!: borel_measurable_pinfreal_times Diff borel_measurable_const
hoelzl@38656
   696
        borel_measurable_psuminf borel_measurable_indicator `A \<in> sets M` Q_sets borel countable_UN Q'_sets)
hoelzl@38656
   697
      unfolding psuminf_cmult_right[symmetric]
hoelzl@38656
   698
      apply (subst positive_integral_psuminf)
hoelzl@38656
   699
      apply (safe intro!: borel_measurable_pinfreal_times Diff borel_measurable_const
hoelzl@38656
   700
        borel_measurable_psuminf borel_measurable_indicator `A \<in> sets M` Q_sets borel countable_UN Q'_sets)
hoelzl@38656
   701
      apply (subst positive_integral_cmult)
hoelzl@38656
   702
      apply (safe intro!: borel_measurable_pinfreal_times Diff borel_measurable_const
hoelzl@38656
   703
        borel_measurable_psuminf borel_measurable_indicator `A \<in> sets M` Q_sets borel countable_UN Q'_sets)
hoelzl@38656
   704
      unfolding *
hoelzl@38656
   705
      apply (subst positive_integral_indicator)
hoelzl@38656
   706
      apply (safe intro!: borel_measurable_pinfreal_times Diff borel_measurable_const Int
hoelzl@38656
   707
        borel_measurable_psuminf borel_measurable_indicator `A \<in> sets M` Q_sets borel countable_UN Q'_sets)
hoelzl@38656
   708
      by simp
hoelzl@38656
   709
    moreover have "(\<Sum>\<^isub>\<infinity>i. \<nu> (Q i \<inter> A)) = \<nu> ((\<Union>i. Q i) \<inter> A)"
hoelzl@38656
   710
    proof (rule v.measure_countably_additive[of "\<lambda>i. Q i \<inter> A", unfolded comp_def, simplified])
hoelzl@38656
   711
      show "range (\<lambda>i. Q i \<inter> A) \<subseteq> sets M"
hoelzl@38656
   712
        using Q_sets `A \<in> sets M` by auto
hoelzl@38656
   713
      show "disjoint_family (\<lambda>i. Q i \<inter> A)"
hoelzl@38656
   714
        by (fastsimp simp: disjoint_family_on_def Q_def
hoelzl@38656
   715
          split: nat.split_asm)
hoelzl@38656
   716
    qed
hoelzl@38656
   717
    moreover have "\<omega> * \<mu> ?C = \<nu> ?C"
hoelzl@38656
   718
    proof cases
hoelzl@38656
   719
      assume null: "\<mu> ?C = 0"
hoelzl@38656
   720
      hence "?C \<in> null_sets" using Q_sets `A \<in> sets M` by auto
hoelzl@38656
   721
      with `absolutely_continuous \<nu>` and null
hoelzl@38656
   722
      show ?thesis by (simp add: absolutely_continuous_def)
hoelzl@38656
   723
    next
hoelzl@38656
   724
      assume not_null: "\<mu> ?C \<noteq> 0"
hoelzl@38656
   725
      have "\<nu> ?C = \<omega>"
hoelzl@38656
   726
      proof (rule ccontr)
hoelzl@38656
   727
        assume "\<nu> ?C \<noteq> \<omega>"
hoelzl@38656
   728
        then have "?C \<in> ?Q"
hoelzl@38656
   729
          using Q_sets `A \<in> sets M` by auto
hoelzl@38656
   730
        from stetic[OF this] not_null
hoelzl@38656
   731
        show False unfolding O_0_eq_Q by auto
hoelzl@38656
   732
      qed
hoelzl@38656
   733
      then show ?thesis using not_null by simp
hoelzl@38656
   734
    qed
hoelzl@38656
   735
    moreover have "?C \<in> sets M" "((\<Union>i. Q i) \<inter> A) \<in> sets M"
hoelzl@38656
   736
      using Q_sets `A \<in> sets M` by (auto intro!: countable_UN)
hoelzl@38656
   737
    moreover have "((\<Union>i. Q i) \<inter> A) \<union> ?C = A" "((\<Union>i. Q i) \<inter> A) \<inter> ?C = {}"
hoelzl@38656
   738
      using `A \<in> sets M` sets_into_space by auto
hoelzl@38656
   739
    ultimately show "\<nu> A = positive_integral (\<lambda>x. ?f x * indicator A x)"
hoelzl@38656
   740
      using v.measure_additive[simplified, of "(\<Union>i. Q i) \<inter> A" ?C] by auto
hoelzl@38656
   741
  qed
hoelzl@38656
   742
qed
hoelzl@38656
   743
hoelzl@38656
   744
lemma (in sigma_finite_measure) Radon_Nikodym:
hoelzl@38656
   745
  assumes "measure_space M \<nu>"
hoelzl@38656
   746
  assumes "absolutely_continuous \<nu>"
hoelzl@38656
   747
  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
   748
proof -
hoelzl@38656
   749
  from Ex_finite_integrable_function
hoelzl@38656
   750
  obtain h where finite: "positive_integral h \<noteq> \<omega>" and
hoelzl@38656
   751
    borel: "h \<in> borel_measurable M" and
hoelzl@38656
   752
    pos: "\<And>x. x \<in> space M \<Longrightarrow> 0 < h x" and
hoelzl@38656
   753
    "\<And>x. x \<in> space M \<Longrightarrow> h x < \<omega>" by auto
hoelzl@38656
   754
  let "?T A" = "positive_integral (\<lambda>x. h x * indicator A x)"
hoelzl@38656
   755
  from measure_space_density[OF borel] finite
hoelzl@38656
   756
  interpret T: finite_measure M ?T
hoelzl@38656
   757
    unfolding finite_measure_def finite_measure_axioms_def
hoelzl@38656
   758
    by (simp cong: positive_integral_cong)
hoelzl@38656
   759
  have "\<And>N. N \<in> sets M \<Longrightarrow> {x \<in> space M. h x \<noteq> 0 \<and> indicator N x \<noteq> (0::pinfreal)} = N"
hoelzl@38656
   760
    using sets_into_space pos by (force simp: indicator_def)
hoelzl@38656
   761
  then have "T.absolutely_continuous \<nu>" using assms(2) borel
hoelzl@38656
   762
    unfolding T.absolutely_continuous_def absolutely_continuous_def
hoelzl@38656
   763
    by (fastsimp simp: borel_measurable_indicator positive_integral_0_iff)
hoelzl@38656
   764
  from T.Radon_Nikodym_finite_measure_infinite[simplified, OF assms(1) this]
hoelzl@38656
   765
  obtain f where f_borel: "f \<in> borel_measurable M" and
hoelzl@38656
   766
    fT: "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = T.positive_integral (\<lambda>x. f x * indicator A x)" by auto
hoelzl@38656
   767
  show ?thesis
hoelzl@38656
   768
  proof (safe intro!: bexI[of _ "\<lambda>x. h x * f x"])
hoelzl@38656
   769
    show "(\<lambda>x. h x * f x) \<in> borel_measurable M"
hoelzl@38656
   770
      using borel f_borel by (auto intro: borel_measurable_pinfreal_times)
hoelzl@38656
   771
    fix A assume "A \<in> sets M"
hoelzl@38656
   772
    then have "(\<lambda>x. f x * indicator A x) \<in> borel_measurable M"
hoelzl@38656
   773
      using f_borel by (auto intro: borel_measurable_pinfreal_times borel_measurable_indicator)
hoelzl@38656
   774
    from positive_integral_translated_density[OF borel this]
hoelzl@38656
   775
    show "\<nu> A = positive_integral (\<lambda>x. h x * f x * indicator A x)"
hoelzl@38656
   776
      unfolding fT[OF `A \<in> sets M`] by (simp add: field_simps)
hoelzl@38656
   777
  qed
hoelzl@38656
   778
qed
hoelzl@38656
   779
hoelzl@38656
   780
section "Radon Nikodym derivative"
hoelzl@38656
   781
hoelzl@38656
   782
definition (in sigma_finite_measure)
hoelzl@38656
   783
  "RN_deriv \<nu> \<equiv> SOME f. f \<in> borel_measurable M \<and>
hoelzl@38656
   784
    (\<forall>A \<in> sets M. \<nu> A = positive_integral (\<lambda>x. f x * indicator A x))"
hoelzl@38656
   785
hoelzl@38656
   786
lemma (in sigma_finite_measure) RN_deriv:
hoelzl@38656
   787
  assumes "measure_space M \<nu>"
hoelzl@38656
   788
  assumes "absolutely_continuous \<nu>"
hoelzl@38656
   789
  shows "RN_deriv \<nu> \<in> borel_measurable M" (is ?borel)
hoelzl@38656
   790
  and "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = positive_integral (\<lambda>x. RN_deriv \<nu> x * indicator A x)"
hoelzl@38656
   791
    (is "\<And>A. _ \<Longrightarrow> ?int A")
hoelzl@38656
   792
proof -
hoelzl@38656
   793
  note Ex = Radon_Nikodym[OF assms, unfolded Bex_def]
hoelzl@38656
   794
  thus ?borel unfolding RN_deriv_def by (rule someI2_ex) auto
hoelzl@38656
   795
  fix A assume "A \<in> sets M"
hoelzl@38656
   796
  from Ex show "?int A" unfolding RN_deriv_def
hoelzl@38656
   797
    by (rule someI2_ex) (simp add: `A \<in> sets M`)
hoelzl@38656
   798
qed
hoelzl@38656
   799
hoelzl@38656
   800
lemma (in sigma_finite_measure) RN_deriv_singleton:
hoelzl@38656
   801
  assumes "measure_space M \<nu>"
hoelzl@38656
   802
  and ac: "absolutely_continuous \<nu>"
hoelzl@38656
   803
  and "{x} \<in> sets M"
hoelzl@38656
   804
  shows "\<nu> {x} = RN_deriv \<nu> x * \<mu> {x}"
hoelzl@38656
   805
proof -
hoelzl@38656
   806
  note deriv = RN_deriv[OF assms(1, 2)]
hoelzl@38656
   807
  from deriv(2)[OF `{x} \<in> sets M`]
hoelzl@38656
   808
  have "\<nu> {x} = positive_integral (\<lambda>w. RN_deriv \<nu> x * indicator {x} w)"
hoelzl@38656
   809
    by (auto simp: indicator_def intro!: positive_integral_cong)
hoelzl@38656
   810
  thus ?thesis using positive_integral_cmult_indicator[OF `{x} \<in> sets M`]
hoelzl@38656
   811
    by auto
hoelzl@38656
   812
qed
hoelzl@38656
   813
hoelzl@38656
   814
theorem (in finite_measure_space) RN_deriv_finite_measure:
hoelzl@38656
   815
  assumes "measure_space M \<nu>"
hoelzl@38656
   816
  and ac: "absolutely_continuous \<nu>"
hoelzl@38656
   817
  and "x \<in> space M"
hoelzl@38656
   818
  shows "\<nu> {x} = RN_deriv \<nu> x * \<mu> {x}"
hoelzl@38656
   819
proof -
hoelzl@38656
   820
  have "{x} \<in> sets M" using sets_eq_Pow `x \<in> space M` by auto
hoelzl@38656
   821
  from RN_deriv_singleton[OF assms(1,2) this] show ?thesis .
hoelzl@38656
   822
qed
hoelzl@38656
   823
hoelzl@38656
   824
end