src/HOL/Probability/Borel_Space.thy
author hoelzl
Fri Feb 19 13:40:50 2016 +0100 (2016-02-19)
changeset 62378 85ed00c1fe7c
parent 62372 4fe872ff91bf
child 62390 842917225d56
permissions -rw-r--r--
generalize more theorems to support enat and ennreal
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@61808
     6
section \<open>Borel spaces\<close>
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@62372
    22
    by (auto intro: topological_basis_prod topological_basis_trivial topological_basis_imp_subbasis)
hoelzl@59088
    23
qed
hoelzl@59088
    24
hoelzl@62083
    25
definition "mono_on f A \<equiv> \<forall>r s. r \<in> A \<and> s \<in> A \<and> r \<le> s \<longrightarrow> f r \<le> f s"
hoelzl@62083
    26
hoelzl@62083
    27
lemma mono_onI:
hoelzl@62083
    28
  "(\<And>r s. r \<in> A \<Longrightarrow> s \<in> A \<Longrightarrow> r \<le> s \<Longrightarrow> f r \<le> f s) \<Longrightarrow> mono_on f A"
hoelzl@62083
    29
  unfolding mono_on_def by simp
hoelzl@62083
    30
hoelzl@62083
    31
lemma mono_onD:
hoelzl@62083
    32
  "\<lbrakk>mono_on f A; r \<in> A; s \<in> A; r \<le> s\<rbrakk> \<Longrightarrow> f r \<le> f s"
hoelzl@62083
    33
  unfolding mono_on_def by simp
hoelzl@62083
    34
hoelzl@62083
    35
lemma mono_imp_mono_on: "mono f \<Longrightarrow> mono_on f A"
hoelzl@62083
    36
  unfolding mono_def mono_on_def by auto
hoelzl@62083
    37
hoelzl@62083
    38
lemma mono_on_subset: "mono_on f A \<Longrightarrow> B \<subseteq> A \<Longrightarrow> mono_on f B"
hoelzl@62083
    39
  unfolding mono_on_def by auto
hoelzl@62083
    40
hoelzl@62083
    41
definition "strict_mono_on f A \<equiv> \<forall>r s. r \<in> A \<and> s \<in> A \<and> r < s \<longrightarrow> f r < f s"
hoelzl@62083
    42
hoelzl@62083
    43
lemma strict_mono_onI:
hoelzl@62083
    44
  "(\<And>r s. r \<in> A \<Longrightarrow> s \<in> A \<Longrightarrow> r < s \<Longrightarrow> f r < f s) \<Longrightarrow> strict_mono_on f A"
hoelzl@62083
    45
  unfolding strict_mono_on_def by simp
hoelzl@62083
    46
hoelzl@62083
    47
lemma strict_mono_onD:
hoelzl@62083
    48
  "\<lbrakk>strict_mono_on f A; r \<in> A; s \<in> A; r < s\<rbrakk> \<Longrightarrow> f r < f s"
hoelzl@62083
    49
  unfolding strict_mono_on_def by simp
hoelzl@62083
    50
hoelzl@62083
    51
lemma mono_on_greaterD:
hoelzl@62083
    52
  assumes "mono_on g A" "x \<in> A" "y \<in> A" "g x > (g (y::_::linorder) :: _ :: linorder)"
hoelzl@62083
    53
  shows "x > y"
hoelzl@62083
    54
proof (rule ccontr)
hoelzl@62083
    55
  assume "\<not>x > y"
hoelzl@62083
    56
  hence "x \<le> y" by (simp add: not_less)
hoelzl@62083
    57
  from assms(1-3) and this have "g x \<le> g y" by (rule mono_onD)
hoelzl@62083
    58
  with assms(4) show False by simp
hoelzl@62083
    59
qed
hoelzl@62083
    60
hoelzl@62083
    61
lemma strict_mono_inv:
hoelzl@62083
    62
  fixes f :: "('a::linorder) \<Rightarrow> ('b::linorder)"
hoelzl@62083
    63
  assumes "strict_mono f" and "surj f" and inv: "\<And>x. g (f x) = x"
hoelzl@62083
    64
  shows "strict_mono g"
hoelzl@62083
    65
proof
hoelzl@62083
    66
  fix x y :: 'b assume "x < y"
hoelzl@62083
    67
  from \<open>surj f\<close> obtain x' y' where [simp]: "x = f x'" "y = f y'" by blast
hoelzl@62083
    68
  with \<open>x < y\<close> and \<open>strict_mono f\<close> have "x' < y'" by (simp add: strict_mono_less)
hoelzl@62083
    69
  with inv show "g x < g y" by simp
hoelzl@62083
    70
qed
hoelzl@62083
    71
hoelzl@62083
    72
lemma strict_mono_on_imp_inj_on:
hoelzl@62083
    73
  assumes "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> (_ :: preorder)) A"
hoelzl@62083
    74
  shows "inj_on f A"
hoelzl@62083
    75
proof (rule inj_onI)
hoelzl@62083
    76
  fix x y assume "x \<in> A" "y \<in> A" "f x = f y"
hoelzl@62083
    77
  thus "x = y"
hoelzl@62083
    78
    by (cases x y rule: linorder_cases)
hoelzl@62372
    79
       (auto dest: strict_mono_onD[OF assms, of x y] strict_mono_onD[OF assms, of y x])
hoelzl@62083
    80
qed
hoelzl@62083
    81
hoelzl@62083
    82
lemma strict_mono_on_leD:
hoelzl@62083
    83
  assumes "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A" "x \<in> A" "y \<in> A" "x \<le> y"
hoelzl@62083
    84
  shows "f x \<le> f y"
hoelzl@62083
    85
proof (insert le_less_linear[of y x], elim disjE)
hoelzl@62083
    86
  assume "x < y"
hoelzl@62083
    87
  with assms have "f x < f y" by (rule_tac strict_mono_onD[OF assms(1)]) simp_all
hoelzl@62083
    88
  thus ?thesis by (rule less_imp_le)
hoelzl@62083
    89
qed (insert assms, simp)
hoelzl@62083
    90
hoelzl@62083
    91
lemma strict_mono_on_eqD:
hoelzl@62083
    92
  fixes f :: "(_ :: linorder) \<Rightarrow> (_ :: preorder)"
hoelzl@62083
    93
  assumes "strict_mono_on f A" "f x = f y" "x \<in> A" "y \<in> A"
hoelzl@62083
    94
  shows "y = x"
hoelzl@62083
    95
  using assms by (rule_tac linorder_cases[of x y]) (auto dest: strict_mono_onD)
hoelzl@62083
    96
hoelzl@62083
    97
lemma mono_on_imp_deriv_nonneg:
hoelzl@62083
    98
  assumes mono: "mono_on f A" and deriv: "(f has_real_derivative D) (at x)"
hoelzl@62083
    99
  assumes "x \<in> interior A"
hoelzl@62083
   100
  shows "D \<ge> 0"
hoelzl@62083
   101
proof (rule tendsto_le_const)
hoelzl@62083
   102
  let ?A' = "(\<lambda>y. y - x) ` interior A"
hoelzl@62083
   103
  from deriv show "((\<lambda>h. (f (x + h) - f x) / h) \<longlongrightarrow> D) (at 0)"
hoelzl@62083
   104
      by (simp add: field_has_derivative_at has_field_derivative_def)
hoelzl@62083
   105
  from mono have mono': "mono_on f (interior A)" by (rule mono_on_subset) (rule interior_subset)
hoelzl@62083
   106
hoelzl@62083
   107
  show "eventually (\<lambda>h. (f (x + h) - f x) / h \<ge> 0) (at 0)"
hoelzl@62083
   108
  proof (subst eventually_at_topological, intro exI conjI ballI impI)
hoelzl@62083
   109
    have "open (interior A)" by simp
hoelzl@62083
   110
    hence "open (op + (-x) ` interior A)" by (rule open_translation)
hoelzl@62083
   111
    also have "(op + (-x) ` interior A) = ?A'" by auto
hoelzl@62083
   112
    finally show "open ?A'" .
hoelzl@62083
   113
  next
hoelzl@62083
   114
    from \<open>x \<in> interior A\<close> show "0 \<in> ?A'" by auto
hoelzl@62083
   115
  next
hoelzl@62083
   116
    fix h assume "h \<in> ?A'"
hoelzl@62083
   117
    hence "x + h \<in> interior A" by auto
hoelzl@62083
   118
    with mono' and \<open>x \<in> interior A\<close> show "(f (x + h) - f x) / h \<ge> 0"
hoelzl@62083
   119
      by (cases h rule: linorder_cases[of _ 0])
hoelzl@62083
   120
         (simp_all add: divide_nonpos_neg divide_nonneg_pos mono_onD field_simps)
hoelzl@62083
   121
  qed
hoelzl@62083
   122
qed simp
hoelzl@62083
   123
hoelzl@62372
   124
lemma strict_mono_on_imp_mono_on:
hoelzl@62083
   125
  "strict_mono_on (f :: (_ :: linorder) \<Rightarrow> _ :: preorder) A \<Longrightarrow> mono_on f A"
hoelzl@62083
   126
  by (rule mono_onI, rule strict_mono_on_leD)
hoelzl@62083
   127
hoelzl@62083
   128
lemma mono_on_ctble_discont:
hoelzl@62083
   129
  fixes f :: "real \<Rightarrow> real"
hoelzl@62083
   130
  fixes A :: "real set"
hoelzl@62083
   131
  assumes "mono_on f A"
hoelzl@62083
   132
  shows "countable {a\<in>A. \<not> continuous (at a within A) f}"
hoelzl@62083
   133
proof -
hoelzl@62083
   134
  have mono: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@62083
   135
    using `mono_on f A` by (simp add: mono_on_def)
hoelzl@62083
   136
  have "\<forall>a \<in> {a\<in>A. \<not> continuous (at a within A) f}. \<exists>q :: nat \<times> rat.
hoelzl@62083
   137
      (fst q = 0 \<and> of_rat (snd q) < f a \<and> (\<forall>x \<in> A. x < a \<longrightarrow> f x < of_rat (snd q))) \<or>
hoelzl@62083
   138
      (fst q = 1 \<and> of_rat (snd q) > f a \<and> (\<forall>x \<in> A. x > a \<longrightarrow> f x > of_rat (snd q)))"
hoelzl@62083
   139
  proof (clarsimp simp del: One_nat_def)
hoelzl@62083
   140
    fix a assume "a \<in> A" assume "\<not> continuous (at a within A) f"
hoelzl@62083
   141
    thus "\<exists>q1 q2.
hoelzl@62083
   142
            q1 = 0 \<and> real_of_rat q2 < f a \<and> (\<forall>x\<in>A. x < a \<longrightarrow> f x < real_of_rat q2) \<or>
hoelzl@62083
   143
            q1 = 1 \<and> f a < real_of_rat q2 \<and> (\<forall>x\<in>A. a < x \<longrightarrow> real_of_rat q2 < f x)"
hoelzl@62083
   144
    proof (auto simp add: continuous_within order_tendsto_iff eventually_at)
hoelzl@62083
   145
      fix l assume "l < f a"
hoelzl@62083
   146
      then obtain q2 where q2: "l < of_rat q2" "of_rat q2 < f a"
hoelzl@62083
   147
        using of_rat_dense by blast
hoelzl@62083
   148
      assume * [rule_format]: "\<forall>d>0. \<exists>x\<in>A. x \<noteq> a \<and> dist x a < d \<and> \<not> l < f x"
hoelzl@62083
   149
      from q2 have "real_of_rat q2 < f a \<and> (\<forall>x\<in>A. x < a \<longrightarrow> f x < real_of_rat q2)"
hoelzl@62083
   150
      proof auto
hoelzl@62083
   151
        fix x assume "x \<in> A" "x < a"
hoelzl@62083
   152
        with q2 *[of "a - x"] show "f x < real_of_rat q2"
hoelzl@62083
   153
          apply (auto simp add: dist_real_def not_less)
hoelzl@62083
   154
          apply (subgoal_tac "f x \<le> f xa")
hoelzl@62083
   155
          by (auto intro: mono)
hoelzl@62372
   156
      qed
hoelzl@62083
   157
      thus ?thesis by auto
hoelzl@62083
   158
    next
hoelzl@62083
   159
      fix u assume "u > f a"
hoelzl@62083
   160
      then obtain q2 where q2: "f a < of_rat q2" "of_rat q2 < u"
hoelzl@62083
   161
        using of_rat_dense by blast
hoelzl@62083
   162
      assume *[rule_format]: "\<forall>d>0. \<exists>x\<in>A. x \<noteq> a \<and> dist x a < d \<and> \<not> u > f x"
hoelzl@62083
   163
      from q2 have "real_of_rat q2 > f a \<and> (\<forall>x\<in>A. x > a \<longrightarrow> f x > real_of_rat q2)"
hoelzl@62083
   164
      proof auto
hoelzl@62083
   165
        fix x assume "x \<in> A" "x > a"
hoelzl@62083
   166
        with q2 *[of "x - a"] show "f x > real_of_rat q2"
hoelzl@62083
   167
          apply (auto simp add: dist_real_def)
hoelzl@62083
   168
          apply (subgoal_tac "f x \<ge> f xa")
hoelzl@62083
   169
          by (auto intro: mono)
hoelzl@62372
   170
      qed
hoelzl@62083
   171
      thus ?thesis by auto
hoelzl@62083
   172
    qed
hoelzl@62083
   173
  qed
hoelzl@62372
   174
  hence "\<exists>g :: real \<Rightarrow> nat \<times> rat . \<forall>a \<in> {a\<in>A. \<not> continuous (at a within A) f}.
hoelzl@62083
   175
      (fst (g a) = 0 \<and> of_rat (snd (g a)) < f a \<and> (\<forall>x \<in> A. x < a \<longrightarrow> f x < of_rat (snd (g a)))) |
hoelzl@62083
   176
      (fst (g a) = 1 \<and> of_rat (snd (g a)) > f a \<and> (\<forall>x \<in> A. x > a \<longrightarrow> f x > of_rat (snd (g a))))"
hoelzl@62083
   177
    by (rule bchoice)
hoelzl@62083
   178
  then guess g ..
hoelzl@62083
   179
  hence g: "\<And>a x. a \<in> A \<Longrightarrow> \<not> continuous (at a within A) f \<Longrightarrow> x \<in> A \<Longrightarrow>
hoelzl@62083
   180
      (fst (g a) = 0 \<and> of_rat (snd (g a)) < f a \<and> (x < a \<longrightarrow> f x < of_rat (snd (g a)))) |
hoelzl@62083
   181
      (fst (g a) = 1 \<and> of_rat (snd (g a)) > f a \<and> (x > a \<longrightarrow> f x > of_rat (snd (g a))))"
hoelzl@62083
   182
    by auto
hoelzl@62083
   183
  have "inj_on g {a\<in>A. \<not> continuous (at a within A) f}"
hoelzl@62083
   184
  proof (auto simp add: inj_on_def)
hoelzl@62083
   185
    fix w z
hoelzl@62083
   186
    assume 1: "w \<in> A" and 2: "\<not> continuous (at w within A) f" and
hoelzl@62083
   187
           3: "z \<in> A" and 4: "\<not> continuous (at z within A) f" and
hoelzl@62083
   188
           5: "g w = g z"
hoelzl@62372
   189
    from g [OF 1 2 3] g [OF 3 4 1] 5
hoelzl@62083
   190
    show "w = z" by auto
hoelzl@62083
   191
  qed
hoelzl@62372
   192
  thus ?thesis
