# HG changeset patch # User hoelzl # Date 1476376566 -7200 # Node ID 979cdfdf7a79daa1a06a256e89680b50f6899d80 # Parent 261d42f0bfac06ef84076cf56e707f3cfa68269f HOL-Probability: move conditional expectation from AFP/Ergodic_Theory diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Analysis/Bochner_Integration.thy --- a/src/HOL/Analysis/Bochner_Integration.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Analysis/Bochner_Integration.thy Thu Oct 13 18:36:06 2016 +0200 @@ -1747,11 +1747,23 @@ unfolding sums_iff by auto qed -lemma integral_norm_bound: +lemma integral_norm_bound [simp]: fixes f :: "_ \ 'a :: {banach, second_countable_topology}" - shows "integrable M f \ norm (integral\<^sup>L M f) \ (\x. norm (f x) \M)" - using nn_integral_eq_integral[of M "\x. norm (f x)"] - using integral_norm_bound_ennreal[of M f] by (simp add: integral_nonneg_AE) + shows "norm (integral\<^sup>L M f) \ (\x. norm (f x) \M)" +proof (cases "integrable M f") + case True then show ?thesis + using nn_integral_eq_integral[of M "\x. norm (f x)"] integral_norm_bound_ennreal[of M f] + by (simp add: integral_nonneg_AE) +next + case False + then have "norm (integral\<^sup>L M f) = 0" by (simp add: not_integrable_integral_eq) + moreover have "(\x. norm (f x) \M) \ 0" by auto + ultimately show ?thesis by simp +qed + +lemma integral_abs_bound [simp]: + fixes f :: "'a \ real" shows "abs (\x. f x \M) \ (\x. \f x\ \M)" +using integral_norm_bound[of M f] by auto lemma integral_eq_nn_integral: assumes [measurable]: "f \ borel_measurable M" @@ -1919,6 +1931,30 @@ integral\<^sup>L M f \ integral\<^sup>L M g" by (intro integral_mono_AE) auto +text {*The next two statements are useful to bound Lebesgue integrals, as they avoid one +integrability assumption. The price to pay is that the upper function has to be nonnegative, +but this is often true and easy to check in computations.*} + +lemma integral_mono_AE': + fixes f::"_ \ real" + assumes "integrable M f" "AE x in M. g x \ f x" "AE x in M. 0 \ f x" + shows "(\x. g x \M) \ (\x. f x \M)" +proof (cases "integrable M g") + case True + show ?thesis by (rule integral_mono_AE, auto simp add: assms True) +next + case False + then have "(\x. g x \M) = 0" by (simp add: not_integrable_integral_eq) + also have "... \ (\x. f x \M)" by (simp add: integral_nonneg_AE[OF assms(3)]) + finally show ?thesis by simp +qed + +lemma integral_mono': + fixes f::"_ \ real" + assumes "integrable M f" "\x. x \ space M \ g x \ f x" "\x. x \ space M \ 0 \ f x" + shows "(\x. g x \M) \ (\x. f x \M)" +by (rule integral_mono_AE', insert assms, auto) + lemma (in finite_measure) integrable_measure: assumes I: "disjoint_family_on X I" "countable I" shows "integrable (count_space I) (\i. measure M (X i))" @@ -1942,6 +1978,12 @@ finally show "(\\<^sup>+ x. ennreal (norm (f x)) \M) < \" . qed fact +lemma nn_integral_nonneg_infinite: + fixes f::"'a \ real" + assumes "f \ borel_measurable M" "\ integrable M f" "AE x in M. f x \ 0" + shows "(\\<^sup>+x. f x \M) = \" +using assms integrableI_real_bounded less_top by auto + lemma integral_real_bounded: assumes "0 \ r" "integral\<^sup>N M f \ ennreal r" shows "integral\<^sup>L M f \ r" @@ -1966,6 +2008,220 @@ using \0 \ r\ by (simp add: not_integrable_integral_eq) qed +lemma integrable_Min: + fixes f:: "_ \ _ \ real" + assumes "finite I" "I \ {}" + "\i. i \ I \ integrable M (f i)" + shows "integrable M (\x. Min {f i x|i. i \ I})" +using assms apply (induct rule: finite_ne_induct) apply simp+ +proof - + fix j F assume H: "finite F" "F \ {}" "integrable M (\x. Min {f i x |i. i \ F})" + "(\i. i = j \ i \ F \ integrable M (f i))" + have "{f i x |i. i = j \ i \ F} = insert (f j x) {f i x |i. i \ F}" for x by blast + then have "Min {f i x |i. i = j \ i \ F} = min (f j x) (Min {f i x |i. i \ F})" for x + using H(1) H(2) Min_insert by simp + moreover have "integrable M (\x. min (f j x) (Min {f i x |i. i \ F}))" + by (rule integrable_min, auto simp add: H) + ultimately show "integrable M (\x. Min {f i x |i. i = j \ i \ F})" by simp +qed + +lemma integrable_Max: + fixes f:: "_ \ _ \ real" + assumes "finite I" "I \ {}" + "\i. i \ I \ integrable M (f i)" + shows "integrable M (\x. Max {f i x|i. i \ I})" +using assms apply (induct rule: finite_ne_induct) apply simp+ +proof - + fix j F assume H: "finite F" "F \ {}" "integrable M (\x. Max {f i x |i. i \ F})" + "(\i. i = j \ i \ F \ integrable M (f i))" + have "{f i x |i. i = j \ i \ F} = insert (f j x) {f i x |i. i \ F}" for x by blast + then have "Max {f i x |i. i = j \ i \ F} = max (f j x) (Max {f i x |i. i \ F})" for x + using H(1) H(2) Max_insert by simp + moreover have "integrable M (\x. max (f j x) (Max {f i x |i. i \ F}))" + by (rule integrable_max, auto simp add: H) + ultimately show "integrable M (\x. Max {f i x |i. i = j \ i \ F})" by simp +qed + +lemma integral_Markov_inequality: + assumes [measurable]: "integrable M u" and "AE x in M. 0 \ u x" "0 < (c::real)" + shows "(emeasure M) {x\space M. u x \ c} \ (1/c) * (\x. u x \M)" +proof - + have "(\\<^sup>+ x. ennreal(u x) * indicator (space M) x \M) \ (\\<^sup>+ x. u x \M)" + by (rule nn_integral_mono_AE, auto simp add: `c>0` less_eq_real_def) + also have "... = (\x. u x \M)" + by (rule nn_integral_eq_integral, auto simp add: assms) + finally have *: "(\\<^sup>+ x. ennreal(u x) * indicator (space M) x \M) \ (\x. u x \M)" + by simp + + have "{x \ space M. u x \ c} = {x \ space M. ennreal(1/c) * u x \ 1} \ (space M)" + using `c>0` by (auto simp: ennreal_mult'[symmetric]) + then have "emeasure M {x \ space M. u x \ c} = emeasure M ({x \ space M. ennreal(1/c) * u x \ 1} \ (space M))" + by simp + also have "... \ ennreal(1/c) * (\\<^sup>+ x. ennreal(u x) * indicator (space M) x \M)" + by (rule nn_integral_Markov_inequality) (auto simp add: assms) + also have "... \ ennreal(1/c) * (\x. u x \M)" + apply (rule mult_left_mono) using * `c>0` by auto + finally show ?thesis + using \0 by (simp add: ennreal_mult'[symmetric]) +qed + +lemma integral_ineq_eq_0_then_AE: + fixes f::"_ \ real" + assumes "AE x in M. f x \ g x" "integrable M f" "integrable M g" + "(\x. f x \M) = (\x. g x \M)" + shows "AE x in M. f x = g x" +proof - + define h where "h = (\x. g x - f x)" + have "AE x in M. h x = 0" + apply (subst integral_nonneg_eq_0_iff_AE[symmetric]) + unfolding h_def using assms by auto + then show ?thesis unfolding h_def by auto +qed + +lemma not_AE_zero_int_E: + fixes f::"'a \ real" + assumes "AE x in M. f x \ 0" "(\x. f x \M) > 0" + and [measurable]: "f \ borel_measurable M" + shows "\A e. A \ sets M \ e>0 \ emeasure M A > 0 \ (\x \ A. f x \ e)" +proof (rule not_AE_zero_E, auto simp add: assms) + assume *: "AE x in M. f x = 0" + have "(\x. f x \M) = (\x. 0 \M)" by (rule integral_cong_AE, auto simp add: *) + then have "(\x. f x \M) = 0" by simp + then show False using assms(2) by simp +qed + +lemma tendsto_L1_int: + fixes u :: "_ \ _ \ 'b::{banach, second_countable_topology}" + assumes [measurable]: "\n. integrable M (u n)" "integrable M f" + and "((\n. (\\<^sup>+x. norm(u n x - f x) \M)) \ 0) F" + shows "((\n. (\x. u n x \M)) \ (\x. f x \M)) F" +proof - + have "((\n. norm((\x. u n x \M) - (\x. f x \M))) \ (0::ennreal)) F" + proof (rule tendsto_sandwich[of "\_. 0", where ?h = "\n. (\\<^sup>+x. norm(u n x - f x) \M)"], auto simp add: assms) + { + fix n + have "(\x. u n x \M) - (\x. f x \M) = (\x. u n x - f x \M)" + apply (rule Bochner_Integration.integral_diff[symmetric]) using assms by auto + then have "norm((\x. u n x \M) - (\x. f x \M)) = norm (\x. u n x - f x \M)" + by auto + also have "... \ (\x. norm(u n x - f x) \M)" + by (rule integral_norm_bound) + finally have "ennreal(norm((\x. u n x \M) - (\x. f x \M))) \ (\x. norm(u n x - f x) \M)" + by simp + also have "... = (\\<^sup>+x. norm(u n x - f x) \M)" + apply (rule nn_integral_eq_integral[symmetric]) using assms by auto + finally have "norm((\x. u n x \M) - (\x. f x \M)) \ (\\<^sup>+x. norm(u n x - f x) \M)" by simp + } + then show "eventually (\n. norm((\x. u n x \M) - (\x. f x \M)) \ (\\<^sup>+x. norm(u n x - f x) \M)) F" + by auto + qed + then have "((\n. norm((\x. u n x \M) - (\x. f x \M))) \ 0) F" + by (simp add: ennreal_0[symmetric] del: ennreal_0) + then have "((\n. ((\x. u n x \M) - (\x. f x \M))) \ 0) F" using tendsto_norm_zero_iff by blast + then show ?thesis using Lim_null by auto +qed + +text {*The next lemma asserts that, if a sequence of functions converges in $L^1$, then +it admits a subsequence that converges almost everywhere.*} + +lemma tendsto_L1_AE_subseq: + fixes u :: "nat \ 'a \ 'b::{banach, second_countable_topology}" + assumes [measurable]: "\n. integrable M (u n)" + and "(\n. (\x. norm(u n x) \M)) \ 0" + shows "\r. subseq r \ (AE x in M. (\n. u (r n) x) \ 0)" +proof - + { + fix k + have "eventually (\n. (\x. norm(u n x) \M) < (1/2)^k) sequentially" + using order_tendstoD(2)[OF assms(2)] by auto + with eventually_elim2[OF eventually_gt_at_top[of k] this] + have "\n>k. (\x. norm(u n x) \M) < (1/2)^k" + by (metis eventually_False_sequentially) + } + then have "\r. \n. True \ (r (Suc n) > r n \ (\x. norm(u (r (Suc n)) x) \M) < (1/2)^(r n))" + by (intro dependent_nat_choice, auto) + then obtain r0 where r0: "subseq r0" "\n. (\x. norm(u (r0 (Suc n)) x) \M) < (1/2)^(r0 n)" + by (auto simp: subseq_Suc_iff) + define r where "r = (\n. r0(n+1))" + have "subseq r" unfolding r_def using r0(1) by (simp add: subseq_Suc_iff) + have I: "(\\<^sup>+x. norm(u (r n) x) \M) < ennreal((1/2)^n)" for n + proof - + have "r0 n \ n" using `subseq r0` by (simp add: seq_suble) + have "(1/2::real)^(r0 n) \ (1/2)^n" by (rule power_decreasing[OF `r0 n \ n`], auto) + then have "(\x. norm(u (r0 (Suc n)) x) \M) < (1/2)^n" using r0(2) less_le_trans by auto + then have "(\x. norm(u (r n) x) \M) < (1/2)^n" unfolding r_def by auto + moreover have "(\\<^sup>+x. norm(u (r n) x) \M) = (\x. norm(u (r n) x) \M)" + by (rule nn_integral_eq_integral, auto simp add: integrable_norm[OF assms(1)[of "r n"]]) + ultimately show ?thesis by (auto intro: ennreal_lessI) + qed + + have "AE x in M. limsup (\n. ennreal (norm(u (r n) x))) \ 0" + proof (rule AE_upper_bound_inf_ennreal) + fix e::real assume "e > 0" + define A where "A = (\n. {x \ space M. norm(u (r n) x) \ e})" + have A_meas [measurable]: "\n. A n \ sets M" unfolding A_def by auto + have A_bound: "emeasure M (A n) < (1/e) * ennreal((1/2)^n)" for n + proof - + have *: "indicator (A n) x \ (1/e) * ennreal(norm(u (r n) x))" for x + apply (cases "x \ A n") unfolding A_def using \0 < e\ by (auto simp: ennreal_mult[symmetric]) + have "emeasure M (A n) = (\\<^sup>+x. indicator (A n) x \M)" by auto + also have "... \ (\\<^sup>+x. (1/e) * ennreal(norm(u (r n) x)) \M)" + apply (rule nn_integral_mono) using * by auto + also have "... = (1/e) * (\\<^sup>+x. norm(u (r n) x) \M)" + apply (rule nn_integral_cmult) using `e > 0` by auto + also have "... < (1/e) * ennreal((1/2)^n)" + using I[of n] `e > 0` by (intro ennreal_mult_strict_left_mono) auto + finally show ?thesis by simp + qed + have A_fin: "emeasure M (A n) < \" for n + using `e > 0` A_bound[of n] + by (auto simp add: ennreal_mult less_top[symmetric]) + + have A_sum: "summable (\n. measure M (A n))" + proof (rule summable_comparison_test'[of "\n. (1/e) * (1/2)^n" 0]) + have "summable (\n. (1/(2::real))^n)" by (simp add: summable_geometric) + then show "summable (\n. (1/e) * (1/2)^n)" using summable_mult by blast + fix n::nat assume "n \ 0" + have "norm(measure M (A n)) = measure M (A n)" by simp + also have "... = enn2real(emeasure M (A n))" unfolding measure_def by simp + also have "... < enn2real((1/e) * (1/2)^n)" + using A_bound[of n] \emeasure M (A n) < \\ \0 < e\ + by (auto simp: emeasure_eq_ennreal_measure ennreal_mult[symmetric] ennreal_less_iff) + also have "... = (1/e) * (1/2)^n" + using \0 by auto + finally show "norm(measure M (A n)) \ (1/e) * (1/2)^n" by simp + qed + + have "AE x in M. eventually (\n. x \ space M - A n) sequentially" + by (rule borel_cantelli_AE1[OF A_meas A_fin A_sum]) + moreover + { + fix x assume "eventually (\n. x \ space M - A n) sequentially" + moreover have "norm(u (r n) x) \ ennreal e" if "x \ space M - A n" for n + using that unfolding A_def by (auto intro: ennreal_leI) + ultimately have "eventually (\n. norm(u (r n) x) \ ennreal e) sequentially" + by (simp add: eventually_mono) + then have "limsup (\n. ennreal (norm(u (r n) x))) \ e" + by (simp add: Limsup_bounded) + } + ultimately show "AE x in M. limsup (\n. ennreal (norm(u (r n) x))) \ 0 + ennreal e" by auto + qed + moreover + { + fix x assume "limsup (\n. ennreal (norm(u (r n) x))) \ 0" + moreover then have "liminf (\n. ennreal (norm(u (r n) x))) \ 0" + by (rule order_trans[rotated]) (auto intro: Liminf_le_Limsup) + ultimately have "(\n. ennreal (norm(u (r n) x))) \ 0" + using tendsto_Limsup[of sequentially "\n. ennreal (norm(u (r n) x))"] by auto + then have "(\n. norm(u (r n) x)) \ 0" + by (simp add: ennreal_0[symmetric] del: ennreal_0) + then have "(\n. u (r n) x) \ 0" + by (simp add: tendsto_norm_zero_iff) + } + ultimately have "AE x in M. (\n. u (r n) x) \ 0" by auto + then show ?thesis using `subseq r` by auto +qed + subsection \Restricted measure spaces\ lemma integrable_restrict_space: @@ -2478,6 +2734,12 @@ apply auto done +lemma (in finite_measure) integral_bounded_eq_bound_then_AE: + assumes "AE x in M. f x \ (c::real)" + "integrable M f" "(\x. f x \M) = c * measure M (space M)" + shows "AE x in M. f x = c" + apply (rule integral_ineq_eq_0_then_AE) using assms by auto + lemma integral_indicator_finite_real: fixes f :: "'a \ real" assumes [simp]: "finite A" diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Analysis/Borel_Space.thy --- a/src/HOL/Analysis/Borel_Space.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Analysis/Borel_Space.thy Thu Oct 13 18:36:06 2016 +0200 @@ -1896,6 +1896,9 @@ by auto qed +text \The next lemmas hold in any second countable linorder (including ennreal or ereal for instance), +but in the current state they are restricted to reals.\ + lemma borel_measurable_mono_on_fnc: fixes f :: "real \ real" and A :: "real set" assumes "mono_on f A" @@ -1907,6 +1910,12 @@ intro!: borel_measurable_continuous_on_restrict intro: continuous_within_subset) done +lemma borel_measurable_piecewise_mono: + fixes f::"real \ real" and C::"real set set" + assumes "countable C" "\c. c \ C \ c \ sets borel" "\c. c \ C \ mono_on f c" "(\C) = UNIV" + shows "f \ borel_measurable borel" +by (rule measurable_piecewise_restrict[of C], auto intro: borel_measurable_mono_on_fnc simp: assms) + lemma borel_measurable_mono: fixes f :: "real \ real" shows "mono f \ f \ borel_measurable borel" diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Analysis/Measurable.thy --- a/src/HOL/Analysis/Measurable.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Analysis/Measurable.thy Thu Oct 13 18:36:06 2016 +0200 @@ -636,6 +636,16 @@ unfolding pred_restrict_space[OF P_f] by (simp cong: measurable_cong) qed +lemma measurable_limsup [measurable (raw)]: + assumes [measurable]: "\n. A n \ sets M" + shows "limsup A \ sets M" +by (subst limsup_INF_SUP, auto) + +lemma measurable_liminf [measurable (raw)]: + assumes [measurable]: "\n. A n \ sets M" + shows "liminf A \ sets M" +by (subst liminf_SUP_INF, auto) + hide_const (open) pred end diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Analysis/Measure_Space.thy --- a/src/HOL/Analysis/Measure_Space.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Analysis/Measure_Space.thy Thu Oct 13 18:36:06 2016 +0200 @@ -1059,6 +1059,11 @@ with AE_iff_null[of M P] assms show ?thesis by auto qed +lemma AE_E3: + assumes "AE x in M. P x" + obtains N where "\x. x \ space M - N \ P x" "N \ null_sets M" +using assms unfolding eventually_ae_filter by auto + lemma AE_I: assumes "{x \ space M. \ P x} \ N" "emeasure M N = 0" "N \ sets M" shows "AE x in M. P x" @@ -1087,6 +1092,10 @@ qed qed +text {*The next lemma is convenient to combine with a lemma whose conclusion is of the +form \AE x in M. P x = Q x\: for such a lemma, there is no \verb+[symmetric]+ variant, +but using \AE_symmetric[OF...]\ will replace it.*} + (* depricated replace by laws about eventually *) lemma shows AE_iffI: "AE x in M. P x \ AE x in M. P x \ Q x \ AE x in M. Q x" @@ -1096,6 +1105,11 @@ and AE_conj_iff[simp]: "(AE x in M. P x \ Q x) \ (AE x in M. P x) \ (AE x in M. Q x)" by auto +lemma AE_symmetric: + assumes "AE x in M. P x = Q x" + shows "AE x in M. Q x = P x" + using assms by auto + lemma AE_impI: "(P \ AE x in M. Q x) \ AE x in M. P \ Q x" by (cases P) auto @@ -1166,6 +1180,10 @@ unfolding eventually_ae_filter by auto qed auto +lemma AE_ball_countable': + "(\N. N \ I \ AE x in M. P N x) \ countable I \ AE x in M. \N \ I. P N x" + unfolding AE_ball_countable by simp + lemma pairwise_alt: "pairwise R S \ (\x\S. \y\S-{x}. R x y)" by (auto simp add: pairwise_def) @@ -1225,6 +1243,11 @@ using AE_iff_measurable[OF _ refl, of M "\x. \ P x"] by (cases "{x\space M. P x} \ sets M") (simp_all add: emeasure_notin_sets) +lemma emeasure_0_AE: + assumes "emeasure M (space M) = 0" + shows "AE x in M. P x" +using eventually_ae_filter assms by blast + lemma emeasure_add_AE: assumes [measurable]: "A \ sets M" "B \ sets M" "C \ sets M" assumes 1: "AE x in M. x \ C \ x \ A \ x \ B" @@ -1328,6 +1351,40 @@ qed qed +lemma (in sigma_finite_measure) approx_PInf_emeasure_with_finite: + fixes C::real + assumes W_meas: "W \ sets M" + and W_inf: "emeasure M W = \" + obtains Z where "Z \ sets M" "Z \ W" "emeasure M Z < \" "emeasure M Z > C" +proof - + obtain A :: "nat \ 'a set" + where A: "range A \ sets M" "(\i. A i) = space M" "\i. emeasure M (A i) \ \" "incseq A" + using sigma_finite_incseq by blast + define B where "B = (\i. W \ A i)" + have B_meas: "\i. B i \ sets M" using W_meas `range A \ sets M` B_def by blast + have b: "\i. B i \ W" using B_def by blast + + { fix i + have "emeasure M (B i) \ emeasure M (A i)" + using A by (intro emeasure_mono) (auto simp: B_def) + also have "emeasure M (A i) < \" + using `\i. emeasure M (A i) \ \` by (simp add: less_top) + finally have "emeasure M (B i) < \" . } + note c = this + + have "W = (\i. B i)" using B_def `(\i. A i) = space M` W_meas by auto + moreover have "incseq B" using B_def `incseq A` by (simp add: incseq_def subset_eq) + ultimately have "(\i. emeasure M (B i)) \ emeasure M W" using W_meas B_meas + by (simp add: B_meas Lim_emeasure_incseq image_subset_iff) + then have "(\i. emeasure M (B i)) \ \" using W_inf by simp + from order_tendstoD(1)[OF this, of C] + obtain i where d: "emeasure M (B i) > C" + by (auto simp: eventually_sequentially) + have "B i \ sets M" "B i \ W" "emeasure M (B i) < \" "emeasure M (B i) > C" + using B_meas b c d by auto + then show ?thesis using that by blast +qed + subsection \Measure space induced by distribution of @{const measurable}-functions\ definition distr :: "'a measure \ 'b measure \ ('a \ 'b) \ 'b measure" where @@ -1824,6 +1881,88 @@ then show ?fm ?m by auto qed +lemma suminf_exist_split2: + fixes f :: "nat \ 'a::real_normed_vector" + assumes "summable f" + shows "(\n. (\k. f(k+n))) \ 0" +by (subst lim_sequentially, auto simp add: dist_norm suminf_exist_split[OF _ assms]) + +lemma emeasure_union_summable: + assumes [measurable]: "\n. A n \ sets M" + and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" + shows "emeasure M (\n. A n) < \" "emeasure M (\n. A n) \ (\n. measure M (A n))" +proof - + define B where "B = (\N. (\n\{.. sets M" for N unfolding B_def by auto + have "(\N. emeasure M (B N)) \ emeasure M (\N. B N)" + apply (rule Lim_emeasure_incseq) unfolding B_def by (auto simp add: SUP_subset_mono incseq_def) + moreover have "emeasure M (B N) \ ennreal (\n. measure M (A n))" for N + proof - + have *: "(\n\{.. (\n. measure M (A n))" + using assms(3) measure_nonneg sum_le_suminf by blast + + have "emeasure M (B N) \ (\n\{..n\{..n\{.. ennreal (\n. measure M (A n))" + using * by (auto simp: ennreal_leI) + finally show ?thesis by simp + qed + ultimately have "emeasure M (\N. B N) \ ennreal (\n. measure M (A n))" + by (simp add: Lim_bounded_ereal) + then show "emeasure M (\n. A n) \ (\n. measure M (A n))" + unfolding B_def by (metis UN_UN_flatten UN_lessThan_UNIV) + then show "emeasure M (\n. A n) < \" + by (auto simp: less_top[symmetric] top_unique) +qed + +lemma borel_cantelli_limsup1: + assumes [measurable]: "\n. A n \ sets M" + and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" + shows "limsup A \ null_sets M" +proof - + have "emeasure M (limsup A) \ 0" + proof (rule LIMSEQ_le_const) + have "(\n. (\k. measure M (A (k+n)))) \ 0" by (rule suminf_exist_split2[OF assms(3)]) + then show "(\n. ennreal (\k. measure M (A (k+n)))) \ 0" + unfolding ennreal_0[symmetric] by (intro tendsto_ennrealI) + have "emeasure M (limsup A) \ (\k. measure M (A (k+n)))" for n + proof - + have I: "(\k\{n..}. A k) = (\k. A (k+n))" by (auto, metis le_add_diff_inverse2, fastforce) + have "emeasure M (limsup A) \ emeasure M (\k\{n..}. A k)" + by (rule emeasure_mono, auto simp add: limsup_INF_SUP) + also have "... = emeasure M (\k. A (k+n))" + using I by auto + also have "... \ (\k. measure M (A (k+n)))" + apply (rule emeasure_union_summable) + using assms summable_ignore_initial_segment[OF assms(3), of n] by auto + finally show ?thesis by simp + qed + then show "\N. \n\N. emeasure M (limsup A) \ (\k. measure M (A (k+n)))" + by auto + qed + then show ?thesis using assms(1) measurable_limsup by auto +qed + +lemma borel_cantelli_AE1: + assumes [measurable]: "\n. A n \ sets M" + and "\n. emeasure M (A n) < \" "summable (\n. measure M (A n))" + shows "AE x in M. eventually (\n. x \ space M - A n) sequentially" +proof - + have "AE x in M. x \ limsup A" + using borel_cantelli_limsup1[OF assms] unfolding eventually_ae_filter by auto + moreover + { + fix x assume "x \ limsup A" + then obtain N where "x \ (\n\{N..}. A n)" unfolding limsup_INF_SUP by blast + then have "eventually (\n. x \ A n) sequentially" using eventually_sequentially by auto + } + ultimately show ?thesis by auto +qed + subsection \Measure spaces with @{term "emeasure M (space M) < \"}\ locale finite_measure = sigma_finite_measure M for M + diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Analysis/Nonnegative_Lebesgue_Integration.thy --- a/src/HOL/Analysis/Nonnegative_Lebesgue_Integration.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Analysis/Nonnegative_Lebesgue_Integration.thy Thu Oct 13 18:36:06 2016 +0200 @@ -9,6 +9,102 @@ imports Measure_Space Borel_Space begin +subsection \Approximating functions\ + +lemma AE_upper_bound_inf_ennreal: + fixes F G::"'a \ ennreal" + assumes "\e. (e::real) > 0 \ AE x in M. F x \ G x + e" + shows "AE x in M. F x \ G x" +proof - + have "AE x in M. \n::nat. F x \ G x + ennreal (1 / Suc n)" + using assms by (auto simp: AE_all_countable) + then show ?thesis + proof (eventually_elim) + fix x assume x: "\n::nat. F x \ G x + ennreal (1 / Suc n)" + show "F x \ G x" + proof (rule ennreal_le_epsilon) + fix e :: real assume "0 < e" + then obtain n where n: "1 / Suc n < e" + by (blast elim: nat_approx_posE) + have "F x \ G x + 1 / Suc n" + using x by simp + also have "\ \ G x + e" + using n by (intro add_mono ennreal_leI) auto + finally show "F x \ G x + ennreal e" . + qed + qed +qed + +lemma AE_upper_bound_inf: + fixes F G::"'a \ real" + assumes "\e. e > 0 \ AE x in M. F x \ G x + e" + shows "AE x in M. F x \ G x" +proof - + have "AE x in M. F x \ G x + 1/real (n+1)" for n::nat + by (rule assms, auto) + then have "AE x in M. \n::nat \ UNIV. F x \ G x + 1/real (n+1)" + by (rule AE_ball_countable', auto) + moreover + { + fix x assume i: "\n::nat \ UNIV. F x \ G x + 1/real (n+1)" + have "(\n. G x + 1/real (n+1)) \ G x + 0" + by (rule tendsto_add, simp, rule LIMSEQ_ignore_initial_segment[OF lim_1_over_n, of 1]) + then have "F x \ G x" using i LIMSEQ_le_const by fastforce + } + ultimately show ?thesis by auto +qed + +lemma not_AE_zero_ennreal_E: + fixes f::"'a \ ennreal" + assumes "\ (AE x in M. f x = 0)" and [measurable]: "f \ borel_measurable M" + shows "\A\sets M. \e::real>0. emeasure M A > 0 \ (\x \ A. f x \ e)" +proof - + { assume "\ (\e::real>0. {x \ space M. f x \ e} \ null_sets M)" + then have "0 < e \ AE x in M. f x \ e" for e :: real + by (auto simp: not_le less_imp_le dest!: AE_not_in) + then have "AE x in M. f x \ 0" + by (intro AE_upper_bound_inf_ennreal[where G="\_. 0"]) simp + then have False + using assms by auto } + then obtain e::real where e: "e > 0" "{x \ space M. f x \ e} \ null_sets M" by auto + define A where "A = {x \ space M. f x \ e}" + have 1 [measurable]: "A \ sets M" unfolding A_def by auto + have 2: "emeasure M A > 0" + using e(2) A_def \A \ sets M\ by auto + have 3: "\x. x \ A \ f x \ e" unfolding A_def by auto + show ?thesis using e(1) 1 2 3 by blast +qed + +lemma not_AE_zero_E: + fixes f::"'a \ real" + assumes "AE x in M. f x \ 0" + "\(AE x in M. f x = 0)" + and [measurable]: "f \ borel_measurable M" + shows "\A e. A \ sets M \ e>0 \ emeasure M A > 0 \ (\x \ A. f x \ e)" +proof - + have "\e. e > 0 \ {x \ space M. f x \ e} \ null_sets M" + proof (rule ccontr) + assume *: "\(\e. e > 0 \ {x \ space M. f x \ e} \ null_sets M)" + { + fix e::real assume "e > 0" + then have "{x \ space M. f x \ e} \ null_sets M" using * by blast + then have "AE x in M. x \ {x \ space M. f x \ e}" using AE_not_in by blast + then have "AE x in M. f x \ e" by auto + } + then have "AE x in M. f x \ 0" by (rule AE_upper_bound_inf, auto) + then have "AE x in M. f x = 0" using assms(1) by auto + then show False using assms(2) by auto + qed + then obtain e where e: "e>0" "{x \ space M. f x \ e} \ null_sets M" by auto + define A where "A = {x \ space M. f x \ e}" + have 1 [measurable]: "A \ sets M" unfolding A_def by auto + have 2: "emeasure M A > 0" + using e(2) A_def \A \ sets M\ by auto + have 3: "\x. x \ A \ f x \ e" unfolding A_def by auto + show ?thesis + using e(1) 1 2 3 by blast +qed + subsection "Simple function" text \ diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Analysis/Radon_Nikodym.thy --- a/src/HOL/Analysis/Radon_Nikodym.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Analysis/Radon_Nikodym.thy Thu Oct 13 18:36:06 2016 +0200 @@ -44,6 +44,64 @@ qed qed fact +text {*An equivalent characterization of sigma-finite spaces is the existence of integrable +positive functions (or, still equivalently, the existence of a probability measure which is in +the same measure class as the original measure).*} + +lemma (in sigma_finite_measure) obtain_positive_integrable_function: + obtains f::"'a \ real" where + "f \ borel_measurable M" + "\x. f x > 0" + "\x. f x \ 1" + "integrable M f" +proof - + obtain A :: "nat \ 'a set" where "range A \ sets M" "(\i. A i) = space M" "\i. emeasure M (A i) \ \" + using sigma_finite by auto + then have [measurable]:"A n \ sets M" for n by auto + define g where "g = (\x. (\n. (1/2)^(Suc n) * indicator (A n) x / (1+ measure M (A n))))" + have [measurable]: "g \ borel_measurable M" unfolding g_def by auto + have *: "summable (\n. (1/2)^(Suc n) * indicator (A n) x / (1+ measure M (A n)))" for x + apply (rule summable_comparison_test'[of "\n. (1/2)^(Suc n)" 0]) + using power_half_series summable_def by (auto simp add: indicator_def divide_simps) + have "g x \ (\n. (1/2)^(Suc n))" for x unfolding g_def + apply (rule suminf_le) using * power_half_series summable_def by (auto simp add: indicator_def divide_simps) + then have g_le_1: "g x \ 1" for x using power_half_series sums_unique by fastforce + + have g_pos: "g x > 0" if "x \ space M" for x + unfolding g_def proof (subst suminf_pos_iff[OF *[of x]], auto) + obtain i where "x \ A i" using `(\i. A i) = space M` `x \ space M` by auto + then have "0 < (1 / 2) ^ Suc i * indicator (A i) x / (1 + Sigma_Algebra.measure M (A i))" + unfolding indicator_def apply (auto simp add: divide_simps) using measure_nonneg[of M "A i"] + by (auto, meson add_nonneg_nonneg linorder_not_le mult_nonneg_nonneg zero_le_numeral zero_le_one zero_le_power) + then show "\i. 0 < (1 / 2) ^ i * indicator (A i) x / (2 + 2 * Sigma_Algebra.measure M (A i))" + by auto + qed + + have "integrable M g" + unfolding g_def proof (rule integrable_suminf) + fix n + show "integrable M (\x. (1 / 2) ^ Suc n * indicator (A n) x / (1 + Sigma_Algebra.measure M (A n)))" + using `emeasure M (A n) \ \` + by (auto intro!: integrable_mult_right integrable_divide_zero integrable_real_indicator simp add: top.not_eq_extremum) + next + show "AE x in M. summable (\n. norm ((1 / 2) ^ Suc n * indicator (A n) x / (1 + Sigma_Algebra.measure M (A n))))" + using * by auto + show "summable (\n. (\x. norm ((1 / 2) ^ Suc n * indicator (A n) x / (1 + Sigma_Algebra.measure M (A n))) \M))" + apply (rule summable_comparison_test'[of "\n. (1/2)^(Suc n)" 0], auto) + using power_half_series summable_def apply auto[1] + apply (auto simp add: divide_simps) using measure_nonneg[of M] not_less by fastforce + qed + + define f where "f = (\x. if x \ space M then g x else 1)" + have "f x > 0" for x unfolding f_def using g_pos by auto + moreover have "f x \ 1" for x unfolding f_def using g_le_1 by auto + moreover have [measurable]: "f \ borel_measurable M" unfolding f_def by auto + moreover have "integrable M f" + apply (subst integrable_cong[of _ _ _ g]) unfolding f_def using `integrable M g` by auto + ultimately show "(\f. f \ borel_measurable M \ (\x. 0 < f x) \ (\x. f x \ 1) \ integrable M f \ thesis) \ thesis" + by (meson that) +qed + lemma (in sigma_finite_measure) Ex_finite_integrable_function: "\h\borel_measurable M. integral\<^sup>N M h \ \ \ (\x\space M. 0 < h x \ h x < \)" proof - @@ -878,9 +936,6 @@ finally show ?thesis by simp qed -lemma null_setsD_AE: "N \ null_sets M \ AE x in M. x \ N" - using AE_iff_null_sets[of N M] by auto - lemma (in sigma_finite_measure) RN_deriv_unique: assumes f: "f \ borel_measurable M" and eq: "density M f = N" diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Analysis/Set_Integral.thy --- a/src/HOL/Analysis/Set_Integral.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Analysis/Set_Integral.thy Thu Oct 13 18:36:06 2016 +0200 @@ -1,5 +1,6 @@ (* Title: HOL/Analysis/Set_Integral.thy Author: Jeremy Avigad (CMU), Johannes Hölzl (TUM), Luke Serafin (CMU) + Author: Sébastien Gouëzel sebastien.gouezel@univ-rennes1.fr Notation and useful facts for working with integrals over a set. @@ -7,7 +8,7 @@ *) theory Set_Integral - imports Bochner_Integration + imports Radon_Nikodym begin (* @@ -523,5 +524,235 @@ shows "set_borel_measurable borel {a..b} f" by (rule set_borel_measurable_continuous[OF _ assms]) simp + +text{* This notation is from Sébastien Gouëzel: His use is not directly in line with the +notations in this file, they are more in line with sum, and more readable he thinks. *} + +abbreviation "set_nn_integral M A f \ nn_integral M (\x. f x * indicator A x)" + +syntax +"_set_nn_integral" :: "pttrn => 'a set => 'a measure => ereal => ereal" +("(\\<^sup>+((_)\(_)./ _)/\_)" [0,60,110,61] 60) + +"_set_lebesgue_integral" :: "pttrn => 'a set => 'a measure => ereal => ereal" +("(\((_)\(_)./ _)/\_)" [0,60,110,61] 60) + +translations +"\\<^sup>+x \ A. f \M" == "CONST set_nn_integral M A (\x. f)" +"\x \ A. f \M" == "CONST set_lebesgue_integral M A (\x. f)" + +lemma nn_integral_disjoint_pair: + assumes [measurable]: "f \ borel_measurable M" + "B \ sets M" "C \ sets M" + "B \ C = {}" + shows "(\\<^sup>+x \ B \ C. f x \M) = (\\<^sup>+x \ B. f x \M) + (\\<^sup>+x \ C. f x \M)" +proof - + have mes: "\D. D \ sets M \ (\x. f x * indicator D x) \ borel_measurable M" by simp + have pos: "\D. AE x in M. f x * indicator D x \ 0" using assms(2) by auto + have "\x. f x * indicator (B \ C) x = f x * indicator B x + f x * indicator C x" using assms(4) + by (auto split: split_indicator) + then have "(\\<^sup>+x. f x * indicator (B \ C) x \M) = (\\<^sup>+x. f x * indicator B x + f x * indicator C x \M)" + by simp + also have "... = (\\<^sup>+x. f x * indicator B x \M) + (\\<^sup>+x. f x * indicator C x \M)" + by (rule nn_integral_add) (auto simp add: assms mes pos) + finally show ?thesis by simp +qed + +lemma nn_integral_disjoint_pair_countspace: + assumes "B \ C = {}" + shows "(\\<^sup>+x \ B \ C. f x \count_space UNIV) = (\\<^sup>+x \ B. f x \count_space UNIV) + (\\<^sup>+x \ C. f x \count_space UNIV)" +by (rule nn_integral_disjoint_pair) (simp_all add: assms) + +lemma nn_integral_null_delta: + assumes "A \ sets M" "B \ sets M" + "(A - B) \ (B - A) \ null_sets M" + shows "(\\<^sup>+x \ A. f x \M) = (\\<^sup>+x \ B. f x \M)" +proof (rule nn_integral_cong_AE, auto simp add: indicator_def) + have *: "AE a in M. a \ (A - B) \ (B - A)" + using assms(3) AE_not_in by blast + then show "AE a in M. a \ A \ a \ B \ f a = 0" + by auto + show "AE x\A in M. x \ B \ f x = 0" + using * by auto +qed + +lemma nn_integral_disjoint_family: + assumes [measurable]: "f \ borel_measurable M" "\(n::nat). B n \ sets M" + and "disjoint_family B" + shows "(\\<^sup>+x \ (\n. B n). f x \M) = (\n. (\\<^sup>+x \ B n. f x \M))" +proof - + have "(\\<^sup>+ x. (\n. f x * indicator (B n) x) \M) = (\n. (\\<^sup>+ x. f x * indicator (B n) x \M))" + by (rule nn_integral_suminf) simp + moreover have "(\n. f x * indicator (B n) x) = f x * indicator (\n. B n) x" for x + proof (cases) + assume "x \ (\n. B n)" + then obtain n where "x \ B n" by blast + have a: "finite {n}" by simp + have "\i. i \ n \ x \ B i" using `x \ B n` assms(3) disjoint_family_on_def + by (metis IntI UNIV_I empty_iff) + then have "\i. i \ {n} \ indicator (B i) x = (0::ennreal)" using indicator_def by simp + then have b: "\i. i \ {n} \ f x * indicator (B i) x = (0::ennreal)" by simp + + define h where "h = (\i. f x * indicator (B i) x)" + then have "\i. i \ {n} \ h i = 0" using b by simp + then have "(\i. h i) = (\i\{n}. h i)" + by (metis sums_unique[OF sums_finite[OF a]]) + then have "(\i. h i) = h n" by simp + then have "(\n. f x * indicator (B n) x) = f x * indicator (B n) x" using h_def by simp + then have "(\n. f x * indicator (B n) x) = f x" using `x \ B n` indicator_def by simp + then show ?thesis using `x \ (\n. B n)` by auto + next + assume "x \ (\n. B n)" + then have "\n. f x * indicator (B n) x = 0" by simp + have "(\n. f x * indicator (B n) x) = 0" + by (simp add: `\n. f x * indicator (B n) x = 0`) + then show ?thesis using `x \ (\n. B n)` by auto + qed + ultimately show ?thesis by simp +qed + +lemma nn_set_integral_add: + assumes [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" + "A \ sets M" + shows "(\\<^sup>+x \ A. (f x + g x) \M) = (\\<^sup>+x \ A. f x \M) + (\\<^sup>+x \ A. g x \M)" +proof - + have "(\\<^sup>+x \ A. (f x + g x) \M) = (\\<^sup>+x. (f x * indicator A x + g x * indicator A x) \M)" + by (auto simp add: indicator_def intro!: nn_integral_cong) + also have "... = (\\<^sup>+x. f x * indicator A x \M) + (\\<^sup>+x. g x * indicator A x \M)" + apply (rule nn_integral_add) using assms(1) assms(2) by auto + finally show ?thesis by simp +qed + +lemma nn_set_integral_cong: + assumes "AE x in M. f x = g x" + shows "(\\<^sup>+x \ A. f x \M) = (\\<^sup>+x \ A. g x \M)" +apply (rule nn_integral_cong_AE) using assms(1) by auto + +lemma nn_set_integral_set_mono: + "A \ B \ (\\<^sup>+ x \ A. f x \M) \ (\\<^sup>+ x \ B. f x \M)" +by (auto intro!: nn_integral_mono split: split_indicator) + +lemma nn_set_integral_mono: + assumes [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" + "A \ sets M" + and "AE x\A in M. f x \ g x" + shows "(\\<^sup>+x \ A. f x \M) \ (\\<^sup>+x \ A. g x \M)" +by (auto intro!: nn_integral_mono_AE split: split_indicator simp: assms) + +lemma nn_set_integral_space [simp]: + shows "(\\<^sup>+ x \ space M. f x \M) = (\\<^sup>+x. f x \M)" +by (metis (mono_tags, lifting) indicator_simps(1) mult.right_neutral nn_integral_cong) + +lemma nn_integral_count_compose_inj: + assumes "inj_on g A" + shows "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+y \ g`A. f y \count_space UNIV)" +proof - + have "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+x. f (g x) \count_space A)" + by (auto simp add: nn_integral_count_space_indicator[symmetric]) + also have "... = (\\<^sup>+y. f y \count_space (g`A))" + by (simp add: assms nn_integral_bij_count_space inj_on_imp_bij_betw) + also have "... = (\\<^sup>+y \ g`A. f y \count_space UNIV)" + by (auto simp add: nn_integral_count_space_indicator[symmetric]) + finally show ?thesis by simp +qed + +lemma nn_integral_count_compose_bij: + assumes "bij_betw g A B" + shows "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+y \ B. f y \count_space UNIV)" +proof - + have "inj_on g A" using assms bij_betw_def by auto + then have "(\\<^sup>+x \ A. f (g x) \count_space UNIV) = (\\<^sup>+y \ g`A. f y \count_space UNIV)" + by (rule nn_integral_count_compose_inj) + then show ?thesis using assms by (simp add: bij_betw_def) +qed + +lemma set_integral_null_delta: + fixes f::"_ \ _ :: {banach, second_countable_topology}" + assumes [measurable]: "integrable M f" "A \ sets M" "B \ sets M" + and "(A - B) \ (B - A) \ null_sets M" + shows "(\x \ A. f x \M) = (\x \ B. f x \M)" +proof (rule set_integral_cong_set, auto) + have *: "AE a in M. a \ (A - B) \ (B - A)" + using assms(4) AE_not_in by blast + then show "AE x in M. (x \ B) = (x \ A)" + by auto +qed + +lemma set_integral_space: + assumes "integrable M f" + shows "(\x \ space M. f x \M) = (\x. f x \M)" +by (metis (mono_tags, lifting) indicator_simps(1) Bochner_Integration.integral_cong real_vector.scale_one) + +lemma null_if_pos_func_has_zero_nn_int: + fixes f::"'a \ ennreal" + assumes [measurable]: "f \ borel_measurable M" "A \ sets M" + and "AE x\A in M. f x > 0" "(\\<^sup>+x\A. f x \M) = 0" + shows "A \ null_sets M" +proof - + have "AE x in M. f x * indicator A x = 0" + by (subst nn_integral_0_iff_AE[symmetric], auto simp add: assms(4)) + then have "AE x\A in M. False" using assms(3) by auto + then show "A \ null_sets M" using assms(2) by (simp add: AE_iff_null_sets) +qed + +lemma null_if_pos_func_has_zero_int: + assumes [measurable]: "integrable M f" "A \ sets M" + and "AE x\A in M. f x > 0" "(\x\A. f x \M) = (0::real)" + shows "A \ null_sets M" +proof - + have "AE x in M. indicator A x * f x = 0" + apply (subst integral_nonneg_eq_0_iff_AE[symmetric]) + using assms integrable_mult_indicator[OF `A \ sets M` assms(1)] by auto + then have "AE x\A in M. f x = 0" by auto + then have "AE x\A in M. False" using assms(3) by auto + then show "A \ null_sets M" using assms(2) by (simp add: AE_iff_null_sets) +qed + +text{*The next lemma is a variant of \density_unique\. Note that it uses the notation +for nonnegative set integrals introduced earlier.*} + +lemma (in sigma_finite_measure) density_unique2: + assumes [measurable]: "f \ borel_measurable M" "f' \ borel_measurable M" + assumes density_eq: "\A. A \ sets M \ (\\<^sup>+ x \ A. f x \M) = (\\<^sup>+ x \ A. f' x \M)" + shows "AE x in M. f x = f' x" +proof (rule density_unique) + show "density M f = density M f'" + by (intro measure_eqI) (auto simp: emeasure_density intro!: density_eq) +qed (auto simp add: assms) + + +text {* The next lemma implies the same statement for Banach-space valued functions +using Hahn-Banach theorem and linear forms. Since they are not yet easily available, I +only formulate it for real-valued functions.*} + +lemma density_unique_real: + fixes f f'::"_ \ real" + assumes [measurable]: "integrable M f" "integrable M f'" + assumes density_eq: "\A. A \ sets M \ (\x \ A. f x \M) = (\x \ A. f' x \M)" + shows "AE x in M. f x = f' x" +proof - + define A where "A = {x \ space M. f x < f' x}" + then have [measurable]: "A \ sets M" by simp + have "(\x \ A. (f' x - f x) \M) = (\x \ A. f' x \M) - (\x \ A. f x \M)" + using `A \ sets M` assms(1) assms(2) integrable_mult_indicator by blast + then have "(\x \ A. (f' x - f x) \M) = 0" using assms(3) by simp + then have "A \ null_sets M" + using A_def null_if_pos_func_has_zero_int[where ?f = "\x. f' x - f x" and ?A = A] assms by auto + then have "AE x in M. x \ A" by (simp add: AE_not_in) + then have *: "AE x in M. f' x \ f x" unfolding A_def by auto + + + define B where "B = {x \ space M. f' x < f x}" + then have [measurable]: "B \ sets M" by simp + have "(\x \ B. (f x - f' x) \M) = (\x \ B. f x \M) - (\x \ B. f' x \M)" + using `B \ sets M` assms(1) assms(2) integrable_mult_indicator by blast + then have "(\x \ B. (f x - f' x) \M) = 0" using assms(3) by simp + then have "B \ null_sets M" + using B_def null_if_pos_func_has_zero_int[where ?f = "\x. f x - f' x" and ?A = B] assms by auto + then have "AE x in M. x \ B" by (simp add: AE_not_in) + then have "AE x in M. f' x \ f x" unfolding B_def by auto + + then show ?thesis using * by auto +qed + end - diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Probability/Characteristic_Functions.thy --- a/src/HOL/Probability/Characteristic_Functions.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Probability/Characteristic_Functions.thy Thu Oct 13 18:36:06 2016 +0200 @@ -75,7 +75,7 @@ lemma (in real_distribution) cmod_char_le_1: "norm (char M t) \ 1" proof - have "norm (char M t) \ (\x. norm (iexp (t * x)) \M)" - unfolding char_def by (intro integral_norm_bound integrable_iexp) auto + unfolding char_def by (intro integral_norm_bound) also have "\ \ 1" by (simp del: of_real_mult) finally show ?thesis . @@ -318,7 +318,7 @@ also have "\ = norm ((CLINT x | M. iexp (t * x) - (\k \ n. c k x)))" unfolding char_def by (subst Bochner_Integration.integral_diff[OF integ_iexp]) (auto intro!: integ_c) also have "\ \ expectation (\x. cmod (iexp (t * x) - (\k \ n. c k x)))" - by (intro integral_norm_bound Bochner_Integration.integrable_diff integ_iexp Bochner_Integration.integrable_sum integ_c) simp + by (intro integral_norm_bound) also have "\ \ expectation (\x. 2 * \t\ ^ n / fact n * \x\ ^ n)" proof (rule integral_mono) show "integrable M (\x. cmod (iexp (t * x) - (\k\n. c k x)))" @@ -362,7 +362,7 @@ also have "\ = norm ((CLINT x | M. iexp (t * x) - (\k \ n. c k x)))" unfolding char_def by (subst Bochner_Integration.integral_diff[OF integ_iexp]) (auto intro!: integ_c) also have "\ \ expectation (\x. cmod (iexp (t * x) - (\k \ n. c k x)))" - by (intro integral_norm_bound Bochner_Integration.integrable_diff integ_iexp Bochner_Integration.integrable_sum integ_c) simp + by (rule integral_norm_bound) also have "\ \ expectation (\x. min (2 * \t * x\^n / fact n) (\t * x\^(Suc n) / fact (Suc n)))" (is "_ \ expectation ?f") proof (rule integral_mono) diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Probability/Conditional_Expectation.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Conditional_Expectation.thy Thu Oct 13 18:36:06 2016 +0200 @@ -0,0 +1,1340 @@ +(* Author: Sébastien Gouëzel sebastien.gouezel@univ-rennes1.fr + License: BSD +*) + +section \Conditional Expectation\ + +theory Conditional_Expectation +imports Probability_Measure +begin + +subsection {*Restricting a measure to a sub-sigma-algebra*} + +definition subalgebra::"'a measure \ 'a measure \ bool" where + "subalgebra M F = ((space F = space M) \ (sets F \ sets M))" + +lemma sub_measure_space: + assumes i: "subalgebra M F" + shows "measure_space (space M) (sets F) (emeasure M)" +proof - + have "sigma_algebra (space M) (sets F)" + by (metis i measure_space measure_space_def subalgebra_def) + moreover have "positive (sets F) (emeasure M)" + using Sigma_Algebra.positive_def by auto + moreover have "countably_additive (sets F) (emeasure M)" + by (meson countably_additive_def emeasure_countably_additive i order_trans subalgebra_def subsetCE) + ultimately show ?thesis unfolding measure_space_def by simp +qed + +definition restr_to_subalg::"'a measure \ 'a measure \ 'a measure" where + "restr_to_subalg M F = measure_of (space M) (sets F) (emeasure M)" + +lemma space_restr_to_subalg: + "space (restr_to_subalg M F) = space M" +unfolding restr_to_subalg_def by (simp add: space_measure_of_conv) + +lemma sets_restr_to_subalg [measurable_cong]: + assumes "subalgebra M F" + shows "sets (restr_to_subalg M F) = sets F" +unfolding restr_to_subalg_def by (metis sets.sets_measure_of_eq assms subalgebra_def) + +lemma emeasure_restr_to_subalg: + assumes "subalgebra M F" + "A \ sets F" + shows "emeasure (restr_to_subalg M F) A = emeasure M A" +unfolding restr_to_subalg_def +by (metis assms subalgebra_def emeasure_measure_of_conv sub_measure_space sets.sigma_sets_eq) + +lemma null_sets_restr_to_subalg: + assumes "subalgebra M F" + shows "null_sets (restr_to_subalg M F) = null_sets M \ sets F" +proof + have "x \ null_sets M \ sets F" if "x \ null_sets (restr_to_subalg M F)" for x + by (metis that Int_iff assms emeasure_restr_to_subalg null_setsD1 null_setsD2 null_setsI + sets_restr_to_subalg subalgebra_def subsetD) + then show "null_sets (restr_to_subalg M F) \ null_sets M \ sets F" by auto +next + have "x \ null_sets (restr_to_subalg M F)" if "x \ null_sets M \ sets F" for x + by (metis that Int_iff assms null_setsD1 null_setsI sets_restr_to_subalg emeasure_restr_to_subalg[OF assms]) + then show "null_sets M \ sets F \ null_sets (restr_to_subalg M F)" by auto +qed + +lemma AE_restr_to_subalg: + assumes "subalgebra M F" + "AE x in (restr_to_subalg M F). P x" + shows "AE x in M. P x" +proof - + obtain A where A: "\x. x \ space (restr_to_subalg M F) - A \ P x" "A \ null_sets (restr_to_subalg M F)" + using AE_E3[OF assms(2)] by auto + then have "A \ null_sets M" using null_sets_restr_to_subalg[OF assms(1)] by auto + moreover have "\x. x \ space M - A \ P x" + using space_restr_to_subalg A(1) by fastforce + ultimately show ?thesis + unfolding eventually_ae_filter by auto +qed + +lemma AE_restr_to_subalg2: + assumes "subalgebra M F" + "AE x in M. P x" and [measurable]: "P \ measurable F (count_space UNIV)" + shows "AE x in (restr_to_subalg M F). P x" +proof - + define U where "U = {x \ space M. \(P x)}" + then have *: "U = {x \ space F. \(P x)}" using assms(1) by (simp add: subalgebra_def) + then have "U \ sets F" by simp + then have "U \ sets M" using assms(1) by (meson subalgebra_def subsetD) + then have "U \ null_sets M" unfolding U_def using assms(2) using AE_iff_measurable by blast + then have "U \ null_sets (restr_to_subalg M F)" using null_sets_restr_to_subalg[OF assms(1)] `U \ sets F` by auto + then show ?thesis using * by (metis (no_types, lifting) Collect_mono U_def eventually_ae_filter space_restr_to_subalg) +qed + +lemma prob_space_restr_to_subalg: + assumes "subalgebra M F" + "prob_space M" + shows "prob_space (restr_to_subalg M F)" +by (metis (no_types, lifting) assms(1) assms(2) emeasure_restr_to_subalg prob_space.emeasure_space_1 prob_spaceI + sets.top space_restr_to_subalg subalgebra_def) + +lemma finite_measure_restr_to_subalg: + assumes "subalgebra M F" + "finite_measure M" + shows "finite_measure (restr_to_subalg M F)" +by (metis (no_types, lifting) assms emeasure_restr_to_subalg finite_measure.finite_emeasure_space + finite_measureI sets.top space_restr_to_subalg subalgebra_def infinity_ennreal_def) + +lemma measurable_in_subalg: + assumes "subalgebra M F" + "f \ measurable F N" + shows "f \ measurable (restr_to_subalg M F) N" +by (metis measurable_cong_sets assms(2) sets_restr_to_subalg[OF assms(1)]) + +lemma measurable_in_subalg': + assumes "subalgebra M F" + "f \ measurable (restr_to_subalg M F) N" + shows "f \ measurable F N" +by (metis measurable_cong_sets assms(2) sets_restr_to_subalg[OF assms(1)]) + +lemma measurable_from_subalg: + assumes "subalgebra M F" + "f \ measurable F N" + shows "f \ measurable M N" +using assms unfolding measurable_def subalgebra_def by auto + +text{*The following is the direct transposition of \verb+nn_integral_subalgebra+ +(from \verb+Nonnegative_Lebesgue_Integration+) in the +current notations, with the removal of the useless assumption $f \geq 0$.*} + +lemma nn_integral_subalgebra2: + assumes "subalgebra M F" and [measurable]: "f \ borel_measurable F" + shows "(\\<^sup>+ x. f x \(restr_to_subalg M F)) = (\\<^sup>+ x. f x \M)" +proof (rule nn_integral_subalgebra) + show "f \ borel_measurable (restr_to_subalg M F)" + by (rule measurable_in_subalg[OF assms(1)]) simp + show "sets (restr_to_subalg M F) \ sets M" by (metis sets_restr_to_subalg[OF assms(1)] assms(1) subalgebra_def) + fix A assume "A \ sets (restr_to_subalg M F)" + then show "emeasure (restr_to_subalg M F) A = emeasure M A" + by (metis sets_restr_to_subalg[OF assms(1)] emeasure_restr_to_subalg[OF assms(1)]) +qed (auto simp add: assms space_restr_to_subalg sets_restr_to_subalg[OF assms(1)]) + +text{*The following is the direct transposition of \verb+integral_subalgebra+ +(from \verb+Bochner_Integration+) in the current notations.*} + +lemma integral_subalgebra2: + fixes f :: "'a \ 'b::{banach, second_countable_topology}" + assumes "subalgebra M F" and + [measurable]: "f \ borel_measurable F" + shows "(\x. f x \(restr_to_subalg M F)) = (\x. f x \M)" +by (rule integral_subalgebra, + metis measurable_in_subalg[OF assms(1)] assms(2), + auto simp add: assms space_restr_to_subalg sets_restr_to_subalg emeasure_restr_to_subalg, + meson assms(1) subalgebra_def subset_eq) + +lemma integrable_from_subalg: + fixes f :: "'a \ 'b::{banach, second_countable_topology}" + assumes "subalgebra M F" + "integrable (restr_to_subalg M F) f" + shows "integrable M f" +proof (rule integrableI_bounded) + have [measurable]: "f \ borel_measurable F" using assms by auto + then show "f \ borel_measurable M" using assms(1) measurable_from_subalg by blast + + have "(\\<^sup>+ x. ennreal (norm (f x)) \M) = (\\<^sup>+ x. ennreal (norm (f x)) \(restr_to_subalg M F))" + by (rule nn_integral_subalgebra2[symmetric], auto simp add: assms) + also have "... < \" using integrable_iff_bounded assms by auto + finally show "(\\<^sup>+ x. ennreal (norm (f x)) \M) < \" by simp +qed + +lemma integrable_in_subalg: + fixes f :: "'a \ 'b::{banach, second_countable_topology}" + assumes [measurable]: "subalgebra M F" + "f \ borel_measurable F" + "integrable M f" + shows "integrable (restr_to_subalg M F) f" +proof (rule integrableI_bounded) + show "f \ borel_measurable (restr_to_subalg M F)" using assms(2) assms(1) by auto + have "(\\<^sup>+ x. ennreal (norm (f x)) \(restr_to_subalg M F)) = (\\<^sup>+ x. ennreal (norm (f x)) \M)" + by (rule nn_integral_subalgebra2, auto simp add: assms) + also have "... < \" using integrable_iff_bounded assms by auto + finally show "(\\<^sup>+ x. ennreal (norm (f x)) \(restr_to_subalg M F)) < \" by simp +qed + +subsection {*Nonnegative conditional expectation*} + +text {* The conditional expectation of a function $f$, on a measure space $M$, with respect to a +sub sigma algebra $F$, should be a function $g$ which is $F$-measurable whose integral on any +$F$-set coincides with the integral of $f$. +Such a function is uniquely defined almost everywhere. +The most direct construction is to use the measure $f dM$, restrict it to the sigma-algebra $F$, +and apply the Radon-Nikodym theorem to write it as $g dM_{|F}$ for some $F$-measurable function $g$. +Another classical construction for $L^2$ functions is done by orthogonal projection on $F$-measurable +functions, and then extending by density to $L^1$. The Radon-Nikodym point of view avoids the $L^2$ +machinery, and works for all positive functions. + +In this paragraph, we develop the definition and basic properties for nonnegative functions, +as the basics of the general case. As in the definition of integrals, the nonnegative case is done +with ennreal-valued functions, without any integrability assumption. +*} + +definition nn_cond_exp :: "'a measure \ 'a measure \ ('a \ ennreal) \ ('a \ ennreal)" +where + "nn_cond_exp M F f = + (if f \ borel_measurable M \ subalgebra M F + then RN_deriv (restr_to_subalg M F) (restr_to_subalg (density M f) F) + else (\_. 0))" + +lemma + shows borel_measurable_nn_cond_exp [measurable]: "nn_cond_exp M F f \ borel_measurable F" + and borel_measurable_nn_cond_exp2 [measurable]: "nn_cond_exp M F f \ borel_measurable M" +by (simp_all add: nn_cond_exp_def) + (metis borel_measurable_RN_deriv borel_measurable_subalgebra sets_restr_to_subalg space_restr_to_subalg subalgebra_def) + +text {* The good setting for conditional expectations is the situation where the subalgebra $F$ +gives rise to a sigma-finite measure space. To see what goes wrong if it is not sigma-finite, +think of $\mathbb{R}$ with the trivial sigma-algebra $\{\emptyset, \mathbb{R}\}$. In this case, +conditional expectations have to be constant functions, so they have integral $0$ or $\infty$. +This means that a positive integrable function can have no meaningful conditional expectation.*} + +locale sigma_finite_subalgebra = + fixes M F::"'a measure" + assumes subalg: "subalgebra M F" + and sigma_fin_subalg: "sigma_finite_measure (restr_to_subalg M F)" + +lemma sigma_finite_subalgebra_is_sigma_finite: + assumes "sigma_finite_subalgebra M F" + shows "sigma_finite_measure M" +proof + have subalg: "subalgebra M F" + and sigma_fin_subalg: "sigma_finite_measure (restr_to_subalg M F)" + using assms unfolding sigma_finite_subalgebra_def by auto + obtain A where Ap: "countable A \ A \ sets (restr_to_subalg M F) \ \A = space (restr_to_subalg M F) \ (\a\A. emeasure (restr_to_subalg M F) a \ \)" + using sigma_finite_measure.sigma_finite_countable[OF sigma_fin_subalg] by fastforce + have "A \ sets F" using Ap sets_restr_to_subalg[OF subalg] by fastforce + then have "A \ sets M" using subalg subalgebra_def by force + moreover have "\A = space M" using Ap space_restr_to_subalg by simp + moreover have "\a\A. emeasure M a \ \" by (metis subsetD emeasure_restr_to_subalg[OF subalg] `A \ sets F` Ap) + ultimately show "\A. countable A \ A \ sets M \ \A = space M \ (\a\A. emeasure M a \ \)" using Ap by auto +qed + +sublocale sigma_finite_subalgebra \ sigma_finite_measure +using sigma_finite_subalgebra_is_sigma_finite sigma_finite_subalgebra_axioms by blast + +text {* Conditional expectations are very often used in probability spaces. This is a special case +of the previous one, as we prove now. *} + +locale finite_measure_subalgebra = finite_measure + + fixes F::"'a measure" + assumes subalg: "subalgebra M F" + +lemma finite_measure_subalgebra_is_sigma_finite: + assumes "finite_measure_subalgebra M F" + shows "sigma_finite_subalgebra M F" +proof - + interpret finite_measure_subalgebra M F using assms by simp + have "finite_measure (restr_to_subalg M F)" + using finite_measure_restr_to_subalg subalg finite_emeasure_space finite_measureI unfolding infinity_ennreal_def by blast + then have "sigma_finite_measure (restr_to_subalg M F)" + unfolding finite_measure_def by simp + then show "sigma_finite_subalgebra M F" unfolding sigma_finite_subalgebra_def using subalg by simp +qed + +sublocale finite_measure_subalgebra \ sigma_finite_subalgebra +proof - + have "finite_measure (restr_to_subalg M F)" + using finite_measure_restr_to_subalg subalg finite_emeasure_space finite_measureI unfolding infinity_ennreal_def by blast + then have "sigma_finite_measure (restr_to_subalg M F)" + unfolding finite_measure_def by simp + then show "sigma_finite_subalgebra M F" unfolding sigma_finite_subalgebra_def using subalg by simp +qed + +context sigma_finite_subalgebra +begin + +text{* The next lemma is arguably the most fundamental property of conditional expectation: +when computing an expectation against an $F$-measurable function, it is equivalent to work +with a function or with its $F$-conditional expectation. + +This property (even for bounded test functions) characterizes conditional expectations, as the second lemma below shows. +From this point on, we will only work with it, and forget completely about +the definition using Radon-Nikodym derivatives. +*} + +lemma nn_cond_exp_intg: + assumes [measurable]: "f \ borel_measurable F" "g \ borel_measurable M" + shows "(\\<^sup>+ x. f x * nn_cond_exp M F g x \M) = (\\<^sup>+ x. f x * g x \M)" +proof - + have [measurable]: "f \ borel_measurable M" + by (meson assms subalg borel_measurable_subalgebra subalgebra_def) + have ac: "absolutely_continuous (restr_to_subalg M F) (restr_to_subalg (density M g) F)" + unfolding absolutely_continuous_def + proof - + have "null_sets (restr_to_subalg M F) = null_sets M \ sets F" by (rule null_sets_restr_to_subalg[OF subalg]) + moreover have "null_sets M \ null_sets (density M g)" + by (rule absolutely_continuousI_density[unfolded absolutely_continuous_def]) auto + ultimately have "null_sets (restr_to_subalg M F) \ null_sets (density M g) \ sets F" by auto + moreover have "null_sets (density M g) \ sets F = null_sets (restr_to_subalg (density M g) F)" + by (rule null_sets_restr_to_subalg[symmetric]) (metis subalg sets_density space_density subalgebra_def) + ultimately show "null_sets (restr_to_subalg M F) \ null_sets (restr_to_subalg (density M g) F)" by auto + qed + + have "(\\<^sup>+ x. f x * nn_cond_exp M F g x \M) = (\\<^sup>+ x. f x * nn_cond_exp M F g x \(restr_to_subalg M F))" + by (rule nn_integral_subalgebra2[symmetric]) (simp_all add: assms subalg) + also have "... = (\\<^sup>+ x. f x * RN_deriv (restr_to_subalg M F) (restr_to_subalg (density M g) F) x \(restr_to_subalg M F))" + unfolding nn_cond_exp_def using assms subalg by simp + also have "... = (\\<^sup>+ x. RN_deriv (restr_to_subalg M F) (restr_to_subalg (density M g) F) x * f x \(restr_to_subalg M F))" + by (simp add: mult.commute) + also have "... = (\\<^sup>+ x. f x \(restr_to_subalg (density M g) F))" + proof (rule sigma_finite_measure.RN_deriv_nn_integral[symmetric]) + show "sets (restr_to_subalg (density M g) F) = sets (restr_to_subalg M F)" + by (metis subalg restr_to_subalg_def sets.sets_measure_of_eq space_density subalgebra_def) + qed (auto simp add: assms measurable_restrict ac measurable_in_subalg subalg sigma_fin_subalg) + also have "... = (\\<^sup>+ x. f x \(density M g))" + by (metis nn_integral_subalgebra2 subalg assms(1) sets_density space_density subalgebra_def) + also have "... = (\\<^sup>+ x. g x * f x \M)" + by (rule nn_integral_density) (simp_all add: assms) + also have "... = (\\<^sup>+ x. f x * g x \M)" + by (simp add: mult.commute) + finally show ?thesis by simp +qed + +lemma nn_cond_exp_charact: + assumes "\A. A \ sets F \ (\\<^sup>+ x \ A. f x \M) = (\\<^sup>+ x \ A. g x \M)" and + [measurable]: "f \ borel_measurable M" "g \ borel_measurable F" + shows "AE x in M. g x = nn_cond_exp M F f x" +proof - + let ?MF = "restr_to_subalg M F" + { + fix A assume "A \ sets ?MF" + then have [measurable]: "A \ sets F" using sets_restr_to_subalg[OF subalg] by simp + have "(\\<^sup>+ x \ A. g x \ ?MF) = (\\<^sup>+ x \ A. g x \M)" + by (simp add: nn_integral_subalgebra2 subalg) + also have "... = (\\<^sup>+ x \ A. f x \M)" using assms(1) by simp + also have "... = (\\<^sup>+ x. indicator A x * f x \M)" by (simp add: mult.commute) + also have "... = (\\<^sup>+ x. indicator A x * nn_cond_exp M F f x \M)" + by (rule nn_cond_exp_intg[symmetric]) (auto simp add: assms) + also have "... = (\\<^sup>+ x \ A. nn_cond_exp M F f x \M)" by (simp add: mult.commute) + also have "... = (\\<^sup>+ x \ A. nn_cond_exp M F f x \ ?MF)" + by (simp add: nn_integral_subalgebra2 subalg) + finally have "(\\<^sup>+ x \ A. g x \ ?MF) = (\\<^sup>+ x \ A. nn_cond_exp M F f x \ ?MF)" by simp + } note * = this + have "AE x in ?MF. g x = nn_cond_exp M F f x" + by (rule sigma_finite_measure.density_unique2) + (auto simp add: assms subalg sigma_fin_subalg AE_restr_to_subalg2 *) + then show ?thesis using AE_restr_to_subalg[OF subalg] by simp +qed + +lemma nn_cond_exp_F_meas: + assumes "f \ borel_measurable F" + shows "AE x in M. f x = nn_cond_exp M F f x" +by (rule nn_cond_exp_charact) (auto simp add: assms measurable_from_subalg[OF subalg]) + +lemma nn_cond_exp_prod: + assumes [measurable]: "f \ borel_measurable F" "g \ borel_measurable M" + shows "AE x in M. f x * nn_cond_exp M F g x = nn_cond_exp M F (\x. f x * g x) x" +proof (rule nn_cond_exp_charact) + have [measurable]: "f \ borel_measurable M" by (rule measurable_from_subalg[OF subalg assms(1)]) + show "(\x. f x * g x) \ borel_measurable M" by measurable + + fix A assume "A \ sets F" + then have [measurable]: "(\x. f x * indicator A x) \ borel_measurable F" by measurable + have "\\<^sup>+x\A. (f x * g x) \M = \\<^sup>+x. (f x * indicator A x) * g x \M" + by (simp add: mult.commute mult.left_commute) + also have "... = \\<^sup>+x. (f x * indicator A x) * nn_cond_exp M F g x \M" + by (rule nn_cond_exp_intg[symmetric]) (auto simp add: assms) + also have "... = \\<^sup>+x\A. (f x * nn_cond_exp M F g x)\M" + by (simp add: mult.commute mult.left_commute) + finally show "\\<^sup>+x\A. (f x * g x) \M = \\<^sup>+x\A. (f x * nn_cond_exp M F g x)\M" by simp +qed (auto simp add: assms) + +lemma nn_cond_exp_sum: + assumes [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" + shows "AE x in M. nn_cond_exp M F f x + nn_cond_exp M F g x = nn_cond_exp M F (\x. f x + g x) x" +proof (rule nn_cond_exp_charact) + fix A assume [measurable]: "A \ sets F" + then have "A \ sets M" by (meson subalg subalgebra_def subsetD) + have "\\<^sup>+x\A. (nn_cond_exp M F f x + nn_cond_exp M F g x)\M = (\\<^sup>+x\A. nn_cond_exp M F f x \M) + (\\<^sup>+x\A. nn_cond_exp M F g x \M)" + by (rule nn_set_integral_add) (auto simp add: assms `A \ sets M`) + also have "... = (\\<^sup>+x. indicator A x * nn_cond_exp M F f x \M) + (\\<^sup>+x. indicator A x * nn_cond_exp M F g x \M)" + by (metis (no_types, lifting) mult.commute nn_integral_cong) + also have "... = (\\<^sup>+x. indicator A x * f x \M) + (\\<^sup>+x. indicator A x * g x \M)" + by (simp add: nn_cond_exp_intg) + also have "... = (\\<^sup>+x\A. f x \M) + (\\<^sup>+x\A. g x \M)" + by (metis (no_types, lifting) mult.commute nn_integral_cong) + also have "... = \\<^sup>+x\A. (f x + g x)\M" + by (rule nn_set_integral_add[symmetric]) (auto simp add: assms `A \ sets M`) + finally show "\\<^sup>+x\A. (f x + g x)\M = \\<^sup>+x\A. (nn_cond_exp M F f x + nn_cond_exp M F g x)\M" + by simp +qed (auto simp add: assms) + +lemma nn_cond_exp_cong: + assumes "AE x in M. f x = g x" + and [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" + shows "AE x in M. nn_cond_exp M F f x = nn_cond_exp M F g x" +proof (rule nn_cond_exp_charact) + fix A assume [measurable]: "A \ sets F" + have "\\<^sup>+x\A. nn_cond_exp M F f x \M = \\<^sup>+x. indicator A x * nn_cond_exp M F f x \M" + by (simp add: mult.commute) + also have "... = \\<^sup>+x. indicator A x * f x \M" by (simp add: nn_cond_exp_intg assms) + also have "... = \\<^sup>+x\A. f x \M" by (simp add: mult.commute) + also have "... = \\<^sup>+x\A. g x \M" by (rule nn_set_integral_cong[OF assms(1)]) + finally show "\\<^sup>+x\A. g x \M = \\<^sup>+x\A. nn_cond_exp M F f x \M" by simp +qed (auto simp add: assms) + +lemma nn_cond_exp_mono: + assumes "AE x in M. f x \ g x" + and [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" + shows "AE x in M. nn_cond_exp M F f x \ nn_cond_exp M F g x" +proof - + define h where "h = (\x. g x - f x)" + have [measurable]: "h \ borel_measurable M" unfolding h_def by simp + have *: "AE x in M. g x = f x + h x" unfolding h_def using assms(1) by (auto simp: ennreal_ineq_diff_add) + have "AE x in M. nn_cond_exp M F g x = nn_cond_exp M F (\x. f x + h x) x" + by (rule nn_cond_exp_cong) (auto simp add: * assms) + moreover have "AE x in M. nn_cond_exp M F f x + nn_cond_exp M F h x = nn_cond_exp M F (\x. f x + h x) x" + by (rule nn_cond_exp_sum) (auto simp add: assms) + ultimately have "AE x in M. nn_cond_exp M F g x = nn_cond_exp M F f x + nn_cond_exp M F h x" by auto + then show ?thesis by force +qed + +lemma nested_subalg_is_sigma_finite: + assumes "subalgebra M G" "subalgebra G F" + shows "sigma_finite_subalgebra M G" +unfolding sigma_finite_subalgebra_def +proof (auto simp add: assms) + have "\A. countable A \ A \ sets (restr_to_subalg M F) \ \A = space (restr_to_subalg M F) \ (\a\A. emeasure (restr_to_subalg M F) a \ \)" + using sigma_fin_subalg sigma_finite_measure_def by auto + then obtain A where A:"countable A \ A \ sets (restr_to_subalg M F) \ \A = space (restr_to_subalg M F) \ (\a\A. emeasure (restr_to_subalg M F) a \ \)" + by auto + have "sets F \ sets M" + by (meson assms order_trans subalgebra_def) + then have "countable A \ A \ sets (restr_to_subalg M G) \ \A = space (restr_to_subalg M F) \ (\a\A. emeasure (restr_to_subalg M G) a \ \)" + by (metis (no_types) A assms basic_trans_rules(31) emeasure_restr_to_subalg order_trans sets_restr_to_subalg subalgebra_def) + then show "sigma_finite_measure (restr_to_subalg M G)" + by (metis sigma_finite_measure.intro space_restr_to_subalg) +qed + +lemma nn_cond_exp_nested_subalg: + assumes "subalgebra M G" "subalgebra G F" + and [measurable]: "f \ borel_measurable M" + shows "AE x in M. nn_cond_exp M F f x = nn_cond_exp M F (nn_cond_exp M G f) x" +proof (rule nn_cond_exp_charact, auto) + interpret G: sigma_finite_subalgebra M G by (rule nested_subalg_is_sigma_finite[OF assms(1) assms(2)]) + fix A assume [measurable]: "A \ sets F" + then have [measurable]: "A \ sets G" using assms(2) by (meson set_mp subalgebra_def) + + have "set_nn_integral M A (nn_cond_exp M G f) = (\\<^sup>+ x. indicator A x * nn_cond_exp M G f x\M)" + by (metis (no_types) mult.commute) + also have "... = (\\<^sup>+ x. indicator A x * f x \M)" by (rule G.nn_cond_exp_intg, auto simp add: assms) + also have "... = (\\<^sup>+ x. indicator A x * nn_cond_exp M F f x \M)" by (rule nn_cond_exp_intg[symmetric], auto simp add: assms) + also have "... = set_nn_integral M A (nn_cond_exp M F f)" by (metis (no_types) mult.commute) + finally show "set_nn_integral M A (nn_cond_exp M G f) = set_nn_integral M A (nn_cond_exp M F f)". +qed + +end + +subsection {*Real conditional expectation*} + +text {*Once conditional expectations of positive functions are defined, the definition for real-valued functions +follows readily, by taking the difference of positive and negative parts. +One could also define a conditional expectation of vector-space valued functions, as in +\verb+Bochner_Integral+, but since the real-valued case is the most important, and quicker to formalize, I +concentrate on it. (It is also essential for the case of the most general Pettis integral.) +*} + +definition real_cond_exp :: "'a measure \ 'a measure \ ('a \ real) \ ('a \ real)" where + "real_cond_exp M F f = + (\x. enn2real(nn_cond_exp M F (\x. ennreal (f x)) x) - enn2real(nn_cond_exp M F (\x. ennreal (-f x)) x))" + +lemma + shows borel_measurable_cond_exp [measurable]: "real_cond_exp M F f \ borel_measurable F" + and borel_measurable_cond_exp2 [measurable]: "real_cond_exp M F f \ borel_measurable M" +unfolding real_cond_exp_def by auto + +context sigma_finite_subalgebra +begin + +lemma real_cond_exp_abs: + assumes [measurable]: "f \ borel_measurable M" + shows "AE x in M. abs(real_cond_exp M F f x) \ nn_cond_exp M F (\x. ennreal (abs(f x))) x" +proof - + define fp where "fp = (\x. ennreal (f x))" + define fm where "fm = (\x. ennreal (- f x))" + have [measurable]: "fp \ borel_measurable M" "fm \ borel_measurable M" unfolding fp_def fm_def by auto + have eq: "\x. ennreal \f x\ = fp x + fm x" unfolding fp_def fm_def by (simp add: abs_real_def ennreal_neg) + + { + fix x assume H: "nn_cond_exp M F fp x + nn_cond_exp M F fm x = nn_cond_exp M F (\x. fp x + fm x) x" + have "\real_cond_exp M F f x\ \ \enn2real(nn_cond_exp M F fp x)\ + \enn2real(nn_cond_exp M F fm x)\" + unfolding real_cond_exp_def fp_def fm_def by (auto intro: abs_triangle_ineq4 simp del: enn2real_nonneg) + from ennreal_leI[OF this] + have "abs(real_cond_exp M F f x) \ nn_cond_exp M F fp x + nn_cond_exp M F fm x" + by simp (metis add.commute ennreal_enn2real le_iff_add not_le top_unique) + also have "... = nn_cond_exp M F (\x. fp x + fm x) x" using H by simp + finally have "abs(real_cond_exp M F f x) \ nn_cond_exp M F (\x. fp x + fm x) x" by simp + } + moreover have "AE x in M. nn_cond_exp M F fp x + nn_cond_exp M F fm x = nn_cond_exp M F (\x. fp x + fm x) x" + by (rule nn_cond_exp_sum) (auto simp add: fp_def fm_def) + ultimately have "AE x in M. abs(real_cond_exp M F f x) \ nn_cond_exp M F (\x. fp x + fm x) x" + by auto + then show ?thesis using eq by simp +qed + +text{* The next lemma shows that the conditional expectation +is an $F$-measurable function whose average against an $F$-measurable +function $f$ coincides with the average of the original function against $f$. +It is obtained as a consequence of the same property for the positive conditional +expectation, taking the difference of the positive and the negative part. The proof +is given first assuming $f \geq 0$ for simplicity, and then extended to the general case in +the subsequent lemma. The idea of the proof is essentially trivial, but the implementation +is slightly tedious as one should check all the integrability properties of the different parts, and go +back and forth between positive integral and signed integrals, and between real-valued +functions and ennreal-valued functions. + +Once this lemma is available, we will use it to characterize the conditional expectation, +and never come back to the original technical definition, as we did in the case of the +nonnegative conditional expectation. +*} + +lemma real_cond_exp_intg_fpos: + assumes "integrable M (\x. f x * g x)" and f_pos[simp]: "\x. f x \ 0" and + [measurable]: "f \ borel_measurable F" "g \ borel_measurable M" + shows "integrable M (\x. f x * real_cond_exp M F g x)" + "(\ x. f x * real_cond_exp M F g x \M) = (\ x. f x * g x \M)" +proof - + have [measurable]: "f \ borel_measurable M" by (rule measurable_from_subalg[OF subalg assms(3)]) + define gp where "gp = (\x. ennreal (g x))" + define gm where "gm = (\x. ennreal (- g x))" + have [measurable]: "gp \ borel_measurable M" "gm \ borel_measurable M" unfolding gp_def gm_def by auto + define h where "h = (\x. ennreal(abs(g x)))" + have hgpgm: "\x. h x = gp x + gm x" unfolding gp_def gm_def h_def by (simp add: abs_real_def ennreal_neg) + have [measurable]: "h \ borel_measurable M" unfolding h_def by simp + have pos[simp]: "\x. h x \ 0" "\x. gp x \ 0" "\x. gm x \ 0" unfolding h_def gp_def gm_def by simp_all + have gp_real: "\x. enn2real(gp x) = max (g x) 0" + unfolding gp_def by (simp add: max_def ennreal_neg) + have gm_real: "\x. enn2real(gm x) = max (-g x) 0" + unfolding gm_def by (simp add: max_def ennreal_neg) + + have "(\\<^sup>+ x. norm(f x * max (g x) 0) \M) \ (\\<^sup>+ x. norm(f x * g x) \M)" + by (simp add: nn_integral_mono) + also have "... < \" using assms(1) by (simp add: integrable_iff_bounded) + finally have "(\\<^sup>+ x. norm(f x * max (g x) 0) \M) < \" by simp + then have int1: "integrable M (\x. f x * max (g x) 0)" by (simp add: integrableI_bounded) + + have "(\\<^sup>+ x. norm(f x * max (-g x) 0) \M) \ (\\<^sup>+ x. norm(f x * g x) \M)" + by (simp add: nn_integral_mono) + also have "... < \" using assms(1) by (simp add: integrable_iff_bounded) + finally have "(\\<^sup>+ x. norm(f x * max (-g x) 0) \M) < \" by simp + then have int2: "integrable M (\x. f x * max (-g x) 0)" by (simp add: integrableI_bounded) + + have "(\\<^sup>+x. f x * nn_cond_exp M F h x \M) = (\\<^sup>+x. f x * h x \M)" + by (rule nn_cond_exp_intg) auto + also have "\ = \\<^sup>+ x. ennreal (f x * max (g x) 0 + f x * max (- g x) 0) \M" + unfolding h_def + by (intro nn_integral_cong)(auto simp: ennreal_mult[symmetric] abs_mult split: split_max) + also have "... < \" + using Bochner_Integration.integrable_add[OF int1 int2, THEN integrableD(2)] by (auto simp add: less_top) + finally have *: "(\\<^sup>+x. f x * nn_cond_exp M F h x \M) < \" by simp + + have "(\\<^sup>+x. norm(f x * real_cond_exp M F g x) \M) = (\\<^sup>+x. f x * abs(real_cond_exp M F g x) \M)" + by (simp add: abs_mult) + also have "... \ (\\<^sup>+x. f x * nn_cond_exp M F h x \M)" + proof (rule nn_integral_mono_AE) + { + fix x assume *: "abs(real_cond_exp M F g x) \ nn_cond_exp M F h x" + have "ennreal (f x * \real_cond_exp M F g x\) = f x * ennreal(\real_cond_exp M F g x\)" + by (simp add: ennreal_mult) + also have "... \ f x * nn_cond_exp M F h x" + using * by (auto intro!: mult_left_mono) + finally have "ennreal (f x * \real_cond_exp M F g x\) \ f x * nn_cond_exp M F h x" + by simp + } + then show "AE x in M. ennreal (f x * \real_cond_exp M F g x\) \ f x * nn_cond_exp M F h x" + using real_cond_exp_abs[OF assms(4)] h_def by auto + qed + finally have **: "(\\<^sup>+x. norm(f x * real_cond_exp M F g x) \M) < \" using * by auto + show "integrable M (\x. f x * real_cond_exp M F g x)" + using ** by (intro integrableI_bounded) auto + + + have "(\\<^sup>+x. f x * nn_cond_exp M F gp x \M) \ (\\<^sup>+x. f x * nn_cond_exp M F h x \M)" + proof (rule nn_integral_mono_AE) + have "AE x in M. nn_cond_exp M F gp x \ nn_cond_exp M F h x" + by (rule nn_cond_exp_mono) (auto simp add: hgpgm) + then show "AE x in M. f x * nn_cond_exp M F gp x \ f x * nn_cond_exp M F h x" + by (auto simp: mult_left_mono) + qed + then have a: "(\\<^sup>+x. f x * nn_cond_exp M F gp x \M) < \" + using * by auto + have "ennreal(norm(f x * enn2real(nn_cond_exp M F gp x))) \ f x * nn_cond_exp M F gp x" for x + by (auto simp add: ennreal_mult intro!: mult_left_mono) + (metis enn2real_ennreal enn2real_nonneg le_cases le_ennreal_iff) + then have "(\\<^sup>+x. norm(f x * enn2real(nn_cond_exp M F gp x)) \M) \ (\\<^sup>+x. f x * nn_cond_exp M F gp x \M)" + by (simp add: nn_integral_mono) + then have "(\\<^sup>+x. norm(f x * enn2real(nn_cond_exp M F gp x)) \M) < \" using a by auto + then have gp_int: "integrable M (\x. f x * enn2real(nn_cond_exp M F gp x))" by (simp add: integrableI_bounded) + have gp_fin: "AE x in M. f x * nn_cond_exp M F gp x \ \" + apply (rule nn_integral_PInf_AE) using a by auto + + have "(\ x. f x * enn2real(nn_cond_exp M F gp x) \M) = enn2real (\\<^sup>+ x. f x * enn2real(nn_cond_exp M F gp x) \M)" + by (rule integral_eq_nn_integral) auto + also have "... = enn2real(\\<^sup>+ x. ennreal(f x * enn2real(gp x)) \M)" + proof - + { + fix x assume "f x * nn_cond_exp M F gp x \ \" + then have "ennreal (f x * enn2real (nn_cond_exp M F gp x)) = ennreal (f x) * nn_cond_exp M F gp x" + by (auto simp add: ennreal_mult ennreal_mult_eq_top_iff less_top intro!: ennreal_mult_left_cong) + } + then have "AE x in M. ennreal (f x * enn2real (nn_cond_exp M F gp x)) = ennreal (f x) * nn_cond_exp M F gp x" + using gp_fin by auto + then have "(\\<^sup>+ x. f x * enn2real(nn_cond_exp M F gp x) \M) = (\\<^sup>+ x. f x * nn_cond_exp M F gp x \M)" + by (rule nn_integral_cong_AE) + also have "... = (\\<^sup>+ x. f x * gp x \M)" + by (rule nn_cond_exp_intg) (auto simp add: gp_def) + also have "... = (\\<^sup>+ x. ennreal(f x * enn2real(gp x)) \M)" + by (rule nn_integral_cong_AE) (auto simp: ennreal_mult gp_def) + finally have "(\\<^sup>+ x. f x * enn2real(nn_cond_exp M F gp x) \M) = (\\<^sup>+ x. ennreal(f x * enn2real(gp x)) \M)" by simp + then show ?thesis by simp + qed + also have "... = (\ x. f x * enn2real(gp x) \M)" + by (rule integral_eq_nn_integral[symmetric]) (auto simp add: gp_def) + finally have gp_expr: "(\ x. f x * enn2real(nn_cond_exp M F gp x) \M) = (\ x. f x * enn2real(gp x) \M)" by simp + + + have "(\\<^sup>+x. f x * nn_cond_exp M F gm x \M) \ (\\<^sup>+x. f x * nn_cond_exp M F h x \M)" + proof (rule nn_integral_mono_AE) + have "AE x in M. nn_cond_exp M F gm x \ nn_cond_exp M F h x" + by (rule nn_cond_exp_mono) (auto simp add: hgpgm) + then show "AE x in M. f x * nn_cond_exp M F gm x \ f x * nn_cond_exp M F h x" + by (auto simp: mult_left_mono) + qed + then have a: "(\\<^sup>+x. f x * nn_cond_exp M F gm x \M) < \" + using * by auto + have "\x. ennreal(norm(f x * enn2real(nn_cond_exp M F gm x))) \ f x * nn_cond_exp M F gm x" + by (auto simp add: ennreal_mult intro!: mult_left_mono) + (metis enn2real_ennreal enn2real_nonneg le_cases le_ennreal_iff) + then have "(\\<^sup>+x. norm(f x * enn2real(nn_cond_exp M F gm x)) \M) \ (\\<^sup>+x. f x * nn_cond_exp M F gm x \M)" + by (simp add: nn_integral_mono) + then have "(\\<^sup>+x. norm(f x * enn2real(nn_cond_exp M F gm x)) \M) < \" using a by auto + then have gm_int: "integrable M (\x. f x * enn2real(nn_cond_exp M F gm x))" by (simp add: integrableI_bounded) + have gm_fin: "AE x in M. f x * nn_cond_exp M F gm x \ \" + apply (rule nn_integral_PInf_AE) using a by auto + + have "(\ x. f x * enn2real(nn_cond_exp M F gm x) \M) = enn2real (\\<^sup>+ x. f x * enn2real(nn_cond_exp M F gm x) \M)" + by (rule integral_eq_nn_integral) auto + also have "... = enn2real(\\<^sup>+ x. ennreal(f x * enn2real(gm x)) \M)" + proof - + { + fix x assume "f x * nn_cond_exp M F gm x \ \" + then have "ennreal (f x * enn2real (nn_cond_exp M F gm x)) = ennreal (f x) * nn_cond_exp M F gm x" + by (auto simp add: ennreal_mult ennreal_mult_eq_top_iff less_top intro!: ennreal_mult_left_cong) + } + then have "AE x in M. ennreal (f x * enn2real (nn_cond_exp M F gm x)) = ennreal (f x) * nn_cond_exp M F gm x" + using gm_fin by auto + then have "(\\<^sup>+ x. f x * enn2real(nn_cond_exp M F gm x) \M) = (\\<^sup>+ x. f x * nn_cond_exp M F gm x \M)" + by (rule nn_integral_cong_AE) + also have "... = (\\<^sup>+ x. f x * gm x \M)" + by (rule nn_cond_exp_intg) (auto simp add: gm_def) + also have "... = (\\<^sup>+ x. ennreal(f x * enn2real(gm x)) \M)" + by (rule nn_integral_cong_AE) (auto simp: ennreal_mult gm_def) + finally have "(\\<^sup>+ x. f x * enn2real(nn_cond_exp M F gm x) \M) = (\\<^sup>+ x. ennreal(f x * enn2real(gm x)) \M)" by simp + then show ?thesis by simp + qed + also have "... = (\ x. f x * enn2real(gm x) \M)" + by (rule integral_eq_nn_integral[symmetric]) (auto simp add: gm_def) + finally have gm_expr: "(\ x. f x * enn2real(nn_cond_exp M F gm x) \M) = (\ x. f x * enn2real(gm x) \M)" by simp + + + have "(\ x. f x * real_cond_exp M F g x \M) = (\ x. f x * enn2real(nn_cond_exp M F gp x) - f x * enn2real(nn_cond_exp M F gm x) \M)" + unfolding real_cond_exp_def gp_def gm_def by (simp add: right_diff_distrib) + also have "... = (\ x. f x * enn2real(nn_cond_exp M F gp x) \M) - (\ x. f x * enn2real(nn_cond_exp M F gm x) \M)" + by (rule Bochner_Integration.integral_diff) (simp_all add: gp_int gm_int) + also have "... = (\ x. f x * enn2real(gp x) \M) - (\ x. f x * enn2real(gm x) \M)" + using gp_expr gm_expr by simp + also have "... = (\ x. f x * max (g x) 0 \M) - (\ x. f x * max (-g x) 0 \M)" + using gp_real gm_real by simp + also have "... = (\ x. f x * max (g x) 0 - f x * max (-g x) 0 \M)" + by (rule Bochner_Integration.integral_diff[symmetric]) (simp_all add: int1 int2) + also have "... = (\x. f x * g x \M)" + by (metis (mono_tags, hide_lams) diff_0 diff_zero eq_iff max.cobounded2 max_def minus_minus neg_le_0_iff_le right_diff_distrib) + finally show "(\ x. f x * real_cond_exp M F g x \M) = (\x. f x * g x \M)" + by simp +qed + +lemma real_cond_exp_intg: + assumes "integrable M (\x. f x * g x)" and + [measurable]: "f \ borel_measurable F" "g \ borel_measurable M" + shows "integrable M (\x. f x * real_cond_exp M F g x)" + "(\ x. f x * real_cond_exp M F g x \M) = (\ x. f x * g x \M)" +proof - + have [measurable]: "f \ borel_measurable M" by (rule measurable_from_subalg[OF subalg assms(2)]) + define fp where "fp = (\x. max (f x) 0)" + define fm where "fm = (\x. max (-f x) 0)" + have [measurable]: "fp \ borel_measurable M" "fm \ borel_measurable M" + unfolding fp_def fm_def by simp_all + have [measurable]: "fp \ borel_measurable F" "fm \ borel_measurable F" + unfolding fp_def fm_def by simp_all + + have "(\\<^sup>+ x. norm(fp x * g x) \M) \ (\\<^sup>+ x. norm(f x * g x) \M)" + by (simp add: fp_def nn_integral_mono) + also have "... < \" using assms(1) by (simp add: integrable_iff_bounded) + finally have "(\\<^sup>+ x. norm(fp x * g x) \M) < \" by simp + then have intp: "integrable M (\x. fp x * g x)" by (simp add: integrableI_bounded) + moreover have "\x. fp x \ 0" unfolding fp_def by simp + ultimately have Rp: "integrable M (\x. fp x * real_cond_exp M F g x)" + "(\ x. fp x * real_cond_exp M F g x \M) = (\ x. fp x * g x \M)" + using real_cond_exp_intg_fpos by auto + + have "(\\<^sup>+ x. norm(fm x * g x) \M) \ (\\<^sup>+ x. norm(f x * g x) \M)" + by (simp add: fm_def nn_integral_mono) + also have "... < \" using assms(1) by (simp add: integrable_iff_bounded) + finally have "(\\<^sup>+ x. norm(fm x * g x) \M) < \" by simp + then have intm: "integrable M (\x. fm x * g x)" by (simp add: integrableI_bounded) + moreover have "\x. fm x \ 0" unfolding fm_def by simp + ultimately have Rm: "integrable M (\x. fm x * real_cond_exp M F g x)" + "(\ x. fm x * real_cond_exp M F g x \M) = (\ x. fm x * g x \M)" + using real_cond_exp_intg_fpos by auto + + have "integrable M (\x. fp x * real_cond_exp M F g x - fm x * real_cond_exp M F g x)" + using Rp(1) Rm(1) integrable_diff by simp + moreover have *: "\x. f x * real_cond_exp M F g x = fp x * real_cond_exp M F g x - fm x * real_cond_exp M F g x" + unfolding fp_def fm_def by (simp add: max_def) + ultimately show "integrable M (\x. f x * real_cond_exp M F g x)" + by simp + + have "(\ x. f x * real_cond_exp M F g x \M) = (\ x. fp x * real_cond_exp M F g x - fm x * real_cond_exp M F g x \M)" + using * by simp + also have "... = (\ x. fp x * real_cond_exp M F g x \M) - (\ x. fm x * real_cond_exp M F g x \M)" + using Rp(1) Rm(1) by simp + also have "... = (\ x. fp x * g x \M) - (\ x. fm x * g x \M)" + using Rp(2) Rm(2) by simp + also have "... = (\ x. fp x * g x - fm x * g x \M)" + using intm intp by simp + also have "... = (\ x. f x * g x \M)" + unfolding fp_def fm_def by (metis (no_types, hide_lams) diff_0 diff_zero max.commute + max_def minus_minus mult.commute neg_le_iff_le right_diff_distrib) + finally show "(\ x. f x * real_cond_exp M F g x \M) = (\ x. f x * g x \M)" by simp +qed + +lemma real_cond_exp_intA: + assumes [measurable]: "integrable M f" "A \ sets F" + shows "(\ x \ A. f x \M) = (\x \ A. real_cond_exp M F f x \M)" +proof - + have "A \ sets M" by (meson assms(2) subalg subalgebra_def subsetD) + have "integrable M (\x. indicator A x * f x)" using integrable_mult_indicator[OF `A \ sets M` assms(1)] by auto + then show ?thesis using real_cond_exp_intg(2)[where ?f = "indicator A" and ?g = f, symmetric] by auto +qed + +lemma real_cond_exp_int [intro]: + assumes "integrable M f" + shows "integrable M (real_cond_exp M F f)" "(\x. real_cond_exp M F f x \M) = (\x. f x \M)" +using real_cond_exp_intg[where ?f = "\x. 1" and ?g = f] assms by auto + +lemma real_cond_exp_charact: + assumes "\A. A \ sets F \ (\ x \ A. f x \M) = (\ x \ A. g x \M)" + and [measurable]: "integrable M f" "integrable M g" + "g \ borel_measurable F" + shows "AE x in M. real_cond_exp M F f x = g x" +proof - + let ?MF = "restr_to_subalg M F" + have "AE x in ?MF. real_cond_exp M F f x = g x" + proof (rule AE_symmetric[OF density_unique_real]) + fix A assume "A \ sets ?MF" + then have [measurable]: "A \ sets F" using sets_restr_to_subalg[OF subalg] by simp + then have a [measurable]: "A \ sets M" by (meson subalg subalgebra_def subsetD) + have "(\x \ A. g x \ ?MF) = (\x \ A. g x \M)" + by (simp add: integral_subalgebra2 subalg) + also have "... = (\x \ A. f x \M)" using assms(1) by simp + also have "... = (\x. indicator A x * f x \M)" by (simp add: mult.commute) + also have "... = (\x. indicator A x * real_cond_exp M F f x \M)" + apply (rule real_cond_exp_intg(2)[symmetric]) using integrable_mult_indicator[OF a assms(2)] by (auto simp add: assms) + also have "... = (\x \ A. real_cond_exp M F f x \M)" by (simp add: mult.commute) + also have "... = (\x \ A. real_cond_exp M F f x \ ?MF)" + by (simp add: integral_subalgebra2 subalg) + finally show "(\x \ A. g x \ ?MF) = (\x \ A. real_cond_exp M F f x \ ?MF)" by simp + next + have "integrable M (real_cond_exp M F f)" by (rule real_cond_exp_int(1)[OF assms(2)]) + then show "integrable ?MF (real_cond_exp M F f)" by (metis borel_measurable_cond_exp integrable_in_subalg[OF subalg]) + show "integrable (restr_to_subalg M F) g" by (simp add: assms(3) integrable_in_subalg[OF subalg]) + qed + then show ?thesis using AE_restr_to_subalg[OF subalg] by auto +qed + +lemma real_cond_exp_F_meas [intro, simp]: + assumes "integrable M f" + "f \ borel_measurable F" + shows "AE x in M. real_cond_exp M F f x = f x" +by (rule real_cond_exp_charact, auto simp add: assms measurable_from_subalg[OF subalg]) + +lemma real_cond_exp_mult: + assumes [measurable]:"f \ borel_measurable F" "g \ borel_measurable M" "integrable M (\x. f x * g x)" + shows "AE x in M. real_cond_exp M F (\x. f x * g x) x = f x * real_cond_exp M F g x" +proof (rule real_cond_exp_charact) + fix A assume "A \ sets F" + then have [measurable]: "(\x. f x * indicator A x) \ borel_measurable F" by measurable + have [measurable]: "A \ sets M" using subalg by (meson `A \ sets F` subalgebra_def subsetD) + have "\x\A. (f x * g x) \M = \x. (f x * indicator A x) * g x \M" + by (simp add: mult.commute mult.left_commute) + also have "... = \x. (f x * indicator A x) * real_cond_exp M F g x \M" + apply (rule real_cond_exp_intg(2)[symmetric], auto simp add: assms) + using integrable_mult_indicator[OF `A \ sets M` assms(3)] by (simp add: mult.commute mult.left_commute) + also have "... = \x\A. (f x * real_cond_exp M F g x)\M" + by (simp add: mult.commute mult.left_commute) + finally show "\x\A. (f x * g x) \M = \x\A. (f x * real_cond_exp M F g x)\M" by simp +qed (auto simp add: real_cond_exp_intg(1) assms) + +lemma real_cond_exp_add [intro]: + assumes [measurable]: "integrable M f" "integrable M g" + shows "AE x in M. real_cond_exp M F (\x. f x + g x) x = real_cond_exp M F f x + real_cond_exp M F g x" +proof (rule real_cond_exp_charact) + have "integrable M (real_cond_exp M F f)" "integrable M (real_cond_exp M F g)" + using real_cond_exp_int(1) assms by auto + then show "integrable M (\x. real_cond_exp M F f x + real_cond_exp M F g x)" + by auto + + fix A assume [measurable]: "A \ sets F" + then have "A \ sets M" by (meson subalg subalgebra_def subsetD) + have intAf: "integrable M (\x. indicator A x * f x)" + using integrable_mult_indicator[OF `A \ sets M` assms(1)] by auto + have intAg: "integrable M (\x. indicator A x * g x)" + using integrable_mult_indicator[OF `A \ sets M` assms(2)] by auto + + have "\x\A. (real_cond_exp M F f x + real_cond_exp M F g x)\M = (\x\A. real_cond_exp M F f x \M) + (\x\A. real_cond_exp M F g x \M)" + apply (rule set_integral_add, auto simp add: assms) + using integrable_mult_indicator[OF `A \ sets M` real_cond_exp_int(1)[OF assms(1)]] + integrable_mult_indicator[OF `A \ sets M` real_cond_exp_int(1)[OF assms(2)]] by simp_all + also have "... = (\x. indicator A x * real_cond_exp M F f x \M) + (\x. indicator A x * real_cond_exp M F g x \M)" + by auto + also have "... = (\x. indicator A x * f x \M) + (\x. indicator A x * g x \M)" + using real_cond_exp_intg(2) assms `A \ sets F` intAf intAg by auto + also have "... = (\x\A. f x \M) + (\x\A. g x \M)" + by auto + also have "... = \x\A. (f x + g x)\M" + by (rule set_integral_add(2)[symmetric]) (auto simp add: assms `A \ sets M` intAf intAg) + finally show "\x\A. (f x + g x)\M = \x\A. (real_cond_exp M F f x + real_cond_exp M F g x)\M" + by simp +qed (auto simp add: assms) + +lemma real_cond_exp_cong: + assumes ae: "AE x in M. f x = g x" and [measurable]: "f \ borel_measurable M" "g \ borel_measurable M" + shows "AE x in M. real_cond_exp M F f x = real_cond_exp M F g x" +proof - + have "AE x in M. nn_cond_exp M F (\x. ennreal (f x)) x = nn_cond_exp M F (\x. ennreal (g x)) x" + apply (rule nn_cond_exp_cong) using assms by auto + moreover have "AE x in M. nn_cond_exp M F (\x. ennreal (-f x)) x = nn_cond_exp M F (\x. ennreal(-g x)) x" + apply (rule nn_cond_exp_cong) using assms by auto + ultimately show "AE x in M. real_cond_exp M F f x = real_cond_exp M F g x" + unfolding real_cond_exp_def by auto +qed + +lemma real_cond_exp_cmult [intro, simp]: + fixes c::real + assumes "integrable M f" + shows "AE x in M. real_cond_exp M F (\x. c * f x) x = c * real_cond_exp M F f x" +by (rule real_cond_exp_mult[where ?f = "\x. c" and ?g = f], auto simp add: assms borel_measurable_integrable) + +lemma real_cond_exp_cdiv [intro, simp]: + fixes c::real + assumes "integrable M f" + shows "AE x in M. real_cond_exp M F (\x. f x / c) x = real_cond_exp M F f x / c" +using real_cond_exp_cmult[of _ "1/c", OF assms] by (auto simp add: divide_simps) + +lemma real_cond_exp_diff [intro, simp]: + assumes [measurable]: "integrable M f" "integrable M g" + shows "AE x in M. real_cond_exp M F (\x. f x - g x) x = real_cond_exp M F f x - real_cond_exp M F g x" +proof - + have "AE x in M. real_cond_exp M F (\x. f x + (- g x)) x = real_cond_exp M F f x + real_cond_exp M F (\x. -g x) x" + using real_cond_exp_add[where ?f = f and ?g = "\x. - g x"] assms by auto + moreover have "AE x in M. real_cond_exp M F (\x. -g x) x = - real_cond_exp M F g x" + using real_cond_exp_cmult[where ?f = g and ?c = "-1"] assms(2) by auto + ultimately show ?thesis by auto +qed + +lemma real_cond_exp_pos [intro]: + assumes "AE x in M. f x \ 0" and [measurable]: "f \ borel_measurable M" + shows "AE x in M. real_cond_exp M F f x \ 0" +proof - + define g where "g = (\x. max (f x) 0)" + have "AE x in M. f x = g x" using assms g_def by auto + then have *: "AE x in M. real_cond_exp M F f x = real_cond_exp M F g x" using real_cond_exp_cong g_def by auto + + have "\x. g x \ 0" unfolding g_def by simp + then have "(\x. ennreal(-g x)) = (\x. 0)" + by (simp add: ennreal_neg) + moreover have "AE x in M. 0 = nn_cond_exp M F (\x. 0) x" + by (rule nn_cond_exp_F_meas, auto) + ultimately have "AE x in M. nn_cond_exp M F (\x. ennreal(-g x)) x = 0" + by simp + then have "AE x in M. real_cond_exp M F g x = enn2real(nn_cond_exp M F (\x. ennreal (g x)) x)" + unfolding real_cond_exp_def by auto + then have "AE x in M. real_cond_exp M F g x \ 0" by auto + then show ?thesis using * by auto +qed + +lemma real_cond_exp_mono: + assumes "AE x in M. f x \ g x" and [measurable]: "integrable M f" "integrable M g" + shows "AE x in M. real_cond_exp M F f x \ real_cond_exp M F g x" +proof - + have "AE x in M. real_cond_exp M F g x - real_cond_exp M F f x = real_cond_exp M F (\x. g x - f x) x" + by (rule AE_symmetric[OF real_cond_exp_diff], auto simp add: assms) + moreover have "AE x in M. real_cond_exp M F (\x. g x - f x) x \ 0" + by (rule real_cond_exp_pos, auto simp add: assms(1)) + ultimately have "AE x in M. real_cond_exp M F g x - real_cond_exp M F f x \ 0" by auto + then show ?thesis by auto +qed + +lemma (in -) measurable_P_restriction [measurable (raw)]: + assumes [measurable]: "Measurable.pred M P" "A \ sets M" + shows "{x \ A. P x} \ sets M" +proof - + have "A \ space M" using sets.sets_into_space[OF assms(2)]. + then have "{x \ A. P x} = A \ {x \ space M. P x}" by blast + then show ?thesis by auto +qed + +lemma real_cond_exp_gr_c: + assumes [measurable]: "integrable M f" + and "AE x in M. f x > c" + shows "AE x in M. real_cond_exp M F f x > c" +proof - + define X where "X = {x \ space M. real_cond_exp M F f x \ c}" + have [measurable]: "X \ sets F" + unfolding X_def apply measurable by (metis sets.top subalg subalgebra_def) + then have [measurable]: "X \ sets M" using sets_restr_to_subalg subalg subalgebra_def by blast + have "emeasure M X = 0" + proof (rule ccontr) + assume "\(emeasure M X) = 0" + have "emeasure (restr_to_subalg M F) X = emeasure M X" + by (simp add: emeasure_restr_to_subalg subalg) + then have "emeasure (restr_to_subalg M F) X > 0" + using `\(emeasure M X) = 0` gr_zeroI by auto + then obtain A where "A \ sets (restr_to_subalg M F)" "A \ X" "emeasure (restr_to_subalg M F) A > 0" "emeasure (restr_to_subalg M F) A < \" + using sigma_fin_subalg by (metis emeasure_notin_sets ennreal_0 infinity_ennreal_def le_less_linear neq_top_trans + not_gr_zero order_refl sigma_finite_measure.approx_PInf_emeasure_with_finite) + then have [measurable]: "A \ sets F" using subalg sets_restr_to_subalg by blast + then have [measurable]: "A \ sets M" using sets_restr_to_subalg subalg subalgebra_def by blast + have Ic: "set_integrable M A (\x. c)" + using \emeasure (restr_to_subalg M F) A < \\ emeasure_restr_to_subalg subalg by fastforce + have If: "set_integrable M A f" + by (rule integrable_mult_indicator, auto simp add: `integrable M f`) + have *: "(\x\A. c \M) = (\x\A. f x \M)" + proof (rule antisym) + show "(\x\A. c \M) \ (\x\A. f x \M)" + apply (rule set_integral_mono_AE) using Ic If assms(2) by auto + have "(\x\A. f x \M) = (\x\A. real_cond_exp M F f x \M)" + by (rule real_cond_exp_intA, auto simp add: `integrable M f`) + also have "... \ (\x\A. c \M)" + apply (rule set_integral_mono) + apply (rule integrable_mult_indicator, simp, simp add: real_cond_exp_int(1)[OF `integrable M f`]) + using Ic X_def \A \ X\ by auto + finally show "(\x\A. f x \M) \ (\x\A. c \M)" by simp + qed + have "AE x in M. indicator A x * c = indicator A x * f x" + apply (rule integral_ineq_eq_0_then_AE) using Ic If * apply auto + using assms(2) unfolding indicator_def by auto + then have "AE x\A in M. c = f x" by auto + then have "AE x\A in M. False" using assms(2) by auto + have "A \ null_sets M" unfolding ae_filter_def by (meson AE_iff_null_sets \A \ sets M\ \AE x\A in M. False\) + then show False using `emeasure (restr_to_subalg M F) A > 0` + by (simp add: emeasure_restr_to_subalg null_setsD1 subalg) + qed + then show ?thesis using AE_iff_null_sets[OF `X \ sets M`] unfolding X_def by auto +qed + +lemma real_cond_exp_less_c: + assumes [measurable]: "integrable M f" + and "AE x in M. f x < c" + shows "AE x in M. real_cond_exp M F f x < c" +proof - + have "AE x in M. real_cond_exp M F f x = -real_cond_exp M F (\x. -f x) x" + using real_cond_exp_cmult[OF `integrable M f`, of "-1"] by auto + moreover have "AE x in M. real_cond_exp M F (\x. -f x) x > -c" + apply (rule real_cond_exp_gr_c) using assms by auto + ultimately show ?thesis by auto +qed + +lemma real_cond_exp_ge_c: + assumes [measurable]: "integrable M f" + and "AE x in M. f x \ c" + shows "AE x in M. real_cond_exp M F f x \ c" +proof - + obtain u::"nat \ real" where u: "\n. u n < c" "u \ c" + using approx_from_below_dense_linorder[of "c-1" c] by auto + have *: "AE x in M. real_cond_exp M F f x > u n" for n::nat + apply (rule real_cond_exp_gr_c) using assms `u n < c` by auto + have "AE x in M. \n. real_cond_exp M F f x > u n" + by (subst AE_all_countable, auto simp add: *) + moreover have "real_cond_exp M F f x \ c" if "\n. real_cond_exp M F f x > u n" for x + proof - + have "real_cond_exp M F f x \ u n" for n using that less_imp_le by auto + then show ?thesis using u(2) LIMSEQ_le_const2 by blast + qed + ultimately show ?thesis by auto +qed + +lemma real_cond_exp_le_c: + assumes [measurable]: "integrable M f" + and "AE x in M. f x \ c" + shows "AE x in M. real_cond_exp M F f x \ c" +proof - + have "AE x in M. real_cond_exp M F f x = -real_cond_exp M F (\x. -f x) x" + using real_cond_exp_cmult[OF `integrable M f`, of "-1"] by auto + moreover have "AE x in M. real_cond_exp M F (\x. -f x) x \ -c" + apply (rule real_cond_exp_ge_c) using assms by auto + ultimately show ?thesis by auto +qed + +lemma real_cond_exp_mono_strict: + assumes "AE x in M. f x < g x" and [measurable]: "integrable M f" "integrable M g" + shows "AE x in M. real_cond_exp M F f x < real_cond_exp M F g x" +proof - + have "AE x in M. real_cond_exp M F g x - real_cond_exp M F f x = real_cond_exp M F (\x. g x - f x) x" + by (rule AE_symmetric[OF real_cond_exp_diff], auto simp add: assms) + moreover have "AE x in M. real_cond_exp M F (\x. g x - f x) x > 0" + by (rule real_cond_exp_gr_c, auto simp add: assms) + ultimately have "AE x in M. real_cond_exp M F g x - real_cond_exp M F f x > 0" by auto + then show ?thesis by auto +qed + +lemma real_cond_exp_nested_subalg [intro, simp]: + assumes "subalgebra M G" "subalgebra G F" + and [measurable]: "integrable M f" + shows "AE x in M. real_cond_exp M F (real_cond_exp M G f) x = real_cond_exp M F f x" +proof (rule real_cond_exp_charact) + interpret G: sigma_finite_subalgebra M G by (rule nested_subalg_is_sigma_finite[OF assms(1) assms(2)]) + show "integrable M (real_cond_exp M G f)" by (auto simp add: assms G.real_cond_exp_int(1)) + + fix A assume [measurable]: "A \ sets F" + then have [measurable]: "A \ sets G" using assms(2) by (meson set_mp subalgebra_def) + have "set_lebesgue_integral M A (real_cond_exp M G f) = set_lebesgue_integral M A f" + by (rule G.real_cond_exp_intA[symmetric], auto simp add: assms(3)) + also have "... = set_lebesgue_integral M A (real_cond_exp M F f)" + by (rule real_cond_exp_intA, auto simp add: assms(3)) + finally show "set_lebesgue_integral M A (real_cond_exp M G f) = set_lebesgue_integral M A (real_cond_exp M F f)" by auto +qed (auto simp add: assms real_cond_exp_int(1)) + +lemma real_cond_exp_sum [intro, simp]: + fixes f::"'b \ 'a \ real" + assumes [measurable]: "\i. integrable M (f i)" + shows "AE x in M. real_cond_exp M F (\x. \i\I. f i x) x = (\i\I. real_cond_exp M F (f i) x)" +proof (rule real_cond_exp_charact) + fix A assume [measurable]: "A \ sets F" + then have A_meas [measurable]: "A \ sets M" by (meson set_mp subalg subalgebra_def) + have *: "integrable M (\x. indicator A x * f i x)" for i + using integrable_mult_indicator[OF `A \ sets M` assms(1)] by auto + have **: "integrable M (\x. indicator A x * real_cond_exp M F (f i) x)" for i + using integrable_mult_indicator[OF `A \ sets M` real_cond_exp_int(1)[OF assms(1)]] by auto + have inti: "(\x. indicator A x * f i x \M) = (\x. indicator A x * real_cond_exp M F (f i) x \M)" for i + by (rule real_cond_exp_intg(2)[symmetric], auto simp add: *) + + have "(\x\A. (\i\I. f i x)\M) = (\x. (\i\I. indicator A x * f i x)\M)" + by (simp add: sum_distrib_left) + also have "... = (\i\I. (\x. indicator A x * f i x \M))" + by (rule Bochner_Integration.integral_sum, simp add: *) + also have "... = (\i\I. (\x. indicator A x * real_cond_exp M F (f i) x \M))" + using inti by auto + also have "... = (\x. (\i\I. indicator A x * real_cond_exp M F (f i) x)\M)" + by (rule Bochner_Integration.integral_sum[symmetric], simp add: **) + also have "... = (\x\A. (\i\I. real_cond_exp M F (f i) x)\M)" + by (simp add: sum_distrib_left) + finally show "(\x\A. (\i\I. f i x)\M) = (\x\A. (\i\I. real_cond_exp M F (f i) x)\M)" by auto +qed (auto simp add: assms real_cond_exp_int(1)[OF assms(1)]) + +text {*Jensen's inequality, describing the behavior of the integral under a convex function, admits +a version for the conditional expectation, as follows.*} + +theorem real_cond_exp_jensens_inequality: + fixes q :: "real \ real" + assumes X: "integrable M X" "AE x in M. X x \ I" + assumes I: "I = {a <..< b} \ I = {a <..} \ I = {..< b} \ I = UNIV" + assumes q: "integrable M (\x. q (X x))" "convex_on I q" "q \ borel_measurable borel" + shows "AE x in M. real_cond_exp M F X x \ I" + "AE x in M. q (real_cond_exp M F X x) \ real_cond_exp M F (\x. q (X x)) x" +proof - + have "open I" using I by auto + then have "interior I = I" by (simp add: interior_eq) + have [measurable]: "I \ sets borel" using I by auto + define phi where "phi = (\x. Inf ((\t. (q x - q t) / (x - t)) ` ({x<..} \ I)))" + have **: "q (X x) \ q (real_cond_exp M F X x) + phi (real_cond_exp M F X x) * (X x - real_cond_exp M F X x)" + if "X x \ I" "real_cond_exp M F X x \ I" for x + unfolding phi_def apply (rule convex_le_Inf_differential) + using `convex_on I q` that `interior I = I` by auto + text {*It is not clear that the function $\phi$ is measurable. We replace it by a version which + is better behaved.*} + define psi where "psi = (\x. phi x * indicator I x)" + have A: "psi y = phi y" if "y \ I" for y unfolding psi_def indicator_def using that by auto + have *: "q (X x) \ q (real_cond_exp M F X x) + psi (real_cond_exp M F X x) * (X x - real_cond_exp M F X x)" + if "X x \ I" "real_cond_exp M F X x \ I" for x + unfolding A[OF `real_cond_exp M F X x \ I`] using ** that by auto + + note I + moreover have "AE x in M. real_cond_exp M F X x > a" if "I \ {a <..}" for a + apply (rule real_cond_exp_gr_c) using X that by auto + moreover have "AE x in M. real_cond_exp M F X x < b" if "I \ {.. I" + by (elim disjE) (auto simp: subset_eq) + then have main_ineq: "AE x in M. q (X x) \ q (real_cond_exp M F X x) + psi (real_cond_exp M F X x) * (X x - real_cond_exp M F X x)" + using * X(2) by auto + + text {*Then, one wants to take the conditional expectation of this inequality. On the left, one gets + the conditional expectation of $q \circ X$. On the right, the last term vanishes, and one + is left with $q$ of the conditional expectation, as desired. Unfortunately, this argument only + works if $\psi \cdot X$ and $q(E(X | F))$ are integrable, and there is no reason why this should be true. The + trick is to multiply by a $F$-measurable function which is small enough to make + everything integrable.*} + + obtain f::"'a \ real" where [measurable]: "f \ borel_measurable (restr_to_subalg M F)" + "integrable (restr_to_subalg M F) f" + and f: "\x. f x > 0" "\x. f x \ 1" + using sigma_finite_measure.obtain_positive_integrable_function[OF sigma_fin_subalg] by metis + then have [measurable]: "f \ borel_measurable F" by (simp add: subalg) + then have [measurable]: "f \ borel_measurable M" using measurable_from_subalg[OF subalg] by blast + define g where "g = (\x. f x/(1+ \psi (real_cond_exp M F X x)\ + \q (real_cond_exp M F X x)\))" + define G where "G = (\x. g x * psi (real_cond_exp M F X x))" + have g: "g x > 0" "g x \ 1" for x unfolding G_def g_def using f[of x] by (auto simp add: abs_mult) + have G: "\G x\ \ 1" for x unfolding G_def g_def using f[of x] + proof (auto simp add: abs_mult) + have "f x * \psi (real_cond_exp M F X x)\ \ 1 * \psi (real_cond_exp M F X x)\" + apply (rule mult_mono) using f[of x] by auto + also have "... \ 1 + \psi (real_cond_exp M F X x)\ + \q (real_cond_exp M F X x)\" by auto + finally show "f x * \psi (real_cond_exp M F X x)\ \ 1 + \psi (real_cond_exp M F X x)\ + \q (real_cond_exp M F X x)\" + by simp + qed + have "AE x in M. g x * q (X x) \ g x * (q (real_cond_exp M F X x) + psi (real_cond_exp M F X x) * (X x - real_cond_exp M F X x))" + using main_ineq g by (auto simp add: divide_simps) + then have main_G: "AE x in M. g x * q (X x) \ g x * q (real_cond_exp M F X x) + G x * (X x - real_cond_exp M F X x)" + unfolding G_def by (auto simp add: algebra_simps) + + text {*To proceed, we need to know that $\psi$ is measurable.*} + have phi_mono: "phi x \ phi y" if "x \ y" "x \ I" "y \ I" for x y + proof (cases "x < y") + case True + have "q x + phi x * (y-x) \ q y" + unfolding phi_def apply (rule convex_le_Inf_differential) using `convex_on I q` that `interior I = I` by auto + then have "phi x \ (q x - q y) / (x - y)" + using that `x < y` by (auto simp add: divide_simps algebra_simps) + moreover have "(q x - q y)/(x - y) \ phi y" + unfolding phi_def proof (rule cInf_greatest, auto) + fix t assume "t \ I" "y < t" + have "(q x - q y) / (x - y) \ (q x - q t) / (x - t)" + apply (rule convex_on_diff[OF q(2)]) using `y < t` `x < y` `t \ I` `x \ I` by auto + also have "... \ (q y - q t) / (y - t)" + apply (rule convex_on_diff[OF q(2)]) using `y < t` `x < y` `t \ I` `x \ I` by auto + finally show "(q x - q y) / (x - y) \ (q y - q t) / (y - t)" by simp + next + obtain e where "0 < e" "ball y e \ I" using `open I` `y \ I` openE by blast + then have "y + e/2 \ {y<..} \ I" by (auto simp: dist_real_def) + then show "{y<..} \ I = {} \ False" by auto + qed + ultimately show "phi x \ phi y" by auto + next + case False + then have "x = y" using `x \ y` by auto + then show ?thesis by auto + qed + have [measurable]: "psi \ borel_measurable borel" + by (rule borel_measurable_piecewise_mono[of "{I, -I}"]) + (auto simp add: psi_def indicator_def phi_mono intro: mono_onI) + have [measurable]: "q \ borel_measurable borel" using q by simp + + have [measurable]: "X \ borel_measurable M" + "real_cond_exp M F X \ borel_measurable F" + "g \ borel_measurable F" "g \ borel_measurable M" + "G \ borel_measurable F" "G \ borel_measurable M" + using X measurable_from_subalg[OF subalg] unfolding G_def g_def by auto + have int1: "integrable (restr_to_subalg M F) (\x. g x * q (real_cond_exp M F X x))" + apply (rule Bochner_Integration.integrable_bound[of _ f], auto simp add: subalg `integrable (restr_to_subalg M F) f`) + unfolding g_def by (auto simp add: divide_simps abs_mult algebra_simps) + have int2: "integrable M (\x. G x * (X x - real_cond_exp M F X x))" + apply (rule Bochner_Integration.integrable_bound[of _ "\x. \X x\ + \real_cond_exp M F X x\"]) + apply (auto intro!: Bochner_Integration.integrable_add integrable_abs real_cond_exp_int `integrable M X` AE_I2) + using G unfolding abs_mult by (meson abs_ge_zero abs_triangle_ineq4 dual_order.trans mult_left_le_one_le) + have int3: "integrable M (\x. g x * q (X x))" + apply (rule Bochner_Integration.integrable_bound[of _ "\x. q(X x)"], auto simp add: q(1) abs_mult) + using g by (simp add: less_imp_le mult_left_le_one_le) + + text {*Taking the conditional expectation of the main convexity inequality \verb+main_G+, we get + the following.*} + have "AE x in M. real_cond_exp M F (\x. g x * q (X x)) x \ real_cond_exp M F (\x. g x * q (real_cond_exp M F X x) + G x * (X x - real_cond_exp M F X x)) x" + apply (rule real_cond_exp_mono[OF main_G]) + apply (rule Bochner_Integration.integrable_add[OF integrable_from_subalg[OF subalg int1]]) + using int2 int3 by auto + text {*This reduces to the desired inequality thanks to the properties of conditional expectation, + i.e., the conditional expectation of an $F$-measurable function is this function, and one can + multiply an $F$-measurable function outside of conditional expectations. + Since all these equalities only hold almost everywhere, we formulate them separately, + and then combine all of them to simplify the above equation, again almost everywhere.*} + moreover have "AE x in M. real_cond_exp M F (\x. g x * q (X x)) x = g x * real_cond_exp M F (\x. q (X x)) x" + by (rule real_cond_exp_mult, auto simp add: int3) + moreover have "AE x in M. real_cond_exp M F (\x. g x * q (real_cond_exp M F X x) + G x * (X x - real_cond_exp M F X x)) x + = real_cond_exp M F (\x. g x * q (real_cond_exp M F X x)) x + real_cond_exp M F (\x. G x * (X x - real_cond_exp M F X x)) x" + by (rule real_cond_exp_add, auto simp add: integrable_from_subalg[OF subalg int1] int2) + moreover have "AE x in M. real_cond_exp M F (\x. g x * q (real_cond_exp M F X x)) x = g x * q (real_cond_exp M F X x)" + by (rule real_cond_exp_F_meas, auto simp add: integrable_from_subalg[OF subalg int1]) + moreover have "AE x in M. real_cond_exp M F (\x. G x * (X x - real_cond_exp M F X x)) x = G x * real_cond_exp M F (\x. (X x - real_cond_exp M F X x)) x" + by (rule real_cond_exp_mult, auto simp add: int2) + moreover have "AE x in M. real_cond_exp M F (\x. (X x - real_cond_exp M F X x)) x = real_cond_exp M F X x - real_cond_exp M F (\x. real_cond_exp M F X x) x" + by (rule real_cond_exp_diff, auto intro!: real_cond_exp_int `integrable M X`) + moreover have "AE x in M. real_cond_exp M F (\x. real_cond_exp M F X x) x = real_cond_exp M F X x " + by (rule real_cond_exp_F_meas, auto intro!: real_cond_exp_int `integrable M X`) + ultimately have "AE x in M. g x * real_cond_exp M F (\x. q (X x)) x \ g x * q (real_cond_exp M F X x)" + by auto + then show "AE x in M. real_cond_exp M F (\x. q (X x)) x \ q (real_cond_exp M F X x)" + using g(1) by (auto simp add: divide_simps) +qed + +text {*Jensen's inequality does not imply that $q(E(X|F))$ is integrable, as it only proves an upper +bound for it. Indeed, this is not true in general, as the following counterexample shows: + +on $[1,\infty)$ with Lebesgue measure, let $F$ be the sigma-algebra generated by the intervals $[n, n+1)$ +for integer $n$. Let $q(x) = - \sqrt{x}$ for $x\geq 0$. Define $X$ which is equal to $1/n$ over +$[n, n+1/n)$ and $2^{-n}$ on $[n+1/n, n+1)$. Then $X$ is integrable as $\sum 1/n^2 < \infty$, and +$q(X)$ is integrable as $\sum 1/n^{3/2} < \infty$. On the other hand, $E(X|F)$ is essentially equal +to $1/n^2$ on $[n, n+1)$ (we neglect the term $2^{-n}$, we only put it there because $X$ should take +its values in $I=(0,\infty)$). Hence, $q(E(X|F))$ is equal to $-1/n$ on $[n, n+1)$, hence it is not +integrable. + +However, this counterexample is essentially the only situation where this function is not +integrable, as shown by the next lemma. +*} + +lemma integrable_convex_cond_exp: + fixes q :: "real \ real" + assumes X: "integrable M X" "AE x in M. X x \ I" + assumes I: "I = {a <..< b} \ I = {a <..} \ I = {..< b} \ I = UNIV" + assumes q: "integrable M (\x. q (X x))" "convex_on I q" "q \ borel_measurable borel" + assumes H: "emeasure M (space M) = \ \ 0 \ I" + shows "integrable M (\x. q (real_cond_exp M F X x))" +proof - + have [measurable]: "(\x. q (real_cond_exp M F X x)) \ borel_measurable M" + "q \ borel_measurable borel" + "X \ borel_measurable M" + using X(1) q(3) by auto + have "open I" using I by auto + then have "interior I = I" by (simp add: interior_eq) + + consider "emeasure M (space M) = 0" | "emeasure M (space M) > 0 \ emeasure M (space M) < \" | "emeasure M (space M) = \" + by (metis infinity_ennreal_def not_gr_zero top.not_eq_extremum) + then show ?thesis + proof (cases) + case 1 + show ?thesis by (subst integrable_cong_AE[of _ _ "\x. 0"], auto intro: emeasure_0_AE[OF 1]) + next + case 2 + interpret finite_measure M using 2 by (auto intro!: finite_measureI) + + have "I \ {}" + using `AE x in M. X x \ I` 2 eventually_mono integral_less_AE_space by fastforce + then obtain z where "z \ I" by auto + + define A where "A = Inf ((\t. (q z - q t) / (z - t)) ` ({z<..} \ I))" + have "q y \ q z + A * (y - z)" if "y \ I" for y unfolding A_def apply (rule convex_le_Inf_differential) + using `z \ I` `y \ I` `interior I = I` q(2) by auto + then have "AE x in M. q (real_cond_exp M F X x) \ q z + A * (real_cond_exp M F X x - z)" + using real_cond_exp_jensens_inequality(1)[OF X I q] by auto + moreover have "AE x in M. q (real_cond_exp M F X x) \ real_cond_exp M F (\x. q (X x)) x" + using real_cond_exp_jensens_inequality(2)[OF X I q] by auto + moreover have "\a\ \ \b\ + \c\" if "b \ a \ a \ c" for a b c::real + using that by auto + ultimately have *: "AE x in M. \q (real_cond_exp M F X x)\ + \ \real_cond_exp M F (\x. q (X x)) x\ + \q z + A * (real_cond_exp M F X x - z)\" + by auto + + show "integrable M (\x. q (real_cond_exp M F X x))" + apply (rule Bochner_Integration.integrable_bound[of _ "\x. \real_cond_exp M F (\x. q (X x)) x\ + \q z + A * (real_cond_exp M F X x - z)\"]) + apply (auto intro!: Bochner_Integration.integrable_add integrable_abs integrable_mult_right Bochner_Integration.integrable_diff real_cond_exp_int(1)) + using X(1) q(1) * by auto + next + case 3 + then have "0 \ I" using H finite_measure.finite_emeasure_space by auto + have "q(0) = 0" + proof (rule ccontr) + assume *: "\(q(0) = 0)" + define e where "e = \q(0)\ / 2" + then have "e > 0" using * by auto + have "continuous (at 0) q" + using q(2) `0 \ I` `open I` \interior I = I\ continuous_on_interior convex_on_continuous by blast + then obtain d where d: "d > 0" "\y. \y - 0\ < d \ \q y - q 0\ < e" using `e > 0` + by (metis continuous_at_real_range real_norm_def) + then have *: "\q(y)\ > e" if "\y\ < d" for y + proof - + have "\q 0\ \ \q 0 - q y\ + \q y\" by auto + also have "... < e + \q y\" using d(2) that by force + finally have "\q y\ > \q 0\ - e" by auto + then show ?thesis unfolding e_def by simp + qed + have "emeasure M {x \ space M. \X x\ < d} \ emeasure M ({x \ space M. 1 \ ennreal(1/e) * \q(X x)\} \ space M)" + by (rule emeasure_mono, auto simp add: * `e>0` less_imp_le ennreal_mult''[symmetric]) + also have "... \ (1/e) * (\\<^sup>+x. ennreal(\q(X x)\) * indicator (space M) x \M)" + by (rule nn_integral_Markov_inequality, auto) + also have "... = (1/e) * (\\<^sup>+x. ennreal(\q(X x)\) \M)" by auto + also have "... = (1/e) * ennreal(\x. \q(X x)\ \M)" + using nn_integral_eq_integral[OF integrable_abs[OF q(1)]] by auto + also have "... < \" + by (simp add: ennreal_mult_less_top) + finally have A: "emeasure M {x \ space M. \X x\ < d} < \" by simp + + have "{x \ space M. \X x\ \ d} = {x \ space M. 1 \ ennreal(1/d) * \X x\} \ space M" + by (auto simp add: `d>0` ennreal_mult''[symmetric]) + then have "emeasure M {x \ space M. \X x\ \ d} = emeasure M ({x \ space M. 1 \ ennreal(1/d) * \X x\} \ space M)" + by auto + also have "... \ (1/d) * (\\<^sup>+x. ennreal(\X x\) * indicator (space M) x \M)" + by (rule nn_integral_Markov_inequality, auto) + also have "... = (1/d) * (\\<^sup>+x. ennreal(\X x\) \M)" by auto + also have "... = (1/d) * ennreal(\x. \X x\ \M)" + using nn_integral_eq_integral[OF integrable_abs[OF X(1)]] by auto + also have "... < \" + by (simp add: ennreal_mult_less_top) + finally have B: "emeasure M {x \ space M. \X x\ \ d} < \" by simp + + have "space M = {x \ space M. \X x\ < d} \ {x \ space M. \X x\ \ d}" by auto + then have "emeasure M (space M) = emeasure M ({x \ space M. \X x\ < d} \ {x \ space M. \X x\ \ d})" + by simp + also have "... \ emeasure M {x \ space M. \X x\ < d} + emeasure M {x \ space M. \X x\ \ d}" + by (auto intro!: emeasure_subadditive) + also have "... < \" using A B by auto + finally show False using `emeasure M (space M) = \` by auto + qed + + define A where "A = Inf ((\t. (q 0 - q t) / (0 - t)) ` ({0<..} \ I))" + have "q y \ q 0 + A * (y - 0)" if "y \ I" for y unfolding A_def apply (rule convex_le_Inf_differential) + using `0 \ I` `y \ I` `interior I = I` q(2) by auto + then have "q y \ A * y" if "y \ I" for y using `q 0 = 0` that by auto + then have "AE x in M. q (real_cond_exp M F X x) \ A * real_cond_exp M F X x" + using real_cond_exp_jensens_inequality(1)[OF X I q] by auto + moreover have "AE x in M. q (real_cond_exp M F X x) \ real_cond_exp M F (\x. q (X x)) x" + using real_cond_exp_jensens_inequality(2)[OF X I q] by auto + moreover have "\a\ \ \b\ + \c\" if "b \ a \ a \ c" for a b c::real + using that by auto + ultimately have *: "AE x in M. \q (real_cond_exp M F X x)\ + \ \real_cond_exp M F (\x. q (X x)) x\ + \A * real_cond_exp M F X x\" + by auto + + show "integrable M (\x. q (real_cond_exp M F X x))" + apply (rule Bochner_Integration.integrable_bound[of _ "\x. \real_cond_exp M F (\x. q (X x)) x\ + \A * real_cond_exp M F X x \"]) + apply (auto intro!: Bochner_Integration.integrable_add integrable_abs integrable_mult_right Bochner_Integration.integrable_diff real_cond_exp_int(1)) + using X(1) q(1) * by auto + qed +qed + +end + +end diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Probability/Levy.thy --- a/src/HOL/Probability/Levy.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Probability/Levy.thy Thu Oct 13 18:36:06 2016 +0200 @@ -390,7 +390,7 @@ by (intro borel_integrable_compact[OF compact_Icc] continuous_at_imp_continuous_on continuous_intros ballI M'.isCont_char continuous_intros) have "cmod (CLBINT t:{-d/2..d/2}. 1 - char M' t) \ LBINT t:{-d/2..d/2}. cmod (1 - char M' t)" - using integral_norm_bound[OF 2] by simp + using integral_norm_bound[of _ "\x. indicator {u..v} x *\<^sub>R (1 - char M' x)" for u v] by simp also have 4: "\ \ LBINT t:{-d/2..d/2}. \ / 4" apply (rule integral_mono [OF 3]) apply (simp add: emeasure_lborel_Icc_eq) diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Probability/Probability.thy --- a/src/HOL/Probability/Probability.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Probability/Probability.thy Thu Oct 13 18:36:06 2016 +0200 @@ -11,6 +11,7 @@ Random_Permutations SPMF Stream_Space + Conditional_Expectation begin end diff -r 261d42f0bfac -r 979cdfdf7a79 src/HOL/Topological_Spaces.thy --- a/src/HOL/Topological_Spaces.thy Mon Oct 17 15:20:06 2016 +0200 +++ b/src/HOL/Topological_Spaces.thy Thu Oct 13 18:36:06 2016 +0200 @@ -1440,6 +1440,42 @@ at_within_def eventually_nhds_within_iff_sequentially comp_def by metis +lemma approx_from_above_dense_linorder: + fixes x::"'a::{dense_linorder, linorder_topology, first_countable_topology}" + assumes "x < y" + shows "\u. (\n. u n > x) \ (u \ x)" +proof - + obtain A :: "nat \ 'a set" where A: "\i. open (A i)" "\i. x \ A i" + "\F. (\n. F n \ A n) \ F \ x" + by (metis first_countable_topology_class.countable_basis) + define u where "u = (\n. SOME z. z \ A n \ z > x)" + have "\z. z \ U \ x < z" if "x \ U" "open U" for U + using open_right[OF `open U` `x \ U` `x < y`] + by (meson atLeastLessThan_iff dense less_imp_le subset_eq) + then have *: "u n \ A n \ x < u n" for n + using `x \ A n` `open (A n)` unfolding u_def by (metis (no_types, lifting) someI_ex) + then have "u \ x" using A(3) by simp + then show ?thesis using * by auto +qed + +lemma approx_from_below_dense_linorder: + fixes x::"'a::{dense_linorder, linorder_topology, first_countable_topology}" + assumes "x > y" + shows "\u. (\n. u n < x) \ (u \ x)" +proof - + obtain A :: "nat \ 'a set" where A: "\i. open (A i)" "\i. x \ A i" + "\F. (\n. F n \ A n) \ F \ x" + by (metis first_countable_topology_class.countable_basis) + define u where "u = (\n. SOME z. z \ A n \ z < x)" + have "\z. z \ U \ z < x" if "x \ U" "open U" for U + using open_left[OF `open U` `x \ U` `x > y`] + by (meson dense greaterThanAtMost_iff less_imp_le subset_eq) + then have *: "u n \ A n \ u n < x" for n + using `x \ A n` `open (A n)` unfolding u_def by (metis (no_types, lifting) someI_ex) + then have "u \ x" using A(3) by simp + then show ?thesis using * by auto +qed + subsection \Function limit at a point\