src/HOL/Probability/Infinite_Product_Measure.thy
author immler@in.tum.de
Wed Nov 07 11:33:27 2012 +0100 (2012-11-07)
changeset 50039 bfd5198cbe40
parent 50038 8e32c9254535
child 50040 5da32dc55cd8
permissions -rw-r--r--
added projective_family; generalized generator in product_prob_space to projective_family
hoelzl@42147
     1
(*  Title:      HOL/Probability/Infinite_Product_Measure.thy
hoelzl@42147
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42147
     3
*)
hoelzl@42147
     4
hoelzl@42147
     5
header {*Infinite Product Measure*}
hoelzl@42147
     6
hoelzl@42147
     7
theory Infinite_Product_Measure
immler@50039
     8
  imports Probability_Measure Caratheodory Projective_Family
hoelzl@42147
     9
begin
hoelzl@42147
    10
hoelzl@49780
    11
lemma split_merge: "P (merge I J (x,y) i) \<longleftrightarrow> (i \<in> I \<longrightarrow> P (x i)) \<and> (i \<in> J - I \<longrightarrow> P (y i)) \<and> (i \<notin> I \<union> J \<longrightarrow> P undefined)"
hoelzl@42147
    12
  unfolding merge_def by auto
hoelzl@42147
    13
hoelzl@49780
    14
lemma extensional_merge_sub: "I \<union> J \<subseteq> K \<Longrightarrow> merge I J (x, y) \<in> extensional K"
hoelzl@42147
    15
  unfolding merge_def extensional_def by auto
hoelzl@42147
    16
hoelzl@42147
    17
lemma injective_vimage_restrict:
hoelzl@42147
    18
  assumes J: "J \<subseteq> I"
hoelzl@42147
    19
  and sets: "A \<subseteq> (\<Pi>\<^isub>E i\<in>J. S i)" "B \<subseteq> (\<Pi>\<^isub>E i\<in>J. S i)" and ne: "(\<Pi>\<^isub>E i\<in>I. S i) \<noteq> {}"
hoelzl@42147
    20
  and eq: "(\<lambda>x. restrict x J) -` A \<inter> (\<Pi>\<^isub>E i\<in>I. S i) = (\<lambda>x. restrict x J) -` B \<inter> (\<Pi>\<^isub>E i\<in>I. S i)"
hoelzl@42147
    21
  shows "A = B"
hoelzl@42147
    22
proof  (intro set_eqI)
hoelzl@42147
    23
  fix x
hoelzl@42147
    24
  from ne obtain y where y: "\<And>i. i \<in> I \<Longrightarrow> y i \<in> S i" by auto
hoelzl@42147
    25
  have "J \<inter> (I - J) = {}" by auto
hoelzl@42147
    26
  show "x \<in> A \<longleftrightarrow> x \<in> B"
hoelzl@42147
    27
  proof cases
hoelzl@42147
    28
    assume x: "x \<in> (\<Pi>\<^isub>E i\<in>J. S i)"
hoelzl@49780
    29
    have "x \<in> A \<longleftrightarrow> merge J (I - J) (x,y) \<in> (\<lambda>x. restrict x J) -` A \<inter> (\<Pi>\<^isub>E i\<in>I. S i)"
hoelzl@42147
    30
      using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub split: split_merge)
hoelzl@42147
    31
    then show "x \<in> A \<longleftrightarrow> x \<in> B"
hoelzl@42147
    32
      using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub eq split: split_merge)
hoelzl@42147
    33
  next
hoelzl@42147
    34
    assume "x \<notin> (\<Pi>\<^isub>E i\<in>J. S i)" with sets show "x \<in> A \<longleftrightarrow> x \<in> B" by auto
hoelzl@42147
    35
  qed
hoelzl@42147
    36
qed
hoelzl@42147
    37
hoelzl@47694
    38
lemma (in product_prob_space) distr_restrict:
hoelzl@42147
    39
  assumes "J \<noteq> {}" "J \<subseteq> K" "finite K"
hoelzl@47694
    40
  shows "(\<Pi>\<^isub>M i\<in>J. M i) = distr (\<Pi>\<^isub>M i\<in>K. M i) (\<Pi>\<^isub>M i\<in>J. M i) (\<lambda>f. restrict f J)" (is "?P = ?D")
hoelzl@47694
    41
proof (rule measure_eqI_generator_eq)
hoelzl@47694
    42
  have "finite J" using `J \<subseteq> K` `finite K` by (auto simp add: finite_subset)
hoelzl@47694
    43
  interpret J: finite_product_prob_space M J proof qed fact
hoelzl@47694
    44
  interpret K: finite_product_prob_space M K proof qed fact
hoelzl@47694
    45
hoelzl@47694
    46
  let ?J = "{Pi\<^isub>E J E | E. \<forall>i\<in>J. E i \<in> sets (M i)}"
hoelzl@47694
    47
  let ?F = "\<lambda>i. \<Pi>\<^isub>E k\<in>J. space (M k)"
hoelzl@47694
    48
  let ?\<Omega> = "(\<Pi>\<^isub>E k\<in>J. space (M k))"
hoelzl@47694
    49
  show "Int_stable ?J"
hoelzl@47694
    50
    by (rule Int_stable_PiE)
hoelzl@49784
    51
  show "range ?F \<subseteq> ?J" "(\<Union>i. ?F i) = ?\<Omega>"
hoelzl@47694
    52
    using `finite J` by (auto intro!: prod_algebraI_finite)
hoelzl@47694
    53
  { fix i show "emeasure ?P (?F i) \<noteq> \<infinity>" by simp }
hoelzl@47694
    54
  show "?J \<subseteq> Pow ?\<Omega>" by (auto simp: Pi_iff dest: sets_into_space)
hoelzl@47694
    55
  show "sets (\<Pi>\<^isub>M i\<in>J. M i) = sigma_sets ?\<Omega> ?J" "sets ?D = sigma_sets ?\<Omega> ?J"
hoelzl@47694
    56
    using `finite J` by (simp_all add: sets_PiM prod_algebra_eq_finite Pi_iff)
hoelzl@47694
    57
  
hoelzl@47694
    58
  fix X assume "X \<in> ?J"
hoelzl@47694
    59
  then obtain E where [simp]: "X = Pi\<^isub>E J E" and E: "\<forall>i\<in>J. E i \<in> sets (M i)" by auto
hoelzl@50003
    60
  with `finite J` have X: "X \<in> sets (Pi\<^isub>M J M)"
hoelzl@50003
    61
    by simp
hoelzl@47694
    62
hoelzl@47694
    63
  have "emeasure ?P X = (\<Prod> i\<in>J. emeasure (M i) (E i))"
hoelzl@47694
    64
    using E by (simp add: J.measure_times)
hoelzl@47694
    65
  also have "\<dots> = (\<Prod> i\<in>J. emeasure (M i) (if i \<in> J then E i else space (M i)))"
hoelzl@47694
    66
    by simp
hoelzl@47694
    67
  also have "\<dots> = (\<Prod> i\<in>K. emeasure (M i) (if i \<in> J then E i else space (M i)))"
hoelzl@47694
    68
    using `finite K` `J \<subseteq> K`
hoelzl@47694
    69
    by (intro setprod_mono_one_left) (auto simp: M.emeasure_space_1)
hoelzl@47694
    70
  also have "\<dots> = emeasure (Pi\<^isub>M K M) (\<Pi>\<^isub>E i\<in>K. if i \<in> J then E i else space (M i))"
hoelzl@47694
    71
    using E by (simp add: K.measure_times)
hoelzl@47694
    72
  also have "(\<Pi>\<^isub>E i\<in>K. if i \<in> J then E i else space (M i)) = (\<lambda>f. restrict f J) -` Pi\<^isub>E J E \<inter> (\<Pi>\<^isub>E i\<in>K. space (M i))"
hoelzl@47694
    73
    using `J \<subseteq> K` sets_into_space E by (force simp:  Pi_iff split: split_if_asm)
hoelzl@47694
    74
  finally show "emeasure (Pi\<^isub>M J M) X = emeasure ?D X"
hoelzl@47694
    75
    using X `J \<subseteq> K` apply (subst emeasure_distr)
hoelzl@47694
    76
    by (auto intro!: measurable_restrict_subset simp: space_PiM)
hoelzl@42147
    77
qed
hoelzl@42147
    78
hoelzl@47694
    79
lemma (in product_prob_space) emeasure_prod_emb[simp]:
hoelzl@47694
    80
  assumes L: "J \<noteq> {}" "J \<subseteq> L" "finite L" and X: "X \<in> sets (Pi\<^isub>M J M)"
immler@50039
    81
  shows "emeasure (Pi\<^isub>M L M) (prod_emb L M J X) = emeasure (Pi\<^isub>M J M) X"
hoelzl@47694
    82
  by (subst distr_restrict[OF L])
hoelzl@47694
    83
     (simp add: prod_emb_def space_PiM emeasure_distr measurable_restrict_subset L X)
hoelzl@42147
    84
immler@50039
    85
sublocale product_prob_space \<subseteq> projective_family I "\<lambda>J. PiM J M" M
immler@50039
    86
proof
immler@50039
    87
  fix J::"'i set" assume "finite J"
immler@50039
    88
  interpret f: finite_product_prob_space M J proof qed fact
immler@50039
    89
  show "emeasure (Pi\<^isub>M J M) (space (Pi\<^isub>M J M)) \<noteq> \<infinity>" by simp
immler@50039
    90
qed simp_all
immler@50039
    91
immler@50039
    92
lemma (in projective_family) prod_emb_injective:
hoelzl@47694
    93
  assumes "J \<noteq> {}" "J \<subseteq> L" "finite J" and sets: "X \<in> sets (Pi\<^isub>M J M)" "Y \<in> sets (Pi\<^isub>M J M)"
