src/HOL/Probability/Infinite_Product_Measure.thy
author hoelzl
Wed Oct 10 12:12:21 2012 +0200 (2012-10-10)
changeset 49780 92a58f80b20c
parent 49776 199d1d5bb17e
child 49784 5e5b2da42a69
permissions -rw-r--r--
merge should operate on pairs
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@42147
    11
lemma restrict_extensional_sub[intro]: "A \<subseteq> B \<Longrightarrow> restrict f A \<in> extensional B"
hoelzl@42147
    12
  unfolding restrict_def extensional_def by auto
hoelzl@42147
    13
hoelzl@42147
    14
lemma restrict_restrict[simp]: "restrict (restrict f A) B = restrict f (A \<inter> B)"
hoelzl@42147
    15
  unfolding restrict_def by (simp add: fun_eq_iff)
hoelzl@42147
    16
hoelzl@49780
    17
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
    18
  unfolding merge_def by auto
hoelzl@42147
    19
hoelzl@49780
    20
lemma extensional_merge_sub: "I \<union> J \<subseteq> K \<Longrightarrow> merge I J (x, y) \<in> extensional K"
hoelzl@42147
    21
  unfolding merge_def extensional_def by auto
hoelzl@42147
    22
hoelzl@42147
    23
lemma injective_vimage_restrict:
hoelzl@42147
    24
  assumes J: "J \<subseteq> I"
hoelzl@42147
    25
  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
    26
  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
    27
  shows "A = B"
hoelzl@42147
    28
proof  (intro set_eqI)
hoelzl@42147
    29
  fix x
hoelzl@42147
    30
  from ne obtain y where y: "\<And>i. i \<in> I \<Longrightarrow> y i \<in> S i" by auto
hoelzl@42147
    31
  have "J \<inter> (I - J) = {}" by auto
hoelzl@42147
    32
  show "x \<in> A \<longleftrightarrow> x \<in> B"
hoelzl@42147
    33
  proof cases
hoelzl@42147
    34
    assume x: "x \<in> (\<Pi>\<^isub>E i\<in>J. S i)"
hoelzl@49780
    35
    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
    36
      using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub split: split_merge)
hoelzl@42147
    37
    then show "x \<in> A \<longleftrightarrow> x \<in> B"
hoelzl@42147
    38
      using y x `J \<subseteq> I` by (auto simp add: Pi_iff extensional_restrict extensional_merge_sub eq split: split_merge)
hoelzl@42147
    39
  next
hoelzl@42147
    40
    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
    41
  qed
hoelzl@42147
    42
qed
hoelzl@42147
    43
hoelzl@47694
    44
lemma prod_algebraI_finite:
hoelzl@47694
    45
  "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
    46
  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
    47
hoelzl@47694
    48
lemma Int_stable_PiE: "Int_stable {Pi\<^isub>E J E | E. \<forall>i\<in>I. E i \<in> sets (M i)}"
hoelzl@47694
    49
proof (safe intro!: Int_stableI)
hoelzl@47694
    50
  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
    51
  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
    52
    by (auto intro!: exI[of _ "\<lambda>i. E i \<inter> F i"])
hoelzl@47694
    53
qed
hoelzl@47694
    54
hoelzl@47694
    55
lemma prod_emb_trans[simp]:
hoelzl@47694
    56
  "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
    57
  by (auto simp add: Int_absorb1 prod_emb_def)
hoelzl@47694
    58
hoelzl@47694
    59
lemma prod_emb_Pi:
hoelzl@47694
    60
  assumes "X \<in> (\<Pi> j\<in>J. sets (M j))" "J \<subseteq> K"
hoelzl@47694
    61
  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
    62
  using assms space_closed
hoelzl@47694
    63
  by (auto simp: prod_emb_def Pi_iff split: split_if_asm) blast+
hoelzl@47694
    64
hoelzl@47694
    65
lemma prod_emb_id:
hoelzl@47694
    66
  "B \<subseteq> (\<Pi>\<^isub>E i\<in>L. space (M i)) \<Longrightarrow> prod_emb L M L B = B"
hoelzl@47694
    67
  by (auto simp: prod_emb_def Pi_iff subset_eq extensional_restrict)
hoelzl@47694
    68
hoelzl@47694
    69
lemma measurable_prod_emb[intro, simp]:
hoelzl@47694
    70
  "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
    71
  unfolding prod_emb_def space_PiM[symmetric]
hoelzl@47694
    72
  by (auto intro!: measurable_sets measurable_restrict measurable_component_singleton)
hoelzl@47694
    73
hoelzl@47694
    74
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
    75
  by (intro measurable_restrict measurable_component_singleton) auto
hoelzl@47694
    76
hoelzl@47694
    77
lemma (in product_prob_space) distr_restrict:
hoelzl@42147
    78
  assumes "J \<noteq> {}" "J \<subseteq> K" "finite K"
hoelzl@47694
    79
  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
    80
proof (rule measure_eqI_generator_eq)
hoelzl@47694
    81
  have "finite J" using `J \<subseteq> K` `finite K` by (auto simp add: finite_subset)
hoelzl@47694
    82
  interpret J: finite_product_prob_space M J proof qed fact
hoelzl@47694
    83
  interpret K: finite_product_prob_space M K proof qed fact
hoelzl@47694
    84
hoelzl@47694
    85
  let ?J = "{Pi\<^isub>E J E | E. \<forall>i\<in>J. E i \<in> sets (M i)}"
hoelzl@47694
    86
  let ?F = "\<lambda>i. \<Pi>\<^isub>E k\<in>J. space (M k)"
hoelzl@47694
    87
  let ?\<Omega> = "(\<Pi>\<^isub>E k\<in>J. space (M k))"
hoelzl@47694
    88
  show "Int_stable ?J"
hoelzl@47694
    89
    by (rule Int_stable_PiE)
hoelzl@47694
    90
  show "range ?F \<subseteq> ?J" "incseq ?F" "(\<Union>i. ?F i) = ?\<Omega>"
hoelzl@47694
    91
    using `finite J` by (auto intro!: prod_algebraI_finite)
hoelzl@47694
    92
  { fix i show "emeasure ?P (?F i) \<noteq> \<infinity>" by simp }
hoelzl@47694
    93
  show "?J \<subseteq> Pow ?\<Omega>" by (auto simp: Pi_iff dest: sets_into_space)
hoelzl@47694
    94
  show "sets (\<Pi>\<^isub>M i\<in>J. M i) = sigma_sets ?\<Omega> ?J" "sets ?D = sigma_sets ?\<Omega> ?J"
