src/HOL/Probability/Borel_Space.thy
author immler
Wed Feb 13 16:35:07 2013 +0100 (2013-02-13)
changeset 51106 5746e671ea70
parent 50882 a382bf90867e
child 51351 dd1dd470690b
permissions -rw-r--r--
eliminated union_closed_basis; cleanup Fin_Map
wenzelm@42150
     1
(*  Title:      HOL/Probability/Borel_Space.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
    Author:     Armin Heller, TU München
hoelzl@42067
     4
*)
hoelzl@38656
     5
hoelzl@38656
     6
header {*Borel spaces*}
paulson@33533
     7
hoelzl@40859
     8
theory Borel_Space
hoelzl@50387
     9
imports
hoelzl@50387
    10
  Measurable
hoelzl@50387
    11
  "~~/src/HOL/Multivariate_Analysis/Multivariate_Analysis"
paulson@33533
    12
begin
paulson@33533
    13
hoelzl@38656
    14
section "Generic Borel spaces"
paulson@33533
    15
hoelzl@47694
    16
definition borel :: "'a::topological_space measure" where
hoelzl@47694
    17
  "borel = sigma UNIV {S. open S}"
paulson@33533
    18
hoelzl@47694
    19
abbreviation "borel_measurable M \<equiv> measurable M borel"
paulson@33533
    20
paulson@33533
    21
