src/HOL/Analysis/Borel_Space.thy
author eberlm <eberlm@in.tum.de>
Sun Dec 24 14:28:10 2017 +0100 (22 months ago)
changeset 67278 c60e3d615b8c
parent 66164 2d79288b042c
child 67399 eab6ce8368fa
permissions -rw-r--r--
Removed Analysis/ex/Circle_Area; replaced by more general Analysis/Ball_Volume
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@64320
   348
lemma sets_borel_eq_count_space: "sets (borel :: 'a::{countable, t2_space} measure) = count_space UNIV"
hoelzl@64320
   349
proof -
hoelzl@64320
   350
  have "(\<Union>a\<in>A. {a}) \<in> sets borel" for A :: "'a set"
hoelzl@64320
   351
    by (intro sets.countable_UN') auto
hoelzl@64320
   352
  then show ?thesis
hoelzl@64320
   353
    by auto
hoelzl@64320
   354
qed
hoelzl@64320
   355
hoelzl@50003
   356
lemma borel_comp[measurable]: "A \<in> sets borel \<Longrightarrow> - A \<in> sets borel"
hoelzl@50002
   357
  unfolding Compl_eq_Diff_UNIV by simp
hoelzl@41830
   358
hoelzl@47694
   359
lemma borel_measurable_vimage:
hoelzl@38656
   360
  fixes f :: "'a \<Rightarrow> 'x::t2_space"
hoelzl@50002
   361
  assumes borel[measurable]: "f \<in> borel_measurable M"
hoelzl@38656
   362
  shows "f -` {x} \<inter> space M \<in> sets M"
hoelzl@50002
   363
  by simp
paulson@33533
   364
hoelzl@47694
   365
lemma borel_measurableI:
wenzelm@61076
   366
  fixes f :: "'a \<Rightarrow> 'x::topological_space"
hoelzl@38656
   367
  assumes "\<And>S. open S \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
hoelzl@38656
   368
  shows "f \<in> borel_measurable M"
hoelzl@40859
   369
  unfolding borel_def
hoelzl@47694
   370
proof (rule measurable_measure_of, simp_all)
huffman@44537
   371
  fix S :: "'x set" assume "open S" thus "f -` S \<inter> space M \<in> sets M"
huffman@44537
   372
    using assms[of S] by simp
hoelzl@40859
   373
qed
paulson@33533
   374
hoelzl@50021
   375
lemma borel_measurable_const:
hoelzl@38656
   376
  "(\<lambda>x. c) \<in> borel_measurable M"
hoelzl@47694
   377
  by auto
paulson@33533
   378
hoelzl@50003
   379
lemma borel_measurable_indicator:
hoelzl@38656
   380
  assumes A: "A \<in> sets M"
hoelzl@38656
   381
  shows "indicator A \<in> borel_measurable M"
wenzelm@46905
   382
  unfolding indicator_def [abs_def] using A
hoelzl@47694
   383
  by (auto intro!: measurable_If_set)
paulson@33533
   384
hoelzl@50096
   385
lemma borel_measurable_count_space[measurable (raw)]:
hoelzl@50096
   386
  "f \<in> borel_measurable (count_space S)"
hoelzl@50096
   387
  unfolding measurable_def by auto
hoelzl@50096
   388
hoelzl@50096
   389
lemma borel_measurable_indicator'[measurable (raw)]:
hoelzl@50096
   390
  assumes [measurable]: "{x\<in>space M. f x \<in> A x} \<in> sets M"
hoelzl@50096
   391
  shows "(\<lambda>x. indicator (A x) (f x)) \<in> borel_measurable M"
hoelzl@50001
   392
  unfolding indicator_def[abs_def]
hoelzl@50001
   393
  by (auto intro!: measurable_If)
hoelzl@50001
   394
hoelzl@47694
   395
lemma borel_measurable_indicator_iff:
hoelzl@40859
   396
  "(indicator A :: 'a \<Rightarrow> 'x::{t1_space, zero_neq_one}) \<in> borel_measurable M \<longleftrightarrow> A \<inter> space M \<in> sets M"
hoelzl@40859
   397
    (is "?I \<in> borel_measurable M \<longleftrightarrow> _")
hoelzl@40859
   398
proof
hoelzl@40859
   399
  assume "?I \<in> borel_measurable M"
hoelzl@40859
   400
  then have "?I -` {1} \<inter> space M \<in> sets M"
hoelzl@40859
   401
    unfolding measurable_def by auto
hoelzl@40859
   402
  also have "?I -` {1} \<inter> space M = A \<inter> space M"
wenzelm@46905
   403
    unfolding indicator_def [abs_def] by auto
hoelzl@40859
   404
  finally show "A \<inter> space M \<in> sets M" .
hoelzl@40859
   405
next
hoelzl@40859
   406
  assume "A \<inter> space M \<in> sets M"
hoelzl@40859
   407
  moreover have "?I \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
   408
    (indicator (A \<inter> space M) :: 'a \<Rightarrow> 'x) \<in> borel_measurable M"
hoelzl@40859
   409
    by (intro measurable_cong) (auto simp: indicator_def)
hoelzl@40859
   410
  ultimately show "?I \<in> borel_measurable M" by auto
hoelzl@40859
   411
qed
hoelzl@40859
   412
hoelzl@47694
   413
lemma borel_measurable_subalgebra:
hoelzl@41545
   414
  assumes "sets N \<subseteq> sets M" "space N = space M" "f \<in> borel_measurable N"
hoelzl@39092
   415
  shows "f \<in> borel_measurable M"
hoelzl@39092
   416
  using assms unfolding measurable_def by auto
hoelzl@39092
   417
hoelzl@57137
   418
lemma borel_measurable_restrict_space_iff_ereal:
hoelzl@57137
   419
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@57137
   420
  assumes \<Omega>[measurable, simp]: "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
   421
  shows "f \<in> borel_measurable (restrict_space M \<Omega>) \<longleftrightarrow>
hoelzl@57137
   422
    (\<lambda>x. f x * indicator \<Omega> x) \<in> borel_measurable M"
hoelzl@57138
   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@57137
   425
hoelzl@62975
   426
lemma borel_measurable_restrict_space_iff_ennreal:
hoelzl@62975
   427
  fixes f :: "'a \<Rightarrow> ennreal"
hoelzl@62975
   428
  assumes \<Omega>[measurable, simp]: "\<Omega> \<inter> space M \<in> sets M"
hoelzl@62975
   429
  shows "f \<in> borel_measurable (restrict_space M \<Omega>) \<longleftrightarrow>
hoelzl@62975
   430
    (\<lambda>x. f x * indicator \<Omega> x) \<in> borel_measurable M"
hoelzl@62975
   431
  by (subst measurable_restrict_space_iff)
wenzelm@63566
   432
     (auto simp: indicator_def if_distrib[where f="\<lambda>x. a * x" for a] cong del: if_weak_cong)
hoelzl@62975
   433
hoelzl@57137
   434
lemma borel_measurable_restrict_space_iff:
hoelzl@57137
   435
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@57137
   436
  assumes \<Omega>[measurable, simp]: "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
   437
  shows "f \<in> borel_measurable (restrict_space M \<Omega>) \<longleftrightarrow>
hoelzl@57137
   438
    (\<lambda>x. indicator \<Omega> x *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@57138
   439
  by (subst measurable_restrict_space_iff)
wenzelm@63566
   440
     (auto simp: indicator_def if_distrib[where f="\<lambda>x. x *\<^sub>R a" for a] ac_simps
wenzelm@63566
   441
       cong del: if_weak_cong)
hoelzl@57138
   442
hoelzl@57138
   443
lemma cbox_borel[measurable]: "cbox a b \<in> sets borel"
hoelzl@57138
   444
  by (auto intro: borel_closed)
hoelzl@57138
   445
hoelzl@57447
   446
lemma box_borel[measurable]: "box a b \<in> sets borel"
hoelzl@57447
   447
  by (auto intro: borel_open)
hoelzl@57447
   448
hoelzl@57138
   449
lemma borel_compact: "compact (A::'a::t2_space set) \<Longrightarrow> A \<in> sets borel"
hoelzl@57138
   450
  by (auto intro: borel_closed dest!: compact_imp_closed)
hoelzl@57137
   451
hoelzl@62624
   452
lemma borel_sigma_sets_subset:
hoelzl@62624
   453
  "A \<subseteq> sets borel \<Longrightarrow> sigma_sets UNIV A \<subseteq> sets borel"
hoelzl@62624
   454
  using sets.sigma_sets_subset[of A borel] by simp
hoelzl@62624
   455
hoelzl@62624
   456
lemma borel_eq_sigmaI1:
hoelzl@62624
   457
  fixes F :: "'i \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@62624
   458
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@62624
   459
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV (F ` A))"
hoelzl@62624
   460
  assumes F: "\<And>i. i \<in> A \<Longrightarrow> F i \<in> sets borel"
hoelzl@62624
   461
  shows "borel = sigma UNIV (F ` A)"
hoelzl@62624
   462
  unfolding borel_def
hoelzl@62624
   463
proof (intro sigma_eqI antisym)
hoelzl@62624
   464
  have borel_rev_eq: "sigma_sets UNIV {S::'a set. open S} = sets borel"
hoelzl@62624
   465
    unfolding borel_def by simp
hoelzl@62624
   466
  also have "\<dots> = sigma_sets UNIV X"
hoelzl@62624
   467
    unfolding borel_eq by simp
hoelzl@62624
   468
  also have "\<dots> \<subseteq> sigma_sets UNIV (F`A)"
hoelzl@62624
   469
    using X by (intro sigma_algebra.sigma_sets_subset[OF sigma_algebra_sigma_sets]) auto
hoelzl@62624
   470
  finally show "sigma_sets UNIV {S. open S} \<subseteq> sigma_sets UNIV (F`A)" .
hoelzl@62624
   471
  show "sigma_sets UNIV (F`A) \<subseteq> sigma_sets UNIV {S. open S}"
hoelzl@62624
   472
    unfolding borel_rev_eq using F by (intro borel_sigma_sets_subset) auto
hoelzl@62624
   473
qed auto
hoelzl@62624
   474
hoelzl@62624
   475
lemma borel_eq_sigmaI2:
hoelzl@62624
   476
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set"
hoelzl@62624
   477
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@62624
   478
  assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`B)"
hoelzl@62624
   479
  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
   480
  assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
hoelzl@62624
   481
  shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
hoelzl@62624
   482
  using assms
hoelzl@62624
   483
  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
   484
hoelzl@62624
   485
lemma borel_eq_sigmaI3:
hoelzl@62624
   486
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@62624
   487
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@62624
   488
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV ((\<lambda>(i, j). F i j) ` A))"
hoelzl@62624
   489
  assumes F: "\<And>i j. (i, j) \<in> A \<Longrightarrow> F i j \<in> sets borel"
hoelzl@62624
   490
  shows "borel = sigma UNIV ((\<lambda>(i, j). F i j) ` A)"