hoelzl@47694
    95
    using `finite J` by (simp_all add: sets_PiM prod_algebra_eq_finite Pi_iff)
hoelzl@47694
    96
  
hoelzl@47694
    97
  fix X assume "X \<in> ?J"
hoelzl@47694
    98
  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@47694
    99
  with `finite J` have X: "X \<in> sets (Pi\<^isub>M J M)" by auto
hoelzl@47694
   100
hoelzl@47694
   101
  have "emeasure ?P X = (\<Prod> i\<in>J. emeasure (M i) (E i))"
hoelzl@47694
   102
    using E by (simp add: J.measure_times)
hoelzl@47694
   103
  also have "\<dots> = (\<Prod> i\<in>J. emeasure (M i) (if i \<in> J then E i else space (M i)))"
hoelzl@47694
   104
    by simp
hoelzl@47694
   105
  also have "\<dots> = (\<Prod> i\<in>K. emeasure (M i) (if i \<in> J then E i else space (M i)))"
hoelzl@47694
   106
    using `finite K` `J \<subseteq> K`
hoelzl@47694
   107
    by (intro setprod_mono_one_left) (auto simp: M.emeasure_space_1)
hoelzl@47694
   108
  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
   109
    using E by (simp add: K.measure_times)
hoelzl@47694
   110
  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
   111
    using `J \<subseteq> K` sets_into_space E by (force simp:  Pi_iff split: split_if_asm)
hoelzl@47694
   112
  finally show "emeasure (Pi\<^isub>M J M) X = emeasure ?D X"
hoelzl@47694
   113
    using X `J \<subseteq> K` apply (subst emeasure_distr)
hoelzl@47694
   114
    by (auto intro!: measurable_restrict_subset simp: space_PiM)
hoelzl@42147
   115
qed
hoelzl@42147
   116
hoelzl@47694
   117
abbreviation (in product_prob_space)
hoelzl@47694
   118
  "emb L K X \<equiv> prod_emb L M K X"
hoelzl@47694
   119
hoelzl@47694
   120
lemma (in product_prob_space) emeasure_prod_emb[simp]:
hoelzl@47694
   121
  assumes L: "J \<noteq> {}" "J \<subseteq> L" "finite L" and X: "X \<in> sets (Pi\<^isub>M J M)"
hoelzl@47694
   122
  shows "emeasure (Pi\<^isub>M L M) (emb L J X) = emeasure (Pi\<^isub>M J M) X"
hoelzl@47694
   123
  by (subst distr_restrict[OF L])
hoelzl@47694
   124
     (simp add: prod_emb_def space_PiM emeasure_distr measurable_restrict_subset L X)
hoelzl@42147
   125
hoelzl@47694
   126
lemma (in product_prob_space) prod_emb_injective:
hoelzl@47694
   127
  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
   128
  assumes "prod_emb L M J X = prod_emb L M J Y"
hoelzl@47694
   129
  shows "X = Y"
hoelzl@47694
   130
proof (rule injective_vimage_restrict)
hoelzl@47694
   131
  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
   132
    using sets[THEN sets_into_space] by (auto simp: space_PiM)
hoelzl@47694
   133
  have "\<forall>i\<in>L. \<exists>x. x \<in> space (M i)"
hoelzl@49780
   134
      using M.not_empty by auto
hoelzl@47694
   135
  from bchoice[OF this]
hoelzl@47694
   136
  show "(\<Pi>\<^isub>E i\<in>L. space (M i)) \<noteq> {}" by auto
hoelzl@47694
   137
  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
   138
    using `prod_emb L M J X = prod_emb L M J Y` by (simp add: prod_emb_def)
hoelzl@47694
   139
qed fact
hoelzl@42147
   140
hoelzl@47694
   141
definition (in product_prob_space) generator :: "('i \<Rightarrow> 'a) set set" where
hoelzl@47694
   142
  "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
   143
hoelzl@47694
   144
lemma (in product_prob_space) generatorI':
hoelzl@47694
   145
  "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
   146
  unfolding generator_def by auto
hoelzl@42147
   147
hoelzl@47694
   148
lemma (in product_prob_space) algebra_generator:
hoelzl@47694
   149
  assumes "I \<noteq> {}" shows "algebra (\<Pi>\<^isub>E i\<in>I. space (M i)) generator" (is "algebra ?\<Omega> ?G")
hoelzl@47762
   150
  unfolding algebra_def algebra_axioms_def ring_of_sets_iff
hoelzl@47762
   151
proof (intro conjI ballI)
hoelzl@47694
   152
  let ?G = generator
hoelzl@47694
   153
  show "?G \<subseteq> Pow ?\<Omega>"
hoelzl@47694
   154
    by (auto simp: generator_def prod_emb_def)
hoelzl@47694
   155
  from `I \<noteq> {}` obtain i where "i \<in> I" by auto
hoelzl@47694
   156
  then show "{} \<in> ?G"
hoelzl@47694
   157
    by (auto intro!: exI[of _ "{i}"] image_eqI[where x="\<lambda>i. {}"]
hoelzl@47694
   158
             simp: sigma_sets.Empty generator_def prod_emb_def)
hoelzl@47694
   159
  from `i \<in> I` show "?\<Omega> \<in> ?G"
hoelzl@47694
   160
    by (auto intro!: exI[of _ "{i}"] image_eqI[where x="Pi\<^isub>E {i} (\<lambda>i. space (M i))"]
hoelzl@47694
   161
             simp: generator_def prod_emb_def)
hoelzl@47694
   162
  fix A assume "A \<in> ?G"
hoelzl@47694
   163
  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
   164
    by (auto simp: generator_def)
hoelzl@47694
   165
  fix B assume "B \<in> ?G"
hoelzl@47694
   166
  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
   167
    by (auto simp: generator_def)
hoelzl@47694
   168
  let ?RA = "emb (JA \<union> JB) JA XA"
hoelzl@47694
   169
  let ?RB = "emb (JA \<union> JB) JB XB"
hoelzl@47694
   170
  have *: "A - B = emb I (JA \<union> JB) (?RA - ?RB)" "A \<union> B = emb I (JA \<union> JB) (?RA \<union> ?RB)"
hoelzl@47694
   171
    using XA A XB B by auto
hoelzl@47694
   172
  show "A - B \<in> ?G" "A \<union> B \<in> ?G"