lemma in_borel_measurable:
paulson@33533
    22
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@47694
    23
    (\<forall>S \<in> sigma_sets UNIV {S. open S}. f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
    24
  by (auto simp add: measurable_def borel_def)
paulson@33533
    25
hoelzl@40859
    26
lemma in_borel_measurable_borel:
hoelzl@38656
    27
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
    28
    (\<forall>S \<in> sets borel.
hoelzl@38656
    29
      f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
    30
  by (auto simp add: measurable_def borel_def)
paulson@33533
    31
hoelzl@40859
    32
lemma space_borel[simp]: "space borel = UNIV"
hoelzl@40859
    33
  unfolding borel_def by auto
hoelzl@38656
    34
hoelzl@50002
    35
lemma space_in_borel[measurable]: "UNIV \<in> sets borel"
hoelzl@50002
    36
  unfolding borel_def by auto
hoelzl@50002
    37
hoelzl@50387
    38
lemma pred_Collect_borel[measurable (raw)]: "Measurable.pred borel P \<Longrightarrow> {x. P x} \<in> sets borel"
hoelzl@50002
    39
  unfolding borel_def pred_def by auto
hoelzl@50002
    40
hoelzl@50003
    41
lemma borel_open[measurable (raw generic)]:
hoelzl@40859
    42
  assumes "open A" shows "A \<in> sets borel"
hoelzl@38656
    43
proof -
huffman@44537
    44
  have "A \<in> {S. open S}" unfolding mem_Collect_eq using assms .
hoelzl@47694
    45
  thus ?thesis unfolding borel_def by auto
paulson@33533
    46
qed
paulson@33533
    47
hoelzl@50003
    48
lemma borel_closed[measurable (raw generic)]:
hoelzl@40859
    49
  assumes "closed A" shows "A \<in> sets borel"
paulson@33533
    50
proof -
hoelzl@40859
    51
  have "space borel - (- A) \<in> sets borel"
hoelzl@40859
    52
    using assms unfolding closed_def by (blast intro: borel_open)
hoelzl@38656
    53
  thus ?thesis by simp
paulson@33533
    54
qed
paulson@33533
    55
hoelzl@50003
    56
lemma borel_singleton[measurable]:
hoelzl@50003
    57
  "A \<in> sets borel \<Longrightarrow> insert x A \<in> sets (borel :: 'a::t1_space measure)"
immler@50244
    58
  unfolding insert_def by (rule sets.Un) auto
hoelzl@50002
    59
hoelzl@50003
    60
lemma borel_comp[measurable]: "A \<in> sets borel \<Longrightarrow> - A \<in> sets borel"
hoelzl@50002
    61
  unfolding Compl_eq_Diff_UNIV by simp
hoelzl@41830
    62
hoelzl@47694
    63
lemma borel_measurable_vimage:
hoelzl@38656
    64
  fixes f :: "'a \<Rightarrow> 'x::t2_space"
hoelzl@50002
    65
  assumes borel[measurable]: "f \<in> borel_measurable M"
hoelzl@38656
    66
  shows "f -` {x} \<inter> space M \<in> sets M"
hoelzl@50002
    67
  by simp
paulson@33533
    68
hoelzl@47694
    69
lemma borel_measurableI:
hoelzl@38656
    70
  fixes f :: "'a \<Rightarrow> 'x\<Colon>topological_space"
hoelzl@38656
    71
  assumes "\<And>S. open S \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
hoelzl@38656
    72
  shows "f \<in> borel_measurable M"
hoelzl@40859
    73
  unfolding borel_def
hoelzl@47694
    74
proof (rule measurable_measure_of, simp_all)
huffman@44537
    75
  fix S :: "'x set" assume "open S" thus "f -` S \<inter> space M \<in> sets M"
huffman@44537
    76
    using assms[of S] by simp
hoelzl@40859
    77
qed
paulson@33533
    78
hoelzl@50021
    79
lemma borel_measurable_const:
hoelzl@38656
    80
  "(\<lambda>x. c) \<in> borel_measurable M"
hoelzl@47694
    81
  by auto
paulson@33533
    82
hoelzl@50003
    83
lemma borel_measurable_indicator:
hoelzl@38656
    84
  assumes A: "A \<in> sets M"
hoelzl@38656
    85
  shows "indicator A \<in> borel_measurable M"
wenzelm@46905
    86
  unfolding indicator_def [abs_def] using A
hoelzl@47694
    87
  by (auto intro!: measurable_If_set)
paulson@33533
    88
hoelzl@50096
    89
lemma borel_measurable_count_space[measurable (raw)]:
hoelzl@50096
    90
  "f \<in> borel_measurable (count_space S)"
hoelzl@50096
    91
  unfolding measurable_def by auto
hoelzl@50096
    92
hoelzl@50096
    93
lemma borel_measurable_indicator'[measurable (raw)]:
hoelzl@50096
    94
  assumes [measurable]: "{x\<in>space M. f x \<in> A x} \<in> sets M"
hoelzl@50096
    95
  shows "(\<lambda>x. indicator (A x) (f x)) \<in> borel_measurable M"
hoelzl@50001
    96
  unfolding indicator_def[abs_def]
hoelzl@50001
    97
  by (auto intro!: measurable_If)
hoelzl@50001
    98
hoelzl@47694
    99
lemma borel_measurable_indicator_iff:
hoelzl@40859
   100
  "(indicator A :: 'a \<Rightarrow> 'x::{t1_space, zero_neq_one}) \<in> borel_measurable M \<longleftrightarrow> A \<inter> space M \<in> sets M"
hoelzl@40859
   101
    (is "?I \<in> borel_measurable M \<longleftrightarrow> _")
hoelzl@40859
   102
proof
hoelzl@40859
   103
  assume "?I \<in> borel_measurable M"
hoelzl@40859
   104
  then have "?I -` {1} \<inter> space M \<in> sets M"
hoelzl@40859
   105
    unfolding measurable_def by auto
hoelzl@40859
   106
  also have "?I -` {1} \<inter> space M = A \<inter> space M"
wenzelm@46905
   107
    unfolding indicator_def [abs_def] by auto
hoelzl@40859
   108
  finally show "A \<inter> space M \<in> sets M" .
hoelzl@40859
   109
next
hoelzl@40859
   110
  assume "A \<inter> space M \<in> sets M"
hoelzl@40859
   111
  moreover have "?I \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
   112
    (indicator (A \<inter> space M) :: 'a \<Rightarrow> 'x) \<in> borel_measurable M"
hoelzl@40859
   113
    by (intro measurable_cong) (auto simp: indicator_def)
hoelzl@40859
   114
  ultimately show "?I \<in> borel_measurable M" by auto
hoelzl@40859
   115
qed
hoelzl@40859
   116
hoelzl@47694
   117
lemma borel_measurable_subalgebra:
hoelzl@41545
   118
  assumes "sets N \<subseteq> sets M" "space N = space M" "f \<in> borel_measurable N"
hoelzl@39092
   119
  shows "f \<in> borel_measurable M"
hoelzl@39092
   120
  using assms unfolding measurable_def by auto
hoelzl@39092
   121
hoelzl@50002
   122
lemma borel_measurable_continuous_on1:
hoelzl@50002
   123
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@50002
   124
  assumes "continuous_on UNIV f"
hoelzl@50002
   125
  shows "f \<in> borel_measurable borel"
hoelzl@50002
   126
  apply(rule borel_measurableI)
hoelzl@50002
   127
  using continuous_open_preimage[OF assms] unfolding vimage_def by auto
hoelzl@50002
   128
immler@50245
   129
lemma borel_eq_countable_basis:
immler@50245
   130
  fixes B::"'a::topological_space set set"
immler@50245
   131
  assumes "countable B"
immler@50245
   132
  assumes "topological_basis B"
immler@50245
   133
  shows "borel = sigma UNIV B"
immler@50087
   134
  unfolding borel_def
immler@50087
   135
proof (intro sigma_eqI sigma_sets_eqI, safe)
immler@50245
   136
  interpret countable_basis using assms by unfold_locales
immler@50245
   137
  fix X::"'a set" assume "open X"
immler@50245
   138
  from open_countable_basisE[OF this] guess B' . note B' = this
immler@50245
   139
  show "X \<in> sigma_sets UNIV B"
immler@50245
   140
  proof cases
immler@50245
   141
    assume "B' \<noteq> {}"
immler@50245
   142
    thus "X \<in> sigma_sets UNIV B" using assms B'
immler@50245
   143
      by (metis from_nat_into Union_image_eq countable_subset range_from_nat_into
immler@50245
   144
        in_mono sigma_sets.Basic sigma_sets.Union)
immler@50245
   145
  qed (simp add: sigma_sets.Empty B')
immler@50087
   146
next
immler@50245
   147
  fix b assume "b \<in> B"
immler@50245
   148
  hence "open b" by (rule topological_basis_open[OF assms(2)])
immler@50245
   149
  thus "b \<in> sigma_sets UNIV (Collect open)" by auto
immler@50087
   150
qed simp_all
immler@50087
   151
hoelzl@50526
   152
lemma borel_measurable_Pair[measurable (raw)]:
hoelzl@50881
   153
  fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
hoelzl@50526
   154
  assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50526
   155
  assumes g[measurable]: "g \<in> borel_measurable M"
hoelzl@50526
   156
  shows "(\<lambda>x. (f x, g x)) \<in> borel_measurable M"
hoelzl@50526
   157
proof (subst borel_eq_countable_basis)
hoelzl@50526
   158
  let ?B = "SOME B::'b set set. countable B \<and> topological_basis B"
hoelzl@50526
   159
  let ?C = "SOME B::'c set set. countable B \<and> topological_basis B"
hoelzl@50526
   160
  let ?P = "(\<lambda>(b, c). b \<times> c) ` (?B \<times> ?C)"
hoelzl@50526
   161
  show "countable ?P" "topological_basis ?P"
hoelzl@50526
   162
    by (auto intro!: countable_basis topological_basis_prod is_basis)
hoelzl@38656
   163
hoelzl@50526
   164
  show "(\<lambda>x. (f x, g x)) \<in> measurable M (sigma UNIV ?P)"
hoelzl@50526
   165
  proof (rule measurable_measure_of)
hoelzl@50526
   166
    fix S assume "S \<in> ?P"
hoelzl@50526
   167
    then obtain b c where "b \<in> ?B" "c \<in> ?C" and S: "S = b \<times> c" by auto
hoelzl@50526
   168
    then have borel: "open b" "open c"
hoelzl@50526
   169
      by (auto intro: is_basis topological_basis_open)
hoelzl@50526
   170
    have "(\<lambda>x. (f x, g x)) -` S \<inter> space M = (f -` b \<inter> space M) \<inter> (g -` c \<inter> space M)"
hoelzl@50526
   171
      unfolding S by auto
hoelzl@50526
   172
    also have "\<dots> \<in> sets M"
hoelzl@50526
   173
      using borel by simp
hoelzl@50526
   174
    finally show "(\<lambda>x. (f x, g x)) -` S \<inter> space M \<in> sets M" .
hoelzl@50526
   175
  qed auto
hoelzl@39087
   176
qed
hoelzl@39087
   177
hoelzl@49774
   178
lemma borel_measurable_continuous_on:
hoelzl@49774
   179
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@49774
   180
  assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
hoelzl@49774
   181
  shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
hoelzl@49774
   182
  using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
hoelzl@49774
   183
hoelzl@49774
   184
lemma borel_measurable_continuous_on_open':
hoelzl@49774
   185
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@49774
   186
  assumes cont: "continuous_on A f" "open A"
hoelzl@49774
   187
  shows "(\<lambda>x. if x \<in> A then f x else c) \<in> borel_measurable borel" (is "?f \<in> _")
hoelzl@49774
   188
proof (rule borel_measurableI)
hoelzl@49774
   189
  fix S :: "'b set" assume "open S"
hoelzl@49774
   190
  then have "open {x\<in>A. f x \<in> S}"
hoelzl@49774
   191
    by (intro continuous_open_preimage[OF cont]) auto
hoelzl@49774
   192
  then have *: "{x\<in>A. f x \<in> S} \<in> sets borel" by auto
hoelzl@49774
   193
  have "?f -` S \<inter> space borel = 
hoelzl@49774
   194
    {x\<in>A. f x \<in> S} \<union> (if c \<in> S then space borel - A else {})"
hoelzl@49774
   195
    by (auto split: split_if_asm)
hoelzl@49774
   196
  also have "\<dots> \<in> sets borel"
hoelzl@50002
   197
    using * `open A` by auto
hoelzl@49774
   198
  finally show "?f -` S \<inter> space borel \<in> sets borel" .
hoelzl@49774
   199
qed
hoelzl@49774
   200
hoelzl@49774
   201
lemma borel_measurable_continuous_on_open:
hoelzl@49774
   202
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@49774
   203
  assumes cont: "continuous_on A f" "open A"
hoelzl@49774
   204
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   205
  shows "(\<lambda>x. if g x \<in> A then f (g x) else c) \<in> borel_measurable M"
hoelzl@49774
   206
  using measurable_comp[OF g borel_measurable_continuous_on_open'[OF cont], of c]
hoelzl@49774
   207
  by (simp add: comp_def)
hoelzl@49774
   208
hoelzl@49774
   209
lemma continuous_on_fst: "continuous_on UNIV fst"
hoelzl@49774
   210
proof -
hoelzl@49774
   211
  have [simp]: "range fst = UNIV" by (auto simp: image_iff)
hoelzl@49774
   212
  show ?thesis
hoelzl@49774
   213
    using closed_vimage_fst
hoelzl@49774
   214
    by (auto simp: continuous_on_closed closed_closedin vimage_def)
hoelzl@49774
   215
qed
hoelzl@49774
   216
hoelzl@49774
   217
lemma continuous_on_snd: "continuous_on UNIV snd"
hoelzl@49774
   218
proof -
hoelzl@49774
   219
  have [simp]: "range snd = UNIV" by (auto simp: image_iff)
hoelzl@49774
   220
  show ?thesis
hoelzl@49774
   221
    using closed_vimage_snd
hoelzl@49774
   222
    by (auto simp: continuous_on_closed closed_closedin vimage_def)
hoelzl@49774
   223
qed
hoelzl@49774
   224
hoelzl@49774
   225
lemma borel_measurable_continuous_Pair:
hoelzl@50881
   226
  fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
hoelzl@50003
   227
  assumes [measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   228
  assumes [measurable]: "g \<in> borel_measurable M"
hoelzl@49774
   229
  assumes H: "continuous_on UNIV (\<lambda>x. H (fst x) (snd x))"
hoelzl@49774
   230
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   231
proof -
hoelzl@49774
   232
  have eq: "(\<lambda>x. H (f x) (g x)) = (\<lambda>x. (\<lambda>x. H (fst x) (snd x)) (f x, g x))" by auto
hoelzl@49774
   233
  show ?thesis
hoelzl@49774
   234
    unfolding eq by (rule borel_measurable_continuous_on[OF H]) auto
hoelzl@49774
   235
qed
hoelzl@49774
   236
hoelzl@50526
   237
section "Borel spaces on euclidean spaces"
hoelzl@50526
   238
hoelzl@50526
   239
lemma borel_measurable_inner[measurable (raw)]:
hoelzl@50881
   240
  fixes f g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_inner}"
hoelzl@50526
   241
  assumes "f \<in> borel_measurable M"
hoelzl@50526
   242
  assumes "g \<in> borel_measurable M"
hoelzl@50526
   243
  shows "(\<lambda>x. f x \<bullet> g x) \<in> borel_measurable M"
hoelzl@50526
   244
  using assms
hoelzl@50526
   245
  by (rule borel_measurable_continuous_Pair)
hoelzl@50526
   246
     (intro continuous_on_inner continuous_on_snd continuous_on_fst)
hoelzl@50526
   247
hoelzl@50526
   248
lemma [measurable]:
hoelzl@50526
   249
  fixes a b :: "'a\<Colon>ordered_euclidean_space"
hoelzl@50526
   250
  shows lessThan_borel: "{..< a} \<in> sets borel"
hoelzl@50526
   251
    and greaterThan_borel: "{a <..} \<in> sets borel"
hoelzl@50526
   252
    and greaterThanLessThan_borel: "{a<..<b} \<in> sets borel"
hoelzl@50526
   253
    and atMost_borel: "{..a} \<in> sets borel"
hoelzl@50526
   254
    and atLeast_borel: "{a..} \<in> sets borel"
hoelzl@50526
   255
    and atLeastAtMost_borel: "{a..b} \<in> sets borel"
hoelzl@50526
   256
    and greaterThanAtMost_borel: "{a<..b} \<in> sets borel"
hoelzl@50526
   257
    and atLeastLessThan_borel: "{a..<b} \<in> sets borel"
hoelzl@50526
   258
  unfolding greaterThanAtMost_def atLeastLessThan_def
hoelzl@50526
   259
  by (blast intro: borel_open borel_closed)+
hoelzl@50526
   260
hoelzl@50526
   261
lemma borel_measurable_less[measurable]:
hoelzl@50526
   262
  fixes f :: "'a \<Rightarrow> real"
hoelzl@50526
   263
  assumes f: "f \<in> borel_measurable M"
hoelzl@50526
   264
  assumes g: "g \<in> borel_measurable M"
hoelzl@50526
   265
  shows "{w \<in> space M. f w < g w} \<in> sets M"
hoelzl@50526
   266
proof -
hoelzl@50526
   267
  have "{w \<in> space M. f w < g w} = {x \<in> space M. \<exists>r. f x < of_rat r \<and> of_rat r < g x}"
hoelzl@50526
   268
    using Rats_dense_in_real by (auto simp add: Rats_def)
hoelzl@50526
   269
  with f g show ?thesis
hoelzl@50526
   270
    by simp
hoelzl@50526
   271
qed
hoelzl@50526
   272
hoelzl@50526
   273
lemma
hoelzl@50526
   274
  fixes f :: "'a \<Rightarrow> real"
hoelzl@50526
   275
  assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50526
   276
  assumes g[measurable]: "g \<in> borel_measurable M"
hoelzl@50526
   277
  shows borel_measurable_le[measurable]: "{w \<in> space M. f w \<le> g w} \<in> sets M"
hoelzl@50526
   278
    and borel_measurable_eq[measurable]: "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@50526
   279
    and borel_measurable_neq: "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
hoelzl@50526
   280
  unfolding eq_iff not_less[symmetric]
hoelzl@50526
   281
  by measurable
hoelzl@50526
   282
hoelzl@50526
   283
lemma 
hoelzl@50526
   284
  shows hafspace_less_borel: "{x::'a::euclidean_space. a < x \<bullet> i} \<in> sets borel"
hoelzl@50526
   285
    and hafspace_greater_borel: "{x::'a::euclidean_space. x \<bullet> i < a} \<in> sets borel"
hoelzl@50526
   286
    and hafspace_less_eq_borel: "{x::'a::euclidean_space. a \<le> x \<bullet> i} \<in> sets borel"
hoelzl@50526
   287
    and hafspace_greater_eq_borel: "{x::'a::euclidean_space. x \<bullet> i \<le> a} \<in> sets borel"
hoelzl@50526
   288
  by simp_all
hoelzl@50526
   289
hoelzl@50526
   290
subsection "Borel space equals sigma algebras over intervals"
hoelzl@50526
   291
hoelzl@50526
   292
lemma borel_sigma_sets_subset:
hoelzl@50526
   293
  "A \<subseteq> sets borel \<Longrightarrow> sigma_sets UNIV A \<subseteq> sets borel"
hoelzl@50526
   294
  using sets.sigma_sets_subset[of A borel] by simp
hoelzl@50526
   295
hoelzl@50526
   296
lemma borel_eq_sigmaI1:
hoelzl@50526
   297
  fixes F :: "'i \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@50526
   298
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@50526
   299
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV (F ` A))"
hoelzl@50526
   300
  assumes F: "\<And>i. i \<in> A \<Longrightarrow> F i \<in> sets borel"
hoelzl@50526
   301
  shows "borel = sigma UNIV (F ` A)"
hoelzl@50526
   302
  unfolding borel_def
hoelzl@50526
   303
proof (intro sigma_eqI antisym)
hoelzl@50526
   304
  have borel_rev_eq: "sigma_sets UNIV {S::'a set. open S} = sets borel"
hoelzl@50526
   305
    unfolding borel_def by simp
hoelzl@50526
   306
  also have "\<dots> = sigma_sets UNIV X"
hoelzl@50526
   307
    unfolding borel_eq by simp
hoelzl@50526
   308
  also have "\<dots> \<subseteq> sigma_sets UNIV (F`A)"
hoelzl@50526
   309
    using X by (intro sigma_algebra.sigma_sets_subset[OF sigma_algebra_sigma_sets]) auto
hoelzl@50526
   310
  finally show "sigma_sets UNIV {S. open S} \<subseteq> sigma_sets UNIV (F`A)" .
hoelzl@50526
   311
  show "sigma_sets UNIV (F`A) \<subseteq> sigma_sets UNIV {S. open S}"
hoelzl@50526
   312
    unfolding borel_rev_eq using F by (intro borel_sigma_sets_subset) auto
hoelzl@50526
   313
qed auto
hoelzl@50526
   314
hoelzl@50526
   315
lemma borel_eq_sigmaI2:
hoelzl@50526
   316
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   317
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   318
  assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`B)"
hoelzl@50526
   319
  assumes X: "\<And>i j. (i, j) \<in> B \<Longrightarrow> G i j \<in> sets (sigma UNIV ((\<lambda>(i, j). F i j) ` A))"
hoelzl@50526
   320
  assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
hoelzl@50526
   321
  shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
hoelzl@50526
   322
  using assms
hoelzl@50526
   323
  by (intro borel_eq_sigmaI1[where X="(\<lambda>(i, j). G i j) ` B" and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@50526
   324
hoelzl@50526
   325
lemma borel_eq_sigmaI3:
hoelzl@50526
   326
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@50526
   327
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@50526
   328
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV ((\<lambda>(i, j). F i j) ` A))"
hoelzl@50526
   329
  assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
hoelzl@50526
   330
  shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
hoelzl@50526
   331
  using assms by (intro borel_eq_sigmaI1[where X=X and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@50526
   332
hoelzl@50526
   333
lemma borel_eq_sigmaI4:
hoelzl@50526
   334
  fixes F :: "'i \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   335
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   336
  assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`A)"
hoelzl@50526
   337
  assumes X: "\<And>i j. (i, j) \<in> A \<Longrightarrow> G i j \<in> sets (sigma UNIV (range F))"
hoelzl@50526
   338
  assumes F: "\<And>i. F i \<in> sets borel"
hoelzl@50526
   339
  shows "borel = sigma UNIV (range F)"
hoelzl@50526
   340
  using assms by (intro borel_eq_sigmaI1[where X="(\<lambda>(i, j). G i j) ` A" and F=F]) auto
hoelzl@50526
   341
hoelzl@50526
   342
lemma borel_eq_sigmaI5:
hoelzl@50526
   343
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and G :: "'l \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   344
  assumes borel_eq: "borel = sigma UNIV (range G)"
hoelzl@50526
   345
  assumes X: "\<And>i. G i \<in> sets (sigma UNIV (range (\<lambda>(i, j). F i j)))"
hoelzl@50526
   346
  assumes F: "\<And>i j. F i j \<in> sets borel"
hoelzl@50526
   347
  shows "borel = sigma UNIV (range (\<lambda>(i, j). F i j))"
hoelzl@50526
   348
  using assms by (intro borel_eq_sigmaI1[where X="range G" and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@50526
   349
hoelzl@50526
   350
lemma borel_eq_box:
hoelzl@50526
   351
  "borel = sigma UNIV (range (\<lambda> (a, b). box a b :: 'a \<Colon> euclidean_space set))"
hoelzl@50526
   352
    (is "_ = ?SIGMA")
hoelzl@50526
   353
proof (rule borel_eq_sigmaI1[OF borel_def])
hoelzl@50526
   354
  fix M :: "'a set" assume "M \<in> {S. open S}"
hoelzl@50526
   355
  then have "open M" by simp
hoelzl@50526
   356
  show "M \<in> ?SIGMA"
hoelzl@50526
   357
    apply (subst open_UNION_box[OF `open M`])
hoelzl@50526
   358
    apply (safe intro!: sets.countable_UN' countable_PiE countable_Collect)
hoelzl@50526
   359
    apply (auto intro: countable_rat)
hoelzl@50526
   360
    done
hoelzl@50526
   361
qed (auto simp: box_def)
hoelzl@50526
   362
hoelzl@50526
   363
lemma borel_eq_greaterThanLessThan:
hoelzl@50526
   364
  "borel = sigma UNIV (range (\<lambda> (a, b). {a <..< b} :: 'a \<Colon> ordered_euclidean_space set))"
hoelzl@50526
   365
  unfolding borel_eq_box apply (rule arg_cong2[where f=sigma])
hoelzl@50526
   366
  by (auto simp: box_def image_iff mem_interval set_eq_iff simp del: greaterThanLessThan_iff)
hoelzl@50526
   367
hoelzl@50526
   368
lemma halfspace_gt_in_halfspace:
hoelzl@50526
   369
  assumes i: "i \<in> A"
hoelzl@50526
   370
  shows "{x\<Colon>'a. a < x \<bullet> i} \<in> 
hoelzl@50526
   371
    sigma_sets UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> A))"
hoelzl@50526
   372
  (is "?set \<in> ?SIGMA")
hoelzl@50526
   373
proof -
hoelzl@50526
   374
  interpret sigma_algebra UNIV ?SIGMA
hoelzl@50526
   375
    by (intro sigma_algebra_sigma_sets) simp_all
hoelzl@50526
   376
  have *: "?set = (\<Union>n. UNIV - {x\<Colon>'a. x \<bullet> i < a + 1 / real (Suc n)})"
hoelzl@50526
   377
  proof (safe, simp_all add: not_less)
hoelzl@50526
   378
    fix x :: 'a assume "a < x \<bullet> i"
hoelzl@50526
   379
    with reals_Archimedean[of "x \<bullet> i - a"]
hoelzl@50526
   380
    obtain n where "a + 1 / real (Suc n) < x \<bullet> i"
hoelzl@50526
   381
      by (auto simp: inverse_eq_divide field_simps)
hoelzl@50526
   382
    then show "\<exists>n. a + 1 / real (Suc n) \<le> x \<bullet> i"
hoelzl@50526
   383
      by (blast intro: less_imp_le)
hoelzl@50526
   384
  next
hoelzl@50526
   385
    fix x n
hoelzl@50526
   386
    have "a < a + 1 / real (Suc n)" by auto
hoelzl@50526
   387
    also assume "\<dots> \<le> x"
hoelzl@50526
   388
    finally show "a < x" .
hoelzl@50526
   389
  qed
hoelzl@50526
   390
  show "?set \<in> ?SIGMA" unfolding *
hoelzl@50526
   391
    by (auto del: Diff intro!: Diff i)
hoelzl@50526
   392
qed
hoelzl@50526
   393
hoelzl@50526
   394
lemma borel_eq_halfspace_less:
hoelzl@50526
   395
  "borel = sigma UNIV ((\<lambda>(a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> Basis))"
hoelzl@50526
   396
  (is "_ = ?SIGMA")
hoelzl@50526
   397
proof (rule borel_eq_sigmaI2[OF borel_eq_box])
hoelzl@50526
   398
  fix a b :: 'a
hoelzl@50526
   399
  have "box a b = {x\<in>space ?SIGMA. \<forall>i\<in>Basis. a \<bullet> i < x \<bullet> i \<and> x \<bullet> i < b \<bullet> i}"
hoelzl@50526
   400
    by (auto simp: box_def)
hoelzl@50526
   401
  also have "\<dots> \<in> sets ?SIGMA"
hoelzl@50526
   402
    by (intro sets.sets_Collect_conj sets.sets_Collect_finite_All sets.sets_Collect_const)
hoelzl@50526
   403
       (auto intro!: halfspace_gt_in_halfspace countable_PiE countable_rat)
hoelzl@50526
   404
  finally show "box a b \<in> sets ?SIGMA" .
hoelzl@50526
   405
qed auto
hoelzl@50526
   406
hoelzl@50526
   407
lemma borel_eq_halfspace_le:
hoelzl@50526
   408
  "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i \<le> a}) ` (UNIV \<times> Basis))"
hoelzl@50526
   409
  (is "_ = ?SIGMA")
hoelzl@50526
   410
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@50526
   411
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   412
  then have i: "i \<in> Basis" by auto
hoelzl@50526
   413
  have *: "{x::'a. x\<bullet>i < a} = (\<Union>n. {x. x\<bullet>i \<le> a - 1/real (Suc n)})"
hoelzl@50526
   414
  proof (safe, simp_all)
hoelzl@50526
   415
    fix x::'a assume *: "x\<bullet>i < a"
hoelzl@50526
   416
    with reals_Archimedean[of "a - x\<bullet>i"]
hoelzl@50526
   417
    obtain n where "x \<bullet> i < a - 1 / (real (Suc n))"
hoelzl@50526
   418
      by (auto simp: field_simps inverse_eq_divide)
hoelzl@50526
   419
    then show "\<exists>n. x \<bullet> i \<le> a - 1 / (real (Suc n))"
hoelzl@50526
   420
      by (blast intro: less_imp_le)
hoelzl@50526
   421
  next
hoelzl@50526
   422
    fix x::'a and n
hoelzl@50526
   423
    assume "x\<bullet>i \<le> a - 1 / real (Suc n)"
hoelzl@50526
   424
    also have "\<dots> < a" by auto
hoelzl@50526
   425
    finally show "x\<bullet>i < a" .
hoelzl@50526
   426
  qed
hoelzl@50526
   427
  show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
hoelzl@50526
   428
    by (safe intro!: sets.countable_UN) (auto intro: i)
hoelzl@50526
   429
qed auto
hoelzl@50526
   430
hoelzl@50526
   431
lemma borel_eq_halfspace_ge:
hoelzl@50526
   432
  "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a \<le> x \<bullet> i}) ` (UNIV \<times> Basis))"
hoelzl@50526
   433
  (is "_ = ?SIGMA")
hoelzl@50526
   434
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@50526
   435
  fix a :: real and i :: 'a assume i: "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   436
  have *: "{x::'a. x\<bullet>i < a} = space ?SIGMA - {x::'a. a \<le> x\<bullet>i}" by auto
hoelzl@50526
   437
  show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
hoelzl@50526
   438
    using i by (safe intro!: sets.compl_sets) auto
hoelzl@50526
   439
qed auto
hoelzl@50526
   440
hoelzl@50526
   441
lemma borel_eq_halfspace_greater:
hoelzl@50526
   442
  "borel = sigma UNIV ((\<lambda> (a, i). {x\<Colon>'a\<Colon>euclidean_space. a < x \<bullet> i}) ` (UNIV \<times> Basis))"
hoelzl@50526
   443
  (is "_ = ?SIGMA")
hoelzl@50526
   444
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
hoelzl@50526
   445
  fix a :: real and i :: 'a assume "(a, i) \<in> (UNIV \<times> Basis)"
hoelzl@50526
   446
  then have i: "i \<in> Basis" by auto
hoelzl@50526
   447
  have *: "{x::'a. x\<bullet>i \<le> a} = space ?SIGMA - {x::'a. a < x\<bullet>i}" by auto
hoelzl@50526
   448
  show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@50526
   449
    by (safe intro!: sets.compl_sets) (auto intro: i)
hoelzl@50526
   450
qed auto
hoelzl@50526
   451
hoelzl@50526
   452
lemma borel_eq_atMost:
hoelzl@50526
   453
  "borel = sigma UNIV (range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space}))"
hoelzl@50526
   454
  (is "_ = ?SIGMA")
hoelzl@50526
   455
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@50526
   456
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   457
  then have "i \<in> Basis" by auto
hoelzl@50526
   458
  then have *: "{x::'a. x\<bullet>i \<le> a} = (\<Union>k::nat. {.. (\<Sum>n\<in>Basis. (if n = i then a else real k)*\<^sub>R n)})"
hoelzl@50526
   459
  proof (safe, simp_all add: eucl_le[where 'a='a] split: split_if_asm)
hoelzl@50526
   460
    fix x :: 'a
hoelzl@50526
   461
    from real_arch_simple[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"] guess k::nat ..
hoelzl@50526
   462
    then have "\<And>i. i \<in> Basis \<Longrightarrow> x\<bullet>i \<le> real k"
hoelzl@50526
   463
      by (subst (asm) Max_le_iff) auto
hoelzl@50526
   464
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia \<le> real k"
hoelzl@50526
   465
      by (auto intro!: exI[of _ k])
hoelzl@50526
   466
  qed
hoelzl@50526
   467
  show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@50526
   468
    by (safe intro!: sets.countable_UN) auto
hoelzl@50526
   469
qed auto
hoelzl@50526
   470
hoelzl@50526
   471
lemma borel_eq_greaterThan:
hoelzl@50526
   472
  "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {a<..}))"
hoelzl@50526
   473
  (is "_ = ?SIGMA")
hoelzl@50526
   474
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@50526
   475
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   476
  then have i: "i \<in> Basis" by auto
hoelzl@50526
   477
  have "{x::'a. x\<bullet>i \<le> a} = UNIV - {x::'a. a < x\<bullet>i}" by auto
hoelzl@50526
   478
  also have *: "{x::'a. a < x\<bullet>i} =
hoelzl@50526
   479
      (\<Union>k::nat. {\<Sum>n\<in>Basis. (if n = i then a else -real k) *\<^sub>R n <..})" using i
hoelzl@50526
   480
  proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@50526
   481
    fix x :: 'a
hoelzl@50526
   482
    from reals_Archimedean2[of "Max ((\<lambda>i. -x\<bullet>i)`Basis)"]
hoelzl@50526
   483
    guess k::nat .. note k = this
hoelzl@50526
   484
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
   485
      then have "-x\<bullet>i < real k"
hoelzl@50526
   486
        using k by (subst (asm) Max_less_iff) auto
hoelzl@50526
   487
      then have "- real k < x\<bullet>i" by simp }
hoelzl@50526
   488
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> -real k < x \<bullet> ia"
hoelzl@50526
   489
      by (auto intro!: exI[of _ k])
hoelzl@50526
   490
  qed
hoelzl@50526
   491
  finally show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA"
hoelzl@50526
   492
    apply (simp only:)
hoelzl@50526
   493
    apply (safe intro!: sets.countable_UN sets.Diff)
hoelzl@50526
   494
    apply (auto intro: sigma_sets_top)
hoelzl@50526
   495
    done
hoelzl@50526
   496
qed auto
hoelzl@50526
   497
hoelzl@50526
   498
lemma borel_eq_lessThan:
hoelzl@50526
   499
  "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {..<a}))"
hoelzl@50526
   500
  (is "_ = ?SIGMA")
hoelzl@50526
   501
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_ge])
hoelzl@50526
   502
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   503
  then have i: "i \<in> Basis" by auto
hoelzl@50526
   504
  have "{x::'a. a \<le> x\<bullet>i} = UNIV - {x::'a. x\<bullet>i < a}" by auto
hoelzl@50526
   505
  also have *: "{x::'a. x\<bullet>i < a} = (\<Union>k::nat. {..< \<Sum>n\<in>Basis. (if n = i then a else real k) *\<^sub>R n})" using `i\<in> Basis`
hoelzl@50526
   506
  proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@50526
   507
    fix x :: 'a
hoelzl@50526
   508
    from reals_Archimedean2[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"]
hoelzl@50526
   509
    guess k::nat .. note k = this
hoelzl@50526
   510
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
   511
      then have "x\<bullet>i < real k"
hoelzl@50526
   512
        using k by (subst (asm) Max_less_iff) auto
hoelzl@50526
   513
      then have "x\<bullet>i < real k" by simp }
hoelzl@50526
   514
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia < real k"
hoelzl@50526
   515
      by (auto intro!: exI[of _ k])
hoelzl@50526
   516
  qed
hoelzl@50526
   517
  finally show "{x. a \<le> x\<bullet>i} \<in> ?SIGMA"
hoelzl@50526
   518
    apply (simp only:)
hoelzl@50526
   519
    apply (safe intro!: sets.countable_UN sets.Diff)
hoelzl@50526
   520
    apply (auto intro: sigma_sets_top)
hoelzl@50526
   521
    done
hoelzl@50526
   522
qed auto
hoelzl@50526
   523
hoelzl@50526
   524
lemma borel_eq_atLeastAtMost:
hoelzl@50526
   525
  "borel = sigma UNIV (range (\<lambda>(a,b). {a..b} \<Colon>'a\<Colon>ordered_euclidean_space set))"
hoelzl@50526
   526
  (is "_ = ?SIGMA")
hoelzl@50526
   527
proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
hoelzl@50526
   528
  fix a::'a
hoelzl@50526
   529
  have *: "{..a} = (\<Union>n::nat. {- real n *\<^sub>R One .. a})"
hoelzl@50526
   530
  proof (safe, simp_all add: eucl_le[where 'a='a])
hoelzl@50526
   531
    fix x :: 'a
hoelzl@50526
   532
    from real_arch_simple[of "Max ((\<lambda>i. - x\<bullet>i)`Basis)"]
hoelzl@50526
   533
    guess k::nat .. note k = this
hoelzl@50526
   534
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
   535
      with k have "- x\<bullet>i \<le> real k"
hoelzl@50526
   536
        by (subst (asm) Max_le_iff) (auto simp: field_simps)
hoelzl@50526
   537
      then have "- real k \<le> x\<bullet>i" by simp }
hoelzl@50526
   538
    then show "\<exists>n::nat. \<forall>i\<in>Basis. - real n \<le> x \<bullet> i"
hoelzl@50526
   539
      by (auto intro!: exI[of _ k])
hoelzl@50526
   540
  qed
hoelzl@50526
   541
  show "{..a} \<in> ?SIGMA" unfolding *
hoelzl@50526
   542
    by (safe intro!: sets.countable_UN)
hoelzl@50526
   543
       (auto intro!: sigma_sets_top)
hoelzl@50526
   544
qed auto
hoelzl@50526
   545
hoelzl@50526
   546
lemma borel_eq_atLeastLessThan:
hoelzl@50526
   547
  "borel = sigma UNIV (range (\<lambda>(a, b). {a ..< b :: real}))" (is "_ = ?SIGMA")
hoelzl@50526
   548
proof (rule borel_eq_sigmaI5[OF borel_eq_lessThan])
hoelzl@50526
   549
  have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
hoelzl@50526
   550
  fix x :: real
hoelzl@50526
   551
  have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
hoelzl@50526
   552
    by (auto simp: move_uminus real_arch_simple)
hoelzl@50526
   553
  then show "{..< x} \<in> ?SIGMA"
hoelzl@50526
   554
    by (auto intro: sigma_sets.intros)
hoelzl@50526
   555
qed auto
hoelzl@50526
   556
hoelzl@50526
   557
lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
hoelzl@50526
   558
  unfolding borel_def
hoelzl@50526
   559
proof (intro sigma_eqI sigma_sets_eqI, safe)
hoelzl@50526
   560
  fix x :: "'a set" assume "open x"
hoelzl@50526
   561
  hence "x = UNIV - (UNIV - x)" by auto
hoelzl@50526
   562
  also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
hoelzl@50526
   563
    by (rule sigma_sets.Compl)
hoelzl@50526
   564
       (auto intro!: sigma_sets.Basic simp: `open x`)
hoelzl@50526
   565
  finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
hoelzl@50526
   566
next
hoelzl@50526
   567
  fix x :: "'a set" assume "closed x"
hoelzl@50526
   568
  hence "x = UNIV - (UNIV - x)" by auto
hoelzl@50526
   569
  also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
hoelzl@50526
   570
    by (rule sigma_sets.Compl)
hoelzl@50526
   571
       (auto intro!: sigma_sets.Basic simp: `closed x`)
hoelzl@50526
   572
  finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
hoelzl@50526
   573
qed simp_all
hoelzl@50526
   574
hoelzl@50526
   575
lemma borel_measurable_halfspacesI:
hoelzl@50526
   576
  fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
hoelzl@50526
   577
  assumes F: "borel = sigma UNIV (F ` (UNIV \<times> Basis))"
hoelzl@50526
   578
  and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M" 
hoelzl@50526
   579
  shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a::real. S a i \<in> sets M)"
hoelzl@50526
   580
proof safe
hoelzl@50526
   581
  fix a :: real and i :: 'b assume i: "i \<in> Basis" and f: "f \<in> borel_measurable M"
hoelzl@50526
   582
  then show "S a i \<in> sets M" unfolding assms
hoelzl@50526
   583
    by (auto intro!: measurable_sets simp: assms(1))
hoelzl@50526
   584
next
hoelzl@50526
   585
  assume a: "\<forall>i\<in>Basis. \<forall>a. S a i \<in> sets M"
hoelzl@50526
   586
  then show "f \<in> borel_measurable M"
hoelzl@50526
   587
    by (auto intro!: measurable_measure_of simp: S_eq F)
hoelzl@50526
   588
qed
hoelzl@50526
   589
hoelzl@50526
   590
lemma borel_measurable_iff_halfspace_le:
hoelzl@50526
   591
  fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
hoelzl@50526
   592
  shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. f w \<bullet> i \<le> a} \<in> sets M)"
