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