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