hoelzl@62372
   193
    by (rule countableI')
hoelzl@62083
   194
qed
hoelzl@62083
   195
hoelzl@62083
   196
lemma mono_on_ctble_discont_open:
hoelzl@62083
   197
  fixes f :: "real \<Rightarrow> real"
hoelzl@62083
   198
  fixes A :: "real set"
hoelzl@62083
   199
  assumes "open A" "mono_on f A"
hoelzl@62083
   200
  shows "countable {a\<in>A. \<not>isCont f a}"
hoelzl@62083
   201
proof -
hoelzl@62083
   202
  have "{a\<in>A. \<not>isCont f a} = {a\<in>A. \<not>(continuous (at a within A) f)}"
hoelzl@62083
   203
    by (auto simp add: continuous_within_open [OF _ `open A`])
hoelzl@62083
   204
  thus ?thesis
hoelzl@62083
   205
    apply (elim ssubst)
hoelzl@62083
   206
    by (rule mono_on_ctble_discont, rule assms)
hoelzl@62083
   207
qed
hoelzl@62083
   208
hoelzl@62083
   209
lemma mono_ctble_discont:
hoelzl@62083
   210
  fixes f :: "real \<Rightarrow> real"
hoelzl@62083
   211
  assumes "mono f"
hoelzl@62083
   212
  shows "countable {a. \<not> isCont f a}"
hoelzl@62083
   213
using assms mono_on_ctble_discont [of f UNIV] unfolding mono_on_def mono_def by auto
hoelzl@62083
   214
hoelzl@62083
   215
lemma has_real_derivative_imp_continuous_on:
hoelzl@62083
   216
  assumes "\<And>x. x \<in> A \<Longrightarrow> (f has_real_derivative f' x) (at x)"
hoelzl@62083
   217
  shows "continuous_on A f"
hoelzl@62083
   218
  apply (intro differentiable_imp_continuous_on, unfold differentiable_on_def)
hoelzl@62083
   219
  apply (intro ballI Deriv.differentiableI)
hoelzl@62083
   220
  apply (rule has_field_derivative_subset[OF assms])
hoelzl@62083
   221
  apply simp_all
hoelzl@62083
   222
  done
hoelzl@62083
   223
hoelzl@62083
   224
lemma closure_contains_Sup:
hoelzl@62083
   225
  fixes S :: "real set"
hoelzl@62083
   226
  assumes "S \<noteq> {}" "bdd_above S"
hoelzl@62083
   227
  shows "Sup S \<in> closure S"
hoelzl@62083
   228
proof-
hoelzl@62372
   229
  have "Inf (uminus ` S) \<in> closure (uminus ` S)"
hoelzl@62083
   230
      using assms by (intro closure_contains_Inf) auto
hoelzl@62083
   231
  also have "Inf (uminus ` S) = -Sup S" by (simp add: Inf_real_def)
hoelzl@62083
   232
  also have "closure (uminus ` S) = uminus ` closure S"
hoelzl@62083
   233
      by (rule sym, intro closure_injective_linear_image) (auto intro: linearI)
hoelzl@62083
   234
  finally show ?thesis by auto
hoelzl@62083
   235
qed
hoelzl@62083
   236
hoelzl@62083
   237
lemma closed_contains_Sup:
hoelzl@62083
   238
  fixes S :: "real set"
hoelzl@62083
   239
  shows "S \<noteq> {} \<Longrightarrow> bdd_above S \<Longrightarrow> closed S \<Longrightarrow> Sup S \<in> S"
hoelzl@62083
   240
  by (subst closure_closed[symmetric], assumption, rule closure_contains_Sup)
hoelzl@62083
   241
hoelzl@62083
   242
lemma deriv_nonneg_imp_mono:
hoelzl@62083
   243
  assumes deriv: "\<And>x. x \<in> {a..b} \<Longrightarrow> (g has_real_derivative g' x) (at x)"
hoelzl@62083
   244
  assumes nonneg: "\<And>x. x \<in> {a..b} \<Longrightarrow> g' x \<ge> 0"
hoelzl@62083
   245
  assumes ab: "a \<le> b"
hoelzl@62083
   246
  shows "g a \<le> g b"
hoelzl@62083
   247
proof (cases "a < b")
hoelzl@62083
   248
  assume "a < b"
hoelzl@62083
   249
  from deriv have "\<forall>x. x \<ge> a \<and> x \<le> b \<longrightarrow> (g has_real_derivative g' x) (at x)" by simp
hoelzl@62372
   250
  from MVT2[OF \<open>a < b\<close> this] and deriv
hoelzl@62083
   251
    obtain \<xi> where \<xi>_ab: "\<xi> > a" "\<xi> < b" and g_ab: "g b - g a = (b - a) * g' \<xi>" by blast
hoelzl@62083
   252
  from \<xi>_ab ab nonneg have "(b - a) * g' \<xi> \<ge> 0" by simp
hoelzl@62083
   253
  with g_ab show ?thesis by simp
hoelzl@62083
   254
qed (insert ab, simp)
hoelzl@62083
   255
hoelzl@62083
   256
lemma continuous_interval_vimage_Int:
hoelzl@62083
   257
  assumes "continuous_on {a::real..b} g" and mono: "\<And>x y. a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<le> b \<Longrightarrow> g x \<le> g y"
hoelzl@62083
   258
  assumes "a \<le> b" "(c::real) \<le> d" "{c..d} \<subseteq> {g a..g b}"
hoelzl@62083
   259
  obtains c' d' where "{a..b} \<inter> g -` {c..d} = {c'..d'}" "c' \<le> d'" "g c' = c" "g d' = d"
hoelzl@62083
   260
proof-
hoelzl@62083
   261
    let ?A = "{a..b} \<inter> g -` {c..d}"
hoelzl@62372
   262
    from IVT'[of g a c b, OF _ _ \<open>a \<le> b\<close> assms(1)] assms(4,5)
hoelzl@62083
   263
         obtain c'' where c'': "c'' \<in> ?A" "g c'' = c" by auto
hoelzl@62372
   264
    from IVT'[of g a d b, OF _ _ \<open>a \<le> b\<close> assms(1)] assms(4,5)
hoelzl@62083
   265
         obtain d'' where d'': "d'' \<in> ?A" "g d'' = d" by auto
hoelzl@62083
   266
    hence [simp]: "?A \<noteq> {}" by blast
hoelzl@62083
   267
hoelzl@62083
   268
    def c' \<equiv> "Inf ?A" and d' \<equiv> "Sup ?A"
hoelzl@62083
   269
    have "?A \<subseteq> {c'..d'}" unfolding c'_def d'_def
hoelzl@62083
   270
        by (intro subsetI) (auto intro: cInf_lower cSup_upper)
hoelzl@62372
   271
    moreover from assms have "closed ?A"
hoelzl@62083
   272
        using continuous_on_closed_vimage[of "{a..b}" g] by (subst Int_commute) simp
hoelzl@62083
   273
    hence c'd'_in_set: "c' \<in> ?A" "d' \<in> ?A" unfolding c'_def d'_def
hoelzl@62083
   274
        by ((intro closed_contains_Inf closed_contains_Sup, simp_all)[])+
hoelzl@62372
   275
    hence "{c'..d'} \<subseteq> ?A" using assms
hoelzl@62083
   276
        by (intro subsetI)
hoelzl@62372
   277
           (auto intro!: order_trans[of c "g c'" "g x" for x] order_trans[of "g x" "g d'" d for x]
hoelzl@62083
   278
                 intro!: mono)
hoelzl@62083
   279
    moreover have "c' \<le> d'" using c'd'_in_set(2) unfolding c'_def by (intro cInf_lower) auto
hoelzl@62083
   280
    moreover have "g c' \<le> c" "g d' \<ge> d"
hoelzl@62083
   281
      apply (insert c'' d'' c'd'_in_set)
hoelzl@62083
   282
      apply (subst c''(2)[symmetric])
hoelzl@62083
   283
      apply (auto simp: c'_def intro!: mono cInf_lower c'') []
hoelzl@62083
   284
      apply (subst d''(2)[symmetric])
hoelzl@62083
   285
      apply (auto simp: d'_def intro!: mono cSup_upper d'') []
hoelzl@62083
   286
      done
hoelzl@62083
   287
    with c'd'_in_set have "g c' = c" "g d' = d" by auto
hoelzl@62083
   288
    ultimately show ?thesis using that by blast
hoelzl@62083
   289
qed
hoelzl@62083
   290
wenzelm@61808
   291
subsection \<open>Generic Borel spaces\<close>
paulson@33533
   292
hoelzl@62372
   293
definition (in topological_space) borel :: "'a measure" where
hoelzl@47694
   294
  "borel = sigma UNIV {S. open S}"
paulson@33533
   295
hoelzl@47694
   296
abbreviation "borel_measurable M \<equiv> measurable M borel"
paulson@33533
   297
paulson@33533
   298
lemma in_borel_measurable:
paulson@33533
   299
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@47694
   300
    (\<forall>S \<in> sigma_sets UNIV {S. open S}. f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
   301
  by (auto simp add: measurable_def borel_def)
paulson@33533
   302
hoelzl@40859
   303
lemma in_borel_measurable_borel:
hoelzl@38656
   304
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
   305
    (\<forall>S \<in> sets borel.
hoelzl@38656
   306
      f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
   307
  by (auto simp add: measurable_def borel_def)
paulson@33533
   308
hoelzl@40859
   309
lemma space_borel[simp]: "space borel = UNIV"
hoelzl@40859
   310
  unfolding borel_def by auto
hoelzl@38656
   311
hoelzl@50002
   312
lemma space_in_borel[measurable]: "UNIV \<in> sets borel"
hoelzl@50002
   313
  unfolding borel_def by auto
hoelzl@50002
   314
hoelzl@57235
   315
lemma sets_borel: "sets borel = sigma_sets UNIV {S. open S}"
hoelzl@57235
   316
  unfolding borel_def by (rule sets_measure_of) simp
hoelzl@57235
   317
hoelzl@62083
   318
lemma measurable_sets_borel:
hoelzl@62083
   319
    "\<lbrakk>f \<in> measurable borel M; A \<in> sets M\<rbrakk> \<Longrightarrow> f -` A \<in> sets borel"
hoelzl@62083
   320
  by (drule (1) measurable_sets) simp
hoelzl@62083
   321
hoelzl@50387
   322
lemma pred_Collect_borel[measurable (raw)]: "Measurable.pred borel P \<Longrightarrow> {x. P x} \<in> sets borel"
hoelzl@50002
   323
  unfolding borel_def pred_def by auto
hoelzl@50002
   324
hoelzl@50003
   325
lemma borel_open[measurable (raw generic)]:
hoelzl@40859
   326
  assumes "open A" shows "A \<in> sets borel"
hoelzl@38656
   327
proof -
huffman@44537
   328
  have "A \<in> {S. open S}" unfolding mem_Collect_eq using assms .
hoelzl@47694
   329
  thus ?thesis unfolding borel_def by auto
paulson@33533
   330
qed
paulson@33533
   331
hoelzl@50003
   332
lemma borel_closed[measurable (raw generic)]:
hoelzl@40859
   333
  assumes "closed A" shows "A \<in> sets borel"
paulson@33533
   334
proof -
hoelzl@40859
   335
  have "space borel - (- A) \<in> sets borel"
hoelzl@40859
   336
    using assms unfolding closed_def by (blast intro: borel_open)
hoelzl@38656
   337
  thus ?thesis by simp
paulson@33533
   338
qed
paulson@33533
   339
hoelzl@50003
   340
lemma borel_singleton[measurable]:
hoelzl@50003
   341
  "A \<in> sets borel \<Longrightarrow> insert x A \<in> sets (borel :: 'a::t1_space measure)"
immler@50244
   342
  unfolding insert_def by (rule sets.Un) auto
hoelzl@50002
   343
hoelzl@50003
   344
lemma borel_comp[measurable]: "A \<in> sets borel \<Longrightarrow> - A \<in> sets borel"
hoelzl@50002
   345
  unfolding Compl_eq_Diff_UNIV by simp
hoelzl@41830
   346
hoelzl@47694
   347
lemma borel_measurable_vimage:
hoelzl@38656
   348
  fixes f :: "'a \<Rightarrow> 'x::t2_space"
hoelzl@50002
   349
  assumes borel[measurable]: "f \<in> borel_measurable M"
hoelzl@38656
   350
  shows "f -` {x} \<inter> space M \<in> sets M"
hoelzl@50002
   351
  by simp
paulson@33533
   352
hoelzl@47694
   353
lemma borel_measurableI:
wenzelm@61076
   354
  fixes f :: "'a \<Rightarrow> 'x::topological_space"
hoelzl@38656
   355
  assumes "\<And>S. open S \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
hoelzl@38656
   356
  shows "f \<in> borel_measurable M"
hoelzl@40859
   357
  unfolding borel_def
hoelzl@47694
   358
proof (rule measurable_measure_of, simp_all)
huffman@44537
   359
  fix S :: "'x set" assume "open S" thus "f -` S \<inter> space M \<in> sets M"
huffman@44537
   360
    using assms[of S] by simp
hoelzl@40859
   361
qed
paulson@33533
   362
hoelzl@50021
   363
lemma borel_measurable_const:
hoelzl@38656
   364
  "(\<lambda>x. c) \<in> borel_measurable M"
hoelzl@47694
   365
  by auto
paulson@33533
   366
hoelzl@50003
   367
lemma borel_measurable_indicator:
hoelzl@38656
   368
  assumes A: "A \<in> sets M"
hoelzl@38656
   369
  shows "indicator A \<in> borel_measurable M"
wenzelm@46905
   370
  unfolding indicator_def [abs_def] using A
hoelzl@47694
   371
  by (auto intro!: measurable_If_set)
paulson@33533
   372
hoelzl@50096
   373
lemma borel_measurable_count_space[measurable (raw)]:
hoelzl@50096
   374
  "f \<in> borel_measurable (count_space S)"
hoelzl@50096
   375
  unfolding measurable_def by auto
hoelzl@50096
   376
hoelzl@50096
   377
lemma borel_measurable_indicator'[measurable (raw)]:
hoelzl@50096
   378
  assumes [measurable]: "{x\<in>space M. f x \<in> A x} \<in> sets M"
hoelzl@50096
   379
  shows "(\<lambda>x. indicator (A x) (f x)) \<in> borel_measurable M"
hoelzl@50001
   380
  unfolding indicator_def[abs_def]
hoelzl@50001
   381
  by (auto intro!: measurable_If)
hoelzl@50001
   382
hoelzl@47694
   383
lemma borel_measurable_indicator_iff:
hoelzl@40859
   384
  "(indicator A :: 'a \<Rightarrow> 'x::{t1_space, zero_neq_one}) \<in> borel_measurable M \<longleftrightarrow> A \<inter> space M \<in> sets M"
hoelzl@40859
   385
    (is "?I \<in> borel_measurable M \<longleftrightarrow> _")
hoelzl@40859
   386
proof
hoelzl@40859
   387
  assume "?I \<in> borel_measurable M"
hoelzl@40859
   388
  then have "?I -` {1} \<inter> space M \<in> sets M"
hoelzl@40859
   389
    unfolding measurable_def by auto
hoelzl@40859
   390
  also have "?I -` {1} \<inter> space M = A \<inter> space M"
wenzelm@46905
   391
    unfolding indicator_def [abs_def] by auto
hoelzl@40859
   392
  finally show "A \<inter> space M \<in> sets M" .
hoelzl@40859
   393
next
hoelzl@40859
   394
  assume "A \<inter> space M \<in> sets M"
hoelzl@40859
   395
  moreover have "?I \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
   396
    (indicator (A \<inter> space M) :: 'a \<Rightarrow> 'x) \<in> borel_measurable M"
hoelzl@40859
   397
    by (intro measurable_cong) (auto simp: indicator_def)
hoelzl@40859
   398
  ultimately show "?I \<in> borel_measurable M" by auto
hoelzl@40859
   399
qed
hoelzl@40859
   400
hoelzl@47694
   401
lemma borel_measurable_subalgebra:
hoelzl@41545
   402
  assumes "sets N \<subseteq> sets M" "space N = space M" "f \<in> borel_measurable N"
hoelzl@39092
   403
  shows "f \<in> borel_measurable M"
hoelzl@39092
   404
  using assms unfolding measurable_def by auto
hoelzl@39092
   405
hoelzl@57137
   406
lemma borel_measurable_restrict_space_iff_ereal:
hoelzl@57137
   407
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@57137
   408
  assumes \<Omega>[measurable, simp]: "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
   409
  shows "f \<in> borel_measurable (restrict_space M \<Omega>) \<longleftrightarrow>
hoelzl@57137
   410
    (\<lambda>x. f x * indicator \<Omega> x) \<in> borel_measurable M"
hoelzl@57138
   411
  by (subst measurable_restrict_space_iff)
hoelzl@57138
   412
     (auto simp: indicator_def if_distrib[where f="\<lambda>x. a * x" for a] cong del: if_cong)
hoelzl@57137
   413
hoelzl@57137
   414
lemma borel_measurable_restrict_space_iff:
hoelzl@57137
   415
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@57137
   416
  assumes \<Omega>[measurable, simp]: "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
   417
  shows "f \<in> borel_measurable (restrict_space M \<Omega>) \<longleftrightarrow>
hoelzl@57137
   418
    (\<lambda>x. indicator \<Omega> x *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@57138
   419
  by (subst measurable_restrict_space_iff)
haftmann@57514
   420
     (auto simp: indicator_def if_distrib[where f="\<lambda>x. x *\<^sub>R a" for a] ac_simps cong del: if_cong)
hoelzl@57138
   421
hoelzl@57138
   422
lemma cbox_borel[measurable]: "cbox a b \<in> sets borel"
hoelzl@57138
   423
  by (auto intro: borel_closed)
hoelzl@57138
   424
hoelzl@57447
   425
lemma box_borel[measurable]: "box a b \<in> sets borel"
hoelzl@57447
   426
  by (auto intro: borel_open)
hoelzl@57447
   427
hoelzl@57138
   428
lemma borel_compact: "compact (A::'a::t2_space set) \<Longrightarrow> A \<in> sets borel"
hoelzl@57138
   429
  by (auto intro: borel_closed dest!: compact_imp_closed)
hoelzl@57137
   430
hoelzl@59088
   431
lemma second_countable_borel_measurable:
hoelzl@59088
   432
  fixes X :: "'a::second_countable_topology set set"
hoelzl@59088
   433
  assumes eq: "open = generate_topology X"
hoelzl@59088
   434
  shows "borel = sigma UNIV X"
hoelzl@59088
   435
  unfolding borel_def
hoelzl@59088
   436
proof (intro sigma_eqI sigma_sets_eqI)
hoelzl@59088
   437
  interpret X: sigma_algebra UNIV "sigma_sets UNIV X"
hoelzl@59088
   438
    by (rule sigma_algebra_sigma_sets) simp
hoelzl@59088
   439
hoelzl@59088
   440
  fix S :: "'a set" assume "S \<in> Collect open"
hoelzl@59088
   441
  then have "generate_topology X S"
hoelzl@59088
   442
    by (auto simp: eq)
hoelzl@59088
   443
  then show "S \<in> sigma_sets UNIV X"
hoelzl@59088
   444
  proof induction
hoelzl@59088
   445
    case (UN K)
hoelzl@59088
   446
    then have K: "\<And>k. k \<in> K \<Longrightarrow> open k"
hoelzl@59088
   447
      unfolding eq by auto
hoelzl@59088
   448
    from ex_countable_basis obtain B :: "'a set set" where
hoelzl@59088
   449
      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
   450
      by (auto simp: topological_basis_def)
hoelzl@59088
   451
    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
   452
      by metis
hoelzl@59088
   453
    def U \<equiv> "(\<Union>k\<in>K. m k)"
hoelzl@59088
   454
    with m have "countable U"
wenzelm@61808
   455
      by (intro countable_subset[OF _ \<open>countable B\<close>]) auto
hoelzl@59088
   456
    have "\<Union>U = (\<Union>A\<in>U. A)" by simp
hoelzl@59088
   457
    also have "\<dots> = \<Union>K"
hoelzl@59088
   458
      unfolding U_def UN_simps by (simp add: m)
hoelzl@59088
   459
    finally have "\<Union>U = \<Union>K" .
hoelzl@59088
   460
hoelzl@59088
   461
    have "\<forall>b\<in>U. \<exists>k\<in>K. b \<subseteq> k"
hoelzl@59088
   462
      using m by (auto simp: U_def)
hoelzl@59088
   463
    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
   464
      by metis
hoelzl@59088
   465
    then have "(\<Union>b\<in>U. u b) \<subseteq> \<Union>K" "\<Union>U \<subseteq> (\<Union>b\<in>U. u b)"
hoelzl@59088
   466
      by auto
hoelzl@59088
   467
    then have "\<Union>K = (\<Union>b\<in>U. u b)"
wenzelm@61808
   468
      unfolding \<open>\<Union>U = \<Union>K\<close> by auto
hoelzl@59088
   469
    also have "\<dots> \<in> sigma_sets UNIV X"
wenzelm@61808
   470
      using u UN by (intro X.countable_UN' \<open>countable U\<close>) auto
hoelzl@59088
   471
    finally show "\<Union>K \<in> sigma_sets UNIV X" .
hoelzl@59088
   472
  qed auto
hoelzl@59088
   473
qed (auto simp: eq intro: generate_topology.Basis)
hoelzl@59088
   474
hoelzl@59361
   475
lemma borel_measurable_continuous_on_restrict:
hoelzl@59361
   476
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@59361
   477
  assumes f: "continuous_on A f"
hoelzl@59361
   478
  shows "f \<in> borel_measurable (restrict_space borel A)"
hoelzl@57138
   479
proof (rule borel_measurableI)
hoelzl@57138
   480
  fix S :: "'b set" assume "open S"
hoelzl@59361
   481
  with f obtain T where "f -` S \<inter> A = T \<inter> A" "open T"
hoelzl@59361
   482
    by (metis continuous_on_open_invariant)
hoelzl@59361
   483
  then show "f -` S \<inter> space (restrict_space borel A) \<in> sets (restrict_space borel A)"
hoelzl@59361
   484
    by (force simp add: sets_restrict_space space_restrict_space)
hoelzl@57137
   485
qed
hoelzl@57137
   486
hoelzl@59361
   487
lemma borel_measurable_continuous_on1: "continuous_on UNIV f \<Longrightarrow> f \<in> borel_measurable borel"
hoelzl@59361
   488
  by (drule borel_measurable_continuous_on_restrict) simp
hoelzl@59361
   489
hoelzl@59361
   490
lemma borel_measurable_continuous_on_if:
hoelzl@59415
   491
  "A \<in> sets borel \<Longrightarrow> continuous_on A f \<Longrightarrow> continuous_on (- A) g \<Longrightarrow>
hoelzl@59415
   492
    (\<lambda>x. if x \<in> A then f x else g x) \<in> borel_measurable borel"
hoelzl@59415
   493
  by (auto simp add: measurable_If_restrict_space_iff Collect_neg_eq
hoelzl@59415
   494
           intro!: borel_measurable_continuous_on_restrict)
hoelzl@59361
   495
hoelzl@57275
   496
lemma borel_measurable_continuous_countable_exceptions:
hoelzl@57275
   497
  fixes f :: "'a::t1_space \<Rightarrow> 'b::topological_space"
hoelzl@57275
   498
  assumes X: "countable X"
hoelzl@57275
   499
  assumes "continuous_on (- X) f"
hoelzl@57275
   500
  shows "f \<in> borel_measurable borel"
hoelzl@57275
   501
proof (rule measurable_discrete_difference[OF _ X])
hoelzl@57275
   502
  have "X \<in> sets borel"
hoelzl@57275
   503
    by (rule sets.countable[OF _ X]) auto
hoelzl@57275
   504
  then show "(\<lambda>x. if x \<in> X then undefined else f x) \<in> borel_measurable borel"
hoelzl@57275
   505
    by (intro borel_measurable_continuous_on_if assms continuous_intros)
hoelzl@57275
   506
qed auto
hoelzl@57275
   507
hoelzl@57138
   508
lemma borel_measurable_continuous_on:
hoelzl@57138
   509
  assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
hoelzl@57138
   510
  shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
hoelzl@57138
   511
  using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
hoelzl@57138
   512
hoelzl@57138
   513
lemma borel_measurable_continuous_on_indicator:
hoelzl@57138
   514
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@59415
   515
  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
   516
  by (subst borel_measurable_restrict_space_iff[symmetric])
hoelzl@59415
   517
     (auto intro: borel_measurable_continuous_on_restrict)
hoelzl@50002
   518
immler@50245
   519
lemma borel_eq_countable_basis:
immler@50245
   520
  fixes B::"'a::topological_space set set"
immler@50245
   521
  assumes "countable B"
immler@50245
   522
  assumes "topological_basis B"
immler@50245
   523
  shows "borel = sigma UNIV B"
immler@50087
   524
  unfolding borel_def
immler@50087
   525
proof (intro sigma_eqI sigma_sets_eqI, safe)
immler@50245
   526
  interpret countable_basis using assms by unfold_locales
immler@50245
   527
  fix X::"'a set" assume "open X"
immler@50245
   528
  from open_countable_basisE[OF this] guess B' . note B' = this
hoelzl@51683
   529
  then show "X \<in> sigma_sets UNIV B"
wenzelm@61808
   530
    by (blast intro: sigma_sets_UNION \<open>countable B\<close> countable_subset)
immler@50087
   531
next
immler@50245
   532
  fix b assume "b \<in> B"
immler@50245
   533
  hence "open b" by (rule topological_basis_open[OF assms(2)])
immler@50245
   534
  thus "b \<in> sigma_sets UNIV (Collect open)" by auto
immler@50087
   535
qed simp_all
immler@50087
   536
hoelzl@50526
   537
lemma borel_measurable_Pair[measurable (raw)]:
hoelzl@50881
   538
  fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
hoelzl@50526
   539
  assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50526
   540
  assumes g[measurable]: "g \<in> borel_measurable M"
hoelzl@50526
   541
  shows "(\<lambda>x. (f x, g x)) \<in> borel_measurable M"
hoelzl@50526
   542
proof (subst borel_eq_countable_basis)
hoelzl@50526
   543
  let ?B = "SOME B::'b set set. countable B \<and> topological_basis B"
hoelzl@50526
   544
  let ?C = "SOME B::'c set set. countable B \<and> topological_basis B"
hoelzl@50526
   545
  let ?P = "(\<lambda>(b, c). b \<times> c) ` (?B \<times> ?C)"
hoelzl@50526
   546
  show "countable ?P" "topological_basis ?P"
hoelzl@50526
   547
    by (auto intro!: countable_basis topological_basis_prod is_basis)
hoelzl@38656
   548
hoelzl@50526
   549
  show "(\<lambda>x. (f x, g x)) \<in> measurable M (sigma UNIV ?P)"
hoelzl@50526
   550
  proof (rule measurable_measure_of)
hoelzl@50526
   551
    fix S assume "S \<in> ?P"
hoelzl@50526
   552
    then obtain b c where "b \<in> ?B" "c \<in> ?C" and S: "S = b \<times> c" by auto
hoelzl@50526
   553
    then have borel: "open b" "open c"
hoelzl@50526
   554
      by (auto intro: is_basis topological_basis_open)
hoelzl@50526
   555
    have "(\<lambda>x. (f x, g x)) -` S \<inter> space M = (f -` b \<inter> space M) \<inter> (g -` c \<inter> space M)"
hoelzl@50526
   556
      unfolding S by auto
hoelzl@50526
   557
    also have "\<dots> \<in> sets M"
hoelzl@50526
   558
      using borel by simp
hoelzl@50526
   559
    finally show "(\<lambda>x. (f x, g x)) -` S \<inter> space M \<in> sets M" .
hoelzl@50526
   560
  qed auto
hoelzl@39087
   561
qed
hoelzl@39087
   562
hoelzl@49774
   563
lemma borel_measurable_continuous_Pair:
hoelzl@50881
   564
  fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
hoelzl@50003
   565
  assumes [measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   566
  assumes [measurable]: "g \<in> borel_measurable M"
hoelzl@49774
   567
  assumes H: "continuous_on UNIV (\<lambda>x. H (fst x) (snd x))"
hoelzl@49774
   568
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   569
proof -
hoelzl@49774
   570
  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
   571
  show ?thesis
hoelzl@49774
   572
    unfolding eq by (rule borel_measurable_continuous_on[OF H]) auto
hoelzl@49774
   573
qed
hoelzl@49774
   574
wenzelm@61808
   575
subsection \<open>Borel spaces on order topologies\<close>
hoelzl@59088
   576
hoelzl@59088
   577
hoelzl@59088
   578
lemma borel_Iio:
hoelzl@59088
   579
  "borel = sigma UNIV (range lessThan :: 'a::{linorder_topology, second_countable_topology} set set)"
hoelzl@59088
   580
  unfolding second_countable_borel_measurable[OF open_generated_order]
hoelzl@59088
   581
proof (intro sigma_eqI sigma_sets_eqI)
hoelzl@59088
   582
  from countable_dense_setE guess D :: "'a set" . note D = this
hoelzl@59088
   583
hoelzl@59088
   584
  interpret L: sigma_algebra UNIV "sigma_sets UNIV (range lessThan)"
hoelzl@59088
   585
    by (rule sigma_algebra_sigma_sets) simp
hoelzl@59088
   586
hoelzl@59088
   587
  fix A :: "'a set" assume "A \<in> range lessThan \<union> range greaterThan"
hoelzl@59088
   588
  then obtain y where "A = {y <..} \<or> A = {..< y}"
hoelzl@59088
   589
    by blast
hoelzl@59088
   590
  then show "A \<in> sigma_sets UNIV (range lessThan)"
hoelzl@59088
   591
  proof
hoelzl@59088
   592
    assume A: "A = {y <..}"
hoelzl@59088
   593
    show ?thesis
hoelzl@59088
   594
    proof cases
hoelzl@59088
   595
      assume "\<forall>x>y. \<exists>d. y < d \<and> d < x"
hoelzl@59088
   596
      with D(2)[of "{y <..< x}" for x] have "\<forall>x>y. \<exists>d\<in>D. y < d \<and> d < x"
hoelzl@59088
   597
        by (auto simp: set_eq_iff)
hoelzl@59088
   598
      then have "A = UNIV - (\<Inter>d\<in>{d\<in>D. y < d}. {..< d})"
hoelzl@59088
   599
        by (auto simp: A) (metis less_asym)
hoelzl@59088
   600
      also have "\<dots> \<in> sigma_sets UNIV (range lessThan)"
hoelzl@59088
   601
        using D(1) by (intro L.Diff L.top L.countable_INT'') auto
hoelzl@59088
   602
      finally show ?thesis .
hoelzl@59088
   603
    next
hoelzl@59088
   604
      assume "\<not> (\<forall>x>y. \<exists>d. y < d \<and> d < x)"
hoelzl@59088
   605
      then obtain x where "y < x"  "\<And>d. y < d \<Longrightarrow> \<not> d < x"
hoelzl@59088
   606
        by auto
hoelzl@59088
   607
      then have "A = UNIV - {..< x}"
hoelzl@59088
   608
        unfolding A by (auto simp: not_less[symmetric])
hoelzl@59088
   609
      also have "\<dots> \<in> sigma_sets UNIV (range lessThan)"
hoelzl@59088
   610
        by auto
hoelzl@59088
   611
      finally show ?thesis .
hoelzl@59088
   612
    qed
hoelzl@59088
   613
  qed auto
hoelzl@59088
   614
qed auto
hoelzl@59088
   615
hoelzl@59088
   616
lemma borel_Ioi:
hoelzl@59088
   617
  "borel = sigma UNIV (range greaterThan :: 'a::{linorder_topology, second_countable_topology} set set)"
hoelzl@59088
   618
  unfolding second_countable_borel_measurable[OF open_generated_order]
hoelzl@59088
   619
proof (intro sigma_eqI sigma_sets_eqI)
hoelzl@59088
   620
  from countable_dense_setE guess D :: "'a set" . note D = this
hoelzl@59088
   621
hoelzl@59088
   622
  interpret L: sigma_algebra UNIV "sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   623
    by (rule sigma_algebra_sigma_sets) simp
hoelzl@59088
   624
hoelzl@59088
   625
  fix A :: "'a set" assume "A \<in> range lessThan \<union> range greaterThan"
hoelzl@59088
   626
  then obtain y where "A = {y <..} \<or> A = {..< y}"
hoelzl@59088
   627
    by blast
hoelzl@59088
   628
  then show "A \<in> sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   629
  proof
hoelzl@59088
   630
    assume A: "A = {..< y}"
hoelzl@59088
   631
    show ?thesis
hoelzl@59088
   632
    proof cases
hoelzl@59088
   633
      assume "\<forall>x<y. \<exists>d. x < d \<and> d < y"
hoelzl@59088
   634
      with D(2)[of "{x <..< y}" for x] have "\<forall>x<y. \<exists>d\<in>D. x < d \<and> d < y"
hoelzl@59088
   635
        by (auto simp: set_eq_iff)
hoelzl@59088
   636
      then have "A = UNIV - (\<Inter>d\<in>{d\<in>D. d < y}. {d <..})"
hoelzl@59088
   637
        by (auto simp: A) (metis less_asym)
hoelzl@59088
   638
      also have "\<dots> \<in> sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   639
        using D(1) by (intro L.Diff L.top L.countable_INT'') auto
hoelzl@59088
   640
      finally show ?thesis .
hoelzl@59088
   641
    next
hoelzl@59088
   642
      assume "\<not> (\<forall>x<y. \<exists>d. x < d \<and> d < y)"
hoelzl@59088
   643
      then obtain x where "x < y"  "\<And>d. y > d \<Longrightarrow> x \<ge> d"
hoelzl@59088
   644
        by (auto simp: not_less[symmetric])
hoelzl@59088
   645
      then have "A = UNIV - {x <..}"
hoelzl@59088
   646
        unfolding A Compl_eq_Diff_UNIV[symmetric] by auto
hoelzl@59088
   647
      also have "\<dots> \<in> sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   648
        by auto
hoelzl@59088
   649
      finally show ?thesis .
hoelzl@59088
   650
    qed
hoelzl@59088
   651
  qed auto
hoelzl@59088
   652
qed auto
hoelzl@59088
   653
hoelzl@59088
   654
lemma borel_measurableI_less:
hoelzl@59088
   655
  fixes f :: "'a \<Rightarrow> 'b::{linorder_topology, second_countable_topology}"
hoelzl@59088
   656
  shows "(\<And>y. {x\<in>space M. f x < y} \<in> sets M) \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@59088
   657
  unfolding borel_Iio
hoelzl@59088
   658
  by (rule measurable_measure_of) (auto simp: Int_def conj_commute)
hoelzl@59088
   659
hoelzl@59088
   660
lemma borel_measurableI_greater:
hoelzl@59088
   661
  fixes f :: "'a \<Rightarrow> 'b::{linorder_topology, second_countable_topology}"
hoelzl@59088
   662
  shows "(\<And>y. {x\<in>space M. y < f x} \<in> sets M) \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@59088
   663
  unfolding borel_Ioi
hoelzl@59088
   664
  by (rule measurable_measure_of) (auto simp: Int_def conj_commute)
hoelzl@59088
   665
hoelzl@59088
   666
lemma borel_measurable_SUP[measurable (raw)]:
hoelzl@59088
   667
  fixes F :: "_ \<Rightarrow> _ \<Rightarrow> _::{complete_linorder, linorder_topology, second_countable_topology}"
hoelzl@59088
   668
  assumes [simp]: "countable I"
hoelzl@59088
   669
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> borel_measurable M"
hoelzl@59088
   670
  shows "(\<lambda>x. SUP i:I. F i x) \<in> borel_measurable M"
hoelzl@59088
   671
  by (rule borel_measurableI_greater) (simp add: less_SUP_iff)
hoelzl@59088
   672
hoelzl@59088
   673
lemma borel_measurable_INF[measurable (raw)]:
hoelzl@59088
   674
  fixes F :: "_ \<Rightarrow> _ \<Rightarrow> _::{complete_linorder, linorder_topology, second_countable_topology}"
hoelzl@59088
   675
  assumes [simp]: "countable I"
hoelzl@59088
   676
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> borel_measurable M"
hoelzl@59088
   677
  shows "(\<lambda>x. INF i:I. F i x) \<in> borel_measurable M"
hoelzl@59088
   678
  by (rule borel_measurableI_less) (simp add: INF_less_iff)
hoelzl@59088
   679
hoelzl@59088
   680
lemma borel_measurable_lfp[consumes 1, case_names continuity step]:
hoelzl@59088
   681
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_linorder, linorder_topology, second_countable_topology})"
hoelzl@60172
   682
  assumes "sup_continuous F"
hoelzl@59088
   683
  assumes *: "\<And>f. f \<in> borel_measurable M \<Longrightarrow> F f \<in> borel_measurable M"
hoelzl@59088
   684
  shows "lfp F \<in> borel_measurable M"
hoelzl@59088
   685
proof -
hoelzl@59088
   686
  { fix i have "((F ^^ i) bot) \<in> borel_measurable M"
hoelzl@59088
   687
      by (induct i) (auto intro!: *) }
hoelzl@59088
   688
  then have "(\<lambda>x. SUP i. (F ^^ i) bot x) \<in> borel_measurable M"
hoelzl@59088
   689
    by measurable
hoelzl@59088
   690
  also have "(\<lambda>x. SUP i. (F ^^ i) bot x) = (SUP i. (F ^^ i) bot)"
hoelzl@59088
   691
    by auto
hoelzl@59088
   692
  also have "(SUP i. (F ^^ i) bot) = lfp F"
hoelzl@60172
   693
    by (rule sup_continuous_lfp[symmetric]) fact
hoelzl@59088
   694
  finally show ?thesis .
hoelzl@59088
   695
qed
hoelzl@59088
   696
hoelzl@59088
   697
lemma borel_measurable_gfp[consumes 1, case_names continuity step]:
hoelzl@59088
   698
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_linorder, linorder_topology, second_countable_topology})"
hoelzl@60172
   699
  assumes "inf_continuous F"
hoelzl@59088
   700
  assumes *: "\<And>f. f \<in> borel_measurable M \<Longrightarrow> F f \<in> borel_measurable M"
hoelzl@59088
   701
  shows "gfp F \<in> borel_measurable M"
hoelzl@59088
   702
proof -
hoelzl@59088
   703
  { fix i have "((F ^^ i) top) \<in> borel_measurable M"
hoelzl@59088
   704
      by (induct i) (auto intro!: * simp: bot_fun_def) }
hoelzl@59088
   705
  then have "(\<lambda>x. INF i. (F ^^ i) top x) \<in> borel_measurable M"
hoelzl@59088
   706
    by measurable
hoelzl@59088
   707
  also have "(\<lambda>x. INF i. (F ^^ i) top x) = (INF i. (F ^^ i) top)"
hoelzl@59088
   708
    by auto
hoelzl@59088
   709
  also have "\<dots> = gfp F"
hoelzl@60172
   710
    by (rule inf_continuous_gfp[symmetric]) fact
hoelzl@59088
   711
  finally show ?thesis .
hoelzl@59088
   712
qed
hoelzl@59088
   713
wenzelm@61808
   714
subsection \<open>Borel spaces on euclidean spaces\<close>
hoelzl@50526
   715
hoelzl@50526
   716
lemma borel_measurable_inner[measurable (raw)]:
hoelzl@50881
   717
  fixes f g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_inner}"
hoelzl@50526
   718
  assumes "f \<in> borel_measurable M"
hoelzl@50526
   719
  assumes "g \<in> borel_measurable M"
hoelzl@50526
   720
  shows "(\<lambda>x. f x \<bullet> g x) \<in> borel_measurable M"
hoelzl@50526
   721
  using assms
hoelzl@56371
   722
  by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@50526
   723
hoelzl@50526
   724
lemma [measurable]:
wenzelm@61076
   725
  fixes a b :: "'a::linorder_topology"
hoelzl@50526
   726
  shows lessThan_borel: "{..< a} \<in> sets borel"
hoelzl@50526
   727
    and greaterThan_borel: "{a <..} \<in> sets borel"
hoelzl@50526
   728
    and greaterThanLessThan_borel: "{a<..<b} \<in> sets borel"
hoelzl@50526
   729
    and atMost_borel: "{..a} \<in> sets borel"
hoelzl@50526
   730
    and atLeast_borel: "{a..} \<in> sets borel"
hoelzl@50526
   731
    and atLeastAtMost_borel: "{a..b} \<in> sets borel"
hoelzl@50526
   732
    and greaterThanAtMost_borel: "{a<..b} \<in> sets borel"
hoelzl@50526
   733
    and atLeastLessThan_borel: "{a..<b} \<in> sets borel"
hoelzl@50526
   734
  unfolding greaterThanAtMost_def atLeastLessThan_def
hoelzl@51683
   735
  by (blast intro: borel_open borel_closed open_lessThan open_greaterThan open_greaterThanLessThan
hoelzl@51683
   736
                   closed_atMost closed_atLeast closed_atLeastAtMost)+
hoelzl@51683
   737
immler@54775
   738
notation
immler@54775
   739
  eucl_less (infix "<e" 50)
immler@54775
   740
immler@54775
   741
lemma box_oc: "{x. a <e x \<and> x \<le> b} = {x. a <e x} \<inter> {..b}"
immler@54775
   742
  and box_co: "{x. a \<le> x \<and> x <e b} = {a..} \<inter> {x. x <e b}"
immler@54775
   743
  by auto
immler@54775
   744
hoelzl@51683
   745
lemma eucl_ivals[measurable]:
wenzelm@61076
   746
  fixes a b :: "'a::ordered_euclidean_space"
immler@54775
   747
  shows "{x. x <e a} \<in> sets borel"
immler@54775
   748
    and "{x. a <e x} \<in> sets borel"
hoelzl@51683
   749
    and "{..a} \<in> sets borel"
hoelzl@51683
   750
    and "{a..} \<in> sets borel"
hoelzl@51683
   751
    and "{a..b} \<in> sets borel"
immler@54775
   752
    and  "{x. a <e x \<and> x \<le> b} \<in> sets borel"
immler@54775
   753
    and "{x. a \<le> x \<and>  x <e b} \<in> sets borel"
immler@54775
   754
  unfolding box_oc box_co
immler@54775
   755
  by (auto intro: borel_open borel_closed)
hoelzl@50526
   756
hoelzl@51683
   757
lemma open_Collect_less:
hoelzl@53216
   758
  fixes f g :: "'i::topological_space \<Rightarrow> 'a :: {dense_linorder, linorder_topology}"
hoelzl@51683
   759
  assumes "continuous_on UNIV f"
hoelzl@51683
   760
  assumes "continuous_on UNIV g"
hoelzl@51683
   761
  shows "open {x. f x < g x}"
hoelzl@51683
   762
proof -
hoelzl@51683
   763
  have "open (\<Union>y. {x \<in> UNIV. f x \<in> {..< y}} \<inter> {x \<in> UNIV. g x \<in> {y <..}})" (is "open ?X")
hoelzl@51683
   764
    by (intro open_UN ballI open_Int continuous_open_preimage assms) auto
hoelzl@51683
   765
  also have "?X = {x. f x < g x}"
hoelzl@51683
   766
    by (auto intro: dense)
hoelzl@51683
   767
  finally show ?thesis .
hoelzl@51683
   768
qed
hoelzl@51683
   769
hoelzl@51683
   770
lemma closed_Collect_le:
hoelzl@53216
   771
  fixes f g :: "'i::topological_space \<Rightarrow> 'a :: {dense_linorder, linorder_topology}"
hoelzl@51683
   772
  assumes f: "continuous_on UNIV f"
hoelzl@51683
   773
  assumes g: "continuous_on UNIV g"
hoelzl@51683
   774
  shows "closed {x. f x \<le> g x}"
hoelzl@51683
   775
  using open_Collect_less[OF g f] unfolding not_less[symmetric] Collect_neg_eq open_closed .
hoelzl@51683
   776
hoelzl@50526
   777
lemma borel_measurable_less[measurable]:
hoelzl@53216
   778
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, dense_linorder, linorder_topology}"
hoelzl@51683
   779
  assumes "f \<in> borel_measurable M"
hoelzl@51683
   780
  assumes "g \<in> borel_measurable M"
hoelzl@50526
   781
  shows "{w \<in> space M. f w < g w} \<in> sets M"
hoelzl@50526
   782
proof -
hoelzl@51683
   783
  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
   784
    by auto
hoelzl@51683
   785
  also have "\<dots> \<in> sets M"
hoelzl@51683
   786
    by (intro measurable_sets[OF borel_measurable_Pair borel_open, OF assms open_Collect_less]
hoelzl@56371
   787
              continuous_intros)
hoelzl@51683
   788
  finally show ?thesis .
hoelzl@50526
   789
qed
hoelzl@50526
   790
hoelzl@50526
   791
lemma
hoelzl@53216
   792
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, dense_linorder, linorder_topology}"
hoelzl@50526
   793
  assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50526
   794
  assumes g[measurable]: "g \<in> borel_measurable M"
hoelzl@50526
   795
  shows borel_measurable_le[measurable]: "{w \<in> space M. f w \<le> g w} \<in> sets M"
hoelzl@50526
   796
    and borel_measurable_eq[measurable]: "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@50526
   797
    and borel_measurable_neq: "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
hoelzl@50526
   798
  unfolding eq_iff not_less[symmetric]
hoelzl@50526
   799
  by measurable
hoelzl@50526
   800
hoelzl@62372
   801
lemma
hoelzl@51683
   802
  fixes i :: "'a::{second_countable_topology, real_inner}"
hoelzl@51683
   803
  shows hafspace_less_borel: "{x. a < x \<bullet> i} \<in> sets borel"
hoelzl@51683
   804
    and hafspace_greater_borel: "{x. x \<bullet> i < a} \<in> sets borel"
hoelzl@51683
   805
    and hafspace_less_eq_borel: "{x. a \<le> x \<bullet> i} \<in> sets borel"
hoelzl@51683
   806
    and hafspace_greater_eq_borel: "{x. x \<bullet> i \<le> a} \<in> sets borel"
hoelzl@50526
   807
  by simp_all
hoelzl@50526
   808
hoelzl@50526
   809
subsection "Borel space equals sigma algebras over intervals"
hoelzl@50526
   810
hoelzl@50526
   811
lemma borel_sigma_sets_subset:
hoelzl@50526
   812
  "A \<subseteq> sets borel \<Longrightarrow> sigma_sets UNIV A \<subseteq> sets borel"
hoelzl@50526
   813
  using sets.sigma_sets_subset[of A borel] by simp
hoelzl@50526
   814
hoelzl@50526
   815
lemma borel_eq_sigmaI1:
hoelzl@50526
   816
  fixes F :: "'i \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@50526
   817
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@50526
   818
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV (F ` A))"
hoelzl@50526
   819
  assumes F: "\<And>i. i \<in> A \<Longrightarrow> F i \<in> sets borel"
hoelzl@50526
   820
  shows "borel = sigma UNIV (F ` A)"
hoelzl@50526
   821
  unfolding borel_def
hoelzl@50526
   822
proof (intro sigma_eqI antisym)
hoelzl@50526
   823
  have borel_rev_eq: "sigma_sets UNIV {S::'a set. open S} = sets borel"
hoelzl@50526
   824
    unfolding borel_def by simp
hoelzl@50526
   825
  also have "\<dots> = sigma_sets UNIV X"
hoelzl@50526
   826
    unfolding borel_eq by simp
hoelzl@50526
   827
  also have "\<dots> \<subseteq> sigma_sets UNIV (F`A)"
hoelzl@50526
   828
    using X by (intro sigma_algebra.sigma_sets_subset[OF sigma_algebra_sigma_sets]) auto
hoelzl@50526
   829
  finally show "sigma_sets UNIV {S. open S} \<subseteq> sigma_sets UNIV (F`A)" .
hoelzl@50526
   830
  show "sigma_sets UNIV (F`A) \<subseteq> sigma_sets UNIV {S. open S}"
hoelzl@50526
   831
    unfolding borel_rev_eq using F by (intro borel_sigma_sets_subset) auto
hoelzl@50526
   832
qed auto
hoelzl@50526
   833
hoelzl@50526
   834
lemma borel_eq_sigmaI2:
hoelzl@50526
   835
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   836
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   837
  assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`B)"
hoelzl@50526
   838
  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
   839
  assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
hoelzl@50526
   840
  shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
hoelzl@50526
   841
  using assms
hoelzl@50526
   842
  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
   843
hoelzl@50526
   844
lemma borel_eq_sigmaI3:
hoelzl@50526
   845
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@50526
   846
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@50526
   847
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV ((\<lambda>(i, j). F i j) ` A))"
hoelzl@50526
   848
  assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
