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