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