hoelzl@50526
   593
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_le]) auto
hoelzl@50526
   594
hoelzl@50526
   595
lemma borel_measurable_iff_halfspace_less:
hoelzl@50526
   596
  fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
hoelzl@50526
   597
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. f w \<bullet> i < a} \<in> sets M)"
hoelzl@50526
   598
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_less]) auto
hoelzl@50526
   599
hoelzl@50526
   600
lemma borel_measurable_iff_halfspace_ge:
hoelzl@50526
   601
  fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
hoelzl@50526
   602
  shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. a \<le> f w \<bullet> i} \<in> sets M)"
hoelzl@50526
   603
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_ge]) auto
hoelzl@50526
   604
hoelzl@50526
   605
lemma borel_measurable_iff_halfspace_greater:
hoelzl@50526
   606
  fixes f :: "'a \<Rightarrow> 'c\<Colon>euclidean_space"
hoelzl@50526
   607
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. \<forall>a. {w \<in> space M. a < f w \<bullet> i} \<in> sets M)"
hoelzl@50526
   608
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_greater]) auto
hoelzl@50526
   609
hoelzl@50526
   610
lemma borel_measurable_iff_le:
hoelzl@50526
   611
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w \<le> a} \<in> sets M)"
hoelzl@50526
   612
  using borel_measurable_iff_halfspace_le[where 'c=real] by simp
hoelzl@50526
   613
hoelzl@50526
   614
lemma borel_measurable_iff_less:
hoelzl@50526
   615
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w < a} \<in> sets M)"
hoelzl@50526
   616
  using borel_measurable_iff_halfspace_less[where 'c=real] by simp
hoelzl@50526
   617
hoelzl@50526
   618
lemma borel_measurable_iff_ge:
hoelzl@50526
   619
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a \<le> f w} \<in> sets M)"
hoelzl@50526
   620
  using borel_measurable_iff_halfspace_ge[where 'c=real]
hoelzl@50526
   621
  by simp
hoelzl@50526
   622
hoelzl@50526
   623
lemma borel_measurable_iff_greater:
hoelzl@50526
   624
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a < f w} \<in> sets M)"
hoelzl@50526
   625
  using borel_measurable_iff_halfspace_greater[where 'c=real] by simp
hoelzl@50526
   626
hoelzl@50526
   627
lemma borel_measurable_euclidean_space:
hoelzl@50526
   628
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
   629
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M)"
hoelzl@50526
   630
