src/HOL/Probability/Borel_Space.thy
author hoelzl
Mon Mar 14 14:37:49 2011 +0100 (2011-03-14)
changeset 41981 cdf7693bbe08
parent 41969 1cf3e4107a2a
child 42067 66c8281349ec
permissions -rw-r--r--
reworked Probability theory: measures are not type restricted to positive extended reals
hoelzl@38656
     1
(* Author: Armin Heller, Johannes Hoelzl, TU Muenchen *)
hoelzl@38656
     2
hoelzl@38656
     3
header {*Borel spaces*}
paulson@33533
     4
hoelzl@40859
     5
theory Borel_Space
hoelzl@41981
     6
  imports Sigma_Algebra Multivariate_Analysis
paulson@33533
     7
begin
paulson@33533
     8
hoelzl@38656
     9
section "Generic Borel spaces"
paulson@33533
    10
hoelzl@40859
    11
definition "borel = sigma \<lparr> space = UNIV::'a::topological_space set, sets = open\<rparr>"
hoelzl@40859
    12
abbreviation "borel_measurable M \<equiv> measurable M borel"
paulson@33533
    13
hoelzl@40859
    14
interpretation borel: sigma_algebra borel
hoelzl@40859
    15
  by (auto simp: borel_def intro!: sigma_algebra_sigma)
paulson@33533
    16
paulson@33533
    17
lemma in_borel_measurable:
paulson@33533
    18
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
    19
    (\<forall>S \<in> sets (sigma \<lparr> space = UNIV, sets = open\<rparr>).
hoelzl@38656
    20
      f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
    21
  by (auto simp add: measurable_def borel_def)
paulson@33533
    22
hoelzl@40859
    23
lemma in_borel_measurable_borel:
hoelzl@38656
    24
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
    25
    (\<forall>S \<in> sets borel.
hoelzl@38656
    26
      f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
    27
  by (auto simp add: measurable_def borel_def)
paulson@33533
    28
hoelzl@40859
    29
lemma space_borel[simp]: "space borel = UNIV"
hoelzl@40859
    30
  unfolding borel_def by auto
hoelzl@38656
    31
hoelzl@40859
    32
lemma borel_open[simp]:
hoelzl@40859
    33
  assumes "open A" shows "A \<in> sets borel"
hoelzl@38656
    34
proof -
hoelzl@38656
    35
  have "A \<in> open" unfolding mem_def using assms .
hoelzl@40859
    36
  thus ?thesis unfolding borel_def sigma_def by (auto intro!: sigma_sets.Basic)
paulson@33533
    37
qed
paulson@33533
    38
hoelzl@40859
    39
lemma borel_closed[simp]:
hoelzl@40859
    40
  assumes "closed A" shows "A \<in> sets borel"
paulson@33533
    41
proof -
hoelzl@40859
    42
  have "space borel - (- A) \<in> sets borel"
hoelzl@40859
    43
    using assms unfolding closed_def by (blast intro: borel_open)
hoelzl@38656
    44
  thus ?thesis by simp
paulson@33533
    45
qed
paulson@33533
    46
hoelzl@41830
    47
lemma borel_comp[intro,simp]: "A \<in> sets borel \<Longrightarrow> - A \<in> sets borel"
hoelzl@41830
    48
  unfolding Compl_eq_Diff_UNIV by (intro borel.Diff) auto
hoelzl@41830
    49
hoelzl@38656
    50
lemma (in sigma_algebra) borel_measurable_vimage:
hoelzl@38656
    51
  fixes f :: "'a \<Rightarrow> 'x::t2_space"
hoelzl@38656
    52
  assumes borel: "f \<in> borel_measurable M"
hoelzl@38656
    53
  shows "f -` {x} \<inter> space M \<in> sets M"
hoelzl@38656
    54
proof (cases "x \<in> f ` space M")
hoelzl@38656
    55
  case True then obtain y where "x = f y" by auto
hoelzl@41969
    56
  from closed_singleton[of "f y"]
hoelzl@40859
    57
  have "{f y} \<in> sets borel" by (rule borel_closed)
hoelzl@38656
    58
  with assms show ?thesis
hoelzl@40859
    59
    unfolding in_borel_measurable_borel `x = f y` by auto
hoelzl@38656
    60
next
hoelzl@38656
    61
  case False hence "f -` {x} \<inter> space M = {}" by auto
hoelzl@38656
    62
  thus ?thesis by auto
paulson@33533
    63
qed
paulson@33533
    64
hoelzl@38656
    65
lemma (in sigma_algebra) borel_measurableI:
hoelzl@38656
    66
  fixes f :: "'a \<Rightarrow> 'x\<Colon>topological_space"
hoelzl@38656
    67
  assumes "\<And>S. open S \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
hoelzl@38656
    68
  shows "f \<in> borel_measurable M"
hoelzl@40859
    69
  unfolding borel_def
hoelzl@40859
    70
proof (rule measurable_sigma, simp_all)
hoelzl@38656
    71
  fix S :: "'x set" assume "S \<in> open" thus "f -` S \<inter> space M \<in> sets M"
hoelzl@38656
    72
    using assms[of S] by (simp add: mem_def)
hoelzl@40859
    73
qed
paulson@33533
    74
hoelzl@40859
    75
lemma borel_singleton[simp, intro]:
hoelzl@38656
    76
  fixes x :: "'a::t1_space"
hoelzl@40859
    77
  shows "A \<in> sets borel \<Longrightarrow> insert x A \<in> sets borel"
hoelzl@40859
    78
  proof (rule borel.insert_in_sets)
hoelzl@40859
    79
    show "{x} \<in> sets borel"
hoelzl@41969
    80
      using closed_singleton[of x] by (rule borel_closed)
hoelzl@38656
    81
  qed simp
hoelzl@38656
    82
hoelzl@38656
    83
lemma (in sigma_algebra) borel_measurable_const[simp, intro]:
hoelzl@38656
    84
  "(\<lambda>x. c) \<in> borel_measurable M"
hoelzl@38656
    85
  by (auto intro!: measurable_const)
paulson@33533
    86
hoelzl@39083
    87
lemma (in sigma_algebra) borel_measurable_indicator[simp, intro!]:
hoelzl@38656
    88
  assumes A: "A \<in> sets M"
hoelzl@38656
    89
  shows "indicator A \<in> borel_measurable M"
hoelzl@38656
    90
  unfolding indicator_def_raw using A
hoelzl@38656
    91
  by (auto intro!: measurable_If_set borel_measurable_const)
paulson@33533
    92
hoelzl@40859
    93
lemma (in sigma_algebra) borel_measurable_indicator_iff:
hoelzl@40859
    94
  "(indicator A :: 'a \<Rightarrow> 'x::{t1_space, zero_neq_one}) \<in> borel_measurable M \<longleftrightarrow> A \<inter> space M \<in> sets M"
hoelzl@40859
    95
    (is "?I \<in> borel_measurable M \<longleftrightarrow> _")
hoelzl@40859
    96
proof
hoelzl@40859
    97
  assume "?I \<in> borel_measurable M"
hoelzl@40859
    98
  then have "?I -` {1} \<inter> space M \<in> sets M"
hoelzl@40859
    99
    unfolding measurable_def by auto
hoelzl@40859
   100
  also have "?I -` {1} \<inter> space M = A \<inter> space M"
hoelzl@40859
   101
    unfolding indicator_def_raw by auto
hoelzl@40859
   102
  finally show "A \<inter> space M \<in> sets M" .
hoelzl@40859
   103
next
hoelzl@40859
   104
  assume "A \<inter> space M \<in> sets M"
hoelzl@40859
   105
  moreover have "?I \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
   106
    (indicator (A \<inter> space M) :: 'a \<Rightarrow> 'x) \<in> borel_measurable M"
hoelzl@40859
   107
    by (intro measurable_cong) (auto simp: indicator_def)
hoelzl@40859
   108
  ultimately show "?I \<in> borel_measurable M" by auto
hoelzl@40859
   109
qed
hoelzl@40859
   110
hoelzl@39092
   111
lemma (in sigma_algebra) borel_measurable_restricted:
hoelzl@41981
   112
  fixes f :: "'a \<Rightarrow> extreal" assumes "A \<in> sets M"
hoelzl@39092
   113
  shows "f \<in> borel_measurable (restricted_space A) \<longleftrightarrow>
hoelzl@39092
   114
    (\<lambda>x. f x * indicator A x) \<in> borel_measurable M"
hoelzl@39092
   115
    (is "f \<in> borel_measurable ?R \<longleftrightarrow> ?f \<in> borel_measurable M")
hoelzl@39092
   116
proof -
hoelzl@39092
   117
  interpret R: sigma_algebra ?R by (rule restricted_sigma_algebra[OF `A \<in> sets M`])
hoelzl@39092
   118
  have *: "f \<in> borel_measurable ?R \<longleftrightarrow> ?f \<in> borel_measurable ?R"
hoelzl@39092
   119
    by (auto intro!: measurable_cong)
hoelzl@39092
   120
  show ?thesis unfolding *
hoelzl@40859
   121
    unfolding in_borel_measurable_borel
hoelzl@39092
   122
  proof (simp, safe)
hoelzl@41981
   123
    fix S :: "extreal set" assume "S \<in> sets borel"
hoelzl@40859
   124
      "\<forall>S\<in>sets borel. ?f -` S \<inter> A \<in> op \<inter> A ` sets M"
hoelzl@39092
   125
    then have "?f -` S \<inter> A \<in> op \<inter> A ` sets M" by auto
hoelzl@39092
   126
    then have f: "?f -` S \<inter> A \<in> sets M"
hoelzl@39092
   127
      using `A \<in> sets M` sets_into_space by fastsimp
hoelzl@39092
   128
    show "?f -` S \<inter> space M \<in> sets M"
hoelzl@39092
   129
    proof cases
hoelzl@39092
   130
      assume "0 \<in> S"
hoelzl@39092
   131
      then have "?f -` S \<inter> space M = ?f -` S \<inter> A \<union> (space M - A)"
hoelzl@39092
   132
        using `A \<in> sets M` sets_into_space by auto
hoelzl@39092
   133
      then show ?thesis using f `A \<in> sets M` by (auto intro!: Un Diff)
hoelzl@39092
   134
    next
hoelzl@39092
   135
      assume "0 \<notin> S"
hoelzl@39092
   136
      then have "?f -` S \<inter> space M = ?f -` S \<inter> A"
hoelzl@39092
   137
        using `A \<in> sets M` sets_into_space
hoelzl@39092
   138
        by (auto simp: indicator_def split: split_if_asm)
hoelzl@39092
   139
      then show ?thesis using f by auto
hoelzl@39092
   140
    qed
hoelzl@39092
   141
  next
hoelzl@41981
   142
    fix S :: "extreal set" assume "S \<in> sets borel"
hoelzl@40859
   143
      "\<forall>S\<in>sets borel. ?f -` S \<inter> space M \<in> sets M"
hoelzl@39092
   144
    then have f: "?f -` S \<inter> space M \<in> sets M" by auto
hoelzl@39092
   145
    then show "?f -` S \<inter> A \<in> op \<inter> A ` sets M"
hoelzl@39092
   146
      using `A \<in> sets M` sets_into_space
hoelzl@39092
   147
      apply (simp add: image_iff)
hoelzl@39092
   148
      apply (rule bexI[OF _ f])
hoelzl@39092
   149
      by auto
hoelzl@39092
   150
  qed
hoelzl@39092
   151
qed
hoelzl@39092
   152
hoelzl@39092
   153
lemma (in sigma_algebra) borel_measurable_subalgebra:
hoelzl@41545
   154
  assumes "sets N \<subseteq> sets M" "space N = space M" "f \<in> borel_measurable N"
hoelzl@39092
   155
  shows "f \<in> borel_measurable M"
hoelzl@39092
   156
  using assms unfolding measurable_def by auto
hoelzl@39092
   157
hoelzl@38656
   158
section "Borel spaces on euclidean spaces"
hoelzl@38656
   159
hoelzl@38656
   160
lemma lessThan_borel[simp, intro]:
hoelzl@38656
   161
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   162
  shows "{..< a} \<in> sets borel"
hoelzl@40859
   163
  by (blast intro: borel_open)
hoelzl@38656
   164
hoelzl@38656
   165
lemma greaterThan_borel[simp, intro]:
hoelzl@38656
   166
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   167
  shows "{a <..} \<in> sets borel"
hoelzl@40859
   168
  by (blast intro: borel_open)
hoelzl@38656
   169
hoelzl@38656
   170
lemma greaterThanLessThan_borel[simp, intro]:
hoelzl@38656
   171
  fixes a b :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   172
  shows "{a<..<b} \<in> sets borel"
hoelzl@40859
   173
  by (blast intro: borel_open)
hoelzl@38656
   174
hoelzl@38656
   175
lemma atMost_borel[simp, intro]:
hoelzl@38656
   176
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   177
  shows "{..a} \<in> sets borel"
hoelzl@40859
   178
  by (blast intro: borel_closed)
hoelzl@38656
   179
hoelzl@38656
   180
lemma atLeast_borel[simp, intro]:
hoelzl@38656
   181
  fixes a :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   182
  shows "{a..} \<in> sets borel"
hoelzl@40859
   183
  by (blast intro: borel_closed)
hoelzl@38656
   184
hoelzl@38656
   185
lemma atLeastAtMost_borel[simp, intro]:
hoelzl@38656
   186
  fixes a b :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   187
  shows "{a..b} \<in> sets borel"
hoelzl@40859
   188
  by (blast intro: borel_closed)
paulson@33533
   189
hoelzl@38656
   190
lemma greaterThanAtMost_borel[simp, intro]:
hoelzl@38656
   191
  fixes a b :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   192
  shows "{a<..b} \<in> sets borel"
hoelzl@38656
   193
  unfolding greaterThanAtMost_def by blast
hoelzl@38656
   194
hoelzl@38656
   195
lemma atLeastLessThan_borel[simp, intro]:
hoelzl@38656
   196
  fixes a b :: "'a\<Colon>ordered_euclidean_space"
hoelzl@40859
   197
  shows "{a..<b} \<in> sets borel"
hoelzl@38656
   198
  unfolding atLeastLessThan_def by blast
hoelzl@38656
   199
hoelzl@38656
   200
lemma hafspace_less_borel[simp, intro]:
hoelzl@38656
   201
  fixes a :: real
hoelzl@40859
   202
  shows "{x::'a::euclidean_space. a < x $$ i} \<in> sets borel"
hoelzl@40859
   203
  by (auto intro!: borel_open open_halfspace_component_gt)
paulson@33533
   204
hoelzl@38656
   205
lemma hafspace_greater_borel[simp, intro]:
hoelzl@38656
   206
  fixes a :: real
hoelzl@40859
   207
  shows "{x::'a::euclidean_space. x $$ i < a} \<in> sets borel"
hoelzl@40859
   208
  by (auto intro!: borel_open open_halfspace_component_lt)
paulson@33533
   209
hoelzl@38656
   210
lemma hafspace_less_eq_borel[simp, intro]:
hoelzl@38656
   211
  fixes a :: real
hoelzl@40859
   212
  shows "{x::'a::euclidean_space. a \<le> x $$ i} \<in> sets borel"
hoelzl@40859
   213
  by (auto intro!: borel_closed closed_halfspace_component_ge)
paulson@33533
   214
hoelzl@38656
   215
lemma hafspace_greater_eq_borel[simp, intro]:
hoelzl@38656
   216
  fixes a :: real
hoelzl@40859
   217
  shows "{x::'a::euclidean_space. x $$ i \<le> a} \<in> sets borel"
hoelzl@40859
   218
  by (auto intro!: borel_closed closed_halfspace_component_le)
paulson@33533
   219
hoelzl@38656
   220
lemma (in sigma_algebra) borel_measurable_less[simp, intro]:
hoelzl@38656
   221
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   222
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   223
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   224
  shows "{w \<in> space M. f w < g w} \<in> sets M"
paulson@33533
   225
proof -
paulson@33533
   226
  have "{w \<in> space M. f w < g w} =
hoelzl@38656
   227
        (\<Union>r. (f -` {..< of_rat r} \<inter> space M) \<inter> (g -` {of_rat r <..} \<inter> space M))"
hoelzl@38656
   228
    using Rats_dense_in_real by (auto simp add: Rats_def)
hoelzl@38656
   229
  then show ?thesis using f g
hoelzl@38656
   230
    by simp (blast intro: measurable_sets)
paulson@33533
   231
qed
hoelzl@38656
   232
hoelzl@38656
   233
lemma (in sigma_algebra) borel_measurable_le[simp, intro]:
hoelzl@38656
   234
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   235
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   236
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   237
  shows "{w \<in> space M. f w \<le> g w} \<in> sets M"
paulson@33533
   238
proof -
hoelzl@38656
   239
  have "{w \<in> space M. f w \<le> g w} = space M - {w \<in> space M. g w < f w}"
hoelzl@38656
   240
    by auto
hoelzl@38656
   241
  thus ?thesis using f g
hoelzl@38656
   242
    by simp blast
paulson@33533
   243
qed
paulson@33533
   244
hoelzl@38656
   245
lemma (in sigma_algebra) borel_measurable_eq[simp, intro]:
hoelzl@38656
   246
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   247
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   248
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   249
  shows "{w \<in> space M. f w = g w} \<in> sets M"
paulson@33533
   250
proof -
paulson@33533
   251
  have "{w \<in> space M. f w = g w} =
wenzelm@33536
   252
        {w \<in> space M. f w \<le> g w} \<inter> {w \<in> space M. g w \<le> f w}"
paulson@33533
   253
    by auto
hoelzl@38656
   254
  thus ?thesis using f g by auto
paulson@33533
   255
qed
paulson@33533
   256
hoelzl@38656
   257
lemma (in sigma_algebra) borel_measurable_neq[simp, intro]:
hoelzl@38656
   258
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   259
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   260
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   261
  shows "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
paulson@33533
   262
proof -
paulson@33533
   263
  have "{w \<in> space M. f w \<noteq> g w} = space M - {w \<in> space M. f w = g w}"
paulson@33533
   264
    by auto
hoelzl@38656
   265
  thus ?thesis using f g by auto
hoelzl@38656
   266
qed
hoelzl@38656
   267
hoelzl@38656
   268
subsection "Borel space equals sigma algebras over intervals"
hoelzl@38656
   269
hoelzl@38656
   270
lemma rational_boxes:
hoelzl@38656
   271
  fixes x :: "'a\<Colon>ordered_euclidean_space"
hoelzl@38656
   272
  assumes "0 < e"
hoelzl@38656
   273
  shows "\<exists>a b. (\<forall>i. a $$ i \<in> \<rat>) \<and> (\<forall>i. b $$ i \<in> \<rat>) \<and> x \<in> {a <..< b} \<and> {a <..< b} \<subseteq> ball x e"
hoelzl@38656
   274
proof -
hoelzl@38656
   275
  def e' \<equiv> "e / (2 * sqrt (real (DIM ('a))))"
