src/HOL/Probability/Stream_Space.thy
author hoelzl
Fri Feb 19 13:40:50 2016 +0100 (2016-02-19)
changeset 62378 85ed00c1fe7c
parent 61810 3c5040d5694a
child 63333 158ab2239496
permissions -rw-r--r--
generalize more theorems to support enat and ennreal
hoelzl@58606
     1
(*  Title:      HOL/Probability/Stream_Space.thy
hoelzl@58606
     2
    Author:     Johannes Hölzl, TU München *)
hoelzl@58606
     3
hoelzl@58588
     4
theory Stream_Space
hoelzl@58588
     5
imports
hoelzl@58588
     6
  Infinite_Product_Measure
hoelzl@58607
     7
  "~~/src/HOL/Library/Stream"
hoelzl@59000
     8
  "~~/src/HOL/Library/Linear_Temporal_Logic_on_Streams"
hoelzl@58588
     9
begin
hoelzl@58588
    10
hoelzl@58588
    11
lemma stream_eq_Stream_iff: "s = x ## t \<longleftrightarrow> (shd s = x \<and> stl s = t)"
hoelzl@58588
    12
  by (cases s) simp
hoelzl@58588
    13
hoelzl@58588
    14
lemma Stream_snth: "(x ## s) !! n = (case n of 0 \<Rightarrow> x | Suc n \<Rightarrow> s !! n)"
hoelzl@58588
    15
  by (cases n) simp_all
hoelzl@58588
    16
hoelzl@58588
    17
definition to_stream :: "(nat \<Rightarrow> 'a) \<Rightarrow> 'a stream" where
hoelzl@58588
    18
  "to_stream X = smap X nats"
hoelzl@58588
    19
hoelzl@58588
    20
lemma to_stream_nat_case: "to_stream (case_nat x X) = x ## to_stream X"
hoelzl@58588
    21
  unfolding to_stream_def
hoelzl@58588
    22
  by (subst siterate.ctr) (simp add: smap_siterate[symmetric] stream.map_comp comp_def)
hoelzl@58588
    23
hoelzl@59000
    24
lemma to_stream_in_streams: "to_stream X \<in> streams S \<longleftrightarrow> (\<forall>n. X n \<in> S)"
hoelzl@59000
    25
  by (simp add: to_stream_def streams_iff_snth)
hoelzl@59000
    26
hoelzl@58588
    27
definition stream_space :: "'a measure \<Rightarrow> 'a stream measure" where
hoelzl@58588
    28
  "stream_space M =
hoelzl@58588
    29
    distr (\<Pi>\<^sub>M i\<in>UNIV. M) (vimage_algebra (streams (space M)) snth (\<Pi>\<^sub>M i\<in>UNIV. M)) to_stream"
hoelzl@58588
    30
hoelzl@58588
    31
lemma space_stream_space: "space (stream_space M) = streams (space M)"
hoelzl@58588
    32
  by (simp add: stream_space_def)
hoelzl@58588
    33
hoelzl@58588
    34
lemma streams_stream_space[intro]: "streams (space M) \<in> sets (stream_space M)"
hoelzl@58588
    35
  using sets.top[of "stream_space M"] by (simp add: space_stream_space)
hoelzl@58588
    36
hoelzl@58588
    37
lemma stream_space_Stream:
hoelzl@58588
    38
  "x ## \<omega> \<in> space (stream_space M) \<longleftrightarrow> x \<in> space M \<and> \<omega> \<in> space (stream_space M)"
hoelzl@58588
    39
  by (simp add: space_stream_space streams_Stream)
hoelzl@58588
    40
hoelzl@58588
    41
lemma stream_space_eq_distr: "stream_space M = distr (\<Pi>\<^sub>M i\<in>UNIV. M) (stream_space M) to_stream"
hoelzl@58588
    42
  unfolding stream_space_def by (rule distr_cong) auto
hoelzl@58588
    43
hoelzl@59048
    44
lemma sets_stream_space_cong[measurable_cong]:
hoelzl@59048
    45
  "sets M = sets N \<Longrightarrow> sets (stream_space M) = sets (stream_space N)"
hoelzl@58588
    46
  using sets_eq_imp_space_eq[of M N] by (simp add: stream_space_def vimage_algebra_def cong: sets_PiM_cong)
hoelzl@58588
    47
hoelzl@58588
    48
lemma measurable_snth_PiM: "(\<lambda>\<omega> n. \<omega> !! n) \<in> measurable (stream_space M) (\<Pi>\<^sub>M i\<in>UNIV. M)"
hoelzl@58588
    49
  by (auto intro!: measurable_vimage_algebra1
hoelzl@58588
    50
           simp: space_PiM streams_iff_sset sset_range image_subset_iff stream_space_def)
hoelzl@58588
    51
hoelzl@58588
    52
lemma measurable_snth[measurable]: "(\<lambda>\<omega>. \<omega> !! n) \<in> measurable (stream_space M) M"
hoelzl@58588
    53
  using measurable_snth_PiM measurable_component_singleton by (rule measurable_compose) simp
