diff -r a6cd18af8bf9 -r 685fb01256af src/HOL/Probability/Probability_Mass_Function.thy --- a/src/HOL/Probability/Probability_Mass_Function.thy Thu Sep 15 22:41:05 2016 +0200 +++ b/src/HOL/Probability/Probability_Mass_Function.thy Fri Sep 16 13:56:51 2016 +0200 @@ -167,7 +167,7 @@ lemma pmf_nonneg[simp]: "0 \ pmf p x" by transfer simp - + lemma pmf_not_neg [simp]: "\pmf p x < 0" by (simp add: not_less pmf_nonneg) @@ -546,7 +546,7 @@ lemma measure_return_pmf [simp]: "measure_pmf.prob (return_pmf x) A = indicator A x" proof - - have "ennreal (measure_pmf.prob (return_pmf x) A) = + have "ennreal (measure_pmf.prob (return_pmf x) A) = emeasure (measure_pmf (return_pmf x)) A" by (simp add: measure_pmf.emeasure_eq_measure) also have "\ = ennreal (indicator A x)" by (simp add: ennreal_indicator) @@ -778,10 +778,10 @@ have "1 = measure (measure_pmf M) UNIV" by simp also have "\ = measure (measure_pmf N) {x} + measure (measure_pmf N) (UNIV - {x})" by (subst measure_pmf.finite_measure_Union [symmetric]) simp_all - also from gt have "measure (measure_pmf N) {x} < measure (measure_pmf M) {x}" + also from gt have "measure (measure_pmf N) {x} < measure (measure_pmf M) {x}" by (simp add: measure_pmf_single) also have "measure (measure_pmf N) (UNIV - {x}) \ measure (measure_pmf M) (UNIV - {x})" - by (subst (1 2) integral_pmf [symmetric]) + by (subst (1 2) integral_pmf [symmetric]) (intro integral_mono integrable_pmf, simp_all add: ge) also have "measure (measure_pmf M) {x} + \ = 1" by (subst measure_pmf.finite_measure_Union [symmetric]) simp_all @@ -803,7 +803,7 @@ by unfold_locales have "(\ x. \ y. pmf (C x y) i \B \A) = (\ x. (\ y. pmf (C x y) i \restrict_space B B) \A)" - by (rule integral_cong) (auto intro!: integral_pmf_restrict) + by (rule Bochner_Integration.integral_cong) (auto intro!: integral_pmf_restrict) also have "\ = (\ x. (\ y. pmf (C x y) i \restrict_space B B) \restrict_space A A)" by (intro integral_pmf_restrict B.borel_measurable_lebesgue_integral measurable_pair_restrict_pmf2 countable_set_pmf borel_measurable_count_space) @@ -815,7 +815,7 @@ by (intro integral_pmf_restrict[symmetric] A.borel_measurable_lebesgue_integral measurable_pair_restrict_pmf2 countable_set_pmf borel_measurable_count_space) also have "\ = (\ y. \ x. pmf (C x y) i \A \B)" - by (rule integral_cong) (auto intro!: integral_pmf_restrict[symmetric]) + by (rule Bochner_Integration.integral_cong) (auto intro!: integral_pmf_restrict[symmetric]) finally show "(\ x. \ y. pmf (C x y) i \B \A) = (\ y. \ x. pmf (C x y) i \A \B)" . qed @@ -1629,7 +1629,7 @@ lemma map_pmf_of_set: assumes "finite A" "A \ {}" - shows "map_pmf f (pmf_of_set A) = pmf_of_multiset (image_mset f (mset_set A))" + shows "map_pmf f (pmf_of_set A) = pmf_of_multiset (image_mset f (mset_set A))" (is "?lhs = ?rhs") proof (intro pmf_eqI) fix x @@ -1641,13 +1641,13 @@ lemma pmf_bind_pmf_of_set: assumes "A \ {}" "finite A" - shows "pmf (bind_pmf (pmf_of_set A) f) x = + shows "pmf (bind_pmf (pmf_of_set A) f) x = (\xa\A. pmf (f xa) x) / real_of_nat (card A)" (is "?lhs = ?rhs") proof - from assms have "card A > 0" by auto with assms have "ennreal ?lhs = ennreal ?rhs" - by (subst ennreal_pmf_bind) - (simp_all add: nn_integral_pmf_of_set max_def pmf_nonneg divide_ennreal [symmetric] + by (subst ennreal_pmf_bind) + (simp_all add: nn_integral_pmf_of_set max_def pmf_nonneg divide_ennreal [symmetric] setsum_nonneg ennreal_of_nat_eq_real_of_nat) thus ?thesis by (subst (asm) ennreal_inj) (auto intro!: setsum_nonneg divide_nonneg_nonneg) qed @@ -1675,10 +1675,10 @@ 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 - from the family uniformly at random and then choosing an element from the chosen set - uniformly at random. + 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 + from the family uniformly at random and then choosing an element from the chosen set + uniformly at random. \ lemma pmf_of_set_UN: assumes "finite (UNION A f)" "A \ {}" "\x. x \ A \ f x \ {}" @@ -1694,8 +1694,8 @@ by (subst pmf_of_set) auto also from assms have "card (\x\A. f x) = card A * n" by (subst card_UN_disjoint) (auto simp: disjoint_family_on_def) - also from assms - have "indicator (\x\A. f x) x / real \ = + also from assms + have "indicator (\x\A. f x) x / real \ = indicator (\x\A. f x) x / (n * real (card A))" by (simp add: setsum_divide_distrib [symmetric] mult_ac) also from assms have "indicator (\x\A. f x) x = (\y\A. indicator (f y) x)" @@ -1794,17 +1794,17 @@ lemma replicate_pmf_1: "replicate_pmf 1 p = map_pmf (\x. [x]) p" by (simp add: map_pmf_def bind_return_pmf) - -lemma set_replicate_pmf: + +lemma set_replicate_pmf: "set_pmf (replicate_pmf n p) = {xs\lists (set_pmf p). length xs = n}" by (induction n) (auto simp: length_Suc_conv) lemma replicate_pmf_distrib: - "replicate_pmf (m + n) p = + "replicate_pmf (m + n) p = do {xs \ replicate_pmf m p; ys \ replicate_pmf n p; return_pmf (xs @ ys)}" by (induction m) (simp_all add: bind_return_pmf bind_return_pmf' bind_assoc_pmf) -lemma power_diff': +lemma power_diff': assumes "b \ a" shows "x ^ (a - b) = (if x = 0 \ a = b then 1 else x ^ a / (x::'a::field) ^ b)" proof (cases "x = 0") @@ -1812,12 +1812,12 @@ with assms show ?thesis by (cases "a - b") simp_all qed (insert assms, simp_all add: power_diff) - + lemma binomial_pmf_Suc: assumes "p \ {0..1}" - shows "binomial_pmf (Suc n) p = - do {b \ bernoulli_pmf p; - k \ binomial_pmf n p; + shows "binomial_pmf (Suc n) p = + do {b \ bernoulli_pmf p; + k \ binomial_pmf n p; return_pmf ((if b then 1 else 0) + k)}" (is "_ = ?rhs") proof (intro pmf_eqI) fix k @@ -1835,14 +1835,14 @@ lemma binomial_pmf_altdef: assumes "p \ {0..1}" shows "binomial_pmf n p = map_pmf (length \ filter id) (replicate_pmf n (bernoulli_pmf p))" - by (induction n) - (insert assms, auto simp: binomial_pmf_Suc map_pmf_def bind_return_pmf bind_assoc_pmf + by (induction n) + (insert assms, auto simp: binomial_pmf_Suc map_pmf_def bind_return_pmf bind_assoc_pmf bind_return_pmf' binomial_pmf_0 intro!: bind_pmf_cong) subsection \PMFs from assiciation lists\ -definition pmf_of_list ::" ('a \ real) list \ 'a pmf" where +definition pmf_of_list ::" ('a \ real) list \ 'a pmf" where "pmf_of_list xs = embed_pmf (\x. sum_list (map snd (filter (\z. fst z = x) xs)))" definition pmf_of_list_wf where @@ -1870,12 +1870,12 @@ from Cons.prems have "snd x \ 0" by simp moreover have "b \ 0" if "(a,b) \ set xs" for a b using Cons.prems[of b] that by force - ultimately have "(\\<^sup>+ y. ennreal (\(x', p)\x # xs. indicator {x'} y * p) \count_space UNIV) = - (\\<^sup>+ y. ennreal (indicator {fst x} y * snd x) + + ultimately have "(\\<^sup>+ y. ennreal (\(x', p)\x # xs. indicator {x'} y * p) \count_space UNIV) = + (\\<^sup>+ y. ennreal (indicator {fst x} y * snd x) + ennreal (\(x', p)\xs. indicator {x'} y * p) \count_space UNIV)" - by (intro nn_integral_cong, subst ennreal_plus [symmetric]) + by (intro nn_integral_cong, subst ennreal_plus [symmetric]) (auto simp: case_prod_unfold indicator_def intro!: sum_list_nonneg) - also have "\ = (\\<^sup>+ y. ennreal (indicator {fst x} y * snd x) \count_space UNIV) + + also have "\ = (\\<^sup>+ y. ennreal (indicator {fst x} y * snd x) \count_space UNIV) + (\\<^sup>+ y. ennreal (\(x', p)\xs. indicator {x'} y * p) \count_space UNIV)" by (intro nn_integral_add) (force intro!: sum_list_nonneg AE_I2 intro: Cons simp: indicator_def)+ @@ -1934,20 +1934,20 @@ proof - have "emeasure (pmf_of_list xs) A = nn_integral (measure_pmf (pmf_of_list xs)) (indicator A)" by simp - also from assms + also from assms have "\ = (\x\set_pmf (pmf_of_list xs) \ A. ennreal (sum_list (map snd [z\xs . fst z = x])))" by (subst nn_integral_measure_pmf_finite) (simp_all add: finite_set_pmf_of_list pmf_pmf_of_list) - also from assms + also from assms have "\ = ennreal (\x\set_pmf (pmf_of_list xs) \ A. sum_list (map snd [z\xs . fst z = x]))" by (subst setsum_ennreal) (auto simp: pmf_of_list_wf_def intro!: sum_list_nonneg) - also have "\ = ennreal (\x\set_pmf (pmf_of_list xs) \ A. + also have "\ = ennreal (\x\set_pmf (pmf_of_list xs) \ A. indicator A x * pmf (pmf_of_list xs) x)" (is "_ = ennreal ?S") using assms by (intro ennreal_cong setsum.cong) (auto simp: pmf_pmf_of_list) also have "?S = (\x\set_pmf (pmf_of_list xs). indicator A x * pmf (pmf_of_list xs) x)" using assms by (intro setsum.mono_neutral_left set_pmf_of_list finite_set_pmf_of_list) auto also have "\ = (\x\set (map fst xs). indicator A x * pmf (pmf_of_list xs) x)" using assms by (intro setsum.mono_neutral_left set_pmf_of_list) (auto simp: set_pmf_eq) - also have "\ = (\x\set (map fst xs). indicator A x * + also have "\ = (\x\set (map fst xs). indicator A x * sum_list (map snd (filter (\z. fst z = x) xs)))" using assms by (simp add: pmf_pmf_of_list) also have "\ = (\x\set (map fst xs). sum_list (map snd (filter (\z. fst z = x \ x \ A) xs)))" @@ -1955,17 +1955,17 @@ also have "\ = (\x\set (map fst xs). (\xa = 0.. x \ A then snd (xs ! xa) else 0))" by (intro setsum.cong refl, subst sum_list_map_filter', subst sum_list_setsum_nth) simp - also have "\ = (\xa = 0..x\set (map fst xs). + also have "\ = (\xa = 0..x\set (map fst xs). if fst (xs ! xa) = x \ x \ A then snd (xs ! xa) else 0))" by (rule setsum.commute) - also have "\ = (\xa = 0.. A then + also have "\ = (\xa = 0.. A then (\x\set (map fst xs). if x = fst (xs ! xa) then snd (xs ! xa) else 0) else 0)" by (auto intro!: setsum.cong setsum.neutral) also have "\ = (\xa = 0.. A then snd (xs ! xa) else 0)" by (intro setsum.cong refl) (simp_all add: setsum.delta) also have "\ = sum_list (map snd (filter (\x. fst x \ A) xs))" by (subst sum_list_map_filter', subst sum_list_setsum_nth) simp_all - finally show ?thesis . + finally show ?thesis . qed lemma measure_pmf_of_list: @@ -1989,7 +1989,7 @@ "sum_list (filter (\x. x \ 0) xs) = sum_list xs" by (induction xs) simp_all (* END MOVE *) - + lemma set_pmf_of_list_eq: assumes "pmf_of_list_wf xs" "\x. x \ snd ` set xs \ x > 0" shows "set_pmf (pmf_of_list xs) = fst ` set xs" @@ -2000,13 +2000,13 @@ from B have "sum_list (map snd [z\xs. fst z = x]) = 0" by (simp add: pmf_pmf_of_list[OF assms(1)] set_pmf_eq) moreover from y have "y \ snd ` {xa \ set xs. fst xa = x}" by force - ultimately have "y = 0" using assms(1) + ultimately have "y = 0" using assms(1) by (subst (asm) sum_list_nonneg_eq_zero_iff) (auto simp: pmf_of_list_wf_def) with assms(2) y have False by force } thus "fst ` set xs \ set_pmf (pmf_of_list xs)" by blast qed (insert set_pmf_of_list[OF assms(1)], simp_all) - + lemma pmf_of_list_remove_zeros: assumes "pmf_of_list_wf xs" defines "xs' \ filter (\z. snd z \ 0) xs"