proof safe
hoelzl@50526
   631
  assume f: "\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M"
hoelzl@50526
   632
  then show "f \<in> borel_measurable M"
hoelzl@50526
   633
    by (subst borel_measurable_iff_halfspace_le) auto
hoelzl@50526
   634
qed auto
hoelzl@50526
   635
hoelzl@50526
   636
subsection "Borel measurable operators"
hoelzl@50526
   637
hoelzl@50526
   638
lemma borel_measurable_uminus[measurable (raw)]:
hoelzl@50526
   639
  fixes g :: "'a \<Rightarrow> real"
hoelzl@50526
   640
  assumes g: "g \<in> borel_measurable M"
hoelzl@50526
   641
  shows "(\<lambda>x. - g x) \<in> borel_measurable M"
hoelzl@50526
   642
  by (rule borel_measurable_continuous_on[OF _ g]) (auto intro: continuous_on_minus continuous_on_id)
hoelzl@50526
   643
hoelzl@50003
   644
lemma borel_measurable_add[measurable (raw)]:
hoelzl@49774
   645
  fixes f g :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@49774
   646
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   647
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   648
  shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@49774
   649
  using f g
hoelzl@49774
   650
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   651
     (auto intro: continuous_on_fst continuous_on_snd continuous_on_add)
