src/HOL/Probability/Probability_Measure.thy
changeset 56996 891e992e510f
parent 56994 8d5e5ec1cac3
child 57025 e7fd64f82876
equal deleted inserted replaced
56995:61855ade6c7e 56996:891e992e510f
   288     by (rule emeasure_UN_countable)
   288     by (rule emeasure_UN_countable)
   289        (auto intro!: sets.sets_Collect_countable_Ex' sets.sets_Collect_conj sets.sets_Collect_countable_Ex1' I sets
   289        (auto intro!: sets.sets_Collect_countable_Ex' sets.sets_Collect_conj sets.sets_Collect_countable_Ex1' I sets
   290              simp: disjoint_family_on_def)
   290              simp: disjoint_family_on_def)
   291   also have "\<dots> = (\<integral>\<^sup>+i. \<P>(x in M. P i x) \<partial>count_space I)"
   291   also have "\<dots> = (\<integral>\<^sup>+i. \<P>(x in M. P i x) \<partial>count_space I)"
   292     unfolding emeasure_eq_measure using disj
   292     unfolding emeasure_eq_measure using disj
   293     by (intro positive_integral_cong ereal.inject[THEN iffD2] prob_eq_AE)
   293     by (intro nn_integral_cong ereal.inject[THEN iffD2] prob_eq_AE)
   294        (auto intro!: sets.sets_Collect_countable_Ex' sets.sets_Collect_conj sets.sets_Collect_countable_Ex1' I sets)+
   294        (auto intro!: sets.sets_Collect_countable_Ex' sets.sets_Collect_conj sets.sets_Collect_countable_Ex1' I sets)+
   295   finally show ?thesis .
   295   finally show ?thesis .
   296 qed
   296 qed
   297 
   297 
   298 lemma (in prob_space) cond_prob_eq_AE:
   298 lemma (in prob_space) cond_prob_eq_AE:
   400   have "emeasure M (X -` {a} \<inter> space M) = emeasure (distr M (count_space A) X) {a}"
   400   have "emeasure M (X -` {a} \<inter> space M) = emeasure (distr M (count_space A) X) {a}"
   401     using X a A by (simp add: emeasure_distr)
   401     using X a A by (simp add: emeasure_distr)
   402   also have "\<dots> = emeasure (density (count_space A) P) {a}"
   402   also have "\<dots> = emeasure (density (count_space A) P) {a}"
   403     using X by (simp add: distributed_distr_eq_density)
   403     using X by (simp add: distributed_distr_eq_density)
   404   also have "\<dots> = (\<integral>\<^sup>+x. P a * indicator {a} x \<partial>count_space A)"
   404   also have "\<dots> = (\<integral>\<^sup>+x. P a * indicator {a} x \<partial>count_space A)"
   405     using X a by (auto simp add: emeasure_density distributed_def indicator_def intro!: positive_integral_cong)
   405     using X a by (auto simp add: emeasure_density distributed_def indicator_def intro!: nn_integral_cong)
   406   also have "\<dots> = P a"
   406   also have "\<dots> = P a"
   407     using X a by (subst positive_integral_cmult_indicator) (auto simp: distributed_def one_ereal_def[symmetric] AE_count_space)
   407     using X a by (subst nn_integral_cmult_indicator) (auto simp: distributed_def one_ereal_def[symmetric] AE_count_space)
   408   finally show ?thesis ..
   408   finally show ?thesis ..
   409 qed
   409 qed
   410 
   410 
   411 lemma distributed_cong_density:
   411 lemma distributed_cong_density:
   412   "(AE x in N. f x = g x) \<Longrightarrow> g \<in> borel_measurable N \<Longrightarrow> f \<in> borel_measurable N \<Longrightarrow>
   412   "(AE x in N. f x = g x) \<Longrightarrow> g \<in> borel_measurable N \<Longrightarrow> f \<in> borel_measurable N \<Longrightarrow>
   444 lemma distributed_emeasure:
   444 lemma distributed_emeasure:
   445   "distributed M N X f \<Longrightarrow> A \<in> sets N \<Longrightarrow> emeasure M (X -` A \<inter> space M) = (\<integral>\<^sup>+x. f x * indicator A x \<partial>N)"
   445   "distributed M N X f \<Longrightarrow> A \<in> sets N \<Longrightarrow> emeasure M (X -` A \<inter> space M) = (\<integral>\<^sup>+x. f x * indicator A x \<partial>N)"
   446   by (auto simp: distributed_AE
   446   by (auto simp: distributed_AE
   447                  distributed_distr_eq_density[symmetric] emeasure_density[symmetric] emeasure_distr)
   447                  distributed_distr_eq_density[symmetric] emeasure_density[symmetric] emeasure_distr)
   448 
   448 
   449 lemma distributed_positive_integral:
   449 lemma distributed_nn_integral:
   450   "distributed M N X f \<Longrightarrow> g \<in> borel_measurable N \<Longrightarrow> (\<integral>\<^sup>+x. f x * g x \<partial>N) = (\<integral>\<^sup>+x. g (X x) \<partial>M)"
   450   "distributed M N X f \<Longrightarrow> g \<in> borel_measurable N \<Longrightarrow> (\<integral>\<^sup>+x. f x * g x \<partial>N) = (\<integral>\<^sup>+x. g (X x) \<partial>M)"
   451   by (auto simp: distributed_AE
   451   by (auto simp: distributed_AE
   452                  distributed_distr_eq_density[symmetric] positive_integral_density[symmetric] positive_integral_distr)
   452                  distributed_distr_eq_density[symmetric] nn_integral_density[symmetric] nn_integral_distr)
   453 
   453 
   454 lemma distributed_integral:
   454 lemma distributed_integral:
   455   "distributed M N X f \<Longrightarrow> g \<in> borel_measurable N \<Longrightarrow> (\<integral>x. f x * g x \<partial>N) = (\<integral>x. g (X x) \<partial>M)"
   455   "distributed M N X f \<Longrightarrow> g \<in> borel_measurable N \<Longrightarrow> (\<integral>x. f x * g x \<partial>N) = (\<integral>x. g (X x) \<partial>M)"
   456   by (auto simp: distributed_real_AE
   456   by (auto simp: distributed_real_AE
   457                  distributed_distr_eq_density[symmetric] integral_real_density[symmetric] integral_distr)
   457                  distributed_distr_eq_density[symmetric] integral_real_density[symmetric] integral_distr)
   518     then obtain A B where E[simp]: "E = A \<times> B"
   518     then obtain A B where E[simp]: "E = A \<times> B"
   519       and A[measurable]: "A \<in> sets S" and B[measurable]: "B \<in> sets T" by auto
   519       and A[measurable]: "A \<in> sets S" and B[measurable]: "B \<in> sets T" by auto
   520     have "emeasure ?L E = emeasure M {x \<in> space M. X x \<in> A \<and> Y x \<in> B}"
   520     have "emeasure ?L E = emeasure M {x \<in> space M. X x \<in> A \<and> Y x \<in> B}"
   521       by (auto intro!: arg_cong[where f="emeasure M"] simp add: emeasure_distr measurable_Pair)
   521       by (auto intro!: arg_cong[where f="emeasure M"] simp add: emeasure_distr measurable_Pair)
   522     also have "\<dots> = (\<integral>\<^sup>+x. (\<integral>\<^sup>+y. (f (x, y) * indicator B y) * indicator A x \<partial>T) \<partial>S)"
   522     also have "\<dots> = (\<integral>\<^sup>+x. (\<integral>\<^sup>+y. (f (x, y) * indicator B y) * indicator A x \<partial>T) \<partial>S)"
   523       using f by (auto simp add: eq positive_integral_multc intro!: positive_integral_cong)
   523       using f by (auto simp add: eq nn_integral_multc intro!: nn_integral_cong)
   524     also have "\<dots> = emeasure ?R E"
   524     also have "\<dots> = emeasure ?R E"
   525       by (auto simp add: emeasure_density T.positive_integral_fst[symmetric]
   525       by (auto simp add: emeasure_density T.nn_integral_fst[symmetric]
   526                intro!: positive_integral_cong split: split_indicator)
   526                intro!: nn_integral_cong split: split_indicator)
   527     finally show "emeasure ?L E = emeasure ?R E" .
   527     finally show "emeasure ?L E = emeasure ?R E" .
   528   qed
   528   qed
   529 qed (auto simp: f)
   529 qed (auto simp: f)
   530 
   530 
   531 lemma (in prob_space) distributed_swap:
   531 lemma (in prob_space) distributed_swap:
   562         by (auto intro!: arg_cong2[where f=emeasure] simp: space_pair_measure)
   562         by (auto intro!: arg_cong2[where f=emeasure] simp: space_pair_measure)
   563       also have "\<dots> = (\<integral>\<^sup>+ x. Pxy x * indicator ?B x \<partial>(S \<Otimes>\<^sub>M T))"
   563       also have "\<dots> = (\<integral>\<^sup>+ x. Pxy x * indicator ?B x \<partial>(S \<Otimes>\<^sub>M T))"
   564         using Pxy A by (intro distributed_emeasure) auto
   564         using Pxy A by (intro distributed_emeasure) auto
   565       finally have "emeasure M ((\<lambda>x. (Y x, X x)) -` A \<inter> space M) =
   565       finally have "emeasure M ((\<lambda>x. (Y x, X x)) -` A \<inter> space M) =
   566         (\<integral>\<^sup>+ x. Pxy x * indicator A (snd x, fst x) \<partial>(S \<Otimes>\<^sub>M T))"
   566         (\<integral>\<^sup>+ x. Pxy x * indicator A (snd x, fst x) \<partial>(S \<Otimes>\<^sub>M T))"
   567         by (auto intro!: positive_integral_cong split: split_indicator) }
   567         by (auto intro!: nn_integral_cong split: split_indicator) }
   568     note * = this
   568     note * = this
   569     show "distr M ?D (\<lambda>x. (Y x, X x)) = density ?D (\<lambda>(x, y). Pxy (y, x))"
   569     show "distr M ?D (\<lambda>x. (Y x, X x)) = density ?D (\<lambda>(x, y). Pxy (y, x))"
   570       apply (intro measure_eqI)
   570       apply (intro measure_eqI)
   571       apply (simp_all add: emeasure_distr[OF 2] emeasure_density[OF 1])
   571       apply (simp_all add: emeasure_distr[OF 2] emeasure_density[OF 1])
   572       apply (subst positive_integral_distr)
   572       apply (subst nn_integral_distr)
   573       apply (auto intro!: * simp: comp_def split_beta)
   573       apply (auto intro!: * simp: comp_def split_beta)
   574       done
   574       done
   575   qed
   575   qed
   576 qed
   576 qed
   577 
   577 
   588 
   588 
   589   note Pxy[measurable]
   589   note Pxy[measurable]
   590   show X: "X \<in> measurable M S" by simp
   590   show X: "X \<in> measurable M S" by simp
   591 
   591 
   592   show borel: "Px \<in> borel_measurable S"
   592   show borel: "Px \<in> borel_measurable S"
   593     by (auto intro!: T.positive_integral_fst simp: Px_def)
   593     by (auto intro!: T.nn_integral_fst simp: Px_def)
   594 
   594 
   595   interpret Pxy: prob_space "distr M (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x))"
   595   interpret Pxy: prob_space "distr M (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x))"
   596     by (intro prob_space_distr) simp
   596     by (intro prob_space_distr) simp
   597   have "(\<integral>\<^sup>+ x. max 0 (- Pxy x) \<partial>(S \<Otimes>\<^sub>M T)) = (\<integral>\<^sup>+ x. 0 \<partial>(S \<Otimes>\<^sub>M T))"
   597   have "(\<integral>\<^sup>+ x. max 0 (- Pxy x) \<partial>(S \<Otimes>\<^sub>M T)) = (\<integral>\<^sup>+ x. 0 \<partial>(S \<Otimes>\<^sub>M T))"
   598     using Pxy
   598     using Pxy
   599     by (intro positive_integral_cong_AE) (auto simp: max_def dest: distributed_AE)
   599     by (intro nn_integral_cong_AE) (auto simp: max_def dest: distributed_AE)
   600 
   600 
   601   show "distr M S X = density S Px"
   601   show "distr M S X = density S Px"
   602   proof (rule measure_eqI)
   602   proof (rule measure_eqI)
   603     fix A assume A: "A \<in> sets (distr M S X)"
   603     fix A assume A: "A \<in> sets (distr M S X)"
   604     with X measurable_space[of Y M T]
   604     with X measurable_space[of Y M T]
   606       by (auto simp add: emeasure_distr intro!: arg_cong[where f="emeasure M"])
   606       by (auto simp add: emeasure_distr intro!: arg_cong[where f="emeasure M"])
   607     also have "\<dots> = emeasure (density (S \<Otimes>\<^sub>M T) Pxy) (A \<times> space T)"
   607     also have "\<dots> = emeasure (density (S \<Otimes>\<^sub>M T) Pxy) (A \<times> space T)"
   608       using Pxy by (simp add: distributed_def)
   608       using Pxy by (simp add: distributed_def)
   609     also have "\<dots> = \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. Pxy (x, y) * indicator (A \<times> space T) (x, y) \<partial>T \<partial>S"
   609     also have "\<dots> = \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. Pxy (x, y) * indicator (A \<times> space T) (x, y) \<partial>T \<partial>S"
   610       using A borel Pxy
   610       using A borel Pxy
   611       by (simp add: emeasure_density T.positive_integral_fst[symmetric])
   611       by (simp add: emeasure_density T.nn_integral_fst[symmetric])
   612     also have "\<dots> = \<integral>\<^sup>+ x. Px x * indicator A x \<partial>S"
   612     also have "\<dots> = \<integral>\<^sup>+ x. Px x * indicator A x \<partial>S"
   613       apply (rule positive_integral_cong_AE)
   613       apply (rule nn_integral_cong_AE)
   614       using Pxy[THEN distributed_AE, THEN ST.AE_pair] AE_space
   614       using Pxy[THEN distributed_AE, THEN ST.AE_pair] AE_space
   615     proof eventually_elim
   615     proof eventually_elim
   616       fix x assume "x \<in> space S" "AE y in T. 0 \<le> Pxy (x, y)"
   616       fix x assume "x \<in> space S" "AE y in T. 0 \<le> Pxy (x, y)"
   617       moreover have eq: "\<And>y. y \<in> space T \<Longrightarrow> indicator (A \<times> space T) (x, y) = indicator A x"
   617       moreover have eq: "\<And>y. y \<in> space T \<Longrightarrow> indicator (A \<times> space T) (x, y) = indicator A x"
   618         by (auto simp: indicator_def)
   618         by (auto simp: indicator_def)
   619       ultimately have "(\<integral>\<^sup>+ y. Pxy (x, y) * indicator (A \<times> space T) (x, y) \<partial>T) = (\<integral>\<^sup>+ y. Pxy (x, y) \<partial>T) * indicator A x"
   619       ultimately have "(\<integral>\<^sup>+ y. Pxy (x, y) * indicator (A \<times> space T) (x, y) \<partial>T) = (\<integral>\<^sup>+ y. Pxy (x, y) \<partial>T) * indicator A x"
   620         by (simp add: eq positive_integral_multc cong: positive_integral_cong)
   620         by (simp add: eq nn_integral_multc cong: nn_integral_cong)
   621       also have "(\<integral>\<^sup>+ y. Pxy (x, y) \<partial>T) = Px x"
   621       also have "(\<integral>\<^sup>+ y. Pxy (x, y) \<partial>T) = Px x"
   622         by (simp add: Px_def ereal_real positive_integral_positive)
   622         by (simp add: Px_def ereal_real nn_integral_nonneg)
   623       finally show "(\<integral>\<^sup>+ y. Pxy (x, y) * indicator (A \<times> space T) (x, y) \<partial>T) = Px x * indicator A x" .
   623       finally show "(\<integral>\<^sup>+ y. Pxy (x, y) * indicator (A \<times> space T) (x, y) \<partial>T) = Px x * indicator A x" .
   624     qed
   624     qed
   625     finally show "emeasure (distr M S X) A = emeasure (density S Px) A"
   625     finally show "emeasure (distr M S X) A = emeasure (density S Px) A"
   626       using A borel Pxy by (simp add: emeasure_density)
   626       using A borel Pxy by (simp add: emeasure_density)
   627   qed simp
   627   qed simp
   628   
   628   
   629   show "AE x in S. 0 \<le> Px x"
   629   show "AE x in S. 0 \<le> Px x"
   630     by (simp add: Px_def positive_integral_positive real_of_ereal_pos)
   630     by (simp add: Px_def nn_integral_nonneg real_of_ereal_pos)
   631 qed
   631 qed
   632 
   632 
   633 lemma (in prob_space) distr_marginal2:
   633 lemma (in prob_space) distr_marginal2:
   634   assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
   634   assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
   635   assumes Pxy: "distributed M (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x)) Pxy"
   635   assumes Pxy: "distributed M (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x)) Pxy"
   725       by (subst emeasure_distr)
   725       by (subst emeasure_distr)
   726          (auto simp add: S_def P'_def simple_functionD emeasure_eq_measure measurable_count_space_eq2
   726          (auto simp add: S_def P'_def simple_functionD emeasure_eq_measure measurable_count_space_eq2
   727                intro!: arg_cong[where f=prob])
   727                intro!: arg_cong[where f=prob])
   728     also have "\<dots> = (\<integral>\<^sup>+x. ereal (P' a) * indicator {a} x \<partial>S)"
   728     also have "\<dots> = (\<integral>\<^sup>+x. ereal (P' a) * indicator {a} x \<partial>S)"
   729       using A X a
   729       using A X a
   730       by (subst positive_integral_cmult_indicator)
   730       by (subst nn_integral_cmult_indicator)
   731          (auto simp: S_def P'_def simple_distributed_def simple_functionD measure_nonneg)
   731          (auto simp: S_def P'_def simple_distributed_def simple_functionD measure_nonneg)
   732     also have "\<dots> = (\<integral>\<^sup>+x. ereal (P' x) * indicator {a} x \<partial>S)"
   732     also have "\<dots> = (\<integral>\<^sup>+x. ereal (P' x) * indicator {a} x \<partial>S)"
   733       by (auto simp: indicator_def intro!: positive_integral_cong)
   733       by (auto simp: indicator_def intro!: nn_integral_cong)
   734     also have "\<dots> = emeasure (density S P') {a}"
   734     also have "\<dots> = emeasure (density S P') {a}"
   735       using a A by (intro emeasure_density[symmetric]) (auto simp: S_def)
   735       using a A by (intro emeasure_density[symmetric]) (auto simp: S_def)
   736     finally show "emeasure (distr M S X) {a} = emeasure (density S P') {a}" .
   736     finally show "emeasure (distr M S X) {a} = emeasure (density S P') {a}" .
   737   qed
   737   qed
   738   show "random_variable S X"
   738   show "random_variable S X"
   864     Px[THEN simple_distributed_finite]
   864     Px[THEN simple_distributed_finite]
   865     Py[THEN simple_distributed_finite]
   865     Py[THEN simple_distributed_finite]
   866     Pxy[THEN simple_distributed, THEN distributed_real_AE]
   866     Pxy[THEN simple_distributed, THEN distributed_real_AE]
   867   show ?thesis
   867   show ?thesis
   868     unfolding AE_count_space
   868     unfolding AE_count_space
   869     apply (auto simp add: positive_integral_count_space_finite * intro!: setsum_cong split: split_max)
   869     apply (auto simp add: nn_integral_count_space_finite * intro!: setsum_cong split: split_max)
   870     done
   870     done
   871 qed
   871 qed
   872 
   872 
   873 lemma distributedI_real:
   873 lemma distributedI_real:
   874   fixes f :: "'a \<Rightarrow> real"
   874   fixes f :: "'a \<Rightarrow> real"