hoelzl@50526
   849
  shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
hoelzl@50526
   850
  using assms by (intro borel_eq_sigmaI1[where X=X and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@50526
   851
hoelzl@50526
   852
lemma borel_eq_sigmaI4:
hoelzl@50526
   853
  fixes F :: "'i \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   854
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   855
  assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`A)"
hoelzl@50526
   856
  assumes X: "\<And>i j. (i, j) \<in> A \<Longrightarrow> G i j \<in> sets (sigma UNIV (range F))"
hoelzl@50526
   857
  assumes F: "\<And>i. F i \<in> sets borel"
hoelzl@50526
   858
  shows "borel = sigma UNIV (range F)"
hoelzl@50526
   859
  using assms by (intro borel_eq_sigmaI1[where X="(\<lambda>(i, j). G i j) ` A" and F=F]) auto
hoelzl@50526
   860
hoelzl@50526
   861
lemma borel_eq_sigmaI5:
hoelzl@50526
   862
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and G :: "'l \<Rightarrow> 'a::topological_space set"
hoelzl@50526
   863
  assumes borel_eq: "borel = sigma UNIV (range G)"
hoelzl@50526
   864
  assumes X: "\<And>i. G i \<in> sets (sigma UNIV (range (\<lambda>(i, j). F i j)))"
hoelzl@50526
   865
  assumes F: "\<And>i j. F i j \<in> sets borel"
hoelzl@50526
   866
  shows "borel = sigma UNIV (range (\<lambda>(i, j). F i j))"
hoelzl@50526
   867
  using assms by (intro borel_eq_sigmaI1[where X="range G" and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@50526
   868
hoelzl@50526
   869
lemma borel_eq_box:
wenzelm@61076
   870
  "borel = sigma UNIV (range (\<lambda> (a, b). box a b :: 'a :: euclidean_space set))"
hoelzl@50526
   871
    (is "_ = ?SIGMA")
hoelzl@50526
   872
proof (rule borel_eq_sigmaI1[OF borel_def])
hoelzl@50526
   873
  fix M :: "'a set" assume "M \<in> {S. open S}"
hoelzl@50526
   874
  then have "open M" by simp
hoelzl@50526
   875
  show "M \<in> ?SIGMA"
wenzelm@61808
   876
    apply (subst open_UNION_box[OF \<open>open M\<close>])
hoelzl@50526
   877
    apply (safe intro!: sets.countable_UN' countable_PiE countable_Collect)
hoelzl@50526
   878
    apply (auto intro: countable_rat)
hoelzl@50526
   879
    done
hoelzl@50526
   880
qed (auto simp: box_def)
hoelzl@50526
   881
hoelzl@50526
   882
lemma halfspace_gt_in_halfspace:
hoelzl@50526
   883
  assumes i: "i \<in> A"
hoelzl@62372
   884
  shows "{x::'a. a < x \<bullet> i} \<in>
wenzelm@61076
   885
    sigma_sets UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> A))"
hoelzl@50526
   886
  (is "?set \<in> ?SIGMA")
hoelzl@50526
   887
proof -
hoelzl@50526
   888
  interpret sigma_algebra UNIV ?SIGMA
hoelzl@50526
   889
    by (intro sigma_algebra_sigma_sets) simp_all
wenzelm@61076
   890
  have *: "?set = (\<Union>n. UNIV - {x::'a. x \<bullet> i < a + 1 / real (Suc n)})"
lp15@61609
   891
  proof (safe, simp_all add: not_less del: of_nat_Suc)
hoelzl@50526
   892
    fix x :: 'a assume "a < x \<bullet> i"
hoelzl@50526
   893
    with reals_Archimedean[of "x \<bullet> i - a"]
hoelzl@50526
   894
    obtain n where "a + 1 / real (Suc n) < x \<bullet> i"
hoelzl@59361
   895
      by (auto simp: field_simps)
hoelzl@50526
   896
    then show "\<exists>n. a + 1 / real (Suc n) \<le> x \<bullet> i"
hoelzl@50526
   897
      by (blast intro: less_imp_le)
hoelzl@50526
   898
  next
hoelzl@50526
   899
    fix x n
hoelzl@50526
   900
    have "a < a + 1 / real (Suc n)" by auto
hoelzl@50526
   901
    also assume "\<dots> \<le> x"
hoelzl@50526
   902
    finally show "a < x" .
hoelzl@50526
   903
  qed
hoelzl@50526
   904
  show "?set \<in> ?SIGMA" unfolding *
haftmann@61424
   905
    by (auto intro!: Diff sigma_sets_Inter i)
hoelzl@50526
   906
qed
hoelzl@50526
   907
hoelzl@50526
   908
lemma borel_eq_halfspace_less:
hoelzl@50526
   909
  "borel = sigma UNIV ((\<lambda>(a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> Basis))"
hoelzl@50526
   910
  (is "_ = ?SIGMA")
hoelzl@50526
   911
proof (rule borel_eq_sigmaI2[OF borel_eq_box])
hoelzl@50526
   912
  fix a b :: 'a
hoelzl@50526
   913
  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
   914
    by (auto simp: box_def)
hoelzl@50526
   915
  also have "\<dots> \<in> sets ?SIGMA"
hoelzl@50526
   916
    by (intro sets.sets_Collect_conj sets.sets_Collect_finite_All sets.sets_Collect_const)
hoelzl@50526
   917
       (auto intro!: halfspace_gt_in_halfspace countable_PiE countable_rat)
hoelzl@50526
   918
  finally show "box a b \<in> sets ?SIGMA" .
hoelzl@50526
   919
qed auto
hoelzl@50526
   920
hoelzl@50526
   921
lemma borel_eq_halfspace_le:
hoelzl@50526
   922
  "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i \<le> a}) ` (UNIV \<times> Basis))"
hoelzl@50526
   923
  (is "_ = ?SIGMA")
hoelzl@50526
   924
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@50526
   925
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   926
  then have i: "i \<in> Basis" by auto
hoelzl@50526
   927
  have *: "{x::'a. x\<bullet>i < a} = (\<Union>n. {x. x\<bullet>i \<le> a - 1/real (Suc n)})"
lp15@61609
   928
  proof (safe, simp_all del: of_nat_Suc)
hoelzl@50526
   929
    fix x::'a assume *: "x\<bullet>i < a"
hoelzl@50526
   930
    with reals_Archimedean[of "a - x\<bullet>i"]
hoelzl@50526
   931
    obtain n where "x \<bullet> i < a - 1 / (real (Suc n))"
hoelzl@59361
   932
      by (auto simp: field_simps)
hoelzl@50526
   933
    then show "\<exists>n. x \<bullet> i \<le> a - 1 / (real (Suc n))"
hoelzl@50526
   934
      by (blast intro: less_imp_le)
hoelzl@50526
   935
  next
hoelzl@50526
   936
    fix x::'a and n
hoelzl@50526
   937
    assume "x\<bullet>i \<le> a - 1 / real (Suc n)"
hoelzl@50526
   938
    also have "\<dots> < a" by auto
hoelzl@50526
   939
    finally show "x\<bullet>i < a" .
hoelzl@50526
   940
  qed
hoelzl@50526
   941
  show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
hoelzl@59361
   942
    by (intro sets.countable_UN) (auto intro: i)
hoelzl@50526
   943
qed auto
hoelzl@50526
   944
hoelzl@50526
   945
lemma borel_eq_halfspace_ge:
wenzelm@61076
   946
  "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. a \<le> x \<bullet> i}) ` (UNIV \<times> Basis))"
hoelzl@50526
   947
  (is "_ = ?SIGMA")
hoelzl@50526
   948
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@50526
   949
  fix a :: real and i :: 'a assume i: "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   950
  have *: "{x::'a. x\<bullet>i < a} = space ?SIGMA - {x::'a. a \<le> x\<bullet>i}" by auto
hoelzl@50526
   951
  show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
hoelzl@59361
   952
    using i by (intro sets.compl_sets) auto
hoelzl@50526
   953
qed auto
hoelzl@50526
   954
hoelzl@50526
   955
lemma borel_eq_halfspace_greater:
wenzelm@61076
   956
  "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. a < x \<bullet> i}) ` (UNIV \<times> Basis))"
hoelzl@50526
   957
  (is "_ = ?SIGMA")
hoelzl@50526
   958
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
hoelzl@50526
   959
  fix a :: real and i :: 'a assume "(a, i) \<in> (UNIV \<times> Basis)"
hoelzl@50526
   960
  then have i: "i \<in> Basis" by auto
hoelzl@50526
   961
  have *: "{x::'a. x\<bullet>i \<le> a} = space ?SIGMA - {x::'a. a < x\<bullet>i}" by auto
hoelzl@50526
   962
  show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@59361
   963
    by (intro sets.compl_sets) (auto intro: i)
hoelzl@50526
   964
qed auto
hoelzl@50526
   965
hoelzl@50526
   966
lemma borel_eq_atMost:
wenzelm@61076
   967
  "borel = sigma UNIV (range (\<lambda>a. {..a::'a::ordered_euclidean_space}))"
hoelzl@50526
   968
  (is "_ = ?SIGMA")
hoelzl@50526
   969
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@50526
   970
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   971
  then have "i \<in> Basis" by auto
hoelzl@50526
   972
  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
   973
  proof (safe, simp_all add: eucl_le[where 'a='a] split: split_if_asm)
hoelzl@50526
   974
    fix x :: 'a
hoelzl@50526
   975
    from real_arch_simple[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"] guess k::nat ..
hoelzl@50526
   976
    then have "\<And>i. i \<in> Basis \<Longrightarrow> x\<bullet>i \<le> real k"
hoelzl@50526
   977
      by (subst (asm) Max_le_iff) auto
hoelzl@50526
   978
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia \<le> real k"
hoelzl@50526
   979
      by (auto intro!: exI[of _ k])
hoelzl@50526
   980
  qed
hoelzl@50526
   981
  show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@59361
   982
    by (intro sets.countable_UN) auto
hoelzl@50526
   983
qed auto
hoelzl@50526
   984
hoelzl@50526
   985
lemma borel_eq_greaterThan:
wenzelm@61076
   986
  "borel = sigma UNIV (range (\<lambda>a::'a::ordered_euclidean_space. {x. a <e x}))"
hoelzl@50526
   987
  (is "_ = ?SIGMA")
hoelzl@50526
   988
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@50526
   989
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
   990
  then have i: "i \<in> Basis" by auto
hoelzl@50526
   991
  have "{x::'a. x\<bullet>i \<le> a} = UNIV - {x::'a. a < x\<bullet>i}" by auto
hoelzl@50526
   992
  also have *: "{x::'a. a < x\<bullet>i} =
immler@54775
   993
      (\<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
   994
  proof (safe, simp_all add: eucl_less_def split: split_if_asm)
hoelzl@50526
   995
    fix x :: 'a
hoelzl@50526
   996
    from reals_Archimedean2[of "Max ((\<lambda>i. -x\<bullet>i)`Basis)"]
hoelzl@50526
   997
    guess k::nat .. note k = this
hoelzl@50526
   998
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
   999
      then have "-x\<bullet>i < real k"
hoelzl@50526
  1000
        using k by (subst (asm) Max_less_iff) auto
hoelzl@50526
  1001
      then have "- real k < x\<bullet>i" by simp }
hoelzl@50526
  1002
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> -real k < x \<bullet> ia"
hoelzl@50526
  1003
      by (auto intro!: exI[of _ k])
hoelzl@50526
  1004
  qed
hoelzl@50526
  1005
  finally show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA"
hoelzl@50526
  1006
    apply (simp only:)
hoelzl@59361
  1007
    apply (intro sets.countable_UN sets.Diff)
hoelzl@50526
  1008
    apply (auto intro: sigma_sets_top)
hoelzl@50526
  1009
    done
hoelzl@50526
  1010
qed auto
hoelzl@50526
  1011
hoelzl@50526
  1012
lemma borel_eq_lessThan:
wenzelm@61076
  1013
  "borel = sigma UNIV (range (\<lambda>a::'a::ordered_euclidean_space. {x. x <e a}))"
hoelzl@50526
  1014
  (is "_ = ?SIGMA")
hoelzl@50526
  1015
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_ge])
hoelzl@50526
  1016
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
  1017
  then have i: "i \<in> Basis" by auto
hoelzl@50526
  1018
  have "{x::'a. a \<le> x\<bullet>i} = UNIV - {x::'a. x\<bullet>i < a}" by auto
wenzelm@61808
  1019
  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 \<open>i\<in> Basis\<close>
immler@54775
  1020
  proof (safe, simp_all add: eucl_less_def split: split_if_asm)
hoelzl@50526
  1021
    fix x :: 'a
hoelzl@50526
  1022
    from reals_Archimedean2[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"]
hoelzl@50526
  1023
    guess k::nat .. note k = this
hoelzl@50526
  1024
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
  1025
      then have "x\<bullet>i < real k"
hoelzl@50526
  1026
        using k by (subst (asm) Max_less_iff) auto
hoelzl@50526
  1027
      then have "x\<bullet>i < real k" by simp }
hoelzl@50526
  1028
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia < real k"
hoelzl@50526
  1029
      by (auto intro!: exI[of _ k])
hoelzl@50526
  1030
  qed
hoelzl@50526
  1031
  finally show "{x. a \<le> x\<bullet>i} \<in> ?SIGMA"
hoelzl@50526
  1032
    apply (simp only:)
hoelzl@59361
  1033
    apply (intro sets.countable_UN sets.Diff)
immler@54775
  1034
    apply (auto intro: sigma_sets_top )
hoelzl@50526
  1035
    done
hoelzl@50526
  1036
qed auto
hoelzl@50526
  1037
hoelzl@50526
  1038
lemma borel_eq_atLeastAtMost:
wenzelm@61076
  1039
  "borel = sigma UNIV (range (\<lambda>(a,b). {a..b} ::'a::ordered_euclidean_space set))"
hoelzl@50526
  1040
  (is "_ = ?SIGMA")
hoelzl@50526
  1041
proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
hoelzl@50526
  1042
  fix a::'a
hoelzl@50526
  1043
  have *: "{..a} = (\<Union>n::nat. {- real n *\<^sub>R One .. a})"
hoelzl@50526
  1044
  proof (safe, simp_all add: eucl_le[where 'a='a])
hoelzl@50526
  1045
    fix x :: 'a
hoelzl@50526
  1046
    from real_arch_simple[of "Max ((\<lambda>i. - x\<bullet>i)`Basis)"]
hoelzl@50526
  1047
    guess k::nat .. note k = this
hoelzl@50526
  1048
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
  1049
      with k have "- x\<bullet>i \<le> real k"
hoelzl@50526
  1050
        by (subst (asm) Max_le_iff) (auto simp: field_simps)
hoelzl@50526
  1051
      then have "- real k \<le> x\<bullet>i" by simp }
hoelzl@50526
  1052
    then show "\<exists>n::nat. \<forall>i\<in>Basis. - real n \<le> x \<bullet> i"
hoelzl@50526
  1053
      by (auto intro!: exI[of _ k])
hoelzl@50526
  1054
  qed
hoelzl@50526
  1055
  show "{..a} \<in> ?SIGMA" unfolding *
hoelzl@59361
  1056
    by (intro sets.countable_UN)
hoelzl@50526
  1057
       (auto intro!: sigma_sets_top)
hoelzl@50526
  1058
qed auto
hoelzl@50526
  1059
hoelzl@57447
  1060
lemma borel_sigma_sets_Ioc: "borel = sigma UNIV (range (\<lambda>(a, b). {a <.. b::real}))"
hoelzl@57447
  1061
proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
hoelzl@57447
  1062
  fix i :: real
hoelzl@57447
  1063
  have "{..i} = (\<Union>j::nat. {-j <.. i})"
hoelzl@57447
  1064
    by (auto simp: minus_less_iff reals_Archimedean2)
hoelzl@57447
  1065
  also have "\<dots> \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))"
hoelzl@62372
  1066
    by (intro sets.countable_nat_UN) auto
hoelzl@57447
  1067
  finally show "{..i} \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))" .
hoelzl@57447
  1068
qed simp
hoelzl@57447
  1069
immler@54775
  1070
lemma eucl_lessThan: "{x::real. x <e a} = lessThan a"
immler@54775
  1071
  by (simp add: eucl_less_def lessThan_def)
immler@54775
  1072
hoelzl@50526
  1073
lemma borel_eq_atLeastLessThan:
hoelzl@50526
  1074
  "borel = sigma UNIV (range (\<lambda>(a, b). {a ..< b :: real}))" (is "_ = ?SIGMA")
hoelzl@50526
  1075
proof (rule borel_eq_sigmaI5[OF borel_eq_lessThan])
hoelzl@50526
  1076
  have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
hoelzl@50526
  1077
  fix x :: real
hoelzl@50526
  1078
  have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
hoelzl@50526
  1079
    by (auto simp: move_uminus real_arch_simple)
immler@54775
  1080
  then show "{y. y <e x} \<in> ?SIGMA"
hoelzl@59361
  1081
    by (auto intro: sigma_sets.intros(2-) simp: eucl_lessThan)
hoelzl@50526
  1082
qed auto
hoelzl@50526
  1083
hoelzl@50526
  1084
lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
hoelzl@50526
  1085
  unfolding borel_def
hoelzl@50526
  1086
proof (intro sigma_eqI sigma_sets_eqI, safe)
hoelzl@50526
  1087
  fix x :: "'a set" assume "open x"
hoelzl@50526
  1088
  hence "x = UNIV - (UNIV - x)" by auto
hoelzl@50526
  1089
  also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
wenzelm@61808
  1090
    by (force intro: sigma_sets.Compl simp: \<open>open x\<close>)
hoelzl@50526
  1091
  finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
hoelzl@50526
  1092
next
hoelzl@50526
  1093
  fix x :: "'a set" assume "closed x"
hoelzl@50526
  1094
  hence "x = UNIV - (UNIV - x)" by auto
hoelzl@50526
  1095
  also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
wenzelm@61808
  1096
    by (force intro: sigma_sets.Compl simp: \<open>closed x\<close>)
hoelzl@50526
  1097
  finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
hoelzl@50526
  1098
qed simp_all
hoelzl@50526
  1099
hoelzl@50526
  1100
lemma borel_measurable_halfspacesI:
wenzelm@61076
  1101
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1102
  assumes F: "borel = sigma UNIV (F ` (UNIV \<times> Basis))"
hoelzl@62372
  1103
  and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M"
hoelzl@50526
  1104
  shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a::real. S a i \<in> sets M)"
