diff -r 4ff2ba82d668 -r 7504569a73c7 src/HOL/Probability/Probability_Mass_Function.thy --- a/src/HOL/Probability/Probability_Mass_Function.thy Mon Apr 03 22:18:56 2017 +0200 +++ b/src/HOL/Probability/Probability_Mass_Function.thy Tue Apr 04 08:57:21 2017 +0200 @@ -663,6 +663,7 @@ lemma measurable_set_pmf[measurable]: "Measurable.pred (count_space UNIV) (\x. x \ set_pmf M)" by simp + subsection \ PMFs as function \ context @@ -754,6 +755,39 @@ apply (subst lebesgue_integral_count_space_finite_support) apply (auto intro!: finite_subset[OF _ \finite A\] sum.mono_neutral_left simp: pmf_eq_0_set_pmf) done + +lemma expectation_return_pmf [simp]: + fixes f :: "'a \ 'b::{banach, second_countable_topology}" + shows "measure_pmf.expectation (return_pmf x) f = f x" + by (subst integral_measure_pmf[of "{x}"]) simp_all + +lemma pmf_expectation_bind: + fixes p :: "'a pmf" and f :: "'a \ 'b pmf" + and h :: "'b \ 'c::{banach, second_countable_topology}" + assumes "finite A" "\x. x \ A \ finite (set_pmf (f x))" "set_pmf p \ A" + shows "measure_pmf.expectation (p \ f) h = + (\a\A. pmf p a *\<^sub>R measure_pmf.expectation (f a) h)" +proof - + have "measure_pmf.expectation (p \ f) h = (\a\(\x\A. set_pmf (f x)). pmf (p \ f) a *\<^sub>R h a)" + using assms by (intro integral_measure_pmf) auto + also have "\ = (\x\(\x\A. set_pmf (f x)). (\a\A. (pmf p a * pmf (f a) x) *\<^sub>R h x))" + proof (intro sum.cong refl, goal_cases) + case (1 x) + thus ?case + by (subst pmf_bind, subst integral_measure_pmf[of A]) + (insert assms, auto simp: scaleR_sum_left) + qed + also have "\ = (\j\A. pmf p j *\<^sub>R (\i\(\x\A. set_pmf (f x)). pmf (f j) i *\<^sub>R h i))" + by (subst sum.commute) (simp add: scaleR_sum_right) + also have "\ = (\j\A. pmf p j *\<^sub>R measure_pmf.expectation (f j) h)" + proof (intro sum.cong refl, goal_cases) + case (1 x) + thus ?case + by (subst integral_measure_pmf[of "(\x\A. set_pmf (f x))"]) + (insert assms, auto simp: scaleR_sum_left) + qed + finally show ?thesis . +qed lemma continuous_on_LINT_pmf: -- \This is dominated convergence!?\ fixes f :: "'i \ 'a::topological_space \ 'b::{banach, second_countable_topology}" @@ -1725,6 +1759,14 @@ by (simp add: measure_nonneg measure_pmf.emeasure_eq_measure) end + +lemma pmf_expectation_bind_pmf_of_set: + fixes A :: "'a set" and f :: "'a \ 'b pmf" + and h :: "'b \ 'c::{banach, second_countable_topology}" + assumes "A \ {}" "finite A" "\x. x \ A \ finite (set_pmf (f x))" + shows "measure_pmf.expectation (pmf_of_set A \ f) h = + (\a\A. measure_pmf.expectation (f a) h /\<^sub>R real (card A))" + using assms by (subst pmf_expectation_bind[of A]) (auto simp: divide_simps) lemma map_pmf_of_set: assumes "finite A" "A \ {}" @@ -1773,6 +1815,16 @@ qed qed +lemma map_pmf_of_set_bij_betw: + assumes "bij_betw f A B" "A \ {}" "finite A" + shows "map_pmf f (pmf_of_set A) = pmf_of_set B" +proof - + have "map_pmf f (pmf_of_set A) = pmf_of_set (f ` A)" + by (intro map_pmf_of_set_inj assms bij_betw_imp_inj_on[OF assms(1)]) + also from assms have "f ` A = B" by (simp add: bij_betw_def) + finally show ?thesis . +qed + text \ Choosing an element uniformly at random from the union of a disjoint family of finite non-empty sets with the same size is the same as first choosing a set