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