src/HOL/Probability/Fin_Map.thy
author immler
Wed Feb 13 16:35:07 2013 +0100 (2013-02-13)
changeset 51104 59b574c6f803
parent 50881 ae630bab13da
child 51105 a27fcd14c384
permissions -rw-r--r--
use maximum norm for type finmap
immler@50091
     1
(*  Title:      HOL/Probability/Fin_Map.thy
immler@50088
     2
    Author:     Fabian Immler, TU M√ľnchen
immler@50088
     3
*)
immler@50088
     4
immler@50091
     5
header {* Finite Maps *}
immler@50091
     6
immler@50088
     7
theory Fin_Map
immler@50088
     8
imports Finite_Product_Measure
immler@50088
     9
begin
immler@50088
    10
immler@50088
    11
text {* Auxiliary type that is instantiated to @{class polish_space}, needed for the proof of
immler@50088
    12
  projective limit. @{const extensional} functions are used for the representation in order to
immler@50088
    13
  stay close to the developments of (finite) products @{const Pi\<^isub>E} and their sigma-algebra
immler@50088
    14
  @{const Pi\<^isub>M}. *}
immler@50088
    15
immler@50088
    16
typedef ('i, 'a) finmap ("(_ \<Rightarrow>\<^isub>F /_)" [22, 21] 21) =
immler@50088
    17
  "{(I::'i set, f::'i \<Rightarrow> 'a). finite I \<and> f \<in> extensional I}" by auto
immler@50088
    18
immler@50088
    19
subsection {* Domain and Application *}
immler@50088
    20
immler@50088
    21
definition domain where "domain P = fst (Rep_finmap P)"
immler@50088
    22
immler@50088
    23
lemma finite_domain[simp, intro]: "finite (domain P)"
immler@50088
    24
  by (cases P) (auto simp: domain_def Abs_finmap_inverse)
immler@50088
    25
wenzelm@50251
    26
definition proj ("'((_)')\<^isub>F" [0] 1000) where "proj P i = snd (Rep_finmap P) i"
immler@50088
    27
immler@50088
    28
declare [[coercion proj]]
immler@50088
    29
immler@50088
    30
lemma extensional_proj[simp, intro]: "(P)\<^isub>F \<in> extensional (domain P)"
immler@50088
    31
  by (cases P) (auto simp: domain_def Abs_finmap_inverse proj_def[abs_def])
immler@50088
    32
immler@50088
    33
lemma proj_undefined[simp, intro]: "i \<notin> domain P \<Longrightarrow> P i = undefined"
immler@50088
    34
  using extensional_proj[of P] unfolding extensional_def by auto
immler@50088
    35
immler@50088
    36
lemma finmap_eq_iff: "P = Q \<longleftrightarrow> (domain P = domain Q \<and> (\<forall>i\<in>domain P. P i = Q i))"
immler@50088
    37
  by (cases P, cases Q)
immler@50088
    38
     (auto simp add: Abs_finmap_inject extensional_def domain_def proj_def Abs_finmap_inverse
immler@50088
    39
              intro: extensionalityI)
immler@50088
    40
immler@50088
    41
subsection {* Countable Finite Maps *}
immler@50088
    42
immler@50088
    43
instance finmap :: (countable, countable) countable
immler@50088
    44
proof
immler@50088
    45
  obtain mapper where mapper: "\<And>fm :: 'a \<Rightarrow>\<^isub>F 'b. set (mapper fm) = domain fm"
immler@50088
    46
    by (metis finite_list[OF finite_domain])
immler@50088
    47
  have "inj (\<lambda>fm. map (\<lambda>i. (i, (fm)\<^isub>F i)) (mapper fm))" (is "inj ?F")
immler@50088
    48
  proof (rule inj_onI)
immler@50088
    49
    fix f1 f2 assume "?F f1 = ?F f2"
immler@50088
    50
    then have "map fst (?F f1) = map fst (?F f2)" by simp
immler@50088
    51
    then have "mapper f1 = mapper f2" by (simp add: comp_def)
immler@50088
    52
    then have "domain f1 = domain f2" by (simp add: mapper[symmetric])
immler@50088
    53
    with `?F f1 = ?F f2` show "f1 = f2"
immler@50088
    54
      unfolding `mapper f1 = mapper f2` map_eq_conv mapper
immler@50088
    55
      by (simp add: finmap_eq_iff)
immler@50088
    56
  qed
immler@50088
    57
  then show "\<exists>to_nat :: 'a \<Rightarrow>\<^isub>F 'b \<Rightarrow> nat. inj to_nat"
immler@50088
    58
    by (intro exI[of _ "to_nat \<circ> ?F"] inj_comp) auto
immler@50088
    59
qed
immler@50088
    60
immler@50088
    61
subsection {* Constructor of Finite Maps *}
immler@50088
    62
immler@50088
    63
definition "finmap_of inds f = Abs_finmap (inds, restrict f inds)"
immler@50088
    64
immler@50088
    65
lemma proj_finmap_of[simp]:
immler@50088
    66
  assumes "finite inds"
immler@50088
    67
  shows "(finmap_of inds f)\<^isub>F = restrict f inds"
immler@50088
    68
  using assms
immler@50088
    69
  by (auto simp: Abs_finmap_inverse finmap_of_def proj_def)
immler@50088
    70
immler@50088
    71
lemma domain_finmap_of[simp]:
immler@50088
    72
  assumes "finite inds"
immler@50088
    73
  shows "domain (finmap_of inds f) = inds"
immler@50088
    74
  using assms
immler@50088
    75
  by (auto simp: Abs_finmap_inverse finmap_of_def domain_def)
immler@50088
    76
immler@50088
    77
lemma finmap_of_eq_iff[simp]:
immler@50088
    78
  assumes "finite i" "finite j"
immler@51104
    79
  shows "finmap_of i m = finmap_of j n \<longleftrightarrow> i = j \<and> (\<forall>k\<in>i. m k= n k)"
immler@51104
    80
  using assms by (auto simp: finmap_eq_iff)
immler@50088
    81
hoelzl@50124
    82
lemma finmap_of_inj_on_extensional_finite:
immler@50088
    83
  assumes "finite K"
immler@50088
    84
  assumes "S \<subseteq> extensional K"
immler@50088
    85
  shows "inj_on (finmap_of K) S"
immler@50088
    86
proof (rule inj_onI)
immler@50088
    87
  fix x y::"'a \<Rightarrow> 'b"
immler@50088
    88
  assume "finmap_of K x = finmap_of K y"
immler@50088
    89
  hence "(finmap_of K x)\<^isub>F = (finmap_of K y)\<^isub>F" by simp
immler@50088
    90
  moreover
immler@50088
    91
  assume "x \<in> S" "y \<in> S" hence "x \<in> extensional K" "y \<in> extensional K" using assms by auto
immler@50088
    92
  ultimately
immler@50088
    93
  show "x = y" using assms by (simp add: extensional_restrict)
immler@50088
    94
qed
immler@50088
    95
immler@50088
    96
lemma finmap_choice:
immler@50088
    97
  assumes *: "\<And>i. i \<in> I \<Longrightarrow> \<exists>x. P i x" and I: "finite I"
immler@50088
    98
  shows "\<exists>fm. domain fm = I \<and> (\<forall>i\<in>I. P i (fm i))"
immler@50088
    99
proof -
immler@50088
   100
  have "\<exists>f. \<forall>i\<in>I. P i (f i)"
immler@50088
   101
    unfolding bchoice_iff[symmetric] using * by auto
immler@50088
   102
  then guess f ..
immler@50088
   103
  with I show ?thesis
immler@50088
   104
    by (intro exI[of _ "finmap_of I f"]) auto
immler@50088
   105
qed
immler@50088
   106
immler@50088
   107
subsection {* Product set of Finite Maps *}
immler@50088
   108
immler@50088
   109
text {* This is @{term Pi} for Finite Maps, most of this is copied *}
immler@50088
   110
immler@50088
   111
definition Pi' :: "'i set \<Rightarrow> ('i \<Rightarrow> 'a set) \<Rightarrow> ('i \<Rightarrow>\<^isub>F 'a) set" where
immler@50088
   112
  "Pi' I A = { P. domain P = I \<and> (\<forall>i. i \<in> I \<longrightarrow> (P)\<^isub>F i \<in> A i) } "
immler@50088
   113
immler@50088
   114
syntax
immler@50088
   115
  "_Pi'"  :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3PI' _:_./ _)" 10)
immler@50088
   116
immler@50088
   117
syntax (xsymbols)
immler@50088
   118
  "_Pi'" :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3\<Pi>' _\<in>_./ _)"   10)
immler@50088
   119
immler@50088
   120
syntax (HTML output)
immler@50088
   121
  "_Pi'" :: "[pttrn, 'a set, 'b set] => ('a => 'b) set"  ("(3\<Pi>' _\<in>_./ _)"   10)
immler@50088
   122
immler@50088
   123
translations
immler@50088
   124
  "PI' x:A. B" == "CONST Pi' A (%x. B)"
immler@50088
   125
immler@50088
   126