hoelzl@49774
   652
hoelzl@50003
   653
lemma borel_measurable_setsum[measurable (raw)]:
hoelzl@49774
   654
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@49774
   655
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@49774
   656
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@49774
   657
proof cases
hoelzl@49774
   658
  assume "finite S"
hoelzl@49774
   659
  thus ?thesis using assms by induct auto
hoelzl@49774
   660
qed simp
hoelzl@49774
   661
hoelzl@50003
   662
lemma borel_measurable_diff[measurable (raw)]:
hoelzl@49774
   663
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   664
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   665
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   666
  shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50003
   667
  unfolding diff_minus using assms by simp
hoelzl@49774
   668
hoelzl@50003
   669
lemma borel_measurable_times[measurable (raw)]:
hoelzl@49774
   670
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   671
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   672
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   673
  shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@49774
   674
  using f g
hoelzl@49774
   675
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   676
     (auto intro: continuous_on_fst continuous_on_snd continuous_on_mult)
hoelzl@49774
   677
hoelzl@49774
   678
lemma continuous_on_dist:
hoelzl@49774
   679
  fixes f :: "'a :: t2_space \<Rightarrow> 'b :: metric_space"
hoelzl@49774
   680
  shows "continuous_on A f \<Longrightarrow> continuous_on A g \<Longrightarrow> continuous_on A (\<lambda>x. dist (f x) (g x))"
hoelzl@49774
   681
  unfolding continuous_on_eq_continuous_within by (auto simp: continuous_dist)
hoelzl@49774
   682
hoelzl@50003
   683
lemma borel_measurable_dist[measurable (raw)]:
hoelzl@49774
   684
  fixes g f :: "'a \<Rightarrow> 'b::ordered_euclidean_space"
hoelzl@49774
   685
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   686
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   687
  shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   688
  using f g
hoelzl@49774
   689
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   690
     (intro continuous_on_dist continuous_on_fst continuous_on_snd)
hoelzl@49774
   691
  
hoelzl@50002
   692
lemma borel_measurable_scaleR[measurable (raw)]:
hoelzl@50002
   693
  fixes g :: "'a \<Rightarrow> 'b::ordered_euclidean_space"
hoelzl@50002
   694
  assumes f: "f \<in> borel_measurable M"
hoelzl@50002
   695
  assumes g: "g \<in> borel_measurable M"
hoelzl@50002
   696
  shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
hoelzl@50002
   697
  by (rule borel_measurable_continuous_Pair[OF f g])
hoelzl@50002
   698
     (auto intro!: continuous_on_scaleR continuous_on_fst continuous_on_snd)
hoelzl@50002
   699
hoelzl@47694
   700
lemma affine_borel_measurable_vector:
hoelzl@38656
   701
  fixes f :: "'a \<Rightarrow> 'x::real_normed_vector"
hoelzl@38656
   702
  assumes "f \<in> borel_measurable M"
hoelzl@38656
   703
  shows "(\<lambda>x. a + b *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@38656
   704
proof (rule borel_measurableI)
hoelzl@38656
   705
  fix S :: "'x set" assume "open S"
hoelzl@38656
   706
  show "(\<lambda>x. a + b *\<^sub>R f x) -` S \<inter> space M \<in> sets M"
hoelzl@38656
   707
  proof cases
hoelzl@38656
   708
    assume "b \<noteq> 0"
huffman@44537
   709
    with `open S` have "open ((\<lambda>x. (- a + x) /\<^sub>R b) ` S)" (is "open ?S")
huffman@44537
   710
      by (auto intro!: open_affinity simp: scaleR_add_right)
hoelzl@47694
   711
    hence "?S \<in> sets borel" by auto
hoelzl@38656
   712
    moreover
hoelzl@38656
   713
    from `b \<noteq> 0` have "(\<lambda>x. a + b *\<^sub>R f x) -` S = f -` ?S"
hoelzl@38656
   714
      apply auto by (rule_tac x="a + b *\<^sub>R f x" in image_eqI, simp_all)
hoelzl@40859
   715
    ultimately show ?thesis using assms unfolding in_borel_measurable_borel
hoelzl@38656
   716
      by auto
hoelzl@38656
   717
  qed simp
hoelzl@38656
   718
qed
hoelzl@38656
   719
hoelzl@50002
   720
lemma borel_measurable_const_scaleR[measurable (raw)]:
hoelzl@50002
   721
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. b *\<^sub>R f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
   722
  using affine_borel_measurable_vector[of f M 0 b] by simp
hoelzl@38656
   723
hoelzl@50002
   724
lemma borel_measurable_const_add[measurable (raw)]:
hoelzl@50002
   725
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. a + f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
   726
  using affine_borel_measurable_vector[of f M a 1] by simp
hoelzl@50002
   727
hoelzl@50003
   728
lemma borel_measurable_setprod[measurable (raw)]:
hoelzl@41026
   729
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41026
   730
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41026
   731
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41026
   732
proof cases
hoelzl@41026
   733
  assume "finite S"
hoelzl@41026
   734
  thus ?thesis using assms by induct auto
hoelzl@41026
   735
qed simp
hoelzl@41026
   736
hoelzl@50003
   737
lemma borel_measurable_inverse[measurable (raw)]:
hoelzl@38656
   738
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   739
  assumes f: "f \<in> borel_measurable M"
hoelzl@35692
   740
  shows "(\<lambda>x. inverse (f x)) \<in> borel_measurable M"
hoelzl@49774
   741
proof -
hoelzl@50003
   742
  have "(\<lambda>x::real. if x \<in> UNIV - {0} then inverse x else 0) \<in> borel_measurable borel"
hoelzl@50003
   743
    by (intro borel_measurable_continuous_on_open' continuous_on_inverse continuous_on_id) auto
hoelzl@50003
   744
  also have "(\<lambda>x::real. if x \<in> UNIV - {0} then inverse x else 0) = inverse" by (intro ext) auto
hoelzl@50003
   745
  finally show ?thesis using f by simp
hoelzl@35692
   746
qed
hoelzl@35692
   747
hoelzl@50003
   748
lemma borel_measurable_divide[measurable (raw)]:
hoelzl@50003
   749
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. f x / g x::real) \<in> borel_measurable M"
hoelzl@50003
   750
  by (simp add: field_divide_inverse)
hoelzl@38656
   751
hoelzl@50003
   752
lemma borel_measurable_max[measurable (raw)]:
hoelzl@50003
   753
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. max (g x) (f x) :: real) \<in> borel_measurable M"
hoelzl@50003
   754
  by (simp add: max_def)
