src/HOL/Probability/Borel_Space.thy
author immler
Thu Nov 15 10:49:58 2012 +0100 (2012-11-15)
changeset 50087 635d73673b5e
parent 50021 d96a3f468203
child 50094 84ddcf5364b4
permissions -rw-r--r--
regularity of measures, therefore:
characterization of closure with infimum distance;
characterize of compact sets as totally bounded;
added Diagonal_Subsequence to Library;
introduced (enumerable) topological basis;
rational boxes as basis of ordered euclidean space;
moved some lemmas upwards
wenzelm@42150
     1
(*  Title:      HOL/Probability/Borel_Space.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
    Author:     Armin Heller, TU München
hoelzl@42067
     4
*)
hoelzl@38656
     5
hoelzl@38656
     6
header {*Borel spaces*}
paulson@33533
     7
hoelzl@40859
     8
theory Borel_Space
hoelzl@45288
     9
  imports Sigma_Algebra "~~/src/HOL/Multivariate_Analysis/Multivariate_Analysis"
paulson@33533
    10
begin
paulson@33533
    11
hoelzl@38656
    12
section "Generic Borel spaces"
paulson@33533
    13
hoelzl@47694
    14
definition borel :: "'a::topological_space measure" where
hoelzl@47694
    15
  "borel = sigma UNIV {S. open S}"
paulson@33533
    16
hoelzl@47694
    17
abbreviation "borel_measurable M \<equiv> measurable M borel"
paulson@33533
    18
paulson@33533
    19