hoelzl@50526
  1105
proof safe
hoelzl@50526
  1106
  fix a :: real and i :: 'b assume i: "i \<in> Basis" and f: "f \<in> borel_measurable M"
hoelzl@50526
  1107
  then show "S a i \<in> sets M" unfolding assms
hoelzl@50526
  1108
    by (auto intro!: measurable_sets simp: assms(1))
hoelzl@50526
  1109
next
hoelzl@50526
  1110
  assume a: "\<forall>i\<in>Basis. \<forall>a. S a i \<in> sets M"
hoelzl@50526
  1111
  then show "f \<in> borel_measurable M"
hoelzl@50526
  1112
    by (auto intro!: measurable_measure_of simp: S_eq F)
hoelzl@50526
  1113
qed
hoelzl@50526
  1114
hoelzl@50526
  1115
lemma borel_measurable_iff_halfspace_le:
wenzelm@61076
  1116
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1117
  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
  1118
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_le]) auto
hoelzl@50526
  1119
hoelzl@50526
  1120
lemma borel_measurable_iff_halfspace_less:
wenzelm@61076
  1121
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1122
  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
  1123
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_less]) auto
hoelzl@50526
  1124
hoelzl@50526
  1125
lemma borel_measurable_iff_halfspace_ge:
wenzelm@61076
  1126
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1127
  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
  1128
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_ge]) auto
hoelzl@50526
  1129
