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