hoelzl@62624
   491
  using assms by (intro borel_eq_sigmaI1[where X=X and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@62624
   492
hoelzl@62624
   493
lemma borel_eq_sigmaI4:
hoelzl@62624
   494
  fixes F :: "'i \<Rightarrow> 'a::topological_space set"
hoelzl@62624
   495
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@62624
   496
  assumes borel_eq: "borel = sigma UNIV ((\<lambda>(i, j). G i j)`A)"
hoelzl@62624
   497
  assumes X: "\<And>i j. (i, j) \<in> A \<Longrightarrow> G i j \<in> sets (sigma UNIV (range F))"
hoelzl@62624
   498
  assumes F: "\<And>i. F i \<in> sets borel"
hoelzl@62624
   499
  shows "borel = sigma UNIV (range F)"
hoelzl@62624
   500
  using assms by (intro borel_eq_sigmaI1[where X="(\<lambda>(i, j). G i j) ` A" and F=F]) auto
hoelzl@62624
   501
hoelzl@62624
   502
lemma borel_eq_sigmaI5:
hoelzl@62624
   503
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and G :: "'l \<Rightarrow> 'a::topological_space set"
hoelzl@62624
   504
  assumes borel_eq: "borel = sigma UNIV (range G)"
hoelzl@62624
   505
  assumes X: "\<And>i. G i \<in> sets (sigma UNIV (range (\<lambda>(i, j). F i j)))"
hoelzl@62624
   506
  assumes F: "\<And>i j. F i j \<in> sets borel"
hoelzl@62624
   507
  shows "borel = sigma UNIV (range (\<lambda>(i, j). F i j))"
hoelzl@62624
   508
  using assms by (intro borel_eq_sigmaI1[where X="range G" and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@62624
   509
hoelzl@59088
   510
lemma second_countable_borel_measurable:
hoelzl@59088
   511
  fixes X :: "'a::second_countable_topology set set"
hoelzl@59088
   512
  assumes eq: "open = generate_topology X"
hoelzl@59088
   513
  shows "borel = sigma UNIV X"
hoelzl@59088
   514
  unfolding borel_def
hoelzl@59088
   515
proof (intro sigma_eqI sigma_sets_eqI)
hoelzl@59088
   516
  interpret X: sigma_algebra UNIV "sigma_sets UNIV X"
hoelzl@59088
   517
    by (rule sigma_algebra_sigma_sets) simp
hoelzl@59088
   518
hoelzl@59088
   519
  fix S :: "'a set" assume "S \<in> Collect open"
hoelzl@59088
   520
  then have "generate_topology X S"
hoelzl@59088
   521
    by (auto simp: eq)
hoelzl@59088
   522
  then show "S \<in> sigma_sets UNIV X"
hoelzl@59088
   523
  proof induction
hoelzl@59088
   524
    case (UN K)
hoelzl@59088
   525
    then have K: "\<And>k. k \<in> K \<Longrightarrow> open k"
hoelzl@59088
   526
      unfolding eq by auto
hoelzl@59088
   527
    from ex_countable_basis obtain B :: "'a set set" where
hoelzl@59088
   528
      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
   529
      by (auto simp: topological_basis_def)
hoelzl@59088
   530
    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
   531
      by metis
wenzelm@63040
   532
    define U where "U = (\<Union>k\<in>K. m k)"
hoelzl@59088
   533
    with m have "countable U"
wenzelm@61808
   534
      by (intro countable_subset[OF _ \<open>countable B\<close>]) auto
hoelzl@59088
   535
    have "\<Union>U = (\<Union>A\<in>U. A)" by simp
hoelzl@59088
   536
    also have "\<dots> = \<Union>K"
hoelzl@59088
   537
      unfolding U_def UN_simps by (simp add: m)
hoelzl@59088
   538
    finally have "\<Union>U = \<Union>K" .
hoelzl@59088
   539
hoelzl@59088
   540
    have "\<forall>b\<in>U. \<exists>k\<in>K. b \<subseteq> k"
hoelzl@59088
   541
      using m by (auto simp: U_def)
hoelzl@59088
   542
    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
   543
      by metis
hoelzl@59088
   544
    then have "(\<Union>b\<in>U. u b) \<subseteq> \<Union>K" "\<Union>U \<subseteq> (\<Union>b\<in>U. u b)"
hoelzl@59088
   545
      by auto
hoelzl@59088
   546
    then have "\<Union>K = (\<Union>b\<in>U. u b)"
wenzelm@61808
   547
      unfolding \<open>\<Union>U = \<Union>K\<close> by auto
hoelzl@59088
   548
    also have "\<dots> \<in> sigma_sets UNIV X"
wenzelm@61808
   549
      using u UN by (intro X.countable_UN' \<open>countable U\<close>) auto
hoelzl@59088
   550
    finally show "\<Union>K \<in> sigma_sets UNIV X" .
hoelzl@59088
   551
  qed auto
hoelzl@59088
   552
qed (auto simp: eq intro: generate_topology.Basis)
hoelzl@59088
   553
hoelzl@62624
   554
lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
hoelzl@62624
   555
  unfolding borel_def
hoelzl@62624
   556
proof (intro sigma_eqI sigma_sets_eqI, safe)
hoelzl@62624
   557
  fix x :: "'a set" assume "open x"
hoelzl@62624
   558
  hence "x = UNIV - (UNIV - x)" by auto
hoelzl@62624
   559
  also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
hoelzl@62624
   560
    by (force intro: sigma_sets.Compl simp: \<open>open x\<close>)
hoelzl@62624
   561
  finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
hoelzl@62624
   562
next
hoelzl@62624
   563
  fix x :: "'a set" assume "closed x"
hoelzl@62624
   564
  hence "x = UNIV - (UNIV - x)" by auto
hoelzl@62624
   565
  also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
hoelzl@62624
   566
    by (force intro: sigma_sets.Compl simp: \<open>closed x\<close>)
hoelzl@62624
   567
  finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
hoelzl@62624
   568
qed simp_all
hoelzl@62624
   569
hoelzl@62624
   570
lemma borel_eq_countable_basis:
hoelzl@62624
   571
  fixes B::"'a::topological_space set set"
hoelzl@62624
   572
  assumes "countable B"
hoelzl@62624
   573
  assumes "topological_basis B"
hoelzl@62624
   574
  shows "borel = sigma UNIV B"
hoelzl@62624
   575
  unfolding borel_def
hoelzl@62624
   576
proof (intro sigma_eqI sigma_sets_eqI, safe)
hoelzl@62624
   577
  interpret countable_basis using assms by unfold_locales
hoelzl@62624
   578
  fix X::"'a set" assume "open X"
hoelzl@62624
   579
  from open_countable_basisE[OF this] guess B' . note B' = this
hoelzl@62624
   580
  then show "X \<in> sigma_sets UNIV B"
hoelzl@62624
   581
    by (blast intro: sigma_sets_UNION \<open>countable B\<close> countable_subset)
hoelzl@62624
   582
next
hoelzl@62624
   583
  fix b assume "b \<in> B"
hoelzl@62624
   584
  hence "open b" by (rule topological_basis_open[OF assms(2)])
hoelzl@62624
   585
  thus "b \<in> sigma_sets UNIV (Collect open)" by auto
hoelzl@62624
   586
qed simp_all
hoelzl@62624
   587
hoelzl@59361
   588
lemma borel_measurable_continuous_on_restrict:
hoelzl@59361
   589
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@59361
   590
  assumes f: "continuous_on A f"
hoelzl@59361
   591
  shows "f \<in> borel_measurable (restrict_space borel A)"
hoelzl@57138
   592
proof (rule borel_measurableI)
hoelzl@57138
   593
  fix S :: "'b set" assume "open S"
hoelzl@59361
   594
  with f obtain T where "f -` S \<inter> A = T \<inter> A" "open T"
hoelzl@59361
   595
    by (metis continuous_on_open_invariant)
hoelzl@59361
   596
  then show "f -` S \<inter> space (restrict_space borel A) \<in> sets (restrict_space borel A)"
hoelzl@59361
   597
    by (force simp add: sets_restrict_space space_restrict_space)
hoelzl@57137
   598
qed
hoelzl@57137
   599
hoelzl@59361
   600
lemma borel_measurable_continuous_on1: "continuous_on UNIV f \<Longrightarrow> f \<in> borel_measurable borel"
hoelzl@59361
   601
  by (drule borel_measurable_continuous_on_restrict) simp
hoelzl@59361
   602
hoelzl@59361
   603
lemma borel_measurable_continuous_on_if:
hoelzl@59415
   604
  "A \<in> sets borel \<Longrightarrow> continuous_on A f \<Longrightarrow> continuous_on (- A) g \<Longrightarrow>
hoelzl@59415
   605
    (\<lambda>x. if x \<in> A then f x else g x) \<in> borel_measurable borel"
hoelzl@59415
   606
  by (auto simp add: measurable_If_restrict_space_iff Collect_neg_eq
hoelzl@59415
   607
           intro!: borel_measurable_continuous_on_restrict)
hoelzl@59361
   608
hoelzl@57275
   609
lemma borel_measurable_continuous_countable_exceptions:
hoelzl@57275
   610
  fixes f :: "'a::t1_space \<Rightarrow> 'b::topological_space"
hoelzl@57275
   611
  assumes X: "countable X"
hoelzl@57275
   612
  assumes "continuous_on (- X) f"
hoelzl@57275
   613
  shows "f \<in> borel_measurable borel"
hoelzl@57275
   614
proof (rule measurable_discrete_difference[OF _ X])
hoelzl@57275
   615
  have "X \<in> sets borel"
hoelzl@57275
   616
    by (rule sets.countable[OF _ X]) auto
hoelzl@57275
   617
  then show "(\<lambda>x. if x \<in> X then undefined else f x) \<in> borel_measurable borel"
hoelzl@57275
   618
    by (intro borel_measurable_continuous_on_if assms continuous_intros)
hoelzl@57275
   619
qed auto
hoelzl@57275
   620
hoelzl@57138
   621
lemma borel_measurable_continuous_on:
hoelzl@57138
   622
  assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
hoelzl@57138
   623
  shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
hoelzl@57138
   624
  using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
hoelzl@57138
   625
hoelzl@57138
   626
lemma borel_measurable_continuous_on_indicator:
hoelzl@57138
   627
  fixes f g :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@59415
   628
  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
   629
  by (subst borel_measurable_restrict_space_iff[symmetric])
hoelzl@59415
   630
     (auto intro: borel_measurable_continuous_on_restrict)
hoelzl@50002
   631
hoelzl@50526
   632
lemma borel_measurable_Pair[measurable (raw)]:
hoelzl@50881
   633
  fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
hoelzl@50526
   634
  assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50526
   635
  assumes g[measurable]: "g \<in> borel_measurable M"
hoelzl@50526
   636
  shows "(\<lambda>x. (f x, g x)) \<in> borel_measurable M"
hoelzl@50526
   637
proof (subst borel_eq_countable_basis)
hoelzl@50526
   638
  let ?B = "SOME B::'b set set. countable B \<and> topological_basis B"
hoelzl@50526
   639
  let ?C = "SOME B::'c set set. countable B \<and> topological_basis B"
hoelzl@50526
   640
  let ?P = "(\<lambda>(b, c). b \<times> c) ` (?B \<times> ?C)"
hoelzl@50526
   641
  show "countable ?P" "topological_basis ?P"
hoelzl@50526
   642
    by (auto intro!: countable_basis topological_basis_prod is_basis)
hoelzl@38656
   643
hoelzl@50526
   644
  show "(\<lambda>x. (f x, g x)) \<in> measurable M (sigma UNIV ?P)"
hoelzl@50526
   645
  proof (rule measurable_measure_of)
hoelzl@50526
   646
    fix S assume "S \<in> ?P"
hoelzl@50526
   647
    then obtain b c where "b \<in> ?B" "c \<in> ?C" and S: "S = b \<times> c" by auto
hoelzl@50526
   648
    then have borel: "open b" "open c"
hoelzl@50526
   649
      by (auto intro: is_basis topological_basis_open)
hoelzl@50526
   650
    have "(\<lambda>x. (f x, g x)) -` S \<inter> space M = (f -` b \<inter> space M) \<inter> (g -` c \<inter> space M)"
hoelzl@50526
   651
      unfolding S by auto
hoelzl@50526
   652
    also have "\<dots> \<in> sets M"
hoelzl@50526
   653
      using borel by simp
hoelzl@50526
   654
    finally show "(\<lambda>x. (f x, g x)) -` S \<inter> space M \<in> sets M" .
hoelzl@50526
   655
  qed auto
hoelzl@39087
   656
qed
hoelzl@39087
   657
hoelzl@49774
   658
lemma borel_measurable_continuous_Pair:
hoelzl@50881
   659
  fixes f :: "'a \<Rightarrow> 'b::second_countable_topology" and g :: "'a \<Rightarrow> 'c::second_countable_topology"
hoelzl@50003
   660
  assumes [measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   661
  assumes [measurable]: "g \<in> borel_measurable M"
hoelzl@49774
   662
  assumes H: "continuous_on UNIV (\<lambda>x. H (fst x) (snd x))"
hoelzl@49774
   663
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   664
proof -
hoelzl@49774
   665
  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
   666
  show ?thesis
hoelzl@49774
   667
    unfolding eq by (rule borel_measurable_continuous_on[OF H]) auto
hoelzl@49774
   668
qed
hoelzl@49774
   669
wenzelm@61808
   670
subsection \<open>Borel spaces on order topologies\<close>
hoelzl@59088
   671
hoelzl@62624
   672
lemma [measurable]:
hoelzl@62624
   673
  fixes a b :: "'a::linorder_topology"
hoelzl@62624
   674
  shows lessThan_borel: "{..< a} \<in> sets borel"
hoelzl@62624
   675
    and greaterThan_borel: "{a <..} \<in> sets borel"
hoelzl@62624
   676
    and greaterThanLessThan_borel: "{a<..<b} \<in> sets borel"
hoelzl@62624
   677
    and atMost_borel: "{..a} \<in> sets borel"
hoelzl@62624
   678
    and atLeast_borel: "{a..} \<in> sets borel"
hoelzl@62624
   679
    and atLeastAtMost_borel: "{a..b} \<in> sets borel"
hoelzl@62624
   680
    and greaterThanAtMost_borel: "{a<..b} \<in> sets borel"
hoelzl@62624
   681
    and atLeastLessThan_borel: "{a..<b} \<in> sets borel"
hoelzl@62624
   682
  unfolding greaterThanAtMost_def atLeastLessThan_def
hoelzl@62624
   683
  by (blast intro: borel_open borel_closed open_lessThan open_greaterThan open_greaterThanLessThan
hoelzl@62624
   684
                   closed_atMost closed_atLeast closed_atLeastAtMost)+
hoelzl@59088
   685
hoelzl@59088
   686
lemma borel_Iio:
hoelzl@59088
   687
  "borel = sigma UNIV (range lessThan :: 'a::{linorder_topology, second_countable_topology} set set)"
hoelzl@59088
   688
  unfolding second_countable_borel_measurable[OF open_generated_order]
hoelzl@59088
   689
proof (intro sigma_eqI sigma_sets_eqI)
hoelzl@59088
   690
  from countable_dense_setE guess D :: "'a set" . note D = this
hoelzl@59088
   691
hoelzl@59088
   692
  interpret L: sigma_algebra UNIV "sigma_sets UNIV (range lessThan)"
hoelzl@59088
   693
    by (rule sigma_algebra_sigma_sets) simp
hoelzl@59088
   694
hoelzl@59088
   695
  fix A :: "'a set" assume "A \<in> range lessThan \<union> range greaterThan"
hoelzl@59088
   696
  then obtain y where "A = {y <..} \<or> A = {..< y}"
hoelzl@59088
   697
    by blast
hoelzl@59088
   698
  then show "A \<in> sigma_sets UNIV (range lessThan)"
hoelzl@59088
   699
  proof
hoelzl@59088
   700
    assume A: "A = {y <..}"
hoelzl@59088
   701
    show ?thesis
hoelzl@59088
   702
    proof cases
hoelzl@59088
   703
      assume "\<forall>x>y. \<exists>d. y < d \<and> d < x"
hoelzl@59088
   704
      with D(2)[of "{y <..< x}" for x] have "\<forall>x>y. \<exists>d\<in>D. y < d \<and> d < x"
hoelzl@59088
   705
        by (auto simp: set_eq_iff)
hoelzl@59088
   706
      then have "A = UNIV - (\<Inter>d\<in>{d\<in>D. y < d}. {..< d})"
hoelzl@59088
   707
        by (auto simp: A) (metis less_asym)
hoelzl@59088
   708
      also have "\<dots> \<in> sigma_sets UNIV (range lessThan)"
hoelzl@59088
   709
        using D(1) by (intro L.Diff L.top L.countable_INT'') auto
hoelzl@59088
   710
      finally show ?thesis .
hoelzl@59088
   711
    next
hoelzl@59088
   712
      assume "\<not> (\<forall>x>y. \<exists>d. y < d \<and> d < x)"
hoelzl@59088
   713
      then obtain x where "y < x"  "\<And>d. y < d \<Longrightarrow> \<not> d < x"
hoelzl@59088
   714
        by auto
hoelzl@59088
   715
      then have "A = UNIV - {..< x}"
hoelzl@59088
   716
        unfolding A by (auto simp: not_less[symmetric])
hoelzl@59088
   717
      also have "\<dots> \<in> sigma_sets UNIV (range lessThan)"
hoelzl@59088
   718
        by auto
hoelzl@59088
   719
      finally show ?thesis .
hoelzl@59088
   720
    qed
hoelzl@59088
   721
  qed auto
hoelzl@59088
   722
qed auto
hoelzl@59088
   723
hoelzl@59088
   724
lemma borel_Ioi:
hoelzl@59088
   725
  "borel = sigma UNIV (range greaterThan :: 'a::{linorder_topology, second_countable_topology} set set)"
hoelzl@59088
   726
  unfolding second_countable_borel_measurable[OF open_generated_order]
hoelzl@59088
   727
proof (intro sigma_eqI sigma_sets_eqI)
hoelzl@59088
   728
  from countable_dense_setE guess D :: "'a set" . note D = this
hoelzl@59088
   729
hoelzl@59088
   730
  interpret L: sigma_algebra UNIV "sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   731
    by (rule sigma_algebra_sigma_sets) simp
hoelzl@59088
   732
hoelzl@59088
   733
  fix A :: "'a set" assume "A \<in> range lessThan \<union> range greaterThan"
hoelzl@59088
   734
  then obtain y where "A = {y <..} \<or> A = {..< y}"
hoelzl@59088
   735
    by blast
hoelzl@59088
   736
  then show "A \<in> sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   737
  proof
hoelzl@59088
   738
    assume A: "A = {..< y}"
hoelzl@59088
   739
    show ?thesis
hoelzl@59088
   740
    proof cases
hoelzl@59088
   741
      assume "\<forall>x<y. \<exists>d. x < d \<and> d < y"
hoelzl@59088
   742
      with D(2)[of "{x <..< y}" for x] have "\<forall>x<y. \<exists>d\<in>D. x < d \<and> d < y"
hoelzl@59088
   743
        by (auto simp: set_eq_iff)
hoelzl@59088
   744
      then have "A = UNIV - (\<Inter>d\<in>{d\<in>D. d < y}. {d <..})"
hoelzl@59088
   745
        by (auto simp: A) (metis less_asym)
hoelzl@59088
   746
      also have "\<dots> \<in> sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   747
        using D(1) by (intro L.Diff L.top L.countable_INT'') auto
hoelzl@59088
   748
      finally show ?thesis .
hoelzl@59088
   749
    next
hoelzl@59088
   750
      assume "\<not> (\<forall>x<y. \<exists>d. x < d \<and> d < y)"
hoelzl@59088
   751
      then obtain x where "x < y"  "\<And>d. y > d \<Longrightarrow> x \<ge> d"
hoelzl@59088
   752
        by (auto simp: not_less[symmetric])
hoelzl@59088
   753
      then have "A = UNIV - {x <..}"
hoelzl@59088
   754
        unfolding A Compl_eq_Diff_UNIV[symmetric] by auto
hoelzl@59088
   755
      also have "\<dots> \<in> sigma_sets UNIV (range greaterThan)"
hoelzl@59088
   756
        by auto
hoelzl@59088
   757
      finally show ?thesis .
hoelzl@59088
   758
    qed
hoelzl@59088
   759
  qed auto
hoelzl@59088
   760
qed auto
hoelzl@59088
   761
hoelzl@59088
   762
lemma borel_measurableI_less:
hoelzl@59088
   763
  fixes f :: "'a \<Rightarrow> 'b::{linorder_topology, second_countable_topology}"
hoelzl@59088
   764
  shows "(\<And>y. {x\<in>space M. f x < y} \<in> sets M) \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@59088
   765
  unfolding borel_Iio
hoelzl@59088
   766
  by (rule measurable_measure_of) (auto simp: Int_def conj_commute)
hoelzl@59088
   767
hoelzl@59088
   768
lemma borel_measurableI_greater:
hoelzl@59088
   769
  fixes f :: "'a \<Rightarrow> 'b::{linorder_topology, second_countable_topology}"
hoelzl@59088
   770
  shows "(\<And>y. {x\<in>space M. y < f x} \<in> sets M) \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@59088
   771
  unfolding borel_Ioi
hoelzl@59088
   772
  by (rule measurable_measure_of) (auto simp: Int_def conj_commute)
hoelzl@59088
   773
hoelzl@62624
   774
lemma borel_measurableI_le:
hoelzl@62624
   775
  fixes f :: "'a \<Rightarrow> 'b::{linorder_topology, second_countable_topology}"
hoelzl@62624
   776
  shows "(\<And>y. {x\<in>space M. f x \<le> y} \<in> sets M) \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@62624
   777
  by (rule borel_measurableI_greater) (auto simp: not_le[symmetric])
hoelzl@62624
   778
hoelzl@62624
   779
lemma borel_measurableI_ge:
hoelzl@62624
   780
  fixes f :: "'a \<Rightarrow> 'b::{linorder_topology, second_countable_topology}"
hoelzl@62624
   781
  shows "(\<And>y. {x\<in>space M. y \<le> f x} \<in> sets M) \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@62624
   782
  by (rule borel_measurableI_less) (auto simp: not_le[symmetric])
hoelzl@62624
   783
hoelzl@62624
   784
lemma borel_measurable_less[measurable]:
hoelzl@63332
   785
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, linorder_topology}"
hoelzl@62624
   786
  assumes "f \<in> borel_measurable M"
hoelzl@62624
   787
  assumes "g \<in> borel_measurable M"
hoelzl@62624
   788
  shows "{w \<in> space M. f w < g w} \<in> sets M"
hoelzl@62624
   789
proof -
hoelzl@62624
   790
  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
   791
    by auto
hoelzl@62624
   792
  also have "\<dots> \<in> sets M"
hoelzl@62624
   793
    by (intro measurable_sets[OF borel_measurable_Pair borel_open, OF assms open_Collect_less]
hoelzl@62624
   794
              continuous_intros)
hoelzl@62624
   795
  finally show ?thesis .
hoelzl@62624
   796
qed
hoelzl@62624
   797
hoelzl@62624
   798
lemma
hoelzl@63332
   799
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, linorder_topology}"
hoelzl@62624
   800
  assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@62624
   801
  assumes g[measurable]: "g \<in> borel_measurable M"
hoelzl@62624
   802
  shows borel_measurable_le[measurable]: "{w \<in> space M. f w \<le> g w} \<in> sets M"
hoelzl@62624
   803
    and borel_measurable_eq[measurable]: "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@62624
   804
    and borel_measurable_neq: "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
hoelzl@62624
   805
  unfolding eq_iff not_less[symmetric]
hoelzl@62624
   806
  by measurable
hoelzl@62624
   807
hoelzl@59088
   808
lemma borel_measurable_SUP[measurable (raw)]:
hoelzl@59088
   809
  fixes F :: "_ \<Rightarrow> _ \<Rightarrow> _::{complete_linorder, linorder_topology, second_countable_topology}"
hoelzl@59088
   810
  assumes [simp]: "countable I"
hoelzl@59088
   811
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> borel_measurable M"
hoelzl@59088
   812
  shows "(\<lambda>x. SUP i:I. F i x) \<in> borel_measurable M"
hoelzl@59088
   813
  by (rule borel_measurableI_greater) (simp add: less_SUP_iff)
hoelzl@59088
   814
hoelzl@59088
   815
lemma borel_measurable_INF[measurable (raw)]:
hoelzl@59088
   816
  fixes F :: "_ \<Rightarrow> _ \<Rightarrow> _::{complete_linorder, linorder_topology, second_countable_topology}"
hoelzl@59088
   817
  assumes [simp]: "countable I"
hoelzl@59088
   818
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> borel_measurable M"
hoelzl@59088
   819
  shows "(\<lambda>x. INF i:I. F i x) \<in> borel_measurable M"
hoelzl@59088
   820
  by (rule borel_measurableI_less) (simp add: INF_less_iff)
hoelzl@59088
   821
hoelzl@62624
   822
lemma borel_measurable_cSUP[measurable (raw)]:
hoelzl@62624
   823
  fixes F :: "_ \<Rightarrow> _ \<Rightarrow> 'a::{conditionally_complete_linorder, linorder_topology, second_countable_topology}"
hoelzl@62624
   824
  assumes [simp]: "countable I"
hoelzl@62624
   825
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> borel_measurable M"
hoelzl@62624
   826
  assumes bdd: "\<And>x. x \<in> space M \<Longrightarrow> bdd_above ((\<lambda>i. F i x) ` I)"
hoelzl@62624
   827
  shows "(\<lambda>x. SUP i:I. F i x) \<in> borel_measurable M"
hoelzl@62624
   828
proof cases
hoelzl@62624
   829
  assume "I = {}" then show ?thesis
hoelzl@62624
   830
    unfolding \<open>I = {}\<close> image_empty by simp
hoelzl@62624
   831
next
hoelzl@62624
   832
  assume "I \<noteq> {}"
hoelzl@62624
   833
  show ?thesis
hoelzl@62624
   834
  proof (rule borel_measurableI_le)
hoelzl@62624
   835
    fix y
hoelzl@62624
   836
    have "{x \<in> space M. \<forall>i\<in>I. F i x \<le> y} \<in> sets M"
hoelzl@62624
   837
      by measurable
hoelzl@62624
   838
    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
   839
      by (simp add: cSUP_le_iff \<open>I \<noteq> {}\<close> bdd cong: conj_cong)
hoelzl@62624
   840
    finally show "{x \<in> space M. (SUP i:I. F i x) \<le>  y} \<in> sets M"  .
hoelzl@62624
   841
  qed
hoelzl@62624
   842
qed
hoelzl@62624
   843
hoelzl@62624
   844
lemma borel_measurable_cINF[measurable (raw)]:
hoelzl@62624
   845
  fixes F :: "_ \<Rightarrow> _ \<Rightarrow> 'a::{conditionally_complete_linorder, linorder_topology, second_countable_topology}"
hoelzl@62624
   846
  assumes [simp]: "countable I"
hoelzl@62624
   847
  assumes [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> borel_measurable M"
hoelzl@62624
   848
  assumes bdd: "\<And>x. x \<in> space M \<Longrightarrow> bdd_below ((\<lambda>i. F i x) ` I)"
hoelzl@62624
   849
  shows "(\<lambda>x. INF i:I. F i x) \<in> borel_measurable M"
hoelzl@62624
   850
proof cases
hoelzl@62624
   851
  assume "I = {}" then show ?thesis
hoelzl@62624
   852
    unfolding \<open>I = {}\<close> image_empty by simp
hoelzl@62624
   853
next
hoelzl@62624
   854
  assume "I \<noteq> {}"
hoelzl@62624
   855
  show ?thesis
hoelzl@62624
   856
  proof (rule borel_measurableI_ge)
hoelzl@62624
   857
    fix y
hoelzl@62624
   858
    have "{x \<in> space M. \<forall>i\<in>I. y \<le> F i x} \<in> sets M"
hoelzl@62624
   859
      by measurable
hoelzl@62624
   860
    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
   861
      by (simp add: le_cINF_iff \<open>I \<noteq> {}\<close> bdd cong: conj_cong)
hoelzl@62624
   862
    finally show "{x \<in> space M. y \<le> (INF i:I. F i x)} \<in> sets M"  .
hoelzl@62624
   863
  qed
hoelzl@62624
   864
qed
hoelzl@62624
   865
hoelzl@59088
   866
lemma borel_measurable_lfp[consumes 1, case_names continuity step]:
hoelzl@59088
   867
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_linorder, linorder_topology, second_countable_topology})"
hoelzl@60172
   868
  assumes "sup_continuous F"
hoelzl@59088
   869
  assumes *: "\<And>f. f \<in> borel_measurable M \<Longrightarrow> F f \<in> borel_measurable M"
hoelzl@59088
   870
  shows "lfp F \<in> borel_measurable M"
hoelzl@59088
   871
proof -
hoelzl@59088
   872
  { fix i have "((F ^^ i) bot) \<in> borel_measurable M"
hoelzl@59088
   873
      by (induct i) (auto intro!: *) }
hoelzl@59088
   874
  then have "(\<lambda>x. SUP i. (F ^^ i) bot x) \<in> borel_measurable M"
hoelzl@59088
   875
    by measurable
hoelzl@59088
   876
  also have "(\<lambda>x. SUP i. (F ^^ i) bot x) = (SUP i. (F ^^ i) bot)"
hoelzl@59088
   877
    by auto
hoelzl@59088
   878
  also have "(SUP i. (F ^^ i) bot) = lfp F"
hoelzl@60172
   879
    by (rule sup_continuous_lfp[symmetric]) fact
hoelzl@59088
   880
  finally show ?thesis .
hoelzl@59088
   881
qed
hoelzl@59088
   882
hoelzl@59088
   883
lemma borel_measurable_gfp[consumes 1, case_names continuity step]:
hoelzl@59088
   884
  fixes F :: "('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b::{complete_linorder, linorder_topology, second_countable_topology})"
hoelzl@60172
   885
  assumes "inf_continuous F"
hoelzl@59088
   886
  assumes *: "\<And>f. f \<in> borel_measurable M \<Longrightarrow> F f \<in> borel_measurable M"
hoelzl@59088
   887
  shows "gfp F \<in> borel_measurable M"
hoelzl@59088
   888
proof -
hoelzl@59088
   889
  { fix i have "((F ^^ i) top) \<in> borel_measurable M"
hoelzl@59088
   890
      by (induct i) (auto intro!: * simp: bot_fun_def) }
hoelzl@59088
   891
  then have "(\<lambda>x. INF i. (F ^^ i) top x) \<in> borel_measurable M"
hoelzl@59088
   892
    by measurable
hoelzl@59088
   893
  also have "(\<lambda>x. INF i. (F ^^ i) top x) = (INF i. (F ^^ i) top)"
hoelzl@59088
   894
    by auto
hoelzl@59088
   895
  also have "\<dots> = gfp F"
hoelzl@60172
   896
    by (rule inf_continuous_gfp[symmetric]) fact
hoelzl@59088
   897
  finally show ?thesis .
hoelzl@59088
   898
qed
hoelzl@59088
   899
hoelzl@62624
   900
lemma borel_measurable_max[measurable (raw)]:
hoelzl@62624
   901
  "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
   902
  by (rule borel_measurableI_less) simp
hoelzl@62624
   903
hoelzl@62624
   904
lemma borel_measurable_min[measurable (raw)]:
hoelzl@62624
   905
  "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
   906
  by (rule borel_measurableI_greater) simp
hoelzl@62624
   907
hoelzl@62624
   908
lemma borel_measurable_Min[measurable (raw)]:
hoelzl@62624
   909
  "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
   910
proof (induct I rule: finite_induct)
hoelzl@62624
   911
  case (insert i I) then show ?case
hoelzl@62624
   912
    by (cases "I = {}") auto
hoelzl@62624
   913
qed auto
hoelzl@62624
   914
hoelzl@62624
   915
lemma borel_measurable_Max[measurable (raw)]:
hoelzl@62624
   916
  "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
   917
proof (induct I rule: finite_induct)
hoelzl@62624
   918
  case (insert i I) then show ?case
hoelzl@62624
   919
    by (cases "I = {}") auto
hoelzl@62624
   920
qed auto
hoelzl@62624
   921
hoelzl@62624
   922
lemma borel_measurable_sup[measurable (raw)]:
hoelzl@62624
   923
  "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
   924
  unfolding sup_max by measurable
hoelzl@62624
   925
hoelzl@62624
   926
lemma borel_measurable_inf[measurable (raw)]:
hoelzl@62624
   927
  "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
   928
  unfolding inf_min by measurable
hoelzl@62624
   929
hoelzl@62624
   930
lemma [measurable (raw)]:
hoelzl@62624
   931
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{complete_linorder, second_countable_topology, linorder_topology}"
hoelzl@62624
   932
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@62624
   933
  shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@62624
   934
    and borel_measurable_limsup: "(\<lambda>x. limsup (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@62624
   935
  unfolding liminf_SUP_INF limsup_INF_SUP using assms by auto
hoelzl@62624
   936
hoelzl@62624
   937
lemma measurable_convergent[measurable (raw)]:
hoelzl@63332
   938
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{complete_linorder, second_countable_topology, linorder_topology}"
hoelzl@62624
   939
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@62624
   940
  shows "Measurable.pred M (\<lambda>x. convergent (\<lambda>i. f i x))"
hoelzl@62624
   941
  unfolding convergent_ereal by measurable
hoelzl@62624
   942
hoelzl@62624
   943
lemma sets_Collect_convergent[measurable]:
hoelzl@63332
   944
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{complete_linorder, second_countable_topology, linorder_topology}"
hoelzl@62624
   945
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@62624
   946
  shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
hoelzl@62624
   947
  by measurable
hoelzl@62624
   948
hoelzl@62624
   949
lemma borel_measurable_lim[measurable (raw)]:
hoelzl@63332
   950
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{complete_linorder, second_countable_topology, linorder_topology}"
hoelzl@62624
   951
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@62624
   952
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@62624
   953
proof -
hoelzl@62624
   954
  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
   955
    by (simp add: lim_def convergent_def convergent_limsup_cl)
hoelzl@62624
   956
  then show ?thesis
hoelzl@62624
   957
    by simp
hoelzl@62624
   958
qed
hoelzl@62624
   959
hoelzl@62624
   960
lemma borel_measurable_LIMSEQ_order:
hoelzl@63332
   961
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{complete_linorder, second_countable_topology, linorder_topology}"
hoelzl@62624
   962
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) \<longlonglongrightarrow> u' x"
hoelzl@62624
   963
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@62624
   964
  shows "u' \<in> borel_measurable M"
hoelzl@62624
   965
proof -
hoelzl@62624
   966
  have "\<And>x. x \<in> space M \<Longrightarrow> u' x = liminf (\<lambda>n. u n x)"
hoelzl@62624
   967
    using u' by (simp add: lim_imp_Liminf[symmetric])
hoelzl@62624
   968
  with u show ?thesis by (simp cong: measurable_cong)
hoelzl@62624
   969
qed
hoelzl@62624
   970
hoelzl@62624
   971
subsection \<open>Borel spaces on topological monoids\<close>
hoelzl@62624
   972
hoelzl@62624
   973
lemma borel_measurable_add[measurable (raw)]:
hoelzl@62624
   974
  fixes f g :: "'a \<Rightarrow> 'b::{second_countable_topology, topological_monoid_add}"
hoelzl@62624
   975
  assumes f: "f \<in> borel_measurable M"
hoelzl@62624
   976
  assumes g: "g \<in> borel_measurable M"
hoelzl@62624
   977
  shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@62624
   978
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@62624
   979
nipkow@64267
   980
lemma borel_measurable_sum[measurable (raw)]:
hoelzl@62624
   981
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> 'b::{second_countable_topology, topological_comm_monoid_add}"
hoelzl@62624
   982
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@62624
   983
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@62624
   984
proof cases
hoelzl@62624
   985
  assume "finite S"
hoelzl@62624
   986
  thus ?thesis using assms by induct auto
hoelzl@62624
   987
qed simp
hoelzl@62624
   988
hoelzl@62624
   989
lemma borel_measurable_suminf_order[measurable (raw)]:
hoelzl@63332
   990
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{complete_linorder, second_countable_topology, linorder_topology, topological_comm_monoid_add}"
hoelzl@62624
   991
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@62624
   992
  shows "(\<lambda>x. suminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@62624
   993
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@62624
   994
hoelzl@62624
   995
subsection \<open>Borel spaces on Euclidean spaces\<close>
hoelzl@50526
   996
hoelzl@50526
   997
lemma borel_measurable_inner[measurable (raw)]:
hoelzl@50881
   998
  fixes f g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_inner}"
hoelzl@50526
   999
  assumes "f \<in> borel_measurable M"
hoelzl@50526
  1000
  assumes "g \<in> borel_measurable M"
hoelzl@50526
  1001
  shows "(\<lambda>x. f x \<bullet> g x) \<in> borel_measurable M"
hoelzl@50526
  1002
  using assms
hoelzl@56371
  1003
  by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@50526
  1004
immler@54775
  1005
notation
immler@54775
  1006
  eucl_less (infix "<e" 50)
immler@54775
  1007
immler@54775
  1008
lemma box_oc: "{x. a <e x \<and> x \<le> b} = {x. a <e x} \<inter> {..b}"
immler@54775
  1009
  and box_co: "{x. a \<le> x \<and> x <e b} = {a..} \<inter> {x. x <e b}"
immler@54775
  1010
  by auto
immler@54775
  1011
hoelzl@51683
  1012
lemma eucl_ivals[measurable]:
wenzelm@61076
  1013
  fixes a b :: "'a::ordered_euclidean_space"
immler@54775
  1014
  shows "{x. x <e a} \<in> sets borel"
immler@54775
  1015
    and "{x. a <e x} \<in> sets borel"
hoelzl@51683
  1016
    and "{..a} \<in> sets borel"
hoelzl@51683
  1017
    and "{a..} \<in> sets borel"
hoelzl@51683
  1018
    and "{a..b} \<in> sets borel"
immler@54775
  1019
    and  "{x. a <e x \<and> x \<le> b} \<in> sets borel"
immler@54775
  1020
    and "{x. a \<le> x \<and>  x <e b} \<in> sets borel"
immler@54775
  1021
  unfolding box_oc box_co
immler@54775
  1022
  by (auto intro: borel_open borel_closed)
hoelzl@50526
  1023
hoelzl@62372
  1024
lemma
hoelzl@51683
  1025
  fixes i :: "'a::{second_countable_topology, real_inner}"
hoelzl@51683
  1026
  shows hafspace_less_borel: "{x. a < x \<bullet> i} \<in> sets borel"
hoelzl@51683
  1027
    and hafspace_greater_borel: "{x. x \<bullet> i < a} \<in> sets borel"
hoelzl@51683
  1028
    and hafspace_less_eq_borel: "{x. a \<le> x \<bullet> i} \<in> sets borel"
hoelzl@51683
  1029
    and hafspace_greater_eq_borel: "{x. x \<bullet> i \<le> a} \<in> sets borel"
hoelzl@50526
  1030
  by simp_all
hoelzl@50526
  1031
hoelzl@50526
  1032
lemma borel_eq_box:
wenzelm@61076
  1033
  "borel = sigma UNIV (range (\<lambda> (a, b). box a b :: 'a :: euclidean_space set))"
hoelzl@50526
  1034
    (is "_ = ?SIGMA")
hoelzl@50526
  1035
proof (rule borel_eq_sigmaI1[OF borel_def])
hoelzl@50526
  1036
  fix M :: "'a set" assume "M \<in> {S. open S}"
hoelzl@50526
  1037
  then have "open M" by simp
hoelzl@50526
  1038
  show "M \<in> ?SIGMA"
wenzelm@61808
  1039
    apply (subst open_UNION_box[OF \<open>open M\<close>])
hoelzl@50526
  1040
    apply (safe intro!: sets.countable_UN' countable_PiE countable_Collect)
hoelzl@50526
  1041
    apply (auto intro: countable_rat)
hoelzl@50526
  1042
    done
hoelzl@50526
  1043
qed (auto simp: box_def)
hoelzl@50526
  1044
hoelzl@50526
  1045
lemma halfspace_gt_in_halfspace:
hoelzl@50526
  1046
  assumes i: "i \<in> A"
hoelzl@62372
  1047
  shows "{x::'a. a < x \<bullet> i} \<in>
wenzelm@61076
  1048
    sigma_sets UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> A))"