hoelzl@50526
  1130
lemma borel_measurable_iff_halfspace_greater:
wenzelm@61076
  1131
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1132
  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
  1133
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_greater]) auto
hoelzl@50526
  1134
hoelzl@50526
  1135
lemma borel_measurable_iff_le:
hoelzl@50526
  1136
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w \<le> a} \<in> sets M)"
hoelzl@50526
  1137
  using borel_measurable_iff_halfspace_le[where 'c=real] by simp
hoelzl@50526
  1138
hoelzl@50526
  1139
lemma borel_measurable_iff_less:
hoelzl@50526
  1140
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w < a} \<in> sets M)"
hoelzl@50526
  1141
  using borel_measurable_iff_halfspace_less[where 'c=real] by simp
hoelzl@50526
  1142
hoelzl@50526
  1143
lemma borel_measurable_iff_ge:
hoelzl@50526
  1144
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a \<le> f w} \<in> sets M)"
hoelzl@50526
  1145
  using borel_measurable_iff_halfspace_ge[where 'c=real]
hoelzl@50526
  1146
  by simp
hoelzl@50526
  1147
hoelzl@50526
  1148
lemma borel_measurable_iff_greater:
hoelzl@50526
  1149
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a < f w} \<in> sets M)"
hoelzl@50526
  1150
  using borel_measurable_iff_halfspace_greater[where 'c=real] by simp
hoelzl@50526
  1151
hoelzl@50526
  1152
lemma borel_measurable_euclidean_space:
hoelzl@50526
  1153
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1154
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M)"
hoelzl@50526
  1155
