
hoelzl@42861: (*  Title:      HOL/Probability/Independent_Family.thy
hoelzl@42861:     Author:     Johannes Hölzl, TU München
hoelzl@42861: *)
hoelzl@42861: 
hoelzl@42861: header {* Independent families of events, event sets, and random variables *}
hoelzl@42861: 
hoelzl@42861: theory Independent_Family
hoelzl@42861:   imports Probability_Measure
hoelzl@42861: begin
hoelzl@42861: 
hoelzl@42861: definition (in prob_space)
hoelzl@42981:   "indep_events A I \<longleftrightarrow> (A`I \<subseteq> sets M) \<and>
hoelzl@42981:     (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j)))"
hoelzl@42861: 
hoelzl@42861: definition (in prob_space)
hoelzl@42981:   "indep_event A B \<longleftrightarrow> indep_events (bool_case A B) UNIV"
hoelzl@42861: 
hoelzl@42861: definition (in prob_space)
hoelzl@42981:   "indep_sets F I \<longleftrightarrow> (\<forall>i\<in>I. F i \<subseteq> sets M) \<and>
hoelzl@42981:     (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> (\<forall>A\<in>Pi J F. prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))))"
hoelzl@42981: 
hoelzl@42981: definition (in prob_space)
hoelzl@42981:   "indep_set A B \<longleftrightarrow> indep_sets (bool_case A B) UNIV"
hoelzl@42861: 
hoelzl@42861: definition (in prob_space)
hoelzl@42861:   "indep_rv M' X I \<longleftrightarrow>
hoelzl@42861:     (\<forall>i\<in>I. random_variable (M' i) (X i)) \<and>
hoelzl@42861:     indep_sets (\<lambda>i. sigma_sets (space M) { X i -` A \<inter> space M | A. A \<in> sets (M' i)}) I"
hoelzl@42861: 
hoelzl@42981: lemma (in prob_space) indep_sets_cong:
hoelzl@42981:   "I = J \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> F i = G i) \<Longrightarrow> indep_sets F I \<longleftrightarrow> indep_sets G J"
hoelzl@42981:   by (simp add: indep_sets_def, intro conj_cong all_cong imp_cong ball_cong) blast+
hoelzl@42981: 
hoelzl@42981: lemma (in prob_space) indep_events_finite_index_events:
hoelzl@42981:   "indep_events F I \<longleftrightarrow> (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_events F J)"
hoelzl@42981:   by (auto simp: indep_events_def)
hoelzl@42981: 
hoelzl@42861: lemma (in prob_space) indep_sets_finite_index_sets:
hoelzl@42861:   "indep_sets F I \<longleftrightarrow> (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_sets F J)"
hoelzl@42861: proof (intro iffI allI impI)
hoelzl@42861:   assume *: "\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_sets F J"
hoelzl@42861:   show "indep_sets F I" unfolding indep_sets_def
hoelzl@42861:   proof (intro conjI ballI allI impI)
hoelzl@42861:     fix i assume "i \<in> I"
hoelzl@42861:     with *[THEN spec, of "{i}"] show "F i \<subseteq> events"
hoelzl@42861:       by (auto simp: indep_sets_def)
hoelzl@42861:   qed (insert *, auto simp: indep_sets_def)
hoelzl@42861: qed (auto simp: indep_sets_def)
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_sets_mono_index:
hoelzl@42861:   "J \<subseteq> I \<Longrightarrow> indep_sets F I \<Longrightarrow> indep_sets F J"
hoelzl@42861:   unfolding indep_sets_def by auto
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_sets_mono_sets:
hoelzl@42861:   assumes indep: "indep_sets F I"
hoelzl@42861:   assumes mono: "\<And>i. i\<in>I \<Longrightarrow> G i \<subseteq> F i"
hoelzl@42861:   shows "indep_sets G I"
hoelzl@42861: proof -
hoelzl@42861:   have "(\<forall>i\<in>I. F i \<subseteq> events) \<Longrightarrow> (\<forall>i\<in>I. G i \<subseteq> events)"
hoelzl@42861:     using mono by auto
hoelzl@42861:   moreover have "\<And>A J. J \<subseteq> I \<Longrightarrow> A \<in> (\<Pi> j\<in>J. G j) \<Longrightarrow> A \<in> (\<Pi> j\<in>J. F j)"
hoelzl@42861:     using mono by (auto simp: Pi_iff)
hoelzl@42861:   ultimately show ?thesis
hoelzl@42861:     using indep by (auto simp: indep_sets_def)
hoelzl@42861: qed
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_setsI:
hoelzl@42861:   assumes "\<And>i. i \<in> I \<Longrightarrow> F i \<subseteq> events"
hoelzl@42861:     and "\<And>A J. J \<noteq> {} \<Longrightarrow> J \<subseteq> I \<Longrightarrow> finite J \<Longrightarrow> (\<forall>j\<in>J. A j \<in> F j) \<Longrightarrow> prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861:   shows "indep_sets F I"
hoelzl@42861:   using assms unfolding indep_sets_def by (auto simp: Pi_iff)
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_setsD:
hoelzl@42861:   assumes "indep_sets F I" and "J \<subseteq> I" "J \<noteq> {}" "finite J" "\<forall>j\<in>J. A j \<in> F j"
hoelzl@42861:   shows "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861:   using assms unfolding indep_sets_def by auto
hoelzl@42861: 
hoelzl@42861: lemma dynkin_systemI':
hoelzl@42861:   assumes 1: "\<And> A. A \<in> sets M \<Longrightarrow> A \<subseteq> space M"
hoelzl@42861:   assumes empty: "{} \<in> sets M"
hoelzl@42861:   assumes Diff: "\<And> A. A \<in> sets M \<Longrightarrow> space M - A \<in> sets M"
hoelzl@42861:   assumes 2: "\<And> A. disjoint_family A \<Longrightarrow> range A \<subseteq> sets M
hoelzl@42861:           \<Longrightarrow> (\<Union>i::nat. A i) \<in> sets M"
hoelzl@42861:   shows "dynkin_system M"
hoelzl@42861: proof -
hoelzl@42861:   from Diff[OF empty] have "space M \<in> sets M" by auto
hoelzl@42861:   from 1 this Diff 2 show ?thesis
hoelzl@42861:     by (intro dynkin_systemI) auto
hoelzl@42861: qed
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_sets_dynkin:
hoelzl@42861:   assumes indep: "indep_sets F I"
hoelzl@42861:   shows "indep_sets (\<lambda>i. sets (dynkin \<lparr> space = space M, sets = F i \<rparr>)) I"
hoelzl@42861:     (is "indep_sets ?F I")
hoelzl@42861: proof (subst indep_sets_finite_index_sets, intro allI impI ballI)
hoelzl@42861:   fix J assume "finite J" "J \<subseteq> I" "J \<noteq> {}"
hoelzl@42861:   with indep have "indep_sets F J"
hoelzl@42861:     by (subst (asm) indep_sets_finite_index_sets) auto
hoelzl@42861:   { fix J K assume "indep_sets F K"
hoelzl@42861:     let "?G S i" = "if i \<in> S then ?F i else F i"
hoelzl@42861:     assume "finite J" "J \<subseteq> K"
hoelzl@42861:     then have "indep_sets (?G J) K"
hoelzl@42861:     proof induct
hoelzl@42861:       case (insert j J)
hoelzl@42861:       moreover def G \<equiv> "?G J"
hoelzl@42861:       ultimately have G: "indep_sets G K" "\<And>i. i \<in> K \<Longrightarrow> G i \<subseteq> events" and "j \<in> K"
hoelzl@42861:         by (auto simp: indep_sets_def)
hoelzl@42861:       let ?D = "{E\<in>events. indep_sets (G(j := {E})) K }"
hoelzl@42861:       { fix X assume X: "X \<in> events"
hoelzl@42861:         assume indep: "\<And>J A. J \<noteq> {} \<Longrightarrow> J \<subseteq> K \<Longrightarrow> finite J \<Longrightarrow> j \<notin> J \<Longrightarrow> (\<forall>i\<in>J. A i \<in> G i)
hoelzl@42861:           \<Longrightarrow> prob ((\<Inter>i\<in>J. A i) \<inter> X) = prob X * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861:         have "indep_sets (G(j := {X})) K"
hoelzl@42861:         proof (rule indep_setsI)
hoelzl@42861:           fix i assume "i \<in> K" then show "(G(j:={X})) i \<subseteq> events"
hoelzl@42861:             using G X by auto
hoelzl@42861:         next
hoelzl@42861:           fix A J assume J: "J \<noteq> {}" "J \<subseteq> K" "finite J" "\<forall>i\<in>J. A i \<in> (G(j := {X})) i"
hoelzl@42861:           show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861:           proof cases
hoelzl@42861:             assume "j \<in> J"
hoelzl@42861:             with J have "A j = X" by auto
hoelzl@42861:             show ?thesis
hoelzl@42861:             proof cases
hoelzl@42861:               assume "J = {j}" then show ?thesis by simp
hoelzl@42861:             next
hoelzl@42861:               assume "J \<noteq> {j}"
hoelzl@42861:               have "prob (\<Inter>i\<in>J. A i) = prob ((\<Inter>i\<in>J-{j}. A i) \<inter> X)"
hoelzl@42861:                 using `j \<in> J` `A j = X` by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
hoelzl@42861:               also have "\<dots> = prob X * (\<Prod>i\<in>J-{j}. prob (A i))"
hoelzl@42861:               proof (rule indep)
hoelzl@42861:                 show "J - {j} \<noteq> {}" "J - {j} \<subseteq> K" "finite (J - {j})" "j \<notin> J - {j}"
hoelzl@42861:                   using J `J \<noteq> {j}` `j \<in> J` by auto
hoelzl@42861:                 show "\<forall>i\<in>J - {j}. A i \<in> G i"
hoelzl@42861:                   using J by auto
hoelzl@42861:               qed
hoelzl@42861:               also have "\<dots> = prob (A j) * (\<Prod>i\<in>J-{j}. prob (A i))"
hoelzl@42861:                 using `A j = X` by simp
hoelzl@42861:               also have "\<dots> = (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861:                 unfolding setprod.insert_remove[OF `finite J`, symmetric, of "\<lambda>i. prob  (A i)"]
hoelzl@42861:                 using `j \<in> J` by (simp add: insert_absorb)
hoelzl@42861:               finally show ?thesis .
hoelzl@42861:             qed
hoelzl@42861:           next
hoelzl@42861:             assume "j \<notin> J"
hoelzl@42861:             with J have "\<forall>i\<in>J. A i \<in> G i" by (auto split: split_if_asm)
hoelzl@42861:             with J show ?thesis
hoelzl@42861:               by (intro indep_setsD[OF G(1)]) auto
hoelzl@42861:           qed
hoelzl@42861:         qed }
hoelzl@42861:       note indep_sets_insert = this
hoelzl@42861:       have "dynkin_system \<lparr> space = space M, sets = ?D \<rparr>"
hoelzl@42861:       proof (rule dynkin_systemI', simp_all, safe)
hoelzl@42861:         show "indep_sets (G(j := {{}})) K"
hoelzl@42861:           by (rule indep_sets_insert) auto
hoelzl@42861:       next
hoelzl@42861:         fix X assume X: "X \<in> events" and G': "indep_sets (G(j := {X})) K"
hoelzl@42861:         show "indep_sets (G(j := {space M - X})) K"
hoelzl@42861:         proof (rule indep_sets_insert)
hoelzl@42861:           fix J A assume J: "J \<noteq> {}" "J \<subseteq> K" "finite J" "j \<notin> J" and A: "\<forall>i\<in>J. A i \<in> G i"
hoelzl@42861:           then have A_sets: "\<And>i. i\<in>J \<Longrightarrow> A i \<in> events"
hoelzl@42861:             using G by auto
hoelzl@42861:           have "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) =
hoelzl@42861:               prob ((\<Inter>j\<in>J. A j) - (\<Inter>i\<in>insert j J. (A(j := X)) i))"
hoelzl@42861:             using A_sets sets_into_space X `J \<noteq> {}`
hoelzl@42861:             by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
hoelzl@42861:           also have "\<dots> = prob (\<Inter>j\<in>J. A j) - prob (\<Inter>i\<in>insert j J. (A(j := X)) i)"
hoelzl@42861:             using J `J \<noteq> {}` `j \<notin> J` A_sets X sets_into_space
hoelzl@42861:             by (auto intro!: finite_measure_Diff finite_INT split: split_if_asm)
hoelzl@42861:           finally have "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) =
hoelzl@42861:               prob (\<Inter>j\<in>J. A j) - prob (\<Inter>i\<in>insert j J. (A(j := X)) i)" .
hoelzl@42861:           moreover {
hoelzl@42861:             have "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861:               using J A `finite J` by (intro indep_setsD[OF G(1)]) auto
hoelzl@42861:             then have "prob (\<Inter>j\<in>J. A j) = prob (space M) * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861:               using prob_space by simp }
hoelzl@42861:           moreover {
hoelzl@42861:             have "prob (\<Inter>i\<in>insert j J. (A(j := X)) i) = (\<Prod>i\<in>insert j J. prob ((A(j := X)) i))"
hoelzl@42861:               using J A `j \<in> K` by (intro indep_setsD[OF G']) auto
hoelzl@42861:             then have "prob (\<Inter>i\<in>insert j J. (A(j := X)) i) = prob X * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861:               using `finite J` `j \<notin> J` by (auto intro!: setprod_cong) }
hoelzl@42861:           ultimately have "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) = (prob (space M) - prob X) * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861:             by (simp add: field_simps)
hoelzl@42861:           also have "\<dots> = prob (space M - X) * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861:             using X A by (simp add: finite_measure_compl)
hoelzl@42861:           finally show "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) = prob (space M - X) * (\<Prod>i\<in>J. prob (A i))" .
hoelzl@42861:         qed (insert X, auto)
hoelzl@42861:       next
hoelzl@42861:         fix F :: "nat \<Rightarrow> 'a set" assume disj: "disjoint_family F" and "range F \<subseteq> ?D"
hoelzl@42861:         then have F: "\<And>i. F i \<in> events" "\<And>i. indep_sets (G(j:={F i})) K" by auto
hoelzl@42861:         show "indep_sets (G(j := {\<Union>k. F k})) K"
hoelzl@42861:         proof (rule indep_sets_insert)
hoelzl@42861:           fix J A assume J: "j \<notin> J" "J \<noteq> {}" "J \<subseteq> K" "finite J" and A: "\<forall>i\<in>J. A i \<in> G i"
hoelzl@42861:           then have A_sets: "\<And>i. i\<in>J \<Longrightarrow> A i \<in> events"
hoelzl@42861:             using G by auto
hoelzl@42861:           have "prob ((\<Inter>j\<in>J. A j) \<inter> (\<Union>k. F k)) = prob (\<Union>k. (\<Inter>i\<in>insert j J. (A(j := F k)) i))"
hoelzl@42861:             using `J \<noteq> {}` `j \<notin> J` `j \<in> K` by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
hoelzl@42861:           moreover have "(\<lambda>k. prob (\<Inter>i\<in>insert j J. (A(j := F k)) i)) sums prob (\<Union>k. (\<Inter>i\<in>insert j J. (A(j := F k)) i))"
hoelzl@42861:           proof (rule finite_measure_UNION)
hoelzl@42861:             show "disjoint_family (\<lambda>k. \<Inter>i\<in>insert j J. (A(j := F k)) i)"
hoelzl@42861:               using disj by (rule disjoint_family_on_bisimulation) auto
hoelzl@42861:             show "range (\<lambda>k. \<Inter>i\<in>insert j J. (A(j := F k)) i) \<subseteq> events"
hoelzl@42861:               using A_sets F `finite J` `J \<noteq> {}` `j \<notin> J` by (auto intro!: Int)
hoelzl@42861:           qed
hoelzl@42861:           moreover { fix k
hoelzl@42861:             from J A `j \<in> K` have "prob (\<Inter>i\<in>insert j J. (A(j := F k)) i) = prob (F k) * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861:               by (subst indep_setsD[OF F(2)]) (auto intro!: setprod_cong split: split_if_asm)
hoelzl@42861:             also have "\<dots> = prob (F k) * prob (\<Inter>i\<in>J. A i)"
hoelzl@42861:               using J A `j \<in> K` by (subst indep_setsD[OF G(1)]) auto
hoelzl@42861:             finally have "prob (\<Inter>i\<in>insert j J. (A(j := F k)) i) = prob (F k) * prob (\<Inter>i\<in>J. A i)" . }
hoelzl@42861:           ultimately have "(\<lambda>k. prob (F k) * prob (\<Inter>i\<in>J. A i)) sums (prob ((\<Inter>j\<in>J. A j) \<inter> (\<Union>k. F k)))"
hoelzl@42861:             by simp
hoelzl@42861:           moreover
hoelzl@42861:           have "(\<lambda>k. prob (F k) * prob (\<Inter>i\<in>J. A i)) sums (prob (\<Union>k. F k) * prob (\<Inter>i\<in>J. A i))"
hoelzl@42861:             using disj F(1) by (intro finite_measure_UNION sums_mult2) auto
hoelzl@42861:           then have "(\<lambda>k. prob (F k) * prob (\<Inter>i\<in>J. A i)) sums (prob (\<Union>k. F k) * (\<Prod>i\<in>J. prob (A i)))"
hoelzl@42861:             using J A `j \<in> K` by (subst indep_setsD[OF G(1), symmetric]) auto
hoelzl@42861:           ultimately
hoelzl@42861:           show "prob ((\<Inter>j\<in>J. A j) \<inter> (\<Union>k. F k)) = prob (\<Union>k. F k) * (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861:             by (auto dest!: sums_unique)
hoelzl@42861:         qed (insert F, auto)
hoelzl@42861:       qed (insert sets_into_space, auto)
hoelzl@42861:       then have mono: "sets (dynkin \<lparr>space = space M, sets = G j\<rparr>) \<subseteq>
hoelzl@42861:         sets \<lparr>space = space M, sets = {E \<in> events. indep_sets (G(j := {E})) K}\<rparr>"
hoelzl@42861:       proof (rule dynkin_system.dynkin_subset, simp_all, safe)
hoelzl@42861:         fix X assume "X \<in> G j"
hoelzl@42861:         then show "X \<in> events" using G `j \<in> K` by auto
hoelzl@42861:         from `indep_sets G K`
hoelzl@42861:         show "indep_sets (G(j := {X})) K"
hoelzl@42861:           by (rule indep_sets_mono_sets) (insert `X \<in> G j`, auto)
hoelzl@42861:       qed
hoelzl@42861:       have "indep_sets (G(j:=?D)) K"
hoelzl@42861:       proof (rule indep_setsI)
hoelzl@42861:         fix i assume "i \<in> K" then show "(G(j := ?D)) i \<subseteq> events"
hoelzl@42861:           using G(2) by auto
hoelzl@42861:       next
hoelzl@42861:         fix A J assume J: "J\<noteq>{}" "J \<subseteq> K" "finite J" and A: "\<forall>i\<in>J. A i \<in> (G(j := ?D)) i"
hoelzl@42861:         show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861:         proof cases
hoelzl@42861:           assume "j \<in> J"
hoelzl@42861:           with A have indep: "indep_sets (G(j := {A j})) K" by auto
hoelzl@42861:           from J A show ?thesis
hoelzl@42861:             by (intro indep_setsD[OF indep]) auto
hoelzl@42861:         next
hoelzl@42861:           assume "j \<notin> J"
hoelzl@42861:           with J A have "\<forall>i\<in>J. A i \<in> G i" by (auto split: split_if_asm)
hoelzl@42861:           with J show ?thesis
hoelzl@42861:             by (intro indep_setsD[OF G(1)]) auto
hoelzl@42861:         qed
hoelzl@42861:       qed
hoelzl@42861:       then have "indep_sets (G(j:=sets (dynkin \<lparr>space = space M, sets = G j\<rparr>))) K"
hoelzl@42861:         by (rule indep_sets_mono_sets) (insert mono, auto)
hoelzl@42861:       then show ?case
hoelzl@42861:         by (rule indep_sets_mono_sets) (insert `j \<in> K` `j \<notin> J`, auto simp: G_def)
hoelzl@42861:     qed (insert `indep_sets F K`, simp) }
hoelzl@42861:   from this[OF `indep_sets F J` `finite J` subset_refl]
hoelzl@42861:   show "indep_sets (\<lambda>i. sets (dynkin \<lparr> space = space M, sets = F i \<rparr>)) J"
hoelzl@42861:     by (rule indep_sets_mono_sets) auto
hoelzl@42861: qed
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_sets_sigma:
hoelzl@42861:   assumes indep: "indep_sets F I"
hoelzl@42861:   assumes stable: "\<And>i. i \<in> I \<Longrightarrow> Int_stable \<lparr> space = space M, sets = F i \<rparr>"
hoelzl@42861:   shows "indep_sets (\<lambda>i. sets (sigma \<lparr> space = space M, sets = F i \<rparr>)) I"
hoelzl@42861: proof -
hoelzl@42861:   from indep_sets_dynkin[OF indep]
hoelzl@42861:   show ?thesis
hoelzl@42861:   proof (rule indep_sets_mono_sets, subst sigma_eq_dynkin, simp_all add: stable)
hoelzl@42861:     fix i assume "i \<in> I"
hoelzl@42861:     with indep have "F i \<subseteq> events" by (auto simp: indep_sets_def)
hoelzl@42861:     with sets_into_space show "F i \<subseteq> Pow (space M)" by auto
hoelzl@42861:   qed
hoelzl@42861: qed
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_sets_sigma_sets:
hoelzl@42861:   assumes "indep_sets F I"
hoelzl@42861:   assumes "\<And>i. i \<in> I \<Longrightarrow> Int_stable \<lparr> space = space M, sets = F i \<rparr>"
hoelzl@42861:   shows "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I"
hoelzl@42861:   using indep_sets_sigma[OF assms] by (simp add: sets_sigma)
hoelzl@42861: 
hoelzl@42861: lemma (in prob_space) indep_sets2_eq:
hoelzl@42981:   "indep_set A B \<longleftrightarrow> A \<subseteq> events \<and> B \<subseteq> events \<and> (\<forall>a\<in>A. \<forall>b\<in>B. prob (a \<inter> b) = prob a * prob b)"
hoelzl@42981:   unfolding indep_set_def
hoelzl@42861: proof (intro iffI ballI conjI)
hoelzl@42861:   assume indep: "indep_sets (bool_case A B) UNIV"
hoelzl@42861:   { fix a b assume "a \<in> A" "b \<in> B"
hoelzl@42861:     with indep_setsD[OF indep, of UNIV "bool_case a b"]
hoelzl@42861:     show "prob (a \<inter> b) = prob a * prob b"
hoelzl@42861:       unfolding UNIV_bool by (simp add: ac_simps) }
hoelzl@42861:   from indep show "A \<subseteq> events" "B \<subseteq> events"
hoelzl@42861:     unfolding indep_sets_def UNIV_bool by auto
hoelzl@42861: next
hoelzl@42861:   assume *: "A \<subseteq> events \<and> B \<subseteq> events \<and> (\<forall>a\<in>A. \<forall>b\<in>B. prob (a \<inter> b) = prob a * prob b)"
hoelzl@42861:   show "indep_sets (bool_case A B) UNIV"
hoelzl@42861:   proof (rule indep_setsI)
hoelzl@42861:     fix i show "(case i of True \<Rightarrow> A | False \<Rightarrow> B) \<subseteq> events"
hoelzl@42861:       using * by (auto split: bool.split)
hoelzl@42861:   next
hoelzl@42861:     fix J X assume "J \<noteq> {}" "J \<subseteq> UNIV" and X: "\<forall>j\<in>J. X j \<in> (case j of True \<Rightarrow> A | False \<Rightarrow> B)"
hoelzl@42861:     then have "J = {True} \<or> J = {False} \<or> J = {True,False}"
hoelzl@42861:       by (auto simp: UNIV_bool)
hoelzl@42861:     then show "prob (\<Inter>j\<in>J. X j) = (\<Prod>j\<in>J. prob (X j))"
hoelzl@42861:       using X * by auto
hoelzl@42861:   qed
hoelzl@42861: qed
hoelzl@42861: 
hoelzl@42981: lemma (in prob_space) indep_set_sigma_sets:
hoelzl@42981:   assumes "indep_set A B"
hoelzl@42861:   assumes A: "Int_stable \<lparr> space = space M, sets = A \<rparr>"
hoelzl@42861:   assumes B: "Int_stable \<lparr> space = space M, sets = B \<rparr>"
hoelzl@42981:   shows "indep_set (sigma_sets (space M) A) (sigma_sets (space M) B)"
hoelzl@42861: proof -
hoelzl@42861:   have "indep_sets (\<lambda>i. sigma_sets (space M) (case i of True \<Rightarrow> A | False \<Rightarrow> B)) UNIV"
hoelzl@42861:   proof (rule indep_sets_sigma_sets)
hoelzl@42861:     show "indep_sets (bool_case A B) UNIV"
hoelzl@42981:       by (rule `indep_set A B`[unfolded indep_set_def])
hoelzl@42861:     fix i show "Int_stable \<lparr>space = space M, sets = case i of True \<Rightarrow> A | False \<Rightarrow> B\<rparr>"
hoelzl@42861:       using A B by (cases i) auto
hoelzl@42861:   qed
hoelzl@42861:   then show ?thesis
hoelzl@42981:     unfolding indep_set_def
hoelzl@42861:     by (rule indep_sets_mono_sets) (auto split: bool.split)
hoelzl@42861: qed
hoelzl@42861: 
hoelzl@42981: lemma (in prob_space) indep_sets_collect_sigma:
hoelzl@42981:   fixes I :: "'j \<Rightarrow> 'i set" and J :: "'j set" and E :: "'i \<Rightarrow> 'a set set"
hoelzl@42981:   assumes indep: "indep_sets E (\<Union>j\<in>J. I j)"
hoelzl@42981:   assumes Int_stable: "\<And>i j. j \<in> J \<Longrightarrow> i \<in> I j \<Longrightarrow> Int_stable \<lparr>space = space M, sets = E i\<rparr>"
hoelzl@42981:   assumes disjoint: "disjoint_family_on I J"
hoelzl@42981:   shows "indep_sets (\<lambda>j. sigma_sets (space M) (\<Union>i\<in>I j. E i)) J"
hoelzl@42981: proof -
hoelzl@42981:   let "?E j" = "{\<Inter>k\<in>K. E' k| E' K. finite K \<and> K \<noteq> {} \<and> K \<subseteq> I j \<and> (\<forall>k\<in>K. E' k \<in> E k) }"
hoelzl@42981: 
hoelzl@42981:   from indep have E: "\<And>j i. j \<in> J \<Longrightarrow> i \<in> I j \<Longrightarrow> E i \<subseteq> sets M"
hoelzl@42981:     unfolding indep_sets_def by auto
hoelzl@42981:   { fix j
hoelzl@42981:     let ?S = "sigma \<lparr> space = space M, sets = (\<Union>i\<in>I j. E i) \<rparr>"
hoelzl@42981:     assume "j \<in> J"
hoelzl@42981:     from E[OF this] interpret S: sigma_algebra ?S
hoelzl@42981:       using sets_into_space by (intro sigma_algebra_sigma) auto
hoelzl@42981: 
hoelzl@42981:     have "sigma_sets (space M) (\<Union>i\<in>I j. E i) = sigma_sets (space M) (?E j)"
hoelzl@42981:     proof (rule sigma_sets_eqI)
hoelzl@42981:       fix A assume "A \<in> (\<Union>i\<in>I j. E i)"
hoelzl@42981:       then guess i ..
hoelzl@42981:       then show "A \<in> sigma_sets (space M) (?E j)"
hoelzl@42981:         by (auto intro!: sigma_sets.intros exI[of _ "{i}"] exI[of _ "\<lambda>i. A"])
hoelzl@42981:     next
hoelzl@42981:       fix A assume "A \<in> ?E j"
hoelzl@42981:       then obtain E' K where "finite K" "K \<noteq> {}" "K \<subseteq> I j" "\<And>k. k \<in> K \<Longrightarrow> E' k \<in> E k"
hoelzl@42981:         and A: "A = (\<Inter>k\<in>K. E' k)"
hoelzl@42981:         by auto
hoelzl@42981:       then have "A \<in> sets ?S" unfolding A
hoelzl@42981:         by (safe intro!: S.finite_INT)
hoelzl@42981:            (auto simp: sets_sigma intro!: sigma_sets.Basic)
hoelzl@42981:       then show "A \<in> sigma_sets (space M) (\<Union>i\<in>I j. E i)"
hoelzl@42981:         by (simp add: sets_sigma)
hoelzl@42981:     qed }
hoelzl@42981:   moreover have "indep_sets (\<lambda>j. sigma_sets (space M) (?E j)) J"
hoelzl@42981:   proof (rule indep_sets_sigma_sets)
hoelzl@42981:     show "indep_sets ?E J"
hoelzl@42981:     proof (intro indep_setsI)
hoelzl@42981:       fix j assume "j \<in> J" with E show "?E j \<subseteq> events" by (force  intro!: finite_INT)
hoelzl@42981:     next
hoelzl@42981:       fix K A assume K: "K \<noteq> {}" "K \<subseteq> J" "finite K"
hoelzl@42981:         and "\<forall>j\<in>K. A j \<in> ?E j"
hoelzl@42981:       then have "\<forall>j\<in>K. \<exists>E' L. A j = (\<Inter>l\<in>L. E' l) \<and> finite L \<and> L \<noteq> {} \<and> L \<subseteq> I j \<and> (\<forall>l\<in>L. E' l \<in> E l)"
hoelzl@42981:         by simp
hoelzl@42981:       from bchoice[OF this] guess E' ..
hoelzl@42981:       from bchoice[OF this] obtain L
hoelzl@42981:         where A: "\<And>j. j\<in>K \<Longrightarrow> A j = (\<Inter>l\<in>L j. E' j l)"
hoelzl@42981:         and L: "\<And>j. j\<in>K \<Longrightarrow> finite (L j)" "\<And>j. j\<in>K \<Longrightarrow> L j \<noteq> {}" "\<And>j. j\<in>K \<Longrightarrow> L j \<subseteq> I j"
hoelzl@42981:         and E': "\<And>j l. j\<in>K \<Longrightarrow> l \<in> L j \<Longrightarrow> E' j l \<in> E l"
hoelzl@42981:         by auto
hoelzl@42981: 
hoelzl@42981:       { fix k l j assume "k \<in> K" "j \<in> K" "l \<in> L j" "l \<in> L k"
hoelzl@42981:         have "k = j"
hoelzl@42981:         proof (rule ccontr)
hoelzl@42981:           assume "k \<noteq> j"
hoelzl@42981:           with disjoint `K \<subseteq> J` `k \<in> K` `j \<in> K` have "I k \<inter> I j = {}"
hoelzl@42981:             unfolding disjoint_family_on_def by auto
hoelzl@42981:           with L(2,3)[OF `j \<in> K`] L(2,3)[OF `k \<in> K`]
hoelzl@42981:           show False using `l \<in> L k` `l \<in> L j` by auto
hoelzl@42981:         qed }
hoelzl@42981:       note L_inj = this
hoelzl@42981: 
hoelzl@42981:       def k \<equiv> "\<lambda>l. (SOME k. k \<in> K \<and> l \<in> L k)"
hoelzl@42981:       { fix x j l assume *: "j \<in> K" "l \<in> L j"
hoelzl@42981:         have "k l = j" unfolding k_def
hoelzl@42981:         proof (rule some_equality)
hoelzl@42981:           fix k assume "k \<in> K \<and> l \<in> L k"
hoelzl@42981:           with * L_inj show "k = j" by auto
hoelzl@42981:         qed (insert *, simp) }
hoelzl@42981:       note k_simp[simp] = this
hoelzl@42981:       let "?E' l" = "E' (k l) l"
hoelzl@42981:       have "prob (\<Inter>j\<in>K. A j) = prob (\<Inter>l\<in>(\<Union>k\<in>K. L k). ?E' l)"
hoelzl@42981:         by (auto simp: A intro!: arg_cong[where f=prob])
hoelzl@42981:       also have "\<dots> = (\<Prod>l\<in>(\<Union>k\<in>K. L k). prob (?E' l))"
hoelzl@42981:         using L K E' by (intro indep_setsD[OF indep]) (simp_all add: UN_mono)
hoelzl@42981:       also have "\<dots> = (\<Prod>j\<in>K. \<Prod>l\<in>L j. prob (E' j l))"
hoelzl@42981:         using K L L_inj by (subst setprod_UN_disjoint) auto
hoelzl@42981:       also have "\<dots> = (\<Prod>j\<in>K. prob (A j))"
hoelzl@42981:         using K L E' by (auto simp add: A intro!: setprod_cong indep_setsD[OF indep, symmetric]) blast
hoelzl@42981:       finally show "prob (\<Inter>j\<in>K. A j) = (\<Prod>j\<in>K. prob (A j))" .
hoelzl@42981:     qed
hoelzl@42981:   next
hoelzl@42981:     fix j assume "j \<in> J"
hoelzl@42981:     show "Int_stable \<lparr> space = space M, sets = ?E j \<rparr>"
hoelzl@42981:     proof (rule Int_stableI)
hoelzl@42981:       fix a assume "a \<in> ?E j" then obtain Ka Ea
hoelzl@42981:         where a: "a = (\<Inter>k\<in>Ka. Ea k)" "finite Ka" "Ka \<noteq> {}" "Ka \<subseteq> I j" "\<And>k. k\<in>Ka \<Longrightarrow> Ea k \<in> E k" by auto
hoelzl@42981:       fix b assume "b \<in> ?E j" then obtain Kb Eb
hoelzl@42981:         where b: "b = (\<Inter>k\<in>Kb. Eb k)" "finite Kb" "Kb \<noteq> {}" "Kb \<subseteq> I j" "\<And>k. k\<in>Kb \<Longrightarrow> Eb k \<in> E k" by auto
hoelzl@42981:       let ?A = "\<lambda>k. (if k \<in> Ka \<inter> Kb then Ea k \<inter> Eb k else if k \<in> Kb then Eb k else if k \<in> Ka then Ea k else {})"
hoelzl@42981:       have "a \<inter> b = INTER (Ka \<union> Kb) ?A"
hoelzl@42981:         by (simp add: a b set_eq_iff) auto
hoelzl@42981:       with a b `j \<in> J` Int_stableD[OF Int_stable] show "a \<inter> b \<in> ?E j"
hoelzl@42981:         by (intro CollectI exI[of _ "Ka \<union> Kb"] exI[of _ ?A]) auto
hoelzl@42981:     qed
hoelzl@42981:   qed
hoelzl@42981:   ultimately show ?thesis
hoelzl@42981:     by (simp cong: indep_sets_cong)
hoelzl@42981: qed
hoelzl@42981: 
hoelzl@42861: end




