9 imports |
9 imports |
10 Giry_Monad |
10 Giry_Monad |
11 "~~/src/HOL/Number_Theory/Binomial" |
11 "~~/src/HOL/Number_Theory/Binomial" |
12 "~~/src/HOL/Library/Multiset" |
12 "~~/src/HOL/Library/Multiset" |
13 begin |
13 begin |
14 |
|
15 lemma bind_return'': "sets M = sets N \<Longrightarrow> M \<guillemotright>= return N = M" |
|
16 by (cases "space M = {}") |
|
17 (simp_all add: bind_empty space_empty[symmetric] bind_nonempty join_return' |
|
18 cong: subprob_algebra_cong) |
|
19 |
|
20 |
|
21 lemma (in prob_space) distr_const[simp]: |
|
22 "c \<in> space N \<Longrightarrow> distr M N (\<lambda>x. c) = return N c" |
|
23 by (rule measure_eqI) (auto simp: emeasure_distr emeasure_space_1) |
|
24 |
14 |
25 lemma (in finite_measure) countable_support: |
15 lemma (in finite_measure) countable_support: |
26 "countable {x. measure M {x} \<noteq> 0}" |
16 "countable {x. measure M {x} \<noteq> 0}" |
27 proof cases |
17 proof cases |
28 assume "measure M (space M) = 0" |
18 assume "measure M (space M) = 0" |
212 |
202 |
213 lemma emeasure_measure_pmf_finite: "finite S \<Longrightarrow> emeasure (measure_pmf M) S = (\<Sum>s\<in>S. pmf M s)" |
203 lemma emeasure_measure_pmf_finite: "finite S \<Longrightarrow> emeasure (measure_pmf M) S = (\<Sum>s\<in>S. pmf M s)" |
214 by (subst emeasure_eq_setsum_singleton) (auto simp: emeasure_pmf_single) |
204 by (subst emeasure_eq_setsum_singleton) (auto simp: emeasure_pmf_single) |
215 |
205 |
216 lemma measure_measure_pmf_finite: "finite S \<Longrightarrow> measure (measure_pmf M) S = setsum (pmf M) S" |
206 lemma measure_measure_pmf_finite: "finite S \<Longrightarrow> measure (measure_pmf M) S = setsum (pmf M) S" |
217 using emeasure_measure_pmf_finite[of S M] |
207 using emeasure_measure_pmf_finite[of S M] by(simp add: measure_pmf.emeasure_eq_measure) |
218 by(simp add: measure_pmf.emeasure_eq_measure) |
|
219 |
208 |
220 lemma nn_integral_measure_pmf_support: |
209 lemma nn_integral_measure_pmf_support: |
221 fixes f :: "'a \<Rightarrow> ereal" |
210 fixes f :: "'a \<Rightarrow> ereal" |
222 assumes f: "finite A" and nn: "\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x" "\<And>x. x \<in> set_pmf M \<Longrightarrow> x \<notin> A \<Longrightarrow> f x = 0" |
211 assumes f: "finite A" and nn: "\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x" "\<And>x. x \<in> set_pmf M \<Longrightarrow> x \<notin> A \<Longrightarrow> f x = 0" |
223 shows "(\<integral>\<^sup>+x. f x \<partial>measure_pmf M) = (\<Sum>x\<in>A. f x * pmf M x)" |
212 shows "(\<integral>\<^sup>+x. f x \<partial>measure_pmf M) = (\<Sum>x\<in>A. f x * pmf M x)" |
757 apply (subst integral_nonneg_eq_0_iff_AE) |
746 apply (subst integral_nonneg_eq_0_iff_AE) |
758 apply (auto simp: pmf_nonneg pmf_le_1 AE_measure_pmf_iff |
747 apply (auto simp: pmf_nonneg pmf_le_1 AE_measure_pmf_iff |
759 intro!: measure_pmf.integrable_const_bound[where B=1]) |
748 intro!: measure_pmf.integrable_const_bound[where B=1]) |
760 done |
749 done |
761 |
750 |
|
751 |
762 lemma measurable_pair_restrict_pmf2: |
752 lemma measurable_pair_restrict_pmf2: |
763 assumes "countable A" |
753 assumes "countable A" |
764 assumes "\<And>y. y \<in> A \<Longrightarrow> (\<lambda>x. f (x, y)) \<in> measurable M L" |
754 assumes [measurable]: "\<And>y. y \<in> A \<Longrightarrow> (\<lambda>x. f (x, y)) \<in> measurable M L" |
765 shows "f \<in> measurable (M \<Otimes>\<^sub>M restrict_space (measure_pmf N) A) L" |
755 shows "f \<in> measurable (M \<Otimes>\<^sub>M restrict_space (measure_pmf N) A) L" (is "f \<in> measurable ?M _") |
766 apply (subst measurable_cong_sets) |
756 proof - |
767 apply (rule sets_pair_measure_cong sets_restrict_space_cong sets_measure_pmf_count_space refl)+ |
757 have [measurable_cong]: "sets (restrict_space (count_space UNIV) A) = sets (count_space A)" |
768 apply (simp_all add: restrict_count_space) |
758 by (simp add: restrict_count_space) |
769 apply (subst split_eta[symmetric]) |
759 |
770 unfolding measurable_split_conv |
760 show ?thesis |
771 apply (rule measurable_compose_countable'[OF _ measurable_snd `countable A`]) |
761 by (intro measurable_compose_countable'[where f="\<lambda>a b. f (fst b, a)" and g=snd and I=A, |
772 apply (rule measurable_compose[OF measurable_fst]) |
762 unfolded pair_collapse] assms) |
773 apply fact |
763 measurable |
774 done |
764 qed |
775 |
765 |
776 lemma measurable_pair_restrict_pmf1: |
766 lemma measurable_pair_restrict_pmf1: |
777 assumes "countable A" |
767 assumes "countable A" |
778 assumes "\<And>x. x \<in> A \<Longrightarrow> (\<lambda>y. f (x, y)) \<in> measurable N L" |
768 assumes [measurable]: "\<And>x. x \<in> A \<Longrightarrow> (\<lambda>y. f (x, y)) \<in> measurable N L" |
779 shows "f \<in> measurable (restrict_space (measure_pmf M) A \<Otimes>\<^sub>M N) L" |
769 shows "f \<in> measurable (restrict_space (measure_pmf M) A \<Otimes>\<^sub>M N) L" |
780 apply (subst measurable_cong_sets) |
770 proof - |
781 apply (rule sets_pair_measure_cong sets_restrict_space_cong sets_measure_pmf_count_space refl)+ |
771 have [measurable_cong]: "sets (restrict_space (count_space UNIV) A) = sets (count_space A)" |
782 apply (simp_all add: restrict_count_space) |
772 by (simp add: restrict_count_space) |
783 apply (subst split_eta[symmetric]) |
773 |
784 unfolding measurable_split_conv |
774 show ?thesis |
785 apply (rule measurable_compose_countable'[OF _ measurable_fst `countable A`]) |
775 by (intro measurable_compose_countable'[where f="\<lambda>a b. f (a, snd b)" and g=fst and I=A, |
786 apply (rule measurable_compose[OF measurable_snd]) |
776 unfolded pair_collapse] assms) |
787 apply fact |
777 measurable |
788 done |
778 qed |
789 |
779 |
790 lemma bind_commute_pmf: "bind_pmf A (\<lambda>x. bind_pmf B (C x)) = bind_pmf B (\<lambda>y. bind_pmf A (\<lambda>x. C x y))" |
780 lemma bind_commute_pmf: "bind_pmf A (\<lambda>x. bind_pmf B (C x)) = bind_pmf B (\<lambda>y. bind_pmf A (\<lambda>x. C x y))" |
791 unfolding pmf_eq_iff pmf_bind |
781 unfolding pmf_eq_iff pmf_bind |
792 proof |
782 proof |
793 fix i |
783 fix i |
990 for R p q |
980 for R p q |
991 where |
981 where |
992 "\<lbrakk> \<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> R x y; |
982 "\<lbrakk> \<And>x y. (x, y) \<in> set_pmf pq \<Longrightarrow> R x y; |
993 map_pmf fst pq = p; map_pmf snd pq = q \<rbrakk> |
983 map_pmf fst pq = p; map_pmf snd pq = q \<rbrakk> |
994 \<Longrightarrow> rel_pmf R p q" |
984 \<Longrightarrow> rel_pmf R p q" |
995 |
|
996 lemma nn_integral_count_space_eq: |
|
997 "(\<And>x. x \<in> A - B \<Longrightarrow> f x = 0) \<Longrightarrow> (\<And>x. x \<in> B - A \<Longrightarrow> f x = 0) \<Longrightarrow> |
|
998 (\<integral>\<^sup>+x. f x \<partial>count_space A) = (\<integral>\<^sup>+x. f x \<partial>count_space B)" |
|
999 by (auto simp: nn_integral_count_space_indicator intro!: nn_integral_cong split: split_indicator) |
|
1000 |
985 |
1001 bnf pmf: "'a pmf" map: map_pmf sets: set_pmf bd : "natLeq" rel: rel_pmf |
986 bnf pmf: "'a pmf" map: map_pmf sets: set_pmf bd : "natLeq" rel: rel_pmf |
1002 proof - |
987 proof - |
1003 show "map_pmf id = id" by (rule map_pmf_id) |
988 show "map_pmf id = id" by (rule map_pmf_id) |
1004 show "\<And>f g. map_pmf (f \<circ> g) = map_pmf f \<circ> map_pmf g" by (rule map_pmf_compose) |
989 show "\<And>f g. map_pmf (f \<circ> g) = map_pmf f \<circ> map_pmf g" by (rule map_pmf_compose) |