proof safe
hoelzl@50526
  1156
  assume f: "\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M"
hoelzl@50526
  1157
  then show "f \<in> borel_measurable M"
hoelzl@50526
  1158
    by (subst borel_measurable_iff_halfspace_le) auto
hoelzl@50526
  1159
qed auto
hoelzl@50526
  1160
hoelzl@62083
  1161
lemma borel_set_induct[consumes 1, case_names empty interval compl union]:
hoelzl@62372
  1162
  assumes "A \<in> sets borel"
hoelzl@62083
  1163
  assumes empty: "P {}" and int: "\<And>a b. a \<le> b \<Longrightarrow> P {a..b}" and compl: "\<And>A. A \<in> sets borel \<Longrightarrow> P A \<Longrightarrow> P (-A)" and
hoelzl@62083
  1164
          un: "\<And>f. disjoint_family f \<Longrightarrow> (\<And>i. f i \<in> sets borel) \<Longrightarrow>  (\<And>i. P (f i)) \<Longrightarrow> P (\<Union>i::nat. f i)"
hoelzl@62083
  1165
  shows "P (A::real set)"
hoelzl@62083
  1166
proof-
hoelzl@62083
  1167
  let ?G = "range (\<lambda>(a,b). {a..b::real})"
hoelzl@62372
  1168
  have "Int_stable ?G" "?G \<subseteq> Pow UNIV" "A \<in> sigma_sets UNIV ?G"
hoelzl@62083
  1169
      using assms(1) by (auto simp add: borel_eq_atLeastAtMost Int_stable_def)
hoelzl@62083
  1170
  thus ?thesis
hoelzl@62372
  1171
  proof (induction rule: sigma_sets_induct_disjoint)
hoelzl@62083
  1172
    case (union f)
hoelzl@62083
  1173
      from union.hyps(2) have "\<And>i. f i \<in> sets borel" by (auto simp: borel_eq_atLeastAtMost)
hoelzl@62083
  1174
      with union show ?case by (auto intro: un)
hoelzl@62083
  1175
  next
hoelzl@62083
  1176
    case (basic A)
hoelzl@62083
  1177
    then obtain a b where "A = {a .. b}" by auto
hoelzl@62083
  1178
    then show ?case
hoelzl@62083
  1179
      by (cases "a \<le> b") (auto intro: int empty)
hoelzl@62083
  1180
  qed (auto intro: empty compl simp: Compl_eq_Diff_UNIV[symmetric] borel_eq_atLeastAtMost)
hoelzl@62083
  1181
qed
hoelzl@62083
  1182
hoelzl@50526
  1183
subsection "Borel measurable operators"
hoelzl@50526
  1184
hoelzl@56993
  1185
lemma borel_measurable_norm[measurable]: "norm \<in> borel_measurable borel"
hoelzl@56993
  1186
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@56993
  1187
hoelzl@57275
  1188
lemma borel_measurable_sgn [measurable]: "(sgn::'a::real_normed_vector \<Rightarrow> 'a) \<in> borel_measurable borel"
hoelzl@57275
  1189
  by (rule borel_measurable_continuous_countable_exceptions[where X="{0}"])
hoelzl@57275
  1190
     (auto intro!: continuous_on_sgn continuous_on_id)
hoelzl@57275
  1191
hoelzl@50526
  1192
lemma borel_measurable_uminus[measurable (raw)]:
hoelzl@51683
  1193
  fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@50526
  1194
  assumes g: "g \<in> borel_measurable M"
hoelzl@50526
  1195
  shows "(\<lambda>x. - g x) \<in> borel_measurable M"
hoelzl@56371
  1196
  by (rule borel_measurable_continuous_on[OF _ g]) (intro continuous_intros)
hoelzl@50526
  1197
hoelzl@50003
  1198
lemma borel_measurable_add[measurable (raw)]:
hoelzl@51683
  1199
  fixes f g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@49774
  1200
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1201
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1202
  shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@56371
  1203
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@49774
  1204
hoelzl@50003
  1205
lemma borel_measurable_setsum[measurable (raw)]:
hoelzl@51683
  1206
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@49774
  1207
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@49774
  1208
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@49774
  1209
proof cases
hoelzl@49774
  1210
  assume "finite S"
hoelzl@49774
  1211
  thus ?thesis using assms by induct auto
hoelzl@49774
  1212
qed simp
hoelzl@49774
  1213
hoelzl@50003
  1214
lemma borel_measurable_diff[measurable (raw)]:
hoelzl@51683
  1215
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@49774
  1216
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1217
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1218
  shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
haftmann@54230
  1219
  using borel_measurable_add [of f M "- g"] assms by (simp add: fun_Compl_def)
hoelzl@49774
  1220
hoelzl@50003
  1221
lemma borel_measurable_times[measurable (raw)]:
hoelzl@51683
  1222
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_algebra}"
hoelzl@49774
  1223
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1224
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1225
  shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@56371
  1226
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@51683
  1227
hoelzl@51683
  1228
lemma borel_measurable_setprod[measurable (raw)]:
hoelzl@51683
  1229
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> 'b::{second_countable_topology, real_normed_field}"
hoelzl@51683
  1230
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@51683
  1231
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@51683
  1232
proof cases
hoelzl@51683
  1233
  assume "finite S"
hoelzl@51683
  1234
  thus ?thesis using assms by induct auto
hoelzl@51683
  1235
qed simp
hoelzl@49774
  1236
hoelzl@50003
  1237
lemma borel_measurable_dist[measurable (raw)]:
hoelzl@51683
  1238
  fixes g f :: "'a \<Rightarrow> 'b::{second_countable_topology, metric_space}"
hoelzl@49774
  1239
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1240
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1241
  shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
hoelzl@56371
  1242
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@62372
  1243
hoelzl@50002
  1244
lemma borel_measurable_scaleR[measurable (raw)]:
hoelzl@51683
  1245
  fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@50002
  1246
  assumes f: "f \<in> borel_measurable M"
hoelzl@50002
  1247
  assumes g: "g \<in> borel_measurable M"
hoelzl@50002
  1248
  shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
hoelzl@56371
  1249
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@50002
  1250
hoelzl@47694
  1251
lemma affine_borel_measurable_vector:
hoelzl@38656
  1252
  fixes f :: "'a \<Rightarrow> 'x::real_normed_vector"
hoelzl@38656
  1253
  assumes "f \<in> borel_measurable M"
hoelzl@38656
  1254
  shows "(\<lambda>x. a + b *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@38656
  1255
proof (rule borel_measurableI)
hoelzl@38656
  1256
  fix S :: "'x set" assume "open S"
hoelzl@38656
  1257
  show "(\<lambda>x. a + b *\<^sub>R f x) -` S \<inter> space M \<in> sets M"
hoelzl@38656
  1258
  proof cases
hoelzl@38656
  1259
    assume "b \<noteq> 0"
wenzelm@61808
  1260
    with \<open>open S\<close> have "open ((\<lambda>x. (- a + x) /\<^sub>R b) ` S)" (is "open ?S")
haftmann@54230
  1261
      using open_affinity [of S "inverse b" "- a /\<^sub>R b"]
haftmann@54230
  1262
      by (auto simp: algebra_simps)
hoelzl@47694
  1263
    hence "?S \<in> sets borel" by auto
hoelzl@38656
  1264
    moreover
wenzelm@61808
  1265
    from \<open>b \<noteq> 0\<close> have "(\<lambda>x. a + b *\<^sub>R f x) -` S = f -` ?S"
hoelzl@38656
  1266
      apply auto by (rule_tac x="a + b *\<^sub>R f x" in image_eqI, simp_all)
hoelzl@40859
  1267
    ultimately show ?thesis using assms unfolding in_borel_measurable_borel
hoelzl@38656
  1268
      by auto
hoelzl@38656
  1269
  qed simp
hoelzl@38656
  1270
qed
hoelzl@38656
  1271
hoelzl@50002
  1272
lemma borel_measurable_const_scaleR[measurable (raw)]:
hoelzl@50002
  1273
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. b *\<^sub>R f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
  1274
  using affine_borel_measurable_vector[of f M 0 b] by simp
hoelzl@38656
  1275
hoelzl@50002
  1276
lemma borel_measurable_const_add[measurable (raw)]:
hoelzl@50002
  1277
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. a + f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
  1278
  using affine_borel_measurable_vector[of f M a 1] by simp
hoelzl@50002
  1279
hoelzl@50003
  1280
lemma borel_measurable_inverse[measurable (raw)]:
hoelzl@57275
  1281
  fixes f :: "'a \<Rightarrow> 'b::real_normed_div_algebra"
hoelzl@49774
  1282
  assumes f: "f \<in> borel_measurable M"
hoelzl@35692
  1283
  shows "(\<lambda>x. inverse (f x)) \<in> borel_measurable M"
hoelzl@57275
  1284
  apply (rule measurable_compose[OF f])
hoelzl@57275
  1285
  apply (rule borel_measurable_continuous_countable_exceptions[of "{0}"])
hoelzl@57275
  1286
  apply (auto intro!: continuous_on_inverse continuous_on_id)
hoelzl@57275
  1287
  done
hoelzl@35692
  1288
hoelzl@50003
  1289
lemma borel_measurable_divide[measurable (raw)]:
hoelzl@51683
  1290
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow>
hoelzl@57275
  1291
    (\<lambda>x. f x / g x::'b::{second_countable_topology, real_normed_div_algebra}) \<in> borel_measurable M"
hoelzl@57275
  1292
  by (simp add: divide_inverse)
hoelzl@38656
  1293
hoelzl@50003
  1294
lemma borel_measurable_max[measurable (raw)]:
hoelzl@53216
  1295
  "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
  1296
  by (simp add: max_def)
hoelzl@38656
  1297
hoelzl@50003
  1298
lemma borel_measurable_min[measurable (raw)]:
hoelzl@53216
  1299
  "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
  1300
  by (simp add: min_def)
hoelzl@38656
  1301
hoelzl@57235
  1302
lemma borel_measurable_Min[measurable (raw)]:
hoelzl@57235
  1303
  "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
  1304
proof (induct I rule: finite_induct)
hoelzl@57235
  1305
  case (insert i I) then show ?case
hoelzl@57235
  1306
    by (cases "I = {}") auto
hoelzl@57235
  1307
qed auto
hoelzl@57235
  1308
hoelzl@57235
  1309
lemma borel_measurable_Max[measurable (raw)]:
hoelzl@57235
  1310
  "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
  1311
proof (induct I rule: finite_induct)
hoelzl@57235
  1312
  case (insert i I) then show ?case
hoelzl@57235
  1313
    by (cases "I = {}") auto
hoelzl@57235
  1314
qed auto
hoelzl@57235
  1315
hoelzl@50003
  1316
lemma borel_measurable_abs[measurable (raw)]:
hoelzl@50003
  1317
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. \<bar>f x :: real\<bar>) \<in> borel_measurable M"
hoelzl@50003
  1318
  unfolding abs_real_def by simp
hoelzl@38656
  1319
hoelzl@50003
  1320
lemma borel_measurable_nth[measurable (raw)]:
hoelzl@41026
  1321
  "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
hoelzl@50526
  1322
  by (simp add: cart_eq_inner_axis)
hoelzl@41026
  1323
hoelzl@47694
  1324
lemma convex_measurable:
hoelzl@59415
  1325
  fixes A :: "'a :: euclidean_space set"
hoelzl@62372
  1326
  shows "X \<in> borel_measurable M \<Longrightarrow> X ` space M \<subseteq> A \<Longrightarrow> open A \<Longrightarrow> convex_on A q \<Longrightarrow>