lemma in_borel_measurable:
paulson@33533
    20
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@47694
    21
    (\<forall>S \<in> sigma_sets UNIV {S. open S}. f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
    22
  by (auto simp add: measurable_def borel_def)
paulson@33533
    23
hoelzl@40859
    24
lemma in_borel_measurable_borel:
hoelzl@38656
    25
   "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
    26
    (\<forall>S \<in> sets borel.
hoelzl@38656
    27
      f -` S \<inter> space M \<in> sets M)"
hoelzl@40859
    28
  by (auto simp add: measurable_def borel_def)
paulson@33533
    29
hoelzl@40859
    30
lemma space_borel[simp]: "space borel = UNIV"
hoelzl@40859
    31
  unfolding borel_def by auto
hoelzl@38656
    32
hoelzl@50002
    33
lemma space_in_borel[measurable]: "UNIV \<in> sets borel"
hoelzl@50002
    34
  unfolding borel_def by auto
hoelzl@50002
    35
hoelzl@50002
    36
lemma pred_Collect_borel[measurable (raw)]: "Sigma_Algebra.pred borel P \<Longrightarrow> {x. P x} \<in> sets borel"
hoelzl@50002
    37
  unfolding borel_def pred_def by auto
hoelzl@50002
    38
hoelzl@50003
    39
lemma borel_open[measurable (raw generic)]:
hoelzl@40859
    40
  assumes "open A" shows "A \<in> sets borel"
hoelzl@38656
    41
proof -
huffman@44537
    42
  have "A \<in> {S. open S}" unfolding mem_Collect_eq using assms .
hoelzl@47694
    43
  thus ?thesis unfolding borel_def by auto
paulson@33533
    44
qed
paulson@33533
    45
hoelzl@50003
    46
lemma borel_closed[measurable (raw generic)]:
hoelzl@40859
    47
  assumes "closed A" shows "A \<in> sets borel"
paulson@33533
    48
proof -
hoelzl@40859
    49
  have "space borel - (- A) \<in> sets borel"
hoelzl@40859
    50
    using assms unfolding closed_def by (blast intro: borel_open)
hoelzl@38656
    51
  thus ?thesis by simp
paulson@33533
    52
qed
paulson@33533
    53
hoelzl@50003
    54
lemma borel_singleton[measurable]:
hoelzl@50003
    55
  "A \<in> sets borel \<Longrightarrow> insert x A \<in> sets (borel :: 'a::t1_space measure)"
hoelzl@50002
    56
  unfolding insert_def by (rule Un) auto
hoelzl@50002
    57
hoelzl@50003
    58
lemma borel_comp[measurable]: "A \<in> sets borel \<Longrightarrow> - A \<in> sets borel"
hoelzl@50002
    59
  unfolding Compl_eq_Diff_UNIV by simp
hoelzl@41830
    60
hoelzl@47694
    61
lemma borel_measurable_vimage:
hoelzl@38656
    62
  fixes f :: "'a \<Rightarrow> 'x::t2_space"
hoelzl@50002
    63
  assumes borel[measurable]: "f \<in> borel_measurable M"
hoelzl@38656
    64
  shows "f -` {x} \<inter> space M \<in> sets M"
hoelzl@50002
    65
  by simp
paulson@33533
    66
hoelzl@47694
    67
lemma borel_measurableI:
hoelzl@38656
    68
  fixes f :: "'a \<Rightarrow> 'x\<Colon>topological_space"
hoelzl@38656
    69
  assumes "\<And>S. open S \<Longrightarrow> f -` S \<inter> space M \<in> sets M"
hoelzl@38656
    70
  shows "f \<in> borel_measurable M"
hoelzl@40859
    71
  unfolding borel_def
hoelzl@47694
    72
proof (rule measurable_measure_of, simp_all)
huffman@44537
    73
  fix S :: "'x set" assume "open S" thus "f -` S \<inter> space M \<in> sets M"
huffman@44537
    74
    using assms[of S] by simp
hoelzl@40859
    75
qed
paulson@33533
    76
hoelzl@50021
    77
lemma borel_measurable_const:
hoelzl@38656
    78
  "(\<lambda>x. c) \<in> borel_measurable M"
hoelzl@47694
    79
  by auto
paulson@33533
    80
hoelzl@50003
    81
lemma borel_measurable_indicator:
hoelzl@38656
    82
  assumes A: "A \<in> sets M"
hoelzl@38656
    83
  shows "indicator A \<in> borel_measurable M"
wenzelm@46905
    84
  unfolding indicator_def [abs_def] using A
hoelzl@47694
    85
  by (auto intro!: measurable_If_set)
paulson@33533
    86
hoelzl@50002
    87
lemma borel_measurable_indicator'[measurable]:
hoelzl@50001
    88
  "{x\<in>space M. x \<in> A} \<in> sets M \<Longrightarrow> indicator A \<in> borel_measurable M"
hoelzl@50001
    89
  unfolding indicator_def[abs_def]
hoelzl@50001
    90
  by (auto intro!: measurable_If)
hoelzl@50001
    91
hoelzl@47694
    92
lemma borel_measurable_indicator_iff:
hoelzl@40859
    93
  "(indicator A :: 'a \<Rightarrow> 'x::{t1_space, zero_neq_one}) \<in> borel_measurable M \<longleftrightarrow> A \<inter> space M \<in> sets M"
hoelzl@40859
    94
    (is "?I \<in> borel_measurable M \<longleftrightarrow> _")
hoelzl@40859
    95
proof
hoelzl@40859
    96
  assume "?I \<in> borel_measurable M"
hoelzl@40859
    97
  then have "?I -` {1} \<inter> space M \<in> sets M"
hoelzl@40859
    98
    unfolding measurable_def by auto
hoelzl@40859
    99
  also have "?I -` {1} \<inter> space M = A \<inter> space M"
wenzelm@46905
   100
    unfolding indicator_def [abs_def] by auto
hoelzl@40859
   101
  finally show "A \<inter> space M \<in> sets M" .
hoelzl@40859
   102
next
hoelzl@40859
   103
  assume "A \<inter> space M \<in> sets M"
hoelzl@40859
   104
  moreover have "?I \<in> borel_measurable M \<longleftrightarrow>
hoelzl@40859
   105
    (indicator (A \<inter> space M) :: 'a \<Rightarrow> 'x) \<in> borel_measurable M"
hoelzl@40859
   106
    by (intro measurable_cong) (auto simp: indicator_def)
hoelzl@40859
   107
  ultimately show "?I \<in> borel_measurable M" by auto
hoelzl@40859
   108
qed
hoelzl@40859
   109
hoelzl@47694
   110
lemma borel_measurable_subalgebra:
hoelzl@41545
   111
  assumes "sets N \<subseteq> sets M" "space N = space M" "f \<in> borel_measurable N"
hoelzl@39092
   112
  shows "f \<in> borel_measurable M"
hoelzl@39092
   113
  using assms unfolding measurable_def by auto
hoelzl@39092
   114
hoelzl@50002
   115
lemma borel_measurable_continuous_on1:
hoelzl@50002
   116
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@50002
   117
  assumes "continuous_on UNIV f"
hoelzl@50002
   118
  shows "f \<in> borel_measurable borel"
hoelzl@50002
   119
  apply(rule borel_measurableI)
hoelzl@50002
   120
  using continuous_open_preimage[OF assms] unfolding vimage_def by auto
hoelzl@50002
   121
hoelzl@38656
   122
section "Borel spaces on euclidean spaces"
hoelzl@38656
   123
hoelzl@50002
   124
lemma borel_measurable_euclidean_component'[measurable]:
hoelzl@50002
   125
  "(\<lambda>x::'a::euclidean_space. x $$ i) \<in> borel_measurable borel"
hoelzl@50002
   126
  by (intro continuous_on_euclidean_component continuous_on_id borel_measurable_continuous_on1)
hoelzl@38656
   127
hoelzl@50002
   128
lemma borel_measurable_euclidean_component:
hoelzl@50002
   129
  "(f :: 'a \<Rightarrow> 'b::euclidean_space) \<in> borel_measurable M \<Longrightarrow>(\<lambda>x. f x $$ i) \<in> borel_measurable M"
hoelzl@50002
   130
  by simp
paulson@33533
   131
hoelzl@50003
   132
lemma [measurable]:
hoelzl@38656
   133
  fixes a b :: "'a\<Colon>ordered_euclidean_space"
hoelzl@50002
   134
  shows lessThan_borel: "{..< a} \<in> sets borel"
hoelzl@50002
   135
    and greaterThan_borel: "{a <..} \<in> sets borel"
hoelzl@50002
   136
    and greaterThanLessThan_borel: "{a<..<b} \<in> sets borel"
hoelzl@50002
   137
    and atMost_borel: "{..a} \<in> sets borel"
hoelzl@50002
   138
    and atLeast_borel: "{a..} \<in> sets borel"
hoelzl@50002
   139
    and atLeastAtMost_borel: "{a..b} \<in> sets borel"
hoelzl@50002
   140
    and greaterThanAtMost_borel: "{a<..b} \<in> sets borel"
hoelzl@50002
   141
    and atLeastLessThan_borel: "{a..<b} \<in> sets borel"
hoelzl@50002
   142
  unfolding greaterThanAtMost_def atLeastLessThan_def
hoelzl@50002
   143
  by (blast intro: borel_open borel_closed)+
paulson@33533
   144
hoelzl@50002
   145
lemma 
hoelzl@50003
   146
  shows hafspace_less_borel: "{x::'a::euclidean_space. a < x $$ i} \<in> sets borel"
hoelzl@50003
   147
    and hafspace_greater_borel: "{x::'a::euclidean_space. x $$ i < a} \<in> sets borel"
hoelzl@50003
   148
    and hafspace_less_eq_borel: "{x::'a::euclidean_space. a \<le> x $$ i} \<in> sets borel"
hoelzl@50003
   149
    and hafspace_greater_eq_borel: "{x::'a::euclidean_space. x $$ i \<le> a} \<in> sets borel"
hoelzl@50002
   150
  by simp_all
paulson@33533
   151
hoelzl@50003
   152
lemma borel_measurable_less[measurable]:
hoelzl@38656
   153
  fixes f :: "'a \<Rightarrow> real"
paulson@33533
   154
  assumes f: "f \<in> borel_measurable M"
paulson@33533
   155
  assumes g: "g \<in> borel_measurable M"
paulson@33533
   156
  shows "{w \<in> space M. f w < g w} \<in> sets M"
paulson@33533
   157
proof -
hoelzl@50002
   158
  have "{w \<in> space M. f w < g w} = {x \<in> space M. \<exists>r. f x < of_rat r \<and> of_rat r < g x}"
hoelzl@38656
   159
    using Rats_dense_in_real by (auto simp add: Rats_def)
hoelzl@50002
   160
  with f g show ?thesis
hoelzl@50002
   161
    by simp
paulson@33533
   162
qed
paulson@33533
   163
hoelzl@50003
   164
lemma
hoelzl@38656
   165
  fixes f :: "'a \<Rightarrow> real"
hoelzl@50002
   166
  assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50002
   167
  assumes g[measurable]: "g \<in> borel_measurable M"
hoelzl@50002
   168
  shows borel_measurable_le[measurable]: "{w \<in> space M. f w \<le> g w} \<in> sets M"
hoelzl@50002
   169
    and borel_measurable_eq[measurable]: "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@50002
   170
    and borel_measurable_neq: "{w \<in> space M. f w \<noteq> g w} \<in> sets M"
hoelzl@50021
   171
  unfolding eq_iff not_less[symmetric]
hoelzl@50021
   172
  by measurable
hoelzl@38656
   173
hoelzl@38656
   174
subsection "Borel space equals sigma algebras over intervals"
hoelzl@38656
   175
hoelzl@47694
   176
lemma borel_sigma_sets_subset:
hoelzl@47694
   177
  "A \<subseteq> sets borel \<Longrightarrow> sigma_sets UNIV A \<subseteq> sets borel"
hoelzl@47694
   178
  using sigma_sets_subset[of A borel] by simp
hoelzl@47694
   179
hoelzl@47694
   180
lemma borel_eq_sigmaI1:
hoelzl@47694
   181
  fixes F :: "'i \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@47694
   182
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@47694
   183
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV (range F))"
hoelzl@47694
   184
  assumes F: "\<And>i. F i \<in> sets borel"
hoelzl@47694
   185
  shows "borel = sigma UNIV (range F)"
hoelzl@47694
   186
  unfolding borel_def
hoelzl@47694
   187
proof (intro sigma_eqI antisym)
hoelzl@47694
   188
  have borel_rev_eq: "sigma_sets UNIV {S::'a set. open S} = sets borel"
hoelzl@47694
   189
    unfolding borel_def by simp
hoelzl@47694
   190
  also have "\<dots> = sigma_sets UNIV X"
hoelzl@47694
   191
    unfolding borel_eq by simp
hoelzl@47694
   192
  also have "\<dots> \<subseteq> sigma_sets UNIV (range F)"
hoelzl@47694
   193
    using X by (intro sigma_algebra.sigma_sets_subset[OF sigma_algebra_sigma_sets]) auto
hoelzl@47694
   194
  finally show "sigma_sets UNIV {S. open S} \<subseteq> sigma_sets UNIV (range F)" .
hoelzl@47694
   195
  show "sigma_sets UNIV (range F) \<subseteq> sigma_sets UNIV {S. open S}"
hoelzl@47694
   196
    unfolding borel_rev_eq using F by (intro borel_sigma_sets_subset) auto
hoelzl@47694
   197
qed auto
hoelzl@38656
   198
hoelzl@47694
   199
lemma borel_eq_sigmaI2:
hoelzl@47694
   200
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set"
hoelzl@47694
   201
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@47694
   202
  assumes borel_eq: "borel = sigma UNIV (range (\<lambda>(i, j). G i j))"
hoelzl@47694
   203
  assumes X: "\<And>i j. G i j \<in> sets (sigma UNIV (range (\<lambda>(i, j). F i j)))"
hoelzl@47694
   204
  assumes F: "\<And>i j. F i j \<in> sets borel"
hoelzl@47694
   205
  shows "borel = sigma UNIV (range (\<lambda>(i, j). F i j))"
hoelzl@47694
   206
  using assms by (intro borel_eq_sigmaI1[where X="range (\<lambda>(i, j). G i j)" and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@47694
   207
hoelzl@47694
   208
lemma borel_eq_sigmaI3:
hoelzl@47694
   209
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and X :: "'a::topological_space set set"
hoelzl@47694
   210
  assumes borel_eq: "borel = sigma UNIV X"
hoelzl@47694
   211
  assumes X: "\<And>x. x \<in> X \<Longrightarrow> x \<in> sets (sigma UNIV (range (\<lambda>(i, j). F i j)))"
hoelzl@47694
   212
  assumes F: "\<And>i j. F i j \<in> sets borel"
hoelzl@47694
   213
  shows "borel = sigma UNIV (range (\<lambda>(i, j). F i j))"
hoelzl@47694
   214
  using assms by (intro borel_eq_sigmaI1[where X=X and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@47694
   215
hoelzl@47694
   216
lemma borel_eq_sigmaI4:
hoelzl@47694
   217
  fixes F :: "'i \<Rightarrow> 'a::topological_space set"
hoelzl@47694
   218
    and G :: "'l \<Rightarrow> 'k \<Rightarrow> 'a::topological_space set"
hoelzl@47694
   219
  assumes borel_eq: "borel = sigma UNIV (range (\<lambda>(i, j). G i j))"
hoelzl@47694
   220
  assumes X: "\<And>i j. G i j \<in> sets (sigma UNIV (range F))"
hoelzl@47694
   221
  assumes F: "\<And>i. F i \<in> sets borel"
hoelzl@47694
   222
  shows "borel = sigma UNIV (range F)"
hoelzl@47694
   223
  using assms by (intro borel_eq_sigmaI1[where X="range (\<lambda>(i, j). G i j)" and F=F]) auto
hoelzl@47694
   224
hoelzl@47694
   225
lemma borel_eq_sigmaI5:
hoelzl@47694
   226
  fixes F :: "'i \<Rightarrow> 'j \<Rightarrow> 'a::topological_space set" and G :: "'l \<Rightarrow> 'a::topological_space set"
hoelzl@47694
   227
  assumes borel_eq: "borel = sigma UNIV (range G)"
hoelzl@47694
   228
  assumes X: "\<And>i. G i \<in> sets (sigma UNIV (range (\<lambda>(i, j). F i j)))"
hoelzl@47694
   229
  assumes F: "\<And>i j. F i j \<in> sets borel"
hoelzl@47694
   230
  shows "borel = sigma UNIV (range (\<lambda>(i, j). F i j))"
hoelzl@47694
   231
  using assms by (intro borel_eq_sigmaI1[where X="range G" and F="(\<lambda>(i, j). F i j)"]) auto
hoelzl@38656
   232
hoelzl@38656
   233
lemma halfspace_gt_in_halfspace:
hoelzl@47694
   234
  "{x\<Colon>'a. a < x $$ i} \<in> sigma_sets UNIV (range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. x $$ i < a}))"
hoelzl@47694
   235
  (is "?set \<in> ?SIGMA")
hoelzl@38656
   236
proof -
hoelzl@47694
   237
  interpret sigma_algebra UNIV ?SIGMA
hoelzl@47694
   238
    by (intro sigma_algebra_sigma_sets) simp_all
hoelzl@47694
   239
  have *: "?set = (\<Union>n. UNIV - {x\<Colon>'a. x $$ i < a + 1 / real (Suc n)})"
hoelzl@38656
   240
  proof (safe, simp_all add: not_less)
hoelzl@50002
   241
    fix x :: 'a assume "a < x $$ i"
hoelzl@38656
   242
    with reals_Archimedean[of "x $$ i - a"]
hoelzl@38656
   243
    obtain n where "a + 1 / real (Suc n) < x $$ i"
hoelzl@38656
   244
      by (auto simp: inverse_eq_divide field_simps)
hoelzl@38656
   245
    then show "\<exists>n. a + 1 / real (Suc n) \<le> x $$ i"
hoelzl@38656
   246
      by (blast intro: less_imp_le)
hoelzl@38656
   247
  next
hoelzl@38656
   248
    fix x n
hoelzl@38656
   249
    have "a < a + 1 / real (Suc n)" by auto
hoelzl@38656
   250
    also assume "\<dots> \<le> x"
hoelzl@38656
   251
    finally show "a < x" .
hoelzl@38656
   252
  qed
hoelzl@47694
   253
  show "?set \<in> ?SIGMA" unfolding *
hoelzl@50002
   254
    by (auto del: Diff intro!: Diff)
hoelzl@40859
   255
qed
hoelzl@38656
   256
hoelzl@47694
   257
lemma borel_eq_halfspace_less:
hoelzl@47694
   258
  "borel = sigma UNIV (range (\<lambda>(a, i). {x::'a::ordered_euclidean_space. x $$ i < a}))"
hoelzl@47694
   259
  (is "_ = ?SIGMA")
hoelzl@47694
   260
proof (rule borel_eq_sigmaI3[OF borel_def])
hoelzl@47694
   261
  fix S :: "'a set" assume "S \<in> {S. open S}"
hoelzl@47694
   262
  then have "open S" by simp
hoelzl@47694
   263
  from open_UNION[OF this]
hoelzl@47694
   264
  obtain I where *: "S =
hoelzl@47694
   265
    (\<Union>(a, b)\<in>I.
hoelzl@47694
   266
        (\<Inter> i<DIM('a). {x. (Chi (real_of_rat \<circ> op ! a)::'a) $$ i < x $$ i}) \<inter>
hoelzl@47694
   267
        (\<Inter> i<DIM('a). {x. x $$ i < (Chi (real_of_rat \<circ> op ! b)::'a) $$ i}))"
hoelzl@47694
   268
    unfolding greaterThanLessThan_def
hoelzl@47694
   269
    unfolding eucl_greaterThan_eq_halfspaces[where 'a='a]
hoelzl@47694
   270
    unfolding eucl_lessThan_eq_halfspaces[where 'a='a]
hoelzl@47694
   271
    by blast
hoelzl@47694
   272
  show "S \<in> ?SIGMA"
hoelzl@47694
   273
    unfolding *
hoelzl@47694
   274
    by (safe intro!: countable_UN Int countable_INT) (auto intro!: halfspace_gt_in_halfspace)
hoelzl@47694
   275
qed auto
hoelzl@38656
   276
hoelzl@47694
   277
lemma borel_eq_halfspace_le:
hoelzl@47694
   278
  "borel = sigma UNIV (range (\<lambda> (a, i). {x::'a::ordered_euclidean_space. x $$ i \<le> a}))"
hoelzl@47694
   279
  (is "_ = ?SIGMA")
hoelzl@47694
   280
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@47694
   281
  fix a i
hoelzl@47694
   282
  have *: "{x::'a. x$$i < a} = (\<Union>n. {x. x$$i \<le> a - 1/real (Suc n)})"
hoelzl@47694
   283
  proof (safe, simp_all)
hoelzl@47694
   284
    fix x::'a assume *: "x$$i < a"
hoelzl@47694
   285
    with reals_Archimedean[of "a - x$$i"]
hoelzl@47694
   286
    obtain n where "x $$ i < a - 1 / (real (Suc n))"
hoelzl@47694
   287
      by (auto simp: field_simps inverse_eq_divide)
hoelzl@47694
   288
    then show "\<exists>n. x $$ i \<le> a - 1 / (real (Suc n))"
hoelzl@47694
   289
      by (blast intro: less_imp_le)
hoelzl@47694
   290
  next
hoelzl@47694
   291
    fix x::'a and n
hoelzl@47694
   292
    assume "x$$i \<le> a - 1 / real (Suc n)"
hoelzl@47694
   293
    also have "\<dots> < a" by auto
hoelzl@47694
   294
    finally show "x$$i < a" .
hoelzl@47694
   295
  qed
hoelzl@47694
   296
  show "{x. x$$i < a} \<in> ?SIGMA" unfolding *
hoelzl@47694
   297
    by (safe intro!: countable_UN) auto
hoelzl@47694
   298
qed auto
hoelzl@38656
   299
hoelzl@47694
   300
lemma borel_eq_halfspace_ge:
hoelzl@47694
   301
  "borel = sigma UNIV (range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. a \<le> x $$ i}))"
hoelzl@47694
   302
  (is "_ = ?SIGMA")
hoelzl@47694
   303
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_less])
hoelzl@47694
   304
  fix a i have *: "{x::'a. x$$i < a} = space ?SIGMA - {x::'a. a \<le> x$$i}" by auto
hoelzl@47694
   305
  show "{x. x$$i < a} \<in> ?SIGMA" unfolding *
hoelzl@47694
   306
      by (safe intro!: compl_sets) auto
hoelzl@47694
   307
qed auto
hoelzl@38656
   308
hoelzl@47694
   309
lemma borel_eq_halfspace_greater:
hoelzl@47694
   310
  "borel = sigma UNIV (range (\<lambda> (a, i). {x\<Colon>'a\<Colon>ordered_euclidean_space. a < x $$ i}))"
hoelzl@47694
   311
  (is "_ = ?SIGMA")
hoelzl@47694
   312
proof (rule borel_eq_sigmaI2[OF borel_eq_halfspace_le])
hoelzl@47694
   313
  fix a i have *: "{x::'a. x$$i \<le> a} = space ?SIGMA - {x::'a. a < x$$i}" by auto
hoelzl@47694
   314
  show "{x. x$$i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@47694
   315
    by (safe intro!: compl_sets) auto
hoelzl@47694
   316
qed auto
hoelzl@47694
   317
hoelzl@47694
   318
lemma borel_eq_atMost:
hoelzl@47694
   319
  "borel = sigma UNIV (range (\<lambda>a. {..a\<Colon>'a\<Colon>ordered_euclidean_space}))"
hoelzl@47694
   320
  (is "_ = ?SIGMA")
hoelzl@47694
   321
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@47694
   322
  fix a i show "{x. x$$i \<le> a} \<in> ?SIGMA"
hoelzl@38656
   323
  proof cases
hoelzl@47694
   324
    assume "i < DIM('a)"
hoelzl@38656
   325
    then have *: "{x::'a. x$$i \<le> a} = (\<Union>k::nat. {.. (\<chi>\<chi> n. if n = i then a else real k)})"
hoelzl@38656
   326
    proof (safe, simp_all add: eucl_le[where 'a='a] split: split_if_asm)
hoelzl@38656
   327
      fix x
hoelzl@38656
   328
      from real_arch_simple[of "Max ((\<lambda>i. x$$i)`{..<DIM('a)})"] guess k::nat ..
hoelzl@38656
   329
      then have "\<And>i. i < DIM('a) \<Longrightarrow> x$$i \<le> real k"
hoelzl@38656
   330
        by (subst (asm) Max_le_iff) auto
hoelzl@38656
   331
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> x $$ ia \<le> real k"
hoelzl@38656
   332
        by (auto intro!: exI[of _ k])
hoelzl@38656
   333
    qed
hoelzl@47694
   334
    show "{x. x$$i \<le> a} \<in> ?SIGMA" unfolding *
hoelzl@47694
   335
      by (safe intro!: countable_UN) auto
hoelzl@47694
   336
  qed (auto intro: sigma_sets_top sigma_sets.Empty)
hoelzl@47694
   337
qed auto
hoelzl@38656
   338
hoelzl@47694
   339
lemma borel_eq_greaterThan:
hoelzl@47694
   340
  "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {a<..}))"
hoelzl@47694
   341
  (is "_ = ?SIGMA")
hoelzl@47694
   342
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_le])
hoelzl@47694
   343
  fix a i show "{x. x$$i \<le> a} \<in> ?SIGMA"
