src/HOL/Probability/Borel_Space.thy
author immler
Tue Nov 27 11:29:47 2012 +0100 (2012-11-27)
changeset 50244 de72bbe42190
parent 50104 de19856feb54
child 50245 dea9363887a6
permissions -rw-r--r--
qualified interpretation of sigma_algebra, to avoid name clashes
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)"
immler@50244
    56
  unfolding insert_def by (rule sets.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"
immler@50244
   183
  using sets.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 *
immler@50244
   279
    by (safe intro!: sets.countable_UN sets.Int sets.countable_INT)
immler@50244
   280
      (auto intro!: halfspace_gt_in_halfspace)
hoelzl@47694
   281
qed auto
hoelzl@38656
   282
hoelzl@47694
   283
lemma borel_eq_halfspace_le:
hoelzl@47694
   284
  "borel = sigma UNIV (range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. x $$ i \<le> a}))"
hoelzl@47694
   285
  (is "_ = ?SIGMA")
hoelzl@47694
   286
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@47694
   287
  fix a i
hoelzl@47694
   288
  have *: "{x::'a. x$$i < a} = (\<Union>n. {x. x$$i \<le> a - 1/real (Suc n)})"
hoelzl@47694
   289
  proof (safe, simp_all)
hoelzl@47694
   290
    fix x::'a assume *: "x$$i < a"
hoelzl@47694
   291
    with reals_Archimedean[of "a - x$$i"]
hoelzl@47694
   292
    obtain n where "x $$ i < a - 1 / (real (Suc n))"
hoelzl@47694
   293
      by (auto simp: field_simps inverse_eq_divide)
hoelzl@47694
   294
    then show "\<exists>n. x $$ i \<le> a - 1 / (real (Suc n))"
hoelzl@47694
   295
      by (blast intro: less_imp_le)
hoelzl@47694
   296
  next
hoelzl@47694
   297
    fix x::'a and n
hoelzl@47694
   298
    assume "x$$i \<le> a - 1 / real (Suc n)"
hoelzl@47694
   299
    also have "\<dots> < a" by auto
hoelzl@47694
   300
    finally show "x$$i < a" .
hoelzl@47694
   301
  qed
hoelzl@47694
   302
  show "{x. x$$i < a} \<in> ?SIGMA" unfolding *
immler@50244
   303
    by (safe intro!: sets.countable_UN) auto
hoelzl@47694
   304
qed auto
hoelzl@38656
   305
hoelzl@47694
   306
lemma borel_eq_halfspace_ge:
hoelzl@47694
   307
  "borel = sigma UNIV (range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. a \<le> x $$ i}))"
hoelzl@47694
   308
  (is "_ = ?SIGMA")
hoelzl@47694
   309
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@47694
   310
  fix a i have *: "{x::'a. x$$i < a} = space ?SIGMA - {x::'a. a \<le> x$$i}" by auto
hoelzl@47694
   311
  show "{x. x$$i < a} \<in> ?SIGMA" unfolding *
immler@50244
   312
      by (safe intro!: sets.compl_sets) auto
hoelzl@47694
   313
qed auto
hoelzl@38656
   314
hoelzl@47694
   315
lemma borel_eq_halfspace_greater:
hoelzl@47694
   316
  "borel = sigma UNIV (range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. a < x $$ i}))"
hoelzl@47694
   317
  (is "_ = ?SIGMA")
hoelzl@47694
   318
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
hoelzl@47694
   319
  fix a i have *: "{x::'a. x$$i \<le> a} = space ?SIGMA - {x::'a. a < x$$i}" by auto
hoelzl@47694
   320
  show "{x. x$$i \<le> a} \<in> ?SIGMA" unfolding *
immler@50244
   321
    by (safe intro!: sets.compl_sets) auto
hoelzl@47694
   322
qed auto
hoelzl@47694
   323
hoelzl@47694
   324
lemma borel_eq_atMost:
hoelzl@47694
   325
  "borel = sigma UNIV (range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space}))"
hoelzl@47694
   326
  (is "_ = ?SIGMA")
hoelzl@47694
   327
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@47694
   328
  fix a i show "{x. x$$i \<le> a} \<in> ?SIGMA"
hoelzl@38656
   329
  proof cases
hoelzl@47694
   330
    assume "i < DIM('a)"
hoelzl@38656
   331
    then have *: "{x::'a. x$$i \<le> a} = (\<Union>k::nat. {.. (\<chi>\<chi> n. if n = i then a else real k)})"
hoelzl@38656
   332
    proof (safe, simp_all add: eucl_le[where 'a='a] split: split_if_asm)
hoelzl@38656
   333
      fix x
hoelzl@38656
   334
      from real_arch_simple[of "Max ((\<lambda>i. x$$i)`{..<DIM('a)})"] guess k::nat ..
hoelzl@38656
   335
      then have "\<And>i. i < DIM('a) \<Longrightarrow> x$$i \<le> real k"
hoelzl@38656
   336
        by (subst (asm) Max_le_iff) auto
hoelzl@38656
   337
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> x $$ ia \<le> real k"
hoelzl@38656
   338
        by (auto intro!: exI[of _ k])
hoelzl@38656
   339
    qed
hoelzl@47694
   340
    show "{x. x$$i \<le> a} \<in> ?SIGMA" unfolding *
immler@50244
   341
      by (safe intro!: sets.countable_UN) auto
hoelzl@47694
   342
  qed (auto intro: sigma_sets_top sigma_sets.Empty)
hoelzl@47694
   343
qed auto
hoelzl@38656
   344
hoelzl@47694
   345
lemma borel_eq_greaterThan:
hoelzl@47694
   346
  "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {a<..}))"
hoelzl@47694
   347
  (is "_ = ?SIGMA")
hoelzl@47694
   348
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@47694
   349
  fix a i show "{x. x$$i \<le> a} \<in> ?SIGMA"
hoelzl@38656
   350
  proof cases
hoelzl@47694
   351
    assume "i < DIM('a)"
hoelzl@47694
   352
    have "{x::'a. x$$i \<le> a} = UNIV - {x::'a. a < x$$i}" by auto
hoelzl@38656
   353
    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
   354
    proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@38656
   355
      fix x
huffman@44666
   356
      from reals_Archimedean2[of "Max ((\<lambda>i. -x$$i)`{..<DIM('a)})"]
hoelzl@38656
   357
      guess k::nat .. note k = this
hoelzl@38656
   358
      { fix i assume "i < DIM('a)"
hoelzl@38656
   359
        then have "-x$$i < real k"
hoelzl@38656
   360
          using k by (subst (asm) Max_less_iff) auto
hoelzl@38656
   361
        then have "- real k < x$$i" by simp }
hoelzl@38656
   362
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> -real k < x $$ ia"
hoelzl@38656
   363
        by (auto intro!: exI[of _ k])
hoelzl@38656
   364
    qed
hoelzl@47694
   365
    finally show "{x. x$$i \<le> a} \<in> ?SIGMA"
hoelzl@38656
   366
      apply (simp only:)
immler@50244
   367
      apply (safe intro!: sets.countable_UN sets.Diff)
hoelzl@47694
   368
      apply (auto intro: sigma_sets_top)
wenzelm@46731
   369
      done
hoelzl@47694
   370
  qed (auto intro: sigma_sets_top sigma_sets.Empty)
hoelzl@47694
   371
qed auto
hoelzl@40859
   372
hoelzl@47694
   373
lemma borel_eq_lessThan:
hoelzl@47694
   374
  "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {..<a}))"
hoelzl@47694
   375
  (is "_ = ?SIGMA")
hoelzl@47694
   376
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_ge])
hoelzl@47694
   377
  fix a i show "{x. a \<le> x$$i} \<in> ?SIGMA"
