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