src/HOL/Probability/Independent_Family.thy
author haftmann
Sat Mar 15 08:31:33 2014 +0100 (2014-03-15)
changeset 56154 f0a927235162
parent 55414 eab03e9cee8a
child 57235 b0b9a10e4bf4
permissions -rw-r--r--
more complete set of lemmas wrt. image and composition
hoelzl@42861
     1
(*  Title:      HOL/Probability/Independent_Family.thy
hoelzl@42861
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42861
     3
*)
hoelzl@42861
     4
hoelzl@42861
     5
header {* Independent families of events, event sets, and random variables *}
hoelzl@42861
     6
hoelzl@42861
     7
theory Independent_Family
hoelzl@47694
     8
  imports Probability_Measure Infinite_Product_Measure
hoelzl@42861
     9
begin
hoelzl@42861
    10
hoelzl@42861
    11
definition (in prob_space)
hoelzl@42983
    12
  "indep_sets F I \<longleftrightarrow> (\<forall>i\<in>I. F i \<subseteq> events) \<and>
hoelzl@42981
    13
    (\<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
    14
hoelzl@42981
    15
definition (in prob_space)
blanchet@55414
    16
  "indep_set A B \<longleftrightarrow> indep_sets (case_bool A B) UNIV"
hoelzl@42861
    17
hoelzl@42861
    18
definition (in prob_space)
hoelzl@49784
    19
  indep_events_def_alt: "indep_events A I \<longleftrightarrow> indep_sets (\<lambda>i. {A i}) I"
hoelzl@49784
    20
hoelzl@49784
    21
lemma (in prob_space) indep_events_def:
hoelzl@49784
    22
  "indep_events A I \<longleftrightarrow> (A`I \<subseteq> events) \<and>
hoelzl@49784
    23
    (\<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
    24
  unfolding indep_events_def_alt indep_sets_def
hoelzl@49784
    25
  apply (simp add: Ball_def Pi_iff image_subset_iff_funcset)
hoelzl@49784
    26
  apply (intro conj_cong refl arg_cong[where f=All] ext imp_cong)
hoelzl@49784
    27
  apply auto
hoelzl@49784
    28
  done
hoelzl@49784
    29
hoelzl@49784
    30
definition (in prob_space)
blanchet@55414
    31
  "indep_event A B \<longleftrightarrow> indep_events (case_bool A B) UNIV"
hoelzl@49784
    32
hoelzl@47694
    33
lemma (in prob_space) indep_sets_cong:
hoelzl@42981
    34
  "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
    35
  by (simp add: indep_sets_def, intro conj_cong all_cong imp_cong ball_cong) blast+
hoelzl@42981
    36
hoelzl@42981
    37
lemma (in prob_space) indep_events_finite_index_events:
hoelzl@42981
    38
  "indep_events F I \<longleftrightarrow> (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_events F J)"
hoelzl@42981
    39
  by (auto simp: indep_events_def)
hoelzl@42981
    40
hoelzl@42861
    41
lemma (in prob_space) indep_sets_finite_index_sets:
hoelzl@42861
    42
  "indep_sets F I \<longleftrightarrow> (\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_sets F J)"
hoelzl@42861
    43
proof (intro iffI allI impI)
hoelzl@42861
    44
  assume *: "\<forall>J\<subseteq>I. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> indep_sets F J"
hoelzl@42861
    45
  show "indep_sets F I" unfolding indep_sets_def
hoelzl@42861
    46
  proof (intro conjI ballI allI impI)
hoelzl@42861
    47
    fix i assume "i \<in> I"
hoelzl@42861
    48
    with *[THEN spec, of "{i}"] show "F i \<subseteq> events"
hoelzl@42861
    49
      by (auto simp: indep_sets_def)
hoelzl@42861
    50
  qed (insert *, auto simp: indep_sets_def)
hoelzl@42861
    51
qed (auto simp: indep_sets_def)
hoelzl@42861
    52
hoelzl@42861
    53
lemma (in prob_space) indep_sets_mono_index:
hoelzl@42861
    54
  "J \<subseteq> I \<Longrightarrow> indep_sets F I \<Longrightarrow> indep_sets F J"
hoelzl@42861
    55
  unfolding indep_sets_def by auto
hoelzl@42861
    56
hoelzl@42861
    57
lemma (in prob_space) indep_sets_mono_sets:
hoelzl@42861
    58
  assumes indep: "indep_sets F I"
hoelzl@42861
    59
  assumes mono: "\<And>i. i\<in>I \<Longrightarrow> G i \<subseteq> F i"
hoelzl@42861
    60
  shows "indep_sets G I"
hoelzl@42861
    61
proof -
hoelzl@42861
    62
  have "(\<forall>i\<in>I. F i \<subseteq> events) \<Longrightarrow> (\<forall>i\<in>I. G i \<subseteq> events)"
hoelzl@42861
    63
    using mono by auto
hoelzl@42861
    64
  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
    65
    using mono by (auto simp: Pi_iff)
hoelzl@42861
    66
  ultimately show ?thesis
hoelzl@42861
    67
    using indep by (auto simp: indep_sets_def)
hoelzl@42861
    68
qed
hoelzl@42861
    69
hoelzl@49772
    70
lemma (in prob_space) indep_sets_mono:
hoelzl@49772
    71
  assumes indep: "indep_sets F I"
hoelzl@49772
    72
  assumes mono: "J \<subseteq> I" "\<And>i. i\<in>J \<Longrightarrow> G i \<subseteq> F i"
hoelzl@49772
    73
  shows "indep_sets G J"
hoelzl@49772
    74
  apply (rule indep_sets_mono_sets)
hoelzl@49772
    75
  apply (rule indep_sets_mono_index)
hoelzl@49772
    76
  apply (fact +)
hoelzl@49772
    77
  done
hoelzl@49772
    78
hoelzl@42861
    79
lemma (in prob_space) indep_setsI:
hoelzl@42861
    80
  assumes "\<And>i. i \<in> I \<Longrightarrow> F i \<subseteq> events"
hoelzl@42861
    81
    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
    82
  shows "indep_sets F I"
hoelzl@42861
    83
  using assms unfolding indep_sets_def by (auto simp: Pi_iff)
hoelzl@42861
    84
hoelzl@42861
    85
lemma (in prob_space) indep_setsD:
hoelzl@42861
    86
  assumes "indep_sets F I" and "J \<subseteq> I" "J \<noteq> {}" "finite J" "\<forall>j\<in>J. A j \<in> F j"
hoelzl@42861
    87
  shows "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861
    88
  using assms unfolding indep_sets_def by auto
hoelzl@42861
    89
hoelzl@42982
    90
lemma (in prob_space) indep_setI:
hoelzl@42982
    91
  assumes ev: "A \<subseteq> events" "B \<subseteq> events"
hoelzl@42982
    92
    and indep: "\<And>a b. a \<in> A \<Longrightarrow> b \<in> B \<Longrightarrow> prob (a \<inter> b) = prob a * prob b"
hoelzl@42982
    93
  shows "indep_set A B"
hoelzl@42982
    94
  unfolding indep_set_def
hoelzl@42982
    95
proof (rule indep_setsI)
hoelzl@42982
    96
  fix F J assume "J \<noteq> {}" "J \<subseteq> UNIV"
hoelzl@42982
    97
    and F: "\<forall>j\<in>J. F j \<in> (case j of True \<Rightarrow> A | False \<Rightarrow> B)"
hoelzl@42982
    98
  have "J \<in> Pow UNIV" by auto
hoelzl@42982
    99
  with F `J \<noteq> {}` indep[of "F True" "F False"]
hoelzl@42982
   100
  show "prob (\<Inter>j\<in>J. F j) = (\<Prod>j\<in>J. prob (F j))"
hoelzl@42982
   101
    unfolding UNIV_bool Pow_insert by (auto simp: ac_simps)
hoelzl@42982
   102
qed (auto split: bool.split simp: ev)
hoelzl@42982
   103
hoelzl@42982
   104
lemma (in prob_space) indep_setD:
hoelzl@42982
   105
  assumes indep: "indep_set A B" and ev: "a \<in> A" "b \<in> B"
hoelzl@42982
   106
  shows "prob (a \<inter> b) = prob a * prob b"
blanchet@55414
   107
  using indep[unfolded indep_set_def, THEN indep_setsD, of UNIV "case_bool a b"] ev
hoelzl@42982
   108
  by (simp add: ac_simps UNIV_bool)
hoelzl@42982
   109
hoelzl@42982
   110
lemma (in prob_space)
hoelzl@42982
   111
  assumes indep: "indep_set A B"
hoelzl@42983
   112
  shows indep_setD_ev1: "A \<subseteq> events"
hoelzl@42983
   113
    and indep_setD_ev2: "B \<subseteq> events"
hoelzl@42982
   114
  using indep unfolding indep_set_def indep_sets_def UNIV_bool by auto
hoelzl@42982
   115
hoelzl@42861
   116
lemma (in prob_space) indep_sets_dynkin:
hoelzl@42861
   117
  assumes indep: "indep_sets F I"
hoelzl@47694
   118
  shows "indep_sets (\<lambda>i. dynkin (space M) (F i)) I"
hoelzl@42861
   119
    (is "indep_sets ?F I")
hoelzl@42861
   120
proof (subst indep_sets_finite_index_sets, intro allI impI ballI)
hoelzl@42861
   121
  fix J assume "finite J" "J \<subseteq> I" "J \<noteq> {}"
hoelzl@42861
   122
  with indep have "indep_sets F J"
hoelzl@42861
   123
    by (subst (asm) indep_sets_finite_index_sets) auto
hoelzl@42861
   124
  { fix J K assume "indep_sets F K"
wenzelm@46731
   125
    let ?G = "\<lambda>S i. if i \<in> S then ?F i else F i"
hoelzl@42861
   126
    assume "finite J" "J \<subseteq> K"
hoelzl@42861
   127
    then have "indep_sets (?G J) K"
hoelzl@42861
   128
    proof induct
hoelzl@42861
   129
      case (insert j J)
hoelzl@42861
   130
      moreover def G \<equiv> "?G J"
hoelzl@42861
   131
      ultimately have G: "indep_sets G K" "\<And>i. i \<in> K \<Longrightarrow> G i \<subseteq> events" and "j \<in> K"
hoelzl@42861
   132
        by (auto simp: indep_sets_def)
hoelzl@42861
   133
      let ?D = "{E\<in>events. indep_sets (G(j := {E})) K }"
hoelzl@42861
   134
      { fix X assume X: "X \<in> events"
hoelzl@42861
   135
        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
   136
          \<Longrightarrow> prob ((\<Inter>i\<in>J. A i) \<inter> X) = prob X * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861
   137
        have "indep_sets (G(j := {X})) K"
hoelzl@42861
   138
        proof (rule indep_setsI)
hoelzl@42861
   139
          fix i assume "i \<in> K" then show "(G(j:={X})) i \<subseteq> events"
hoelzl@42861
   140
            using G X by auto
hoelzl@42861
   141
        next
hoelzl@42861
   142
          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
   143
          show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861
   144
          proof cases
hoelzl@42861
   145
            assume "j \<in> J"
hoelzl@42861
   146
            with J have "A j = X" by auto
hoelzl@42861
   147
            show ?thesis
hoelzl@42861
   148
            proof cases
hoelzl@42861
   149
              assume "J = {j}" then show ?thesis by simp
hoelzl@42861
   150
            next
hoelzl@42861
   151
              assume "J \<noteq> {j}"
hoelzl@42861
   152
              have "prob (\<Inter>i\<in>J. A i) = prob ((\<Inter>i\<in>J-{j}. A i) \<inter> X)"
hoelzl@42861
   153
                using `j \<in> J` `A j = X` by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
hoelzl@42861
   154
              also have "\<dots> = prob X * (\<Prod>i\<in>J-{j}. prob (A i))"
hoelzl@42861
   155
              proof (rule indep)
hoelzl@42861
   156
                show "J - {j} \<noteq> {}" "J - {j} \<subseteq> K" "finite (J - {j})" "j \<notin> J - {j}"
hoelzl@42861
   157
                  using J `J \<noteq> {j}` `j \<in> J` by auto
hoelzl@42861
   158
                show "\<forall>i\<in>J - {j}. A i \<in> G i"
hoelzl@42861
   159
                  using J by auto
hoelzl@42861
   160
              qed
hoelzl@42861
   161
              also have "\<dots> = prob (A j) * (\<Prod>i\<in>J-{j}. prob (A i))"
hoelzl@42861
   162
                using `A j = X` by simp
hoelzl@42861
   163
              also have "\<dots> = (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861
   164
                unfolding setprod.insert_remove[OF `finite J`, symmetric, of "\<lambda>i. prob  (A i)"]
hoelzl@42861
   165
                using `j \<in> J` by (simp add: insert_absorb)
hoelzl@42861
   166
              finally show ?thesis .
hoelzl@42861
   167
            qed
hoelzl@42861
   168
          next
hoelzl@42861
   169
            assume "j \<notin> J"
hoelzl@42861
   170
            with J have "\<forall>i\<in>J. A i \<in> G i" by (auto split: split_if_asm)
hoelzl@42861
   171
            with J show ?thesis
hoelzl@42861
   172
              by (intro indep_setsD[OF G(1)]) auto
hoelzl@42861
   173
          qed
hoelzl@42861
   174
        qed }
hoelzl@42861
   175
      note indep_sets_insert = this
hoelzl@47694
   176
      have "dynkin_system (space M) ?D"
hoelzl@42987
   177
      proof (rule dynkin_systemI', simp_all cong del: indep_sets_cong, safe)
hoelzl@42861
   178
        show "indep_sets (G(j := {{}})) K"
hoelzl@42861
   179
          by (rule indep_sets_insert) auto
hoelzl@42861
   180
      next
hoelzl@42861
   181
        fix X assume X: "X \<in> events" and G': "indep_sets (G(j := {X})) K"
hoelzl@42861
   182
        show "indep_sets (G(j := {space M - X})) K"
hoelzl@42861
   183
        proof (rule indep_sets_insert)
hoelzl@42861
   184
          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
   185
          then have A_sets: "\<And>i. i\<in>J \<Longrightarrow> A i \<in> events"
hoelzl@42861
   186
            using G by auto
hoelzl@42861
   187
          have "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) =
hoelzl@42861
   188
              prob ((\<Inter>j\<in>J. A j) - (\<Inter>i\<in>insert j J. (A(j := X)) i))"
immler@50244
   189
            using A_sets sets.sets_into_space[of _ M] X `J \<noteq> {}`
hoelzl@42861
   190
            by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
hoelzl@42861
   191
          also have "\<dots> = prob (\<Inter>j\<in>J. A j) - prob (\<Inter>i\<in>insert j J. (A(j := X)) i)"
immler@50244
   192
            using J `J \<noteq> {}` `j \<notin> J` A_sets X sets.sets_into_space
immler@50244
   193
            by (auto intro!: finite_measure_Diff sets.finite_INT split: split_if_asm)
hoelzl@42861
   194
          finally have "prob ((\<Inter>j\<in>J. A j) \<inter> (space M - X)) =
hoelzl@42861
   195
              prob (\<Inter>j\<in>J. A j) - prob (\<Inter>i\<in>insert j J. (A(j := X)) i)" .
hoelzl@42861
   196
          moreover {
hoelzl@42861
   197
            have "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861
   198
              using J A `finite J` by (intro indep_setsD[OF G(1)]) auto
hoelzl@42861
   199
            then have "prob (\<Inter>j\<in>J. A j) = prob (space M) * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861
   200
              using prob_space by simp }
hoelzl@42861
   201
          moreover {
hoelzl@42861
   202
            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
   203
              using J A `j \<in> K` by (intro indep_setsD[OF G']) auto
hoelzl@42861
   204
            then have "prob (\<Inter>i\<in>insert j J. (A(j := X)) i) = prob X * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861
   205
              using `finite J` `j \<notin> J` by (auto intro!: setprod_cong) }
hoelzl@42861
   206
          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
   207
            by (simp add: field_simps)
hoelzl@42861
   208
          also have "\<dots> = prob (space M - X) * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861
   209
            using X A by (simp add: finite_measure_compl)
hoelzl@42861
   210
          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
   211
        qed (insert X, auto)
hoelzl@42861
   212
      next
hoelzl@42861
   213
        fix F :: "nat \<Rightarrow> 'a set" assume disj: "disjoint_family F" and "range F \<subseteq> ?D"
hoelzl@42861
   214
        then have F: "\<And>i. F i \<in> events" "\<And>i. indep_sets (G(j:={F i})) K" by auto
hoelzl@42861
   215
        show "indep_sets (G(j := {\<Union>k. F k})) K"
hoelzl@42861
   216
        proof (rule indep_sets_insert)
hoelzl@42861
   217
          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
   218
          then have A_sets: "\<And>i. i\<in>J \<Longrightarrow> A i \<in> events"
hoelzl@42861
   219
            using G by auto
hoelzl@42861
   220
          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
   221
            using `J \<noteq> {}` `j \<notin> J` `j \<in> K` by (auto intro!: arg_cong[where f=prob] split: split_if_asm)
hoelzl@42861
   222
          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
   223
          proof (rule finite_measure_UNION)
hoelzl@42861
   224
            show "disjoint_family (\<lambda>k. \<Inter>i\<in>insert j J. (A(j := F k)) i)"
hoelzl@42861
   225
              using disj by (rule disjoint_family_on_bisimulation) auto
hoelzl@42861
   226
            show "range (\<lambda>k. \<Inter>i\<in>insert j J. (A(j := F k)) i) \<subseteq> events"
immler@50244
   227
              using A_sets F `finite J` `J \<noteq> {}` `j \<notin> J` by (auto intro!: sets.Int)
hoelzl@42861
   228
          qed
hoelzl@42861
   229
          moreover { fix k
hoelzl@42861
   230
            from J A `j \<in> K` have "prob (\<Inter>i\<in>insert j J. (A(j := F k)) i) = prob (F k) * (\<Prod>i\<in>J. prob (A i))"
hoelzl@42861
   231
              by (subst indep_setsD[OF F(2)]) (auto intro!: setprod_cong split: split_if_asm)
hoelzl@42861
   232
            also have "\<dots> = prob (F k) * prob (\<Inter>i\<in>J. A i)"
hoelzl@42861
   233
              using J A `j \<in> K` by (subst indep_setsD[OF G(1)]) auto
hoelzl@42861
   234
            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
   235
          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
   236
            by simp
hoelzl@42861
   237
          moreover
hoelzl@42861
   238
          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
   239
            using disj F(1) by (intro finite_measure_UNION sums_mult2) auto
hoelzl@42861
   240
          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
   241
            using J A `j \<in> K` by (subst indep_setsD[OF G(1), symmetric]) auto
hoelzl@42861
   242
          ultimately
hoelzl@42861
   243
          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
   244
            by (auto dest!: sums_unique)
hoelzl@42861
   245
        qed (insert F, auto)
immler@50244
   246
      qed (insert sets.sets_into_space, auto)
hoelzl@47694
   247
      then have mono: "dynkin (space M) (G j) \<subseteq> {E \<in> events. indep_sets (G(j := {E})) K}"
hoelzl@47694
   248
      proof (rule dynkin_system.dynkin_subset, safe)
hoelzl@42861
   249
        fix X assume "X \<in> G j"
hoelzl@42861
   250
        then show "X \<in> events" using G `j \<in> K` by auto
hoelzl@42861
   251
        from `indep_sets G K`
hoelzl@42861
   252
        show "indep_sets (G(j := {X})) K"
hoelzl@42861
   253
          by (rule indep_sets_mono_sets) (insert `X \<in> G j`, auto)
hoelzl@42861
   254
      qed
hoelzl@42861
   255
      have "indep_sets (G(j:=?D)) K"
hoelzl@42861
   256
      proof (rule indep_setsI)
hoelzl@42861
   257
        fix i assume "i \<in> K" then show "(G(j := ?D)) i \<subseteq> events"
hoelzl@42861
   258
          using G(2) by auto
hoelzl@42861
   259
      next
hoelzl@42861
   260
        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
   261
        show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42861
   262
        proof cases
hoelzl@42861
   263
          assume "j \<in> J"
hoelzl@42861
   264
          with A have indep: "indep_sets (G(j := {A j})) K" by auto
hoelzl@42861
   265
          from J A show ?thesis
hoelzl@42861
   266
            by (intro indep_setsD[OF indep]) auto
hoelzl@42861
   267
        next
hoelzl@42861
   268
          assume "j \<notin> J"
hoelzl@42861
   269
          with J A have "\<forall>i\<in>J. A i \<in> G i" by (auto split: split_if_asm)
hoelzl@42861
   270
          with J show ?thesis
hoelzl@42861
   271
            by (intro indep_setsD[OF G(1)]) auto
hoelzl@42861
   272
        qed
hoelzl@42861
   273
      qed
hoelzl@47694
   274
      then have "indep_sets (G(j := dynkin (space M) (G j))) K"
hoelzl@42861
   275
        by (rule indep_sets_mono_sets) (insert mono, auto)
hoelzl@42861
   276
      then show ?case
hoelzl@42861
   277
        by (rule indep_sets_mono_sets) (insert `j \<in> K` `j \<notin> J`, auto simp: G_def)
hoelzl@42861
   278
    qed (insert `indep_sets F K`, simp) }
hoelzl@42861
   279
  from this[OF `indep_sets F J` `finite J` subset_refl]
hoelzl@47694
   280
  show "indep_sets ?F J"
hoelzl@42861
   281
    by (rule indep_sets_mono_sets) auto
hoelzl@42861
   282
qed
hoelzl@42861
   283
hoelzl@42861
   284
lemma (in prob_space) indep_sets_sigma:
hoelzl@42861
   285
  assumes indep: "indep_sets F I"
hoelzl@47694
   286
  assumes stable: "\<And>i. i \<in> I \<Longrightarrow> Int_stable (F i)"
hoelzl@47694
   287
  shows "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I"
hoelzl@42861
   288
proof -
hoelzl@42861
   289
  from indep_sets_dynkin[OF indep]
hoelzl@42861
   290
  show ?thesis
hoelzl@42861
   291
  proof (rule indep_sets_mono_sets, subst sigma_eq_dynkin, simp_all add: stable)
hoelzl@42861
   292
    fix i assume "i \<in> I"
hoelzl@42861
   293
    with indep have "F i \<subseteq> events" by (auto simp: indep_sets_def)
immler@50244
   294
    with sets.sets_into_space show "F i \<subseteq> Pow (space M)" by auto
hoelzl@42861
   295
  qed
hoelzl@42861
   296
qed
hoelzl@42861
   297
hoelzl@42987
   298
lemma (in prob_space) indep_sets_sigma_sets_iff:
hoelzl@47694
   299
  assumes "\<And>i. i \<in> I \<Longrightarrow> Int_stable (F i)"
hoelzl@42987
   300
  shows "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I \<longleftrightarrow> indep_sets F I"
hoelzl@42987
   301
proof
hoelzl@42987
   302
  assume "indep_sets F I" then show "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I"
hoelzl@47694
   303
    by (rule indep_sets_sigma) fact
hoelzl@42987
   304
next
hoelzl@42987
   305
  assume "indep_sets (\<lambda>i. sigma_sets (space M) (F i)) I" then show "indep_sets F I"
hoelzl@42987
   306
    by (rule indep_sets_mono_sets) (intro subsetI sigma_sets.Basic)
hoelzl@42987
   307
qed
hoelzl@42987
   308
hoelzl@49794
   309
definition (in prob_space)
hoelzl@49794
   310
  indep_vars_def2: "indep_vars M' X I \<longleftrightarrow>
hoelzl@49781
   311
    (\<forall>i\<in>I. random_variable (M' i) (X i)) \<and>
hoelzl@49781
   312
    indep_sets (\<lambda>i. { X i -` A \<inter> space M | A. A \<in> sets (M' i)}) I"
hoelzl@49794
   313
hoelzl@49794
   314
definition (in prob_space)
blanchet@55414
   315
  "indep_var Ma A Mb B \<longleftrightarrow> indep_vars (case_bool Ma Mb) (case_bool A B) UNIV"
hoelzl@49794
   316
hoelzl@49794
   317
lemma (in prob_space) indep_vars_def:
hoelzl@49794
   318
  "indep_vars M' X I \<longleftrightarrow>
hoelzl@49794
   319
    (\<forall>i\<in>I. random_variable (M' i) (X i)) \<and>
hoelzl@49794
   320
    indep_sets (\<lambda>i. sigma_sets (space M) { X i -` A \<inter> space M | A. A \<in> sets (M' i)}) I"
hoelzl@49794
   321
  unfolding indep_vars_def2
hoelzl@49781
   322
  apply (rule conj_cong[OF refl])
hoelzl@49794
   323
  apply (rule indep_sets_sigma_sets_iff[symmetric])
hoelzl@49781
   324
  apply (auto simp: Int_stable_def)
hoelzl@49781
   325
  apply (rule_tac x="A \<inter> Aa" in exI)
hoelzl@49781
   326
  apply auto
hoelzl@49781
   327
  done
hoelzl@49781
   328
hoelzl@49794
   329
lemma (in prob_space) indep_var_eq:
hoelzl@49794
   330
  "indep_var S X T Y \<longleftrightarrow>
hoelzl@49794
   331
    (random_variable S X \<and> random_variable T Y) \<and>
hoelzl@49794
   332
    indep_set
hoelzl@49794
   333
      (sigma_sets (space M) { X -` A \<inter> space M | A. A \<in> sets S})
hoelzl@49794
   334
      (sigma_sets (space M) { Y -` A \<inter> space M | A. A \<in> sets T})"
hoelzl@49794
   335
  unfolding indep_var_def indep_vars_def indep_set_def UNIV_bool
hoelzl@49794
   336
  by (intro arg_cong2[where f="op \<and>"] arg_cong2[where f=indep_sets] ext)
hoelzl@49794
   337
     (auto split: bool.split)
hoelzl@49794
   338
hoelzl@42861
   339
lemma (in prob_space) indep_sets2_eq:
hoelzl@42981
   340
  "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
   341
  unfolding indep_set_def
hoelzl@42861
   342
proof (intro iffI ballI conjI)
blanchet@55414
   343
  assume indep: "indep_sets (case_bool A B) UNIV"
hoelzl@42861
   344
  { fix a b assume "a \<in> A" "b \<in> B"
blanchet@55414
   345
    with indep_setsD[OF indep, of UNIV "case_bool a b"]
hoelzl@42861
   346
    show "prob (a \<inter> b) = prob a * prob b"
hoelzl@42861
   347
      unfolding UNIV_bool by (simp add: ac_simps) }
hoelzl@42861
   348
  from indep show "A \<subseteq> events" "B \<subseteq> events"
hoelzl@42861
   349
    unfolding indep_sets_def UNIV_bool by auto
hoelzl@42861
   350
next
hoelzl@42861
   351
  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
   352
  show "indep_sets (case_bool A B) UNIV"
hoelzl@42861
   353
  proof (rule indep_setsI)
hoelzl@42861
   354
    fix i show "(case i of True \<Rightarrow> A | False \<Rightarrow> B) \<subseteq> events"
hoelzl@42861
   355
      using * by (auto split: bool.split)
hoelzl@42861
   356
  next
hoelzl@42861
   357
    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
   358
    then have "J = {True} \<or> J = {False} \<or> J = {True,False}"
hoelzl@42861
   359
      by (auto simp: UNIV_bool)
hoelzl@42861
   360
    then show "prob (\<Inter>j\<in>J. X j) = (\<Prod>j\<in>J. prob (X j))"
hoelzl@42861
   361
      using X * by auto
hoelzl@42861
   362
  qed
hoelzl@42861
   363
qed
hoelzl@42861
   364
hoelzl@42981
   365
lemma (in prob_space) indep_set_sigma_sets:
hoelzl@42981
   366
  assumes "indep_set A B"
hoelzl@47694
   367
  assumes A: "Int_stable A" and B: "Int_stable B"
hoelzl@42981
   368
  shows "indep_set (sigma_sets (space M) A) (sigma_sets (space M) B)"
hoelzl@42861
   369
proof -
hoelzl@42861
   370
  have "indep_sets (\<lambda>i. sigma_sets (space M) (case i of True \<Rightarrow> A | False \<Rightarrow> B)) UNIV"
hoelzl@47694
   371
  proof (rule indep_sets_sigma)
blanchet@55414
   372
    show "indep_sets (case_bool A B) UNIV"
hoelzl@42981
   373
      by (rule `indep_set A B`[unfolded indep_set_def])
hoelzl@47694
   374
    fix i show "Int_stable (case i of True \<Rightarrow> A | False \<Rightarrow> B)"
hoelzl@42861
   375
      using A B by (cases i) auto
hoelzl@42861
   376
  qed
hoelzl@42861
   377
  then show ?thesis
hoelzl@42981
   378
    unfolding indep_set_def
hoelzl@42861
   379
    by (rule indep_sets_mono_sets) (auto split: bool.split)
hoelzl@42861
   380
qed
hoelzl@42861
   381
hoelzl@42981
   382
lemma (in prob_space) indep_sets_collect_sigma:
hoelzl@42981
   383
  fixes I :: "'j \<Rightarrow> 'i set" and J :: "'j set" and E :: "'i \<Rightarrow> 'a set set"
hoelzl@42981
   384
  assumes indep: "indep_sets E (\<Union>j\<in>J. I j)"
hoelzl@47694
   385
  assumes Int_stable: "\<And>i j. j \<in> J \<Longrightarrow> i \<in> I j \<Longrightarrow> Int_stable (E i)"
hoelzl@42981
   386
  assumes disjoint: "disjoint_family_on I J"
hoelzl@42981
   387
  shows "indep_sets (\<lambda>j. sigma_sets (space M) (\<Union>i\<in>I j. E i)) J"
hoelzl@42981
   388
proof -
wenzelm@46731
   389
  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
   390
hoelzl@42983
   391
  from indep have E: "\<And>j i. j \<in> J \<Longrightarrow> i \<in> I j \<Longrightarrow> E i \<subseteq> events"
hoelzl@42981
   392
    unfolding indep_sets_def by auto
hoelzl@42981
   393
  { fix j
hoelzl@47694
   394
    let ?S = "sigma_sets (space M) (\<Union>i\<in>I j. E i)"
hoelzl@42981
   395
    assume "j \<in> J"
hoelzl@47694
   396
    from E[OF this] interpret S: sigma_algebra "space M" ?S
immler@50244
   397
      using sets.sets_into_space[of _ M] by (intro sigma_algebra_sigma_sets) auto
hoelzl@42981
   398
hoelzl@42981
   399
    have "sigma_sets (space M) (\<Union>i\<in>I j. E i) = sigma_sets (space M) (?E j)"
hoelzl@42981
   400
    proof (rule sigma_sets_eqI)
hoelzl@42981
   401
      fix A assume "A \<in> (\<Union>i\<in>I j. E i)"
hoelzl@42981
   402
      then guess i ..
hoelzl@42981
   403
      then show "A \<in> sigma_sets (space M) (?E j)"
hoelzl@47694
   404
        by (auto intro!: sigma_sets.intros(2-) exI[of _ "{i}"] exI[of _ "\<lambda>i. A"])
hoelzl@42981
   405
    next
hoelzl@42981
   406
      fix A assume "A \<in> ?E j"
hoelzl@42981
   407
      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
   408
        and A: "A = (\<Inter>k\<in>K. E' k)"
hoelzl@42981
   409
        by auto
hoelzl@47694
   410
      then have "A \<in> ?S" unfolding A
hoelzl@47694
   411
        by (safe intro!: S.finite_INT) auto
hoelzl@42981
   412
      then show "A \<in> sigma_sets (space M) (\<Union>i\<in>I j. E i)"
hoelzl@47694
   413
        by simp
hoelzl@42981
   414
    qed }
hoelzl@42981
   415
  moreover have "indep_sets (\<lambda>j. sigma_sets (space M) (?E j)) J"
hoelzl@47694
   416
  proof (rule indep_sets_sigma)
hoelzl@42981
   417
    show "indep_sets ?E J"
hoelzl@42981
   418
    proof (intro indep_setsI)
immler@50244
   419
      fix j assume "j \<in> J" with E show "?E j \<subseteq> events" by (force  intro!: sets.finite_INT)
hoelzl@42981
   420
    next
hoelzl@42981
   421
      fix K A assume K: "K \<noteq> {}" "K \<subseteq> J" "finite K"
hoelzl@42981
   422
        and "\<forall>j\<in>K. A j \<in> ?E j"
hoelzl@42981
   423
      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
   424
        by simp
hoelzl@42981
   425
      from bchoice[OF this] guess E' ..
hoelzl@42981
   426
      from bchoice[OF this] obtain L
hoelzl@42981
   427
        where A: "\<And>j. j\<in>K \<Longrightarrow> A j = (\<Inter>l\<in>L j. E' j l)"
hoelzl@42981
   428
        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
   429
        and E': "\<And>j l. j\<in>K \<Longrightarrow> l \<in> L j \<Longrightarrow> E' j l \<in> E l"
hoelzl@42981
   430
        by auto
hoelzl@42981
   431
hoelzl@42981
   432
      { fix k l j assume "k \<in> K" "j \<in> K" "l \<in> L j" "l \<in> L k"
hoelzl@42981
   433
        have "k = j"
hoelzl@42981
   434
        proof (rule ccontr)
hoelzl@42981
   435
          assume "k \<noteq> j"
hoelzl@42981
   436
          with disjoint `K \<subseteq> J` `k \<in> K` `j \<in> K` have "I k \<inter> I j = {}"
hoelzl@42981
   437
            unfolding disjoint_family_on_def by auto
hoelzl@42981
   438
          with L(2,3)[OF `j \<in> K`] L(2,3)[OF `k \<in> K`]
hoelzl@42981
   439
          show False using `l \<in> L k` `l \<in> L j` by auto
hoelzl@42981
   440
        qed }
hoelzl@42981
   441
      note L_inj = this
hoelzl@42981
   442
hoelzl@42981
   443
      def k \<equiv> "\<lambda>l. (SOME k. k \<in> K \<and> l \<in> L k)"
hoelzl@42981
   444
      { fix x j l assume *: "j \<in> K" "l \<in> L j"
hoelzl@42981
   445
        have "k l = j" unfolding k_def
hoelzl@42981
   446
        proof (rule some_equality)
hoelzl@42981
   447
          fix k assume "k \<in> K \<and> l \<in> L k"
hoelzl@42981
   448
          with * L_inj show "k = j" by auto
hoelzl@42981
   449
        qed (insert *, simp) }
hoelzl@42981
   450
      note k_simp[simp] = this
wenzelm@46731
   451
      let ?E' = "\<lambda>l. E' (k l) l"
hoelzl@42981
   452
      have "prob (\<Inter>j\<in>K. A j) = prob (\<Inter>l\<in>(\<Union>k\<in>K. L k). ?E' l)"
hoelzl@42981
   453
        by (auto simp: A intro!: arg_cong[where f=prob])
hoelzl@42981
   454
      also have "\<dots> = (\<Prod>l\<in>(\<Union>k\<in>K. L k). prob (?E' l))"
hoelzl@42981
   455
        using L K E' by (intro indep_setsD[OF indep]) (simp_all add: UN_mono)
hoelzl@42981
   456
      also have "\<dots> = (\<Prod>j\<in>K. \<Prod>l\<in>L j. prob (E' j l))"
hoelzl@42981
   457
        using K L L_inj by (subst setprod_UN_disjoint) auto
hoelzl@42981
   458
      also have "\<dots> = (\<Prod>j\<in>K. prob (A j))"
hoelzl@42981
   459
        using K L E' by (auto simp add: A intro!: setprod_cong indep_setsD[OF indep, symmetric]) blast
hoelzl@42981
   460
      finally show "prob (\<Inter>j\<in>K. A j) = (\<Prod>j\<in>K. prob (A j))" .
hoelzl@42981
   461
    qed
hoelzl@42981
   462
  next
hoelzl@42981
   463
    fix j assume "j \<in> J"
hoelzl@47694
   464
    show "Int_stable (?E j)"
hoelzl@42981
   465
    proof (rule Int_stableI)
hoelzl@42981
   466
      fix a assume "a \<in> ?E j" then obtain Ka Ea
hoelzl@42981
   467
        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
   468
      fix b assume "b \<in> ?E j" then obtain Kb Eb
hoelzl@42981
   469
        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
   470
      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
   471
      have "a \<inter> b = INTER (Ka \<union> Kb) ?A"
hoelzl@42981
   472
        by (simp add: a b set_eq_iff) auto
hoelzl@42981
   473
      with a b `j \<in> J` Int_stableD[OF Int_stable] show "a \<inter> b \<in> ?E j"
hoelzl@42981
   474
        by (intro CollectI exI[of _ "Ka \<union> Kb"] exI[of _ ?A]) auto
hoelzl@42981
   475
    qed
hoelzl@42981
   476
  qed
hoelzl@42981
   477
  ultimately show ?thesis
hoelzl@42981
   478
    by (simp cong: indep_sets_cong)
hoelzl@42981
   479
qed
hoelzl@42981
   480
hoelzl@49772
   481
definition (in prob_space) tail_events where
hoelzl@49772
   482
  "tail_events A = (\<Inter>n. sigma_sets (space M) (UNION {n..} A))"
hoelzl@42982
   483
hoelzl@49772
   484
lemma (in prob_space) tail_events_sets:
hoelzl@49772
   485
  assumes A: "\<And>i::nat. A i \<subseteq> events"
hoelzl@49772
   486
  shows "tail_events A \<subseteq> events"
hoelzl@49772
   487
proof
hoelzl@49772
   488
  fix X assume X: "X \<in> tail_events A"
hoelzl@42982
   489
  let ?A = "(\<Inter>n. sigma_sets (space M) (UNION {n..} A))"
hoelzl@49772
   490
  from X have "\<And>n::nat. X \<in> sigma_sets (space M) (UNION {n..} A)" by (auto simp: tail_events_def)
hoelzl@42982
   491
  from this[of 0] have "X \<in> sigma_sets (space M) (UNION UNIV A)" by simp
hoelzl@42983
   492
  then show "X \<in> events"
hoelzl@42982
   493
    by induct (insert A, auto)
hoelzl@42982
   494
qed
hoelzl@42982
   495
hoelzl@49772
   496
lemma (in prob_space) sigma_algebra_tail_events:
hoelzl@47694
   497
  assumes "\<And>i::nat. sigma_algebra (space M) (A i)"
hoelzl@49772
   498
  shows "sigma_algebra (space M) (tail_events A)"
hoelzl@49772
   499
  unfolding tail_events_def
hoelzl@42982
   500
proof (simp add: sigma_algebra_iff2, safe)
hoelzl@42982
   501
  let ?A = "(\<Inter>n. sigma_sets (space M) (UNION {n..} A))"
hoelzl@47694
   502
  interpret A: sigma_algebra "space M" "A i" for i by fact
hoelzl@43340
   503
  { fix X x assume "X \<in> ?A" "x \<in> X"
hoelzl@42982
   504
    then have "\<And>n. X \<in> sigma_sets (space M) (UNION {n..} A)" by auto
hoelzl@42982
   505
    from this[of 0] have "X \<in> sigma_sets (space M) (UNION UNIV A)" by simp
hoelzl@42982
   506
    then have "X \<subseteq> space M"
hoelzl@42982
   507
      by induct (insert A.sets_into_space, auto)
hoelzl@42982
   508
    with `x \<in> X` show "x \<in> space M" by auto }
hoelzl@42982
   509
  { fix F :: "nat \<Rightarrow> 'a set" and n assume "range F \<subseteq> ?A"
hoelzl@42982
   510
    then show "(UNION UNIV F) \<in> sigma_sets (space M) (UNION {n..} A)"
hoelzl@42982
   511
      by (intro sigma_sets.Union) auto }
hoelzl@42982
   512
qed (auto intro!: sigma_sets.Compl sigma_sets.Empty)
hoelzl@42982
   513
hoelzl@42982
   514
lemma (in prob_space) kolmogorov_0_1_law:
hoelzl@42982
   515
  fixes A :: "nat \<Rightarrow> 'a set set"
hoelzl@47694
   516
  assumes "\<And>i::nat. sigma_algebra (space M) (A i)"
hoelzl@42982
   517
  assumes indep: "indep_sets A UNIV"
hoelzl@49772
   518
  and X: "X \<in> tail_events A"
hoelzl@42982
   519
  shows "prob X = 0 \<or> prob X = 1"
hoelzl@42982
   520
proof -
hoelzl@49781
   521
  have A: "\<And>i. A i \<subseteq> events"
hoelzl@49781
   522
    using indep unfolding indep_sets_def by simp
hoelzl@49781
   523
hoelzl@47694
   524
  let ?D = "{D \<in> events. prob (X \<inter> D) = prob X * prob D}"
hoelzl@47694
   525
  interpret A: sigma_algebra "space M" "A i" for i by fact
hoelzl@49772
   526
  interpret T: sigma_algebra "space M" "tail_events A"
hoelzl@49772
   527
    by (rule sigma_algebra_tail_events) fact
hoelzl@42982
   528
  have "X \<subseteq> space M" using T.space_closed X by auto
hoelzl@42982
   529
hoelzl@42983
   530
  have X_in: "X \<in> events"
hoelzl@49772
   531
    using tail_events_sets A X by auto
hoelzl@42982
   532
hoelzl@47694
   533
  interpret D: dynkin_system "space M" ?D
hoelzl@42982
   534
  proof (rule dynkin_systemI)
hoelzl@47694
   535
    fix D assume "D \<in> ?D" then show "D \<subseteq> space M"
immler@50244
   536
      using sets.sets_into_space by auto
hoelzl@42982
   537
  next
hoelzl@47694
   538
    show "space M \<in> ?D"
hoelzl@42982
   539
      using prob_space `X \<subseteq> space M` by (simp add: Int_absorb2)
hoelzl@42982
   540
  next
hoelzl@47694
   541
    fix A assume A: "A \<in> ?D"
hoelzl@42982
   542
    have "prob (X \<inter> (space M - A)) = prob (X - (X \<inter> A))"
hoelzl@42982
   543
      using `X \<subseteq> space M` by (auto intro!: arg_cong[where f=prob])
hoelzl@42982
   544
    also have "\<dots> = prob X - prob (X \<inter> A)"
hoelzl@42982
   545
      using X_in A by (intro finite_measure_Diff) auto
hoelzl@42982
   546
    also have "\<dots> = prob X * prob (space M) - prob X * prob A"
hoelzl@42982
   547
      using A prob_space by auto
hoelzl@42982
   548
    also have "\<dots> = prob X * prob (space M - A)"
immler@50244
   549
      using X_in A sets.sets_into_space
hoelzl@42982
   550
      by (subst finite_measure_Diff) (auto simp: field_simps)
hoelzl@47694
   551
    finally show "space M - A \<in> ?D"
hoelzl@42982
   552
      using A `X \<subseteq> space M` by auto
hoelzl@42982
   553
  next
hoelzl@47694
   554
    fix F :: "nat \<Rightarrow> 'a set" assume dis: "disjoint_family F" and "range F \<subseteq> ?D"
hoelzl@42982
   555
    then have F: "range F \<subseteq> events" "\<And>i. prob (X \<inter> F i) = prob X * prob (F i)"
hoelzl@42982
   556
      by auto
hoelzl@42982
   557
    have "(\<lambda>i. prob (X \<inter> F i)) sums prob (\<Union>i. X \<inter> F i)"
hoelzl@42982
   558
    proof (rule finite_measure_UNION)
hoelzl@42982
   559
      show "range (\<lambda>i. X \<inter> F i) \<subseteq> events"
hoelzl@42982
   560
        using F X_in by auto
hoelzl@42982
   561
      show "disjoint_family (\<lambda>i. X \<inter> F i)"
hoelzl@42982
   562
        using dis by (rule disjoint_family_on_bisimulation) auto
hoelzl@42982
   563
    qed
hoelzl@42982
   564
    with F have "(\<lambda>i. prob X * prob (F i)) sums prob (X \<inter> (\<Union>i. F i))"
hoelzl@42982
   565
      by simp
hoelzl@42982
   566
    moreover have "(\<lambda>i. prob X * prob (F i)) sums (prob X * prob (\<Union>i. F i))"
huffman@44282
   567
      by (intro sums_mult finite_measure_UNION F dis)
hoelzl@42982
   568
    ultimately have "prob (X \<inter> (\<Union>i. F i)) = prob X * prob (\<Union>i. F i)"
hoelzl@42982
   569
      by (auto dest!: sums_unique)
hoelzl@47694
   570
    with F show "(\<Union>i. F i) \<in> ?D"
hoelzl@42982
   571
      by auto
hoelzl@42982
   572
  qed
hoelzl@42982
   573
hoelzl@42982
   574
  { fix n
blanchet@55414
   575
    have "indep_sets (\<lambda>b. sigma_sets (space M) (\<Union>m\<in>case_bool {..n} {Suc n..} b. A m)) UNIV"
hoelzl@42982
   576
    proof (rule indep_sets_collect_sigma)
hoelzl@42982
   577
      have *: "(\<Union>b. case b of True \<Rightarrow> {..n} | False \<Rightarrow> {Suc n..}) = UNIV" (is "?U = _")
hoelzl@42982
   578
        by (simp split: bool.split add: set_eq_iff) (metis not_less_eq_eq)
hoelzl@42982
   579
      with indep show "indep_sets A ?U" by simp
blanchet@55414
   580
      show "disjoint_family (case_bool {..n} {Suc n..})"
hoelzl@42982
   581
        unfolding disjoint_family_on_def by (auto split: bool.split)
hoelzl@42982
   582
      fix m
hoelzl@47694
   583
      show "Int_stable (A m)"
hoelzl@42982
   584
        unfolding Int_stable_def using A.Int by auto
hoelzl@42982
   585
    qed
blanchet@55414
   586
    also have "(\<lambda>b. sigma_sets (space M) (\<Union>m\<in>case_bool {..n} {Suc n..} b. A m)) =
blanchet@55414
   587
      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
   588
      by (auto intro!: ext split: bool.split)
hoelzl@42982
   589
    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
   590
      unfolding indep_set_def by simp
hoelzl@42982
   591
hoelzl@47694
   592
    have "sigma_sets (space M) (\<Union>m\<in>{..n}. A m) \<subseteq> ?D"
hoelzl@42982
   593
    proof (simp add: subset_eq, rule)
hoelzl@42982
   594
      fix D assume D: "D \<in> sigma_sets (space M) (\<Union>m\<in>{..n}. A m)"
hoelzl@42982
   595
      have "X \<in> sigma_sets (space M) (\<Union>m\<in>{Suc n..}. A m)"
hoelzl@49772
   596
        using X unfolding tail_events_def by simp
hoelzl@42982
   597
      from indep_setD[OF indep D this] indep_setD_ev1[OF indep] D
hoelzl@42982
   598
      show "D \<in> events \<and> prob (X \<inter> D) = prob X * prob D"
hoelzl@42982
   599
        by (auto simp add: ac_simps)
hoelzl@42982
   600
    qed }
hoelzl@47694
   601
  then have "(\<Union>n. sigma_sets (space M) (\<Union>m\<in>{..n}. A m)) \<subseteq> ?D" (is "?A \<subseteq> _")
hoelzl@42982
   602
    by auto
hoelzl@42982
   603
hoelzl@49772
   604
  note `X \<in> tail_events A`
hoelzl@47694
   605
  also {
hoelzl@47694
   606
    have "\<And>n. sigma_sets (space M) (\<Union>i\<in>{n..}. A i) \<subseteq> sigma_sets (space M) ?A"
hoelzl@47694
   607
      by (intro sigma_sets_subseteq UN_mono) auto
hoelzl@49772
   608
   then have "tail_events A \<subseteq> sigma_sets (space M) ?A"
hoelzl@49772
   609
      unfolding tail_events_def by auto }
hoelzl@47694
   610
  also have "sigma_sets (space M) ?A = dynkin (space M) ?A"
hoelzl@42982
   611
  proof (rule sigma_eq_dynkin)
hoelzl@42982
   612
    { fix B n assume "B \<in> sigma_sets (space M) (\<Union>m\<in>{..n}. A m)"
hoelzl@42982
   613
      then have "B \<subseteq> space M"
immler@50244
   614
        by induct (insert A sets.sets_into_space[of _ M], auto) }
hoelzl@47694
   615
    then show "?A \<subseteq> Pow (space M)" by auto
hoelzl@47694
   616
    show "Int_stable ?A"
hoelzl@42982
   617
    proof (rule Int_stableI)
hoelzl@42982
   618
      fix a assume "a \<in> ?A" then guess n .. note a = this
hoelzl@42982
   619
      fix b assume "b \<in> ?A" then guess m .. note b = this
hoelzl@47694
   620
      interpret Amn: sigma_algebra "space M" "sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)"
immler@50244
   621
        using A sets.sets_into_space[of _ M] by (intro sigma_algebra_sigma_sets) auto
hoelzl@42982
   622
      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
   623
        by (intro sigma_sets_subseteq UN_mono) auto
hoelzl@42982
   624
      with a have "a \<in> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)" by auto
hoelzl@42982
   625
      moreover
hoelzl@42982
   626
      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
   627
        by (intro sigma_sets_subseteq UN_mono) auto
hoelzl@42982
   628
      with b have "b \<in> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)" by auto
hoelzl@42982
   629
      ultimately have "a \<inter> b \<in> sigma_sets (space M) (\<Union>i\<in>{..max m n}. A i)"
hoelzl@47694
   630
        using Amn.Int[of a b] by simp
hoelzl@42982
   631
      then show "a \<inter> b \<in> (\<Union>n. sigma_sets (space M) (\<Union>i\<in>{..n}. A i))" by auto
hoelzl@42982
   632
    qed
hoelzl@42982
   633
  qed
hoelzl@47694
   634
  also have "dynkin (space M) ?A \<subseteq> ?D"
hoelzl@47694
   635
    using `?A \<subseteq> ?D` by (auto intro!: D.dynkin_subset)
hoelzl@47694
   636
  finally show ?thesis by auto
hoelzl@42982
   637
qed
hoelzl@42982
   638
hoelzl@42985
   639
lemma (in prob_space) borel_0_1_law:
hoelzl@42985
   640
  fixes F :: "nat \<Rightarrow> 'a set"
hoelzl@49781
   641
  assumes F2: "indep_events F UNIV"
hoelzl@42985
   642
  shows "prob (\<Inter>n. \<Union>m\<in>{n..}. F m) = 0 \<or> prob (\<Inter>n. \<Union>m\<in>{n..}. F m) = 1"
hoelzl@42985
   643
proof (rule kolmogorov_0_1_law[of "\<lambda>i. sigma_sets (space M) { F i }"])
hoelzl@49781
   644
  have F1: "range F \<subseteq> events"
hoelzl@49781
   645
    using F2 by (simp add: indep_events_def subset_eq)
hoelzl@47694
   646
  { fix i show "sigma_algebra (space M) (sigma_sets (space M) {F i})"
immler@50244
   647
      using sigma_algebra_sigma_sets[of "{F i}" "space M"] F1 sets.sets_into_space
hoelzl@47694
   648
      by auto }
hoelzl@42985
   649
  show "indep_sets (\<lambda>i. sigma_sets (space M) {F i}) UNIV"
hoelzl@47694
   650
  proof (rule indep_sets_sigma)
hoelzl@42985
   651
    show "indep_sets (\<lambda>i. {F i}) UNIV"
hoelzl@49784
   652
      unfolding indep_events_def_alt[symmetric] by fact
hoelzl@47694
   653
    fix i show "Int_stable {F i}"
hoelzl@42985
   654
      unfolding Int_stable_def by simp
hoelzl@42985
   655
  qed
wenzelm@46731
   656
  let ?Q = "\<lambda>n. \<Union>i\<in>{n..}. F i"
hoelzl@49772
   657
  show "(\<Inter>n. \<Union>m\<in>{n..}. F m) \<in> tail_events (\<lambda>i. sigma_sets (space M) {F i})"
hoelzl@49772
   658
    unfolding tail_events_def
hoelzl@42985
   659
  proof
hoelzl@42985
   660
    fix j
hoelzl@47694
   661
    interpret S: sigma_algebra "space M" "sigma_sets (space M) (\<Union>i\<in>{j..}. sigma_sets (space M) {F i})"
immler@50244
   662
      using order_trans[OF F1 sets.space_closed]
hoelzl@47694
   663
      by (intro sigma_algebra_sigma_sets) (simp add: sigma_sets_singleton subset_eq)
hoelzl@42985
   664
    have "(\<Inter>n. ?Q n) = (\<Inter>n\<in>{j..}. ?Q n)"
hoelzl@42985
   665
      by (intro decseq_SucI INT_decseq_offset UN_mono) auto
hoelzl@47694
   666
    also have "\<dots> \<in> sigma_sets (space M) (\<Union>i\<in>{j..}. sigma_sets (space M) {F i})"
immler@50244
   667
      using order_trans[OF F1 sets.space_closed]
hoelzl@42985
   668
      by (safe intro!: S.countable_INT S.countable_UN)
hoelzl@47694
   669
         (auto simp: sigma_sets_singleton intro!: sigma_sets.Basic bexI)
hoelzl@42985
   670
    finally show "(\<Inter>n. ?Q n) \<in> sigma_sets (space M) (\<Union>i\<in>{j..}. sigma_sets (space M) {F i})"
hoelzl@47694
   671
      by simp
hoelzl@42985
   672
  qed
hoelzl@42985
   673
qed
hoelzl@42985
   674
hoelzl@42987
   675
lemma (in prob_space) indep_sets_finite:
hoelzl@42987
   676
  assumes I: "I \<noteq> {}" "finite I"
hoelzl@42987
   677
    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
   678
  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
   679
proof
hoelzl@42987
   680
  assume *: "indep_sets F I"
hoelzl@42987
   681
  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
   682
    by (intro indep_setsD[OF *] ballI) auto
hoelzl@42987
   683
next
hoelzl@42987
   684
  assume indep: "\<forall>A\<in>Pi I F. prob (\<Inter>j\<in>I. A j) = (\<Prod>j\<in>I. prob (A j))"
hoelzl@42987
   685
  show "indep_sets F I"
hoelzl@42987
   686
  proof (rule indep_setsI[OF F(1)])
hoelzl@42987
   687
    fix A J assume J: "J \<noteq> {}" "J \<subseteq> I" "finite J"
hoelzl@42987
   688
    assume A: "\<forall>j\<in>J. A j \<in> F j"
wenzelm@46731
   689
    let ?A = "\<lambda>j. if j \<in> J then A j else space M"
hoelzl@42987
   690
    have "prob (\<Inter>j\<in>I. ?A j) = prob (\<Inter>j\<in>J. A j)"
immler@50244
   691
      using subset_trans[OF F(1) sets.space_closed] J A
hoelzl@42987
   692
      by (auto intro!: arg_cong[where f=prob] split: split_if_asm) blast
hoelzl@42987
   693
    also
hoelzl@42987
   694
    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
   695
      by (auto split: split_if_asm)
hoelzl@42987
   696
    with indep have "prob (\<Inter>j\<in>I. ?A j) = (\<Prod>j\<in>I. prob (?A j))"
hoelzl@42987
   697
      by auto
hoelzl@42987
   698
    also have "\<dots> = (\<Prod>j\<in>J. prob (A j))"
hoelzl@42987
   699
      unfolding if_distrib setprod.If_cases[OF `finite I`]
hoelzl@42987
   700
      using prob_space `J \<subseteq> I` by (simp add: Int_absorb1 setprod_1)
hoelzl@42987
   701
    finally show "prob (\<Inter>j\<in>J. A j) = (\<Prod>j\<in>J. prob (A j))" ..
hoelzl@42987
   702
  qed
hoelzl@42987
   703
qed
hoelzl@42987
   704
hoelzl@42989
   705
lemma (in prob_space) indep_vars_finite:
hoelzl@42987
   706
  fixes I :: "'i set"
hoelzl@42987
   707
  assumes I: "I \<noteq> {}" "finite I"
hoelzl@47694
   708
    and M': "\<And>i. i \<in> I \<Longrightarrow> sets (M' i) = sigma_sets (space (M' i)) (E i)"
hoelzl@47694
   709
    and rv: "\<And>i. i \<in> I \<Longrightarrow> random_variable (M' i) (X i)"
hoelzl@47694
   710
    and Int_stable: "\<And>i. i \<in> I \<Longrightarrow> Int_stable (E i)"
hoelzl@47694
   711
    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
   712
  shows "indep_vars M' X I \<longleftrightarrow>
hoelzl@47694
   713
    (\<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
   714
proof -
hoelzl@42987
   715
  from rv have X: "\<And>i. i \<in> I \<Longrightarrow> X i \<in> space M \<rightarrow> space (M' i)"
hoelzl@42987
   716
    unfolding measurable_def by simp
hoelzl@42987
   717
hoelzl@42987
   718
  { fix i assume "i\<in>I"
hoelzl@47694
   719
    from closed[OF `i \<in> I`]
hoelzl@47694
   720
    have "sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}
hoelzl@47694
   721
      = sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> E i}"
hoelzl@47694
   722
      unfolding sigma_sets_vimage_commute[OF X, OF `i \<in> I`, symmetric] M'[OF `i \<in> I`]
hoelzl@42987
   723
      by (subst sigma_sets_sigma_sets_eq) auto }
hoelzl@47694
   724
  note sigma_sets_X = this
hoelzl@42987
   725
hoelzl@42987
   726
  { fix i assume "i\<in>I"
hoelzl@47694
   727
    have "Int_stable {X i -` A \<inter> space M |A. A \<in> E i}"
hoelzl@42987
   728
    proof (rule Int_stableI)
hoelzl@47694
   729
      fix a assume "a \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
hoelzl@47694
   730
      then obtain A where "a = X i -` A \<inter> space M" "A \<in> E i" by auto
hoelzl@42987
   731
      moreover
hoelzl@47694
   732
      fix b assume "b \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
hoelzl@47694
   733
      then obtain B where "b = X i -` B \<inter> space M" "B \<in> E i" by auto
hoelzl@42987
   734
      moreover
hoelzl@42987
   735
      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
   736
      moreover note Int_stable[OF `i \<in> I`]
hoelzl@42987
   737
      ultimately
hoelzl@47694
   738
      show "a \<inter> b \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
hoelzl@42987
   739
        by (auto simp del: vimage_Int intro!: exI[of _ "A \<inter> B"] dest: Int_stableD)
hoelzl@42987
   740
    qed }
hoelzl@47694
   741
  note indep_sets_X = indep_sets_sigma_sets_iff[OF this]
hoelzl@43340
   742
hoelzl@42987
   743
  { fix i assume "i \<in> I"
hoelzl@47694
   744
    { fix A assume "A \<in> E i"
hoelzl@47694
   745
      with M'[OF `i \<in> I`] have "A \<in> sets (M' i)" by auto
hoelzl@42987
   746
      moreover
hoelzl@47694
   747
      from rv[OF `i\<in>I`] have "X i \<in> measurable M (M' i)" by auto
hoelzl@42987
   748
      ultimately
hoelzl@42987
   749
      have "X i -` A \<inter> space M \<in> sets M" by (auto intro: measurable_sets) }
hoelzl@42987
   750
    with X[OF `i\<in>I`] space[OF `i\<in>I`]
hoelzl@47694
   751
    have "{X i -` A \<inter> space M |A. A \<in> E i} \<subseteq> events"
hoelzl@47694
   752
      "space M \<in> {X i -` A \<inter> space M |A. A \<in> E i}"
hoelzl@42987
   753
      by (auto intro!: exI[of _ "space (M' i)"]) }
hoelzl@47694
   754
  note indep_sets_finite_X = indep_sets_finite[OF I this]
hoelzl@43340
   755
hoelzl@47694
   756
  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
   757
    (\<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
   758
    (is "?L = ?R")
hoelzl@42987
   759
  proof safe
hoelzl@47694
   760
    fix A assume ?L and A: "A \<in> (\<Pi> i\<in>I. E i)"
hoelzl@42987
   761
    from `?L`[THEN bspec, of "\<lambda>i. X i -` A i \<inter> space M"] A `I \<noteq> {}`
hoelzl@42987
   762
    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
   763
      by (auto simp add: Pi_iff)
hoelzl@42987
   764
  next
hoelzl@47694
   765
    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
   766
    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
   767
    from bchoice[OF this] obtain B where B: "\<forall>i\<in>I. A i = X i -` B i \<inter> space M"
hoelzl@47694
   768
      "B \<in> (\<Pi> i\<in>I. E i)" by auto
hoelzl@42987
   769
    from `?R`[THEN bspec, OF B(2)] B(1) `I \<noteq> {}`
hoelzl@42987
   770
    show "prob (INTER I A) = (\<Prod>j\<in>I. prob (A j))"
hoelzl@42987
   771
      by simp
hoelzl@42987
   772
  qed
hoelzl@42987
   773
  then show ?thesis using `I \<noteq> {}`
hoelzl@47694
   774
    by (simp add: rv indep_vars_def indep_sets_X sigma_sets_X indep_sets_finite_X cong: indep_sets_cong)
hoelzl@42988
   775
qed
hoelzl@42988
   776
hoelzl@42989
   777
lemma (in prob_space) indep_vars_compose:
hoelzl@42989
   778
  assumes "indep_vars M' X I"
hoelzl@47694
   779
  assumes rv: "\<And>i. i \<in> I \<Longrightarrow> Y i \<in> measurable (M' i) (N i)"
hoelzl@42989
   780
  shows "indep_vars N (\<lambda>i. Y i \<circ> X i) I"
hoelzl@42989
   781
  unfolding indep_vars_def
hoelzl@42988
   782
proof
hoelzl@42989
   783
  from rv `indep_vars M' X I`
hoelzl@42988
   784
  show "\<forall>i\<in>I. random_variable (N i) (Y i \<circ> X i)"
hoelzl@47694
   785
    by (auto simp: indep_vars_def)
hoelzl@42988
   786
hoelzl@42988
   787
  have "indep_sets (\<lambda>i. sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) I"
hoelzl@42989
   788
    using `indep_vars M' X I` by (simp add: indep_vars_def)
hoelzl@42988
   789
  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
   790
  proof (rule indep_sets_mono_sets)
hoelzl@42988
   791
    fix i assume "i \<in> I"
hoelzl@42989
   792
    with `indep_vars M' X I` have X: "X i \<in> space M \<rightarrow> space (M' i)"
hoelzl@42989
   793
      unfolding indep_vars_def measurable_def by auto
hoelzl@42988
   794
    { fix A assume "A \<in> sets (N i)"
hoelzl@42988
   795
      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
   796
        by (intro exI[of _ "Y i -` A \<inter> space (M' i)"])
haftmann@56154
   797
           (auto simp: vimage_comp intro!: measurable_sets rv `i \<in> I` funcset_mem[OF X]) }
hoelzl@42988
   798
    then show "sigma_sets (space M) {(Y i \<circ> X i) -` A \<inter> space M |A. A \<in> sets (N i)} \<subseteq>
hoelzl@42988
   799
      sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}"
haftmann@56154
   800
      by (intro sigma_sets_subseteq) (auto simp: vimage_comp)
hoelzl@42988
   801
  qed
hoelzl@42988
   802
qed
hoelzl@42988
   803
hoelzl@47694
   804
lemma (in prob_space) indep_varsD_finite:
hoelzl@42989
   805
  assumes X: "indep_vars M' X I"
hoelzl@42988
   806
  assumes I: "I \<noteq> {}" "finite I" "\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M' i)"
hoelzl@42988
   807
  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
   808
proof (rule indep_setsD)
hoelzl@42988
   809
  show "indep_sets (\<lambda>i. sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) I"
hoelzl@42989
   810
    using X by (auto simp: indep_vars_def)
hoelzl@42988
   811
  show "I \<subseteq> I" "I \<noteq> {}" "finite I" using I by auto
hoelzl@42988
   812
  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
   813
    using I by auto
hoelzl@42988
   814
qed
hoelzl@42988
   815
hoelzl@47694
   816
lemma (in prob_space) indep_varsD:
hoelzl@47694
   817
  assumes X: "indep_vars M' X I"
hoelzl@47694
   818
  assumes I: "J \<noteq> {}" "finite J" "J \<subseteq> I" "\<And>i. i \<in> J \<Longrightarrow> A i \<in> sets (M' i)"
hoelzl@47694
   819
  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
   820
proof (rule indep_setsD)
hoelzl@47694
   821
  show "indep_sets (\<lambda>i. sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)}) I"
hoelzl@47694
   822
    using X by (auto simp: indep_vars_def)
hoelzl@47694
   823
  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
   824
    using I by auto
hoelzl@47694
   825
qed fact+
hoelzl@47694
   826
hoelzl@47694
   827
lemma (in prob_space) indep_vars_iff_distr_eq_PiM:
hoelzl@47694
   828
  fixes I :: "'i set" and X :: "'i \<Rightarrow> 'a \<Rightarrow> 'b"
hoelzl@47694
   829
  assumes "I \<noteq> {}"
hoelzl@42988
   830
  assumes rv: "\<And>i. random_variable (M' i) (X i)"
hoelzl@42989
   831
  shows "indep_vars M' X I \<longleftrightarrow>
wenzelm@53015
   832
    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
   833
proof -
wenzelm@53015
   834
  let ?P = "\<Pi>\<^sub>M i\<in>I. M' i"
hoelzl@47694
   835
  let ?X = "\<lambda>x. \<lambda>i\<in>I. X i x"
hoelzl@47694
   836
  let ?D = "distr M ?P ?X"
hoelzl@47694
   837
  have X: "random_variable ?P ?X" by (intro measurable_restrict rv)
hoelzl@47694
   838
  interpret D: prob_space ?D by (intro prob_space_distr X)
hoelzl@42988
   839
hoelzl@47694
   840
  let ?D' = "\<lambda>i. distr M (M' i) (X i)"
wenzelm@53015
   841
  let ?P' = "\<Pi>\<^sub>M i\<in>I. distr M (M' i) (X i)"
hoelzl@47694
   842
  interpret D': prob_space "?D' i" for i by (intro prob_space_distr rv)
hoelzl@47694
   843
  interpret P: product_prob_space ?D' I ..
hoelzl@47694
   844
    
hoelzl@42988
   845
  show ?thesis
hoelzl@47694
   846
  proof
hoelzl@42989
   847
    assume "indep_vars M' X I"
hoelzl@47694
   848
    show "?D = ?P'"
hoelzl@47694
   849
    proof (rule measure_eqI_generator_eq)
hoelzl@47694
   850
      show "Int_stable (prod_algebra I M')"
hoelzl@47694
   851
        by (rule Int_stable_prod_algebra)
hoelzl@47694
   852
      show "prod_algebra I M' \<subseteq> Pow (space ?P)"
hoelzl@47694
   853
        using prod_algebra_sets_into_space by (simp add: space_PiM)
hoelzl@47694
   854
      show "sets ?D = sigma_sets (space ?P) (prod_algebra I M')"
hoelzl@47694
   855
        by (simp add: sets_PiM space_PiM)
hoelzl@47694
   856
      show "sets ?P' = sigma_sets (space ?P) (prod_algebra I M')"
hoelzl@47694
   857
        by (simp add: sets_PiM space_PiM cong: prod_algebra_cong)
wenzelm@53015
   858
      let ?A = "\<lambda>i. \<Pi>\<^sub>E i\<in>I. space (M' i)"
wenzelm@53015
   859
      show "range ?A \<subseteq> prod_algebra I M'" "(\<Union>i. ?A i) = space (Pi\<^sub>M I M')"
hoelzl@47694
   860
        by (auto simp: space_PiM intro!: space_in_prod_algebra cong: prod_algebra_cong)
wenzelm@53015
   861
      { fix i show "emeasure ?D (\<Pi>\<^sub>E i\<in>I. space (M' i)) \<noteq> \<infinity>" by auto }
hoelzl@47694
   862
    next
hoelzl@47694
   863
      fix E assume E: "E \<in> prod_algebra I M'"
hoelzl@47694
   864
      from prod_algebraE[OF E] guess J Y . note J = this
hoelzl@43340
   865
hoelzl@47694
   866
      from E have "E \<in> sets ?P" by (auto simp: sets_PiM)
hoelzl@47694
   867
      then have "emeasure ?D E = emeasure M (?X -` E \<inter> space M)"
hoelzl@47694
   868
        by (simp add: emeasure_distr X)
hoelzl@47694
   869
      also have "?X -` E \<inter> space M = (\<Inter>i\<in>J. X i -` Y i \<inter> space M)"
hoelzl@50123
   870
        using J `I \<noteq> {}` measurable_space[OF rv] by (auto simp: prod_emb_def PiE_iff split: split_if_asm)
hoelzl@47694
   871
      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
   872
        using `indep_vars M' X I` J `I \<noteq> {}` using indep_varsD[of M' X I J]
hoelzl@47694
   873
        by (auto simp: emeasure_eq_measure setprod_ereal)
hoelzl@47694
   874
      also have "\<dots> = (\<Prod> i\<in>J. emeasure (?D' i) (Y i))"
hoelzl@47694
   875
        using rv J by (simp add: emeasure_distr)
hoelzl@47694
   876
      also have "\<dots> = emeasure ?P' E"
hoelzl@47694
   877
        using P.emeasure_PiM_emb[of J Y] J by (simp add: prod_emb_def)
hoelzl@47694
   878
      finally show "emeasure ?D E = emeasure ?P' E" .
hoelzl@42988
   879
    qed
hoelzl@42988
   880
  next
hoelzl@47694
   881
    assume "?D = ?P'"
hoelzl@47694
   882
    show "indep_vars M' X I" unfolding indep_vars_def
hoelzl@47694
   883
    proof (intro conjI indep_setsI ballI rv)
hoelzl@47694
   884
      fix i show "sigma_sets (space M) {X i -` A \<inter> space M |A. A \<in> sets (M' i)} \<subseteq> events"
immler@50244
   885
        by (auto intro!: sets.sigma_sets_subset measurable_sets rv)
hoelzl@42988
   886
    next
hoelzl@47694
   887
      fix J Y' assume J: "J \<noteq> {}" "J \<subseteq> I" "finite J"
hoelzl@47694
   888
      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
   889
      have "\<forall>j\<in>J. \<exists>Y. Y' j = X j -` Y \<inter> space M \<and> Y \<in> sets (M' j)"
hoelzl@42988
   890
      proof
hoelzl@47694
   891
        fix j assume "j \<in> J"
hoelzl@47694
   892
        from Y'[rule_format, OF this] rv[of j]
hoelzl@47694
   893
        show "\<exists>Y. Y' j = X j -` Y \<inter> space M \<and> Y \<in> sets (M' j)"
hoelzl@47694
   894
          by (subst (asm) sigma_sets_vimage_commute[symmetric, of _ _ "space (M' j)"])
immler@50244
   895
             (auto dest: measurable_space simp: sets.sigma_sets_eq)
hoelzl@42988
   896
      qed
hoelzl@47694
   897
      from bchoice[OF this] obtain Y where
hoelzl@47694
   898
        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
   899
      let ?E = "prod_emb I M' J (Pi\<^sub>E J Y)"
hoelzl@47694
   900
      from Y have "(\<Inter>j\<in>J. Y' j) = ?X -` ?E \<inter> space M"
hoelzl@50123
   901
        using J `I \<noteq> {}` measurable_space[OF rv] by (auto simp: prod_emb_def PiE_iff split: split_if_asm)
hoelzl@47694
   902
      then have "emeasure M (\<Inter>j\<in>J. Y' j) = emeasure M (?X -` ?E \<inter> space M)"
hoelzl@47694
   903
        by simp
hoelzl@47694
   904
      also have "\<dots> = emeasure ?D ?E"
hoelzl@47694
   905
        using Y  J by (intro emeasure_distr[symmetric] X sets_PiM_I) auto
hoelzl@47694
   906
      also have "\<dots> = emeasure ?P' ?E"
hoelzl@47694
   907
        using `?D = ?P'` by simp
hoelzl@47694
   908
      also have "\<dots> = (\<Prod> i\<in>J. emeasure (?D' i) (Y i))"
hoelzl@47694
   909
        using P.emeasure_PiM_emb[of J Y] J Y by (simp add: prod_emb_def)
hoelzl@47694
   910
      also have "\<dots> = (\<Prod> i\<in>J. emeasure M (Y' i))"
hoelzl@47694
   911
        using rv J Y by (simp add: emeasure_distr)
hoelzl@47694
   912
      finally have "emeasure M (\<Inter>j\<in>J. Y' j) = (\<Prod> i\<in>J. emeasure M (Y' i))" .
hoelzl@47694
   913
      then show "prob (\<Inter>j\<in>J. Y' j) = (\<Prod> i\<in>J. prob (Y' i))"
hoelzl@47694
   914
        by (auto simp: emeasure_eq_measure setprod_ereal)
hoelzl@42988
   915
    qed
hoelzl@42988
   916
  qed
hoelzl@42987
   917
qed
hoelzl@42987
   918
hoelzl@42989
   919
lemma (in prob_space) indep_varD:
hoelzl@42989
   920
  assumes indep: "indep_var Ma A Mb B"
hoelzl@42989
   921
  assumes sets: "Xa \<in> sets Ma" "Xb \<in> sets Mb"
hoelzl@42989
   922
  shows "prob ((\<lambda>x. (A x, B x)) -` (Xa \<times> Xb) \<inter> space M) =
hoelzl@42989
   923
    prob (A -` Xa \<inter> space M) * prob (B -` Xb \<inter> space M)"
hoelzl@42989
   924
proof -
hoelzl@42989
   925
  have "prob ((\<lambda>x. (A x, B x)) -` (Xa \<times> Xb) \<inter> space M) =
blanchet@55414
   926
    prob (\<Inter>i\<in>UNIV. (case_bool A B i -` case_bool Xa Xb i \<inter> space M))"
hoelzl@42989
   927
    by (auto intro!: arg_cong[where f=prob] simp: UNIV_bool)
blanchet@55414
   928
  also have "\<dots> = (\<Prod>i\<in>UNIV. prob (case_bool A B i -` case_bool Xa Xb i \<inter> space M))"
hoelzl@42989
   929
    using indep unfolding indep_var_def
hoelzl@42989
   930
    by (rule indep_varsD) (auto split: bool.split intro: sets)
hoelzl@42989
   931
  also have "\<dots> = prob (A -` Xa \<inter> space M) * prob (B -` Xb \<inter> space M)"
hoelzl@42989
   932
    unfolding UNIV_bool by simp
hoelzl@42989
   933
  finally show ?thesis .
hoelzl@42989
   934
qed
hoelzl@42989
   935
hoelzl@43340
   936
lemma (in prob_space)
hoelzl@43340
   937
  assumes "indep_var S X T Y"
hoelzl@43340
   938
  shows indep_var_rv1: "random_variable S X"
hoelzl@43340
   939
    and indep_var_rv2: "random_variable T Y"
hoelzl@43340
   940
proof -
blanchet@55414
   941
  have "\<forall>i\<in>UNIV. random_variable (case_bool S T i) (case_bool X Y i)"
hoelzl@43340
   942
    using assms unfolding indep_var_def indep_vars_def by auto
hoelzl@43340
   943
  then show "random_variable S X" "random_variable T Y"
hoelzl@43340
   944
    unfolding UNIV_bool by auto
hoelzl@43340
   945
qed
hoelzl@43340
   946
hoelzl@47694
   947
lemma (in prob_space) indep_var_distribution_eq:
hoelzl@47694
   948
  "indep_var S X T Y \<longleftrightarrow> random_variable S X \<and> random_variable T Y \<and>
wenzelm@53015
   949
    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
   950
proof safe
hoelzl@47694
   951
  assume "indep_var S X T Y"
hoelzl@47694
   952
  then show rvs: "random_variable S X" "random_variable T Y"
hoelzl@47694
   953
    by (blast dest: indep_var_rv1 indep_var_rv2)+
wenzelm@53015
   954
  then have XY: "random_variable (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@47694
   955
    by (rule measurable_Pair)
hoelzl@47694
   956
hoelzl@47694
   957
  interpret X: prob_space ?S by (rule prob_space_distr) fact
hoelzl@47694
   958
  interpret Y: prob_space ?T by (rule prob_space_distr) fact
hoelzl@47694
   959
  interpret XY: pair_prob_space ?S ?T ..
wenzelm@53015
   960
  show "?S \<Otimes>\<^sub>M ?T = ?J"
hoelzl@47694
   961
  proof (rule pair_measure_eqI)
hoelzl@47694
   962
    show "sigma_finite_measure ?S" ..
hoelzl@47694
   963
    show "sigma_finite_measure ?T" ..
hoelzl@43340
   964
hoelzl@47694
   965
    fix A B assume A: "A \<in> sets ?S" and B: "B \<in> sets ?T"
hoelzl@47694
   966
    have "emeasure ?J (A \<times> B) = emeasure M ((\<lambda>x. (X x, Y x)) -` (A \<times> B) \<inter> space M)"
hoelzl@47694
   967
      using A B by (intro emeasure_distr[OF XY]) auto
hoelzl@47694
   968
    also have "\<dots> = emeasure M (X -` A \<inter> space M) * emeasure M (Y -` B \<inter> space M)"
hoelzl@47694
   969
      using indep_varD[OF `indep_var S X T Y`, of A B] A B by (simp add: emeasure_eq_measure)
hoelzl@47694
   970
    also have "\<dots> = emeasure ?S A * emeasure ?T B"
hoelzl@47694
   971
      using rvs A B by (simp add: emeasure_distr)
hoelzl@47694
   972
    finally show "emeasure ?S A * emeasure ?T B = emeasure ?J (A \<times> B)" by simp
hoelzl@47694
   973
  qed simp
hoelzl@47694
   974
next
hoelzl@47694
   975
  assume rvs: "random_variable S X" "random_variable T Y"
wenzelm@53015
   976
  then have XY: "random_variable (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x))"
hoelzl@47694
   977
    by (rule measurable_Pair)
hoelzl@43340
   978
hoelzl@47694
   979
  let ?S = "distr M S X" and ?T = "distr M T Y"
hoelzl@47694
   980
  interpret X: prob_space ?S by (rule prob_space_distr) fact
hoelzl@47694
   981
  interpret Y: prob_space ?T by (rule prob_space_distr) fact
hoelzl@47694
   982
  interpret XY: pair_prob_space ?S ?T ..
hoelzl@47694
   983
wenzelm@53015
   984
  assume "?S \<Otimes>\<^sub>M ?T = ?J"
hoelzl@43340
   985
hoelzl@47694
   986
  { fix S and X
hoelzl@47694
   987
    have "Int_stable {X -` A \<inter> space M |A. A \<in> sets S}"
hoelzl@47694
   988
    proof (safe intro!: Int_stableI)
hoelzl@47694
   989
      fix A B assume "A \<in> sets S" "B \<in> sets S"
hoelzl@47694
   990
      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
   991
        by (intro exI[of _ "A \<inter> B"]) auto
hoelzl@47694
   992
    qed }
hoelzl@47694
   993
  note Int_stable = this
hoelzl@47694
   994
hoelzl@47694
   995
  show "indep_var S X T Y" unfolding indep_var_eq
hoelzl@47694
   996
  proof (intro conjI indep_set_sigma_sets Int_stable rvs)
hoelzl@47694
   997
    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
   998
    proof (safe intro!: indep_setI)
hoelzl@47694
   999
      { fix A assume "A \<in> sets S" then show "X -` A \<inter> space M \<in> sets M"
hoelzl@47694
  1000
        using `X \<in> measurable M S` by (auto intro: measurable_sets) }
hoelzl@47694
  1001
      { fix A assume "A \<in> sets T" then show "Y -` A \<inter> space M \<in> sets M"
hoelzl@47694
  1002
        using `Y \<in> measurable M T` by (auto intro: measurable_sets) }
hoelzl@47694
  1003
    next
hoelzl@47694
  1004
      fix A B assume ab: "A \<in> sets S" "B \<in> sets T"
hoelzl@47694
  1005
      then have "ereal (prob ((X -` A \<inter> space M) \<inter> (Y -` B \<inter> space M))) = emeasure ?J (A \<times> B)"
hoelzl@47694
  1006
        using XY by (auto simp add: emeasure_distr emeasure_eq_measure intro!: arg_cong[where f="prob"])
wenzelm@53015
  1007
      also have "\<dots> = emeasure (?S \<Otimes>\<^sub>M ?T) (A \<times> B)"
wenzelm@53015
  1008
        unfolding `?S \<Otimes>\<^sub>M ?T = ?J` ..
hoelzl@47694
  1009
      also have "\<dots> = emeasure ?S A * emeasure ?T B"
hoelzl@49776
  1010
        using ab by (simp add: Y.emeasure_pair_measure_Times)
hoelzl@47694
  1011
      finally show "prob ((X -` A \<inter> space M) \<inter> (Y -` B \<inter> space M)) =
hoelzl@47694
  1012
        prob (X -` A \<inter> space M) * prob (Y -` B \<inter> space M)"
hoelzl@47694
  1013
        using rvs ab by (simp add: emeasure_eq_measure emeasure_distr)
hoelzl@47694
  1014
    qed
hoelzl@43340
  1015
  qed
hoelzl@43340
  1016
qed
hoelzl@42989
  1017
hoelzl@49795
  1018
lemma (in prob_space) distributed_joint_indep:
hoelzl@49795
  1019
  assumes S: "sigma_finite_measure S" and T: "sigma_finite_measure T"
hoelzl@49795
  1020
  assumes X: "distributed M S X Px" and Y: "distributed M T Y Py"
hoelzl@49795
  1021
  assumes indep: "indep_var S X T Y"
wenzelm@53015
  1022
  shows "distributed M (S \<Otimes>\<^sub>M T) (\<lambda>x. (X x, Y x)) (\<lambda>(x, y). Px x * Py y)"
hoelzl@49795
  1023
  using indep_var_distribution_eq[of S X T Y] indep
hoelzl@49795
  1024
  by (intro distributed_joint_indep'[OF S T X Y]) auto
hoelzl@49795
  1025
hoelzl@42861
  1026
end