hoelzl@38656
   344
  proof cases
hoelzl@47694
   345
    assume "i < DIM('a)"
hoelzl@47694
   346
    have "{x::'a. x$$i \<le> a} = UNIV - {x::'a. a < x$$i}" by auto
hoelzl@38656
   347
    also have *: "{x::'a. a < x$$i} = (\<Union>k::nat. {(\<chi>\<chi> n. if n = i then a else -real k) <..})" using `i <DIM('a)`
hoelzl@38656
   348
    proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@38656
   349
      fix x
huffman@44666
   350
      from reals_Archimedean2[of "Max ((\<lambda>i. -x$$i)`{..<DIM('a)})"]
hoelzl@38656
   351
      guess k::nat .. note k = this
hoelzl@38656
   352
      { fix i assume "i < DIM('a)"
hoelzl@38656
   353
        then have "-x$$i < real k"
hoelzl@38656
   354
          using k by (subst (asm) Max_less_iff) auto
hoelzl@38656
   355
        then have "- real k < x$$i" by simp }
hoelzl@38656
   356
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> -real k < x $$ ia"
hoelzl@38656
   357
        by (auto intro!: exI[of _ k])
hoelzl@38656
   358
    qed
hoelzl@47694
   359
    finally show "{x. x$$i \<le> a} \<in> ?SIGMA"
hoelzl@38656
   360
      apply (simp only:)
hoelzl@38656
   361
      apply (safe intro!: countable_UN Diff)
hoelzl@47694
   362
      apply (auto intro: sigma_sets_top)
wenzelm@46731
   363
      done
hoelzl@47694
   364
  qed (auto intro: sigma_sets_top sigma_sets.Empty)
hoelzl@47694
   365
qed auto
hoelzl@40859
   366
hoelzl@47694
   367
lemma borel_eq_lessThan:
hoelzl@47694
   368
  "borel = sigma UNIV (range (\<lambda>a\<Colon>'a\<Colon>ordered_euclidean_space. {..<a}))"
hoelzl@47694
   369
  (is "_ = ?SIGMA")
hoelzl@47694
   370
proof (rule borel_eq_sigmaI4[OF borel_eq_halfspace_ge])
hoelzl@47694
   371
  fix a i show "{x. a \<le> x$$i} \<in> ?SIGMA"
hoelzl@40859
   372
  proof cases
hoelzl@40859
   373
    fix a i assume "i < DIM('a)"
hoelzl@47694
   374
    have "{x::'a. a \<le> x$$i} = UNIV - {x::'a. x$$i < a}" by auto
hoelzl@40859
   375
    also have *: "{x::'a. x$$i < a} = (\<Union>k::nat. {..< (\<chi>\<chi> n. if n = i then a else real k)})" using `i <DIM('a)`
hoelzl@40859
   376
    proof (safe, simp_all add: eucl_less[where 'a='a] split: split_if_asm)
hoelzl@40859
   377
      fix x
huffman@44666
   378
      from reals_Archimedean2[of "Max ((\<lambda>i. x$$i)`{..<DIM('a)})"]
hoelzl@40859
   379
      guess k::nat .. note k = this
hoelzl@40859
   380
      { fix i assume "i < DIM('a)"
hoelzl@40859
   381
        then have "x$$i < real k"
hoelzl@40859
   382
          using k by (subst (asm) Max_less_iff) auto
hoelzl@40859
   383
        then have "x$$i < real k" by simp }
hoelzl@40859
   384
      then show "\<exists>k::nat. \<forall>ia. ia \<noteq> i \<longrightarrow> ia < DIM('a) \<longrightarrow> x $$ ia < real k"
hoelzl@40859
   385
        by (auto intro!: exI[of _ k])
hoelzl@40859
   386
    qed
hoelzl@47694
   387
    finally show "{x. a \<le> x$$i} \<in> ?SIGMA"
hoelzl@40859
   388
      apply (simp only:)
hoelzl@40859
   389
      apply (safe intro!: countable_UN Diff)
hoelzl@47694
   390
      apply (auto intro: sigma_sets_top)
wenzelm@46731
   391
      done
hoelzl@47694
   392
  qed (auto intro: sigma_sets_top sigma_sets.Empty)
hoelzl@40859
   393
qed auto
hoelzl@40859
   394
hoelzl@40859
   395
lemma borel_eq_atLeastAtMost:
hoelzl@47694
   396
  "borel = sigma UNIV (range (\<lambda>(a,b). {a..b} \<Colon>'a\<Colon>ordered_euclidean_space set))"
hoelzl@47694
   397
  (is "_ = ?SIGMA")
hoelzl@47694
   398
proof (rule borel_eq_sigmaI5[OF borel_eq_atMost])
hoelzl@47694
   399
  fix a::'a
hoelzl@47694
   400
  have *: "{..a} = (\<Union>n::nat. {- real n *\<^sub>R One .. a})"
hoelzl@47694
   401
  proof (safe, simp_all add: eucl_le[where 'a='a])
hoelzl@47694
   402
    fix x
hoelzl@47694
   403
    from real_arch_simple[of "Max ((\<lambda>i. - x$$i)`{..<DIM('a)})"]
hoelzl@47694
   404
    guess k::nat .. note k = this
hoelzl@47694
   405
    { fix i assume "i < DIM('a)"
hoelzl@47694
   406
      with k have "- x$$i \<le> real k"
hoelzl@47694
   407
        by (subst (asm) Max_le_iff) (auto simp: field_simps)
hoelzl@47694
   408
      then have "- real k \<le> x$$i" by simp }
hoelzl@47694
   409
    then show "\<exists>n::nat. \<forall>i<DIM('a). - real n \<le> x $$ i"
hoelzl@47694
   410
      by (auto intro!: exI[of _ k])
hoelzl@47694
   411
  qed
hoelzl@47694
   412
  show "{..a} \<in> ?SIGMA" unfolding *
hoelzl@47694
   413
    by (safe intro!: countable_UN)
hoelzl@47694
   414
       (auto intro!: sigma_sets_top)
hoelzl@40859
   415
qed auto
hoelzl@40859
   416
hoelzl@40859
   417
lemma borel_eq_greaterThanLessThan:
hoelzl@47694
   418
  "borel = sigma UNIV (range (\<lambda> (a, b). {a <..< b} :: 'a \<Colon> ordered_euclidean_space set))"
hoelzl@40859
   419
    (is "_ = ?SIGMA")
hoelzl@47694
   420
proof (rule borel_eq_sigmaI1[OF borel_def])
hoelzl@47694
   421
  fix M :: "'a set" assume "M \<in> {S. open S}"
hoelzl@47694
   422
  then have "open M" by simp
hoelzl@47694
   423
  show "M \<in> ?SIGMA"
hoelzl@47694
   424
    apply (subst open_UNION[OF `open M`])
hoelzl@47694
   425
    apply (safe intro!: countable_UN)
hoelzl@47694
   426
    apply auto
hoelzl@47694
   427
    done
hoelzl@38656
   428
qed auto
hoelzl@38656
   429
hoelzl@42862
   430
lemma borel_eq_atLeastLessThan:
hoelzl@47694
   431
  "borel = sigma UNIV (range (\<lambda>(a, b). {a ..< b :: real}))" (is "_ = ?SIGMA")
hoelzl@47694
   432
