# HG changeset patch # User hoelzl # Date 1475244518 -7200 # Node ID 17a20ca86d62037d2b31bd8f49d1673ba07a1680 # Parent 041cda506fb22860dd10263f930e204ea0188509 HOL-Probability: more about probability, prepare for Markov processes in the AFP diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Binary_Product_Measure.thy --- a/src/HOL/Analysis/Binary_Product_Measure.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Binary_Product_Measure.thy Fri Sep 30 16:08:38 2016 +0200 @@ -686,6 +686,53 @@ show "a \ A" and "b \ B" by auto qed +lemma sets_pair_eq: + assumes Ea: "Ea \ Pow (space A)" "sets A = sigma_sets (space A) Ea" + and Ca: "countable Ca" "Ca \ Ea" "\Ca = space A" + and Eb: "Eb \ Pow (space B)" "sets B = sigma_sets (space B) Eb" + and Cb: "countable Cb" "Cb \ Eb" "\Cb = space B" + shows "sets (A \\<^sub>M B) = sets (sigma (space A \ space B) { a \ b | a b. a \ Ea \ b \ Eb })" + (is "_ = sets (sigma ?\ ?E)") +proof + show "sets (sigma ?\ ?E) \ sets (A \\<^sub>M B)" + using Ea(1) Eb(1) by (subst sigma_le_sets) (auto simp: Ea(2) Eb(2)) + have "?E \ Pow ?\" + using Ea(1) Eb(1) by auto + then have E: "a \ Ea \ b \ Eb \ a \ b \ sets (sigma ?\ ?E)" for a b + by auto + have "sets (A \\<^sub>M B) \ sets (Sup {vimage_algebra ?\ fst A, vimage_algebra ?\ snd B})" + unfolding sets_pair_eq_sets_fst_snd .. + also have "vimage_algebra ?\ fst A = vimage_algebra ?\ fst (sigma (space A) Ea)" + by (intro vimage_algebra_cong[OF refl refl]) (simp add: Ea) + also have "\ = sigma ?\ {fst -` A \ ?\ |A. A \ Ea}" + by (intro Ea vimage_algebra_sigma) auto + also have "vimage_algebra ?\ snd B = vimage_algebra ?\ snd (sigma (space B) Eb)" + by (intro vimage_algebra_cong[OF refl refl]) (simp add: Eb) + also have "\ = sigma ?\ {snd -` A \ ?\ |A. A \ Eb}" + by (intro Eb vimage_algebra_sigma) auto + also have "{sigma ?\ {fst -` Aa \ ?\ |Aa. Aa \ Ea}, sigma ?\ {snd -` Aa \ ?\ |Aa. Aa \ Eb}} = + sigma ?\ ` {{fst -` Aa \ ?\ |Aa. Aa \ Ea}, {snd -` Aa \ ?\ |Aa. Aa \ Eb}}" + by auto + also have "sets (SUP S:{{fst -` Aa \ ?\ |Aa. Aa \ Ea}, {snd -` Aa \ ?\ |Aa. Aa \ Eb}}. sigma ?\ S) = + sets (sigma ?\ (\{{fst -` Aa \ ?\ |Aa. Aa \ Ea}, {snd -` Aa \ ?\ |Aa. Aa \ Eb}}))" + using Ea(1) Eb(1) by (intro sets_Sup_sigma) auto + also have "\ \ sets (sigma ?\ ?E)" + proof (subst sigma_le_sets, safe intro!: space_in_measure_of) + fix a assume "a \ Ea" + then have "fst -` a \ ?\ = (\b\Cb. a \ b)" + using Cb(3)[symmetric] Ea(1) by auto + then show "fst -` a \ ?\ \ sets (sigma ?\ ?E)" + using Cb \a \ Ea\ by (auto intro!: sets.countable_UN' E) + next + fix b assume "b \ Eb" + then have "snd -` b \ ?\ = (\a\Ca. a \ b)" + using Ca(3)[symmetric] Eb(1) by auto + then show "snd -` b \ ?\ \ sets (sigma ?\ ?E)" + using Ca \b \ Eb\ by (auto intro!: sets.countable_UN' E) + qed + finally show "sets (A \\<^sub>M B) \ sets (sigma ?\ ?E)" . +qed + lemma borel_prod: "(borel \\<^sub>M borel) = (borel :: ('a::second_countable_topology \ 'b::second_countable_topology) measure)" (is "?P = ?B") diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Bochner_Integration.thy --- a/src/HOL/Analysis/Bochner_Integration.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Bochner_Integration.thy Fri Sep 30 16:08:38 2016 +0200 @@ -951,6 +951,10 @@ unfolding integrable.simps by (intro has_bochner_integral_cong_AE arg_cong[where f=Ex] ext) +lemma integrable_cong_AE_imp: + "integrable M g \ f \ borel_measurable M \ (AE x in M. g x = f x) \ integrable M f" + using integrable_cong_AE[of f M g] by (auto simp: eq_commute) + lemma integral_cong: "M = N \ (\x. x \ space N \ f x = g x) \ integral\<^sup>L M f = integral\<^sup>L N g" by (simp cong: has_bochner_integral_cong cong del: if_weak_cong add: lebesgue_integral_def) @@ -1682,6 +1686,16 @@ finally show ?thesis . qed +lemma nn_integral_eq_integrable: + assumes f: "f \ M \\<^sub>M borel" "AE x in M. 0 \ f x" and "0 \ x" + shows "(\\<^sup>+x. f x \M) = ennreal x \ (integrable M f \ integral\<^sup>L M f = x)" +proof (safe intro!: nn_integral_eq_integral assms) + assume *: "(\\<^sup>+x. f x \M) = ennreal x" + with integrableI_nn_integral_finite[OF f this] nn_integral_eq_integral[of M f, OF _ f(2)] + show "integrable M f" "integral\<^sup>L M f = x" + by (simp_all add: * assms integral_nonneg_AE) +qed + lemma fixes f :: "_ \ _ \ 'a :: {banach, second_countable_topology}" assumes integrable[measurable]: "\i. integrable M (f i)" @@ -2227,6 +2241,27 @@ shows "integrable (count_space UNIV) f \ integral\<^sup>L (count_space UNIV) f = (\x. f x)" using sums_integral_count_space_nat by (rule sums_unique) +lemma integrable_bij_count_space: + fixes f :: "'a \ 'b::{banach, second_countable_topology}" + assumes g: "bij_betw g A B" + shows "integrable (count_space A) (\x. f (g x)) \ integrable (count_space B) f" + unfolding integrable_iff_bounded by (subst nn_integral_bij_count_space[OF g]) auto + +lemma integral_bij_count_space: + fixes f :: "'a \ 'b::{banach, second_countable_topology}" + assumes g: "bij_betw g A B" + shows "integral\<^sup>L (count_space A) (\x. f (g x)) = integral\<^sup>L (count_space B) f" + using g[THEN bij_betw_imp_funcset] + apply (subst distr_bij_count_space[OF g, symmetric]) + apply (intro integral_distr[symmetric]) + apply auto + done + +lemma has_bochner_integral_count_space_nat: + fixes f :: "nat \ _::{banach,second_countable_topology}" + shows "has_bochner_integral (count_space UNIV) f x \ f sums x" + unfolding has_bochner_integral_iff by (auto intro!: sums_integral_count_space_nat) + subsection \Point measure\ lemma lebesgue_integral_point_measure_finite: diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Borel_Space.thy --- a/src/HOL/Analysis/Borel_Space.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Borel_Space.thy Fri Sep 30 16:08:38 2016 +0200 @@ -1500,6 +1500,9 @@ apply auto done +lemma measurable_of_bool[measurable]: "of_bool \ count_space UNIV \\<^sub>M borel" + by simp + subsection "Borel space on the extended reals" lemma borel_measurable_ereal[measurable (raw)]: @@ -1909,6 +1912,56 @@ shows "mono f \ f \ borel_measurable borel" using borel_measurable_mono_on_fnc[of f UNIV] by (simp add: mono_def mono_on_def) +lemma measurable_bdd_below_real[measurable (raw)]: + fixes F :: "'a \ 'i \ real" + assumes [simp]: "countable I" and [measurable]: "\i. i \ I \ F i \ M \\<^sub>M borel" + shows "Measurable.pred M (\x. bdd_below ((\i. F i x)`I))" +proof (subst measurable_cong) + show "bdd_below ((\i. F i x)`I) \ (\q\\. \i\I. q \ F i x)" for x + by (auto simp: bdd_below_def intro!: bexI[of _ "of_int (floor _)"] intro: order_trans of_int_floor_le) + show "Measurable.pred M (\w. \q\\. \i\I. q \ F i w)" + using countable_int by measurable +qed + +lemma borel_measurable_cINF_real[measurable (raw)]: + fixes F :: "_ \ _ \ real" + assumes [simp]: "countable I" + assumes F[measurable]: "\i. i \ I \ F i \ borel_measurable M" + shows "(\x. INF i:I. F i x) \ borel_measurable M" +proof (rule measurable_piecewise_restrict) + let ?\ = "{x\space M. bdd_below ((\i. F i x)`I)}" + show "countable {?\, - ?\}" "space M \ \{?\, - ?\}" "\X. X \ {?\, - ?\} \ X \ space M \ sets M" + by auto + fix X assume "X \ {?\, - ?\}" then show "(\x. INF i:I. F i x) \ borel_measurable (restrict_space M X)" + proof safe + show "(\x. INF i:I. F i x) \ borel_measurable (restrict_space M ?\)" + by (intro borel_measurable_cINF measurable_restrict_space1 F) + (auto simp: space_restrict_space) + show "(\x. INF i:I. F i x) \ borel_measurable (restrict_space M (-?\))" + proof (subst measurable_cong) + fix x assume "x \ space (restrict_space M (-?\))" + then have "\ (\i\I. - F i x \ y)" for y + by (auto simp: space_restrict_space bdd_above_def bdd_above_uminus[symmetric]) + then show "(INF i:I. F i x) = - (THE x. False)" + by (auto simp: space_restrict_space Inf_real_def Sup_real_def Least_def simp del: Set.ball_simps(10)) + qed simp + qed +qed + +lemma borel_Ici: "borel = sigma UNIV (range (\x::real. {x ..}))" +proof (safe intro!: borel_eq_sigmaI1[OF borel_Iio]) + fix x :: real + have eq: "{.. sets (sigma UNIV (range atLeast))" + unfolding eq by (intro sets.compl_sets) auto +qed auto + +lemma borel_measurable_pred_less[measurable (raw)]: + fixes f :: "'a \ 'b::{second_countable_topology, linorder_topology}" + shows "f \ borel_measurable M \ g \ borel_measurable M \ Measurable.pred M (\w. f w < g w)" + unfolding Measurable.pred_def by (rule borel_measurable_less) + no_notation eucl_less (infix "c. (f has_real_derivative c) F) = (\D. (f has_derivative D) F)" by (metis has_field_derivative_def has_real_derivative) +lemma has_vector_derivative_cong_ev: + assumes *: "eventually (\x. x \ s \ f x = g x) (nhds x)" "f x = g x" + shows "(f has_vector_derivative f') (at x within s) = (g has_vector_derivative f') (at x within s)" + unfolding has_vector_derivative_def has_derivative_def + using * + apply (cases "at x within s \ bot") + apply (intro refl conj_cong filterlim_cong) + apply (auto simp: netlimit_within eventually_at_filter elim: eventually_mono) + done + definition deriv :: "('a \ 'a::real_normed_field) \ 'a \ 'a" where "deriv f x \ SOME D. DERIV f x :> D" diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Finite_Product_Measure.thy --- a/src/HOL/Analysis/Finite_Product_Measure.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Finite_Product_Measure.thy Fri Sep 30 16:08:38 2016 +0200 @@ -1196,4 +1196,14 @@ by (subst emeasure_distr) (auto simp: measurable_pair_iff) qed simp +lemma infprod_in_sets[intro]: + fixes E :: "nat \ 'a set" assumes E: "\i. E i \ sets (M i)" + shows "Pi UNIV E \ sets (\\<^sub>M i\UNIV::nat set. M i)" +proof - + have "Pi UNIV E = (\i. prod_emb UNIV M {..i} (\\<^sub>E j\{..i}. E j))" + using E E[THEN sets.sets_into_space] + by (auto simp: prod_emb_def Pi_iff extensional_def) + with E show ?thesis by auto +qed + end diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Lebesgue_Measure.thy --- a/src/HOL/Analysis/Lebesgue_Measure.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Lebesgue_Measure.thy Fri Sep 30 16:08:38 2016 +0200 @@ -11,6 +11,24 @@ imports Finite_Product_Measure Bochner_Integration Caratheodory Complete_Measure Summation_Tests Regularity begin +lemma measure_eqI_lessThan: + fixes M N :: "real measure" + assumes sets: "sets M = sets borel" "sets N = sets borel" + assumes fin: "\x. emeasure M {x <..} < \" + assumes "\x. emeasure M {x <..} = emeasure N {x <..}" + shows "M = N" +proof (rule measure_eqI_generator_eq_countable) + let ?LT = "\a::real. {a <..}" let ?E = "range ?LT" + show "Int_stable ?E" + by (auto simp: Int_stable_def lessThan_Int_lessThan) + + show "?E \ Pow UNIV" "sets M = sigma_sets UNIV ?E" "sets N = sigma_sets UNIV ?E" + unfolding sets borel_Ioi by auto + + show "?LT`Rats \ ?E" "(\i\Rats. ?LT i) = UNIV" "\a. a \ ?LT`Rats \ emeasure M a \ \" + using fin by (auto intro: Rats_no_bot_less simp: less_top) +qed (auto intro: assms countable_rat) + subsection \Every right continuous and nondecreasing function gives rise to a measure\ definition interval_measure :: "(real \ real) \ real measure" where diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Measurable.thy --- a/src/HOL/Analysis/Measurable.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Measurable.thy Fri Sep 30 16:08:38 2016 +0200 @@ -618,6 +618,24 @@ shows "Measurable.pred M ((R ^^ n) T)" by (induct n) (auto intro: assms) +lemma measurable_compose_countable_restrict: + assumes P: "countable {i. P i}" + and f: "f \ M \\<^sub>M count_space UNIV" + and Q: "\i. P i \ pred M (Q i)" + shows "pred M (\x. P (f x) \ Q (f x) x)" +proof - + have P_f: "{x \ space M. P (f x)} \ sets M" + unfolding pred_def[symmetric] by (rule measurable_compose[OF f]) simp + have "pred (restrict_space M {x\space M. P (f x)}) (\x. Q (f x) x)" + proof (rule measurable_compose_countable'[where g=f, OF _ _ P]) + show "f \ restrict_space M {x\space M. P (f x)} \\<^sub>M count_space {i. P i}" + by (rule measurable_count_space_extend[OF subset_UNIV]) + (auto simp: space_restrict_space intro!: measurable_restrict_space1 f) + qed (auto intro!: measurable_restrict_space1 Q) + then show ?thesis + unfolding pred_restrict_space[OF P_f] by (simp cong: measurable_cong) +qed + hide_const (open) pred end diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Measure_Space.thy --- a/src/HOL/Analysis/Measure_Space.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Measure_Space.thy Fri Sep 30 16:08:38 2016 +0200 @@ -838,6 +838,38 @@ qed qed +lemma space_empty: "space M = {} \ M = count_space {}" + by (rule measure_eqI) (simp_all add: space_empty_iff) + +lemma measure_eqI_generator_eq_countable: + fixes M N :: "'a measure" and E :: "'a set set" and A :: "'a set set" + assumes E: "Int_stable E" "E \ Pow \" "\X. X \ E \ emeasure M X = emeasure N X" + and sets: "sets M = sigma_sets \ E" "sets N = sigma_sets \ E" + and A: "A \ E" "(\A) = \" "countable A" "\a. a \ A \ emeasure M a \ \" + shows "M = N" +proof cases + assume "\ = {}" + have *: "sigma_sets \ E = sets (sigma \ E)" + using E(2) by simp + have "space M = \" "space N = \" + using sets E(2) unfolding * by (auto dest: sets_eq_imp_space_eq simp del: sets_measure_of) + then show "M = N" + unfolding \\ = {}\ by (auto dest: space_empty) +next + assume "\ \ {}" with \\A = \\ have "A \ {}" by auto + from this \countable A\ have rng: "range (from_nat_into A) = A" + by (rule range_from_nat_into) + show "M = N" + proof (rule measure_eqI_generator_eq[OF E sets]) + show "range (from_nat_into A) \ E" + unfolding rng using \A \ E\ . + show "(\i. from_nat_into A i) = \" + unfolding rng using \\A = \\ . + show "emeasure M (from_nat_into A i) \ \" for i + using rng by (intro A) auto + qed +qed + lemma measure_of_of_measure: "measure_of (space M) (sets M) (emeasure M) = M" proof (intro measure_eqI emeasure_measure_of_sigma) show "sigma_algebra (space M) (sets M)" .. @@ -1097,6 +1129,9 @@ "(\x. x \ space M \ P x \ Q x) \ (AE x in M. P x) \ (AE x in M. Q x)" by auto +lemma AE_cong_strong: "M = N \ (\x. x \ space N =simp=> P x = Q x) \ (AE x in M. P x) \ (AE x in N. Q x)" + by (auto simp: simp_implies_def) + lemma AE_all_countable: "(AE x in M. \i. P i x) \ (\i::'i::countable. AE x in M. P i x)" proof @@ -2135,9 +2170,6 @@ qed simp qed (simp add: emeasure_notin_sets) -lemma space_empty: "space M = {} \ M = count_space {}" - by (rule measure_eqI) (simp_all add: space_empty_iff) - lemma null_sets_count_space: "null_sets (count_space A) = { {} }" unfolding null_sets_def by (auto simp add: emeasure_count_space_eq_0) diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Nonnegative_Lebesgue_Integration.thy --- a/src/HOL/Analysis/Nonnegative_Lebesgue_Integration.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Nonnegative_Lebesgue_Integration.thy Fri Sep 30 16:08:38 2016 +0200 @@ -1692,6 +1692,16 @@ by (simp add: ** nn_integral_suminf from_nat_into) qed +lemma of_bool_Bex_eq_nn_integral: + assumes unique: "\x y. x \ X \ y \ X \ P x \ P y \ x = y" + shows "of_bool (\y\X. P y) = (\\<^sup>+y. of_bool (P y) \count_space X)" +proof cases + assume "\y\X. P y" + then obtain y where "P y" "y \ X" by auto + then show ?thesis + by (subst nn_integral_count_space'[where A="{y}"]) (auto dest: unique) +qed (auto cong: nn_integral_cong_simp) + lemma emeasure_UN_countable: assumes sets[measurable]: "\i. i \ I \ X i \ sets M" and I[simp]: "countable I" assumes disj: "disjoint_family_on X I" diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Analysis/Sigma_Algebra.thy --- a/src/HOL/Analysis/Sigma_Algebra.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Analysis/Sigma_Algebra.thy Fri Sep 30 16:08:38 2016 +0200 @@ -1244,6 +1244,10 @@ lemma (in algebra) Int_stable: "Int_stable M" unfolding Int_stable_def by auto +lemma Int_stableI_image: + "(\i j. i \ I \ j \ I \ \k\I. A i \ A j = A k) \ Int_stable (A ` I)" + by (auto simp: Int_stable_def image_def) + lemma Int_stableI: "(\a b. a \ A \ b \ A \ a \ b \ A) \ Int_stable A" unfolding Int_stable_def by auto @@ -1574,6 +1578,9 @@ using assms by(simp_all add: sets_measure_of_conv space_measure_of_conv) +lemma space_in_measure_of[simp]: "\ \ sets (measure_of \ M \)" + by (subst sets_measure_of_conv) (auto simp: sigma_sets_top) + lemma (in sigma_algebra) sets_measure_of_eq[simp]: "sets (measure_of \ M \) = M" using space_closed by (auto intro!: sigma_sets_eq) @@ -2259,4 +2266,7 @@ by (rule measurable_restrict_countable[OF X]) (auto simp: eq[symmetric] space_restrict_space cong: measurable_cong' intro: f measurable_restrict_space1) +lemma measurable_count_space_extend: "A \ B \ f \ space M \ A \ f \ M \\<^sub>M count_space B \ f \ M \\<^sub>M count_space A" + by (auto simp: measurable_def) + end diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Library/Countable_Set.thy --- a/src/HOL/Library/Countable_Set.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Library/Countable_Set.thy Fri Sep 30 16:08:38 2016 +0200 @@ -284,6 +284,9 @@ lemma countable_Collect_finite: "countable (Collect (finite::'a::countable set\bool))" by (simp add: Collect_finite_eq_lists) +lemma countable_int: "countable \" + unfolding Ints_def by auto + lemma countable_rat: "countable \" unfolding Rats_def by auto diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Library/Extended_Nonnegative_Real.thy --- a/src/HOL/Library/Extended_Nonnegative_Real.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Library/Extended_Nonnegative_Real.thy Fri Sep 30 16:08:38 2016 +0200 @@ -220,6 +220,11 @@ shows "summable f \ finite I \ \m\- I. 0 \ f m \ setsum f I \ suminf f" by (rule sums_le[OF _ sums_If_finite_set summable_sums]) auto +lemma suminf_eq_SUP_real: + assumes X: "summable X" "\i. 0 \ X i" shows "suminf X = (SUP i. \nDefining the extended non-negative reals\ text \Basic definitions and type class setup\ diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Probability/Giry_Monad.thy --- a/src/HOL/Probability/Giry_Monad.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Probability/Giry_Monad.thy Fri Sep 30 16:08:38 2016 +0200 @@ -28,6 +28,9 @@ show "subprob_space M" by standard fact+ qed +lemma (in subprob_space) emeasure_subprob_space_less_top: "emeasure M A \ top" + using emeasure_finite[of A] . + lemma prob_space_imp_subprob_space: "prob_space M \ subprob_space M" by (rule subprob_spaceI) (simp_all add: prob_space.emeasure_space_1 prob_space.not_empty) @@ -245,6 +248,43 @@ by (auto dest: subprob_space_kernel sets_kernel) qed +lemma measurable_subprob_algebra_generated: + assumes eq: "sets N = sigma_sets \ G" and "Int_stable G" "G \ Pow \" + assumes subsp: "\a. a \ space M \ subprob_space (K a)" + assumes sets: "\a. a \ space M \ sets (K a) = sets N" + assumes "\A. A \ G \ (\a. emeasure (K a) A) \ borel_measurable M" + assumes \: "(\a. emeasure (K a) \) \ borel_measurable M" + shows "K \ measurable M (subprob_algebra N)" +proof (rule measurable_subprob_algebra) + fix a assume "a \ space M" then show "subprob_space (K a)" "sets (K a) = sets N" by fact+ +next + interpret G: sigma_algebra \ "sigma_sets \ G" + using \G \ Pow \\ by (rule sigma_algebra_sigma_sets) + fix A assume "A \ sets N" with assms(2,3) show "(\a. emeasure (K a) A) \ borel_measurable M" + unfolding \sets N = sigma_sets \ G\ + proof (induction rule: sigma_sets_induct_disjoint) + case (basic A) then show ?case by fact + next + case empty then show ?case by simp + next + case (compl A) + have "(\a. emeasure (K a) (\ - A)) \ borel_measurable M \ + (\a. emeasure (K a) \ - emeasure (K a) A) \ borel_measurable M" + using G.top G.sets_into_space sets eq compl subprob_space.emeasure_subprob_space_less_top[OF subsp] + by (intro measurable_cong emeasure_Diff) auto + with compl \ show ?case + by simp + next + case (union F) + moreover have "(\a. emeasure (K a) (\i. F i)) \ borel_measurable M \ + (\a. \i. emeasure (K a) (F i)) \ borel_measurable M" + using sets union eq + by (intro measurable_cong suminf_emeasure[symmetric]) auto + ultimately show ?case + by auto + qed +qed + lemma space_subprob_algebra_empty_iff: "space (subprob_algebra N) = {} \ space N = {}" proof @@ -1080,7 +1120,7 @@ shows "space (bind M f) = space N" using assms by (intro sets_eq_imp_space_eq sets_bind) -lemma bind_cong: +lemma bind_cong_All: assumes "\x \ space M. f x = g x" shows "bind M f = bind M g" proof (cases "space M = {}") @@ -1090,6 +1130,10 @@ with \space M \ {}\ and assms show ?thesis by (simp add: bind_nonempty cong: distr_cong) qed (simp add: bind_empty) +lemma bind_cong: + "M = N \ (\x. x \ space M \ f x = g x) \ bind M f = bind N g" + using bind_cong_All[of M f g] by auto + lemma bind_nonempty': assumes "f \ measurable M (subprob_algebra N)" "x \ space M" shows "bind M f = join (distr M (subprob_algebra N) f)" @@ -1121,8 +1165,8 @@ qed (simp add: bind_empty space_empty[of M] nn_integral_count_space) lemma AE_bind: + assumes N[measurable]: "N \ measurable M (subprob_algebra B)" assumes P[measurable]: "Measurable.pred B P" - assumes N[measurable]: "N \ measurable M (subprob_algebra B)" shows "(AE x in M \ N. P x) \ (AE x in M. AE y in N x. P y)" proof cases assume M: "space M = {}" show ?thesis @@ -1454,7 +1498,7 @@ also from Mh have "\x. x \ space M \ h x \ measurable M' N" by measurable hence "do {x \ M; do {y \ f x; return N (h x y)} \ g} = do {x \ M; y \ f x; return N (h x y) \ g}" - apply (intro ballI bind_cong bind_assoc) + apply (intro ballI bind_cong refl bind_assoc) apply (subst measurable_cong_sets[OF sets_kernel[OF Mf] refl], simp) apply (rule measurable_compose[OF _ return_measurable], auto intro: Mg) done @@ -1522,4 +1566,150 @@ "null_measure M \ space (subprob_algebra M) \ space M \ {}" by(simp add: space_subprob_algebra subprob_space_null_measure_iff) +subsection \Giry monad on probability spaces\ + +definition prob_algebra :: "'a measure \ 'a measure measure" where + "prob_algebra K = restrict_space (subprob_algebra K) {M. prob_space M}" + +lemma space_prob_algebra: "space (prob_algebra M) = {N. sets N = sets M \ prob_space N}" + unfolding prob_algebra_def by (auto simp: space_subprob_algebra space_restrict_space prob_space_imp_subprob_space) + +lemma measurable_measure_prob_algebra[measurable]: + "a \ sets A \ (\M. Sigma_Algebra.measure M a) \ prob_algebra A \\<^sub>M borel" + unfolding prob_algebra_def by (intro measurable_restrict_space1 measurable_measure_subprob_algebra) + +lemma measurable_prob_algebraD: + "f \ N \\<^sub>M prob_algebra M \ f \ N \\<^sub>M subprob_algebra M" + unfolding prob_algebra_def measurable_restrict_space2_iff by auto + +lemma measure_measurable_prob_algebra2: + "Sigma (space M) A \ sets (M \\<^sub>M N) \ L \ M \\<^sub>M prob_algebra N \ + (\x. Sigma_Algebra.measure (L x) (A x)) \ borel_measurable M" + using measure_measurable_subprob_algebra2[of M A N L] by (auto intro: measurable_prob_algebraD) + +lemma measurable_prob_algebraI: + "(\x. x \ space N \ prob_space (f x)) \ f \ N \\<^sub>M subprob_algebra M \ f \ N \\<^sub>M prob_algebra M" + unfolding prob_algebra_def by (intro measurable_restrict_space2) auto + +lemma measurable_distr_prob_space: + assumes f: "f \ M \\<^sub>M N" + shows "(\M'. distr M' N f) \ prob_algebra M \\<^sub>M prob_algebra N" + unfolding prob_algebra_def measurable_restrict_space2_iff +proof (intro conjI measurable_restrict_space1 measurable_distr f) + show "(\M'. distr M' N f) \ space (restrict_space (subprob_algebra M) (Collect prob_space)) \ Collect prob_space" + using f by (auto simp: space_restrict_space space_subprob_algebra intro!: prob_space.prob_space_distr) +qed + +lemma measurable_return_prob_space[measurable]: "return N \ N \\<^sub>M prob_algebra N" + by (rule measurable_prob_algebraI) (auto simp: prob_space_return) + +lemma measurable_distr_prob_space2[measurable (raw)]: + assumes f: "g \ L \\<^sub>M prob_algebra M" "(\(x, y). f x y) \ L \\<^sub>M M \\<^sub>M N" + shows "(\x. distr (g x) N (f x)) \ L \\<^sub>M prob_algebra N" + unfolding prob_algebra_def measurable_restrict_space2_iff +proof (intro conjI measurable_restrict_space1 measurable_distr2[where M=M] f measurable_prob_algebraD) + show "(\x. distr (g x) N (f x)) \ space L \ Collect prob_space" + using f subprob_measurableD[OF measurable_prob_algebraD[OF f(1)]] + by (auto simp: measurable_restrict_space2_iff prob_algebra_def + intro!: prob_space.prob_space_distr) +qed + +lemma measurable_bind_prob_space: + assumes f: "f \ M \\<^sub>M prob_algebra N" and g: "g \ N \\<^sub>M prob_algebra R" + shows "(\x. bind (f x) g) \ M \\<^sub>M prob_algebra R" + unfolding prob_algebra_def measurable_restrict_space2_iff +proof (intro conjI measurable_restrict_space1 measurable_bind2[where N=N] f g measurable_prob_algebraD) + show "(\x. f x \ g) \ space M \ Collect prob_space" + using g f subprob_measurableD[OF measurable_prob_algebraD[OF f]] + by (auto simp: measurable_restrict_space2_iff prob_algebra_def + intro!: prob_space.prob_space_bind[where S=R] AE_I2) +qed + +lemma measurable_bind_prob_space2[measurable (raw)]: + assumes f: "f \ M \\<^sub>M prob_algebra N" and g: "(\(x, y). g x y) \ (M \\<^sub>M N) \\<^sub>M prob_algebra R" + shows "(\x. bind (f x) (g x)) \ M \\<^sub>M prob_algebra R" + unfolding prob_algebra_def measurable_restrict_space2_iff +proof (intro conjI measurable_restrict_space1 measurable_bind[where N=N] f g measurable_prob_algebraD) + show "(\x. f x \ g x) \ space M \ Collect prob_space" + using g f subprob_measurableD[OF measurable_prob_algebraD[OF f]] + using measurable_space[OF g] + by (auto simp: measurable_restrict_space2_iff prob_algebra_def space_pair_measure Pi_iff + intro!: prob_space.prob_space_bind[where S=R] AE_I2) +qed (insert g, simp) + + +lemma measurable_prob_algebra_generated: + assumes eq: "sets N = sigma_sets \ G" and "Int_stable G" "G \ Pow \" + assumes subsp: "\a. a \ space M \ prob_space (K a)" + assumes sets: "\a. a \ space M \ sets (K a) = sets N" + assumes "\A. A \ G \ (\a. emeasure (K a) A) \ borel_measurable M" + shows "K \ measurable M (prob_algebra N)" + unfolding measurable_restrict_space2_iff prob_algebra_def +proof + show "K \ M \\<^sub>M subprob_algebra N" + proof (rule measurable_subprob_algebra_generated[OF assms(1,2,3) _ assms(5,6)]) + fix a assume "a \ space M" then show "subprob_space (K a)" + using subsp[of a] by (intro prob_space_imp_subprob_space) + next + have "(\a. emeasure (K a) \) \ borel_measurable M \ (\a. 1::ennreal) \ borel_measurable M" + using sets_eq_imp_space_eq[of "sigma \ G" N] \G \ Pow \\ eq sets_eq_imp_space_eq[OF sets] + prob_space.emeasure_space_1[OF subsp] + by (intro measurable_cong) auto + then show "(\a. emeasure (K a) \) \ borel_measurable M" by simp + qed +qed (insert subsp, auto) + +lemma in_space_prob_algebra: + "x \ space (prob_algebra M) \ emeasure x (space M) = 1" + unfolding prob_algebra_def space_restrict_space space_subprob_algebra + by (auto dest!: prob_space.emeasure_space_1 sets_eq_imp_space_eq) + +lemma prob_space_pair: + assumes "prob_space M" "prob_space N" shows "prob_space (M \\<^sub>M N)" +proof - + interpret M: prob_space M by fact + interpret N: prob_space N by fact + interpret P: pair_prob_space M N proof qed + show ?thesis + by unfold_locales +qed + +lemma measurable_pair_prob[measurable]: + "f \ M \\<^sub>M prob_algebra N \ g \ M \\<^sub>M prob_algebra L \ (\x. f x \\<^sub>M g x) \ M \\<^sub>M prob_algebra (N \\<^sub>M L)" + unfolding prob_algebra_def measurable_restrict_space2_iff + by (auto intro!: measurable_pair_measure prob_space_pair) + +lemma emeasure_bind_prob_algebra: + assumes A: "A \ space (prob_algebra N)" + assumes B: "B \ N \\<^sub>M prob_algebra L" + assumes X: "X \ sets L" + shows "emeasure (bind A B) X = (\\<^sup>+x. emeasure (B x) X \A)" + using A B + by (intro emeasure_bind[OF _ _ X]) + (auto simp: space_prob_algebra measurable_prob_algebraD cong: measurable_cong_sets intro!: prob_space.not_empty) + +lemma prob_space_bind': + assumes A: "A \ space (prob_algebra M)" and B: "B \ M \\<^sub>M prob_algebra N" shows "prob_space (A \ B)" + using measurable_bind_prob_space[OF measurable_const, OF A B, THEN measurable_space, of undefined "count_space UNIV"] + by (simp add: space_prob_algebra) + +lemma sets_bind': + assumes A: "A \ space (prob_algebra M)" and B: "B \ M \\<^sub>M prob_algebra N" shows "sets (A \ B) = sets N" + using measurable_bind_prob_space[OF measurable_const, OF A B, THEN measurable_space, of undefined "count_space UNIV"] + by (simp add: space_prob_algebra) + +lemma bind_cong_AE: + assumes M: "M \ space (prob_algebra L)" + and f: "f \ L \\<^sub>M prob_algebra N" and g: "g \ L \\<^sub>M prob_algebra N" + and ae: "AE x in M. f x = g x" + shows "bind M f = bind M g" +proof (rule measure_eqI) + show "sets (M \ f) = sets (M \ g)" + unfolding sets_bind'[OF M f] sets_bind'[OF M g] .. + show "A \ sets (M \ f) \ emeasure (M \ f) A = emeasure (M \ g) A" for A + unfolding sets_bind'[OF M f] + using emeasure_bind_prob_algebra[OF M f, of A] emeasure_bind_prob_algebra[OF M g, of A] ae + by (auto intro: nn_integral_cong_AE) +qed + end diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Probability/Infinite_Product_Measure.thy --- a/src/HOL/Probability/Infinite_Product_Measure.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Probability/Infinite_Product_Measure.thy Fri Sep 30 16:08:38 2016 +0200 @@ -63,6 +63,21 @@ using emeasure_PiM_emb[of "{}" "\_. {}"] by (simp add: *) qed +lemma prob_space_PiM: + assumes M: "\i. i \ I \ prob_space (M i)" shows "prob_space (PiM I M)" +proof - + let ?M = "\i. if i \ I then M i else count_space {undefined}" + interpret M': prob_space "?M i" for i + using M by (cases "i \ I") (auto intro!: prob_spaceI) + interpret product_prob_space ?M I + by unfold_locales + have "prob_space (\\<^sub>M i\I. ?M i)" + by unfold_locales + also have "(\\<^sub>M i\I. ?M i) = (\\<^sub>M i\I. M i)" + by (intro PiM_cong) auto + finally show ?thesis . +qed + lemma (in product_prob_space) emeasure_PiM_Collect: assumes X: "J \ I" "finite J" "\i. i \ J \ X i \ sets (M i)" shows "emeasure (Pi\<^sub>M I M) {x\space (Pi\<^sub>M I M). \i\J. x i \ X i} = (\ i\J. emeasure (M i) (X i))" @@ -123,6 +138,107 @@ apply simp_all done +lemma emeasure_PiM_emb: + assumes M: "\i. i \ I \ prob_space (M i)" + assumes J: "J \ I" "finite J" and A: "\i. i \ J \ A i \ sets (M i)" + shows "emeasure (Pi\<^sub>M I M) (prod_emb I M J (Pi\<^sub>E J A)) = (\i\J. emeasure (M i) (A i))" +proof - + let ?M = "\i. if i \ I then M i else count_space {undefined}" + interpret M': prob_space "?M i" for i + using M by (cases "i \ I") (auto intro!: prob_spaceI) + interpret P: product_prob_space ?M I + by unfold_locales + have "emeasure (Pi\<^sub>M I M) (prod_emb I M J (Pi\<^sub>E J A)) = emeasure (Pi\<^sub>M I ?M) (P.emb I J (Pi\<^sub>E J A))" + by (auto simp: prod_emb_def PiE_iff intro!: arg_cong2[where f=emeasure] PiM_cong) + also have "\ = (\i\J. emeasure (M i) (A i))" + using J A by (subst P.emeasure_PiM_emb[OF J]) (auto intro!: setprod.cong) + finally show ?thesis . +qed + +lemma distr_pair_PiM_eq_PiM: + fixes i' :: "'i" and I :: "'i set" and M :: "'i \ 'a measure" + assumes M: "\i. i \ I \ prob_space (M i)" "prob_space (M i')" + shows "distr (M i' \\<^sub>M (\\<^sub>M i\I. M i)) (\\<^sub>M i\insert i' I. M i) (\(x, X). X(i' := x)) = + (\\<^sub>M i\insert i' I. M i)" (is "?L = _") +proof (rule measure_eqI_PiM_infinite[symmetric, OF refl]) + interpret M': prob_space "M i'" by fact + interpret I: prob_space "(\\<^sub>M i\I. M i)" + using M by (intro prob_space_PiM) auto + interpret I': prob_space "(\\<^sub>M i\insert i' I. M i)" + using M by (intro prob_space_PiM) auto + show "finite_measure (\\<^sub>M i\insert i' I. M i)" + by unfold_locales + fix J A assume J: "finite J" "J \ insert i' I" and A: "\i. i \ J \ A i \ sets (M i)" + let ?X = "prod_emb (insert i' I) M J (Pi\<^sub>E J A)" + have "Pi\<^sub>M (insert i' I) M ?X = (\i\J. M i (A i))" + using M J A by (intro emeasure_PiM_emb) auto + also have "\ = M i' (if i' \ J then (A i') else space (M i')) * (\i\J-{i'}. M i (A i))" + using setprod.insert_remove[of J "\i. M i (A i)" i'] J M'.emeasure_space_1 + by (cases "i' \ J") (auto simp: insert_absorb) + also have "(\i\J-{i'}. M i (A i)) = Pi\<^sub>M I M (prod_emb I M (J - {i'}) (Pi\<^sub>E (J - {i'}) A))" + using M J A by (intro emeasure_PiM_emb[symmetric]) auto + also have "M i' (if i' \ J then (A i') else space (M i')) * \ = + (M i' \\<^sub>M Pi\<^sub>M I M) ((if i' \ J then (A i') else space (M i')) \ prod_emb I M (J - {i'}) (Pi\<^sub>E (J - {i'}) A))" + using J A by (intro I.emeasure_pair_measure_Times[symmetric] sets_PiM_I) auto + also have "((if i' \ J then (A i') else space (M i')) \ prod_emb I M (J - {i'}) (Pi\<^sub>E (J - {i'}) A)) = + (\(x, X). X(i' := x)) -` ?X \ space (M i' \\<^sub>M Pi\<^sub>M I M)" + using A[of i', THEN sets.sets_into_space] unfolding set_eq_iff + by (simp add: prod_emb_def space_pair_measure space_PiM PiE_fun_upd ac_simps cong: conj_cong) + (auto simp add: Pi_iff Ball_def all_conj_distrib) + finally show "Pi\<^sub>M (insert i' I) M ?X = ?L ?X" + using J A by (simp add: emeasure_distr) +qed simp + +lemma distr_PiM_reindex: + assumes M: "\i. i \ K \ prob_space (M i)" + assumes f: "inj_on f I" "f \ I \ K" + shows "distr (Pi\<^sub>M K M) (\\<^sub>M i\I. M (f i)) (\\. \n\I. \ (f n)) = (\\<^sub>M i\I. M (f i))" + (is "distr ?K ?I ?t = ?I") +proof (rule measure_eqI_PiM_infinite[symmetric, OF refl]) + interpret prob_space ?I + using f M by (intro prob_space_PiM) auto + show "finite_measure ?I" + by unfold_locales + fix A J assume J: "finite J" "J \ I" and A: "\i. i \ J \ A i \ sets (M (f i))" + have [simp]: "i \ J \ the_inv_into I f (f i) = i" for i + using J f by (intro the_inv_into_f_f) auto + have "?I (prod_emb I (\i. M (f i)) J (Pi\<^sub>E J A)) = (\j\J. M (f j) (A j))" + using f J A by (intro emeasure_PiM_emb M) auto + also have "\ = (\j\f`J. M j (A (the_inv_into I f j)))" + using f J by (subst setprod.reindex) (auto intro!: setprod.cong intro: inj_on_subset simp: the_inv_into_f_f) + also have "\ = ?K (prod_emb K M (f`J) (\\<^sub>E j\f`J. A (the_inv_into I f j)))" + using f J A by (intro emeasure_PiM_emb[symmetric] M) (auto simp: the_inv_into_f_f) + also have "prod_emb K M (f`J) (\\<^sub>E j\f`J. A (the_inv_into I f j)) = ?t -` prod_emb I (\i. M (f i)) J (Pi\<^sub>E J A) \ space ?K" + using f J A by (auto simp: prod_emb_def space_PiM Pi_iff PiE_iff Int_absorb1) + also have "?K \ = distr ?K ?I ?t (prod_emb I (\i. M (f i)) J (Pi\<^sub>E J A))" + using f J A by (intro emeasure_distr[symmetric] sets_PiM_I) (auto simp: Pi_iff) + finally show "?I (prod_emb I (\i. M (f i)) J (Pi\<^sub>E J A)) = distr ?K ?I ?t (prod_emb I (\i. M (f i)) J (Pi\<^sub>E J A))" . +qed simp + +lemma distr_PiM_component: + assumes M: "\i. i \ I \ prob_space (M i)" + assumes "i \ I" + shows "distr (Pi\<^sub>M I M) (M i) (\\. \ i) = M i" +proof - + have *: "(\\. \ i) -` A \ space (Pi\<^sub>M I M) = prod_emb I M {i} (\\<^sub>E i'\{i}. A)" for A + by (auto simp: prod_emb_def space_PiM) + show ?thesis + apply (intro measure_eqI) + apply (auto simp add: emeasure_distr \i\I\ * emeasure_PiM_emb M) + apply (subst emeasure_PiM_emb) + apply (simp_all add: M \i\I\) + done +qed + +lemma AE_PiM_component: + "(\i. i \ I \ prob_space (M i)) \ i \ I \ AE x in M i. P x \ AE x in PiM I M. P (x i)" + using AE_distrD[of "\x. x i" "PiM I M" "M i"] + by (subst (asm) distr_PiM_component[of I _ i]) (auto intro: AE_distrD[of "\x. x i" _ _ P]) + +lemma decseq_emb_PiE: + "incseq J \ decseq (\i. prod_emb I M (J i) (\\<^sub>E j\J i. X j))" + by (fastforce simp: decseq_def prod_emb_def incseq_def Pi_iff) + subsection \Sequence space\ definition comb_seq :: "nat \ (nat \ 'a) \ (nat \ 'a) \ (nat \ 'a)" where diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Probability/Information.thy --- a/src/HOL/Probability/Information.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Probability/Information.thy Fri Sep 30 16:08:38 2016 +0200 @@ -389,10 +389,6 @@ done qed -lemma integrable_cong_AE_imp: - "integrable M g \ f \ borel_measurable M \ (AE x in M. g x = f x) \ integrable M f" - using integrable_cong_AE[of f M g] by (auto simp: eq_commute) - lemma (in information_space) finite_entropy_integrable: "finite_entropy S X Px \ integrable S (\x. Px x * log b (Px x))" unfolding finite_entropy_def by auto diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Probability/Probability_Mass_Function.thy --- a/src/HOL/Probability/Probability_Mass_Function.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Probability/Probability_Mass_Function.thy Fri Sep 30 16:08:38 2016 +0200 @@ -246,7 +246,7 @@ shows "finite (set_pmf M) \ integrable M f" by (auto intro!: integrableI_bounded simp: nn_integral_measure_pmf_finite ennreal_mult_less_top) -lemma integral_measure_pmf: +lemma integral_measure_pmf_real: assumes [simp]: "finite A" and "\a. a \ set_pmf M \ f a \ 0 \ a \ A" shows "(\x. f x \measure_pmf M) = (\a\A. f a * pmf M a)" proof - @@ -572,9 +572,9 @@ lemma pmf_pair: "pmf (pair_pmf M N) (a, b) = pmf M a * pmf N b" unfolding pair_pmf_def pmf_bind pmf_return - apply (subst integral_measure_pmf[where A="{b}"]) + apply (subst integral_measure_pmf_real[where A="{b}"]) apply (auto simp: indicator_eq_0_iff) - apply (subst integral_measure_pmf[where A="{a}"]) + apply (subst integral_measure_pmf_real[where A="{a}"]) apply (auto simp: indicator_eq_0_iff setsum_nonneg_eq_0_iff pmf_nonneg) done @@ -658,7 +658,10 @@ done lemma pmf_map_outside: "x \ f ` set_pmf M \ pmf (map_pmf f M) x = 0" -unfolding pmf_eq_0_set_pmf by simp + unfolding pmf_eq_0_set_pmf by simp + +lemma measurable_set_pmf[measurable]: "Measurable.pred (count_space UNIV) (\x. x \ set_pmf M)" + by simp subsection \ PMFs as function \ @@ -742,6 +745,107 @@ lemma nn_integral_measure_pmf: "(\\<^sup>+ x. f x \measure_pmf p) = \\<^sup>+ x. ennreal (pmf p x) * f x \count_space UNIV" by(simp add: measure_pmf_eq_density nn_integral_density pmf_nonneg) +lemma integral_measure_pmf: + fixes f :: "'a \ 'b::{banach, second_countable_topology}" + assumes A: "finite A" + shows "(\a. a \ set_pmf M \ f a \ 0 \ a \ A) \ (LINT x|M. f x) = (\a\A. pmf M a *\<^sub>R f a)" + unfolding measure_pmf_eq_density + apply (simp add: integral_density) + apply (subst lebesgue_integral_count_space_finite_support) + apply (auto intro!: finite_subset[OF _ \finite A\] setsum.mono_neutral_left simp: pmf_eq_0_set_pmf) + done + +lemma continuous_on_LINT_pmf: -- \This is dominated convergence!?\ + fixes f :: "'i \ 'a::topological_space \ 'b::{banach, second_countable_topology}" + assumes f: "\i. i \ set_pmf M \ continuous_on A (f i)" + and bnd: "\a i. a \ A \ i \ set_pmf M \ norm (f i a) \ B" + shows "continuous_on A (\a. LINT i|M. f i a)" +proof cases + assume "finite M" with f show ?thesis + using integral_measure_pmf[OF \finite M\] + by (subst integral_measure_pmf[OF \finite M\]) + (auto intro!: continuous_on_setsum continuous_on_scaleR continuous_on_const) +next + assume "infinite M" + let ?f = "\i x. pmf (map_pmf (to_nat_on M) M) i *\<^sub>R f (from_nat_into M i) x" + + show ?thesis + proof (rule uniform_limit_theorem) + show "\\<^sub>F n in sequentially. continuous_on A (\a. \in a. \ia. LINT i|M. f i a) sequentially" + proof (subst uniform_limit_cong[where g="\n a. \i A" + have 1: "(LINT i|M. f i a) = (LINT i|map_pmf (to_nat_on M) M. f (from_nat_into M i) a)" + by (auto intro!: integral_cong_AE AE_pmfI) + have 2: "\ = (LINT i|count_space UNIV. pmf (map_pmf (to_nat_on M) M) i *\<^sub>R f (from_nat_into M i) a)" + by (simp add: measure_pmf_eq_density integral_density) + have "(\n. ?f n a) sums (LINT i|M. f i a)" + unfolding 1 2 + proof (intro sums_integral_count_space_nat) + have A: "integrable M (\i. f i a)" + using \a\A\ by (auto intro!: measure_pmf.integrable_const_bound AE_pmfI bnd) + have "integrable (map_pmf (to_nat_on M) M) (\i. f (from_nat_into M i) a)" + by (auto simp add: map_pmf_rep_eq integrable_distr_eq intro!: AE_pmfI integrable_cong_AE_imp[OF A]) + then show "integrable (count_space UNIV) (\n. ?f n a)" + by (simp add: measure_pmf_eq_density integrable_density) + qed + then show "(LINT i|M. f i a) = (\ n. ?f n a)" + by (simp add: sums_unique) + next + show "uniform_limit A (\n a. \ia. (\ n. ?f n a)) sequentially" + proof (rule weierstrass_m_test) + fix n a assume "a\A" + then show "norm (?f n a) \ pmf (map_pmf (to_nat_on M) M) n * B" + using bnd by (auto intro!: mult_mono simp: from_nat_into set_pmf_not_empty) + next + have "integrable (map_pmf (to_nat_on M) M) (\n. B)" + by auto + then show "summable (\n. pmf (map_pmf (to_nat_on (set_pmf M)) M) n * B)" + by (simp add: measure_pmf_eq_density integrable_density integrable_count_space_nat_iff summable_rabs_cancel) + qed + qed simp + qed simp +qed + +lemma continuous_on_LBINT: + fixes f :: "real \ real" + assumes f: "\b. a \ b \ set_integrable lborel {a..b} f" + shows "continuous_on UNIV (\b. LBINT x:{a..b}. f x)" +proof (subst set_borel_integral_eq_integral) + { fix b :: real assume "a \ b" + from f[OF this] have "continuous_on {a..b} (\b. integral {a..b} f)" + by (intro indefinite_integral_continuous set_borel_integral_eq_integral) } + note * = this + + have "continuous_on (\b\{a..}. {a <..< b}) (\b. integral {a..b} f)" + proof (intro continuous_on_open_UN) + show "b \ {a..} \ continuous_on {a<..b. integral {a..b} f)" for b + using *[of b] by (rule continuous_on_subset) auto + qed simp + also have "(\b\{a..}. {a <..< b}) = {a <..}" + by (auto simp: lt_ex gt_ex less_imp_le) (simp add: Bex_def less_imp_le gt_ex cong: rev_conj_cong) + finally have "continuous_on {a+1 ..} (\b. integral {a..b} f)" + by (rule continuous_on_subset) auto + moreover have "continuous_on {a..a+1} (\b. integral {a..b} f)" + by (rule *) simp + moreover + have "x \ a \ {a..x} = (if a = x then {a} else {})" for x + by auto + then have "continuous_on {..a} (\b. integral {a..b} f)" + by (subst continuous_on_cong[OF refl, where g="\x. 0"]) (auto intro!: continuous_on_const) + ultimately have "continuous_on ({..a} \ {a..a+1} \ {a+1 ..}) (\b. integral {a..b} f)" + by (intro continuous_on_closed_Un) auto + also have "{..a} \ {a..a+1} \ {a+1 ..} = UNIV" + by auto + finally show "continuous_on UNIV (\b. integral {a..b} f)" + by auto +next + show "set_integrable lborel {a..b} f" for b + using f by (cases "a \ b") auto +qed + locale pmf_as_function begin diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Probability/Probability_Measure.thy --- a/src/HOL/Probability/Probability_Measure.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Probability/Probability_Measure.thy Fri Sep 30 16:08:38 2016 +0200 @@ -508,8 +508,6 @@ "distributed M N X f \ distr M N X = density N f \ f \ borel_measurable N \ X \ measurable M N" -term distributed - lemma assumes "distributed M N X f" shows distributed_distr_eq_density: "distr M N X = density N f" diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Probability/Stream_Space.thy --- a/src/HOL/Probability/Stream_Space.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Probability/Stream_Space.thy Fri Sep 30 16:08:38 2016 +0200 @@ -109,6 +109,10 @@ shows "(\x. stake n (f x) @- g x) \ measurable N (stream_space M)" using f by (induction n arbitrary: f) simp_all +lemma measurable_case_stream_replace[measurable (raw)]: + "(\x. f x (shd (g x)) (stl (g x))) \ measurable M N \ (\x. case_stream (f x) (g x)) \ measurable M N" + unfolding stream.case_eq_if . + lemma measurable_ev_at[measurable]: assumes [measurable]: "Measurable.pred (stream_space M) P" shows "Measurable.pred (stream_space M) (ev_at P n)" @@ -442,4 +446,212 @@ by (cases "xs = []") (auto simp: * space_stream_space del: in_listsD) qed (auto simp: * ae sets_M del: in_listsD intro!: streams_sets) +primrec scylinder :: "'a set \ 'a set list \ 'a stream set" +where + "scylinder S [] = streams S" +| "scylinder S (A # As) = {\\streams S. shd \ \ A \ stl \ \ scylinder S As}" + +lemma scylinder_streams: "scylinder S xs \ streams S" + by (induction xs) auto + +lemma sets_scylinder: "(\x\set xs. x \ sets S) \ scylinder (space S) xs \ sets (stream_space S)" + by (induction xs) (auto simp: space_stream_space[symmetric]) + +lemma stream_space_eq_scylinder: + assumes P: "prob_space M" "prob_space N" + assumes "Int_stable G" and S: "sets S = sets (sigma (space S) G)" + and C: "countable C" "C \ G" "\C = space S" and G: "G \ Pow (space S)" + assumes sets_M: "sets M = sets (stream_space S)" + assumes sets_N: "sets N = sets (stream_space S)" + assumes *: "\xs. xs \ [] \ xs \ lists G \ emeasure M (scylinder (space S) xs) = emeasure N (scylinder (space S) xs)" + shows "M = N" +proof (rule measure_eqI_generator_eq) + interpret M: prob_space M by fact + interpret N: prob_space N by fact + + let ?G = "scylinder (space S) ` lists G" + show sc_Pow: "?G \ Pow (streams (space S))" + using scylinder_streams by auto + + have "sets (stream_space S) = sets (sigma (streams (space S)) ?G)" + (is "?S = sets ?R") + proof (rule antisym) + let ?V = "\i. vimage_algebra (streams (space S)) (\s. s !! i) S" + show "?S \ sets ?R" + unfolding sets_stream_space_eq + proof (safe intro!: sets_Sup_in_sets del: subsetI equalityI) + fix i :: nat + show "space (?V i) = space ?R" + using scylinder_streams by (subst space_measure_of) (auto simp: ) + { fix A assume "A \ G" + then have "scylinder (space S) (replicate i (space S) @ [A]) = (\s. s !! i) -` A \ streams (space S)" + by (induction i) (auto simp add: streams_shd streams_stl cong: conj_cong) + also have "scylinder (space S) (replicate i (space S) @ [A]) = (\xs\{xs\lists C. length xs = i}. scylinder (space S) (xs @ [A]))" + apply (induction i) + apply auto [] + apply (simp add: length_Suc_conv set_eq_iff ex_simps(1,2)[symmetric] cong: conj_cong del: ex_simps(1,2)) + apply rule + subgoal for i x + apply (cases x) + apply (subst (2) C(3)[symmetric]) + apply (simp del: ex_simps(1,2) add: ex_simps(1,2)[symmetric] ac_simps Bex_def) + apply auto + done + done + finally have "(\s. s !! i) -` A \ streams (space S) = (\xs\{xs\lists C. length xs = i}. scylinder (space S) (xs @ [A]))" + .. + also have "\ \ ?R" + using C(2) \A\G\ + by (intro sets.countable_UN' countable_Collect countable_lists C) + (auto intro!: in_measure_of[OF sc_Pow] imageI) + finally have "(\s. s !! i) -` A \ streams (space S) \ ?R" . } + then show "sets (?V i) \ ?R" + apply (subst vimage_algebra_cong[OF refl refl S]) + apply (subst vimage_algebra_sigma[OF G]) + apply (simp add: streams_iff_snth) [] + apply (subst sigma_le_sets) + apply auto + done + qed + have "G \ sets S" + unfolding S using G by auto + with C(2) show "sets ?R \ ?S" + unfolding sigma_le_sets[OF sc_Pow] by (auto intro!: sets_scylinder) + qed + then show "sets M = sigma_sets (streams (space S)) (scylinder (space S) ` lists G)" + "sets N = sigma_sets (streams (space S)) (scylinder (space S) ` lists G)" + unfolding sets_M sets_N by (simp_all add: sc_Pow) + + show "Int_stable ?G" + proof (rule Int_stableI_image) + fix xs ys assume "xs \ lists G" "ys \ lists G" + then show "\zs\lists G. scylinder (space S) xs \ scylinder (space S) ys = scylinder (space S) zs" + proof (induction xs arbitrary: ys) + case Nil then show ?case + by (auto simp add: Int_absorb1 scylinder_streams) + next + case xs: (Cons x xs) + show ?case + proof (cases ys) + case Nil with xs.hyps show ?thesis + by (auto simp add: Int_absorb2 scylinder_streams intro!: bexI[of _ "x#xs"]) + next + case ys: (Cons y ys') + with xs.IH[of ys'] xs.prems obtain zs where + "zs \ lists G" and eq: "scylinder (space S) xs \ scylinder (space S) ys' = scylinder (space S) zs" + by auto + show ?thesis + proof (intro bexI[of _ "(x \ y)#zs"]) + show "x \ y # zs \ lists G" + using \zs\lists G\ \x\G\ \ys\lists G\ ys \Int_stable G\[THEN Int_stableD, of x y] by auto + show "scylinder (space S) (x # xs) \ scylinder (space S) ys = scylinder (space S) (x \ y # zs)" + by (auto simp add: eq[symmetric] ys) + qed + qed + qed + qed + + show "range (\_::nat. streams (space S)) \ scylinder (space S) ` lists G" + "(\i. streams (space S)) = streams (space S)" + "emeasure M (streams (space S)) \ \" + by (auto intro!: image_eqI[of _ _ "[]"]) + + fix X assume "X \ scylinder (space S) ` lists G" + then obtain xs where xs: "xs \ lists G" and eq: "X = scylinder (space S) xs" + by auto + then show "emeasure M X = emeasure N X" + proof (cases "xs = []") + assume "xs = []" then show ?thesis + unfolding eq + using sets_M[THEN sets_eq_imp_space_eq] sets_N[THEN sets_eq_imp_space_eq] + M.emeasure_space_1 N.emeasure_space_1 + by (simp add: space_stream_space[symmetric]) + next + assume "xs \ []" with xs show ?thesis + unfolding eq by (intro *) + qed +qed + +lemma stream_space_coinduct: + fixes R :: "'a stream measure \ 'a stream measure \ bool" + assumes "R A B" + assumes R: "\A B. R A B \ \K\space (prob_algebra M). + \A'\M \\<^sub>M prob_algebra (stream_space M). \B'\M \\<^sub>M prob_algebra (stream_space M). + (AE y in K. R (A' y) (B' y) \ A' y = B' y) \ + A = do { y \ K; \ \ A' y; return (stream_space M) (y ## \) } \ + B = do { y \ K; \ \ B' y; return (stream_space M) (y ## \) }" + shows "A = B" +proof (rule stream_space_eq_scylinder) + let ?step = "\K L. do { y \ K; \ \ L y; return (stream_space M) (y ## \) }" + { fix K A A' assume K: "K \ space (prob_algebra M)" + and A'[measurable]: "A' \ M \\<^sub>M prob_algebra (stream_space M)" and A_eq: "A = ?step K A'" + have ps: "prob_space A" + unfolding A_eq by (rule prob_space_bind'[OF K]) measurable + have "sets A = sets (stream_space M)" + unfolding A_eq by (rule sets_bind'[OF K]) measurable + note ps this } + note ** = this + + { fix A B assume "R A B" + obtain K A' B' where K: "K \ space (prob_algebra M)" + and A': "A' \ M \\<^sub>M prob_algebra (stream_space M)" "A = ?step K A'" + and B': "B' \ M \\<^sub>M prob_algebra (stream_space M)" "B = ?step K B'" + using R[OF \R A B\] by blast + have "prob_space A" "prob_space B" "sets A = sets (stream_space M)" "sets B = sets (stream_space M)" + using **[OF K A'] **[OF K B'] by auto } + note R_D = this + + show "prob_space A" "prob_space B" "sets A = sets (stream_space M)" "sets B = sets (stream_space M)" + using R_D[OF \R A B\] by auto + + show "Int_stable (sets M)" "sets M = sets (sigma (space M) (sets M))" "countable {space M}" + "{space M} \ sets M" "\{space M} = space M" "sets M \ Pow (space M)" + using sets.space_closed[of M] by (auto simp: Int_stable_def) + + { fix A As L K assume K[measurable]: "K \ space (prob_algebra M)" and A: "A \ sets M" "As \ lists (sets M)" + and L[measurable]: "L \ M \\<^sub>M prob_algebra (stream_space M)" + from A have [measurable]: "\x\set (A # As). x \ sets M" "\x\set As. x \ sets M" + by auto + have [simp]: "space K = space M" "sets K = sets M" + using K by (auto simp: space_prob_algebra intro!: sets_eq_imp_space_eq) + have [simp]: "x \ space M \ sets (L x) = sets (stream_space M)" for x + using measurable_space[OF L] by (auto simp: space_prob_algebra) + note sets_scylinder[measurable] + have *: "indicator (scylinder (space M) (A # As)) (x ## \) = + (indicator A x * indicator (scylinder (space M) As) \ :: ennreal)" for \ x + using scylinder_streams[of "space M" As] \A \ sets M\[THEN sets.sets_into_space] + by (auto split: split_indicator) + have "emeasure (?step K L) (scylinder (space M) (A # As)) = (\\<^sup>+y. L y (scylinder (space M) As) * indicator A y \K)" + apply (subst emeasure_bind_prob_algebra[OF K]) + apply measurable + apply (rule nn_integral_cong) + apply (subst emeasure_bind_prob_algebra[OF L[THEN measurable_space]]) + apply (simp_all add: ac_simps * nn_integral_cmult_indicator del: scylinder.simps) + apply measurable + done } + note emeasure_step = this + + fix Xs assume "Xs \ lists (sets M)" + from this \R A B\ show "emeasure A (scylinder (space M) Xs) = emeasure B (scylinder (space M) Xs)" + proof (induction Xs arbitrary: A B) + case (Cons X Xs) + obtain K A' B' where K: "K \ space (prob_algebra M)" + and A'[measurable]: "A' \ M \\<^sub>M prob_algebra (stream_space M)" and A: "A = ?step K A'" + and B'[measurable]: "B' \ M \\<^sub>M prob_algebra (stream_space M)" and B: "B = ?step K B'" + and AE_R: "AE x in K. R (A' x) (B' x) \ A' x = B' x" + using R[OF \R A B\] by blast + + show ?case + unfolding A B emeasure_step[OF K Cons.hyps A'] emeasure_step[OF K Cons.hyps B'] + apply (rule nn_integral_cong_AE) + using AE_R by eventually_elim (auto simp add: Cons.IH) + next + case Nil + note R_D[OF this] + from this(1,2)[THEN prob_space.emeasure_space_1] this(3,4)[THEN sets_eq_imp_space_eq] + show ?case + by (simp add: space_stream_space) + qed +qed + end diff -r 041cda506fb2 -r 17a20ca86d62 src/HOL/Topological_Spaces.thy --- a/src/HOL/Topological_Spaces.thy Mon Oct 03 14:09:26 2016 +0100 +++ b/src/HOL/Topological_Spaces.thy Fri Sep 30 16:08:38 2016 +0200 @@ -699,7 +699,7 @@ assumes "filterlim f (nhds c) F" assumes "eventually (\x. f x \ A - {c}) F" shows "filterlim f (at c within A) F" - using assms by (simp add: filterlim_at) + using assms by (simp add: filterlim_at) lemma filterlim_atI: assumes "filterlim f (nhds c) F" @@ -1644,6 +1644,10 @@ unfolding continuous_on_def by (intro ball_cong filterlim_cong) (auto simp: eventually_at_filter) +lemma continuous_on_strong_cong: + "s = t \ (\x. x \ t =simp=> f x = g x) \ continuous_on s f \ continuous_on t g" + unfolding simp_implies_def by (rule continuous_on_cong) + lemma continuous_on_topological: "continuous_on s f \ (\x\s. \B. open B \ f x \ B \ (\A. open A \ x \ A \ (\y\s. y \ A \ f y \ B)))"