subsubsection{*Basic Properties of @{term Pi'}*}
immler@50088
   127
immler@50088
   128
lemma Pi'_I[intro!]: "domain f = A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<in> B x) \<Longrightarrow> f \<in> Pi' A B"
immler@50088
   129
  by (simp add: Pi'_def)
immler@50088
   130
immler@50088
   131
lemma Pi'_I'[simp]: "domain f = A \<Longrightarrow> (\<And>x. x \<in> A \<longrightarrow> f x \<in> B x) \<Longrightarrow> f \<in> Pi' A B"
immler@50088
   132
  by (simp add:Pi'_def)
immler@50088
   133
immler@50088
   134
lemma Pi'_mem: "f\<in> Pi' A B \<Longrightarrow> x \<in> A \<Longrightarrow> f x \<in> B x"
immler@50088
   135
  by (simp add: Pi'_def)
immler@50088
   136
immler@50088
   137
lemma Pi'_iff: "f \<in> Pi' I X \<longleftrightarrow> domain f = I \<and> (\<forall>i\<in>I. f i \<in> X i)"
immler@50088
   138
  unfolding Pi'_def by auto
immler@50088
   139
immler@50088
   140
lemma Pi'E [elim]:
immler@50088
   141
  "f \<in> Pi' A B \<Longrightarrow> (f x \<in> B x \<Longrightarrow> domain f = A \<Longrightarrow> Q) \<Longrightarrow> (x \<notin> A \<Longrightarrow> Q) \<Longrightarrow> Q"
immler@50088
   142
  by(auto simp: Pi'_def)
immler@50088
   143
immler@50088
   144
lemma in_Pi'_cong:
immler@50088
   145
  "domain f = domain g \<Longrightarrow> (\<And> w. w \<in> A \<Longrightarrow> f w = g w) \<Longrightarrow> f \<in> Pi' A B \<longleftrightarrow> g \<in> Pi' A B"
immler@50088
   146
  by (auto simp: Pi'_def)
immler@50088
   147
immler@50088
   148
lemma Pi'_eq_empty[simp]:
immler@50088
   149
  assumes "finite A" shows "(Pi' A B) = {} \<longleftrightarrow> (\<exists>x\<in>A. B x = {})"
immler@50088
   150
  using assms
immler@50088
   151
  apply (simp add: Pi'_def, auto)
immler@50088
   152
  apply (drule_tac x = "finmap_of A (\<lambda>u. SOME y. y \<in> B u)" in spec, auto)
immler@50088
   153
  apply (cut_tac P= "%y. y \<in> B i" in some_eq_ex, auto)
immler@50088
   154
  done
immler@50088
   155
immler@50088
   156
lemma Pi'_mono: "(\<And>x. x \<in> A \<Longrightarrow> B x \<subseteq> C x) \<Longrightarrow> Pi' A B \<subseteq> Pi' A C"
immler@50088
   157
  by (auto simp: Pi'_def)
immler@50088
   158
immler@50088
   159
lemma Pi_Pi': "finite A \<Longrightarrow> (Pi\<^isub>E A B) = proj ` Pi' A B"
immler@50088
   160
  apply (auto simp: Pi'_def Pi_def extensional_def)
immler@50088
   161
  apply (rule_tac x = "finmap_of A (restrict x A)" in image_eqI)
immler@50088
   162
  apply auto
immler@50088
   163
  done
immler@50088
   164
immler@50088
   165
subsection {* Metric Space of Finite Maps *}
immler@50088
   166
immler@50088
   167
instantiation finmap :: (type, metric_space) metric_space
immler@50088
   168
begin
immler@50088
   169
immler@50088
   170
definition dist_finmap where
immler@51104
   171
  "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)"
immler@50088
   172
immler@50088
   173
definition open_finmap :: "('a \<Rightarrow>\<^isub>F 'b) set \<Rightarrow> bool" where
immler@50088
   174
  "open_finmap S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
immler@50088
   175
immler@50088
   176
lemma add_eq_zero_iff[simp]:
immler@50088
   177
  fixes a b::real
immler@50088
   178
  assumes "a \<ge> 0" "b \<ge> 0"
immler@50088
   179
  shows "a + b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
immler@50088
   180
using assms by auto
immler@50088
   181
immler@51104
   182
lemma finite_proj_image': "x \<notin> domain P \<Longrightarrow> finite ((P)\<^isub>F ` S)"
immler@51104
   183
  by (rule finite_subset[of _ "proj P ` (domain P \<inter> S \<union> {x})"]) auto
immler@51104
   184
immler@51104
   185
lemma finite_proj_image: "finite ((P)\<^isub>F ` S)"
immler@51104
   186
 by (cases "\<exists>x. x \<notin> domain P") (auto intro: finite_proj_image' finite_subset[where B="domain P"])
immler@51104
   187
immler@51104
   188
lemma finite_proj_diag: "finite ((\<lambda>i. d ((P)\<^isub>F i) ((Q)\<^isub>F i)) ` S)"
immler@50088
   189
proof -
immler@51104
   190
  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
immler@51104
   191
  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
immler@51104
   192
  moreover have "finite \<dots>" using finite_proj_image[of P S] finite_proj_image[of Q S]
immler@51104
   193
    by (intro finite_cartesian_product) simp_all
immler@51104
   194
  ultimately show ?thesis by (simp add: finite_subset)
immler@50088
   195
qed
immler@50088
   196
immler@51104
   197
lemma dist_le_1_imp_domain_eq:
immler@51104
   198
  shows "dist P Q < 1 \<Longrightarrow> domain P = domain Q"
immler@51104
   199
  by (simp add: dist_finmap_def finite_proj_diag split: split_if_asm)
immler@51104
   200
immler@50088
   201
lemma dist_proj:
immler@50088
   202
  shows "dist ((x)\<^isub>F i) ((y)\<^isub>F i) \<le> dist x y"
immler@50088
   203
proof -
immler@51104
   204
  have "dist (x i) (y i) \<le> Max (range (\<lambda>i. dist (x i) (y i)))"
immler@51104
   205
    by (simp add: Max_ge_iff finite_proj_diag)
immler@51104
   206
  also have "\<dots> \<le> dist x y" by (simp add: dist_finmap_def)
immler@51104
   207
  finally show ?thesis .
immler@51104
   208
qed
immler@51104
   209
immler@51104
   210
lemma dist_finmap_lessI:
immler@51104
   211
  assumes "domain P = domain Q" "0 < e" "\<And>i. i \<in> domain P \<Longrightarrow> dist (P i) (Q i) < e"
immler@51104
   212
  shows "dist P Q < e"
immler@51104
   213
proof -
immler@51104
   214
  have "dist P Q = Max (range (\<lambda>i. dist (P i) (Q i)))"
immler@51104
   215
    using assms by (simp add: dist_finmap_def finite_proj_diag)
immler@51104
   216
  also have "\<dots> < e"
immler@51104
   217
  proof (subst Max_less_iff, safe)
immler@51104
   218
    fix i show "dist ((P)\<^isub>F i) ((Q)\<^isub>F i) < e" using assms by (cases "i \<in> domain P") simp_all
immler@51104
   219
  qed (simp add: finite_proj_diag)
immler@51104
   220
  finally show ?thesis .
immler@50088
   221
qed
immler@50088
   222
immler@50088
   223
lemma open_Pi'I:
immler@50088
   224
  assumes open_component: "\<And>i. i \<in> I \<Longrightarrow> open (A i)"
immler@50088
   225
  shows "open (Pi' I A)"
immler@50088
   226
proof (subst open_finmap_def, safe)
immler@50088
   227
  fix x assume x: "x \<in> Pi' I A"
immler@50088
   228
  hence dim_x: "domain x = I" by (simp add: Pi'_def)
immler@50088
   229
  hence [simp]: "finite I" unfolding dim_x[symmetric] by simp
immler@50088
   230
  have "\<exists>ei. \<forall>i\<in>I. 0 < ei i \<and> (\<forall>y. dist y (x i) < ei i \<longrightarrow> y \<in> A i)"
immler@50088
   231
  proof (safe intro!: bchoice)
immler@50088
   232
    fix i assume i: "i \<in> I"
immler@50088
   233
    moreover with open_component have "open (A i)" by simp
immler@50088
   234
    moreover have "x i \<in> A i" using x i
immler@50088
   235
      by (auto simp: proj_def)
immler@50088
   236
    ultimately show "\<exists>e>0. \<forall>y. dist y (x i) < e \<longrightarrow> y \<in> A i"
immler@50088
   237
      using x by (auto simp: open_dist Ball_def)
immler@50088
   238
  qed
immler@50088
   239
  then guess ei .. note ei = this
immler@50088
   240
  def es \<equiv> "ei ` I"
immler@50088
   241
  def e \<equiv> "if es = {} then 0.5 else min 0.5 (Min es)"
immler@50088
   242
  from ei have "e > 0" using x
immler@50088
   243
    by (auto simp add: e_def es_def Pi'_def Ball_def)
immler@50088
   244
  moreover have "\<forall>y. dist y x < e \<longrightarrow> y \<in> Pi' I A"
immler@50088
   245
  proof (intro allI impI)
immler@50088
   246
    fix y
immler@50088
   247
    assume "dist y x < e"
immler@50088
   248
    also have "\<dots> < 1" by (auto simp: e_def)
immler@50088
   249
    finally have "domain y = domain x" by (rule dist_le_1_imp_domain_eq)
immler@50088
   250
    with dim_x have dims: "domain y = domain x" "domain x = I" by auto
immler@50088
   251
    show "y \<in> Pi' I A"
immler@50088
   252
    proof
immler@50088
   253
      show "domain y = I" using dims by simp
immler@50088
   254
    next
immler@50088
   255
      fix i
immler@50088
   256
      assume "i \<in> I"
immler@50088
   257
      have "dist (y i) (x i) \<le> dist y x" using dims `i \<in> I`
immler@50088
   258
        by (auto intro: dist_proj)
immler@50088
   259
      also have "\<dots> < e" using `dist y x < e` dims
immler@50088
   260
        by (simp add: dist_finmap_def)
immler@50088
   261
      also have "e \<le> Min (ei ` I)" using dims `i \<in> I`
immler@50088
   262
        by (auto simp: e_def es_def)
immler@50088
   263
      also have "\<dots> \<le> ei i" using `i \<in> I` by (simp add: e_def)
immler@50088
   264
      finally have "dist (y i) (x i) < ei i" .
immler@50088
   265
      with ei `i \<in> I` show "y i \<in> A  i" by simp
immler@50088
   266
    qed
immler@50088
   267
  qed
immler@50088
   268
  ultimately
immler@50088
   269
  show "\<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> Pi' I A" by blast
immler@50088
   270
qed
immler@50088
   271
immler@50088
   272
instance
immler@50088
   273
proof
immler@50088
   274
  fix S::"('a \<Rightarrow>\<^isub>F 'b) set"
immler@50088
   275
  show "open S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
immler@50088
   276
    unfolding open_finmap_def ..
immler@50088
   277
next
immler@50088
   278
  fix P Q::"'a \<Rightarrow>\<^isub>F 'b"
immler@51104
   279
  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))"
immler@51104
   280
    by (metis Max.in_idem Max_in max_def min_max.sup.commute order_refl)
immler@50088
   281
  show "dist P Q = 0 \<longleftrightarrow> P = Q"
immler@51104
   282
    by (auto simp: finmap_eq_iff dist_finmap_def Max_ge_iff finite_proj_diag Max_eq_iff
immler@51104
   283
      intro!: Max_eqI image_eqI[where x=undefined])
immler@50088
   284
next
immler@50088
   285
  fix P Q R::"'a \<Rightarrow>\<^isub>F 'b"
immler@51104
   286
  let ?dists = "\<lambda>P Q i. dist ((P)\<^isub>F i) ((Q)\<^isub>F i)"
immler@51104
   287
  let ?dpq = "?dists P Q" and ?dpr = "?dists P R" and ?dqr = "?dists Q R"
immler@51104
   288
  let ?dom = "\<lambda>P Q. (if domain P = domain Q then 0 else 1::real)"
immler@51104
   289
  have "dist P Q = Max (range ?dpq) + ?dom P Q"
immler@51104
   290
    by (simp add: dist_finmap_def)
immler@51104
   291
  also obtain t where "t \<in> range ?dpq" "t = Max (range ?dpq)" by (simp add: finite_proj_diag)
immler@51104
   292
  then obtain i where "Max (range ?dpq) = ?dpq i" by auto
immler@51104
   293
  also have "?dpq i \<le> ?dpr i + ?dqr i" by (rule dist_triangle2)
immler@51104
   294
  also have "?dpr i \<le> Max (range ?dpr)" by (simp add: finite_proj_diag)
immler@51104
   295
  also have "?dqr i \<le> Max (range ?dqr)" by (simp add: finite_proj_diag)
immler@51104
   296
  also have "?dom P Q \<le> ?dom P R + ?dom Q R" by simp
immler@51104
   297
  finally show "dist P Q \<le> dist P R + dist Q R" by (simp add: dist_finmap_def ac_simps)
immler@50088
   298
qed
immler@50088
   299
immler@50088
   300
end
immler@50088
   301
immler@50088
   302
lemma open_restricted_space:
immler@50088
   303
  shows "open {m. P (domain m)}"
immler@50088
   304
proof -
immler@50088
   305
  have "{m. P (domain m)} = (\<Union>i \<in> Collect P. {m. domain m = i})" by auto
immler@50088
   306
  also have "open \<dots>"
immler@50088
   307
  proof (rule, safe, cases)
immler@50088
   308
    fix i::"'a set"
immler@50088
   309
    assume "finite i"
immler@50088
   310
    hence "{m. domain m = i} = Pi' i (\<lambda>_. UNIV)" by (auto simp: Pi'_def)
immler@50088
   311
    also have "open \<dots>" by (auto intro: open_Pi'I simp: `finite i`)
immler@50088
   312
    finally show "open {m. domain m = i}" .
immler@50088
   313
  next
immler@50088
   314
    fix i::"'a set"
immler@50088
   315
    assume "\<not> finite i" hence "{m. domain m = i} = {}" by auto
immler@50088
   316
    also have "open \<dots>" by simp
immler@50088
   317
    finally show "open {m. domain m = i}" .
immler@50088
   318
  qed
immler@50088
   319
  finally show ?thesis .
immler@50088
   320
qed
immler@50088
   321
immler@50088
   322
lemma closed_restricted_space:
immler@50088
   323
  shows "closed {m. P (domain m)}"
immler@50088
   324
proof -
immler@50088
   325
  have "{m. P (domain m)} = - (\<Union>i \<in> - Collect P. {m. domain m = i})" by auto
immler@50088
   326
  also have "closed \<dots>"
immler@50088
   327
  proof (rule, rule, rule, cases)
immler@50088
   328
    fix i::"'a set"
immler@50088
   329
    assume "finite i"
immler@50088
   330
    hence "{m. domain m = i} = Pi' i (\<lambda>_. UNIV)" by (auto simp: Pi'_def)
immler@50088
   331
    also have "open \<dots>" by (auto intro: open_Pi'I simp: `finite i`)
immler@50088
   332
    finally show "open {m. domain m = i}" .
immler@50088
   333
  next
immler@50088
   334
    fix i::"'a set"
immler@50088
   335
    assume "\<not> finite i" hence "{m. domain m = i} = {}" by auto
immler@50088
   336
    also have "open \<dots>" by simp
immler@50088
   337
    finally show "open {m. domain m = i}" .
immler@50088
   338
  qed
immler@50088
   339
  finally show ?thesis .
immler@50088
   340
qed
immler@50088
   341
immler@50088
   342
lemma continuous_proj:
immler@50088
   343
  shows "continuous_on s (\<lambda>x. (x)\<^isub>F i)"
immler@50088
   344
  unfolding continuous_on_topological
immler@50088
   345
proof safe
immler@50088
   346
  fix x B assume "x \<in> s" "open B" "x i \<in> B"
immler@50088
   347
  let ?A = "Pi' (domain x) (\<lambda>j. if i = j then B else UNIV)"
immler@50088
   348
  have "open ?A" using `open B` by (auto intro: open_Pi'I)
immler@50088
   349
  moreover have "x \<in> ?A" using `x i \<in> B` by auto
immler@50088
   350
  moreover have "(\<forall>y\<in>s. y \<in> ?A \<longrightarrow> y i \<in> B)"
immler@50088
   351
  proof (cases, safe)
immler@50088
   352
    fix y assume "y \<in> s"
immler@50088
   353
    assume "i \<notin> domain x" hence "undefined \<in> B" using `x i \<in> B`
immler@50088
   354
      by simp
immler@50088
   355
    moreover
immler@50088
   356
    assume "y \<in> ?A" hence "domain y = domain x" by (simp add: Pi'_def)
immler@50088
   357
    hence "y i = undefined" using `i \<notin> domain x` by simp
immler@50088
   358
    ultimately
immler@50088
   359
    show "y i \<in> B" by simp
immler@50088
   360
  qed force
immler@50088
   361
  ultimately
immler@50088
   362
  show "\<exists>A. open A \<and> x \<in> A \<and> (\<forall>y\<in>s. y \<in> A \<longrightarrow> y i \<in> B)" by blast
immler@50088
   363
qed
immler@50088
   364
immler@50088
   365
subsection {* Complete Space of Finite Maps *}
immler@50088
   366
immler@50088
   367
lemma tendsto_finmap:
immler@50088
   368
  fixes f::"nat \<Rightarrow> ('i \<Rightarrow>\<^isub>F ('a::metric_space))"
immler@50088
   369
  assumes ind_f:  "\<And>n. domain (f n) = domain g"
immler@50088
   370
  assumes proj_g:  "\<And>i. i \<in> domain g \<Longrightarrow> (\<lambda>n. (f n) i) ----> g i"
immler@50088
   371
  shows "f ----> g"
immler@51104
   372
  unfolding tendsto_iff
immler@51104
   373
proof safe
immler@51104
   374
  fix e::real assume "0 < e"
immler@51104
   375
  let ?dists = "\<lambda>x i. dist ((f x)\<^isub>F i) ((g)\<^isub>F i)"
immler@51104
   376
  have "eventually (\<lambda>x. \<forall>i\<in>domain g. ?dists x i < e) sequentially"
immler@51104
   377
    using finite_domain[of g] proj_g
immler@51104
   378
  proof induct
immler@51104
   379
    case (insert i G)
immler@51104
   380
    with `0 < e` have "eventually (\<lambda>x. ?dists x i < e) sequentially" by (auto simp add: tendsto_iff)
immler@51104
   381
    moreover
immler@51104
   382
    from insert have "eventually (\<lambda>x. \<forall>i\<in>G. dist ((f x)\<^isub>F i) ((g)\<^isub>F i) < e) sequentially" by simp
immler@51104
   383
    ultimately show ?case by eventually_elim auto
immler@51104
   384
  qed simp
immler@51104
   385
  thus "eventually (\<lambda>x. dist (f x) g < e) sequentially"
immler@51104
   386
    by eventually_elim (auto simp add: dist_finmap_def finite_proj_diag ind_f `0 < e`)
immler@51104
   387
qed
immler@50088
   388
immler@50088
   389
instance finmap :: (type, complete_space) complete_space
immler@50088
   390
proof
immler@50088
   391
  fix P::"nat \<Rightarrow> 'a \<Rightarrow>\<^isub>F 'b"
immler@50088
   392
  assume "Cauchy P"
immler@50088
   393
  then obtain Nd where Nd: "\<And>n. n \<ge> Nd \<Longrightarrow> dist (P n) (P Nd) < 1"
immler@50088
   394
    by (force simp: cauchy)
immler@50088
   395
  def d \<equiv> "domain (P Nd)"
immler@50088
   396
  with Nd have dim: "\<And>n. n \<ge> Nd \<Longrightarrow> domain (P n) = d" using dist_le_1_imp_domain_eq by auto
immler@50088
   397
  have [simp]: "finite d" unfolding d_def by simp
immler@50088
   398
  def p \<equiv> "\<lambda>i n. (P n) i"
immler@50088
   399
  def q \<equiv> "\<lambda>i. lim (p i)"
immler@50088
   400
  def Q \<equiv> "finmap_of d q"
immler@50088
   401
  have q: "\<And>i. i \<in> d \<Longrightarrow> q i = Q i" by (auto simp add: Q_def Abs_finmap_inverse)
immler@50088
   402
  {
immler@50088
   403
    fix i assume "i \<in> d"
immler@50088
   404
    have "Cauchy (p i)" unfolding cauchy p_def
immler@50088
   405
    proof safe
immler@50088
   406
      fix e::real assume "0 < e"
immler@50088
   407
      with `Cauchy P` obtain N where N: "\<And>n. n\<ge>N \<Longrightarrow> dist (P n) (P N) < min e 1"
immler@50088
   408
        by (force simp: cauchy min_def)
immler@50088
   409
      hence "\<And>n. n \<ge> N \<Longrightarrow> domain (P n) = domain (P N)" using dist_le_1_imp_domain_eq by auto
immler@50088
   410
      with dim have dim: "\<And>n. n \<ge> N \<Longrightarrow> domain (P n) = d" by (metis nat_le_linear)
immler@50088
   411
      show "\<exists>N. \<forall>n\<ge>N. dist ((P n) i) ((P N) i) < e"
immler@50088
   412
      proof (safe intro!: exI[where x="N"])
immler@50088
   413
        fix n assume "N \<le> n" have "N \<le> N" by simp
immler@50088
   414
        have "dist ((P n) i) ((P N) i) \<le> dist (P n) (P N)"
immler@50088
   415
          using dim[OF `N \<le> n`]  dim[OF `N \<le> N`] `i \<in> d`
immler@50088
   416
          by (auto intro!: dist_proj)
immler@50088
   417
        also have "\<dots> < e" using N[OF `N \<le> n`] by simp
immler@50088
   418
        finally show "dist ((P n) i) ((P N) i) < e" .
immler@50088
   419
      qed
immler@50088
   420
    qed
immler@50088
   421
    hence "convergent (p i)" by (metis Cauchy_convergent_iff)
immler@50088
   422
    hence "p i ----> q i" unfolding q_def convergent_def by (metis limI)
immler@50088
   423
  } note p = this
immler@50088
   424
  have "P ----> Q"
immler@50088
   425
  proof (rule metric_LIMSEQ_I)
immler@50088
   426
    fix e::real assume "0 < e"
immler@51104
   427
    have "\<exists>ni. \<forall>i\<in>d. \<forall>n\<ge>ni i. dist (p i n) (q i) < e"
immler@50088
   428
    proof (safe intro!: bchoice)
immler@50088
   429
      fix i assume "i \<in> d"
immler@51104
   430
      from p[OF `i \<in> d`, THEN metric_LIMSEQ_D, OF `0 < e`]
immler@51104
   431
      show "\<exists>no. \<forall>n\<ge>no. dist (p i n) (q i) < e" .
immler@50088
   432
    qed then guess ni .. note ni = this
immler@50088
   433
    def N \<equiv> "max Nd (Max (ni ` d))"
immler@50088
   434
    show "\<exists>N. \<forall>n\<ge>N. dist (P n) Q < e"
immler@50088
   435
    proof (safe intro!: exI[where x="N"])
immler@50088
   436
      fix n assume "N \<le> n"
immler@51104
   437
      hence dom: "domain (P n) = d" "domain Q = d" "domain (P n) = domain Q"
immler@50088
   438
        using dim by (simp_all add: N_def Q_def dim_def Abs_finmap_inverse)
immler@51104
   439
      show "dist (P n) Q < e"
immler@51104
   440
      proof (rule dist_finmap_lessI[OF dom(3) `0 < e`])
immler@51104
   441
        fix i
immler@51104
   442
        assume "i \<in> domain (P n)"
immler@51104
   443
        hence "ni i \<le> Max (ni ` d)" using dom by simp
immler@50088
   444
        also have "\<dots> \<le> N" by (simp add: N_def)
immler@51104
   445
        finally show "dist ((P n)\<^isub>F i) ((Q)\<^isub>F i) < e" using ni `i \<in> domain (P n)` `N \<le> n` dom
immler@51104
   446
          by (auto simp: p_def q N_def less_imp_le)
immler@50088
   447
      qed
immler@50088
   448
    qed
immler@50088
   449
  qed
immler@50088
   450
  thus "convergent P" by (auto simp: convergent_def)
immler@50088
   451
qed
immler@50088
   452
immler@50088
   453
subsection {* Polish Space of Finite Maps *}
immler@50088
   454
immler@50088
   455
instantiation finmap :: (countable, polish_space) polish_space
immler@50088
   456
begin
immler@50088
   457
immler@50245
   458
definition basis_finmap::"('a \<Rightarrow>\<^isub>F 'b) set set"
immler@50245
   459
  where "basis_finmap = {Pi' I S|I S. finite I \<and> (\<forall>i \<in> I. S i \<in> union_closed_basis)}"
immler@50245
   460
immler@50245
   461
lemma in_basis_finmapI:
immler@50245
   462
  assumes "finite I" assumes "\<And>i. i \<in> I \<Longrightarrow> S i \<in> union_closed_basis"
immler@50245
   463
  shows "Pi' I S \<in> basis_finmap"
immler@50245
   464
  using assms unfolding basis_finmap_def by auto
immler@50245
   465
immler@50245
   466
lemma in_basis_finmapE:
immler@50245
   467
  assumes "x \<in> basis_finmap"
immler@50245
   468
  obtains I S where "x = Pi' I S" "finite I" "\<And>i. i \<in> I \<Longrightarrow> S i \<in> union_closed_basis"
immler@50245
   469
  using assms unfolding basis_finmap_def by auto
immler@50088
   470
immler@50245
   471
lemma basis_finmap_eq:
immler@50245
   472
  "basis_finmap = (\<lambda>f. Pi' (domain f) (\<lambda>i. from_nat_into union_closed_basis ((f)\<^isub>F i))) `
immler@50245
   473
    (UNIV::('a \<Rightarrow>\<^isub>F nat) set)" (is "_ = ?f ` _")
immler@50245
   474
  unfolding basis_finmap_def
immler@50245
   475
proof safe
immler@50245
   476
  fix I::"'a set" and S::"'a \<Rightarrow> 'b set"
immler@50245
   477
  assume "finite I" "\<forall>i\<in>I. S i \<in> union_closed_basis"
immler@50245
   478
  hence "Pi' I S = ?f (finmap_of I (\<lambda>x. to_nat_on union_closed_basis (S x)))"
immler@50245
   479
    by (force simp: Pi'_def countable_union_closed_basis)
immler@50245
   480
  thus "Pi' I S \<in> range ?f" by simp
immler@50245
   481
qed (metis (mono_tags) empty_basisI equals0D finite_domain from_nat_into)
immler@50088
   482
immler@50245
   483
lemma countable_basis_finmap: "countable basis_finmap"
immler@50245
   484
  unfolding basis_finmap_eq by simp
immler@50088
   485
immler@50088
   486
lemma finmap_topological_basis:
immler@50245
   487
  "topological_basis basis_finmap"
immler@50088
   488
proof (subst topological_basis_iff, safe)
immler@50245
   489
  fix B' assume "B' \<in> basis_finmap"
immler@50245
   490
  thus "open B'"
immler@50245
   491
    by (auto intro!: open_Pi'I topological_basis_open[OF basis_union_closed_basis]
immler@50245
   492
      simp: topological_basis_def basis_finmap_def Let_def)
immler@50088
   493
next
immler@50088
   494
  fix O'::"('a \<Rightarrow>\<^isub>F 'b) set" and x
immler@50088
   495
  assume "open O'" "x \<in> O'"
immler@50088
   496
  then obtain e where e: "e > 0" "\<And>y. dist y x < e \<Longrightarrow> y \<in> O'"  unfolding open_dist by blast
immler@50088
   497
  have "\<exists>B.
immler@51104
   498
    (\<forall>i\<in>domain x. x i \<in> B i \<and> B i \<subseteq> ball (x i) e \<and> B i \<in> union_closed_basis)"
immler@50088
   499
  proof (rule bchoice, safe)
immler@50088
   500
    fix i assume "i \<in> domain x"
immler@51104
   501
    have "open (ball (x i) e)" "x i \<in> ball (x i) e" using e
immler@51104
   502
      by (auto simp add: intro!: divide_pos_pos)
immler@50245
   503
    from topological_basisE[OF basis_union_closed_basis this] guess b' .
immler@51104
   504
    thus "\<exists>y. x i \<in> y \<and> y \<subseteq> ball (x i) e \<and> y \<in> union_closed_basis" by auto
immler@50088
   505
  qed
immler@50088
   506
  then guess B .. note B = this
immler@50245
   507
  def B' \<equiv> "Pi' (domain x) (\<lambda>i. (B i)::'b set)"
immler@50245
   508
  hence "B' \<in> basis_finmap" unfolding B'_def using B
immler@50245
   509
    by (intro in_basis_finmapI) auto
immler@50088
   510
  moreover have "x \<in> B'" unfolding B'_def using B by auto
immler@50088
   511
  moreover have "B' \<subseteq> O'"
immler@50088
   512
  proof
immler@51104
   513
    fix y assume "y \<in> B'" with B have dom: "domain y = domain x" unfolding B'_def
immler@50088
   514
      by (simp add: Pi'_def)
immler@50088
   515
    show "y \<in> O'"
immler@51104
   516
    proof (rule e, rule dist_finmap_lessI[OF dom `0 < e`])
immler@51104
   517
      fix i assume "i \<in> domain y"
immler@51104
   518
      with `y \<in> B'` B have "y i \<in> B i"
immler@51104
   519
        by (simp add: Pi'_def B'_def)
immler@51104
   520
      hence "y i \<in> ball (x i) e" using B `domain y = domain x` `i \<in> domain y`
immler@51104
   521
        by force
immler@51104
   522
      thus "dist (y i) (x i) < e" by (simp add: dist_commute)
immler@50088
   523
    qed
immler@50088
   524
  qed
immler@50088
   525
  ultimately
immler@50245
   526
  show "\<exists>B'\<in>basis_finmap. x \<in> B' \<and> B' \<subseteq> O'" by blast
immler@50088
   527
qed
immler@50088
   528
immler@50088
   529
lemma range_enum_basis_finmap_imp_open:
immler@50245
   530
  assumes "x \<in> basis_finmap"
immler@50088
   531
  shows "open x"
immler@50088
   532
  using finmap_topological_basis assms by (auto simp: topological_basis_def)
immler@50088
   533
immler@50245
   534
instance proof qed (blast intro: finmap_topological_basis countable_basis_finmap)
immler@50088
   535
immler@50088
   536
end
immler@50088
   537
immler@50088
   538
subsection {* Product Measurable Space of Finite Maps *}
immler@50088
   539
immler@50088
   540
definition "PiF I M \<equiv>
hoelzl@50124
   541
  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))}"
immler@50088
   542
immler@50088
   543
abbreviation
immler@50088
   544
  "Pi\<^isub>F I M \<equiv> PiF I M"
immler@50088
   545
immler@50088
   546
syntax
immler@50088
   547
  "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3PIF _:_./ _)" 10)
immler@50088
   548
immler@50088
   549
syntax (xsymbols)
immler@50088
   550
  "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3\<Pi>\<^isub>F _\<in>_./ _)"  10)
immler@50088
   551
immler@50088
   552
syntax (HTML output)
immler@50088
   553
  "_PiF" :: "pttrn \<Rightarrow> 'i set \<Rightarrow> 'a measure \<Rightarrow> ('i => 'a) measure"  ("(3\<Pi>\<^isub>F _\<in>_./ _)"  10)
immler@50088
   554
immler@50088
   555
translations
immler@50088
   556
  "PIF x:I. M" == "CONST PiF I (%x. M)"
immler@50088
   557
immler@50088
   558
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>
immler@50088
   559
    Pow (\<Union>J \<in> I. (\<Pi>' j\<in>J. space (M j)))"
immler@50244
   560
  by (auto simp: Pi'_def) (blast dest: sets.sets_into_space)
immler@50088
   561
immler@50088
   562
lemma space_PiF: "space (PiF I M) = (\<Union>J \<in> I. (\<Pi>' j\<in>J. space (M j)))"
immler@50088
   563
  unfolding PiF_def using PiF_gen_subset by (rule space_measure_of)
immler@50088
   564
immler@50088
   565
lemma sets_PiF:
immler@50088
   566
  "sets (PiF I M) = sigma_sets (\<Union>J \<in> I. (\<Pi>' j\<in>J. space (M j)))
immler@50088
   567
    {(\<Pi>' j\<in>J. X j) |X J. J \<in> I \<and> X \<in> (\<Pi> j\<in>J. sets (M j))}"
immler@50088
   568
  unfolding PiF_def using PiF_gen_subset by (rule sets_measure_of)
immler@50088
   569
immler@50088
   570
lemma sets_PiF_singleton:
immler@50088
   571
  "sets (PiF {I} M) = sigma_sets (\<Pi>' j\<in>I. space (M j))
immler@50088
   572
    {(\<Pi>' j\<in>I. X j) |X. X \<in> (\<Pi> j\<in>I. sets (M j))}"
immler@50088
   573
  unfolding sets_PiF by simp
immler@50088
   574
immler@50088
   575
lemma in_sets_PiFI:
immler@50088
   576
  assumes "X = (Pi' J S)" "J \<in> I" "\<And>i. i\<in>J \<Longrightarrow> S i \<in> sets (M i)"
immler@50088
   577
  shows "X \<in> sets (PiF I M)"
immler@50088
   578
  unfolding sets_PiF
immler@50088
   579
  using assms by blast
immler@50088
   580
immler@50088
   581
lemma product_in_sets_PiFI:
immler@50088
   582
  assumes "J \<in> I" "\<And>i. i\<in>J \<Longrightarrow> S i \<in> sets (M i)"
immler@50088
   583
  shows "(Pi' J S) \<in> sets (PiF I M)"
immler@50088
   584
  unfolding sets_PiF
immler@50088
   585
  using assms by blast
immler@50088
   586
immler@50088
   587
lemma singleton_space_subset_in_sets:
immler@50088
   588
  fixes J
immler@50088
   589
  assumes "J \<in> I"
immler@50088
   590
  assumes "finite J"
immler@50088
   591
  shows "space (PiF {J} M) \<in> sets (PiF I M)"
immler@50088
   592
  using assms
immler@50088
   593
  by (intro in_sets_PiFI[where J=J and S="\<lambda>i. space (M i)"])
immler@50088
   594
      (auto simp: product_def space_PiF)
immler@50088
   595
immler@50088
   596
lemma singleton_subspace_set_in_sets:
immler@50088
   597
  assumes A: "A \<in> sets (PiF {J} M)"
immler@50088
   598
  assumes "finite J"
immler@50088
   599
  assumes "J \<in> I"
immler@50088
   600
  shows "A \<in> sets (PiF I M)"
immler@50088
   601
  using A[unfolded sets_PiF]
immler@50088
   602
  apply (induct A)
immler@50088
   603
  unfolding sets_PiF[symmetric] unfolding space_PiF[symmetric]
immler@50088
   604
  using assms
immler@50088
   605
  by (auto intro: in_sets_PiFI intro!: singleton_space_subset_in_sets)
immler@50088
   606
hoelzl@50124
   607
lemma finite_measurable_singletonI:
immler@50088
   608
  assumes "finite I"
immler@50088
   609
  assumes "\<And>J. J \<in> I \<Longrightarrow> finite J"
immler@50088
   610
  assumes MN: "\<And>J. J \<in> I \<Longrightarrow> A \<in> measurable (PiF {J} M) N"
immler@50088
   611
  shows "A \<in> measurable (PiF I M) N"
immler@50088
   612
  unfolding measurable_def
immler@50088
   613
proof safe
immler@50088
   614
  fix y assume "y \<in> sets N"
immler@50088
   615
  have "A -` y \<inter> space (PiF I M) = (\<Union>J\<in>I. A -` y \<inter> space (PiF {J} M))"
immler@50088
   616
    by (auto simp: space_PiF)
immler@50088
   617
  also have "\<dots> \<in> sets (PiF I M)"
immler@50088
   618
  proof
immler@50088
   619
    show "finite I" by fact
immler@50088
   620
    fix J assume "J \<in> I"
immler@50088
   621
    with assms have "finite J" by simp
immler@50088
   622
    show "A -` y \<inter> space (PiF {J} M) \<in> sets (PiF I M)"
immler@50088
   623
      by (rule singleton_subspace_set_in_sets[OF measurable_sets[OF assms(3)]]) fact+
immler@50088
   624
  qed
immler@50088
   625
  finally show "A -` y \<inter> space (PiF I M) \<in> sets (PiF I M)" .
immler@50088
   626
next
immler@50088
   627
  fix x assume "x \<in> space (PiF I M)" thus "A x \<in> space N"
immler@50088
   628
    using MN[of "domain x"]
immler@50088
   629
    by (auto simp: space_PiF measurable_space Pi'_def)
immler@50088
   630
qed
immler@50088
   631
hoelzl@50124
   632
lemma countable_finite_comprehension:
immler@50088
   633
  fixes f :: "'a::countable set \<Rightarrow> _"
immler@50088
   634
  assumes "\<And>s. P s \<Longrightarrow> finite s"
immler@50088
   635
  assumes "\<And>s. P s \<Longrightarrow> f s \<in> sets M"
immler@50088
   636
  shows "\<Union>{f s|s. P s} \<in> sets M"
immler@50088
   637
proof -
immler@50088
   638
  have "\<Union>{f s|s. P s} = (\<Union>n::nat. let s = set (from_nat n) in if P s then f s else {})"
immler@50088
   639
  proof safe
immler@50088
   640
    fix x X s assume "x \<in> f s" "P s"
immler@50088
   641
    moreover with assms obtain l where "s = set l" using finite_list by blast
immler@50088
   642
    ultimately show "x \<in> (\<Union>n. let s = set (from_nat n) in if P s then f s else {})" using `P s`
immler@50088
   643
      by (auto intro!: exI[where x="to_nat l"])
immler@50088
   644
  next
immler@50088
   645
    fix x n assume "x \<in> (let s = set (from_nat n) in if P s then f s else {})"
immler@50088
   646
    thus "x \<in> \<Union>{f s|s. P s}" using assms by (auto simp: Let_def split: split_if_asm)
immler@50088
   647
  qed
immler@50088
   648
  hence "\<Union>{f s|s. P s} = (\<Union>n. let s = set (from_nat n) in if P s then f s else {})" by simp
immler@50088
   649
  also have "\<dots> \<in> sets M" using assms by (auto simp: Let_def)
immler@50088
   650
  finally show ?thesis .
immler@50088
   651
qed
immler@50088
   652
immler@50088
   653
lemma space_subset_in_sets:
immler@50088
   654
  fixes J::"'a::countable set set"
immler@50088
   655
  assumes "J \<subseteq> I"
immler@50088
   656
  assumes "\<And>j. j \<in> J \<Longrightarrow> finite j"
immler@50088
   657
  shows "space (PiF J M) \<in> sets (PiF I M)"
immler@50088
   658
proof -
immler@50088
   659
  have "space (PiF J M) = \<Union>{space (PiF {j} M)|j. j \<in> J}"
immler@50088
   660
    unfolding space_PiF by blast
immler@50088
   661
  also have "\<dots> \<in> sets (PiF I M)" using assms
immler@50088
   662
    by (intro countable_finite_comprehension) (auto simp: singleton_space_subset_in_sets)
immler@50088
   663
  finally show ?thesis .
immler@50088
   664
qed
immler@50088
   665
immler@50088
   666
lemma subspace_set_in_sets:
immler@50088
   667
  fixes J::"'a::countable set set"
immler@50088
   668
  assumes A: "A \<in> sets (PiF J M)"
immler@50088
   669
  assumes "J \<subseteq> I"
immler@50088
   670
  assumes "\<And>j. j \<in> J \<Longrightarrow> finite j"
immler@50088
   671
  shows "A \<in> sets (PiF I M)"
immler@50088
   672
  using A[unfolded sets_PiF]
immler@50088
   673
  apply (induct A)
immler@50088
   674
  unfolding sets_PiF[symmetric] unfolding space_PiF[symmetric]
immler@50088
   675
  using assms
immler@50088
   676
  by (auto intro: in_sets_PiFI intro!: space_subset_in_sets)
immler@50088
   677
hoelzl@50124
   678
lemma countable_measurable_PiFI:
immler@50088
   679
  fixes I::"'a::countable set set"
immler@50088
   680
  assumes MN: "\<And>J. J \<in> I \<Longrightarrow> finite J \<Longrightarrow> A \<in> measurable (PiF {J} M) N"
immler@50088
   681
  shows "A \<in> measurable (PiF I M) N"
immler@50088
   682
  unfolding measurable_def
immler@50088
   683
proof safe
immler@50088
   684
  fix y assume "y \<in> sets N"
immler@50088
   685
  have "A -` y = (\<Union>{A -` y \<inter> {x. domain x = J}|J. finite J})" by auto
immler@50245
   686
  { fix x::"'a \<Rightarrow>\<^isub>F 'b"
immler@50088
   687
    from finite_list[of "domain x"] obtain xs where "set xs = domain x" by auto
immler@50245
   688
    hence "\<exists>n. domain x = set (from_nat n)"
immler@50245
   689
      by (intro exI[where x="to_nat xs"]) auto }
immler@50245
   690
  hence "A -` y \<inter> space (PiF I M) = (\<Union>n. A -` y \<inter> space (PiF ({set (from_nat n)}\<inter>I) M))"
immler@50245
   691
    by (auto simp: space_PiF Pi'_def)
immler@50088
   692
  also have "\<dots> \<in> sets (PiF I M)"
immler@50244
   693
    apply (intro sets.Int sets.countable_nat_UN subsetI, safe)
immler@50088
   694
    apply (case_tac "set (from_nat i) \<in> I")
immler@50088
   695
    apply simp_all
immler@50088
   696
    apply (rule singleton_subspace_set_in_sets[OF measurable_sets[OF MN]])
immler@50088
   697
    using assms `y \<in> sets N`
immler@50088
   698
    apply (auto simp: space_PiF)
immler@50088
   699
    done
immler@50088
   700
  finally show "A -` y \<inter> space (PiF I M) \<in> sets (PiF I M)" .
immler@50088
   701
next
immler@50088
   702
  fix x assume "x \<in> space (PiF I M)" thus "A x \<in> space N"
immler@50088
   703
    using MN[of "domain x"] by (auto simp: space_PiF measurable_space Pi'_def)
immler@50088
   704
qed
immler@50088
   705
immler@50088
   706
lemma measurable_PiF:
immler@50088
   707
  assumes f: "\<And>x. x \<in> space N \<Longrightarrow> domain (f x) \<in> I \<and> (\<forall>i\<in>domain (f x). (f x) i \<in> space (M i))"
immler@50088
   708
  assumes S: "\<And>J S. J \<in> I \<Longrightarrow> (\<And>i. i \<in> J \<Longrightarrow> S i \<in> sets (M i)) \<Longrightarrow>
immler@50088
   709
    f -` (Pi' J S) \<inter> space N \<in> sets N"
immler@50088
   710
  shows "f \<in> measurable N (PiF I M)"
immler@50088
   711
  unfolding PiF_def
immler@50088
   712
  using PiF_gen_subset
immler@50088
   713
  apply (rule measurable_measure_of)
immler@50088
   714
  using f apply force
immler@50088
   715
  apply (insert S, auto)
immler@50088
   716
  done
immler@50088
   717
hoelzl@50124
   718
lemma restrict_sets_measurable:
immler@50088
   719
  assumes A: "A \<in> sets (PiF I M)" and "J \<subseteq> I"
immler@50088
   720
  shows "A \<inter> {m. domain m \<in> J} \<in> sets (PiF J M)"
immler@50088
   721
  using A[unfolded sets_PiF]
hoelzl@50124
   722
proof (induct A)
hoelzl@50124
   723
  case (Basic a)
immler@50088
   724
  then obtain K S where S: "a = Pi' K S" "K \<in> I" "(\<forall>i\<in>K. S i \<in> sets (M i))"
immler@50088
   725
    by auto
hoelzl@50124
   726
  show ?case
immler@50088
   727
  proof cases
immler@50088
   728
    assume "K \<in> J"
immler@50088
   729
    hence "a \<inter> {m. domain m \<in> J} \<in> {Pi' K X |X K. K \<in> J \<and> X \<in> (\<Pi> j\<in>K. sets (M j))}" using S
immler@50088
   730
      by (auto intro!: exI[where x=K] exI[where x=S] simp: Pi'_def)
immler@50088
   731
    also have "\<dots> \<subseteq> sets (PiF J M)" unfolding sets_PiF by auto
immler@50088
   732
    finally show ?thesis .
immler@50088
   733
  next
immler@50088
   734
    assume "K \<notin> J"
immler@50088
   735
    hence "a \<inter> {m. domain m \<in> J} = {}" using S by (auto simp: Pi'_def)
immler@50088
   736
    also have "\<dots> \<in> sets (PiF J M)" by simp
immler@50088
   737
    finally show ?thesis .
immler@50088
   738
  qed
immler@50088
   739
next
hoelzl@50124
   740
  case (Union a)
immler@50088
   741
  have "UNION UNIV a \<inter> {m. domain m \<in> J} = (\<Union>i. (a i \<inter> {m. domain m \<in> J}))"
immler@50088
   742
    by simp
immler@50244
   743
  also have "\<dots> \<in> sets (PiF J M)" using Union by (intro sets.countable_nat_UN) auto
hoelzl@50124
   744
  finally show ?case .
immler@50088
   745
next
hoelzl@50124
   746
  case (Compl a)
immler@50088
   747
  have "(space (PiF I M) - a) \<inter> {m. domain m \<in> J} = (space (PiF J M) - (a \<inter> {m. domain m \<in> J}))"
immler@50088
   748
    using `J \<subseteq> I` by (auto simp: space_PiF Pi'_def)
hoelzl@50124
   749
  also have "\<dots> \<in> sets (PiF J M)" using Compl by auto
hoelzl@50124
   750
  finally show ?case by (simp add: space_PiF)
hoelzl@50124
   751
qed simp
immler@50088
   752
immler@50088
   753
lemma measurable_finmap_of:
immler@50088
   754
  assumes f: "\<And>i. (\<exists>x \<in> space N. i \<in> J x) \<Longrightarrow> (\<lambda>x. f x i) \<in> measurable N (M i)"
immler@50088
   755
  assumes J: "\<And>x. x \<in> space N \<Longrightarrow> J x \<in> I" "\<And>x. x \<in> space N \<Longrightarrow> finite (J x)"
immler@50088
   756
  assumes JN: "\<And>S. {x. J x = S} \<inter> space N \<in> sets N"
immler@50088
   757
  shows "(\<lambda>x. finmap_of (J x) (f x)) \<in> measurable N (PiF I M)"
immler@50088
   758
proof (rule measurable_PiF)
immler@50088
   759
  fix x assume "x \<in> space N"
immler@50088
   760
  with J[of x] measurable_space[OF f]
immler@50088
   761
  show "domain (finmap_of (J x) (f x)) \<in> I \<and>
immler@50088
   762
        (\<forall>i\<in>domain (finmap_of (J x) (f x)). (finmap_of (J x) (f x)) i \<in> space (M i))"
immler@50088
   763
    by auto
immler@50088
   764
next
immler@50088
   765
  fix K S assume "K \<in> I" and *: "\<And>i. i \<in> K \<Longrightarrow> S i \<in> sets (M i)"
immler@50088
   766
  with J have eq: "(\<lambda>x. finmap_of (J x) (f x)) -` Pi' K S \<inter> space N =
immler@50088
   767
    (if \<exists>x \<in> space N. K = J x \<and> finite K then if K = {} then {x \<in> space N. J x = K}
immler@50088
   768
      else (\<Inter>i\<in>K. (\<lambda>x. f x i) -` S i \<inter> {x \<in> space N. J x = K}) else {})"
immler@50088
   769
    by (auto simp: Pi'_def)
immler@50088
   770
  have r: "{x \<in> space N. J x = K} = space N \<inter> ({x. J x = K} \<inter> space N)" by auto
immler@50088
   771
  show "(\<lambda>x. finmap_of (J x) (f x)) -` Pi' K S \<inter> space N \<in> sets N"
immler@50088
   772
    unfolding eq r
immler@50088
   773
    apply (simp del: INT_simps add: )
immler@50244
   774
    apply (intro conjI impI sets.finite_INT JN sets.Int[OF sets.top])
immler@50088
   775
    apply simp apply assumption
immler@50088
   776
    apply (subst Int_assoc[symmetric])
immler@50244
   777
    apply (rule sets.Int)
immler@50088
   778
    apply (intro measurable_sets[OF f] *) apply force apply assumption
immler@50088
   779
    apply (intro JN)
immler@50088
   780
    done
immler@50088
   781
qed
immler@50088
   782
immler@50088
   783
lemma measurable_PiM_finmap_of:
immler@50088
   784
  assumes "finite J"
immler@50088
   785
  shows "finmap_of J \<in> measurable (Pi\<^isub>M J M) (PiF {J} M)"
immler@50088
   786
  apply (rule measurable_finmap_of)
immler@50088
   787
  apply (rule measurable_component_singleton)
immler@50088
   788
  apply simp
immler@50088
   789
  apply rule
immler@50088
   790
  apply (rule `finite J`)
immler@50088
   791
  apply simp
immler@50088
   792
  done
immler@50088
   793
immler@50088
   794
lemma proj_measurable_singleton:
hoelzl@50124
   795
  assumes "A \<in> sets (M i)"
immler@50088
   796
  shows "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space (PiF {I} M) \<in> sets (PiF {I} M)"
immler@50088
   797
proof cases
immler@50088
   798
  assume "i \<in> I"
immler@50088
   799
  hence "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space (PiF {I} M) =
immler@50088
   800
    Pi' I (\<lambda>x. if x = i then A else space (M x))"
immler@50244
   801
    using sets.sets_into_space[OF ] `A \<in> sets (M i)` assms
immler@50088
   802
    by (auto simp: space_PiF Pi'_def)
immler@50088
   803
  thus ?thesis  using assms `A \<in> sets (M i)`
immler@50088
   804
    by (intro in_sets_PiFI) auto
immler@50088
   805
next
immler@50088
   806
  assume "i \<notin> I"
immler@50088
   807
  hence "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space (PiF {I} M) =
immler@50088
   808
    (if undefined \<in> A then space (PiF {I} M) else {})" by (auto simp: space_PiF Pi'_def)
immler@50088
   809
  thus ?thesis by simp
immler@50088
   810
qed
immler@50088
   811
immler@50088
   812
lemma measurable_proj_singleton:
hoelzl@50124
   813
  assumes "i \<in> I"
immler@50088
   814
  shows "(\<lambda>x. (x)\<^isub>F i) \<in> measurable (PiF {I} M) (M i)"
hoelzl@50124
   815
  by (unfold measurable_def, intro CollectI conjI ballI proj_measurable_singleton assms)
hoelzl@50124
   816
     (insert `i \<in> I`, auto simp: space_PiF)
immler@50088
   817
immler@50088
   818
lemma measurable_proj_countable:
immler@50088
   819
  fixes I::"'a::countable set set"
immler@50088
   820
  assumes "y \<in> space (M i)"
immler@50088
   821
  shows "(\<lambda>x. if i \<in> domain x then (x)\<^isub>F i else y) \<in> measurable (PiF I M) (M i)"
immler@50088
   822
proof (rule countable_measurable_PiFI)
immler@50088
   823
  fix J assume "J \<in> I" "finite J"
immler@50088
   824
  show "(\<lambda>x. if i \<in> domain x then x i else y) \<in> measurable (PiF {J} M) (M i)"
immler@50088
   825
    unfolding measurable_def
immler@50088
   826
  proof safe
immler@50088
   827
    fix z assume "z \<in> sets (M i)"
immler@50088
   828
    have "(\<lambda>x. if i \<in> domain x then x i else y) -` z \<inter> space (PiF {J} M) =
immler@50088
   829
      (\<lambda>x. if i \<in> J then (x)\<^isub>F i else y) -` z \<inter> space (PiF {J} M)"
immler@50088
   830
      by (auto simp: space_PiF Pi'_def)
immler@50088
   831
    also have "\<dots> \<in> sets (PiF {J} M)" using `z \<in> sets (M i)` `finite J`
immler@50088
   832
      by (cases "i \<in> J") (auto intro!: measurable_sets[OF measurable_proj_singleton])
immler@50088
   833
    finally show "(\<lambda>x. if i \<in> domain x then x i else y) -` z \<inter> space (PiF {J} M) \<in>
immler@50088
   834
      sets (PiF {J} M)" .
immler@50088
   835
  qed (insert `y \<in> space (M i)`, auto simp: space_PiF Pi'_def)
immler@50088
   836
qed
immler@50088
   837
immler@50088
   838
lemma measurable_restrict_proj:
immler@50088
   839
  assumes "J \<in> II" "finite J"
immler@50088
   840
  shows "finmap_of J \<in> measurable (PiM J M) (PiF II M)"
immler@50088
   841
  using assms
immler@50088
   842
  by (intro measurable_finmap_of measurable_component_singleton) auto
immler@50088
   843
hoelzl@50124
   844
lemma measurable_proj_PiM:
immler@50088
   845
  fixes J K ::"'a::countable set" and I::"'a set set"
immler@50088
   846
  assumes "finite J" "J \<in> I"
immler@50088
   847
  assumes "x \<in> space (PiM J M)"
hoelzl@50124
   848
  shows "proj \<in> measurable (PiF {J} M) (PiM J M)"
immler@50088
   849
proof (rule measurable_PiM_single)
immler@50088
   850
  show "proj \<in> space (PiF {J} M) \<rightarrow> (\<Pi>\<^isub>E i \<in> J. space (M i))"
immler@50088
   851
    using assms by (auto simp add: space_PiM space_PiF extensional_def sets_PiF Pi'_def)
immler@50088
   852
next
immler@50088
   853
  fix A i assume A: "i \<in> J" "A \<in> sets (M i)"
immler@50088
   854
  show "{\<omega> \<in> space (PiF {J} M). (\<omega>)\<^isub>F i \<in> A} \<in> sets (PiF {J} M)"
immler@50088
   855
  proof
immler@50088
   856
    have "{\<omega> \<in> space (PiF {J} M). (\<omega>)\<^isub>F i \<in> A} =
immler@50088
   857
      (\<lambda>\<omega>. (\<omega>)\<^isub>F i) -` A \<inter> space (PiF {J} M)" by auto
immler@50088
   858
    also have "\<dots> \<in> sets (PiF {J} M)"
immler@50088
   859
      using assms A by (auto intro: measurable_sets[OF measurable_proj_singleton] simp: space_PiM)
immler@50088
   860
    finally show ?thesis .
immler@50088
   861
  qed simp
immler@50088
   862
qed
immler@50088
   863
immler@50088
   864
lemma space_PiF_singleton_eq_product:
immler@50088
   865
  assumes "finite I"
immler@50088
   866
  shows "space (PiF {I} M) = (\<Pi>' i\<in>I. space (M i))"
immler@50088
   867
  by (auto simp: product_def space_PiF assms)
immler@50088
   868
immler@50088
   869
text {* adapted from @{thm sets_PiM_single} *}
immler@50088
   870
immler@50088
   871
lemma sets_PiF_single:
immler@50088
   872
  assumes "finite I" "I \<noteq> {}"
immler@50088
   873
  shows "sets (PiF {I} M) =
immler@50088
   874
    sigma_sets (\<Pi>' i\<in>I. space (M i))
immler@50088
   875
      {{f\<in>\<Pi>' i\<in>I. space (M i). f i \<in> A} | i A. i \<in> I \<and> A \<in> sets (M i)}"
immler@50088
   876
    (is "_ = sigma_sets ?\<Omega> ?R")
immler@50088
   877
  unfolding sets_PiF_singleton
immler@50088
   878
proof (rule sigma_sets_eqI)
immler@50088
   879
  interpret R: sigma_algebra ?\<Omega> "sigma_sets ?\<Omega> ?R" by (rule sigma_algebra_sigma_sets) auto
immler@50088
   880
  fix A assume "A \<in> {Pi' I X |X. X \<in> (\<Pi> j\<in>I. sets (M j))}"
immler@50088
   881
  then obtain X where X: "A = Pi' I X" "X \<in> (\<Pi> j\<in>I. sets (M j))" by auto
immler@50088
   882
  show "A \<in> sigma_sets ?\<Omega> ?R"
immler@50088
   883
  proof -
immler@50088
   884
    from `I \<noteq> {}` X have "A = (\<Inter>j\<in>I. {f\<in>space (PiF {I} M). f j \<in> X j})"
immler@50244
   885
      using sets.sets_into_space
immler@50088
   886
      by (auto simp: space_PiF product_def) blast
immler@50088
   887
    also have "\<dots> \<in> sigma_sets ?\<Omega> ?R"
immler@50088
   888
      using X `I \<noteq> {}` assms by (intro R.finite_INT) (auto simp: space_PiF)
immler@50088
   889
    finally show "A \<in> sigma_sets ?\<Omega> ?R" .
immler@50088
   890
  qed
immler@50088
   891
next
immler@50088
   892
  fix A assume "A \<in> ?R"
immler@50088
   893
  then obtain i B where A: "A = {f\<in>\<Pi>' i\<in>I. space (M i). f i \<in> B}" "i \<in> I" "B \<in> sets (M i)"
immler@50088
   894
    by auto
immler@50088
   895
  then have "A = (\<Pi>' j \<in> I. if j = i then B else space (M j))"
immler@50244
   896
    using sets.sets_into_space[OF A(3)]
immler@50088
   897
    apply (auto simp: Pi'_iff split: split_if_asm)
immler@50088
   898
    apply blast
immler@50088
   899
    done
immler@50088
   900
  also have "\<dots> \<in> sigma_sets ?\<Omega> {Pi' I X |X. X \<in> (\<Pi> j\<in>I. sets (M j))}"
immler@50088
   901
    using A
immler@50088
   902
    by (intro sigma_sets.Basic )
immler@50088
   903
       (auto intro: exI[where x="\<lambda>j. if j = i then B else space (M j)"])
immler@50088
   904
  finally show "A \<in> sigma_sets ?\<Omega> {Pi' I X |X. X \<in> (\<Pi> j\<in>I. sets (M j))}" .
immler@50088
   905
qed
immler@50088
   906
immler@50088
   907
text {* adapted from @{thm PiE_cong} *}
immler@50088
   908
immler@50088
   909
lemma Pi'_cong:
immler@50088
   910
  assumes "finite I"
immler@50088
   911
  assumes "\<And>i. i \<in> I \<Longrightarrow> f i = g i"
immler@50088
   912
  shows "Pi' I f = Pi' I g"
immler@50088
   913
using assms by (auto simp: Pi'_def)
immler@50088
   914
immler@50088
   915
text {* adapted from @{thm Pi_UN} *}
immler@50088
   916
immler@50088
   917
lemma Pi'_UN:
immler@50088
   918
  fixes A :: "nat \<Rightarrow> 'i \<Rightarrow> 'a set"
immler@50088
   919
  assumes "finite I"
immler@50088
   920
  assumes mono: "\<And>i n m. i \<in> I \<Longrightarrow> n \<le> m \<Longrightarrow> A n i \<subseteq> A m i"
immler@50088
   921
  shows "(\<Union>n. Pi' I (A n)) = Pi' I (\<lambda>i. \<Union>n. A n i)"
immler@50088
   922
proof (intro set_eqI iffI)
immler@50088
   923
  fix f assume "f \<in> Pi' I (\<lambda>i. \<Union>n. A n i)"
immler@50088
   924
  then have "\<forall>i\<in>I. \<exists>n. f i \<in> A n i" "domain f = I" by (auto simp: `finite I` Pi'_def)
immler@50088
   925
  from bchoice[OF this(1)] obtain n where n: "\<And>i. i \<in> I \<Longrightarrow> f i \<in> (A (n i) i)" by auto
immler@50088
   926
  obtain k where k: "\<And>i. i \<in> I \<Longrightarrow> n i \<le> k"
immler@50088
   927
    using `finite I` finite_nat_set_iff_bounded_le[of "n`I"] by auto
immler@50088
   928
  have "f \<in> Pi' I (\<lambda>i. A k i)"
immler@50088
   929
  proof
immler@50088
   930
    fix i assume "i \<in> I"
immler@50088
   931
    from mono[OF this, of "n i" k] k[OF this] n[OF this] `domain f = I` `i \<in> I`
immler@50088
   932
    show "f i \<in> A k i " by (auto simp: `finite I`)
immler@50088
   933
  qed (simp add: `domain f = I` `finite I`)
immler@50088
   934
  then show "f \<in> (\<Union>n. Pi' I (A n))" by auto
immler@50088
   935
qed (auto simp: Pi'_def `finite I`)
immler@50088
   936
immler@50088
   937
text {* adapted from @{thm sigma_prod_algebra_sigma_eq} *}
immler@50088
   938
immler@50088
   939
lemma sigma_fprod_algebra_sigma_eq:
immler@50088
   940
  fixes E :: "'i \<Rightarrow> 'a set set"
immler@50088
   941
  assumes [simp]: "finite I" "I \<noteq> {}"
immler@50088
   942
  assumes S_mono: "\<And>i. i \<in> I \<Longrightarrow> incseq (S i)"
immler@50088
   943
    and S_union: "\<And>i. i \<in> I \<Longrightarrow> (\<Union>j. S i j) = space (M i)"
immler@50088
   944
    and S_in_E: "\<And>i. i \<in> I \<Longrightarrow> range (S i) \<subseteq> E i"
immler@50088
   945
  assumes E_closed: "\<And>i. i \<in> I \<Longrightarrow> E i \<subseteq> Pow (space (M i))"
immler@50088
   946
    and E_generates: "\<And>i. i \<in> I \<Longrightarrow> sets (M i) = sigma_sets (space (M i)) (E i)"
immler@50088
   947
  defines "P == { Pi' I F | F. \<forall>i\<in>I. F i \<in> E i }"
immler@50088
   948
  shows "sets (PiF {I} M) = sigma_sets (space (PiF {I} M)) P"
immler@50088
   949
proof
immler@50088
   950
  let ?P = "sigma (space (Pi\<^isub>F {I} M)) P"
immler@50088
   951
  have P_closed: "P \<subseteq> Pow (space (Pi\<^isub>F {I} M))"
immler@50088
   952
    using E_closed by (auto simp: space_PiF P_def Pi'_iff subset_eq)
immler@50088
   953
  then have space_P: "space ?P = (\<Pi>' i\<in>I. space (M i))"
immler@50088
   954
    by (simp add: space_PiF)
immler@50088
   955
  have "sets (PiF {I} M) =
immler@50088
   956
      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)}"
immler@50088
   957
    using sets_PiF_single[of I M] by (simp add: space_P)
immler@50088
   958
  also have "\<dots> \<subseteq> sets (sigma (space (PiF {I} M)) P)"
immler@50244
   959
  proof (safe intro!: sets.sigma_sets_subset)
immler@50088
   960
    fix i A assume "i \<in> I" and A: "A \<in> sets (M i)"
immler@50088
   961
    have "(\<lambda>x. (x)\<^isub>F i) \<in> measurable ?P (sigma (space (M i)) (E i))"
immler@50088
   962
    proof (subst measurable_iff_measure_of)
immler@50088
   963
      show "E i \<subseteq> Pow (space (M i))" using `i \<in> I` by fact
immler@50088
   964
      from space_P `i \<in> I` show "(\<lambda>x. (x)\<^isub>F i) \<in> space ?P \<rightarrow> space (M i)"
immler@50088
   965
        by auto
immler@50088
   966
      show "\<forall>A\<in>E i. (\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P \<in> sets ?P"
immler@50088
   967
      proof
immler@50088
   968
        fix A assume A: "A \<in> E i"
immler@50088
   969
        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))"
immler@50088
   970
          using E_closed `i \<in> I` by (auto simp: space_P Pi_iff subset_eq split: split_if_asm)
immler@50088
   971
        also have "\<dots> = (\<Pi>' j\<in>I. \<Union>n. if i = j then A else S j n)"
immler@50088
   972
          by (intro Pi'_cong) (simp_all add: S_union)
immler@50088
   973
        also have "\<dots> = (\<Union>n. \<Pi>' j\<in>I. if i = j then A else S j n)"
immler@50088
   974
          using S_mono
immler@50088
   975
          by (subst Pi'_UN[symmetric, OF `finite I`]) (auto simp: incseq_def)
immler@50088
   976
        also have "\<dots> \<in> sets ?P"
immler@50244
   977
        proof (safe intro!: sets.countable_UN)
immler@50088
   978
          fix n show "(\<Pi>' j\<in>I. if i = j then A else S j n) \<in> sets ?P"
immler@50088
   979
            using A S_in_E
immler@50088
   980
            by (simp add: P_closed)
immler@50088
   981
               (auto simp: P_def subset_eq intro!: exI[of _ "\<lambda>j. if i = j then A else S j n"])
immler@50088
   982
        qed
immler@50088
   983
        finally show "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P \<in> sets ?P"
immler@50088
   984
          using P_closed by simp
immler@50088
   985
      qed
immler@50088
   986
    qed
immler@50088
   987
    from measurable_sets[OF this, of A] A `i \<in> I` E_closed
immler@50088
   988
    have "(\<lambda>x. (x)\<^isub>F i) -` A \<inter> space ?P \<in> sets ?P"
immler@50088
   989
      by (simp add: E_generates)
immler@50088
   990
    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}"
immler@50088
   991
      using P_closed by (auto simp: space_PiF)
immler@50088
   992
    finally show "\<dots> \<in> sets ?P" .
immler@50088
   993
  qed
immler@50088
   994
  finally show "sets (PiF {I} M) \<subseteq> sigma_sets (space (PiF {I} M)) P"
immler@50088
   995
    by (simp add: P_closed)
immler@50088
   996
  show "sigma_sets (space (PiF {I} M)) P \<subseteq> sets (PiF {I} M)"
immler@50088
   997
    using `finite I` `I \<noteq> {}`
immler@50244
   998
    by (auto intro!: sets.sigma_sets_subset product_in_sets_PiFI simp: E_generates P_def)
immler@50088
   999
qed
immler@50088
  1000
immler@50245
  1001
lemma sets_PiF_eq_sigma_union_closed_basis_single:
immler@50088
  1002
  assumes "I \<noteq> {}"
immler@50088
  1003
  assumes [simp]: "finite I"
immler@50088
  1004
  shows "sets (PiF {I} (\<lambda>_. borel)) = sigma_sets (space (PiF {I} (\<lambda>_. borel)))
immler@50245
  1005
    {Pi' I F |F. (\<forall>i\<in>I. F i \<in> union_closed_basis)}"
immler@50088
  1006
proof -
immler@50088
  1007
  from open_incseqE[OF open_UNIV] guess S::"nat \<Rightarrow> 'b set" . note S = this
immler@50088
  1008
  show ?thesis
immler@50088
  1009
  proof (rule sigma_fprod_algebra_sigma_eq)
immler@50088
  1010
    show "finite I" by simp
immler@50088
  1011
    show "I \<noteq> {}" by fact
immler@50245
  1012
    show "incseq S" "(\<Union>j. S j) = space borel" "range S \<subseteq> union_closed_basis"
immler@50088
  1013
      using S by simp_all
immler@50245
  1014
    show "union_closed_basis \<subseteq> Pow (space borel)" by simp
immler@50245
  1015
    show "sets borel = sigma_sets (space borel) union_closed_basis"
immler@50245
  1016
      by (simp add: borel_eq_union_closed_basis)
immler@50088
  1017
  qed
immler@50088
  1018
qed
immler@50088
  1019
immler@50245
  1020
text {* adapted from @{thm sets_PiF_eq_sigma_union_closed_basis_single} *}
immler@50088
  1021
immler@50245
  1022
lemma sets_PiM_eq_sigma_union_closed_basis:
immler@50088
  1023
  assumes "I \<noteq> {}"
immler@50088
  1024
  assumes [simp]: "finite I"
immler@50088
  1025
  shows "sets (PiM I (\<lambda>_. borel)) = sigma_sets (space (PiM I (\<lambda>_. borel)))
immler@50245
  1026
    {Pi\<^isub>E I F |F. \<forall>i\<in>I. F i \<in> union_closed_basis}"
immler@50088
  1027
proof -
immler@50088
  1028
  from open_incseqE[OF open_UNIV] guess S::"nat \<Rightarrow> 'b set" . note S = this
immler@50088
  1029
  show ?thesis
immler@50088
  1030
  proof (rule sigma_prod_algebra_sigma_eq)
immler@50088
  1031
    show "finite I" by simp note[[show_types]]
immler@50245
  1032
    fix i show "(\<Union>j. S j) = space borel" "range S \<subseteq> union_closed_basis"
immler@50088
  1033
      using S by simp_all
immler@50245
  1034
    show "union_closed_basis \<subseteq> Pow (space borel)" by simp
immler@50245
  1035
    show "sets borel = sigma_sets (space borel) union_closed_basis"
immler@50245
  1036
      by (simp add: borel_eq_union_closed_basis)
immler@50088
  1037
  qed
immler@50088
  1038
qed
immler@50088
  1039
immler@50088
  1040
lemma product_open_generates_sets_PiF_single:
immler@50088
  1041
  assumes "I \<noteq> {}"
immler@50088
  1042
  assumes [simp]: "finite I"
hoelzl@50881
  1043
  shows "sets (PiF {I} (\<lambda>_. borel::'b::second_countable_topology measure)) =
immler@50088
  1044
    sigma_sets (space (PiF {I} (\<lambda>_. borel))) {Pi' I F |F. (\<forall>i\<in>I. F i \<in> Collect open)}"
immler@50088
  1045
proof -
immler@50088
  1046
  from open_incseqE[OF open_UNIV] guess S::"nat \<Rightarrow> 'b set" . note S = this
immler@50088
  1047
  show ?thesis
immler@50088
  1048
  proof (rule sigma_fprod_algebra_sigma_eq)
immler@50088
  1049
    show "finite I" by simp
immler@50088
  1050
    show "I \<noteq> {}" by fact
immler@50088
  1051
    show "incseq S" "(\<Union>j. S j) = space borel" "range S \<subseteq> Collect open"
immler@50245
  1052
      using S by (auto simp: open_union_closed_basis)
immler@50088
  1053
    show "Collect open \<subseteq> Pow (space borel)" by simp
immler@50088
  1054
    show "sets borel = sigma_sets (space borel) (Collect open)"
immler@50088
  1055
      by (simp add: borel_def)
immler@50088
  1056
  qed
immler@50088
  1057
qed
immler@50088
  1058
immler@50088
  1059
lemma product_open_generates_sets_PiM:
immler@50088
  1060
  assumes "I \<noteq> {}"
immler@50088
  1061
  assumes [simp]: "finite I"
hoelzl@50881
  1062
  shows "sets (PiM I (\<lambda>_. borel::'b::second_countable_topology measure)) =
immler@50088
  1063
    sigma_sets (space (PiM I (\<lambda>_. borel))) {Pi\<^isub>E I F |F. \<forall>i\<in>I. F i \<in> Collect open}"
immler@50088
  1064
proof -
immler@50088
  1065
  from open_incseqE[OF open_UNIV] guess S::"nat \<Rightarrow> 'b set" . note S = this
immler@50088
  1066
  show ?thesis
immler@50088
  1067
  proof (rule sigma_prod_algebra_sigma_eq)
immler@50088
  1068
    show "finite I" by simp note[[show_types]]
immler@50088
  1069
    fix i show "(\<Union>j. S j) = space borel" "range S \<subseteq> Collect open"
immler@50245
  1070
      using S by (auto simp: open_union_closed_basis)
immler@50088
  1071
    show "Collect open \<subseteq> Pow (space borel)" by simp
immler@50088
  1072
    show "sets borel = sigma_sets (space borel) (Collect open)"
immler@50088
  1073
      by (simp add: borel_def)
immler@50088
  1074
  qed
immler@50088
  1075
qed
immler@50088
  1076
hoelzl@50124
  1077
lemma finmap_UNIV[simp]: "(\<Union>J\<in>Collect finite. PI' j : J. UNIV) = UNIV" by auto
immler@50088
  1078
immler@50088
  1079
lemma borel_eq_PiF_borel:
immler@50088
  1080
  shows "(borel :: ('i::countable \<Rightarrow>\<^isub>F 'a::polish_space) measure) =
immler@50245
  1081
    PiF (Collect finite) (\<lambda>_. borel :: 'a measure)"
immler@50245
  1082
  unfolding borel_def PiF_def
immler@50245
  1083
proof (rule measure_eqI, clarsimp, rule sigma_sets_eqI)
immler@50245
  1084
  fix a::"('i \<Rightarrow>\<^isub>F 'a) set" assume "a \<in> Collect open" hence "open a" by simp
immler@50245
  1085
  then obtain B' where B': "B'\<subseteq>basis_finmap" "a = \<Union>B'"
immler@50245
  1086
    using finmap_topological_basis by (force simp add: topological_basis_def)
immler@50245
  1087
  have "a \<in> sigma UNIV {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
immler@50245
  1088
    unfolding `a = \<Union>B'`
immler@50245
  1089
  proof (rule sets.countable_Union)
immler@50245
  1090
    from B' countable_basis_finmap show "countable B'" by (metis countable_subset)
immler@50088
  1091
  next
immler@50245
  1092
    show "B' \<subseteq> sets (sigma UNIV
immler@50245
  1093
      {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)})" (is "_ \<subseteq> sets ?s")
immler@50088
  1094
    proof
immler@50245
  1095
      fix x assume "x \<in> B'" with B' have "x \<in> basis_finmap" by auto
immler@50245
  1096
      then obtain J X where "x = Pi' J X" "finite J" "X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)"
immler@50245
  1097
        by (auto simp: basis_finmap_def open_union_closed_basis)
immler@50245
  1098
      thus "x \<in> sets ?s" by auto
immler@50088
  1099
    qed
immler@50088
  1100
  qed
immler@50245
  1101
  thus "a \<in> sigma_sets UNIV {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
immler@50245
  1102
    by simp
immler@50245
  1103
next
immler@50245
  1104
  fix b::"('i \<Rightarrow>\<^isub>F 'a) set"
immler@50245
  1105
  assume "b \<in> {Pi' J X |X J. finite J \<and> X \<in> J \<rightarrow> sigma_sets UNIV (Collect open)}"
immler@50245
  1106
  hence b': "b \<in> sets (Pi\<^isub>F (Collect finite) (\<lambda>_. borel))" by (auto simp: sets_PiF borel_def)
immler@50245
  1107
  let ?b = "\<lambda>J. b \<inter> {x. domain x = J}"
immler@50245
  1108
  have "b = \<Union>((\<lambda>J. ?b J) ` Collect finite)" by auto
immler@50245
  1109
  also have "\<dots> \<in> sets borel"
immler@50245
  1110
  proof (rule sets.countable_Union, safe)
immler@50245
  1111
    fix J::"'i set" assume "finite J"
immler@50245
  1112
    { assume ef: "J = {}"
immler@50245
  1113
      have "?b J \<in> sets borel"
immler@50245
  1114
      proof cases
immler@50245
  1115
        assume "?b J \<noteq> {}"
immler@50245
  1116
        then obtain f where "f \<in> b" "domain f = {}" using ef by auto
immler@50245
  1117
        hence "?b J = {f}" using `J = {}`
immler@50245
  1118
          by (auto simp: finmap_eq_iff)
immler@50245
  1119
        also have "{f} \<in> sets borel" by simp
immler@50245
  1120
        finally show ?thesis .
immler@50245
  1121
      qed simp
immler@50245
  1122
    } moreover {
immler@50245
  1123
      assume "J \<noteq> ({}::'i set)"
immler@50245
  1124
      have "(?b J) = b \<inter> {m. domain m \<in> {J}}" by auto
immler@50245
  1125
      also have "\<dots> \<in> sets (PiF {J} (\<lambda>_. borel))"
immler@50245
  1126
        using b' by (rule restrict_sets_measurable) (auto simp: `finite J`)
immler@50245
  1127
      also have "\<dots> = sigma_sets (space (PiF {J} (\<lambda>_. borel)))
immler@50245
  1128
        {Pi' (J) F |F. (\<forall>j\<in>J. F j \<in> Collect open)}"
immler@50245
  1129
        (is "_ = sigma_sets _ ?P")
immler@50245
  1130
       by (rule product_open_generates_sets_PiF_single[OF `J \<noteq> {}` `finite J`])
immler@50245
  1131
      also have "\<dots> \<subseteq> sigma_sets UNIV (Collect open)"
immler@50245
  1132
        by (intro sigma_sets_mono'') (auto intro!: open_Pi'I simp: space_PiF)
immler@50245
  1133
      finally have "(?b J) \<in> sets borel" by (simp add: borel_def)
immler@50245
  1134
    } ultimately show "(?b J) \<in> sets borel" by blast
immler@50245
  1135
  qed (simp add: countable_Collect_finite)
immler@50245
  1136
  finally show "b \<in> sigma_sets UNIV (Collect open)" by (simp add: borel_def)
immler@50088
  1137
qed (simp add: emeasure_sigma borel_def PiF_def)
immler@50088
  1138
immler@50088
  1139
subsection {* Isomorphism between Functions and Finite Maps *}
immler@50088
  1140
hoelzl@50124
  1141
lemma measurable_finmap_compose:
immler@50088
  1142
  shows "(\<lambda>m. compose J m f) \<in> measurable (PiM (f ` J) (\<lambda>_. M)) (PiM J (\<lambda>_. M))"
hoelzl@50124
  1143
  unfolding compose_def by measurable
immler@50088
  1144
hoelzl@50124
  1145
lemma measurable_compose_inv:
immler@50088
  1146
  assumes inj: "\<And>j. j \<in> J \<Longrightarrow> f' (f j) = j"
immler@50088
  1147
  shows "(\<lambda>m. compose (f ` J) m f') \<in> measurable (PiM J (\<lambda>_. M)) (PiM (f ` J) (\<lambda>_. M))"
hoelzl@50124
  1148
  unfolding compose_def by (rule measurable_restrict) (auto simp: inj)
immler@50088
  1149
immler@50088
  1150
locale function_to_finmap =
immler@50088
  1151
  fixes J::"'a set" and f :: "'a \<Rightarrow> 'b::countable" and f'
immler@50088
  1152
  assumes [simp]: "finite J"
immler@50088
  1153
  assumes inv: "i \<in> J \<Longrightarrow> f' (f i) = i"
immler@50088
  1154
begin
immler@50088
  1155
immler@50088
  1156
text {* to measure finmaps *}
immler@50088
  1157
immler@50088
  1158
definition "fm = (finmap_of (f ` J)) o (\<lambda>g. compose (f ` J) g f')"
immler@50088
  1159
immler@50088
  1160
lemma domain_fm[simp]: "domain (fm x) = f ` J"
immler@50088
  1161
  unfolding fm_def by simp
immler@50088
  1162
immler@50088
  1163
lemma fm_restrict[simp]: "fm (restrict y J) = fm y"
immler@50088
  1164
  unfolding fm_def by (auto simp: compose_def inv intro: restrict_ext)
immler@50088
  1165
immler@50088
  1166
lemma fm_product:
immler@50088
  1167
  assumes "\<And>i. space (M i) = UNIV"
immler@50088
  1168
  shows "fm -` Pi' (f ` J) S \<inter> space (Pi\<^isub>M J M) = (\<Pi>\<^isub>E j \<in> J. S (f j))"
immler@50088
  1169
  using assms
immler@50088
  1170
  by (auto simp: inv fm_def compose_def space_PiM Pi'_def)
immler@50088
  1171
immler@50088
  1172
lemma fm_measurable:
immler@50088
  1173
  assumes "f ` J \<in> N"
immler@50088
  1174
  shows "fm \<in> measurable (Pi\<^isub>M J (\<lambda>_. M)) (Pi\<^isub>F N (\<lambda>_. M))"
immler@50088
  1175
  unfolding fm_def
immler@50088
  1176
proof (rule measurable_comp, rule measurable_compose_inv)
immler@50088
  1177
  show "finmap_of (f ` J) \<in> measurable (Pi\<^isub>M (f ` J) (\<lambda>_. M)) (PiF N (\<lambda>_. M)) "
immler@50088
  1178
    using assms by (intro measurable_finmap_of measurable_component_singleton) auto
immler@50088
  1179
qed (simp_all add: inv)
immler@50088
  1180
immler@50088
  1181
lemma proj_fm:
immler@50088
  1182
  assumes "x \<in> J"
immler@50088
  1183
  shows "fm m (f x) = m x"
immler@50088
  1184
  using assms by (auto simp: fm_def compose_def o_def inv)
immler@50088
  1185
immler@50088
  1186
lemma inj_on_compose_f': "inj_on (\<lambda>g. compose (f ` J) g f') (extensional J)"
immler@50088
  1187
proof (rule inj_on_inverseI)
immler@50088
  1188
  fix x::"'a \<Rightarrow> 'c" assume "x \<in> extensional J"
immler@50088
  1189
  thus "(\<lambda>x. compose J x f) (compose (f ` J) x f') = x"
immler@50088
  1190
    by (auto simp: compose_def inv extensional_def)
immler@50088
  1191
qed
immler@50088
  1192
immler@50088
  1193
lemma inj_on_fm:
immler@50088
  1194
  assumes "\<And>i. space (M i) = UNIV"
immler@50088
  1195
  shows "inj_on fm (space (Pi\<^isub>M J M))"
immler@50088
  1196
  using assms
hoelzl@50123
  1197
  apply (auto simp: fm_def space_PiM PiE_def)
immler@50088
  1198
  apply (rule comp_inj_on)
immler@50088
  1199
  apply (rule inj_on_compose_f')
immler@50088
  1200
  apply (rule finmap_of_inj_on_extensional_finite)
immler@50088
  1201
  apply simp
immler@50088
  1202
  apply (auto)
immler@50088
  1203
  done
immler@50088
  1204
immler@50088
  1205
text {* to measure functions *}
immler@50088
  1206
immler@50088
  1207
definition "mf = (\<lambda>g. compose J g f) o proj"
immler@50088
  1208
immler@50088
  1209
lemma mf_fm:
immler@50088
  1210
  assumes "x \<in> space (Pi\<^isub>M J (\<lambda>_. M))"
immler@50088
  1211
  shows "mf (fm x) = x"
immler@50088
  1212
proof -
immler@50088
  1213
  have "mf (fm x) \<in> extensional J"
immler@50088
  1214
    by (auto simp: mf_def extensional_def compose_def)
immler@50088
  1215
  moreover
immler@50244
  1216
  have "x \<in> extensional J" using assms sets.sets_into_space
hoelzl@50123
  1217
    by (force simp: space_PiM PiE_def)
immler@50088
  1218
  moreover
immler@50088
  1219
  { fix i assume "i \<in> J"
immler@50088
  1220
    hence "mf (fm x) i = x i"
immler@50088
  1221
      by (auto simp: inv mf_def compose_def fm_def)
immler@50088
  1222
  }
immler@50088
  1223
  ultimately
immler@50088
  1224
  show ?thesis by (rule extensionalityI)
immler@50088
  1225
qed
immler@50088
  1226
immler@50088
  1227
lemma mf_measurable:
immler@50088
  1228
  assumes "space M = UNIV"
immler@50088
  1229
  shows "mf \<in> measurable (PiF {f ` J} (\<lambda>_. M)) (PiM J (\<lambda>_. M))"
immler@50088
  1230
  unfolding mf_def
immler@50088
  1231
proof (rule measurable_comp, rule measurable_proj_PiM)
hoelzl@50124
  1232
  show "(\<lambda>g. compose J g f) \<in> measurable (Pi\<^isub>M (f ` J) (\<lambda>x. M)) (Pi\<^isub>M J (\<lambda>_. M))"
hoelzl@50124
  1233
    by (rule measurable_finmap_compose)
immler@50088
  1234
qed (auto simp add: space_PiM extensional_def assms)
immler@50088
  1235
immler@50088
  1236
lemma fm_image_measurable:
immler@50088
  1237
  assumes "space M = UNIV"
immler@50088
  1238
  assumes "X \<in> sets (Pi\<^isub>M J (\<lambda>_. M))"
immler@50088
  1239
  shows "fm ` X \<in> sets (PiF {f ` J} (\<lambda>_. M))"
immler@50088
  1240
proof -
immler@50088
  1241
  have "fm ` X = (mf) -` X \<inter> space (PiF {f ` J} (\<lambda>_. M))"
immler@50088
  1242
  proof safe
immler@50088
  1243
    fix x assume "x \<in> X"
immler@50244
  1244
    with mf_fm[of x] sets.sets_into_space[OF assms(2)] show "fm x \<in> mf -` X" by auto
immler@50088
  1245
    show "fm x \<in> space (PiF {f ` J} (\<lambda>_. M))" by (simp add: space_PiF assms)
immler@50088
  1246
  next
immler@50088
  1247
    fix y x
immler@50088
  1248
    assume x: "mf y \<in> X"
immler@50088
  1249
    assume y: "y \<in> space (PiF {f ` J} (\<lambda>_. M))"
immler@50088
  1250
    thus "y \<in> fm ` X"
immler@50088
  1251
      by (intro image_eqI[OF _ x], unfold finmap_eq_iff)
immler@50088
  1252
         (auto simp: space_PiF fm_def mf_def compose_def inv Pi'_def)
immler@50088
  1253
  qed
immler@50088
  1254
  also have "\<dots> \<in> sets (PiF {f ` J} (\<lambda>_. M))"
immler@50088
  1255
    using assms
immler@50088
  1256
    by (intro measurable_sets[OF mf_measurable]) auto
immler@50088
  1257
  finally show ?thesis .
immler@50088
  1258
qed
immler@50088
  1259
immler@50088
  1260
lemma fm_image_measurable_finite:
immler@50088
  1261
  assumes "space M = UNIV"
immler@50088
  1262
  assumes "X \<in> sets (Pi\<^isub>M J (\<lambda>_. M::'c measure))"
immler@50088
  1263
  shows "fm ` X \<in> sets (PiF (Collect finite) (\<lambda>_. M::'c measure))"
immler@50088
  1264
  using fm_image_measurable[OF assms]
immler@50088
  1265
  by (rule subspace_set_in_sets) (auto simp: finite_subset)
immler@50088
  1266
immler@50088
  1267
text {* measure on finmaps *}
immler@50088
  1268
immler@50088
  1269
definition "mapmeasure M N = distr M (PiF (Collect finite) N) (fm)"
immler@50088
  1270
immler@50088
  1271
lemma sets_mapmeasure[simp]: "sets (mapmeasure M N) = sets (PiF (Collect finite) N)"
immler@50088
  1272
  unfolding mapmeasure_def by simp
immler@50088
  1273
immler@50088
  1274
lemma space_mapmeasure[simp]: "space (mapmeasure M N) = space (PiF (Collect finite) N)"
immler@50088
  1275
  unfolding mapmeasure_def by simp
immler@50088
  1276
immler@50088
  1277
lemma mapmeasure_PiF:
immler@50088
  1278
  assumes s1: "space M = space (Pi\<^isub>M J (\<lambda>_. N))"
hoelzl@50123
  1279
  assumes s2: "sets M = sets (Pi\<^isub>M J (\<lambda>_. N))"
immler@50088
  1280
  assumes "space N = UNIV"
immler@50088
  1281
  assumes "X \<in> sets (PiF (Collect finite) (\<lambda>_. N))"
immler@50088
  1282
  shows "emeasure (mapmeasure M (\<lambda>_. N)) X = emeasure M ((fm -` X \<inter> extensional J))"
immler@50088
  1283
  using assms
immler@50088
  1284
  by (auto simp: measurable_eqI[OF s1 refl s2 refl] mapmeasure_def emeasure_distr
hoelzl@50123
  1285
    fm_measurable space_PiM PiE_def)
immler@50088
  1286
immler@50088
  1287
lemma mapmeasure_PiM:
immler@50088
  1288
  fixes N::"'c measure"
immler@50088
  1289
  assumes s1: "space M = space (Pi\<^isub>M J (\<lambda>_. N))"
immler@50088
  1290
  assumes s2: "sets M = (Pi\<^isub>M J (\<lambda>_. N))"
immler@50088
  1291
  assumes N: "space N = UNIV"
immler@50088
  1292
  assumes X: "X \<in> sets M"
immler@50088
  1293
  shows "emeasure M X = emeasure (mapmeasure M (\<lambda>_. N)) (fm ` X)"
immler@50088
  1294
  unfolding mapmeasure_def
immler@50088
  1295
proof (subst emeasure_distr, subst measurable_eqI[OF s1 refl s2 refl], rule fm_measurable)
immler@50244
  1296
  have "X \<subseteq> space (Pi\<^isub>M J (\<lambda>_. N))" using assms by (simp add: sets.sets_into_space)
immler@50088
  1297
  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"
immler@50088
  1298
    by (auto simp: vimage_image_eq inj_on_def)
immler@50088
  1299
  thus "emeasure M X = emeasure M (fm -` fm ` X \<inter> space M)" using s1
immler@50088
  1300
    by simp
immler@50088
  1301
  show "fm ` X \<in> sets (PiF (Collect finite) (\<lambda>_. N))"
immler@50088
  1302
    by (rule fm_image_measurable_finite[OF N X[simplified s2]])
immler@50088
  1303
qed simp
immler@50088
  1304
immler@50088
  1305
end
immler@50088
  1306
immler@50088
  1307
end