hoelzl@47694
    94
  assumes "prod_emb L M J X = prod_emb L M J Y"
hoelzl@47694
    95
  shows "X = Y"
hoelzl@47694
    96
proof (rule injective_vimage_restrict)
hoelzl@47694
    97
  show "X \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))" "Y \<subseteq> (\<Pi>\<^isub>E i\<in>J. space (M i))"
hoelzl@47694
    98
    using sets[THEN sets_into_space] by (auto simp: space_PiM)
hoelzl@47694
    99
  have "\<forall>i\<in>L. \<exists>x. x \<in> space (M i)"
hoelzl@49780
   100
      using M.not_empty by auto
hoelzl@47694
   101
  from bchoice[OF this]
hoelzl@47694
   102
  show "(\<Pi>\<^isub>E i\<in>L. space (M i)) \<noteq> {}" by auto
hoelzl@47694
   103
  show "(\<lambda>x. restrict x J) -` X \<inter> (\<Pi>\<^isub>E i\<in>L. space (M i)) = (\<lambda>x. restrict x J) -` Y \<inter> (\<Pi>\<^isub>E i\<in>L. space (M i))"
hoelzl@47694
   104
    using `prod_emb L M J X = prod_emb L M J Y` by (simp add: prod_emb_def)
hoelzl@47694
   105
qed fact
hoelzl@42147
   106
immler@50039
   107
abbreviation (in projective_family)
immler@50039
   108
  "emb L K X \<equiv> prod_emb L M K X"
immler@50039
   109
immler@50039
   110
definition (in projective_family) generator :: "('i \<Rightarrow> 'a) set set" where
hoelzl@47694
   111
  "generator = (\<Union>J\<in>{J. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I}. emb I J ` sets (Pi\<^isub>M J M))"
hoelzl@42147
   112
immler@50039
   113
lemma (in projective_family) generatorI':
hoelzl@47694
   114
  "J \<noteq> {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> emb I J X \<in> generator"
hoelzl@47694
   115
  unfolding generator_def by auto
hoelzl@42147
   116
immler@50039
   117
lemma (in projective_family) algebra_generator:
hoelzl@47694
   118
  assumes "I \<noteq> {}" shows "algebra (\<Pi>\<^isub>E i\<in>I. space (M i)) generator" (is "algebra ?\<Omega> ?G")
hoelzl@47762
   119
  unfolding algebra_def algebra_axioms_def ring_of_sets_iff
hoelzl@47762
   120
proof (intro conjI ballI)
hoelzl@47694
   121
  let ?G = generator
hoelzl@47694
   122
  show "?G \<subseteq> Pow ?\<Omega>"
hoelzl@47694
   123
    by (auto simp: generator_def prod_emb_def)
hoelzl@47694
   124
  from `I \<noteq> {}` obtain i where "i \<in> I" by auto
hoelzl@47694
   125
  then show "{} \<in> ?G"
hoelzl@47694
   126
    by (auto intro!: exI[of _ "{i}"] image_eqI[where x="\<lambda>i. {}"]
hoelzl@47694
   127
             simp: sigma_sets.Empty generator_def prod_emb_def)
hoelzl@47694
   128
  from `i \<in> I` show "?\<Omega> \<in> ?G"
hoelzl@47694
   129
    by (auto intro!: exI[of _ "{i}"] image_eqI[where x="Pi\<^isub>E {i} (\<lambda>i. space (M i))"]
hoelzl@47694
   130
             simp: generator_def prod_emb_def)
hoelzl@47694
   131
  fix A assume "A \<in> ?G"
hoelzl@47694
   132
  then obtain JA XA where XA: "JA \<noteq> {}" "finite JA" "JA \<subseteq> I" "XA \<in> sets (Pi\<^isub>M JA M)" and A: "A = emb I JA XA"
hoelzl@47694
   133
    by (auto simp: generator_def)
hoelzl@47694
   134
  fix B assume "B \<in> ?G"
hoelzl@47694
   135
  then obtain JB XB where XB: "JB \<noteq> {}" "finite JB" "JB \<subseteq> I" "XB \<in> sets (Pi\<^isub>M JB M)" and B: "B = emb I JB XB"
hoelzl@47694
   136
    by (auto simp: generator_def)
hoelzl@47694
   137
  let ?RA = "emb (JA \<union> JB) JA XA"
hoelzl@47694
   138
  let ?RB = "emb (JA \<union> JB) JB XB"
hoelzl@47694
   139
  have *: "A - B = emb I (JA \<union> JB) (?RA - ?RB)" "A \<union> B = emb I (JA \<union> JB) (?RA \<union> ?RB)"
hoelzl@47694
   140
    using XA A XB B by auto
hoelzl@47694
   141
  show "A - B \<in> ?G" "A \<union> B \<in> ?G"