hoelzl@38656
   276
  then have e: "0 < e'" using assms by (auto intro!: divide_pos_pos)
hoelzl@38656
   277
  have "\<forall>i. \<exists>y. y \<in> \<rat> \<and> y < x $$ i \<and> x $$ i - y < e'" (is "\<forall>i. ?th i")
hoelzl@38656
   278
  proof
hoelzl@38656
   279
    fix i from Rats_dense_in_real[of "x $$ i - e'" "x $$ i"] e
hoelzl@38656
   280
    show "?th i" by auto
hoelzl@38656
   281
  qed
hoelzl@38656
   282
  from choice[OF this] guess a .. note a = this
hoelzl@38656
   283
  have "\<forall>i. \<exists>y. y \<in> \<rat> \<and> x $$ i < y \<and> y - x $$ i < e'" (is "\<forall>i. ?th i")
hoelzl@38656
   284
  proof
hoelzl@38656
   285
    fix i from Rats_dense_in_real[of "x $$ i" "x $$ i + e'"] e
hoelzl@38656
   286
    show "?th i" by auto
hoelzl@38656
   287
  qed
hoelzl@38656
   288
  from choice[OF this] guess b .. note b = this
hoelzl@38656
   289
  { fix y :: 'a assume *: "Chi a < y" "y < Chi b"
hoelzl@38656
   290
    have "dist x y = sqrt (\<Sum>i<DIM('a). (dist (x $$ i) (y $$ i))\<twosuperior>)"
hoelzl@38656
   291
      unfolding setL2_def[symmetric] by (rule euclidean_dist_l2)
hoelzl@38656
   292
    also have "\<dots> < sqrt (\<Sum>i<DIM('a). e^2 / real (DIM('a)))"
hoelzl@38656
   293
    proof (rule real_sqrt_less_mono, rule setsum_strict_mono)
hoelzl@38656
   294
      fix i assume i: "i \<in> {..<DIM('a)}"
hoelzl@38656
   295
      have "a i < y$$i \<and> y$$i < b i" using * i eucl_less[where 'a='a] by auto
hoelzl@38656
   296
      moreover have "a i < x$$i" "x$$i - a i < e'" using a by auto
hoelzl@38656
   297
      moreover have "x$$i < b i" "b i - x$$i < e'" using b by auto
hoelzl@38656
   298
      ultimately have "\<bar>x$$i - y$$i\<bar> < 2 * e'" by auto
hoelzl@38656
   299
      then have "dist (x $$ i) (y $$ i) < e/sqrt (real (DIM('a)))"
hoelzl@38656
   300
        unfolding e'_def by (auto simp: dist_real_def)
hoelzl@38656
   301
      then have "(dist (x $$ i) (y $$ i))\<twosuperior> < (e/sqrt (real (DIM('a))))\<twosuperior>"
hoelzl@38656
   302
        by (rule power_strict_mono) auto
hoelzl@38656
   303
      then show "(dist (x $$ i) (y $$ i))\<twosuperior> < e\<twosuperior> / real DIM('a)"
hoelzl@38656
   304
        by (simp add: power_divide)
hoelzl@38656
   305
    qed auto
hoelzl@38656
   306
    also have "\<dots> = e" using `0 < e` by (simp add: real_eq_of_nat DIM_positive)
hoelzl@38656
   307
    finally have "dist x y < e" . }
hoelzl@38656
   308
  with a b show ?thesis
hoelzl@38656
   309
    apply (rule_tac exI[of _ "Chi a"])
hoelzl@38656
   310
    apply (rule_tac exI[of _ "Chi b"])
hoelzl@38656
   311
    using eucl_less[where 'a='a] by auto
hoelzl@38656
   312
qed
hoelzl@38656
   313
hoelzl@38656
   314
lemma ex_rat_list:
hoelzl@38656
   315
  fixes x :: "'a\<Colon>ordered_euclidean_space"
hoelzl@38656
   316
  assumes "\<And> i. x $$ i \<in> \<rat>"
hoelzl@38656
   317
  shows "\<exists> r. length r = DIM('a) \<and> (\<forall> i < DIM('a). of_rat (r ! i) = x $$ i)"
hoelzl@38656
   318
proof -
hoelzl@38656
   319
  have "\<forall>i. \<exists>r. x $$ i = of_rat r" using assms unfolding Rats_def by blast
hoelzl@38656
   320
  from choice[OF this] guess r ..
hoelzl@38656
   321
  then show ?thesis by (auto intro!: exI[of _ "map r [0 ..< DIM('a)]"])
hoelzl@38656
   322
qed
hoelzl@38656
   323
hoelzl@38656
   324
lemma open_UNION:
hoelzl@38656
   325
  fixes M :: "'a\<Colon>ordered_euclidean_space set"
hoelzl@38656
   326
  assumes "open M"
hoelzl@38656
   327
  shows "M = UNION {(a, b) | a b. {Chi (of_rat \<circ> op ! a) <..< Chi (of_rat \<circ> op ! b)} \<subseteq> M}
hoelzl@38656
   328
                   (\<lambda> (a, b). {Chi (of_rat \<circ> op ! a) <..< Chi (of_rat \<circ> op ! b)})"
hoelzl@38656
   329
    (is "M = UNION ?idx ?box")
hoelzl@38656
   330
proof safe
hoelzl@38656
   331
  fix x assume "x \<in> M"
hoelzl@38656
   332
  obtain e where e: "e > 0" "ball x e \<subseteq> M"
hoelzl@38656
   333
    using openE[OF assms `x \<in> M`] by auto
hoelzl@38656
   334
  then obtain a b where ab: "x \<in> {a <..< b}" "\<And>i. a $$ i \<in> \<rat>" "\<And>i. b $$ i \<in> \<rat>" "{a <..< b} \<subseteq> ball x e"
hoelzl@38656
   335
    using rational_boxes[OF e(1)] by blast
hoelzl@38656
   336
  then obtain p q where pq: "length p = DIM ('a)"
hoelzl@38656
   337
                            "length q = DIM ('a)"
hoelzl@38656
   338
                            "\<forall> i < DIM ('a). of_rat (p ! i) = a $$ i \<and> of_rat (q ! i) = b $$ i"
hoelzl@38656
   339
    using ex_rat_list[OF ab(2)] ex_rat_list[OF ab(3)] by blast
hoelzl@38656
   340
  hence p: "Chi (of_rat \<circ> op ! p) = a"
hoelzl@38656
   341
    using euclidean_eq[of "Chi (of_rat \<circ> op ! p)" a]
hoelzl@38656
   342
    unfolding o_def by auto
hoelzl@38656
   343
  from pq have q: "Chi (of_rat \<circ> op ! q) = b"
hoelzl@38656
   344
    using euclidean_eq[of "Chi (of_rat \<circ> op ! q)" b]
hoelzl@38656
   345
    unfolding o_def by auto
hoelzl@38656
   346
  have "x \<in> ?box (p, q)"
hoelzl@38656
   347
    using p q ab by auto
hoelzl@38656
   348
  thus "x \<in> UNION ?idx ?box" using ab e p q exI[of _ p] exI[of _ q] by auto
hoelzl@38656
   349
qed auto
hoelzl@38656
   350
hoelzl@38656
   351
lemma halfspace_span_open:
hoelzl@40859
   352
  "sigma_sets UNIV (range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i < a}))
hoelzl@40859
   353
    \<subseteq> sets borel"
hoelzl@40859
   354
  by (auto intro!: borel.sigma_sets_subset[simplified] borel_open
hoelzl@40859
   355
                   open_halfspace_component_lt)
hoelzl@38656
   356
hoelzl@38656
   357
lemma halfspace_lt_in_halfspace:
hoelzl@40859
   358
  "{x\<Colon>'a. x $$ i < a} \<in> sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i < a})\<rparr>)"
hoelzl@40859
   359
  by (auto intro!: sigma_sets.Basic simp: sets_sigma)
hoelzl@38656
   360
hoelzl@38656
   361
