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