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