lemma halfspace_gt_in_halfspace:
hoelzl@40859
   362
  "{x\<Colon>'a. a < x $$ i} \<in> sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i < a})\<rparr>)"
hoelzl@40859
   363
  (is "?set \<in> sets ?SIGMA")
hoelzl@38656
   364
proof -
hoelzl@40859
   365
  interpret sigma_algebra "?SIGMA"
hoelzl@40859
   366
    by (intro sigma_algebra_sigma_sets) (simp_all add: sets_sigma)
hoelzl@38656
   367
  have *: "?set = (\<Union>n. space ?SIGMA - {x\<Colon>'a. x $$ i < a + 1 / real (Suc n)})"
hoelzl@38656
   368
  proof (safe, simp_all add: not_less)
hoelzl@38656
   369
    fix x assume "a < x $$ i"
hoelzl@38656
   370
    with reals_Archimedean[of "x $$ i - a"]
hoelzl@38656
   371
    obtain n where "a + 1 / real (Suc n) < x $$ i"
hoelzl@38656
   372
      by (auto simp: inverse_eq_divide field_simps)
hoelzl@38656
   373
    then show "\<exists>n. a + 1 / real (Suc n) \<le> x $$ i"
hoelzl@38656
   374
      by (blast intro: less_imp_le)
hoelzl@38656
   375
  next
hoelzl@38656
   376
    fix x n
hoelzl@38656
   377
    have "a < a + 1 / real (Suc n)" by auto
hoelzl@38656
   378
    also assume "\<dots> \<le> x"
hoelzl@38656
   379
    finally show "a < x" .
hoelzl@38656
   380
  qed
hoelzl@38656
   381
  show "?set \<in> sets ?SIGMA" unfolding *
hoelzl@38656
   382
    by (safe intro!: countable_UN Diff halfspace_lt_in_halfspace)
paulson@33533
   383
qed
paulson@33533
   384
hoelzl@38656
   385
lemma open_span_halfspace:
hoelzl@40859
   386
  "sets borel \<subseteq> sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. x $$ i < a})\<rparr>)"
hoelzl@38656
   387
    (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   388
proof -
hoelzl@40859
   389
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) simp
hoelzl@38656
   390
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   391
  { fix S :: "'a set" assume "S \<in> open" then have "open S" unfolding mem_def .
hoelzl@40859
   392
    from open_UNION[OF this]
hoelzl@40859
   393
    obtain I where *: "S =
hoelzl@40859
   394
      (\<Union>(a, b)\<in>I.
hoelzl@40859
   395
          (\<Inter> i<DIM('a). {x. (Chi (real_of_rat \<circ> op ! a)::'a) $$ i < x $$ i}) \<inter>
hoelzl@40859
   396
          (\<Inter> i<DIM('a). {x. x $$ i < (Chi (real_of_rat \<circ> op ! b)::'a) $$ i}))"
hoelzl@40859
   397
      unfolding greaterThanLessThan_def
hoelzl@40859
   398
      unfolding eucl_greaterThan_eq_halfspaces[where 'a='a]
hoelzl@40859
   399
      unfolding eucl_lessThan_eq_halfspaces[where 'a='a]
hoelzl@40859
   400
      by blast
hoelzl@40859
   401
    have "S \<in> sets ?SIGMA"
hoelzl@40859
   402
      unfolding *
hoelzl@40859
   403
      by (auto intro!: countable_UN Int countable_INT halfspace_lt_in_halfspace halfspace_gt_in_halfspace) }
hoelzl@40859
   404
  then show ?thesis unfolding borel_def
hoelzl@40859
   405
    by (intro sets_sigma_subset) auto
hoelzl@40859
   406
qed
hoelzl@38656
   407
hoelzl@38656
   408
lemma halfspace_span_halfspace_le:
hoelzl@40859
   409
  "sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i < a})\<rparr>) \<subseteq>
hoelzl@40859
   410
   sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x. x $$ i \<le> a})\<rparr>)"
hoelzl@38656
   411
  (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   412
proof -
hoelzl@40859
   413
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@38656
   414
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   415
  { fix a i
hoelzl@40859
   416
    have *: "{x::'a. x$$i < a} = (\<Union>n. {x. x$$i \<le> a - 1/real (Suc n)})"
hoelzl@40859
   417
    proof (safe, simp_all)
hoelzl@40859
   418
      fix x::'a assume *: "x$$i < a"
hoelzl@40859
   419
      with reals_Archimedean[of "a - x$$i"]
hoelzl@40859
   420
      obtain n where "x $$ i < a - 1 / (real (Suc n))"
hoelzl@40859
   421
        by (auto simp: field_simps inverse_eq_divide)
hoelzl@40859
   422
      then show "\<exists>n. x $$ i \<le> a - 1 / (real (Suc n))"
hoelzl@40859
   423
        by (blast intro: less_imp_le)
hoelzl@40859
   424
    next
hoelzl@40859
   425
      fix x::'a and n
hoelzl@40859
   426
      assume "x$$i \<le> a - 1 / real (Suc n)"
hoelzl@40859
   427
      also have "\<dots> < a" by auto
hoelzl@40859
   428
      finally show "x$$i < a" .
hoelzl@40859
   429
    qed
hoelzl@40859
   430
    have "{x. x$$i < a} \<in> sets ?SIGMA" unfolding *
hoelzl@40859
   431
      by (safe intro!: countable_UN)
hoelzl@40859
   432
         (auto simp: sets_sigma intro!: sigma_sets.Basic) }
hoelzl@40859
   433
  then show ?thesis by (intro sets_sigma_subset) auto
hoelzl@40859
   434
qed
hoelzl@38656
   435
hoelzl@38656
   436
lemma halfspace_span_halfspace_ge:
hoelzl@40859
   437
  "sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i < a})\<rparr>) \<subseteq>
hoelzl@40859
   438
   sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x. a \<le> x $$ i})\<rparr>)"
hoelzl@38656
   439
  (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   440
proof -
hoelzl@40859
   441
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@38656
   442
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   443
  { fix a i have *: "{x::'a. x$$i < a} = space ?SIGMA - {x::'a. a \<le> x$$i}" by auto
hoelzl@40859
   444
    have "{x. x$$i < a} \<in> sets ?SIGMA" unfolding *
hoelzl@40859
   445
      by (safe intro!: Diff)
hoelzl@40859
   446
         (auto simp: sets_sigma intro!: sigma_sets.Basic) }
hoelzl@40859
   447
  then show ?thesis by (intro sets_sigma_subset) auto
hoelzl@40859
   448
qed
hoelzl@38656
   449
hoelzl@38656
   450
lemma halfspace_le_span_halfspace_gt:
hoelzl@40859
   451
  "sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i \<le> a})\<rparr>) \<subseteq>
hoelzl@40859
   452
   sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x. a < x $$ i})\<rparr>)"
hoelzl@38656
   453
  (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   454
proof -
hoelzl@40859
   455
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@38656
   456
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   457
  { fix a i have *: "{x::'a. x$$i \<le> a} = space ?SIGMA - {x::'a. a < x$$i}" by auto
hoelzl@40859
   458
    have "{x. x$$i \<le> a} \<in> sets ?SIGMA" unfolding *
hoelzl@40859
   459
      by (safe intro!: Diff)
hoelzl@40859
   460
         (auto simp: sets_sigma intro!: sigma_sets.Basic) }
hoelzl@40859
   461
  then show ?thesis by (intro sets_sigma_subset) auto
hoelzl@40859
   462
qed
hoelzl@38656
   463
hoelzl@38656
   464
lemma halfspace_le_span_atMost:
hoelzl@40859
   465
  "sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i \<le> a})\<rparr>) \<subseteq>
hoelzl@40859
   466
   sets (sigma \<lparr>space=UNIV, sets=range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space})\<rparr>)"