hoelzl@47694
   173
    unfolding * using XA XB by (safe intro!: generatorI') auto
hoelzl@42147
   174
qed
hoelzl@42147
   175
hoelzl@47694
   176
lemma (in product_prob_space) sets_PiM_generator:
hoelzl@47694
   177
  assumes "I \<noteq> {}" shows "sets (PiM I M) = sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) generator"
hoelzl@47694
   178
proof
hoelzl@47694
   179
  show "sets (Pi\<^isub>M I M) \<subseteq> sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) generator"
hoelzl@47694
   180
    unfolding sets_PiM
hoelzl@47694
   181
  proof (safe intro!: sigma_sets_subseteq)
hoelzl@47694
   182
    fix A assume "A \<in> prod_algebra I M" with `I \<noteq> {}` show "A \<in> generator"
hoelzl@47694
   183
      by (auto intro!: generatorI' elim!: prod_algebraE)
hoelzl@47694
   184
  qed
hoelzl@47694
   185
qed (auto simp: generator_def space_PiM[symmetric] intro!: sigma_sets_subset)
hoelzl@42147
   186
hoelzl@42147
   187
lemma (in product_prob_space) generatorI:
hoelzl@47694
   188
  "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
   189
  unfolding generator_def by auto
hoelzl@42147
   190
hoelzl@42147
   191
definition (in product_prob_space)
hoelzl@42147
   192
  "\<mu>G A =
hoelzl@47694
   193
    (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
   194
hoelzl@42147
   195
lemma (in product_prob_space) \<mu>G_spec:
hoelzl@42147
   196
  assumes J: "J \<noteq> {}" "finite J" "J \<subseteq> I" "A = emb I J X" "X \<in> sets (Pi\<^isub>M J M)"
hoelzl@47694
   197
  shows "\<mu>G A = emeasure (Pi\<^isub>M J M) X"
hoelzl@42147
   198
  unfolding \<mu>G_def
hoelzl@42147
   199
proof (intro the_equality allI impI ballI)
hoelzl@42147
   200
  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
   201
  have "emeasure (Pi\<^isub>M K M) Y = emeasure (Pi\<^isub>M (K \<union> J) M) (emb (K \<union> J) K Y)"
hoelzl@42147
   202
    using K J by simp
hoelzl@42147
   203
  also have "emb (K \<union> J) K Y = emb (K \<union> J) J X"
hoelzl@47694
   204
    using K J by (simp add: prod_emb_injective[of "K \<union> J" I])
hoelzl@47694
   205
  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
   206
    using K J by simp
hoelzl@47694
   207
  finally show "emeasure (Pi\<^isub>M J M) X = emeasure (Pi\<^isub>M K M) Y" ..
hoelzl@42147
   208
qed (insert J, force)
hoelzl@42147
   209
hoelzl@42147
   210
lemma (in product_prob_space) \<mu>G_eq:
hoelzl@47694
   211
  "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
   212
  by (intro \<mu>G_spec) auto
hoelzl@42147
   213
hoelzl@42147
   214
lemma (in product_prob_space) generator_Ex:
hoelzl@47694
   215
  assumes *: "A \<in> generator"
hoelzl@47694
   216
  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
   217
proof -
hoelzl@42147
   218
  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
   219
    unfolding generator_def by auto
hoelzl@42147
   220
  with \<mu>G_spec[OF this] show ?thesis by auto
hoelzl@42147
   221
qed
hoelzl@42147
   222
hoelzl@42147
   223
lemma (in product_prob_space) generatorE:
hoelzl@47694
   224
  assumes A: "A \<in> generator"
hoelzl@47694
   225
  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
   226
proof -
hoelzl@42147
   227
  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
   228
    "\<mu>G A = emeasure (Pi\<^isub>M J M) X" by auto
hoelzl@42147
   229
  then show thesis by (intro that) auto
hoelzl@42147
   230
qed
hoelzl@42147
   231
hoelzl@42147
   232
lemma (in product_prob_space) merge_sets:
hoelzl@49780
   233
  assumes "J \<inter> K = {}" and A: "A \<in> sets (Pi\<^isub>M (J \<union> K) M)" and x: "x \<in> space (Pi\<^isub>M J M)"
hoelzl@49780
   234
  shows "(\<lambda>y. merge J K (x,y)) -` A \<inter> space (Pi\<^isub>M K M) \<in> sets (Pi\<^isub>M K M)"
hoelzl@49780
   235
  by (rule measurable_sets[OF _ A] measurable_compose[OF measurable_Pair measurable_merge]  
hoelzl@49780
   236
           measurable_const x measurable_ident)+
hoelzl@42147
   237
hoelzl@42147
   238
lemma (in product_prob_space) merge_emb:
hoelzl@42147
   239
  assumes "K \<subseteq> I" "J \<subseteq> I" and y: "y \<in> space (Pi\<^isub>M J M)"
hoelzl@49780
   240
  shows "((\<lambda>x. merge J (I - J) (y, x)) -` emb I K X \<inter> space (Pi\<^isub>M I M)) =
hoelzl@49780
   241
    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
   242
proof -
hoelzl@49780
   243
  have [simp]: "\<And>x J K L. merge J K (y, restrict x L) = merge J (K \<inter> L) (y, x)"
hoelzl@42147
   244
    by (auto simp: restrict_def merge_def)
hoelzl@49780
   245
  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
   246
    by (auto simp: restrict_def merge_def)
hoelzl@42147
   247
  have [simp]: "(I - J) \<inter> K = K - J" using `K \<subseteq> I` `J \<subseteq> I` by auto
hoelzl@42147
   248
  have [simp]: "(K - J) \<inter> (K \<union> J) = K - J" by auto
hoelzl@42147
   249
  have [simp]: "(K - J) \<inter> K = K - J" by auto
hoelzl@42147
   250
  from y `K \<subseteq> I` `J \<subseteq> I` show ?thesis
hoelzl@47694
   251
    by (simp split: split_merge add: prod_emb_def Pi_iff extensional_merge_sub set_eq_iff space_PiM)
hoelzl@47694
   252
       auto
hoelzl@42147
   253
qed
hoelzl@42147
   254
hoelzl@45777
   255
lemma (in product_prob_space) positive_\<mu>G: 
hoelzl@45777
   256
  assumes "I \<noteq> {}"
hoelzl@45777
   257
  shows "positive generator \<mu>G"
hoelzl@45777
   258
proof -
hoelzl@47694
   259
  interpret G!: algebra "\<Pi>\<^isub>E i\<in>I. space (M i)" generator by (rule algebra_generator) fact
hoelzl@45777
   260
  show ?thesis
hoelzl@45777
   261
  proof (intro positive_def[THEN iffD2] conjI ballI)
hoelzl@45777
   262
    from generatorE[OF G.empty_sets] guess J X . note this[simp]
hoelzl@45777
   263
    interpret J: finite_product_sigma_finite M J by default fact
hoelzl@45777
   264
    have "X = {}"
hoelzl@47694
   265
      by (rule prod_emb_injective[of J I]) simp_all
hoelzl@45777
   266
    then show "\<mu>G {} = 0" by simp
hoelzl@45777
   267
  next
hoelzl@47694
   268
    fix A assume "A \<in> generator"
hoelzl@45777
   269
    from generatorE[OF this] guess J X . note this[simp]
hoelzl@45777
   270
    interpret J: finite_product_sigma_finite M J by default fact
hoelzl@47694
   271
    show "0 \<le> \<mu>G A" by (simp add: emeasure_nonneg)
hoelzl@45777
   272
  qed
hoelzl@42147
   273
qed
hoelzl@42147
   274
hoelzl@45777
   275
lemma (in product_prob_space) additive_\<mu>G: 
hoelzl@45777
   276
  assumes "I \<noteq> {}"
hoelzl@45777
   277
  shows "additive generator \<mu>G"
hoelzl@45777
   278
proof -
hoelzl@47694
   279
  interpret G!: algebra "\<Pi>\<^isub>E i\<in>I. space (M i)" generator by (rule algebra_generator) fact
hoelzl@45777
   280
  show ?thesis
hoelzl@45777
   281
  proof (intro additive_def[THEN iffD2] ballI impI)
hoelzl@47694
   282
    fix A assume "A \<in> generator" with generatorE guess J X . note J = this
hoelzl@47694
   283
    fix B assume "B \<in> generator" with generatorE guess K Y . note K = this
hoelzl@45777
   284
    assume "A \<inter> B = {}"
hoelzl@45777
   285
    have JK: "J \<union> K \<noteq> {}" "J \<union> K \<subseteq> I" "finite (J \<union> K)"
hoelzl@45777
   286
      using J K by auto
hoelzl@45777
   287
    interpret JK: finite_product_sigma_finite M "J \<union> K" by default fact
hoelzl@45777
   288
    have JK_disj: "emb (J \<union> K) J X \<inter> emb (J \<union> K) K Y = {}"
hoelzl@47694
   289
      apply (rule prod_emb_injective[of "J \<union> K" I])
hoelzl@45777
   290
      apply (insert `A \<inter> B = {}` JK J K)
hoelzl@47694
   291
      apply (simp_all add: Int prod_emb_Int)
hoelzl@45777
   292
      done
hoelzl@45777
   293
    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
   294
      using J K by simp_all
hoelzl@45777
   295
    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
   296
      by simp
hoelzl@47694
   297
    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
   298
      using JK J(1, 4) K(1, 4) by (simp add: \<mu>G_eq Un del: prod_emb_Un)
hoelzl@45777
   299
    also have "\<dots> = \<mu>G A + \<mu>G B"
hoelzl@47694
   300
      using J K JK_disj by (simp add: plus_emeasure[symmetric])
hoelzl@45777
   301
    finally show "\<mu>G (A \<union> B) = \<mu>G A + \<mu>G B" .
hoelzl@45777
   302
  qed
hoelzl@42147
   303
qed
hoelzl@42147
   304
hoelzl@47694
   305
lemma (in product_prob_space) emeasure_PiM_emb_not_empty:
hoelzl@47694
   306
  assumes X: "J \<noteq> {}" "J \<subseteq> I" "finite J" "\<forall>i\<in>J. X i \<in> sets (M i)"
hoelzl@47694
   307
  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
   308
proof cases
hoelzl@47694
   309
  assume "finite I" with X show ?thesis by simp
hoelzl@42147
   310
next
hoelzl@47694
   311
  let ?\<Omega> = "\<Pi>\<^isub>E i\<in>I. space (M i)"
hoelzl@42147
   312
  let ?G = generator
hoelzl@42147
   313
  assume "\<not> finite I"
hoelzl@45777
   314
  then have I_not_empty: "I \<noteq> {}" by auto
hoelzl@47694
   315
  interpret G!: algebra ?\<Omega> generator by (rule algebra_generator) fact
hoelzl@42147
   316
  note \<mu>G_mono =
hoelzl@45777
   317
    G.additive_increasing[OF positive_\<mu>G[OF I_not_empty] additive_\<mu>G[OF I_not_empty], THEN increasingD]
hoelzl@42147
   318
hoelzl@47694
   319
  { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> ?G"
hoelzl@42147
   320
hoelzl@42147
   321
    from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
hoelzl@42147
   322
      by (metis rev_finite_subset subsetI)
hoelzl@42147
   323
    moreover from Z guess K' X' by (rule generatorE)
hoelzl@42147
   324
    moreover def K \<equiv> "insert k K'"
hoelzl@42147
   325
    moreover def X \<equiv> "emb K K' X'"
hoelzl@42147
   326
    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
   327
      "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = emeasure (Pi\<^isub>M K M) X"
hoelzl@42147
   328
      by (auto simp: subset_insertI)
hoelzl@42147
   329
hoelzl@49780
   330
    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
   331
    { fix y assume y: "y \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
   332
      note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
hoelzl@42147
   333
      moreover
hoelzl@42147
   334
      have **: "?M y \<in> sets (Pi\<^isub>M (K - J) M)"
hoelzl@42147
   335
        using J K y by (intro merge_sets) auto
hoelzl@42147
   336
      ultimately
hoelzl@49780
   337
      have ***: "((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)) \<in> ?G"
hoelzl@42147
   338
        using J K by (intro generatorI) auto
hoelzl@49780
   339
      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
   340
        unfolding * using K J by (subst \<mu>G_eq[OF _ _ _ **]) auto
hoelzl@42147
   341
      note * ** *** this }
hoelzl@42147
   342
    note merge_in_G = this
hoelzl@42147
   343
hoelzl@42147
   344
    have "finite (K - J)" using K by auto
hoelzl@42147
   345
hoelzl@42147
   346
    interpret J: finite_product_prob_space M J by default fact+
hoelzl@42147
   347
    interpret KmJ: finite_product_prob_space M "K - J" by default fact+
hoelzl@42147
   348
hoelzl@47694
   349
    have "\<mu>G Z = emeasure (Pi\<^isub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
hoelzl@42147
   350
      using K J by simp
hoelzl@47694
   351
    also have "\<dots> = (\<integral>\<^isup>+ x. emeasure (Pi\<^isub>M (K - J) M) (?M x) \<partial>Pi\<^isub>M J M)"
hoelzl@47694
   352
      using K J by (subst emeasure_fold_integral) auto
hoelzl@49780
   353
    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
   354
      (is "_ = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)")
hoelzl@47694
   355
    proof (intro positive_integral_cong)
hoelzl@42147
   356
      fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
   357
      with K merge_in_G(2)[OF this]
hoelzl@47694
   358
      show "emeasure (Pi\<^isub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
hoelzl@42147
   359
        unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst \<mu>G_eq) auto
hoelzl@42147
   360
    qed
hoelzl@42147
   361
    finally have fold: "\<mu>G Z = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)" .
hoelzl@42147
   362
hoelzl@42147
   363
    { fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
   364
      then have "\<mu>G (?MZ x) \<le> 1"
hoelzl@42147
   365
        unfolding merge_in_G(4)[OF x] `Z = emb I K X`
hoelzl@42147
   366
        by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
hoelzl@42147
   367
    note le_1 = this
hoelzl@42147
   368
hoelzl@49780
   369
    let ?q = "\<lambda>y. \<mu>G ((\<lambda>x. merge J (I - J) (y,x)) -` Z \<inter> space (Pi\<^isub>M I M))"
hoelzl@42147
   370
    have "?q \<in> borel_measurable (Pi\<^isub>M J M)"
hoelzl@42147
   371
      unfolding `Z = emb I K X` using J K merge_in_G(3)
hoelzl@47694
   372
      by (simp add: merge_in_G  \<mu>G_eq emeasure_fold_measurable cong: measurable_cong)
hoelzl@42147
   373
    note this fold le_1 merge_in_G(3) }
hoelzl@42147
   374
  note fold = this
hoelzl@42147
   375
hoelzl@47694
   376
  have "\<exists>\<mu>. (\<forall>s\<in>?G. \<mu> s = \<mu>G s) \<and> measure_space ?\<Omega> (sigma_sets ?\<Omega> ?G) \<mu>"
hoelzl@42147
   377
  proof (rule G.caratheodory_empty_continuous[OF positive_\<mu>G additive_\<mu>G])
hoelzl@47694
   378
    fix A assume "A \<in> ?G"
hoelzl@42147
   379
    with generatorE guess J X . note JX = this
hoelzl@42147
   380
    interpret JK: finite_product_prob_space M J by default fact+
wenzelm@46898
   381
    from JX show "\<mu>G A \<noteq> \<infinity>" by simp
hoelzl@42147
   382
  next
hoelzl@47694
   383
    fix A assume A: "range A \<subseteq> ?G" "decseq A" "(\<Inter>i. A i) = {}"
hoelzl@42147
   384
    then have "decseq (\<lambda>i. \<mu>G (A i))"
hoelzl@42147
   385
      by (auto intro!: \<mu>G_mono simp: decseq_def)
hoelzl@42147
   386
    moreover
hoelzl@42147
   387
    have "(INF i. \<mu>G (A i)) = 0"
hoelzl@42147
   388
    proof (rule ccontr)
hoelzl@42147
   389
      assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
hoelzl@42147
   390
      moreover have "0 \<le> ?a"
hoelzl@45777
   391
        using A positive_\<mu>G[OF I_not_empty] by (auto intro!: INF_greatest simp: positive_def)
hoelzl@42147
   392
      ultimately have "0 < ?a" by auto
hoelzl@42147
   393
hoelzl@47694
   394
      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
   395
        using A by (intro allI generator_Ex) auto
hoelzl@42147
   396
      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
   397
        and A': "\<And>n. A n = emb I (J' n) (X' n)"
hoelzl@42147
   398
        unfolding choice_iff by blast
hoelzl@42147
   399
      moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
hoelzl@42147
   400
      moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
hoelzl@42147
   401
      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
   402
        by auto
hoelzl@47694
   403
      with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> ?G"
hoelzl@47694
   404
        unfolding J_def X_def by (subst prod_emb_trans) (insert A, auto)
hoelzl@42147
   405
hoelzl@42147
   406
      have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
hoelzl@42147
   407
        unfolding J_def by force
hoelzl@42147
   408
hoelzl@42147
   409
      interpret J: finite_product_prob_space M "J i" for i by default fact+
hoelzl@42147
   410
hoelzl@42147
   411
      have a_le_1: "?a \<le> 1"
hoelzl@42147
   412
        using \<mu>G_spec[of "J 0" "A 0" "X 0"] J A_eq
hoelzl@44928
   413
        by (auto intro!: INF_lower2[of 0] J.measure_le_1)
hoelzl@42147
   414
hoelzl@49780
   415
      let ?M = "\<lambda>K Z y. (\<lambda>x. merge K (I - K) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)"
hoelzl@42147
   416
hoelzl@47694
   417
      { fix Z k assume Z: "range Z \<subseteq> ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
hoelzl@47694
   418
        then have Z_sets: "\<And>n. Z n \<in> ?G" by auto
hoelzl@42147
   419
        fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
hoelzl@42147
   420
        interpret J': finite_product_prob_space M J' by default fact+
hoelzl@42147
   421
wenzelm@46731
   422
        let ?q = "\<lambda>n y. \<mu>G (?M J' (Z n) y)"
wenzelm@46731
   423
        let ?Q = "\<lambda>n. ?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^isub>M J' M)"
hoelzl@42147
   424
        { fix n
hoelzl@42147
   425
          have "?q n \<in> borel_measurable (Pi\<^isub>M J' M)"
hoelzl@42147
   426
            using Z J' by (intro fold(1)) auto
hoelzl@42147
   427
          then have "?Q n \<in> sets (Pi\<^isub>M J' M)"
hoelzl@42147
   428
            by (rule measurable_sets) auto }
hoelzl@42147
   429
        note Q_sets = this
hoelzl@42147
   430
hoelzl@47694
   431
        have "?a / 2^(k+1) \<le> (INF n. emeasure (Pi\<^isub>M J' M) (?Q n))"
hoelzl@44928
   432
        proof (intro INF_greatest)
hoelzl@42147
   433
          fix n
hoelzl@42147
   434
          have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
hoelzl@42147
   435
          also have "\<dots> \<le> (\<integral>\<^isup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^isub>M J' M)"
hoelzl@47694
   436
            unfolding fold(2)[OF J' `Z n \<in> ?G`]
hoelzl@47694
   437
          proof (intro positive_integral_mono)
hoelzl@42147
   438
            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
hoelzl@42147
   439
            then have "?q n x \<le> 1 + 0"
hoelzl@42147
   440
              using J' Z fold(3) Z_sets by auto
hoelzl@42147
   441
            also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
hoelzl@42147
   442
              using `0 < ?a` by (intro add_mono) auto
hoelzl@42147
   443
            finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
hoelzl@42147
   444
            with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
hoelzl@42147
   445
              by (auto split: split_indicator simp del: power_Suc)
hoelzl@42147
   446
          qed
hoelzl@47694
   447
          also have "\<dots> = emeasure (Pi\<^isub>M J' M) (?Q n) + ?a / 2^(k+1)"
hoelzl@47694
   448
            using `0 \<le> ?a` Q_sets J'.emeasure_space_1
hoelzl@47694
   449
            by (subst positive_integral_add) auto
hoelzl@47694
   450
          finally show "?a / 2^(k+1) \<le> emeasure (Pi\<^isub>M J' M) (?Q n)" using `?a \<le> 1`
hoelzl@47694
   451
            by (cases rule: ereal2_cases[of ?a "emeasure (Pi\<^isub>M J' M) (?Q n)"])
hoelzl@42147
   452
               (auto simp: field_simps)
hoelzl@42147
   453
        qed
hoelzl@47694
   454
        also have "\<dots> = emeasure (Pi\<^isub>M J' M) (\<Inter>n. ?Q n)"
hoelzl@47694
   455
        proof (intro INF_emeasure_decseq)
hoelzl@42147
   456
          show "range ?Q \<subseteq> sets (Pi\<^isub>M J' M)" using Q_sets by auto
hoelzl@42147
   457
          show "decseq ?Q"
hoelzl@42147
   458
            unfolding decseq_def
hoelzl@42147
   459
          proof (safe intro!: vimageI[OF refl])
hoelzl@42147
   460
            fix m n :: nat assume "m \<le> n"
hoelzl@42147
   461
            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
hoelzl@42147
   462
            assume "?a / 2^(k+1) \<le> ?q n x"
hoelzl@42147
   463
            also have "?q n x \<le> ?q m x"
hoelzl@42147
   464
            proof (rule \<mu>G_mono)
hoelzl@42147
   465
              from fold(4)[OF J', OF Z_sets x]
hoelzl@47694
   466
              show "?M J' (Z n) x \<in> ?G" "?M J' (Z m) x \<in> ?G" by auto
hoelzl@42147
   467
              show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
hoelzl@42147
   468
                using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
hoelzl@42147
   469
            qed
hoelzl@42147
   470
            finally show "?a / 2^(k+1) \<le> ?q m x" .
hoelzl@42147
   471
          qed
hoelzl@47694
   472
        qed simp
hoelzl@42147
   473
        finally have "(\<Inter>n. ?Q n) \<noteq> {}"
hoelzl@42147
   474
          using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
hoelzl@42147
   475
        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
   476
      note Ex_w = this
hoelzl@42147
   477
wenzelm@46731
   478
      let ?q = "\<lambda>k n y. \<mu>G (?M (J k) (A n) y)"
hoelzl@42147
   479
hoelzl@44928
   480
      have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_lower)
hoelzl@42147
   481
      from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
hoelzl@42147
   482
wenzelm@46731
   483
      let ?P =
wenzelm@46731
   484
        "\<lambda>k wk w. w \<in> space (Pi\<^isub>M (J (Suc k)) M) \<and> restrict w (J k) = wk \<and>
wenzelm@46731
   485
          (\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n w)"
hoelzl@42147
   486
      def w \<equiv> "nat_rec w0 (\<lambda>k wk. Eps (?P k wk))"
hoelzl@42147
   487
hoelzl@42147
   488
      { fix k have w: "w k \<in> space (Pi\<^isub>M (J k) M) \<and>
hoelzl@42147
   489
          (\<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
   490
        proof (induct k)
hoelzl@42147
   491
          case 0 with w0 show ?case
hoelzl@42147
   492
            unfolding w_def nat_rec_0 by auto
hoelzl@42147
   493
        next
hoelzl@42147
   494
          case (Suc k)
hoelzl@42147
   495
          then have wk: "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
hoelzl@42147
   496
          have "\<exists>w'. ?P k (w k) w'"
hoelzl@42147
   497
          proof cases
hoelzl@42147
   498
            assume [simp]: "J k = J (Suc k)"
hoelzl@42147
   499
            show ?thesis
hoelzl@42147
   500
            proof (intro exI[of _ "w k"] conjI allI)
hoelzl@42147
   501
              fix n
hoelzl@42147
   502
              have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
hoelzl@42147
   503
                using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
hoelzl@42147
   504
              also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
hoelzl@42147
   505
              finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
hoelzl@42147
   506
            next
hoelzl@42147
   507
              show "w k \<in> space (Pi\<^isub>M (J (Suc k)) M)"
hoelzl@42147
   508
                using Suc by simp
hoelzl@42147
   509
              then show "restrict (w k) (J k) = w k"
hoelzl@47694
   510
                by (simp add: extensional_restrict space_PiM)
hoelzl@42147
   511
            qed
hoelzl@42147
   512
          next
hoelzl@42147
   513
            assume "J k \<noteq> J (Suc k)"
hoelzl@42147
   514
            with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
hoelzl@47694
   515
            have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> ?G"
hoelzl@42147
   516
              "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
hoelzl@42147
   517
              "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
hoelzl@42147
   518
              using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
hoelzl@42147
   519
              by (auto simp: decseq_def)
hoelzl@42147
   520
            from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
hoelzl@42147
   521
            obtain w' where w': "w' \<in> space (Pi\<^isub>M ?D M)"
hoelzl@42147
   522
              "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
hoelzl@49780
   523
            let ?w = "merge (J k) ?D (w k, w')"
hoelzl@49780
   524
            have [simp]: "\<And>x. merge (J k) (I - J k) (w k, merge ?D (I - ?D) (w', x)) =
hoelzl@49780
   525
              merge (J (Suc k)) (I - (J (Suc k))) (?w, x)"
hoelzl@42147
   526
              using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
hoelzl@42147
   527
              by (auto intro!: ext split: split_merge)
hoelzl@42147
   528
            have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
hoelzl@42147
   529
              using w'(1) J(3)[of "Suc k"]
hoelzl@47694
   530
              by (auto simp: space_PiM split: split_merge intro!: extensional_merge_sub) force+
hoelzl@42147
   531
            show ?thesis
hoelzl@42147
   532
              apply (rule exI[of _ ?w])
hoelzl@42147
   533
              using w' J_mono[of k "Suc k"] wk unfolding *
hoelzl@47694
   534
              apply (auto split: split_merge intro!: extensional_merge_sub ext simp: space_PiM)
hoelzl@42147
   535
              apply (force simp: extensional_def)
hoelzl@42147
   536
              done
hoelzl@42147
   537
          qed
hoelzl@42147
   538
          then have "?P k (w k) (w (Suc k))"
hoelzl@42147
   539
            unfolding w_def nat_rec_Suc unfolding w_def[symmetric]
hoelzl@42147
   540
            by (rule someI_ex)
hoelzl@42147
   541
          then show ?case by auto
hoelzl@42147
   542
        qed
hoelzl@42147
   543
        moreover
hoelzl@42147
   544
        then have "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
hoelzl@42147
   545
        moreover
hoelzl@42147
   546
        from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
hoelzl@42147
   547
        then have "?M (J k) (A k) (w k) \<noteq> {}"
hoelzl@45777
   548
          using positive_\<mu>G[OF I_not_empty, unfolded positive_def] `0 < ?a` `?a \<le> 1`
hoelzl@42147
   549
          by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
hoelzl@42147
   550
        then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
hoelzl@49780
   551
        then have "merge (J k) (I - J k) (w k, x) \<in> A k" by auto
hoelzl@42147
   552
        then have "\<exists>x\<in>A k. restrict x (J k) = w k"
hoelzl@42147
   553
          using `w k \<in> space (Pi\<^isub>M (J k) M)`
hoelzl@47694
   554
          by (intro rev_bexI) (auto intro!: ext simp: extensional_def space_PiM)
hoelzl@42147
   555
        ultimately have "w k \<in> space (Pi\<^isub>M (J k) M)"
hoelzl@42147
   556
          "\<exists>x\<in>A k. restrict x (J k) = w k"
hoelzl@42147
   557
          "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
hoelzl@42147
   558
          by auto }
hoelzl@42147
   559
      note w = this
hoelzl@42147
   560
hoelzl@42147
   561
      { fix k l i assume "k \<le> l" "i \<in> J k"
hoelzl@42147
   562
        { fix l have "w k i = w (k + l) i"
hoelzl@42147
   563
          proof (induct l)
hoelzl@42147
   564
            case (Suc l)
hoelzl@42147
   565
            from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
hoelzl@42147
   566
            with w(3)[of "k + Suc l"]
hoelzl@42147
   567
            have "w (k + l) i = w (k + Suc l) i"
hoelzl@42147
   568
              by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
hoelzl@42147
   569
            with Suc show ?case by simp
hoelzl@42147
   570
          qed simp }
hoelzl@42147
   571
        from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
hoelzl@42147
   572
      note w_mono = this
hoelzl@42147
   573
hoelzl@42147
   574
      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
   575
      { fix i k assume k: "i \<in> J k"
hoelzl@42147
   576
        have "w k i = w (LEAST k. i \<in> J k) i"
hoelzl@42147
   577
          by (intro w_mono Least_le k LeastI[of _ k])
hoelzl@42147
   578
        then have "w' i = w k i"
hoelzl@42147
   579
          unfolding w'_def using k by auto }
hoelzl@42147
   580
      note w'_eq = this
hoelzl@42147
   581
      have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
hoelzl@42147
   582
        using J by (auto simp: w'_def)
hoelzl@42147
   583
      have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
hoelzl@42147
   584
        using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
hoelzl@42147
   585
      { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
hoelzl@47694
   586
          using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq space_PiM)+ }
hoelzl@42147
   587
      note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
hoelzl@42147
   588
hoelzl@42147
   589
      have w': "w' \<in> space (Pi\<^isub>M I M)"
hoelzl@47694
   590
        using w(1) by (auto simp add: Pi_iff extensional_def space_PiM)
hoelzl@42147
   591
hoelzl@42147
   592
      { fix n
hoelzl@42147
   593
        have "restrict w' (J n) = w n" using w(1)
hoelzl@47694
   594
          by (auto simp add: fun_eq_iff restrict_def Pi_iff extensional_def space_PiM)
hoelzl@42147
   595
        with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
hoelzl@47694
   596
        then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: prod_emb_def space_PiM) }
hoelzl@42147
   597
      then have "w' \<in> (\<Inter>i. A i)" by auto
hoelzl@42147
   598
      with `(\<Inter>i. A i) = {}` show False by auto
hoelzl@42147
   599
    qed
hoelzl@42147
   600
    ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
hoelzl@43920
   601
      using LIMSEQ_ereal_INFI[of "\<lambda>i. \<mu>G (A i)"] by simp
hoelzl@45777
   602
  qed fact+
hoelzl@45777
   603
  then guess \<mu> .. note \<mu> = this
hoelzl@45777
   604
  show ?thesis
hoelzl@47694
   605
  proof (subst emeasure_extend_measure_Pair[OF PiM_def, of I M \<mu> J X])
hoelzl@47694
   606
    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
   607
      by (simp add: Pi_iff)
hoelzl@47694
   608
  next
hoelzl@47694
   609
    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
   610
    then show "emb I J (Pi\<^isub>E J X) \<in> Pow (\<Pi>\<^isub>E i\<in>I. space (M i))"
hoelzl@47694
   611
      by (auto simp: Pi_iff prod_emb_def dest: sets_into_space)
hoelzl@47694
   612
    have "emb I J (Pi\<^isub>E J X) \<in> generator"
hoelzl@47694
   613
      using J `I \<noteq> {}` by (intro generatorI') auto
hoelzl@47694
   614
    then have "\<mu> (emb I J (Pi\<^isub>E J X)) = \<mu>G (emb I J (Pi\<^isub>E J X))"
hoelzl@47694
   615
      using \<mu> by simp
hoelzl@47694
   616
    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
   617
      using J  `I \<noteq> {}` by (subst \<mu>G_spec[OF _ _ _ refl]) (auto simp: emeasure_PiM Pi_iff)
hoelzl@47694
   618
    also have "\<dots> = (\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}.
hoelzl@47694
   619
      if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
hoelzl@47694
   620
      using J `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
hoelzl@47694
   621
    finally show "\<mu> (emb I J (Pi\<^isub>E J X)) = \<dots>" .
hoelzl@47694
   622
  next
hoelzl@47694
   623
    let ?F = "\<lambda>j. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j))"
hoelzl@47694
   624
    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
   625
      using X `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
hoelzl@47694
   626
    then show "(\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}. ?F j) =
hoelzl@47694
   627
      emeasure (Pi\<^isub>M J M) (Pi\<^isub>E J X)"
hoelzl@47694
   628
      using X by (auto simp add: emeasure_PiM) 
hoelzl@47694
   629
  next
hoelzl@47694
   630
    show "positive (sets (Pi\<^isub>M I M)) \<mu>" "countably_additive (sets (Pi\<^isub>M I M)) \<mu>"
hoelzl@47694
   631
      using \<mu> unfolding sets_PiM_generator[OF `I \<noteq> {}`] by (auto simp: measure_space_def)
hoelzl@42147
   632
  qed
hoelzl@42147
   633
qed
hoelzl@42147
   634
hoelzl@47694
   635
sublocale product_prob_space \<subseteq> P: prob_space "Pi\<^isub>M I M"
hoelzl@42257
   636
proof
hoelzl@47694
   637
  show "emeasure (Pi\<^isub>M I M) (space (Pi\<^isub>M I M)) = 1"
hoelzl@47694
   638
  proof cases
hoelzl@47694
   639
    assume "I = {}" then show ?thesis by (simp add: space_PiM_empty)
hoelzl@47694
   640
  next
hoelzl@47694
   641
    assume "I \<noteq> {}"
hoelzl@47694
   642
    then obtain i where "i \<in> I" by auto
hoelzl@47694
   643
    moreover then have "emb I {i} (\<Pi>\<^isub>E i\<in>{i}. space (M i)) = (space (Pi\<^isub>M I M))"
hoelzl@47694
   644
      by (auto simp: prod_emb_def space_PiM)
hoelzl@47694
   645
    ultimately show ?thesis
hoelzl@47694
   646
      using emeasure_PiM_emb_not_empty[of "{i}" "\<lambda>i. space (M i)"]
hoelzl@47694
   647
      by (simp add: emeasure_PiM emeasure_space_1)
hoelzl@47694
   648
  qed
hoelzl@42257
   649
qed
hoelzl@42257
   650
hoelzl@47694
   651
lemma (in product_prob_space) emeasure_PiM_emb:
hoelzl@47694
   652
  assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@47694
   653
  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
   654
proof cases
hoelzl@47694
   655
  assume "J = {}"
hoelzl@47694
   656
  moreover have "emb I {} {\<lambda>x. undefined} = space (Pi\<^isub>M I M)"
hoelzl@47694
   657
    by (auto simp: space_PiM prod_emb_def)
hoelzl@47694
   658
  ultimately show ?thesis
hoelzl@47694
   659
    by (simp add: space_PiM_empty P.emeasure_space_1)
hoelzl@47694
   660
next
hoelzl@47694
   661
  assume "J \<noteq> {}" with X show ?thesis
hoelzl@47694
   662
    by (subst emeasure_PiM_emb_not_empty) (auto simp: emeasure_PiM)
hoelzl@42257
   663
qed
hoelzl@42257
   664
hoelzl@47694
   665
lemma (in product_prob_space) measure_PiM_emb:
hoelzl@47694
   666
  assumes "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@47694
   667
  shows "measure (PiM I M) (emb I J (Pi\<^isub>E J X)) = (\<Prod> i\<in>J. measure (M i) (X i))"
hoelzl@47694
   668
  using emeasure_PiM_emb[OF assms]
hoelzl@47694
   669
  unfolding emeasure_eq_measure M.emeasure_eq_measure by (simp add: setprod_ereal)
hoelzl@42865
   670
hoelzl@47694
   671
lemma (in finite_product_prob_space) finite_measure_PiM_emb:
hoelzl@47694
   672
  "(\<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
   673
  using measure_PiM_emb[of I A] finite_index prod_emb_PiE_same_index[OF sets_into_space, of I A M]
hoelzl@47694
   674
  by auto
hoelzl@42865
   675
hoelzl@42257
   676
subsection {* Sequence space *}
hoelzl@42257
   677
hoelzl@42257
   678
locale sequence_space = product_prob_space M "UNIV :: nat set" for M
hoelzl@42257
   679
hoelzl@42257
   680
lemma (in sequence_space) infprod_in_sets[intro]:
hoelzl@42257
   681
  fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
hoelzl@47694
   682
  shows "Pi UNIV E \<in> sets (Pi\<^isub>M UNIV M)"
hoelzl@42257
   683
proof -
hoelzl@42257
   684
  have "Pi UNIV E = (\<Inter>i. emb UNIV {..i} (\<Pi>\<^isub>E j\<in>{..i}. E j))"
hoelzl@47694
   685
    using E E[THEN sets_into_space]
hoelzl@47694
   686
    by (auto simp: prod_emb_def Pi_iff extensional_def) blast
hoelzl@47694
   687
  with E show ?thesis by auto
hoelzl@42257
   688
qed
hoelzl@42257
   689
hoelzl@47694
   690
lemma (in sequence_space) measure_PiM_countable:
hoelzl@42257
   691
  fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets (M i)"
hoelzl@47694
   692
  shows "(\<lambda>n. \<Prod>i\<le>n. measure (M i) (E i)) ----> measure (Pi\<^isub>M UNIV M) (Pi UNIV E)"
hoelzl@42257
   693
proof -
wenzelm@46731
   694
  let ?E = "\<lambda>n. emb UNIV {..n} (Pi\<^isub>E {.. n} E)"
hoelzl@47694
   695
  have "\<And>n. (\<Prod>i\<le>n. measure (M i) (E i)) = measure (Pi\<^isub>M UNIV M) (?E n)"
hoelzl@47694
   696
    using E by (simp add: measure_PiM_emb)
hoelzl@42257
   697
  moreover have "Pi UNIV E = (\<Inter>n. ?E n)"
hoelzl@47694
   698
    using E E[THEN sets_into_space]
hoelzl@47694
   699
    by (auto simp: prod_emb_def extensional_def Pi_iff) blast
hoelzl@47694
   700
  moreover have "range ?E \<subseteq> sets (Pi\<^isub>M UNIV M)"
hoelzl@42257
   701
    using E by auto
hoelzl@42257
   702
  moreover have "decseq ?E"
hoelzl@47694
   703
    by (auto simp: prod_emb_def Pi_iff decseq_def)
hoelzl@42257
   704
  ultimately show ?thesis
hoelzl@47694
   705
    by (simp add: finite_Lim_measure_decseq)
hoelzl@42257
   706
qed
hoelzl@42257
   707
hoelzl@42147
   708
end