proof (rule borel_eq_sigmaI5[OF borel_eq_lessThan])
hoelzl@47694
   433
  have move_uminus: "\<And>x y::real. -x \<le> y \<longleftrightarrow> -y \<le> x" by auto
hoelzl@47694
   434
  fix x :: real
hoelzl@47694
   435
  have "{..<x} = (\<Union>i::nat. {-real i ..< x})"
hoelzl@47694
   436
    by (auto simp: move_uminus real_arch_simple)
hoelzl@47694
   437
  then show "{..< x} \<in> ?SIGMA"
hoelzl@47694
   438
    by (auto intro: sigma_sets.intros)
hoelzl@40859
   439
qed auto
hoelzl@40859
   440
immler@50087
   441
lemma borel_eq_closed: "borel = sigma UNIV (Collect closed)"
immler@50087
   442
  unfolding borel_def
immler@50087
   443
proof (intro sigma_eqI sigma_sets_eqI, safe)
immler@50087
   444
  fix x :: "'a set" assume "open x"
immler@50087
   445
  hence "x = UNIV - (UNIV - x)" by auto
immler@50087
   446
  also have "\<dots> \<in> sigma_sets UNIV (Collect closed)"
immler@50087
   447
    by (rule sigma_sets.Compl)
immler@50087
   448
       (auto intro!: sigma_sets.Basic simp: `open x`)
immler@50087
   449
  finally show "x \<in> sigma_sets UNIV (Collect closed)" by simp
immler@50087
   450
next
immler@50087
   451
  fix x :: "'a set" assume "closed x"
immler@50087
   452
  hence "x = UNIV - (UNIV - x)" by auto
immler@50087
   453
  also have "\<dots> \<in> sigma_sets UNIV (Collect open)"
immler@50087
   454
    by (rule sigma_sets.Compl)
immler@50087
   455
       (auto intro!: sigma_sets.Basic simp: `closed x`)
immler@50087
   456
  finally show "x \<in> sigma_sets UNIV (Collect open)" by simp
immler@50087
   457
qed simp_all
immler@50087
   458
immler@50087
   459
lemma borel_eq_enum_basis:
immler@50087
   460
  "borel = sigma UNIV (range enum_basis)"
immler@50087
   461
  unfolding borel_def
immler@50087
   462
proof (intro sigma_eqI sigma_sets_eqI, safe)
immler@50087
   463
  fix x::"'a set" assume "open x"
immler@50087
   464
  from open_enumerable_basisE[OF this] guess N .
immler@50087
   465
  hence x: "x = (\<Union>n. if n \<in> N then enum_basis n else {})" by (auto split: split_if_asm)
immler@50087
   466
  also have "\<dots> \<in> sigma_sets UNIV (range enum_basis)" by (rule Union) auto
immler@50087
   467
  finally show "x \<in> sigma_sets UNIV (range enum_basis)" .
immler@50087
   468
next
immler@50087
   469
  fix n
immler@50087
   470
  have "open (enum_basis n)" by (rule open_enum_basis) simp
immler@50087
   471
  thus "enum_basis n \<in> sigma_sets UNIV (Collect open)" by auto
immler@50087
   472
qed simp_all
immler@50087
   473
hoelzl@47694
   474
lemma borel_measurable_halfspacesI:
hoelzl@38656
   475
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@47694
   476
  assumes F: "borel = sigma UNIV (range F)"
hoelzl@47694
   477
  and S_eq: "\<And>a i. S a i = f -` F (a,i) \<inter> space M" 
hoelzl@47694
   478
  and S: "\<And>a i. \<not> i < DIM('c) \<Longrightarrow> S a i \<in> sets M"
hoelzl@38656
   479
  shows "f \<in> borel_measurable M = (\<forall>i<DIM('c). \<forall>a::real. S a i \<in> sets M)"
hoelzl@38656
   480
proof safe
hoelzl@38656
   481
  fix a :: real and i assume i: "i < DIM('c)" and f: "f \<in> borel_measurable M"
hoelzl@38656
   482
  then show "S a i \<in> sets M" unfolding assms
hoelzl@47694
   483
    by (auto intro!: measurable_sets sigma_sets.Basic simp: assms(1))
hoelzl@38656
   484
next
hoelzl@38656
   485
  assume a: "\<forall>i<DIM('c). \<forall>a. S a i \<in> sets M"
hoelzl@38656
   486
  { fix a i have "S a i \<in> sets M"
hoelzl@38656
   487
    proof cases
hoelzl@38656
   488
      assume "i < DIM('c)"
hoelzl@38656
   489
      with a show ?thesis unfolding assms(2) by simp
hoelzl@38656
   490
    next
hoelzl@38656
   491
      assume "\<not> i < DIM('c)"
hoelzl@47694
   492
      from S[OF this] show ?thesis .
hoelzl@38656
   493
    qed }
hoelzl@47694
   494
  then show "f \<in> borel_measurable M"
hoelzl@47694
   495
    by (auto intro!: measurable_measure_of simp: S_eq F)
hoelzl@38656
   496
qed
hoelzl@38656
   497
hoelzl@47694
   498
lemma borel_measurable_iff_halfspace_le:
hoelzl@38656
   499
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   500
  shows "f \<in> borel_measurable M = (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. f w $$ i \<le> a} \<in> sets M)"
hoelzl@40859
   501
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_le]) auto
hoelzl@38656
   502
hoelzl@47694
   503
lemma borel_measurable_iff_halfspace_less:
hoelzl@38656
   504
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   505
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. f w $$ i < a} \<in> sets M)"
hoelzl@40859
   506
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_less]) auto
hoelzl@38656
   507
hoelzl@47694
   508
lemma borel_measurable_iff_halfspace_ge:
hoelzl@38656
   509
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   510
  shows "f \<in> borel_measurable M = (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. a \<le> f w $$ i} \<in> sets M)"
hoelzl@40859
   511
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_ge]) auto
hoelzl@38656
   512
hoelzl@47694
   513
lemma borel_measurable_iff_halfspace_greater:
hoelzl@38656
   514
  fixes f :: "'a \<Rightarrow> 'c\<Colon>ordered_euclidean_space"