hoelzl@50526
  1049
  (is "?set \<in> ?SIGMA")
hoelzl@50526
  1050
proof -
hoelzl@50526
  1051
  interpret sigma_algebra UNIV ?SIGMA
hoelzl@50526
  1052
    by (intro sigma_algebra_sigma_sets) simp_all
wenzelm@61076
  1053
  have *: "?set = (\<Union>n. UNIV - {x::'a. x \<bullet> i < a + 1 / real (Suc n)})"
lp15@61609
  1054
  proof (safe, simp_all add: not_less del: of_nat_Suc)
hoelzl@50526
  1055
    fix x :: 'a assume "a < x \<bullet> i"
hoelzl@50526
  1056
    with reals_Archimedean[of "x \<bullet> i - a"]
hoelzl@50526
  1057
    obtain n where "a + 1 / real (Suc n) < x \<bullet> i"
hoelzl@59361
  1058
      by (auto simp: field_simps)
hoelzl@50526
  1059
    then show "\<exists>n. a + 1 / real (Suc n) \<le> x \<bullet> i"
hoelzl@50526
  1060
      by (blast intro: less_imp_le)
hoelzl@50526
  1061
  next
hoelzl@50526
  1062
    fix x n
hoelzl@50526
  1063
    have "a < a + 1 / real (Suc n)" by auto