hoelzl@38656
   755
hoelzl@50003
   756
lemma borel_measurable_min[measurable (raw)]:
hoelzl@50003
   757
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. min (g x) (f x) :: real) \<in> borel_measurable M"
hoelzl@50003
   758
  by (simp add: min_def)
hoelzl@38656
   759
hoelzl@50003
   760
lemma borel_measurable_abs[measurable (raw)]:
hoelzl@50003
   761
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. \<bar>f x :: real\<bar>) \<in> borel_measurable M"
hoelzl@50003
   762
  unfolding abs_real_def by simp
hoelzl@38656
   763
hoelzl@50003
   764
lemma borel_measurable_nth[measurable (raw)]:
hoelzl@41026
   765
  "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
hoelzl@50526
   766
  by (simp add: cart_eq_inner_axis)
hoelzl@41026
   767
hoelzl@47694
   768
lemma convex_measurable:
hoelzl@42990
   769
  fixes a b :: real
hoelzl@42990
   770
  assumes X: "X \<in> borel_measurable M" "X ` space M \<subseteq> { a <..< b}"
hoelzl@42990
   771
  assumes q: "convex_on { a <..< b} q"
hoelzl@49774
   772
  shows "(\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@42990
   773
proof -
hoelzl@49774
   774
  have "(\<lambda>x. if X x \<in> {a <..< b} then q (X x) else 0) \<in> borel_measurable M" (is "?qX")
hoelzl@49774
   775
  proof (rule borel_measurable_continuous_on_open[OF _ _ X(1)])
hoelzl@42990
   776
    show "open {a<..<b}" by auto
hoelzl@42990
   777
    from this q show "continuous_on {a<..<b} q"
hoelzl@42990
   778
      by (rule convex_on_continuous)
hoelzl@41830
   779
  qed
hoelzl@50002
   780
  also have "?qX \<longleftrightarrow> (\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@42990
   781
    using X by (intro measurable_cong) auto
hoelzl@50002
   782
  finally show ?thesis .
hoelzl@41830
   783
qed
hoelzl@41830
   784
hoelzl@50003
   785
lemma borel_measurable_ln[measurable (raw)]:
hoelzl@49774
   786
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   787
  shows "(\<lambda>x. ln (f x)) \<in> borel_measurable M"
hoelzl@41830
   788
proof -
hoelzl@41830
   789
  { fix x :: real assume x: "x \<le> 0"
hoelzl@41830
   790
    { fix x::real assume "x \<le> 0" then have "\<And>u. exp u = x \<longleftrightarrow> False" by auto }
hoelzl@49774
   791
    from this[of x] x this[of 0] have "ln 0 = ln x"
hoelzl@49774
   792
      by (auto simp: ln_def) }
hoelzl@49774
   793
  note ln_imp = this
hoelzl@49774
   794
  have "(\<lambda>x. if f x \<in> {0<..} then ln (f x) else ln 0) \<in> borel_measurable M"
hoelzl@49774
   795
  proof (rule borel_measurable_continuous_on_open[OF _ _ f])
hoelzl@49774
   796
    show "continuous_on {0<..} ln"
hoelzl@49774
   797
      by (auto intro!: continuous_at_imp_continuous_on DERIV_ln DERIV_isCont
hoelzl@41830
   798
               simp: continuous_isCont[symmetric])
hoelzl@41830
   799
    show "open ({0<..}::real set)" by auto
hoelzl@41830
   800
  qed
hoelzl@49774
   801
  also have "(\<lambda>x. if x \<in> {0<..} then ln x else ln 0) = ln"
hoelzl@49774
   802
    by (simp add: fun_eq_iff not_less ln_imp)
hoelzl@41830
   803
  finally show ?thesis .
hoelzl@41830
   804
qed
hoelzl@41830
   805
hoelzl@50003
   806
lemma borel_measurable_log[measurable (raw)]:
hoelzl@50002
   807
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. log (g x) (f x)) \<in> borel_measurable M"
hoelzl@49774
   808
  unfolding log_def by auto
hoelzl@41830
   809
hoelzl@50419
   810
lemma borel_measurable_exp[measurable]: "exp \<in> borel_measurable borel"
hoelzl@50419
   811
  by (intro borel_measurable_continuous_on1 continuous_at_imp_continuous_on ballI
hoelzl@50419
   812
            continuous_isCont[THEN iffD1] isCont_exp)
hoelzl@50419
   813
hoelzl@50002
   814
lemma measurable_count_space_eq2_countable:
hoelzl@50002
   815
  fixes f :: "'a => 'c::countable"
hoelzl@50002
   816
  shows "f \<in> measurable M (count_space A) \<longleftrightarrow> (f \<in> space M \<rightarrow> A \<and> (\<forall>a\<in>A. f -` {a} \<inter> space M \<in> sets M))"
hoelzl@50002
   817
proof -
hoelzl@50002
   818
  { fix X assume "X \<subseteq> A" "f \<in> space M \<rightarrow> A"
hoelzl@50002
   819
    then have "f -` X \<inter> space M = (\<Union>a\<in>X. f -` {a} \<inter> space M)"
hoelzl@50002
   820
      by auto
hoelzl@50002
   821
    moreover assume "\<And>a. a\<in>A \<Longrightarrow> f -` {a} \<inter> space M \<in> sets M"
hoelzl@50002
   822
    ultimately have "f -` X \<inter> space M \<in> sets M"
hoelzl@50002
   823
      using `X \<subseteq> A` by (simp add: subset_eq del: UN_simps) }
hoelzl@50002
   824
  then show ?thesis
hoelzl@50002
   825
    unfolding measurable_def by auto
hoelzl@47761
   826
qed
hoelzl@47761
   827
hoelzl@50002
   828
lemma measurable_real_floor[measurable]:
hoelzl@50002
   829
  "(floor :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@47761
   830
proof -
hoelzl@50002
   831
  have "\<And>a x. \<lfloor>x\<rfloor> = a \<longleftrightarrow> (real a \<le> x \<and> x < real (a + 1))"
hoelzl@50002
   832
    by (auto intro: floor_eq2)
hoelzl@50002
   833
  then show ?thesis
hoelzl@50002
   834
    by (auto simp: vimage_def measurable_count_space_eq2_countable)
hoelzl@47761
   835
qed
hoelzl@47761
   836
hoelzl@50002
   837
lemma measurable_real_natfloor[measurable]:
hoelzl@50002
   838
  "(natfloor :: real \<Rightarrow> nat) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
   839
  by (simp add: natfloor_def[abs_def])
hoelzl@50002
   840
hoelzl@50002
   841
lemma measurable_real_ceiling[measurable]:
hoelzl@50002
   842
  "(ceiling :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
   843
  unfolding ceiling_def[abs_def] by simp
hoelzl@50002
   844
hoelzl@50002
   845
lemma borel_measurable_real_floor: "(\<lambda>x::real. real \<lfloor>x\<rfloor>) \<in> borel_measurable borel"
hoelzl@50002
   846
  by simp
hoelzl@50002
   847
hoelzl@50003
   848
lemma borel_measurable_real_natfloor:
hoelzl@50002
   849
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. real (natfloor (f x))) \<in> borel_measurable M"
hoelzl@50002
   850
  by simp
hoelzl@50002
   851
hoelzl@41981
   852
subsection "Borel space on the extended reals"
hoelzl@41981
   853
hoelzl@50003
   854
lemma borel_measurable_ereal[measurable (raw)]:
hoelzl@43920
   855
  assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@49774
   856
  using continuous_on_ereal f by (rule borel_measurable_continuous_on)
hoelzl@41981
   857
hoelzl@50003
   858
lemma borel_measurable_real_of_ereal[measurable (raw)]:
hoelzl@49774
   859
  fixes f :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   860
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   861
  shows "(\<lambda>x. real (f x)) \<in> borel_measurable M"
hoelzl@49774
   862
proof -
hoelzl@49774
   863
  have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) \<in> borel_measurable M"
hoelzl@49774
   864
    using continuous_on_real
hoelzl@49774
   865
    by (rule borel_measurable_continuous_on_open[OF _ _ f]) auto
hoelzl@49774
   866
  also have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) = (\<lambda>x. real (f x))"
hoelzl@49774
   867
    by auto
hoelzl@49774
   868
  finally show ?thesis .
hoelzl@49774
   869
qed
hoelzl@49774
   870
hoelzl@49774
   871
lemma borel_measurable_ereal_cases:
hoelzl@49774
   872
  fixes f :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   873
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   874
  assumes H: "(\<lambda>x. H (ereal (real (f x)))) \<in> borel_measurable M"
hoelzl@49774
   875
  shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
hoelzl@49774
   876
proof -
hoelzl@50002
   877
  let ?F = "\<lambda>x. if f x = \<infinity> then H \<infinity> else if f x = - \<infinity> then H (-\<infinity>) else H (ereal (real (f x)))"
hoelzl@49774
   878
  { fix x have "H (f x) = ?F x" by (cases "f x") auto }
hoelzl@50002
   879
  with f H show ?thesis by simp
hoelzl@47694
   880
qed
hoelzl@41981
   881
hoelzl@49774
   882
lemma
hoelzl@50003
   883
  fixes f :: "'a \<Rightarrow> ereal" assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   884
  shows borel_measurable_ereal_abs[measurable(raw)]: "(\<lambda>x. \<bar>f x\<bar>) \<in> borel_measurable M"
hoelzl@50003
   885
    and borel_measurable_ereal_inverse[measurable(raw)]: "(\<lambda>x. inverse (f x) :: ereal) \<in> borel_measurable M"
hoelzl@50003
   886
    and borel_measurable_uminus_ereal[measurable(raw)]: "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M"
hoelzl@49774
   887
  by (auto simp del: abs_real_of_ereal simp: borel_measurable_ereal_cases[OF f] measurable_If)
hoelzl@49774
   888
hoelzl@49774
   889
lemma borel_measurable_uminus_eq_ereal[simp]:
hoelzl@49774
   890
  "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
hoelzl@49774
   891
proof
hoelzl@49774
   892
  assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
hoelzl@49774
   893
qed auto
hoelzl@49774
   894
hoelzl@49774
   895
lemma set_Collect_ereal2:
hoelzl@49774
   896
  fixes f g :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   897
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   898
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   899
  assumes H: "{x \<in> space M. H (ereal (real (f x))) (ereal (real (g x)))} \<in> sets M"
hoelzl@50002
   900
    "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
   901
    "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
   902
    "{x \<in> space borel. H (ereal x) (-\<infinity>)} \<in> sets borel"
hoelzl@50002
   903
    "{x \<in> space borel. H (ereal x) (\<infinity>)} \<in> sets borel"