hoelzl@38656
   467
  (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   468
proof -
hoelzl@40859
   469
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@38656
   470
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   471
  have "\<And>a i. {x. x$$i \<le> a} \<in> sets ?SIGMA"
hoelzl@38656
   472
  proof cases
hoelzl@40859
   473
    fix a i assume "i < DIM('a)"
hoelzl@38656
   474
    then have *: "{x::'a. x$$i \<le> a} = (\<Union>k::nat. {.. (\<chi>\<chi> n. if n = i then a else real k)})"
hoelzl@38656
   475
    proof (safe, simp_all add: eucl_le[where 'a='a] split: split_if_asm)
hoelzl@38656
   476
      fix x
hoelzl@38656
   477
      from real_arch_simple[of "Max ((\<lambda>i. x$$i)`{..<DIM('a)})"] guess k::nat ..
hoelzl@38656
   478
      then have "\<And>i. i < DIM('a) \<Longrightarrow> x$$i \<le> real k"
hoelzl@38656
   479
        by (subst (asm) Max_le_iff) auto
hoelzl@38656
   480
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> x $$ ia \<le> real k"
hoelzl@38656
   481
        by (auto intro!: exI[of _ k])
hoelzl@38656
   482
    qed
hoelzl@38656
   483
    show "{x. x$$i \<le> a} \<in> sets ?SIGMA" unfolding *
hoelzl@38656
   484
      by (safe intro!: countable_UN)
hoelzl@38656
   485
         (auto simp: sets_sigma intro!: sigma_sets.Basic)
hoelzl@38656
   486
  next
hoelzl@40859
   487
    fix a i assume "\<not> i < DIM('a)"
hoelzl@38656
   488
    then show "{x. x$$i \<le> a} \<in> sets ?SIGMA"
hoelzl@38656
   489
      using top by auto
hoelzl@38656
   490
  qed
hoelzl@40859
   491
  then show ?thesis by (intro sets_sigma_subset) auto
hoelzl@40859
   492
qed
hoelzl@38656
   493
hoelzl@38656
   494
lemma halfspace_le_span_greaterThan:
hoelzl@40859
   495
  "sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i \<le> a})\<rparr>) \<subseteq>
hoelzl@40859
   496
   sets (sigma \<lparr>space=UNIV, sets=range (\<lambda>a. {a<..})\<rparr>)"
hoelzl@38656
   497
  (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   498
proof -
hoelzl@40859
   499
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@38656
   500
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   501
  have "\<And>a i. {x. x$$i \<le> a} \<in> sets ?SIGMA"
hoelzl@38656
   502
  proof cases
hoelzl@40859
   503
    fix a i assume "i < DIM('a)"
hoelzl@38656
   504
    have "{x::'a. x$$i \<le> a} = space ?SIGMA - {x::'a. a < x$$i}" by auto
hoelzl@38656
   505
    also have *: "{x::'a. a < x$$i} = (\<Union>k::nat. {(\<chi>\<chi> n. if n = i then a else -real k) <..})" using `i <DIM('a)`
hoelzl@38656
   506
    proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@38656
   507
      fix x
hoelzl@38656
   508
      from real_arch_lt[of "Max ((\<lambda>i. -x$$i)`{..<DIM('a)})"]
hoelzl@38656
   509
      guess k::nat .. note k = this
hoelzl@38656
   510
      { fix i assume "i < DIM('a)"
hoelzl@38656
   511
        then have "-x$$i < real k"
hoelzl@38656
   512
          using k by (subst (asm) Max_less_iff) auto
hoelzl@38656
   513
        then have "- real k < x$$i" by simp }
hoelzl@38656
   514
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> -real k < x $$ ia"
hoelzl@38656
   515
        by (auto intro!: exI[of _ k])
hoelzl@38656
   516
    qed
hoelzl@38656
   517
    finally show "{x. x$$i \<le> a} \<in> sets ?SIGMA"
hoelzl@38656
   518
      apply (simp only:)
hoelzl@38656
   519
      apply (safe intro!: countable_UN Diff)
hoelzl@38656
   520
      by (auto simp: sets_sigma intro!: sigma_sets.Basic)
hoelzl@38656
   521
  next
hoelzl@40859
   522
    fix a i assume "\<not> i < DIM('a)"
hoelzl@38656
   523
    then show "{x. x$$i \<le> a} \<in> sets ?SIGMA"
hoelzl@38656
   524
      using top by auto
hoelzl@38656
   525
  qed
hoelzl@40859
   526
  then show ?thesis by (intro sets_sigma_subset) auto
hoelzl@40859
   527
qed
hoelzl@40859
   528
hoelzl@40859
   529
lemma halfspace_le_span_lessThan:
hoelzl@40859
   530
  "sets (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. a \<le> x $$ i})\<rparr>) \<subseteq>
hoelzl@40859
   531
   sets (sigma \<lparr>space=UNIV, sets=range (\<lambda>a. {..<a})\<rparr>)"
hoelzl@40859
   532
  (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   533
proof -
hoelzl@40859
   534
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@40859
   535
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   536
  have "\<And>a i. {x. a \<le> x$$i} \<in> sets ?SIGMA"
hoelzl@40859
   537
  proof cases
hoelzl@40859
   538
    fix a i assume "i < DIM('a)"
hoelzl@40859
   539
    have "{x::'a. a \<le> x$$i} = space ?SIGMA - {x::'a. x$$i < a}" by auto
hoelzl@40859
   540
    also have *: "{x::'a. x$$i < a} = (\<Union>k::nat. {..< (\<chi>\<chi> n. if n = i then a else real k)})" using `i <DIM('a)`
hoelzl@40859
   541
    proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@40859
   542
      fix x
hoelzl@40859
   543
      from real_arch_lt[of "Max ((\<lambda>i. x$$i)`{..<DIM('a)})"]
hoelzl@40859
   544
      guess k::nat .. note k = this
hoelzl@40859
   545
      { fix i assume "i < DIM('a)"
hoelzl@40859
   546
        then have "x$$i < real k"
hoelzl@40859
   547
          using k by (subst (asm) Max_less_iff) auto
hoelzl@40859
   548
        then have "x$$i < real k" by simp }
hoelzl@40859
   549
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> x $$ ia < real k"
hoelzl@40859
   550
        by (auto intro!: exI[of _ k])
hoelzl@40859
   551
    qed
hoelzl@40859
   552
    finally show "{x. a \<le> x$$i} \<in> sets ?SIGMA"
hoelzl@40859
   553
      apply (simp only:)
hoelzl@40859
   554
      apply (safe intro!: countable_UN Diff)
hoelzl@40859
   555
      by (auto simp: sets_sigma intro!: sigma_sets.Basic)
hoelzl@40859
   556
  next
hoelzl@40859
   557
    fix a i assume "\<not> i < DIM('a)"
hoelzl@40859
   558
    then show "{x. a \<le> x$$i} \<in> sets ?SIGMA"
hoelzl@40859
   559
      using top by auto
hoelzl@40859
   560
  qed
hoelzl@40859
   561
  then show ?thesis by (intro sets_sigma_subset) auto
hoelzl@40859
   562
qed
hoelzl@40859
   563
hoelzl@40859
   564
lemma atMost_span_atLeastAtMost:
hoelzl@40859
   565
  "sets (sigma \<lparr>space=UNIV, sets=range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space})\<rparr>) \<subseteq>
hoelzl@40859
   566
   sets (sigma \<lparr>space=UNIV, sets=range (\<lambda>(a,b). {a..b})\<rparr>)"
hoelzl@40859
   567
  (is "_ \<subseteq> sets ?SIGMA")
hoelzl@40859
   568
proof -
hoelzl@40859
   569
  have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@40859
   570
  then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   571
  { fix a::'a
hoelzl@40859
   572
    have *: "{..a} = (\<Union>n::nat. {- real n *\<^sub>R One .. a})"
hoelzl@40859
   573
    proof (safe, simp_all add: eucl_le[where 'a='a])
hoelzl@40859
   574
      fix x
hoelzl@40859
   575
      from real_arch_simple[of "Max ((\<lambda>i. - x$$i)`{..<DIM('a)})"]
hoelzl@40859
   576
      guess k::nat .. note k = this
hoelzl@40859
   577
      { fix i assume "i < DIM('a)"
hoelzl@40859
   578
        with k have "- x$$i \<le> real k"
hoelzl@40859
   579
          by (subst (asm) Max_le_iff) (auto simp: field_simps)
hoelzl@40859
   580
        then have "- real k \<le> x$$i" by simp }
hoelzl@40859
   581
      then show "\<exists>n::nat. \<forall>i<DIM('a). - real n \<le> x $$ i"
hoelzl@40859
   582
        by (auto intro!: exI[of _ k])
hoelzl@40859
   583
    qed
hoelzl@40859
   584
    have "{..a} \<in> sets ?SIGMA" unfolding *
hoelzl@40859
   585
      by (safe intro!: countable_UN)
hoelzl@40859
   586
         (auto simp: sets_sigma intro!: sigma_sets.Basic) }
hoelzl@40859
   587
  then show ?thesis by (intro sets_sigma_subset) auto
hoelzl@40859
   588
qed
hoelzl@40859
   589
hoelzl@40859
   590
lemma borel_eq_atMost:
hoelzl@40859
   591
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> a. {.. a::'a\<Colon>ordered_euclidean_space})\<rparr>)"
hoelzl@40859
   592
    (is "_ = ?SIGMA")
hoelzl@40869
   593
proof (intro algebra.equality antisym)
hoelzl@40859
   594
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   595
    using halfspace_le_span_atMost halfspace_span_halfspace_le open_span_halfspace
hoelzl@40859
   596
    by auto
hoelzl@40859
   597
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   598
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   599
qed auto
hoelzl@40859
   600
hoelzl@40859
   601
lemma borel_eq_atLeastAtMost:
hoelzl@40859
   602
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a :: 'a\<Colon>ordered_euclidean_space, b). {a .. b})\<rparr>)"
hoelzl@40859
   603
   (is "_ = ?SIGMA")
hoelzl@40869
   604
proof (intro algebra.equality antisym)
hoelzl@40859
   605
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   606
    using atMost_span_atLeastAtMost halfspace_le_span_atMost
hoelzl@40859
   607
      halfspace_span_halfspace_le open_span_halfspace
hoelzl@40859
   608
    by auto
hoelzl@40859
   609
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   610
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   611
qed auto
hoelzl@40859
   612
hoelzl@40859
   613
lemma borel_eq_greaterThan:
hoelzl@40859
   614
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a :: 'a\<Colon>ordered_euclidean_space). {a <..})\<rparr>)"
hoelzl@40859
   615
   (is "_ = ?SIGMA")
hoelzl@40869
   616
proof (intro algebra.equality antisym)
hoelzl@40859
   617
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   618
    using halfspace_le_span_greaterThan
hoelzl@40859
   619
      halfspace_span_halfspace_le open_span_halfspace
hoelzl@40859
   620
    by auto
hoelzl@40859
   621
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   622
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   623
qed auto
hoelzl@40859
   624
hoelzl@40859
   625
lemma borel_eq_lessThan:
hoelzl@40859
   626
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a :: 'a\<Colon>ordered_euclidean_space). {..< a})\<rparr>)"
hoelzl@40859
   627
   (is "_ = ?SIGMA")
hoelzl@40869
   628
proof (intro algebra.equality antisym)
hoelzl@40859
   629
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   630
    using halfspace_le_span_lessThan
hoelzl@40859
   631
      halfspace_span_halfspace_ge open_span_halfspace
hoelzl@40859
   632
    by auto
hoelzl@40859
   633
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   634
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   635
qed auto
hoelzl@40859
   636
hoelzl@40859
   637
lemma borel_eq_greaterThanLessThan:
hoelzl@40859
   638
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, b). {a <..< (b :: 'a \<Colon> ordered_euclidean_space)})\<rparr>)"
hoelzl@40859
   639
    (is "_ = ?SIGMA")
hoelzl@40869
   640
proof (intro algebra.equality antisym)
hoelzl@40859
   641
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   642
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   643
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   644
  proof -
hoelzl@40859
   645
    have "sigma_algebra ?SIGMA" by (rule sigma_algebra_sigma) auto
hoelzl@40859
   646
    then interpret sigma_algebra ?SIGMA .
hoelzl@40859
   647
    { fix M :: "'a set" assume "M \<in> open"
hoelzl@40859
   648
      then have "open M" by (simp add: mem_def)
hoelzl@40859
   649
      have "M \<in> sets ?SIGMA"
hoelzl@40859
   650
        apply (subst open_UNION[OF `open M`])
hoelzl@40859
   651
        apply (safe intro!: countable_UN)
hoelzl@40859
   652
        by (auto simp add: sigma_def intro!: sigma_sets.Basic) }
hoelzl@40859
   653
    then show ?thesis
hoelzl@40859
   654
      unfolding borel_def by (intro sets_sigma_subset) auto
hoelzl@40859
   655
  qed
hoelzl@38656
   656
qed auto
hoelzl@38656
   657
hoelzl@40859
   658
lemma borel_eq_halfspace_le:
hoelzl@40859
   659
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. x$$i \<le> a})\<rparr>)"
hoelzl@40859
   660
   (is "_ = ?SIGMA")
hoelzl@40869
   661
proof (intro algebra.equality antisym)
hoelzl@40859
   662
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   663
    using open_span_halfspace halfspace_span_halfspace_le by auto
hoelzl@40859
   664
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   665
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   666
qed auto
hoelzl@40859
   667
hoelzl@40859
   668
lemma borel_eq_halfspace_less:
hoelzl@40859
   669
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. x$$i < a})\<rparr>)"
hoelzl@40859
   670
   (is "_ = ?SIGMA")
hoelzl@40869
   671
proof (intro algebra.equality antisym)
hoelzl@40859
   672
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   673
    using open_span_halfspace .
hoelzl@40859
   674
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   675
    by (rule borel.sets_sigma_subset) auto
hoelzl@38656
   676
qed auto
hoelzl@38656
   677
hoelzl@40859
   678
lemma borel_eq_halfspace_gt:
hoelzl@40859
   679
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. a < x$$i})\<rparr>)"
hoelzl@40859
   680
   (is "_ = ?SIGMA")
hoelzl@40869
   681
proof (intro algebra.equality antisym)
hoelzl@40859
   682
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@40859
   683
    using halfspace_le_span_halfspace_gt open_span_halfspace halfspace_span_halfspace_le by auto
hoelzl@40859
   684
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   685
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   686
qed auto
hoelzl@38656
   687
hoelzl@40859
   688
lemma borel_eq_halfspace_ge:
hoelzl@40859
   689
  "borel = (sigma \<lparr>space=UNIV, sets=range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. a \<le> x$$i})\<rparr>)"
hoelzl@40859
   690
   (is "_ = ?SIGMA")
hoelzl@40869
   691
proof (intro algebra.equality antisym)
hoelzl@40859
   692
  show "sets borel \<subseteq> sets ?SIGMA"
hoelzl@38656
   693
    using halfspace_span_halfspace_ge open_span_halfspace by auto
hoelzl@40859
   694
  show "sets ?SIGMA \<subseteq> sets borel"
hoelzl@40859
   695
    by (rule borel.sets_sigma_subset) auto
hoelzl@40859
   696
qed auto
hoelzl@38656
   697
hoelzl@38656
   698
lemma (in sigma_algebra) borel_measurable_halfspacesI:
hoelzl@38656
   699
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@40859
   700
  assumes "borel = (sigma \<lparr>space=UNIV, sets=range F\<rparr>)"
hoelzl@38656
   701
  and "\<And>a i. S a i = f -` F (a,i) \<inter> space M"
hoelzl@38656
   702
  and "\<And>a i. \<not> i < DIM('c) \<Longrightarrow> S a i \<in> sets M"
hoelzl@38656
   703
  shows "f \<in> borel_measurable M = (\<forall>i<DIM('c). \<forall>a::real. S a i \<in> sets M)"
hoelzl@38656
   704
proof safe
hoelzl@38656
   705
  fix a :: real and i assume i: "i < DIM('c)" and f: "f \<in> borel_measurable M"
hoelzl@38656
   706
  then show "S a i \<in> sets M" unfolding assms
hoelzl@38656
   707
    by (auto intro!: measurable_sets sigma_sets.Basic simp: assms(1) sigma_def)
hoelzl@38656
   708
next
hoelzl@38656
   709
  assume a: "\<forall>i<DIM('c). \<forall>a. S a i \<in> sets M"
hoelzl@38656
   710
  { fix a i have "S a i \<in> sets M"
hoelzl@38656
   711
    proof cases
hoelzl@38656
   712
      assume "i < DIM('c)"
hoelzl@38656
   713
      with a show ?thesis unfolding assms(2) by simp
hoelzl@38656
   714
    next
hoelzl@38656
   715
      assume "\<not> i < DIM('c)"
hoelzl@38656
   716
      from assms(3)[OF this] show ?thesis .
hoelzl@38656
   717
    qed }
hoelzl@40859
   718
  then have "f \<in> measurable M (sigma \<lparr>space=UNIV, sets=range F\<rparr>)"
hoelzl@38656
   719
    by (auto intro!: measurable_sigma simp: assms(2))
hoelzl@38656
   720
  then show "f \<in> borel_measurable M" unfolding measurable_def
hoelzl@38656
   721
    unfolding assms(1) by simp
hoelzl@38656
   722
qed
hoelzl@38656
   723
hoelzl@38656
   724
lemma (in sigma_algebra) borel_measurable_iff_halfspace_le:
hoelzl@38656
   725
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   726
  shows "f \<in> borel_measurable M = (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. f w $$ i \<le> a} \<in> sets M)"
hoelzl@40859
   727
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_le]) auto
hoelzl@38656
   728
hoelzl@38656
   729
lemma (in sigma_algebra) borel_measurable_iff_halfspace_less:
hoelzl@38656
   730
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   731
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. f w $$ i < a} \<in> sets M)"
hoelzl@40859
   732
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_less]) auto
hoelzl@38656
   733
hoelzl@38656
   734
lemma (in sigma_algebra) borel_measurable_iff_halfspace_ge:
hoelzl@38656
   735
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   736
  shows "f \<in> borel_measurable M = (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. a \<le> f w $$ i} \<in> sets M)"
hoelzl@40859
   737
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_ge]) auto
hoelzl@38656
   738
hoelzl@38656
   739
lemma (in sigma_algebra) borel_measurable_iff_halfspace_greater:
hoelzl@38656
   740
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   741
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. a < f w $$ i} \<in> sets M)"
hoelzl@40859
   742
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_gt]) auto
hoelzl@38656
   743
hoelzl@38656
   744