hoelzl@58588
    54
hoelzl@58588
    55
lemma measurable_shd[measurable]: "shd \<in> measurable (stream_space M) M"
hoelzl@58588
    56
  using measurable_snth[of 0] by simp
hoelzl@58588
    57
hoelzl@58588
    58
lemma measurable_stream_space2:
hoelzl@58588
    59
  assumes f_snth: "\<And>n. (\<lambda>x. f x !! n) \<in> measurable N M"
hoelzl@58588
    60
  shows "f \<in> measurable N (stream_space M)"
hoelzl@58588
    61
  unfolding stream_space_def measurable_distr_eq2
hoelzl@58588
    62
proof (rule measurable_vimage_algebra2)
hoelzl@58588
    63
  show "f \<in> space N \<rightarrow> streams (space M)"
hoelzl@58588
    64
    using f_snth[THEN measurable_space] by (auto simp add: streams_iff_sset sset_range)
hoelzl@58588
    65
  show "(\<lambda>x. op !! (f x)) \<in> measurable N (Pi\<^sub>M UNIV (\<lambda>i. M))"
hoelzl@58588
    66
  proof (rule measurable_PiM_single')
hoelzl@58588
    67
    show "(\<lambda>x. op !! (f x)) \<in> space N \<rightarrow> UNIV \<rightarrow>\<^sub>E space M"
hoelzl@58588
    68
      using f_snth[THEN measurable_space] by auto
hoelzl@58588
    69
  qed (rule f_snth)
hoelzl@58588
    70
qed
hoelzl@58588
    71
hoelzl@58588
    72
lemma measurable_stream_coinduct[consumes 1, case_names shd stl, coinduct set: measurable]:
hoelzl@58588
    73
  assumes "F f"
hoelzl@58588
    74
  assumes h: "\<And>f. F f \<Longrightarrow> (\<lambda>x. shd (f x)) \<in> measurable N M"
hoelzl@58588
    75
  assumes t: "\<And>f. F f \<Longrightarrow> F (\<lambda>x. stl (f x))"
hoelzl@58588
    76
  shows "f \<in> measurable N (stream_space M)"
hoelzl@58588
    77
proof (rule measurable_stream_space2)
hoelzl@58588
    78
  fix n show "(\<lambda>x. f x !! n) \<in> measurable N M"
wenzelm@61808
    79
    using \<open>F f\<close> by (induction n arbitrary: f) (auto intro: h t)
hoelzl@58588
    80
qed
hoelzl@58588
    81
hoelzl@58588
    82
lemma measurable_sdrop[measurable]: "sdrop n \<in> measurable (stream_space M) (stream_space M)"
hoelzl@58588
    83
  by (rule measurable_stream_space2) (simp add: sdrop_snth)
hoelzl@58588
    84
hoelzl@58588
    85
lemma measurable_stl[measurable]: "(\<lambda>\<omega>. stl \<omega>) \<in> measurable (stream_space M) (stream_space M)"
hoelzl@58588
    86
  by (rule measurable_stream_space2) (simp del: snth.simps add: snth.simps[symmetric])
hoelzl@58588
    87
hoelzl@58588
    88
lemma measurable_to_stream[measurable]: "to_stream \<in> measurable (\<Pi>\<^sub>M i\<in>UNIV. M) (stream_space M)"
hoelzl@58588
    89
  by (rule measurable_stream_space2) (simp add: to_stream_def)
hoelzl@58588
    90
hoelzl@58588
    91
lemma measurable_Stream[measurable (raw)]:
hoelzl@58588
    92
  assumes f[measurable]: "f \<in> measurable N M"
hoelzl@58588
    93
  assumes g[measurable]: "g \<in> measurable N (stream_space M)"
hoelzl@58588
    94
  shows "(\<lambda>x. f x ## g x) \<in> measurable N (stream_space M)"
hoelzl@58588
    95
  by (rule measurable_stream_space2) (simp add: Stream_snth)
hoelzl@58588
    96
hoelzl@58588
    97
lemma measurable_smap[measurable]: 
hoelzl@58588
    98
  assumes X[measurable]: "X \<in> measurable N M"
hoelzl@58588
    99
  shows "smap X \<in> measurable (stream_space N) (stream_space M)"
hoelzl@58588
   100
  by (rule measurable_stream_space2) simp
hoelzl@58588
   101
hoelzl@58588
   102
lemma measurable_stake[measurable]: 
hoelzl@58588
   103
  "stake i \<in> measurable (stream_space (count_space UNIV)) (count_space (UNIV :: 'a::countable list set))"
hoelzl@58588
   104
  by (induct i) auto
hoelzl@58588
   105
hoelzl@59000
   106
lemma measurable_shift[measurable]: 
hoelzl@59000
   107
  assumes f: "f \<in> measurable N (stream_space M)"
hoelzl@59000
   108
  assumes [measurable]: "g \<in> measurable N (stream_space M)"
hoelzl@59000
   109
  shows "(\<lambda>x. stake n (f x) @- g x) \<in> measurable N (stream_space M)"
hoelzl@59000
   110
  using f by (induction n arbitrary: f) simp_all
hoelzl@59000
   111
hoelzl@59000
   112
lemma measurable_ev_at[measurable]:
hoelzl@59000
   113
  assumes [measurable]: "Measurable.pred (stream_space M) P"
hoelzl@59000
   114
  shows "Measurable.pred (stream_space M) (ev_at P n)"
hoelzl@59000
   115
  by (induction n) auto
hoelzl@59000
   116
hoelzl@59000
   117
lemma measurable_alw[measurable]:
hoelzl@59000
   118
  "Measurable.pred (stream_space M) P \<Longrightarrow> Measurable.pred (stream_space M) (alw P)"
hoelzl@59000
   119
  unfolding alw_def
hoelzl@60172
   120
  by (coinduction rule: measurable_gfp_coinduct) (auto simp: inf_continuous_def)
hoelzl@59000
   121
hoelzl@59000
   122
lemma measurable_ev[measurable]:
hoelzl@59000
   123
  "Measurable.pred (stream_space M) P \<Longrightarrow> Measurable.pred (stream_space M) (ev P)"
hoelzl@59000
   124
  unfolding ev_def
hoelzl@60172
   125
  by (coinduction rule: measurable_lfp_coinduct) (auto simp: sup_continuous_def)
hoelzl@59000
   126
hoelzl@59000
   127
lemma measurable_until:
hoelzl@59000
   128
  assumes [measurable]: "Measurable.pred (stream_space M) \<phi>" "Measurable.pred (stream_space M) \<psi>"
hoelzl@59000
   129
  shows "Measurable.pred (stream_space M) (\<phi> until \<psi>)"
hoelzl@59000
   130
  unfolding UNTIL_def
hoelzl@60172
   131
  by (coinduction rule: measurable_gfp_coinduct) (simp_all add: inf_continuous_def fun_eq_iff)
hoelzl@59000
   132
hoelzl@59000
   133
lemma measurable_holds [measurable]: "Measurable.pred M P \<Longrightarrow> Measurable.pred (stream_space M) (holds P)"
hoelzl@59000
   134
  unfolding holds.simps[abs_def]
hoelzl@59000
   135
  by (rule measurable_compose[OF measurable_shd]) simp
hoelzl@59000
   136
hoelzl@59000
   137
lemma measurable_hld[measurable]: assumes [measurable]: "t \<in> sets M" shows "Measurable.pred (stream_space M) (HLD t)"
hoelzl@59000
   138
  unfolding HLD_def by measurable
hoelzl@59000
   139
hoelzl@59000
   140
lemma measurable_nxt[measurable (raw)]:
hoelzl@59000
   141
  "Measurable.pred (stream_space M) P \<Longrightarrow> Measurable.pred (stream_space M) (nxt P)"
hoelzl@59000
   142
  unfolding nxt.simps[abs_def] by simp
hoelzl@59000
   143
hoelzl@59000
   144
lemma measurable_suntil[measurable]:
hoelzl@59000
   145
  assumes [measurable]: "Measurable.pred (stream_space M) Q" "Measurable.pred (stream_space M) P"
hoelzl@59000
   146
  shows "Measurable.pred (stream_space M) (Q suntil P)"
hoelzl@60172
   147
  unfolding suntil_def by (coinduction rule: measurable_lfp_coinduct) (auto simp: sup_continuous_def)
hoelzl@59000
   148
hoelzl@59000
   149
lemma measurable_szip:
hoelzl@59000
   150
  "(\<lambda>(\<omega>1, \<omega>2). szip \<omega>1 \<omega>2) \<in> measurable (stream_space M \<Otimes>\<^sub>M stream_space N) (stream_space (M \<Otimes>\<^sub>M N))"
hoelzl@59000
   151
proof (rule measurable_stream_space2)
hoelzl@59000
   152
  fix n
hoelzl@59000
   153
  have "(\<lambda>x. (case x of (\<omega>1, \<omega>2) \<Rightarrow> szip \<omega>1 \<omega>2) !! n) = (\<lambda>(\<omega>1, \<omega>2). (\<omega>1 !! n, \<omega>2 !! n))"
hoelzl@59000
   154
    by auto
hoelzl@59000
   155
  also have "\<dots> \<in> measurable (stream_space M \<Otimes>\<^sub>M stream_space N) (M \<Otimes>\<^sub>M N)"
hoelzl@59000
   156
    by measurable
hoelzl@59000
   157
  finally show "(\<lambda>x. (case x of (\<omega>1, \<omega>2) \<Rightarrow> szip \<omega>1 \<omega>2) !! n) \<in> measurable (stream_space M \<Otimes>\<^sub>M stream_space N) (M \<Otimes>\<^sub>M N)"
hoelzl@59000
   158
    .
hoelzl@59000
   159
qed
hoelzl@59000
   160
hoelzl@58588
   161
lemma (in prob_space) prob_space_stream_space: "prob_space (stream_space M)"
hoelzl@58588
   162
proof -
wenzelm@61169
   163
  interpret product_prob_space "\<lambda>_. M" UNIV ..
hoelzl@58588
   164
  show ?thesis
hoelzl@58588
   165
    by (subst stream_space_eq_distr) (auto intro!: P.prob_space_distr)
hoelzl@58588
   166
qed
hoelzl@58588
   167
hoelzl@58588
   168
lemma (in prob_space) nn_integral_stream_space:
hoelzl@58588
   169
  assumes [measurable]: "f \<in> borel_measurable (stream_space M)"
hoelzl@58588
   170
  shows "(\<integral>\<^sup>+X. f X \<partial>stream_space M) = (\<integral>\<^sup>+x. (\<integral>\<^sup>+X. f (x ## X) \<partial>stream_space M) \<partial>M)"
hoelzl@58588
   171
proof -                  
wenzelm@61169
   172
  interpret S: sequence_space M ..
wenzelm@61169
   173
  interpret P: pair_sigma_finite M "\<Pi>\<^sub>M i::nat\<in>UNIV. M" ..
hoelzl@58588
   174
hoelzl@58588
   175
  have "(\<integral>\<^sup>+X. f X \<partial>stream_space M) = (\<integral>\<^sup>+X. f (to_stream X) \<partial>S.S)"
hoelzl@58588
   176
    by (subst stream_space_eq_distr) (simp add: nn_integral_distr)
hoelzl@58588
   177
  also have "\<dots> = (\<integral>\<^sup>+X. f (to_stream ((\<lambda>(s, \<omega>). case_nat s \<omega>) X)) \<partial>(M \<Otimes>\<^sub>M S.S))"
hoelzl@58588
   178
    by (subst S.PiM_iter[symmetric]) (simp add: nn_integral_distr)
hoelzl@58588
   179
  also have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+X. f (to_stream ((\<lambda>(s, \<omega>). case_nat s \<omega>) (x, X))) \<partial>S.S \<partial>M)"
