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