hoelzl@50526
  1064
    also assume "\<dots> \<le> x"
hoelzl@50526
  1065
    finally show "a < x" .
hoelzl@50526
  1066
  qed
hoelzl@50526
  1067
  show "?set \<in> ?SIGMA" unfolding *
haftmann@61424
  1068
    by (auto intro!: Diff sigma_sets_Inter i)
hoelzl@50526
  1069
qed
hoelzl@50526
  1070
hoelzl@50526
  1071
lemma borel_eq_halfspace_less:
hoelzl@50526
  1072
  "borel = sigma UNIV ((\<lambda>(a, i). {x::'a::euclidean_space. x \<bullet> i < a}) ` (UNIV \<times> Basis))"
hoelzl@50526
  1073
  (is "_ = ?SIGMA")
hoelzl@50526
  1074
proof (rule borel_eq_sigmaI2[OF borel_eq_box])
hoelzl@50526
  1075
  fix a b :: 'a
hoelzl@50526
  1076
  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
  1077
    by (auto simp: box_def)
hoelzl@50526
  1078
  also have "\<dots> \<in> sets ?SIGMA"
hoelzl@50526
  1079
    by (intro sets.sets_Collect_conj sets.sets_Collect_finite_All sets.sets_Collect_const)
hoelzl@50526
  1080
       (auto intro!: halfspace_gt_in_halfspace countable_PiE countable_rat)
hoelzl@50526
  1081
  finally show "box a b \<in> sets ?SIGMA" .
hoelzl@50526
  1082
qed auto
hoelzl@50526
  1083
hoelzl@50526
  1084
lemma borel_eq_halfspace_le:
hoelzl@50526
  1085
  "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. x \<bullet> i \<le> a}) ` (UNIV \<times> Basis))"
hoelzl@50526
  1086
  (is "_ = ?SIGMA")
hoelzl@50526
  1087
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@50526
  1088
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
  1089
  then have i: "i \<in> Basis" by auto
hoelzl@50526
  1090
  have *: "{x::'a. x\<bullet>i < a} = (\<Union>n. {x. x\<bullet>i \<le> a - 1/real (Suc n)})"
lp15@61609
  1091
  proof (safe, simp_all del: of_nat_Suc)
hoelzl@50526
  1092
    fix x::'a assume *: "x\<bullet>i < a"
hoelzl@50526
  1093
    with reals_Archimedean[of "a - x\<bullet>i"]
hoelzl@50526
  1094
    obtain n where "x \<bullet> i < a - 1 / (real (Suc n))"
hoelzl@59361
  1095
      by (auto simp: field_simps)
hoelzl@50526
  1096
    then show "\<exists>n. x \<bullet> i \<le> a - 1 / (real (Suc n))"
hoelzl@50526
  1097
      by (blast intro: less_imp_le)
hoelzl@50526
  1098
  next
hoelzl@50526
  1099
    fix x::'a and n
hoelzl@50526
  1100
    assume "x\<bullet>i \<le> a - 1 / real (Suc n)"
hoelzl@50526
  1101
    also have "\<dots> < a" by auto
hoelzl@50526
  1102
    finally show "x\<bullet>i < a" .
hoelzl@50526
  1103
  qed
hoelzl@50526
  1104
  show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
hoelzl@59361
  1105
    by (intro sets.countable_UN) (auto intro: i)
hoelzl@50526
  1106
qed auto
hoelzl@50526
  1107
hoelzl@50526
  1108
lemma borel_eq_halfspace_ge:
wenzelm@61076
  1109
  "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. a \<le> x \<bullet> i}) ` (UNIV \<times> Basis))"
hoelzl@50526
  1110
  (is "_ = ?SIGMA")
hoelzl@50526
  1111
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@50526
  1112
  fix a :: real and i :: 'a assume i: "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
  1113
  have *: "{x::'a. x\<bullet>i < a} = space ?SIGMA - {x::'a. a \<le> x\<bullet>i}" by auto
hoelzl@50526
  1114
  show "{x. x\<bullet>i < a} \<in> ?SIGMA" unfolding *
hoelzl@59361
  1115
    using i by (intro sets.compl_sets) auto
hoelzl@50526
  1116
qed auto
hoelzl@50526
  1117
hoelzl@50526
  1118
lemma borel_eq_halfspace_greater:
wenzelm@61076
  1119
  "borel = sigma UNIV ((\<lambda> (a, i). {x::'a::euclidean_space. a < x \<bullet> i}) ` (UNIV \<times> Basis))"
hoelzl@50526
  1120
  (is "_ = ?SIGMA")
hoelzl@50526
  1121
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
hoelzl@50526
  1122
  fix a :: real and i :: 'a assume "(a, i) \<in> (UNIV \<times> Basis)"
hoelzl@50526
  1123
  then have i: "i \<in> Basis" by auto
hoelzl@50526
  1124
  have *: "{x::'a. x\<bullet>i \<le> a} = space ?SIGMA - {x::'a. a < x\<bullet>i}" by auto
hoelzl@50526
  1125
  show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@59361
  1126
    by (intro sets.compl_sets) (auto intro: i)
hoelzl@50526
  1127
qed auto
hoelzl@50526
  1128
hoelzl@50526
  1129
lemma borel_eq_atMost:
wenzelm@61076
  1130
  "borel = sigma UNIV (range (\<lambda>a. {..a::'a::ordered_euclidean_space}))"
hoelzl@50526
  1131
  (is "_ = ?SIGMA")
hoelzl@50526
  1132
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@50526
  1133
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
  1134
  then have "i \<in> Basis" by auto
hoelzl@50526
  1135
  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
  1136
  proof (safe, simp_all add: eucl_le[where 'a='a] split: if_split_asm)
hoelzl@50526
  1137
    fix x :: 'a
hoelzl@50526
  1138
    from real_arch_simple[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"] guess k::nat ..
hoelzl@50526
  1139
    then have "\<And>i. i \<in> Basis \<Longrightarrow> x\<bullet>i \<le> real k"
hoelzl@50526
  1140
      by (subst (asm) Max_le_iff) auto
hoelzl@50526
  1141
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia \<le> real k"
hoelzl@50526
  1142
      by (auto intro!: exI[of _ k])
hoelzl@50526
  1143
  qed
hoelzl@50526
  1144
  show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@59361
  1145
    by (intro sets.countable_UN) auto
hoelzl@50526
  1146
qed auto
hoelzl@50526
  1147
hoelzl@50526
  1148
lemma borel_eq_greaterThan:
wenzelm@61076
  1149
  "borel = sigma UNIV (range (\<lambda>a::'a::ordered_euclidean_space. {x. a <e x}))"
hoelzl@50526
  1150
  (is "_ = ?SIGMA")
hoelzl@50526
  1151
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@50526
  1152
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
  1153
  then have i: "i \<in> Basis" by auto
hoelzl@50526
  1154
  have "{x::'a. x\<bullet>i \<le> a} = UNIV - {x::'a. a < x\<bullet>i}" by auto
hoelzl@50526
  1155
  also have *: "{x::'a. a < x\<bullet>i} =
immler@54775
  1156
      (\<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
  1157
  proof (safe, simp_all add: eucl_less_def split: if_split_asm)
hoelzl@50526
  1158
    fix x :: 'a
hoelzl@50526
  1159
    from reals_Archimedean2[of "Max ((\<lambda>i. -x\<bullet>i)`Basis)"]
hoelzl@50526
  1160
    guess k::nat .. note k = this
hoelzl@50526
  1161
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
  1162
      then have "-x\<bullet>i < real k"
hoelzl@50526
  1163
        using k by (subst (asm) Max_less_iff) auto
hoelzl@50526
  1164
      then have "- real k < x\<bullet>i" by simp }
hoelzl@50526
  1165
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> -real k < x \<bullet> ia"
hoelzl@50526
  1166
      by (auto intro!: exI[of _ k])
hoelzl@50526
  1167
  qed
hoelzl@50526
  1168
  finally show "{x. x\<bullet>i \<le> a} \<in> ?SIGMA"
hoelzl@50526
  1169
    apply (simp only:)
hoelzl@59361
  1170
    apply (intro sets.countable_UN sets.Diff)
hoelzl@50526
  1171
    apply (auto intro: sigma_sets_top)
hoelzl@50526
  1172
    done
hoelzl@50526
  1173
qed auto
hoelzl@50526
  1174
hoelzl@50526
  1175
lemma borel_eq_lessThan:
wenzelm@61076
  1176
  "borel = sigma UNIV (range (\<lambda>a::'a::ordered_euclidean_space. {x. x <e a}))"
hoelzl@50526
  1177
  (is "_ = ?SIGMA")
hoelzl@50526
  1178
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_ge])
hoelzl@50526
  1179
  fix a :: real and i :: 'a assume "(a, i) \<in> UNIV \<times> Basis"
hoelzl@50526
  1180
  then have i: "i \<in> Basis" by auto
hoelzl@50526
  1181
  have "{x::'a. a \<le> x\<bullet>i} = UNIV - {x::'a. x\<bullet>i < a}" by auto
wenzelm@61808
  1182
  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
  1183
  proof (safe, simp_all add: eucl_less_def split: if_split_asm)
hoelzl@50526
  1184
    fix x :: 'a
hoelzl@50526
  1185
    from reals_Archimedean2[of "Max ((\<lambda>i. x\<bullet>i)`Basis)"]
hoelzl@50526
  1186
    guess k::nat .. note k = this
hoelzl@50526
  1187
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
  1188
      then have "x\<bullet>i < real k"
hoelzl@50526
  1189
        using k by (subst (asm) Max_less_iff) auto
hoelzl@50526
  1190
      then have "x\<bullet>i < real k" by simp }
hoelzl@50526
  1191
    then show "\<exists>k::nat. \<forall>ia\<in>Basis. ia \<noteq> i \<longrightarrow> x \<bullet> ia < real k"
hoelzl@50526
  1192
      by (auto intro!: exI[of _ k])
hoelzl@50526
  1193
  qed
hoelzl@50526
  1194
  finally show "{x. a \<le> x\<bullet>i} \<in> ?SIGMA"
hoelzl@50526
  1195
    apply (simp only:)
hoelzl@59361
  1196
    apply (intro sets.countable_UN sets.Diff)
immler@54775
  1197
    apply (auto intro: sigma_sets_top )
hoelzl@50526
  1198
    done
hoelzl@50526
  1199
qed auto
hoelzl@50526
  1200
hoelzl@50526
  1201
lemma borel_eq_atLeastAtMost:
wenzelm@61076
  1202
  "borel = sigma UNIV (range (\<lambda>(a,b). {a..b} ::'a::ordered_euclidean_space set))"
hoelzl@50526
  1203
  (is "_ = ?SIGMA")
hoelzl@50526
  1204
proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
hoelzl@50526
  1205
  fix a::'a
hoelzl@50526
  1206
  have *: "{..a} = (\<Union>n::nat. {- real n *\<^sub>R One .. a})"
hoelzl@50526
  1207
  proof (safe, simp_all add: eucl_le[where 'a='a])
hoelzl@50526
  1208
    fix x :: 'a
hoelzl@50526
  1209
    from real_arch_simple[of "Max ((\<lambda>i. - x\<bullet>i)`Basis)"]
hoelzl@50526
  1210
    guess k::nat .. note k = this
hoelzl@50526
  1211
    { fix i :: 'a assume "i \<in> Basis"
hoelzl@50526
  1212
      with k have "- x\<bullet>i \<le> real k"
hoelzl@50526
  1213
        by (subst (asm) Max_le_iff) (auto simp: field_simps)
hoelzl@50526
  1214
      then have "- real k \<le> x\<bullet>i" by simp }
hoelzl@50526
  1215
    then show "\<exists>n::nat. \<forall>i\<in>Basis. - real n \<le> x \<bullet> i"
hoelzl@50526
  1216
      by (auto intro!: exI[of _ k])
hoelzl@50526
  1217
  qed
hoelzl@50526
  1218
  show "{..a} \<in> ?SIGMA" unfolding *
hoelzl@59361
  1219
    by (intro sets.countable_UN)
hoelzl@50526
  1220
       (auto intro!: sigma_sets_top)
hoelzl@50526
  1221
qed auto
hoelzl@50526
  1222
hoelzl@62624
  1223
lemma borel_set_induct[consumes 1, case_names empty interval compl union]:
hoelzl@62624
  1224
  assumes "A \<in> sets borel"
hoelzl@62624
  1225
  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
  1226
          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
  1227
  shows "P (A::real set)"
hoelzl@62624
  1228
proof-
hoelzl@62624
  1229
  let ?G = "range (\<lambda>(a,b). {a..b::real})"
hoelzl@62624
  1230
  have "Int_stable ?G" "?G \<subseteq> Pow UNIV" "A \<in> sigma_sets UNIV ?G"
hoelzl@62624
  1231
      using assms(1) by (auto simp add: borel_eq_atLeastAtMost Int_stable_def)
hoelzl@62624
  1232
  thus ?thesis
hoelzl@62624
  1233
  proof (induction rule: sigma_sets_induct_disjoint)
hoelzl@62624
  1234
    case (union f)
hoelzl@62624
  1235
      from union.hyps(2) have "\<And>i. f i \<in> sets borel" by (auto simp: borel_eq_atLeastAtMost)
hoelzl@62624
  1236
      with union show ?case by (auto intro: un)
hoelzl@62624
  1237
  next
hoelzl@62624
  1238
    case (basic A)
hoelzl@62624
  1239
    then obtain a b where "A = {a .. b}" by auto
hoelzl@62624
  1240
    then show ?case
hoelzl@62624
  1241
      by (cases "a \<le> b") (auto intro: int empty)
hoelzl@62624
  1242
  qed (auto intro: empty compl simp: Compl_eq_Diff_UNIV[symmetric] borel_eq_atLeastAtMost)
hoelzl@62624
  1243
qed
hoelzl@62624
  1244
hoelzl@57447
  1245
lemma borel_sigma_sets_Ioc: "borel = sigma UNIV (range (\<lambda>(a, b). {a <.. b::real}))"
hoelzl@57447
  1246
proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
hoelzl@57447
  1247
  fix i :: real
hoelzl@57447
  1248
  have "{..i} = (\<Union>j::nat. {-j <.. i})"
hoelzl@57447
  1249
    by (auto simp: minus_less_iff reals_Archimedean2)
hoelzl@57447
  1250
  also have "\<dots> \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))"
hoelzl@62372
  1251
    by (intro sets.countable_nat_UN) auto
hoelzl@57447
  1252
  finally show "{..i} \<in> sets (sigma UNIV (range (\<lambda>(i, j). {i<..j})))" .
hoelzl@57447
  1253
qed simp
hoelzl@57447
  1254
immler@54775
  1255
lemma eucl_lessThan: "{x::real. x <e a} = lessThan a"
immler@54775
  1256
  by (simp add: eucl_less_def lessThan_def)
immler@54775
  1257
hoelzl@50526
  1258
lemma borel_eq_atLeastLessThan:
hoelzl@50526
  1259
  "borel = sigma UNIV (range (\<lambda>(a, b). {a ..< b :: real}))" (is "_ = ?SIGMA")
hoelzl@50526
  1260
proof (rule borel_eq_sigmaI5[OF borel_eq_lessThan])
hoelzl@50526
  1261
  have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
hoelzl@50526
  1262
  fix x :: real
hoelzl@50526
  1263
  have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
hoelzl@50526
  1264
    by (auto simp: move_uminus real_arch_simple)
