src/HOL/Probability/Independent_Family.thy
 author wenzelm Mon Dec 07 20:19:59 2015 +0100 (2015-12-07) changeset 61808 fc1556774cfe parent 61359 e985b52c3eb3 child 62343 24106dc44def permissions -rw-r--r--
isabelle update_cartouches -c -t;
```     1 (*  Title:      HOL/Probability/Independent_Family.thy
```
```     2     Author:     Johannes Hölzl, TU München
```
```     3     Author:     Sudeep Kanav, TU München
```
```     4 *)
```
```     5
```
```     6 section \<open>Independent families of events, event sets, and random variables\<close>
```
```     7
```
```     8 theory Independent_Family
```
```     9   imports Probability_Measure Infinite_Product_Measure
```
```    10 begin
```
```    11
```
```    12 definition (in prob_space)
```
```    13   "indep_sets F I \<longleftrightarrow> (\<forall>i\<in>I. F i \<subseteq> events) \<and>
```
```    14     (\<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))))"
```
```    15
```
```    16 definition (in prob_space)
```
```    17   "indep_set A B \<longleftrightarrow> indep_sets (case_bool A B) UNIV"
```
```    18
```
```    19 definition (in prob_space)
```
```    20   indep_events_def_alt: "indep_events A I \<longleftrightarrow> indep_sets (\<lambda>i. {A i}) I"
```
```    21
```
```    22 lemma (in prob_space) indep_events_def:
```
```    23   "indep_events A I \<longleftrightarrow> (A`I \<subseteq> events) \<and>
```
```    24     (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j)))"
```
```    25   unfolding indep_events_def_alt indep_sets_def
```
```    26   apply (simp add: Ball_def Pi_iff image_subset_iff_funcset)
```
```    27   apply (intro conj_cong refl arg_cong[where f=All] ext imp_cong)
```
```    28   apply auto
```
```    29   done
```
```    30
```
```    31 lemma (in prob_space) indep_eventsI:
```
```    32   "(\<And>i. i \<in> I \<Longrightarrow> F i \<in> sets M) \<Longrightarrow> (\<And>J. J \<subseteq> I \<Longrightarrow> finite J \<Longrightarrow> J \<noteq> {} \<Longrightarrow> prob (\<Inter>i\<in>J. F i) = (\<Prod>i\<in>J. prob (F i))) \<Longrightarrow> indep_events F I"
```
```    33   by (auto simp: indep_events_def)
```
```    34
```
```    35 definition (in prob_space)
```
```    36   "indep_event A B \<longleftrightarrow> indep_events (case_bool A B) UNIV"
```
```    37
```
```    38 lemma (in prob_space) indep_sets_cong:
```
```    39   "I = J \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> F i = G i) \<Longrightarrow> indep_sets F I \<longleftrightarrow> indep_sets G J"
```
```    40   by (simp add: indep_sets_def, intro conj_cong all_cong imp_cong ball_cong) blast+
```
```    41
```
```    42 lemma (in prob_space) indep_events_finite_index_events:
```
```    43   "indep_events F I \<longleftrightarrow> (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_events F J)"
```
```    44   by (auto simp: indep_events_def)
```
```    45
```
```    46 lemma (in prob_space) indep_sets_finite_index_sets:
```
```    47   "indep_sets F I \<longleftrightarrow> (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_sets F J)"
```
```    48 proof (intro iffI allI impI)
```
```    49   assume *: "\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_sets F J"
```
```    50   show "indep_sets F I" unfolding indep_sets_def
```
```    51   proof (intro conjI ballI allI impI)
```
```    52     fix i assume "i \<in> I"
```
```    53     with *[THEN spec, of "{i}"] show "F i \<subseteq> events"
```
```    54       by (auto simp: indep_sets_def)
```
```    55   qed (insert *, auto simp: indep_sets_def)
```
```    56 qed (auto simp: indep_sets_def)
```
```    57
```
```    58 lemma (in prob_space) indep_sets_mono_index:
```
```    59   "J \<subseteq> I \<Longrightarrow> indep_sets F I \<Longrightarrow> indep_sets F J"
```
```    60   unfolding indep_sets_def by auto
```
```    61
```
```    62 lemma (in prob_space) indep_sets_mono_sets:
```
```    63   assumes indep: "indep_sets F I"
```
```    64   assumes mono: "\<And>i. i\<in>I \<Longrightarrow> G i \<subseteq> F i"
```
```    65   shows "indep_sets G I"
```
```    66 proof -
```
```    67   have "(\<forall>i\<in>I. F i \<subseteq> events) \<Longrightarrow> (\<forall>i\<in>I. G i \<subseteq> events)"
```
```    68     using mono by auto
```
```    69   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)"
```
```    70     using mono by (auto simp: Pi_iff)
```
```    71   ultimately show ?thesis
```
```    72     using indep by (auto simp: indep_sets_def)
```
```    73 qed
```
```    74
```
```    75 lemma (in prob_space) indep_sets_mono:
```
```    76   assumes indep: "indep_sets F I"
```
```    77   assumes mono: "J \<subseteq> I" "\<And>i. i\<in>J \<Longrightarrow> G i \<subseteq> F i"
```
```    78   shows "indep_sets G J"
```
```    79   apply (rule indep_sets_mono_sets)
```
```    80   apply (rule indep_sets_mono_index)
```
```    81   apply (fact +)
```
```    82   done
```
```    83
```
```    84 lemma (in prob_space) indep_setsI:
```
```    85   assumes "\<And>i. i \<in> I \<Longrightarrow> F i \<subseteq> events"
```
```    86     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))"
```
```    87   shows "indep_sets F I"
```
```    88   using assms unfolding indep_sets_def by (auto simp: Pi_iff)
```
```    89
```
```    90 lemma (in prob_space) indep_setsD:
```
```    91   assumes "indep_sets F I" and "J \<subseteq> I" "J \<noteq> {}" "finite J" "\<forall>j\<in>J. A j \<in> F j"
```
```    92   shows "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
```
```    93   using assms unfolding indep_sets_def by auto
```
```    94
```
```    95 lemma (in prob_space) indep_setI:
```
```    96   assumes ev: "A \<subseteq> events" "B \<subseteq> events"
```
```    97     and indep: "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> prob (a \<inter> b) = prob a * prob b"
```
```    98   shows "indep_set A B"
```
```    99   unfolding indep_set_def
```
```   100 proof (rule indep_setsI)
```
```   101   fix F J assume "J \<noteq> {}" "J \<subseteq> UNIV"
```
```   102     and F: "\<forall>j\<in>J. F j \<in> (case j of True \<Rightarrow> A | False \<Rightarrow> B)"
```
```   103   have "J \<in> Pow UNIV" by auto
```
```   104   with F \<open>J \<noteq> {}\<close> indep[of "F True" "F False"]
```
```   105   show "prob (\<Inter>j\<in>J. F j) = (\<Prod>j\<in>J. prob (F j))"
```
```   106     unfolding UNIV_bool Pow_insert by (auto simp: ac_simps)
```
```   107 qed (auto split: bool.split simp: ev)
```
```   108
```
```   109 lemma (in prob_space) indep_setD:
```
```   110   assumes indep: "indep_set A B" and ev: "a \<in> A" "b \<in> B"
```
```   111   shows "prob (a \<inter> b) = prob a * prob b"
```
```   112   using indep[unfolded indep_set_def, THEN indep_setsD, of UNIV "case_bool a b"] ev
```
```   113   by (simp add: ac_simps UNIV_bool)
```
```   114
```
```   115 lemma (in prob_space)
```
```   116   assumes indep: "indep_set A B"
```
```   117   shows indep_setD_ev1: "A \<subseteq> events"
```
```   118     and indep_setD_ev2: "B \<subseteq> events"
```
```   119   using indep unfolding indep_set_def indep_sets_def UNIV_bool by auto
```
```   120
```
```   121 lemma (in prob_space) indep_sets_dynkin:
```
```   122   assumes indep: "indep_sets F I"
```
```   123   shows "indep_sets (\<lambda>i. dynkin (space M) (F i)) I"
```
```   124     (is "indep_sets ?F I")
```
```   125 proof (subst indep_sets_finite_index_sets, intro allI impI ballI)
```
```   126   fix J assume "finite J" "J \<subseteq> I" "J \<noteq> {}"
```
```   127   with indep have "indep_sets F J"
```
```   128     by (subst (asm) indep_sets_finite_index_sets) auto
```
```   129   { fix J K assume "indep_sets F K"
```
```   130     let ?G = "\<lambda>S i. if i \<in> S then ?F i else F i"
```
```   131     assume "finite J" "J \<subseteq> K"
```
```   132     then have "indep_sets (?G J) K"
```
```   133     proof induct
```
```   134       case (insert j J)
```
```   135       moreover def G \<equiv> "?G J"
```
```   136       ultimately have G: "indep_sets G K" "\<And>i. i \<in> K \<Longrightarrow> G i \<subseteq> events" and "j \<in> K"
```
```   137         by (auto simp: indep_sets_def)
```
```   138       let ?D = "{E\<in>events. indep_sets (G(j := {E})) K }"
```
```   139       { fix X assume X: "X \<in> events"
```
```   140         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)
```
```   141           \<Longrightarrow> prob ((\<Inter>i\<in>J. A i) \<inter> X) = prob X * (\<Prod>i\<in>J. prob (A i))"
```
```   142         have "indep_sets (G(j := {X})) K"
```
```   143         proof (rule indep_setsI)
```
```   144           fix i assume "i \<in> K" then show "(G(j:={X})) i \<subseteq> events"
```
```   145             using G X by auto
```
```   146         next
```
```   147           fix A J assume J: "J \<noteq> {}" "J \<subseteq> K" "finite J" "\<forall>i\<in>J. A i \<in> (G(j := {X})) i"
```
```   148           show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
```
```   149           proof cases
```
```   150             assume "j \<in> J"
```
```   151             with J have "A j = X" by auto
```
```   152             show ?thesis
```
```   153             proof cases
```
```   154               assume "J = {j}" then show ?thesis by simp
```
```   155             next
```
```   156               assume "J \<noteq> {j}"
```
```   157               have "prob (\<Inter>i\<in>J. A i) = prob ((\<Inter>i\<in>J-{j}. A i) \<inter> X)"
```
```   158                 using \<open>j \<in> J\<close> \<open>A j = X\<close> by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
```
```   159               also have "\<dots> = prob X * (\<Prod>i\<in>J-{j}. prob (A i))"
```
```   160               proof (rule indep)
```
```   161                 show "J - {j} \<noteq> {}" "J - {j} \<subseteq> K" "finite (J - {j})" "j \<notin> J - {j}"
```
```   162                   using J \<open>J \<noteq> {j}\<close> \<open>j \<in> J\<close> by auto
```
```   163                 show "\<forall>i\<in>J - {j}. A i \<in> G i"
```
```   164                   using J by auto
```
```   165               qed
```
```   166               also have "\<dots> = prob (A j) * (\<Prod>i\<in>J-{j}. prob (A i))"
```
```   167                 using \<open>A j = X\<close> by simp
```
```   168               also have "\<dots> = (\<Prod>i\<in>J. prob (A i))"
```
```   169                 unfolding setprod.insert_remove[OF \<open>finite J\<close>, symmetric, of "\<lambda>i. prob  (A i)"]
```
```   170                 using \<open>j \<in> J\<close> by (simp add: insert_absorb)
```
```   171               finally show ?thesis .
```
```   172             qed
```
```   173           next
```
```   174             assume "j \<notin> J"
```
```   175             with J have "\<forall>i\<in>J. A i \<in> G i" by (auto split: split_if_asm)
```
```   176             with J show ?thesis
```
```   177               by (intro indep_setsD[OF G(1)]) auto
```
```   178           qed
```
```   179         qed }
```
```   180       note indep_sets_insert = this
```
```   181       have "dynkin_system (space M) ?D"
```
```   182       proof (rule dynkin_systemI', simp_all cong del: indep_sets_cong, safe)
```
```   183         show "indep_sets (G(j := {{}})) K"
```
```   184           by (rule indep_sets_insert) auto
```
```   185       next
```
```   186         fix X assume X: "X \<in> events" and G': "indep_sets (G(j := {X})) K"
```
```   187         show "indep_sets (G(j := {space M - X})) K"
```
```   188         proof (rule indep_sets_insert)
```
```   189           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"
```
```   190           then have A_sets: "\<And>i. i\<in>J \<Longrightarrow> A i \<in> events"
```
```   191             using G by auto
```
```   192           have "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) =
```
```   193               prob ((\<Inter>j\<in>J. A j) - (\<Inter>i\<in>insert j J. (A(j := X)) i))"
```
```   194             using A_sets sets.sets_into_space[of _ M] X \<open>J \<noteq> {}\<close>
```
```   195             by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
```
```   196           also have "\<dots> = prob (\<Inter>j\<in>J. A j) - prob (\<Inter>i\<in>insert j J. (A(j := X)) i)"
```
```   197             using J \<open>J \<noteq> {}\<close> \<open>j \<notin> J\<close> A_sets X sets.sets_into_space
```
```   198             by (auto intro!: finite_measure_Diff sets.finite_INT split: split_if_asm)
```
```   199           finally have "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) =
```
```   200               prob (\<Inter>j\<in>J. A j) - prob (\<Inter>i\<in>insert j J. (A(j := X)) i)" .
```
```   201           moreover {
```
```   202             have "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
```
```   203               using J A \<open>finite J\<close> by (intro indep_setsD[OF G(1)]) auto
```
```   204             then have "prob (\<Inter>j\<in>J. A j) = prob (space M) * (\<Prod>i\<in>J. prob (A i))"
```
```   205               using prob_space by simp }
```
```   206           moreover {
```
```   207             have "prob (\<Inter>i\<in>insert j J. (A(j := X)) i) = (\<Prod>i\<in>insert j J. prob ((A(j := X)) i))"
```
```   208               using J A \<open>j \<in> K\<close> by (intro indep_setsD[OF G']) auto
```
```   209             then have "prob (\<Inter>i\<in>insert j J. (A(j := X)) i) = prob X * (\<Prod>i\<in>J. prob (A i))"
```
```   210               using \<open>finite J\<close> \<open>j \<notin> J\<close> by (auto intro!: setprod.cong) }
```
```   211           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))"
```
```   212             by (simp add: field_simps)
```
```   213           also have "\<dots> = prob (space M - X) * (\<Prod>i\<in>J. prob (A i))"
```
```   214             using X A by (simp add: finite_measure_compl)
```
```   215           finally show "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) = prob (space M - X) * (\<Prod>i\<in>J. prob (A i))" .
```
```   216         qed (insert X, auto)
```
```   217       next
```
```   218         fix F :: "nat \<Rightarrow> 'a set" assume disj: "disjoint_family F" and "range F \<subseteq> ?D"
```
```   219         then have F: "\<And>i. F i \<in> events" "\<And>i. indep_sets (G(j:={F i})) K" by auto
```
```   220         show "indep_sets (G(j := {\<Union>k. F k})) K"
```
```   221         proof (rule indep_sets_insert)
```
```   222           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"
```
```   223           then have A_sets: "\<And>i. i\<in>J \<Longrightarrow> A i \<in> events"
```
```   224             using G by auto
```
```   225           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))"
```
```   226             using \<open>J \<noteq> {}\<close> \<open>j \<notin> J\<close> \<open>j \<in> K\<close> by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
```
```   227           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))"
```
```   228           proof (rule finite_measure_UNION)
```
```   229             show "disjoint_family (\<lambda>k. \<Inter>i\<in>insert j J. (A(j := F k)) i)"
```
```   230               using disj by (rule disjoint_family_on_bisimulation) auto
```
```   231             show "range (\<lambda>k. \<Inter>i\<in>insert j J. (A(j := F k)) i) \<subseteq> events"
```
```   232               using A_sets F \<open>finite J\<close> \<open>J \<noteq> {}\<close> \<open>j \<notin> J\<close> by (auto intro!: sets.Int)
```
```   233           qed
```
```   234           moreover { fix k
```
```   235             from J A \<open>j \<in> K\<close> have "prob (\<Inter>i\<in>insert j J. (A(j := F k)) i) = prob (F k) * (\<Prod>i\<in>J. prob (A i))"
```
```   236               by (subst indep_setsD[OF F(2)]) (auto intro!: setprod.cong split: split_if_asm)
```
```   237             also have "\<dots> = prob (F k) * prob (\<Inter>i\<in>J. A i)"
```
```   238               using J A \<open>j \<in> K\<close> by (subst indep_setsD[OF G(1)]) auto
```
```   239             finally have "prob (\<Inter>i\<in>insert j J. (A(j := F k)) i) = prob (F k) * prob (\<Inter>i\<in>J. A i)" . }
```
```   240           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)))"
```
```   241             by simp
```
```   242           moreover
```
```   243           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))"
```
```   244             using disj F(1) by (intro finite_measure_UNION sums_mult2) auto
```
```   245           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)))"
```
```   246             using J A \<open>j \<in> K\<close> by (subst indep_setsD[OF G(1), symmetric]) auto
```
```   247           ultimately
```
```   248           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))"
```
```   249             by (auto dest!: sums_unique)
```
```   250         qed (insert F, auto)
```
```   251       qed (insert sets.sets_into_space, auto)
```
```   252       then have mono: "dynkin (space M) (G j) \<subseteq> {E \<in> events. indep_sets (G(j := {E})) K}"
```
```   253       proof (rule dynkin_system.dynkin_subset, safe)
```
```   254         fix X assume "X \<in> G j"
```
```   255         then show "X \<in> events" using G \<open>j \<in> K\<close> by auto
```
```   256         from \<open>indep_sets G K\<close>
```
```   257         show "indep_sets (G(j := {X})) K"
```
```   258           by (rule indep_sets_mono_sets) (insert \<open>X \<in> G j\<close>, auto)
```
```   259       qed
```
```   260       have "indep_sets (G(j:=?D)) K"
```
```   261       proof (rule indep_setsI)
```
```   262         fix i assume "i \<in> K" then show "(G(j := ?D)) i \<subseteq> events"
```
```   263           using G(2) by auto
```
```   264       next
```
```   265         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"
```
```   266         show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
```
```   267         proof cases
```
```   268           assume "j \<in> J"
```
```   269           with A have indep: "indep_sets (G(j := {A j})) K" by auto
```
```   270           from J A show ?thesis
```
```   271             by (intro indep_setsD[OF indep]) auto
```
```   272         next
```
```   273           assume "j \<notin> J"
```
```   274           with J A have "\<forall>i\<in>J. A i \<in> G i" by (auto split: split_if_asm)
```
```   275           with J show ?thesis
```
```   276             by (intro indep_setsD[OF G(1)]) auto
```
```   277         qed
```
```   278       qed
```
```   279       then have "indep_sets (G(j := dynkin (space M) (G j))) K"
```
```   280         by (rule indep_sets_mono_sets) (insert mono, auto)
```
```   281       then show ?case
```
```   282         by (rule indep_sets_mono_sets) (insert \<open>j \<in> K\<close> \<open>j \<notin> J\<close>, auto simp: G_def)
```
```   283     qed (insert \<open>indep_sets F K\<close>, simp) }
```
```   284   from this[OF \<open>indep_sets F J\<close> \<open>finite J\<close> subset_refl]
```
```   285   show "indep_sets ?F J"
```
```   286     by (rule indep_sets_mono_sets) auto
```
```   287 qed
```
```   288
```
```   289 lemma (in prob_space) indep_sets_sigma:
```
```   290   assumes indep: "indep_sets F I"
```
```   291   assumes stable: "\<And>i. i \<in> I \<Longrightarrow> Int_stable (F i)"
```
```   292   shows "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I"
```
```   293 proof -
```
```   294   from indep_sets_dynkin[OF indep]
```
```   295   show ?thesis
```
```   296   proof (rule indep_sets_mono_sets, subst sigma_eq_dynkin, simp_all add: stable)
```
```   297     fix i assume "i \<in> I"
```
```   298     with indep have "F i \<subseteq> events" by (auto simp: indep_sets_def)
```
```   299     with sets.sets_into_space show "F i \<subseteq> Pow (space M)" by auto
```
```   300   qed
```
```   301 qed
```
```   302
```
```   303 lemma (in prob_space) indep_sets_sigma_sets_iff:
```
```   304   assumes "\<And>i. i \<in> I \<Longrightarrow> Int_stable (F i)"
```
```   305   shows "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I \<longleftrightarrow> indep_sets F I"
```
```   306 proof
```
```   307   assume "indep_sets F I" then show "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I"
```
```   308     by (rule indep_sets_sigma) fact
```
```   309 next
```
```   310   assume "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I" then show "indep_sets F I"
```
```   311     by (rule indep_sets_mono_sets) (intro subsetI sigma_sets.Basic)
```
```   312 qed
```
```   313
```
```   314 definition (in prob_space)
```
```   315   indep_vars_def2: "indep_vars M' X I \<longleftrightarrow>
```
```   316     (\<forall>i\<in>I. random_variable (M' i) (X i)) \<and>
```
```   317     indep_sets (\<lambda>i. { X i -` A \<inter> space M | A. A \<in> sets (M' i)}) I"
```
```   318
```
```   319 definition (in prob_space)
```
```   320   "indep_var Ma A Mb B \<longleftrightarrow> indep_vars (case_bool Ma Mb) (case_bool A B) UNIV"
```
```   321
```
```   322 lemma (in prob_space) indep_vars_def:
```
```   323   "indep_vars M' X I \<longleftrightarrow>
```
```   324     (\<forall>i\<in>I. random_variable (M' i) (X i)) \<and>
```
```   325     indep_sets (\<lambda>i. sigma_sets (space M) { X i -` A \<inter> space M | A. A \<in> sets (M' i)}) I"
```
```   326   unfolding indep_vars_def2
```
```   327   apply (rule conj_cong[OF refl])
```
```   328   apply (rule indep_sets_sigma_sets_iff[symmetric])
```
```   329   apply (auto simp: Int_stable_def)
```
```   330   apply (rule_tac x="A \<inter> Aa" in exI)
```
```   331   apply auto
```
```   332   done
```
```   333
```
```   334 lemma (in prob_space) indep_var_eq:
```
```   335   "indep_var S X T Y \<longleftrightarrow>
```
```   336     (random_variable S X \<and> random_variable T Y) \<and>
```
```   337     indep_set
```
```   338       (sigma_sets (space M) { X -` A \<inter> space M | A. A \<in> sets S})
```
```   339       (sigma_sets (space M) { Y -` A \<inter> space M | A. A \<in> sets T})"
```
```   340   unfolding indep_var_def indep_vars_def indep_set_def UNIV_bool
```
```   341   by (intro arg_cong2[where f="op \<and>"] arg_cong2[where f=indep_sets] ext)
```
```   342      (auto split: bool.split)
```
```   343
```
```   344 lemma (in prob_space) indep_sets2_eq:
```
```   345   "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)"
```
```   346   unfolding indep_set_def
```
```   347 proof (intro iffI ballI conjI)
```
```   348   assume indep: "indep_sets (case_bool A B) UNIV"
```
```   349   { fix a b assume "a \<in> A" "b \<in> B"
```
```   350     with indep_setsD[OF indep, of UNIV "case_bool a b"]
```
```   351     show "prob (a \<inter> b) = prob a * prob b"
```
```   352       unfolding UNIV_bool by (simp add: ac_simps) }
```
```   353   from indep show "A \<subseteq> events" "B \<subseteq> events"
```
```   354     unfolding indep_sets_def UNIV_bool by auto
```
```   355 next
```
```   356   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)"
```
```   357   show "indep_sets (case_bool A B) UNIV"
```
```   358   proof (rule indep_setsI)
```
```   359     fix i show "(case i of True \<Rightarrow> A | False \<Rightarrow> B) \<subseteq> events"
```
```   360       using * by (auto split: bool.split)
```
```   361   next
```
```   362     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)"
```
```   363     then have "J = {True} \<or> J = {False} \<or> J = {True,False}"
```
```   364       by (auto simp: UNIV_bool)
```
```   365     then show "prob (\<Inter>j\<in>J. X j) = (\<Prod>j\<in>J. prob (X j))"
```
```   366       using X * by auto
```
```   367   qed
```
```   368 qed
```
```   369
```
```   370 lemma (in prob_space) indep_set_sigma_sets:
```
```   371   assumes "indep_set A B"
```
```   372   assumes A: "Int_stable A" and B: "Int_stable B"
```
```   373   shows "indep_set (sigma_sets (space M) A) (sigma_sets (space M) B)"
```
```   374 proof -
```
```   375   have "indep_sets (\<lambda>i. sigma_sets (space M) (case i of True \<Rightarrow> A | False \<Rightarrow> B)) UNIV"
```
```   376   proof (rule indep_sets_sigma)
```
```   377     show "indep_sets (case_bool A B) UNIV"
```
```   378       by (rule \<open>indep_set A B\<close>[unfolded indep_set_def])
```
```   379     fix i show "Int_stable (case i of True \<Rightarrow> A | False \<Rightarrow> B)"
```
```   380       using A B by (cases i) auto
```
```   381   qed
```
```   382   then show ?thesis
```
```   383     unfolding indep_set_def
```
```   384     by (rule indep_sets_mono_sets) (auto split: bool.split)
```
```   385 qed
```
```   386
```
```   387 lemma (in prob_space) indep_eventsI_indep_vars:
```
```   388   assumes indep: "indep_vars N X I"
```
```   389   assumes P: "\<And>i. i \<in> I \<Longrightarrow> {x\<in>space (N i). P i x} \<in> sets (N i)"
```
```   390   shows "indep_events (\<lambda>i. {x\<in>space M. P i (X i x)}) I"
```
```   391 proof -
```
```   392   have "indep_sets (\<lambda>i. {X i -` A \<inter> space M |A. A \<in> sets (N i)}) I"
```
```   393     using indep unfolding indep_vars_def2 by auto
```
```   394   then show ?thesis
```
```   395     unfolding indep_events_def_alt
```
```   396   proof (rule indep_sets_mono_sets)
```
```   397     fix i assume "i \<in> I"
```
```   398     then have "{{x \<in> space M. P i (X i x)}} = {X i -` {x\<in>space (N i). P i x} \<inter> space M}"
```
```   399       using indep by (auto simp: indep_vars_def dest: measurable_space)
```
```   400     also have "\<dots> \<subseteq> {X i -` A \<inter> space M |A. A \<in> sets (N i)}"
```
```   401       using P[OF \<open>i \<in> I\<close>] by blast
```
```   402     finally show "{{x \<in> space M. P i (X i x)}} \<subseteq> {X i -` A \<inter> space M |A. A \<in> sets (N i)}" .
```
```   403   qed
```
```   404 qed
```
```   405
```
```   406 lemma (in prob_space) indep_sets_collect_sigma:
```
```   407   fixes I :: "'j \<Rightarrow> 'i set" and J :: "'j set" and E :: "'i \<Rightarrow> 'a set set"
```
```   408   assumes indep: "indep_sets E (\<Union>j\<in>J. I j)"
```
```   409   assumes Int_stable: "\<And>i j. j \<in> J \<Longrightarrow> i \<in> I j \<Longrightarrow> Int_stable (E i)"
```
```   410   assumes disjoint: "disjoint_family_on I J"
```
```   411   shows "indep_sets (\<lambda>j. sigma_sets (space M) (\<Union>i\<in>I j. E i)) J"
```
```   412 proof -
```
```   413   let ?E = "\<lambda>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) }"
```
```   414
```
```   415   from indep have E: "\<And>j i. j \<in> J \<Longrightarrow> i \<in> I j \<Longrightarrow> E i \<subseteq> events"
```
```   416     unfolding indep_sets_def by auto
```
```   417   { fix j
```
```   418     let ?S = "sigma_sets (space M) (\<Union>i\<in>I j. E i)"
```
```   419     assume "j \<in> J"
```
```   420     from E[OF this] interpret S: sigma_algebra "space M" ?S
```
```   421       using sets.sets_into_space[of _ M] by (intro sigma_algebra_sigma_sets) auto
```
```   422
```
```   423     have "sigma_sets (space M) (\<Union>i\<in>I j. E i) = sigma_sets (space M) (?E j)"
```
```   424     proof (rule sigma_sets_eqI)
```
```   425       fix A assume "A \<in> (\<Union>i\<in>I j. E i)"
```
```   426       then guess i ..
```
```   427       then show "A \<in> sigma_sets (space M) (?E j)"
```
```   428         by (auto intro!: sigma_sets.intros(2-) exI[of _ "{i}"] exI[of _ "\<lambda>i. A"])
```
```   429     next
```
```   430       fix A assume "A \<in> ?E j"
```
```   431       then obtain E' K where "finite K" "K \<noteq> {}" "K \<subseteq> I j" "\<And>k. k \<in> K \<Longrightarrow> E' k \<in> E k"
```
```   432         and A: "A = (\<Inter>k\<in>K. E' k)"
```
```   433         by auto
```
```   434       then have "A \<in> ?S" unfolding A
```
```   435         by (safe intro!: S.finite_INT) auto
```
```   436       then show "A \<in> sigma_sets (space M) (\<Union>i\<in>I j. E i)"
```
```   437         by simp
```
```   438     qed }
```
```   439   moreover have "indep_sets (\<lambda>j. sigma_sets (space M) (?E j)) J"
```
```   440   proof (rule indep_sets_sigma)
```
```   441     show "indep_sets ?E J"
```
```   442     proof (intro indep_setsI)
```
```   443       fix j assume "j \<in> J" with E show "?E j \<subseteq> events" by (force  intro!: sets.finite_INT)
```
```   444     next
```
```   445       fix K A assume K: "K \<noteq> {}" "K \<subseteq> J" "finite K"
```
```   446         and "\<forall>j\<in>K. A j \<in> ?E j"
```
```   447       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)"
```
```   448         by simp
```
```   449       from bchoice[OF this] guess E' ..
```
```   450       from bchoice[OF this] obtain L
```
```   451         where A: "\<And>j. j\<in>K \<Longrightarrow> A j = (\<Inter>l\<in>L j. E' j l)"
```
```   452         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"
```
```   453         and E': "\<And>j l. j\<in>K \<Longrightarrow> l \<in> L j \<Longrightarrow> E' j l \<in> E l"
```
```   454         by auto
```
```   455
```
```   456       { fix k l j assume "k \<in> K" "j \<in> K" "l \<in> L j" "l \<in> L k"
```
```   457         have "k = j"
```
```   458         proof (rule ccontr)
```
```   459           assume "k \<noteq> j"
```
```   460           with disjoint \<open>K \<subseteq> J\<close> \<open>k \<in> K\<close> \<open>j \<in> K\<close> have "I k \<inter> I j = {}"
```
```   461             unfolding disjoint_family_on_def by auto
```
```   462           with L(2,3)[OF \<open>j \<in> K\<close>] L(2,3)[OF \<open>k \<in> K\<close>]
```
```   463           show False using \<open>l \<in> L k\<close> \<open>l \<in> L j\<close> by auto
```
```   464         qed }
```
```   465       note L_inj = this
```
```   466
```
```   467       def k \<equiv> "\<lambda>l. (SOME k. k \<in> K \<and> l \<in> L k)"
```
```   468       { fix x j l assume *: "j \<in> K" "l \<in> L j"
```
```   469         have "k l = j" unfolding k_def
```
```   470         proof (rule some_equality)
```
```   471           fix k assume "k \<in> K \<and> l \<in> L k"
```
```   472           with * L_inj show "k = j" by auto
```
```   473         qed (insert *, simp) }
```
```   474       note k_simp[simp] = this
```
```   475       let ?E' = "\<lambda>l. E' (k l) l"
```
```   476       have "prob (\<Inter>j\<in>K. A j) = prob (\<Inter>l\<in>(\<Union>k\<in>K. L k). ?E' l)"
```
```   477         by (auto simp: A intro!: arg_cong[where f=prob])
```
```   478       also have "\<dots> = (\<Prod>l\<in>(\<Union>k\<in>K. L k). prob (?E' l))"
```
```   479         using L K E' by (intro indep_setsD[OF indep]) (simp_all add: UN_mono)
```
```   480       also have "\<dots> = (\<Prod>j\<in>K. \<Prod>l\<in>L j. prob (E' j l))"
```
```   481         using K L L_inj by (subst setprod.UNION_disjoint) auto
```
```   482       also have "\<dots> = (\<Prod>j\<in>K. prob (A j))"
```
```   483         using K L E' by (auto simp add: A intro!: setprod.cong indep_setsD[OF indep, symmetric]) blast
```
```   484       finally show "prob (\<Inter>j\<in>K. A j) = (\<Prod>j\<in>K. prob (A j))" .
```
```   485     qed
```
```   486   next
```
```   487     fix j assume "j \<in> J"
```
```   488     show "Int_stable (?E j)"
```
```   489     proof (rule Int_stableI)
```
```   490       fix a assume "a \<in> ?E j" then obtain Ka Ea
```
```   491         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
```
```   492       fix b assume "b \<in> ?E j" then obtain Kb Eb
```
```   493         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
```
```   494       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 {})"
```
```   495       have "a \<inter> b = INTER (Ka \<union> Kb) ?A"
```
```   496         by (simp add: a b set_eq_iff) auto
```
```   497       with a b \<open>j \<in> J\<close> Int_stableD[OF Int_stable] show "a \<inter> b \<in> ?E j"
```
```   498         by (intro CollectI exI[of _ "Ka \<union> Kb"] exI[of _ ?A]) auto
```
```   499     qed
```
```   500   qed
```
```   501   ultimately show ?thesis
```
```   502     by (simp cong: indep_sets_cong)
```
```   503 qed
```
```   504
```
```   505 lemma (in prob_space) indep_vars_restrict:
```
```   506   assumes ind: "indep_vars M' X I" and K: "\<And>j. j \<in> L \<Longrightarrow> K j \<subseteq> I" and J: "disjoint_family_on K L"
```
```   507   shows "indep_vars (\<lambda>j. PiM (K j) M') (\<lambda>j \<omega>. restrict (\<lambda>i. X i \<omega>) (K j)) L"
```
```   508   unfolding indep_vars_def
```
```   509 proof safe
```
```   510   fix j assume "j \<in> L" then show "random_variable (Pi\<^sub>M (K j) M') (\<lambda>\<omega>. \<lambda>i\<in>K j. X i \<omega>)"
```
```   511     using K ind by (auto simp: indep_vars_def intro!: measurable_restrict)
```
```   512 next
```
```   513   have X: "\<And>i. i \<in> I \<Longrightarrow> X i \<in> measurable M (M' i)"
```
```   514     using ind by (auto simp: indep_vars_def)
```
```   515   let ?proj = "\<lambda>j S. {(\<lambda>\<omega>. \<lambda>i\<in>K j. X i \<omega>) -` A \<inter> space M |A. A \<in> S}"
```
```   516   let ?UN = "\<lambda>j. sigma_sets (space M) (\<Union>i\<in>K j. { X i -` A \<inter> space M| A. A \<in> sets (M' i) })"
```
```   517   show "indep_sets (\<lambda>i. sigma_sets (space M) (?proj i (sets (Pi\<^sub>M (K i) M')))) L"
```
```   518   proof (rule indep_sets_mono_sets)
```
```   519     fix j assume j: "j \<in> L"
```
```   520     have "sigma_sets (space M) (?proj j (sets (Pi\<^sub>M (K j) M'))) =
```
```   521       sigma_sets (space M) (sigma_sets (space M) (?proj j (prod_algebra (K j) M')))"
```
```   522       using j K X[THEN measurable_space] unfolding sets_PiM
```
```   523       by (subst sigma_sets_vimage_commute) (auto simp add: Pi_iff)
```
```   524     also have "\<dots> = sigma_sets (space M) (?proj j (prod_algebra (K j) M'))"
```
```   525       by (rule sigma_sets_sigma_sets_eq) auto
```
```   526     also have "\<dots> \<subseteq> ?UN j"
```
```   527     proof (rule sigma_sets_mono, safe del: disjE elim!: prod_algebraE)
```
```   528       fix J E assume J: "finite J" "J \<noteq> {} \<or> K j = {}"  "J \<subseteq> K j" and E: "\<forall>i. i \<in> J \<longrightarrow> E i \<in> sets (M' i)"
```
```   529       show "(\<lambda>\<omega>. \<lambda>i\<in>K j. X i \<omega>) -` prod_emb (K j) M' J (Pi\<^sub>E J E) \<inter> space M \<in> ?UN j"
```
```   530       proof cases
```
```   531         assume "K j = {}" with J show ?thesis
```
```   532           by (auto simp add: sigma_sets_empty_eq prod_emb_def)
```
```   533       next
```
```   534         assume "K j \<noteq> {}" with J have "J \<noteq> {}"
```
```   535           by auto
```
```   536         { interpret sigma_algebra "space M" "?UN j"
```
```   537             by (rule sigma_algebra_sigma_sets) auto
```
```   538           have "\<And>A. (\<And>i. i \<in> J \<Longrightarrow> A i \<in> ?UN j) \<Longrightarrow> INTER J A \<in> ?UN j"
```
```   539             using \<open>finite J\<close> \<open>J \<noteq> {}\<close> by (rule finite_INT) blast }
```
```   540         note INT = this
```
```   541
```
```   542         from \<open>J \<noteq> {}\<close> J K E[rule_format, THEN sets.sets_into_space] j
```
```   543         have "(\<lambda>\<omega>. \<lambda>i\<in>K j. X i \<omega>) -` prod_emb (K j) M' J (Pi\<^sub>E J E) \<inter> space M
```
```   544           = (\<Inter>i\<in>J. X i -` E i \<inter> space M)"
```
```   545           apply (subst prod_emb_PiE[OF _ ])
```
```   546           apply auto []
```
```   547           apply auto []
```
```   548           apply (auto simp add: Pi_iff intro!: X[THEN measurable_space])
```
```   549           apply (erule_tac x=i in ballE)
```
```   550           apply auto
```
```   551           done
```
```   552         also have "\<dots> \<in> ?UN j"
```
```   553           apply (rule INT)
```
```   554           apply (rule sigma_sets.Basic)
```
```   555           using \<open>J \<subseteq> K j\<close> E
```
```   556           apply auto
```
```   557           done
```
```   558         finally show ?thesis .
```
```   559       qed
```
```   560     qed
```
```   561     finally show "sigma_sets (space M) (?proj j (sets (Pi\<^sub>M (K j) M'))) \<subseteq> ?UN j" .
```
```   562   next
```
```   563     show "indep_sets ?UN L"
```
```   564     proof (rule indep_sets_collect_sigma)
```
```   565       show "indep_sets (\<lambda>i. {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) (\<Union>j\<in>L. K j)"
```
```   566       proof (rule indep_sets_mono_index)
```
```   567         show "indep_sets (\<lambda>i. {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) I"
```
```   568           using ind unfolding indep_vars_def2 by auto
```
```   569         show "(\<Union>l\<in>L. K l) \<subseteq> I"
```
```   570           using K by auto
```
```   571       qed
```
```   572     next
```
```   573       fix l i assume "l \<in> L" "i \<in> K l"
```
```   574       show "Int_stable {X i -` A \<inter> space M |A. A \<in> sets (M' i)}"
```
```   575         apply (auto simp: Int_stable_def)
```
```   576         apply (rule_tac x="A \<inter> Aa" in exI)
```
```   577         apply auto
```
```   578         done
```
```   579     qed fact
```
```   580   qed
```
```   581 qed
```
```   582
```
```   583 lemma (in prob_space) indep_var_restrict:
```
```   584   assumes ind: "indep_vars M' X I" and AB: "A \<inter> B = {}" "A \<subseteq> I" "B \<subseteq> I"
```
```   585   shows "indep_var (PiM A M') (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) A) (PiM B M') (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) B)"
```
```   586 proof -
```
```   587   have *:
```
```   588     "case_bool (Pi\<^sub>M A M') (Pi\<^sub>M B M') = (\<lambda>b. PiM (case_bool A B b) M')"
```
```   589     "case_bool (\<lambda>\<omega>. \<lambda>i\<in>A. X i \<omega>) (\<lambda>\<omega>. \<lambda>i\<in>B. X i \<omega>) = (\<lambda>b \<omega>. \<lambda>i\<in>case_bool A B b. X i \<omega>)"
```
```   590     by (simp_all add: fun_eq_iff split: bool.split)
```
```   591   show ?thesis
```
```   592     unfolding indep_var_def * using AB
```
```   593     by (intro indep_vars_restrict[OF ind]) (auto simp: disjoint_family_on_def split: bool.split)
```
```   594 qed
```
```   595
```
```   596 lemma (in prob_space) indep_vars_subset:
```
```   597   assumes "indep_vars M' X I" "J \<subseteq> I"
```
```   598   shows "indep_vars M' X J"
```
```   599   using assms unfolding indep_vars_def indep_sets_def
```
```   600   by auto
```
```   601
```
```   602 lemma (in prob_space) indep_vars_cong:
```
```   603   "I = J \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> X i = Y i) \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> M' i = N' i) \<Longrightarrow> indep_vars M' X I \<longleftrightarrow> indep_vars N' Y J"
```
```   604   unfolding indep_vars_def2 by (intro conj_cong indep_sets_cong) auto
```
```   605
```
```   606 definition (in prob_space) tail_events where
```
```   607   "tail_events A = (\<Inter>n. sigma_sets (space M) (UNION {n..} A))"
```
```   608
```
```   609 lemma (in prob_space) tail_events_sets:
```
```   610   assumes A: "\<And>i::nat. A i \<subseteq> events"
```
```   611   shows "tail_events A \<subseteq> events"
```
```   612 proof
```
```   613   fix X assume X: "X \<in> tail_events A"
```
```   614   let ?A = "(\<Inter>n. sigma_sets (space M) (UNION {n..} A))"
```
```   615   from X have "\<And>n::nat. X \<in> sigma_sets (space M) (UNION {n..} A)" by (auto simp: tail_events_def)
```
```   616   from this[of 0] have "X \<in> sigma_sets (space M) (UNION UNIV A)" by simp
```
```   617   then show "X \<in> events"
```
```   618     by induct (insert A, auto)
```
```   619 qed
```
```   620
```
```   621 lemma (in prob_space) sigma_algebra_tail_events:
```
```   622   assumes "\<And>i::nat. sigma_algebra (space M) (A i)"
```
```   623   shows "sigma_algebra (space M) (tail_events A)"
```
```   624   unfolding tail_events_def
```
```   625 proof (simp add: sigma_algebra_iff2, safe)
```
```   626   let ?A = "(\<Inter>n. sigma_sets (space M) (UNION {n..} A))"
```
```   627   interpret A: sigma_algebra "space M" "A i" for i by fact
```
```   628   { fix X x assume "X \<in> ?A" "x \<in> X"
```
```   629     then have "\<And>n. X \<in> sigma_sets (space M) (UNION {n..} A)" by auto
```
```   630     from this[of 0] have "X \<in> sigma_sets (space M) (UNION UNIV A)" by simp
```
```   631     then have "X \<subseteq> space M"
```
```   632       by induct (insert A.sets_into_space, auto)
```
```   633     with \<open>x \<in> X\<close> show "x \<in> space M" by auto }
```
```   634   { fix F :: "nat \<Rightarrow> 'a set" and n assume "range F \<subseteq> ?A"
```
```   635     then show "(UNION UNIV F) \<in> sigma_sets (space M) (UNION {n..} A)"
```
```   636       by (intro sigma_sets.Union) auto }
```
```   637 qed (auto intro!: sigma_sets.Compl sigma_sets.Empty)
```
```   638
```
```   639 lemma (in prob_space) kolmogorov_0_1_law:
```
```   640   fixes A :: "nat \<Rightarrow> 'a set set"
```
```   641   assumes "\<And>i::nat. sigma_algebra (space M) (A i)"
```
```   642   assumes indep: "indep_sets A UNIV"
```
```   643   and X: "X \<in> tail_events A"
```
```   644   shows "prob X = 0 \<or> prob X = 1"
```
```   645 proof -
```
```   646   have A: "\<And>i. A i \<subseteq> events"
```
```   647     using indep unfolding indep_sets_def by simp
```
```   648
```
```   649   let ?D = "{D \<in> events. prob (X \<inter> D) = prob X * prob D}"
```
```   650   interpret A: sigma_algebra "space M" "A i" for i by fact
```
```   651   interpret T: sigma_algebra "space M" "tail_events A"
```
```   652     by (rule sigma_algebra_tail_events) fact
```
```   653   have "X \<subseteq> space M" using T.space_closed X by auto
```
```   654
```
```   655   have X_in: "X \<in> events"
```
```   656     using tail_events_sets A X by auto
```
```   657
```
```   658   interpret D: dynkin_system "space M" ?D
```
```   659   proof (rule dynkin_systemI)
```
```   660     fix D assume "D \<in> ?D" then show "D \<subseteq> space M"
```
```   661       using sets.sets_into_space by auto
```
```   662   next
```
```   663     show "space M \<in> ?D"
```
```   664       using prob_space \<open>X \<subseteq> space M\<close> by (simp add: Int_absorb2)
```
```   665   next
```
```   666     fix A assume A: "A \<in> ?D"
```
```   667     have "prob (X \<inter> (space M - A)) = prob (X - (X \<inter> A))"
```
```   668       using \<open>X \<subseteq> space M\<close> by (auto intro!: arg_cong[where f=prob])
```
```   669     also have "\<dots> = prob X - prob (X \<inter> A)"
```
```   670       using X_in A by (intro finite_measure_Diff) auto
```
```   671     also have "\<dots> = prob X * prob (space M) - prob X * prob A"
```
```   672       using A prob_space by auto
```
```   673     also have "\<dots> = prob X * prob (space M - A)"
```
```   674       using X_in A sets.sets_into_space
```
```   675       by (subst finite_measure_Diff) (auto simp: field_simps)
```
```   676     finally show "space M - A \<in> ?D"
```
```   677       using A \<open>X \<subseteq> space M\<close> by auto
```
```   678   next
```
```   679     fix F :: "nat \<Rightarrow> 'a set" assume dis: "disjoint_family F" and "range F \<subseteq> ?D"
```
```   680     then have F: "range F \<subseteq> events" "\<And>i. prob (X \<inter> F i) = prob X * prob (F i)"
```
```   681       by auto
```
```   682     have "(\<lambda>i. prob (X \<inter> F i)) sums prob (\<Union>i. X \<inter> F i)"
```
```   683     proof (rule finite_measure_UNION)
```
```   684       show "range (\<lambda>i. X \<inter> F i) \<subseteq> events"
```
```   685         using F X_in by auto
```
```   686       show "disjoint_family (\<lambda>i. X \<inter> F i)"
```
```   687         using dis by (rule disjoint_family_on_bisimulation) auto
```
```   688     qed
```
```   689     with F have "(\<lambda>i. prob X * prob (F i)) sums prob (X \<inter> (\<Union>i. F i))"
```
```   690       by simp
```
```   691     moreover have "(\<lambda>i. prob X * prob (F i)) sums (prob X * prob (\<Union>i. F i))"
```
```   692       by (intro sums_mult finite_measure_UNION F dis)
```
```   693     ultimately have "prob (X \<inter> (\<Union>i. F i)) = prob X * prob (\<Union>i. F i)"
```
```   694       by (auto dest!: sums_unique)
```
```   695     with F show "(\<Union>i. F i) \<in> ?D"
```
```   696       by auto
```
```   697   qed
```
```   698
```
```   699   { fix n
```
```   700     have "indep_sets (\<lambda>b. sigma_sets (space M) (\<Union>m\<in>case_bool {..n} {Suc n..} b. A m)) UNIV"
```
```   701     proof (rule indep_sets_collect_sigma)
```
```   702       have *: "(\<Union>b. case b of True \<Rightarrow> {..n} | False \<Rightarrow> {Suc n..}) = UNIV" (is "?U = _")
```
```   703         by (simp split: bool.split add: set_eq_iff) (metis not_less_eq_eq)
```
```   704       with indep show "indep_sets A ?U" by simp
```
```   705       show "disjoint_family (case_bool {..n} {Suc n..})"
```
```   706         unfolding disjoint_family_on_def by (auto split: bool.split)
```
```   707       fix m
```
```   708       show "Int_stable (A m)"
```
```   709         unfolding Int_stable_def using A.Int by auto
```
```   710     qed
```
```   711     also have "(\<lambda>b. sigma_sets (space M) (\<Union>m\<in>case_bool {..n} {Suc n..} b. A m)) =
```
```   712       case_bool (sigma_sets (space M) (\<Union>m\<in>{..n}. A m)) (sigma_sets (space M) (\<Union>m\<in>{Suc n..}. A m))"
```
```   713       by (auto intro!: ext split: bool.split)
```
```   714     finally have indep: "indep_set (sigma_sets (space M) (\<Union>m\<in>{..n}. A m)) (sigma_sets (space M) (\<Union>m\<in>{Suc n..}. A m))"
```
```   715       unfolding indep_set_def by simp
```
```   716
```
```   717     have "sigma_sets (space M) (\<Union>m\<in>{..n}. A m) \<subseteq> ?D"
```
```   718     proof (simp add: subset_eq, rule)
```
```   719       fix D assume D: "D \<in> sigma_sets (space M) (\<Union>m\<in>{..n}. A m)"
```
```   720       have "X \<in> sigma_sets (space M) (\<Union>m\<in>{Suc n..}. A m)"
```
```   721         using X unfolding tail_events_def by simp
```
```   722       from indep_setD[OF indep D this] indep_setD_ev1[OF indep] D
```
```   723       show "D \<in> events \<and> prob (X \<inter> D) = prob X * prob D"
```
```   724         by (auto simp add: ac_simps)
```
```   725     qed }
```
```   726   then have "(\<Union>n. sigma_sets (space M) (\<Union>m\<in>{..n}. A m)) \<subseteq> ?D" (is "?A \<subseteq> _")
```
```   727     by auto
```
```   728
```
```   729   note \<open>X \<in> tail_events A\<close>
```
```   730   also {
```
```   731     have "\<And>n. sigma_sets (space M) (\<Union>i\<in>{n..}. A i) \<subseteq> sigma_sets (space M) ?A"
```
```   732       by (intro sigma_sets_subseteq UN_mono) auto
```
```   733    then have "tail_events A \<subseteq> sigma_sets (space M) ?A"
```
```   734       unfolding tail_events_def by auto }
```
```   735   also have "sigma_sets (space M) ?A = dynkin (space M) ?A"
```
```   736   proof (rule sigma_eq_dynkin)
```
```   737     { fix B n assume "B \<in> sigma_sets (space M) (\<Union>m\<in>{..n}. A m)"
```
```   738       then have "B \<subseteq> space M"
```
```   739         by induct (insert A sets.sets_into_space[of _ M], auto) }
```
```   740     then show "?A \<subseteq> Pow (space M)" by auto
```
```   741     show "Int_stable ?A"
```
```   742     proof (rule Int_stableI)
```
```   743       fix a assume "a \<in> ?A" then guess n .. note a = this
```
```   744       fix b assume "b \<in> ?A" then guess m .. note b = this
```
```   745       interpret Amn: sigma_algebra "space M" "sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)"
```
```   746         using A sets.sets_into_space[of _ M] by (intro sigma_algebra_sigma_sets) auto
```
```   747       have "sigma_sets (space M) (\<Union>i\<in>{..n}. A i) \<subseteq> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)"
```
```   748         by (intro sigma_sets_subseteq UN_mono) auto
```
```   749       with a have "a \<in> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)" by auto
```
```   750       moreover
```
```   751       have "sigma_sets (space M) (\<Union>i\<in>{..m}. A i) \<subseteq> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)"
```
```   752         by (intro sigma_sets_subseteq UN_mono) auto
```
```   753       with b have "b \<in> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)" by auto
```
```   754       ultimately have "a \<inter> b \<in> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)"
```
```   755         using Amn.Int[of a b] by simp
```
```   756       then show "a \<inter> b \<in> (\<Union>n. sigma_sets (space M) (\<Union>i\<in>{..n}. A i))" by auto
```
```   757     qed
```
```   758   qed
```
```   759   also have "dynkin (space M) ?A \<subseteq> ?D"
```
```   760     using \<open>?A \<subseteq> ?D\<close> by (auto intro!: D.dynkin_subset)
```
```   761   finally show ?thesis by auto
```
```   762 qed
```
```   763
```
```   764 lemma (in prob_space) borel_0_1_law:
```
```   765   fixes F :: "nat \<Rightarrow> 'a set"
```
```   766   assumes F2: "indep_events F UNIV"
```
```   767   shows "prob (\<Inter>n. \<Union>m\<in>{n..}. F m) = 0 \<or> prob (\<Inter>n. \<Union>m\<in>{n..}. F m) = 1"
```
```   768 proof (rule kolmogorov_0_1_law[of "\<lambda>i. sigma_sets (space M) { F i }"])
```
```   769   have F1: "range F \<subseteq> events"
```
```   770     using F2 by (simp add: indep_events_def subset_eq)
```
```   771   { fix i show "sigma_algebra (space M) (sigma_sets (space M) {F i})"
```
```   772       using sigma_algebra_sigma_sets[of "{F i}" "space M"] F1 sets.sets_into_space
```
```   773       by auto }
```
```   774   show "indep_sets (\<lambda>i. sigma_sets (space M) {F i}) UNIV"
```
```   775   proof (rule indep_sets_sigma)
```
```   776     show "indep_sets (\<lambda>i. {F i}) UNIV"
```
```   777       unfolding indep_events_def_alt[symmetric] by fact
```
```   778     fix i show "Int_stable {F i}"
```
```   779       unfolding Int_stable_def by simp
```
```   780   qed
```
```   781   let ?Q = "\<lambda>n. \<Union>i\<in>{n..}. F i"
```
```   782   show "(\<Inter>n. \<Union>m\<in>{n..}. F m) \<in> tail_events (\<lambda>i. sigma_sets (space M) {F i})"
```
```   783     unfolding tail_events_def
```
```   784   proof
```
```   785     fix j
```
```   786     interpret S: sigma_algebra "space M" "sigma_sets (space M) (\<Union>i\<in>{j..}. sigma_sets (space M) {F i})"
```
```   787       using order_trans[OF F1 sets.space_closed]
```
```   788       by (intro sigma_algebra_sigma_sets) (simp add: sigma_sets_singleton subset_eq)
```
```   789     have "(\<Inter>n. ?Q n) = (\<Inter>n\<in>{j..}. ?Q n)"
```
```   790       by (intro decseq_SucI INT_decseq_offset UN_mono) auto
```
```   791     also have "\<dots> \<in> sigma_sets (space M) (\<Union>i\<in>{j..}. sigma_sets (space M) {F i})"
```
```   792       using order_trans[OF F1 sets.space_closed]
```
```   793       by (safe intro!: S.countable_INT S.countable_UN)
```
```   794          (auto simp: sigma_sets_singleton intro!: sigma_sets.Basic bexI)
```
```   795     finally show "(\<Inter>n. ?Q n) \<in> sigma_sets (space M) (\<Union>i\<in>{j..}. sigma_sets (space M) {F i})"
```
```   796       by simp
```
```   797   qed
```
```   798 qed
```
```   799
```
```   800 lemma (in prob_space) borel_0_1_law_AE:
```
```   801   fixes P :: "nat \<Rightarrow> 'a \<Rightarrow> bool"
```
```   802   assumes "indep_events (\<lambda>m. {x\<in>space M. P m x}) UNIV" (is "indep_events ?P _")
```
```   803   shows "(AE x in M. infinite {m. P m x}) \<or> (AE x in M. finite {m. P m x})"
```
```   804 proof -
```
```   805   have [measurable]: "\<And>m. {x\<in>space M. P m x} \<in> sets M"
```
```   806     using assms by (auto simp: indep_events_def)
```
```   807   have "prob (\<Inter>n. \<Union>m\<in>{n..}. ?P m) = 0 \<or> prob (\<Inter>n. \<Union>m\<in>{n..}. ?P m) = 1"
```
```   808     by (rule borel_0_1_law) fact
```
```   809   also have "prob (\<Inter>n. \<Union>m\<in>{n..}. ?P m) = 0 \<longleftrightarrow> (AE x in M. finite {m. P m x})"
```
```   810     by (subst prob_eq_0) (auto simp add: finite_nat_iff_bounded Ball_def not_less[symmetric])
```
```   811   also have "prob (\<Inter>n. \<Union>m\<in>{n..}. ?P m) = 1 \<longleftrightarrow> (AE x in M. infinite {m. P m x})"
```
```   812     by (subst prob_eq_1) (simp_all add: Bex_def infinite_nat_iff_unbounded_le)
```
```   813   finally show ?thesis
```
```   814     by metis
```
```   815 qed
```
```   816
```
```   817 lemma (in prob_space) indep_sets_finite:
```
```   818   assumes I: "I \<noteq> {}" "finite I"
```
```   819     and F: "\<And>i. i \<in> I \<Longrightarrow> F i \<subseteq> events" "\<And>i. i \<in> I \<Longrightarrow> space M \<in> F i"
```
```   820   shows "indep_sets F I \<longleftrightarrow> (\<forall>A\<in>Pi I F. prob (\<Inter>j\<in>I. A j) = (\<Prod>j\<in>I. prob (A j)))"
```
```   821 proof
```
```   822   assume *: "indep_sets F I"
```
```   823   from I show "\<forall>A\<in>Pi I F. prob (\<Inter>j\<in>I. A j) = (\<Prod>j\<in>I. prob (A j))"
```
```   824     by (intro indep_setsD[OF *] ballI) auto
```
```   825 next
```
```   826   assume indep: "\<forall>A\<in>Pi I F. prob (\<Inter>j\<in>I. A j) = (\<Prod>j\<in>I. prob (A j))"
```
```   827   show "indep_sets F I"
```
```   828   proof (rule indep_setsI[OF F(1)])
```
```   829     fix A J assume J: "J \<noteq> {}" "J \<subseteq> I" "finite J"
```
```   830     assume A: "\<forall>j\<in>J. A j \<in> F j"
```
```   831     let ?A = "\<lambda>j. if j \<in> J then A j else space M"
```
```   832     have "prob (\<Inter>j\<in>I. ?A j) = prob (\<Inter>j\<in>J. A j)"
```
```   833       using subset_trans[OF F(1) sets.space_closed] J A
```
```   834       by (auto intro!: arg_cong[where f=prob] split: split_if_asm) blast
```
```   835     also
```
```   836     from A F have "(\<lambda>j. if j \<in> J then A j else space M) \<in> Pi I F" (is "?A \<in> _")
```
```   837       by (auto split: split_if_asm)
```
```   838     with indep have "prob (\<Inter>j\<in>I. ?A j) = (\<Prod>j\<in>I. prob (?A j))"
```
```   839       by auto
```
```   840     also have "\<dots> = (\<Prod>j\<in>J. prob (A j))"
```
```   841       unfolding if_distrib setprod.If_cases[OF \<open>finite I\<close>]
```
```   842       using prob_space \<open>J \<subseteq> I\<close> by (simp add: Int_absorb1 setprod.neutral_const)
```
```   843     finally show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))" ..
```
```   844   qed
```
```   845 qed
```
```   846
```
```   847 lemma (in prob_space) indep_vars_finite:
```
```   848   fixes I :: "'i set"
```
```   849   assumes I: "I \<noteq> {}" "finite I"
```
```   850     and M': "\<And>i. i \<in> I \<Longrightarrow> sets (M' i) = sigma_sets (space (M' i)) (E i)"
```
```   851     and rv: "\<And>i. i \<in> I \<Longrightarrow> random_variable (M' i) (X i)"
```
```   852     and Int_stable: "\<And>i. i \<in> I \<Longrightarrow> Int_stable (E i)"
```
```   853     and space: "\<And>i. i \<in> I \<Longrightarrow> space (M' i) \<in> E i" and closed: "\<And>i. i \<in> I \<Longrightarrow> E i \<subseteq> Pow (space (M' i))"
```
```   854   shows "indep_vars M' X I \<longleftrightarrow>
```
```   855     (\<forall>A\<in>(\<Pi> i\<in>I. E i). prob (\<Inter>j\<in>I. X j -` A j \<inter> space M) = (\<Prod>j\<in>I. prob (X j -` A j \<inter> space M)))"
```
```   856 proof -
```
```   857   from rv have X: "\<And>i. i \<in> I \<Longrightarrow> X i \<in> space M \<rightarrow> space (M' i)"
```
```   858     unfolding measurable_def by simp
```
```   859
```
```   860   { fix i assume "i\<in>I"
```
```   861     from closed[OF \<open>i \<in> I\<close>]
```
```   862     have "sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}
```
```   863       = sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> E i}"
```
```   864       unfolding sigma_sets_vimage_commute[OF X, OF \<open>i \<in> I\<close>, symmetric] M'[OF \<open>i \<in> I\<close>]
```
```   865       by (subst sigma_sets_sigma_sets_eq) auto }
```
```   866   note sigma_sets_X = this
```
```   867
```
```   868   { fix i assume "i\<in>I"
```
```   869     have "Int_stable {X i -` A \<inter> space M |A. A \<in> E i}"
```
```   870     proof (rule Int_stableI)
```
```   871       fix a assume "a \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
```
```   872       then obtain A where "a = X i -` A \<inter> space M" "A \<in> E i" by auto
```
```   873       moreover
```
```   874       fix b assume "b \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
```
```   875       then obtain B where "b = X i -` B \<inter> space M" "B \<in> E i" by auto
```
```   876       moreover
```
```   877       have "(X i -` A \<inter> space M) \<inter> (X i -` B \<inter> space M) = X i -` (A \<inter> B) \<inter> space M" by auto
```
```   878       moreover note Int_stable[OF \<open>i \<in> I\<close>]
```
```   879       ultimately
```
```   880       show "a \<inter> b \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
```
```   881         by (auto simp del: vimage_Int intro!: exI[of _ "A \<inter> B"] dest: Int_stableD)
```
```   882     qed }
```
```   883   note indep_sets_X = indep_sets_sigma_sets_iff[OF this]
```
```   884
```
```   885   { fix i assume "i \<in> I"
```
```   886     { fix A assume "A \<in> E i"
```
```   887       with M'[OF \<open>i \<in> I\<close>] have "A \<in> sets (M' i)" by auto
```
```   888       moreover
```
```   889       from rv[OF \<open>i\<in>I\<close>] have "X i \<in> measurable M (M' i)" by auto
```
```   890       ultimately
```
```   891       have "X i -` A \<inter> space M \<in> sets M" by (auto intro: measurable_sets) }
```
```   892     with X[OF \<open>i\<in>I\<close>] space[OF \<open>i\<in>I\<close>]
```
```   893     have "{X i -` A \<inter> space M |A. A \<in> E i} \<subseteq> events"
```
```   894       "space M \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
```
```   895       by (auto intro!: exI[of _ "space (M' i)"]) }
```
```   896   note indep_sets_finite_X = indep_sets_finite[OF I this]
```
```   897
```
```   898   have "(\<forall>A\<in>\<Pi> i\<in>I. {X i -` A \<inter> space M |A. A \<in> E i}. prob (INTER I A) = (\<Prod>j\<in>I. prob (A j))) =
```
```   899     (\<forall>A\<in>\<Pi> i\<in>I. E i. prob ((\<Inter>j\<in>I. X j -` A j) \<inter> space M) = (\<Prod>x\<in>I. prob (X x -` A x \<inter> space M)))"
```
```   900     (is "?L = ?R")
```
```   901   proof safe
```
```   902     fix A assume ?L and A: "A \<in> (\<Pi> i\<in>I. E i)"
```
```   903     from \<open>?L\<close>[THEN bspec, of "\<lambda>i. X i -` A i \<inter> space M"] A \<open>I \<noteq> {}\<close>
```
```   904     show "prob ((\<Inter>j\<in>I. X j -` A j) \<inter> space M) = (\<Prod>x\<in>I. prob (X x -` A x \<inter> space M))"
```
```   905       by (auto simp add: Pi_iff)
```
```   906   next
```
```   907     fix A assume ?R and A: "A \<in> (\<Pi> i\<in>I. {X i -` A \<inter> space M |A. A \<in> E i})"
```
```   908     from A have "\<forall>i\<in>I. \<exists>B. A i = X i -` B \<inter> space M \<and> B \<in> E i" by auto
```
```   909     from bchoice[OF this] obtain B where B: "\<forall>i\<in>I. A i = X i -` B i \<inter> space M"
```
```   910       "B \<in> (\<Pi> i\<in>I. E i)" by auto
```
```   911     from \<open>?R\<close>[THEN bspec, OF B(2)] B(1) \<open>I \<noteq> {}\<close>
```
```   912     show "prob (INTER I A) = (\<Prod>j\<in>I. prob (A j))"
```
```   913       by simp
```
```   914   qed
```
```   915   then show ?thesis using \<open>I \<noteq> {}\<close>
```
```   916     by (simp add: rv indep_vars_def indep_sets_X sigma_sets_X indep_sets_finite_X cong: indep_sets_cong)
```
```   917 qed
```
```   918
```
```   919 lemma (in prob_space) indep_vars_compose:
```
```   920   assumes "indep_vars M' X I"
```
```   921   assumes rv: "\<And>i. i \<in> I \<Longrightarrow> Y i \<in> measurable (M' i) (N i)"
```
```   922   shows "indep_vars N (\<lambda>i. Y i \<circ> X i) I"
```
```   923   unfolding indep_vars_def
```
```   924 proof
```
```   925   from rv \<open>indep_vars M' X I\<close>
```
```   926   show "\<forall>i\<in>I. random_variable (N i) (Y i \<circ> X i)"
```
```   927     by (auto simp: indep_vars_def)
```
```   928
```
```   929   have "indep_sets (\<lambda>i. sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) I"
```
```   930     using \<open>indep_vars M' X I\<close> by (simp add: indep_vars_def)
```
```   931   then show "indep_sets (\<lambda>i. sigma_sets (space M) {(Y i \<circ> X i) -` A \<inter> space M |A. A \<in> sets (N i)}) I"
```
```   932   proof (rule indep_sets_mono_sets)
```
```   933     fix i assume "i \<in> I"
```
```   934     with \<open>indep_vars M' X I\<close> have X: "X i \<in> space M \<rightarrow> space (M' i)"
```
```   935       unfolding indep_vars_def measurable_def by auto
```
```   936     { fix A assume "A \<in> sets (N i)"
```
```   937       then have "\<exists>B. (Y i \<circ> X i) -` A \<inter> space M = X i -` B \<inter> space M \<and> B \<in> sets (M' i)"
```
```   938         by (intro exI[of _ "Y i -` A \<inter> space (M' i)"])
```
```   939            (auto simp: vimage_comp intro!: measurable_sets rv \<open>i \<in> I\<close> funcset_mem[OF X]) }
```
```   940     then show "sigma_sets (space M) {(Y i \<circ> X i) -` A \<inter> space M |A. A \<in> sets (N i)} \<subseteq>
```
```   941       sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}"
```
```   942       by (intro sigma_sets_subseteq) (auto simp: vimage_comp)
```
```   943   qed
```
```   944 qed
```
```   945
```
```   946 lemma (in prob_space) indep_vars_compose2:
```
```   947   assumes "indep_vars M' X I"
```
```   948   assumes rv: "\<And>i. i \<in> I \<Longrightarrow> Y i \<in> measurable (M' i) (N i)"
```
```   949   shows "indep_vars N (\<lambda>i x. Y i (X i x)) I"
```
```   950   using indep_vars_compose [OF assms] by (simp add: comp_def)
```
```   951
```
```   952 lemma (in prob_space) indep_var_compose:
```
```   953   assumes "indep_var M1 X1 M2 X2" "Y1 \<in> measurable M1 N1" "Y2 \<in> measurable M2 N2"
```
```   954   shows "indep_var N1 (Y1 \<circ> X1) N2 (Y2 \<circ> X2)"
```
```   955 proof -
```
```   956   have "indep_vars (case_bool N1 N2) (\<lambda>b. case_bool Y1 Y2 b \<circ> case_bool X1 X2 b) UNIV"
```
```   957     using assms
```
```   958     by (intro indep_vars_compose[where M'="case_bool M1 M2"])
```
```   959        (auto simp: indep_var_def split: bool.split)
```
```   960   also have "(\<lambda>b. case_bool Y1 Y2 b \<circ> case_bool X1 X2 b) = case_bool (Y1 \<circ> X1) (Y2 \<circ> X2)"
```
```   961     by (simp add: fun_eq_iff split: bool.split)
```
```   962   finally show ?thesis
```
```   963     unfolding indep_var_def .
```
```   964 qed
```
```   965
```
```   966 lemma (in prob_space) indep_vars_Min:
```
```   967   fixes X :: "'i \<Rightarrow> 'a \<Rightarrow> real"
```
```   968   assumes I: "finite I" "i \<notin> I" and indep: "indep_vars (\<lambda>_. borel) X (insert i I)"
```
```   969   shows "indep_var borel (X i) borel (\<lambda>\<omega>. Min ((\<lambda>i. X i \<omega>)`I))"
```
```   970 proof -
```
```   971   have "indep_var
```
```   972     borel ((\<lambda>f. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) {i}))
```
```   973     borel ((\<lambda>f. Min (f`I)) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) I))"
```
```   974     using I by (intro indep_var_compose[OF indep_var_restrict[OF indep]] borel_measurable_Min) auto
```
```   975   also have "((\<lambda>f. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) {i})) = X i"
```
```   976     by auto
```
```   977   also have "((\<lambda>f. Min (f`I)) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) I)) = (\<lambda>\<omega>. Min ((\<lambda>i. X i \<omega>)`I))"
```
```   978     by (auto cong: rev_conj_cong)
```
```   979   finally show ?thesis
```
```   980     unfolding indep_var_def .
```
```   981 qed
```
```   982
```
```   983 lemma (in prob_space) indep_vars_setsum:
```
```   984   fixes X :: "'i \<Rightarrow> 'a \<Rightarrow> real"
```
```   985   assumes I: "finite I" "i \<notin> I" and indep: "indep_vars (\<lambda>_. borel) X (insert i I)"
```
```   986   shows "indep_var borel (X i) borel (\<lambda>\<omega>. \<Sum>i\<in>I. X i \<omega>)"
```
```   987 proof -
```
```   988   have "indep_var
```
```   989     borel ((\<lambda>f. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) {i}))
```
```   990     borel ((\<lambda>f. \<Sum>i\<in>I. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) I))"
```
```   991     using I by (intro indep_var_compose[OF indep_var_restrict[OF indep]] ) auto
```
```   992   also have "((\<lambda>f. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) {i})) = X i"
```
```   993     by auto
```
```   994   also have "((\<lambda>f. \<Sum>i\<in>I. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) I)) = (\<lambda>\<omega>. \<Sum>i\<in>I. X i \<omega>)"
```
```   995     by (auto cong: rev_conj_cong)
```
```   996   finally show ?thesis .
```
```   997 qed
```
```   998
```
```   999 lemma (in prob_space) indep_vars_setprod:
```
```  1000   fixes X :: "'i \<Rightarrow> 'a \<Rightarrow> real"
```
```  1001   assumes I: "finite I" "i \<notin> I" and indep: "indep_vars (\<lambda>_. borel) X (insert i I)"
```
```  1002   shows "indep_var borel (X i) borel (\<lambda>\<omega>. \<Prod>i\<in>I. X i \<omega>)"
```
```  1003 proof -
```
```  1004   have "indep_var
```
```  1005     borel ((\<lambda>f. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) {i}))
```
```  1006     borel ((\<lambda>f. \<Prod>i\<in>I. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) I))"
```
```  1007     using I by (intro indep_var_compose[OF indep_var_restrict[OF indep]] ) auto
```
```  1008   also have "((\<lambda>f. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) {i})) = X i"
```
```  1009     by auto
```
```  1010   also have "((\<lambda>f. \<Prod>i\<in>I. f i) \<circ> (\<lambda>\<omega>. restrict (\<lambda>i. X i \<omega>) I)) = (\<lambda>\<omega>. \<Prod>i\<in>I. X i \<omega>)"
```
```  1011     by (auto cong: rev_conj_cong)
```
```  1012   finally show ?thesis .
```
```  1013 qed
```
```  1014
```
```  1015 lemma (in prob_space) indep_varsD_finite:
```
```  1016   assumes X: "indep_vars M' X I"
```
```  1017   assumes I: "I \<noteq> {}" "finite I" "\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M' i)"
```
```  1018   shows "prob (\<Inter>i\<in>I. X i -` A i \<inter> space M) = (\<Prod>i\<in>I. prob (X i -` A i \<inter> space M))"
```
```  1019 proof (rule indep_setsD)
```
```  1020   show "indep_sets (\<lambda>i. sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) I"
```
```  1021     using X by (auto simp: indep_vars_def)
```
```  1022   show "I \<subseteq> I" "I \<noteq> {}" "finite I" using I by auto
```
```  1023   show "\<forall>i\<in>I. X i -` A i \<inter> space M \<in> sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}"
```
```  1024     using I by auto
```
```  1025 qed
```
```  1026
```
```  1027 lemma (in prob_space) indep_varsD:
```
```  1028   assumes X: "indep_vars M' X I"
```
```  1029   assumes I: "J \<noteq> {}" "finite J" "J \<subseteq> I" "\<And>i. i \<in> J \<Longrightarrow> A i \<in> sets (M' i)"
```
```  1030   shows "prob (\<Inter>i\<in>J. X i -` A i \<inter> space M) = (\<Prod>i\<in>J. prob (X i -` A i \<inter> space M))"
```
```  1031 proof (rule indep_setsD)
```
```  1032   show "indep_sets (\<lambda>i. sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) I"
```
```  1033     using X by (auto simp: indep_vars_def)
```
```  1034   show "\<forall>i\<in>J. X i -` A i \<inter> space M \<in> sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}"
```
```  1035     using I by auto
```
```  1036 qed fact+
```
```  1037
```
```  1038 lemma (in prob_space) indep_vars_iff_distr_eq_PiM:
```
```  1039   fixes I :: "'i set" and X :: "'i \<Rightarrow> 'a \<Rightarrow> 'b"
```
```  1040   assumes "I \<noteq> {}"
```
```  1041   assumes rv: "\<And>i. random_variable (M' i) (X i)"
```
```  1042   shows "indep_vars M' X I \<longleftrightarrow>
```
```  1043     distr M (\<Pi>\<^sub>M i\<in>I. M' i) (\<lambda>x. \<lambda>i\<in>I. X i x) = (\<Pi>\<^sub>M i\<in>I. distr M (M' i) (X i))"
```
```  1044 proof -
```
```  1045   let ?P = "\<Pi>\<^sub>M i\<in>I. M' i"
```
```  1046   let ?X = "\<lambda>x. \<lambda>i\<in>I. X i x"
```
```  1047   let ?D = "distr M ?P ?X"
```
```  1048   have X: "random_variable ?P ?X" by (intro measurable_restrict rv)
```
```  1049   interpret D: prob_space ?D by (intro prob_space_distr X)
```
```  1050
```
```  1051   let ?D' = "\<lambda>i. distr M (M' i) (X i)"
```
```  1052   let ?P' = "\<Pi>\<^sub>M i\<in>I. distr M (M' i) (X i)"
```
```  1053   interpret D': prob_space "?D' i" for i by (intro prob_space_distr rv)
```
```  1054   interpret P: product_prob_space ?D' I ..
```
```  1055
```
```  1056   show ?thesis
```
```  1057   proof
```
```  1058     assume "indep_vars M' X I"
```
```  1059     show "?D = ?P'"
```
```  1060     proof (rule measure_eqI_generator_eq)
```
```  1061       show "Int_stable (prod_algebra I M')"
```
```  1062         by (rule Int_stable_prod_algebra)
```
```  1063       show "prod_algebra I M' \<subseteq> Pow (space ?P)"
```
```  1064         using prod_algebra_sets_into_space by (simp add: space_PiM)
```
```  1065       show "sets ?D = sigma_sets (space ?P) (prod_algebra I M')"
```
```  1066         by (simp add: sets_PiM space_PiM)
```
```  1067       show "sets ?P' = sigma_sets (space ?P) (prod_algebra I M')"
```
```  1068         by (simp add: sets_PiM space_PiM cong: prod_algebra_cong)
```
```  1069       let ?A = "\<lambda>i. \<Pi>\<^sub>E i\<in>I. space (M' i)"
```
```  1070       show "range ?A \<subseteq> prod_algebra I M'" "(\<Union>i. ?A i) = space (Pi\<^sub>M I M')"
```
```  1071         by (auto simp: space_PiM intro!: space_in_prod_algebra cong: prod_algebra_cong)
```
```  1072       { fix i show "emeasure ?D (\<Pi>\<^sub>E i\<in>I. space (M' i)) \<noteq> \<infinity>" by auto }
```
```  1073     next
```
```  1074       fix E assume E: "E \<in> prod_algebra I M'"
```
```  1075       from prod_algebraE[OF E] guess J Y . note J = this
```
```  1076
```
```  1077       from E have "E \<in> sets ?P" by (auto simp: sets_PiM)
```
```  1078       then have "emeasure ?D E = emeasure M (?X -` E \<inter> space M)"
```
```  1079         by (simp add: emeasure_distr X)
```
```  1080       also have "?X -` E \<inter> space M = (\<Inter>i\<in>J. X i -` Y i \<inter> space M)"
```
```  1081         using J \<open>I \<noteq> {}\<close> measurable_space[OF rv] by (auto simp: prod_emb_def PiE_iff split: split_if_asm)
```
```  1082       also have "emeasure M (\<Inter>i\<in>J. X i -` Y i \<inter> space M) = (\<Prod> i\<in>J. emeasure M (X i -` Y i \<inter> space M))"
```
```  1083         using \<open>indep_vars M' X I\<close> J \<open>I \<noteq> {}\<close> using indep_varsD[of M' X I J]
```
```  1084         by (auto simp: emeasure_eq_measure setprod_ereal)
```
```  1085       also have "\<dots> = (\<Prod> i\<in>J. emeasure (?D' i) (Y i))"
```
```  1086         using rv J by (simp add: emeasure_distr)
```
```  1087       also have "\<dots> = emeasure ?P' E"
```
```  1088         using P.emeasure_PiM_emb[of J Y] J by (simp add: prod_emb_def)
```
```  1089       finally show "emeasure ?D E = emeasure ?P' E" .
```
```  1090     qed
```
```  1091   next
```
```  1092     assume "?D = ?P'"
```
```  1093     show "indep_vars M' X I" unfolding indep_vars_def
```
```  1094     proof (intro conjI indep_setsI ballI rv)
```
```  1095       fix i show "sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)} \<subseteq> events"
```
```  1096         by (auto intro!: sets.sigma_sets_subset measurable_sets rv)
```
```  1097     next
```
```  1098       fix J Y' assume J: "J \<noteq> {}" "J \<subseteq> I" "finite J"
```
```  1099       assume Y': "\<forall>j\<in>J. Y' j \<in> sigma_sets (space M) {X j -` A \<inter> space M |A. A \<in> sets (M' j)}"
```
```  1100       have "\<forall>j\<in>J. \<exists>Y. Y' j = X j -` Y \<inter> space M \<and> Y \<in> sets (M' j)"
```
```  1101       proof
```
```  1102         fix j assume "j \<in> J"
```
```  1103         from Y'[rule_format, OF this] rv[of j]
```
```  1104         show "\<exists>Y. Y' j = X j -` Y \<inter> space M \<and> Y \<in> sets (M' j)"
```
```  1105           by (subst (asm) sigma_sets_vimage_commute[symmetric, of _ _ "space (M' j)"])
```
```  1106              (auto dest: measurable_space simp: sets.sigma_sets_eq)
```
```  1107       qed
```
```  1108       from bchoice[OF this] obtain Y where
```
```  1109         Y: "\<And>j. j \<in> J \<Longrightarrow> Y' j = X j -` Y j \<inter> space M" "\<And>j. j \<in> J \<Longrightarrow> Y j \<in> sets (M' j)" by auto
```
```  1110       let ?E = "prod_emb I M' J (Pi\<^sub>E J Y)"
```
```  1111       from Y have "(\<Inter>j\<in>J. Y' j) = ?X -` ?E \<inter> space M"
```
```  1112         using J \<open>I \<noteq> {}\<close> measurable_space[OF rv] by (auto simp: prod_emb_def PiE_iff split: split_if_asm)
```
```  1113       then have "emeasure M (\<Inter>j\<in>J. Y' j) = emeasure M (?X -` ?E \<inter> space M)"
```
```  1114         by simp
```
```  1115       also have "\<dots> = emeasure ?D ?E"
```
```  1116         using Y  J by (intro emeasure_distr[symmetric] X sets_PiM_I) auto
```
```  1117       also have "\<dots> = emeasure ?P' ?E"
```
```  1118         using \<open>?D = ?P'\<close> by simp
```
```  1119       also have "\<dots> = (\<Prod> i\<in>J. emeasure (?D' i) (Y i))"
```
```  1120         using P.emeasure_PiM_emb[of J Y] J Y by (simp add: prod_emb_def)
```
```  1121       also have "\<dots> = (\<Prod> i\<in>J. emeasure M (Y' i))"
```
```  1122         using rv J Y by (simp add: emeasure_distr)
```
```  1123       finally have "emeasure M (\<Inter>j\<in>J. Y' j) = (\<Prod> i\<in>J. emeasure M (Y' i))" .
```
```  1124       then show "prob (\<Inter>j\<in>J. Y' j) = (\<Prod> i\<in>J. prob (Y' i))"
```
```  1125         by (auto simp: emeasure_eq_measure setprod_ereal)
```
```  1126     qed
```
```  1127   qed
```
```  1128 qed
```
```  1129
```
```  1130 lemma (in prob_space) indep_varD:
```
```  1131   assumes indep: "indep_var Ma A Mb B"
```
```  1132   assumes sets: "Xa \<in> sets Ma" "Xb \<in> sets Mb"
```
```  1133   shows "prob ((\<lambda>x. (A x, B x)) -` (Xa \<times> Xb) \<inter> space M) =
```
```  1134     prob (A -` Xa \<inter> space M) * prob (B -` Xb \<inter> space M)"
```
```  1135 proof -
```
```  1136   have "prob ((\<lambda>x. (A x, B x)) -` (Xa \<times> Xb) \<inter> space M) =
```
```  1137     prob (\<Inter>i\<in>UNIV. (case_bool A B i -` case_bool Xa Xb i \<inter> space M))"
```
```  1138     by (auto intro!: arg_cong[where f=prob] simp: UNIV_bool)
```
```  1139   also have "\<dots> = (\<Prod>i\<in>UNIV. prob (case_bool A B i -` case_bool Xa Xb i \<inter> space M))"
```
```  1140     using indep unfolding indep_var_def
```
```  1141     by (rule indep_varsD) (auto split: bool.split intro: sets)
```
```  1142   also have "\<dots> = prob (A -` Xa \<inter> space M) * prob (B -` Xb \<inter> space M)"
```
```  1143     unfolding UNIV_bool by simp
```
```  1144   finally show ?thesis .
```
```  1145 qed
```
```  1146
```
```  1147 lemma (in prob_space) prob_indep_random_variable:
```
```  1148   assumes ind[simp]: "indep_var N X N Y"
```
```  1149   assumes [simp]: "A \<in> sets N" "B \<in> sets N"
```
```  1150   shows "\<P>(x in M. X x \<in> A \<and> Y x \<in> B) = \<P>(x in M. X x \<in> A) * \<P>(x in M. Y x \<in> B)"
```
```  1151 proof-
```
```  1152   have  " \<P>(x in M. (X x)\<in>A \<and>  (Y x)\<in> B ) = prob ((\<lambda>x. (X x, Y x)) -` (A \<times> B) \<inter> space M)"
```
```  1153     by (auto intro!: arg_cong[where f= prob])
```
```  1154   also have "...=  prob (X -` A \<inter> space M) * prob (Y -` B \<inter> space M)"
```
```  1155     by (auto intro!: indep_varD[where Ma=N and Mb=N])
```
```  1156   also have "... = \<P>(x in M. X x \<in> A) * \<P>(x in M. Y x \<in> B)"
```
```  1157     by (auto intro!: arg_cong2[where f= "op *"] arg_cong[where f= prob])
```
```  1158   finally show ?thesis .
```
```  1159 qed
```
```  1160
```
```  1161 lemma (in prob_space)
```
```  1162   assumes "indep_var S X T Y"
```
```  1163   shows indep_var_rv1: "random_variable S X"
```
```  1164     and indep_var_rv2: "random_variable T Y"
```
```  1165 proof -
```
```  1166   have "\<forall>i\<in>UNIV. random_variable (case_bool S T i) (case_bool X Y i)"
```
```  1167     using assms unfolding indep_var_def indep_vars_def by auto
```
```  1168   then show "random_variable S X" "random_variable T Y"
```
```  1169     unfolding UNIV_bool by auto
```
```  1170 qed
```
```  1171
```
```  1172 lemma (in prob_space) indep_var_distribution_eq:
```
```  1173   "indep_var S X T Y \<longleftrightarrow> random_variable S X \<and> random_variable T Y \<and>
```
```  1174     distr M S X \<Otimes>\<^sub>M distr M T Y = distr M (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x))" (is "_ \<longleftrightarrow> _ \<and> _ \<and> ?S \<Otimes>\<^sub>M ?T = ?J")
```
```  1175 proof safe
```
```  1176   assume "indep_var S X T Y"
```
```  1177   then show rvs: "random_variable S X" "random_variable T Y"
```
```  1178     by (blast dest: indep_var_rv1 indep_var_rv2)+
```
```  1179   then have XY: "random_variable (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x))"
```
```  1180     by (rule measurable_Pair)
```
```  1181
```
```  1182   interpret X: prob_space ?S by (rule prob_space_distr) fact
```
```  1183   interpret Y: prob_space ?T by (rule prob_space_distr) fact
```
```  1184   interpret XY: pair_prob_space ?S ?T ..
```
```  1185   show "?S \<Otimes>\<^sub>M ?T = ?J"
```
```  1186   proof (rule pair_measure_eqI)
```
```  1187     show "sigma_finite_measure ?S" ..
```
```  1188     show "sigma_finite_measure ?T" ..
```
```  1189
```
```  1190     fix A B assume A: "A \<in> sets ?S" and B: "B \<in> sets ?T"
```
```  1191     have "emeasure ?J (A \<times> B) = emeasure M ((\<lambda>x. (X x, Y x)) -` (A \<times> B) \<inter> space M)"
```
```  1192       using A B by (intro emeasure_distr[OF XY]) auto
```
```  1193     also have "\<dots> = emeasure M (X -` A \<inter> space M) * emeasure M (Y -` B \<inter> space M)"
```
```  1194       using indep_varD[OF \<open>indep_var S X T Y\<close>, of A B] A B by (simp add: emeasure_eq_measure)
```
```  1195     also have "\<dots> = emeasure ?S A * emeasure ?T B"
```
```  1196       using rvs A B by (simp add: emeasure_distr)
```
```  1197     finally show "emeasure ?S A * emeasure ?T B = emeasure ?J (A \<times> B)" by simp
```
```  1198   qed simp
```
```  1199 next
```
```  1200   assume rvs: "random_variable S X" "random_variable T Y"
```
```  1201   then have XY: "random_variable (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x))"
```
```  1202     by (rule measurable_Pair)
```
```  1203
```
```  1204   let ?S = "distr M S X" and ?T = "distr M T Y"
```
```  1205   interpret X: prob_space ?S by (rule prob_space_distr) fact
```
```  1206   interpret Y: prob_space ?T by (rule prob_space_distr) fact
```
```  1207   interpret XY: pair_prob_space ?S ?T ..
```
```  1208
```
```  1209   assume "?S \<Otimes>\<^sub>M ?T = ?J"
```
```  1210
```
```  1211   { fix S and X
```
```  1212     have "Int_stable {X -` A \<inter> space M |A. A \<in> sets S}"
```
```  1213     proof (safe intro!: Int_stableI)
```
```  1214       fix A B assume "A \<in> sets S" "B \<in> sets S"
```
```  1215       then show "\<exists>C. (X -` A \<inter> space M) \<inter> (X -` B \<inter> space M) = (X -` C \<inter> space M) \<and> C \<in> sets S"
```
```  1216         by (intro exI[of _ "A \<inter> B"]) auto
```
```  1217     qed }
```
```  1218   note Int_stable = this
```
```  1219
```
```  1220   show "indep_var S X T Y" unfolding indep_var_eq
```
```  1221   proof (intro conjI indep_set_sigma_sets Int_stable rvs)
```
```  1222     show "indep_set {X -` A \<inter> space M |A. A \<in> sets S} {Y -` A \<inter> space M |A. A \<in> sets T}"
```
```  1223     proof (safe intro!: indep_setI)
```
```  1224       { fix A assume "A \<in> sets S" then show "X -` A \<inter> space M \<in> sets M"
```
```  1225         using \<open>X \<in> measurable M S\<close> by (auto intro: measurable_sets) }
```
```  1226       { fix A assume "A \<in> sets T" then show "Y -` A \<inter> space M \<in> sets M"
```
```  1227         using \<open>Y \<in> measurable M T\<close> by (auto intro: measurable_sets) }
```
```  1228     next
```
```  1229       fix A B assume ab: "A \<in> sets S" "B \<in> sets T"
```
```  1230       then have "ereal (prob ((X -` A \<inter> space M) \<inter> (Y -` B \<inter> space M))) = emeasure ?J (A \<times> B)"
```
```  1231         using XY by (auto simp add: emeasure_distr emeasure_eq_measure intro!: arg_cong[where f="prob"])
```
```  1232       also have "\<dots> = emeasure (?S \<Otimes>\<^sub>M ?T) (A \<times> B)"
```
```  1233         unfolding \<open>?S \<Otimes>\<^sub>M ?T = ?J\<close> ..
```
```  1234       also have "\<dots> = emeasure ?S A * emeasure ?T B"
```
```  1235         using ab by (simp add: Y.emeasure_pair_measure_Times)
```
```  1236       finally show "prob ((X -` A \<inter> space M) \<inter> (Y -` B \<inter> space M)) =
```
```  1237         prob (X -` A \<inter> space M) * prob (Y -` B \<inter> space M)"
```
```  1238         using rvs ab by (simp add: emeasure_eq_measure emeasure_distr)
```
```  1239     qed
```
```  1240   qed
```
```  1241 qed
```
```  1242
```
```  1243 lemma (in prob_space) distributed_joint_indep:
```
```  1244   assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
```
```  1245   assumes X: "distributed M S X Px" and Y: "distributed M T Y Py"
```
```  1246   assumes indep: "indep_var S X T Y"
```
```  1247   shows "distributed M (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x)) (\<lambda>(x, y). Px x * Py y)"
```
```  1248   using indep_var_distribution_eq[of S X T Y] indep
```
```  1249   by (intro distributed_joint_indep'[OF S T X Y]) auto
```
```  1250
```
```  1251 lemma (in prob_space) indep_vars_nn_integral:
```
```  1252   assumes I: "finite I" "indep_vars (\<lambda>_. borel) X I" "\<And>i \<omega>. i \<in> I \<Longrightarrow> 0 \<le> X i \<omega>"
```
```  1253   shows "(\<integral>\<^sup>+\<omega>. (\<Prod>i\<in>I. X i \<omega>) \<partial>M) = (\<Prod>i\<in>I. \<integral>\<^sup>+\<omega>. X i \<omega> \<partial>M)"
```
```  1254 proof cases
```
```  1255   assume "I \<noteq> {}"
```
```  1256   def Y \<equiv> "\<lambda>i \<omega>. if i \<in> I then X i \<omega> else 0"
```
```  1257   { fix i have "i \<in> I \<Longrightarrow> random_variable borel (X i)"
```
```  1258     using I(2) by (cases "i\<in>I") (auto simp: indep_vars_def) }
```
```  1259   note rv_X = this
```
```  1260
```
```  1261   { fix i have "random_variable borel (Y i)"
```
```  1262     using I(2) by (cases "i\<in>I") (auto simp: Y_def rv_X) }
```
```  1263   note rv_Y = this[measurable]
```
```  1264
```
```  1265   interpret Y: prob_space "distr M borel (Y i)" for i
```
```  1266     using I(2) by (cases "i \<in> I") (auto intro!: prob_space_distr simp: indep_vars_def prob_space_return)
```
```  1267   interpret product_sigma_finite "\<lambda>i. distr M borel (Y i)"
```
```  1268     ..
```
```  1269
```
```  1270   have indep_Y: "indep_vars (\<lambda>i. borel) Y I"
```
```  1271     by (rule indep_vars_cong[THEN iffD1, OF _ _ _ I(2)]) (auto simp: Y_def)
```
```  1272
```
```  1273   have "(\<integral>\<^sup>+\<omega>. (\<Prod>i\<in>I. X i \<omega>) \<partial>M) = (\<integral>\<^sup>+\<omega>. (\<Prod>i\<in>I. max 0 (Y i \<omega>)) \<partial>M)"
```
```  1274     using I(3) by (auto intro!: nn_integral_cong setprod.cong simp add: Y_def max_def)
```
```  1275   also have "\<dots> = (\<integral>\<^sup>+\<omega>. (\<Prod>i\<in>I. max 0 (\<omega> i)) \<partial>distr M (Pi\<^sub>M I (\<lambda>i. borel)) (\<lambda>x. \<lambda>i\<in>I. Y i x))"
```
```  1276     by (subst nn_integral_distr) auto
```
```  1277   also have "\<dots> = (\<integral>\<^sup>+\<omega>. (\<Prod>i\<in>I. max 0 (\<omega> i)) \<partial>Pi\<^sub>M I (\<lambda>i. distr M borel (Y i)))"
```
```  1278     unfolding indep_vars_iff_distr_eq_PiM[THEN iffD1, OF \<open>I \<noteq> {}\<close> rv_Y indep_Y] ..
```
```  1279   also have "\<dots> = (\<Prod>i\<in>I. (\<integral>\<^sup>+\<omega>. max 0 \<omega> \<partial>distr M borel (Y i)))"
```
```  1280     by (rule product_nn_integral_setprod) (auto intro: \<open>finite I\<close>)
```
```  1281   also have "\<dots> = (\<Prod>i\<in>I. \<integral>\<^sup>+\<omega>. X i \<omega> \<partial>M)"
```
```  1282     by (intro setprod.cong nn_integral_cong)
```
```  1283        (auto simp: nn_integral_distr nn_integral_max_0 Y_def rv_X)
```
```  1284   finally show ?thesis .
```
```  1285 qed (simp add: emeasure_space_1)
```
```  1286
```
```  1287 lemma (in prob_space)
```
```  1288   fixes X :: "'i \<Rightarrow> 'a \<Rightarrow> 'b::{real_normed_field, banach, second_countable_topology}"
```
```  1289   assumes I: "finite I" "indep_vars (\<lambda>_. borel) X I" "\<And>i. i \<in> I \<Longrightarrow> integrable M (X i)"
```
```  1290   shows indep_vars_lebesgue_integral: "(\<integral>\<omega>. (\<Prod>i\<in>I. X i \<omega>) \<partial>M) = (\<Prod>i\<in>I. \<integral>\<omega>. X i \<omega> \<partial>M)" (is ?eq)
```
```  1291     and indep_vars_integrable: "integrable M (\<lambda>\<omega>. (\<Prod>i\<in>I. X i \<omega>))" (is ?int)
```
```  1292 proof (induct rule: case_split)
```
```  1293   assume "I \<noteq> {}"
```
```  1294   def Y \<equiv> "\<lambda>i \<omega>. if i \<in> I then X i \<omega> else 0"
```
```  1295   { fix i have "i \<in> I \<Longrightarrow> random_variable borel (X i)"
```
```  1296     using I(2) by (cases "i\<in>I") (auto simp: indep_vars_def) }
```
```  1297   note rv_X = this[measurable]
```
```  1298
```
```  1299   { fix i have "random_variable borel (Y i)"
```
```  1300     using I(2) by (cases "i\<in>I") (auto simp: Y_def rv_X) }
```
```  1301   note rv_Y = this[measurable]
```
```  1302
```
```  1303   { fix i have "integrable M (Y i)"
```
```  1304     using I(3) by (cases "i\<in>I") (auto simp: Y_def) }
```
```  1305   note int_Y = this
```
```  1306
```
```  1307   interpret Y: prob_space "distr M borel (Y i)" for i
```
```  1308     using I(2) by (cases "i \<in> I") (auto intro!: prob_space_distr simp: indep_vars_def prob_space_return)
```
```  1309   interpret product_sigma_finite "\<lambda>i. distr M borel (Y i)"
```
```  1310     ..
```
```  1311
```
```  1312   have indep_Y: "indep_vars (\<lambda>i. borel) Y I"
```
```  1313     by (rule indep_vars_cong[THEN iffD1, OF _ _ _ I(2)]) (auto simp: Y_def)
```
```  1314
```
```  1315   have "(\<integral>\<omega>. (\<Prod>i\<in>I. X i \<omega>) \<partial>M) = (\<integral>\<omega>. (\<Prod>i\<in>I. Y i \<omega>) \<partial>M)"
```
```  1316     using I(3) by (simp add: Y_def)
```
```  1317   also have "\<dots> = (\<integral>\<omega>. (\<Prod>i\<in>I. \<omega> i) \<partial>distr M (Pi\<^sub>M I (\<lambda>i. borel)) (\<lambda>x. \<lambda>i\<in>I. Y i x))"
```
```  1318     by (subst integral_distr) auto
```
```  1319   also have "\<dots> = (\<integral>\<omega>. (\<Prod>i\<in>I. \<omega> i) \<partial>Pi\<^sub>M I (\<lambda>i. distr M borel (Y i)))"
```
```  1320     unfolding indep_vars_iff_distr_eq_PiM[THEN iffD1, OF \<open>I \<noteq> {}\<close> rv_Y indep_Y] ..
```
```  1321   also have "\<dots> = (\<Prod>i\<in>I. (\<integral>\<omega>. \<omega> \<partial>distr M borel (Y i)))"
```
```  1322     by (rule product_integral_setprod) (auto intro: \<open>finite I\<close> simp: integrable_distr_eq int_Y)
```
```  1323   also have "\<dots> = (\<Prod>i\<in>I. \<integral>\<omega>. X i \<omega> \<partial>M)"
```
```  1324     by (intro setprod.cong integral_cong)
```
```  1325        (auto simp: integral_distr Y_def rv_X)
```
```  1326   finally show ?eq .
```
```  1327
```
```  1328   have "integrable (distr M (Pi\<^sub>M I (\<lambda>i. borel)) (\<lambda>x. \<lambda>i\<in>I. Y i x)) (\<lambda>\<omega>. (\<Prod>i\<in>I. \<omega> i))"
```
```  1329     unfolding indep_vars_iff_distr_eq_PiM[THEN iffD1, OF \<open>I \<noteq> {}\<close> rv_Y indep_Y]
```
```  1330     by (intro product_integrable_setprod[OF \<open>finite I\<close>])
```
```  1331        (simp add: integrable_distr_eq int_Y)
```
```  1332   then show ?int
```
```  1333     by (simp add: integrable_distr_eq Y_def)
```
```  1334 qed (simp_all add: prob_space)
```
```  1335
```
```  1336 lemma (in prob_space)
```
```  1337   fixes X1 X2 :: "'a \<Rightarrow> 'b::{real_normed_field, banach, second_countable_topology}"
```
```  1338   assumes "indep_var borel X1 borel X2" "integrable M X1" "integrable M X2"
```
```  1339   shows indep_var_lebesgue_integral: "(\<integral>\<omega>. X1 \<omega> * X2 \<omega> \<partial>M) = (\<integral>\<omega>. X1 \<omega> \<partial>M) * (\<integral>\<omega>. X2 \<omega> \<partial>M)" (is ?eq)
```
```  1340     and indep_var_integrable: "integrable M (\<lambda>\<omega>. X1 \<omega> * X2 \<omega>)" (is ?int)
```
```  1341 unfolding indep_var_def
```
```  1342 proof -
```
```  1343   have *: "(\<lambda>\<omega>. X1 \<omega> * X2 \<omega>) = (\<lambda>\<omega>. \<Prod>i\<in>UNIV. (case_bool X1 X2 i \<omega>))"
```
```  1344     by (simp add: UNIV_bool mult.commute)
```
```  1345   have **: "(\<lambda> _. borel) = case_bool borel borel"
```
```  1346     by (rule ext, metis (full_types) bool.simps(3) bool.simps(4))
```
```  1347   show ?eq
```
```  1348     apply (subst *)
```
```  1349     apply (subst indep_vars_lebesgue_integral)
```
```  1350     apply (auto)
```
```  1351     apply (subst **, subst indep_var_def [symmetric], rule assms)
```
```  1352     apply (simp split: bool.split add: assms)
```
```  1353     by (simp add: UNIV_bool mult.commute)
```
```  1354   show ?int
```
```  1355     apply (subst *)
```
```  1356     apply (rule indep_vars_integrable)
```
```  1357     apply auto
```
```  1358     apply (subst **, subst indep_var_def [symmetric], rule assms)
```
```  1359     by (simp split: bool.split add: assms)
```
```  1360 qed
```
```  1361
```
```  1362 end
```