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