hoelzl@47694
   142
    unfolding * using XA XB by (safe intro!: generatorI') auto
hoelzl@42147
   143
qed
hoelzl@42147
   144
immler@50039
   145
lemma (in projective_family) sets_PiM_generator:
hoelzl@49804
   146
  "sets (PiM I M) = sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) generator"
hoelzl@49804
   147
proof cases
hoelzl@49804
   148
  assume "I = {}" then show ?thesis
hoelzl@49804
   149
    unfolding generator_def
hoelzl@49804
   150
    by (auto simp: sets_PiM_empty sigma_sets_empty_eq cong: conj_cong)
hoelzl@49804
   151
next
hoelzl@49804
   152
  assume "I \<noteq> {}"
hoelzl@49804
   153
  show ?thesis
hoelzl@49804
   154
  proof
hoelzl@49804
   155
    show "sets (Pi\<^isub>M I M) \<subseteq> sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) generator"
hoelzl@49804
   156
      unfolding sets_PiM
hoelzl@49804
   157
    proof (safe intro!: sigma_sets_subseteq)
hoelzl@49804
   158
      fix A assume "A \<in> prod_algebra I M" with `I \<noteq> {}` show "A \<in> generator"
hoelzl@50003
   159
        by (auto intro!: generatorI' sets_PiM_I_finite elim!: prod_algebraE)
hoelzl@49804
   160
    qed
hoelzl@49804
   161
  qed (auto simp: generator_def space_PiM[symmetric] intro!: sigma_sets_subset)
hoelzl@49804
   162
qed
hoelzl@49804
   163
immler@50039
   164
lemma (in projective_family) generatorI:
hoelzl@47694
   165
  "J \<noteq> {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> A = emb I J X \<Longrightarrow> A \<in> generator"
hoelzl@42147
   166
  unfolding generator_def by auto
hoelzl@42147
   167
immler@50039
   168
definition (in projective_family)
hoelzl@42147
   169
  "\<mu>G A =
immler@50039
   170
    (THE x. \<forall>J. J \<noteq> {} \<longrightarrow> finite J \<longrightarrow> J \<subseteq> I \<longrightarrow> (\<forall>X\<in>sets (Pi\<^isub>M J M). A = emb I J X \<longrightarrow> x = emeasure (PiP J M P) X))"
hoelzl@42147
   171
immler@50039
   172
lemma (in projective_family) \<mu>G_spec:
hoelzl@42147
   173
  assumes J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
immler@50039
   174
  shows "\<mu>G A = emeasure (PiP J M P) X"
hoelzl@42147
   175
  unfolding \<mu>G_def
hoelzl@42147
   176
proof (intro the_equality allI impI ballI)
hoelzl@42147
   177
  fix K Y assume K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "A = emb I K Y" "Y \<in> sets (Pi\<^isub>M K M)"
immler@50039
   178
  have "emeasure (PiP K M P) Y = emeasure (PiP (K \<union> J) M P) (emb (K \<union> J) K Y)"
hoelzl@42147
   179
    using K J by simp
hoelzl@42147
   180
  also have "emb (K \<union> J) K Y = emb (K \<union> J) J X"
hoelzl@47694
   181
    using K J by (simp add: prod_emb_injective[of "K \<union> J" I])
immler@50039
   182
  also have "emeasure (PiP (K \<union> J) M P) (emb (K \<union> J) J X) = emeasure (PiP J M P) X"
hoelzl@42147
   183
    using K J by simp
immler@50039
   184
  finally show "emeasure (PiP J M P) X = emeasure (PiP K M P) Y" ..
hoelzl@42147
   185
qed (insert J, force)
hoelzl@42147
   186
immler@50039
   187
lemma (in projective_family) \<mu>G_eq:
immler@50039
   188
  "J \<noteq> {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> X \<in> sets (Pi\<^isub>M J M) \<Longrightarrow> \<mu>G (emb I J X) = emeasure (PiP J M P) X"
hoelzl@42147
   189
  by (intro \<mu>G_spec) auto
hoelzl@42147
   190
immler@50039
   191
lemma (in projective_family) generator_Ex:
hoelzl@47694
   192
  assumes *: "A \<in> generator"
immler@50039
   193
  shows "\<exists>J X. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I \<and> X \<in> sets (Pi\<^isub>M J M) \<and> A = emb I J X \<and> \<mu>G A = emeasure (PiP J M P) X"
hoelzl@42147
   194
proof -
hoelzl@42147
   195
  from * obtain J X where J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
hoelzl@42147
   196
    unfolding generator_def by auto
hoelzl@42147
   197
  with \<mu>G_spec[OF this] show ?thesis by auto
hoelzl@42147
   198
qed
hoelzl@42147
   199
immler@50039
   200
lemma (in projective_family) generatorE:
hoelzl@47694
   201
  assumes A: "A \<in> generator"
immler@50039
   202
  obtains J X where "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)" "emb I J X = A" "\<mu>G A = emeasure (PiP J M P) X"
hoelzl@42147
   203
proof -
hoelzl@42147
   204
  from generator_Ex[OF A] obtain X J where "J \<noteq> {}" "finite J" "J \<subseteq> I" "X \<in> sets (Pi\<^isub>M J M)" "emb I J X = A"
immler@50039
   205
    "\<mu>G A = emeasure (PiP J M P) X" by auto
hoelzl@42147
   206
  then show thesis by (intro that) auto
hoelzl@42147
   207
qed
hoelzl@42147
   208
immler@50039
   209
lemma (in projective_family) merge_sets:
hoelzl@50003
   210
  "J \<inter> K = {} \<Longrightarrow> A \<in> sets (Pi\<^isub>M (J \<union> K) M) \<Longrightarrow> x \<in> space (Pi\<^isub>M J M) \<Longrightarrow> (\<lambda>y. merge J K (x,y)) -` A \<inter> space (Pi\<^isub>M K M) \<in> sets (Pi\<^isub>M K M)"
hoelzl@50003
   211
  by simp
hoelzl@42147
   212
immler@50039
   213
lemma (in projective_family) merge_emb:
hoelzl@42147
   214
  assumes "K \<subseteq> I" "J \<subseteq> I" and y: "y \<in> space (Pi\<^isub>M J M)"
hoelzl@49780
   215
  shows "((\<lambda>x. merge J (I - J) (y, x)) -` emb I K X \<inter> space (Pi\<^isub>M I M)) =
hoelzl@49780
   216
    emb I (K - J) ((\<lambda>x. merge J (K - J) (y, x)) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M))"
hoelzl@42147
   217
proof -
hoelzl@49780
   218
  have [simp]: "\<And>x J K L. merge J K (y, restrict x L) = merge J (K \<inter> L) (y, x)"
hoelzl@42147
   219
    by (auto simp: restrict_def merge_def)
hoelzl@49780
   220
  have [simp]: "\<And>x J K L. restrict (merge J K (y, x)) L = merge (J \<inter> L) (K \<inter> L) (y, x)"
hoelzl@42147
   221
    by (auto simp: restrict_def merge_def)
hoelzl@42147
   222
  have [simp]: "(I - J) \<inter> K = K - J" using `K \<subseteq> I` `J \<subseteq> I` by auto
hoelzl@42147
   223
  have [simp]: "(K - J) \<inter> (K \<union> J) = K - J" by auto
hoelzl@42147
   224
  have [simp]: "(K - J) \<inter> K = K - J" by auto
hoelzl@42147
   225
  from y `K \<subseteq> I` `J \<subseteq> I` show ?thesis
hoelzl@47694
   226
    by (simp split: split_merge add: prod_emb_def Pi_iff extensional_merge_sub set_eq_iff space_PiM)
hoelzl@47694
   227
       auto
hoelzl@42147
   228
qed
hoelzl@42147
   229
immler@50039
   230
lemma (in projective_family) positive_\<mu>G:
hoelzl@45777
   231
  assumes "I \<noteq> {}"
hoelzl@45777
   232
  shows "positive generator \<mu>G"
hoelzl@45777
   233
proof -
hoelzl@47694
   234
  interpret G!: algebra "\<Pi>\<^isub>E i\<in>I. space (M i)" generator by (rule algebra_generator) fact
hoelzl@45777
   235
  show ?thesis
hoelzl@45777
   236
  proof (intro positive_def[THEN iffD2] conjI ballI)
hoelzl@45777
   237
    from generatorE[OF G.empty_sets] guess J X . note this[simp]
hoelzl@45777
   238
    interpret J: finite_product_sigma_finite M J by default fact
hoelzl@45777
   239
    have "X = {}"
hoelzl@47694
   240
      by (rule prod_emb_injective[of J I]) simp_all
hoelzl@45777
   241
    then show "\<mu>G {} = 0" by simp
hoelzl@45777
   242
  next
hoelzl@47694
   243
    fix A assume "A \<in> generator"
hoelzl@45777
   244
    from generatorE[OF this] guess J X . note this[simp]
hoelzl@45777
   245
    interpret J: finite_product_sigma_finite M J by default fact
hoelzl@47694
   246
    show "0 \<le> \<mu>G A" by (simp add: emeasure_nonneg)
hoelzl@45777
   247
  qed
hoelzl@42147
   248
qed
hoelzl@42147
   249
immler@50039
   250
lemma (in projective_family) additive_\<mu>G:
hoelzl@45777
   251
  assumes "I \<noteq> {}"
hoelzl@45777
   252
  shows "additive generator \<mu>G"
hoelzl@45777
   253
proof -
hoelzl@47694
   254
  interpret G!: algebra "\<Pi>\<^isub>E i\<in>I. space (M i)" generator by (rule algebra_generator) fact
hoelzl@45777
   255
  show ?thesis
hoelzl@45777
   256
  proof (intro additive_def[THEN iffD2] ballI impI)
hoelzl@47694
   257
    fix A assume "A \<in> generator" with generatorE guess J X . note J = this
hoelzl@47694
   258
    fix B assume "B \<in> generator" with generatorE guess K Y . note K = this
hoelzl@45777
   259
    assume "A \<inter> B = {}"
hoelzl@45777
   260
    have JK: "J \<union> K \<noteq> {}" "J \<union> K \<subseteq> I" "finite (J \<union> K)"
hoelzl@45777
   261
      using J K by auto
hoelzl@45777
   262
    interpret JK: finite_product_sigma_finite M "J \<union> K" by default fact
hoelzl@45777
   263
    have JK_disj: "emb (J \<union> K) J X \<inter> emb (J \<union> K) K Y = {}"
hoelzl@47694
   264
      apply (rule prod_emb_injective[of "J \<union> K" I])
hoelzl@45777
   265
      apply (insert `A \<inter> B = {}` JK J K)
hoelzl@47694
   266
      apply (simp_all add: Int prod_emb_Int)
hoelzl@45777
   267
      done
hoelzl@45777
   268
    have AB: "A = emb I (J \<union> K) (emb (J \<union> K) J X)" "B = emb I (J \<union> K) (emb (J \<union> K) K Y)"
hoelzl@45777
   269
      using J K by simp_all
hoelzl@45777
   270
    then have "\<mu>G (A \<union> B) = \<mu>G (emb I (J \<union> K) (emb (J \<union> K) J X \<union> emb (J \<union> K) K Y))"
hoelzl@47694
   271
      by simp
immler@50039
   272
    also have "\<dots> = emeasure (PiP (J \<union> K) M P) (emb (J \<union> K) J X \<union> emb (J \<union> K) K Y)"
hoelzl@47694
   273
      using JK J(1, 4) K(1, 4) by (simp add: \<mu>G_eq Un del: prod_emb_Un)
hoelzl@45777
   274
    also have "\<dots> = \<mu>G A + \<mu>G B"
hoelzl@47694
   275
      using J K JK_disj by (simp add: plus_emeasure[symmetric])
hoelzl@45777
   276
    finally show "\<mu>G (A \<union> B) = \<mu>G A + \<mu>G B" .
hoelzl@45777
   277
  qed
hoelzl@42147
   278
qed
hoelzl@42147
   279
immler@50039
   280
lemma (in product_prob_space) PiP_PiM_finite[simp]:
immler@50039
   281
  assumes "J \<noteq> {}" "finite J" "J \<subseteq> I" shows "PiP J M (\<lambda>J. PiM J M) = PiM J M"
immler@50039
   282
  using assms by (simp add: PiP_finite)
immler@50039
   283
hoelzl@47694
   284
lemma (in product_prob_space) emeasure_PiM_emb_not_empty:
hoelzl@47694
   285
  assumes X: "J \<noteq> {}" "J \<subseteq> I" "finite J" "\<forall>i\<in>J. X i \<in> sets (M i)"
hoelzl@47694
   286
  shows "emeasure (Pi\<^isub>M I M) (emb I J (Pi\<^isub>E J X)) = emeasure (Pi\<^isub>M J M) (Pi\<^isub>E J X)"
hoelzl@42147
   287
proof cases
hoelzl@47694
   288
  assume "finite I" with X show ?thesis by simp
hoelzl@42147
   289
next
hoelzl@47694
   290
  let ?\<Omega> = "\<Pi>\<^isub>E i\<in>I. space (M i)"
hoelzl@42147
   291
  let ?G = generator
hoelzl@42147
   292
  assume "\<not> finite I"
hoelzl@45777
   293
  then have I_not_empty: "I \<noteq> {}" by auto
hoelzl@47694
   294
  interpret G!: algebra ?\<Omega> generator by (rule algebra_generator) fact
hoelzl@42147
   295
  note \<mu>G_mono =
hoelzl@45777
   296
    G.additive_increasing[OF positive_\<mu>G[OF I_not_empty] additive_\<mu>G[OF I_not_empty], THEN increasingD]
hoelzl@42147
   297
hoelzl@47694
   298
  { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> ?G"
hoelzl@42147
   299
hoelzl@42147
   300
    from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
hoelzl@42147
   301
      by (metis rev_finite_subset subsetI)
hoelzl@42147
   302
    moreover from Z guess K' X' by (rule generatorE)
hoelzl@42147
   303
    moreover def K \<equiv> "insert k K'"
hoelzl@42147
   304
    moreover def X \<equiv> "emb K K' X'"
hoelzl@42147
   305
    ultimately have K: "K \<noteq> {}" "finite K" "K \<subseteq> I" "X \<in> sets (Pi\<^isub>M K M)" "Z = emb I K X"
hoelzl@47694
   306
      "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = emeasure (Pi\<^isub>M K M) X"
hoelzl@42147
   307
      by (auto simp: subset_insertI)
hoelzl@49780
   308
    let ?M = "\<lambda>y. (\<lambda>x. merge J (K - J) (y, x)) -` emb (J \<union> K) K X \<inter> space (Pi\<^isub>M (K - J) M)"
hoelzl@42147
   309
    { fix y assume y: "y \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
   310
      note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
hoelzl@42147
   311
      moreover
hoelzl@42147
   312
      have **: "?M y \<in> sets (Pi\<^isub>M (K - J) M)"
hoelzl@42147
   313
        using J K y by (intro merge_sets) auto
hoelzl@42147
   314
      ultimately
hoelzl@49780
   315
      have ***: "((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)) \<in> ?G"
hoelzl@42147
   316
        using J K by (intro generatorI) auto
hoelzl@49780
   317
      have "\<mu>G ((\<lambda>x. merge J (I - J) (y, x)) -` emb I K X \<inter> space (Pi\<^isub>M I M)) = emeasure (Pi\<^isub>M (K - J) M) (?M y)"
hoelzl@42147
   318
        unfolding * using K J by (subst \<mu>G_eq[OF _ _ _ **]) auto
hoelzl@42147
   319
      note * ** *** this }
hoelzl@42147
   320
    note merge_in_G = this
hoelzl@42147
   321
hoelzl@42147
   322
    have "finite (K - J)" using K by auto
hoelzl@42147
   323
hoelzl@42147
   324
    interpret J: finite_product_prob_space M J by default fact+
hoelzl@42147
   325
    interpret KmJ: finite_product_prob_space M "K - J" by default fact+
hoelzl@42147
   326
hoelzl@47694
   327
    have "\<mu>G Z = emeasure (Pi\<^isub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
hoelzl@42147
   328
      using K J by simp
hoelzl@47694
   329
    also have "\<dots> = (\<integral>\<^isup>+ x. emeasure (Pi\<^isub>M (K - J) M) (?M x) \<partial>Pi\<^isub>M J M)"
hoelzl@47694
   330
      using K J by (subst emeasure_fold_integral) auto
hoelzl@49780
   331
    also have "\<dots> = (\<integral>\<^isup>+ y. \<mu>G ((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)) \<partial>Pi\<^isub>M J M)"
hoelzl@42147
   332
      (is "_ = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)")
hoelzl@47694
   333
    proof (intro positive_integral_cong)
hoelzl@42147
   334
      fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
   335
      with K merge_in_G(2)[OF this]
hoelzl@47694
   336
      show "emeasure (Pi\<^isub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
hoelzl@42147
   337
        unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst \<mu>G_eq) auto
hoelzl@42147
   338
    qed
hoelzl@42147
   339
    finally have fold: "\<mu>G Z = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)" .
hoelzl@42147
   340
hoelzl@42147
   341
    { fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
   342
      then have "\<mu>G (?MZ x) \<le> 1"
hoelzl@42147
   343
        unfolding merge_in_G(4)[OF x] `Z = emb I K X`
hoelzl@42147
   344
        by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
hoelzl@42147
   345
    note le_1 = this
hoelzl@42147
   346
hoelzl@49780
   347
    let ?q = "\<lambda>y. \<mu>G ((\<lambda>x. merge J (I - J) (y,x)) -` Z \<inter> space (Pi\<^isub>M I M))"
hoelzl@42147
   348
    have "?q \<in> borel_measurable (Pi\<^isub>M J M)"
hoelzl@42147
   349
      unfolding `Z = emb I K X` using J K merge_in_G(3)
hoelzl@47694
   350
      by (simp add: merge_in_G  \<mu>G_eq emeasure_fold_measurable cong: measurable_cong)
hoelzl@42147
   351
    note this fold le_1 merge_in_G(3) }
hoelzl@42147
   352
  note fold = this
hoelzl@42147
   353
hoelzl@47694
   354
  have "\<exists>\<mu>. (\<forall>s\<in>?G. \<mu> s = \<mu>G s) \<and> measure_space ?\<Omega> (sigma_sets ?\<Omega> ?G) \<mu>"
hoelzl@42147
   355
  proof (rule G.caratheodory_empty_continuous[OF positive_\<mu>G additive_\<mu>G])
hoelzl@47694
   356
    fix A assume "A \<in> ?G"
hoelzl@42147
   357
    with generatorE guess J X . note JX = this
hoelzl@50000
   358
    interpret JK: finite_product_prob_space M J by default fact+ 
wenzelm@46898
   359
    from JX show "\<mu>G A \<noteq> \<infinity>" by simp
hoelzl@42147
   360
  next
hoelzl@47694
   361
    fix A assume A: "range A \<subseteq> ?G" "decseq A" "(\<Inter>i. A i) = {}"
hoelzl@42147
   362
    then have "decseq (\<lambda>i. \<mu>G (A i))"
hoelzl@42147
   363
      by (auto intro!: \<mu>G_mono simp: decseq_def)
hoelzl@42147
   364
    moreover
hoelzl@42147
   365
    have "(INF i. \<mu>G (A i)) = 0"
hoelzl@42147
   366
    proof (rule ccontr)
hoelzl@42147
   367
      assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
hoelzl@42147
   368
      moreover have "0 \<le> ?a"
hoelzl@45777
   369
        using A positive_\<mu>G[OF I_not_empty] by (auto intro!: INF_greatest simp: positive_def)
hoelzl@42147
   370
      ultimately have "0 < ?a" by auto
hoelzl@42147
   371
immler@50039
   372
      have "\<forall>n. \<exists>J X. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I \<and> X \<in> sets (Pi\<^isub>M J M) \<and> A n = emb I J X \<and> \<mu>G (A n) = emeasure (PiP J M (\<lambda>J. (Pi\<^isub>M J M))) X"
hoelzl@42147
   373
        using A by (intro allI generator_Ex) auto
hoelzl@42147
   374
      then obtain J' X' where J': "\<And>n. J' n \<noteq> {}" "\<And>n. finite (J' n)" "\<And>n. J' n \<subseteq> I" "\<And>n. X' n \<in> sets (Pi\<^isub>M (J' n) M)"
