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