hoelzl@38656
   515
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i<DIM('c). \<forall>a. {w \<in> space M. a < f w $$ i} \<in> sets M)"
hoelzl@47694
   516
  by (rule borel_measurable_halfspacesI[OF borel_eq_halfspace_greater]) auto
hoelzl@38656
   517
hoelzl@47694
   518
lemma borel_measurable_iff_le:
hoelzl@38656
   519
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w \<le> a} \<in> sets M)"
hoelzl@38656
   520
  using borel_measurable_iff_halfspace_le[where 'c=real] by simp
hoelzl@38656
   521
hoelzl@47694
   522
lemma borel_measurable_iff_less:
hoelzl@38656
   523
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. f w < a} \<in> sets M)"
hoelzl@38656
   524
  using borel_measurable_iff_halfspace_less[where 'c=real] by simp
hoelzl@38656
   525
hoelzl@47694
   526
lemma borel_measurable_iff_ge:
hoelzl@38656
   527
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a \<le> f w} \<in> sets M)"
hoelzl@50002
   528
  using borel_measurable_iff_halfspace_ge[where 'c=real]
hoelzl@50002
   529
  by simp
hoelzl@38656
   530
hoelzl@47694
   531
lemma borel_measurable_iff_greater:
hoelzl@38656
   532
  "(f::'a \<Rightarrow> real) \<in> borel_measurable M = (\<forall>a. {w \<in> space M. a < f w} \<in> sets M)"
hoelzl@38656
   533
  using borel_measurable_iff_halfspace_greater[where 'c=real] by simp
hoelzl@38656
   534
hoelzl@47694
   535
lemma borel_measurable_euclidean_space:
hoelzl@39087
   536
  fixes f :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@39087
   537
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>i<DIM('c). (\<lambda>x. f x $$ i) \<in> borel_measurable M)"
hoelzl@39087
   538
proof safe
hoelzl@39087
   539
  fix i assume "f \<in> borel_measurable M"
hoelzl@39087
   540
  then show "(\<lambda>x. f x $$ i) \<in> borel_measurable M"
hoelzl@41025
   541
    by (auto intro: borel_measurable_euclidean_component)
hoelzl@39087
   542
next
hoelzl@39087
   543
  assume f: "\<forall>i<DIM('c). (\<lambda>x. f x $$ i) \<in> borel_measurable M"
hoelzl@39087
   544
  then show "f \<in> borel_measurable M"
hoelzl@39087
   545
    unfolding borel_measurable_iff_halfspace_le by auto
hoelzl@39087
   546
qed
hoelzl@39087
   547
hoelzl@38656
   548
subsection "Borel measurable operators"
hoelzl@38656
   549
hoelzl@49774
   550
lemma borel_measurable_continuous_on:
hoelzl@49774
   551
  fixes f :: "'a::topological_space \<Rightarrow> 'b::topological_space"
hoelzl@49774
   552
  assumes f: "continuous_on UNIV f" and g: "g \<in> borel_measurable M"
hoelzl@49774
   553
  shows "(\<lambda>x. f (g x)) \<in> borel_measurable M"
hoelzl@49774
   554
  using measurable_comp[OF g borel_measurable_continuous_on1[OF f]] by (simp add: comp_def)
hoelzl@49774
   555
hoelzl@49774
   556
lemma borel_measurable_continuous_on_open':
hoelzl@49774
   557
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@49774
   558
  assumes cont: "continuous_on A f" "open A"
hoelzl@49774
   559
  shows "(\<lambda>x. if x \<in> A then f x else c) \<in> borel_measurable borel" (is "?f \<in> _")
hoelzl@49774
   560
proof (rule borel_measurableI)
hoelzl@49774
   561
  fix S :: "'b set" assume "open S"
hoelzl@49774
   562
  then have "open {x\<in>A. f x \<in> S}"
hoelzl@49774
   563
    by (intro continuous_open_preimage[OF cont]) auto
hoelzl@49774
   564
  then have *: "{x\<in>A. f x \<in> S} \<in> sets borel" by auto
hoelzl@49774
   565
  have "?f -` S \<inter> space borel = 
hoelzl@49774
   566
    {x\<in>A. f x \<in> S} \<union> (if c \<in> S then space borel - A else {})"
hoelzl@49774
   567
    by (auto split: split_if_asm)
hoelzl@49774
   568
  also have "\<dots> \<in> sets borel"
hoelzl@50002
   569
    using * `open A` by auto
hoelzl@49774
   570
  finally show "?f -` S \<inter> space borel \<in> sets borel" .
hoelzl@49774
   571
qed
hoelzl@49774
   572
hoelzl@49774
   573
lemma borel_measurable_continuous_on_open:
hoelzl@49774
   574
  fixes f :: "'a::topological_space \<Rightarrow> 'b::t1_space"
hoelzl@49774
   575
  assumes cont: "continuous_on A f" "open A"
hoelzl@49774
   576
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   577
  shows "(\<lambda>x. if g x \<in> A then f (g x) else c) \<in> borel_measurable M"
hoelzl@49774
   578
  using measurable_comp[OF g borel_measurable_continuous_on_open'[OF cont], of c]
hoelzl@49774
   579
  by (simp add: comp_def)
hoelzl@49774
   580
hoelzl@50003
   581
lemma borel_measurable_uminus[measurable (raw)]:
hoelzl@49774
   582
  fixes g :: "'a \<Rightarrow> real"
hoelzl@49774
   583
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   584
  shows "(\<lambda>x. - g x) \<in> borel_measurable M"
hoelzl@49774
   585
  by (rule borel_measurable_continuous_on[OF _ g]) (auto intro: continuous_on_minus continuous_on_id)
hoelzl@49774
   586
hoelzl@49774
   587
lemma euclidean_component_prod:
hoelzl@49774
   588
  fixes x :: "'a :: euclidean_space \<times> 'b :: euclidean_space"
hoelzl@49774
   589
  shows "x $$ i = (if i < DIM('a) then fst x $$ i else snd x $$ (i - DIM('a)))"
hoelzl@49774
   590
  unfolding euclidean_component_def basis_prod_def inner_prod_def by auto
hoelzl@49774
   591
hoelzl@50003
   592
lemma borel_measurable_Pair[measurable (raw)]:
hoelzl@49774
   593
  fixes f :: "'a \<Rightarrow> 'b::ordered_euclidean_space" and g :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@49774
   594
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   595
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   596
  shows "(\<lambda>x. (f x, g x)) \<in> borel_measurable M"
hoelzl@49774
   597
proof (intro borel_measurable_iff_halfspace_le[THEN iffD2] allI impI)
hoelzl@49774
   598
  fix i and a :: real assume i: "i < DIM('b \<times> 'c)"
hoelzl@49774
   599
  have [simp]: "\<And>P A B C. {w. (P \<longrightarrow> A w \<and> B w) \<and> (\<not> P \<longrightarrow> A w \<and> C w)} = 
hoelzl@49774
   600
    {w. A w \<and> (P \<longrightarrow> B w) \<and> (\<not> P \<longrightarrow> C w)}" by auto
hoelzl@49774
   601
  from i f g show "{w \<in> space M. (f w, g w) $$ i \<le> a} \<in> sets M"
hoelzl@50002
   602
    by (auto simp: euclidean_component_prod)
hoelzl@49774
   603
qed
hoelzl@49774
   604
hoelzl@49774
   605
lemma continuous_on_fst: "continuous_on UNIV fst"
hoelzl@49774
   606
proof -
hoelzl@49774
   607
  have [simp]: "range fst = UNIV" by (auto simp: image_iff)
hoelzl@49774
   608
  show ?thesis
hoelzl@49774
   609
    using closed_vimage_fst
hoelzl@49774
   610
    by (auto simp: continuous_on_closed closed_closedin vimage_def)
hoelzl@49774
   611
qed
hoelzl@49774
   612
hoelzl@49774
   613
lemma continuous_on_snd: "continuous_on UNIV snd"
hoelzl@49774
   614
proof -
hoelzl@49774
   615
  have [simp]: "range snd = UNIV" by (auto simp: image_iff)
hoelzl@49774
   616
  show ?thesis
hoelzl@49774
   617
    using closed_vimage_snd
hoelzl@49774
   618
    by (auto simp: continuous_on_closed closed_closedin vimage_def)
hoelzl@49774
   619
qed
hoelzl@49774
   620
hoelzl@49774
   621
lemma borel_measurable_continuous_Pair:
hoelzl@49774
   622
  fixes f :: "'a \<Rightarrow> 'b::ordered_euclidean_space" and g :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@50003
   623
  assumes [measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   624
  assumes [measurable]: "g \<in> borel_measurable M"
hoelzl@49774
   625
  assumes H: "continuous_on UNIV (\<lambda>x. H (fst x) (snd x))"
hoelzl@49774
   626
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   627
proof -
hoelzl@49774
   628
  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
   629
  show ?thesis
hoelzl@49774
   630
    unfolding eq by (rule borel_measurable_continuous_on[OF H]) auto
hoelzl@49774
   631
qed
hoelzl@49774
   632
hoelzl@50003
   633
lemma borel_measurable_add[measurable (raw)]:
hoelzl@49774
   634
  fixes f g :: "'a \<Rightarrow> 'c::ordered_euclidean_space"
hoelzl@49774
   635
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   636
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   637
  shows "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@49774
   638
  using f g
hoelzl@49774
   639
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   640
     (auto intro: continuous_on_fst continuous_on_snd continuous_on_add)
hoelzl@49774
   641
hoelzl@50003
   642
lemma borel_measurable_setsum[measurable (raw)]:
hoelzl@49774
   643
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@49774
   644
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@49774
   645
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@49774
   646
proof cases
hoelzl@49774
   647
  assume "finite S"
hoelzl@49774
   648
  thus ?thesis using assms by induct auto
hoelzl@49774
   649
qed simp
hoelzl@49774
   650
hoelzl@50003
   651
lemma borel_measurable_diff[measurable (raw)]:
hoelzl@49774
   652
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   653
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   654
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   655
  shows "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50003
   656
  unfolding diff_minus using assms by simp
hoelzl@49774
   657
hoelzl@50003
   658
lemma borel_measurable_times[measurable (raw)]:
hoelzl@49774
   659
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   660
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   661
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   662
  shows "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@49774
   663
  using f g
hoelzl@49774
   664
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   665
     (auto intro: continuous_on_fst continuous_on_snd continuous_on_mult)
hoelzl@49774
   666
hoelzl@49774
   667
lemma continuous_on_dist:
hoelzl@49774
   668
  fixes f :: "'a :: t2_space \<Rightarrow> 'b :: metric_space"
hoelzl@49774
   669
  shows "continuous_on A f \<Longrightarrow> continuous_on A g \<Longrightarrow> continuous_on A (\<lambda>x. dist (f x) (g x))"
hoelzl@49774
   670
  unfolding continuous_on_eq_continuous_within by (auto simp: continuous_dist)
hoelzl@49774
   671
hoelzl@50003
   672
lemma borel_measurable_dist[measurable (raw)]:
hoelzl@49774
   673
  fixes g f :: "'a \<Rightarrow> 'b::ordered_euclidean_space"
hoelzl@49774
   674
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   675
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   676
  shows "(\<lambda>x. dist (f x) (g x)) \<in> borel_measurable M"
hoelzl@49774
   677
  using f g
hoelzl@49774
   678
  by (rule borel_measurable_continuous_Pair)
hoelzl@49774
   679
     (intro continuous_on_dist continuous_on_fst continuous_on_snd)
hoelzl@49774
   680
  
hoelzl@50002
   681
lemma borel_measurable_scaleR[measurable (raw)]:
hoelzl@50002
   682
  fixes g :: "'a \<Rightarrow> 'b::ordered_euclidean_space"
hoelzl@50002
   683
  assumes f: "f \<in> borel_measurable M"
hoelzl@50002
   684
  assumes g: "g \<in> borel_measurable M"
hoelzl@50002
   685
  shows "(\<lambda>x. f x *\<^sub>R g x) \<in> borel_measurable M"
hoelzl@50002
   686
  by (rule borel_measurable_continuous_Pair[OF f g])
hoelzl@50002
   687
     (auto intro!: continuous_on_scaleR continuous_on_fst continuous_on_snd)
hoelzl@50002
   688
hoelzl@47694
   689
lemma affine_borel_measurable_vector:
hoelzl@38656
   690
  fixes f :: "'a \<Rightarrow> 'x::real_normed_vector"
hoelzl@38656
   691
  assumes "f \<in> borel_measurable M"
hoelzl@38656
   692
  shows "(\<lambda>x. a + b *\<^sub>R f x) \<in> borel_measurable M"
hoelzl@38656
   693
proof (rule borel_measurableI)
hoelzl@38656
   694
  fix S :: "'x set" assume "open S"
hoelzl@38656
   695
  show "(\<lambda>x. a + b *\<^sub>R f x) -` S \<inter> space M \<in> sets M"
hoelzl@38656
   696
  proof cases
hoelzl@38656
   697
    assume "b \<noteq> 0"
huffman@44537
   698
    with `open S` have "open ((\<lambda>x. (- a + x) /\<^sub>R b) ` S)" (is "open ?S")
huffman@44537
   699
      by (auto intro!: open_affinity simp: scaleR_add_right)
hoelzl@47694
   700
    hence "?S \<in> sets borel" by auto
hoelzl@38656
   701
    moreover
hoelzl@38656
   702
    from `b \<noteq> 0` have "(\<lambda>x. a + b *\<^sub>R f x) -` S = f -` ?S"
hoelzl@38656
   703
      apply auto by (rule_tac x="a + b *\<^sub>R f x" in image_eqI, simp_all)
hoelzl@40859
   704
    ultimately show ?thesis using assms unfolding in_borel_measurable_borel
hoelzl@38656
   705
      by auto
hoelzl@38656
   706
  qed simp
hoelzl@38656
   707
qed
hoelzl@38656
   708
hoelzl@50002
   709
lemma borel_measurable_const_scaleR[measurable (raw)]:
hoelzl@50002
   710
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. b *\<^sub>R f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
   711
  using affine_borel_measurable_vector[of f M 0 b] by simp
hoelzl@38656
   712
hoelzl@50002
   713
lemma borel_measurable_const_add[measurable (raw)]:
hoelzl@50002
   714
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. a + f x ::'a::real_normed_vector) \<in> borel_measurable M"
hoelzl@50002
   715
  using affine_borel_measurable_vector[of f M a 1] by simp
hoelzl@50002
   716
hoelzl@50003
   717
lemma borel_measurable_setprod[measurable (raw)]:
hoelzl@41026
   718
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41026
   719
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41026
   720
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41026
   721
proof cases
hoelzl@41026
   722
  assume "finite S"
hoelzl@41026
   723
  thus ?thesis using assms by induct auto
hoelzl@41026
   724
qed simp
hoelzl@41026
   725
hoelzl@50003
   726
lemma borel_measurable_inverse[measurable (raw)]:
hoelzl@38656
   727
  fixes f :: "'a \<Rightarrow> real"
hoelzl@49774
   728
  assumes f: "f \<in> borel_measurable M"
hoelzl@35692
   729
  shows "(\<lambda>x. inverse (f x)) \<in> borel_measurable M"
hoelzl@49774
   730
proof -
hoelzl@50003
   731
  have "(\<lambda>x::real. if x \<in> UNIV - {0} then inverse x else 0) \<in> borel_measurable borel"
hoelzl@50003
   732
    by (intro borel_measurable_continuous_on_open' continuous_on_inverse continuous_on_id) auto
hoelzl@50003
   733
  also have "(\<lambda>x::real. if x \<in> UNIV - {0} then inverse x else 0) = inverse" by (intro ext) auto
hoelzl@50003
   734
  finally show ?thesis using f by simp
hoelzl@35692
   735
qed
hoelzl@35692
   736
hoelzl@50003
   737
lemma borel_measurable_divide[measurable (raw)]:
hoelzl@50003
   738
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. f x / g x::real) \<in> borel_measurable M"
hoelzl@50003
   739
  by (simp add: field_divide_inverse)
hoelzl@38656
   740
hoelzl@50003
   741
lemma borel_measurable_max[measurable (raw)]:
hoelzl@50003
   742
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. max (g x) (f x) :: real) \<in> borel_measurable M"
hoelzl@50003
   743
  by (simp add: max_def)
hoelzl@38656
   744
hoelzl@50003
   745
lemma borel_measurable_min[measurable (raw)]:
hoelzl@50003
   746
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. min (g x) (f x) :: real) \<in> borel_measurable M"
hoelzl@50003
   747
  by (simp add: min_def)
hoelzl@38656
   748
hoelzl@50003
   749
lemma borel_measurable_abs[measurable (raw)]:
hoelzl@50003
   750
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. \<bar>f x :: real\<bar>) \<in> borel_measurable M"
hoelzl@50003
   751
  unfolding abs_real_def by simp
hoelzl@38656
   752
hoelzl@50003
   753
lemma borel_measurable_nth[measurable (raw)]:
hoelzl@41026
   754
  "(\<lambda>x::real^'n. x $ i) \<in> borel_measurable borel"
hoelzl@50003
   755
  by (simp add: nth_conv_component)
hoelzl@41026
   756
hoelzl@47694
   757
lemma convex_measurable:
hoelzl@42990
   758
  fixes a b :: real
hoelzl@42990
   759
  assumes X: "X \<in> borel_measurable M" "X ` space M \<subseteq> { a <..< b}"
hoelzl@42990
   760
  assumes q: "convex_on { a <..< b} q"
hoelzl@49774
   761
  shows "(\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@42990
   762
proof -
hoelzl@49774
   763
  have "(\<lambda>x. if X x \<in> {a <..< b} then q (X x) else 0) \<in> borel_measurable M" (is "?qX")
hoelzl@49774
   764
  proof (rule borel_measurable_continuous_on_open[OF _ _ X(1)])
hoelzl@42990
   765
    show "open {a<..<b}" by auto
hoelzl@42990
   766
    from this q show "continuous_on {a<..<b} q"
hoelzl@42990
   767
      by (rule convex_on_continuous)
hoelzl@41830
   768
  qed
hoelzl@50002
   769
  also have "?qX \<longleftrightarrow> (\<lambda>x. q (X x)) \<in> borel_measurable M"
hoelzl@42990
   770
    using X by (intro measurable_cong) auto
hoelzl@50002
   771
  finally show ?thesis .
hoelzl@41830
   772
qed
hoelzl@41830
   773
hoelzl@50003
   774
lemma borel_measurable_ln[measurable (raw)]:
hoelzl@49774
   775
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   776
  shows "(\<lambda>x. ln (f x)) \<in> borel_measurable M"
hoelzl@41830
   777
proof -
hoelzl@41830
   778
  { fix x :: real assume x: "x \<le> 0"
hoelzl@41830
   779
    { fix x::real assume "x \<le> 0" then have "\<And>u. exp u = x \<longleftrightarrow> False" by auto }
hoelzl@49774
   780
    from this[of x] x this[of 0] have "ln 0 = ln x"
hoelzl@49774
   781
      by (auto simp: ln_def) }
hoelzl@49774
   782
  note ln_imp = this
hoelzl@49774
   783
  have "(\<lambda>x. if f x \<in> {0<..} then ln (f x) else ln 0) \<in> borel_measurable M"
hoelzl@49774
   784
  proof (rule borel_measurable_continuous_on_open[OF _ _ f])
hoelzl@49774
   785
    show "continuous_on {0<..} ln"
hoelzl@49774
   786
      by (auto intro!: continuous_at_imp_continuous_on DERIV_ln DERIV_isCont
hoelzl@41830
   787
               simp: continuous_isCont[symmetric])
hoelzl@41830
   788
    show "open ({0<..}::real set)" by auto
hoelzl@41830
   789
  qed
hoelzl@49774
   790
  also have "(\<lambda>x. if x \<in> {0<..} then ln x else ln 0) = ln"
hoelzl@49774
   791
    by (simp add: fun_eq_iff not_less ln_imp)
hoelzl@41830
   792
  finally show ?thesis .
hoelzl@41830
   793
qed
hoelzl@41830
   794
hoelzl@50003
   795
lemma borel_measurable_log[measurable (raw)]:
hoelzl@50002
   796
  "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
   797
  unfolding log_def by auto
hoelzl@41830
   798
hoelzl@50002
   799
lemma measurable_count_space_eq2_countable:
hoelzl@50002
   800
  fixes f :: "'a => 'c::countable"
hoelzl@50002
   801
  shows "f \<in> measurable M (count_space A) \<longleftrightarrow> (f \<in> space M \<rightarrow> A \<and> (\<forall>a\<in>A. f -` {a} \<inter> space M \<in> sets M))"
hoelzl@50002
   802
proof -
hoelzl@50002
   803
  { fix X assume "X \<subseteq> A" "f \<in> space M \<rightarrow> A"
hoelzl@50002
   804
    then have "f -` X \<inter> space M = (\<Union>a\<in>X. f -` {a} \<inter> space M)"
hoelzl@50002
   805
      by auto
hoelzl@50002
   806
    moreover assume "\<And>a. a\<in>A \<Longrightarrow> f -` {a} \<inter> space M \<in> sets M"
hoelzl@50002
   807
    ultimately have "f -` X \<inter> space M \<in> sets M"
hoelzl@50002
   808
      using `X \<subseteq> A` by (simp add: subset_eq del: UN_simps) }
hoelzl@50002
   809
  then show ?thesis
hoelzl@50002
   810
    unfolding measurable_def by auto
hoelzl@47761
   811
qed
hoelzl@47761
   812
hoelzl@50002
   813
lemma measurable_real_floor[measurable]:
hoelzl@50002
   814
  "(floor :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@47761
   815
proof -
hoelzl@50002
   816
  have "\<And>a x. \<lfloor>x\<rfloor> = a \<longleftrightarrow> (real a \<le> x \<and> x < real (a + 1))"
hoelzl@50002
   817
    by (auto intro: floor_eq2)
hoelzl@50002
   818
  then show ?thesis
hoelzl@50002
   819
    by (auto simp: vimage_def measurable_count_space_eq2_countable)
hoelzl@47761
   820
qed
hoelzl@47761
   821
hoelzl@50002
   822
lemma measurable_real_natfloor[measurable]:
hoelzl@50002
   823
  "(natfloor :: real \<Rightarrow> nat) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
   824
  by (simp add: natfloor_def[abs_def])
hoelzl@50002
   825
hoelzl@50002
   826
lemma measurable_real_ceiling[measurable]:
hoelzl@50002
   827
  "(ceiling :: real \<Rightarrow> int) \<in> measurable borel (count_space UNIV)"
hoelzl@50002
   828
  unfolding ceiling_def[abs_def] by simp
hoelzl@50002
   829
hoelzl@50002
   830
lemma borel_measurable_real_floor: "(\<lambda>x::real. real \<lfloor>x\<rfloor>) \<in> borel_measurable borel"
hoelzl@50002
   831
  by simp
hoelzl@50002
   832
hoelzl@50003
   833
lemma borel_measurable_real_natfloor:
hoelzl@50002
   834
  "f \<in> borel_measurable M \<Longrightarrow> (\<lambda>x. real (natfloor (f x))) \<in> borel_measurable M"
hoelzl@50002
   835
  by simp
hoelzl@50002
   836
hoelzl@41981
   837
subsection "Borel space on the extended reals"
hoelzl@41981
   838
hoelzl@50003
   839
lemma borel_measurable_ereal[measurable (raw)]:
hoelzl@43920
   840
  assumes f: "f \<in> borel_measurable M" shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@49774
   841
  using continuous_on_ereal f by (rule borel_measurable_continuous_on)
hoelzl@41981
   842
hoelzl@50003
   843
lemma borel_measurable_real_of_ereal[measurable (raw)]:
hoelzl@49774
   844
  fixes f :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   845
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   846
  shows "(\<lambda>x. real (f x)) \<in> borel_measurable M"
hoelzl@49774
   847
proof -
hoelzl@49774
   848
  have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) \<in> borel_measurable M"
hoelzl@49774
   849
    using continuous_on_real
hoelzl@49774
   850
    by (rule borel_measurable_continuous_on_open[OF _ _ f]) auto
hoelzl@49774
   851
  also have "(\<lambda>x. if f x \<in> UNIV - { \<infinity>, - \<infinity> } then real (f x) else 0) = (\<lambda>x. real (f x))"
hoelzl@49774
   852
    by auto
hoelzl@49774
   853
  finally show ?thesis .
hoelzl@49774
   854
qed
hoelzl@49774
   855
hoelzl@49774
   856
lemma borel_measurable_ereal_cases:
hoelzl@49774
   857
  fixes f :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   858
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   859
  assumes H: "(\<lambda>x. H (ereal (real (f x)))) \<in> borel_measurable M"
hoelzl@49774
   860
  shows "(\<lambda>x. H (f x)) \<in> borel_measurable M"
hoelzl@49774
   861
proof -
hoelzl@50002
   862
  let ?F = "\<lambda>x. if f x = \<infinity> then H \<infinity> else if f x = - \<infinity> then H (-\<infinity>) else H (ereal (real (f x)))"
hoelzl@49774
   863
  { fix x have "H (f x) = ?F x" by (cases "f x") auto }
hoelzl@50002
   864
  with f H show ?thesis by simp
hoelzl@47694
   865
qed
hoelzl@41981
   866
hoelzl@49774
   867
lemma
hoelzl@50003
   868
  fixes f :: "'a \<Rightarrow> ereal" assumes f[measurable]: "f \<in> borel_measurable M"
hoelzl@50003
   869
  shows borel_measurable_ereal_abs[measurable(raw)]: "(\<lambda>x. \<bar>f x\<bar>) \<in> borel_measurable M"
hoelzl@50003
   870
    and borel_measurable_ereal_inverse[measurable(raw)]: "(\<lambda>x. inverse (f x) :: ereal) \<in> borel_measurable M"
hoelzl@50003
   871
    and borel_measurable_uminus_ereal[measurable(raw)]: "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M"
hoelzl@49774
   872
  by (auto simp del: abs_real_of_ereal simp: borel_measurable_ereal_cases[OF f] measurable_If)
hoelzl@49774
   873
hoelzl@49774
   874
lemma borel_measurable_uminus_eq_ereal[simp]:
hoelzl@49774
   875
  "(\<lambda>x. - f x :: ereal) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M" (is "?l = ?r")
hoelzl@49774
   876
proof
hoelzl@49774
   877
  assume ?l from borel_measurable_uminus_ereal[OF this] show ?r by simp
hoelzl@49774
   878
qed auto
hoelzl@49774
   879
hoelzl@49774
   880
lemma set_Collect_ereal2:
hoelzl@49774
   881
  fixes f g :: "'a \<Rightarrow> ereal" 
hoelzl@49774
   882
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   883
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
   884
  assumes H: "{x \<in> space M. H (ereal (real (f x))) (ereal (real (g x)))} \<in> sets M"
hoelzl@50002
   885
    "{x \<in> space borel. H (-\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
   886
    "{x \<in> space borel. H (\<infinity>) (ereal x)} \<in> sets borel"
hoelzl@50002
   887
    "{x \<in> space borel. H (ereal x) (-\<infinity>)} \<in> sets borel"
hoelzl@50002
   888
    "{x \<in> space borel. H (ereal x) (\<infinity>)} \<in> sets borel"
hoelzl@49774
   889
  shows "{x \<in> space M. H (f x) (g x)} \<in> sets M"
hoelzl@49774
   890
proof -
hoelzl@50002
   891
  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 (g x)))"