lemma (in sigma_algebra) borel_measurable_iff_le:
hoelzl@38656
   745
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w \<le> a} \<in> sets M)"
hoelzl@38656
   746
  using borel_measurable_iff_halfspace_le[where 'c=real] by simp
hoelzl@38656
   747
hoelzl@38656
   748
lemma (in sigma_algebra) borel_measurable_iff_less:
hoelzl@38656
   749
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w < a} \<in> sets M)"
hoelzl@38656
   750
  using borel_measurable_iff_halfspace_less[where 'c=real] by simp
hoelzl@38656
   751
hoelzl@38656
   752
lemma (in sigma_algebra) borel_measurable_iff_ge:
hoelzl@38656
   753
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a \<le> f w} \<in> sets M)"
hoelzl@38656
   754
  using borel_measurable_iff_halfspace_ge[where 'c=real] by simp
hoelzl@38656
   755
hoelzl@38656
   756
lemma (in sigma_algebra) borel_measurable_iff_greater:
hoelzl@38656
   757
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a < f w} \<in> sets M)"
hoelzl@38656
   758
  using borel_measurable_iff_halfspace_greater[where 'c=real] by simp
hoelzl@38656
   759
hoelzl@41025
   760
lemma borel_measurable_euclidean_component:
hoelzl@40859
   761
  "(\<lambda>x::'a::euclidean_space. x $$ i) \<in> borel_measurable borel"
hoelzl@40859
   762
  unfolding borel_def[where 'a=real]
hoelzl@40859
   763
proof (rule borel.measurable_sigma, simp_all)
hoelzl@39087
   764
  fix S::"real set" assume "S \<in> open" then have "open S" unfolding mem_def .
hoelzl@39087
   765
  from open_vimage_euclidean_component[OF this]
hoelzl@40859
   766
  show "(\<lambda>x. x $$ i) -` S \<in> sets borel"
hoelzl@40859
   767
    by (auto intro: borel_open)
hoelzl@40859
   768
qed
hoelzl@39087
   769
hoelzl@41025
   770
lemma (in sigma_algebra) borel_measurable_euclidean_space:
hoelzl@39087
   771
  fixes f :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@39087
   772
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i<DIM('c). (\<lambda>x. f x $$ i) \<in> borel_measurable M)"
hoelzl@39087
   773
proof safe
hoelzl@39087
   774
  fix i assume "f \<in> borel_measurable M"
hoelzl@39087
   775
  then show "(\<lambda>x. f x $$ i) \<in> borel_measurable M"
hoelzl@39087
   776
    using measurable_comp[of f _ _ "\<lambda>x. x $$ i", unfolded comp_def]
hoelzl@41025
   777
    by (auto intro: borel_measurable_euclidean_component)
hoelzl@39087
   778
next
hoelzl@39087
   779
  assume f: "\<forall>i<DIM('c). (\<lambda>x. f x $$ i) \<in> borel_measurable M"
hoelzl@39087
   780
  then show "f \<in> borel_measurable M"
hoelzl@39087
   781
    unfolding borel_measurable_iff_halfspace_le by auto
hoelzl@39087
   782
qed
hoelzl@39087
   783
hoelzl@38656
   784
subsection "Borel measurable operators"
hoelzl@38656
   785
hoelzl@38656
   786
lemma (in sigma_algebra) affine_borel_measurable_vector:
hoelzl@38656
   787
  fixes f :: "'a \<Rightarrow> 'x::real_normed_vector"
hoelzl@38656
   788
  assumes "f \<in> borel_measurable M"
hoelzl@38656
   789
  shows "(\<lambda>x. a + b *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@38656
   790
proof (rule borel_measurableI)
hoelzl@38656
   791
  fix S :: "'x set" assume "open S"
hoelzl@38656
   792
  show "(\<lambda>x. a + b *\<^sub>R f x) -` S \<inter> space M \<in> sets M"
hoelzl@38656
   793
  proof cases
hoelzl@38656
   794
    assume "b \<noteq> 0"
hoelzl@38656
   795
    with `open S` have "((\<lambda>x. (- a + x) /\<^sub>R b) ` S) \<in> open" (is "?S \<in> open")
hoelzl@38656
   796
      by (auto intro!: open_affinity simp: scaleR.add_right mem_def)
hoelzl@40859
   797
    hence "?S \<in> sets borel"
hoelzl@40859
   798
      unfolding borel_def by (auto simp: sigma_def intro!: sigma_sets.Basic)
hoelzl@38656
   799
    moreover
hoelzl@38656
   800
    from `b \<noteq> 0` have "(\<lambda>x. a + b *\<^sub>R f x) -` S = f -` ?S"
hoelzl@38656
   801
      apply auto by (rule_tac x="a + b *\<^sub>R f x" in image_eqI, simp_all)
hoelzl@40859
   802
    ultimately show ?thesis using assms unfolding in_borel_measurable_borel
hoelzl@38656
   803
      by auto
hoelzl@38656
   804
  qed simp
hoelzl@38656
   805
qed
hoelzl@38656
   806
hoelzl@38656
   807
lemma (in sigma_algebra) affine_borel_measurable:
hoelzl@38656
   808
  fixes g :: "'a \<Rightarrow> real"
hoelzl@38656
   809
  assumes g: "g \<in> borel_measurable M"
hoelzl@38656
   810
  shows "(\<lambda>x. a + (g x) * b) \<in> borel_measurable M"
hoelzl@38656
   811
  using affine_borel_measurable_vector[OF assms] by (simp add: mult_commute)
hoelzl@38656
   812
hoelzl@38656
   813
lemma (in sigma_algebra) borel_measurable_add[simp, intro]:
hoelzl@38656
   814
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   815
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   816
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   817
  shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
paulson@33533
   818
proof -
hoelzl@38656
   819
  have 1: "\<And>a. {w\<in>space M. a \<le> f w + g w} = {w \<in> space M. a + g w * -1 \<le> f w}"
paulson@33533
   820
    by auto
hoelzl@38656
   821
  have "\<And>a. (\<lambda>w. a + (g w) * -1) \<in> borel_measurable M"
hoelzl@38656
   822
    by (rule affine_borel_measurable [OF g])
hoelzl@38656
   823
  then have "\<And>a. {w \<in> space M. (\<lambda>w. a + (g w) * -1)(w) \<le> f w} \<in> sets M" using f
hoelzl@38656
   824
    by auto
hoelzl@38656
   825
  then have "\<And>a. {w \<in> space M. a \<le> f w + g w} \<in> sets M"
hoelzl@38656
   826
    by (simp add: 1)
hoelzl@38656
   827
  then show ?thesis
hoelzl@38656
   828
    by (simp add: borel_measurable_iff_ge)
paulson@33533
   829
qed
paulson@33533
   830
hoelzl@41026
   831
lemma (in sigma_algebra) borel_measurable_setsum[simp, intro]:
hoelzl@41026
   832
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41026
   833
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41026
   834
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41026
   835
proof cases
hoelzl@41026
   836
  assume "finite S"
hoelzl@41026
   837
  thus ?thesis using assms by induct auto
hoelzl@41026
   838
qed simp
hoelzl@41026
   839
hoelzl@38656
   840
lemma (in sigma_algebra) borel_measurable_square:
hoelzl@38656
   841
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   842
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   843
  shows "(\<lambda>x. (f x)^2) \<in> borel_measurable M"
paulson@33533
   844
proof -
paulson@33533
   845
  {
paulson@33533
   846
    fix a
paulson@33533
   847
    have "{w \<in> space M. (f w)\<twosuperior> \<le> a} \<in> sets M"
paulson@33533
   848
    proof (cases rule: linorder_cases [of a 0])
paulson@33533
   849
      case less
hoelzl@38656
   850
      hence "{w \<in> space M. (f w)\<twosuperior> \<le> a} = {}"
paulson@33533
   851
        by auto (metis less order_le_less_trans power2_less_0)
paulson@33533
   852
      also have "... \<in> sets M"
hoelzl@38656
   853
        by (rule empty_sets)
paulson@33533
   854
      finally show ?thesis .
paulson@33533
   855
    next
paulson@33533
   856
      case equal
hoelzl@38656
   857
      hence "{w \<in> space M. (f w)\<twosuperior> \<le> a} =
paulson@33533
   858
             {w \<in> space M. f w \<le> 0} \<inter> {w \<in> space M. 0 \<le> f w}"
paulson@33533
   859
        by auto
paulson@33533
   860
      also have "... \<in> sets M"
hoelzl@38656
   861
        apply (insert f)
hoelzl@38656
   862
        apply (rule Int)
hoelzl@38656
   863
        apply (simp add: borel_measurable_iff_le)
hoelzl@38656
   864
        apply (simp add: borel_measurable_iff_ge)
paulson@33533
   865
        done
paulson@33533
   866
      finally show ?thesis .
paulson@33533
   867
    next
paulson@33533
   868
      case greater
paulson@33533
   869
      have "\<forall>x. (f x ^ 2 \<le> sqrt a ^ 2) = (- sqrt a  \<le> f x & f x \<le> sqrt a)"
paulson@33533
   870
        by (metis abs_le_interval_iff abs_of_pos greater real_sqrt_abs
paulson@33533
   871
                  real_sqrt_le_iff real_sqrt_power)
paulson@33533
   872
      hence "{w \<in> space M. (f w)\<twosuperior> \<le> a} =
hoelzl@38656
   873
             {w \<in> space M. -(sqrt a) \<le> f w} \<inter> {w \<in> space M. f w \<le> sqrt a}"
paulson@33533
   874
        using greater by auto
paulson@33533
   875
      also have "... \<in> sets M"
hoelzl@38656
   876
        apply (insert f)
hoelzl@38656
   877
        apply (rule Int)
hoelzl@38656
   878
        apply (simp add: borel_measurable_iff_ge)
hoelzl@38656
   879
        apply (simp add: borel_measurable_iff_le)
paulson@33533
   880
        done
paulson@33533
   881
      finally show ?thesis .
paulson@33533
   882
    qed
paulson@33533
   883
  }
hoelzl@38656
   884
  thus ?thesis by (auto simp add: borel_measurable_iff_le)
paulson@33533
   885
qed
paulson@33533
   886
paulson@33533
   887
lemma times_eq_sum_squares:
paulson@33533
   888
   fixes x::real
paulson@33533
   889
   shows"x*y = ((x+y)^2)/4 - ((x-y)^ 2)/4"
hoelzl@38656
   890
by (simp add: power2_eq_square ring_distribs diff_divide_distrib [symmetric])
paulson@33533
   891
hoelzl@38656
   892
lemma (in sigma_algebra) borel_measurable_uminus[simp, intro]:
hoelzl@38656
   893
  fixes g :: "'a \<Rightarrow> real"
paulson@33533
   894
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   895
  shows "(\<lambda>x. - g x) \<in> borel_measurable M"
paulson@33533
   896
proof -
paulson@33533
   897
  have "(\<lambda>x. - g x) = (\<lambda>x. 0 + (g x) * -1)"
paulson@33533
   898
    by simp
hoelzl@38656
   899
  also have "... \<in> borel_measurable M"
hoelzl@38656
   900
    by (fast intro: affine_borel_measurable g)
paulson@33533
   901
  finally show ?thesis .
paulson@33533
   902
qed
paulson@33533
   903
hoelzl@38656
   904
lemma (in sigma_algebra) borel_measurable_times[simp, intro]:
hoelzl@38656
   905
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   906
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   907
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   908
  shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
paulson@33533
   909
proof -
paulson@33533
   910
  have 1: "(\<lambda>x. 0 + (f x + g x)\<twosuperior> * inverse 4) \<in> borel_measurable M"
hoelzl@38656
   911
    using assms by (fast intro: affine_borel_measurable borel_measurable_square)
hoelzl@38656
   912
  have "(\<lambda>x. -((f x + -g x) ^ 2 * inverse 4)) =
paulson@33533
   913
        (\<lambda>x. 0 + ((f x + -g x) ^ 2 * inverse -4))"
hoelzl@35582
   914
    by (simp add: minus_divide_right)
hoelzl@38656
   915
  also have "... \<in> borel_measurable M"
hoelzl@38656
   916
    using f g by (fast intro: affine_borel_measurable borel_measurable_square f g)
paulson@33533
   917
  finally have 2: "(\<lambda>x. -((f x + -g x) ^ 2 * inverse 4)) \<in> borel_measurable M" .
paulson@33533
   918
  show ?thesis
hoelzl@38656
   919
    apply (simp add: times_eq_sum_squares diff_minus)
hoelzl@38656
   920
    using 1 2 by simp
paulson@33533
   921
qed
paulson@33533
   922
hoelzl@41026
   923
lemma (in sigma_algebra) borel_measurable_setprod[simp, intro]:
hoelzl@41026
   924
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41026
   925
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41026
   926
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41026
   927
proof cases
hoelzl@41026
   928
  assume "finite S"
hoelzl@41026
   929
  thus ?thesis using assms by induct auto
hoelzl@41026
   930
qed simp
hoelzl@41026
   931
hoelzl@38656
   932
lemma (in sigma_algebra) borel_measurable_diff[simp, intro]:
hoelzl@38656
   933
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   934
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   935
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   936
  shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@38656
   937
  unfolding diff_minus using assms by fast
paulson@33533
   938
hoelzl@38656
   939
lemma (in sigma_algebra) borel_measurable_inverse[simp, intro]:
hoelzl@38656
   940
  fixes f :: "'a \<Rightarrow> real"
hoelzl@35692
   941
  assumes "f \<in> borel_measurable M"
hoelzl@35692
   942
  shows "(\<lambda>x. inverse (f x)) \<in> borel_measurable M"
hoelzl@38656
   943
  unfolding borel_measurable_iff_ge unfolding inverse_eq_divide
hoelzl@38656
   944
proof safe
hoelzl@38656
   945
  fix a :: real
hoelzl@38656
   946
  have *: "{w \<in> space M. a \<le> 1 / f w} =
hoelzl@38656
   947
      ({w \<in> space M. 0 < f w} \<inter> {w \<in> space M. a * f w \<le> 1}) \<union>
hoelzl@38656
   948
      ({w \<in> space M. f w < 0} \<inter> {w \<in> space M. 1 \<le> a * f w}) \<union>
hoelzl@38656
   949
      ({w \<in> space M. f w = 0} \<inter> {w \<in> space M. a \<le> 0})" by (auto simp: le_divide_eq)
hoelzl@38656
   950
  show "{w \<in> space M. a \<le> 1 / f w} \<in> sets M" using assms unfolding *
hoelzl@38656
   951
    by (auto intro!: Int Un)
hoelzl@35692
   952
qed
hoelzl@35692
   953
hoelzl@38656
   954
lemma (in sigma_algebra) borel_measurable_divide[simp, intro]:
hoelzl@38656
   955
  fixes f :: "'a \<Rightarrow> real"
hoelzl@35692
   956
  assumes "f \<in> borel_measurable M"
hoelzl@35692
   957
  and "g \<in> borel_measurable M"
hoelzl@35692
   958
  shows "(\<lambda>x. f x / g x) \<in> borel_measurable M"
hoelzl@35692
   959
  unfolding field_divide_inverse
hoelzl@38656
   960
  by (rule borel_measurable_inverse borel_measurable_times assms)+
hoelzl@38656
   961
hoelzl@38656
   962
lemma (in sigma_algebra) borel_measurable_max[intro, simp]:
hoelzl@38656
   963
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@38656
   964
  assumes "f \<in> borel_measurable M"
hoelzl@38656
   965
  assumes "g \<in> borel_measurable M"
hoelzl@38656
   966
  shows "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
hoelzl@38656
   967
  unfolding borel_measurable_iff_le
hoelzl@38656
   968
proof safe
hoelzl@38656
   969
  fix a
hoelzl@38656
   970
  have "{x \<in> space M. max (g x) (f x) \<le> a} =
hoelzl@38656
   971
    {x \<in> space M. g x \<le> a} \<inter> {x \<in> space M. f x \<le> a}" by auto
hoelzl@38656
   972
  thus "{x \<in> space M. max (g x) (f x) \<le> a} \<in> sets M"
hoelzl@38656
   973
    using assms unfolding borel_measurable_iff_le
hoelzl@38656
   974
    by (auto intro!: Int)
hoelzl@38656
   975
qed
hoelzl@38656
   976
hoelzl@38656
   977
lemma (in sigma_algebra) borel_measurable_min[intro, simp]:
hoelzl@38656
   978
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@38656
   979
  assumes "f \<in> borel_measurable M"
hoelzl@38656
   980
  assumes "g \<in> borel_measurable M"
hoelzl@38656
   981
  shows "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
hoelzl@38656
   982
  unfolding borel_measurable_iff_ge
hoelzl@38656
   983
proof safe
hoelzl@38656
   984
  fix a
hoelzl@38656
   985
  have "{x \<in> space M. a \<le> min (g x) (f x)} =
hoelzl@38656
   986
    {x \<in> space M. a \<le> g x} \<inter> {x \<in> space M. a \<le> f x}" by auto
hoelzl@38656
   987
  thus "{x \<in> space M. a \<le> min (g x) (f x)} \<in> sets M"
hoelzl@38656
   988
    using assms unfolding borel_measurable_iff_ge
hoelzl@38656
   989
    by (auto intro!: Int)
hoelzl@38656
   990
qed
hoelzl@38656
   991
hoelzl@38656
   992
lemma (in sigma_algebra) borel_measurable_abs[simp, intro]:
hoelzl@38656
   993
  assumes "f \<in> borel_measurable M"
hoelzl@38656
   994
  shows "(\<lambda>x. \<bar>f x :: real\<bar>) \<in> borel_measurable M"
hoelzl@38656
   995
proof -
hoelzl@38656
   996
  have *: "\<And>x. \<bar>f x\<bar> = max 0 (f x) + max 0 (- f x)" by (simp add: max_def)
hoelzl@38656
   997
  show ?thesis unfolding * using assms by auto
hoelzl@38656
   998
qed
hoelzl@38656
   999
hoelzl@41026
  1000
lemma borel_measurable_nth[simp, intro]:
hoelzl@41026
  1001
  "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
hoelzl@41026
  1002
  using borel_measurable_euclidean_component
hoelzl@41026
  1003
  unfolding nth_conv_component by auto
hoelzl@41026
  1004
hoelzl@41830
  1005
lemma borel_measurable_continuous_on1:
hoelzl@41830
  1006
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@41830
  1007
  assumes "continuous_on UNIV f"
hoelzl@41830
  1008
  shows "f \<in> borel_measurable borel"
hoelzl@41830
  1009
  apply(rule borel.borel_measurableI)
hoelzl@41830
  1010
  using continuous_open_preimage[OF assms] unfolding vimage_def by auto
hoelzl@41830
  1011
hoelzl@41830
  1012
lemma borel_measurable_continuous_on:
hoelzl@41830
  1013
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@41830
  1014
  assumes cont: "continuous_on A f" "open A" and f: "f -` {c} \<inter> A \<in> sets borel"
hoelzl@41830
  1015
  shows "(\<lambda>x. if x \<in> A then f x else c) \<in> borel_measurable borel" (is "?f \<in> _")
hoelzl@41830
  1016
proof (rule borel.borel_measurableI)
hoelzl@41830
  1017
  fix S :: "'b set" assume "open S"
hoelzl@41830
  1018
  then have "open {x\<in>A. f x \<in> S - {c}}"
hoelzl@41830
  1019
    by (intro continuous_open_preimage[OF cont]) auto
hoelzl@41830
  1020
  then have *: "{x\<in>A. f x \<in> S - {c}} \<in> sets borel" by auto
hoelzl@41830
  1021
  show "?f -` S \<inter> space borel \<in> sets borel"
hoelzl@41830
  1022
  proof cases
hoelzl@41830
  1023
    assume "c \<in> S"
hoelzl@41830
  1024
    then have "?f -` S = {x\<in>A. f x \<in> S - {c}} \<union> (f -` {c} \<inter> A) \<union> -A"
hoelzl@41830
  1025
      by auto
hoelzl@41830
  1026
    with * show "?f -` S \<inter> space borel \<in> sets borel"
hoelzl@41830
  1027
      using `open A` f by (auto intro!: borel.Un)
hoelzl@41830
  1028
  next
hoelzl@41830
  1029
    assume "c \<notin> S"
hoelzl@41830
  1030
    then have "?f -` S = {x\<in>A. f x \<in> S - {c}}" by (auto split: split_if_asm)
hoelzl@41830
  1031
    with * show "?f -` S \<inter> space borel \<in> sets borel" by auto
hoelzl@41830
  1032
  qed
hoelzl@41830
  1033
qed
hoelzl@41830
  1034
hoelzl@41830
  1035
lemma borel_measurable_borel_log: assumes "1 < b" shows "log b \<in> borel_measurable borel"
hoelzl@41830
  1036
proof -
hoelzl@41830
  1037
  { fix x :: real assume x: "x \<le> 0"
hoelzl@41830
  1038
    { fix x::real assume "x \<le> 0" then have "\<And>u. exp u = x \<longleftrightarrow> False" by auto }
hoelzl@41830
  1039
    from this[of x] x this[of 0] have "log b 0 = log b x"
hoelzl@41830
  1040
      by (auto simp: ln_def log_def) }
hoelzl@41830
  1041
  note log_imp = this
hoelzl@41830
  1042
  have "(\<lambda>x. if x \<in> {0<..} then log b x else log b 0) \<in> borel_measurable borel"
hoelzl@41830
  1043
  proof (rule borel_measurable_continuous_on)
hoelzl@41830
  1044
    show "continuous_on {0<..} (log b)"
hoelzl@41830
  1045
      by (auto intro!: continuous_at_imp_continuous_on DERIV_log DERIV_isCont
hoelzl@41830
  1046
               simp: continuous_isCont[symmetric])
hoelzl@41830
  1047
    show "open ({0<..}::real set)" by auto
hoelzl@41830
  1048
    show "log b -` {log b 0} \<inter> {0<..} \<in> sets borel"
hoelzl@41830
  1049
    proof cases
hoelzl@41830
  1050
      assume "log b -` {log b 0} \<inter> {0<..} = {}"
hoelzl@41830
  1051
      then show ?thesis by simp
hoelzl@41830
  1052
    next
hoelzl@41830
  1053
      assume "log b -` {log b 0} \<inter> {0<..} \<noteq> {}"
hoelzl@41830
  1054
      then obtain x where "0 < x" "log b x = log b 0" by auto
hoelzl@41830
  1055
      with log_inj[OF `1 < b`] have "log b -` {log b 0} \<inter> {0<..} = {x}"
hoelzl@41830
  1056
        by (auto simp: inj_on_def)
hoelzl@41830
  1057
      then show ?thesis by simp
hoelzl@41830
  1058
    qed
hoelzl@41830
  1059
  qed
hoelzl@41830
  1060
  also have "(\<lambda>x. if x \<in> {0<..} then log b x else log b 0) = log b"
hoelzl@41830
  1061
    by (simp add: fun_eq_iff not_less log_imp)
hoelzl@41830
  1062
  finally show ?thesis .
hoelzl@41830
  1063
qed
hoelzl@41830
  1064
hoelzl@41830
  1065
lemma (in sigma_algebra) borel_measurable_log[simp,intro]:
hoelzl@41830
  1066
  assumes f: "f \<in> borel_measurable M" and "1 < b"
hoelzl@41830
  1067
  shows "(\<lambda>x. log b (f x)) \<in> borel_measurable M"
hoelzl@41830
  1068
  using measurable_comp[OF f borel_measurable_borel_log[OF `1 < b`]]
hoelzl@41830
  1069
  by (simp add: comp_def)
hoelzl@41830
  1070
hoelzl@41981
  1071
subsection "Borel space on the extended reals"
hoelzl@41981
  1072
hoelzl@41981
  1073
lemma borel_measurable_extreal_borel:
hoelzl@41981
  1074
  "extreal \<in> borel_measurable borel"
hoelzl@41981
  1075
  unfolding borel_def[where 'a=extreal]
hoelzl@41981
  1076
proof (rule borel.measurable_sigma)
hoelzl@41981
  1077
  fix X :: "extreal set" assume "X \<in> sets \<lparr>space = UNIV, sets = open \<rparr>"
hoelzl@41981
  1078
  then have "open X" by (auto simp: mem_def)
hoelzl@41981
  1079
  then have "open (extreal -` X \<inter> space borel)"
hoelzl@41981
  1080
    by (simp add: open_extreal_vimage)
hoelzl@41981
  1081
  then show "extreal -` X \<inter> space borel \<in> sets borel" by auto
hoelzl@41981
  1082
qed auto
hoelzl@41981
  1083
hoelzl@41981
  1084
lemma (in sigma_algebra) borel_measurable_extreal[simp, intro]:
hoelzl@41981
  1085
  assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. extreal (f x)) \<in> borel_measurable M"
hoelzl@41981
  1086
  using measurable_comp[OF f borel_measurable_extreal_borel] unfolding comp_def .
hoelzl@41981
  1087
hoelzl@41981
  1088
lemma borel_measurable_real_of_extreal_borel:
hoelzl@41981
  1089
  "(real :: extreal \<Rightarrow> real) \<in> borel_measurable borel"
hoelzl@41981
  1090
  unfolding borel_def[where 'a=real]
hoelzl@41981
  1091
proof (rule borel.measurable_sigma)
hoelzl@41981
  1092
  fix B :: "real set" assume "B \<in> sets \<lparr>space = UNIV, sets = open \<rparr>"
hoelzl@41981
  1093
  then have "open B" by (auto simp: mem_def)
hoelzl@41981
  1094
  have *: "extreal -` real -` (B - {0}) = B - {0}" by auto
hoelzl@41981
  1095
  have open_real: "open (real -` (B - {0}) :: extreal set)"
hoelzl@41981
  1096
    unfolding open_extreal_def * using `open B` by auto
hoelzl@41981
  1097
  show "(real -` B \<inter> space borel :: extreal set) \<in> sets borel"
hoelzl@41981
  1098
  proof cases
hoelzl@41981
  1099
    assume "0 \<in> B"
hoelzl@41981
  1100
    then have *: "real -` B = real -` (B - {0}) \<union> {-\<infinity>, \<infinity>, 0}"
hoelzl@41981
  1101
      by (auto simp add: real_of_extreal_eq_0)
hoelzl@41981
  1102
    then show "(real -` B :: extreal set) \<inter> space borel \<in> sets borel"
hoelzl@41981
  1103
      using open_real by auto
hoelzl@41981
  1104
  next
hoelzl@41981
  1105
    assume "0 \<notin> B"
hoelzl@41981
  1106
    then have *: "(real -` B :: extreal set) = real -` (B - {0})"
hoelzl@41981
  1107
      by (auto simp add: real_of_extreal_eq_0)
hoelzl@41981
  1108
    then show "(real -` B :: extreal set) \<inter> space borel \<in> sets borel"
hoelzl@41981
  1109
      using open_real by auto
hoelzl@41981
  1110
  qed
hoelzl@41981
  1111
qed auto
hoelzl@41981
  1112
hoelzl@41981
  1113
lemma (in sigma_algebra) borel_measurable_real_of_extreal[simp, intro]:
hoelzl@41981
  1114
  assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. real (f x :: extreal)) \<in> borel_measurable M"
hoelzl@41981
  1115
  using measurable_comp[OF f borel_measurable_real_of_extreal_borel] unfolding comp_def .
hoelzl@41981
  1116
hoelzl@41981
  1117
lemma (in sigma_algebra) borel_measurable_extreal_iff:
hoelzl@41981
  1118
  shows "(\<lambda>x. extreal (f x)) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M"
hoelzl@41981
  1119
proof
hoelzl@41981
  1120
  assume "(\<lambda>x. extreal (f x)) \<in> borel_measurable M"
hoelzl@41981
  1121
  from borel_measurable_real_of_extreal[OF this]
hoelzl@41981
  1122
  show "f \<in> borel_measurable M" by auto
hoelzl@41981
  1123
qed auto
hoelzl@41981
  1124
hoelzl@41981
  1125
lemma (in sigma_algebra) borel_measurable_extreal_iff_real:
hoelzl@41981
  1126
  "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@41981
  1127
    ((\<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
  1128
proof safe
hoelzl@41981
  1129
  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
  1130
  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
  1131
  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
hoelzl@41981
  1132
  let "?f x" = "if f x = \<infinity> then \<infinity> else if f x = -\<infinity> then -\<infinity> else extreal (real (f x))"
hoelzl@41981
  1133
  have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
hoelzl@41981
  1134
  also have "?f = f" by (auto simp: fun_eq_iff extreal_real)
hoelzl@41981
  1135
  finally show "f \<in> borel_measurable M" .
hoelzl@41981
  1136
qed (auto intro: measurable_sets borel_measurable_real_of_extreal)
hoelzl@41830
  1137
hoelzl@38656
  1138
lemma (in sigma_algebra) less_eq_ge_measurable:
hoelzl@38656
  1139
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@41981
  1140
  shows "f -` {a <..} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {..a} \<inter> space M \<in> sets M"
hoelzl@38656
  1141
proof
hoelzl@41981
  1142
  assume "f -` {a <..} \<inter> space M \<in> sets M"
hoelzl@41981
  1143
  moreover have "f -` {..a} \<inter> space M = space M - f -` {a <..} \<inter> space M" by auto
hoelzl@41981
  1144
  ultimately show "f -` {..a} \<inter> space M \<in> sets M" by auto
hoelzl@38656
  1145
next
hoelzl@41981
  1146
  assume "f -` {..a} \<inter> space M \<in> sets M"
hoelzl@41981
  1147
  moreover have "f -` {a <..} \<inter> space M = space M - f -` {..a} \<inter> space M" by auto
hoelzl@41981
  1148
  ultimately show "f -` {a <..} \<inter> space M \<in> sets M" by auto
hoelzl@38656
  1149
qed
hoelzl@35692
  1150
hoelzl@38656
  1151
lemma (in sigma_algebra) greater_eq_le_measurable:
hoelzl@38656
  1152
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@41981
  1153
  shows "f -` {..< a} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@38656
  1154
proof
hoelzl@41981
  1155
  assume "f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@41981
  1156
  moreover have "f -` {..< a} \<inter> space M = space M - f -` {a ..} \<inter> space M" by auto
hoelzl@41981
  1157
  ultimately show "f -` {..< a} \<inter> space M \<in> sets M" by auto
hoelzl@38656
  1158
next
hoelzl@41981
  1159
  assume "f -` {..< a} \<inter> space M \<in> sets M"
hoelzl@41981
  1160
  moreover have "f -` {a ..} \<inter> space M = space M - f -` {..< a} \<inter> space M" by auto
hoelzl@41981
  1161
  ultimately show "f -` {a ..} \<inter> space M \<in> sets M" by auto
hoelzl@38656
  1162
qed
hoelzl@38656
  1163
hoelzl@41981
  1164
lemma (in sigma_algebra) borel_measurable_uminus_borel_extreal:
hoelzl@41981
  1165
  "(uminus :: extreal \<Rightarrow> extreal) \<in> borel_measurable borel"
hoelzl@41981
  1166
proof (subst borel_def, rule borel.measurable_sigma)
hoelzl@41981
  1167
  fix X :: "extreal set" assume "X \<in> sets \<lparr>space = UNIV, sets = open\<rparr>"
hoelzl@41981
  1168
  then have "open X" by (simp add: mem_def)
hoelzl@41981
  1169
  have "uminus -` X = uminus ` X" by (force simp: image_iff)
hoelzl@41981
  1170
  then have "open (uminus -` X)" using `open X` extreal_open_uminus by auto
hoelzl@41981
  1171
  then show "uminus -` X \<inter> space borel \<in> sets borel" by auto
hoelzl@41981
  1172
qed auto
hoelzl@41981
  1173
hoelzl@41981
  1174
lemma (in sigma_algebra) borel_measurable_uminus_extreal[intro]:
hoelzl@41981
  1175
  assumes "f \<in> borel_measurable M"
hoelzl@41981
  1176
  shows "(\<lambda>x. - f x :: extreal) \<in> borel_measurable M"
hoelzl@41981
  1177
  using measurable_comp[OF assms borel_measurable_uminus_borel_extreal] by (simp add: comp_def)
hoelzl@41981
  1178
hoelzl@41981
  1179
lemma (in sigma_algebra) borel_measurable_uminus_eq_extreal[simp]:
hoelzl@41981
  1180
  "(\<lambda>x. - f x :: extreal) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
hoelzl@38656
  1181
proof
hoelzl@41981
  1182
  assume ?l from borel_measurable_uminus_extreal[OF this] show ?r by simp
hoelzl@41981
  1183
qed auto
hoelzl@41981
  1184
hoelzl@41981
  1185
lemma (in sigma_algebra) borel_measurable_eq_atMost_extreal:
hoelzl@41981
  1186
  "(f::'a \<Rightarrow> extreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
hoelzl@41981
  1187
proof (intro iffI allI)
hoelzl@41981
  1188
  assume pos[rule_format]: "\<forall>a. f -` {..a} \<inter> space M \<in> sets M"
hoelzl@41981
  1189
  show "f \<in> borel_measurable M"
hoelzl@41981
  1190
    unfolding borel_measurable_extreal_iff_real borel_measurable_iff_le
hoelzl@41981
  1191
  proof (intro conjI allI)
hoelzl@41981
  1192
    fix a :: real
hoelzl@41981
  1193
    { fix x :: extreal assume *: "\<forall>i::nat. real i < x"
hoelzl@41981
  1194
      have "x = \<infinity>"
hoelzl@41981
  1195
      proof (rule extreal_top)
hoelzl@41981
  1196
        fix B from real_arch_lt[of B] guess n ..
hoelzl@41981
  1197
        then have "extreal B < real n" by auto
hoelzl@41981
  1198
        with * show "B \<le> x" by (metis less_trans less_imp_le)
hoelzl@41981
  1199
      qed }
hoelzl@41981
  1200
    then have "f -` {\<infinity>} \<inter> space M = space M - (\<Union>i::nat. f -` {.. real i} \<inter> space M)"
hoelzl@41981
  1201
      by (auto simp: not_le)
hoelzl@41981
  1202
    then show "f -` {\<infinity>} \<inter> space M \<in> sets M" using pos by (auto simp del: UN_simps intro!: Diff)
hoelzl@41981
  1203
    moreover
hoelzl@41981
  1204
    have "{-\<infinity>} = {..-\<infinity>}" by auto
hoelzl@41981
  1205
    then show "f -` {-\<infinity>} \<inter> space M \<in> sets M" using pos by auto
hoelzl@41981
  1206
    moreover have "{x\<in>space M. f x \<le> extreal a} \<in> sets M"
hoelzl@41981
  1207
      using pos[of "extreal a"] by (simp add: vimage_def Int_def conj_commute)
hoelzl@41981
  1208
    moreover have "{w \<in> space M. real (f w) \<le> a} =
hoelzl@41981
  1209
      (if a < 0 then {w \<in> space M. f w \<le> extreal a} - f -` {-\<infinity>} \<inter> space M
hoelzl@41981
  1210
      else {w \<in> space M. f w \<le> extreal a} \<union> (f -` {\<infinity>} \<inter> space M) \<union> (f -` {-\<infinity>} \<inter> space M))" (is "?l = ?r")
hoelzl@41981
  1211
      proof (intro set_eqI) fix x show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" by (cases "f x") auto qed
hoelzl@41981
  1212
    ultimately show "{w \<in> space M. real (f w) \<le> a} \<in> sets M" by auto
hoelzl@35582
  1213
  qed
hoelzl@41981
  1214
qed (simp add: measurable_sets)
hoelzl@35582
  1215
hoelzl@41981
  1216
lemma (in sigma_algebra) borel_measurable_eq_atLeast_extreal:
hoelzl@41981
  1217
  "(f::'a \<Rightarrow> extreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
hoelzl@41981
  1218
proof
hoelzl@41981
  1219
  assume pos: "\<forall>a. f -` {a..} \<inter> space M \<in> sets M"
hoelzl@41981
  1220
  moreover have "\<And>a. (\<lambda>x. - f x) -` {..a} = f -` {-a ..}"
hoelzl@41981
  1221
    by (auto simp: extreal_uminus_le_reorder)
hoelzl@41981
  1222
  ultimately have "(\<lambda>x. - f x) \<in> borel_measurable M"
hoelzl@41981
  1223
    unfolding borel_measurable_eq_atMost_extreal by auto
hoelzl@41981
  1224
  then show "f \<in> borel_measurable M" by simp
hoelzl@41981
  1225
qed (simp add: measurable_sets)
hoelzl@35582
  1226
hoelzl@41981
  1227
lemma (in sigma_algebra) borel_measurable_extreal_iff_less:
hoelzl@41981
  1228
  "(f::'a \<Rightarrow> extreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
hoelzl@41981
  1229
  unfolding borel_measurable_eq_atLeast_extreal greater_eq_le_measurable ..
hoelzl@38656
  1230
hoelzl@41981
  1231
lemma (in sigma_algebra) borel_measurable_extreal_iff_ge:
hoelzl@41981
  1232
  "(f::'a \<Rightarrow> extreal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
hoelzl@41981
  1233
  unfolding borel_measurable_eq_atMost_extreal less_eq_ge_measurable ..
hoelzl@38656
  1234
hoelzl@41981
  1235
lemma (in sigma_algebra) borel_measurable_extreal_eq_const:
hoelzl@41981
  1236
  fixes f :: "'a \<Rightarrow> extreal" assumes "f \<in> borel_measurable M"
hoelzl@38656
  1237
  shows "{x\<in>space M. f x = c} \<in> sets M"
hoelzl@38656
  1238
proof -
hoelzl@38656
  1239
  have "{x\<in>space M. f x = c} = (f -` {c} \<inter> space M)" by auto
hoelzl@38656
  1240
  then show ?thesis using assms by (auto intro!: measurable_sets)
hoelzl@38656
  1241
qed
hoelzl@38656
  1242
hoelzl@41981
  1243
lemma (in sigma_algebra) borel_measurable_extreal_neq_const:
hoelzl@41981
  1244
  fixes f :: "'a \<Rightarrow> extreal" assumes "f \<in> borel_measurable M"
hoelzl@38656
  1245
  shows "{x\<in>space M. f x \<noteq> c} \<in> sets M"
hoelzl@38656
  1246
proof -
hoelzl@38656
  1247
  have "{x\<in>space M. f x \<noteq> c} = space M - (f -` {c} \<inter> space M)" by auto
hoelzl@38656
  1248
  then show ?thesis using assms by (auto intro!: measurable_sets)
hoelzl@38656
  1249
qed
hoelzl@38656
  1250
hoelzl@41981
  1251
lemma (in sigma_algebra) borel_measurable_extreal_le[intro,simp]:
hoelzl@41981
  1252
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@41981
  1253
  assumes f: "f \<in> borel_measurable M"
hoelzl@41981
  1254
  assumes g: "g \<in> borel_measurable M"
hoelzl@41981
  1255
  shows "{x \<in> space M. f x \<le> g x} \<in> sets M"
hoelzl@41981
  1256
proof -
hoelzl@41981
  1257
  have "{x \<in> space M. f x \<le> g x} =
hoelzl@41981
  1258
    {x \<in> space M. real (f x) \<le> real (g x)} - (f -` {\<infinity>, -\<infinity>} \<inter> space M \<union> g -` {\<infinity>, -\<infinity>} \<inter> space M) \<union>
hoelzl@41981
  1259
    f -` {-\<infinity>} \<inter> space M \<union> g -` {\<infinity>} \<inter> space M" (is "?l = ?r")
hoelzl@41981
  1260
  proof (intro set_eqI)
hoelzl@41981
  1261
    fix x show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" by (cases rule: extreal2_cases[of "f x" "g x"]) auto
hoelzl@41981
  1262
  qed
hoelzl@41981
  1263
  with f g show ?thesis by (auto intro!: Un simp: measurable_sets)
hoelzl@41981
  1264
qed
hoelzl@41981
  1265
hoelzl@41981
  1266
lemma (in sigma_algebra) borel_measurable_extreal_less[intro,simp]:
hoelzl@41981
  1267
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@38656
  1268
  assumes f: "f \<in> borel_measurable M"
hoelzl@38656
  1269
  assumes g: "g \<in> borel_measurable M"
hoelzl@38656
  1270
  shows "{x \<in> space M. f x < g x} \<in> sets M"
hoelzl@38656
  1271
proof -
hoelzl@41981
  1272
  have "{x \<in> space M. f x < g x} = space M - {x \<in> space M. g x \<le> f x}" by auto
hoelzl@38656
  1273
  then show ?thesis using g f by auto
hoelzl@38656
  1274
qed
hoelzl@38656
  1275
hoelzl@41981
  1276
lemma (in sigma_algebra) borel_measurable_extreal_eq[intro,simp]:
hoelzl@41981
  1277
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@38656
  1278
  assumes f: "f \<in> borel_measurable M"
hoelzl@38656
  1279
  assumes g: "g \<in> borel_measurable M"
hoelzl@38656
  1280
  shows "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@38656
  1281
proof -
hoelzl@38656
  1282
  have "{x \<in> space M. f x = g x} = {x \<in> space M. g x \<le> f x} \<inter> {x \<in> space M. f x \<le> g x}" by auto
hoelzl@38656
  1283
  then show ?thesis using g f by auto
hoelzl@38656
  1284
qed
hoelzl@38656
  1285
hoelzl@41981
  1286
lemma (in sigma_algebra) borel_measurable_extreal_neq[intro,simp]:
hoelzl@41981
  1287
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@38656
  1288
  assumes f: "f \<in> borel_measurable M"
hoelzl@38656
  1289
  assumes g: "g \<in> borel_measurable M"
hoelzl@38656
  1290
  shows "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
hoelzl@35692
  1291
proof -
hoelzl@38656
  1292
  have "{w \<in> space M. f w \<noteq> g w} = space M - {w \<in> space M. f w = g w}" by auto
hoelzl@38656
  1293
  thus ?thesis using f g by auto
hoelzl@38656
  1294
qed
hoelzl@38656
  1295
hoelzl@41981
  1296
lemma (in sigma_algebra) split_sets:
hoelzl@41981
  1297
  "{x\<in>space M. P x \<or> Q x} = {x\<in>space M. P x} \<union> {x\<in>space M. Q x}"
hoelzl@41981
  1298
  "{x\<in>space M. P x \<and> Q x} = {x\<in>space M. P x} \<inter> {x\<in>space M. Q x}"
hoelzl@41981
  1299
  by auto
hoelzl@41981
  1300
hoelzl@41981
  1301
lemma (in sigma_algebra) borel_measurable_extreal_add[intro, simp]:
hoelzl@41981
  1302
  fixes f :: "'a \<Rightarrow> extreal"
hoelzl@41025
  1303
  assumes "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@38656
  1304
  shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@38656
  1305
proof -
hoelzl@41981
  1306
  { fix x assume "x \<in> space M" then have "f x + g x =
hoelzl@41981
  1307
      (if f x = \<infinity> \<or> g x = \<infinity> then \<infinity>
hoelzl@41981
  1308
        else if f x = -\<infinity> \<or> g x = -\<infinity> then -\<infinity>
hoelzl@41981
  1309
        else extreal (real (f x) + real (g x)))"
hoelzl@41981
  1310
      by (cases rule: extreal2_cases[of "f x" "g x"]) auto }
hoelzl@41981
  1311
  with assms show ?thesis
hoelzl@41981
  1312
    by (auto cong: measurable_cong simp: split_sets
hoelzl@41981
  1313
             intro!: Un measurable_If measurable_sets)
hoelzl@38656
  1314
qed
hoelzl@38656
  1315
hoelzl@41981
  1316
lemma (in sigma_algebra) borel_measurable_extreal_setsum[simp, intro]:
hoelzl@41981
  1317
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@41096
  1318
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1319
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41096
  1320
proof cases
hoelzl@41096
  1321
  assume "finite S"
hoelzl@41096
  1322
  thus ?thesis using assms
hoelzl@41096
  1323
    by induct auto
hoelzl@41096
  1324
qed (simp add: borel_measurable_const)
hoelzl@41096
  1325
hoelzl@41981
  1326
lemma abs_extreal_ge0[simp]: "0 \<le> x \<Longrightarrow> \<bar>x :: extreal\<bar> = x"
hoelzl@41981
  1327
  by (cases x) auto
hoelzl@41981
  1328
hoelzl@41981
  1329
lemma abs_extreal_less0[simp]: "x < 0 \<Longrightarrow> \<bar>x :: extreal\<bar> = -x"
hoelzl@41981
  1330
  by (cases x) auto
hoelzl@41981
  1331
hoelzl@41981
  1332
lemma abs_extreal_pos[simp]: "0 \<le> \<bar>x :: extreal\<bar>"
hoelzl@41981
  1333
  by (cases x) auto
hoelzl@41981
  1334
hoelzl@41981
  1335
lemma (in sigma_algebra) borel_measurable_extreal_abs[intro, simp]:
hoelzl@41981
  1336
  fixes f :: "'a \<Rightarrow> extreal" assumes "f \<in> borel_measurable M"
hoelzl@41981
  1337
  shows "(\<lambda>x. \<bar>f x\<bar>) \<in> borel_measurable M"
hoelzl@41981
  1338
proof -
hoelzl@41981
  1339
  { fix x have "\<bar>f x\<bar> = (if 0 \<le> f x then f x else - f x)" by auto }
hoelzl@41981
  1340
  then show ?thesis using assms by (auto intro!: measurable_If)
hoelzl@41981
  1341
qed
hoelzl@41981
  1342
hoelzl@41981
  1343
lemma (in sigma_algebra) borel_measurable_extreal_times[intro, simp]:
hoelzl@41981
  1344
  fixes f :: "'a \<Rightarrow> extreal" assumes "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@38656
  1345
  shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@38656
  1346
proof -
hoelzl@41981
  1347
  { fix f g :: "'a \<Rightarrow> extreal"
hoelzl@41981
  1348
    assume b: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@41981
  1349
      and pos: "\<And>x. 0 \<le> f x" "\<And>x. 0 \<le> g x"
hoelzl@41981
  1350
    { fix x have *: "f x * g x = (if f x = 0 \<or> g x = 0 then 0
hoelzl@41981
  1351
        else if f x = \<infinity> \<or> g x = \<infinity> then \<infinity>
hoelzl@41981
  1352
        else extreal (real (f x) * real (g x)))"
hoelzl@41981
  1353
      apply (cases rule: extreal2_cases[of "f x" "g x"])
hoelzl@41981
  1354
      using pos[of x] by auto }
hoelzl@41981
  1355
    with b have "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@41981
  1356
      by (auto cong: measurable_cong simp: split_sets
hoelzl@41981
  1357
               intro!: Un measurable_If measurable_sets) }
hoelzl@41981
  1358
  note pos_times = this
hoelzl@38656
  1359
  have *: "(\<lambda>x. f x * g x) =
hoelzl@41981
  1360
    (\<lambda>x. if 0 \<le> f x \<and> 0 \<le> g x \<or> f x < 0 \<and> g x < 0 then \<bar>f x\<bar> * \<bar>g x\<bar> else - (\<bar>f x\<bar> * \<bar>g x\<bar>))"
hoelzl@41981
  1361
    by (auto simp: fun_eq_iff)
hoelzl@38656
  1362
  show ?thesis using assms unfolding *
hoelzl@41981
  1363
    by (intro measurable_If pos_times borel_measurable_uminus_extreal)
hoelzl@41981
  1364
       (auto simp: split_sets intro!: Int)
hoelzl@38656
  1365
qed
hoelzl@38656
  1366
hoelzl@41981
  1367
lemma (in sigma_algebra) borel_measurable_extreal_setprod[simp, intro]:
hoelzl@41981
  1368
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@38656
  1369
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1370
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@38656
  1371
proof cases
hoelzl@38656
  1372
  assume "finite S"
hoelzl@41096
  1373
  thus ?thesis using assms by induct auto
hoelzl@41096
  1374
qed simp
hoelzl@38656
  1375
hoelzl@41981
  1376
lemma (in sigma_algebra) borel_measurable_extreal_min[simp, intro]:
hoelzl@41981
  1377
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@38656
  1378
  assumes "f \<in> borel_measurable M"
hoelzl@38656
  1379
  assumes "g \<in> borel_measurable M"
hoelzl@38656
  1380
  shows "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
hoelzl@38656
  1381
  using assms unfolding min_def by (auto intro!: measurable_If)
hoelzl@38656
  1382
hoelzl@41981
  1383
lemma (in sigma_algebra) borel_measurable_extreal_max[simp, intro]:
hoelzl@41981
  1384
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@38656
  1385
  assumes "f \<in> borel_measurable M"
hoelzl@38656
  1386
  and "g \<in> borel_measurable M"
hoelzl@38656
  1387
  shows "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
hoelzl@38656
  1388
  using assms unfolding max_def by (auto intro!: measurable_If)
hoelzl@38656
  1389
hoelzl@38656
  1390
lemma (in sigma_algebra) borel_measurable_SUP[simp, intro]:
hoelzl@41981
  1391
  fixes f :: "'d\<Colon>countable \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@38656
  1392
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1393
  shows "(\<lambda>x. SUP i : A. f i x) \<in> borel_measurable M" (is "?sup \<in> borel_measurable M")
hoelzl@41981
  1394
  unfolding borel_measurable_extreal_iff_ge
hoelzl@41981
  1395
proof
hoelzl@38656
  1396
  fix a
hoelzl@41981
  1397
  have "?sup -` {a<..} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. a < f i x})"
haftmann@41083
  1398
    by (auto simp: less_SUP_iff SUPR_apply)
hoelzl@41981
  1399
  then show "?sup -` {a<..} \<inter> space M \<in> sets M"
hoelzl@38656
  1400
    using assms by auto
hoelzl@38656
  1401
qed
hoelzl@38656
  1402
hoelzl@38656
  1403
lemma (in sigma_algebra) borel_measurable_INF[simp, intro]:
hoelzl@41981
  1404
  fixes f :: "'d :: countable \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@38656
  1405
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1406
  shows "(\<lambda>x. INF i : A. f i x) \<in> borel_measurable M" (is "?inf \<in> borel_measurable M")
hoelzl@41981
  1407
  unfolding borel_measurable_extreal_iff_less
hoelzl@41981
  1408
proof
hoelzl@38656
  1409
  fix a
hoelzl@41981
  1410
  have "?inf -` {..<a} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. f i x < a})"
haftmann@41083
  1411
    by (auto simp: INF_less_iff INFI_apply)
hoelzl@41981
  1412
  then show "?inf -` {..<a} \<inter> space M \<in> sets M"
hoelzl@38656
  1413
    using assms by auto
hoelzl@38656
  1414
qed
hoelzl@38656
  1415
hoelzl@41981
  1416
lemma (in sigma_algebra) borel_measurable_liminf[simp, intro]:
hoelzl@41981
  1417
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@41981
  1418
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@41981
  1419
  shows "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@41981
  1420
  unfolding liminf_SUPR_INFI using assms by auto
hoelzl@41981
  1421
hoelzl@41981
  1422
lemma (in sigma_algebra) borel_measurable_limsup[simp, intro]:
hoelzl@41981
  1423
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@41981
  1424
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@41981
  1425
  shows "(\<lambda>x. limsup (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@41981
  1426
  unfolding limsup_INFI_SUPR using assms by auto
hoelzl@41981
  1427
hoelzl@41981
  1428
lemma (in sigma_algebra) borel_measurable_extreal_diff[simp, intro]:
hoelzl@41981
  1429
  fixes f g :: "'a \<Rightarrow> extreal"
hoelzl@38656
  1430
  assumes "f \<in> borel_measurable M"
hoelzl@38656
  1431
  assumes "g \<in> borel_measurable M"
hoelzl@38656
  1432
  shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@41981
  1433
  unfolding minus_extreal_def using assms by auto
hoelzl@35692
  1434
hoelzl@40870
  1435
lemma (in sigma_algebra) borel_measurable_psuminf[simp, intro]:
hoelzl@41981
  1436
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> extreal"
hoelzl@41981
  1437
  assumes "\<And>i. f i \<in> borel_measurable M" and pos: "\<And>i x. x \<in> space M \<Longrightarrow> 0 \<le> f i x"
hoelzl@41981
  1438
  shows "(\<lambda>x. (\<Sum>i. f i x)) \<in> borel_measurable M"
hoelzl@41981
  1439
  apply (subst measurable_cong)
hoelzl@41981
  1440
  apply (subst suminf_extreal_eq_SUPR)
hoelzl@41981
  1441
  apply (rule pos)
hoelzl@41981
  1442
  using assms by auto
hoelzl@39092
  1443
hoelzl@39092
  1444
section "LIMSEQ is borel measurable"
hoelzl@39092
  1445
hoelzl@39092
  1446
lemma (in sigma_algebra) borel_measurable_LIMSEQ:
hoelzl@39092
  1447
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@39092
  1448
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
hoelzl@39092
  1449
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@39092
  1450
  shows "u' \<in> borel_measurable M"
hoelzl@39092
  1451
proof -
hoelzl@41981
  1452
  have "\<And>x. x \<in> space M \<Longrightarrow> liminf (\<lambda>n. extreal (u n x)) = extreal (u' x)"
hoelzl@41981
  1453
    using u' by (simp add: lim_imp_Liminf trivial_limit_sequentially lim_extreal)
hoelzl@41981
  1454
  moreover from u have "(\<lambda>x. liminf (\<lambda>n. extreal (u n x))) \<in> borel_measurable M"
hoelzl@39092
  1455
    by auto
hoelzl@41981
  1456
  ultimately show ?thesis by (simp cong: measurable_cong add: borel_measurable_extreal_iff)
hoelzl@39092
  1457
qed
hoelzl@39092
  1458
paulson@33533
  1459
end