hoelzl@40859
   378
  proof cases
hoelzl@40859
   379
    fix a i assume "i < DIM('a)"
hoelzl@47694
   380
    have "{x::'a. a \<le> x$$i} = UNIV - {x::'a. x$$i < a}" by auto
hoelzl@40859
   381
    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
   382
    proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@40859
   383
      fix x
huffman@44666
   384
      from reals_Archimedean2[of "Max ((\<lambda>i. x$$i)`{..<DIM('a)})"]
hoelzl@40859
   385
      guess k::nat .. note k = this
hoelzl@40859
   386
      { fix i assume "i < DIM('a)"
hoelzl@40859
   387
        then have "x$$i < real k"
hoelzl@40859
   388
          using k by (subst (asm) Max_less_iff) auto
hoelzl@40859
   389
        then have "x$$i < real k" by simp }
hoelzl@40859
   390
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> x $$ ia < real k"
hoelzl@40859
   391
        by (auto intro!: exI[of _ k])
hoelzl@40859
   392
    qed
hoelzl@47694
   393
    finally show "{x. a \<le> x$$i} \<in> ?SIGMA"
hoelzl@40859
   394
      apply (simp only:)
immler@50244
   395
      apply (safe intro!: sets.countable_UN sets.Diff)
hoelzl@47694
   396
      apply (auto intro: sigma_sets_top)
wenzelm@46731
   397
      done
hoelzl@47694
   398
  qed (auto intro: sigma_sets_top sigma_sets.Empty)
hoelzl@40859
   399
qed auto
hoelzl@40859
   400
hoelzl@40859
   401
lemma borel_eq_atLeastAtMost:
hoelzl@47694
   402
  "borel = sigma UNIV (range (\<lambda>(a,b). {a..b} \<Colon>'a\<Colon>ordered_euclidean_space set))"
hoelzl@47694
   403
  (is "_ = ?SIGMA")
hoelzl@47694
   404
proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
hoelzl@47694
   405
  fix a::'a
hoelzl@47694
   406
  have *: "{..a} = (\<Union>n::nat. {- real n *\<^sub>R One .. a})"
hoelzl@47694
   407
  proof (safe, simp_all add: eucl_le[where 'a='a])
hoelzl@47694
   408
    fix x
hoelzl@47694
   409
    from real_arch_simple[of "Max ((\<lambda>i. - x$$i)`{..<DIM('a)})"]
hoelzl@47694
   410
    guess k::nat .. note k = this
hoelzl@47694
   411
    { fix i assume "i < DIM('a)"
hoelzl@47694
   412
      with k have "- x$$i \<le> real k"
hoelzl@47694
   413
        by (subst (asm) Max_le_iff) (auto simp: field_simps)
hoelzl@47694
   414
      then have "- real k \<le> x$$i" by simp }
hoelzl@47694
   415
    then show "\<exists>n::nat. \<forall>i<DIM('a). - real n \<le> x $$ i"
hoelzl@47694
   416
      by (auto intro!: exI[of _ k])
hoelzl@47694
   417
  qed
hoelzl@47694
   418
  show "{..a} \<in> ?SIGMA" unfolding *
immler@50244
   419
    by (safe intro!: sets.countable_UN)
hoelzl@47694
   420
       (auto intro!: sigma_sets_top)
hoelzl@40859
   421
qed auto
hoelzl@40859
   422
hoelzl@40859
   423
lemma borel_eq_greaterThanLessThan:
hoelzl@47694
   424
  "borel = sigma UNIV (range (\<lambda> (a, b). {a <..< b} :: 'a \<Colon> ordered_euclidean_space set))"
hoelzl@40859
   425
    (is "_ = ?SIGMA")
hoelzl@47694
   426
proof (rule borel_eq_sigmaI1[OF borel_def])
hoelzl@47694
   427
  fix M :: "'a set" assume "M \<in> {S. open S}"
hoelzl@47694
   428
  then have "open M" by simp
hoelzl@47694
   429
  show "M \<in> ?SIGMA"
hoelzl@47694
   430
    apply (subst open_UNION[OF `open M`])
immler@50244
   431
    apply (safe intro!: sets.countable_UN)
hoelzl@47694
   432
    apply auto
hoelzl@47694
   433
    done
hoelzl@38656
   434
qed auto
hoelzl@38656
   435
hoelzl@42862
   436
lemma borel_eq_atLeastLessThan:
hoelzl@47694
   437
  "borel = sigma UNIV (range (\<lambda>(a, b). {a ..< b :: real}))" (is "_ = ?SIGMA")
hoelzl@47694
   438
proof (rule borel_eq_sigmaI5[OF borel_eq_lessThan])
hoelzl@47694
   439
  have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
hoelzl@47694
   440
  fix x :: real
hoelzl@47694
   441
  have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
hoelzl@47694
   442
    by (auto simp: move_uminus real_arch_simple)
hoelzl@47694
   443
  then show "{..< x} \<in> ?SIGMA"
hoelzl@47694
   444
    by (auto intro: sigma_sets.intros)
hoelzl@40859
   445
qed auto
hoelzl@40859
   446
immler@50087
   447
lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
immler@50087
   448
  unfolding borel_def
immler@50087
   449
proof (intro sigma_eqI sigma_sets_eqI, safe)
immler@50087
   450
  fix x :: "'a set" assume "open x"
immler@50087
   451
  hence "x = UNIV - (UNIV - x)" by auto
immler@50087
   452
  also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
immler@50087
   453
    by (rule sigma_sets.Compl)
immler@50087
   454
       (auto intro!: sigma_sets.Basic simp: `open x`)
immler@50087
   455
  finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
immler@50087
   456
next
immler@50087
   457
  fix x :: "'a set" assume "closed x"
immler@50087
   458
  hence "x = UNIV - (UNIV - x)" by auto
immler@50087
   459
  also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
immler@50087
   460
    by (rule sigma_sets.Compl)
immler@50087
   461
       (auto intro!: sigma_sets.Basic simp: `closed x`)
immler@50087
   462
  finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
immler@50087
   463
qed simp_all
immler@50087
   464
immler@50094
   465
lemma borel_eq_enumerated_basis:
immler@50094
   466
  fixes f::"nat\<Rightarrow>'a::topological_space set"
immler@50094
   467
  assumes "topological_basis (range f)"
immler@50094
   468
  shows "borel = sigma UNIV (range f)"
immler@50087
   469
  unfolding borel_def
immler@50087
   470
proof (intro sigma_eqI sigma_sets_eqI, safe)
immler@50094
   471
  interpret enumerates_basis proof qed (rule assms)
immler@50087
   472
  fix x::"'a set" assume "open x"
immler@50087
   473
  from open_enumerable_basisE[OF this] guess N .
immler@50094
   474
  hence x: "x = (\<Union>n. if n \<in> N then f n else {})" by (auto split: split_if_asm)
immler@50094
   475
  also have "\<dots> \<in> sigma_sets UNIV (range f)" by (auto intro!: sigma_sets.Empty Union)
immler@50094
   476
  finally show "x \<in> sigma_sets UNIV (range f)" .
immler@50087
   477
next
immler@50087
   478
  fix n
immler@50094
   479
  have "open (f n)" by (rule topological_basis_open[OF assms]) simp
immler@50094
   480
  thus "f n \<in> sigma_sets UNIV (Collect open)" by auto
immler@50087
   481
qed simp_all
immler@50087
   482
immler@50094
   483
lemma borel_eq_enum_basis:
immler@50094
   484
  "borel = sigma UNIV (range enum_basis)"