hoelzl@50002
   892
  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 (f x))) x"
hoelzl@49774
   893
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
   894
  note * = this
hoelzl@50002
   895
  from assms show ?thesis
hoelzl@50002
   896
    by (subst *) (simp del: space_borel split del: split_if)
hoelzl@49774
   897
qed
hoelzl@49774
   898
hoelzl@50003
   899
lemma [measurable]:
hoelzl@49774
   900
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
   901
  assumes f: "f \<in> borel_measurable M"
hoelzl@49774
   902
  assumes g: "g \<in> borel_measurable M"
hoelzl@50003
   903
  shows borel_measurable_ereal_le: "{x \<in> space M. f x \<le> g x} \<in> sets M"
hoelzl@50003
   904
    and borel_measurable_ereal_less: "{x \<in> space M. f x < g x} \<in> sets M"
hoelzl@50003
   905
    and borel_measurable_ereal_eq: "{w \<in> space M. f w = g w} \<in> sets M"
hoelzl@50003
   906
  using f g by (simp_all add: set_Collect_ereal2)
hoelzl@50003
   907
hoelzl@50003
   908
lemma borel_measurable_ereal_neq:
hoelzl@50003
   909
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> {w \<in> space M. f w \<noteq> (g w :: ereal)} \<in> sets M"
hoelzl@50003
   910
  by simp
