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