src/HOL/Probability/Infinite_Product_Measure.thy
author hoelzl
Tue Mar 05 15:43:22 2013 +0100 (2013-03-05)
changeset 51351 dd1dd470690b
parent 50252 4aa34bd43228
child 53015 a1119cf551e8
permissions -rw-r--r--
generalized lemmas in Extended_Real_Limits
hoelzl@42147
     1
(*  Title:      HOL/Probability/Infinite_Product_Measure.thy
hoelzl@42147
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42147
     3
*)
hoelzl@42147
     4
hoelzl@42147
     5
header {*Infinite Product Measure*}
hoelzl@42147
     6
hoelzl@42147
     7
theory Infinite_Product_Measure
immler@50039
     8
  imports Probability_Measure Caratheodory Projective_Family
hoelzl@42147
     9
begin
hoelzl@42147
    10
hoelzl@47694
    11
lemma (in product_prob_space) emeasure_PiM_emb_not_empty:
hoelzl@47694
    12
  assumes X: "J \<noteq> {}" "J \<subseteq> I" "finite J" "\<forall>i\<in>J. X i \<in> sets (M i)"
hoelzl@47694
    13
  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
    14
proof cases
hoelzl@47694
    15
  assume "finite I" with X show ?thesis by simp
hoelzl@42147
    16
next
hoelzl@47694
    17
  let ?\<Omega> = "\<Pi>\<^isub>E i\<in>I. space (M i)"
hoelzl@42147
    18
  let ?G = generator
hoelzl@42147
    19
  assume "\<not> finite I"
hoelzl@45777
    20
  then have I_not_empty: "I \<noteq> {}" by auto
hoelzl@47694
    21
  interpret G!: algebra ?\<Omega> generator by (rule algebra_generator) fact
wenzelm@50252
    22
  note mu_G_mono =
wenzelm@50252
    23
    G.additive_increasing[OF positive_mu_G[OF I_not_empty] additive_mu_G[OF I_not_empty],
wenzelm@50252
    24
      THEN increasingD]
wenzelm@50252
    25
  write mu_G  ("\<mu>G")
hoelzl@42147
    26
hoelzl@47694
    27
  { fix Z J assume J: "J \<noteq> {}" "finite J" "J \<subseteq> I" and Z: "Z \<in> ?G"
hoelzl@42147
    28
hoelzl@42147
    29
    from `infinite I` `finite J` obtain k where k: "k \<in> I" "k \<notin> J"
hoelzl@42147
    30
      by (metis rev_finite_subset subsetI)
hoelzl@42147
    31
    moreover from Z guess K' X' by (rule generatorE)
hoelzl@42147
    32
    moreover def K \<equiv> "insert k K'"
hoelzl@42147
    33
    moreover def X \<equiv> "emb K K' X'"
hoelzl@42147
    34
    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
    35
      "K - J \<noteq> {}" "K - J \<subseteq> I" "\<mu>G Z = emeasure (Pi\<^isub>M K M) X"
hoelzl@42147
    36
      by (auto simp: subset_insertI)
hoelzl@49780
    37
    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
    38
    { fix y assume y: "y \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
    39
      note * = merge_emb[OF `K \<subseteq> I` `J \<subseteq> I` y, of X]
hoelzl@42147
    40
      moreover
hoelzl@42147
    41
      have **: "?M y \<in> sets (Pi\<^isub>M (K - J) M)"
hoelzl@42147
    42
        using J K y by (intro merge_sets) auto
hoelzl@42147
    43
      ultimately
hoelzl@49780
    44
      have ***: "((\<lambda>x. merge J (I - J) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)) \<in> ?G"
hoelzl@42147
    45
        using J K by (intro generatorI) auto
hoelzl@49780
    46
      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)"
wenzelm@50252
    47
        unfolding * using K J by (subst mu_G_eq[OF _ _ _ **]) auto
hoelzl@42147
    48
      note * ** *** this }
hoelzl@42147
    49
    note merge_in_G = this
hoelzl@42147
    50
hoelzl@42147
    51
    have "finite (K - J)" using K by auto
hoelzl@42147
    52
hoelzl@42147
    53
    interpret J: finite_product_prob_space M J by default fact+
hoelzl@42147
    54
    interpret KmJ: finite_product_prob_space M "K - J" by default fact+
hoelzl@42147
    55
hoelzl@47694
    56
    have "\<mu>G Z = emeasure (Pi\<^isub>M (J \<union> (K - J)) M) (emb (J \<union> (K - J)) K X)"
hoelzl@42147
    57
      using K J by simp
hoelzl@47694
    58
    also have "\<dots> = (\<integral>\<^isup>+ x. emeasure (Pi\<^isub>M (K - J) M) (?M x) \<partial>Pi\<^isub>M J M)"
hoelzl@47694
    59
      using K J by (subst emeasure_fold_integral) auto
hoelzl@49780
    60
    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
    61
      (is "_ = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)")
hoelzl@47694
    62
    proof (intro positive_integral_cong)
hoelzl@42147
    63
      fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
    64
      with K merge_in_G(2)[OF this]
hoelzl@47694
    65
      show "emeasure (Pi\<^isub>M (K - J) M) (?M x) = \<mu>G (?MZ x)"
wenzelm@50252
    66
        unfolding `Z = emb I K X` merge_in_G(1)[OF x] by (subst mu_G_eq) auto
hoelzl@42147
    67
    qed
hoelzl@42147
    68
    finally have fold: "\<mu>G Z = (\<integral>\<^isup>+x. \<mu>G (?MZ x) \<partial>Pi\<^isub>M J M)" .
hoelzl@42147
    69
hoelzl@42147
    70
    { fix x assume x: "x \<in> space (Pi\<^isub>M J M)"
hoelzl@42147
    71
      then have "\<mu>G (?MZ x) \<le> 1"
hoelzl@42147
    72
        unfolding merge_in_G(4)[OF x] `Z = emb I K X`
hoelzl@42147
    73
        by (intro KmJ.measure_le_1 merge_in_G(2)[OF x]) }
hoelzl@42147
    74
    note le_1 = this
hoelzl@42147
    75
hoelzl@49780
    76
    let ?q = "\<lambda>y. \<mu>G ((\<lambda>x. merge J (I - J) (y,x)) -` Z \<inter> space (Pi\<^isub>M I M))"
hoelzl@42147
    77
    have "?q \<in> borel_measurable (Pi\<^isub>M J M)"
hoelzl@42147
    78
      unfolding `Z = emb I K X` using J K merge_in_G(3)
wenzelm@50252
    79
      by (simp add: merge_in_G  mu_G_eq emeasure_fold_measurable cong: measurable_cong)
hoelzl@42147
    80
    note this fold le_1 merge_in_G(3) }
hoelzl@42147
    81
  note fold = this
hoelzl@42147
    82
hoelzl@47694
    83
  have "\<exists>\<mu>. (\<forall>s\<in>?G. \<mu> s = \<mu>G s) \<and> measure_space ?\<Omega> (sigma_sets ?\<Omega> ?G) \<mu>"