hoelzl@41981
   911
hoelzl@47694
   912
lemma borel_measurable_ereal_iff:
hoelzl@43920
   913
  shows "(\<lambda>x. ereal (f x)) \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable M"
hoelzl@41981
   914
proof
hoelzl@43920
   915
  assume "(\<lambda>x. ereal (f x)) \<in> borel_measurable M"
hoelzl@43920
   916
  from borel_measurable_real_of_ereal[OF this]
hoelzl@41981
   917
  show "f \<in> borel_measurable M" by auto
hoelzl@41981
   918
qed auto
hoelzl@41981
   919
hoelzl@47694
   920
lemma borel_measurable_ereal_iff_real:
hoelzl@43923
   921
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
   922
  shows "f \<in> borel_measurable M \<longleftrightarrow>
hoelzl@41981
   923
    ((\<lambda>x. real (f x)) \<in> borel_measurable M \<and> f -` {\<infinity>} \<inter> space M \<in> sets M \<and> f -` {-\<infinity>} \<inter> space M \<in> sets M)"
hoelzl@41981
   924
proof safe
hoelzl@41981
   925
  assume *: "(\<lambda>x. real (f x)) \<in> borel_measurable M" "f -` {\<infinity>} \<inter> space M \<in> sets M" "f -` {-\<infinity>} \<inter> space M \<in> sets M"
hoelzl@41981
   926
  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
   927
  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
wenzelm@46731
   928
  let ?f = "\<lambda>x. if f x = \<infinity> then \<infinity> else if f x = -\<infinity> then -\<infinity> else ereal (real (f x))"
hoelzl@41981
   929
  have "?f \<in> borel_measurable M" using * ** by (intro measurable_If) auto
hoelzl@43920
   930
  also have "?f = f" by (auto simp: fun_eq_iff ereal_real)
hoelzl@41981
   931
  finally show "f \<in> borel_measurable M" .
hoelzl@50002
   932
qed simp_all
hoelzl@41830
   933
hoelzl@47694
   934
lemma borel_measurable_eq_atMost_ereal:
hoelzl@43923
   935
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@43923
   936
  shows "f \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..a} \<inter> space M \<in> sets M)"
hoelzl@41981
   937
proof (intro iffI allI)
hoelzl@41981
   938
  assume pos[rule_format]: "\<forall>a. f -` {..a} \<inter> space M \<in> sets M"
hoelzl@41981
   939
  show "f \<in> borel_measurable M"
hoelzl@43920
   940
    unfolding borel_measurable_ereal_iff_real borel_measurable_iff_le
hoelzl@41981
   941
  proof (intro conjI allI)
hoelzl@41981
   942
    fix a :: real
hoelzl@43920
   943
    { fix x :: ereal assume *: "\<forall>i::nat. real i < x"
hoelzl@41981
   944
      have "x = \<infinity>"
hoelzl@43920
   945
      proof (rule ereal_top)
huffman@44666
   946
        fix B from reals_Archimedean2[of B] guess n ..
hoelzl@43920
   947
        then have "ereal B < real n" by auto
hoelzl@41981
   948
        with * show "B \<le> x" by (metis less_trans less_imp_le)
hoelzl@41981
   949
      qed }
hoelzl@41981
   950
    then have "f -` {\<infinity>} \<inter> space M = space M - (\<Union>i::nat. f -` {.. real i} \<inter> space M)"
hoelzl@41981
   951
      by (auto simp: not_le)
hoelzl@50002
   952
    then show "f -` {\<infinity>} \<inter> space M \<in> sets M" using pos
hoelzl@50002
   953
      by (auto simp del: UN_simps)
hoelzl@41981
   954
    moreover
hoelzl@43923
   955
    have "{-\<infinity>::ereal} = {..-\<infinity>}" by auto
hoelzl@41981
   956
    then show "f -` {-\<infinity>} \<inter> space M \<in> sets M" using pos by auto
hoelzl@43920
   957
    moreover have "{x\<in>space M. f x \<le> ereal a} \<in> sets M"
hoelzl@43920
   958
      using pos[of "ereal a"] by (simp add: vimage_def Int_def conj_commute)
hoelzl@41981
   959
    moreover have "{w \<in> space M. real (f w) \<le> a} =
hoelzl@43920
   960
      (if a < 0 then {w \<in> space M. f w \<le> ereal a} - f -` {-\<infinity>} \<inter> space M
hoelzl@43920
   961
      else {w \<in> space M. f w \<le> ereal a} \<union> (f -` {\<infinity>} \<inter> space M) \<union> (f -` {-\<infinity>} \<inter> space M))" (is "?l = ?r")
hoelzl@41981
   962
      proof (intro set_eqI) fix x show "x \<in> ?l \<longleftrightarrow> x \<in> ?r" by (cases "f x") auto qed
hoelzl@41981
   963
    ultimately show "{w \<in> space M. real (f w) \<le> a} \<in> sets M" by auto
hoelzl@35582
   964
  qed
hoelzl@41981
   965
qed (simp add: measurable_sets)
hoelzl@35582
   966
hoelzl@47694
   967
lemma borel_measurable_eq_atLeast_ereal:
hoelzl@43920
   968
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a..} \<inter> space M \<in> sets M)"
hoelzl@41981
   969
proof
hoelzl@41981
   970
  assume pos: "\<forall>a. f -` {a..} \<inter> space M \<in> sets M"
hoelzl@41981
   971
  moreover have "\<And>a. (\<lambda>x. - f x) -` {..a} = f -` {-a ..}"
hoelzl@43920
   972
    by (auto simp: ereal_uminus_le_reorder)
hoelzl@41981
   973
  ultimately have "(\<lambda>x. - f x) \<in> borel_measurable M"
hoelzl@43920
   974
    unfolding borel_measurable_eq_atMost_ereal by auto
hoelzl@41981
   975
  then show "f \<in> borel_measurable M" by simp
hoelzl@41981
   976
qed (simp add: measurable_sets)
hoelzl@35582
   977
hoelzl@49774
   978
lemma greater_eq_le_measurable:
hoelzl@49774
   979
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@49774
   980
  shows "f -` {..< a} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@49774
   981
proof
hoelzl@49774
   982
  assume "f -` {a ..} \<inter> space M \<in> sets M"
hoelzl@49774
   983
  moreover have "f -` {..< a} \<inter> space M = space M - f -` {a ..} \<inter> space M" by auto
hoelzl@49774
   984
  ultimately show "f -` {..< a} \<inter> space M \<in> sets M" by auto
hoelzl@49774
   985
next
hoelzl@49774
   986
  assume "f -` {..< a} \<inter> space M \<in> sets M"
hoelzl@49774
   987
  moreover have "f -` {a ..} \<inter> space M = space M - f -` {..< a} \<inter> space M" by auto
hoelzl@49774
   988
  ultimately show "f -` {a ..} \<inter> space M \<in> sets M" by auto
hoelzl@49774
   989
qed
hoelzl@49774
   990
hoelzl@47694
   991
lemma borel_measurable_ereal_iff_less:
hoelzl@43920
   992
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {..< a} \<inter> space M \<in> sets M)"
hoelzl@43920
   993
  unfolding borel_measurable_eq_atLeast_ereal greater_eq_le_measurable ..
hoelzl@38656
   994
hoelzl@49774
   995
lemma less_eq_ge_measurable:
hoelzl@49774
   996
  fixes f :: "'a \<Rightarrow> 'c::linorder"
hoelzl@49774
   997
  shows "f -` {a <..} \<inter> space M \<in> sets M \<longleftrightarrow> f -` {..a} \<inter> space M \<in> sets M"
hoelzl@49774
   998
proof
hoelzl@49774
   999
  assume "f -` {a <..} \<inter> space M \<in> sets M"
hoelzl@49774
  1000
  moreover have "f -` {..a} \<inter> space M = space M - f -` {a <..} \<inter> space M" by auto
hoelzl@49774
  1001
  ultimately show "f -` {..a} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1002
next
hoelzl@49774
  1003
  assume "f -` {..a} \<inter> space M \<in> sets M"
hoelzl@49774
  1004
  moreover have "f -` {a <..} \<inter> space M = space M - f -` {..a} \<inter> space M" by auto
hoelzl@49774
  1005
  ultimately show "f -` {a <..} \<inter> space M \<in> sets M" by auto
hoelzl@49774
  1006
qed
hoelzl@49774
  1007
hoelzl@47694
  1008
lemma borel_measurable_ereal_iff_ge:
hoelzl@43920
  1009
  "(f::'a \<Rightarrow> ereal) \<in> borel_measurable M \<longleftrightarrow> (\<forall>a. f -` {a <..} \<inter> space M \<in> sets M)"
hoelzl@43920
  1010
  unfolding borel_measurable_eq_atMost_ereal less_eq_ge_measurable ..
hoelzl@38656
  1011
hoelzl@49774
  1012
lemma borel_measurable_ereal2:
hoelzl@49774
  1013
  fixes f g :: "'a \<Rightarrow> ereal" 
hoelzl@41981
  1014
  assumes f: "f \<in> borel_measurable M"
hoelzl@41981
  1015
  assumes g: "g \<in> borel_measurable M"
hoelzl@49774
  1016
  assumes H: "(\<lambda>x. H (ereal (real (f x))) (ereal (real (g x)))) \<in> borel_measurable M"
hoelzl@49774
  1017
    "(\<lambda>x. H (-\<infinity>) (ereal (real (g x)))) \<in> borel_measurable M"
hoelzl@49774
  1018
    "(\<lambda>x. H (\<infinity>) (ereal (real (g x)))) \<in> borel_measurable M"
hoelzl@49774
  1019
    "(\<lambda>x. H (ereal (real (f x))) (-\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1020
    "(\<lambda>x. H (ereal (real (f x))) (\<infinity>)) \<in> borel_measurable M"
hoelzl@49774
  1021
  shows "(\<lambda>x. H (f x) (g x)) \<in> borel_measurable M"
hoelzl@41981
  1022
proof -
hoelzl@50002
  1023
  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 (g x)))"
hoelzl@50002
  1024
  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 (f x))) x"
hoelzl@49774
  1025
  { fix x have "H (f x) (g x) = ?F x" by (cases "f x" "g x" rule: ereal2_cases) auto }
hoelzl@50002
  1026
  note * = this
hoelzl@50002
  1027
  from assms show ?thesis unfolding * by simp
hoelzl@41981
  1028
qed
hoelzl@41981
  1029
hoelzl@49774
  1030
lemma
hoelzl@49774
  1031
  fixes f :: "'a \<Rightarrow> ereal" assumes f: "f \<in> borel_measurable M"
hoelzl@49774
  1032
  shows borel_measurable_ereal_eq_const: "{x\<in>space M. f x = c} \<in> sets M"
hoelzl@49774
  1033
    and borel_measurable_ereal_neq_const: "{x\<in>space M. f x \<noteq> c} \<in> sets M"
hoelzl@49774
  1034
  using f by auto
hoelzl@38656
  1035
hoelzl@50003
  1036
