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