hoelzl@59415
  1327
    (\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@59415
  1328
  by (rule measurable_compose[where f=X and N="restrict_space borel A"])
hoelzl@59415
  1329
     (auto intro!: borel_measurable_continuous_on_restrict convex_on_continuous measurable_restrict_space2)
hoelzl@41830
  1330
hoelzl@50003
  1331
lemma borel_measurable_ln[measurable (raw)]:
hoelzl@49774
  1332
  assumes f: "f \<in> borel_measurable M"
lp15@60017
  1333
  shows "(\<lambda>x. ln (f x :: real)) \<in> borel_measurable M"
hoelzl@57275
  1334
  apply (rule measurable_compose[OF f])
hoelzl@57275
  1335
  apply (rule borel_measurable_continuous_countable_exceptions[of "{0}"])
hoelzl@57275
  1336
  apply (auto intro!: continuous_on_ln continuous_on_id)
hoelzl@57275
  1337
  done
hoelzl@41830
  1338
hoelzl@50003
  1339
lemma borel_measurable_log[measurable (raw)]:
hoelzl@50002
  1340
  "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
  1341
  unfolding log_def by auto
hoelzl@41830
  1342
immler@58656
  1343
lemma borel_measurable_exp[measurable]:
immler@58656
  1344
  "(exp::'a::{real_normed_field,banach}\<Rightarrow>'a) \<in> borel_measurable borel"
hoelzl@51478
  1345
  by (intro borel_measurable_continuous_on1 continuous_at_imp_continuous_on ballI isCont_exp)
hoelzl@50419
  1346
hoelzl@50002
  1347
lemma measurable_real_floor[measurable]:
hoelzl@50002
  1348
  "(floor :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@47761
  1349
proof -
lp15@61609
  1350
  have "\<And>a x. \<lfloor>x\<rfloor> = a \<longleftrightarrow> (real_of_int a \<le> x \<and> x < real_of_int (a + 1))"
hoelzl@50002
  1351
    by (auto intro: floor_eq2)
hoelzl@50002
  1352
  then show ?thesis
hoelzl@50002
  1353
    by (auto simp: vimage_def measurable_count_space_eq2_countable)
hoelzl@47761
  1354
qed
hoelzl@47761
  1355
hoelzl@50002
  1356
lemma measurable_real_ceiling[measurable]:
hoelzl@50002
  1357
  "(ceiling :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
  1358
  unfolding ceiling_def[abs_def] by simp
hoelzl@50002
  1359
lp15@61609
  1360
lemma borel_measurable_real_floor: "(\<lambda>x::real. real_of_int \<lfloor>x\<rfloor>) \<in> borel_measurable borel"
hoelzl@50002
  1361
  by simp
hoelzl@50002
  1362
hoelzl@59415
  1363
lemma borel_measurable_root [measurable]: "root n \<in> borel_measurable borel"
hoelzl@57235
  1364
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1365
hoelzl@57235
  1366
lemma borel_measurable_sqrt [measurable]: "sqrt \<in> borel_measurable borel"
hoelzl@57235
  1367
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1368
hoelzl@57235
  1369
lemma borel_measurable_power [measurable (raw)]:
hoelzl@59415
  1370
  fixes f :: "_ \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@59415
  1371
  assumes f: "f \<in> borel_measurable M"
hoelzl@59415
  1372
  shows "(\<lambda>x. (f x) ^ n) \<in> borel_measurable M"
hoelzl@59415
  1373
  by (intro borel_measurable_continuous_on [OF _ f] continuous_intros)
hoelzl@57235
  1374
hoelzl@57235
  1375
lemma borel_measurable_Re [measurable]: "Re \<in> borel_measurable borel"
hoelzl@57235
  1376
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1377
hoelzl@57235
  1378
lemma borel_measurable_Im [measurable]: "Im \<in> borel_measurable borel"
hoelzl@57235
  1379
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1380
hoelzl@57235
  1381
lemma borel_measurable_of_real [measurable]: "(of_real :: _ \<Rightarrow> (_::real_normed_algebra)) \<in> borel_measurable borel"
hoelzl@57235
  1382
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1383
lp15@59658
  1384
lemma borel_measurable_sin [measurable]: "(sin :: _ \<Rightarrow> (_::{real_normed_field,banach})) \<in> borel_measurable borel"
hoelzl@57235
  1385
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1386
lp15@59658
  1387
lemma borel_measurable_cos [measurable]: "(cos :: _ \<Rightarrow> (_::{real_normed_field,banach})) \<in> borel_measurable borel"
hoelzl@57235
  1388
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1389
hoelzl@57235
  1390
lemma borel_measurable_arctan [measurable]: "arctan \<in> borel_measurable borel"
hoelzl@57235
  1391
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1392
hoelzl@57259
  1393
lemma borel_measurable_complex_iff:
hoelzl@57259
  1394
  "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@57259
  1395
    (\<lambda>x. Re (f x)) \<in> borel_measurable M \<and> (\<lambda>x. Im (f x)) \<in> borel_measurable M"
hoelzl@57259
  1396
  apply auto
hoelzl@57259
  1397
  apply (subst fun_complex_eq)
hoelzl@57259
  1398
  apply (intro borel_measurable_add)
hoelzl@57259
  1399
  apply auto
hoelzl@57259
  1400
  done
hoelzl@57259
  1401
hoelzl@41981
  1402
subsection "Borel space on the extended reals"
hoelzl@41981
  1403
hoelzl@50003
  1404
lemma borel_measurable_ereal[measurable (raw)]:
hoelzl@43920
  1405
  assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@60771
  1406
  using continuous_on_ereal f by (rule borel_measurable_continuous_on) (rule continuous_on_id)
hoelzl@41981
  1407
hoelzl@50003
  1408
lemma borel_measurable_real_of_ereal[measurable (raw)]:
hoelzl@62372
  1409
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1410
  assumes f: "f \<in> borel_measurable M"
lp15@61609
  1411
  shows "(\<lambda>x. real_of_ereal (f x)) \<in> borel_measurable M"
hoelzl@59361
  1412
  apply (rule measurable_compose[OF f])
hoelzl@59361
  1413
  apply (rule borel_measurable_continuous_countable_exceptions[of "{\<infinity>, -\<infinity> }"])
hoelzl@59361
  1414
  apply (auto intro: continuous_on_real simp: Compl_eq_Diff_UNIV)
hoelzl@59361
  1415
  done
hoelzl@49774
  1416
hoelzl@49774
  1417
lemma borel_measurable_ereal_cases:
hoelzl@62372
  1418
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1419
  assumes f: "f \<in> borel_measurable M"
lp15@61609
  1420
  assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x)))) \<in> borel_measurable M"
hoelzl@49774
  1421
  shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
hoelzl@49774
  1422
proof -
lp15@61609
  1423
  let ?F = "\<lambda>x. if f x = \<infinity> then H \<infinity> else if f x = - \<infinity> then H (-\<infinity>) else H (ereal (real_of_ereal (f x)))"
hoelzl@49774
  1424
  { fix x have "H (f x) = ?F x" by (cases "f x") auto }
hoelzl@50002
  1425
  with f H show ?thesis by simp
hoelzl@47694
  1426
qed
hoelzl@41981
  1427
hoelzl@49774
  1428
lemma
hoelzl@50003
  1429
  fixes f :: "'a \<Rightarrow> ereal" assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50003
  1430
  shows borel_measurable_ereal_abs[measurable(raw)]: "(\<lambda>x. \<bar>f x\<bar>) \<in> borel_measurable M"
hoelzl@50003
  1431
    and borel_measurable_ereal_inverse[measurable(raw)]: "(\<lambda>x. inverse (f x) :: ereal) \<in> borel_measurable M"
hoelzl@50003
  1432
    and borel_measurable_uminus_ereal[measurable(raw)]: "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M"
hoelzl@49774
  1433
  by (auto simp del: abs_real_of_ereal simp: borel_measurable_ereal_cases[OF f] measurable_If)
hoelzl@49774
  1434
hoelzl@49774
  1435
lemma borel_measurable_uminus_eq_ereal[simp]:
hoelzl@49774
  1436
  "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
hoelzl@49774
  1437
proof
hoelzl@49774
  1438
  assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
hoelzl@49774
  1439
qed auto
hoelzl@49774
  1440
hoelzl@49774
  1441
lemma set_Collect_ereal2:
hoelzl@62372
  1442
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1443
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1444
  assumes g: "g \<in> borel_measurable M"
lp15@61609
  1445
  assumes H: "{x \<in> space M. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))} \<in> sets M"
hoelzl@50002
  1446
    "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
  1447
    "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
  1448
    "{x \<in> space borel. H (ereal x) (-\<infinity>)} \<in> sets borel"
hoelzl@50002
  1449
    "{x \<in> space borel. H (ereal x) (\<infinity>)} \<in> sets borel"
hoelzl@49774
  1450
  shows "{x \<in> space M. H (f x) (g x)} \<in> sets M"
hoelzl@49774
  1451
proof -
lp15@61609
  1452
  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_of_ereal (g x)))"
lp15@61609
  1453
  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_of_ereal (f x))) x"
hoelzl@49774
  1454
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
  1455
  note * = this
hoelzl@50002
  1456
  from assms show ?thesis
hoelzl@50002
  1457
    by (subst *) (simp del: space_borel split del: split_if)
hoelzl@49774
  1458
qed
hoelzl@49774
  1459
hoelzl@47694
  1460
lemma borel_measurable_ereal_iff:
hoelzl@43920
  1461
  shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M"
hoelzl@41981
  1462
proof
hoelzl@43920
  1463
  assume "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@43920
  1464
  from borel_measurable_real_of_ereal[OF this]
hoelzl@41981
  1465
  show "f \<in> borel_measurable M" by auto
hoelzl@41981
  1466
qed auto
hoelzl@41981
  1467
hoelzl@59353
  1468
lemma borel_measurable_erealD[measurable_dest]:
hoelzl@59353
  1469
  "(\<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
  1470
  unfolding borel_measurable_ereal_iff by simp
hoelzl@59353
  1471
hoelzl@47694
  1472
lemma borel_measurable_ereal_iff_real:
hoelzl@43923
  1473
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
  1474
  shows "f \<in> borel_measurable M \<longleftrightarrow>
lp15@61609
  1475
    ((\<lambda>x. real_of_ereal (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
  1476
proof safe
lp15@61609
  1477
  assume *: "(\<lambda>x. real_of_ereal (f x)) \<in> borel_measurable M" "f -` {\<infinity>} \<inter> space M \<in> sets M" "f -` {-\<infinity>} \<inter> space M \<in> sets M"
hoelzl@41981
  1478
  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
  1479
  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
lp15@61609
  1480
  let ?f = "\<lambda>x. if f x = \<infinity> then \<infinity> else if f x = -\<infinity> then -\<infinity> else ereal (real_of_ereal (f x))"
hoelzl@41981
  1481
  have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
hoelzl@43920
  1482
  also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
hoelzl@41981
  1483
  finally show "f \<in> borel_measurable M" .
hoelzl@50002
  1484
qed simp_all
hoelzl@41830
  1485
hoelzl@59361
  1486
lemma borel_measurable_ereal_iff_Iio:
hoelzl@59361
  1487
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
hoelzl@59361
  1488
  by (auto simp: borel_Iio measurable_iff_measure_of)
hoelzl@59361
  1489
hoelzl@59361
  1490
lemma borel_measurable_ereal_iff_Ioi:
hoelzl@59361
  1491
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
hoelzl@59361
  1492
  by (auto simp: borel_Ioi measurable_iff_measure_of)
hoelzl@35582
  1493
hoelzl@59361
  1494
lemma vimage_sets_compl_iff:
hoelzl@59361
  1495
  "f -` A \<inter> space M \<in> sets M \<longleftrightarrow> f -` (- A) \<inter> space M \<in> sets M"
hoelzl@59361
  1496
proof -
hoelzl@59361
  1497
  { fix A assume "f -` A \<inter> space M \<in> sets M"
hoelzl@59361
  1498
    moreover have "f -` (- A) \<inter> space M = space M - f -` A \<inter> space M" by auto
hoelzl@59361
  1499
    ultimately have "f -` (- A) \<inter> space M \<in> sets M" by auto }
hoelzl@59361
  1500
  from this[of A] this[of "-A"] show ?thesis
hoelzl@59361
  1501
    by (metis double_complement)
hoelzl@49774
  1502
qed
hoelzl@49774
  1503
hoelzl@59361
  1504
lemma borel_measurable_iff_Iic_ereal:
hoelzl@59361
  1505
  "(f::'a\<Rightarrow>ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
hoelzl@59361
  1506
  unfolding borel_measurable_ereal_iff_Ioi vimage_sets_compl_iff[where A="{a <..}" for a] by simp
hoelzl@38656
  1507
hoelzl@59361
  1508
lemma borel_measurable_iff_Ici_ereal:
hoelzl@59361
  1509
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
hoelzl@59361
  1510
  unfolding borel_measurable_ereal_iff_Iio vimage_sets_compl_iff[where A="{..< a}" for a] by simp
hoelzl@38656
  1511
hoelzl@49774
  1512
lemma borel_measurable_ereal2:
hoelzl@62372
  1513
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@41981
  1514
  assumes f: "f \<in> borel_measurable M"
hoelzl@41981
  1515
  assumes g: "g \<in> borel_measurable M"
lp15@61609
  1516
  assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
lp15@61609
  1517
    "(\<lambda>x. H (-\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
lp15@61609
  1518
    "(\<lambda>x. H (\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
lp15@61609
  1519
    "(\<lambda>x. H (ereal (real_of_ereal (f x))) (-\<infinity>)) \<in> borel_measurable M"
lp15@61609
  1520
    "(\<lambda>x. H (ereal (real_of_ereal (f x))) (\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1521
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@41981
  1522
proof -
lp15@61609
  1523
  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_of_ereal (g x)))"
lp15@61609
  1524
  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_of_ereal (f x))) x"
hoelzl@49774
  1525
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
  1526
  note * = this
hoelzl@50002
  1527
  from assms show ?thesis unfolding * by simp
hoelzl@41981
  1528
qed
hoelzl@41981
  1529
hoelzl@49774
  1530
lemma
hoelzl@49774
  1531
  fixes f :: "'a \<Rightarrow> ereal" assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1532
  shows borel_measurable_ereal_eq_const: "{x\<in>space M. f x = c} \<in> sets M"
hoelzl@49774
  1533
    and borel_measurable_ereal_neq_const: "{x\<in>space M. f x \<noteq> c} \<in> sets M"
hoelzl@49774
  1534
  using f by auto
hoelzl@38656
  1535
hoelzl@50003
  1536
lemma [measurable(raw)]:
hoelzl@43920
  1537
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@50003
  1538
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@50002
  1539
  shows borel_measurable_ereal_add: "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@50002
  1540
    and borel_measurable_ereal_times: "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@50002
  1541
    and borel_measurable_ereal_min: "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
hoelzl@50002
  1542
    and borel_measurable_ereal_max: "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
hoelzl@50003
  1543
  by (simp_all add: borel_measurable_ereal2 min_def max_def)
hoelzl@49774
  1544
hoelzl@50003
  1545
lemma [measurable(raw)]:
hoelzl@49774
  1546
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1547
  assumes "f \<in> borel_measurable M"
hoelzl@49774
  1548
  assumes "g \<in> borel_measurable M"
hoelzl@50002
  1549
  shows borel_measurable_ereal_diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50002
  1550
    and borel_measurable_ereal_divide: "(\<lambda>x. f x / g x) \<in> borel_measurable M"
hoelzl@50003
  1551
  using assms by (simp_all add: minus_ereal_def divide_ereal_def)
hoelzl@38656
  1552
hoelzl@50003
  1553
lemma borel_measurable_ereal_setsum[measurable (raw)]:
hoelzl@43920
  1554
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41096
  1555
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1556
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@59361
  1557
  using assms by (induction S rule: infinite_finite_induct) auto
hoelzl@38656
  1558
hoelzl@50003
  1559
lemma borel_measurable_ereal_setprod[measurable (raw)]:
hoelzl@43920
  1560
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1561
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1562
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@59361
  1563
  using assms by (induction S rule: infinite_finite_induct) auto
hoelzl@38656
  1564
hoelzl@50003
  1565
