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