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