hoelzl@42147
   375
        and A': "\<And>n. A n = emb I (J' n) (X' n)"
hoelzl@42147
   376
        unfolding choice_iff by blast
hoelzl@42147
   377
      moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
hoelzl@42147
   378
      moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
hoelzl@42147
   379
      ultimately have J: "\<And>n. J n \<noteq> {}" "\<And>n. finite (J n)" "\<And>n. J n \<subseteq> I" "\<And>n. X n \<in> sets (Pi\<^isub>M (J n) M)"
hoelzl@42147
   380
        by auto
hoelzl@47694
   381
      with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> ?G"
hoelzl@47694
   382
        unfolding J_def X_def by (subst prod_emb_trans) (insert A, auto)
hoelzl@42147
   383
hoelzl@42147
   384
      have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
hoelzl@42147
   385
        unfolding J_def by force
hoelzl@42147
   386
hoelzl@42147
   387
      interpret J: finite_product_prob_space M "J i" for i by default fact+
hoelzl@42147
   388
hoelzl@42147
   389
      have a_le_1: "?a \<le> 1"
hoelzl@42147
   390
        using \<mu>G_spec[of "J 0" "A 0" "X 0"] J A_eq
hoelzl@44928
   391
        by (auto intro!: INF_lower2[of 0] J.measure_le_1)
hoelzl@42147
   392
hoelzl@49780
   393
      let ?M = "\<lambda>K Z y. (\<lambda>x. merge K (I - K) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)"
hoelzl@42147
   394
hoelzl@47694
   395
      { fix Z k assume Z: "range Z \<subseteq> ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
hoelzl@47694
   396
        then have Z_sets: "\<And>n. Z n \<in> ?G" by auto
hoelzl@42147
   397
        fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
hoelzl@42147
   398
        interpret J': finite_product_prob_space M J' by default fact+
hoelzl@42147
   399
wenzelm@46731
   400
        let ?q = "\<lambda>n y. \<mu>G (?M J' (Z n) y)"
wenzelm@46731
   401
        let ?Q = "\<lambda>n. ?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^isub>M J' M)"
hoelzl@42147
   402
        { fix n
hoelzl@42147
   403
          have "?q n \<in> borel_measurable (Pi\<^isub>M J' M)"
hoelzl@42147
   404
            using Z J' by (intro fold(1)) auto
hoelzl@42147
   405
          then have "?Q n \<in> sets (Pi\<^isub>M J' M)"
hoelzl@42147
   406
            by (rule measurable_sets) auto }
hoelzl@42147
   407
        note Q_sets = this
hoelzl@42147
   408
hoelzl@47694
   409
        have "?a / 2^(k+1) \<le> (INF n. emeasure (Pi\<^isub>M J' M) (?Q n))"
hoelzl@44928
   410
        proof (intro INF_greatest)
hoelzl@42147
   411
          fix n
hoelzl@42147
   412
          have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
hoelzl@42147
   413
          also have "\<dots> \<le> (\<integral>\<^isup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^isub>M J' M)"
hoelzl@47694
   414
            unfolding fold(2)[OF J' `Z n \<in> ?G`]
hoelzl@47694
   415
          proof (intro positive_integral_mono)
hoelzl@42147
   416
            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
hoelzl@42147
   417
            then have "?q n x \<le> 1 + 0"
hoelzl@42147
   418
              using J' Z fold(3) Z_sets by auto
hoelzl@42147
   419
            also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
hoelzl@42147
   420
              using `0 < ?a` by (intro add_mono) auto
hoelzl@42147
   421
            finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
hoelzl@42147
   422
            with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
hoelzl@42147
   423
              by (auto split: split_indicator simp del: power_Suc)
hoelzl@42147
   424
          qed
hoelzl@47694
   425
          also have "\<dots> = emeasure (Pi\<^isub>M J' M) (?Q n) + ?a / 2^(k+1)"
hoelzl@47694
   426
            using `0 \<le> ?a` Q_sets J'.emeasure_space_1
hoelzl@47694
   427
            by (subst positive_integral_add) auto
hoelzl@47694
   428
          finally show "?a / 2^(k+1) \<le> emeasure (Pi\<^isub>M J' M) (?Q n)" using `?a \<le> 1`
hoelzl@47694
   429
            by (cases rule: ereal2_cases[of ?a "emeasure (Pi\<^isub>M J' M) (?Q n)"])
hoelzl@42147
   430
               (auto simp: field_simps)
hoelzl@42147
   431
        qed
hoelzl@47694
   432
        also have "\<dots> = emeasure (Pi\<^isub>M J' M) (\<Inter>n. ?Q n)"
hoelzl@47694
   433
        proof (intro INF_emeasure_decseq)
hoelzl@42147
   434
          show "range ?Q \<subseteq> sets (Pi\<^isub>M J' M)" using Q_sets by auto
hoelzl@42147
   435
          show "decseq ?Q"
hoelzl@42147
   436
            unfolding decseq_def
hoelzl@42147
   437
          proof (safe intro!: vimageI[OF refl])
hoelzl@42147
   438
            fix m n :: nat assume "m \<le> n"
hoelzl@42147
   439
            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
hoelzl@42147
   440
            assume "?a / 2^(k+1) \<le> ?q n x"
hoelzl@42147
   441
            also have "?q n x \<le> ?q m x"
hoelzl@42147
   442
            proof (rule \<mu>G_mono)
hoelzl@42147
   443
              from fold(4)[OF J', OF Z_sets x]
hoelzl@47694
   444
              show "?M J' (Z n) x \<in> ?G" "?M J' (Z m) x \<in> ?G" by auto
hoelzl@42147
   445
              show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
hoelzl@42147
   446
                using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
hoelzl@42147
   447
            qed
hoelzl@42147
   448
            finally show "?a / 2^(k+1) \<le> ?q m x" .
hoelzl@42147
   449
          qed
hoelzl@47694
   450
        qed simp
hoelzl@42147
   451
        finally have "(\<Inter>n. ?Q n) \<noteq> {}"
hoelzl@42147
   452
          using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
hoelzl@42147
   453
        then have "\<exists>w\<in>space (Pi\<^isub>M J' M). \<forall>n. ?a / 2 ^ (k + 1) \<le> ?q n w" by auto }
hoelzl@42147
   454
      note Ex_w = this
hoelzl@42147
   455
wenzelm@46731
   456
      let ?q = "\<lambda>k n y. \<mu>G (?M (J k) (A n) y)"
hoelzl@42147
   457
hoelzl@44928
   458
      have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_lower)
hoelzl@42147
   459
      from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
hoelzl@42147
   460
wenzelm@46731
   461
      let ?P =
wenzelm@46731
   462
        "\<lambda>k wk w. w \<in> space (Pi\<^isub>M (J (Suc k)) M) \<and> restrict w (J k) = wk \<and>
wenzelm@46731
   463
          (\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n w)"
hoelzl@42147
   464
      def w \<equiv> "nat_rec w0 (\<lambda>k wk. Eps (?P k wk))"
hoelzl@42147
   465
hoelzl@42147
   466
      { fix k have w: "w k \<in> space (Pi\<^isub>M (J k) M) \<and>
hoelzl@42147
   467
          (\<forall>n. ?a / 2 ^ (k + 1) \<le> ?q k n (w k)) \<and> (k \<noteq> 0 \<longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1))"
hoelzl@42147
   468
        proof (induct k)
hoelzl@42147
   469
          case 0 with w0 show ?case
hoelzl@42147
   470
            unfolding w_def nat_rec_0 by auto
hoelzl@42147
   471
        next
hoelzl@42147
   472
          case (Suc k)
hoelzl@42147
   473
          then have wk: "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
hoelzl@42147
   474
          have "\<exists>w'. ?P k (w k) w'"
hoelzl@42147
   475
          proof cases
hoelzl@42147
   476
            assume [simp]: "J k = J (Suc k)"
hoelzl@42147
   477
            show ?thesis
hoelzl@42147
   478
            proof (intro exI[of _ "w k"] conjI allI)
hoelzl@42147
   479
              fix n
hoelzl@42147
   480
              have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
hoelzl@42147
   481
                using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
hoelzl@42147
   482
              also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
hoelzl@42147
   483
              finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
hoelzl@42147
   484
            next
hoelzl@42147
   485
              show "w k \<in> space (Pi\<^isub>M (J (Suc k)) M)"
hoelzl@42147
   486
                using Suc by simp
hoelzl@42147
   487
              then show "restrict (w k) (J k) = w k"
hoelzl@47694
   488
                by (simp add: extensional_restrict space_PiM)
hoelzl@42147
   489
            qed
hoelzl@42147
   490
          next
hoelzl@42147
   491
            assume "J k \<noteq> J (Suc k)"
hoelzl@42147
   492
            with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
hoelzl@47694
   493
            have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> ?G"
hoelzl@42147
   494
              "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
hoelzl@42147
   495
              "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
hoelzl@42147
   496
              using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
hoelzl@42147
   497
              by (auto simp: decseq_def)
hoelzl@42147
   498
            from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
hoelzl@42147
   499
            obtain w' where w': "w' \<in> space (Pi\<^isub>M ?D M)"
hoelzl@42147
   500
              "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
hoelzl@49780
   501
            let ?w = "merge (J k) ?D (w k, w')"
hoelzl@49780
   502
            have [simp]: "\<And>x. merge (J k) (I - J k) (w k, merge ?D (I - ?D) (w', x)) =
hoelzl@49780
   503
              merge (J (Suc k)) (I - (J (Suc k))) (?w, x)"
hoelzl@42147
   504
              using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
hoelzl@42147
   505
              by (auto intro!: ext split: split_merge)
hoelzl@42147
   506
            have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
hoelzl@42147
   507
              using w'(1) J(3)[of "Suc k"]
hoelzl@47694
   508
              by (auto simp: space_PiM split: split_merge intro!: extensional_merge_sub) force+
hoelzl@42147
   509
            show ?thesis
hoelzl@42147
   510
              apply (rule exI[of _ ?w])
hoelzl@42147
   511
              using w' J_mono[of k "Suc k"] wk unfolding *
hoelzl@47694
   512
              apply (auto split: split_merge intro!: extensional_merge_sub ext simp: space_PiM)
hoelzl@42147
   513
              apply (force simp: extensional_def)
hoelzl@42147
   514
              done
hoelzl@42147
   515
          qed
hoelzl@42147
   516
          then have "?P k (w k) (w (Suc k))"
hoelzl@42147
   517
            unfolding w_def nat_rec_Suc unfolding w_def[symmetric]
hoelzl@42147
   518
            by (rule someI_ex)
hoelzl@42147
   519
          then show ?case by auto
hoelzl@42147
   520
        qed
hoelzl@42147
   521
        moreover
hoelzl@42147
   522
        then have "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
hoelzl@42147
   523
        moreover
hoelzl@42147
   524
        from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
hoelzl@42147
   525
        then have "?M (J k) (A k) (w k) \<noteq> {}"
hoelzl@45777
   526
          using positive_\<mu>G[OF I_not_empty, unfolded positive_def] `0 < ?a` `?a \<le> 1`
hoelzl@42147
   527
          by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
hoelzl@42147
   528
        then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
hoelzl@49780
   529
        then have "merge (J k) (I - J k) (w k, x) \<in> A k" by auto
hoelzl@42147
   530
        then have "\<exists>x\<in>A k. restrict x (J k) = w k"
hoelzl@42147
   531
          using `w k \<in> space (Pi\<^isub>M (J k) M)`
hoelzl@47694
   532
          by (intro rev_bexI) (auto intro!: ext simp: extensional_def space_PiM)
hoelzl@42147
   533
        ultimately have "w k \<in> space (Pi\<^isub>M (J k) M)"
hoelzl@42147
   534
          "\<exists>x\<in>A k. restrict x (J k) = w k"
hoelzl@42147
   535
          "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
hoelzl@42147
   536
          by auto }
hoelzl@42147
   537
      note w = this
hoelzl@42147
   538
hoelzl@42147
   539
      { fix k l i assume "k \<le> l" "i \<in> J k"
hoelzl@42147
   540
        { fix l have "w k i = w (k + l) i"
hoelzl@42147
   541
          proof (induct l)
hoelzl@42147
   542
            case (Suc l)
hoelzl@42147
   543
            from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
hoelzl@42147
   544
            with w(3)[of "k + Suc l"]
hoelzl@42147
   545
            have "w (k + l) i = w (k + Suc l) i"
hoelzl@42147
   546
              by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
hoelzl@42147
   547
            with Suc show ?case by simp
hoelzl@42147
   548
          qed simp }
hoelzl@42147
   549
        from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
hoelzl@42147
   550
      note w_mono = this
hoelzl@42147
   551
hoelzl@42147
   552
      def w' \<equiv> "\<lambda>i. if i \<in> (\<Union>k. J k) then w (LEAST k. i \<in> J k) i else if i \<in> I then (SOME x. x \<in> space (M i)) else undefined"
hoelzl@42147
   553
      { fix i k assume k: "i \<in> J k"
hoelzl@42147
   554
        have "w k i = w (LEAST k. i \<in> J k) i"
hoelzl@42147
   555
          by (intro w_mono Least_le k LeastI[of _ k])
hoelzl@42147
   556
        then have "w' i = w k i"
hoelzl@42147
   557
          unfolding w'_def using k by auto }
hoelzl@42147
   558
      note w'_eq = this
hoelzl@42147
   559
      have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
hoelzl@42147
   560
        using J by (auto simp: w'_def)
hoelzl@42147
   561
      have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
hoelzl@42147
   562
        using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
hoelzl@42147
   563
      { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
hoelzl@47694
   564
          using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq space_PiM)+ }
hoelzl@42147
   565
      note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
hoelzl@42147
   566
hoelzl@42147
   567
      have w': "w' \<in> space (Pi\<^isub>M I M)"
hoelzl@47694
   568
        using w(1) by (auto simp add: Pi_iff extensional_def space_PiM)
hoelzl@42147
   569
hoelzl@42147
   570
      { fix n
hoelzl@42147
   571
        have "restrict w' (J n) = w n" using w(1)
hoelzl@47694
   572
          by (auto simp add: fun_eq_iff restrict_def Pi_iff extensional_def space_PiM)
hoelzl@42147
   573
        with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
hoelzl@47694
   574
        then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: prod_emb_def space_PiM) }
hoelzl@42147
   575
      then have "w' \<in> (\<Inter>i. A i)" by auto
hoelzl@42147
   576
      with `(\<Inter>i. A i) = {}` show False by auto
hoelzl@42147
   577
    qed
hoelzl@42147
   578
    ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
hoelzl@43920
   579
      using LIMSEQ_ereal_INFI[of "\<lambda>i. \<mu>G (A i)"] by simp
hoelzl@45777
   580
  qed fact+
hoelzl@45777
   581
  then guess \<mu> .. note \<mu> = this
hoelzl@45777
   582
  show ?thesis
hoelzl@47694
   583
  proof (subst emeasure_extend_measure_Pair[OF PiM_def, of I M \<mu> J X])
hoelzl@47694
   584
    from assms show "(J \<noteq> {} \<or> I = {}) \<and> finite J \<and> J \<subseteq> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))"
hoelzl@47694
   585
      by (simp add: Pi_iff)
hoelzl@47694
   586
  next
hoelzl@47694
   587
    fix J X assume J: "(J \<noteq> {} \<or> I = {}) \<and> finite J \<and> J \<subseteq> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))"
hoelzl@47694
   588
    then show "emb I J (Pi\<^isub>E J X) \<in> Pow (\<Pi>\<^isub>E i\<in>I. space (M i))"
hoelzl@47694
   589
      by (auto simp: Pi_iff prod_emb_def dest: sets_into_space)
hoelzl@47694
   590
    have "emb I J (Pi\<^isub>E J X) \<in> generator"
hoelzl@50003
   591
      using J `I \<noteq> {}` by (intro generatorI') (auto simp: Pi_iff)
hoelzl@47694
   592
    then have "\<mu> (emb I J (Pi\<^isub>E J X)) = \<mu>G (emb I J (Pi\<^isub>E J X))"
hoelzl@47694
   593
      using \<mu> by simp
hoelzl@47694
   594
    also have "\<dots> = (\<Prod> j\<in>J. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
hoelzl@47694
   595
      using J  `I \<noteq> {}` by (subst \<mu>G_spec[OF _ _ _ refl]) (auto simp: emeasure_PiM Pi_iff)
hoelzl@47694
   596
    also have "\<dots> = (\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}.
hoelzl@47694
   597
      if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
hoelzl@47694
   598
      using J `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
hoelzl@47694
   599
    finally show "\<mu> (emb I J (Pi\<^isub>E J X)) = \<dots>" .
hoelzl@47694
   600
  next
hoelzl@47694
   601
    let ?F = "\<lambda>j. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j))"
hoelzl@47694
   602
    have "(\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}. ?F j) = (\<Prod>j\<in>J. ?F j)"
hoelzl@47694
   603
      using X `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
hoelzl@47694
   604
    then show "(\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}. ?F j) =
hoelzl@47694
   605
      emeasure (Pi\<^isub>M J M) (Pi\<^isub>E J X)"
hoelzl@47694
   606
      using X by (auto simp add: emeasure_PiM) 
hoelzl@47694
   607
  next
hoelzl@47694
   608
    show "positive (sets (Pi\<^isub>M I M)) \<mu>" "countably_additive (sets (Pi\<^isub>M I M)) \<mu>"
hoelzl@49804
   609
      using \<mu> unfolding sets_PiM_generator by (auto simp: measure_space_def)
hoelzl@42147
   610
  qed
hoelzl@42147
   611
qed
hoelzl@42147
   612
hoelzl@47694
   613
sublocale product_prob_space \<subseteq> P: prob_space "Pi\<^isub>M I M"
hoelzl@42257
   614
proof
hoelzl@47694
   615
  show "emeasure (Pi\<^isub>M I M) (space (Pi\<^isub>M I M)) = 1"
hoelzl@47694
   616
  proof cases
hoelzl@47694
   617
    assume "I = {}" then show ?thesis by (simp add: space_PiM_empty)
hoelzl@47694
   618
  next
hoelzl@47694
   619
    assume "I \<noteq> {}"
hoelzl@47694
   620
    then obtain i where "i \<in> I" by auto
hoelzl@47694
   621
    moreover then have "emb I {i} (\<Pi>\<^isub>E i\<in>{i}. space (M i)) = (space (Pi\<^isub>M I M))"
hoelzl@47694
   622
      by (auto simp: prod_emb_def space_PiM)
hoelzl@47694
   623
    ultimately show ?thesis
hoelzl@47694
   624
      using emeasure_PiM_emb_not_empty[of "{i}" "\<lambda>i. space (M i)"]
hoelzl@47694
   625
      by (simp add: emeasure_PiM emeasure_space_1)
hoelzl@47694
   626
  qed
hoelzl@42257
   627
qed
hoelzl@42257
   628
hoelzl@47694
   629
lemma (in product_prob_space) emeasure_PiM_emb:
hoelzl@47694
   630
  assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@47694
   631
  shows "emeasure (Pi\<^isub>M I M) (emb I J (Pi\<^isub>E J X)) = (\<Prod> i\<in>J. emeasure (M i) (X i))"
hoelzl@47694
   632
proof cases
hoelzl@47694
   633
  assume "J = {}"
hoelzl@47694
   634
  moreover have "emb I {} {\<lambda>x. undefined} = space (Pi\<^isub>M I M)"
hoelzl@47694
   635
    by (auto simp: space_PiM prod_emb_def)
hoelzl@47694
   636
  ultimately show ?thesis
hoelzl@47694
   637
    by (simp add: space_PiM_empty P.emeasure_space_1)
hoelzl@47694
   638
next
hoelzl@47694
   639
  assume "J \<noteq> {}" with X show ?thesis
hoelzl@47694
   640
    by (subst emeasure_PiM_emb_not_empty) (auto simp: emeasure_PiM)
hoelzl@42257
   641
qed
hoelzl@42257
   642
hoelzl@50000
   643
lemma (in product_prob_space) emeasure_PiM_Collect:
hoelzl@50000
   644
  assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@50000
   645
  shows "emeasure (Pi\<^isub>M I M) {x\<in>space (Pi\<^isub>M I M). \<forall>i\<in>J. x i \<in> X i} = (\<Prod> i\<in>J. emeasure (M i) (X i))"
hoelzl@50000
   646
proof -
hoelzl@50000
   647
  have "{x\<in>space (Pi\<^isub>M I M). \<forall>i\<in>J. x i \<in> X i} = emb I J (Pi\<^isub>E J X)"
hoelzl@50000
   648
    unfolding prod_emb_def using assms by (auto simp: space_PiM Pi_iff)
hoelzl@50000
   649
  with emeasure_PiM_emb[OF assms] show ?thesis by simp
hoelzl@50000
   650
qed
hoelzl@50000
   651
hoelzl@50000
   652
lemma (in product_prob_space) emeasure_PiM_Collect_single:
hoelzl@50000
   653
  assumes X: "i \<in> I" "A \<in> sets (M i)"
hoelzl@50000
   654
  shows "emeasure (Pi\<^isub>M I M) {x\<in>space (Pi\<^isub>M I M). x i \<in> A} = emeasure (M i) A"
hoelzl@50000
   655
  using emeasure_PiM_Collect[of "{i}" "\<lambda>i. A"] assms
hoelzl@50000
   656
  by simp
hoelzl@50000
   657
hoelzl@47694
   658
lemma (in product_prob_space) measure_PiM_emb:
hoelzl@47694
   659
  assumes "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@47694
   660
  shows "measure (PiM I M) (emb I J (Pi\<^isub>E J X)) = (\<Prod> i\<in>J. measure (M i) (X i))"
hoelzl@47694
   661
  using emeasure_PiM_emb[OF assms]
hoelzl@47694
   662
  unfolding emeasure_eq_measure M.emeasure_eq_measure by (simp add: setprod_ereal)
hoelzl@42865
   663
hoelzl@50000
   664
lemma sets_Collect_single':
hoelzl@50000
   665
  "i \<in> I \<Longrightarrow> {x\<in>space (M i). P x} \<in> sets (M i) \<Longrightarrow> {x\<in>space (PiM I M). P (x i)} \<in> sets (PiM I M)"
hoelzl@50000
   666
  using sets_Collect_single[of i I "{x\<in>space (M i). P x}" M]
hoelzl@50000
   667
  by (simp add: space_PiM Pi_iff cong: conj_cong)
hoelzl@50000
   668
hoelzl@47694
   669
lemma (in finite_product_prob_space) finite_measure_PiM_emb:
hoelzl@47694
   670
  "(\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> measure (PiM I M) (Pi\<^isub>E I A) = (\<Prod>i\<in>I. measure (M i) (A i))"
hoelzl@47694
   671
  using measure_PiM_emb[of I A] finite_index prod_emb_PiE_same_index[OF sets_into_space, of I A M]
hoelzl@47694
   672
  by auto
hoelzl@42865
   673
hoelzl@50000
   674
lemma (in product_prob_space) PiM_component:
hoelzl@50000
   675
  assumes "i \<in> I"
hoelzl@50000
   676
  shows "distr (PiM I M) (M i) (\<lambda>\<omega>. \<omega> i) = M i"
hoelzl@50000
   677
proof (rule measure_eqI[symmetric])
hoelzl@50000
   678
  fix A assume "A \<in> sets (M i)"
hoelzl@50000
   679
  moreover have "((\<lambda>\<omega>. \<omega> i) -` A \<inter> space (PiM I M)) = {x\<in>space (PiM I M). x i \<in> A}"
hoelzl@50000
   680
    by auto
hoelzl@50000
   681
  ultimately show "emeasure (M i) A = emeasure (distr (PiM I M) (M i) (\<lambda>\<omega>. \<omega> i)) A"
hoelzl@50000
   682
    by (auto simp: `i\<in>I` emeasure_distr measurable_component_singleton emeasure_PiM_Collect_single)
hoelzl@50000
   683
qed simp
hoelzl@50000
   684
hoelzl@50000
   685
lemma (in product_prob_space) PiM_eq:
hoelzl@50000
   686
  assumes "I \<noteq> {}"
hoelzl@50000
   687
  assumes "sets M' = sets (PiM I M)"
hoelzl@50000
   688
  assumes eq: "\<And>J F. finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>j. j \<in> J \<Longrightarrow> F j \<in> sets (M j)) \<Longrightarrow>
hoelzl@50000
   689
    emeasure M' (prod_emb I M J (\<Pi>\<^isub>E j\<in>J. F j)) = (\<Prod>j\<in>J. emeasure (M j) (F j))"
hoelzl@50000
   690
  shows "M' = (PiM I M)"
hoelzl@50000
   691
proof (rule measure_eqI_generator_eq[symmetric, OF Int_stable_prod_algebra prod_algebra_sets_into_space])
hoelzl@50000
   692
  show "sets (PiM I M) = sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) (prod_algebra I M)"
hoelzl@50000
   693
    by (rule sets_PiM)
hoelzl@50000
   694
  then show "sets M' = sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) (prod_algebra I M)"
hoelzl@50000
   695
    unfolding `sets M' = sets (PiM I M)` by simp
hoelzl@50000
   696
hoelzl@50000
   697
  def i \<equiv> "SOME i. i \<in> I"
hoelzl@50000
   698
  with `I \<noteq> {}` have i: "i \<in> I"
hoelzl@50000
   699
    by (auto intro: someI_ex)
hoelzl@50000
   700
hoelzl@50000
   701
  def A \<equiv> "\<lambda>n::nat. prod_emb I M {i} (\<Pi>\<^isub>E j\<in>{i}. space (M i))"
hoelzl@50000
   702
  then show "range A \<subseteq> prod_algebra I M"
hoelzl@50000
   703
    by (auto intro!: prod_algebraI i)
hoelzl@50000
   704
hoelzl@50000
   705
  have A_eq: "\<And>i. A i = space (PiM I M)"
hoelzl@50000
   706
    by (auto simp: prod_emb_def space_PiM Pi_iff A_def i)
hoelzl@50000
   707
  show "(\<Union>i. A i) = (\<Pi>\<^isub>E i\<in>I. space (M i))"
hoelzl@50000
   708
    unfolding A_eq by (auto simp: space_PiM)
hoelzl@50000
   709
  show "\<And>i. emeasure (PiM I M) (A i) \<noteq> \<infinity>"
hoelzl@50000
   710
    unfolding A_eq P.emeasure_space_1 by simp
hoelzl@50000
   711
next
hoelzl@50000
   712
  fix X assume X: "X \<in> prod_algebra I M"
hoelzl@50000
   713
  then obtain J E where X: "X = prod_emb I M J (PIE j:J. E j)"
hoelzl@50000
   714
    and J: "finite J" "J \<subseteq> I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets (M j)"
hoelzl@50000
   715
    by (force elim!: prod_algebraE)
hoelzl@50000
   716
  from eq[OF J] have "emeasure M' X = (\<Prod>j\<in>J. emeasure (M j) (E j))"
hoelzl@50000
   717
    by (simp add: X)
hoelzl@50000
   718
  also have "\<dots> = emeasure (PiM I M) X"
hoelzl@50000
   719
    unfolding X using J by (intro emeasure_PiM_emb[symmetric]) auto
hoelzl@50000
   720
  finally show "emeasure (PiM I M) X = emeasure M' X" ..
hoelzl@50000
   721
qed
hoelzl@50000
   722
hoelzl@42257
   723
subsection {* Sequence space *}
hoelzl@42257
   724
hoelzl@50000
   725
lemma measurable_nat_case: "(\<lambda>(x, \<omega>). nat_case x \<omega>) \<in> measurable (M \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)) (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   726
proof (rule measurable_PiM_single)
hoelzl@50000
   727
  show "(\<lambda>(x, \<omega>). nat_case x \<omega>) \<in> space (M \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)) \<rightarrow> (UNIV \<rightarrow>\<^isub>E space M)"
hoelzl@50000
   728
    by (auto simp: space_pair_measure space_PiM Pi_iff split: nat.split)
hoelzl@50000
   729
  fix i :: nat and A assume A: "A \<in> sets M"
hoelzl@50000
   730
  then have *: "{\<omega> \<in> space (M \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)). prod_case nat_case \<omega> i \<in> A} =
hoelzl@50000
   731
    (case i of 0 \<Rightarrow> A \<times> space (\<Pi>\<^isub>M i\<in>UNIV. M) | Suc n \<Rightarrow> space M \<times> {\<omega>\<in>space (\<Pi>\<^isub>M i\<in>UNIV. M). \<omega> n \<in> A})"
hoelzl@50000
   732
    by (auto simp: space_PiM space_pair_measure split: nat.split dest: sets_into_space)
hoelzl@50000
   733
  show "{\<omega> \<in> space (M \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)). prod_case nat_case \<omega> i \<in> A} \<in> sets (M \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M))"
hoelzl@50000
   734
    unfolding * by (auto simp: A split: nat.split intro!: sets_Collect_single)
hoelzl@50000
   735
qed
hoelzl@50000
   736
hoelzl@50000
   737
lemma measurable_nat_case':
hoelzl@50000
   738
  assumes f: "f \<in> measurable N M" and g: "g \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   739
  shows "(\<lambda>x. nat_case (f x) (g x)) \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   740
  using measurable_compose[OF measurable_Pair[OF f g] measurable_nat_case] by simp
hoelzl@50000
   741
hoelzl@50000
   742
definition comb_seq :: "nat \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a)" where
hoelzl@50000
   743
  "comb_seq i \<omega> \<omega>' j = (if j < i then \<omega> j else \<omega>' (j - i))"
hoelzl@50000
   744
hoelzl@50000
   745
lemma split_comb_seq: "P (comb_seq i \<omega> \<omega>' j) \<longleftrightarrow> (j < i \<longrightarrow> P (\<omega> j)) \<and> (\<forall>k. j = i + k \<longrightarrow> P (\<omega>' k))"
hoelzl@50000
   746
  by (auto simp: comb_seq_def not_less)
hoelzl@50000
   747
hoelzl@50000
   748
lemma split_comb_seq_asm: "P (comb_seq i \<omega> \<omega>' j) \<longleftrightarrow> \<not> ((j < i \<and> \<not> P (\<omega> j)) \<or> (\<exists>k. j = i + k \<and> \<not> P (\<omega>' k)))"
hoelzl@50000
   749
  by (auto simp: comb_seq_def)
hoelzl@42257
   750
hoelzl@50000
   751
lemma measurable_comb_seq: "(\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') \<in> measurable ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)) (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   752
proof (rule measurable_PiM_single)
hoelzl@50000
   753
  show "(\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') \<in> space ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)) \<rightarrow> (UNIV \<rightarrow>\<^isub>E space M)"
hoelzl@50000
   754
    by (auto simp: space_pair_measure space_PiM Pi_iff split: split_comb_seq)
hoelzl@50000
   755
  fix j :: nat and A assume A: "A \<in> sets M"
hoelzl@50000
   756
  then have *: "{\<omega> \<in> space ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)). prod_case (comb_seq i) \<omega> j \<in> A} =
hoelzl@50000
   757
    (if j < i then {\<omega> \<in> space (\<Pi>\<^isub>M i\<in>UNIV. M). \<omega> j \<in> A} \<times> space (\<Pi>\<^isub>M i\<in>UNIV. M)
hoelzl@50000
   758
              else space (\<Pi>\<^isub>M i\<in>UNIV. M) \<times> {\<omega> \<in> space (\<Pi>\<^isub>M i\<in>UNIV. M). \<omega> (j - i) \<in> A})"
hoelzl@50000
   759
    by (auto simp: space_PiM space_pair_measure comb_seq_def dest: sets_into_space)
hoelzl@50000
   760
  show "{\<omega> \<in> space ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)). prod_case (comb_seq i) \<omega> j \<in> A} \<in> sets ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M))"
hoelzl@50000
   761
    unfolding * by (auto simp: A intro!: sets_Collect_single)
hoelzl@50000
   762
qed
hoelzl@50000
   763
hoelzl@50000
   764
lemma measurable_comb_seq':
hoelzl@50000
   765
  assumes f: "f \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)" and g: "g \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   766
  shows "(\<lambda>x. comb_seq i (f x) (g x)) \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   767
  using measurable_compose[OF measurable_Pair[OF f g] measurable_comb_seq] by simp
hoelzl@50000
   768
hoelzl@50000
   769
locale sequence_space = product_prob_space "\<lambda>i. M" "UNIV :: nat set" for M
hoelzl@50000
   770
begin
hoelzl@50000
   771
hoelzl@50000
   772
abbreviation "S \<equiv> \<Pi>\<^isub>M i\<in>UNIV::nat set. M"
hoelzl@50000
   773
hoelzl@50000
   774
lemma infprod_in_sets[intro]:
hoelzl@50000
   775
  fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets M"
hoelzl@50000
   776
  shows "Pi UNIV E \<in> sets S"
hoelzl@42257
   777
proof -
hoelzl@42257
   778
  have "Pi UNIV E = (\<Inter>i. emb UNIV {..i} (\<Pi>\<^isub>E j\<in>{..i}. E j))"
hoelzl@47694
   779
    using E E[THEN sets_into_space]
hoelzl@47694
   780
    by (auto simp: prod_emb_def Pi_iff extensional_def) blast
hoelzl@47694
   781
  with E show ?thesis by auto
hoelzl@42257
   782
qed
hoelzl@42257
   783
hoelzl@50000
   784
lemma measure_PiM_countable:
hoelzl@50000
   785
  fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets M"
hoelzl@50000
   786
  shows "(\<lambda>n. \<Prod>i\<le>n. measure M (E i)) ----> measure S (Pi UNIV E)"
hoelzl@42257
   787
proof -
wenzelm@46731
   788
  let ?E = "\<lambda>n. emb UNIV {..n} (Pi\<^isub>E {.. n} E)"
hoelzl@50000
   789
  have "\<And>n. (\<Prod>i\<le>n. measure M (E i)) = measure S (?E n)"
hoelzl@47694
   790
    using E by (simp add: measure_PiM_emb)
hoelzl@42257
   791
  moreover have "Pi UNIV E = (\<Inter>n. ?E n)"
hoelzl@47694
   792
    using E E[THEN sets_into_space]
hoelzl@47694
   793
    by (auto simp: prod_emb_def extensional_def Pi_iff) blast
hoelzl@50000
   794
  moreover have "range ?E \<subseteq> sets S"
hoelzl@42257
   795
    using E by auto
hoelzl@42257
   796
  moreover have "decseq ?E"
hoelzl@47694
   797
    by (auto simp: prod_emb_def Pi_iff decseq_def)
hoelzl@42257
   798
  ultimately show ?thesis
hoelzl@47694
   799
    by (simp add: finite_Lim_measure_decseq)
hoelzl@42257
   800
qed
hoelzl@42257
   801
hoelzl@50000
   802
lemma nat_eq_diff_eq: 
hoelzl@50000
   803
  fixes a b c :: nat
hoelzl@50000
   804
  shows "c \<le> b \<Longrightarrow> a = b - c \<longleftrightarrow> a + c = b"
hoelzl@50000
   805
  by auto
hoelzl@50000
   806
hoelzl@50000
   807
lemma PiM_comb_seq:
hoelzl@50000
   808
  "distr (S \<Otimes>\<^isub>M S) S (\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') = S" (is "?D = _")
hoelzl@50000
   809
proof (rule PiM_eq)
hoelzl@50000
   810
  let ?I = "UNIV::nat set" and ?M = "\<lambda>n. M"
hoelzl@50000
   811
  let "distr _ _ ?f" = "?D"
hoelzl@50000
   812
hoelzl@50000
   813
  fix J E assume J: "finite J" "J \<subseteq> ?I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets M"
hoelzl@50000
   814
  let ?X = "prod_emb ?I ?M J (\<Pi>\<^isub>E j\<in>J. E j)"
hoelzl@50000
   815
  have "\<And>j x. j \<in> J \<Longrightarrow> x \<in> E j \<Longrightarrow> x \<in> space M"
hoelzl@50000
   816
    using J(3)[THEN sets_into_space] by (auto simp: space_PiM Pi_iff subset_eq)
hoelzl@50000
   817
  with J have "?f -` ?X \<inter> space (S \<Otimes>\<^isub>M S) =
hoelzl@50000
   818
    (prod_emb ?I ?M (J \<inter> {..<i}) (PIE j:J \<inter> {..<i}. E j)) \<times>
hoelzl@50000
   819
    (prod_emb ?I ?M ((op + i) -` J) (PIE j:(op + i) -` J. E (i + j)))" (is "_ = ?E \<times> ?F")
hoelzl@50000
   820
   by (auto simp: space_pair_measure space_PiM prod_emb_def all_conj_distrib Pi_iff
hoelzl@50000
   821
               split: split_comb_seq split_comb_seq_asm)
hoelzl@50000
   822
  then have "emeasure ?D ?X = emeasure (S \<Otimes>\<^isub>M S) (?E \<times> ?F)"
hoelzl@50000
   823
    by (subst emeasure_distr[OF measurable_comb_seq])
hoelzl@50000
   824
       (auto intro!: sets_PiM_I simp: split_beta' J)
hoelzl@50000
   825
  also have "\<dots> = emeasure S ?E * emeasure S ?F"
hoelzl@50000
   826
    using J by (intro P.emeasure_pair_measure_Times)  (auto intro!: sets_PiM_I finite_vimageI simp: inj_on_def)
hoelzl@50000
   827
  also have "emeasure S ?F = (\<Prod>j\<in>(op + i) -` J. emeasure M (E (i + j)))"
hoelzl@50000
   828
    using J by (intro emeasure_PiM_emb) (simp_all add: finite_vimageI inj_on_def)
hoelzl@50000
   829
  also have "\<dots> = (\<Prod>j\<in>J - (J \<inter> {..<i}). emeasure M (E j))"
hoelzl@50000
   830
    by (rule strong_setprod_reindex_cong[where f="\<lambda>x. x - i"])
hoelzl@50000
   831
       (auto simp: image_iff Bex_def not_less nat_eq_diff_eq ac_simps cong: conj_cong intro!: inj_onI)
hoelzl@50000
   832
  also have "emeasure S ?E = (\<Prod>j\<in>J \<inter> {..<i}. emeasure M (E j))"
hoelzl@50000
   833
    using J by (intro emeasure_PiM_emb) simp_all
hoelzl@50000
   834
  also have "(\<Prod>j\<in>J \<inter> {..<i}. emeasure M (E j)) * (\<Prod>j\<in>J - (J \<inter> {..<i}). emeasure M (E j)) = (\<Prod>j\<in>J. emeasure M (E j))"
hoelzl@50000
   835
    by (subst mult_commute) (auto simp: J setprod_subset_diff[symmetric])
hoelzl@50000
   836
  finally show "emeasure ?D ?X = (\<Prod>j\<in>J. emeasure M (E j))" .
hoelzl@50000
   837
qed simp_all
hoelzl@50000
   838
hoelzl@50000
   839
lemma PiM_iter:
hoelzl@50000
   840
  "distr (M \<Otimes>\<^isub>M S) S (\<lambda>(s, \<omega>). nat_case s \<omega>) = S" (is "?D = _")
hoelzl@50000
   841
proof (rule PiM_eq)
hoelzl@50000
   842
  let ?I = "UNIV::nat set" and ?M = "\<lambda>n. M"
hoelzl@50000
   843
  let "distr _ _ ?f" = "?D"
hoelzl@50000
   844
hoelzl@50000
   845
  fix J E assume J: "finite J" "J \<subseteq> ?I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets M"
hoelzl@50000
   846
  let ?X = "prod_emb ?I ?M J (PIE j:J. E j)"
hoelzl@50000
   847
  have "\<And>j x. j \<in> J \<Longrightarrow> x \<in> E j \<Longrightarrow> x \<in> space M"
hoelzl@50000
   848
    using J(3)[THEN sets_into_space] by (auto simp: space_PiM Pi_iff subset_eq)
hoelzl@50000
   849
  with J have "?f -` ?X \<inter> space (M \<Otimes>\<^isub>M S) = (if 0 \<in> J then E 0 else space M) \<times>
hoelzl@50000
   850
    (prod_emb ?I ?M (Suc -` J) (PIE j:Suc -` J. E (Suc j)))" (is "_ = ?E \<times> ?F")
hoelzl@50000
   851
   by (auto simp: space_pair_measure space_PiM Pi_iff prod_emb_def all_conj_distrib
hoelzl@50000
   852
      split: nat.split nat.split_asm)
hoelzl@50000
   853
  then have "emeasure ?D ?X = emeasure (M \<Otimes>\<^isub>M S) (?E \<times> ?F)"
hoelzl@50000
   854
    by (subst emeasure_distr[OF measurable_nat_case])
hoelzl@50000
   855
       (auto intro!: sets_PiM_I simp: split_beta' J)
hoelzl@50000
   856
  also have "\<dots> = emeasure M ?E * emeasure S ?F"
hoelzl@50000
   857
    using J by (intro P.emeasure_pair_measure_Times) (auto intro!: sets_PiM_I finite_vimageI)
hoelzl@50000
   858
  also have "emeasure S ?F = (\<Prod>j\<in>Suc -` J. emeasure M (E (Suc j)))"
hoelzl@50000
   859
    using J by (intro emeasure_PiM_emb) (simp_all add: finite_vimageI)
hoelzl@50000
   860
  also have "\<dots> = (\<Prod>j\<in>J - {0}. emeasure M (E j))"
hoelzl@50000
   861
    by (rule strong_setprod_reindex_cong[where f="\<lambda>x. x - 1"])
hoelzl@50000
   862
       (auto simp: image_iff Bex_def not_less nat_eq_diff_eq ac_simps cong: conj_cong intro!: inj_onI)
hoelzl@50000
   863
  also have "emeasure M ?E * (\<Prod>j\<in>J - {0}. emeasure M (E j)) = (\<Prod>j\<in>J. emeasure M (E j))"
hoelzl@50000
   864
    by (auto simp: M.emeasure_space_1 setprod.remove J)
hoelzl@50000
   865
  finally show "emeasure ?D ?X = (\<Prod>j\<in>J. emeasure M (E j))" .
hoelzl@50000
   866
qed simp_all
hoelzl@50000
   867
hoelzl@50000
   868
end
hoelzl@50000
   869
hoelzl@42147
   870
end