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