src/HOL/Probability/Projective_Limit.thy
author haftmann
Sat Jul 05 11:01:53 2014 +0200 (2014-07-05)
changeset 57514 bdc2c6b40bf2
parent 57447 87429bdecad5
child 58876 1888e3cb8048
permissions -rw-r--r--
prefer ac_simps collections over separate name bindings for add and mult
     1 (*  Title:      HOL/Probability/Projective_Limit.thy
     2     Author:     Fabian Immler, TU M√ľnchen
     3 *)
     4 
     5 header {* Projective Limit *}
     6 
     7 theory Projective_Limit
     8   imports
     9     Caratheodory
    10     Fin_Map
    11     Regularity
    12     Projective_Family
    13     Infinite_Product_Measure
    14     "~~/src/HOL/Library/Diagonal_Subsequence"
    15 begin
    16 
    17 subsection {* Sequences of Finite Maps in Compact Sets *}
    18 
    19 locale finmap_seqs_into_compact =
    20   fixes K::"nat \<Rightarrow> (nat \<Rightarrow>\<^sub>F 'a::metric_space) set" and f::"nat \<Rightarrow> (nat \<Rightarrow>\<^sub>F 'a)" and M
    21   assumes compact: "\<And>n. compact (K n)"
    22   assumes f_in_K: "\<And>n. K n \<noteq> {}"
    23   assumes domain_K: "\<And>n. k \<in> K n \<Longrightarrow> domain k = domain (f n)"
    24   assumes proj_in_K:
    25     "\<And>t n m. m \<ge> n \<Longrightarrow> t \<in> domain (f n) \<Longrightarrow> (f m)\<^sub>F t \<in> (\<lambda>k. (k)\<^sub>F t) ` K n"
    26 begin
    27 
    28 lemma proj_in_K': "(\<exists>n. \<forall>m \<ge> n. (f m)\<^sub>F t \<in> (\<lambda>k. (k)\<^sub>F t) ` K n)"
    29   using proj_in_K f_in_K
    30 proof cases
    31   obtain k where "k \<in> K (Suc 0)" using f_in_K by auto
    32   assume "\<forall>n. t \<notin> domain (f n)"
    33   thus ?thesis
    34     by (auto intro!: exI[where x=1] image_eqI[OF _ `k \<in> K (Suc 0)`]
    35       simp: domain_K[OF `k \<in> K (Suc 0)`])
    36 qed blast
    37 
    38 lemma proj_in_KE:
    39   obtains n where "\<And>m. m \<ge> n \<Longrightarrow> (f m)\<^sub>F t \<in> (\<lambda>k. (k)\<^sub>F t) ` K n"
    40   using proj_in_K' by blast
    41 
    42 lemma compact_projset:
    43   shows "compact ((\<lambda>k. (k)\<^sub>F i) ` K n)"
    44   using continuous_proj compact by (rule compact_continuous_image)
    45 
    46 end
    47 
    48 lemma compactE':
    49   fixes S :: "'a :: metric_space set"
    50   assumes "compact S" "\<forall>n\<ge>m. f n \<in> S"
    51   obtains l r where "l \<in> S" "subseq r" "((f \<circ> r) ---> l) sequentially"
    52 proof atomize_elim
    53   have "subseq (op + m)" by (simp add: subseq_def)
    54   have "\<forall>n. (f o (\<lambda>i. m + i)) n \<in> S" using assms by auto
    55   from seq_compactE[OF `compact S`[unfolded compact_eq_seq_compact_metric] this] guess l r .
    56   hence "l \<in> S" "subseq ((\<lambda>i. m + i) o r) \<and> (f \<circ> ((\<lambda>i. m + i) o r)) ----> l"
    57     using subseq_o[OF `subseq (op + m)` `subseq r`] by (auto simp: o_def)
    58   thus "\<exists>l r. l \<in> S \<and> subseq r \<and> (f \<circ> r) ----> l" by blast
    59 qed
    60 
    61 sublocale finmap_seqs_into_compact \<subseteq> subseqs "\<lambda>n s. (\<exists>l. (\<lambda>i. ((f o s) i)\<^sub>F n) ----> l)"
    62 proof
    63   fix n s
    64   assume "subseq s"
    65   from proj_in_KE[of n] guess n0 . note n0 = this
    66   have "\<forall>i \<ge> n0. ((f \<circ> s) i)\<^sub>F n \<in> (\<lambda>k. (k)\<^sub>F n) ` K n0"
    67   proof safe
    68     fix i assume "n0 \<le> i"
    69     also have "\<dots> \<le> s i" by (rule seq_suble) fact
    70     finally have "n0 \<le> s i" .
    71     with n0 show "((f \<circ> s) i)\<^sub>F n \<in> (\<lambda>k. (k)\<^sub>F n) ` K n0 "
    72       by auto
    73   qed
    74   from compactE'[OF compact_projset this] guess ls rs .
    75   thus "\<exists>r'. subseq r' \<and> (\<exists>l. (\<lambda>i. ((f \<circ> (s \<circ> r')) i)\<^sub>F n) ----> l)" by (auto simp: o_def)
    76 qed
    77 
    78 lemma (in finmap_seqs_into_compact) diagonal_tendsto: "\<exists>l. (\<lambda>i. (f (diagseq i))\<^sub>F n) ----> l"
    79 proof -
    80   obtain l where "(\<lambda>i. ((f o (diagseq o op + (Suc n))) i)\<^sub>F n) ----> l"
    81   proof (atomize_elim, rule diagseq_holds)
    82     fix r s n
    83     assume "subseq r"
    84     assume "\<exists>l. (\<lambda>i. ((f \<circ> s) i)\<^sub>F n) ----> l"
    85     then obtain l where "((\<lambda>i. (f i)\<^sub>F n) o s) ----> l"
    86       by (auto simp: o_def)
    87     hence "((\<lambda>i. (f i)\<^sub>F n) o s o r) ----> l" using `subseq r`
    88       by (rule LIMSEQ_subseq_LIMSEQ)
    89     thus "\<exists>l. (\<lambda>i. ((f \<circ> (s \<circ> r)) i)\<^sub>F n) ----> l" by (auto simp add: o_def)
    90   qed
    91   hence "(\<lambda>i. ((f (diagseq (i + Suc n))))\<^sub>F n) ----> l" by (simp add: ac_simps)
    92   hence "(\<lambda>i. (f (diagseq i))\<^sub>F n) ----> l" by (rule LIMSEQ_offset)
    93   thus ?thesis ..
    94 qed
    95 
    96 subsection {* Daniell-Kolmogorov Theorem *}
    97 
    98 text {* Existence of Projective Limit *}
    99 
   100 locale polish_projective = projective_family I P "\<lambda>_. borel::'a::polish_space measure"
   101   for I::"'i set" and P
   102 begin
   103 
   104 abbreviation "lim\<^sub>B \<equiv> (\<lambda>J P. limP J (\<lambda>_. borel) P)"
   105 
   106 lemma emeasure_limB_emb_not_empty:
   107   assumes "I \<noteq> {}"
   108   assumes X: "J \<noteq> {}" "J \<subseteq> I" "finite J" "\<forall>i\<in>J. B i \<in> sets borel"
   109   shows "emeasure (lim\<^sub>B I P) (emb I J (Pi\<^sub>E J B)) = emeasure (lim\<^sub>B J P) (Pi\<^sub>E J B)"
   110 proof -
   111   let ?\<Omega> = "\<Pi>\<^sub>E i\<in>I. space borel"
   112   let ?G = generator
   113   interpret G!: algebra ?\<Omega> generator by (intro  algebra_generator) fact
   114   note mu_G_mono =
   115     G.additive_increasing[OF positive_mu_G[OF `I \<noteq> {}`] additive_mu_G[OF `I \<noteq> {}`],
   116       THEN increasingD]
   117   write mu_G  ("\<mu>G")
   118 
   119   have "\<exists>\<mu>. (\<forall>s\<in>?G. \<mu> s = \<mu>G s) \<and> measure_space ?\<Omega> (sigma_sets ?\<Omega> ?G) \<mu>"
   120   proof (rule G.caratheodory_empty_continuous[OF positive_mu_G additive_mu_G,
   121       OF `I \<noteq> {}`, OF `I \<noteq> {}`])
   122     fix A assume "A \<in> ?G"
   123     with generatorE guess J X . note JX = this
   124     interpret prob_space "P J" using proj_prob_space[OF `finite J`] .
   125     show "\<mu>G A \<noteq> \<infinity>" using JX by (simp add: limP_finite)
   126   next
   127     fix Z assume Z: "range Z \<subseteq> ?G" "decseq Z" "(\<Inter>i. Z i) = {}"
   128     then have "decseq (\<lambda>i. \<mu>G (Z i))"
   129       by (auto intro!: mu_G_mono simp: decseq_def)
   130     moreover
   131     have "(INF i. \<mu>G (Z i)) = 0"
   132     proof (rule ccontr)
   133       assume "(INF i. \<mu>G (Z i)) \<noteq> 0" (is "?a \<noteq> 0")
   134       moreover have "0 \<le> ?a"
   135         using Z positive_mu_G[OF `I \<noteq> {}`] by (auto intro!: INF_greatest simp: positive_def)
   136       ultimately have "0 < ?a" by auto
   137       hence "?a \<noteq> -\<infinity>" by auto
   138       have "\<forall>n. \<exists>J B. J \<noteq> {} \<and> finite J \<and> J \<subseteq> I \<and> B \<in> sets (Pi\<^sub>M J (\<lambda>_. borel)) \<and>
   139         Z n = emb I J B \<and> \<mu>G (Z n) = emeasure (lim\<^sub>B J P) B"
   140         using Z by (intro allI generator_Ex) auto
   141       then obtain J' B' where J': "\<And>n. J' n \<noteq> {}" "\<And>n. finite (J' n)" "\<And>n. J' n \<subseteq> I"
   142           "\<And>n. B' n \<in> sets (\<Pi>\<^sub>M i\<in>J' n. borel)"
   143         and Z_emb: "\<And>n. Z n = emb I (J' n) (B' n)"
   144         unfolding choice_iff by blast
   145       moreover def J \<equiv> "\<lambda>n. (\<Union>i\<le>n. J' i)"
   146       moreover def B \<equiv> "\<lambda>n. emb (J n) (J' n) (B' n)"
   147       ultimately have J: "\<And>n. J n \<noteq> {}" "\<And>n. finite (J n)" "\<And>n. J n \<subseteq> I"
   148         "\<And>n. B n \<in> sets (\<Pi>\<^sub>M i\<in>J n. borel)"
   149         by auto
   150       have J_mono: "\<And>n m. n \<le> m \<Longrightarrow> J n \<subseteq> J m"
   151         unfolding J_def by force
   152       have "\<forall>n. \<exists>j. j \<in> J n" using J by blast
   153       then obtain j where j: "\<And>n. j n \<in> J n"
   154         unfolding choice_iff by blast
   155       note [simp] = `\<And>n. finite (J n)`
   156       from J  Z_emb have Z_eq: "\<And>n. Z n = emb I (J n) (B n)" "\<And>n. Z n \<in> ?G"
   157         unfolding J_def B_def by (subst prod_emb_trans) (insert Z, auto)
   158       interpret prob_space "P (J i)" for i using proj_prob_space by simp
   159       have "?a \<le> \<mu>G (Z 0)" by (auto intro: INF_lower)
   160       also have "\<dots> < \<infinity>" using J by (auto simp: Z_eq mu_G_eq limP_finite proj_sets)
   161       finally have "?a \<noteq> \<infinity>" by simp
   162       have "\<And>n. \<bar>\<mu>G (Z n)\<bar> \<noteq> \<infinity>" unfolding Z_eq using J J_mono
   163         by (subst mu_G_eq) (auto simp: limP_finite proj_sets mu_G_eq)
   164 
   165       have countable_UN_J: "countable (\<Union>n. J n)" by (simp add: countable_finite)
   166       def Utn \<equiv> "to_nat_on (\<Union>n. J n)"
   167       interpret function_to_finmap "J n" Utn "from_nat_into (\<Union>n. J n)" for n
   168         by unfold_locales (auto simp: Utn_def intro: from_nat_into_to_nat_on[OF countable_UN_J])
   169       have inj_on_Utn: "inj_on Utn (\<Union>n. J n)"
   170         unfolding Utn_def using countable_UN_J by (rule inj_on_to_nat_on)
   171       hence inj_on_Utn_J: "\<And>n. inj_on Utn (J n)" by (rule subset_inj_on) auto
   172       def P' \<equiv> "\<lambda>n. mapmeasure n (P (J n)) (\<lambda>_. borel)"
   173       let ?SUP = "\<lambda>n. SUP K : {K. K \<subseteq> fm n ` (B n) \<and> compact K}. emeasure (P' n) K"
   174       {
   175         fix n
   176         interpret finite_measure "P (J n)" by unfold_locales
   177         have "emeasure (P (J n)) (B n) = emeasure (P' n) (fm n ` (B n))"
   178           using J by (auto simp: P'_def mapmeasure_PiM proj_space proj_sets)
   179         also
   180         have "\<dots> = ?SUP n"
   181         proof (rule inner_regular)
   182           show "emeasure (P' n) (space (P' n)) \<noteq> \<infinity>"
   183             unfolding P'_def
   184             by (auto simp: P'_def mapmeasure_PiF fm_measurable proj_space proj_sets)
   185           show "sets (P' n) = sets borel" by (simp add: borel_eq_PiF_borel P'_def)
   186         next
   187           show "fm n ` B n \<in> sets borel"
   188             unfolding borel_eq_PiF_borel
   189             by (auto simp del: J(2) simp: P'_def fm_image_measurable_finite proj_sets J)
   190         qed
   191         finally
   192         have "emeasure (P (J n)) (B n) = ?SUP n" "?SUP n \<noteq> \<infinity>" "?SUP n \<noteq> - \<infinity>" by auto
   193       } note R = this
   194       have "\<forall>n. \<exists>K. emeasure (P (J n)) (B n) - emeasure (P' n) K \<le> 2 powr (-n) * ?a
   195         \<and> compact K \<and> K \<subseteq> fm n ` B n"
   196       proof
   197         fix n
   198         have "emeasure (P' n) (space (P' n)) \<noteq> \<infinity>"
   199           by (simp add: mapmeasure_PiF P'_def proj_space proj_sets)
   200         then interpret finite_measure "P' n" ..
   201         show "\<exists>K. emeasure (P (J n)) (B n) - emeasure (P' n) K \<le> ereal (2 powr - real n) * ?a \<and>
   202             compact K \<and> K \<subseteq> fm n ` B n"
   203           unfolding R
   204         proof (rule ccontr)
   205           assume H: "\<not> (\<exists>K'. ?SUP n - emeasure (P' n) K' \<le> ereal (2 powr - real n)  * ?a \<and>
   206             compact K' \<and> K' \<subseteq> fm n ` B n)"
   207           have "?SUP n \<le> ?SUP n - 2 powr (-n) * ?a"
   208           proof (intro SUP_least)
   209             fix K
   210             assume "K \<in> {K. K \<subseteq> fm n ` B n \<and> compact K}"
   211             with H have "\<not> ?SUP n - emeasure (P' n) K \<le> 2 powr (-n) * ?a"
   212               by auto
   213             hence "?SUP n - emeasure (P' n) K > 2 powr (-n) * ?a"
   214               unfolding not_less[symmetric] by simp
   215             hence "?SUP n - 2 powr (-n) * ?a > emeasure (P' n) K"
   216               using `0 < ?a` by (auto simp add: ereal_less_minus_iff ac_simps)
   217             thus "?SUP n - 2 powr (-n) * ?a \<ge> emeasure (P' n) K" by simp
   218           qed
   219           hence "?SUP n + 0 \<le> ?SUP n - (2 powr (-n) * ?a)" using `0 < ?a` by simp
   220           hence "?SUP n + 0 \<le> ?SUP n + - (2 powr (-n) * ?a)" unfolding minus_ereal_def .
   221           hence "0 \<le> - (2 powr (-n) * ?a)"
   222             using `?SUP _ \<noteq> \<infinity>` `?SUP _ \<noteq> - \<infinity>`
   223             by (subst (asm) ereal_add_le_add_iff) (auto simp:)
   224           moreover have "ereal (2 powr - real n) * ?a > 0" using `0 < ?a`
   225             by (auto simp: ereal_zero_less_0_iff)
   226           ultimately show False by simp
   227         qed
   228       qed
   229       then obtain K' where K':
   230         "\<And>n. emeasure (P (J n)) (B n) - emeasure (P' n) (K' n) \<le> ereal (2 powr - real n) * ?a"
   231         "\<And>n. compact (K' n)" "\<And>n. K' n \<subseteq> fm n ` B n"
   232         unfolding choice_iff by blast
   233       def K \<equiv> "\<lambda>n. fm n -` K' n \<inter> space (Pi\<^sub>M (J n) (\<lambda>_. borel))"
   234       have K_sets: "\<And>n. K n \<in> sets (Pi\<^sub>M (J n) (\<lambda>_. borel))"
   235         unfolding K_def
   236         using compact_imp_closed[OF `compact (K' _)`]
   237         by (intro measurable_sets[OF fm_measurable, of _ "Collect finite"])
   238            (auto simp: borel_eq_PiF_borel[symmetric])
   239       have K_B: "\<And>n. K n \<subseteq> B n"
   240       proof
   241         fix x n
   242         assume "x \<in> K n" hence fm_in: "fm n x \<in> fm n ` B n"
   243           using K' by (force simp: K_def)
   244         show "x \<in> B n"
   245           using `x \<in> K n` K_sets sets.sets_into_space J[of n]
   246           by (intro inj_on_image_mem_iff[OF inj_on_fm _ fm_in, of "\<lambda>_. borel"]) auto
   247       qed
   248       def Z' \<equiv> "\<lambda>n. emb I (J n) (K n)"
   249       have Z': "\<And>n. Z' n \<subseteq> Z n"
   250         unfolding Z_eq unfolding Z'_def
   251       proof (rule prod_emb_mono, safe)
   252         fix n x assume "x \<in> K n"
   253         hence "fm n x \<in> K' n" "x \<in> space (Pi\<^sub>M (J n) (\<lambda>_. borel))"
   254           by (simp_all add: K_def proj_space)
   255         note this(1)
   256         also have "K' n \<subseteq> fm n ` B n" by (simp add: K')
   257         finally have "fm n x \<in> fm n ` B n" .
   258         thus "x \<in> B n"
   259         proof safe
   260           fix y assume y: "y \<in> B n"
   261           hence "y \<in> space (Pi\<^sub>M (J n) (\<lambda>_. borel))" using J sets.sets_into_space[of "B n" "P (J n)"]
   262             by (auto simp add: proj_space proj_sets)
   263           assume "fm n x = fm n y"
   264           note inj_onD[OF inj_on_fm[OF space_borel],
   265             OF `fm n x = fm n y` `x \<in> space _` `y \<in> space _`]
   266           with y show "x \<in> B n" by simp
   267         qed
   268       qed
   269       { fix n
   270         have "Z' n \<in> ?G" using K' unfolding Z'_def
   271           apply (intro generatorI'[OF J(1-3)])
   272           unfolding K_def proj_space
   273           apply (rule measurable_sets[OF fm_measurable[of _ "Collect finite"]])
   274           apply (auto simp add: P'_def borel_eq_PiF_borel[symmetric] compact_imp_closed)
   275           done
   276       }
   277       def Y \<equiv> "\<lambda>n. \<Inter>i\<in>{1..n}. Z' i"
   278       hence "\<And>n k. Y (n + k) \<subseteq> Y n" by (induct_tac k) (auto simp: Y_def)
   279       hence Y_mono: "\<And>n m. n \<le> m \<Longrightarrow> Y m \<subseteq> Y n" by (auto simp: le_iff_add)
   280       have Y_Z': "\<And>n. n \<ge> 1 \<Longrightarrow> Y n \<subseteq> Z' n" by (auto simp: Y_def)
   281       hence Y_Z: "\<And>n. n \<ge> 1 \<Longrightarrow> Y n \<subseteq> Z n" using Z' by auto
   282       have Y_notempty: "\<And>n. n \<ge> 1 \<Longrightarrow> (Y n) \<noteq> {}"
   283       proof -
   284         fix n::nat assume "n \<ge> 1" hence "Y n \<subseteq> Z n" by fact
   285         have "Y n = (\<Inter> i\<in>{1..n}. emb I (J n) (emb (J n) (J i) (K i)))" using J J_mono
   286           by (auto simp: Y_def Z'_def)
   287         also have "\<dots> = prod_emb I (\<lambda>_. borel) (J n) (\<Inter> i\<in>{1..n}. emb (J n) (J i) (K i))"
   288           using `n \<ge> 1`
   289           by (subst prod_emb_INT) auto
   290         finally
   291         have Y_emb:
   292           "Y n = prod_emb I (\<lambda>_. borel) (J n)
   293             (\<Inter> i\<in>{1..n}. prod_emb (J n) (\<lambda>_. borel) (J i) (K i))" .
   294         hence "Y n \<in> ?G" using J J_mono K_sets `n \<ge> 1` by (intro generatorI[OF _ _ _ _ Y_emb]) auto
   295         hence "\<bar>\<mu>G (Y n)\<bar> \<noteq> \<infinity>" unfolding Y_emb using J J_mono K_sets `n \<ge> 1`
   296           by (subst mu_G_eq) (auto simp: limP_finite proj_sets mu_G_eq)
   297         interpret finite_measure "(limP (J n) (\<lambda>_. borel) P)"
   298         proof
   299           have "emeasure (limP (J n) (\<lambda>_. borel) P) (J n \<rightarrow>\<^sub>E space borel) \<noteq> \<infinity>"
   300             using J by (subst emeasure_limP) auto
   301           thus  "emeasure (limP (J n) (\<lambda>_. borel) P) (space (limP (J n) (\<lambda>_. borel) P)) \<noteq> \<infinity>"
   302              by (simp add: space_PiM)
   303         qed
   304         have "\<mu>G (Z n) = limP (J n) (\<lambda>_. borel) P (B n)"
   305           unfolding Z_eq using J by (auto simp: mu_G_eq)
   306         moreover have "\<mu>G (Y n) =
   307           limP (J n) (\<lambda>_. borel) P (\<Inter>i\<in>{Suc 0..n}. prod_emb (J n) (\<lambda>_. borel) (J i) (K i))"
   308           unfolding Y_emb using J J_mono K_sets `n \<ge> 1` by (subst mu_G_eq) auto
   309         moreover have "\<mu>G (Z n - Y n) = limP (J n) (\<lambda>_. borel) P
   310           (B n - (\<Inter>i\<in>{Suc 0..n}. prod_emb (J n) (\<lambda>_. borel) (J i) (K i)))"
   311           unfolding Z_eq Y_emb prod_emb_Diff[symmetric] using J J_mono K_sets `n \<ge> 1`
   312           by (subst mu_G_eq) (auto intro!: sets.Diff)
   313         ultimately
   314         have "\<mu>G (Z n) - \<mu>G (Y n) = \<mu>G (Z n - Y n)"
   315           using J J_mono K_sets `n \<ge> 1`
   316           by (simp only: emeasure_eq_measure)
   317             (auto dest!: bspec[where x=n]
   318             simp: extensional_restrict emeasure_eq_measure prod_emb_iff simp del: limP_finite
   319             intro!: measure_Diff[symmetric] set_mp[OF K_B])
   320         also have subs: "Z n - Y n \<subseteq> (\<Union> i\<in>{1..n}. (Z i - Z' i))" using Z' Z `n \<ge> 1`
   321           unfolding Y_def by (force simp: decseq_def)
   322         have "Z n - Y n \<in> ?G" "(\<Union> i\<in>{1..n}. (Z i - Z' i)) \<in> ?G"
   323           using `Z' _ \<in> ?G` `Z _ \<in> ?G` `Y _ \<in> ?G` by auto
   324         hence "\<mu>G (Z n - Y n) \<le> \<mu>G (\<Union> i\<in>{1..n}. (Z i - Z' i))"
   325           using subs G.additive_increasing[OF positive_mu_G[OF `I \<noteq> {}`] additive_mu_G[OF `I \<noteq> {}`]]
   326           unfolding increasing_def by auto
   327         also have "\<dots> \<le> (\<Sum> i\<in>{1..n}. \<mu>G (Z i - Z' i))" using `Z _ \<in> ?G` `Z' _ \<in> ?G`
   328           by (intro G.subadditive[OF positive_mu_G additive_mu_G, OF `I \<noteq> {}` `I \<noteq> {}`]) auto
   329         also have "\<dots> \<le> (\<Sum> i\<in>{1..n}. 2 powr -real i * ?a)"
   330         proof (rule setsum_mono)
   331           fix i assume "i \<in> {1..n}" hence "i \<le> n" by simp
   332           have "\<mu>G (Z i - Z' i) = \<mu>G (prod_emb I (\<lambda>_. borel) (J i) (B i - K i))"
   333             unfolding Z'_def Z_eq by simp
   334           also have "\<dots> = P (J i) (B i - K i)"
   335             using J K_sets by (subst mu_G_eq) auto
   336           also have "\<dots> = P (J i) (B i) - P (J i) (K i)"
   337             apply (subst emeasure_Diff) using K_sets J `K _ \<subseteq> B _` apply (auto simp: proj_sets)
   338             done
   339           also have "\<dots> = P (J i) (B i) - P' i (K' i)"
   340             unfolding K_def P'_def
   341             by (auto simp: mapmeasure_PiF proj_space proj_sets borel_eq_PiF_borel[symmetric]
   342               compact_imp_closed[OF `compact (K' _)`] space_PiM PiE_def)
   343           also have "\<dots> \<le> ereal (2 powr - real i) * ?a" using K'(1)[of i] .
   344           finally show "\<mu>G (Z i - Z' i) \<le> (2 powr - real i) * ?a" .
   345         qed
   346         also have "\<dots> = (\<Sum> i\<in>{1..n}. ereal (2 powr -real i) * ereal(real ?a))"
   347           using `?a \<noteq> \<infinity>` `?a \<noteq> - \<infinity>` by (subst ereal_real') auto
   348         also have "\<dots> = ereal (\<Sum> i\<in>{1..n}. (2 powr -real i) * (real ?a))" by simp
   349         also have "\<dots> = ereal ((\<Sum> i\<in>{1..n}. (2 powr -real i)) * real ?a)"
   350           by (simp add: setsum_left_distrib)
   351         also have "\<dots> < ereal (1 * real ?a)" unfolding less_ereal.simps
   352         proof (rule mult_strict_right_mono)
   353           have "(\<Sum>i\<in>{1..n}. 2 powr - real i) = (\<Sum>i\<in>{1..<Suc n}. (1/2) ^ i)"
   354             by (rule setsum.cong)
   355                (auto simp: powr_realpow[symmetric] powr_minus powr_divide inverse_eq_divide)
   356           also have "{1..<Suc n} = {..<Suc n} - {0}" by auto
   357           also have "setsum (op ^ (1 / 2::real)) ({..<Suc n} - {0}) =
   358             setsum (op ^ (1 / 2)) ({..<Suc n}) - 1" by (auto simp: setsum_diff1)
   359           also have "\<dots> < 1" by (subst geometric_sum) auto
   360           finally show "(\<Sum>i = 1..n. 2 powr - real i) < 1" .
   361         qed (auto simp:
   362           `0 < ?a` `?a \<noteq> \<infinity>` `?a \<noteq> - \<infinity>` ereal_less_real_iff zero_ereal_def[symmetric])
   363         also have "\<dots> = ?a" using `0 < ?a` `?a \<noteq> \<infinity>` by (auto simp: ereal_real')
   364         also have "\<dots> \<le> \<mu>G (Z n)" by (auto intro: INF_lower)
   365         finally have "\<mu>G (Z n) - \<mu>G (Y n) < \<mu>G (Z n)" .
   366         hence R: "\<mu>G (Z n) < \<mu>G (Z n) + \<mu>G (Y n)"
   367           using `\<bar>\<mu>G (Y n)\<bar> \<noteq> \<infinity>` by (simp add: ereal_minus_less)
   368         have "0 \<le> (- \<mu>G (Z n)) + \<mu>G (Z n)" using `\<bar>\<mu>G (Z n)\<bar> \<noteq> \<infinity>` by auto
   369         also have "\<dots> < (- \<mu>G (Z n)) + (\<mu>G (Z n) + \<mu>G (Y n))"
   370           apply (rule ereal_less_add[OF _ R]) using `\<bar>\<mu>G (Z n)\<bar> \<noteq> \<infinity>` by auto
   371         finally have "\<mu>G (Y n) > 0"
   372           using `\<bar>\<mu>G (Z n)\<bar> \<noteq> \<infinity>` by (auto simp: ac_simps zero_ereal_def[symmetric])
   373         thus "Y n \<noteq> {}" using positive_mu_G `I \<noteq> {}` by (auto simp add: positive_def)
   374       qed
   375       hence "\<forall>n\<in>{1..}. \<exists>y. y \<in> Y n" by auto
   376       then obtain y where y: "\<And>n. n \<ge> 1 \<Longrightarrow> y n \<in> Y n" unfolding bchoice_iff by force
   377       {
   378         fix t and n m::nat
   379         assume "1 \<le> n" "n \<le> m" hence "1 \<le> m" by simp
   380         from Y_mono[OF `m \<ge> n`] y[OF `1 \<le> m`] have "y m \<in> Y n" by auto
   381         also have "\<dots> \<subseteq> Z' n" using Y_Z'[OF `1 \<le> n`] .
   382         finally
   383         have "fm n (restrict (y m) (J n)) \<in> K' n"
   384           unfolding Z'_def K_def prod_emb_iff by (simp add: Z'_def K_def prod_emb_iff)
   385         moreover have "finmap_of (J n) (restrict (y m) (J n)) = finmap_of (J n) (y m)"
   386           using J by (simp add: fm_def)
   387         ultimately have "fm n (y m) \<in> K' n" by simp
   388       } note fm_in_K' = this
   389       interpret finmap_seqs_into_compact "\<lambda>n. K' (Suc n)" "\<lambda>k. fm (Suc k) (y (Suc k))" borel
   390       proof
   391         fix n show "compact (K' n)" by fact
   392       next
   393         fix n
   394         from Y_mono[of n "Suc n"] y[of "Suc n"] have "y (Suc n) \<in> Y (Suc n)" by auto
   395         also have "\<dots> \<subseteq> Z' (Suc n)" using Y_Z' by auto
   396         finally
   397         have "fm (Suc n) (restrict (y (Suc n)) (J (Suc n))) \<in> K' (Suc n)"
   398           unfolding Z'_def K_def prod_emb_iff by (simp add: Z'_def K_def prod_emb_iff)
   399         thus "K' (Suc n) \<noteq> {}" by auto
   400         fix k
   401         assume "k \<in> K' (Suc n)"
   402         with K'[of "Suc n"] sets.sets_into_space have "k \<in> fm (Suc n) ` B (Suc n)" by auto
   403         then obtain b where "k = fm (Suc n) b" by auto
   404         thus "domain k = domain (fm (Suc n) (y (Suc n)))"
   405           by (simp_all add: fm_def)
   406       next
   407         fix t and n m::nat
   408         assume "n \<le> m" hence "Suc n \<le> Suc m" by simp
   409         assume "t \<in> domain (fm (Suc n) (y (Suc n)))"
   410         then obtain j where j: "t = Utn j" "j \<in> J (Suc n)" by auto
   411         hence "j \<in> J (Suc m)" using J_mono[OF `Suc n \<le> Suc m`] by auto
   412         have img: "fm (Suc n) (y (Suc m)) \<in> K' (Suc n)" using `n \<le> m`
   413           by (intro fm_in_K') simp_all
   414         show "(fm (Suc m) (y (Suc m)))\<^sub>F t \<in> (\<lambda>k. (k)\<^sub>F t) ` K' (Suc n)"
   415           apply (rule image_eqI[OF _ img])
   416           using `j \<in> J (Suc n)` `j \<in> J (Suc m)`
   417           unfolding j by (subst proj_fm, auto)+
   418       qed
   419       have "\<forall>t. \<exists>z. (\<lambda>i. (fm (Suc (diagseq i)) (y (Suc (diagseq i))))\<^sub>F t) ----> z"
   420         using diagonal_tendsto ..
   421       then obtain z where z:
   422         "\<And>t. (\<lambda>i. (fm (Suc (diagseq i)) (y (Suc (diagseq i))))\<^sub>F t) ----> z t"
   423         unfolding choice_iff by blast
   424       {
   425         fix n :: nat assume "n \<ge> 1"
   426         have "\<And>i. domain (fm n (y (Suc (diagseq i)))) = domain (finmap_of (Utn ` J n) z)"
   427           by simp
   428         moreover
   429         {
   430           fix t
   431           assume t: "t \<in> domain (finmap_of (Utn ` J n) z)"
   432           hence "t \<in> Utn ` J n" by simp
   433           then obtain j where j: "t = Utn j" "j \<in> J n" by auto
   434           have "(\<lambda>i. (fm n (y (Suc (diagseq i))))\<^sub>F t) ----> z t"
   435             apply (subst (2) tendsto_iff, subst eventually_sequentially)
   436           proof safe
   437             fix e :: real assume "0 < e"
   438             { fix i x
   439               assume i: "i \<ge> n"
   440               assume "t \<in> domain (fm n x)"
   441               hence "t \<in> domain (fm i x)" using J_mono[OF `i \<ge> n`] by auto
   442               with i have "(fm i x)\<^sub>F t = (fm n x)\<^sub>F t"
   443                 using j by (auto simp: proj_fm dest!: inj_onD[OF inj_on_Utn])
   444             } note index_shift = this
   445             have I: "\<And>i. i \<ge> n \<Longrightarrow> Suc (diagseq i) \<ge> n"
   446               apply (rule le_SucI)
   447               apply (rule order_trans) apply simp
   448               apply (rule seq_suble[OF subseq_diagseq])
   449               done
   450             from z
   451             have "\<exists>N. \<forall>i\<ge>N. dist ((fm (Suc (diagseq i)) (y (Suc (diagseq i))))\<^sub>F t) (z t) < e"
   452               unfolding tendsto_iff eventually_sequentially using `0 < e` by auto
   453             then obtain N where N: "\<And>i. i \<ge> N \<Longrightarrow>
   454               dist ((fm (Suc (diagseq i)) (y (Suc (diagseq i))))\<^sub>F t) (z t) < e" by auto
   455             show "\<exists>N. \<forall>na\<ge>N. dist ((fm n (y (Suc (diagseq na))))\<^sub>F t) (z t) < e "
   456             proof (rule exI[where x="max N n"], safe)
   457               fix na assume "max N n \<le> na"
   458               hence  "dist ((fm n (y (Suc (diagseq na))))\<^sub>F t) (z t) =
   459                       dist ((fm (Suc (diagseq na)) (y (Suc (diagseq na))))\<^sub>F t) (z t)" using t
   460                 by (subst index_shift[OF I]) auto
   461               also have "\<dots> < e" using `max N n \<le> na` by (intro N) simp
   462               finally show "dist ((fm n (y (Suc (diagseq na))))\<^sub>F t) (z t) < e" .
   463             qed
   464           qed
   465           hence "(\<lambda>i. (fm n (y (Suc (diagseq i))))\<^sub>F t) ----> (finmap_of (Utn ` J n) z)\<^sub>F t"
   466             by (simp add: tendsto_intros)
   467         } ultimately
   468         have "(\<lambda>i. fm n (y (Suc (diagseq i)))) ----> finmap_of (Utn ` J n) z"
   469           by (rule tendsto_finmap)
   470         hence "((\<lambda>i. fm n (y (Suc (diagseq i)))) o (\<lambda>i. i + n)) ----> finmap_of (Utn ` J n) z"
   471           by (intro lim_subseq) (simp add: subseq_def)
   472         moreover
   473         have "(\<forall>i. ((\<lambda>i. fm n (y (Suc (diagseq i)))) o (\<lambda>i. i + n)) i \<in> K' n)"
   474           apply (auto simp add: o_def intro!: fm_in_K' `1 \<le> n` le_SucI)
   475           apply (rule le_trans)
   476           apply (rule le_add2)
   477           using seq_suble[OF subseq_diagseq]
   478           apply auto
   479           done
   480         moreover
   481         from `compact (K' n)` have "closed (K' n)" by (rule compact_imp_closed)
   482         ultimately
   483         have "finmap_of (Utn ` J n) z \<in> K' n"
   484           unfolding closed_sequential_limits by blast
   485         also have "finmap_of (Utn ` J n) z  = fm n (\<lambda>i. z (Utn i))"
   486           unfolding finmap_eq_iff
   487         proof clarsimp
   488           fix i assume i: "i \<in> J n"
   489           hence "from_nat_into (\<Union>n. J n) (Utn i) = i"
   490             unfolding Utn_def
   491             by (subst from_nat_into_to_nat_on[OF countable_UN_J]) auto
   492           with i show "z (Utn i) = (fm n (\<lambda>i. z (Utn i)))\<^sub>F (Utn i)"
   493             by (simp add: finmap_eq_iff fm_def compose_def)
   494         qed
   495         finally have "fm n (\<lambda>i. z (Utn i)) \<in> K' n" .
   496         moreover
   497         let ?J = "\<Union>n. J n"
   498         have "(?J \<inter> J n) = J n" by auto
   499         ultimately have "restrict (\<lambda>i. z (Utn i)) (?J \<inter> J n) \<in> K n"
   500           unfolding K_def by (auto simp: proj_space space_PiM)
   501         hence "restrict (\<lambda>i. z (Utn i)) ?J \<in> Z' n" unfolding Z'_def
   502           using J by (auto simp: prod_emb_def PiE_def extensional_def)
   503         also have "\<dots> \<subseteq> Z n" using Z' by simp
   504         finally have "restrict (\<lambda>i. z (Utn i)) ?J \<in> Z n" .
   505       } note in_Z = this
   506       hence "(\<Inter>i\<in>{1..}. Z i) \<noteq> {}" by auto
   507       hence "(\<Inter>i. Z i) \<noteq> {}" using Z INT_decseq_offset[OF `decseq Z`] by simp
   508       thus False using Z by simp
   509     qed
   510     ultimately show "(\<lambda>i. \<mu>G (Z i)) ----> 0"
   511       using LIMSEQ_INF[of "\<lambda>i. \<mu>G (Z i)"] by simp
   512   qed
   513   then guess \<mu> .. note \<mu> = this
   514   def f \<equiv> "finmap_of J B"
   515   show "emeasure (lim\<^sub>B I P) (emb I J (Pi\<^sub>E J B)) = emeasure (lim\<^sub>B J P) (Pi\<^sub>E J B)"
   516   proof (subst emeasure_extend_measure_Pair[OF limP_def, of I "\<lambda>_. borel" \<mu>])
   517     show "positive (sets (lim\<^sub>B I P)) \<mu>" "countably_additive (sets (lim\<^sub>B I P)) \<mu>"
   518       using \<mu> unfolding sets_limP sets_PiM_generator by (auto simp: measure_space_def)
   519   next
   520     show "(J \<noteq> {} \<or> I = {}) \<and> finite J \<and> J \<subseteq> I \<and> B \<in> J \<rightarrow> sets borel"
   521       using assms by (auto simp: f_def)
   522   next
   523     fix J and X::"'i \<Rightarrow> 'a set"
   524     show "prod_emb I (\<lambda>_. borel) J (Pi\<^sub>E J X) \<in> Pow (I \<rightarrow>\<^sub>E space borel)"
   525       by (auto simp: prod_emb_def)
   526     assume JX: "(J \<noteq> {} \<or> I = {}) \<and> finite J \<and> J \<subseteq> I \<and> X \<in> J \<rightarrow> sets borel"
   527     hence "emb I J (Pi\<^sub>E J X) \<in> generator" using assms
   528       by (intro generatorI[where J=J and X="Pi\<^sub>E J X"]) (auto intro: sets_PiM_I_finite)
   529     hence "\<mu> (emb I J (Pi\<^sub>E J X)) = \<mu>G (emb I J (Pi\<^sub>E J X))" using \<mu> by simp
   530     also have "\<dots> = emeasure (P J) (Pi\<^sub>E J X)"
   531       using JX assms proj_sets
   532       by (subst mu_G_eq) (auto simp: mu_G_eq limP_finite intro: sets_PiM_I_finite)
   533     finally show "\<mu> (emb I J (Pi\<^sub>E J X)) = emeasure (P J) (Pi\<^sub>E J X)" .
   534   next
   535     show "emeasure (P J) (Pi\<^sub>E J B) = emeasure (limP J (\<lambda>_. borel) P) (Pi\<^sub>E J B)"
   536       using assms by (simp add: f_def limP_finite Pi_def)
   537   qed
   538 qed
   539 
   540 end
   541 
   542 hide_const (open) PiF
   543 hide_const (open) Pi\<^sub>F
   544 hide_const (open) Pi'
   545 hide_const (open) Abs_finmap
   546 hide_const (open) Rep_finmap
   547 hide_const (open) finmap_of
   548 hide_const (open) proj
   549 hide_const (open) domain
   550 hide_const (open) basis_finmap
   551 
   552 sublocale polish_projective \<subseteq> P!: prob_space "(lim\<^sub>B I P)"
   553 proof
   554   show "emeasure (lim\<^sub>B I P) (space (lim\<^sub>B I P)) = 1"
   555   proof cases
   556     assume "I = {}"
   557     interpret prob_space "P {}" using proj_prob_space by simp
   558     show ?thesis
   559       by (simp add: space_PiM_empty limP_finite emeasure_space_1 `I = {}`)
   560   next
   561     assume "I \<noteq> {}"
   562     then obtain i where "i \<in> I" by auto
   563     interpret prob_space "P {i}" using proj_prob_space by simp
   564     have R: "(space (lim\<^sub>B I P)) = (emb I {i} (Pi\<^sub>E {i} (\<lambda>_. space borel)))"
   565       by (auto simp: prod_emb_def space_PiM)
   566     moreover have "extensional {i} = space (P {i})" by (simp add: proj_space space_PiM PiE_def)
   567     ultimately show ?thesis using `i \<in> I`
   568       apply (subst R)
   569       apply (subst emeasure_limB_emb_not_empty)
   570       apply (auto simp: limP_finite emeasure_space_1 PiE_def)
   571       done
   572   qed
   573 qed
   574 
   575 context polish_projective begin
   576 
   577 lemma emeasure_limB_emb:
   578   assumes X: "J \<subseteq> I" "finite J" "\<forall>i\<in>J. B i \<in> sets borel"
   579   shows "emeasure (lim\<^sub>B I P) (emb I J (Pi\<^sub>E J B)) = emeasure (P J) (Pi\<^sub>E J B)"
   580 proof cases
   581   interpret prob_space "P {}" using proj_prob_space by simp
   582   assume "J = {}"
   583   moreover have "emb I {} {\<lambda>x. undefined} = space (lim\<^sub>B I P)"
   584     by (auto simp: space_PiM prod_emb_def)
   585   moreover have "{\<lambda>x. undefined} = space (lim\<^sub>B {} P)"
   586     by (auto simp: space_PiM prod_emb_def simp del: limP_finite)
   587   ultimately show ?thesis
   588     by (simp add: P.emeasure_space_1 limP_finite emeasure_space_1 del: space_limP)
   589 next
   590   assume "J \<noteq> {}" with X show ?thesis
   591     by (subst emeasure_limB_emb_not_empty) (auto simp: limP_finite)
   592 qed
   593 
   594 lemma measure_limB_emb:
   595   assumes "J \<subseteq> I" "finite J" "\<forall>i\<in>J. B i \<in> sets borel"
   596   shows "measure (lim\<^sub>B I P) (emb I J (Pi\<^sub>E J B)) = measure (P J) (Pi\<^sub>E J B)"
   597 proof -
   598   interpret prob_space "P J" using proj_prob_space assms by simp
   599   show ?thesis
   600     using emeasure_limB_emb[OF assms]
   601     unfolding emeasure_eq_measure limP_finite[OF `finite J` `J \<subseteq> I`] P.emeasure_eq_measure
   602     by simp
   603 qed
   604 
   605 end
   606 
   607 locale polish_product_prob_space =
   608   product_prob_space "\<lambda>_. borel::('a::polish_space) measure" I for I::"'i set"
   609 
   610 sublocale polish_product_prob_space \<subseteq> P: polish_projective I "\<lambda>J. PiM J (\<lambda>_. borel::('a) measure)"
   611 proof qed
   612 
   613 lemma (in polish_product_prob_space) limP_eq_PiM:
   614   "I \<noteq> {} \<Longrightarrow> lim\<^sub>P I (\<lambda>_. borel) (\<lambda>J. PiM J (\<lambda>_. borel::('a) measure)) =
   615     PiM I (\<lambda>_. borel)"
   616   by (rule PiM_eq) (auto simp: emeasure_PiM emeasure_limB_emb)
   617 
   618 end