immler@54775
  1265
  then show "{y. y <e x} \<in> ?SIGMA"
hoelzl@59361
  1266
    by (auto intro: sigma_sets.intros(2-) simp: eucl_lessThan)
hoelzl@50526
  1267
qed auto
hoelzl@50526
  1268
hoelzl@50526
  1269
lemma borel_measurable_halfspacesI:
wenzelm@61076
  1270
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1271
  assumes F: "borel = sigma UNIV (F ` (UNIV \<times> Basis))"
hoelzl@62372
  1272
  and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M"
hoelzl@50526
  1273
  shows "f \<in> borel_measurable M = (\<forall>i\<in>Basis. \<forall>a::real. S a i \<in> sets M)"
hoelzl@50526
  1274
proof safe
hoelzl@50526
  1275
  fix a :: real and i :: 'b assume i: "i \<in> Basis" and f: "f \<in> borel_measurable M"
hoelzl@50526
  1276
  then show "S a i \<in> sets M" unfolding assms
hoelzl@50526
  1277
    by (auto intro!: measurable_sets simp: assms(1))
hoelzl@50526
  1278
next
hoelzl@50526
  1279
  assume a: "\<forall>i\<in>Basis. \<forall>a. S a i \<in> sets M"
hoelzl@50526
  1280
  then show "f \<in> borel_measurable M"
hoelzl@50526
  1281
    by (auto intro!: measurable_measure_of simp: S_eq F)
hoelzl@50526
  1282
qed
hoelzl@50526
  1283
hoelzl@50526
  1284
lemma borel_measurable_iff_halfspace_le:
wenzelm@61076
  1285
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1286
  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
  1287
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_le]) auto
hoelzl@50526
  1288
hoelzl@50526
  1289
lemma borel_measurable_iff_halfspace_less:
wenzelm@61076
  1290
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1291
  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
  1292
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_less]) auto
hoelzl@50526
  1293
hoelzl@50526
  1294
lemma borel_measurable_iff_halfspace_ge:
wenzelm@61076
  1295
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1296
  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
  1297
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_ge]) auto
hoelzl@50526
  1298
hoelzl@50526
  1299
lemma borel_measurable_iff_halfspace_greater:
wenzelm@61076
  1300
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1301
  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
  1302
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_greater]) auto
hoelzl@50526
  1303
hoelzl@50526
  1304
lemma borel_measurable_iff_le:
hoelzl@50526
  1305
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w \<le> a} \<in> sets M)"
hoelzl@50526
  1306
  using borel_measurable_iff_halfspace_le[where 'c=real] by simp
hoelzl@50526
  1307
hoelzl@50526
  1308
lemma borel_measurable_iff_less:
hoelzl@50526
  1309
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w < a} \<in> sets M)"
hoelzl@50526
  1310
  using borel_measurable_iff_halfspace_less[where 'c=real] by simp
hoelzl@50526
  1311
hoelzl@50526
  1312
lemma borel_measurable_iff_ge:
hoelzl@50526
  1313
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a \<le> f w} \<in> sets M)"
hoelzl@50526
  1314
  using borel_measurable_iff_halfspace_ge[where 'c=real]
hoelzl@50526
  1315
  by simp
hoelzl@50526
  1316
hoelzl@50526
  1317
lemma borel_measurable_iff_greater:
hoelzl@50526
  1318
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a < f w} \<in> sets M)"
hoelzl@50526
  1319
  using borel_measurable_iff_halfspace_greater[where 'c=real] by simp
hoelzl@50526
  1320
hoelzl@50526
  1321
lemma borel_measurable_euclidean_space:
hoelzl@50526
  1322
  fixes f :: "'a \<Rightarrow> 'c::euclidean_space"
hoelzl@50526
  1323
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M)"
hoelzl@50526
  1324
proof safe
hoelzl@50526
  1325
  assume f: "\<forall>i\<in>Basis. (\<lambda>x. f x \<bullet> i) \<in> borel_measurable M"
hoelzl@50526
  1326
  then show "f \<in> borel_measurable M"
hoelzl@50526
  1327
    by (subst borel_measurable_iff_halfspace_le) auto
hoelzl@50526
  1328
qed auto
hoelzl@50526
  1329
hoelzl@50526
  1330
subsection "Borel measurable operators"
hoelzl@50526
  1331
hoelzl@56993
  1332
lemma borel_measurable_norm[measurable]: "norm \<in> borel_measurable borel"
hoelzl@56993
  1333
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@56993
  1334
hoelzl@57275
  1335
lemma borel_measurable_sgn [measurable]: "(sgn::'a::real_normed_vector \<Rightarrow> 'a) \<in> borel_measurable borel"
hoelzl@57275
  1336
  by (rule borel_measurable_continuous_countable_exceptions[where X="{0}"])
hoelzl@57275
  1337
     (auto intro!: continuous_on_sgn continuous_on_id)
hoelzl@57275
  1338
hoelzl@50526
  1339
lemma borel_measurable_uminus[measurable (raw)]:
hoelzl@51683
  1340
  fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@50526
  1341
  assumes g: "g \<in> borel_measurable M"
hoelzl@50526
  1342
  shows "(\<lambda>x. - g x) \<in> borel_measurable M"
hoelzl@56371
  1343
  by (rule borel_measurable_continuous_on[OF _ g]) (intro continuous_intros)
hoelzl@50526
  1344
hoelzl@50003
  1345
lemma borel_measurable_diff[measurable (raw)]:
hoelzl@51683
  1346
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@49774
  1347
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1348
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1349
  shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
haftmann@54230
  1350
  using borel_measurable_add [of f M "- g"] assms by (simp add: fun_Compl_def)
hoelzl@49774
  1351
hoelzl@50003
  1352
lemma borel_measurable_times[measurable (raw)]:
hoelzl@51683
  1353
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_algebra}"
hoelzl@49774
  1354
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1355
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1356
  shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@56371
  1357
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@51683
  1358
nipkow@64272
  1359
lemma borel_measurable_prod[measurable (raw)]:
hoelzl@51683
  1360
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> 'b::{second_countable_topology, real_normed_field}"
hoelzl@51683
  1361
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@51683
  1362
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@51683
  1363
proof cases
hoelzl@51683
  1364
  assume "finite S"
hoelzl@51683
  1365
  thus ?thesis using assms by induct auto
hoelzl@51683
  1366
qed simp
hoelzl@49774
  1367
hoelzl@50003
  1368
lemma borel_measurable_dist[measurable (raw)]:
hoelzl@51683
  1369
  fixes g f :: "'a \<Rightarrow> 'b::{second_countable_topology, metric_space}"
hoelzl@49774
  1370
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1371
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1372
  shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
hoelzl@56371
  1373
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@62372
  1374
hoelzl@50002
  1375
lemma borel_measurable_scaleR[measurable (raw)]:
hoelzl@51683
  1376
  fixes g :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
hoelzl@50002
  1377
  assumes f: "f \<in> borel_measurable M"
hoelzl@50002
  1378
  assumes g: "g \<in> borel_measurable M"
hoelzl@50002
  1379
  shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
hoelzl@56371
  1380
  using f g by (rule borel_measurable_continuous_Pair) (intro continuous_intros)
hoelzl@50002
  1381
lp15@66164
  1382
lemma borel_measurable_uminus_eq [simp]:
lp15@66164
  1383
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, real_normed_vector}"
lp15@66164
  1384
  shows "(\<lambda>x. - f x) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
lp15@66164
  1385
proof
lp15@66164
  1386
  assume ?l from borel_measurable_uminus[OF this] show ?r by simp
lp15@66164
  1387
qed auto
lp15@66164
  1388
hoelzl@47694
  1389
lemma affine_borel_measurable_vector:
hoelzl@38656
  1390
  fixes f :: "'a \<Rightarrow> 'x::real_normed_vector"
hoelzl@38656
  1391
  assumes "f \<in> borel_measurable M"
hoelzl@38656
  1392
  shows "(\<lambda>x. a + b *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@38656
  1393
proof (rule borel_measurableI)
hoelzl@38656
  1394
  fix S :: "'x set" assume "open S"
hoelzl@38656
  1395
  show "(\<lambda>x. a + b *\<^sub>R f x) -` S \<inter> space M \<in> sets M"
hoelzl@38656
  1396
  proof cases
hoelzl@38656
  1397
    assume "b \<noteq> 0"
wenzelm@61808
  1398
    with \<open>open S\<close> have "open ((\<lambda>x. (- a + x) /\<^sub>R b) ` S)" (is "open ?S")
haftmann@54230
  1399
      using open_affinity [of S "inverse b" "- a /\<^sub>R b"]
haftmann@54230
  1400
      by (auto simp: algebra_simps)
hoelzl@47694
  1401
    hence "?S \<in> sets borel" by auto
hoelzl@38656
  1402
    moreover
wenzelm@61808
  1403
    from \<open>b \<noteq> 0\<close> have "(\<lambda>x. a + b *\<^sub>R f x) -` S = f -` ?S"
hoelzl@38656
  1404
      apply auto by (rule_tac x="a + b *\<^sub>R f x" in image_eqI, simp_all)
hoelzl@40859
  1405
    ultimately show ?thesis using assms unfolding in_borel_measurable_borel
hoelzl@38656
  1406
      by auto
hoelzl@38656
  1407
  qed simp
hoelzl@38656
  1408
qed
hoelzl@38656
  1409
hoelzl@50002
  1410
lemma borel_measurable_const_scaleR[measurable (raw)]:
hoelzl@50002
  1411
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. b *\<^sub>R f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
  1412
  using affine_borel_measurable_vector[of f M 0 b] by simp
hoelzl@38656
  1413
hoelzl@50002
  1414
lemma borel_measurable_const_add[measurable (raw)]:
hoelzl@50002
  1415
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. a + f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
  1416
  using affine_borel_measurable_vector[of f M a 1] by simp
hoelzl@50002
  1417
hoelzl@50003
  1418
lemma borel_measurable_inverse[measurable (raw)]:
hoelzl@57275
  1419
  fixes f :: "'a \<Rightarrow> 'b::real_normed_div_algebra"
hoelzl@49774
  1420
  assumes f: "f \<in> borel_measurable M"
hoelzl@35692
  1421
  shows "(\<lambda>x. inverse (f x)) \<in> borel_measurable M"
hoelzl@57275
  1422
  apply (rule measurable_compose[OF f])
hoelzl@57275
  1423
  apply (rule borel_measurable_continuous_countable_exceptions[of "{0}"])
hoelzl@57275
  1424
  apply (auto intro!: continuous_on_inverse continuous_on_id)
hoelzl@57275
  1425
  done
hoelzl@35692
  1426
hoelzl@50003
  1427
lemma borel_measurable_divide[measurable (raw)]:
hoelzl@51683
  1428
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow>
hoelzl@57275
  1429
    (\<lambda>x. f x / g x::'b::{second_countable_topology, real_normed_div_algebra}) \<in> borel_measurable M"
hoelzl@57275
  1430
  by (simp add: divide_inverse)
hoelzl@38656
  1431
hoelzl@50003
  1432
lemma borel_measurable_abs[measurable (raw)]:
hoelzl@50003
  1433
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. \<bar>f x :: real\<bar>) \<in> borel_measurable M"
hoelzl@50003
  1434
  unfolding abs_real_def by simp
hoelzl@38656
  1435
hoelzl@50003
  1436
lemma borel_measurable_nth[measurable (raw)]:
hoelzl@41026
  1437
  "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
hoelzl@50526
  1438
  by (simp add: cart_eq_inner_axis)
hoelzl@41026
  1439
hoelzl@47694
  1440
lemma convex_measurable:
hoelzl@59415
  1441
  fixes A :: "'a :: euclidean_space set"
hoelzl@62372
  1442
  shows "X \<in> borel_measurable M \<Longrightarrow> X ` space M \<subseteq> A \<Longrightarrow> open A \<Longrightarrow> convex_on A q \<Longrightarrow>
hoelzl@59415
  1443
    (\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@59415
  1444
  by (rule measurable_compose[where f=X and N="restrict_space borel A"])
hoelzl@59415
  1445
     (auto intro!: borel_measurable_continuous_on_restrict convex_on_continuous measurable_restrict_space2)
hoelzl@41830
  1446
hoelzl@50003
  1447
lemma borel_measurable_ln[measurable (raw)]:
hoelzl@49774
  1448
  assumes f: "f \<in> borel_measurable M"
lp15@60017
  1449
  shows "(\<lambda>x. ln (f x :: real)) \<in> borel_measurable M"
hoelzl@57275
  1450
  apply (rule measurable_compose[OF f])
hoelzl@57275
  1451
  apply (rule borel_measurable_continuous_countable_exceptions[of "{0}"])
hoelzl@57275
  1452
  apply (auto intro!: continuous_on_ln continuous_on_id)
hoelzl@57275
  1453
  done
hoelzl@41830
  1454
hoelzl@50003
  1455
lemma borel_measurable_log[measurable (raw)]:
hoelzl@50002
  1456
  "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
  1457
  unfolding log_def by auto
hoelzl@41830
  1458
immler@58656
  1459
lemma borel_measurable_exp[measurable]:
immler@58656
  1460
  "(exp::'a::{real_normed_field,banach}\<Rightarrow>'a) \<in> borel_measurable borel"
hoelzl@51478
  1461
  by (intro borel_measurable_continuous_on1 continuous_at_imp_continuous_on ballI isCont_exp)
hoelzl@50419
  1462
hoelzl@50002
  1463
lemma measurable_real_floor[measurable]:
hoelzl@50002
  1464
  "(floor :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@47761
  1465
proof -
lp15@61609
  1466
  have "\<And>a x. \<lfloor>x\<rfloor> = a \<longleftrightarrow> (real_of_int a \<le> x \<and> x < real_of_int (a + 1))"
hoelzl@50002
  1467
    by (auto intro: floor_eq2)
hoelzl@50002
  1468
  then show ?thesis
hoelzl@50002
  1469
    by (auto simp: vimage_def measurable_count_space_eq2_countable)
hoelzl@47761
  1470
qed
hoelzl@47761
  1471
hoelzl@50002
  1472
lemma measurable_real_ceiling[measurable]:
hoelzl@50002
  1473
  "(ceiling :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
  1474
  unfolding ceiling_def[abs_def] by simp
hoelzl@50002
  1475
lp15@61609
  1476
lemma borel_measurable_real_floor: "(\<lambda>x::real. real_of_int \<lfloor>x\<rfloor>) \<in> borel_measurable borel"
hoelzl@50002
  1477
  by simp
hoelzl@50002
  1478
hoelzl@59415
  1479
lemma borel_measurable_root [measurable]: "root n \<in> borel_measurable borel"
hoelzl@57235
  1480
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1481
hoelzl@57235
  1482
lemma borel_measurable_sqrt [measurable]: "sqrt \<in> borel_measurable borel"
hoelzl@57235
  1483
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1484
hoelzl@57235
  1485
lemma borel_measurable_power [measurable (raw)]:
hoelzl@59415
  1486
  fixes f :: "_ \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@59415
  1487
  assumes f: "f \<in> borel_measurable M"
hoelzl@59415
  1488
  shows "(\<lambda>x. (f x) ^ n) \<in> borel_measurable M"
hoelzl@59415
  1489
  by (intro borel_measurable_continuous_on [OF _ f] continuous_intros)
hoelzl@57235
  1490
hoelzl@57235
  1491
lemma borel_measurable_Re [measurable]: "Re \<in> borel_measurable borel"
hoelzl@57235
  1492
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1493
hoelzl@57235
  1494
lemma borel_measurable_Im [measurable]: "Im \<in> borel_measurable borel"
hoelzl@57235
  1495
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1496
hoelzl@57235
  1497
lemma borel_measurable_of_real [measurable]: "(of_real :: _ \<Rightarrow> (_::real_normed_algebra)) \<in> borel_measurable borel"
hoelzl@57235
  1498
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1499
lp15@59658
  1500
lemma borel_measurable_sin [measurable]: "(sin :: _ \<Rightarrow> (_::{real_normed_field,banach})) \<in> borel_measurable borel"
hoelzl@57235
  1501
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1502
lp15@59658
  1503
lemma borel_measurable_cos [measurable]: "(cos :: _ \<Rightarrow> (_::{real_normed_field,banach})) \<in> borel_measurable borel"
hoelzl@57235
  1504
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1505
hoelzl@57235
  1506
lemma borel_measurable_arctan [measurable]: "arctan \<in> borel_measurable borel"
hoelzl@57235
  1507
  by (intro borel_measurable_continuous_on1 continuous_intros)
hoelzl@57235
  1508
hoelzl@57259
  1509
lemma borel_measurable_complex_iff:
hoelzl@57259
  1510
  "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@57259
  1511
    (\<lambda>x. Re (f x)) \<in> borel_measurable M \<and> (\<lambda>x. Im (f x)) \<in> borel_measurable M"
hoelzl@57259
  1512
  apply auto
hoelzl@57259
  1513
  apply (subst fun_complex_eq)
hoelzl@57259
  1514
  apply (intro borel_measurable_add)
hoelzl@57259
  1515
  apply auto
hoelzl@57259
  1516
  done
hoelzl@57259
  1517
eberlm@67278
  1518
lemma powr_real_measurable [measurable]:
eberlm@67278
  1519
  assumes "f \<in> measurable M borel" "g \<in> measurable M borel"
eberlm@67278
  1520
  shows   "(\<lambda>x. f x powr g x :: real) \<in> measurable M borel"
eberlm@67278
  1521
  using assms by (simp_all add: powr_def)
eberlm@67278
  1522
hoelzl@64008
  1523
lemma measurable_of_bool[measurable]: "of_bool \<in> count_space UNIV \<rightarrow>\<^sub>M borel"
hoelzl@64008
  1524
  by simp
hoelzl@64008
  1525
hoelzl@41981
  1526
subsection "Borel space on the extended reals"
hoelzl@41981
  1527
hoelzl@50003
  1528
lemma borel_measurable_ereal[measurable (raw)]:
hoelzl@43920
  1529
  assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@60771
  1530
  using continuous_on_ereal f by (rule borel_measurable_continuous_on) (rule continuous_on_id)
hoelzl@41981
  1531
hoelzl@50003
  1532
lemma borel_measurable_real_of_ereal[measurable (raw)]:
hoelzl@62372
  1533
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1534
  assumes f: "f \<in> borel_measurable M"
lp15@61609
  1535
  shows "(\<lambda>x. real_of_ereal (f x)) \<in> borel_measurable M"
hoelzl@59361
  1536
  apply (rule measurable_compose[OF f])
hoelzl@59361
  1537
  apply (rule borel_measurable_continuous_countable_exceptions[of "{\<infinity>, -\<infinity> }"])
hoelzl@59361
  1538
  apply (auto intro: continuous_on_real simp: Compl_eq_Diff_UNIV)
hoelzl@59361
  1539
  done
hoelzl@49774
  1540
hoelzl@49774
  1541
lemma borel_measurable_ereal_cases:
hoelzl@62372
  1542
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1543
  assumes f: "f \<in> borel_measurable M"
lp15@61609
  1544
  assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x)))) \<in> borel_measurable M"