hoelzl@49774
   904
  shows "{x \<in> space M. H (f x) (g x)} \<in> sets M"
hoelzl@49774
   905
proof -
hoelzl@50002
   906
  let ?G = "\<lambda>y x. if g x = \<infinity> then H y \<infinity> else if g x = -\<infinity> then H y (-\<infinity>) else H y (ereal (real (g x)))"
hoelzl@50002
   907
  let ?F = "\<lambda>x. if f x = \<infinity> then ?G \<infinity> x else if f x = -\<infinity> then ?G (-\<infinity>) x else ?G (ereal (real (f x))) x"
hoelzl@49774
   908
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
   909
  note * = this
hoelzl@50002
   910
  from assms show ?thesis
hoelzl@50002
   911
    by (subst *) (simp del: space_borel split del: split_if)
hoelzl@49774
   912
qed
hoelzl@49774
   913
hoelzl@50003
   914
lemma [measurable]:
hoelzl@49774
   915
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
   916
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   917
  assumes g: "g \<in> borel_measurable M"
hoelzl@50003
   918
  shows borel_measurable_ereal_le: "{x \<in> space M. f x \<le> g x} \<in> sets M"
hoelzl@50003
   919
    and borel_measurable_ereal_less: "{x \<in> space M. f x < g x} \<in> sets M"
hoelzl@50003
   920
    and borel_measurable_ereal_eq: "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@50003
   921
  using f g by (simp_all add: set_Collect_ereal2)
hoelzl@50003
   922
hoelzl@50003
   923
lemma borel_measurable_ereal_neq:
hoelzl@50003
   924
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> {w \<in> space M. f w \<noteq> (g w :: ereal)} \<in> sets M"
hoelzl@50003
   925
  by simp
hoelzl@41981
   926
hoelzl@47694
   927
lemma borel_measurable_ereal_iff:
hoelzl@43920
   928
  shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M"
hoelzl@41981
   929
proof
hoelzl@43920
   930
  assume "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@43920
   931
  from borel_measurable_real_of_ereal[OF this]
hoelzl@41981
   932
  show "f \<in> borel_measurable M" by auto
hoelzl@41981
   933
qed auto
hoelzl@41981
   934
hoelzl@47694
   935
lemma borel_measurable_ereal_iff_real:
hoelzl@43923
   936
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
   937
  shows "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@41981
   938
    ((\<lambda>x. real (f x)) \<in> borel_measurable M \<and> f -` {\<infinity>} \<inter> space M \<in> sets M \<and> f -` {-\<infinity>} \<inter> space M \<in> sets M)"
hoelzl@41981
   939
proof safe
hoelzl@41981
   940
  assume *: "(\<lambda>x. real (f x)) \<in> borel_measurable M" "f -` {\<infinity>} \<inter> space M \<in> sets M" "f -` {-\<infinity>} \<inter> space M \<in> sets M"
hoelzl@41981
   941
  have "f -` {\<infinity>} \<inter> space M = {x\<in>space M. f x = \<infinity>}" "f -` {-\<infinity>} \<inter> space M = {x\<in>space M. f x = -\<infinity>}" by auto
hoelzl@41981
   942
  with * have **: "{x\<in>space M. f x = \<infinity>} \<in> sets M" "{x\<in>space M. f x = -\<infinity>} \<in> sets M" by simp_all
wenzelm@46731
   943
  let ?f = "\<lambda>x. if f x = \<infinity> then \<infinity> else if f x = -\<infinity> then -\<infinity> else ereal (real (f x))"
hoelzl@41981
   944
  have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
hoelzl@43920
   945
  also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
hoelzl@41981
   946
  finally show "f \<in> borel_measurable M" .
hoelzl@50002
   947
qed simp_all
hoelzl@41830
   948
hoelzl@47694
   949
lemma borel_measurable_eq_atMost_ereal:
hoelzl@43923
   950
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
   951
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
hoelzl@41981
   952
proof (intro iffI allI)
hoelzl@41981
   953
  assume pos[rule_format]: "\<forall>a. f -` {..a} \<inter> space M \<in> sets M"
hoelzl@41981
   954
  show "f \<in> borel_measurable M"
hoelzl@43920
   955
    unfolding borel_measurable_ereal_iff_real borel_measurable_iff_le
hoelzl@41981
   956
  proof (intro conjI allI)
hoelzl@41981
   957
    fix a :: real
hoelzl@43920
   958
    { fix x :: ereal assume *: "\<forall>i::nat. real i < x"
hoelzl@41981
   959
      have "x = \<infinity>"
hoelzl@43920
   960
      proof (rule ereal_top)
huffman@44666
   961
        fix B from reals_Archimedean2[of B] guess n ..
hoelzl@43920
   962
        then have "ereal B < real n" by auto
hoelzl@41981
   963
        with * show "B \<le> x" by (metis less_trans less_imp_le)
hoelzl@41981
   964
      qed }
hoelzl@41981
   965
    then have "f -` {\<infinity>} \<inter> space M = space M - (\<Union>i::nat. f -` {.. real i} \<inter> space M)"
hoelzl@41981
   966
      by (auto simp: not_le)
hoelzl@50002
   967
    then show "f -` {\<infinity>} \<inter> space M \<in> sets M" using pos
hoelzl@50002
   968
      by (auto simp del: UN_simps)
hoelzl@41981
   969
    moreover
hoelzl@43923
   970
    have "{-\<infinity>::ereal} = {..-\<infinity>}" by auto
hoelzl@41981
   971
    then show "f -` {-\<infinity>} \<inter> space M \<in> sets M" using pos by auto
hoelzl@43920
   972
    moreover have "{x\<in>space M. f x \<le> ereal a} \<in> sets M"
hoelzl@43920
   973
      using pos[of "ereal a"] by (simp add: vimage_def Int_def conj_commute)
hoelzl@41981
   974
    moreover have "{w \<in> space M. real (f w) \<le> a} =
