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