hoelzl@49774
  1545
  shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
hoelzl@49774
  1546
proof -
lp15@61609
  1547
  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
  1548
  { fix x have "H (f x) = ?F x" by (cases "f x") auto }
hoelzl@50002
  1549
  with f H show ?thesis by simp
hoelzl@47694
  1550
qed
hoelzl@41981
  1551
hoelzl@49774
  1552
lemma
hoelzl@50003
  1553
  fixes f :: "'a \<Rightarrow> ereal" assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50003
  1554
  shows borel_measurable_ereal_abs[measurable(raw)]: "(\<lambda>x. \<bar>f x\<bar>) \<in> borel_measurable M"
hoelzl@50003
  1555
    and borel_measurable_ereal_inverse[measurable(raw)]: "(\<lambda>x. inverse (f x) :: ereal) \<in> borel_measurable M"
hoelzl@50003
  1556
    and borel_measurable_uminus_ereal[measurable(raw)]: "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M"
hoelzl@49774
  1557
  by (auto simp del: abs_real_of_ereal simp: borel_measurable_ereal_cases[OF f] measurable_If)
hoelzl@49774
  1558
hoelzl@49774
  1559
lemma borel_measurable_uminus_eq_ereal[simp]:
hoelzl@49774
  1560
  "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
hoelzl@49774
  1561
proof
hoelzl@49774
  1562
  assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
hoelzl@49774
  1563
qed auto
hoelzl@49774
  1564
hoelzl@49774
  1565
lemma set_Collect_ereal2:
hoelzl@62372
  1566
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1567
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1568
  assumes g: "g \<in> borel_measurable M"
lp15@61609
  1569
  assumes H: "{x \<in> space M. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))} \<in> sets M"
hoelzl@50002
  1570
    "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
  1571
    "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
  1572
    "{x \<in> space borel. H (ereal x) (-\<infinity>)} \<in> sets borel"
hoelzl@50002
  1573
    "{x \<in> space borel. H (ereal x) (\<infinity>)} \<in> sets borel"
hoelzl@49774
  1574
  shows "{x \<in> space M. H (f x) (g x)} \<in> sets M"
hoelzl@49774
  1575
proof -
lp15@61609
  1576
  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
  1577
  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
  1578
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
  1579
  note * = this
hoelzl@50002
  1580
  from assms show ?thesis
nipkow@62390
  1581
    by (subst *) (simp del: space_borel split del: if_split)
hoelzl@49774
  1582
qed
hoelzl@49774
  1583
hoelzl@47694
  1584
lemma borel_measurable_ereal_iff:
hoelzl@43920
  1585
  shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M"
hoelzl@41981
  1586
proof
hoelzl@43920
  1587
  assume "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@43920
  1588
  from borel_measurable_real_of_ereal[OF this]
hoelzl@41981
  1589
  show "f \<in> borel_measurable M" by auto
hoelzl@41981
  1590
qed auto
hoelzl@41981
  1591
hoelzl@59353
  1592
lemma borel_measurable_erealD[measurable_dest]:
hoelzl@59353
  1593
  "(\<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
  1594
  unfolding borel_measurable_ereal_iff by simp
hoelzl@59353
  1595
hoelzl@47694
  1596
lemma borel_measurable_ereal_iff_real:
hoelzl@43923
  1597
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
  1598
  shows "f \<in> borel_measurable M \<longleftrightarrow>
lp15@61609
  1599
    ((\<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
  1600
proof safe
lp15@61609
  1601
  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
  1602
  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
  1603
  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
  1604
  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
  1605
  have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
hoelzl@43920
  1606
  also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
hoelzl@41981
  1607
  finally show "f \<in> borel_measurable M" .
hoelzl@50002
  1608
qed simp_all
hoelzl@41830
  1609
hoelzl@59361
  1610
lemma borel_measurable_ereal_iff_Iio:
hoelzl@59361
  1611
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
hoelzl@59361
  1612
  by (auto simp: borel_Iio measurable_iff_measure_of)
hoelzl@59361
  1613
hoelzl@59361
  1614
lemma borel_measurable_ereal_iff_Ioi:
hoelzl@59361
  1615
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
hoelzl@59361
  1616
  by (auto simp: borel_Ioi measurable_iff_measure_of)
hoelzl@35582
  1617
hoelzl@59361
  1618
lemma vimage_sets_compl_iff:
hoelzl@59361
  1619
  "f -` A \<inter> space M \<in> sets M \<longleftrightarrow> f -` (- A) \<inter> space M \<in> sets M"
hoelzl@59361
  1620
proof -
hoelzl@59361
  1621
  { fix A assume "f -` A \<inter> space M \<in> sets M"
hoelzl@59361
  1622
    moreover have "f -` (- A) \<inter> space M = space M - f -` A \<inter> space M" by auto
hoelzl@59361
  1623
    ultimately have "f -` (- A) \<inter> space M \<in> sets M" by auto }
hoelzl@59361
  1624
  from this[of A] this[of "-A"] show ?thesis
hoelzl@59361
  1625
    by (metis double_complement)
hoelzl@49774
  1626
qed
hoelzl@49774
  1627
hoelzl@59361
  1628
lemma borel_measurable_iff_Iic_ereal:
hoelzl@59361
  1629
  "(f::'a\<Rightarrow>ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
hoelzl@59361
  1630
  unfolding borel_measurable_ereal_iff_Ioi vimage_sets_compl_iff[where A="{a <..}" for a] by simp
hoelzl@38656
  1631
hoelzl@59361
  1632
lemma borel_measurable_iff_Ici_ereal:
hoelzl@59361
  1633
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
hoelzl@59361
  1634
  unfolding borel_measurable_ereal_iff_Iio vimage_sets_compl_iff[where A="{..< a}" for a] by simp
hoelzl@38656
  1635
hoelzl@49774
  1636
lemma borel_measurable_ereal2:
hoelzl@62372
  1637
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@41981
  1638
  assumes f: "f \<in> borel_measurable M"
hoelzl@41981
  1639
  assumes g: "g \<in> borel_measurable M"
lp15@61609
  1640
  assumes H: "(\<lambda>x. H (ereal (real_of_ereal (f x))) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
lp15@61609
  1641
    "(\<lambda>x. H (-\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
lp15@61609
  1642
    "(\<lambda>x. H (\<infinity>) (ereal (real_of_ereal (g x)))) \<in> borel_measurable M"
lp15@61609
  1643
    "(\<lambda>x. H (ereal (real_of_ereal (f x))) (-\<infinity>)) \<in> borel_measurable M"
lp15@61609
  1644
    "(\<lambda>x. H (ereal (real_of_ereal (f x))) (\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1645
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@41981
  1646
proof -
lp15@61609
  1647
  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
  1648
  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
  1649
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
  1650
  note * = this
hoelzl@50002
  1651
  from assms show ?thesis unfolding * by simp
hoelzl@41981
  1652
qed
hoelzl@41981
  1653
hoelzl@50003
  1654
lemma [measurable(raw)]:
hoelzl@43920
  1655
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@50003
  1656
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@50002
  1657
  shows borel_measurable_ereal_add: "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@50002
  1658
    and borel_measurable_ereal_times: "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@62624
  1659
  by (simp_all add: borel_measurable_ereal2)
hoelzl@49774
  1660
hoelzl@50003
  1661
lemma [measurable(raw)]:
hoelzl@49774
  1662
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1663
  assumes "f \<in> borel_measurable M"
hoelzl@49774
  1664
  assumes "g \<in> borel_measurable M"
hoelzl@50002
  1665
  shows borel_measurable_ereal_diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50002
  1666
    and borel_measurable_ereal_divide: "(\<lambda>x. f x / g x) \<in> borel_measurable M"
hoelzl@50003
  1667
  using assms by (simp_all add: minus_ereal_def divide_ereal_def)
hoelzl@38656
  1668
nipkow@64267
  1669
lemma borel_measurable_ereal_sum[measurable (raw)]:
hoelzl@43920
  1670
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41096
  1671
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1672
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@59361
  1673
  using assms by (induction S rule: infinite_finite_induct) auto
hoelzl@38656
  1674
nipkow@64272
  1675
lemma borel_measurable_ereal_prod[measurable (raw)]:
hoelzl@43920
  1676
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1677
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1678
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@59361
  1679
  using assms by (induction S rule: infinite_finite_induct) auto
hoelzl@38656
  1680
hoelzl@50003
  1681
lemma borel_measurable_extreal_suminf[measurable (raw)]:
hoelzl@43920
  1682
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1683
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@41981
  1684
  shows "(\<lambda>x. (\<Sum>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1685
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@39092
  1686
hoelzl@62625
  1687
subsection "Borel space on the extended non-negative reals"
hoelzl@62625
  1688
hoelzl@62625
  1689
text \<open> @{type ennreal} is a topological monoid, so no rules for plus are required, also all order
hoelzl@62625
  1690
  statements are usually done on type classes. \<close>
hoelzl@62625
  1691
hoelzl@62625
  1692
lemma measurable_enn2ereal[measurable]: "enn2ereal \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@62625
  1693
  by (intro borel_measurable_continuous_on1 continuous_on_enn2ereal)
hoelzl@62625
  1694
hoelzl@62625
  1695
lemma measurable_e2ennreal[measurable]: "e2ennreal \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@62625
  1696
  by (intro borel_measurable_continuous_on1 continuous_on_e2ennreal)
hoelzl@62625
  1697
hoelzl@62975
  1698
lemma borel_measurable_enn2real[measurable (raw)]:
hoelzl@62975
  1699
  "f \<in> M \<rightarrow>\<^sub>M borel \<Longrightarrow> (\<lambda>x. enn2real (f x)) \<in> M \<rightarrow>\<^sub>M borel"
hoelzl@62975
  1700
  unfolding enn2real_def[abs_def] by measurable
hoelzl@62975
  1701
hoelzl@62625
  1702
definition [simp]: "is_borel f M \<longleftrightarrow> f \<in> borel_measurable M"
hoelzl@62625
  1703
hoelzl@62625
  1704
lemma is_borel_transfer[transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) op = is_borel is_borel"
hoelzl@62625
  1705
  unfolding is_borel_def[abs_def]
hoelzl@62625
  1706
proof (safe intro!: rel_funI ext dest!: rel_fun_eq_pcr_ennreal[THEN iffD1])
hoelzl@62625
  1707
  fix f and M :: "'a measure"
hoelzl@62625
  1708
  show "f \<in> borel_measurable M" if f: "enn2ereal \<circ> f \<in> borel_measurable M"
hoelzl@62625
  1709
    using measurable_compose[OF f measurable_e2ennreal] by simp
hoelzl@62625
  1710
qed simp
hoelzl@62625
  1711
hoelzl@62975
  1712
context
hoelzl@62975
  1713
  includes ennreal.lifting
hoelzl@62975
  1714
begin
hoelzl@62975
  1715
hoelzl@62625
  1716
lemma measurable_ennreal[measurable]: "ennreal \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@62975
  1717
  unfolding is_borel_def[symmetric]
hoelzl@62975
  1718
  by transfer simp
hoelzl@62975
  1719
hoelzl@62975
  1720
lemma borel_measurable_ennreal_iff[simp]:
hoelzl@62975
  1721
  assumes [simp]: "\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> f x"
hoelzl@62975
  1722
  shows "(\<lambda>x. ennreal (f x)) \<in> M \<rightarrow>\<^sub>M borel \<longleftrightarrow> f \<in> M \<rightarrow>\<^sub>M borel"
hoelzl@62975
  1723
proof safe
hoelzl@62975
  1724
  assume "(\<lambda>x. ennreal (f x)) \<in> M \<rightarrow>\<^sub>M borel"
hoelzl@62975
  1725
  then have "(\<lambda>x. enn2real (ennreal (f x))) \<in> M \<rightarrow>\<^sub>M borel"
hoelzl@62975
  1726
    by measurable
hoelzl@62975
  1727
  then show "f \<in> M \<rightarrow>\<^sub>M borel"
hoelzl@62975
  1728
    by (rule measurable_cong[THEN iffD1, rotated]) auto
hoelzl@62975
  1729
qed measurable
hoelzl@62625
  1730
hoelzl@62625
  1731
lemma borel_measurable_times_ennreal[measurable (raw)]:
hoelzl@62625
  1732
  fixes f g :: "'a \<Rightarrow> ennreal"
hoelzl@62625
  1733
  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
  1734
  unfolding is_borel_def[symmetric] by transfer simp
hoelzl@62625
  1735
hoelzl@62625
  1736
lemma borel_measurable_inverse_ennreal[measurable (raw)]:
hoelzl@62625
  1737
  fixes f :: "'a \<Rightarrow> ennreal"
hoelzl@62625
  1738
  shows "f \<in> M \<rightarrow>\<^sub>M borel \<Longrightarrow> (\<lambda>x. inverse (f x)) \<in> M \<rightarrow>\<^sub>M borel"
hoelzl@62625
  1739
  unfolding is_borel_def[symmetric] by transfer simp
hoelzl@62625
  1740
hoelzl@62625
  1741
lemma borel_measurable_divide_ennreal[measurable (raw)]:
hoelzl@62625
  1742
  fixes f :: "'a \<Rightarrow> ennreal"
hoelzl@62625
  1743
  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
  1744
  unfolding divide_ennreal_def by simp
hoelzl@62625
  1745
hoelzl@62625
  1746
lemma borel_measurable_minus_ennreal[measurable (raw)]:
hoelzl@62625
  1747
  fixes f :: "'a \<Rightarrow> ennreal"
hoelzl@62625
  1748
  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
  1749
  unfolding is_borel_def[symmetric] by transfer simp
hoelzl@62625
  1750
nipkow@64272
  1751
lemma borel_measurable_prod_ennreal[measurable (raw)]:
hoelzl@62625
  1752
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ennreal"
hoelzl@62625
  1753
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@62625
  1754
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@62625
  1755
  using assms by (induction S rule: infinite_finite_induct) auto
hoelzl@62625
  1756
hoelzl@62975
  1757
end
hoelzl@62975
  1758
hoelzl@62625
  1759
hide_const (open) is_borel
hoelzl@62625
  1760
wenzelm@61808
  1761
subsection \<open>LIMSEQ is borel measurable\<close>
hoelzl@39092
  1762
hoelzl@62624
  1763
lemma borel_measurable_LIMSEQ_real:
hoelzl@39092
  1764
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> real"
wenzelm@61969
  1765
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) \<longlonglongrightarrow> u' x"
hoelzl@39092
  1766
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@39092
  1767
  shows "u' \<in> borel_measurable M"
hoelzl@39092
  1768
proof -
hoelzl@43920
  1769
  have "\<And>x. x \<in> space M \<Longrightarrow> liminf (\<lambda>n. ereal (u n x)) = ereal (u' x)"
wenzelm@46731
  1770
    using u' by (simp add: lim_imp_Liminf)
hoelzl@43920
  1771
  moreover from u have "(\<lambda>x. liminf (\<lambda>n. ereal (u n x))) \<in> borel_measurable M"
hoelzl@39092
  1772
    by auto
hoelzl@43920
  1773
  ultimately show ?thesis by (simp cong: measurable_cong add: borel_measurable_ereal_iff)
hoelzl@39092
  1774
qed
hoelzl@39092
  1775
hoelzl@56993
  1776
lemma borel_measurable_LIMSEQ_metric:
hoelzl@56993
  1777
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b :: metric_space"
hoelzl@56993
  1778
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
wenzelm@61969
  1779
  assumes lim: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. f i x) \<longlonglongrightarrow> g x"
