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