src/HOL/Probability/Fin_Map.thy
changeset 53015 a1119cf551e8
parent 51641 cd05e9fcc63d
child 53374 a14d2a854c02
equal deleted inserted replaced
53009:bb18eed53ed6 53015:a1119cf551e8
     8 imports Finite_Product_Measure
     8 imports Finite_Product_Measure
     9 begin
     9 begin
    10 
    10 
    11 text {* Auxiliary type that is instantiated to @{class polish_space}, needed for the proof of
    11 text {* Auxiliary type that is instantiated to @{class polish_space}, needed for the proof of
    12   projective limit. @{const extensional} functions are used for the representation in order to
    12   projective limit. @{const extensional} functions are used for the representation in order to
    13   stay close to the developments of (finite) products @{const Pi\<^isub>E} and their sigma-algebra
    13   stay close to the developments of (finite) products @{const Pi\<^sub>E} and their sigma-algebra
    14   @{const Pi\<^isub>M}. *}
    14   @{const Pi\<^sub>M}. *}
    15 
    15 
    16 typedef ('i, 'a) finmap ("(_ \<Rightarrow>\<^isub>F /_)" [22, 21] 21) =
    16 typedef ('i, 'a) finmap ("(_ \<Rightarrow>\<^sub>F /_)" [22, 21] 21) =
    17   "{(I::'i set, f::'i \<Rightarrow> 'a). finite I \<and> f \<in> extensional I}" by auto
    17   "{(I::'i set, f::'i \<Rightarrow> 'a). finite I \<and> f \<in> extensional I}" by auto
    18 
    18 
    19 subsection {* Domain and Application *}
    19 subsection {* Domain and Application *}
    20 
    20 
    21 definition domain where "domain P = fst (Rep_finmap P)"
    21 definition domain where "domain P = fst (Rep_finmap P)"
    22 
    22 
    23 lemma finite_domain[simp, intro]: "finite (domain P)"
    23 lemma finite_domain[simp, intro]: "finite (domain P)"
    24   by (cases P) (auto simp: domain_def Abs_finmap_inverse)
    24   by (cases P) (auto simp: domain_def Abs_finmap_inverse)
    25 
    25 
    26 definition proj ("'((_)')\<^isub>F" [0] 1000) where "proj P i = snd (Rep_finmap P) i"
    26 definition proj ("'((_)')\<^sub>F" [0] 1000) where "proj P i = snd (Rep_finmap P) i"
    27 
    27 
    28 declare [[coercion proj]]
    28 declare [[coercion proj]]
    29 
    29 
    30 lemma extensional_proj[simp, intro]: "(P)\<^isub>F \<in> extensional (domain P)"
    30 lemma extensional_proj[simp, intro]: "(P)\<^sub>F \<in> extensional (domain P)"
    31   by (cases P) (auto simp: domain_def Abs_finmap_inverse proj_def[abs_def])
    31   by (cases P) (auto simp: domain_def Abs_finmap_inverse proj_def[abs_def])
    32 
    32 
    33 lemma proj_undefined[simp, intro]: "i \<notin> domain P \<Longrightarrow> P i = undefined"
    33 lemma proj_undefined[simp, intro]: "i \<notin> domain P \<Longrightarrow> P i = undefined"
    34   using extensional_proj[of P] unfolding extensional_def by auto
    34   using extensional_proj[of P] unfolding extensional_def by auto
    35 
    35 
    40 
    40 
    41 subsection {* Countable Finite Maps *}
    41 subsection {* Countable Finite Maps *}
    42 
    42 
    43 instance finmap :: (countable, countable) countable
    43 instance finmap :: (countable, countable) countable
    44 proof
    44 proof
    45   obtain mapper where mapper: "\<And>fm :: 'a \<Rightarrow>\<^isub>F 'b. set (mapper fm) = domain fm"
    45   obtain mapper where mapper: "\<And>fm :: 'a \<Rightarrow>\<^sub>F 'b. set (mapper fm) = domain fm"
    46     by (metis finite_list[OF finite_domain])
    46     by (metis finite_list[OF finite_domain])
    47   have "inj (\<lambda>fm. map (\<lambda>i. (i, (fm)\<^isub>F i)) (mapper fm))" (is "inj ?F")
    47   have "inj (\<lambda>fm. map (\<lambda>i. (i, (fm)\<^sub>F i)) (mapper fm))" (is "inj ?F")
    48   proof (rule inj_onI)
    48   proof (rule inj_onI)
    49     fix f1 f2 assume "?F f1 = ?F f2"
    49     fix f1 f2 assume "?F f1 = ?F f2"
    50     then have "map fst (?F f1) = map fst (?F f2)" by simp
    50     then have "map fst (?F f1) = map fst (?F f2)" by simp
    51     then have "mapper f1 = mapper f2" by (simp add: comp_def)
    51     then have "mapper f1 = mapper f2" by (simp add: comp_def)
    52     then have "domain f1 = domain f2" by (simp add: mapper[symmetric])
    52     then have "domain f1 = domain f2" by (simp add: mapper[symmetric])
    53     with `?F f1 = ?F f2` show "f1 = f2"
    53     with `?F f1 = ?F f2` show "f1 = f2"
    54       unfolding `mapper f1 = mapper f2` map_eq_conv mapper
    54       unfolding `mapper f1 = mapper f2` map_eq_conv mapper
    55       by (simp add: finmap_eq_iff)
    55       by (simp add: finmap_eq_iff)
    56   qed
    56   qed
    57   then show "\<exists>to_nat :: 'a \<Rightarrow>\<^isub>F 'b \<Rightarrow> nat. inj to_nat"
    57   then show "\<exists>to_nat :: 'a \<Rightarrow>\<^sub>F 'b \<Rightarrow> nat. inj to_nat"
    58     by (intro exI[of _ "to_nat \<circ> ?F"] inj_comp) auto
    58     by (intro exI[of _ "to_nat \<circ> ?F"] inj_comp) auto
    59 qed
    59 qed
    60 
    60 
    61 subsection {* Constructor of Finite Maps *}
    61 subsection {* Constructor of Finite Maps *}
    62 
    62 
    63 definition "finmap_of inds f = Abs_finmap (inds, restrict f inds)"
    63 definition "finmap_of inds f = Abs_finmap (inds, restrict f inds)"
    64 
    64 
    65 lemma proj_finmap_of[simp]:
    65 lemma proj_finmap_of[simp]:
    66   assumes "finite inds"
    66   assumes "finite inds"
    67   shows "(finmap_of inds f)\<^isub>F = restrict f inds"
    67   shows "(finmap_of inds f)\<^sub>F = restrict f inds"
    68   using assms
    68   using assms
    69   by (auto simp: Abs_finmap_inverse finmap_of_def proj_def)
    69   by (auto simp: Abs_finmap_inverse finmap_of_def proj_def)
    70 
    70 
    71 lemma domain_finmap_of[simp]:
    71 lemma domain_finmap_of[simp]:
    72   assumes "finite inds"
    72   assumes "finite inds"
    84   assumes "S \<subseteq> extensional K"
    84   assumes "S \<subseteq> extensional K"
    85   shows "inj_on (finmap_of K) S"
    85   shows "inj_on (finmap_of K) S"
    86 proof (rule inj_onI)
    86 proof (rule inj_onI)
    87   fix x y::"'a \<Rightarrow> 'b"
    87   fix x y::"'a \<Rightarrow> 'b"
    88   assume "finmap_of K x = finmap_of K y"
    88   assume "finmap_of K x = finmap_of K y"
    89   hence "(finmap_of K x)\<^isub>F = (finmap_of K y)\<^isub>F" by simp
    89   hence "(finmap_of K x)\<^sub>F = (finmap_of K y)\<^sub>F" by simp
    90   moreover
    90   moreover
    91   assume "x \<in> S" "y \<in> S" hence "x \<in> extensional K" "y \<in> extensional K" using assms by auto
    91   assume "x \<in> S" "y \<in> S" hence "x \<in> extensional K" "y \<in> extensional K" using assms by auto
    92   ultimately
    92   ultimately
    93   show "x = y" using assms by (simp add: extensional_restrict)
    93   show "x = y" using assms by (simp add: extensional_restrict)
    94 qed
    94 qed
    95 
    95 
    96 subsection {* Product set of Finite Maps *}
    96 subsection {* Product set of Finite Maps *}
    97 
    97 
    98 text {* This is @{term Pi} for Finite Maps, most of this is copied *}
    98 text {* This is @{term Pi} for Finite Maps, most of this is copied *}
    99 
    99 
   100 definition Pi' :: "'i set \<Rightarrow> ('i \<Rightarrow> 'a set) \<Rightarrow> ('i \<Rightarrow>\<^isub>F 'a) set" where
   100 definition Pi' :: "'i set \<Rightarrow> ('i \<Rightarrow> 'a set) \<Rightarrow> ('i \<Rightarrow>\<^sub>F 'a) set" where
   101   "Pi' I A = { P. domain P = I \<and> (\<forall>i. i \<in> I \<longrightarrow> (P)\<^isub>F i \<in> A i) } "
   101   "Pi' I A = { P. domain P = I \<and> (\<forall>i. i \<in> I \<longrightarrow> (P)\<^sub>F i \<in> A i) } "
   102 
   102 
   103 syntax
   103 syntax
   104   "_Pi'"  :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3PI' _:_./ _)" 10)
   104   "_Pi'"  :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3PI' _:_./ _)" 10)
   105 
   105 
   106 syntax (xsymbols)
   106 syntax (xsymbols)
   143   done
   143   done
   144 
   144 
   145 lemma Pi'_mono: "(\<And>x. x \<in> A \<Longrightarrow> B x \<subseteq> C x) \<Longrightarrow> Pi' A B \<subseteq> Pi' A C"
   145 lemma Pi'_mono: "(\<And>x. x \<in> A \<Longrightarrow> B x \<subseteq> C x) \<Longrightarrow> Pi' A B \<subseteq> Pi' A C"
   146   by (auto simp: Pi'_def)
   146   by (auto simp: Pi'_def)
   147 
   147 
   148 lemma Pi_Pi': "finite A \<Longrightarrow> (Pi\<^isub>E A B) = proj ` Pi' A B"
   148 lemma Pi_Pi': "finite A \<Longrightarrow> (Pi\<^sub>E A B) = proj ` Pi' A B"
   149   apply (auto simp: Pi'_def Pi_def extensional_def)
   149   apply (auto simp: Pi'_def Pi_def extensional_def)
   150   apply (rule_tac x = "finmap_of A (restrict x A)" in image_eqI)
   150   apply (rule_tac x = "finmap_of A (restrict x A)" in image_eqI)
   151   apply auto
   151   apply auto
   152   done
   152   done
   153 
   153 
   154 subsection {* Topological Space of Finite Maps *}
   154 subsection {* Topological Space of Finite Maps *}
   155 
   155 
   156 instantiation finmap :: (type, topological_space) topological_space
   156 instantiation finmap :: (type, topological_space) topological_space
   157 begin
   157 begin
   158 
   158 
   159 definition open_finmap :: "('a \<Rightarrow>\<^isub>F 'b) set \<Rightarrow> bool" where
   159 definition open_finmap :: "('a \<Rightarrow>\<^sub>F 'b) set \<Rightarrow> bool" where
   160   "open_finmap = generate_topology {Pi' a b|a b. \<forall>i\<in>a. open (b i)}"
   160   "open_finmap = generate_topology {Pi' a b|a b. \<forall>i\<in>a. open (b i)}"
   161 
   161 
   162 lemma open_Pi'I: "(\<And>i. i \<in> I \<Longrightarrow> open (A i)) \<Longrightarrow> open (Pi' I A)"
   162 lemma open_Pi'I: "(\<And>i. i \<in> I \<Longrightarrow> open (A i)) \<Longrightarrow> open (Pi' I A)"
   163   by (auto intro: generate_topology.Basis simp: open_finmap_def)
   163   by (auto intro: generate_topology.Basis simp: open_finmap_def)
   164 
   164 
   190 lemma closed_restricted_space:
   190 lemma closed_restricted_space:
   191   shows "closed {m. P (domain m)}"
   191   shows "closed {m. P (domain m)}"
   192   using open_restricted_space[of "\<lambda>x. \<not> P x"]
   192   using open_restricted_space[of "\<lambda>x. \<not> P x"]
   193   unfolding closed_def by (rule back_subst) auto
   193   unfolding closed_def by (rule back_subst) auto
   194 
   194 
   195 lemma tendsto_proj: "((\<lambda>x. x) ---> a) F \<Longrightarrow> ((\<lambda>x. (x)\<^isub>F i) ---> (a)\<^isub>F i) F"
   195 lemma tendsto_proj: "((\<lambda>x. x) ---> a) F \<Longrightarrow> ((\<lambda>x. (x)\<^sub>F i) ---> (a)\<^sub>F i) F"
   196   unfolding tendsto_def
   196   unfolding tendsto_def
   197 proof safe
   197 proof safe
   198   fix S::"'b set"
   198   fix S::"'b set"
   199   let ?S = "Pi' (domain a) (\<lambda>x. if x = i then S else UNIV)"
   199   let ?S = "Pi' (domain a) (\<lambda>x. if x = i then S else UNIV)"
   200   assume "open S" hence "open ?S" by (auto intro!: open_Pi'I)
   200   assume "open S" hence "open ?S" by (auto intro!: open_Pi'I)
   201   moreover assume "\<forall>S. open S \<longrightarrow> a \<in> S \<longrightarrow> eventually (\<lambda>x. x \<in> S) F" "a i \<in> S"
   201   moreover assume "\<forall>S. open S \<longrightarrow> a \<in> S \<longrightarrow> eventually (\<lambda>x. x \<in> S) F" "a i \<in> S"
   202   ultimately have "eventually (\<lambda>x. x \<in> ?S) F" by auto
   202   ultimately have "eventually (\<lambda>x. x \<in> ?S) F" by auto
   203   thus "eventually (\<lambda>x. (x)\<^isub>F i \<in> S) F"
   203   thus "eventually (\<lambda>x. (x)\<^sub>F i \<in> S) F"
   204     by eventually_elim (insert `a i \<in> S`, force simp: Pi'_iff split: split_if_asm)
   204     by eventually_elim (insert `a i \<in> S`, force simp: Pi'_iff split: split_if_asm)
   205 qed
   205 qed
   206 
   206 
   207 lemma continuous_proj:
   207 lemma continuous_proj:
   208   shows "continuous_on s (\<lambda>x. (x)\<^isub>F i)"
   208   shows "continuous_on s (\<lambda>x. (x)\<^sub>F i)"
   209   unfolding continuous_on_def by (safe intro!: tendsto_proj tendsto_ident_at)
   209   unfolding continuous_on_def by (safe intro!: tendsto_proj tendsto_ident_at)
   210 
   210 
   211 instance finmap :: (type, first_countable_topology) first_countable_topology
   211 instance finmap :: (type, first_countable_topology) first_countable_topology
   212 proof
   212 proof
   213   fix x::"'a\<Rightarrow>\<^isub>F'b"
   213   fix x::"'a\<Rightarrow>\<^sub>F'b"
   214   have "\<forall>i. \<exists>A. countable A \<and> (\<forall>a\<in>A. x i \<in> a) \<and> (\<forall>a\<in>A. open a) \<and>
   214   have "\<forall>i. \<exists>A. countable A \<and> (\<forall>a\<in>A. x i \<in> a) \<and> (\<forall>a\<in>A. open a) \<and>
   215     (\<forall>S. open S \<and> x i \<in> S \<longrightarrow> (\<exists>a\<in>A. a \<subseteq> S)) \<and> (\<forall>a b. a \<in> A \<longrightarrow> b \<in> A \<longrightarrow> a \<inter> b \<in> A)" (is "\<forall>i. ?th i")
   215     (\<forall>S. open S \<and> x i \<in> S \<longrightarrow> (\<exists>a\<in>A. a \<subseteq> S)) \<and> (\<forall>a b. a \<in> A \<longrightarrow> b \<in> A \<longrightarrow> a \<inter> b \<in> A)" (is "\<forall>i. ?th i")
   216   proof
   216   proof
   217     fix i from first_countable_basis_Int_stableE[of "x i"] guess A .
   217     fix i from first_countable_basis_Int_stableE[of "x i"] guess A .
   218     thus "?th i" by (intro exI[where x=A]) simp
   218     thus "?th i" by (intro exI[where x=A]) simp
   219   qed
   219   qed
   220   then guess A unfolding choice_iff .. note A = this
   220   then guess A unfolding choice_iff .. note A = this
   221   hence open_sub: "\<And>i S. i\<in>domain x \<Longrightarrow> open (S i) \<Longrightarrow> x i\<in>(S i) \<Longrightarrow> (\<exists>a\<in>A i. a\<subseteq>(S i))" by auto
   221   hence open_sub: "\<And>i S. i\<in>domain x \<Longrightarrow> open (S i) \<Longrightarrow> x i\<in>(S i) \<Longrightarrow> (\<exists>a\<in>A i. a\<subseteq>(S i))" by auto
   222   have A_notempty: "\<And>i. i \<in> domain x \<Longrightarrow> A i \<noteq> {}" using open_sub[of _ "\<lambda>_. UNIV"] by auto
   222   have A_notempty: "\<And>i. i \<in> domain x \<Longrightarrow> A i \<noteq> {}" using open_sub[of _ "\<lambda>_. UNIV"] by auto
   223   let ?A = "(\<lambda>f. Pi' (domain x) f) ` (Pi\<^isub>E (domain x) A)"
   223   let ?A = "(\<lambda>f. Pi' (domain x) f) ` (Pi\<^sub>E (domain x) A)"
   224   show "\<exists>A::nat \<Rightarrow> ('a\<Rightarrow>\<^isub>F'b) set. (\<forall>i. x \<in> (A i) \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
   224   show "\<exists>A::nat \<Rightarrow> ('a\<Rightarrow>\<^sub>F'b) set. (\<forall>i. x \<in> (A i) \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
   225   proof (rule first_countableI[where A="?A"], safe)
   225   proof (rule first_countableI[where A="?A"], safe)
   226     show "countable ?A" using A by (simp add: countable_PiE)
   226     show "countable ?A" using A by (simp add: countable_PiE)
   227   next
   227   next
   228     fix S::"('a \<Rightarrow>\<^isub>F 'b) set" assume "open S" "x \<in> S"
   228     fix S::"('a \<Rightarrow>\<^sub>F 'b) set" assume "open S" "x \<in> S"
   229     thus "\<exists>a\<in>?A. a \<subseteq> S" unfolding open_finmap_def
   229     thus "\<exists>a\<in>?A. a \<subseteq> S" unfolding open_finmap_def
   230     proof (induct rule: generate_topology.induct)
   230     proof (induct rule: generate_topology.induct)
   231       case UNIV thus ?case by (auto simp add: ex_in_conv PiE_eq_empty_iff A_notempty)
   231       case UNIV thus ?case by (auto simp add: ex_in_conv PiE_eq_empty_iff A_notempty)
   232     next
   232     next
   233       case (Int a b)
   233       case (Int a b)
   234       then obtain f g where
   234       then obtain f g where
   235         "f \<in> Pi\<^isub>E (domain x) A" "Pi' (domain x) f \<subseteq> a" "g \<in> Pi\<^isub>E (domain x) A" "Pi' (domain x) g \<subseteq> b"
   235         "f \<in> Pi\<^sub>E (domain x) A" "Pi' (domain x) f \<subseteq> a" "g \<in> Pi\<^sub>E (domain x) A" "Pi' (domain x) g \<subseteq> b"
   236         by auto
   236         by auto
   237       thus ?case using A
   237       thus ?case using A
   238         by (auto simp: Pi'_iff PiE_iff extensional_def Int_stable_def
   238         by (auto simp: Pi'_iff PiE_iff extensional_def Int_stable_def
   239             intro!: bexI[where x="\<lambda>i. f i \<inter> g i"])
   239             intro!: bexI[where x="\<lambda>i. f i \<inter> g i"])
   240     next
   240     next
   243       hence "\<exists>a\<in>?A. a \<subseteq> b" using UN by simp
   243       hence "\<exists>a\<in>?A. a \<subseteq> b" using UN by simp
   244       thus ?case using `b \<in> B` by blast
   244       thus ?case using `b \<in> B` by blast
   245     next
   245     next
   246       case (Basis s)
   246       case (Basis s)
   247       then obtain a b where xs: "x\<in> Pi' a b" "s = Pi' a b" "\<And>i. i\<in>a \<Longrightarrow> open (b i)" by auto
   247       then obtain a b where xs: "x\<in> Pi' a b" "s = Pi' a b" "\<And>i. i\<in>a \<Longrightarrow> open (b i)" by auto
   248       have "\<forall>i. \<exists>a. (i \<in> domain x \<and> open (b i) \<and> (x)\<^isub>F i \<in> b i) \<longrightarrow> (a\<in>A i \<and> a \<subseteq> b i)"
   248       have "\<forall>i. \<exists>a. (i \<in> domain x \<and> open (b i) \<and> (x)\<^sub>F i \<in> b i) \<longrightarrow> (a\<in>A i \<and> a \<subseteq> b i)"
   249         using open_sub[of _ b] by auto
   249         using open_sub[of _ b] by auto
   250       then obtain b'
   250       then obtain b'
   251         where "\<And>i. i \<in> domain x \<Longrightarrow> open (b i) \<Longrightarrow> (x)\<^isub>F i \<in> b i \<Longrightarrow> (b' i \<in>A i \<and> b' i \<subseteq> b i)"
   251         where "\<And>i. i \<in> domain x \<Longrightarrow> open (b i) \<Longrightarrow> (x)\<^sub>F i \<in> b i \<Longrightarrow> (b' i \<in>A i \<and> b' i \<subseteq> b i)"
   252           unfolding choice_iff by auto
   252           unfolding choice_iff by auto
   253       with xs have "\<And>i. i \<in> a \<Longrightarrow> (b' i \<in>A i \<and> b' i \<subseteq> b i)" "Pi' a b' \<subseteq> Pi' a b"
   253       with xs have "\<And>i. i \<in> a \<Longrightarrow> (b' i \<in>A i \<and> b' i \<subseteq> b i)" "Pi' a b' \<subseteq> Pi' a b"
   254         by (auto simp: Pi'_iff intro!: Pi'_mono)
   254         by (auto simp: Pi'_iff intro!: Pi'_mono)
   255       thus ?case using xs
   255       thus ?case using xs
   256         by (intro bexI[where x="Pi' a b'"])
   256         by (intro bexI[where x="Pi' a b'"])
   263 
   263 
   264 instantiation finmap :: (type, metric_space) metric_space
   264 instantiation finmap :: (type, metric_space) metric_space
   265 begin
   265 begin
   266 
   266 
   267 definition dist_finmap where
   267 definition dist_finmap where
   268   "dist P Q = Max (range (\<lambda>i. dist ((P)\<^isub>F i) ((Q)\<^isub>F i))) + (if domain P = domain Q then 0 else 1)"
   268   "dist P Q = Max (range (\<lambda>i. dist ((P)\<^sub>F i) ((Q)\<^sub>F i))) + (if domain P = domain Q then 0 else 1)"
   269 
   269 
   270 lemma add_eq_zero_iff[simp]:
   270 lemma add_eq_zero_iff[simp]:
   271   fixes a b::real
   271   fixes a b::real
   272   assumes "a \<ge> 0" "b \<ge> 0"
   272   assumes "a \<ge> 0" "b \<ge> 0"
   273   shows "a + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
   273   shows "a + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
   274 using assms by auto
   274 using assms by auto
   275 
   275 
   276 lemma finite_proj_image': "x \<notin> domain P \<Longrightarrow> finite ((P)\<^isub>F ` S)"
   276 lemma finite_proj_image': "x \<notin> domain P \<Longrightarrow> finite ((P)\<^sub>F ` S)"
   277   by (rule finite_subset[of _ "proj P ` (domain P \<inter> S \<union> {x})"]) auto
   277   by (rule finite_subset[of _ "proj P ` (domain P \<inter> S \<union> {x})"]) auto
   278 
   278 
   279 lemma finite_proj_image: "finite ((P)\<^isub>F ` S)"
   279 lemma finite_proj_image: "finite ((P)\<^sub>F ` S)"
   280  by (cases "\<exists>x. x \<notin> domain P") (auto intro: finite_proj_image' finite_subset[where B="domain P"])
   280  by (cases "\<exists>x. x \<notin> domain P") (auto intro: finite_proj_image' finite_subset[where B="domain P"])
   281 
   281 
   282 lemma finite_proj_diag: "finite ((\<lambda>i. d ((P)\<^isub>F i) ((Q)\<^isub>F i)) ` S)"
   282 lemma finite_proj_diag: "finite ((\<lambda>i. d ((P)\<^sub>F i) ((Q)\<^sub>F i)) ` S)"
   283 proof -
   283 proof -
   284   have "(\<lambda>i. d ((P)\<^isub>F i) ((Q)\<^isub>F i)) ` S = (\<lambda>(i, j). d i j) ` ((\<lambda>i. ((P)\<^isub>F i, (Q)\<^isub>F i)) ` S)" by auto
   284   have "(\<lambda>i. d ((P)\<^sub>F i) ((Q)\<^sub>F i)) ` S = (\<lambda>(i, j). d i j) ` ((\<lambda>i. ((P)\<^sub>F i, (Q)\<^sub>F i)) ` S)" by auto
   285   moreover have "((\<lambda>i. ((P)\<^isub>F i, (Q)\<^isub>F i)) ` S) \<subseteq> (\<lambda>i. (P)\<^isub>F i) ` S \<times> (\<lambda>i. (Q)\<^isub>F i) ` S" by auto
   285   moreover have "((\<lambda>i. ((P)\<^sub>F i, (Q)\<^sub>F i)) ` S) \<subseteq> (\<lambda>i. (P)\<^sub>F i) ` S \<times> (\<lambda>i. (Q)\<^sub>F i) ` S" by auto
   286   moreover have "finite \<dots>" using finite_proj_image[of P S] finite_proj_image[of Q S]
   286   moreover have "finite \<dots>" using finite_proj_image[of P S] finite_proj_image[of Q S]
   287     by (intro finite_cartesian_product) simp_all
   287     by (intro finite_cartesian_product) simp_all
   288   ultimately show ?thesis by (simp add: finite_subset)
   288   ultimately show ?thesis by (simp add: finite_subset)
   289 qed
   289 qed
   290 
   290 
   291 lemma dist_le_1_imp_domain_eq:
   291 lemma dist_le_1_imp_domain_eq:
   292   shows "dist P Q < 1 \<Longrightarrow> domain P = domain Q"
   292   shows "dist P Q < 1 \<Longrightarrow> domain P = domain Q"
   293   by (simp add: dist_finmap_def finite_proj_diag split: split_if_asm)
   293   by (simp add: dist_finmap_def finite_proj_diag split: split_if_asm)
   294 
   294 
   295 lemma dist_proj:
   295 lemma dist_proj:
   296   shows "dist ((x)\<^isub>F i) ((y)\<^isub>F i) \<le> dist x y"
   296   shows "dist ((x)\<^sub>F i) ((y)\<^sub>F i) \<le> dist x y"
   297 proof -
   297 proof -
   298   have "dist (x i) (y i) \<le> Max (range (\<lambda>i. dist (x i) (y i)))"
   298   have "dist (x i) (y i) \<le> Max (range (\<lambda>i. dist (x i) (y i)))"
   299     by (simp add: Max_ge_iff finite_proj_diag)
   299     by (simp add: Max_ge_iff finite_proj_diag)
   300   also have "\<dots> \<le> dist x y" by (simp add: dist_finmap_def)
   300   also have "\<dots> \<le> dist x y" by (simp add: dist_finmap_def)
   301   finally show ?thesis .
   301   finally show ?thesis .
   310   have "dist P Q = Max (range (\<lambda>i. dist (P i) (Q i)))"
   310   have "dist P Q = Max (range (\<lambda>i. dist (P i) (Q i)))"
   311     using assms by (simp add: dist_finmap_def finite_proj_diag)
   311     using assms by (simp add: dist_finmap_def finite_proj_diag)
   312   also have "\<dots> < e"
   312   also have "\<dots> < e"
   313   proof (subst Max_less_iff, safe)
   313   proof (subst Max_less_iff, safe)
   314     fix i
   314     fix i
   315     show "dist ((P)\<^isub>F i) ((Q)\<^isub>F i) < e" using assms
   315     show "dist ((P)\<^sub>F i) ((Q)\<^sub>F i) < e" using assms
   316       by (cases "i \<in> domain P") simp_all
   316       by (cases "i \<in> domain P") simp_all
   317   qed (simp add: finite_proj_diag)
   317   qed (simp add: finite_proj_diag)
   318   finally show ?thesis .
   318   finally show ?thesis .
   319 qed
   319 qed
   320 
   320 
   321 instance
   321 instance
   322 proof
   322 proof
   323   fix S::"('a \<Rightarrow>\<^isub>F 'b) set"
   323   fix S::"('a \<Rightarrow>\<^sub>F 'b) set"
   324   show "open S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)" (is "_ = ?od")
   324   show "open S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)" (is "_ = ?od")
   325   proof
   325   proof
   326     assume "open S"
   326     assume "open S"
   327     thus ?od
   327     thus ?od
   328       unfolding open_finmap_def
   328       unfolding open_finmap_def
   363           show "y \<in> s" unfolding s
   363           show "y \<in> s" unfolding s
   364           proof
   364           proof
   365             show "domain y = a" using d s `a \<noteq> {}` by (auto simp: dist_le_1_imp_domain_eq a_dom)
   365             show "domain y = a" using d s `a \<noteq> {}` by (auto simp: dist_le_1_imp_domain_eq a_dom)
   366             fix i assume "i \<in> a"
   366             fix i assume "i \<in> a"
   367             moreover
   367             moreover
   368             hence "dist ((y)\<^isub>F i) ((x)\<^isub>F i) < es i" using d
   368             hence "dist ((y)\<^sub>F i) ((x)\<^sub>F i) < es i" using d
   369               by (auto simp: dist_finmap_def `a \<noteq> {}` intro!: le_less_trans[OF dist_proj])
   369               by (auto simp: dist_finmap_def `a \<noteq> {}` intro!: le_less_trans[OF dist_proj])
   370             ultimately
   370             ultimately
   371             show "y i \<in> b i" by (rule in_b)
   371             show "y i \<in> b i" by (rule in_b)
   372           qed
   372           qed
   373         next
   373         next
   401       unfolding open_finmap_def
   401       unfolding open_finmap_def
   402       by (intro generate_topology.UN) (auto intro: generate_topology.Basis)
   402       by (intro generate_topology.UN) (auto intro: generate_topology.Basis)
   403     finally show "open S" .
   403     finally show "open S" .
   404   qed
   404   qed
   405 next
   405 next
   406   fix P Q::"'a \<Rightarrow>\<^isub>F 'b"
   406   fix P Q::"'a \<Rightarrow>\<^sub>F 'b"
   407   have Max_eq_iff: "\<And>A m. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> (Max A = m) = (m \<in> A \<and> (\<forall>a\<in>A. a \<le> m))"
   407   have Max_eq_iff: "\<And>A m. finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> (Max A = m) = (m \<in> A \<and> (\<forall>a\<in>A. a \<le> m))"
   408     by (auto intro: Max_in Max_eqI)
   408     by (auto intro: Max_in Max_eqI)
   409   show "dist P Q = 0 \<longleftrightarrow> P = Q"
   409   show "dist P Q = 0 \<longleftrightarrow> P = Q"
   410     by (auto simp: finmap_eq_iff dist_finmap_def Max_ge_iff finite_proj_diag Max_eq_iff
   410     by (auto simp: finmap_eq_iff dist_finmap_def Max_ge_iff finite_proj_diag Max_eq_iff
   411       intro!: Max_eqI image_eqI[where x=undefined])
   411       intro!: Max_eqI image_eqI[where x=undefined])
   412 next
   412 next
   413   fix P Q R::"'a \<Rightarrow>\<^isub>F 'b"
   413   fix P Q R::"'a \<Rightarrow>\<^sub>F 'b"
   414   let ?dists = "\<lambda>P Q i. dist ((P)\<^isub>F i) ((Q)\<^isub>F i)"
   414   let ?dists = "\<lambda>P Q i. dist ((P)\<^sub>F i) ((Q)\<^sub>F i)"
   415   let ?dpq = "?dists P Q" and ?dpr = "?dists P R" and ?dqr = "?dists Q R"
   415   let ?dpq = "?dists P Q" and ?dpr = "?dists P R" and ?dqr = "?dists Q R"
   416   let ?dom = "\<lambda>P Q. (if domain P = domain Q then 0 else 1::real)"
   416   let ?dom = "\<lambda>P Q. (if domain P = domain Q then 0 else 1::real)"
   417   have "dist P Q = Max (range ?dpq) + ?dom P Q"
   417   have "dist P Q = Max (range ?dpq) + ?dom P Q"
   418     by (simp add: dist_finmap_def)
   418     by (simp add: dist_finmap_def)
   419   also obtain t where "t \<in> range ?dpq" "t = Max (range ?dpq)" by (simp add: finite_proj_diag)
   419   also obtain t where "t \<in> range ?dpq" "t = Max (range ?dpq)" by (simp add: finite_proj_diag)
   428 end
   428 end
   429 
   429 
   430 subsection {* Complete Space of Finite Maps *}
   430 subsection {* Complete Space of Finite Maps *}
   431 
   431 
   432 lemma tendsto_finmap:
   432 lemma tendsto_finmap:
   433   fixes f::"nat \<Rightarrow> ('i \<Rightarrow>\<^isub>F ('a::metric_space))"
   433   fixes f::"nat \<Rightarrow> ('i \<Rightarrow>\<^sub>F ('a::metric_space))"
   434   assumes ind_f:  "\<And>n. domain (f n) = domain g"
   434   assumes ind_f:  "\<And>n. domain (f n) = domain g"
   435   assumes proj_g:  "\<And>i. i \<in> domain g \<Longrightarrow> (\<lambda>n. (f n) i) ----> g i"
   435   assumes proj_g:  "\<And>i. i \<in> domain g \<Longrightarrow> (\<lambda>n. (f n) i) ----> g i"
   436   shows "f ----> g"
   436   shows "f ----> g"
   437   unfolding tendsto_iff
   437   unfolding tendsto_iff
   438 proof safe
   438 proof safe
   439   fix e::real assume "0 < e"
   439   fix e::real assume "0 < e"
   440   let ?dists = "\<lambda>x i. dist ((f x)\<^isub>F i) ((g)\<^isub>F i)"
   440   let ?dists = "\<lambda>x i. dist ((f x)\<^sub>F i) ((g)\<^sub>F i)"
   441   have "eventually (\<lambda>x. \<forall>i\<in>domain g. ?dists x i < e) sequentially"
   441   have "eventually (\<lambda>x. \<forall>i\<in>domain g. ?dists x i < e) sequentially"
   442     using finite_domain[of g] proj_g
   442     using finite_domain[of g] proj_g
   443   proof induct
   443   proof induct
   444     case (insert i G)
   444     case (insert i G)
   445     with `0 < e` have "eventually (\<lambda>x. ?dists x i < e) sequentially" by (auto simp add: tendsto_iff)
   445     with `0 < e` have "eventually (\<lambda>x. ?dists x i < e) sequentially" by (auto simp add: tendsto_iff)
   446     moreover
   446     moreover
   447     from insert have "eventually (\<lambda>x. \<forall>i\<in>G. dist ((f x)\<^isub>F i) ((g)\<^isub>F i) < e) sequentially" by simp
   447     from insert have "eventually (\<lambda>x. \<forall>i\<in>G. dist ((f x)\<^sub>F i) ((g)\<^sub>F i) < e) sequentially" by simp
   448     ultimately show ?case by eventually_elim auto
   448     ultimately show ?case by eventually_elim auto
   449   qed simp
   449   qed simp
   450   thus "eventually (\<lambda>x. dist (f x) g < e) sequentially"
   450   thus "eventually (\<lambda>x. dist (f x) g < e) sequentially"
   451     by eventually_elim (auto simp add: dist_finmap_def finite_proj_diag ind_f `0 < e`)
   451     by eventually_elim (auto simp add: dist_finmap_def finite_proj_diag ind_f `0 < e`)
   452 qed
   452 qed
   453 
   453 
   454 instance finmap :: (type, complete_space) complete_space
   454 instance finmap :: (type, complete_space) complete_space
   455 proof
   455 proof
   456   fix P::"nat \<Rightarrow> 'a \<Rightarrow>\<^isub>F 'b"
   456   fix P::"nat \<Rightarrow> 'a \<Rightarrow>\<^sub>F 'b"
   457   assume "Cauchy P"
   457   assume "Cauchy P"
   458   then obtain Nd where Nd: "\<And>n. n \<ge> Nd \<Longrightarrow> dist (P n) (P Nd) < 1"
   458   then obtain Nd where Nd: "\<And>n. n \<ge> Nd \<Longrightarrow> dist (P n) (P Nd) < 1"
   459     by (force simp: cauchy)
   459     by (force simp: cauchy)
   460   def d \<equiv> "domain (P Nd)"
   460   def d \<equiv> "domain (P Nd)"
   461   with Nd have dim: "\<And>n. n \<ge> Nd \<Longrightarrow> domain (P n) = d" using dist_le_1_imp_domain_eq by auto
   461   with Nd have dim: "\<And>n. n \<ge> Nd \<Longrightarrow> domain (P n) = d" using dist_le_1_imp_domain_eq by auto
   505       proof (rule dist_finmap_lessI[OF dom(3) `0 < e`])
   505       proof (rule dist_finmap_lessI[OF dom(3) `0 < e`])
   506         fix i
   506         fix i
   507         assume "i \<in> domain (P n)"
   507         assume "i \<in> domain (P n)"
   508         hence "ni i \<le> Max (ni ` d)" using dom by simp
   508         hence "ni i \<le> Max (ni ` d)" using dom by simp
   509         also have "\<dots> \<le> N" by (simp add: N_def)
   509         also have "\<dots> \<le> N" by (simp add: N_def)
   510         finally show "dist ((P n)\<^isub>F i) ((Q)\<^isub>F i) < e" using ni `i \<in> domain (P n)` `N \<le> n` dom
   510         finally show "dist ((P n)\<^sub>F i) ((Q)\<^sub>F i) < e" using ni `i \<in> domain (P n)` `N \<le> n` dom
   511           by (auto simp: p_def q N_def less_imp_le)
   511           by (auto simp: p_def q N_def less_imp_le)
   512       qed
   512       qed
   513     qed
   513     qed
   514   qed
   514   qed
   515   thus "convergent P" by (auto simp: convergent_def)
   515   thus "convergent P" by (auto simp: convergent_def)
   524   where "basis_proj = (SOME B. countable B \<and> topological_basis B)"
   524   where "basis_proj = (SOME B. countable B \<and> topological_basis B)"
   525 
   525 
   526 lemma countable_basis_proj: "countable basis_proj" and basis_proj: "topological_basis basis_proj"
   526 lemma countable_basis_proj: "countable basis_proj" and basis_proj: "topological_basis basis_proj"
   527   unfolding basis_proj_def by (intro is_basis countable_basis)+
   527   unfolding basis_proj_def by (intro is_basis countable_basis)+
   528 
   528 
   529 definition basis_finmap::"('a \<Rightarrow>\<^isub>F 'b) set set"
   529 definition basis_finmap::"('a \<Rightarrow>\<^sub>F 'b) set set"
   530   where "basis_finmap = {Pi' I S|I S. finite I \<and> (\<forall>i \<in> I. S i \<in> basis_proj)}"
   530   where "basis_finmap = {Pi' I S|I S. finite I \<and> (\<forall>i \<in> I. S i \<in> basis_proj)}"
   531 
   531 
   532 lemma in_basis_finmapI:
   532 lemma in_basis_finmapI:
   533   assumes "finite I" assumes "\<And>i. i \<in> I \<Longrightarrow> S i \<in> basis_proj"
   533   assumes "finite I" assumes "\<And>i. i \<in> I \<Longrightarrow> S i \<in> basis_proj"
   534   shows "Pi' I S \<in> basis_finmap"
   534   shows "Pi' I S \<in> basis_finmap"
   535   using assms unfolding basis_finmap_def by auto
   535   using assms unfolding basis_finmap_def by auto
   536 
   536 
   537 lemma basis_finmap_eq:
   537 lemma basis_finmap_eq:
   538   assumes "basis_proj \<noteq> {}"
   538   assumes "basis_proj \<noteq> {}"
   539   shows "basis_finmap = (\<lambda>f. Pi' (domain f) (\<lambda>i. from_nat_into basis_proj ((f)\<^isub>F i))) `
   539   shows "basis_finmap = (\<lambda>f. Pi' (domain f) (\<lambda>i. from_nat_into basis_proj ((f)\<^sub>F i))) `
   540     (UNIV::('a \<Rightarrow>\<^isub>F nat) set)" (is "_ = ?f ` _")
   540     (UNIV::('a \<Rightarrow>\<^sub>F nat) set)" (is "_ = ?f ` _")
   541   unfolding basis_finmap_def
   541   unfolding basis_finmap_def
   542 proof safe
   542 proof safe
   543   fix I::"'a set" and S::"'a \<Rightarrow> 'b set"
   543   fix I::"'a set" and S::"'a \<Rightarrow> 'b set"
   544   assume "finite I" "\<forall>i\<in>I. S i \<in> basis_proj"
   544   assume "finite I" "\<forall>i\<in>I. S i \<in> basis_proj"
   545   hence "Pi' I S = ?f (finmap_of I (\<lambda>x. to_nat_on basis_proj (S x)))"
   545   hence "Pi' I S = ?f (finmap_of I (\<lambda>x. to_nat_on basis_proj (S x)))"
   546     by (force simp: Pi'_def countable_basis_proj)
   546     by (force simp: Pi'_def countable_basis_proj)
   547   thus "Pi' I S \<in> range ?f" by simp
   547   thus "Pi' I S \<in> range ?f" by simp
   548 next
   548 next
   549   fix x and f::"'a \<Rightarrow>\<^isub>F nat"
   549   fix x and f::"'a \<Rightarrow>\<^sub>F nat"
   550   show "\<exists>I S. (\<Pi>' i\<in>domain f. from_nat_into local.basis_proj ((f)\<^isub>F i)) = Pi' I S \<and>
   550   show "\<exists>I S. (\<Pi>' i\<in>domain f. from_nat_into local.basis_proj ((f)\<^sub>F i)) = Pi' I S \<and>
   551     finite I \<and> (\<forall>i\<in>I. S i \<in> local.basis_proj)"
   551     finite I \<and> (\<forall>i\<in>I. S i \<in> local.basis_proj)"
   552     using assms by (auto intro: from_nat_into)
   552     using assms by (auto intro: from_nat_into)
   553 qed
   553 qed
   554 
   554 
   555 lemma basis_finmap_eq_empty: "basis_proj = {} \<Longrightarrow> basis_finmap = {Pi' {} undefined}"
   555 lemma basis_finmap_eq_empty: "basis_proj = {} \<Longrightarrow> basis_finmap = {Pi' {} undefined}"
   564   fix B' assume "B' \<in> basis_finmap"
   564   fix B' assume "B' \<in> basis_finmap"
   565   thus "open B'"
   565   thus "open B'"
   566     by (auto intro!: open_Pi'I topological_basis_open[OF basis_proj]
   566     by (auto intro!: open_Pi'I topological_basis_open[OF basis_proj]
   567       simp: topological_basis_def basis_finmap_def Let_def)
   567       simp: topological_basis_def basis_finmap_def Let_def)
   568 next
   568 next
   569   fix O'::"('a \<Rightarrow>\<^isub>F 'b) set" and x
   569   fix O'::"('a \<Rightarrow>\<^sub>F 'b) set" and x
   570   assume O': "open O'" "x \<in> O'"
   570   assume O': "open O'" "x \<in> O'"
   571   then obtain a where a:
   571   then obtain a where a:
   572     "x \<in> Pi' (domain x) a" "Pi' (domain x) a \<subseteq> O'" "\<And>i. i\<in>domain x \<Longrightarrow> open (a i)"
   572     "x \<in> Pi' (domain x) a" "Pi' (domain x) a \<subseteq> O'" "\<And>i. i\<in>domain x \<Longrightarrow> open (a i)"
   573     unfolding open_finmap_def
   573     unfolding open_finmap_def
   574   proof (atomize_elim, induct rule: generate_topology.induct)
   574   proof (atomize_elim, induct rule: generate_topology.induct)
   617 
   617 
   618 definition "PiF I M \<equiv>
   618 definition "PiF I M \<equiv>
   619   sigma (\<Union>J \<in> I. (\<Pi>' j\<in>J. space (M j))) {(\<Pi>' j\<in>J. X j) |X J. J \<in> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))}"
   619   sigma (\<Union>J \<in> I. (\<Pi>' j\<in>J. space (M j))) {(\<Pi>' j\<in>J. X j) |X J. J \<in> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))}"
   620 
   620 
   621 abbreviation
   621 abbreviation
   622   "Pi\<^isub>F I M \<equiv> PiF I M"
   622   "Pi\<^sub>F I M \<equiv> PiF I M"
   623 
   623 
   624 syntax
   624 syntax
   625   "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3PIF _:_./ _)" 10)
   625   "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3PIF _:_./ _)" 10)
   626 
   626 
   627 syntax (xsymbols)
   627 syntax (xsymbols)
   628   "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3\<Pi>\<^isub>F _\<in>_./ _)"  10)
   628   "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3\<Pi>\<^sub>F _\<in>_./ _)"  10)
   629 
   629 
   630 syntax (HTML output)
   630 syntax (HTML output)
   631   "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3\<Pi>\<^isub>F _\<in>_./ _)"  10)
   631   "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3\<Pi>\<^sub>F _\<in>_./ _)"  10)
   632 
   632 
   633 translations
   633 translations
   634   "PIF x:I. M" == "CONST PiF I (%x. M)"
   634   "PIF x:I. M" == "CONST PiF I (%x. M)"
   635 
   635 
   636 lemma PiF_gen_subset: "{(\<Pi>' j\<in>J. X j) |X J. J \<in> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))} \<subseteq>
   636 lemma PiF_gen_subset: "{(\<Pi>' j\<in>J. X j) |X J. J \<in> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))} \<subseteq>
   759   shows "A \<in> measurable (PiF I M) N"
   759   shows "A \<in> measurable (PiF I M) N"
   760   unfolding measurable_def
   760   unfolding measurable_def
   761 proof safe
   761 proof safe
   762   fix y assume "y \<in> sets N"
   762   fix y assume "y \<in> sets N"
   763   have "A -` y = (\<Union>{A -` y \<inter> {x. domain x = J}|J. finite J})" by auto
   763   have "A -` y = (\<Union>{A -` y \<inter> {x. domain x = J}|J. finite J})" by auto
   764   { fix x::"'a \<Rightarrow>\<^isub>F 'b"
   764   { fix x::"'a \<Rightarrow>\<^sub>F 'b"
   765     from finite_list[of "domain x"] obtain xs where "set xs = domain x" by auto
   765     from finite_list[of "domain x"] obtain xs where "set xs = domain x" by auto
   766     hence "\<exists>n. domain x = set (from_nat n)"
   766     hence "\<exists>n. domain x = set (from_nat n)"
   767       by (intro exI[where x="to_nat xs"]) auto }
   767       by (intro exI[where x="to_nat xs"]) auto }
   768   hence "A -` y \<inter> space (PiF I M) = (\<Union>n. A -` y \<inter> space (PiF ({set (from_nat n)}\<inter>I) M))"
   768   hence "A -` y \<inter> space (PiF I M) = (\<Union>n. A -` y \<inter> space (PiF ({set (from_nat n)}\<inter>I) M))"
   769     by (auto simp: space_PiF Pi'_def)
   769     by (auto simp: space_PiF Pi'_def)
   858     done
   858     done
   859 qed
   859 qed
   860 
   860 
   861 lemma measurable_PiM_finmap_of:
   861 lemma measurable_PiM_finmap_of:
   862   assumes "finite J"
   862   assumes "finite J"
   863   shows "finmap_of J \<in> measurable (Pi\<^isub>M J M) (PiF {J} M)"
   863   shows "finmap_of J \<in> measurable (Pi\<^sub>M J M) (PiF {J} M)"
   864   apply (rule measurable_finmap_of)
   864   apply (rule measurable_finmap_of)
   865   apply (rule measurable_component_singleton)
   865   apply (rule measurable_component_singleton)
   866   apply simp
   866   apply simp
   867   apply rule
   867   apply rule
   868   apply (rule `finite J`)
   868   apply (rule `finite J`)
   869   apply simp
   869   apply simp
   870   done
   870   done
   871 
   871 
   872 lemma proj_measurable_singleton:
   872 lemma proj_measurable_singleton:
   873   assumes "A \<in> sets (M i)"
   873   assumes "A \<in> sets (M i)"
   874   shows "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space (PiF {I} M) \<in> sets (PiF {I} M)"
   874   shows "(\<lambda>x. (x)\<^sub>F i) -` A \<inter> space (PiF {I} M) \<in> sets (PiF {I} M)"
   875 proof cases
   875 proof cases
   876   assume "i \<in> I"
   876   assume "i \<in> I"
   877   hence "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space (PiF {I} M) =
   877   hence "(\<lambda>x. (x)\<^sub>F i) -` A \<inter> space (PiF {I} M) =
   878     Pi' I (\<lambda>x. if x = i then A else space (M x))"
   878     Pi' I (\<lambda>x. if x = i then A else space (M x))"
   879     using sets.sets_into_space[OF ] `A \<in> sets (M i)` assms
   879     using sets.sets_into_space[OF ] `A \<in> sets (M i)` assms
   880     by (auto simp: space_PiF Pi'_def)
   880     by (auto simp: space_PiF Pi'_def)
   881   thus ?thesis  using assms `A \<in> sets (M i)`
   881   thus ?thesis  using assms `A \<in> sets (M i)`
   882     by (intro in_sets_PiFI) auto
   882     by (intro in_sets_PiFI) auto
   883 next
   883 next
   884   assume "i \<notin> I"
   884   assume "i \<notin> I"
   885   hence "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space (PiF {I} M) =
   885   hence "(\<lambda>x. (x)\<^sub>F i) -` A \<inter> space (PiF {I} M) =
   886     (if undefined \<in> A then space (PiF {I} M) else {})" by (auto simp: space_PiF Pi'_def)
   886     (if undefined \<in> A then space (PiF {I} M) else {})" by (auto simp: space_PiF Pi'_def)
   887   thus ?thesis by simp
   887   thus ?thesis by simp
   888 qed
   888 qed
   889 
   889 
   890 lemma measurable_proj_singleton:
   890 lemma measurable_proj_singleton:
   891   assumes "i \<in> I"
   891   assumes "i \<in> I"
   892   shows "(\<lambda>x. (x)\<^isub>F i) \<in> measurable (PiF {I} M) (M i)"
   892   shows "(\<lambda>x. (x)\<^sub>F i) \<in> measurable (PiF {I} M) (M i)"
   893   by (unfold measurable_def, intro CollectI conjI ballI proj_measurable_singleton assms)
   893   by (unfold measurable_def, intro CollectI conjI ballI proj_measurable_singleton assms)
   894      (insert `i \<in> I`, auto simp: space_PiF)
   894      (insert `i \<in> I`, auto simp: space_PiF)
   895 
   895 
   896 lemma measurable_proj_countable:
   896 lemma measurable_proj_countable:
   897   fixes I::"'a::countable set set"
   897   fixes I::"'a::countable set set"
   898   assumes "y \<in> space (M i)"
   898   assumes "y \<in> space (M i)"
   899   shows "(\<lambda>x. if i \<in> domain x then (x)\<^isub>F i else y) \<in> measurable (PiF I M) (M i)"
   899   shows "(\<lambda>x. if i \<in> domain x then (x)\<^sub>F i else y) \<in> measurable (PiF I M) (M i)"
   900 proof (rule countable_measurable_PiFI)
   900 proof (rule countable_measurable_PiFI)
   901   fix J assume "J \<in> I" "finite J"
   901   fix J assume "J \<in> I" "finite J"
   902   show "(\<lambda>x. if i \<in> domain x then x i else y) \<in> measurable (PiF {J} M) (M i)"
   902   show "(\<lambda>x. if i \<in> domain x then x i else y) \<in> measurable (PiF {J} M) (M i)"
   903     unfolding measurable_def
   903     unfolding measurable_def
   904   proof safe
   904   proof safe
   905     fix z assume "z \<in> sets (M i)"
   905     fix z assume "z \<in> sets (M i)"
   906     have "(\<lambda>x. if i \<in> domain x then x i else y) -` z \<inter> space (PiF {J} M) =
   906     have "(\<lambda>x. if i \<in> domain x then x i else y) -` z \<inter> space (PiF {J} M) =
   907       (\<lambda>x. if i \<in> J then (x)\<^isub>F i else y) -` z \<inter> space (PiF {J} M)"
   907       (\<lambda>x. if i \<in> J then (x)\<^sub>F i else y) -` z \<inter> space (PiF {J} M)"
   908       by (auto simp: space_PiF Pi'_def)
   908       by (auto simp: space_PiF Pi'_def)
   909     also have "\<dots> \<in> sets (PiF {J} M)" using `z \<in> sets (M i)` `finite J`
   909     also have "\<dots> \<in> sets (PiF {J} M)" using `z \<in> sets (M i)` `finite J`
   910       by (cases "i \<in> J") (auto intro!: measurable_sets[OF measurable_proj_singleton])
   910       by (cases "i \<in> J") (auto intro!: measurable_sets[OF measurable_proj_singleton])
   911     finally show "(\<lambda>x. if i \<in> domain x then x i else y) -` z \<inter> space (PiF {J} M) \<in>
   911     finally show "(\<lambda>x. if i \<in> domain x then x i else y) -` z \<inter> space (PiF {J} M) \<in>
   912       sets (PiF {J} M)" .
   912       sets (PiF {J} M)" .
   923   fixes J K ::"'a::countable set" and I::"'a set set"
   923   fixes J K ::"'a::countable set" and I::"'a set set"
   924   assumes "finite J" "J \<in> I"
   924   assumes "finite J" "J \<in> I"
   925   assumes "x \<in> space (PiM J M)"
   925   assumes "x \<in> space (PiM J M)"
   926   shows "proj \<in> measurable (PiF {J} M) (PiM J M)"
   926   shows "proj \<in> measurable (PiF {J} M) (PiM J M)"
   927 proof (rule measurable_PiM_single)
   927 proof (rule measurable_PiM_single)
   928   show "proj \<in> space (PiF {J} M) \<rightarrow> (\<Pi>\<^isub>E i \<in> J. space (M i))"
   928   show "proj \<in> space (PiF {J} M) \<rightarrow> (\<Pi>\<^sub>E i \<in> J. space (M i))"
   929     using assms by (auto simp add: space_PiM space_PiF extensional_def sets_PiF Pi'_def)
   929     using assms by (auto simp add: space_PiM space_PiF extensional_def sets_PiF Pi'_def)
   930 next
   930 next
   931   fix A i assume A: "i \<in> J" "A \<in> sets (M i)"
   931   fix A i assume A: "i \<in> J" "A \<in> sets (M i)"
   932   show "{\<omega> \<in> space (PiF {J} M). (\<omega>)\<^isub>F i \<in> A} \<in> sets (PiF {J} M)"
   932   show "{\<omega> \<in> space (PiF {J} M). (\<omega>)\<^sub>F i \<in> A} \<in> sets (PiF {J} M)"
   933   proof
   933   proof
   934     have "{\<omega> \<in> space (PiF {J} M). (\<omega>)\<^isub>F i \<in> A} =
   934     have "{\<omega> \<in> space (PiF {J} M). (\<omega>)\<^sub>F i \<in> A} =
   935       (\<lambda>\<omega>. (\<omega>)\<^isub>F i) -` A \<inter> space (PiF {J} M)" by auto
   935       (\<lambda>\<omega>. (\<omega>)\<^sub>F i) -` A \<inter> space (PiF {J} M)" by auto
   936     also have "\<dots> \<in> sets (PiF {J} M)"
   936     also have "\<dots> \<in> sets (PiF {J} M)"
   937       using assms A by (auto intro: measurable_sets[OF measurable_proj_singleton] simp: space_PiM)
   937       using assms A by (auto intro: measurable_sets[OF measurable_proj_singleton] simp: space_PiM)
   938     finally show ?thesis .
   938     finally show ?thesis .
   939   qed simp
   939   qed simp
   940 qed
   940 qed
  1022   assumes E_closed: "\<And>i. i \<in> I \<Longrightarrow> E i \<subseteq> Pow (space (M i))"
  1022   assumes E_closed: "\<And>i. i \<in> I \<Longrightarrow> E i \<subseteq> Pow (space (M i))"
  1023     and E_generates: "\<And>i. i \<in> I \<Longrightarrow> sets (M i) = sigma_sets (space (M i)) (E i)"
  1023     and E_generates: "\<And>i. i \<in> I \<Longrightarrow> sets (M i) = sigma_sets (space (M i)) (E i)"
  1024   defines "P == { Pi' I F | F. \<forall>i\<in>I. F i \<in> E i }"
  1024   defines "P == { Pi' I F | F. \<forall>i\<in>I. F i \<in> E i }"
  1025   shows "sets (PiF {I} M) = sigma_sets (space (PiF {I} M)) P"
  1025   shows "sets (PiF {I} M) = sigma_sets (space (PiF {I} M)) P"
  1026 proof
  1026 proof
  1027   let ?P = "sigma (space (Pi\<^isub>F {I} M)) P"
  1027   let ?P = "sigma (space (Pi\<^sub>F {I} M)) P"
  1028   from `finite I`[THEN ex_bij_betw_finite_nat] guess T ..
  1028   from `finite I`[THEN ex_bij_betw_finite_nat] guess T ..
  1029   then have T: "\<And>i. i \<in> I \<Longrightarrow> T i < card I" "\<And>i. i\<in>I \<Longrightarrow> the_inv_into I T (T i) = i"
  1029   then have T: "\<And>i. i \<in> I \<Longrightarrow> T i < card I" "\<And>i. i\<in>I \<Longrightarrow> the_inv_into I T (T i) = i"
  1030     by (auto simp add: bij_betw_def set_eq_iff image_iff the_inv_into_f_f simp del: `finite I`)
  1030     by (auto simp add: bij_betw_def set_eq_iff image_iff the_inv_into_f_f simp del: `finite I`)
  1031   have P_closed: "P \<subseteq> Pow (space (Pi\<^isub>F {I} M))"
  1031   have P_closed: "P \<subseteq> Pow (space (Pi\<^sub>F {I} M))"
  1032     using E_closed by (auto simp: space_PiF P_def Pi'_iff subset_eq)
  1032     using E_closed by (auto simp: space_PiF P_def Pi'_iff subset_eq)
  1033   then have space_P: "space ?P = (\<Pi>' i\<in>I. space (M i))"
  1033   then have space_P: "space ?P = (\<Pi>' i\<in>I. space (M i))"
  1034     by (simp add: space_PiF)
  1034     by (simp add: space_PiF)
  1035   have "sets (PiF {I} M) =
  1035   have "sets (PiF {I} M) =
  1036       sigma_sets (space ?P) {{f \<in> \<Pi>' i\<in>I. space (M i). f i \<in> A} |i A. i \<in> I \<and> A \<in> sets (M i)}"
  1036       sigma_sets (space ?P) {{f \<in> \<Pi>' i\<in>I. space (M i). f i \<in> A} |i A. i \<in> I \<and> A \<in> sets (M i)}"
  1037     using sets_PiF_single[of I M] by (simp add: space_P)
  1037     using sets_PiF_single[of I M] by (simp add: space_P)
  1038   also have "\<dots> \<subseteq> sets (sigma (space (PiF {I} M)) P)"
  1038   also have "\<dots> \<subseteq> sets (sigma (space (PiF {I} M)) P)"
  1039   proof (safe intro!: sets.sigma_sets_subset)
  1039   proof (safe intro!: sets.sigma_sets_subset)
  1040     fix i A assume "i \<in> I" and A: "A \<in> sets (M i)"
  1040     fix i A assume "i \<in> I" and A: "A \<in> sets (M i)"
  1041     have "(\<lambda>x. (x)\<^isub>F i) \<in> measurable ?P (sigma (space (M i)) (E i))"
  1041     have "(\<lambda>x. (x)\<^sub>F i) \<in> measurable ?P (sigma (space (M i)) (E i))"
  1042     proof (subst measurable_iff_measure_of)
  1042     proof (subst measurable_iff_measure_of)
  1043       show "E i \<subseteq> Pow (space (M i))" using `i \<in> I` by fact
  1043       show "E i \<subseteq> Pow (space (M i))" using `i \<in> I` by fact
  1044       from space_P `i \<in> I` show "(\<lambda>x. (x)\<^isub>F i) \<in> space ?P \<rightarrow> space (M i)"
  1044       from space_P `i \<in> I` show "(\<lambda>x. (x)\<^sub>F i) \<in> space ?P \<rightarrow> space (M i)"
  1045         by auto
  1045         by auto
  1046       show "\<forall>A\<in>E i. (\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P \<in> sets ?P"
  1046       show "\<forall>A\<in>E i. (\<lambda>x. (x)\<^sub>F i) -` A \<inter> space ?P \<in> sets ?P"
  1047       proof
  1047       proof
  1048         fix A assume A: "A \<in> E i"
  1048         fix A assume A: "A \<in> E i"
  1049         then have "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P = (\<Pi>' j\<in>I. if i = j then A else space (M j))"
  1049         then have "(\<lambda>x. (x)\<^sub>F i) -` A \<inter> space ?P = (\<Pi>' j\<in>I. if i = j then A else space (M j))"
  1050           using E_closed `i \<in> I` by (auto simp: space_P Pi_iff subset_eq split: split_if_asm)
  1050           using E_closed `i \<in> I` by (auto simp: space_P Pi_iff subset_eq split: split_if_asm)
  1051         also have "\<dots> = (\<Pi>' j\<in>I. \<Union>n. if i = j then A else S j n)"
  1051         also have "\<dots> = (\<Pi>' j\<in>I. \<Union>n. if i = j then A else S j n)"
  1052           by (intro Pi'_cong) (simp_all add: S_union)
  1052           by (intro Pi'_cong) (simp_all add: S_union)
  1053         also have "\<dots> = (\<Union>xs\<in>{xs. length xs = card I}. \<Pi>' j\<in>I. if i = j then A else S j (xs ! T j))"
  1053         also have "\<dots> = (\<Union>xs\<in>{xs. length xs = card I}. \<Pi>' j\<in>I. if i = j then A else S j (xs ! T j))"
  1054           using T
  1054           using T
  1063           fix xs show "(\<Pi>' j\<in>I. if i = j then A else S j (xs ! T j)) \<in> sets ?P"
  1063           fix xs show "(\<Pi>' j\<in>I. if i = j then A else S j (xs ! T j)) \<in> sets ?P"
  1064             using A S_in_E
  1064             using A S_in_E
  1065             by (simp add: P_closed)
  1065             by (simp add: P_closed)
  1066                (auto simp: P_def subset_eq intro!: exI[of _ "\<lambda>j. if i = j then A else S j (xs ! T j)"])
  1066                (auto simp: P_def subset_eq intro!: exI[of _ "\<lambda>j. if i = j then A else S j (xs ! T j)"])
  1067         qed
  1067         qed
  1068         finally show "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P \<in> sets ?P"
  1068         finally show "(\<lambda>x. (x)\<^sub>F i) -` A \<inter> space ?P \<in> sets ?P"
  1069           using P_closed by simp
  1069           using P_closed by simp
  1070       qed
  1070       qed
  1071     qed
  1071     qed
  1072     from measurable_sets[OF this, of A] A `i \<in> I` E_closed
  1072     from measurable_sets[OF this, of A] A `i \<in> I` E_closed
  1073     have "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P \<in> sets ?P"
  1073     have "(\<lambda>x. (x)\<^sub>F i) -` A \<inter> space ?P \<in> sets ?P"
  1074       by (simp add: E_generates)
  1074       by (simp add: E_generates)
  1075     also have "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P = {f \<in> \<Pi>' i\<in>I. space (M i). f i \<in> A}"
  1075     also have "(\<lambda>x. (x)\<^sub>F i) -` A \<inter> space ?P = {f \<in> \<Pi>' i\<in>I. space (M i). f i \<in> A}"
  1076       using P_closed by (auto simp: space_PiF)
  1076       using P_closed by (auto simp: space_PiF)
  1077     finally show "\<dots> \<in> sets ?P" .
  1077     finally show "\<dots> \<in> sets ?P" .
  1078   qed
  1078   qed
  1079   finally show "sets (PiF {I} M) \<subseteq> sigma_sets (space (PiF {I} M)) P"
  1079   finally show "sets (PiF {I} M) \<subseteq> sigma_sets (space (PiF {I} M)) P"
  1080     by (simp add: P_closed)
  1080     by (simp add: P_closed)
  1112 qed
  1112 qed
  1113 
  1113 
  1114 lemma finmap_UNIV[simp]: "(\<Union>J\<in>Collect finite. PI' j : J. UNIV) = UNIV" by auto
  1114 lemma finmap_UNIV[simp]: "(\<Union>J\<in>Collect finite. PI' j : J. UNIV) = UNIV" by auto
  1115 
  1115 
  1116 lemma borel_eq_PiF_borel:
  1116 lemma borel_eq_PiF_borel:
  1117   shows "(borel :: ('i::countable \<Rightarrow>\<^isub>F 'a::polish_space) measure) =
  1117   shows "(borel :: ('i::countable \<Rightarrow>\<^sub>F 'a::polish_space) measure) =
  1118     PiF (Collect finite) (\<lambda>_. borel :: 'a measure)"
  1118     PiF (Collect finite) (\<lambda>_. borel :: 'a measure)"
  1119   unfolding borel_def PiF_def
  1119   unfolding borel_def PiF_def
  1120 proof (rule measure_eqI, clarsimp, rule sigma_sets_eqI)
  1120 proof (rule measure_eqI, clarsimp, rule sigma_sets_eqI)
  1121   fix a::"('i \<Rightarrow>\<^isub>F 'a) set" assume "a \<in> Collect open" hence "open a" by simp
  1121   fix a::"('i \<Rightarrow>\<^sub>F 'a) set" assume "a \<in> Collect open" hence "open a" by simp
  1122   then obtain B' where B': "B'\<subseteq>basis_finmap" "a = \<Union>B'"
  1122   then obtain B' where B': "B'\<subseteq>basis_finmap" "a = \<Union>B'"
  1123     using finmap_topological_basis by (force simp add: topological_basis_def)
  1123     using finmap_topological_basis by (force simp add: topological_basis_def)
  1124   have "a \<in> sigma UNIV {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
  1124   have "a \<in> sigma UNIV {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
  1125     unfolding `a = \<Union>B'`
  1125     unfolding `a = \<Union>B'`
  1126   proof (rule sets.countable_Union)
  1126   proof (rule sets.countable_Union)
  1136     qed
  1136     qed
  1137   qed
  1137   qed
  1138   thus "a \<in> sigma_sets UNIV {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
  1138   thus "a \<in> sigma_sets UNIV {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
  1139     by simp
  1139     by simp
  1140 next
  1140 next
  1141   fix b::"('i \<Rightarrow>\<^isub>F 'a) set"
  1141   fix b::"('i \<Rightarrow>\<^sub>F 'a) set"
  1142   assume "b \<in> {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
  1142   assume "b \<in> {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
  1143   hence b': "b \<in> sets (Pi\<^isub>F (Collect finite) (\<lambda>_. borel))" by (auto simp: sets_PiF borel_def)
  1143   hence b': "b \<in> sets (Pi\<^sub>F (Collect finite) (\<lambda>_. borel))" by (auto simp: sets_PiF borel_def)
  1144   let ?b = "\<lambda>J. b \<inter> {x. domain x = J}"
  1144   let ?b = "\<lambda>J. b \<inter> {x. domain x = J}"
  1145   have "b = \<Union>((\<lambda>J. ?b J) ` Collect finite)" by auto
  1145   have "b = \<Union>((\<lambda>J. ?b J) ` Collect finite)" by auto
  1146   also have "\<dots> \<in> sets borel"
  1146   also have "\<dots> \<in> sets borel"
  1147   proof (rule sets.countable_Union, safe)
  1147   proof (rule sets.countable_Union, safe)
  1148     fix J::"'i set" assume "finite J"
  1148     fix J::"'i set" assume "finite J"
  1200 lemma fm_restrict[simp]: "fm (restrict y J) = fm y"
  1200 lemma fm_restrict[simp]: "fm (restrict y J) = fm y"
  1201   unfolding fm_def by (auto simp: compose_def inv intro: restrict_ext)
  1201   unfolding fm_def by (auto simp: compose_def inv intro: restrict_ext)
  1202 
  1202 
  1203 lemma fm_product:
  1203 lemma fm_product:
  1204   assumes "\<And>i. space (M i) = UNIV"
  1204   assumes "\<And>i. space (M i) = UNIV"
  1205   shows "fm -` Pi' (f ` J) S \<inter> space (Pi\<^isub>M J M) = (\<Pi>\<^isub>E j \<in> J. S (f j))"
  1205   shows "fm -` Pi' (f ` J) S \<inter> space (Pi\<^sub>M J M) = (\<Pi>\<^sub>E j \<in> J. S (f j))"
  1206   using assms
  1206   using assms
  1207   by (auto simp: inv fm_def compose_def space_PiM Pi'_def)
  1207   by (auto simp: inv fm_def compose_def space_PiM Pi'_def)
  1208 
  1208 
  1209 lemma fm_measurable:
  1209 lemma fm_measurable:
  1210   assumes "f ` J \<in> N"
  1210   assumes "f ` J \<in> N"
  1211   shows "fm \<in> measurable (Pi\<^isub>M J (\<lambda>_. M)) (Pi\<^isub>F N (\<lambda>_. M))"
  1211   shows "fm \<in> measurable (Pi\<^sub>M J (\<lambda>_. M)) (Pi\<^sub>F N (\<lambda>_. M))"
  1212   unfolding fm_def
  1212   unfolding fm_def
  1213 proof (rule measurable_comp, rule measurable_compose_inv)
  1213 proof (rule measurable_comp, rule measurable_compose_inv)
  1214   show "finmap_of (f ` J) \<in> measurable (Pi\<^isub>M (f ` J) (\<lambda>_. M)) (PiF N (\<lambda>_. M)) "
  1214   show "finmap_of (f ` J) \<in> measurable (Pi\<^sub>M (f ` J) (\<lambda>_. M)) (PiF N (\<lambda>_. M)) "
  1215     using assms by (intro measurable_finmap_of measurable_component_singleton) auto
  1215     using assms by (intro measurable_finmap_of measurable_component_singleton) auto
  1216 qed (simp_all add: inv)
  1216 qed (simp_all add: inv)
  1217 
  1217 
  1218 lemma proj_fm:
  1218 lemma proj_fm:
  1219   assumes "x \<in> J"
  1219   assumes "x \<in> J"
  1227     by (auto simp: compose_def inv extensional_def)
  1227     by (auto simp: compose_def inv extensional_def)
  1228 qed
  1228 qed
  1229 
  1229 
  1230 lemma inj_on_fm:
  1230 lemma inj_on_fm:
  1231   assumes "\<And>i. space (M i) = UNIV"
  1231   assumes "\<And>i. space (M i) = UNIV"
  1232   shows "inj_on fm (space (Pi\<^isub>M J M))"
  1232   shows "inj_on fm (space (Pi\<^sub>M J M))"
  1233   using assms
  1233   using assms
  1234   apply (auto simp: fm_def space_PiM PiE_def)
  1234   apply (auto simp: fm_def space_PiM PiE_def)
  1235   apply (rule comp_inj_on)
  1235   apply (rule comp_inj_on)
  1236   apply (rule inj_on_compose_f')
  1236   apply (rule inj_on_compose_f')
  1237   apply (rule finmap_of_inj_on_extensional_finite)
  1237   apply (rule finmap_of_inj_on_extensional_finite)
  1242 text {* to measure functions *}
  1242 text {* to measure functions *}
  1243 
  1243 
  1244 definition "mf = (\<lambda>g. compose J g f) o proj"
  1244 definition "mf = (\<lambda>g. compose J g f) o proj"
  1245 
  1245 
  1246 lemma mf_fm:
  1246 lemma mf_fm:
  1247   assumes "x \<in> space (Pi\<^isub>M J (\<lambda>_. M))"
  1247   assumes "x \<in> space (Pi\<^sub>M J (\<lambda>_. M))"
  1248   shows "mf (fm x) = x"
  1248   shows "mf (fm x) = x"
  1249 proof -
  1249 proof -
  1250   have "mf (fm x) \<in> extensional J"
  1250   have "mf (fm x) \<in> extensional J"
  1251     by (auto simp: mf_def extensional_def compose_def)
  1251     by (auto simp: mf_def extensional_def compose_def)
  1252   moreover
  1252   moreover
  1264 lemma mf_measurable:
  1264 lemma mf_measurable:
  1265   assumes "space M = UNIV"
  1265   assumes "space M = UNIV"
  1266   shows "mf \<in> measurable (PiF {f ` J} (\<lambda>_. M)) (PiM J (\<lambda>_. M))"
  1266   shows "mf \<in> measurable (PiF {f ` J} (\<lambda>_. M)) (PiM J (\<lambda>_. M))"
  1267   unfolding mf_def
  1267   unfolding mf_def
  1268 proof (rule measurable_comp, rule measurable_proj_PiM)
  1268 proof (rule measurable_comp, rule measurable_proj_PiM)
  1269   show "(\<lambda>g. compose J g f) \<in> measurable (Pi\<^isub>M (f ` J) (\<lambda>x. M)) (Pi\<^isub>M J (\<lambda>_. M))"
  1269   show "(\<lambda>g. compose J g f) \<in> measurable (Pi\<^sub>M (f ` J) (\<lambda>x. M)) (Pi\<^sub>M J (\<lambda>_. M))"
  1270     by (rule measurable_finmap_compose)
  1270     by (rule measurable_finmap_compose)
  1271 qed (auto simp add: space_PiM extensional_def assms)
  1271 qed (auto simp add: space_PiM extensional_def assms)
  1272 
  1272 
  1273 lemma fm_image_measurable:
  1273 lemma fm_image_measurable:
  1274   assumes "space M = UNIV"
  1274   assumes "space M = UNIV"
  1275   assumes "X \<in> sets (Pi\<^isub>M J (\<lambda>_. M))"
  1275   assumes "X \<in> sets (Pi\<^sub>M J (\<lambda>_. M))"
  1276   shows "fm ` X \<in> sets (PiF {f ` J} (\<lambda>_. M))"
  1276   shows "fm ` X \<in> sets (PiF {f ` J} (\<lambda>_. M))"
  1277 proof -
  1277 proof -
  1278   have "fm ` X = (mf) -` X \<inter> space (PiF {f ` J} (\<lambda>_. M))"
  1278   have "fm ` X = (mf) -` X \<inter> space (PiF {f ` J} (\<lambda>_. M))"
  1279   proof safe
  1279   proof safe
  1280     fix x assume "x \<in> X"
  1280     fix x assume "x \<in> X"
  1294   finally show ?thesis .
  1294   finally show ?thesis .
  1295 qed
  1295 qed
  1296 
  1296 
  1297 lemma fm_image_measurable_finite:
  1297 lemma fm_image_measurable_finite:
  1298   assumes "space M = UNIV"
  1298   assumes "space M = UNIV"
  1299   assumes "X \<in> sets (Pi\<^isub>M J (\<lambda>_. M::'c measure))"
  1299   assumes "X \<in> sets (Pi\<^sub>M J (\<lambda>_. M::'c measure))"
  1300   shows "fm ` X \<in> sets (PiF (Collect finite) (\<lambda>_. M::'c measure))"
  1300   shows "fm ` X \<in> sets (PiF (Collect finite) (\<lambda>_. M::'c measure))"
  1301   using fm_image_measurable[OF assms]
  1301   using fm_image_measurable[OF assms]
  1302   by (rule subspace_set_in_sets) (auto simp: finite_subset)
  1302   by (rule subspace_set_in_sets) (auto simp: finite_subset)
  1303 
  1303 
  1304 text {* measure on finmaps *}
  1304 text {* measure on finmaps *}
  1310 
  1310 
  1311 lemma space_mapmeasure[simp]: "space (mapmeasure M N) = space (PiF (Collect finite) N)"
  1311 lemma space_mapmeasure[simp]: "space (mapmeasure M N) = space (PiF (Collect finite) N)"
  1312   unfolding mapmeasure_def by simp
  1312   unfolding mapmeasure_def by simp
  1313 
  1313 
  1314 lemma mapmeasure_PiF:
  1314 lemma mapmeasure_PiF:
  1315   assumes s1: "space M = space (Pi\<^isub>M J (\<lambda>_. N))"
  1315   assumes s1: "space M = space (Pi\<^sub>M J (\<lambda>_. N))"
  1316   assumes s2: "sets M = sets (Pi\<^isub>M J (\<lambda>_. N))"
  1316   assumes s2: "sets M = sets (Pi\<^sub>M J (\<lambda>_. N))"
  1317   assumes "space N = UNIV"
  1317   assumes "space N = UNIV"
  1318   assumes "X \<in> sets (PiF (Collect finite) (\<lambda>_. N))"
  1318   assumes "X \<in> sets (PiF (Collect finite) (\<lambda>_. N))"
  1319   shows "emeasure (mapmeasure M (\<lambda>_. N)) X = emeasure M ((fm -` X \<inter> extensional J))"
  1319   shows "emeasure (mapmeasure M (\<lambda>_. N)) X = emeasure M ((fm -` X \<inter> extensional J))"
  1320   using assms
  1320   using assms
  1321   by (auto simp: measurable_eqI[OF s1 refl s2 refl] mapmeasure_def emeasure_distr
  1321   by (auto simp: measurable_eqI[OF s1 refl s2 refl] mapmeasure_def emeasure_distr
  1322     fm_measurable space_PiM PiE_def)
  1322     fm_measurable space_PiM PiE_def)
  1323 
  1323 
  1324 lemma mapmeasure_PiM:
  1324 lemma mapmeasure_PiM:
  1325   fixes N::"'c measure"
  1325   fixes N::"'c measure"
  1326   assumes s1: "space M = space (Pi\<^isub>M J (\<lambda>_. N))"
  1326   assumes s1: "space M = space (Pi\<^sub>M J (\<lambda>_. N))"
  1327   assumes s2: "sets M = (Pi\<^isub>M J (\<lambda>_. N))"
  1327   assumes s2: "sets M = (Pi\<^sub>M J (\<lambda>_. N))"
  1328   assumes N: "space N = UNIV"
  1328   assumes N: "space N = UNIV"
  1329   assumes X: "X \<in> sets M"
  1329   assumes X: "X \<in> sets M"
  1330   shows "emeasure M X = emeasure (mapmeasure M (\<lambda>_. N)) (fm ` X)"
  1330   shows "emeasure M X = emeasure (mapmeasure M (\<lambda>_. N)) (fm ` X)"
  1331   unfolding mapmeasure_def
  1331   unfolding mapmeasure_def
  1332 proof (subst emeasure_distr, subst measurable_eqI[OF s1 refl s2 refl], rule fm_measurable)
  1332 proof (subst emeasure_distr, subst measurable_eqI[OF s1 refl s2 refl], rule fm_measurable)
  1333   have "X \<subseteq> space (Pi\<^isub>M J (\<lambda>_. N))" using assms by (simp add: sets.sets_into_space)
  1333   have "X \<subseteq> space (Pi\<^sub>M J (\<lambda>_. N))" using assms by (simp add: sets.sets_into_space)
  1334   from assms inj_on_fm[of "\<lambda>_. N"] set_mp[OF this] have "fm -` fm ` X \<inter> space (Pi\<^isub>M J (\<lambda>_. N)) = X"
  1334   from assms inj_on_fm[of "\<lambda>_. N"] set_mp[OF this] have "fm -` fm ` X \<inter> space (Pi\<^sub>M J (\<lambda>_. N)) = X"
  1335     by (auto simp: vimage_image_eq inj_on_def)
  1335     by (auto simp: vimage_image_eq inj_on_def)
  1336   thus "emeasure M X = emeasure M (fm -` fm ` X \<inter> space M)" using s1
  1336   thus "emeasure M X = emeasure M (fm -` fm ` X \<inter> space M)" using s1
  1337     by simp
  1337     by simp
  1338   show "fm ` X \<in> sets (PiF (Collect finite) (\<lambda>_. N))"
  1338   show "fm ` X \<in> sets (PiF (Collect finite) (\<lambda>_. N))"
  1339     by (rule fm_image_measurable_finite[OF N X[simplified s2]])
  1339     by (rule fm_image_measurable_finite[OF N X[simplified s2]])