hoelzl@58588
   180
    by (subst S.nn_integral_fst) simp_all
hoelzl@58588
   181
  also have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+X. f (x ## to_stream X) \<partial>S.S \<partial>M)"
hoelzl@58588
   182
    by (auto intro!: nn_integral_cong simp: to_stream_nat_case)
hoelzl@58588
   183
  also have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+X. f (x ## X) \<partial>stream_space M \<partial>M)"
hoelzl@58588
   184
    by (subst stream_space_eq_distr)
hoelzl@58588
   185
       (simp add: nn_integral_distr cong: nn_integral_cong)
hoelzl@58588
   186
  finally show ?thesis .
hoelzl@58588
   187
qed
hoelzl@58588
   188
hoelzl@58588
   189
lemma (in prob_space) emeasure_stream_space:
hoelzl@58588
   190
  assumes X[measurable]: "X \<in> sets (stream_space M)"
hoelzl@58588
   191
  shows "emeasure (stream_space M) X = (\<integral>\<^sup>+t. emeasure (stream_space M) {x\<in>space (stream_space M). t ## x \<in> X } \<partial>M)"
hoelzl@58588
   192
proof -
hoelzl@58588
   193
  have eq: "\<And>x xs. xs \<in> space (stream_space M) \<Longrightarrow> x \<in> space M \<Longrightarrow>
hoelzl@58588
   194
      indicator X (x ## xs) = indicator {xs\<in>space (stream_space M). x ## xs \<in> X } xs"
hoelzl@58588
   195
    by (auto split: split_indicator)
hoelzl@58588
   196
  show ?thesis
hoelzl@58588
   197
    using nn_integral_stream_space[of "indicator X"]
hoelzl@58588
   198
    apply (auto intro!: nn_integral_cong)
hoelzl@58588
   199
    apply (subst nn_integral_cong)
hoelzl@58588
   200
    apply (rule eq)
hoelzl@58588
   201
    apply simp_all
hoelzl@58588
   202
    done
hoelzl@58588
   203
qed
hoelzl@58588
   204
hoelzl@58588
   205
lemma (in prob_space) prob_stream_space:
hoelzl@58588
   206
  assumes P[measurable]: "{x\<in>space (stream_space M). P x} \<in> sets (stream_space M)"
hoelzl@58588
   207
  shows "\<P>(x in stream_space M. P x) = (\<integral>\<^sup>+t. \<P>(x in stream_space M. P (t ## x)) \<partial>M)"
hoelzl@58588
   208
proof -
hoelzl@58588
   209
  interpret S: prob_space "stream_space M"
hoelzl@58588
   210
    by (rule prob_space_stream_space)
hoelzl@58588
   211
  show ?thesis
hoelzl@58588
   212
    unfolding S.emeasure_eq_measure[symmetric]
hoelzl@58588
   213
    by (subst emeasure_stream_space) (auto simp: stream_space_Stream intro!: nn_integral_cong)
hoelzl@58588
   214
qed
hoelzl@58588
   215
hoelzl@58588
   216
lemma (in prob_space) AE_stream_space:
hoelzl@58588
   217
  assumes [measurable]: "Measurable.pred (stream_space M) P"
hoelzl@58588
   218
  shows "(AE X in stream_space M. P X) = (AE x in M. AE X in stream_space M. P (x ## X))"
hoelzl@58588
   219
proof -
hoelzl@58588
   220
  interpret stream: prob_space "stream_space M"
hoelzl@58588
   221
    by (rule prob_space_stream_space)
hoelzl@58588
   222
hoelzl@58588
   223
  have eq: "\<And>x X. indicator {x. \<not> P x} (x ## X) = indicator {X. \<not> P (x ## X)} X"
hoelzl@58588
   224
    by (auto split: split_indicator)
hoelzl@58588
   225
  show ?thesis
hoelzl@58588
   226
    apply (subst AE_iff_nn_integral, simp)
hoelzl@58588
   227
    apply (subst nn_integral_stream_space, simp)
hoelzl@58588
   228
    apply (subst eq)
hoelzl@58588
   229
    apply (subst nn_integral_0_iff_AE, simp)
hoelzl@58588
   230
    apply (simp add: AE_iff_nn_integral[symmetric])
hoelzl@58588
   231
    done
hoelzl@58588
   232
qed
hoelzl@58588
   233
  
hoelzl@58588
   234
lemma (in prob_space) AE_stream_all:
hoelzl@58588
   235
  assumes [measurable]: "Measurable.pred M P" and P: "AE x in M. P x"
hoelzl@58588
   236
  shows "AE x in stream_space M. stream_all P x"
hoelzl@58588
   237
proof -
hoelzl@58588
   238
  { fix n have "AE x in stream_space M. P (x !! n)"
hoelzl@58588
   239
    proof (induct n)
hoelzl@58588
   240
      case 0 with P show ?case
lp15@61810
   241
        by (subst AE_stream_space) (auto elim!: eventually_mono)
hoelzl@58588
   242
    next
hoelzl@58588
   243
      case (Suc n) then show ?case
hoelzl@58588
   244
        by (subst AE_stream_space) auto
hoelzl@58588
   245
    qed }
hoelzl@58588
   246
  then show ?thesis
hoelzl@58588
   247
    unfolding stream_all_def by (simp add: AE_all_countable)
hoelzl@58588
   248
qed
hoelzl@58588
   249
hoelzl@59000
   250
lemma streams_sets:
hoelzl@59000
   251
  assumes X[measurable]: "X \<in> sets M" shows "streams X \<in> sets (stream_space M)"
hoelzl@59000
   252
proof -
hoelzl@59000
   253
  have "streams X = {x\<in>space (stream_space M). x \<in> streams X}"
hoelzl@59000
   254
    using streams_mono[OF _ sets.sets_into_space[OF X]] by (auto simp: space_stream_space)
hoelzl@59000
   255
  also have "\<dots> = {x\<in>space (stream_space M). gfp (\<lambda>p x. shd x \<in> X \<and> p (stl x)) x}"
hoelzl@59000
   256
    apply (simp add: set_eq_iff streams_def streamsp_def)
hoelzl@59000
   257
    apply (intro allI conj_cong refl arg_cong2[where f=gfp] ext)
hoelzl@59000
   258
    apply (case_tac xa)
hoelzl@59000
   259
    apply auto
hoelzl@59000
   260
    done
hoelzl@59000
   261
  also have "\<dots> \<in> sets (stream_space M)"
hoelzl@59000
   262
    apply (intro predE)
hoelzl@59000
   263
    apply (coinduction rule: measurable_gfp_coinduct)
hoelzl@60172
   264
    apply (auto simp: inf_continuous_def)
hoelzl@59000
   265
    done
hoelzl@59000
   266
  finally show ?thesis .
hoelzl@59000
   267
qed
hoelzl@59000
   268
hoelzl@59000
   269
lemma sets_stream_space_in_sets:
hoelzl@59000
   270
  assumes space: "space N = streams (space M)"
hoelzl@59000
   271
  assumes sets: "\<And>i. (\<lambda>x. x !! i) \<in> measurable N M"
hoelzl@59000
   272
  shows "sets (stream_space M) \<subseteq> sets N"
hoelzl@59000
   273
  unfolding stream_space_def sets_distr
hoelzl@59000
   274
  by (auto intro!: sets_image_in_sets measurable_Sup_sigma2 measurable_vimage_algebra2 del: subsetI equalityI 
hoelzl@59000
   275
           simp add: sets_PiM_eq_proj snth_in space sets cong: measurable_cong_sets)
hoelzl@59000
   276
hoelzl@59000
   277
lemma sets_stream_space_eq: "sets (stream_space M) =
hoelzl@59000
   278
    sets (\<Squnion>\<^sub>\<sigma> i\<in>UNIV. vimage_algebra (streams (space M)) (\<lambda>s. s !! i) M)"
hoelzl@59000
   279
  by (auto intro!: sets_stream_space_in_sets sets_Sup_in_sets sets_image_in_sets
hoelzl@59000
   280
                   measurable_Sup_sigma1  snth_in measurable_vimage_algebra1 del: subsetI
hoelzl@59000
   281
           simp: space_Sup_sigma space_stream_space)
hoelzl@59000
   282
hoelzl@59000
   283
lemma sets_restrict_stream_space:
hoelzl@59000
   284
  assumes S[measurable]: "S \<in> sets M"
hoelzl@59000
   285
  shows "sets (restrict_space (stream_space M) (streams S)) = sets (stream_space (restrict_space M S))"
hoelzl@59000
   286
  using  S[THEN sets.sets_into_space]
hoelzl@59000
   287
  apply (subst restrict_space_eq_vimage_algebra)
hoelzl@59000
   288
  apply (simp add: space_stream_space streams_mono2)
hoelzl@59092
   289
  apply (subst vimage_algebra_cong[OF refl refl sets_stream_space_eq])
hoelzl@59000
   290
  apply (subst sets_stream_space_eq)
hoelzl@59000
   291
  apply (subst sets_vimage_Sup_eq)
hoelzl@59000
   292
  apply simp
hoelzl@59000
   293
  apply (auto intro: streams_mono) []
hoelzl@59000
   294
  apply (simp add: image_image space_restrict_space)
hoelzl@59000
   295
  apply (intro SUP_sigma_cong)
hoelzl@59092
   296
  apply (simp add: vimage_algebra_cong[OF refl refl restrict_space_eq_vimage_algebra])
hoelzl@59000
   297
  apply (subst (1 2) vimage_algebra_vimage_algebra_eq)
hoelzl@59000
   298
  apply (auto simp: streams_mono snth_in)
hoelzl@59000
   299
  done
hoelzl@59000
   300
hoelzl@59000
   301
hoelzl@59000
   302
primrec sstart :: "'a set \<Rightarrow> 'a list \<Rightarrow> 'a stream set" where
hoelzl@59000
   303
  "sstart S [] = streams S"
hoelzl@59000
   304
| [simp del]: "sstart S (x # xs) = op ## x ` sstart S xs"
hoelzl@59000
   305
hoelzl@59000
   306
lemma in_sstart[simp]: "s \<in> sstart S (x # xs) \<longleftrightarrow> shd s = x \<and> stl s \<in> sstart S xs"
hoelzl@59000
   307
  by (cases s) (auto simp: sstart.simps(2))
hoelzl@59000
   308
hoelzl@59000
   309
lemma sstart_in_streams: "xs \<in> lists S \<Longrightarrow> sstart S xs \<subseteq> streams S"
hoelzl@59000
   310
  by (induction xs) (auto simp: sstart.simps(2))
hoelzl@59000
   311
hoelzl@59000
   312
lemma sstart_eq: "x \<in> streams S \<Longrightarrow> x \<in> sstart S xs = (\<forall>i<length xs. x !! i = xs ! i)"
hoelzl@59000
   313
  by (induction xs arbitrary: x) (auto simp: nth_Cons streams_stl split: nat.splits)
hoelzl@59000
   314
hoelzl@59000
   315
lemma sstart_sets: "sstart S xs \<in> sets (stream_space (count_space UNIV))"
hoelzl@59000
   316
proof (induction xs)
hoelzl@59000
   317
  case (Cons x xs)
hoelzl@59000
   318
  note Cons[measurable]
hoelzl@59000
   319
  have "sstart S (x # xs) =
hoelzl@59000
   320
    {s\<in>space (stream_space (count_space UNIV)). shd s = x \<and> stl s \<in> sstart S xs}"
hoelzl@59000
   321
    by (simp add: set_eq_iff space_stream_space)
hoelzl@59000
   322
  also have "\<dots> \<in> sets (stream_space (count_space UNIV))"
hoelzl@59000
   323
    by measurable
hoelzl@59000
   324
  finally show ?case .
hoelzl@59000
   325
qed (simp add: streams_sets)
hoelzl@59000
   326
hoelzl@59092
   327
lemma sigma_sets_singletons:
hoelzl@59092
   328
  assumes "countable S"
hoelzl@59092
   329
  shows "sigma_sets S ((\<lambda>s. {s})`S) = Pow S"
hoelzl@59092
   330
proof safe
hoelzl@59092
   331
  interpret sigma_algebra S "sigma_sets S ((\<lambda>s. {s})`S)"
hoelzl@59092
   332
    by (rule sigma_algebra_sigma_sets) auto
hoelzl@59092
   333
  fix A assume "A \<subseteq> S"
hoelzl@59092
   334
  with assms have "(\<Union>a\<in>A. {a}) \<in> sigma_sets S ((\<lambda>s. {s})`S)"
hoelzl@59092
   335
    by (intro countable_UN') (auto dest: countable_subset)
hoelzl@59092
   336
  then show "A \<in> sigma_sets S ((\<lambda>s. {s})`S)"
hoelzl@59092
   337
    by simp
hoelzl@59092
   338
qed (auto dest: sigma_sets_into_sp[rotated])
hoelzl@59092
   339
hoelzl@59092
   340
lemma sets_count_space_eq_sigma:
hoelzl@59092
   341
  "countable S \<Longrightarrow> sets (count_space S) = sets (sigma S ((\<lambda>s. {s})`S))"
hoelzl@59092
   342
  by (subst sets_measure_of) (auto simp: sigma_sets_singletons)
hoelzl@59092
   343
hoelzl@59000
   344
lemma sets_stream_space_sstart:
hoelzl@59000
   345
  assumes S[simp]: "countable S"
hoelzl@59000
   346
  shows "sets (stream_space (count_space S)) = sets (sigma (streams S) (sstart S`lists S \<union> {{}}))"
hoelzl@59000
   347
proof
hoelzl@59000
   348
  have [simp]: "sstart S ` lists S \<subseteq> Pow (streams S)"
hoelzl@59000
   349
    by (simp add: image_subset_iff sstart_in_streams)
hoelzl@59000
   350
hoelzl@59000
   351
  let ?S = "sigma (streams S) (sstart S ` lists S \<union> {{}})"
hoelzl@59000
   352
  { fix i a assume "a \<in> S"
hoelzl@59000
   353
    { fix x have "(x !! i = a \<and> x \<in> streams S) \<longleftrightarrow> (\<exists>xs\<in>lists S. length xs = i \<and> x \<in> sstart S (xs @ [a]))"
hoelzl@59000
   354
      proof (induction i arbitrary: x)
hoelzl@59000
   355
        case (Suc i) from this[of "stl x"] show ?case
hoelzl@59000
   356
          by (simp add: length_Suc_conv Bex_def ex_simps[symmetric] del: ex_simps)
hoelzl@59000
   357
             (metis stream.collapse streams_Stream)
wenzelm@61808
   358
      qed (insert \<open>a \<in> S\<close>, auto intro: streams_stl in_streams) }
hoelzl@59000
   359
    then have "(\<lambda>x. x !! i) -` {a} \<inter> streams S = (\<Union>xs\<in>{xs\<in>lists S. length xs = i}. sstart S (xs @ [a]))"
hoelzl@59000
   360
      by (auto simp add: set_eq_iff)
hoelzl@59000
   361
    also have "\<dots> \<in> sets ?S"
wenzelm@61808
   362
      using \<open>a\<in>S\<close> by (intro sets.countable_UN') (auto intro!: sigma_sets.Basic image_eqI)
hoelzl@59000
   363
    finally have " (\<lambda>x. x !! i) -` {a} \<inter> streams S \<in> sets ?S" . }
hoelzl@59000
   364
  then show "sets (stream_space (count_space S)) \<subseteq> sets (sigma (streams S) (sstart S`lists S \<union> {{}}))"
hoelzl@59000
   365
    by (intro sets_stream_space_in_sets) (auto simp: measurable_count_space_eq_countable snth_in)
hoelzl@59000
   366
hoelzl@59000
   367
  have "sigma_sets (space (stream_space (count_space S))) (sstart S`lists S \<union> {{}}) \<subseteq> sets (stream_space (count_space S))"
hoelzl@59000
   368
  proof (safe intro!: sets.sigma_sets_subset)
hoelzl@59000
   369
    fix xs assume "\<forall>x\<in>set xs. x \<in> S"
hoelzl@59000
   370
    then have "sstart S xs = {x\<in>space (stream_space (count_space S)). \<forall>i<length xs. x !! i = xs ! i}"
hoelzl@59000
   371
      by (induction xs)
hoelzl@59000
   372
         (auto simp: space_stream_space nth_Cons split: nat.split intro: in_streams streams_stl)
hoelzl@59000
   373
    also have "\<dots> \<in> sets (stream_space (count_space S))"
hoelzl@59000
   374
      by measurable
hoelzl@59000
   375
    finally show "sstart S xs \<in> sets (stream_space (count_space S))" .
hoelzl@59000
   376
  qed
hoelzl@59000
   377
  then show "sets (sigma (streams S) (sstart S`lists S \<union> {{}})) \<subseteq> sets (stream_space (count_space S))"
hoelzl@59000
   378
    by (simp add: space_stream_space)
hoelzl@59000
   379
qed
hoelzl@59000
   380
hoelzl@59000
   381
lemma Int_stable_sstart: "Int_stable (sstart S`lists S \<union> {{}})"
hoelzl@59000
   382
proof -
hoelzl@59000
   383
  { fix xs ys assume "xs \<in> lists S" "ys \<in> lists S"
hoelzl@59000
   384
    then have "sstart S xs \<inter> sstart S ys \<in> sstart S ` lists S \<union> {{}}"
hoelzl@59000
   385
    proof (induction xs ys rule: list_induct2')
hoelzl@59000
   386
      case (4 x xs y ys)
hoelzl@59000
   387
      show ?case
hoelzl@59000
   388
      proof cases
hoelzl@59000
   389
        assume "x = y"
hoelzl@59000
   390
        then have "sstart S (x # xs) \<inter> sstart S (y # ys) = op ## x ` (sstart S xs \<inter> sstart S ys)"
hoelzl@59000
   391
          by (auto simp: image_iff intro!: stream.collapse[symmetric])
hoelzl@59000
   392
        also have "\<dots> \<in> sstart S ` lists S \<union> {{}}"
hoelzl@59000
   393
          using 4 by (auto simp: sstart.simps(2)[symmetric] del: in_listsD)
hoelzl@59000
   394
        finally show ?case .
hoelzl@59000
   395
      qed auto
hoelzl@59000
   396
    qed (simp_all add: sstart_in_streams inf.absorb1 inf.absorb2 image_eqI[where x="[]"]) }
hoelzl@59000
   397
  then show ?thesis
hoelzl@59000
   398
    by (auto simp: Int_stable_def)
hoelzl@59000
   399
qed
hoelzl@59000
   400
hoelzl@59000
   401
lemma stream_space_eq_sstart:
hoelzl@59000
   402
  assumes S[simp]: "countable S"
hoelzl@59000
   403
  assumes P: "prob_space M" "prob_space N"
hoelzl@59000
   404
  assumes ae: "AE x in M. x \<in> streams S" "AE x in N. x \<in> streams S"
hoelzl@59000
   405
  assumes sets_M: "sets M = sets (stream_space (count_space UNIV))"
hoelzl@59000
   406
  assumes sets_N: "sets N = sets (stream_space (count_space UNIV))"
hoelzl@59000
   407
  assumes *: "\<And>xs. xs \<noteq> [] \<Longrightarrow> xs \<in> lists S \<Longrightarrow> emeasure M (sstart S xs) = emeasure N (sstart S xs)"
hoelzl@59000
   408
  shows "M = N"
hoelzl@59000
   409
proof (rule measure_eqI_restrict_generator[OF Int_stable_sstart])
hoelzl@59000
   410
  have [simp]: "sstart S ` lists S \<subseteq> Pow (streams S)"
hoelzl@59000
   411
    by (simp add: image_subset_iff sstart_in_streams)
hoelzl@59000
   412
hoelzl@59000
   413
  interpret M: prob_space M by fact
hoelzl@59000
   414
hoelzl@59000
   415
  show "sstart S ` lists S \<union> {{}} \<subseteq> Pow (streams S)"
hoelzl@59000
   416
    by (auto dest: sstart_in_streams del: in_listsD)
hoelzl@59000
   417
hoelzl@59000
   418
  { fix M :: "'a stream measure" assume M: "sets M = sets (stream_space (count_space UNIV))"
hoelzl@59000
   419
    have "sets (restrict_space M (streams S)) = sigma_sets (streams S) (sstart S ` lists S \<union> {{}})"
hoelzl@59092
   420
      by (subst sets_restrict_space_cong[OF M])
hoelzl@59092
   421
         (simp add: sets_restrict_stream_space restrict_count_space sets_stream_space_sstart) }
hoelzl@59000
   422
  from this[OF sets_M] this[OF sets_N]
hoelzl@59000
   423
  show "sets (restrict_space M (streams S)) = sigma_sets (streams S) (sstart S ` lists S \<union> {{}})"
hoelzl@59000
   424
       "sets (restrict_space N (streams S)) = sigma_sets (streams S) (sstart S ` lists S \<union> {{}})"
hoelzl@59000
   425
    by auto
hoelzl@59000
   426
  show "{streams S} \<subseteq> sstart S ` lists S \<union> {{}}"
hoelzl@59000
   427
    "\<Union>{streams S} = streams S" "\<And>s. s \<in> {streams S} \<Longrightarrow> emeasure M s \<noteq> \<infinity>"
hoelzl@59000
   428
    using M.emeasure_space_1 space_stream_space[of "count_space S"] sets_eq_imp_space_eq[OF sets_M]
hoelzl@59000
   429
    by (auto simp add: image_eqI[where x="[]"])
hoelzl@59000
   430
  show "sets M = sets N"
hoelzl@59000
   431
    by (simp add: sets_M sets_N)
hoelzl@59000
   432
next
hoelzl@59000
   433
  fix X assume "X \<in> sstart S ` lists S \<union> {{}}"
hoelzl@59000
   434
  then obtain xs where "X = {} \<or> (xs \<in> lists S \<and> X = sstart S xs)"
hoelzl@59000
   435
    by auto
hoelzl@59000
   436
  moreover have "emeasure M (streams S) = 1"
hoelzl@59000
   437
    using ae by (intro prob_space.emeasure_eq_1_AE[OF P(1)]) (auto simp: sets_M streams_sets)
hoelzl@59000
   438
  moreover have "emeasure N (streams S) = 1"
hoelzl@59000
   439
    using ae by (intro prob_space.emeasure_eq_1_AE[OF P(2)]) (auto simp: sets_N streams_sets)
hoelzl@59000
   440
  ultimately show "emeasure M X = emeasure N X"
hoelzl@59000
   441
    using P[THEN prob_space.emeasure_space_1]
hoelzl@59000
   442
    by (cases "xs = []") (auto simp: * space_stream_space del: in_listsD)
hoelzl@59000
   443
qed (auto simp: * ae sets_M del: in_listsD intro!: streams_sets)
hoelzl@59000
   444
hoelzl@58588
   445
end