immler@50094
   485
  by (rule borel_eq_enumerated_basis[OF enum_basis_basis])
immler@50094
   486
hoelzl@47694
   487
lemma borel_measurable_halfspacesI:
hoelzl@38656
   488
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@47694
   489
  assumes F: "borel = sigma UNIV (range F)"
hoelzl@47694
   490
  and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M" 
hoelzl@47694
   491
  and S: "\<And>a i. \<not> i < DIM('c) \<Longrightarrow> S a i \<in> sets M"
hoelzl@38656
   492
  shows "f \<in> borel_measurable M = (\<forall>i<DIM('c). \<forall>a::real. S a i \<in> sets M)"
hoelzl@38656
   493
proof safe
hoelzl@38656
   494
  fix a :: real and i assume i: "i < DIM('c)" and f: "f \<in> borel_measurable M"
hoelzl@38656
   495
  then show "S a i \<in> sets M" unfolding assms
hoelzl@47694
   496
    by (auto intro!: measurable_sets sigma_sets.Basic simp: assms(1))
hoelzl@38656
   497
next
hoelzl@38656
   498
  assume a: "\<forall>i<DIM('c). \<forall>a. S a i \<in> sets M"
hoelzl@38656
   499
  { fix a i have "S a i \<in> sets M"
hoelzl@38656
   500
    proof cases
hoelzl@38656
   501
      assume "i < DIM('c)"
hoelzl@38656
   502
      with a show ?thesis unfolding assms(2) by simp
hoelzl@38656
   503
    next
hoelzl@38656
   504
      assume "\<not> i < DIM('c)"
hoelzl@47694
   505
      from S[OF this] show ?thesis .
hoelzl@38656
   506
    qed }
hoelzl@47694
   507
  then show "f \<in> borel_measurable M"
hoelzl@47694
   508
    by (auto intro!: measurable_measure_of simp: S_eq F)
hoelzl@38656
   509
qed
hoelzl@38656
   510
hoelzl@47694
   511
lemma borel_measurable_iff_halfspace_le:
hoelzl@38656
   512
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   513
  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
   514
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_le]) auto
hoelzl@38656
   515
hoelzl@47694
   516
lemma borel_measurable_iff_halfspace_less:
hoelzl@38656
   517
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   518
  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
   519
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_less]) auto
hoelzl@38656
   520
hoelzl@47694
   521
lemma borel_measurable_iff_halfspace_ge:
hoelzl@38656
   522
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   523
  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
   524
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_ge]) auto
hoelzl@38656
   525
hoelzl@47694
   526
lemma borel_measurable_iff_halfspace_greater:
hoelzl@38656
   527
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   528
  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
   529
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_greater]) auto
hoelzl@38656
   530
hoelzl@47694
   531