hoelzl@56993
  1780
  shows "g \<in> borel_measurable M"
hoelzl@56993
  1781
  unfolding borel_eq_closed
hoelzl@56993
  1782
proof (safe intro!: measurable_measure_of)
hoelzl@62372
  1783
  fix A :: "'b set" assume "closed A"
hoelzl@56993
  1784
hoelzl@56993
  1785
  have [measurable]: "(\<lambda>x. infdist (g x) A) \<in> borel_measurable M"
hoelzl@62624
  1786
  proof (rule borel_measurable_LIMSEQ_real)
wenzelm@61969
  1787
    show "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. infdist (f i x) A) \<longlonglongrightarrow> infdist (g x) A"
hoelzl@56993
  1788
      by (intro tendsto_infdist lim)
hoelzl@56993
  1789
    show "\<And>i. (\<lambda>x. infdist (f i x) A) \<in> borel_measurable M"
hoelzl@56993
  1790
      by (intro borel_measurable_continuous_on[where f="\<lambda>x. infdist x A"]
lp15@60150
  1791
        continuous_at_imp_continuous_on ballI continuous_infdist continuous_ident) auto
hoelzl@56993
  1792
  qed
hoelzl@56993
  1793
hoelzl@56993
  1794
  show "g -` A \<inter> space M \<in> sets M"
hoelzl@56993
  1795
  proof cases
hoelzl@56993
  1796
    assume "A \<noteq> {}"
hoelzl@56993
  1797
    then have "\<And>x. infdist x A = 0 \<longleftrightarrow> x \<in> A"
wenzelm@61808
  1798
      using \<open>closed A\<close> by (simp add: in_closed_iff_infdist_zero)
hoelzl@56993
  1799
    then have "g -` A \<inter> space M = {x\<in>space M. infdist (g x) A = 0}"
hoelzl@56993
  1800
      by auto
hoelzl@56993
  1801
    also have "\<dots> \<in> sets M"
hoelzl@56993
  1802
      by measurable
hoelzl@56993
  1803
    finally show ?thesis .
hoelzl@56993
  1804
  qed simp
hoelzl@56993
  1805
qed auto
hoelzl@56993
  1806
hoelzl@62372
  1807
lemma sets_Collect_Cauchy[measurable]:
hoelzl@57036
  1808
  fixes f :: "nat \<Rightarrow> 'a => 'b::{metric_space, second_countable_topology}"
hoelzl@50002
  1809
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1810
  shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
hoelzl@57036
  1811
  unfolding metric_Cauchy_iff2 using f by auto
hoelzl@49774
  1812
hoelzl@62624
  1813
lemma borel_measurable_lim_metric[measurable (raw)]:
hoelzl@57036
  1814
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@50002
  1815
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1816
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1817
proof -
wenzelm@63040
  1818
  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
  1819
  then have *: "\<And>x. lim (\<lambda>i. f i x) = (if Cauchy (\<lambda>i. f i x) then u' x else (THE x. False))"
lp15@64287
  1820
    by (auto simp: lim_def convergent_eq_Cauchy[symmetric])
hoelzl@50002
  1821
  have "u' \<in> borel_measurable M"
hoelzl@57036
  1822
  proof (rule borel_measurable_LIMSEQ_metric)
hoelzl@50002
  1823
    fix x
hoelzl@50002
  1824
    have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@49774
  1825
      by (cases "Cauchy (\<lambda>i. f i x)")
lp15@64287
  1826
         (auto simp add: convergent_eq_Cauchy[symmetric] convergent_def)
wenzelm@61969
  1827
    then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) \<longlonglongrightarrow> u' x"
hoelzl@62372
  1828
      unfolding u'_def
hoelzl@50002
  1829
      by (rule convergent_LIMSEQ_iff[THEN iffD1])
hoelzl@50002
  1830
  qed measurable
hoelzl@50002
  1831
  then show ?thesis
hoelzl@50002
  1832
    unfolding * by measurable
hoelzl@49774
  1833
qed
hoelzl@49774
  1834
hoelzl@50002
  1835
lemma borel_measurable_suminf[measurable (raw)]:
hoelzl@57036
  1836
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@50002
  1837
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1838
  shows "(\<lambda>x. suminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1839
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@49774
  1840
hoelzl@63389
  1841
lemma Collect_closed_imp_pred_borel: "closed {x. P x} \<Longrightarrow> Measurable.pred borel P"
hoelzl@63389
  1842
  by (simp add: pred_def)
hoelzl@63389
  1843
hoelzl@57447
  1844
(* Proof by Jeremy Avigad and Luke Serafin *)
hoelzl@63389
  1845
lemma isCont_borel_pred[measurable]:
hoelzl@63389
  1846
  fixes f :: "'b::metric_space \<Rightarrow> 'a::metric_space"
hoelzl@63389
  1847
  shows "Measurable.pred borel (isCont f)"
hoelzl@63389
  1848
proof (subst measurable_cong)
hoelzl@63389
  1849
  let ?I = "\<lambda>j. inverse(real (Suc j))"
hoelzl@63389
  1850
  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
  1851
    unfolding continuous_at_eps_delta
hoelzl@63389
  1852
  proof safe
hoelzl@63389
  1853
    fix i assume "\<forall>e>0. \<exists>d>0. \<forall>y. dist y x < d \<longrightarrow> dist (f y) (f x) < e"
hoelzl@63389
  1854
    moreover have "0 < ?I i / 2"
hoelzl@63389
  1855
      by simp
hoelzl@63389
  1856
    ultimately obtain d where d: "0 < d" "\<And>y. dist x y < d \<Longrightarrow> dist (f y) (f x) < ?I i / 2"
hoelzl@63389
  1857
      by (metis dist_commute)
hoelzl@63389
  1858
    then obtain j where j: "?I j < d"
hoelzl@63389
  1859
      by (metis reals_Archimedean)
hoelzl@63389
  1860
hoelzl@63389
  1861
    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
  1862
    proof (safe intro!: exI[where x=j])
hoelzl@63389
  1863
      fix y z assume *: "dist x y < ?I j" "dist x z < ?I j"
hoelzl@63389
  1864
      have "dist (f y) (f z) \<le> dist (f y) (f x) + dist (f z) (f x)"
hoelzl@63389
  1865
        by (rule dist_triangle2)
hoelzl@63389
  1866
      also have "\<dots> < ?I i / 2 + ?I i / 2"
hoelzl@63389
  1867
        by (intro add_strict_mono d less_trans[OF _ j] *)
hoelzl@63389
  1868
      also have "\<dots> \<le> ?I i"
hoelzl@63389
  1869
        by (simp add: field_simps of_nat_Suc)
hoelzl@63389
  1870
      finally show "dist (f y) (f z) \<le> ?I i"
hoelzl@63389
  1871
        by simp
hoelzl@63389
  1872
    qed
hoelzl@63389
  1873
  next
hoelzl@63389
  1874
    fix e::real assume "0 < e"
hoelzl@63389
  1875
    then obtain n where n: "?I n < e"
hoelzl@63389
  1876
      by (metis reals_Archimedean)
hoelzl@63389
  1877
    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
  1878
    from this[THEN spec, of "Suc n"]
hoelzl@63389
  1879
    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
  1880
      by auto
hoelzl@63389
  1881
hoelzl@63389
  1882
    show "\<exists>d>0. \<forall>y. dist y x < d \<longrightarrow> dist (f y) (f x) < e"
hoelzl@63389
  1883
    proof (safe intro!: exI[of _ "?I j"])
hoelzl@63389
  1884
      fix y assume "dist y x < ?I j"
hoelzl@63389
  1885
      then have "dist (f y) (f x) \<le> ?I (Suc n)"
hoelzl@63389
  1886
        by (intro j) (auto simp: dist_commute)
hoelzl@63389
  1887
      also have "?I (Suc n) < ?I n"
hoelzl@63389
  1888
        by simp
hoelzl@63389
  1889
      also note n
hoelzl@63389
  1890
      finally show "dist (f y) (f x) < e" .
hoelzl@63389
  1891
    qed simp
hoelzl@63389
  1892
  qed
hoelzl@63389
  1893
qed (intro pred_intros_countable closed_Collect_all closed_Collect_le open_Collect_less
hoelzl@63389
  1894
           Collect_closed_imp_pred_borel closed_Collect_imp open_Collect_conj continuous_intros)
hoelzl@63389
  1895
hoelzl@57447
  1896
lemma isCont_borel:
hoelzl@57447
  1897
  fixes f :: "'b::metric_space \<Rightarrow> 'a::metric_space"
hoelzl@57447
  1898
  shows "{x. isCont f x} \<in> sets borel"
hoelzl@63389
  1899
  by simp
hoelzl@62083
  1900
hoelzl@61880
  1901
lemma is_real_interval:
hoelzl@61880
  1902
  assumes S: "is_interval S"
hoelzl@61880
  1903
  shows "\<exists>a b::real. S = {} \<or> S = UNIV \<or> S = {..<b} \<or> S = {..b} \<or> S = {a<..} \<or> S = {a..} \<or>
hoelzl@61880
  1904
    S = {a<..<b} \<or> S = {a<..b} \<or> S = {a..<b} \<or> S = {a..b}"
hoelzl@61880
  1905
  using S unfolding is_interval_1 by (blast intro: interval_cases)
hoelzl@61880
  1906
hoelzl@61880
  1907
lemma real_interval_borel_measurable:
hoelzl@61880
  1908
  assumes "is_interval (S::real set)"
hoelzl@61880
  1909
  shows "S \<in> sets borel"
hoelzl@61880
  1910
proof -
hoelzl@61880
  1911
  from assms is_real_interval have "\<exists>a b::real. S = {} \<or> S = UNIV \<or> S = {..<b} \<or> S = {..b} \<or>
hoelzl@61880
  1912
    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
  1913
  then guess a ..
hoelzl@61880
  1914
  then guess b ..
hoelzl@61880
  1915
  thus ?thesis
hoelzl@61880
  1916
    by auto
hoelzl@61880
  1917
qed
hoelzl@61880
  1918
hoelzl@64283
  1919
text \<open>The next lemmas hold in any second countable linorder (including ennreal or ereal for instance),
hoelzl@64283
  1920
but in the current state they are restricted to reals.\<close>
hoelzl@64283
  1921
hoelzl@62083
  1922
lemma borel_measurable_mono_on_fnc:
hoelzl@62083
  1923
  fixes f :: "real \<Rightarrow> real" and A :: "real set"
hoelzl@62083
  1924
  assumes "mono_on f A"
hoelzl@62083
  1925
  shows "f \<in> borel_measurable (restrict_space borel A)"
hoelzl@62083
  1926
  apply (rule measurable_restrict_countable[OF mono_on_ctble_discont[OF assms]])
hoelzl@62083
  1927
  apply (auto intro!: image_eqI[where x="{x}" for x] simp: sets_restrict_space)
hoelzl@62083
  1928
  apply (auto simp add: sets_restrict_restrict_space continuous_on_eq_continuous_within
hoelzl@62372
  1929
              cong: measurable_cong_sets
hoelzl@62083
  1930
              intro!: borel_measurable_continuous_on_restrict intro: continuous_within_subset)
hoelzl@62083
  1931
  done
hoelzl@62083
  1932
hoelzl@64283
  1933
lemma borel_measurable_piecewise_mono:
hoelzl@64283
  1934
  fixes f::"real \<Rightarrow> real" and C::"real set set"
hoelzl@64283
  1935
  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
  1936
  shows "f \<in> borel_measurable borel"
hoelzl@64283
  1937
by (rule measurable_piecewise_restrict[of C], auto intro: borel_measurable_mono_on_fnc simp: assms)
hoelzl@64283
  1938
hoelzl@61880
  1939
lemma borel_measurable_mono:
hoelzl@61880
  1940
  fixes f :: "real \<Rightarrow> real"
hoelzl@62083
  1941
  shows "mono f \<Longrightarrow> f \<in> borel_measurable borel"
hoelzl@62083
  1942
  using borel_measurable_mono_on_fnc[of f UNIV] by (simp add: mono_def mono_on_def)
hoelzl@61880
  1943
hoelzl@64008
  1944
lemma measurable_bdd_below_real[measurable (raw)]:
hoelzl@64008
  1945
  fixes F :: "'a \<Rightarrow> 'i \<Rightarrow> real"