wenzelm@50252
    84
  proof (rule G.caratheodory_empty_continuous[OF positive_mu_G additive_mu_G])
hoelzl@47694
    85
    fix A assume "A \<in> ?G"
hoelzl@42147
    86
    with generatorE guess J X . note JX = this
hoelzl@50000
    87
    interpret JK: finite_product_prob_space M J by default fact+ 
wenzelm@46898
    88
    from JX show "\<mu>G A \<noteq> \<infinity>" by simp
hoelzl@42147
    89
  next
hoelzl@47694
    90
    fix A assume A: "range A \<subseteq> ?G" "decseq A" "(\<Inter>i. A i) = {}"
hoelzl@42147
    91
    then have "decseq (\<lambda>i. \<mu>G (A i))"
wenzelm@50252
    92
      by (auto intro!: mu_G_mono simp: decseq_def)
hoelzl@42147
    93
    moreover
hoelzl@42147
    94
    have "(INF i. \<mu>G (A i)) = 0"
hoelzl@42147
    95
    proof (rule ccontr)
hoelzl@42147
    96
      assume "(INF i. \<mu>G (A i)) \<noteq> 0" (is "?a \<noteq> 0")
hoelzl@42147
    97
      moreover have "0 \<le> ?a"
wenzelm@50252
    98
        using A positive_mu_G[OF I_not_empty] by (auto intro!: INF_greatest simp: positive_def)
hoelzl@42147
    99
      ultimately have "0 < ?a" by auto
hoelzl@42147
   100
immler@50095
   101
      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 (limP J M (\<lambda>J. (Pi\<^isub>M J M))) X"
hoelzl@42147
   102
        using A by (intro allI generator_Ex) auto
