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