lemma [measurable(raw)]:
hoelzl@43920
  1037
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@50003
  1038
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@50002
  1039
  shows borel_measurable_ereal_add: "(\<lambda>x. f x + g x) \<in> borel_measurable M"
hoelzl@50002
  1040
    and borel_measurable_ereal_times: "(\<lambda>x. f x * g x) \<in> borel_measurable M"
hoelzl@50002
  1041
    and borel_measurable_ereal_min: "(\<lambda>x. min (g x) (f x)) \<in> borel_measurable M"
hoelzl@50002
  1042
    and borel_measurable_ereal_max: "(\<lambda>x. max (g x) (f x)) \<in> borel_measurable M"
hoelzl@50003
  1043
  by (simp_all add: borel_measurable_ereal2 min_def max_def)
hoelzl@49774
  1044
hoelzl@50003
  1045
lemma [measurable(raw)]:
hoelzl@49774
  1046
  fixes f g :: "'a \<Rightarrow> ereal"
hoelzl@49774
  1047
  assumes "f \<in> borel_measurable M"
hoelzl@49774
  1048
  assumes "g \<in> borel_measurable M"
hoelzl@50002
  1049
  shows borel_measurable_ereal_diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@50002
  1050
    and borel_measurable_ereal_divide: "(\<lambda>x. f x / g x) \<in> borel_measurable M"
hoelzl@50003
  1051
  using assms by (simp_all add: minus_ereal_def divide_ereal_def)
hoelzl@38656
  1052
hoelzl@50003
  1053
lemma borel_measurable_ereal_setsum[measurable (raw)]:
hoelzl@43920
  1054
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41096
  1055
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1056
  shows "(\<lambda>x. \<Sum>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@41096
  1057
proof cases
hoelzl@41096
  1058
  assume "finite S"
hoelzl@41096
  1059
  thus ?thesis using assms
hoelzl@41096
  1060
    by induct auto
hoelzl@49774
  1061
qed simp
hoelzl@38656
  1062
hoelzl@50003
  1063
lemma borel_measurable_ereal_setprod[measurable (raw)]:
hoelzl@43920
  1064
  fixes f :: "'c \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1065
  assumes "\<And>i. i \<in> S \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41096
  1066
  shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
hoelzl@38656
  1067
proof cases
hoelzl@38656
  1068
  assume "finite S"
hoelzl@41096
  1069
  thus ?thesis using assms by induct auto
hoelzl@41096
  1070
qed simp
hoelzl@38656
  1071
hoelzl@50003
  1072
lemma borel_measurable_SUP[measurable (raw)]:
hoelzl@43920
  1073
  fixes f :: "'d\<Colon>countable \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1074
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1075
  shows "(\<lambda>x. SUP i : A. f i x) \<in> borel_measurable M" (is "?sup \<in> borel_measurable M")
hoelzl@43920
  1076
  unfolding borel_measurable_ereal_iff_ge
hoelzl@41981
  1077
proof
hoelzl@38656
  1078
  fix a
hoelzl@41981
  1079
  have "?sup -` {a<..} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. a < f i x})"
noschinl@46884
  1080
    by (auto simp: less_SUP_iff)
hoelzl@41981
  1081
  then show "?sup -` {a<..} \<inter> space M \<in> sets M"
hoelzl@38656
  1082
    using assms by auto
hoelzl@38656
  1083
qed
hoelzl@38656
  1084
hoelzl@50003
  1085
lemma borel_measurable_INF[measurable (raw)]:
hoelzl@43920
  1086
  fixes f :: "'d :: countable \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@38656
  1087
  assumes "\<And>i. i \<in> A \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@41097
  1088
  shows "(\<lambda>x. INF i : A. f i x) \<in> borel_measurable M" (is "?inf \<in> borel_measurable M")
hoelzl@43920
  1089
  unfolding borel_measurable_ereal_iff_less
hoelzl@41981
  1090
proof
hoelzl@38656
  1091
  fix a
hoelzl@41981
  1092
  have "?inf -` {..<a} \<inter> space M = (\<Union>i\<in>A. {x\<in>space M. f i x < a})"
noschinl@46884
  1093
    by (auto simp: INF_less_iff)
hoelzl@41981
  1094
  then show "?inf -` {..<a} \<inter> space M \<in> sets M"
hoelzl@38656
  1095
    using assms by auto
hoelzl@38656
  1096
qed
hoelzl@38656
  1097
hoelzl@50003
  1098
lemma [measurable (raw)]:
hoelzl@43920
  1099
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@41981
  1100
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@50002
  1101
  shows borel_measurable_liminf: "(\<lambda>x. liminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1102
    and borel_measurable_limsup: "(\<lambda>x. limsup (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1103
  unfolding liminf_SUPR_INFI limsup_INFI_SUPR using assms by auto
hoelzl@35692
  1104
hoelzl@50003
  1105
lemma sets_Collect_eventually_sequientially[measurable]:
hoelzl@50003
  1106
  "(\<And>i. {x\<in>space M. P x i} \<in> sets M) \<Longrightarrow> {x\<in>space M. eventually (P x) sequentially} \<in> sets M"
hoelzl@50003
  1107
  unfolding eventually_sequentially by simp
hoelzl@50003
  1108
hoelzl@50003
  1109
lemma convergent_ereal:
hoelzl@50003
  1110
  fixes X :: "nat \<Rightarrow> ereal"
hoelzl@50003
  1111
  shows "convergent X \<longleftrightarrow> limsup X = liminf X"
hoelzl@50003
  1112
  using ereal_Liminf_eq_Limsup_iff[of sequentially]
hoelzl@50003
  1113
  by (auto simp: convergent_def)
hoelzl@50003
  1114
hoelzl@50003
  1115
lemma convergent_ereal_limsup:
hoelzl@50003
  1116
  fixes X :: "nat \<Rightarrow> ereal"
hoelzl@50003
  1117
  shows "convergent X \<Longrightarrow> limsup X = lim X"
hoelzl@50003
  1118
  by (auto simp: convergent_def limI lim_imp_Limsup)
hoelzl@50003
  1119
hoelzl@50003
  1120
lemma sets_Collect_ereal_convergent[measurable]: 
hoelzl@50003
  1121
  fixes f :: "nat \<Rightarrow> 'a => ereal"
hoelzl@50003
  1122
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1123
  shows "{x\<in>space M. convergent (\<lambda>i. f i x)} \<in> sets M"
hoelzl@50003
  1124
  unfolding convergent_ereal by auto
hoelzl@50003
  1125
hoelzl@50003
  1126
lemma borel_measurable_extreal_lim[measurable (raw)]:
hoelzl@50003
  1127
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1128
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@50003
  1129
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1130
proof -
hoelzl@50003
  1131
  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@50003
  1132
    using convergent_ereal_limsup by (simp add: lim_def convergent_def)
hoelzl@50003
  1133
  then show ?thesis
hoelzl@50003
  1134
    by simp
hoelzl@50003
  1135
qed
hoelzl@50003
  1136
hoelzl@49774
  1137
lemma borel_measurable_ereal_LIMSEQ:
hoelzl@49774
  1138
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@49774
  1139
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
hoelzl@49774
  1140
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@49774
  1141
  shows "u' \<in> borel_measurable M"
hoelzl@47694
  1142
proof -
hoelzl@49774
  1143
  have "\<And>x. x \<in> space M \<Longrightarrow> u' x = liminf (\<lambda>n. u n x)"
hoelzl@49774
  1144
    using u' by (simp add: lim_imp_Liminf[symmetric])
hoelzl@50003
  1145
  with u show ?thesis by (simp cong: measurable_cong)
hoelzl@47694
  1146
qed
hoelzl@47694
  1147
hoelzl@50003
  1148
lemma borel_measurable_extreal_suminf[measurable (raw)]:
hoelzl@43920
  1149
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@50003
  1150
  assumes [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@41981
  1151
  shows "(\<lambda>x. (\<Sum>i. f i x)) \<in> borel_measurable M"
hoelzl@50003
  1152
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@39092
  1153
hoelzl@39092
  1154
section "LIMSEQ is borel measurable"
hoelzl@39092
  1155
hoelzl@47694
  1156
lemma borel_measurable_LIMSEQ:
hoelzl@39092
  1157
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@39092
  1158
  assumes u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
hoelzl@39092
  1159
  and u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@39092
  1160
  shows "u' \<in> borel_measurable M"
hoelzl@39092
  1161
proof -
hoelzl@43920
  1162
  have "\<And>x. x \<in> space M \<Longrightarrow> liminf (\<lambda>n. ereal (u n x)) = ereal (u' x)"
wenzelm@46731
  1163
    using u' by (simp add: lim_imp_Liminf)
hoelzl@43920
  1164
  moreover from u have "(\<lambda>x. liminf (\<lambda>n. ereal (u n x))) \<in> borel_measurable M"
hoelzl@39092
  1165
    by auto
hoelzl@43920
  1166
  ultimately show ?thesis by (simp cong: measurable_cong add: borel_measurable_ereal_iff)
hoelzl@39092
  1167
qed
hoelzl@39092
  1168
hoelzl@50002
  1169
lemma sets_Collect_Cauchy[measurable]: 
hoelzl@49774
  1170
  fixes f :: "nat \<Rightarrow> 'a => real"
hoelzl@50002
  1171
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1172
  shows "{x\<in>space M. Cauchy (\<lambda>i. f i x)} \<in> sets M"
hoelzl@50002
  1173
  unfolding Cauchy_iff2 using f by auto
hoelzl@49774
  1174
hoelzl@50002
  1175
lemma borel_measurable_lim[measurable (raw)]:
hoelzl@49774
  1176
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@50002
  1177
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1178
  shows "(\<lambda>x. lim (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@49774
  1179
proof -
hoelzl@50002
  1180
  def u' \<equiv> "\<lambda>x. lim (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@50002
  1181
  then have *: "\<And>x. lim (\<lambda>i. f i x) = (if Cauchy (\<lambda>i. f i x) then u' x else (THE x. False))"
hoelzl@49774
  1182
    by (auto simp: lim_def convergent_eq_cauchy[symmetric])
hoelzl@50002
  1183
  have "u' \<in> borel_measurable M"
hoelzl@50002
  1184
  proof (rule borel_measurable_LIMSEQ)
hoelzl@50002
  1185
    fix x
hoelzl@50002
  1186
    have "convergent (\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0)"
hoelzl@49774
  1187
      by (cases "Cauchy (\<lambda>i. f i x)")
hoelzl@50002
  1188
         (auto simp add: convergent_eq_cauchy[symmetric] convergent_def)
hoelzl@50002
  1189
    then show "(\<lambda>i. if Cauchy (\<lambda>i. f i x) then f i x else 0) ----> u' x"
hoelzl@50002
  1190
      unfolding u'_def 
hoelzl@50002
  1191
      by (rule convergent_LIMSEQ_iff[THEN iffD1])
hoelzl@50002
  1192
  qed measurable
hoelzl@50002
  1193
  then show ?thesis
hoelzl@50002
  1194
    unfolding * by measurable
hoelzl@49774
  1195
qed
hoelzl@49774
  1196
hoelzl@50002
  1197
lemma borel_measurable_suminf[measurable (raw)]:
hoelzl@49774
  1198
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@50002
  1199
  assumes f[measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@49774
  1200
  shows "(\<lambda>x. suminf (\<lambda>i. f i x)) \<in> borel_measurable M"
hoelzl@50002
  1201
  unfolding suminf_def sums_def[abs_def] lim_def[symmetric] by simp
hoelzl@49774
  1202
hoelzl@49774
  1203
end