hoelzl@42147
   103
      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
   104
        and A': "\<And>n. A n = emb I (J' n) (X' n)"
hoelzl@42147
   105
        unfolding choice_iff by blast
hoelzl@42147
   106
      moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
hoelzl@42147
   107
      moreover def X \<equiv> "\<lambda>n. emb (J n) (J' n) (X' n)"
hoelzl@42147
   108
      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
   109
        by auto
hoelzl@47694
   110
      with A' have A_eq: "\<And>n. A n = emb I (J n) (X n)" "\<And>n. A n \<in> ?G"
hoelzl@47694
   111
        unfolding J_def X_def by (subst prod_emb_trans) (insert A, auto)
hoelzl@42147
   112
hoelzl@42147
   113
      have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
hoelzl@42147
   114
        unfolding J_def by force
hoelzl@42147
   115
hoelzl@42147
   116
      interpret J: finite_product_prob_space M "J i" for i by default fact+
hoelzl@42147
   117
hoelzl@42147
   118
      have a_le_1: "?a \<le> 1"
wenzelm@50252
   119
        using mu_G_spec[of "J 0" "A 0" "X 0"] J A_eq
hoelzl@44928
   120
        by (auto intro!: INF_lower2[of 0] J.measure_le_1)
hoelzl@42147
   121
hoelzl@49780
   122
      let ?M = "\<lambda>K Z y. (\<lambda>x. merge K (I - K) (y, x)) -` Z \<inter> space (Pi\<^isub>M I M)"
hoelzl@42147
   123
hoelzl@47694
   124
      { fix Z k assume Z: "range Z \<subseteq> ?G" "decseq Z" "\<forall>n. ?a / 2^k \<le> \<mu>G (Z n)"
hoelzl@47694
   125
        then have Z_sets: "\<And>n. Z n \<in> ?G" by auto
hoelzl@42147
   126
        fix J' assume J': "J' \<noteq> {}" "finite J'" "J' \<subseteq> I"
hoelzl@42147
   127
        interpret J': finite_product_prob_space M J' by default fact+
hoelzl@42147
   128
wenzelm@46731
   129
        let ?q = "\<lambda>n y. \<mu>G (?M J' (Z n) y)"
wenzelm@46731
   130
        let ?Q = "\<lambda>n. ?q n -` {?a / 2^(k+1) ..} \<inter> space (Pi\<^isub>M J' M)"
hoelzl@42147
   131
        { fix n
hoelzl@42147
   132
          have "?q n \<in> borel_measurable (Pi\<^isub>M J' M)"
hoelzl@42147
   133
            using Z J' by (intro fold(1)) auto
hoelzl@42147
   134
          then have "?Q n \<in> sets (Pi\<^isub>M J' M)"
hoelzl@42147
   135
            by (rule measurable_sets) auto }
hoelzl@42147
   136
        note Q_sets = this
hoelzl@42147
   137
hoelzl@47694
   138
        have "?a / 2^(k+1) \<le> (INF n. emeasure (Pi\<^isub>M J' M) (?Q n))"
hoelzl@44928
   139
        proof (intro INF_greatest)
hoelzl@42147
   140
          fix n
hoelzl@42147
   141
          have "?a / 2^k \<le> \<mu>G (Z n)" using Z by auto
hoelzl@42147
   142
          also have "\<dots> \<le> (\<integral>\<^isup>+ x. indicator (?Q n) x + ?a / 2^(k+1) \<partial>Pi\<^isub>M J' M)"
hoelzl@47694
   143
            unfolding fold(2)[OF J' `Z n \<in> ?G`]
hoelzl@47694
   144
          proof (intro positive_integral_mono)
hoelzl@42147
   145
            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
hoelzl@42147
   146
            then have "?q n x \<le> 1 + 0"
hoelzl@42147
   147
              using J' Z fold(3) Z_sets by auto
hoelzl@42147
   148
            also have "\<dots> \<le> 1 + ?a / 2^(k+1)"
hoelzl@42147
   149
              using `0 < ?a` by (intro add_mono) auto
hoelzl@42147
   150
            finally have "?q n x \<le> 1 + ?a / 2^(k+1)" .
hoelzl@42147
   151
            with x show "?q n x \<le> indicator (?Q n) x + ?a / 2^(k+1)"
hoelzl@42147
   152
              by (auto split: split_indicator simp del: power_Suc)
hoelzl@42147
   153
          qed
hoelzl@47694
   154
          also have "\<dots> = emeasure (Pi\<^isub>M J' M) (?Q n) + ?a / 2^(k+1)"
hoelzl@47694
   155
            using `0 \<le> ?a` Q_sets J'.emeasure_space_1
hoelzl@47694
   156
            by (subst positive_integral_add) auto
hoelzl@47694
   157
          finally show "?a / 2^(k+1) \<le> emeasure (Pi\<^isub>M J' M) (?Q n)" using `?a \<le> 1`
hoelzl@47694
   158
            by (cases rule: ereal2_cases[of ?a "emeasure (Pi\<^isub>M J' M) (?Q n)"])
hoelzl@42147
   159
               (auto simp: field_simps)
hoelzl@42147
   160
        qed
hoelzl@47694
   161
        also have "\<dots> = emeasure (Pi\<^isub>M J' M) (\<Inter>n. ?Q n)"
hoelzl@47694
   162
        proof (intro INF_emeasure_decseq)
hoelzl@42147
   163
          show "range ?Q \<subseteq> sets (Pi\<^isub>M J' M)" using Q_sets by auto
hoelzl@42147
   164
          show "decseq ?Q"
hoelzl@42147
   165
            unfolding decseq_def
hoelzl@42147
   166
          proof (safe intro!: vimageI[OF refl])
hoelzl@42147
   167
            fix m n :: nat assume "m \<le> n"
hoelzl@42147
   168
            fix x assume x: "x \<in> space (Pi\<^isub>M J' M)"
hoelzl@42147
   169
            assume "?a / 2^(k+1) \<le> ?q n x"
hoelzl@42147
   170
            also have "?q n x \<le> ?q m x"
wenzelm@50252
   171
            proof (rule mu_G_mono)
hoelzl@42147
   172
              from fold(4)[OF J', OF Z_sets x]
hoelzl@47694
   173
              show "?M J' (Z n) x \<in> ?G" "?M J' (Z m) x \<in> ?G" by auto
hoelzl@42147
   174
              show "?M J' (Z n) x \<subseteq> ?M J' (Z m) x"
hoelzl@42147
   175
                using `decseq Z`[THEN decseqD, OF `m \<le> n`] by auto
hoelzl@42147
   176
            qed
hoelzl@42147
   177
            finally show "?a / 2^(k+1) \<le> ?q m x" .
hoelzl@42147
   178
          qed
hoelzl@47694
   179
        qed simp
hoelzl@42147
   180
        finally have "(\<Inter>n. ?Q n) \<noteq> {}"
hoelzl@42147
   181
          using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
hoelzl@42147
   182
        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
   183
      note Ex_w = this
hoelzl@42147
   184
wenzelm@46731
   185
      let ?q = "\<lambda>k n y. \<mu>G (?M (J k) (A n) y)"
hoelzl@42147
   186
hoelzl@44928
   187
      have "\<forall>n. ?a / 2 ^ 0 \<le> \<mu>G (A n)" by (auto intro: INF_lower)
hoelzl@42147
   188
      from Ex_w[OF A(1,2) this J(1-3), of 0] guess w0 .. note w0 = this
hoelzl@42147
   189
wenzelm@46731
   190
      let ?P =
wenzelm@46731
   191
        "\<lambda>k wk w. w \<in> space (Pi\<^isub>M (J (Suc k)) M) \<and> restrict w (J k) = wk \<and>
wenzelm@46731
   192
          (\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n w)"
hoelzl@42147
   193
      def w \<equiv> "nat_rec w0 (\<lambda>k wk. Eps (?P k wk))"
hoelzl@42147
   194
hoelzl@42147
   195
      { fix k have w: "w k \<in> space (Pi\<^isub>M (J k) M) \<and>
hoelzl@42147
   196
          (\<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
   197
        proof (induct k)
hoelzl@42147
   198
          case 0 with w0 show ?case
hoelzl@42147
   199
            unfolding w_def nat_rec_0 by auto
hoelzl@42147
   200
        next
hoelzl@42147
   201
          case (Suc k)
hoelzl@42147
   202
          then have wk: "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
hoelzl@42147
   203
          have "\<exists>w'. ?P k (w k) w'"
hoelzl@42147
   204
          proof cases
hoelzl@42147
   205
            assume [simp]: "J k = J (Suc k)"
hoelzl@42147
   206
            show ?thesis
hoelzl@42147
   207
            proof (intro exI[of _ "w k"] conjI allI)
hoelzl@42147
   208
              fix n
hoelzl@42147
   209
              have "?a / 2 ^ (Suc k + 1) \<le> ?a / 2 ^ (k + 1)"
hoelzl@42147
   210
                using `0 < ?a` `?a \<le> 1` by (cases ?a) (auto simp: field_simps)
hoelzl@42147
   211
              also have "\<dots> \<le> ?q k n (w k)" using Suc by auto
hoelzl@42147
   212
              finally show "?a / 2 ^ (Suc k + 1) \<le> ?q (Suc k) n (w k)" by simp
hoelzl@42147
   213
            next
hoelzl@42147
   214
              show "w k \<in> space (Pi\<^isub>M (J (Suc k)) M)"
hoelzl@42147
   215
                using Suc by simp
hoelzl@42147
   216
              then show "restrict (w k) (J k) = w k"
hoelzl@47694
   217
                by (simp add: extensional_restrict space_PiM)
hoelzl@42147
   218
            qed
hoelzl@42147
   219
          next
hoelzl@42147
   220
            assume "J k \<noteq> J (Suc k)"
hoelzl@42147
   221
            with J_mono[of k "Suc k"] have "J (Suc k) - J k \<noteq> {}" (is "?D \<noteq> {}") by auto
hoelzl@47694
   222
            have "range (\<lambda>n. ?M (J k) (A n) (w k)) \<subseteq> ?G"
hoelzl@42147
   223
              "decseq (\<lambda>n. ?M (J k) (A n) (w k))"
hoelzl@42147
   224
              "\<forall>n. ?a / 2 ^ (k + 1) \<le> \<mu>G (?M (J k) (A n) (w k))"
hoelzl@42147
   225
              using `decseq A` fold(4)[OF J(1-3) A_eq(2), of "w k" k] Suc
hoelzl@42147
   226
              by (auto simp: decseq_def)
hoelzl@42147
   227
            from Ex_w[OF this `?D \<noteq> {}`] J[of "Suc k"]
hoelzl@42147
   228
            obtain w' where w': "w' \<in> space (Pi\<^isub>M ?D M)"
hoelzl@42147
   229
              "\<forall>n. ?a / 2 ^ (Suc k + 1) \<le> \<mu>G (?M ?D (?M (J k) (A n) (w k)) w')" by auto
hoelzl@49780
   230
            let ?w = "merge (J k) ?D (w k, w')"
hoelzl@49780
   231
            have [simp]: "\<And>x. merge (J k) (I - J k) (w k, merge ?D (I - ?D) (w', x)) =
hoelzl@49780
   232
              merge (J (Suc k)) (I - (J (Suc k))) (?w, x)"
hoelzl@42147
   233
              using J(3)[of "Suc k"] J(3)[of k] J_mono[of k "Suc k"]
hoelzl@42147
   234
              by (auto intro!: ext split: split_merge)
hoelzl@42147
   235
            have *: "\<And>n. ?M ?D (?M (J k) (A n) (w k)) w' = ?M (J (Suc k)) (A n) ?w"
hoelzl@42147
   236
              using w'(1) J(3)[of "Suc k"]
hoelzl@47694
   237
              by (auto simp: space_PiM split: split_merge intro!: extensional_merge_sub) force+
hoelzl@42147
   238
            show ?thesis
hoelzl@42147
   239
              using w' J_mono[of k "Suc k"] wk unfolding *
hoelzl@50123
   240
              by (intro exI[of _ ?w])
hoelzl@50123
   241
                 (auto split: split_merge intro!: extensional_merge_sub ext simp: space_PiM PiE_iff)
hoelzl@42147
   242
          qed
hoelzl@42147
   243
          then have "?P k (w k) (w (Suc k))"
hoelzl@42147
   244
            unfolding w_def nat_rec_Suc unfolding w_def[symmetric]
hoelzl@42147
   245
            by (rule someI_ex)
hoelzl@42147
   246
          then show ?case by auto
hoelzl@42147
   247
        qed
hoelzl@42147
   248
        moreover
hoelzl@42147
   249
        then have "w k \<in> space (Pi\<^isub>M (J k) M)" by auto
hoelzl@42147
   250
        moreover
hoelzl@42147
   251
        from w have "?a / 2 ^ (k + 1) \<le> ?q k k (w k)" by auto
hoelzl@42147
   252
        then have "?M (J k) (A k) (w k) \<noteq> {}"
wenzelm@50252
   253
          using positive_mu_G[OF I_not_empty, unfolded positive_def] `0 < ?a` `?a \<le> 1`
hoelzl@42147
   254
          by (cases ?a) (auto simp: divide_le_0_iff power_le_zero_eq)
hoelzl@42147
   255
        then obtain x where "x \<in> ?M (J k) (A k) (w k)" by auto
hoelzl@49780
   256
        then have "merge (J k) (I - J k) (w k, x) \<in> A k" by auto
hoelzl@42147
   257
        then have "\<exists>x\<in>A k. restrict x (J k) = w k"
hoelzl@42147
   258
          using `w k \<in> space (Pi\<^isub>M (J k) M)`
hoelzl@47694
   259
          by (intro rev_bexI) (auto intro!: ext simp: extensional_def space_PiM)
hoelzl@42147
   260
        ultimately have "w k \<in> space (Pi\<^isub>M (J k) M)"
hoelzl@42147
   261
          "\<exists>x\<in>A k. restrict x (J k) = w k"
hoelzl@42147
   262
          "k \<noteq> 0 \<Longrightarrow> restrict (w k) (J (k - 1)) = w (k - 1)"
hoelzl@42147
   263
          by auto }
hoelzl@42147
   264
      note w = this
hoelzl@42147
   265
hoelzl@42147
   266
      { fix k l i assume "k \<le> l" "i \<in> J k"
hoelzl@42147
   267
        { fix l have "w k i = w (k + l) i"
hoelzl@42147
   268
          proof (induct l)
hoelzl@42147
   269
            case (Suc l)
hoelzl@42147
   270
            from `i \<in> J k` J_mono[of k "k + l"] have "i \<in> J (k + l)" by auto
hoelzl@42147
   271
            with w(3)[of "k + Suc l"]
hoelzl@42147
   272
            have "w (k + l) i = w (k + Suc l) i"
hoelzl@42147
   273
              by (auto simp: restrict_def fun_eq_iff split: split_if_asm)
hoelzl@42147
   274
            with Suc show ?case by simp
hoelzl@42147
   275
          qed simp }
hoelzl@42147
   276
        from this[of "l - k"] `k \<le> l` have "w l i = w k i" by simp }
hoelzl@42147
   277
      note w_mono = this
hoelzl@42147
   278
hoelzl@42147
   279
      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
   280
      { fix i k assume k: "i \<in> J k"
hoelzl@42147
   281
        have "w k i = w (LEAST k. i \<in> J k) i"
hoelzl@42147
   282
          by (intro w_mono Least_le k LeastI[of _ k])
hoelzl@42147
   283
        then have "w' i = w k i"
hoelzl@42147
   284
          unfolding w'_def using k by auto }
hoelzl@42147
   285
      note w'_eq = this
hoelzl@42147
   286
      have w'_simps1: "\<And>i. i \<notin> I \<Longrightarrow> w' i = undefined"
hoelzl@42147
   287
        using J by (auto simp: w'_def)
hoelzl@42147
   288
      have w'_simps2: "\<And>i. i \<notin> (\<Union>k. J k) \<Longrightarrow> i \<in> I \<Longrightarrow> w' i \<in> space (M i)"
hoelzl@42147
   289
        using J by (auto simp: w'_def intro!: someI_ex[OF M.not_empty[unfolded ex_in_conv[symmetric]]])
hoelzl@42147
   290
      { fix i assume "i \<in> I" then have "w' i \<in> space (M i)"
hoelzl@47694
   291
          using w(1) by (cases "i \<in> (\<Union>k. J k)") (force simp: w'_simps2 w'_eq space_PiM)+ }
hoelzl@42147
   292
      note w'_simps[simp] = w'_eq w'_simps1 w'_simps2 this
hoelzl@42147
   293
hoelzl@42147
   294
      have w': "w' \<in> space (Pi\<^isub>M I M)"
hoelzl@47694
   295
        using w(1) by (auto simp add: Pi_iff extensional_def space_PiM)
hoelzl@42147
   296
hoelzl@42147
   297
      { fix n
hoelzl@50123
   298
        have "restrict w' (J n) = w n" using w(1)[of n]
hoelzl@50123
   299
          by (auto simp add: fun_eq_iff space_PiM)
hoelzl@42147
   300
        with w[of n] obtain x where "x \<in> A n" "restrict x (J n) = restrict w' (J n)" by auto
hoelzl@47694
   301
        then have "w' \<in> A n" unfolding A_eq using w' by (auto simp: prod_emb_def space_PiM) }
hoelzl@42147
   302
      then have "w' \<in> (\<Inter>i. A i)" by auto
hoelzl@42147
   303
      with `(\<Inter>i. A i) = {}` show False by auto
hoelzl@42147
   304
    qed
hoelzl@42147
   305
    ultimately show "(\<lambda>i. \<mu>G (A i)) ----> 0"
hoelzl@51351
   306
      using LIMSEQ_INF[of "\<lambda>i. \<mu>G (A i)"] by simp
hoelzl@45777
   307
  qed fact+
hoelzl@45777
   308
  then guess \<mu> .. note \<mu> = this
hoelzl@45777
   309
  show ?thesis
hoelzl@47694
   310
  proof (subst emeasure_extend_measure_Pair[OF PiM_def, of I M \<mu> J X])
hoelzl@47694
   311
    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
   312
      by (simp add: Pi_iff)
hoelzl@47694
   313
  next
hoelzl@47694
   314
    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
   315
    then show "emb I J (Pi\<^isub>E J X) \<in> Pow (\<Pi>\<^isub>E i\<in>I. space (M i))"
immler@50244
   316
      by (auto simp: Pi_iff prod_emb_def dest: sets.sets_into_space)
hoelzl@47694
   317
    have "emb I J (Pi\<^isub>E J X) \<in> generator"
hoelzl@50003
   318
      using J `I \<noteq> {}` by (intro generatorI') (auto simp: Pi_iff)
hoelzl@47694
   319
    then have "\<mu> (emb I J (Pi\<^isub>E J X)) = \<mu>G (emb I J (Pi\<^isub>E J X))"
hoelzl@47694
   320
      using \<mu> by simp
hoelzl@47694
   321
    also have "\<dots> = (\<Prod> j\<in>J. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
wenzelm@50252
   322
      using J  `I \<noteq> {}` by (subst mu_G_spec[OF _ _ _ refl]) (auto simp: emeasure_PiM Pi_iff)
hoelzl@47694
   323
    also have "\<dots> = (\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}.
hoelzl@47694
   324
      if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j)))"
hoelzl@47694
   325
      using J `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
hoelzl@47694
   326
    finally show "\<mu> (emb I J (Pi\<^isub>E J X)) = \<dots>" .
hoelzl@47694
   327
  next
hoelzl@47694
   328
    let ?F = "\<lambda>j. if j \<in> J then emeasure (M j) (X j) else emeasure (M j) (space (M j))"
hoelzl@47694
   329
    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
   330
      using X `I \<noteq> {}` by (intro setprod_mono_one_right) (auto simp: M.emeasure_space_1)
hoelzl@47694
   331
    then show "(\<Prod>j\<in>J \<union> {i \<in> I. emeasure (M i) (space (M i)) \<noteq> 1}. ?F j) =
hoelzl@47694
   332
      emeasure (Pi\<^isub>M J M) (Pi\<^isub>E J X)"
hoelzl@47694
   333
      using X by (auto simp add: emeasure_PiM) 
hoelzl@47694
   334
  next
hoelzl@47694
   335
    show "positive (sets (Pi\<^isub>M I M)) \<mu>" "countably_additive (sets (Pi\<^isub>M I M)) \<mu>"
hoelzl@49804
   336
      using \<mu> unfolding sets_PiM_generator by (auto simp: measure_space_def)
hoelzl@42147
   337
  qed
hoelzl@42147
   338
qed
hoelzl@42147
   339
hoelzl@47694
   340
sublocale product_prob_space \<subseteq> P: prob_space "Pi\<^isub>M I M"
hoelzl@42257
   341
proof
hoelzl@47694
   342
  show "emeasure (Pi\<^isub>M I M) (space (Pi\<^isub>M I M)) = 1"
hoelzl@47694
   343
  proof cases
hoelzl@47694
   344
    assume "I = {}" then show ?thesis by (simp add: space_PiM_empty)
hoelzl@47694
   345
  next
hoelzl@47694
   346
    assume "I \<noteq> {}"
hoelzl@47694
   347
    then obtain i where "i \<in> I" by auto
hoelzl@47694
   348
    moreover then have "emb I {i} (\<Pi>\<^isub>E i\<in>{i}. space (M i)) = (space (Pi\<^isub>M I M))"
hoelzl@47694
   349
      by (auto simp: prod_emb_def space_PiM)
hoelzl@47694
   350
    ultimately show ?thesis
hoelzl@47694
   351
      using emeasure_PiM_emb_not_empty[of "{i}" "\<lambda>i. space (M i)"]
hoelzl@47694
   352
      by (simp add: emeasure_PiM emeasure_space_1)
hoelzl@47694
   353
  qed
hoelzl@42257
   354
qed
hoelzl@42257
   355
hoelzl@47694
   356
lemma (in product_prob_space) emeasure_PiM_emb:
hoelzl@47694
   357
  assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@47694
   358
  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
   359
proof cases
hoelzl@47694
   360
  assume "J = {}"
hoelzl@47694
   361
  moreover have "emb I {} {\<lambda>x. undefined} = space (Pi\<^isub>M I M)"
hoelzl@47694
   362
    by (auto simp: space_PiM prod_emb_def)
hoelzl@47694
   363
  ultimately show ?thesis
hoelzl@47694
   364
    by (simp add: space_PiM_empty P.emeasure_space_1)
hoelzl@47694
   365
next
hoelzl@47694
   366
  assume "J \<noteq> {}" with X show ?thesis
hoelzl@47694
   367
    by (subst emeasure_PiM_emb_not_empty) (auto simp: emeasure_PiM)
hoelzl@42257
   368
qed
hoelzl@42257
   369
hoelzl@50000
   370
lemma (in product_prob_space) emeasure_PiM_Collect:
hoelzl@50000
   371
  assumes X: "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@50000
   372
  shows "emeasure (Pi\<^isub>M I M) {x\<in>space (Pi\<^isub>M I M). \<forall>i\<in>J. x i \<in> X i} = (\<Prod> i\<in>J. emeasure (M i) (X i))"
hoelzl@50000
   373
proof -
hoelzl@50000
   374
  have "{x\<in>space (Pi\<^isub>M I M). \<forall>i\<in>J. x i \<in> X i} = emb I J (Pi\<^isub>E J X)"
hoelzl@50000
   375
    unfolding prod_emb_def using assms by (auto simp: space_PiM Pi_iff)
hoelzl@50000
   376
  with emeasure_PiM_emb[OF assms] show ?thesis by simp
hoelzl@50000
   377
qed
hoelzl@50000
   378
hoelzl@50000
   379
lemma (in product_prob_space) emeasure_PiM_Collect_single:
hoelzl@50000
   380
  assumes X: "i \<in> I" "A \<in> sets (M i)"
hoelzl@50000
   381
  shows "emeasure (Pi\<^isub>M I M) {x\<in>space (Pi\<^isub>M I M). x i \<in> A} = emeasure (M i) A"
hoelzl@50000
   382
  using emeasure_PiM_Collect[of "{i}" "\<lambda>i. A"] assms
hoelzl@50000
   383
  by simp
hoelzl@50000
   384
hoelzl@47694
   385
lemma (in product_prob_space) measure_PiM_emb:
hoelzl@47694
   386
  assumes "J \<subseteq> I" "finite J" "\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)"
hoelzl@47694
   387
  shows "measure (PiM I M) (emb I J (Pi\<^isub>E J X)) = (\<Prod> i\<in>J. measure (M i) (X i))"
hoelzl@47694
   388
  using emeasure_PiM_emb[OF assms]
hoelzl@47694
   389
  unfolding emeasure_eq_measure M.emeasure_eq_measure by (simp add: setprod_ereal)
hoelzl@42865
   390
hoelzl@50000
   391
lemma sets_Collect_single':
hoelzl@50000
   392
  "i \<in> I \<Longrightarrow> {x\<in>space (M i). P x} \<in> sets (M i) \<Longrightarrow> {x\<in>space (PiM I M). P (x i)} \<in> sets (PiM I M)"
hoelzl@50000
   393
  using sets_Collect_single[of i I "{x\<in>space (M i). P x}" M]
hoelzl@50123
   394
  by (simp add: space_PiM PiE_iff cong: conj_cong)
hoelzl@50000
   395
hoelzl@47694
   396
lemma (in finite_product_prob_space) finite_measure_PiM_emb:
hoelzl@47694
   397
  "(\<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))"
immler@50244
   398
  using measure_PiM_emb[of I A] finite_index prod_emb_PiE_same_index[OF sets.sets_into_space, of I A M]
hoelzl@47694
   399
  by auto
hoelzl@42865
   400
hoelzl@50000
   401
lemma (in product_prob_space) PiM_component:
hoelzl@50000
   402
  assumes "i \<in> I"
hoelzl@50000
   403
  shows "distr (PiM I M) (M i) (\<lambda>\<omega>. \<omega> i) = M i"
hoelzl@50000
   404
proof (rule measure_eqI[symmetric])
hoelzl@50000
   405
  fix A assume "A \<in> sets (M i)"
hoelzl@50000
   406
  moreover have "((\<lambda>\<omega>. \<omega> i) -` A \<inter> space (PiM I M)) = {x\<in>space (PiM I M). x i \<in> A}"
hoelzl@50000
   407
    by auto
hoelzl@50000
   408
  ultimately show "emeasure (M i) A = emeasure (distr (PiM I M) (M i) (\<lambda>\<omega>. \<omega> i)) A"
hoelzl@50000
   409
    by (auto simp: `i\<in>I` emeasure_distr measurable_component_singleton emeasure_PiM_Collect_single)
hoelzl@50000
   410
qed simp
hoelzl@50000
   411
hoelzl@50000
   412
lemma (in product_prob_space) PiM_eq:
hoelzl@50000
   413
  assumes "I \<noteq> {}"
hoelzl@50000
   414
  assumes "sets M' = sets (PiM I M)"
hoelzl@50000
   415
  assumes eq: "\<And>J F. finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>j. j \<in> J \<Longrightarrow> F j \<in> sets (M j)) \<Longrightarrow>
hoelzl@50000
   416
    emeasure M' (prod_emb I M J (\<Pi>\<^isub>E j\<in>J. F j)) = (\<Prod>j\<in>J. emeasure (M j) (F j))"
hoelzl@50000
   417
  shows "M' = (PiM I M)"
hoelzl@50000
   418
proof (rule measure_eqI_generator_eq[symmetric, OF Int_stable_prod_algebra prod_algebra_sets_into_space])
hoelzl@50000
   419
  show "sets (PiM I M) = sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) (prod_algebra I M)"
hoelzl@50000
   420
    by (rule sets_PiM)
hoelzl@50000
   421
  then show "sets M' = sigma_sets (\<Pi>\<^isub>E i\<in>I. space (M i)) (prod_algebra I M)"
hoelzl@50000
   422
    unfolding `sets M' = sets (PiM I M)` by simp
hoelzl@50000
   423
hoelzl@50000
   424
  def i \<equiv> "SOME i. i \<in> I"
hoelzl@50000
   425
  with `I \<noteq> {}` have i: "i \<in> I"
hoelzl@50000
   426
    by (auto intro: someI_ex)
hoelzl@50000
   427
hoelzl@50000
   428
  def A \<equiv> "\<lambda>n::nat. prod_emb I M {i} (\<Pi>\<^isub>E j\<in>{i}. space (M i))"
hoelzl@50000
   429
  then show "range A \<subseteq> prod_algebra I M"
hoelzl@50000
   430
    by (auto intro!: prod_algebraI i)
hoelzl@50000
   431
hoelzl@50000
   432
  have A_eq: "\<And>i. A i = space (PiM I M)"
hoelzl@50000
   433
    by (auto simp: prod_emb_def space_PiM Pi_iff A_def i)
hoelzl@50000
   434
  show "(\<Union>i. A i) = (\<Pi>\<^isub>E i\<in>I. space (M i))"
hoelzl@50000
   435
    unfolding A_eq by (auto simp: space_PiM)
hoelzl@50000
   436
  show "\<And>i. emeasure (PiM I M) (A i) \<noteq> \<infinity>"
hoelzl@50000
   437
    unfolding A_eq P.emeasure_space_1 by simp
hoelzl@50000
   438
next
hoelzl@50000
   439
  fix X assume X: "X \<in> prod_algebra I M"
hoelzl@50000
   440
  then obtain J E where X: "X = prod_emb I M J (PIE j:J. E j)"
hoelzl@50000
   441
    and J: "finite J" "J \<subseteq> I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets (M j)"
hoelzl@50000
   442
    by (force elim!: prod_algebraE)
hoelzl@50000
   443
  from eq[OF J] have "emeasure M' X = (\<Prod>j\<in>J. emeasure (M j) (E j))"
hoelzl@50000
   444
    by (simp add: X)
hoelzl@50000
   445
  also have "\<dots> = emeasure (PiM I M) X"
hoelzl@50000
   446
    unfolding X using J by (intro emeasure_PiM_emb[symmetric]) auto
hoelzl@50000
   447
  finally show "emeasure (PiM I M) X = emeasure M' X" ..
hoelzl@50000
   448
qed
hoelzl@50000
   449
hoelzl@42257
   450
subsection {* Sequence space *}
hoelzl@42257
   451
hoelzl@50000
   452
definition comb_seq :: "nat \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> (nat \<Rightarrow> 'a)" where
hoelzl@50000
   453
  "comb_seq i \<omega> \<omega>' j = (if j < i then \<omega> j else \<omega>' (j - i))"
hoelzl@50000
   454
hoelzl@50000
   455
lemma split_comb_seq: "P (comb_seq i \<omega> \<omega>' j) \<longleftrightarrow> (j < i \<longrightarrow> P (\<omega> j)) \<and> (\<forall>k. j = i + k \<longrightarrow> P (\<omega>' k))"
hoelzl@50000
   456
  by (auto simp: comb_seq_def not_less)
hoelzl@50000
   457
hoelzl@50000
   458
lemma split_comb_seq_asm: "P (comb_seq i \<omega> \<omega>' j) \<longleftrightarrow> \<not> ((j < i \<and> \<not> P (\<omega> j)) \<or> (\<exists>k. j = i + k \<and> \<not> P (\<omega>' k)))"
hoelzl@50000
   459
  by (auto simp: comb_seq_def)
hoelzl@42257
   460
hoelzl@50099
   461
lemma measurable_comb_seq:
hoelzl@50099
   462
  "(\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') \<in> measurable ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)) (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   463
proof (rule measurable_PiM_single)
hoelzl@50000
   464
  show "(\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') \<in> space ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)) \<rightarrow> (UNIV \<rightarrow>\<^isub>E space M)"
hoelzl@50123
   465
    by (auto simp: space_pair_measure space_PiM PiE_iff split: split_comb_seq)
hoelzl@50000
   466
  fix j :: nat and A assume A: "A \<in> sets M"
hoelzl@50000
   467
  then have *: "{\<omega> \<in> space ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)). prod_case (comb_seq i) \<omega> j \<in> A} =
hoelzl@50000
   468
    (if j < i then {\<omega> \<in> space (\<Pi>\<^isub>M i\<in>UNIV. M). \<omega> j \<in> A} \<times> space (\<Pi>\<^isub>M i\<in>UNIV. M)
hoelzl@50000
   469
              else space (\<Pi>\<^isub>M i\<in>UNIV. M) \<times> {\<omega> \<in> space (\<Pi>\<^isub>M i\<in>UNIV. M). \<omega> (j - i) \<in> A})"
immler@50244
   470
    by (auto simp: space_PiM space_pair_measure comb_seq_def dest: sets.sets_into_space)
hoelzl@50000
   471
  show "{\<omega> \<in> space ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M)). prod_case (comb_seq i) \<omega> j \<in> A} \<in> sets ((\<Pi>\<^isub>M i\<in>UNIV. M) \<Otimes>\<^isub>M (\<Pi>\<^isub>M i\<in>UNIV. M))"
hoelzl@50000
   472
    unfolding * by (auto simp: A intro!: sets_Collect_single)
hoelzl@50000
   473
qed
hoelzl@50000
   474
hoelzl@50099
   475
lemma measurable_comb_seq'[measurable (raw)]:
hoelzl@50000
   476
  assumes f: "f \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)" and g: "g \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   477
  shows "(\<lambda>x. comb_seq i (f x) (g x)) \<in> measurable N (\<Pi>\<^isub>M i\<in>UNIV. M)"
hoelzl@50000
   478
  using measurable_compose[OF measurable_Pair[OF f g] measurable_comb_seq] by simp
hoelzl@50000
   479
hoelzl@50099
   480
lemma comb_seq_0: "comb_seq 0 \<omega> \<omega>' = \<omega>'"
hoelzl@50099
   481
  by (auto simp add: comb_seq_def)
hoelzl@50099
   482
hoelzl@50099
   483
lemma comb_seq_Suc: "comb_seq (Suc n) \<omega> \<omega>' = comb_seq n \<omega> (nat_case (\<omega> n) \<omega>')"
hoelzl@50099
   484
  by (auto simp add: comb_seq_def not_less less_Suc_eq le_imp_diff_is_add intro!: ext split: nat.split)
hoelzl@50099
   485
hoelzl@50099
   486
lemma comb_seq_Suc_0[simp]: "comb_seq (Suc 0) \<omega> = nat_case (\<omega> 0)"
hoelzl@50099
   487
  by (intro ext) (simp add: comb_seq_Suc comb_seq_0)
hoelzl@50099
   488
hoelzl@50099
   489
lemma comb_seq_less: "i < n \<Longrightarrow> comb_seq n \<omega> \<omega>' i = \<omega> i"
hoelzl@50099
   490
  by (auto split: split_comb_seq)
hoelzl@50099
   491
hoelzl@50099
   492
lemma comb_seq_add: "comb_seq n \<omega> \<omega>' (i + n) = \<omega>' i"
hoelzl@50099
   493
  by (auto split: nat.split split_comb_seq)
hoelzl@50099
   494
hoelzl@50099
   495
lemma nat_case_comb_seq: "nat_case s' (comb_seq n \<omega> \<omega>') (i + n) = nat_case (nat_case s' \<omega> n) \<omega>' i"
hoelzl@50099
   496
  by (auto split: nat.split split_comb_seq)
hoelzl@50099
   497
hoelzl@50099
   498
lemma nat_case_comb_seq':
hoelzl@50099
   499
  "nat_case s (comb_seq i \<omega> \<omega>') = comb_seq (Suc i) (nat_case s \<omega>) \<omega>'"
hoelzl@50099
   500
  by (auto split: split_comb_seq nat.split)
hoelzl@50099
   501
hoelzl@50000
   502
locale sequence_space = product_prob_space "\<lambda>i. M" "UNIV :: nat set" for M
hoelzl@50000
   503
begin
hoelzl@50000
   504
hoelzl@50000
   505
abbreviation "S \<equiv> \<Pi>\<^isub>M i\<in>UNIV::nat set. M"
hoelzl@50000
   506
hoelzl@50000
   507
lemma infprod_in_sets[intro]:
hoelzl@50000
   508
  fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets M"
hoelzl@50000
   509
  shows "Pi UNIV E \<in> sets S"
hoelzl@42257
   510
proof -
hoelzl@42257
   511
  have "Pi UNIV E = (\<Inter>i. emb UNIV {..i} (\<Pi>\<^isub>E j\<in>{..i}. E j))"
immler@50244
   512
    using E E[THEN sets.sets_into_space]
hoelzl@47694
   513
    by (auto simp: prod_emb_def Pi_iff extensional_def) blast
hoelzl@47694
   514
  with E show ?thesis by auto
hoelzl@42257
   515
qed
hoelzl@42257
   516
hoelzl@50000
   517
lemma measure_PiM_countable:
hoelzl@50000
   518
  fixes E :: "nat \<Rightarrow> 'a set" assumes E: "\<And>i. E i \<in> sets M"
hoelzl@50000
   519
  shows "(\<lambda>n. \<Prod>i\<le>n. measure M (E i)) ----> measure S (Pi UNIV E)"
hoelzl@42257
   520
proof -
wenzelm@46731
   521
  let ?E = "\<lambda>n. emb UNIV {..n} (Pi\<^isub>E {.. n} E)"
hoelzl@50000
   522
  have "\<And>n. (\<Prod>i\<le>n. measure M (E i)) = measure S (?E n)"
hoelzl@47694
   523
    using E by (simp add: measure_PiM_emb)
hoelzl@42257
   524
  moreover have "Pi UNIV E = (\<Inter>n. ?E n)"
immler@50244
   525
    using E E[THEN sets.sets_into_space]
hoelzl@47694
   526
    by (auto simp: prod_emb_def extensional_def Pi_iff) blast
hoelzl@50000
   527
  moreover have "range ?E \<subseteq> sets S"
hoelzl@42257
   528
    using E by auto
hoelzl@42257
   529
  moreover have "decseq ?E"
hoelzl@47694
   530
    by (auto simp: prod_emb_def Pi_iff decseq_def)
hoelzl@42257
   531
  ultimately show ?thesis
hoelzl@47694
   532
    by (simp add: finite_Lim_measure_decseq)
hoelzl@42257
   533
qed
hoelzl@42257
   534
hoelzl@50000
   535
lemma nat_eq_diff_eq: 
hoelzl@50000
   536
  fixes a b c :: nat
hoelzl@50000
   537
  shows "c \<le> b \<Longrightarrow> a = b - c \<longleftrightarrow> a + c = b"
hoelzl@50000
   538
  by auto
hoelzl@50000
   539
hoelzl@50000
   540
lemma PiM_comb_seq:
hoelzl@50000
   541
  "distr (S \<Otimes>\<^isub>M S) S (\<lambda>(\<omega>, \<omega>'). comb_seq i \<omega> \<omega>') = S" (is "?D = _")
hoelzl@50000
   542
proof (rule PiM_eq)
hoelzl@50000
   543
  let ?I = "UNIV::nat set" and ?M = "\<lambda>n. M"
hoelzl@50000
   544
  let "distr _ _ ?f" = "?D"
hoelzl@50000
   545
hoelzl@50000
   546
  fix J E assume J: "finite J" "J \<subseteq> ?I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets M"
hoelzl@50000
   547
  let ?X = "prod_emb ?I ?M J (\<Pi>\<^isub>E j\<in>J. E j)"
hoelzl@50000
   548
  have "\<And>j x. j \<in> J \<Longrightarrow> x \<in> E j \<Longrightarrow> x \<in> space M"
immler@50244
   549
    using J(3)[THEN sets.sets_into_space] by (auto simp: space_PiM Pi_iff subset_eq)
hoelzl@50000
   550
  with J have "?f -` ?X \<inter> space (S \<Otimes>\<^isub>M S) =
hoelzl@50000
   551
    (prod_emb ?I ?M (J \<inter> {..<i}) (PIE j:J \<inter> {..<i}. E j)) \<times>
hoelzl@50000
   552
    (prod_emb ?I ?M ((op + i) -` J) (PIE j:(op + i) -` J. E (i + j)))" (is "_ = ?E \<times> ?F")
hoelzl@50123
   553
   by (auto simp: space_pair_measure space_PiM prod_emb_def all_conj_distrib PiE_iff
hoelzl@50000
   554
               split: split_comb_seq split_comb_seq_asm)
hoelzl@50000
   555
  then have "emeasure ?D ?X = emeasure (S \<Otimes>\<^isub>M S) (?E \<times> ?F)"
hoelzl@50000
   556
    by (subst emeasure_distr[OF measurable_comb_seq])
hoelzl@50000
   557
       (auto intro!: sets_PiM_I simp: split_beta' J)
hoelzl@50000
   558
  also have "\<dots> = emeasure S ?E * emeasure S ?F"
hoelzl@50000
   559
    using J by (intro P.emeasure_pair_measure_Times)  (auto intro!: sets_PiM_I finite_vimageI simp: inj_on_def)
hoelzl@50000
   560
  also have "emeasure S ?F = (\<Prod>j\<in>(op + i) -` J. emeasure M (E (i + j)))"
hoelzl@50000
   561
    using J by (intro emeasure_PiM_emb) (simp_all add: finite_vimageI inj_on_def)
hoelzl@50000
   562
  also have "\<dots> = (\<Prod>j\<in>J - (J \<inter> {..<i}). emeasure M (E j))"
hoelzl@50000
   563
    by (rule strong_setprod_reindex_cong[where f="\<lambda>x. x - i"])
hoelzl@50000
   564
       (auto simp: image_iff Bex_def not_less nat_eq_diff_eq ac_simps cong: conj_cong intro!: inj_onI)
hoelzl@50000
   565
  also have "emeasure S ?E = (\<Prod>j\<in>J \<inter> {..<i}. emeasure M (E j))"
hoelzl@50000
   566
    using J by (intro emeasure_PiM_emb) simp_all
hoelzl@50000
   567
  also have "(\<Prod>j\<in>J \<inter> {..<i}. emeasure M (E j)) * (\<Prod>j\<in>J - (J \<inter> {..<i}). emeasure M (E j)) = (\<Prod>j\<in>J. emeasure M (E j))"
hoelzl@50000
   568
    by (subst mult_commute) (auto simp: J setprod_subset_diff[symmetric])
hoelzl@50000
   569
  finally show "emeasure ?D ?X = (\<Prod>j\<in>J. emeasure M (E j))" .
hoelzl@50000
   570
qed simp_all
hoelzl@50000
   571
hoelzl@50000
   572
lemma PiM_iter:
hoelzl@50000
   573
  "distr (M \<Otimes>\<^isub>M S) S (\<lambda>(s, \<omega>). nat_case s \<omega>) = S" (is "?D = _")
hoelzl@50000
   574
proof (rule PiM_eq)
hoelzl@50000
   575
  let ?I = "UNIV::nat set" and ?M = "\<lambda>n. M"
hoelzl@50000
   576
  let "distr _ _ ?f" = "?D"
hoelzl@50000
   577
hoelzl@50000
   578
  fix J E assume J: "finite J" "J \<subseteq> ?I" "\<And>j. j \<in> J \<Longrightarrow> E j \<in> sets M"
hoelzl@50000
   579
  let ?X = "prod_emb ?I ?M J (PIE j:J. E j)"
hoelzl@50000
   580
  have "\<And>j x. j \<in> J \<Longrightarrow> x \<in> E j \<Longrightarrow> x \<in> space M"
immler@50244
   581
    using J(3)[THEN sets.sets_into_space] by (auto simp: space_PiM Pi_iff subset_eq)
hoelzl@50000
   582
  with J have "?f -` ?X \<inter> space (M \<Otimes>\<^isub>M S) = (if 0 \<in> J then E 0 else space M) \<times>
hoelzl@50000
   583
    (prod_emb ?I ?M (Suc -` J) (PIE j:Suc -` J. E (Suc j)))" (is "_ = ?E \<times> ?F")
hoelzl@50123
   584
   by (auto simp: space_pair_measure space_PiM PiE_iff prod_emb_def all_conj_distrib
hoelzl@50000
   585
      split: nat.split nat.split_asm)
hoelzl@50000
   586
  then have "emeasure ?D ?X = emeasure (M \<Otimes>\<^isub>M S) (?E \<times> ?F)"
hoelzl@50099
   587
    by (subst emeasure_distr)
hoelzl@50000
   588
       (auto intro!: sets_PiM_I simp: split_beta' J)
hoelzl@50000
   589
  also have "\<dots> = emeasure M ?E * emeasure S ?F"
hoelzl@50000
   590
    using J by (intro P.emeasure_pair_measure_Times) (auto intro!: sets_PiM_I finite_vimageI)
hoelzl@50000
   591
  also have "emeasure S ?F = (\<Prod>j\<in>Suc -` J. emeasure M (E (Suc j)))"
hoelzl@50000
   592
    using J by (intro emeasure_PiM_emb) (simp_all add: finite_vimageI)
hoelzl@50000
   593
  also have "\<dots> = (\<Prod>j\<in>J - {0}. emeasure M (E j))"
hoelzl@50000
   594
    by (rule strong_setprod_reindex_cong[where f="\<lambda>x. x - 1"])
hoelzl@50000
   595
       (auto simp: image_iff Bex_def not_less nat_eq_diff_eq ac_simps cong: conj_cong intro!: inj_onI)
hoelzl@50000
   596
  also have "emeasure M ?E * (\<Prod>j\<in>J - {0}. emeasure M (E j)) = (\<Prod>j\<in>J. emeasure M (E j))"
hoelzl@50000
   597
    by (auto simp: M.emeasure_space_1 setprod.remove J)
hoelzl@50000
   598
  finally show "emeasure ?D ?X = (\<Prod>j\<in>J. emeasure M (E j))" .
hoelzl@50000
   599
qed simp_all
hoelzl@50000
   600
hoelzl@50000
   601
end
hoelzl@50000
   602
hoelzl@42147
   603
end