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