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