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