lemma [measurable (raw)]:
hoelzl@43920
  1566
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41981
  1567
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@50002
  1568
  shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1569
    and borel_measurable_limsup: "(\<lambda>x. limsup (\<lambda>i. f i x)) \<in> borel_measurable M"
haftmann@56212
  1570
  unfolding liminf_SUP_INF limsup_INF_SUP using assms by auto
hoelzl@35692
  1571
hoelzl@50104
  1572
lemma sets_Collect_eventually_sequentially[measurable]:
hoelzl@50003
  1573
  "(\<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
  1574
  unfolding eventually_sequentially by simp
hoelzl@50003
  1575
hoelzl@62372
  1576
lemma sets_Collect_ereal_convergent[measurable]:
hoelzl@50003
  1577
  fixes f :: "nat \<Rightarrow> 'a => ereal"
hoelzl@50003
  1578
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1579
  shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
hoelzl@50003
  1580
  unfolding convergent_ereal by auto
hoelzl@50003
  1581
hoelzl@50003
  1582
lemma borel_measurable_extreal_lim[measurable (raw)]:
hoelzl@50003
  1583
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1584
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1585
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1586
proof -
hoelzl@50003
  1587
  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
  1588
    by (simp add: lim_def convergent_def convergent_limsup_cl)
hoelzl@50003
  1589
  then show ?thesis
hoelzl@50003
  1590
    by simp
hoelzl@50003
  1591
qed
hoelzl@50003
  1592
hoelzl@49774
  1593
lemma borel_measurable_ereal_LIMSEQ:
hoelzl@49774
  1594
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
wenzelm@61969
  1595
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) \<longlonglongrightarrow> u' x"
hoelzl@49774
  1596
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@49774
  1597
  shows "u' \<in> borel_measurable M"
hoelzl@47694
  1598
proof -
hoelzl@49774
  1599
  have "\<And>x. x \<in> space M \<Longrightarrow> u' x = liminf (\<lambda>n. u n x)"
hoelzl@49774
  1600
    using u' by (simp add: lim_imp_Liminf[symmetric])
hoelzl@50003
  1601
  with u show ?thesis by (simp cong: measurable_cong)
hoelzl@47694
  1602
qed
hoelzl@47694
  1603
hoelzl@50003
  1604
lemma borel_measurable_extreal_suminf[measurable (raw)]:
hoelzl@43920
  1605
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1606
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@41981
  1607
  shows "(\<lambda>x. (\<Sum>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1608
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@39092
  1609
wenzelm@61808
  1610
subsection \<open>LIMSEQ is borel measurable\<close>
hoelzl@39092
  1611
hoelzl@47694
  1612
lemma borel_measurable_LIMSEQ:
hoelzl@39092
  1613
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> real"
wenzelm@61969
  1614
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) \<longlonglongrightarrow> u' x"
hoelzl@39092
  1615
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@39092
  1616
  shows "u' \<in> borel_measurable M"
hoelzl@39092
  1617
proof -
hoelzl@43920
  1618
  have "\<And>x. x \<in> space M \<Longrightarrow> liminf (\<lambda>n. ereal (u n x)) = ereal (u' x)"
wenzelm@46731
  1619
    using u' by (simp add: lim_imp_Liminf)
hoelzl@43920
  1620
  moreover from u have "(\<lambda>x. liminf (\<lambda>n. ereal (u n x))) \<in> borel_measurable M"
hoelzl@39092
  1621
    by auto
hoelzl@43920
  1622
  ultimately show ?thesis by (simp cong: measurable_cong add: borel_measurable_ereal_iff)
hoelzl@39092
  1623
qed
hoelzl@39092
  1624
hoelzl@56993
  1625
lemma borel_measurable_LIMSEQ_metric:
hoelzl@56993
  1626
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b :: metric_space"
hoelzl@56993
  1627
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
wenzelm@61969
  1628
  assumes lim: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. f i x) \<longlonglongrightarrow> g x"
hoelzl@56993
  1629
  shows "g \<in> borel_measurable M"
hoelzl@56993
  1630
  unfolding borel_eq_closed
hoelzl@56993
  1631
proof (safe intro!: measurable_measure_of)
hoelzl@62372
  1632
  fix A :: "'b set" assume "closed A"
hoelzl@56993
  1633
hoelzl@56993
  1634
  have [measurable]: "(\<lambda>x. infdist (g x) A) \<in> borel_measurable M"
hoelzl@56993
  1635
  proof (rule borel_measurable_LIMSEQ)
wenzelm@61969
  1636
    show "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. infdist (f i x) A) \<longlonglongrightarrow> infdist (g x) A"
hoelzl@56993
  1637
      by (intro tendsto_infdist lim)
hoelzl@56993
  1638
    show "\<And>i. (\<lambda>x. infdist (f i x) A) \<in> borel_measurable M"
hoelzl@56993
  1639
      by (intro borel_measurable_continuous_on[where f="\<lambda>x. infdist x A"]
lp15@60150
  1640
        continuous_at_imp_continuous_on ballI continuous_infdist continuous_ident) auto
hoelzl@56993
  1641
  qed
hoelzl@56993
  1642
hoelzl@56993
  1643
  show "g -` A \<inter> space M \<in> sets M"
hoelzl@56993
  1644
  proof cases
hoelzl@56993
  1645
    assume "A \<noteq> {}"
hoelzl@56993
  1646
    then have "\<And>x. infdist x A = 0 \<longleftrightarrow> x \<in> A"
wenzelm@61808
  1647
      using \<open>closed A\<close> by (simp add: in_closed_iff_infdist_zero)
hoelzl@56993
  1648
    then have "g -` A \<inter> space M = {x\<in>space M. infdist (g x) A = 0}"
hoelzl@56993
  1649
      by auto
hoelzl@56993
  1650
    also have "\<dots> \<in> sets M"
hoelzl@56993
  1651
      by measurable
hoelzl@56993
  1652
    finally show ?thesis .
hoelzl@56993
  1653
  qed simp
hoelzl@56993
  1654
qed auto
hoelzl@56993
  1655
hoelzl@62372
  1656
lemma sets_Collect_Cauchy[measurable]:
hoelzl@57036
  1657
  fixes f :: "nat \<Rightarrow> 'a => 'b::{metric_space, second_countable_topology}"
hoelzl@50002
  1658
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1659
  shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
hoelzl@57036
  1660
  unfolding metric_Cauchy_iff2 using f by auto
hoelzl@49774
  1661
hoelzl@50002
  1662
lemma borel_measurable_lim[measurable (raw)]:
hoelzl@57036
  1663
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@50002
  1664
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1665
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1666
proof -
hoelzl@50002
  1667
  def u' \<equiv> "\<lambda>x. lim (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@50002
  1668
  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
  1669
    by (auto simp: lim_def convergent_eq_cauchy[symmetric])
hoelzl@50002
  1670
  have "u' \<in> borel_measurable M"
hoelzl@57036
  1671
  proof (rule borel_measurable_LIMSEQ_metric)
hoelzl@50002
  1672
    fix x
hoelzl@50002
  1673
    have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@49774
  1674
      by (cases "Cauchy (\<lambda>i. f i x)")
hoelzl@50002
  1675
         (auto simp add: convergent_eq_cauchy[symmetric] convergent_def)
wenzelm@61969
  1676
    then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) \<longlonglongrightarrow> u' x"
hoelzl@62372
  1677
      unfolding u'_def
hoelzl@50002
  1678
      by (rule convergent_LIMSEQ_iff[THEN iffD1])
hoelzl@50002
  1679
  qed measurable
hoelzl@50002
  1680
  then show ?thesis
hoelzl@50002
  1681
    unfolding * by measurable
hoelzl@49774
  1682
qed
hoelzl@49774
  1683
hoelzl@50002
  1684
lemma borel_measurable_suminf[measurable (raw)]:
hoelzl@57036
  1685
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@50002
  1686
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1687
  shows "(\<lambda>x. suminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1688
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@49774
  1689
hoelzl@59000
  1690
lemma borel_measurable_sup[measurable (raw)]:
hoelzl@59000
  1691
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow>
hoelzl@59000
  1692
    (\<lambda>x. sup (f x) (g x)::ereal) \<in> borel_measurable M"
hoelzl@59000
  1693
  by simp
hoelzl@59000
  1694
hoelzl@57447
  1695
(* Proof by Jeremy Avigad and Luke Serafin *)
hoelzl@57447
  1696
lemma isCont_borel:
hoelzl@57447
  1697
  fixes f :: "'b::metric_space \<Rightarrow> 'a::metric_space"
hoelzl@57447
  1698
  shows "{x. isCont f x} \<in> sets borel"
hoelzl@57447
  1699
proof -
hoelzl@57447
  1700
  let ?I = "\<lambda>j. inverse(real (Suc j))"
hoelzl@57447
  1701
hoelzl@57447
  1702
  { fix x
hoelzl@57447
  1703
    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
  1704
      unfolding continuous_at_eps_delta
hoelzl@57447
  1705
    proof safe
hoelzl@57447
  1706
      fix i assume "\<forall>e>0. \<exists>d>0. \<forall>y. dist y x < d \<longrightarrow> dist (f y) (f x) < e"
hoelzl@57447
  1707
      moreover have "0 < ?I i / 2"
hoelzl@57447
  1708
        by simp
hoelzl@57447
  1709
      ultimately obtain d where d: "0 < d" "\<And>y. dist x y < d \<Longrightarrow> dist (f y) (f x) < ?I i / 2"
hoelzl@57447
  1710
        by (metis dist_commute)
hoelzl@57447
  1711
      then obtain j where j: "?I j < d"
hoelzl@57447
  1712
        by (metis reals_Archimedean)
hoelzl@57447
  1713
hoelzl@57447
  1714
      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
  1715
      proof (safe intro!: exI[where x=j])
hoelzl@57447
  1716
        fix y z assume *: "dist x y < ?I j" "dist x z < ?I j"
hoelzl@57447
  1717
        have "dist (f y) (f z) \<le> dist (f y) (f x) + dist (f z) (f x)"
hoelzl@57447
  1718
          by (rule dist_triangle2)
hoelzl@57447
  1719
        also have "\<dots> < ?I i / 2 + ?I i / 2"
hoelzl@57447
  1720
          by (intro add_strict_mono d less_trans[OF _ j] *)
hoelzl@57447
  1721
        also have "\<dots> \<le> ?I i"
lp15@61609
  1722
          by (simp add: field_simps of_nat_Suc)
hoelzl@57447
  1723
        finally show "dist (f y) (f z) \<le> ?I i"
hoelzl@57447
  1724
          by simp
hoelzl@57447
  1725
      qed
hoelzl@57447
  1726
    next
hoelzl@57447
  1727
      fix e::real assume "0 < e"
hoelzl@57447
  1728
      then obtain n where n: "?I n < e"
hoelzl@57447
  1729
        by (metis reals_Archimedean)
hoelzl@57447
  1730
      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
  1731
      from this[THEN spec, of "Suc n"]
hoelzl@57447
  1732
      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
  1733
        by auto
hoelzl@62372
  1734
hoelzl@57447
  1735
      show "\<exists>d>0. \<forall>y. dist y x < d \<longrightarrow> dist (f y) (f x) < e"
hoelzl@57447
  1736
      proof (safe intro!: exI[of _ "?I j"])
hoelzl@57447
  1737
        fix y assume "dist y x < ?I j"
hoelzl@57447
  1738
        then have "dist (f y) (f x) \<le> ?I (Suc n)"
hoelzl@57447
  1739
          by (intro j) (auto simp: dist_commute)
hoelzl@57447
  1740
        also have "?I (Suc n) < ?I n"
hoelzl@57447
  1741
          by simp
hoelzl@57447
  1742
        also note n
hoelzl@57447
  1743
        finally show "dist (f y) (f x) < e" .
hoelzl@57447
  1744
      qed simp
hoelzl@57447
  1745
    qed }
hoelzl@57447
  1746
  note * = this
hoelzl@57447
  1747
hoelzl@57447
  1748
  have **: "\<And>e y. open {x. dist x y < e}"
hoelzl@57447
  1749
    using open_ball by (simp_all add: ball_def dist_commute)
hoelzl@57447
  1750
hoelzl@59415
  1751
  have "{x\<in>space borel. isCont f x} \<in> sets borel"
hoelzl@57447
  1752
    unfolding *
hoelzl@57447
  1753
    apply (intro sets.sets_Collect_countable_All sets.sets_Collect_countable_Ex)
hoelzl@57447
  1754
    apply (simp add: Collect_all_eq)
hoelzl@57447
  1755
    apply (intro borel_closed closed_INT ballI closed_Collect_imp open_Collect_conj **)
hoelzl@57447
  1756
    apply auto
hoelzl@57447
  1757
    done
hoelzl@57447
  1758
  then show ?thesis
hoelzl@57447
  1759
    by simp
hoelzl@57447
  1760
qed
hoelzl@57447
  1761
hoelzl@62083
  1762
lemma isCont_borel_pred[measurable]:
hoelzl@62083
  1763
  fixes f :: "'b::metric_space \<Rightarrow> 'a::metric_space"
hoelzl@62083
  1764
  shows "Measurable.pred borel (isCont f)"
hoelzl@62083
  1765
  unfolding pred_def by (simp add: isCont_borel)
hoelzl@62083
  1766
hoelzl@61880
  1767
lemma is_real_interval:
hoelzl@61880
  1768
  assumes S: "is_interval S"
hoelzl@61880
  1769
  shows "\<exists>a b::real. S = {} \<or> S = UNIV \<or> S = {..<b} \<or> S = {..b} \<or> S = {a<..} \<or> S = {a..} \<or>
hoelzl@61880
  1770
    S = {a<..<b} \<or> S = {a<..b} \<or> S = {a..<b} \<or> S = {a..b}"
hoelzl@61880
  1771
  using S unfolding is_interval_1 by (blast intro: interval_cases)
hoelzl@61880
  1772
hoelzl@61880
  1773
lemma real_interval_borel_measurable:
hoelzl@61880
  1774
  assumes "is_interval (S::real set)"
hoelzl@61880
  1775
  shows "S \<in> sets borel"
hoelzl@61880
  1776
proof -
hoelzl@61880
  1777
  from assms is_real_interval have "\<exists>a b::real. S = {} \<or> S = UNIV \<or> S = {..<b} \<or> S = {..b} \<or>
hoelzl@61880
  1778
    S = {a<..} \<or> S = {a..} \<or> S = {a<..<b} \<or> S = {a<..b} \<or> S = {a..<b} \<or> S = {a..b}" by auto
hoelzl@61880
  1779
  then guess a ..
hoelzl@61880
  1780
  then guess b ..
hoelzl@61880
  1781
  thus ?thesis
hoelzl@61880
  1782
    by auto
hoelzl@61880
  1783
qed
hoelzl@61880
  1784
hoelzl@62083
  1785
lemma borel_measurable_mono_on_fnc:
hoelzl@62083
  1786
  fixes f :: "real \<Rightarrow> real" and A :: "real set"
hoelzl@62083
  1787
  assumes "mono_on f A"
hoelzl@62083
  1788
  shows "f \<in> borel_measurable (restrict_space borel A)"
hoelzl@62083
  1789
  apply (rule measurable_restrict_countable[OF mono_on_ctble_discont[OF assms]])
hoelzl@62083
  1790
  apply (auto intro!: image_eqI[where x="{x}" for x] simp: sets_restrict_space)
hoelzl@62083
  1791
  apply (auto simp add: sets_restrict_restrict_space continuous_on_eq_continuous_within
hoelzl@62372
  1792
              cong: measurable_cong_sets
hoelzl@62083
  1793
              intro!: borel_measurable_continuous_on_restrict intro: continuous_within_subset)
hoelzl@62083
  1794
  done
hoelzl@62083
  1795
hoelzl@61880
  1796
lemma borel_measurable_mono:
hoelzl@61880
  1797
  fixes f :: "real \<Rightarrow> real"
hoelzl@62083
  1798
  shows "mono f \<Longrightarrow> f \<in> borel_measurable borel"
hoelzl@62083
  1799
  using borel_measurable_mono_on_fnc[of f UNIV] by (simp add: mono_def mono_on_def)
hoelzl@61880
  1800
immler@54775
  1801
no_notation
immler@54775
  1802
  eucl_less (infix "<e" 50)
immler@54775
  1803
hoelzl@51683
  1804
end