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