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