hoelzl@43920
   975
      (if a < 0 then {w \<in> space M. f w \<le> ereal a} - f -` {-\<infinity>} \<inter> space M
hoelzl@43920
   976
      else {w \<in> space M. f w \<le> ereal a} \<union> (f -` {\<infinity>} \<inter> space M) \<union> (f -` {-\<infinity>} \<inter> space M))" (is "?l = ?r")
hoelzl@41981
   977
      proof (intro set_eqI) fix x show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" by (cases "f x") auto qed
hoelzl@41981
   978
    ultimately show "{w \<in> space M. real (f w) \<le> a} \<in> sets M" by auto
hoelzl@35582
   979
  qed
hoelzl@41981
   980
qed (simp add: measurable_sets)
hoelzl@35582
   981
hoelzl@47694
   982
lemma borel_measurable_eq_atLeast_ereal:
hoelzl@43920
   983
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
hoelzl@41981
   984
proof
hoelzl@41981
   985
  assume pos: "\<forall>a. f -` {a..} \<inter> space M \<in> sets M"
hoelzl@41981
   986
  moreover have "\<And>a. (\<lambda>x. - f x) -` {..a} = f -` {-a ..}"
hoelzl@43920
   987
    by (auto simp: ereal_uminus_le_reorder)
hoelzl@41981
   988
  ultimately have "(\<lambda>x. - f x) \<in> borel_measurable M"
hoelzl@43920
   989
    unfolding borel_measurable_eq_atMost_ereal by auto
hoelzl@41981
   990
  then show "f \<in> borel_measurable M" by simp
hoelzl@41981
   991
qed (simp add: measurable_sets)
hoelzl@35582
   992
hoelzl@49774
   993
lemma greater_eq_le_measurable:
hoelzl@49774
   994
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@49774
   995
  shows "f -` {..< a} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@49774
   996
proof
hoelzl@49774
   997
  assume "f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@49774
   998
  moreover have "f -` {..< a} \<inter> space M = space M - f -` {a ..} \<inter> space M" by auto
hoelzl@49774
   999
  ultimately show "f -` {..< a} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1000
next
hoelzl@49774
  1001
  assume "f -` {..< a} \<inter> space M \<in> sets M"
hoelzl@49774
  1002
  moreover have "f -` {a ..} \<inter> space M = space M - f -` {..< a} \<inter> space M" by auto
hoelzl@49774
  1003
  ultimately show "f -` {a ..} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1004
qed
hoelzl@49774
  1005
hoelzl@47694
  1006
lemma borel_measurable_ereal_iff_less:
hoelzl@43920
  1007
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
hoelzl@43920
  1008
  unfolding borel_measurable_eq_atLeast_ereal greater_eq_le_measurable ..
hoelzl@38656
  1009
hoelzl@49774
  1010
lemma less_eq_ge_measurable:
hoelzl@49774
  1011
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@49774
  1012
  shows "f -` {a <..} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {..a} \<inter> space M \<in> sets M"
hoelzl@49774
  1013
proof
hoelzl@49774
  1014
  assume "f -` {a <..} \<inter> space M \<in> sets M"
hoelzl@49774
  1015
  moreover have "f -` {..a} \<inter> space M = space M - f -` {a <..} \<inter> space M" by auto
hoelzl@49774
  1016
  ultimately show "f -` {..a} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1017
next
hoelzl@49774
  1018
  assume "f -` {..a} \<inter> space M \<in> sets M"
hoelzl@49774
  1019
  moreover have "f -` {a <..} \<inter> space M = space M - f -` {..a} \<inter> space M" by auto
hoelzl@49774
  1020
  ultimately show "f -` {a <..} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1021
qed
hoelzl@49774
  1022
hoelzl@47694
  1023
lemma borel_measurable_ereal_iff_ge:
hoelzl@43920
  1024
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
hoelzl@43920
  1025
  unfolding borel_measurable_eq_atMost_ereal less_eq_ge_measurable ..
hoelzl@38656
  1026
hoelzl@49774
  1027
lemma borel_measurable_ereal2:
hoelzl@49774
  1028
  fixes f g :: "'a \<Rightarrow> ereal" 
hoelzl@41981
  1029
  assumes f: "f \<in> borel_measurable M"
hoelzl@41981
  1030
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1031
  assumes H: "(\<lambda>x. H (ereal (real (f x))) (ereal (real (g x)))) \<in> borel_measurable M"
hoelzl@49774
  1032
    "(\<lambda>x. H (-\<infinity>) (ereal (real (g x)))) \<in> borel_measurable M"
hoelzl@49774
  1033
    "(\<lambda>x. H (\<infinity>) (ereal (real (g x)))) \<in> borel_measurable M"
hoelzl@49774
  1034
    "(\<lambda>x. H (ereal (real (f x))) (-\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1035
    "(\<lambda>x. H (ereal (real (f x))) (\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1036
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@41981
  1037
proof -
hoelzl@50002
  1038
  let ?G = "\<lambda>y x. if g x = \<infinity> then H y \<infinity> else if g x = - \<infinity> then H y (-\<infinity>) else H y (ereal (real (g x)))"
hoelzl@50002
  1039
  let ?F = "\<lambda>x. if f x = \<infinity> then ?G \<infinity> x else if f x = - \<infinity> then ?G (-\<infinity>) x else ?G (ereal (real (f x))) x"
hoelzl@49774
  1040
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
  1041
  note * = this
hoelzl@50002
  1042
  from assms show ?thesis unfolding * by simp
hoelzl@41981
  1043
qed
hoelzl@41981
  1044
hoelzl@49774
  1045
lemma
hoelzl@49774
  1046
  fixes f :: "'a \<Rightarrow> ereal" assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1047
  shows borel_measurable_ereal_eq_const: "{x\<in>space M. f x = c} \<in> sets M"
hoelzl@49774
  1048
    and borel_measurable_ereal_neq_const: "{x\<in>space M. f x \<noteq> c} \<in> sets M"
hoelzl@49774
  1049
  using f by auto
hoelzl@38656
  1050
hoelzl@50003
  1051
lemma [measurable(raw)]:
hoelzl@43920
  1052
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@50003
  1053
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@50002
  1054
  shows borel_measurable_ereal_add: "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@50002
  1055
    and borel_measurable_ereal_times: "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@50002
  1056
    and borel_measurable_ereal_min: "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
hoelzl@50002
  1057
    and borel_measurable_ereal_max: "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
hoelzl@50003
  1058
  by (simp_all add: borel_measurable_ereal2 min_def max_def)
hoelzl@49774
  1059
hoelzl@50003
  1060
lemma [measurable(raw)]:
hoelzl@49774
  1061
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1062
  assumes "f \<in> borel_measurable M"
hoelzl@49774
  1063
  assumes "g \<in> borel_measurable M"
hoelzl@50002
  1064
  shows borel_measurable_ereal_diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50002
  1065
    and borel_measurable_ereal_divide: "(\<lambda>x. f x / g x) \<in> borel_measurable M"
hoelzl@50003
  1066
  using assms by (simp_all add: minus_ereal_def divide_ereal_def)
hoelzl@38656
  1067
hoelzl@50003
  1068
lemma borel_measurable_ereal_setsum[measurable (raw)]:
hoelzl@43920
  1069
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41096
  1070
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1071
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41096
  1072
proof cases
hoelzl@41096
  1073
  assume "finite S"
hoelzl@41096
  1074
  thus ?thesis using assms
hoelzl@41096
  1075
    by induct auto
hoelzl@49774
  1076
qed simp
hoelzl@38656
  1077
hoelzl@50003
  1078
lemma borel_measurable_ereal_setprod[measurable (raw)]:
hoelzl@43920
  1079
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1080
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1081
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@38656
  1082
proof cases
hoelzl@38656
  1083
  assume "finite S"
hoelzl@41096
  1084
  thus ?thesis using assms by induct auto
hoelzl@41096
  1085
qed simp
hoelzl@38656
  1086
hoelzl@50003
  1087
lemma borel_measurable_SUP[measurable (raw)]:
hoelzl@43920
  1088
  fixes f :: "'d\<Colon>countable \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1089
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1090
  shows "(\<lambda>x. SUP i : A. f i x) \<in> borel_measurable M" (is "?sup \<in> borel_measurable M")
hoelzl@43920
  1091
  unfolding borel_measurable_ereal_iff_ge
hoelzl@41981
  1092
proof
hoelzl@38656
  1093
  fix a
hoelzl@41981
  1094
  have "?sup -` {a<..} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. a < f i x})"
noschinl@46884
  1095
    by (auto simp: less_SUP_iff)
hoelzl@41981
  1096
  then show "?sup -` {a<..} \<inter> space M \<in> sets M"
hoelzl@38656
  1097
    using assms by auto
hoelzl@38656
  1098
qed
hoelzl@38656
  1099
hoelzl@50003
  1100
lemma borel_measurable_INF[measurable (raw)]:
hoelzl@43920
  1101
  fixes f :: "'d :: countable \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1102
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1103
  shows "(\<lambda>x. INF i : A. f i x) \<in> borel_measurable M" (is "?inf \<in> borel_measurable M")
hoelzl@43920
  1104
  unfolding borel_measurable_ereal_iff_less
hoelzl@41981
  1105
proof
hoelzl@38656
  1106
  fix a
hoelzl@41981
  1107
  have "?inf -` {..<a} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. f i x < a})"
noschinl@46884
  1108
    by (auto simp: INF_less_iff)
hoelzl@41981
  1109
  then show "?inf -` {..<a} \<inter> space M \<in> sets M"
hoelzl@38656
  1110
    using assms by auto
hoelzl@38656
  1111
qed
hoelzl@38656
  1112
hoelzl@50003
  1113
lemma [measurable (raw)]:
hoelzl@43920
  1114
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41981
  1115
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@50002
  1116
  shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1117
    and borel_measurable_limsup: "(\<lambda>x. limsup (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1118
  unfolding liminf_SUPR_INFI limsup_INFI_SUPR using assms by auto
hoelzl@35692
  1119
hoelzl@50104
  1120
lemma sets_Collect_eventually_sequentially[measurable]:
hoelzl@50003
  1121
  "(\<And>i. {x\<in>space M. P x i} \<in> sets M) \<Longrightarrow> {x\<in>space M. eventually (P x) sequentially} \<in> sets M"
hoelzl@50003
  1122
  unfolding eventually_sequentially by simp
hoelzl@50003
  1123
hoelzl@50003
  1124
lemma sets_Collect_ereal_convergent[measurable]: 
hoelzl@50003
  1125
  fixes f :: "nat \<Rightarrow> 'a => ereal"
hoelzl@50003
  1126
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1127
  shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
hoelzl@50003
  1128
  unfolding convergent_ereal by auto
hoelzl@50003
  1129
hoelzl@50003
  1130
lemma borel_measurable_extreal_lim[measurable (raw)]:
hoelzl@50003
  1131
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1132
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1133
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1134
proof -
hoelzl@50003
  1135
  have "\<And>x. lim (\<lambda>i. f i x) = (if convergent (\<lambda>i. f i x) then limsup (\<lambda>i. f i x) else (THE i. False))"
hoelzl@50003
  1136
    using convergent_ereal_limsup by (simp add: lim_def convergent_def)
hoelzl@50003
  1137
  then show ?thesis
hoelzl@50003
  1138
    by simp
hoelzl@50003
  1139
qed
hoelzl@50003
  1140
hoelzl@49774
  1141
lemma borel_measurable_ereal_LIMSEQ:
hoelzl@49774
  1142
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@49774
  1143
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
hoelzl@49774
  1144
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@49774
  1145
  shows "u' \<in> borel_measurable M"
hoelzl@47694
  1146
proof -
hoelzl@49774
  1147
  have "\<And>x. x \<in> space M \<Longrightarrow> u' x = liminf (\<lambda>n. u n x)"
hoelzl@49774
  1148
    using u' by (simp add: lim_imp_Liminf[symmetric])
hoelzl@50003
  1149
  with u show ?thesis by (simp cong: measurable_cong)
hoelzl@47694
  1150
qed
hoelzl@47694
  1151
hoelzl@50003
  1152
lemma borel_measurable_extreal_suminf[measurable (raw)]:
hoelzl@43920
  1153
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1154
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@41981
  1155
  shows "(\<lambda>x. (\<Sum>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1156
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@39092
  1157
hoelzl@39092
  1158
section "LIMSEQ is borel measurable"
hoelzl@39092
  1159
hoelzl@47694
  1160
lemma borel_measurable_LIMSEQ:
hoelzl@39092
  1161
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@39092
  1162
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
hoelzl@39092
  1163
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@39092
  1164
  shows "u' \<in> borel_measurable M"
hoelzl@39092
  1165
proof -
hoelzl@43920
  1166
  have "\<And>x. x \<in> space M \<Longrightarrow> liminf (\<lambda>n. ereal (u n x)) = ereal (u' x)"
wenzelm@46731
  1167
    using u' by (simp add: lim_imp_Liminf)
hoelzl@43920
  1168
  moreover from u have "(\<lambda>x. liminf (\<lambda>n. ereal (u n x))) \<in> borel_measurable M"
hoelzl@39092
  1169
    by auto
hoelzl@43920
  1170
  ultimately show ?thesis by (simp cong: measurable_cong add: borel_measurable_ereal_iff)
hoelzl@39092
  1171
qed
hoelzl@39092
  1172
hoelzl@50002
  1173
lemma sets_Collect_Cauchy[measurable]: 
hoelzl@49774
  1174
  fixes f :: "nat \<Rightarrow> 'a => real"
hoelzl@50002
  1175
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1176
  shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
hoelzl@50002
  1177
  unfolding Cauchy_iff2 using f by auto
hoelzl@49774
  1178
hoelzl@50002
  1179
lemma borel_measurable_lim[measurable (raw)]:
hoelzl@49774
  1180
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@50002
  1181
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1182
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1183
proof -
hoelzl@50002
  1184
  def u' \<equiv> "\<lambda>x. lim (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@50002
  1185
  then have *: "\<And>x. lim (\<lambda>i. f i x) = (if Cauchy (\<lambda>i. f i x) then u' x else (THE x. False))"
hoelzl@49774
  1186
    by (auto simp: lim_def convergent_eq_cauchy[symmetric])
hoelzl@50002
  1187
  have "u' \<in> borel_measurable M"
hoelzl@50002
  1188
  proof (rule borel_measurable_LIMSEQ)
hoelzl@50002
  1189
    fix x
hoelzl@50002
  1190
    have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@49774
  1191
      by (cases "Cauchy (\<lambda>i. f i x)")
hoelzl@50002
  1192
         (auto simp add: convergent_eq_cauchy[symmetric] convergent_def)
hoelzl@50002
  1193
    then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) ----> u' x"
hoelzl@50002
  1194
      unfolding u'_def 
hoelzl@50002
  1195
      by (rule convergent_LIMSEQ_iff[THEN iffD1])
hoelzl@50002
  1196
  qed measurable
hoelzl@50002
  1197
  then show ?thesis
hoelzl@50002
  1198
    unfolding * by measurable
hoelzl@49774
  1199
qed
hoelzl@49774
  1200
hoelzl@50002
  1201
lemma borel_measurable_suminf[measurable (raw)]:
hoelzl@49774
  1202
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@50002
  1203
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1204
  shows "(\<lambda>x. suminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1205
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@49774
  1206
hoelzl@49774
  1207
end