hoelzl@64008
  1946
  assumes [simp]: "countable I" and [measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> M \<rightarrow>\<^sub>M borel"
hoelzl@64008
  1947
  shows "Measurable.pred M (\<lambda>x. bdd_below ((\<lambda>i. F i x)`I))"
hoelzl@64008
  1948
proof (subst measurable_cong)
hoelzl@64008
  1949
  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
  1950
    by (auto simp: bdd_below_def intro!: bexI[of _ "of_int (floor _)"] intro: order_trans of_int_floor_le)
hoelzl@64008
  1951
  show "Measurable.pred M (\<lambda>w. \<exists>q\<in>\<int>. \<forall>i\<in>I. q \<le> F i w)"
hoelzl@64008
  1952
    using countable_int by measurable
hoelzl@64008
  1953
qed
hoelzl@64008
  1954
hoelzl@64008
  1955
lemma borel_measurable_cINF_real[measurable (raw)]:
hoelzl@64008
  1956
  fixes F :: "_ \<Rightarrow> _ \<Rightarrow> real"
hoelzl@64008
  1957
  assumes [simp]: "countable I"
hoelzl@64008
  1958
  assumes F[measurable]: "\<And>i. i \<in> I \<Longrightarrow> F i \<in> borel_measurable M"
hoelzl@64008
  1959
  shows "(\<lambda>x. INF i:I. F i x) \<in> borel_measurable M"
hoelzl@64008
  1960
proof (rule measurable_piecewise_restrict)
hoelzl@64008
  1961
  let ?\<Omega> = "{x\<in>space M. bdd_below ((\<lambda>i. F i x)`I)}"
hoelzl@64008
  1962
  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
  1963
    by auto
hoelzl@64008
  1964
  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
  1965
  proof safe
hoelzl@64008
  1966
    show "(\<lambda>x. INF i:I. F i x) \<in> borel_measurable (restrict_space M ?\<Omega>)"
hoelzl@64008
  1967
      by (intro borel_measurable_cINF measurable_restrict_space1 F)
hoelzl@64008
  1968
         (auto simp: space_restrict_space)
hoelzl@64008
  1969
    show "(\<lambda>x. INF i:I. F i x) \<in> borel_measurable (restrict_space M (-?\<Omega>))"
hoelzl@64008
  1970
    proof (subst measurable_cong)
hoelzl@64008
  1971
      fix x assume "x \<in> space (restrict_space M (-?\<Omega>))"
hoelzl@64008
  1972
      then have "\<not> (\<forall>i\<in>I. - F i x \<le> y)" for y
hoelzl@64008
  1973
        by (auto simp: space_restrict_space bdd_above_def bdd_above_uminus[symmetric])
hoelzl@64008
  1974
      then show "(INF i:I. F i x) = - (THE x. False)"
hoelzl@64008
  1975
        by (auto simp: space_restrict_space Inf_real_def Sup_real_def Least_def simp del: Set.ball_simps(10))
hoelzl@64008
  1976
    qed simp
hoelzl@64008
  1977
  qed
hoelzl@64008
  1978
qed
hoelzl@64008
  1979
hoelzl@64008
  1980
lemma borel_Ici: "borel = sigma UNIV (range (\<lambda>x::real. {x ..}))"
hoelzl@64008
  1981
proof (safe intro!: borel_eq_sigmaI1[OF borel_Iio])
hoelzl@64008
  1982
  fix x :: real
hoelzl@64008
  1983
  have eq: "{..<x} = space (sigma UNIV (range atLeast)) - {x ..}"
hoelzl@64008
  1984
    by auto
hoelzl@64008
  1985
  show "{..<x} \<in> sets (sigma UNIV (range atLeast))"
hoelzl@64008
  1986
    unfolding eq by (intro sets.compl_sets) auto
hoelzl@64008
  1987
qed auto
hoelzl@64008
  1988
hoelzl@64008
  1989
lemma borel_measurable_pred_less[measurable (raw)]:
hoelzl@64008
  1990
  fixes f :: "'a \<Rightarrow> 'b::{second_countable_topology, linorder_topology}"
hoelzl@64008
  1991
  shows "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> Measurable.pred M (\<lambda>w. f w < g w)"
hoelzl@64008
  1992
  unfolding Measurable.pred_def by (rule borel_measurable_less)
hoelzl@64008
  1993
immler@54775
  1994
no_notation
immler@54775
  1995
  eucl_less (infix "<e" 50)
immler@54775
  1996
hoelzl@64284
  1997
lemma borel_measurable_Max2[measurable (raw)]:
hoelzl@64284
  1998
  fixes f::"_ \<Rightarrow> _ \<Rightarrow> 'a::{second_countable_topology, dense_linorder, linorder_topology}"
hoelzl@64284
  1999
  assumes "finite I"
hoelzl@64284
  2000
    and [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@64284
  2001
  shows "(\<lambda>x. Max{f i x |i. i \<in> I}) \<in> borel_measurable M"
hoelzl@64284
  2002
by (simp add: borel_measurable_Max[OF assms(1), where ?f=f and ?M=M] Setcompr_eq_image)
hoelzl@64284
  2003
hoelzl@64284
  2004
lemma measurable_compose_n [measurable (raw)]:
hoelzl@64284
  2005
  assumes "T \<in> measurable M M"
hoelzl@64284
  2006
  shows "(T^^n) \<in> measurable M M"
hoelzl@64284
  2007
by (induction n, auto simp add: measurable_compose[OF _ assms])
hoelzl@64284
  2008
hoelzl@64284
  2009
lemma measurable_real_imp_nat:
hoelzl@64284
  2010
  fixes f::"'a \<Rightarrow> nat"
hoelzl@64284
  2011
  assumes [measurable]: "(\<lambda>x. real(f x)) \<in> borel_measurable M"
hoelzl@64284
  2012
  shows "f \<in> measurable M (count_space UNIV)"
hoelzl@64284
  2013
proof -
hoelzl@64284
  2014
  let ?g = "(\<lambda>x. real(f x))"
hoelzl@64284
  2015
  have "\<And>(n::nat). ?g-`({real n}) \<inter> space M = f-`{n} \<inter> space M" by auto
hoelzl@64284
  2016
  moreover have "\<And>(n::nat). ?g-`({real n}) \<inter> space M \<in> sets M" using assms by measurable
hoelzl@64284
  2017
  ultimately have "\<And>(n::nat). f-`{n} \<inter> space M \<in> sets M" by simp
hoelzl@64284
  2018
  then show ?thesis using measurable_count_space_eq2_countable by blast
hoelzl@64284
  2019
qed
hoelzl@64284
  2020
hoelzl@64284
  2021
lemma measurable_equality_set [measurable]:
hoelzl@64284
  2022
  fixes f g::"_\<Rightarrow> 'a::{second_countable_topology, t2_space}"
hoelzl@64284
  2023
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@64284
  2024
  shows "{x \<in> space M. f x = g x} \<in> sets M"
hoelzl@64284
  2025
hoelzl@64284
  2026
proof -
hoelzl@64284
  2027
  define A where "A = {x \<in> space M. f x = g x}"
hoelzl@64284
  2028
  define B where "B = {y. \<exists>x::'a. y = (x,x)}"
hoelzl@64284
  2029
  have "A = (\<lambda>x. (f x, g x))-`B \<inter> space M" unfolding A_def B_def by auto
hoelzl@64284
  2030
  moreover have "(\<lambda>x. (f x, g x)) \<in> borel_measurable M" by simp
hoelzl@64284
  2031
  moreover have "B \<in> sets borel" unfolding B_def by (simp add: closed_diagonal)
hoelzl@64284
  2032
  ultimately have "A \<in> sets M" by simp
hoelzl@64284
  2033
  then show ?thesis unfolding A_def by simp
hoelzl@64284
  2034
qed
hoelzl@64284
  2035
hoelzl@64284
  2036
lemma measurable_inequality_set [measurable]:
hoelzl@64284
  2037
  fixes f g::"_ \<Rightarrow> 'a::{second_countable_topology, linorder_topology}"
hoelzl@64284
  2038
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@64284
  2039
  shows "{x \<in> space M. f x \<le> g x} \<in> sets M"
hoelzl@64284
  2040
        "{x \<in> space M. f x < g x} \<in> sets M"
hoelzl@64284
  2041
        "{x \<in> space M. f x \<ge> g x} \<in> sets M"
hoelzl@64284
  2042
        "{x \<in> space M. f x > g x} \<in> sets M"
hoelzl@64284
  2043
proof -
hoelzl@64284
  2044
  define F where "F = (\<lambda>x. (f x, g x))"
hoelzl@64284
  2045
  have * [measurable]: "F \<in> borel_measurable M" unfolding F_def by simp
hoelzl@64284
  2046
hoelzl@64284
  2047
  have "{x \<in> space M. f x \<le> g x} = F-`{(x, y) | x y. x \<le> y} \<inter> space M" unfolding F_def by auto
hoelzl@64284
  2048
  moreover have "{(x, y) | x y. x \<le> (y::'a)} \<in> sets borel" using closed_subdiagonal borel_closed by blast
hoelzl@64284
  2049
  ultimately show "{x \<in> space M. f x \<le> g x} \<in> sets M" using * by (metis (mono_tags, lifting) measurable_sets)
hoelzl@64284
  2050
hoelzl@64284
  2051
  have "{x \<in> space M. f x < g x} = F-`{(x, y) | x y. x < y} \<inter> space M" unfolding F_def by auto
hoelzl@64284
  2052
  moreover have "{(x, y) | x y. x < (y::'a)} \<in> sets borel" using open_subdiagonal borel_open by blast
hoelzl@64284
  2053
  ultimately show "{x \<in> space M. f x < g x} \<in> sets M" using * by (metis (mono_tags, lifting) measurable_sets)
hoelzl@64284
  2054
hoelzl@64284
  2055
  have "{x \<in> space M. f x \<ge> g x} = F-`{(x, y) | x y. x \<ge> y} \<inter> space M" unfolding F_def by auto
hoelzl@64284
  2056
  moreover have "{(x, y) | x y. x \<ge> (y::'a)} \<in> sets borel" using closed_superdiagonal borel_closed by blast
hoelzl@64284
  2057
  ultimately show "{x \<in> space M. f x \<ge> g x} \<in> sets M" using * by (metis (mono_tags, lifting) measurable_sets)
hoelzl@64284
  2058
hoelzl@64284
  2059
  have "{x \<in> space M. f x > g x} = F-`{(x, y) | x y. x > y} \<inter> space M" unfolding F_def by auto
hoelzl@64284
  2060
  moreover have "{(x, y) | x y. x > (y::'a)} \<in> sets borel" using open_superdiagonal borel_open by blast
hoelzl@64284
  2061
  ultimately show "{x \<in> space M. f x > g x} \<in> sets M" using * by (metis (mono_tags, lifting) measurable_sets)
hoelzl@64284
  2062
qed
hoelzl@64284
  2063
hoelzl@64284
  2064
lemma measurable_limit [measurable]:
hoelzl@64284
  2065
  fixes f::"nat \<Rightarrow> 'a \<Rightarrow> 'b::first_countable_topology"
hoelzl@64284
  2066
  assumes [measurable]: "\<And>n::nat. f n \<in> borel_measurable M"
hoelzl@64284
  2067
  shows "Measurable.pred M (\<lambda>x. (\<lambda>n. f n x) \<longlonglongrightarrow> c)"
hoelzl@64284
  2068
proof -
hoelzl@64284
  2069
  obtain A :: "nat \<Rightarrow> 'b set" where A:
hoelzl@64284
  2070
    "\<And>i. open (A i)"
hoelzl@64284
  2071
    "\<And>i. c \<in> A i"
hoelzl@64284
  2072
    "\<And>S. open S \<Longrightarrow> c \<in> S \<Longrightarrow> eventually (\<lambda>i. A i \<subseteq> S) sequentially"
hoelzl@64284
  2073
  by (rule countable_basis_at_decseq) blast
hoelzl@64284
  2074
hoelzl@64284
  2075
  have [measurable]: "\<And>N i. (f N)-`(A i) \<inter> space M \<in> sets M" using A(1) by auto
hoelzl@64284
  2076
  then have mes: "(\<Inter>i. \<Union>n. \<Inter>N\<in>{n..}. (f N)-`(A i) \<inter> space M) \<in> sets M" by blast
hoelzl@64284
  2077
hoelzl@64284
  2078
  have "(u \<longlonglongrightarrow> c) \<longleftrightarrow> (\<forall>i. eventually (\<lambda>n. u n \<in> A i) sequentially)" for u::"nat \<Rightarrow> 'b"
hoelzl@64284
  2079
  proof
hoelzl@64284
  2080
    assume "u \<longlonglongrightarrow> c"
hoelzl@64284
  2081
    then have "eventually (\<lambda>n. u n \<in> A i) sequentially" for i using A(1)[of i] A(2)[of i]
hoelzl@64284
  2082
      by (simp add: topological_tendstoD)
hoelzl@64284
  2083
    then show "(\<forall>i. eventually (\<lambda>n. u n \<in> A i) sequentially)" by auto
hoelzl@64284
  2084
  next
hoelzl@64284
  2085
    assume H: "(\<forall>i. eventually (\<lambda>n. u n \<in> A i) sequentially)"
hoelzl@64284
  2086
    show "(u \<longlonglongrightarrow> c)"
hoelzl@64284
  2087
    proof (rule topological_tendstoI)
hoelzl@64284
  2088
      fix S assume "open S" "c \<in> S"
hoelzl@64284
  2089
      with A(3)[OF this] obtain i where "A i \<subseteq> S"
hoelzl@64284
  2090
        using eventually_False_sequentially eventually_mono by blast
hoelzl@64284
  2091
      moreover have "eventually (\<lambda>n. u n \<in> A i) sequentially" using H by simp
hoelzl@64284
  2092
      ultimately show "\<forall>\<^sub>F n in sequentially. u n \<in> S"
hoelzl@64284
  2093
        by (simp add: eventually_mono subset_eq)
hoelzl@64284
  2094
    qed
hoelzl@64284
  2095
  qed
hoelzl@64284
  2096
  then have "{x. (\<lambda>n. f n x) \<longlonglongrightarrow> c} = (\<Inter>i. \<Union>n. \<Inter>N\<in>{n..}. (f N)-`(A i))"
hoelzl@64284
  2097
    by (auto simp add: atLeast_def eventually_at_top_linorder)
hoelzl@64284
  2098
  then have "{x \<in> space M. (\<lambda>n. f n x) \<longlonglongrightarrow> c} = (\<Inter>i. \<Union>n. \<Inter>N\<in>{n..}. (f N)-`(A i) \<inter> space M)"
hoelzl@64284
  2099
    by auto
hoelzl@64284
  2100
  then have "{x \<in> space M. (\<lambda>n. f n x) \<longlonglongrightarrow> c} \<in> sets M" using mes by simp
hoelzl@64284
  2101
  then show ?thesis by auto
hoelzl@64284
  2102
qed
hoelzl@64284
  2103
hoelzl@64284
  2104
lemma measurable_limit2 [measurable]:
hoelzl@64284
  2105
  fixes u::"nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@64284
  2106
  assumes [measurable]: "\<And>n. u n \<in> borel_measurable M" "v \<in> borel_measurable M"
hoelzl@64284
  2107
  shows "Measurable.pred M (\<lambda>x. (\<lambda>n. u n x) \<longlonglongrightarrow> v x)"
hoelzl@64284
  2108
proof -
hoelzl@64284
  2109
  define w where "w = (\<lambda>n x. u n x - v x)"
hoelzl@64284
  2110
  have [measurable]: "w n \<in> borel_measurable M" for n unfolding w_def by auto
hoelzl@64284
  2111
  have "((\<lambda>n. u n x) \<longlonglongrightarrow> v x) \<longleftrightarrow> ((\<lambda>n. w n x) \<longlonglongrightarrow> 0)" for x
hoelzl@64284
  2112
    unfolding w_def using Lim_null by auto
hoelzl@64284
  2113
  then show ?thesis using measurable_limit by auto
hoelzl@64284
  2114
qed
hoelzl@64284
  2115
hoelzl@64284
  2116
lemma measurable_P_restriction [measurable (raw)]:
hoelzl@64284
  2117
  assumes [measurable]: "Measurable.pred M P" "A \<in> sets M"
hoelzl@64284
  2118
  shows "{x \<in> A. P x} \<in> sets M"
hoelzl@64284
  2119
proof -
hoelzl@64284
  2120
  have "A \<subseteq> space M" using sets.sets_into_space[OF assms(2)].
hoelzl@64284
  2121
  then have "{x \<in> A. P x} = A \<inter> {x \<in> space M. P x}" by blast
hoelzl@64284
  2122
  then show ?thesis by auto
hoelzl@64284
  2123
qed
hoelzl@64284
  2124
hoelzl@64284
  2125
lemma measurable_sum_nat [measurable (raw)]:
hoelzl@64284
  2126
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> nat"
hoelzl@64284
  2127
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> measurable M (count_space UNIV)"
hoelzl@64284
  2128
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> measurable M (count_space UNIV)"
hoelzl@64284
  2129
proof cases
hoelzl@64284
  2130
  assume "finite S"
hoelzl@64284
  2131
  then show ?thesis using assms by induct auto
hoelzl@64284
  2132
qed simp
hoelzl@64284
  2133
hoelzl@64284
  2134
hoelzl@64284
  2135
lemma measurable_abs_powr [measurable]:
hoelzl@64284
  2136
  fixes p::real
hoelzl@64284
  2137
  assumes [measurable]: "f \<in> borel_measurable M"
hoelzl@64284
  2138
  shows "(\<lambda>x. \<bar>f x\<bar> powr p) \<in> borel_measurable M"
hoelzl@64284
  2139
unfolding powr_def by auto
hoelzl@64284
  2140
wenzelm@64911
  2141
text \<open>The next one is a variation around \verb+measurable_restrict_space+.\<close>
hoelzl@64284
  2142
hoelzl@64284
  2143
lemma measurable_restrict_space3:
hoelzl@64284
  2144
  assumes "f \<in> measurable M N" and
hoelzl@64284
  2145
          "f \<in> A \<rightarrow> B"
hoelzl@64284
  2146
  shows "f \<in> measurable (restrict_space M A) (restrict_space N B)"
hoelzl@64284
  2147
proof -
hoelzl@64284
  2148
  have "f \<in> measurable (restrict_space M A) N" using assms(1) measurable_restrict_space1 by auto
hoelzl@64284
  2149
  then show ?thesis by (metis Int_iff funcsetI funcset_mem
hoelzl@64284
  2150
      measurable_restrict_space2[of f, of "restrict_space M A", of B, of N] assms(2) space_restrict_space)
hoelzl@64284
  2151
qed
hoelzl@64284
  2152
wenzelm@64911
  2153
text \<open>The next one is a variation around \verb+measurable_piecewise_restrict+.\<close>
hoelzl@64284
  2154
hoelzl@64284
  2155
lemma measurable_piecewise_restrict2:
hoelzl@64284
  2156
  assumes [measurable]: "\<And>n. A n \<in> sets M"
hoelzl@64284
  2157
      and "space M = (\<Union>(n::nat). A n)"
hoelzl@64284
  2158
          "\<And>n. \<exists>h \<in> measurable M N. (\<forall>x \<in> A n. f x = h x)"
hoelzl@64284
  2159
  shows "f \<in> measurable M N"
hoelzl@64284
  2160
proof (rule measurableI)
hoelzl@64284
  2161
  fix B assume [measurable]: "B \<in> sets N"
hoelzl@64284
  2162
  {
hoelzl@64284
  2163
    fix n::nat
hoelzl@64284
  2164
    obtain h where [measurable]: "h \<in> measurable M N" and "\<forall>x \<in> A n. f x = h x" using assms(3) by blast
hoelzl@64284
  2165
    then have *: "f-`B \<inter> A n = h-`B \<inter> A n" by auto
hoelzl@64284
  2166
    have "h-`B \<inter> A n = h-`B \<inter> space M \<inter> A n" using assms(2) sets.sets_into_space by auto
hoelzl@64284
  2167
    then have "h-`B \<inter> A n \<in> sets M" by simp
hoelzl@64284
  2168
    then have "f-`B \<inter> A n \<in> sets M" using * by simp
hoelzl@64284
  2169
  }
hoelzl@64284
  2170
  then have "(\<Union>n. f-`B \<inter> A n) \<in> sets M" by measurable
hoelzl@64284
  2171
  moreover have "f-`B \<inter> space M = (\<Union>n. f-`B \<inter> A n)" using assms(2) by blast
hoelzl@64284
  2172
  ultimately show "f-`B \<inter> space M \<in> sets M" by simp
hoelzl@64284
  2173
next
hoelzl@64284
  2174
  fix x assume "x \<in> space M"
hoelzl@64284
  2175
  then obtain n where "x \<in> A n" using assms(2) by blast
hoelzl@64284
  2176
  obtain h where [measurable]: "h \<in> measurable M N" and "\<forall>x \<in> A n. f x = h x" using assms(3) by blast
wenzelm@64911
  2177
  then have "f x = h x" using \<open>x \<in> A n\<close> by blast
wenzelm@64911
  2178
  moreover have "h x \<in> space N" by (metis measurable_space \<open>x \<in> space M\<close> \<open>h \<in> measurable M N\<close>)
hoelzl@64284
  2179
  ultimately show "f x \<in> space N" by simp
hoelzl@64284
  2180
qed
hoelzl@64284
  2181
hoelzl@51683
  2182
end