lemma borel_measurable_iff_le:
hoelzl@38656
   532
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w \<le> a} \<in> sets M)"
hoelzl@38656
   533
  using borel_measurable_iff_halfspace_le[where 'c=real] by simp
hoelzl@38656
   534
hoelzl@47694
   535
lemma borel_measurable_iff_less:
hoelzl@38656
   536
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w < a} \<in> sets M)"
hoelzl@38656
   537
  using borel_measurable_iff_halfspace_less[where 'c=real] by simp
hoelzl@38656
   538
hoelzl@47694
   539
lemma borel_measurable_iff_ge:
hoelzl@38656
   540
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a \<le> f w} \<in> sets M)"
hoelzl@50002
   541
  using borel_measurable_iff_halfspace_ge[where 'c=real]
hoelzl@50002
   542
  by simp
hoelzl@38656
   543
hoelzl@47694
   544
lemma borel_measurable_iff_greater:
hoelzl@38656
   545
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a < f w} \<in> sets M)"
hoelzl@38656
   546
  using borel_measurable_iff_halfspace_greater[where 'c=real] by simp
hoelzl@38656
   547
hoelzl@47694
   548
lemma borel_measurable_euclidean_space:
hoelzl@39087
   549
  fixes f :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@39087
   550
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i<DIM('c). (\<lambda>x. f x $$ i) \<in> borel_measurable M)"
hoelzl@39087
   551
proof safe
hoelzl@39087
   552
  fix i assume "f \<in> borel_measurable M"
hoelzl@39087
   553
  then show "(\<lambda>x. f x $$ i) \<in> borel_measurable M"
hoelzl@41025
   554
    by (auto intro: borel_measurable_euclidean_component)
hoelzl@39087
   555
next
hoelzl@39087
   556
  assume f: "\<forall>i<DIM('c). (\<lambda>x. f x $$ i) \<in> borel_measurable M"
hoelzl@39087
   557
  then show "f \<in> borel_measurable M"
hoelzl@39087
   558
    unfolding borel_measurable_iff_halfspace_le by auto
hoelzl@39087
   559
qed
hoelzl@39087
   560
hoelzl@38656
   561
subsection "Borel measurable operators"
hoelzl@38656
   562
hoelzl@49774
   563
lemma borel_measurable_continuous_on:
hoelzl@49774
   564
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@49774
   565
  assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
hoelzl@49774
   566
  shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
hoelzl@49774
   567
  using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
hoelzl@49774
   568
hoelzl@49774
   569
lemma borel_measurable_continuous_on_open':
hoelzl@49774
   570
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@49774
   571
  assumes cont: "continuous_on A f" "open A"
hoelzl@49774
   572
  shows "(\<lambda>x. if x \<in> A then f x else c) \<in> borel_measurable borel" (is "?f \<in> _")
hoelzl@49774
   573
proof (rule borel_measurableI)
hoelzl@49774
   574
  fix S :: "'b set" assume "open S"
hoelzl@49774
   575
  then have "open {x\<in>A. f x \<in> S}"
hoelzl@49774
   576
    by (intro continuous_open_preimage[OF cont]) auto
hoelzl@49774
   577
  then have *: "{x\<in>A. f x \<in> S} \<in> sets borel" by auto
hoelzl@49774
   578
  have "?f -` S \<inter> space borel = 
hoelzl@49774
   579
    {x\<in>A. f x \<in> S} \<union> (if c \<in> S then space borel - A else {})"
hoelzl@49774
   580
    by (auto split: split_if_asm)
hoelzl@49774
   581
  also have "\<dots> \<in> sets borel"
hoelzl@50002
   582
    using * `open A` by auto
hoelzl@49774
   583
  finally show "?f -` S \<inter> space borel \<in> sets borel" .
hoelzl@49774
   584
qed
hoelzl@49774
   585
hoelzl@49774
   586
lemma borel_measurable_continuous_on_open:
hoelzl@49774
   587
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@49774
   588
  assumes cont: "continuous_on A f" "open A"
hoelzl@49774
   589
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   590
  shows "(\<lambda>x. if g x \<in> A then f (g x) else c) \<in> borel_measurable M"
hoelzl@49774
   591
  using measurable_comp[OF g borel_measurable_continuous_on_open'[OF cont], of c]
hoelzl@49774
   592
  by (simp add: comp_def)
hoelzl@49774
   593
hoelzl@50003
   594
lemma borel_measurable_uminus[measurable (raw)]:
hoelzl@49774
   595
  fixes g :: "'a \<Rightarrow> real"
hoelzl@49774
   596
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   597
  shows "(\<lambda>x. - g x) \<in> borel_measurable M"
hoelzl@49774
   598
  by (rule borel_measurable_continuous_on[OF _ g]) (auto intro: continuous_on_minus continuous_on_id)
hoelzl@49774
   599
hoelzl@49774
   600
lemma euclidean_component_prod:
hoelzl@49774
   601
  fixes x :: "'a :: euclidean_space \<times> 'b :: euclidean_space"
hoelzl@49774
   602
  shows "x $$ i = (if i < DIM('a) then fst x $$ i else snd x $$ (i - DIM('a)))"
hoelzl@49774
   603
  unfolding euclidean_component_def basis_prod_def inner_prod_def by auto
hoelzl@49774
   604
hoelzl@50003
   605
lemma borel_measurable_Pair[measurable (raw)]:
hoelzl@49774
   606
  fixes f :: "'a \<Rightarrow> 'b::ordered_euclidean_space" and g :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@49774
   607
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   608
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   609
  shows "(\<lambda>x. (f x, g x)) \<in> borel_measurable M"
hoelzl@49774
   610
proof (intro borel_measurable_iff_halfspace_le[THEN iffD2] allI impI)
hoelzl@49774
   611
  fix i and a :: real assume i: "i < DIM('b \<times> 'c)"
hoelzl@49774
   612
  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
   613
    {w. A w \<and> (P \<longrightarrow> B w) \<and> (\<not> P \<longrightarrow> C w)}" by auto
hoelzl@49774
   614
  from i f g show "{w \<in> space M. (f w, g w) $$ i \<le> a} \<in> sets M"
hoelzl@50002
   615
    by (auto simp: euclidean_component_prod)
hoelzl@49774
   616
qed
hoelzl@49774
   617
hoelzl@49774
   618
lemma continuous_on_fst: "continuous_on UNIV fst"
hoelzl@49774
   619
proof -
hoelzl@49774
   620
  have [simp]: "range fst = UNIV" by (auto simp: image_iff)
hoelzl@49774
   621
  show ?thesis
hoelzl@49774
   622
    using closed_vimage_fst
hoelzl@49774
   623
    by (auto simp: continuous_on_closed closed_closedin vimage_def)
hoelzl@49774
   624
qed
hoelzl@49774
   625
hoelzl@49774
   626
lemma continuous_on_snd: "continuous_on UNIV snd"
hoelzl@49774
   627
proof -
hoelzl@49774
   628
  have [simp]: "range snd = UNIV" by (auto simp: image_iff)
hoelzl@49774
   629
  show ?thesis
hoelzl@49774
   630
    using closed_vimage_snd
hoelzl@49774
   631
    by (auto simp: continuous_on_closed closed_closedin vimage_def)
hoelzl@49774
   632
qed
hoelzl@49774
   633
hoelzl@49774
   634
lemma borel_measurable_continuous_Pair:
hoelzl@49774
   635
  fixes f :: "'a \<Rightarrow> 'b::ordered_euclidean_space" and g :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@50003
   636
  assumes [measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   637
  assumes [measurable]: "g \<in> borel_measurable M"
hoelzl@49774
   638
  assumes H: "continuous_on UNIV (\<lambda>x. H (fst x) (snd x))"
hoelzl@49774
   639
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   640
proof -
hoelzl@49774
   641
  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
   642
  show ?thesis
hoelzl@49774
   643
    unfolding eq by (rule borel_measurable_continuous_on[OF H]) auto
hoelzl@49774
   644
qed
hoelzl@49774
   645
hoelzl@50003
   646
lemma borel_measurable_add[measurable (raw)]:
hoelzl@49774
   647
  fixes f g :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@49774
   648
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   649
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   650
  shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@49774
   651
  using f g
hoelzl@49774
   652
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   653
     (auto intro: continuous_on_fst continuous_on_snd continuous_on_add)
hoelzl@49774
   654
hoelzl@50003
   655
lemma borel_measurable_setsum[measurable (raw)]:
hoelzl@49774
   656
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@49774
   657
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@49774
   658
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@49774
   659
proof cases
hoelzl@49774
   660
  assume "finite S"
hoelzl@49774
   661
  thus ?thesis using assms by induct auto
hoelzl@49774
   662
qed simp
hoelzl@49774
   663
hoelzl@50003
   664
lemma borel_measurable_diff[measurable (raw)]:
hoelzl@49774
   665
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   666
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   667
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   668
  shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50003
   669
  unfolding diff_minus using assms by simp
hoelzl@49774
   670
hoelzl@50003
   671
lemma borel_measurable_times[measurable (raw)]:
hoelzl@49774
   672
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   673
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   674
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   675
  shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@49774
   676
  using f g
hoelzl@49774
   677
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   678
     (auto intro: continuous_on_fst continuous_on_snd continuous_on_mult)
hoelzl@49774
   679
hoelzl@49774
   680
lemma continuous_on_dist:
hoelzl@49774
   681
  fixes f :: "'a :: t2_space \<Rightarrow> 'b :: metric_space"
hoelzl@49774
   682
  shows "continuous_on A f \<Longrightarrow> continuous_on A g \<Longrightarrow> continuous_on A (\<lambda>x. dist (f x) (g x))"
hoelzl@49774
   683
  unfolding continuous_on_eq_continuous_within by (auto simp: continuous_dist)
hoelzl@49774
   684
hoelzl@50003
   685
lemma borel_measurable_dist[measurable (raw)]:
hoelzl@49774
   686
  fixes g f :: "'a \<Rightarrow> 'b::ordered_euclidean_space"
hoelzl@49774
   687
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   688
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   689
  shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   690
  using f g
hoelzl@49774
   691
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   692
     (intro continuous_on_dist continuous_on_fst continuous_on_snd)
hoelzl@49774
   693
  
hoelzl@50002
   694
lemma borel_measurable_scaleR[measurable (raw)]:
hoelzl@50002
   695
  fixes g :: "'a \<Rightarrow> 'b::ordered_euclidean_space"
hoelzl@50002
   696
  assumes f: "f \<in> borel_measurable M"
hoelzl@50002
   697
  assumes g: "g \<in> borel_measurable M"
hoelzl@50002
   698
  shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
hoelzl@50002
   699
  by (rule borel_measurable_continuous_Pair[OF f g])
hoelzl@50002
   700
     (auto intro!: continuous_on_scaleR continuous_on_fst continuous_on_snd)
hoelzl@50002
   701
hoelzl@47694
   702
lemma affine_borel_measurable_vector:
hoelzl@38656
   703
  fixes f :: "'a \<Rightarrow> 'x::real_normed_vector"
hoelzl@38656
   704
  assumes "f \<in> borel_measurable M"
hoelzl@38656
   705
  shows "(\<lambda>x. a + b *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@38656
   706
proof (rule borel_measurableI)
hoelzl@38656
   707
  fix S :: "'x set" assume "open S"
hoelzl@38656
   708
  show "(\<lambda>x. a + b *\<^sub>R f x) -` S \<inter> space M \<in> sets M"
hoelzl@38656
   709
  proof cases
hoelzl@38656
   710
    assume "b \<noteq> 0"
huffman@44537
   711
    with `open S` have "open ((\<lambda>x. (- a + x) /\<^sub>R b) ` S)" (is "open ?S")
huffman@44537
   712
      by (auto intro!: open_affinity simp: scaleR_add_right)
hoelzl@47694
   713
    hence "?S \<in> sets borel" by auto
hoelzl@38656
   714
    moreover
hoelzl@38656
   715
    from `b \<noteq> 0` have "(\<lambda>x. a + b *\<^sub>R f x) -` S = f -` ?S"
hoelzl@38656
   716
      apply auto by (rule_tac x="a + b *\<^sub>R f x" in image_eqI, simp_all)
hoelzl@40859
   717
    ultimately show ?thesis using assms unfolding in_borel_measurable_borel
hoelzl@38656
   718
      by auto
hoelzl@38656
   719
  qed simp
hoelzl@38656
   720
qed
hoelzl@38656
   721
hoelzl@50002
   722
lemma borel_measurable_const_scaleR[measurable (raw)]:
hoelzl@50002
   723
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. b *\<^sub>R f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
   724
  using affine_borel_measurable_vector[of f M 0 b] by simp
hoelzl@38656
   725
hoelzl@50002
   726
lemma borel_measurable_const_add[measurable (raw)]:
hoelzl@50002
   727
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. a + f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
   728
  using affine_borel_measurable_vector[of f M a 1] by simp
hoelzl@50002
   729
hoelzl@50003
   730
lemma borel_measurable_setprod[measurable (raw)]:
hoelzl@41026
   731
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41026
   732
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41026
   733
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41026
   734
proof cases
hoelzl@41026
   735
  assume "finite S"
hoelzl@41026
   736
  thus ?thesis using assms by induct auto
hoelzl@41026
   737
qed simp
hoelzl@41026
   738
hoelzl@50003
   739
lemma borel_measurable_inverse[measurable (raw)]:
hoelzl@38656
   740
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   741
  assumes f: "f \<in> borel_measurable M"
hoelzl@35692
   742
  shows "(\<lambda>x. inverse (f x)) \<in> borel_measurable M"
hoelzl@49774
   743
proof -
hoelzl@50003
   744
  have "(\<lambda>x::real. if x \<in> UNIV - {0} then inverse x else 0) \<in> borel_measurable borel"
hoelzl@50003
   745
    by (intro borel_measurable_continuous_on_open' continuous_on_inverse continuous_on_id) auto
hoelzl@50003
   746
  also have "(\<lambda>x::real. if x \<in> UNIV - {0} then inverse x else 0) = inverse" by (intro ext) auto
hoelzl@50003
   747
  finally show ?thesis using f by simp
hoelzl@35692
   748
qed
hoelzl@35692
   749
hoelzl@50003
   750
lemma borel_measurable_divide[measurable (raw)]:
hoelzl@50003
   751
  "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
   752
  by (simp add: field_divide_inverse)
hoelzl@38656
   753
hoelzl@50003
   754
lemma borel_measurable_max[measurable (raw)]:
hoelzl@50003
   755
  "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
   756
  by (simp add: max_def)
hoelzl@38656
   757
hoelzl@50003
   758
lemma borel_measurable_min[measurable (raw)]:
hoelzl@50003
   759
  "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
   760
  by (simp add: min_def)
hoelzl@38656
   761
hoelzl@50003
   762
lemma borel_measurable_abs[measurable (raw)]:
hoelzl@50003
   763
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. \<bar>f x :: real\<bar>) \<in> borel_measurable M"
hoelzl@50003
   764
  unfolding abs_real_def by simp
hoelzl@38656
   765
hoelzl@50003
   766
lemma borel_measurable_nth[measurable (raw)]:
hoelzl@41026
   767
  "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
hoelzl@50003
   768
  by (simp add: nth_conv_component)
hoelzl@41026
   769
hoelzl@47694
   770
lemma convex_measurable:
hoelzl@42990
   771
  fixes a b :: real
hoelzl@42990
   772
  assumes X: "X \<in> borel_measurable M" "X ` space M \<subseteq> { a <..< b}"
hoelzl@42990
   773
  assumes q: "convex_on { a <..< b} q"
hoelzl@49774
   774
  shows "(\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@42990
   775
proof -
hoelzl@49774
   776
  have "(\<lambda>x. if X x \<in> {a <..< b} then q (X x) else 0) \<in> borel_measurable M" (is "?qX")
hoelzl@49774
   777
  proof (rule borel_measurable_continuous_on_open[OF _ _ X(1)])
hoelzl@42990
   778
    show "open {a<..<b}" by auto
hoelzl@42990
   779
    from this q show "continuous_on {a<..<b} q"
hoelzl@42990
   780
      by (rule convex_on_continuous)
hoelzl@41830
   781
  qed
hoelzl@50002
   782
  also have "?qX \<longleftrightarrow> (\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@42990
   783
    using X by (intro measurable_cong) auto
hoelzl@50002
   784
  finally show ?thesis .
hoelzl@41830
   785
qed
hoelzl@41830
   786
hoelzl@50003
   787
lemma borel_measurable_ln[measurable (raw)]:
hoelzl@49774
   788
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   789
  shows "(\<lambda>x. ln (f x)) \<in> borel_measurable M"
hoelzl@41830
   790
proof -
hoelzl@41830
   791
  { fix x :: real assume x: "x \<le> 0"
hoelzl@41830
   792
    { fix x::real assume "x \<le> 0" then have "\<And>u. exp u = x \<longleftrightarrow> False" by auto }
hoelzl@49774
   793
    from this[of x] x this[of 0] have "ln 0 = ln x"
hoelzl@49774
   794
      by (auto simp: ln_def) }
hoelzl@49774
   795
  note ln_imp = this
hoelzl@49774
   796
  have "(\<lambda>x. if f x \<in> {0<..} then ln (f x) else ln 0) \<in> borel_measurable M"
hoelzl@49774
   797
  proof (rule borel_measurable_continuous_on_open[OF _ _ f])
hoelzl@49774
   798
    show "continuous_on {0<..} ln"
hoelzl@49774
   799
      by (auto intro!: continuous_at_imp_continuous_on DERIV_ln DERIV_isCont
hoelzl@41830
   800
               simp: continuous_isCont[symmetric])
hoelzl@41830
   801
    show "open ({0<..}::real set)" by auto
hoelzl@41830
   802
  qed
hoelzl@49774
   803
  also have "(\<lambda>x. if x \<in> {0<..} then ln x else ln 0) = ln"
hoelzl@49774
   804
    by (simp add: fun_eq_iff not_less ln_imp)
hoelzl@41830
   805
  finally show ?thesis .
hoelzl@41830
   806
qed
hoelzl@41830
   807
hoelzl@50003
   808
lemma borel_measurable_log[measurable (raw)]:
hoelzl@50002
   809
  "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
   810
  unfolding log_def by auto
hoelzl@41830
   811
hoelzl@50002
   812
lemma measurable_count_space_eq2_countable:
hoelzl@50002
   813
  fixes f :: "'a => 'c::countable"
hoelzl@50002
   814
  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
   815
proof -
hoelzl@50002
   816
  { fix X assume "X \<subseteq> A" "f \<in> space M \<rightarrow> A"
hoelzl@50002
   817
    then have "f -` X \<inter> space M = (\<Union>a\<in>X. f -` {a} \<inter> space M)"
hoelzl@50002
   818
      by auto
hoelzl@50002
   819
    moreover assume "\<And>a. a\<in>A \<Longrightarrow> f -` {a} \<inter> space M \<in> sets M"
hoelzl@50002
   820
    ultimately have "f -` X \<inter> space M \<in> sets M"
hoelzl@50002
   821
      using `X \<subseteq> A` by (simp add: subset_eq del: UN_simps) }
hoelzl@50002
   822
  then show ?thesis
hoelzl@50002
   823
    unfolding measurable_def by auto
hoelzl@47761
   824
qed
hoelzl@47761
   825
hoelzl@50002
   826
lemma measurable_real_floor[measurable]:
hoelzl@50002
   827
  "(floor :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@47761
   828
proof -
hoelzl@50002
   829
  have "\<And>a x. \<lfloor>x\<rfloor> = a \<longleftrightarrow> (real a \<le> x \<and> x < real (a + 1))"
hoelzl@50002
   830
    by (auto intro: floor_eq2)
hoelzl@50002
   831
  then show ?thesis
hoelzl@50002
   832
    by (auto simp: vimage_def measurable_count_space_eq2_countable)
hoelzl@47761
   833
qed
hoelzl@47761
   834
hoelzl@50002
   835
lemma measurable_real_natfloor[measurable]:
hoelzl@50002
   836
  "(natfloor :: real \<Rightarrow> nat) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
   837
  by (simp add: natfloor_def[abs_def])
hoelzl@50002
   838
hoelzl@50002
   839
lemma measurable_real_ceiling[measurable]:
hoelzl@50002
   840
  "(ceiling :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
   841
  unfolding ceiling_def[abs_def] by simp
hoelzl@50002
   842
hoelzl@50002
   843
lemma borel_measurable_real_floor: "(\<lambda>x::real. real \<lfloor>x\<rfloor>) \<in> borel_measurable borel"
hoelzl@50002
   844
  by simp
hoelzl@50002
   845
hoelzl@50003
   846
lemma borel_measurable_real_natfloor:
hoelzl@50002
   847
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. real (natfloor (f x))) \<in> borel_measurable M"
hoelzl@50002
   848
  by simp
hoelzl@50002
   849
hoelzl@41981
   850
subsection "Borel space on the extended reals"
hoelzl@41981
   851
hoelzl@50003
   852
lemma borel_measurable_ereal[measurable (raw)]:
hoelzl@43920
   853
  assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@49774
   854
  using continuous_on_ereal f by (rule borel_measurable_continuous_on)
hoelzl@41981
   855
hoelzl@50003
   856
lemma borel_measurable_real_of_ereal[measurable (raw)]:
hoelzl@49774
   857
  fixes f :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   858
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   859
  shows "(\<lambda>x. real (f x)) \<in> borel_measurable M"
hoelzl@49774
   860
proof -
hoelzl@49774
   861
  have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) \<in> borel_measurable M"
hoelzl@49774
   862
    using continuous_on_real
hoelzl@49774
   863
    by (rule borel_measurable_continuous_on_open[OF _ _ f]) auto
hoelzl@49774
   864
  also have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) = (\<lambda>x. real (f x))"
hoelzl@49774
   865
    by auto
hoelzl@49774
   866
  finally show ?thesis .
hoelzl@49774
   867
qed
hoelzl@49774
   868
hoelzl@49774
   869
lemma borel_measurable_ereal_cases:
hoelzl@49774
   870
  fixes f :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   871
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   872
  assumes H: "(\<lambda>x. H (ereal (real (f x)))) \<in> borel_measurable M"
hoelzl@49774
   873
  shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
hoelzl@49774
   874
proof -
hoelzl@50002
   875
  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
   876
  { fix x have "H (f x) = ?F x" by (cases "f x") auto }
hoelzl@50002
   877
  with f H show ?thesis by simp
hoelzl@47694
   878
qed
hoelzl@41981
   879
hoelzl@49774
   880
lemma
hoelzl@50003
   881
  fixes f :: "'a \<Rightarrow> ereal" assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   882
  shows borel_measurable_ereal_abs[measurable(raw)]: "(\<lambda>x. \<bar>f x\<bar>) \<in> borel_measurable M"
hoelzl@50003
   883
    and borel_measurable_ereal_inverse[measurable(raw)]: "(\<lambda>x. inverse (f x) :: ereal) \<in> borel_measurable M"
hoelzl@50003
   884
    and borel_measurable_uminus_ereal[measurable(raw)]: "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M"
hoelzl@49774
   885
  by (auto simp del: abs_real_of_ereal simp: borel_measurable_ereal_cases[OF f] measurable_If)
hoelzl@49774
   886
hoelzl@49774
   887
lemma borel_measurable_uminus_eq_ereal[simp]:
hoelzl@49774
   888
  "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
hoelzl@49774
   889
proof
hoelzl@49774
   890
  assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
hoelzl@49774
   891
qed auto
hoelzl@49774
   892
hoelzl@49774
   893
lemma set_Collect_ereal2:
hoelzl@49774
   894
  fixes f g :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   895
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   896
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   897
  assumes H: "{x \<in> space M. H (ereal (real (f x))) (ereal (real (g x)))} \<in> sets M"
hoelzl@50002
   898
    "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
   899
    "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
   900
    "{x \<in> space borel. H (ereal x) (-\<infinity>)} \<in> sets borel"
hoelzl@50002
   901
    "{x \<in> space borel. H (ereal x) (\<infinity>)} \<in> sets borel"
hoelzl@49774
   902
  shows "{x \<in> space M. H (f x) (g x)} \<in> sets M"
hoelzl@49774
   903
proof -
hoelzl@50002
   904
  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
   905
  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
   906
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
   907
  note * = this
hoelzl@50002
   908
  from assms show ?thesis
hoelzl@50002
   909
    by (subst *) (simp del: space_borel split del: split_if)
hoelzl@49774
   910
qed
hoelzl@49774
   911
hoelzl@50003
   912
lemma [measurable]:
hoelzl@49774
   913
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
   914
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   915
  assumes g: "g \<in> borel_measurable M"
hoelzl@50003
   916
  shows borel_measurable_ereal_le: "{x \<in> space M. f x \<le> g x} \<in> sets M"
hoelzl@50003
   917
    and borel_measurable_ereal_less: "{x \<in> space M. f x < g x} \<in> sets M"
hoelzl@50003
   918
    and borel_measurable_ereal_eq: "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@50003
   919
  using f g by (simp_all add: set_Collect_ereal2)
hoelzl@50003
   920
hoelzl@50003
   921
lemma borel_measurable_ereal_neq:
hoelzl@50003
   922
  "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
   923
  by simp
hoelzl@41981
   924
hoelzl@47694
   925
lemma borel_measurable_ereal_iff:
hoelzl@43920
   926
  shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M"
hoelzl@41981
   927
proof
hoelzl@43920
   928
  assume "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@43920
   929
  from borel_measurable_real_of_ereal[OF this]
hoelzl@41981
   930
  show "f \<in> borel_measurable M" by auto
hoelzl@41981
   931
qed auto
hoelzl@41981
   932
hoelzl@47694
   933
lemma borel_measurable_ereal_iff_real:
hoelzl@43923
   934
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
   935
  shows "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@41981
   936
    ((\<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
   937
proof safe
hoelzl@41981
   938
  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
   939
  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
   940
  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
   941
  let ?f = "\<lambda>x. if f x = \<infinity> then \<infinity> else if f x = -\<infinity> then -\<infinity> else ereal (real (f x))"
hoelzl@41981
   942
  have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
hoelzl@43920
   943
  also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
hoelzl@41981
   944
  finally show "f \<in> borel_measurable M" .
hoelzl@50002
   945
qed simp_all
hoelzl@41830
   946
hoelzl@47694
   947
lemma borel_measurable_eq_atMost_ereal:
hoelzl@43923
   948
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
   949
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
hoelzl@41981
   950
proof (intro iffI allI)
hoelzl@41981
   951
  assume pos[rule_format]: "\<forall>a. f -` {..a} \<inter> space M \<in> sets M"
hoelzl@41981
   952
  show "f \<in> borel_measurable M"
hoelzl@43920
   953
    unfolding borel_measurable_ereal_iff_real borel_measurable_iff_le
hoelzl@41981
   954
  proof (intro conjI allI)
hoelzl@41981
   955
    fix a :: real
hoelzl@43920
   956
    { fix x :: ereal assume *: "\<forall>i::nat. real i < x"
hoelzl@41981
   957
      have "x = \<infinity>"
hoelzl@43920
   958
      proof (rule ereal_top)
huffman@44666
   959
        fix B from reals_Archimedean2[of B] guess n ..
hoelzl@43920
   960
        then have "ereal B < real n" by auto
hoelzl@41981
   961
        with * show "B \<le> x" by (metis less_trans less_imp_le)
hoelzl@41981
   962
      qed }
hoelzl@41981
   963
    then have "f -` {\<infinity>} \<inter> space M = space M - (\<Union>i::nat. f -` {.. real i} \<inter> space M)"
hoelzl@41981
   964
      by (auto simp: not_le)
hoelzl@50002
   965
    then show "f -` {\<infinity>} \<inter> space M \<in> sets M" using pos
hoelzl@50002
   966
      by (auto simp del: UN_simps)
hoelzl@41981
   967
    moreover
hoelzl@43923
   968
    have "{-\<infinity>::ereal} = {..-\<infinity>}" by auto
hoelzl@41981
   969
    then show "f -` {-\<infinity>} \<inter> space M \<in> sets M" using pos by auto
hoelzl@43920
   970
    moreover have "{x\<in>space M. f x \<le> ereal a} \<in> sets M"
hoelzl@43920
   971
      using pos[of "ereal a"] by (simp add: vimage_def Int_def conj_commute)
hoelzl@41981
   972
    moreover have "{w \<in> space M. real (f w) \<le> a} =
hoelzl@43920
   973
      (if a < 0 then {w \<in> space M. f w \<le> ereal a} - f -` {-\<infinity>} \<inter> space M
hoelzl@43920
   974
      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
   975
      proof (intro set_eqI) fix x show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" by (cases "f x") auto qed
hoelzl@41981
   976
    ultimately show "{w \<in> space M. real (f w) \<le> a} \<in> sets M" by auto
hoelzl@35582
   977
  qed
hoelzl@41981
   978
qed (simp add: measurable_sets)
hoelzl@35582
   979
hoelzl@47694
   980
lemma borel_measurable_eq_atLeast_ereal:
hoelzl@43920
   981
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
hoelzl@41981
   982
proof
hoelzl@41981
   983
  assume pos: "\<forall>a. f -` {a..} \<inter> space M \<in> sets M"
hoelzl@41981
   984
  moreover have "\<And>a. (\<lambda>x. - f x) -` {..a} = f -` {-a ..}"
hoelzl@43920
   985
    by (auto simp: ereal_uminus_le_reorder)
hoelzl@41981
   986
  ultimately have "(\<lambda>x. - f x) \<in> borel_measurable M"
hoelzl@43920
   987
    unfolding borel_measurable_eq_atMost_ereal by auto
hoelzl@41981
   988
  then show "f \<in> borel_measurable M" by simp
hoelzl@41981
   989
qed (simp add: measurable_sets)
hoelzl@35582
   990
hoelzl@49774
   991
lemma greater_eq_le_measurable:
hoelzl@49774
   992
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@49774
   993
  shows "f -` {..< a} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@49774
   994
proof
hoelzl@49774
   995
  assume "f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@49774
   996
  moreover have "f -` {..< a} \<inter> space M = space M - f -` {a ..} \<inter> space M" by auto
hoelzl@49774
   997
  ultimately show "f -` {..< a} \<inter> space M \<in> sets M" by auto
hoelzl@49774
   998
next
hoelzl@49774
   999
  assume "f -` {..< a} \<inter> space M \<in> sets M"
hoelzl@49774
  1000
  moreover have "f -` {a ..} \<inter> space M = space M - f -` {..< a} \<inter> space M" by auto
hoelzl@49774
  1001
  ultimately show "f -` {a ..} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1002
qed
hoelzl@49774
  1003
hoelzl@47694
  1004
lemma borel_measurable_ereal_iff_less:
hoelzl@43920
  1005
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
hoelzl@43920
  1006
  unfolding borel_measurable_eq_atLeast_ereal greater_eq_le_measurable ..
hoelzl@38656
  1007
hoelzl@49774
  1008
lemma less_eq_ge_measurable:
hoelzl@49774
  1009
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@49774
  1010
  shows "f -` {a <..} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {..a} \<inter> space M \<in> sets M"
hoelzl@49774
  1011
proof
hoelzl@49774
  1012
  assume "f -` {a <..} \<inter> space M \<in> sets M"
hoelzl@49774
  1013
  moreover have "f -` {..a} \<inter> space M = space M - f -` {a <..} \<inter> space M" by auto
hoelzl@49774
  1014
  ultimately show "f -` {..a} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1015
next
hoelzl@49774
  1016
  assume "f -` {..a} \<inter> space M \<in> sets M"
hoelzl@49774
  1017
  moreover have "f -` {a <..} \<inter> space M = space M - f -` {..a} \<inter> space M" by auto
hoelzl@49774
  1018
  ultimately show "f -` {a <..} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1019
qed
hoelzl@49774
  1020
hoelzl@47694
  1021
lemma borel_measurable_ereal_iff_ge:
hoelzl@43920
  1022
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
hoelzl@43920
  1023
  unfolding borel_measurable_eq_atMost_ereal less_eq_ge_measurable ..
hoelzl@38656
  1024
hoelzl@49774
  1025
lemma borel_measurable_ereal2:
hoelzl@49774
  1026
  fixes f g :: "'a \<Rightarrow> ereal" 
hoelzl@41981
  1027
  assumes f: "f \<in> borel_measurable M"
hoelzl@41981
  1028
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1029
  assumes H: "(\<lambda>x. H (ereal (real (f x))) (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 (\<infinity>) (ereal (real (g x)))) \<in> borel_measurable M"
hoelzl@49774
  1032
    "(\<lambda>x. H (ereal (real (f x))) (-\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1033
    "(\<lambda>x. H (ereal (real (f x))) (\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1034
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@41981
  1035
proof -
hoelzl@50002
  1036
  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
  1037
  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
  1038
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
  1039
  note * = this
hoelzl@50002
  1040
  from assms show ?thesis unfolding * by simp
hoelzl@41981
  1041
qed
hoelzl@41981
  1042
hoelzl@49774
  1043
lemma
hoelzl@49774
  1044
  fixes f :: "'a \<Rightarrow> ereal" assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1045
  shows borel_measurable_ereal_eq_const: "{x\<in>space M. f x = c} \<in> sets M"
hoelzl@49774
  1046
    and borel_measurable_ereal_neq_const: "{x\<in>space M. f x \<noteq> c} \<in> sets M"
hoelzl@49774
  1047
  using f by auto
hoelzl@38656
  1048
hoelzl@50003
  1049
lemma [measurable(raw)]:
hoelzl@43920
  1050
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@50003
  1051
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@50002
  1052
  shows borel_measurable_ereal_add: "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@50002
  1053
    and borel_measurable_ereal_times: "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@50002
  1054
    and borel_measurable_ereal_min: "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
hoelzl@50002
  1055
    and borel_measurable_ereal_max: "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
hoelzl@50003
  1056
  by (simp_all add: borel_measurable_ereal2 min_def max_def)
hoelzl@49774
  1057
hoelzl@50003
  1058
lemma [measurable(raw)]:
hoelzl@49774
  1059
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1060
  assumes "f \<in> borel_measurable M"
hoelzl@49774
  1061
  assumes "g \<in> borel_measurable M"
hoelzl@50002
  1062
  shows borel_measurable_ereal_diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50002
  1063
    and borel_measurable_ereal_divide: "(\<lambda>x. f x / g x) \<in> borel_measurable M"
hoelzl@50003
  1064
  using assms by (simp_all add: minus_ereal_def divide_ereal_def)
hoelzl@38656
  1065
hoelzl@50003
  1066
lemma borel_measurable_ereal_setsum[measurable (raw)]:
hoelzl@43920
  1067
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41096
  1068
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1069
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41096
  1070
proof cases
hoelzl@41096
  1071
  assume "finite S"
hoelzl@41096
  1072
  thus ?thesis using assms
hoelzl@41096
  1073
    by induct auto
hoelzl@49774
  1074
qed simp
hoelzl@38656
  1075
hoelzl@50003
  1076
lemma borel_measurable_ereal_setprod[measurable (raw)]:
hoelzl@43920
  1077
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1078
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1079
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@38656
  1080
proof cases
hoelzl@38656
  1081
  assume "finite S"
hoelzl@41096
  1082
  thus ?thesis using assms by induct auto
hoelzl@41096
  1083
qed simp
hoelzl@38656
  1084
hoelzl@50003
  1085
lemma borel_measurable_SUP[measurable (raw)]:
hoelzl@43920
  1086
  fixes f :: "'d\<Colon>countable \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1087
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1088
  shows "(\<lambda>x. SUP i : A. f i x) \<in> borel_measurable M" (is "?sup \<in> borel_measurable M")
hoelzl@43920
  1089
  unfolding borel_measurable_ereal_iff_ge
hoelzl@41981
  1090
proof
hoelzl@38656
  1091
  fix a
hoelzl@41981
  1092
  have "?sup -` {a<..} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. a < f i x})"
noschinl@46884
  1093
    by (auto simp: less_SUP_iff)
hoelzl@41981
  1094
  then show "?sup -` {a<..} \<inter> space M \<in> sets M"
hoelzl@38656
  1095
    using assms by auto
hoelzl@38656
  1096
qed
hoelzl@38656
  1097
hoelzl@50003
  1098
lemma borel_measurable_INF[measurable (raw)]:
hoelzl@43920
  1099
  fixes f :: "'d :: countable \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1100
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1101
  shows "(\<lambda>x. INF i : A. f i x) \<in> borel_measurable M" (is "?inf \<in> borel_measurable M")
hoelzl@43920
  1102
  unfolding borel_measurable_ereal_iff_less
hoelzl@41981
  1103
proof
hoelzl@38656
  1104
  fix a
hoelzl@41981
  1105
  have "?inf -` {..<a} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. f i x < a})"
noschinl@46884
  1106
    by (auto simp: INF_less_iff)
hoelzl@41981
  1107
  then show "?inf -` {..<a} \<inter> space M \<in> sets M"
hoelzl@38656
  1108
    using assms by auto
hoelzl@38656
  1109
qed
hoelzl@38656
  1110
hoelzl@50003
  1111
lemma [measurable (raw)]:
hoelzl@43920
  1112
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41981
  1113
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@50002
  1114
  shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1115
    and borel_measurable_limsup: "(\<lambda>x. limsup (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1116
  unfolding liminf_SUPR_INFI limsup_INFI_SUPR using assms by auto
hoelzl@35692
  1117
hoelzl@50104
  1118
lemma sets_Collect_eventually_sequentially[measurable]:
hoelzl@50003
  1119
  "(\<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
  1120
  unfolding eventually_sequentially by simp
hoelzl@50003
  1121
hoelzl@50003
  1122
lemma sets_Collect_ereal_convergent[measurable]: 
hoelzl@50003
  1123
  fixes f :: "nat \<Rightarrow> 'a => ereal"
hoelzl@50003
  1124
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1125
  shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
hoelzl@50003
  1126
  unfolding convergent_ereal by auto
hoelzl@50003
  1127
hoelzl@50003
  1128
lemma borel_measurable_extreal_lim[measurable (raw)]:
hoelzl@50003
  1129
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1130
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1131
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1132
proof -
hoelzl@50003
  1133
  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
  1134
    using convergent_ereal_limsup by (simp add: lim_def convergent_def)
hoelzl@50003
  1135
  then show ?thesis
hoelzl@50003
  1136
    by simp
hoelzl@50003
  1137
qed
hoelzl@50003
  1138
hoelzl@49774
  1139
lemma borel_measurable_ereal_LIMSEQ:
hoelzl@49774
  1140
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@49774
  1141
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
hoelzl@49774
  1142
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@49774
  1143
  shows "u' \<in> borel_measurable M"
hoelzl@47694
  1144
proof -
hoelzl@49774
  1145
  have "\<And>x. x \<in> space M \<Longrightarrow> u' x = liminf (\<lambda>n. u n x)"
hoelzl@49774
  1146
    using u' by (simp add: lim_imp_Liminf[symmetric])
hoelzl@50003
  1147
  with u show ?thesis by (simp cong: measurable_cong)
hoelzl@47694
  1148
qed
hoelzl@47694
  1149
hoelzl@50003
  1150
lemma borel_measurable_extreal_suminf[measurable (raw)]:
hoelzl@43920
  1151
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1152
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@41981
  1153
  shows "(\<lambda>x. (\<Sum>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1154
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@39092
  1155
hoelzl@39092
  1156
section "LIMSEQ is borel measurable"
hoelzl@39092
  1157
hoelzl@47694
  1158
lemma borel_measurable_LIMSEQ:
hoelzl@39092
  1159
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@39092
  1160
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
hoelzl@39092
  1161
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@39092
  1162
  shows "u' \<in> borel_measurable M"
hoelzl@39092
  1163
proof -
hoelzl@43920
  1164
  have "\<And>x. x \<in> space M \<Longrightarrow> liminf (\<lambda>n. ereal (u n x)) = ereal (u' x)"
wenzelm@46731
  1165
    using u' by (simp add: lim_imp_Liminf)
hoelzl@43920
  1166
  moreover from u have "(\<lambda>x. liminf (\<lambda>n. ereal (u n x))) \<in> borel_measurable M"
hoelzl@39092
  1167
    by auto
hoelzl@43920
  1168
  ultimately show ?thesis by (simp cong: measurable_cong add: borel_measurable_ereal_iff)
hoelzl@39092
  1169
qed
hoelzl@39092
  1170
hoelzl@50002
  1171
lemma sets_Collect_Cauchy[measurable]: 
hoelzl@49774
  1172
  fixes f :: "nat \<Rightarrow> 'a => real"
hoelzl@50002
  1173
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1174
  shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
hoelzl@50002
  1175
  unfolding Cauchy_iff2 using f by auto
hoelzl@49774
  1176
hoelzl@50002
  1177
lemma borel_measurable_lim[measurable (raw)]:
hoelzl@49774
  1178
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@50002
  1179
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1180
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1181
proof -
hoelzl@50002
  1182
  def u' \<equiv> "\<lambda>x. lim (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@50002
  1183
  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
  1184
    by (auto simp: lim_def convergent_eq_cauchy[symmetric])
hoelzl@50002
  1185
  have "u' \<in> borel_measurable M"
hoelzl@50002
  1186
  proof (rule borel_measurable_LIMSEQ)
hoelzl@50002
  1187
    fix x
hoelzl@50002
  1188
    have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@49774
  1189
      by (cases "Cauchy (\<lambda>i. f i x)")
hoelzl@50002
  1190
         (auto simp add: convergent_eq_cauchy[symmetric] convergent_def)
hoelzl@50002
  1191
    then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) ----> u' x"
hoelzl@50002
  1192
      unfolding u'_def 
hoelzl@50002
  1193
      by (rule convergent_LIMSEQ_iff[THEN iffD1])
hoelzl@50002
  1194
  qed measurable
hoelzl@50002
  1195
  then show ?thesis
hoelzl@50002
  1196
    unfolding * by measurable
hoelzl@49774
  1197
qed
hoelzl@49774
  1198
hoelzl@50002
  1199
lemma borel_measurable_suminf[measurable (raw)]:
hoelzl@49774
  1200
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@50002
  1201
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1202
  shows "(\<lambda>x. suminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1203
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@49774
  1204
hoelzl@49774
  1205
end