src/HOL/Probability/Lebesgue_Measure.thy
author paulson <lp15@cam.ac.uk>
Tue Jun 30 13:56:16 2015 +0100 (2015-06-30)
changeset 60615 e5fa1d5d3952
parent 59741 5b762cd73a8e
child 61284 2314c2f62eb1
permissions -rw-r--r--
Useful lemmas. The theorem concerning swapping the variables in a double integral.
hoelzl@42067
     1
(*  Title:      HOL/Probability/Lebesgue_Measure.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
    Author:     Robert Himmelmann, TU München
hoelzl@57447
     4
    Author:     Jeremy Avigad
hoelzl@57447
     5
    Author:     Luke Serafin
hoelzl@42067
     6
*)
hoelzl@42067
     7
Andreas@59357
     8
section {* Lebesgue measure *}
hoelzl@42067
     9
hoelzl@38656
    10
theory Lebesgue_Measure
hoelzl@57447
    11
  imports Finite_Product_Measure Bochner_Integration Caratheodory
hoelzl@38656
    12
begin
hoelzl@38656
    13
hoelzl@57447
    14
subsection {* Every right continuous and nondecreasing function gives rise to a measure *}
hoelzl@57447
    15
hoelzl@57447
    16
definition interval_measure :: "(real \<Rightarrow> real) \<Rightarrow> real measure" where
hoelzl@57447
    17
  "interval_measure F = extend_measure UNIV {(a, b). a \<le> b} (\<lambda>(a, b). {a <.. b}) (\<lambda>(a, b). ereal (F b - F a))"
hoelzl@49777
    18
hoelzl@57447
    19
lemma emeasure_interval_measure_Ioc:
hoelzl@57447
    20
  assumes "a \<le> b"
hoelzl@57447
    21
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
    22
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
    23
  shows "emeasure (interval_measure F) {a <.. b} = F b - F a"
hoelzl@57447
    24
proof (rule extend_measure_caratheodory_pair[OF interval_measure_def `a \<le> b`])
hoelzl@57447
    25
  show "semiring_of_sets UNIV {{a<..b} |a b :: real. a \<le> b}"
hoelzl@57447
    26
  proof (unfold_locales, safe)
hoelzl@57447
    27
    fix a b c d :: real assume *: "a \<le> b" "c \<le> d"
hoelzl@57447
    28
    then show "\<exists>C\<subseteq>{{a<..b} |a b. a \<le> b}. finite C \<and> disjoint C \<and> {a<..b} - {c<..d} = \<Union>C"
hoelzl@57447
    29
    proof cases
hoelzl@57447
    30
      let ?C = "{{a<..b}}"
hoelzl@57447
    31
      assume "b < c \<or> d \<le> a \<or> d \<le> c"
hoelzl@57447
    32
      with * have "?C \<subseteq> {{a<..b} |a b. a \<le> b} \<and> finite ?C \<and> disjoint ?C \<and> {a<..b} - {c<..d} = \<Union>?C"
hoelzl@57447
    33
        by (auto simp add: disjoint_def)
hoelzl@57447
    34
      thus ?thesis ..
hoelzl@57447
    35
    next
hoelzl@57447
    36
      let ?C = "{{a<..c}, {d<..b}}"
hoelzl@57447
    37
      assume "\<not> (b < c \<or> d \<le> a \<or> d \<le> c)"
hoelzl@57447
    38
      with * have "?C \<subseteq> {{a<..b} |a b. a \<le> b} \<and> finite ?C \<and> disjoint ?C \<and> {a<..b} - {c<..d} = \<Union>?C"
hoelzl@57447
    39
        by (auto simp add: disjoint_def Ioc_inj) (metis linear)+
hoelzl@57447
    40
      thus ?thesis ..
hoelzl@57447
    41
    qed
hoelzl@57447
    42
  qed (auto simp: Ioc_inj, metis linear)
lp15@60615
    43
hoelzl@57447
    44
next
hoelzl@57447
    45
  fix l r :: "nat \<Rightarrow> real" and a b :: real
lp15@60615
    46
  assume l_r[simp]: "\<And>n. l n \<le> r n" and "a \<le> b" and disj: "disjoint_family (\<lambda>n. {l n<..r n})"
hoelzl@57447
    47
  assume lr_eq_ab: "(\<Union>i. {l i<..r i}) = {a<..b}"
hoelzl@57447
    48
hoelzl@57447
    49
  have [intro, simp]: "\<And>a b. a \<le> b \<Longrightarrow> 0 \<le> F b - F a"
hoelzl@57447
    50
    by (auto intro!: l_r mono_F simp: diff_le_iff)
hoelzl@57447
    51
hoelzl@57447
    52
  { fix S :: "nat set" assume "finite S"
hoelzl@57447
    53
    moreover note `a \<le> b`
hoelzl@57447
    54
    moreover have "\<And>i. i \<in> S \<Longrightarrow> {l i <.. r i} \<subseteq> {a <.. b}"
hoelzl@57447
    55
      unfolding lr_eq_ab[symmetric] by auto
hoelzl@57447
    56
    ultimately have "(\<Sum>i\<in>S. F (r i) - F (l i)) \<le> F b - F a"
hoelzl@57447
    57
    proof (induction S arbitrary: a rule: finite_psubset_induct)
hoelzl@57447
    58
      case (psubset S)
hoelzl@57447
    59
      show ?case
hoelzl@57447
    60
      proof cases
hoelzl@57447
    61
        assume "\<exists>i\<in>S. l i < r i"
hoelzl@57447
    62
        with `finite S` have "Min (l ` {i\<in>S. l i < r i}) \<in> l ` {i\<in>S. l i < r i}"
hoelzl@57447
    63
          by (intro Min_in) auto
hoelzl@57447
    64
        then obtain m where m: "m \<in> S" "l m < r m" "l m = Min (l ` {i\<in>S. l i < r i})"
hoelzl@57447
    65
          by fastforce
hoelzl@50104
    66
hoelzl@57447
    67
        have "(\<Sum>i\<in>S. F (r i) - F (l i)) = (F (r m) - F (l m)) + (\<Sum>i\<in>S - {m}. F (r i) - F (l i))"
hoelzl@57447
    68
          using m psubset by (intro setsum.remove) auto
hoelzl@57447
    69
        also have "(\<Sum>i\<in>S - {m}. F (r i) - F (l i)) \<le> F b - F (r m)"
hoelzl@57447
    70
        proof (intro psubset.IH)
hoelzl@57447
    71
          show "S - {m} \<subset> S"
hoelzl@57447
    72
            using `m\<in>S` by auto
hoelzl@57447
    73
          show "r m \<le> b"
hoelzl@57447
    74
            using psubset.prems(2)[OF `m\<in>S`] `l m < r m` by auto
hoelzl@57447
    75
        next
hoelzl@57447
    76
          fix i assume "i \<in> S - {m}"
hoelzl@57447
    77
          then have i: "i \<in> S" "i \<noteq> m" by auto
hoelzl@57447
    78
          { assume i': "l i < r i" "l i < r m"
hoelzl@57447
    79
            moreover with `finite S` i m have "l m \<le> l i"
hoelzl@57447
    80
              by auto
hoelzl@57447
    81
            ultimately have "{l i <.. r i} \<inter> {l m <.. r m} \<noteq> {}"
hoelzl@57447
    82
              by auto
hoelzl@57447
    83
            then have False
hoelzl@57447
    84
              using disjoint_family_onD[OF disj, of i m] i by auto }
hoelzl@57447
    85
          then have "l i \<noteq> r i \<Longrightarrow> r m \<le> l i"
hoelzl@57447
    86
            unfolding not_less[symmetric] using l_r[of i] by auto
hoelzl@57447
    87
          then show "{l i <.. r i} \<subseteq> {r m <.. b}"
hoelzl@57447
    88
            using psubset.prems(2)[OF `i\<in>S`] by auto
hoelzl@57447
    89
        qed
hoelzl@57447
    90
        also have "F (r m) - F (l m) \<le> F (r m) - F a"
hoelzl@57447
    91
          using psubset.prems(2)[OF `m \<in> S`] `l m < r m`
hoelzl@57447
    92
          by (auto simp add: Ioc_subset_iff intro!: mono_F)
hoelzl@57447
    93
        finally show ?case
hoelzl@57447
    94
          by (auto intro: add_mono)
hoelzl@57447
    95
      qed (simp add: `a \<le> b` less_le)
hoelzl@57447
    96
    qed }
hoelzl@57447
    97
  note claim1 = this
hoelzl@57447
    98
hoelzl@57447
    99
  (* second key induction: a lower bound on the measures of any finite collection of Ai's
hoelzl@57447
   100
     that cover an interval {u..v} *)
hoelzl@57447
   101
hoelzl@57447
   102
  { fix S u v and l r :: "nat \<Rightarrow> real"
hoelzl@57447
   103
    assume "finite S" "\<And>i. i\<in>S \<Longrightarrow> l i < r i" "{u..v} \<subseteq> (\<Union>i\<in>S. {l i<..< r i})"
hoelzl@57447
   104
    then have "F v - F u \<le> (\<Sum>i\<in>S. F (r i) - F (l i))"
hoelzl@57447
   105
    proof (induction arbitrary: v u rule: finite_psubset_induct)
hoelzl@57447
   106
      case (psubset S)
hoelzl@57447
   107
      show ?case
hoelzl@57447
   108
      proof cases
hoelzl@57447
   109
        assume "S = {}" then show ?case
hoelzl@57447
   110
          using psubset by (simp add: mono_F)
hoelzl@57447
   111
      next
hoelzl@57447
   112
        assume "S \<noteq> {}"
hoelzl@57447
   113
        then obtain j where "j \<in> S"
hoelzl@57447
   114
          by auto
hoelzl@47694
   115
hoelzl@57447
   116
        let ?R = "r j < u \<or> l j > v \<or> (\<exists>i\<in>S-{j}. l i \<le> l j \<and> r j \<le> r i)"
hoelzl@57447
   117
        show ?case
hoelzl@57447
   118
        proof cases
hoelzl@57447
   119
          assume "?R"
hoelzl@57447
   120
          with `j \<in> S` psubset.prems have "{u..v} \<subseteq> (\<Union>i\<in>S-{j}. {l i<..< r i})"
hoelzl@57447
   121
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   122
            apply (metis Diff_iff less_le_trans leD linear singletonD)
hoelzl@57447
   123
            apply (metis Diff_iff less_le_trans leD linear singletonD)
hoelzl@57447
   124
            apply (metis order_trans less_le_not_le linear)
hoelzl@57447
   125
            done
hoelzl@57447
   126
          with `j \<in> S` have "F v - F u \<le> (\<Sum>i\<in>S - {j}. F (r i) - F (l i))"
hoelzl@57447
   127
            by (intro psubset) auto
hoelzl@57447
   128
          also have "\<dots> \<le> (\<Sum>i\<in>S. F (r i) - F (l i))"
hoelzl@57447
   129
            using psubset.prems
hoelzl@57447
   130
            by (intro setsum_mono2 psubset) (auto intro: less_imp_le)
hoelzl@57447
   131
          finally show ?thesis .
hoelzl@57447
   132
        next
hoelzl@57447
   133
          assume "\<not> ?R"
hoelzl@57447
   134
          then have j: "u \<le> r j" "l j \<le> v" "\<And>i. i \<in> S - {j} \<Longrightarrow> r i < r j \<or> l i > l j"
hoelzl@57447
   135
            by (auto simp: not_less)
hoelzl@57447
   136
          let ?S1 = "{i \<in> S. l i < l j}"
hoelzl@57447
   137
          let ?S2 = "{i \<in> S. r i > r j}"
hoelzl@40859
   138
hoelzl@57447
   139
          have "(\<Sum>i\<in>S. F (r i) - F (l i)) \<ge> (\<Sum>i\<in>?S1 \<union> ?S2 \<union> {j}. F (r i) - F (l i))"
hoelzl@57447
   140
            using `j \<in> S` `finite S` psubset.prems j
hoelzl@57447
   141
            by (intro setsum_mono2) (auto intro: less_imp_le)
hoelzl@57447
   142
          also have "(\<Sum>i\<in>?S1 \<union> ?S2 \<union> {j}. F (r i) - F (l i)) =
hoelzl@57447
   143
            (\<Sum>i\<in>?S1. F (r i) - F (l i)) + (\<Sum>i\<in>?S2 . F (r i) - F (l i)) + (F (r j) - F (l j))"
hoelzl@57447
   144
            using psubset(1) psubset.prems(1) j
hoelzl@57447
   145
            apply (subst setsum.union_disjoint)
hoelzl@57447
   146
            apply simp_all
hoelzl@57447
   147
            apply (subst setsum.union_disjoint)
hoelzl@57447
   148
            apply auto
hoelzl@57447
   149
            apply (metis less_le_not_le)
hoelzl@57447
   150
            done
hoelzl@57447
   151
          also (xtrans) have "(\<Sum>i\<in>?S1. F (r i) - F (l i)) \<ge> F (l j) - F u"
hoelzl@57447
   152
            using `j \<in> S` `finite S` psubset.prems j
hoelzl@57447
   153
            apply (intro psubset.IH psubset)
hoelzl@57447
   154
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   155
            apply (metis less_le_trans not_le)
hoelzl@57447
   156
            done
hoelzl@57447
   157
          also (xtrans) have "(\<Sum>i\<in>?S2. F (r i) - F (l i)) \<ge> F v - F (r j)"
hoelzl@57447
   158
            using `j \<in> S` `finite S` psubset.prems j
hoelzl@57447
   159
            apply (intro psubset.IH psubset)
hoelzl@57447
   160
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   161
            apply (metis le_less_trans not_le)
hoelzl@57447
   162
            done
hoelzl@57447
   163
          finally (xtrans) show ?case
hoelzl@57447
   164
            by (auto simp: add_mono)
hoelzl@57447
   165
        qed
hoelzl@57447
   166
      qed
hoelzl@57447
   167
    qed }
hoelzl@57447
   168
  note claim2 = this
hoelzl@49777
   169
hoelzl@57447
   170
  (* now prove the inequality going the other way *)
hoelzl@40859
   171
hoelzl@57447
   172
  { fix epsilon :: real assume egt0: "epsilon > 0"
hoelzl@57447
   173
    have "\<forall>i. \<exists>d. d > 0 &  F (r i + d) < F (r i) + epsilon / 2^(i+2)"
lp15@60615
   174
    proof
hoelzl@57447
   175
      fix i
hoelzl@57447
   176
      note right_cont_F [of "r i"]
hoelzl@57447
   177
      thus "\<exists>d. d > 0 \<and> F (r i + d) < F (r i) + epsilon / 2^(i+2)"
hoelzl@57447
   178
        apply -
hoelzl@57447
   179
        apply (subst (asm) continuous_at_right_real_increasing)
hoelzl@57447
   180
        apply (rule mono_F, assumption)
hoelzl@57447
   181
        apply (drule_tac x = "epsilon / 2 ^ (i + 2)" in spec)
hoelzl@57447
   182
        apply (erule impE)
hoelzl@57447
   183
        using egt0 by (auto simp add: field_simps)
hoelzl@57447
   184
    qed
lp15@60615
   185
    then obtain delta where
hoelzl@57447
   186
        deltai_gt0: "\<And>i. delta i > 0" and
hoelzl@57447
   187
        deltai_prop: "\<And>i. F (r i + delta i) < F (r i) + epsilon / 2^(i+2)"
hoelzl@57447
   188
      by metis
hoelzl@57447
   189
    have "\<exists>a' > a. F a' - F a < epsilon / 2"
hoelzl@57447
   190
      apply (insert right_cont_F [of a])
hoelzl@57447
   191
      apply (subst (asm) continuous_at_right_real_increasing)
hoelzl@57447
   192
      using mono_F apply force
hoelzl@57447
   193
      apply (drule_tac x = "epsilon / 2" in spec)
haftmann@59554
   194
      using egt0 unfolding mult.commute [of 2] by force
lp15@60615
   195
    then obtain a' where a'lea [arith]: "a' > a" and
hoelzl@57447
   196
      a_prop: "F a' - F a < epsilon / 2"
hoelzl@57447
   197
      by auto
hoelzl@57447
   198
    def S' \<equiv> "{i. l i < r i}"
lp15@60615
   199
    obtain S :: "nat set" where
lp15@60615
   200
      "S \<subseteq> S'" and finS: "finite S" and
hoelzl@57447
   201
      Sprop: "{a'..b} \<subseteq> (\<Union>i \<in> S. {l i<..<r i + delta i})"
hoelzl@57447
   202
    proof (rule compactE_image)
hoelzl@57447
   203
      show "compact {a'..b}"
hoelzl@57447
   204
        by (rule compact_Icc)
hoelzl@57447
   205
      show "\<forall>i \<in> S'. open ({l i<..<r i + delta i})" by auto
hoelzl@57447
   206
      have "{a'..b} \<subseteq> {a <.. b}"
hoelzl@57447
   207
        by auto
hoelzl@57447
   208
      also have "{a <.. b} = (\<Union>i\<in>S'. {l i<..r i})"
hoelzl@57447
   209
        unfolding lr_eq_ab[symmetric] by (fastforce simp add: S'_def intro: less_le_trans)
hoelzl@57447
   210
      also have "\<dots> \<subseteq> (\<Union>i \<in> S'. {l i<..<r i + delta i})"
hoelzl@57447
   211
        apply (intro UN_mono)
hoelzl@57447
   212
        apply (auto simp: S'_def)
hoelzl@57447
   213
        apply (cut_tac i=i in deltai_gt0)
hoelzl@57447
   214
        apply simp
hoelzl@57447
   215
        done
hoelzl@57447
   216
      finally show "{a'..b} \<subseteq> (\<Union>i \<in> S'. {l i<..<r i + delta i})" .
hoelzl@57447
   217
    qed
hoelzl@57447
   218
    with S'_def have Sprop2: "\<And>i. i \<in> S \<Longrightarrow> l i < r i" by auto
lp15@60615
   219
    from finS have "\<exists>n. \<forall>i \<in> S. i \<le> n"
hoelzl@57447
   220
      by (subst finite_nat_set_iff_bounded_le [symmetric])
hoelzl@57447
   221
    then obtain n where Sbound [rule_format]: "\<forall>i \<in> S. i \<le> n" ..
hoelzl@57447
   222
    have "F b - F a' \<le> (\<Sum>i\<in>S. F (r i + delta i) - F (l i))"
hoelzl@57447
   223
      apply (rule claim2 [rule_format])
hoelzl@57447
   224
      using finS Sprop apply auto
hoelzl@57447
   225
      apply (frule Sprop2)
hoelzl@57447
   226
      apply (subgoal_tac "delta i > 0")
hoelzl@57447
   227
      apply arith
hoelzl@57447
   228
      by (rule deltai_gt0)
hoelzl@57447
   229
    also have "... \<le> (SUM i : S. F(r i) - F(l i) + epsilon / 2^(i+2))"
hoelzl@57447
   230
      apply (rule setsum_mono)
hoelzl@57447
   231
      apply simp
hoelzl@57447
   232
      apply (rule order_trans)
hoelzl@57447
   233
      apply (rule less_imp_le)
hoelzl@57447
   234
      apply (rule deltai_prop)
hoelzl@57447
   235
      by auto
lp15@60615
   236
    also have "... = (SUM i : S. F(r i) - F(l i)) +
hoelzl@57447
   237
        (epsilon / 4) * (SUM i : S. (1 / 2)^i)" (is "_ = ?t + _")
hoelzl@57447
   238
      by (subst setsum.distrib) (simp add: field_simps setsum_right_distrib)
hoelzl@57447
   239
    also have "... \<le> ?t + (epsilon / 4) * (\<Sum> i < Suc n. (1 / 2)^i)"
hoelzl@57447
   240
      apply (rule add_left_mono)
hoelzl@57447
   241
      apply (rule mult_left_mono)
hoelzl@57447
   242
      apply (rule setsum_mono2)
lp15@60615
   243
      using egt0 apply auto
hoelzl@57447
   244
      by (frule Sbound, auto)
hoelzl@57447
   245
    also have "... \<le> ?t + (epsilon / 2)"
hoelzl@57447
   246
      apply (rule add_left_mono)
hoelzl@57447
   247
      apply (subst geometric_sum)
hoelzl@57447
   248
      apply auto
hoelzl@57447
   249
      apply (rule mult_left_mono)
hoelzl@57447
   250
      using egt0 apply auto
hoelzl@57447
   251
      done
hoelzl@57447
   252
    finally have aux2: "F b - F a' \<le> (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon / 2"
hoelzl@57447
   253
      by simp
hoelzl@50526
   254
hoelzl@57447
   255
    have "F b - F a = (F b - F a') + (F a' - F a)"
hoelzl@57447
   256
      by auto
hoelzl@57447
   257
    also have "... \<le> (F b - F a') + epsilon / 2"
hoelzl@57447
   258
      using a_prop by (intro add_left_mono) simp
hoelzl@57447
   259
    also have "... \<le> (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon / 2 + epsilon / 2"
hoelzl@57447
   260
      apply (intro add_right_mono)
hoelzl@57447
   261
      apply (rule aux2)
hoelzl@57447
   262
      done
hoelzl@57447
   263
    also have "... = (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon"
hoelzl@57447
   264
      by auto
hoelzl@57447
   265
    also have "... \<le> (\<Sum>i\<le>n. F (r i) - F (l i)) + epsilon"
hoelzl@57447
   266
      using finS Sbound Sprop by (auto intro!: add_right_mono setsum_mono3)
hoelzl@57447
   267
    finally have "ereal (F b - F a) \<le> (\<Sum>i\<le>n. ereal (F (r i) - F (l i))) + epsilon"
hoelzl@57447
   268
      by simp
hoelzl@57447
   269
    then have "ereal (F b - F a) \<le> (\<Sum>i. ereal (F (r i) - F (l i))) + (epsilon :: real)"
hoelzl@57447
   270
      apply (rule_tac order_trans)
hoelzl@57447
   271
      prefer 2
hoelzl@57447
   272
      apply (rule add_mono[where c="ereal epsilon"])
hoelzl@57447
   273
      apply (rule suminf_upper[of _ "Suc n"])
hoelzl@57447
   274
      apply (auto simp add: lessThan_Suc_atMost)
hoelzl@57447
   275
      done }
hoelzl@57447
   276
  hence "ereal (F b - F a) \<le> (\<Sum>i. ereal (F (r i) - F (l i)))"
hoelzl@57447
   277
    by (auto intro: ereal_le_epsilon2)
hoelzl@57447
   278
  moreover
hoelzl@57447
   279
  have "(\<Sum>i. ereal (F (r i) - F (l i))) \<le> ereal (F b - F a)"
hoelzl@57447
   280
    by (auto simp add: claim1 intro!: suminf_bound)
hoelzl@57447
   281
  ultimately show "(\<Sum>n. ereal (F (r n) - F (l n))) = ereal (F b - F a)"
hoelzl@57447
   282
    by simp
hoelzl@57447
   283
qed (auto simp: Ioc_inj diff_le_iff mono_F)
hoelzl@38656
   284
hoelzl@57447
   285
lemma measure_interval_measure_Ioc:
hoelzl@57447
   286
  assumes "a \<le> b"
hoelzl@57447
   287
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   288
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
   289
  shows "measure (interval_measure F) {a <.. b} = F b - F a"
hoelzl@57447
   290
  unfolding measure_def
hoelzl@57447
   291
  apply (subst emeasure_interval_measure_Ioc)
hoelzl@57447
   292
  apply fact+
hoelzl@57447
   293
  apply simp
hoelzl@57447
   294
  done
hoelzl@57447
   295
hoelzl@57447
   296
lemma emeasure_interval_measure_Ioc_eq:
hoelzl@57447
   297
  "(\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y) \<Longrightarrow> (\<And>a. continuous (at_right a) F) \<Longrightarrow>
hoelzl@57447
   298
    emeasure (interval_measure F) {a <.. b} = (if a \<le> b then F b - F a else 0)"
hoelzl@57447
   299
  using emeasure_interval_measure_Ioc[of a b F] by auto
hoelzl@57447
   300
hoelzl@59048
   301
lemma sets_interval_measure [simp, measurable_cong]: "sets (interval_measure F) = sets borel"
hoelzl@57447
   302
  apply (simp add: sets_extend_measure interval_measure_def borel_sigma_sets_Ioc)
hoelzl@57447
   303
  apply (rule sigma_sets_eqI)
hoelzl@57447
   304
  apply auto
hoelzl@57447
   305
  apply (case_tac "a \<le> ba")
hoelzl@57447
   306
  apply (auto intro: sigma_sets.Empty)
hoelzl@57447
   307
  done
hoelzl@57447
   308
hoelzl@57447
   309
lemma space_interval_measure [simp]: "space (interval_measure F) = UNIV"
hoelzl@57447
   310
  by (simp add: interval_measure_def space_extend_measure)
hoelzl@57447
   311
hoelzl@57447
   312
lemma emeasure_interval_measure_Icc:
hoelzl@57447
   313
  assumes "a \<le> b"
hoelzl@57447
   314
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   315
  assumes cont_F : "continuous_on UNIV F"
hoelzl@57447
   316
  shows "emeasure (interval_measure F) {a .. b} = F b - F a"
hoelzl@57447
   317
proof (rule tendsto_unique)
hoelzl@57447
   318
  { fix a b :: real assume "a \<le> b" then have "emeasure (interval_measure F) {a <.. b} = F b - F a"
hoelzl@57447
   319
      using cont_F
hoelzl@57447
   320
      by (subst emeasure_interval_measure_Ioc)
hoelzl@57447
   321
         (auto intro: mono_F continuous_within_subset simp: continuous_on_eq_continuous_within) }
hoelzl@57447
   322
  note * = this
hoelzl@38656
   323
hoelzl@57447
   324
  let ?F = "interval_measure F"
hoelzl@57447
   325
  show "((\<lambda>a. F b - F a) ---> emeasure ?F {a..b}) (at_left a)"
hoelzl@57447
   326
  proof (rule tendsto_at_left_sequentially)
hoelzl@57447
   327
    show "a - 1 < a" by simp
hoelzl@57447
   328
    fix X assume "\<And>n. X n < a" "incseq X" "X ----> a"
hoelzl@57447
   329
    with `a \<le> b` have "(\<lambda>n. emeasure ?F {X n<..b}) ----> emeasure ?F (\<Inter>n. {X n <..b})"
hoelzl@57447
   330
      apply (intro Lim_emeasure_decseq)
hoelzl@57447
   331
      apply (auto simp: decseq_def incseq_def emeasure_interval_measure_Ioc *)
hoelzl@57447
   332
      apply force
hoelzl@57447
   333
      apply (subst (asm ) *)
hoelzl@57447
   334
      apply (auto intro: less_le_trans less_imp_le)
hoelzl@57447
   335
      done
hoelzl@57447
   336
    also have "(\<Inter>n. {X n <..b}) = {a..b}"
hoelzl@57447
   337
      using `\<And>n. X n < a`
hoelzl@57447
   338
      apply auto
hoelzl@57447
   339
      apply (rule LIMSEQ_le_const2[OF `X ----> a`])
hoelzl@57447
   340
      apply (auto intro: less_imp_le)
hoelzl@57447
   341
      apply (auto intro: less_le_trans)
hoelzl@57447
   342
      done
hoelzl@57447
   343
    also have "(\<lambda>n. emeasure ?F {X n<..b}) = (\<lambda>n. F b - F (X n))"
hoelzl@57447
   344
      using `\<And>n. X n < a` `a \<le> b` by (subst *) (auto intro: less_imp_le less_le_trans)
hoelzl@57447
   345
    finally show "(\<lambda>n. F b - F (X n)) ----> emeasure ?F {a..b}" .
hoelzl@57447
   346
  qed
hoelzl@57447
   347
  show "((\<lambda>a. ereal (F b - F a)) ---> F b - F a) (at_left a)"
hoelzl@57447
   348
    using cont_F
hoelzl@57447
   349
    by (intro lim_ereal[THEN iffD2] tendsto_intros )
hoelzl@57447
   350
       (auto simp: continuous_on_def intro: tendsto_within_subset)
hoelzl@57447
   351
qed (rule trivial_limit_at_left_real)
lp15@60615
   352
hoelzl@57447
   353
lemma sigma_finite_interval_measure:
hoelzl@57447
   354
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   355
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
   356
  shows "sigma_finite_measure (interval_measure F)"
hoelzl@57447
   357
  apply unfold_locales
hoelzl@57447
   358
  apply (intro exI[of _ "(\<lambda>(a, b). {a <.. b}) ` (\<rat> \<times> \<rat>)"])
hoelzl@57447
   359
  apply (auto intro!: Rats_no_top_le Rats_no_bot_less countable_rat simp: emeasure_interval_measure_Ioc_eq[OF assms])
hoelzl@57447
   360
  done
hoelzl@57447
   361
hoelzl@57447
   362
subsection {* Lebesgue-Borel measure *}
hoelzl@57447
   363
hoelzl@57447
   364
definition lborel :: "('a :: euclidean_space) measure" where
hoelzl@57447
   365
  "lborel = distr (\<Pi>\<^sub>M b\<in>Basis. interval_measure (\<lambda>x. x)) borel (\<lambda>f. \<Sum>b\<in>Basis. f b *\<^sub>R b)"
hoelzl@57447
   366
lp15@60615
   367
lemma
hoelzl@59048
   368
  shows sets_lborel[simp, measurable_cong]: "sets lborel = sets borel"
hoelzl@57447
   369
    and space_lborel[simp]: "space lborel = space borel"
hoelzl@57447
   370
    and measurable_lborel1[simp]: "measurable M lborel = measurable M borel"
hoelzl@57447
   371
    and measurable_lborel2[simp]: "measurable lborel M = measurable borel M"
hoelzl@57447
   372
  by (simp_all add: lborel_def)
hoelzl@57447
   373
hoelzl@57447
   374
context
hoelzl@57447
   375
begin
hoelzl@57447
   376
hoelzl@57447
   377
interpretation sigma_finite_measure "interval_measure (\<lambda>x. x)"
hoelzl@57447
   378
  by (rule sigma_finite_interval_measure) auto
hoelzl@57447
   379
interpretation finite_product_sigma_finite "\<lambda>_. interval_measure (\<lambda>x. x)" Basis
hoelzl@57447
   380
  proof qed simp
hoelzl@57447
   381
hoelzl@57447
   382
lemma lborel_eq_real: "lborel = interval_measure (\<lambda>x. x)"
hoelzl@57447
   383
  unfolding lborel_def Basis_real_def
hoelzl@57447
   384
  using distr_id[of "interval_measure (\<lambda>x. x)"]
hoelzl@57447
   385
  by (subst distr_component[symmetric])
hoelzl@57447
   386
     (simp_all add: distr_distr comp_def del: distr_id cong: distr_cong)
hoelzl@57447
   387
hoelzl@57447
   388
lemma lborel_eq: "lborel = distr (\<Pi>\<^sub>M b\<in>Basis. lborel) borel (\<lambda>f. \<Sum>b\<in>Basis. f b *\<^sub>R b)"
hoelzl@57447
   389
  by (subst lborel_def) (simp add: lborel_eq_real)
hoelzl@57447
   390
hoelzl@57447
   391
lemma nn_integral_lborel_setprod:
hoelzl@57447
   392
  assumes [measurable]: "\<And>b. b \<in> Basis \<Longrightarrow> f b \<in> borel_measurable borel"
hoelzl@57447
   393
  assumes nn[simp]: "\<And>b x. b \<in> Basis \<Longrightarrow> 0 \<le> f b x"
hoelzl@57447
   394
  shows "(\<integral>\<^sup>+x. (\<Prod>b\<in>Basis. f b (x \<bullet> b)) \<partial>lborel) = (\<Prod>b\<in>Basis. (\<integral>\<^sup>+x. f b x \<partial>lborel))"
hoelzl@57447
   395
  by (simp add: lborel_def nn_integral_distr product_nn_integral_setprod
hoelzl@57447
   396
                product_nn_integral_singleton)
hoelzl@57447
   397
lp15@60615
   398
lemma emeasure_lborel_Icc[simp]:
hoelzl@57447
   399
  fixes l u :: real
hoelzl@57447
   400
  assumes [simp]: "l \<le> u"
hoelzl@57447
   401
  shows "emeasure lborel {l .. u} = u - l"
hoelzl@50526
   402
proof -
hoelzl@57447
   403
  have "((\<lambda>f. f 1) -` {l..u} \<inter> space (Pi\<^sub>M {1} (\<lambda>b. interval_measure (\<lambda>x. x)))) = {1::real} \<rightarrow>\<^sub>E {l..u}"
hoelzl@57447
   404
    by (auto simp: space_PiM)
hoelzl@57447
   405
  then show ?thesis
hoelzl@57447
   406
    by (simp add: lborel_def emeasure_distr emeasure_PiM emeasure_interval_measure_Icc continuous_on_id)
hoelzl@50104
   407
qed
hoelzl@50104
   408
hoelzl@57447
   409
lemma emeasure_lborel_Icc_eq: "emeasure lborel {l .. u} = ereal (if l \<le> u then u - l else 0)"
hoelzl@57447
   410
  by simp
hoelzl@47694
   411
hoelzl@57447
   412
lemma emeasure_lborel_cbox[simp]:
hoelzl@57447
   413
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   414
  shows "emeasure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@41654
   415
proof -
hoelzl@57447
   416
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b .. u\<bullet>b} (x \<bullet> b) :: ereal) = indicator (cbox l u)"
hoelzl@57447
   417
    by (auto simp: fun_eq_iff cbox_def setprod_ereal_0 split: split_indicator)
hoelzl@57447
   418
  then have "emeasure lborel (cbox l u) = (\<integral>\<^sup>+x. (\<Prod>b\<in>Basis. indicator {l\<bullet>b .. u\<bullet>b} (x \<bullet> b)) \<partial>lborel)"
hoelzl@57447
   419
    by simp
hoelzl@57447
   420
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   421
    by (subst nn_integral_lborel_setprod) (simp_all add: setprod_ereal inner_diff_left)
hoelzl@47694
   422
  finally show ?thesis .
hoelzl@38656
   423
qed
hoelzl@38656
   424
hoelzl@57447
   425
lemma AE_lborel_singleton: "AE x in lborel::'a::euclidean_space measure. x \<noteq> c"
haftmann@58787
   426
  using SOME_Basis AE_discrete_difference [of "{c}" lborel]
haftmann@58787
   427
    emeasure_lborel_cbox [of c c] by (auto simp add: cbox_sing)
hoelzl@47757
   428
hoelzl@57447
   429
lemma emeasure_lborel_Ioo[simp]:
hoelzl@57447
   430
  assumes [simp]: "l \<le> u"
hoelzl@57447
   431
  shows "emeasure lborel {l <..< u} = ereal (u - l)"
hoelzl@40859
   432
proof -
hoelzl@57447
   433
  have "emeasure lborel {l <..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   434
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@47694
   435
  then show ?thesis
hoelzl@57447
   436
    by simp
hoelzl@41981
   437
qed
hoelzl@38656
   438
hoelzl@57447
   439
lemma emeasure_lborel_Ioc[simp]:
hoelzl@57447
   440
  assumes [simp]: "l \<le> u"
hoelzl@57447
   441
  shows "emeasure lborel {l <.. u} = ereal (u - l)"
hoelzl@41654
   442
proof -
hoelzl@57447
   443
  have "emeasure lborel {l <.. u} = emeasure lborel {l .. u}"
hoelzl@57447
   444
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   445
  then show ?thesis
hoelzl@57447
   446
    by simp
hoelzl@38656
   447
qed
hoelzl@38656
   448
hoelzl@57447
   449
lemma emeasure_lborel_Ico[simp]:
hoelzl@57447
   450
  assumes [simp]: "l \<le> u"
hoelzl@57447
   451
  shows "emeasure lborel {l ..< u} = ereal (u - l)"
hoelzl@57447
   452
proof -
hoelzl@57447
   453
  have "emeasure lborel {l ..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   454
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   455
  then show ?thesis
hoelzl@57447
   456
    by simp
hoelzl@38656
   457
qed
hoelzl@38656
   458
hoelzl@57447
   459
lemma emeasure_lborel_box[simp]:
hoelzl@57447
   460
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   461
  shows "emeasure lborel (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   462
proof -
hoelzl@57447
   463
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b <..< u\<bullet>b} (x \<bullet> b) :: ereal) = indicator (box l u)"
hoelzl@57447
   464
    by (auto simp: fun_eq_iff box_def setprod_ereal_0 split: split_indicator)
hoelzl@57447
   465
  then have "emeasure lborel (box l u) = (\<integral>\<^sup>+x. (\<Prod>b\<in>Basis. indicator {l\<bullet>b <..< u\<bullet>b} (x \<bullet> b)) \<partial>lborel)"
hoelzl@57447
   466
    by simp
hoelzl@57447
   467
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   468
    by (subst nn_integral_lborel_setprod) (simp_all add: setprod_ereal inner_diff_left)
hoelzl@57447
   469
  finally show ?thesis .
hoelzl@40859
   470
qed
hoelzl@38656
   471
hoelzl@57447
   472
lemma emeasure_lborel_cbox_eq:
hoelzl@57447
   473
  "emeasure lborel (cbox l u) = (if \<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b then \<Prod>b\<in>Basis. (u - l) \<bullet> b else 0)"
hoelzl@57447
   474
  using box_eq_empty(2)[THEN iffD2, of u l] by (auto simp: not_le)
hoelzl@41654
   475
hoelzl@57447
   476
lemma emeasure_lborel_box_eq:
hoelzl@57447
   477
  "emeasure lborel (box l u) = (if \<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b then \<Prod>b\<in>Basis. (u - l) \<bullet> b else 0)"
hoelzl@57447
   478
  using box_eq_empty(1)[THEN iffD2, of u l] by (auto simp: not_le dest!: less_imp_le) force
hoelzl@40859
   479
hoelzl@40859
   480
lemma
hoelzl@57447
   481
  fixes l u :: real
hoelzl@57447
   482
  assumes [simp]: "l \<le> u"
hoelzl@57447
   483
  shows measure_lborel_Icc[simp]: "measure lborel {l .. u} = u - l"
hoelzl@57447
   484
    and measure_lborel_Ico[simp]: "measure lborel {l ..< u} = u - l"
hoelzl@57447
   485
    and measure_lborel_Ioc[simp]: "measure lborel {l <.. u} = u - l"
hoelzl@57447
   486
    and measure_lborel_Ioo[simp]: "measure lborel {l <..< u} = u - l"
hoelzl@57447
   487
  by (simp_all add: measure_def)
hoelzl@40859
   488
lp15@60615
   489
lemma
hoelzl@57447
   490
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   491
  shows measure_lborel_box[simp]: "measure lborel (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   492
    and measure_lborel_cbox[simp]: "measure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   493
  by (simp_all add: measure_def)
hoelzl@41654
   494
hoelzl@57447
   495
lemma sigma_finite_lborel: "sigma_finite_measure lborel"
hoelzl@57447
   496
proof
hoelzl@57447
   497
  show "\<exists>A::'a set set. countable A \<and> A \<subseteq> sets lborel \<and> \<Union>A = space lborel \<and> (\<forall>a\<in>A. emeasure lborel a \<noteq> \<infinity>)"
hoelzl@57447
   498
    by (intro exI[of _ "range (\<lambda>n::nat. box (- real n *\<^sub>R One) (real n *\<^sub>R One))"])
hoelzl@57447
   499
       (auto simp: emeasure_lborel_cbox_eq UN_box_eq_UNIV)
hoelzl@49777
   500
qed
hoelzl@40859
   501
hoelzl@57447
   502
end
hoelzl@41689
   503
hoelzl@57447
   504
lemma emeasure_lborel_UNIV: "emeasure lborel (UNIV::'a::euclidean_space set) = \<infinity>"
lp15@59741
   505
proof -
lp15@59741
   506
  { fix n::nat
lp15@59741
   507
    let ?Ba = "Basis :: 'a set"
lp15@59741
   508
    have "real n \<le> (2::real) ^ card ?Ba * real n"
lp15@59741
   509
      by (simp add: mult_le_cancel_right1)
lp15@60615
   510
    also
lp15@59741
   511
    have "... \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba"
lp15@59741
   512
      apply (rule mult_left_mono)
lp15@59741
   513
      apply (metis DIM_positive One_nat_def less_eq_Suc_le less_imp_le real_of_nat_le_iff real_of_nat_power self_le_power zero_less_Suc)
lp15@59741
   514
      apply (simp add: DIM_positive)
lp15@59741
   515
      done
lp15@59741
   516
    finally have "real n \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba" .
lp15@59741
   517
  } note [intro!] = this
lp15@59741
   518
  show ?thesis
lp15@59741
   519
    unfolding UN_box_eq_UNIV[symmetric]
lp15@59741
   520
    apply (subst SUP_emeasure_incseq[symmetric])
lp15@60615
   521
    apply (auto simp: incseq_def subset_box inner_add_left setprod_constant
lp15@59741
   522
               intro!: SUP_PInfty)
lp15@60615
   523
    done
lp15@59741
   524
qed
hoelzl@40859
   525
hoelzl@57447
   526
lemma emeasure_lborel_singleton[simp]: "emeasure lborel {x} = 0"
hoelzl@57447
   527
  using emeasure_lborel_cbox[of x x] nonempty_Basis
hoelzl@57447
   528
  by (auto simp del: emeasure_lborel_cbox nonempty_Basis simp add: cbox_sing)
hoelzl@56993
   529
hoelzl@57447
   530
lemma emeasure_lborel_countable:
hoelzl@57447
   531
  fixes A :: "'a::euclidean_space set"
hoelzl@57447
   532
  assumes "countable A"
hoelzl@57447
   533
  shows "emeasure lborel A = 0"
hoelzl@57447
   534
proof -
hoelzl@57447
   535
  have "A \<subseteq> (\<Union>i. {from_nat_into A i})" using from_nat_into_surj assms by force
hoelzl@57447
   536
  moreover have "emeasure lborel (\<Union>i. {from_nat_into A i}) = 0"
hoelzl@57447
   537
    by (rule emeasure_UN_eq_0) auto
hoelzl@57447
   538
  ultimately have "emeasure lborel A \<le> 0" using emeasure_mono
hoelzl@57447
   539
    by (metis assms bot.extremum_unique emeasure_empty image_eq_UN range_from_nat_into sets.empty_sets)
hoelzl@57447
   540
  thus ?thesis by (auto simp add: emeasure_le_0_iff)
hoelzl@40859
   541
qed
hoelzl@40859
   542
hoelzl@59425
   543
lemma countable_imp_null_set_lborel: "countable A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   544
  by (simp add: null_sets_def emeasure_lborel_countable sets.countable)
hoelzl@59425
   545
hoelzl@59425
   546
lemma finite_imp_null_set_lborel: "finite A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   547
  by (intro countable_imp_null_set_lborel countable_finite)
hoelzl@59425
   548
hoelzl@59425
   549
lemma lborel_neq_count_space[simp]: "lborel \<noteq> count_space (A::('a::ordered_euclidean_space) set)"
hoelzl@59425
   550
proof
hoelzl@59425
   551
  assume asm: "lborel = count_space A"
hoelzl@59425
   552
  have "space lborel = UNIV" by simp
hoelzl@59425
   553
  hence [simp]: "A = UNIV" by (subst (asm) asm) (simp only: space_count_space)
lp15@60615
   554
  have "emeasure lborel {undefined::'a} = 1"
hoelzl@59425
   555
      by (subst asm, subst emeasure_count_space_finite) auto
hoelzl@59425
   556
  moreover have "emeasure lborel {undefined} \<noteq> 1" by simp
hoelzl@59425
   557
  ultimately show False by contradiction
hoelzl@59425
   558
qed
hoelzl@59425
   559
hoelzl@57447
   560
subsection {* Affine transformation on the Lebesgue-Borel *}
hoelzl@49777
   561
hoelzl@49777
   562
lemma lborel_eqI:
hoelzl@57447
   563
  fixes M :: "'a::euclidean_space measure"
hoelzl@57447
   564
  assumes emeasure_eq: "\<And>l u. (\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b) \<Longrightarrow> emeasure M (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@49777
   565
  assumes sets_eq: "sets M = sets borel"
hoelzl@49777
   566
  shows "lborel = M"
hoelzl@57447
   567
proof (rule measure_eqI_generator_eq)
hoelzl@57447
   568
  let ?E = "range (\<lambda>(a, b). box a b::'a set)"
hoelzl@57447
   569
  show "Int_stable ?E"
hoelzl@57447
   570
    by (auto simp: Int_stable_def box_Int_box)
hoelzl@57447
   571
hoelzl@49777
   572
  show "?E \<subseteq> Pow UNIV" "sets lborel = sigma_sets UNIV ?E" "sets M = sigma_sets UNIV ?E"
hoelzl@57447
   573
    by (simp_all add: borel_eq_box sets_eq)
hoelzl@49777
   574
hoelzl@57447
   575
  let ?A = "\<lambda>n::nat. box (- (real n *\<^sub>R One)) (real n *\<^sub>R One) :: 'a set"
hoelzl@57447
   576
  show "range ?A \<subseteq> ?E" "(\<Union>i. ?A i) = UNIV"
hoelzl@57447
   577
    unfolding UN_box_eq_UNIV by auto
hoelzl@49777
   578
hoelzl@57447
   579
  { fix i show "emeasure lborel (?A i) \<noteq> \<infinity>" by auto }
hoelzl@49777
   580
  { fix X assume "X \<in> ?E" then show "emeasure lborel X = emeasure M X"
hoelzl@57447
   581
      apply (auto simp: emeasure_eq emeasure_lborel_box_eq )
hoelzl@57447
   582
      apply (subst box_eq_empty(1)[THEN iffD2])
hoelzl@57447
   583
      apply (auto intro: less_imp_le simp: not_le)
hoelzl@57447
   584
      done }
hoelzl@49777
   585
qed
hoelzl@49777
   586
hoelzl@57447
   587
lemma lborel_affine:
hoelzl@57447
   588
  fixes t :: "'a::euclidean_space" assumes "c \<noteq> 0"
hoelzl@57447
   589
  shows "lborel = density (distr lborel borel (\<lambda>x. t + c *\<^sub>R x)) (\<lambda>_. \<bar>c\<bar>^DIM('a))" (is "_ = ?D")
hoelzl@49777
   590
proof (rule lborel_eqI)
hoelzl@57447
   591
  let ?B = "Basis :: 'a set"
hoelzl@57447
   592
  fix l u assume le: "\<And>b. b \<in> ?B \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   593
  show "emeasure ?D (box l u) = (\<Prod>b\<in>?B. (u - l) \<bullet> b)"
hoelzl@49777
   594
  proof cases
hoelzl@49777
   595
    assume "0 < c"
hoelzl@57447
   596
    then have "(\<lambda>x. t + c *\<^sub>R x) -` box l u = box ((l - t) /\<^sub>R c) ((u - t) /\<^sub>R c)"
hoelzl@57447
   597
      by (auto simp: field_simps box_def inner_simps)
hoelzl@49777
   598
    with `0 < c` show ?thesis
hoelzl@57447
   599
      using le
hoelzl@57447
   600
      by (auto simp: field_simps emeasure_density nn_integral_distr nn_integral_cmult
hoelzl@57447
   601
                     emeasure_lborel_box_eq inner_simps setprod_dividef setprod_constant
hoelzl@49777
   602
                     borel_measurable_indicator' emeasure_distr)
hoelzl@49777
   603
  next
hoelzl@49777
   604
    assume "\<not> 0 < c" with `c \<noteq> 0` have "c < 0" by auto
hoelzl@57447
   605
    then have "box ((u - t) /\<^sub>R c) ((l - t) /\<^sub>R c) = (\<lambda>x. t + c *\<^sub>R x) -` box l u"
hoelzl@57447
   606
      by (auto simp: field_simps box_def inner_simps)
hoelzl@57447
   607
    then have "\<And>x. indicator (box l u) (t + c *\<^sub>R x) = (indicator (box ((u - t) /\<^sub>R c) ((l - t) /\<^sub>R c)) x :: ereal)"
hoelzl@57447
   608
      by (auto split: split_indicator)
hoelzl@57447
   609
    moreover
lp15@60615
   610
    { have "(- c) ^ card ?B * (\<Prod>x\<in>?B. l \<bullet> x - u \<bullet> x) =
hoelzl@57447
   611
         (-1 * c) ^ card ?B * (\<Prod>x\<in>?B. -1 * (u \<bullet> x - l \<bullet> x))"
hoelzl@57447
   612
         by simp
hoelzl@57447
   613
      also have "\<dots> = (-1 * -1)^card ?B * c ^ card ?B * (\<Prod>x\<in>?B. u \<bullet> x - l \<bullet> x)"
hoelzl@57447
   614
        unfolding setprod.distrib power_mult_distrib by (simp add: setprod_constant)
hoelzl@57447
   615
      finally have "(- c) ^ card ?B * (\<Prod>x\<in>?B. l \<bullet> x - u \<bullet> x) = c ^ card ?B * (\<Prod>b\<in>?B. u \<bullet> b - l \<bullet> b)"
hoelzl@57447
   616
        by simp }
hoelzl@57447
   617
    ultimately show ?thesis
hoelzl@57447
   618
      using `c < 0` le
hoelzl@57447
   619
      by (auto simp: field_simps emeasure_density nn_integral_distr nn_integral_cmult
hoelzl@57447
   620
                     emeasure_lborel_box_eq inner_simps setprod_dividef setprod_constant
hoelzl@57447
   621
                     borel_measurable_indicator' emeasure_distr)
hoelzl@49777
   622
  qed
hoelzl@49777
   623
qed simp
hoelzl@49777
   624
hoelzl@57447
   625
lemma lborel_real_affine:
hoelzl@57447
   626
  "c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c * x)) (\<lambda>_. \<bar>c\<bar>)"
hoelzl@57447
   627
  using lborel_affine[of c t] by simp
hoelzl@57447
   628
lp15@60615
   629
lemma AE_borel_affine:
hoelzl@57447
   630
  fixes P :: "real \<Rightarrow> bool"
hoelzl@57447
   631
  shows "c \<noteq> 0 \<Longrightarrow> Measurable.pred borel P \<Longrightarrow> AE x in lborel. P x \<Longrightarrow> AE x in lborel. P (t + c * x)"
hoelzl@57447
   632
  by (subst lborel_real_affine[where t="- t / c" and c="1 / c"])
hoelzl@57447
   633
     (simp_all add: AE_density AE_distr_iff field_simps)
hoelzl@57447
   634
hoelzl@56996
   635
lemma nn_integral_real_affine:
hoelzl@56993
   636
  fixes c :: real assumes [measurable]: "f \<in> borel_measurable borel" and c: "c \<noteq> 0"
hoelzl@56993
   637
  shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = \<bar>c\<bar> * (\<integral>\<^sup>+x. f (t + c * x) \<partial>lborel)"
hoelzl@56993
   638
  by (subst lborel_real_affine[OF c, of t])
hoelzl@56996
   639
     (simp add: nn_integral_density nn_integral_distr nn_integral_cmult)
hoelzl@56993
   640
hoelzl@56993
   641
lemma lborel_integrable_real_affine:
hoelzl@57447
   642
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   643
  assumes f: "integrable lborel f"
hoelzl@56993
   644
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x))"
hoelzl@56993
   645
  using f f[THEN borel_measurable_integrable] unfolding integrable_iff_bounded
hoelzl@56996
   646
  by (subst (asm) nn_integral_real_affine[where c=c and t=t]) auto
hoelzl@56993
   647
hoelzl@56993
   648
lemma lborel_integrable_real_affine_iff:
hoelzl@56993
   649
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   650
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x)) \<longleftrightarrow> integrable lborel f"
hoelzl@56993
   651
  using
hoelzl@56993
   652
    lborel_integrable_real_affine[of f c t]
hoelzl@56993
   653
    lborel_integrable_real_affine[of "\<lambda>x. f (t + c * x)" "1/c" "-t/c"]
hoelzl@56993
   654
  by (auto simp add: field_simps)
hoelzl@56993
   655
hoelzl@56993
   656
lemma lborel_integral_real_affine:
hoelzl@56993
   657
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}" and c :: real
hoelzl@57166
   658
  assumes c: "c \<noteq> 0" shows "(\<integral>x. f x \<partial> lborel) = \<bar>c\<bar> *\<^sub>R (\<integral>x. f (t + c * x) \<partial>lborel)"
hoelzl@57166
   659
proof cases
hoelzl@57166
   660
  assume f[measurable]: "integrable lborel f" then show ?thesis
hoelzl@57166
   661
    using c f f[THEN borel_measurable_integrable] f[THEN lborel_integrable_real_affine, of c t]
hoelzl@57447
   662
    by (subst lborel_real_affine[OF c, of t])
hoelzl@57447
   663
       (simp add: integral_density integral_distr)
hoelzl@57166
   664
next
hoelzl@57166
   665
  assume "\<not> integrable lborel f" with c show ?thesis
hoelzl@57166
   666
    by (simp add: lborel_integrable_real_affine_iff not_integrable_integral_eq)
hoelzl@57166
   667
qed
hoelzl@56993
   668
lp15@60615
   669
lemma divideR_right:
hoelzl@56993
   670
  fixes x y :: "'a::real_normed_vector"
hoelzl@56993
   671
  shows "r \<noteq> 0 \<Longrightarrow> y = x /\<^sub>R r \<longleftrightarrow> r *\<^sub>R y = x"
hoelzl@56993
   672
  using scaleR_cancel_left[of r y "x /\<^sub>R r"] by simp
hoelzl@56993
   673
hoelzl@56993
   674
lemma lborel_has_bochner_integral_real_affine_iff:
hoelzl@56993
   675
  fixes x :: "'a :: {banach, second_countable_topology}"
hoelzl@56993
   676
  shows "c \<noteq> 0 \<Longrightarrow>
hoelzl@56993
   677
    has_bochner_integral lborel f x \<longleftrightarrow>
hoelzl@56993
   678
    has_bochner_integral lborel (\<lambda>x. f (t + c * x)) (x /\<^sub>R \<bar>c\<bar>)"
hoelzl@56993
   679
  unfolding has_bochner_integral_iff lborel_integrable_real_affine_iff
hoelzl@56993
   680
  by (simp_all add: lborel_integral_real_affine[symmetric] divideR_right cong: conj_cong)
hoelzl@49777
   681
hoelzl@59425
   682
lemma lborel_distr_uminus: "distr lborel borel uminus = (lborel :: real measure)"
lp15@60615
   683
  by (subst lborel_real_affine[of "-1" 0])
hoelzl@59425
   684
     (auto simp: density_1 one_ereal_def[symmetric])
hoelzl@59425
   685
lp15@60615
   686
lemma lborel_distr_mult:
hoelzl@59425
   687
  assumes "(c::real) \<noteq> 0"
hoelzl@59425
   688
  shows "distr lborel borel (op * c) = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   689
proof-
hoelzl@59425
   690
  have "distr lborel borel (op * c) = distr lborel lborel (op * c)" by (simp cong: distr_cong)
hoelzl@59425
   691
  also from assms have "... = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   692
    by (subst lborel_real_affine[of "inverse c" 0]) (auto simp: o_def distr_density_distr)
hoelzl@59425
   693
  finally show ?thesis .
hoelzl@59425
   694
qed
hoelzl@59425
   695
lp15@60615
   696
lemma lborel_distr_mult':
hoelzl@59425
   697
  assumes "(c::real) \<noteq> 0"
hoelzl@59425
   698
  shows "lborel = density (distr lborel borel (op * c)) (\<lambda>_. abs c)"
hoelzl@59425
   699
proof-
hoelzl@59425
   700
  have "lborel = density lborel (\<lambda>_. 1)" by (rule density_1[symmetric])
hoelzl@59425
   701
  also from assms have "(\<lambda>_. 1 :: ereal) = (\<lambda>_. inverse (abs c) * abs c)" by (intro ext) simp
hoelzl@59425
   702
  also have "density lborel ... = density (density lborel (\<lambda>_. inverse (abs c))) (\<lambda>_. abs c)"
hoelzl@59425
   703
    by (subst density_density_eq) auto
hoelzl@59425
   704
  also from assms have "density lborel (\<lambda>_. inverse (abs c)) = distr lborel borel (op * c)"
hoelzl@59425
   705
    by (rule lborel_distr_mult[symmetric])
hoelzl@59425
   706
  finally show ?thesis .
hoelzl@59425
   707
qed
hoelzl@59425
   708
hoelzl@59425
   709
lemma lborel_distr_plus: "distr lborel borel (op + c) = (lborel :: real measure)"
hoelzl@59425
   710
  by (subst lborel_real_affine[of 1 c]) (auto simp: density_1 one_ereal_def[symmetric])
hoelzl@59425
   711
hoelzl@57447
   712
interpretation lborel!: sigma_finite_measure lborel
hoelzl@57447
   713
  by (rule sigma_finite_lborel)
hoelzl@57447
   714
hoelzl@57447
   715
interpretation lborel_pair: pair_sigma_finite lborel lborel ..
hoelzl@57447
   716
hoelzl@59425
   717
lemma lborel_prod:
hoelzl@59425
   718
  "lborel \<Otimes>\<^sub>M lborel = (lborel :: ('a::euclidean_space \<times> 'b::euclidean_space) measure)"
hoelzl@59425
   719
proof (rule lborel_eqI[symmetric], clarify)
hoelzl@59425
   720
  fix la ua :: 'a and lb ub :: 'b
hoelzl@59425
   721
  assume lu: "\<And>a b. (a, b) \<in> Basis \<Longrightarrow> (la, lb) \<bullet> (a, b) \<le> (ua, ub) \<bullet> (a, b)"
hoelzl@59425
   722
  have [simp]:
hoelzl@59425
   723
    "\<And>b. b \<in> Basis \<Longrightarrow> la \<bullet> b \<le> ua \<bullet> b"
hoelzl@59425
   724
    "\<And>b. b \<in> Basis \<Longrightarrow> lb \<bullet> b \<le> ub \<bullet> b"
hoelzl@59425
   725
    "inj_on (\<lambda>u. (u, 0)) Basis" "inj_on (\<lambda>u. (0, u)) Basis"
hoelzl@59425
   726
    "(\<lambda>u. (u, 0)) ` Basis \<inter> (\<lambda>u. (0, u)) ` Basis = {}"
hoelzl@59425
   727
    "box (la, lb) (ua, ub) = box la ua \<times> box lb ub"
hoelzl@59425
   728
    using lu[of _ 0] lu[of 0] by (auto intro!: inj_onI simp add: Basis_prod_def ball_Un box_def)
hoelzl@59425
   729
  show "emeasure (lborel \<Otimes>\<^sub>M lborel) (box (la, lb) (ua, ub)) =
hoelzl@59425
   730
      ereal (setprod (op \<bullet> ((ua, ub) - (la, lb))) Basis)"
hoelzl@59425
   731
    by (simp add: lborel.emeasure_pair_measure_Times Basis_prod_def setprod.union_disjoint
hoelzl@59425
   732
                  setprod.reindex)
hoelzl@59425
   733
qed (simp add: borel_prod[symmetric])
hoelzl@59425
   734
hoelzl@57447
   735
(* FIXME: conversion in measurable prover *)
hoelzl@57447
   736
lemma lborelD_Collect[measurable (raw)]: "{x\<in>space borel. P x} \<in> sets borel \<Longrightarrow> {x\<in>space lborel. P x} \<in> sets lborel" by simp
hoelzl@57447
   737
lemma lborelD[measurable (raw)]: "A \<in> sets borel \<Longrightarrow> A \<in> sets lborel" by simp
hoelzl@57447
   738
hoelzl@57447
   739
subsection {* Equivalence Lebesgue integral on @{const lborel} and HK-integral *}
hoelzl@41706
   740
hoelzl@57447
   741
lemma has_integral_measure_lborel:
hoelzl@57447
   742
  fixes A :: "'a::euclidean_space set"
hoelzl@57447
   743
  assumes A[measurable]: "A \<in> sets borel" and finite: "emeasure lborel A < \<infinity>"
hoelzl@57447
   744
  shows "((\<lambda>x. 1) has_integral measure lborel A) A"
hoelzl@57447
   745
proof -
hoelzl@57447
   746
  { fix l u :: 'a
hoelzl@57447
   747
    have "((\<lambda>x. 1) has_integral measure lborel (box l u)) (box l u)"
hoelzl@57447
   748
    proof cases
hoelzl@57447
   749
      assume "\<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   750
      then show ?thesis
hoelzl@57447
   751
        apply simp
hoelzl@57447
   752
        apply (subst has_integral_restrict[symmetric, OF box_subset_cbox])
hoelzl@57447
   753
        apply (subst has_integral_spike_interior_eq[where g="\<lambda>_. 1"])
hoelzl@57447
   754
        using has_integral_const[of "1::real" l u]
hoelzl@57447
   755
        apply (simp_all add: inner_diff_left[symmetric] content_cbox_cases)
hoelzl@57447
   756
        done
hoelzl@57447
   757
    next
hoelzl@57447
   758
      assume "\<not> (\<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b)"
hoelzl@57447
   759
      then have "box l u = {}"
hoelzl@57447
   760
        unfolding box_eq_empty by (auto simp: not_le intro: less_imp_le)
hoelzl@57447
   761
      then show ?thesis
hoelzl@57447
   762
        by simp
hoelzl@57447
   763
    qed }
hoelzl@57447
   764
  note has_integral_box = this
hoelzl@56993
   765
hoelzl@57447
   766
  { fix a b :: 'a let ?M = "\<lambda>A. measure lborel (A \<inter> box a b)"
hoelzl@57447
   767
    have "Int_stable  (range (\<lambda>(a, b). box a b))"
hoelzl@57447
   768
      by (auto simp: Int_stable_def box_Int_box)
hoelzl@57447
   769
    moreover have "(range (\<lambda>(a, b). box a b)) \<subseteq> Pow UNIV"
hoelzl@57447
   770
      by auto
hoelzl@57447
   771
    moreover have "A \<in> sigma_sets UNIV (range (\<lambda>(a, b). box a b))"
hoelzl@57447
   772
       using A unfolding borel_eq_box by simp
hoelzl@57447
   773
    ultimately have "((\<lambda>x. 1) has_integral ?M A) (A \<inter> box a b)"
hoelzl@57447
   774
    proof (induction rule: sigma_sets_induct_disjoint)
hoelzl@57447
   775
      case (basic A) then show ?case
hoelzl@57447
   776
        by (auto simp: box_Int_box has_integral_box)
hoelzl@57447
   777
    next
hoelzl@57447
   778
      case empty then show ?case
hoelzl@57447
   779
        by simp
hoelzl@57447
   780
    next
hoelzl@57447
   781
      case (compl A)
hoelzl@57447
   782
      then have [measurable]: "A \<in> sets borel"
hoelzl@57447
   783
        by (simp add: borel_eq_box)
hoelzl@56993
   784
hoelzl@57447
   785
      have "((\<lambda>x. 1) has_integral ?M (box a b)) (box a b)"
hoelzl@57447
   786
        by (simp add: has_integral_box)
hoelzl@57447
   787
      moreover have "((\<lambda>x. if x \<in> A \<inter> box a b then 1 else 0) has_integral ?M A) (box a b)"
hoelzl@57447
   788
        by (subst has_integral_restrict) (auto intro: compl)
hoelzl@57447
   789
      ultimately have "((\<lambda>x. 1 - (if x \<in> A \<inter> box a b then 1 else 0)) has_integral ?M (box a b) - ?M A) (box a b)"
hoelzl@57447
   790
        by (rule has_integral_sub)
hoelzl@57447
   791
      then have "((\<lambda>x. (if x \<in> (UNIV - A) \<inter> box a b then 1 else 0)) has_integral ?M (box a b) - ?M A) (box a b)"
lp15@60615
   792
        by (rule has_integral_cong[THEN iffD1, rotated 1]) auto
hoelzl@57447
   793
      then have "((\<lambda>x. 1) has_integral ?M (box a b) - ?M A) ((UNIV - A) \<inter> box a b)"
hoelzl@57447
   794
        by (subst (asm) has_integral_restrict) auto
hoelzl@57447
   795
      also have "?M (box a b) - ?M A = ?M (UNIV - A)"
hoelzl@57447
   796
        by (subst measure_Diff[symmetric]) (auto simp: emeasure_lborel_box_eq Diff_Int_distrib2)
hoelzl@57447
   797
      finally show ?case .
hoelzl@57447
   798
    next
hoelzl@57447
   799
      case (union F)
hoelzl@57447
   800
      then have [measurable]: "\<And>i. F i \<in> sets borel"
hoelzl@57447
   801
        by (simp add: borel_eq_box subset_eq)
hoelzl@57447
   802
      have "((\<lambda>x. if x \<in> UNION UNIV F \<inter> box a b then 1 else 0) has_integral ?M (\<Union>i. F i)) (box a b)"
hoelzl@57447
   803
      proof (rule has_integral_monotone_convergence_increasing)
hoelzl@57447
   804
        let ?f = "\<lambda>k x. \<Sum>i<k. if x \<in> F i \<inter> box a b then 1 else 0 :: real"
hoelzl@57447
   805
        show "\<And>k. (?f k has_integral (\<Sum>i<k. ?M (F i))) (box a b)"
hoelzl@57447
   806
          using union.IH by (auto intro!: has_integral_setsum simp del: Int_iff)
hoelzl@57447
   807
        show "\<And>k x. ?f k x \<le> ?f (Suc k) x"
hoelzl@57447
   808
          by (intro setsum_mono2) auto
hoelzl@57447
   809
        from union(1) have *: "\<And>x i j. x \<in> F i \<Longrightarrow> x \<in> F j \<longleftrightarrow> j = i"
hoelzl@57447
   810
          by (auto simp add: disjoint_family_on_def)
hoelzl@57447
   811
        show "\<And>x. (\<lambda>k. ?f k x) ----> (if x \<in> UNION UNIV F \<inter> box a b then 1 else 0)"
hoelzl@57447
   812
          apply (auto simp: * setsum.If_cases Iio_Int_singleton)
hoelzl@57447
   813
          apply (rule_tac k="Suc xa" in LIMSEQ_offset)
hoelzl@57447
   814
          apply (simp add: tendsto_const)
hoelzl@57447
   815
          done
hoelzl@57447
   816
        have *: "emeasure lborel ((\<Union>x. F x) \<inter> box a b) \<le> emeasure lborel (box a b)"
hoelzl@57447
   817
          by (intro emeasure_mono) auto
hoelzl@57447
   818
hoelzl@57447
   819
        with union(1) show "(\<lambda>k. \<Sum>i<k. ?M (F i)) ----> ?M (\<Union>i. F i)"
hoelzl@57447
   820
          unfolding sums_def[symmetric] UN_extend_simps
hoelzl@57447
   821
          by (intro measure_UNION) (auto simp: disjoint_family_on_def emeasure_lborel_box_eq)
hoelzl@57447
   822
      qed
hoelzl@57447
   823
      then show ?case
hoelzl@57447
   824
        by (subst (asm) has_integral_restrict) auto
hoelzl@57447
   825
    qed }
hoelzl@57447
   826
  note * = this
hoelzl@57447
   827
hoelzl@57447
   828
  show ?thesis
hoelzl@57447
   829
  proof (rule has_integral_monotone_convergence_increasing)
hoelzl@57447
   830
    let ?B = "\<lambda>n::nat. box (- real n *\<^sub>R One) (real n *\<^sub>R One) :: 'a set"
hoelzl@57447
   831
    let ?f = "\<lambda>n::nat. \<lambda>x. if x \<in> A \<inter> ?B n then 1 else 0 :: real"
hoelzl@57447
   832
    let ?M = "\<lambda>n. measure lborel (A \<inter> ?B n)"
hoelzl@57447
   833
hoelzl@57447
   834
    show "\<And>n::nat. (?f n has_integral ?M n) A"
hoelzl@57447
   835
      using * by (subst has_integral_restrict) simp_all
hoelzl@57447
   836
    show "\<And>k x. ?f k x \<le> ?f (Suc k) x"
hoelzl@57447
   837
      by (auto simp: box_def)
hoelzl@57447
   838
    { fix x assume "x \<in> A"
hoelzl@57447
   839
      moreover have "(\<lambda>k. indicator (A \<inter> ?B k) x :: real) ----> indicator (\<Union>k::nat. A \<inter> ?B k) x"
hoelzl@57447
   840
        by (intro LIMSEQ_indicator_incseq) (auto simp: incseq_def box_def)
hoelzl@57447
   841
      ultimately show "(\<lambda>k. if x \<in> A \<inter> ?B k then 1 else 0::real) ----> 1"
hoelzl@57447
   842
        by (simp add: indicator_def UN_box_eq_UNIV) }
hoelzl@57447
   843
hoelzl@57447
   844
    have "(\<lambda>n. emeasure lborel (A \<inter> ?B n)) ----> emeasure lborel (\<Union>n::nat. A \<inter> ?B n)"
hoelzl@57447
   845
      by (intro Lim_emeasure_incseq) (auto simp: incseq_def box_def)
hoelzl@57447
   846
    also have "(\<lambda>n. emeasure lborel (A \<inter> ?B n)) = (\<lambda>n. measure lborel (A \<inter> ?B n))"
hoelzl@57447
   847
    proof (intro ext emeasure_eq_ereal_measure)
hoelzl@57447
   848
      fix n have "emeasure lborel (A \<inter> ?B n) \<le> emeasure lborel (?B n)"
hoelzl@57447
   849
        by (intro emeasure_mono) auto
hoelzl@57447
   850
      then show "emeasure lborel (A \<inter> ?B n) \<noteq> \<infinity>"
hoelzl@57447
   851
        by auto
hoelzl@57447
   852
    qed
hoelzl@57447
   853
    finally show "(\<lambda>n. measure lborel (A \<inter> ?B n)) ----> measure lborel A"
hoelzl@57447
   854
      using emeasure_eq_ereal_measure[of lborel A] finite
hoelzl@57447
   855
      by (simp add: UN_box_eq_UNIV)
hoelzl@41654
   856
  qed
hoelzl@40859
   857
qed
hoelzl@40859
   858
hoelzl@56996
   859
lemma nn_integral_has_integral:
hoelzl@57447
   860
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@57447
   861
  assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) = ereal r"
hoelzl@56993
   862
  shows "(f has_integral r) UNIV"
hoelzl@56993
   863
using f proof (induct arbitrary: r rule: borel_measurable_induct_real)
hoelzl@57447
   864
  case (set A)
hoelzl@57447
   865
  moreover then have "((\<lambda>x. 1) has_integral measure lborel A) A"
hoelzl@57447
   866
    by (intro has_integral_measure_lborel) (auto simp: ereal_indicator)
hoelzl@57447
   867
  ultimately show ?case
hoelzl@57447
   868
    by (simp add: ereal_indicator measure_def) (simp add: indicator_def)
hoelzl@56993
   869
next
hoelzl@56993
   870
  case (mult g c)
hoelzl@57447
   871
  then have "ereal c * (\<integral>\<^sup>+ x. g x \<partial>lborel) = ereal r"
hoelzl@56996
   872
    by (subst nn_integral_cmult[symmetric]) auto
hoelzl@57447
   873
  then obtain r' where "(c = 0 \<and> r = 0) \<or> ((\<integral>\<^sup>+ x. ereal (g x) \<partial>lborel) = ereal r' \<and> r = c * r')"
hoelzl@57447
   874
    by (cases "\<integral>\<^sup>+ x. ereal (g x) \<partial>lborel") (auto split: split_if_asm)
hoelzl@56993
   875
  with mult show ?case
hoelzl@56993
   876
    by (auto intro!: has_integral_cmult_real)
hoelzl@56993
   877
next
hoelzl@56993
   878
  case (add g h)
hoelzl@56993
   879
  moreover
hoelzl@57447
   880
  then have "(\<integral>\<^sup>+ x. h x + g x \<partial>lborel) = (\<integral>\<^sup>+ x. h x \<partial>lborel) + (\<integral>\<^sup>+ x. g x \<partial>lborel)"
hoelzl@56996
   881
    unfolding plus_ereal.simps[symmetric] by (subst nn_integral_add) auto
hoelzl@57447
   882
  with add obtain a b where "(\<integral>\<^sup>+ x. h x \<partial>lborel) = ereal a" "(\<integral>\<^sup>+ x. g x \<partial>lborel) = ereal b" "r = a + b"
hoelzl@57447
   883
    by (cases "\<integral>\<^sup>+ x. h x \<partial>lborel" "\<integral>\<^sup>+ x. g x \<partial>lborel" rule: ereal2_cases) auto
hoelzl@56993
   884
  ultimately show ?case
hoelzl@56993
   885
    by (auto intro!: has_integral_add)
hoelzl@56993
   886
next
hoelzl@56993
   887
  case (seq U)
hoelzl@56993
   888
  note seq(1)[measurable] and f[measurable]
hoelzl@40859
   889
lp15@60615
   890
  { fix i x
hoelzl@56993
   891
    have "U i x \<le> f x"
hoelzl@56993
   892
      using seq(5)
hoelzl@56993
   893
      apply (rule LIMSEQ_le_const)
hoelzl@56993
   894
      using seq(4)
hoelzl@56993
   895
      apply (auto intro!: exI[of _ i] simp: incseq_def le_fun_def)
hoelzl@56993
   896
      done }
hoelzl@56993
   897
  note U_le_f = this
lp15@60615
   898
hoelzl@56993
   899
  { fix i
hoelzl@57447
   900
    have "(\<integral>\<^sup>+x. ereal (U i x) \<partial>lborel) \<le> (\<integral>\<^sup>+x. ereal (f x) \<partial>lborel)"
hoelzl@56996
   901
      using U_le_f by (intro nn_integral_mono) simp
hoelzl@57447
   902
    then obtain p where "(\<integral>\<^sup>+x. U i x \<partial>lborel) = ereal p" "p \<le> r"
hoelzl@57447
   903
      using seq(6) by (cases "\<integral>\<^sup>+x. U i x \<partial>lborel") auto
hoelzl@56993
   904
    moreover then have "0 \<le> p"
hoelzl@56996
   905
      by (metis ereal_less_eq(5) nn_integral_nonneg)
hoelzl@56993
   906
    moreover note seq
hoelzl@57447
   907
    ultimately have "\<exists>p. (\<integral>\<^sup>+x. U i x \<partial>lborel) = ereal p \<and> 0 \<le> p \<and> p \<le> r \<and> (U i has_integral p) UNIV"
hoelzl@56993
   908
      by auto }
hoelzl@57447
   909
  then obtain p where p: "\<And>i. (\<integral>\<^sup>+x. ereal (U i x) \<partial>lborel) = ereal (p i)"
hoelzl@56993
   910
    and bnd: "\<And>i. p i \<le> r" "\<And>i. 0 \<le> p i"
hoelzl@56993
   911
    and U_int: "\<And>i.(U i has_integral (p i)) UNIV" by metis
hoelzl@56993
   912
hoelzl@56993
   913
  have int_eq: "\<And>i. integral UNIV (U i) = p i" using U_int by (rule integral_unique)
hoelzl@56993
   914
hoelzl@56993
   915
  have *: "f integrable_on UNIV \<and> (\<lambda>k. integral UNIV (U k)) ----> integral UNIV f"
hoelzl@56993
   916
  proof (rule monotone_convergence_increasing)
hoelzl@56993
   917
    show "\<forall>k. U k integrable_on UNIV" using U_int by auto
hoelzl@56993
   918
    show "\<forall>k. \<forall>x\<in>UNIV. U k x \<le> U (Suc k) x" using `incseq U` by (auto simp: incseq_def le_fun_def)
hoelzl@56993
   919
    then show "bounded {integral UNIV (U k) |k. True}"
hoelzl@56993
   920
      using bnd int_eq by (auto simp: bounded_real intro!: exI[of _ r])
hoelzl@56993
   921
    show "\<forall>x\<in>UNIV. (\<lambda>k. U k x) ----> f x"
hoelzl@56993
   922
      using seq by auto
hoelzl@41981
   923
  qed
hoelzl@57447
   924
  moreover have "(\<lambda>i. (\<integral>\<^sup>+x. U i x \<partial>lborel)) ----> (\<integral>\<^sup>+x. f x \<partial>lborel)"
hoelzl@56996
   925
    using seq U_le_f by (intro nn_integral_dominated_convergence[where w=f]) auto
hoelzl@56993
   926
  ultimately have "integral UNIV f = r"
hoelzl@56993
   927
    by (auto simp add: int_eq p seq intro: LIMSEQ_unique)
hoelzl@56993
   928
  with * show ?case
hoelzl@56993
   929
    by (simp add: has_integral_integral)
hoelzl@40859
   930
qed
hoelzl@40859
   931
hoelzl@57447
   932
lemma nn_integral_lborel_eq_integral:
hoelzl@57447
   933
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@57447
   934
  assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) < \<infinity>"
hoelzl@57447
   935
  shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = integral UNIV f"
hoelzl@57447
   936
proof -
hoelzl@57447
   937
  from f(3) obtain r where r: "(\<integral>\<^sup>+x. f x \<partial>lborel) = ereal r"
hoelzl@57447
   938
    by (cases "\<integral>\<^sup>+x. f x \<partial>lborel") auto
hoelzl@57447
   939
  then show ?thesis
hoelzl@57447
   940
    using nn_integral_has_integral[OF f(1,2) r] by (simp add: integral_unique)
hoelzl@57447
   941
qed
hoelzl@57447
   942
hoelzl@57447
   943
lemma nn_integral_integrable_on:
hoelzl@57447
   944
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@57447
   945
  assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) < \<infinity>"
hoelzl@57447
   946
  shows "f integrable_on UNIV"
hoelzl@57447
   947
proof -
hoelzl@57447
   948
  from f(3) obtain r where r: "(\<integral>\<^sup>+x. f x \<partial>lborel) = ereal r"
hoelzl@57447
   949
    by (cases "\<integral>\<^sup>+x. f x \<partial>lborel") auto
hoelzl@57447
   950
  then show ?thesis
hoelzl@57447
   951
    by (intro has_integral_integrable[where i=r] nn_integral_has_integral[where r=r] f)
hoelzl@57447
   952
qed
hoelzl@57447
   953
lp15@60615
   954
lemma nn_integral_has_integral_lborel:
hoelzl@57447
   955
  fixes f :: "'a::euclidean_space \<Rightarrow> real"
hoelzl@57447
   956
  assumes f_borel: "f \<in> borel_measurable borel" and nonneg: "\<And>x. 0 \<le> f x"
hoelzl@57447
   957
  assumes I: "(f has_integral I) UNIV"
hoelzl@57447
   958
  shows "integral\<^sup>N lborel f = I"
hoelzl@57447
   959
proof -
hoelzl@57447
   960
  from f_borel have "(\<lambda>x. ereal (f x)) \<in> borel_measurable lborel" by auto
hoelzl@57447
   961
  from borel_measurable_implies_simple_function_sequence'[OF this] guess F . note F = this
hoelzl@57447
   962
  let ?B = "\<lambda>i::nat. box (- (real i *\<^sub>R One)) (real i *\<^sub>R One) :: 'a set"
hoelzl@57447
   963
hoelzl@57447
   964
  note F(1)[THEN borel_measurable_simple_function, measurable]
hoelzl@57447
   965
hoelzl@57447
   966
  { fix i x have "real (F i x) \<le> f x"
hoelzl@57447
   967
      using F(3,5) F(4)[of x, symmetric] nonneg
hoelzl@57447
   968
      unfolding real_le_ereal_iff
hoelzl@57447
   969
      by (auto simp: image_iff eq_commute[of \<infinity>] max_def intro: SUP_upper split: split_if_asm) }
hoelzl@57447
   970
  note F_le_f = this
hoelzl@57447
   971
  let ?F = "\<lambda>i x. F i x * indicator (?B i) x"
hoelzl@57447
   972
  have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lborel) = (SUP i. integral\<^sup>N lborel (\<lambda>x. ?F i x))"
hoelzl@57447
   973
  proof (subst nn_integral_monotone_convergence_SUP[symmetric])
hoelzl@57447
   974
    { fix x
hoelzl@57447
   975
      obtain j where j: "x \<in> ?B j"
hoelzl@57447
   976
        using UN_box_eq_UNIV by auto
hoelzl@56993
   977
hoelzl@57447
   978
      have "ereal (f x) = (SUP i. F i x)"
hoelzl@57447
   979
        using F(4)[of x] nonneg[of x] by (simp add: max_def)
hoelzl@57447
   980
      also have "\<dots> = (SUP i. ?F i x)"
hoelzl@57447
   981
      proof (rule SUP_eq)
hoelzl@57447
   982
        fix i show "\<exists>j\<in>UNIV. F i x \<le> ?F j x"
hoelzl@57447
   983
          using j F(2)
hoelzl@57447
   984
          by (intro bexI[of _ "max i j"])
hoelzl@57447
   985
             (auto split: split_max split_indicator simp: incseq_def le_fun_def box_def)
hoelzl@57447
   986
      qed (auto intro!: F split: split_indicator)
hoelzl@57447
   987
      finally have "ereal (f x) =  (SUP i. ?F i x)" . }
hoelzl@57447
   988
    then show "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lborel) = (\<integral>\<^sup>+ x. (SUP i. ?F i x) \<partial>lborel)"
hoelzl@57447
   989
      by simp
hoelzl@57447
   990
  qed (insert F, auto simp: incseq_def le_fun_def box_def split: split_indicator)
hoelzl@57447
   991
  also have "\<dots> \<le> ereal I"
hoelzl@57447
   992
  proof (rule SUP_least)
hoelzl@57447
   993
    fix i :: nat
hoelzl@57447
   994
    have finite_F: "(\<integral>\<^sup>+ x. ereal (real (F i x) * indicator (?B i) x) \<partial>lborel) < \<infinity>"
hoelzl@57447
   995
    proof (rule nn_integral_bound_simple_function)
hoelzl@57447
   996
      have "emeasure lborel {x \<in> space lborel. ereal (real (F i x) * indicator (?B i) x) \<noteq> 0} \<le>
hoelzl@57447
   997
        emeasure lborel (?B i)"
hoelzl@57447
   998
        by (intro emeasure_mono)  (auto split: split_indicator)
lp15@60615
   999
      then show "emeasure lborel {x \<in> space lborel. ereal (real (F i x) * indicator (?B i) x) \<noteq> 0} < \<infinity>"
hoelzl@57447
  1000
        by auto
hoelzl@57447
  1001
    qed (auto split: split_indicator
hoelzl@57447
  1002
              intro!: real_of_ereal_pos F simple_function_compose1[where g="real"] simple_function_ereal)
hoelzl@57447
  1003
hoelzl@57447
  1004
    have int_F: "(\<lambda>x. real (F i x) * indicator (?B i) x) integrable_on UNIV"
hoelzl@57447
  1005
      using F(5) finite_F
hoelzl@57447
  1006
      by (intro nn_integral_integrable_on) (auto split: split_indicator intro: real_of_ereal_pos)
lp15@60615
  1007
lp15@60615
  1008
    have "(\<integral>\<^sup>+ x. F i x * indicator (?B i) x \<partial>lborel) =
hoelzl@57447
  1009
      (\<integral>\<^sup>+ x. ereal (real (F i x) * indicator (?B i) x) \<partial>lborel)"
hoelzl@57447
  1010
      using F(3,5)
hoelzl@57447
  1011
      by (intro nn_integral_cong) (auto simp: image_iff ereal_real eq_commute split: split_indicator)
hoelzl@57447
  1012
    also have "\<dots> = ereal (integral UNIV (\<lambda>x. real (F i x) * indicator (?B i) x))"
hoelzl@57447
  1013
      using F
hoelzl@57447
  1014
      by (intro nn_integral_lborel_eq_integral[OF _ _ finite_F])
hoelzl@57447
  1015
         (auto split: split_indicator intro: real_of_ereal_pos)
hoelzl@57447
  1016
    also have "\<dots> \<le> ereal I"
hoelzl@57447
  1017
      by (auto intro!: has_integral_le[OF integrable_integral[OF int_F] I] nonneg F_le_f
hoelzl@57447
  1018
          split: split_indicator )
hoelzl@57447
  1019
    finally show "(\<integral>\<^sup>+ x. F i x * indicator (?B i) x \<partial>lborel) \<le> ereal I" .
hoelzl@57447
  1020
  qed
hoelzl@57447
  1021
  finally have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lborel) < \<infinity>"
hoelzl@57447
  1022
    by auto
hoelzl@57447
  1023
  from nn_integral_lborel_eq_integral[OF assms(1,2) this] I show ?thesis
hoelzl@57447
  1024
    by (simp add: integral_unique)
hoelzl@57447
  1025
qed
hoelzl@57447
  1026
hoelzl@57447
  1027
lemma has_integral_iff_emeasure_lborel:
hoelzl@57447
  1028
  fixes A :: "'a::euclidean_space set"
hoelzl@57447
  1029
  assumes A[measurable]: "A \<in> sets borel"
hoelzl@57447
  1030
  shows "((\<lambda>x. 1) has_integral r) A \<longleftrightarrow> emeasure lborel A = ereal r"
hoelzl@57447
  1031
proof cases
hoelzl@57447
  1032
  assume emeasure_A: "emeasure lborel A = \<infinity>"
hoelzl@57447
  1033
  have "\<not> (\<lambda>x. 1::real) integrable_on A"
hoelzl@57447
  1034
  proof
hoelzl@57447
  1035
    assume int: "(\<lambda>x. 1::real) integrable_on A"
hoelzl@57447
  1036
    then have "(indicator A::'a \<Rightarrow> real) integrable_on UNIV"
hoelzl@57447
  1037
      unfolding indicator_def[abs_def] integrable_restrict_univ .
hoelzl@57447
  1038
    then obtain r where "((indicator A::'a\<Rightarrow>real) has_integral r) UNIV"
hoelzl@57447
  1039
      by auto
hoelzl@57447
  1040
    from nn_integral_has_integral_lborel[OF _ _ this] emeasure_A show False
hoelzl@57447
  1041
      by (simp add: ereal_indicator)
hoelzl@57447
  1042
  qed
hoelzl@57447
  1043
  with emeasure_A show ?thesis
hoelzl@57447
  1044
    by auto
hoelzl@57447
  1045
next
hoelzl@57447
  1046
  assume "emeasure lborel A \<noteq> \<infinity>"
hoelzl@57447
  1047
  moreover then have "((\<lambda>x. 1) has_integral measure lborel A) A"
hoelzl@57447
  1048
    by (simp add: has_integral_measure_lborel)
hoelzl@57447
  1049
  ultimately show ?thesis
hoelzl@57447
  1050
    by (auto simp: emeasure_eq_ereal_measure has_integral_unique)
hoelzl@57447
  1051
qed
hoelzl@57447
  1052
hoelzl@57447
  1053
lemma has_integral_integral_real:
hoelzl@57447
  1054
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@57447
  1055
  assumes f: "integrable lborel f"
hoelzl@57447
  1056
  shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
hoelzl@56993
  1057
using f proof induct
hoelzl@56993
  1058
  case (base A c) then show ?case
hoelzl@57447
  1059
    by (auto intro!: has_integral_mult_left simp: )
hoelzl@57447
  1060
       (simp add: emeasure_eq_ereal_measure indicator_def has_integral_measure_lborel)
hoelzl@56993
  1061
next
hoelzl@56993
  1062
  case (add f g) then show ?case
hoelzl@56993
  1063
    by (auto intro!: has_integral_add)
hoelzl@56993
  1064
next
hoelzl@56993
  1065
  case (lim f s)
hoelzl@56993
  1066
  show ?case
hoelzl@56993
  1067
  proof (rule has_integral_dominated_convergence)
hoelzl@57447
  1068
    show "\<And>i. (s i has_integral integral\<^sup>L lborel (s i)) UNIV" by fact
hoelzl@56993
  1069
    show "(\<lambda>x. norm (2 * f x)) integrable_on UNIV"
hoelzl@57447
  1070
      using `integrable lborel f`
hoelzl@57447
  1071
      by (intro nn_integral_integrable_on)
hoelzl@57447
  1072
         (auto simp: integrable_iff_bounded abs_mult times_ereal.simps(1)[symmetric] nn_integral_cmult
hoelzl@57447
  1073
               simp del: times_ereal.simps)
hoelzl@56993
  1074
    show "\<And>k. \<forall>x\<in>UNIV. norm (s k x) \<le> norm (2 * f x)"
hoelzl@56993
  1075
      using lim by (auto simp add: abs_mult)
hoelzl@56993
  1076
    show "\<forall>x\<in>UNIV. (\<lambda>k. s k x) ----> f x"
hoelzl@56993
  1077
      using lim by auto
hoelzl@57447
  1078
    show "(\<lambda>k. integral\<^sup>L lborel (s k)) ----> integral\<^sup>L lborel f"
hoelzl@57447
  1079
      using lim lim(1)[THEN borel_measurable_integrable]
hoelzl@57447
  1080
      by (intro integral_dominated_convergence[where w="\<lambda>x. 2 * norm (f x)"]) auto
hoelzl@56993
  1081
  qed
hoelzl@40859
  1082
qed
hoelzl@40859
  1083
hoelzl@57447
  1084
context
hoelzl@57447
  1085
  fixes f::"'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@57447
  1086
begin
hoelzl@41546
  1087
hoelzl@57447
  1088
lemma has_integral_integral_lborel:
hoelzl@57447
  1089
  assumes f: "integrable lborel f"
wenzelm@53015
  1090
  shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
hoelzl@41546
  1091
proof -
hoelzl@57447
  1092
  have "((\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) has_integral (\<Sum>b\<in>Basis. integral\<^sup>L lborel (\<lambda>x. f x \<bullet> b) *\<^sub>R b)) UNIV"
hoelzl@57447
  1093
    using f by (intro has_integral_setsum finite_Basis ballI has_integral_scaleR_left has_integral_integral_real) auto
hoelzl@57447
  1094
  also have eq_f: "(\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) = f"
hoelzl@57447
  1095
    by (simp add: fun_eq_iff euclidean_representation)
hoelzl@57447
  1096
  also have "(\<Sum>b\<in>Basis. integral\<^sup>L lborel (\<lambda>x. f x \<bullet> b) *\<^sub>R b) = integral\<^sup>L lborel f"
hoelzl@57447
  1097
    using f by (subst (2) eq_f[symmetric]) simp
hoelzl@56993
  1098
  finally show ?thesis .
hoelzl@56993
  1099
qed
hoelzl@56993
  1100
hoelzl@57447
  1101
lemma integrable_on_lborel: "integrable lborel f \<Longrightarrow> f integrable_on UNIV"
hoelzl@57447
  1102
  using has_integral_integral_lborel by (auto intro: has_integral_integrable)
lp15@60615
  1103
hoelzl@57447
  1104
lemma integral_lborel: "integrable lborel f \<Longrightarrow> integral UNIV f = (\<integral>x. f x \<partial>lborel)"
hoelzl@57447
  1105
  using has_integral_integral_lborel by auto
hoelzl@49777
  1106
hoelzl@57447
  1107
end
hoelzl@50418
  1108
hoelzl@50418
  1109
subsection {* Fundamental Theorem of Calculus for the Lebesgue integral *}
hoelzl@50418
  1110
hoelzl@57138
  1111
lemma emeasure_bounded_finite:
hoelzl@57138
  1112
  assumes "bounded A" shows "emeasure lborel A < \<infinity>"
hoelzl@57138
  1113
proof -
hoelzl@57138
  1114
  from bounded_subset_cbox[OF `bounded A`] obtain a b where "A \<subseteq> cbox a b"
hoelzl@57138
  1115
    by auto
hoelzl@57138
  1116
  then have "emeasure lborel A \<le> emeasure lborel (cbox a b)"
hoelzl@57138
  1117
    by (intro emeasure_mono) auto
hoelzl@57138
  1118
  then show ?thesis
hoelzl@57447
  1119
    by (auto simp: emeasure_lborel_cbox_eq)
hoelzl@57138
  1120
qed
hoelzl@57138
  1121
hoelzl@57138
  1122
lemma emeasure_compact_finite: "compact A \<Longrightarrow> emeasure lborel A < \<infinity>"
hoelzl@57138
  1123
  using emeasure_bounded_finite[of A] by (auto intro: compact_imp_bounded)
hoelzl@57138
  1124
hoelzl@57138
  1125
lemma borel_integrable_compact:
hoelzl@57447
  1126
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@57138
  1127
  assumes "compact S" "continuous_on S f"
hoelzl@57138
  1128
  shows "integrable lborel (\<lambda>x. indicator S x *\<^sub>R f x)"
hoelzl@57138
  1129
proof cases
hoelzl@57138
  1130
  assume "S \<noteq> {}"
hoelzl@57138
  1131
  have "continuous_on S (\<lambda>x. norm (f x))"
hoelzl@57138
  1132
    using assms by (intro continuous_intros)
hoelzl@57138
  1133
  from continuous_attains_sup[OF `compact S` `S \<noteq> {}` this]
hoelzl@57138
  1134
  obtain M where M: "\<And>x. x \<in> S \<Longrightarrow> norm (f x) \<le> M"
hoelzl@57138
  1135
    by auto
hoelzl@57138
  1136
hoelzl@57138
  1137
  show ?thesis
hoelzl@57138
  1138
  proof (rule integrable_bound)
hoelzl@57138
  1139
    show "integrable lborel (\<lambda>x. indicator S x * M)"
hoelzl@57138
  1140
      using assms by (auto intro!: emeasure_compact_finite borel_compact integrable_mult_left)
hoelzl@57138
  1141
    show "(\<lambda>x. indicator S x *\<^sub>R f x) \<in> borel_measurable lborel"
hoelzl@57138
  1142
      using assms by (auto intro!: borel_measurable_continuous_on_indicator borel_compact)
hoelzl@57138
  1143
    show "AE x in lborel. norm (indicator S x *\<^sub>R f x) \<le> norm (indicator S x * M)"
hoelzl@57138
  1144
      by (auto split: split_indicator simp: abs_real_def dest!: M)
hoelzl@57138
  1145
  qed
hoelzl@57138
  1146
qed simp
hoelzl@57138
  1147
hoelzl@50418
  1148
lemma borel_integrable_atLeastAtMost:
hoelzl@56993
  1149
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
  1150
  assumes f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
hoelzl@50418
  1151
  shows "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is "integrable _ ?f")
hoelzl@57138
  1152
proof -
hoelzl@57138
  1153
  have "integrable lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x)"
hoelzl@57138
  1154
  proof (rule borel_integrable_compact)
hoelzl@57138
  1155
    from f show "continuous_on {a..b} f"
hoelzl@57138
  1156
      by (auto intro: continuous_at_imp_continuous_on)
hoelzl@57138
  1157
  qed simp
hoelzl@57138
  1158
  then show ?thesis
haftmann@57512
  1159
    by (auto simp: mult.commute)
hoelzl@57138
  1160
qed
hoelzl@50418
  1161
hoelzl@50418
  1162
text {*
hoelzl@50418
  1163
lp15@60615
  1164
For the positive integral we replace continuity with Borel-measurability.
hoelzl@50418
  1165
hoelzl@50418
  1166
*}
hoelzl@50418
  1167
hoelzl@56993
  1168
lemma
hoelzl@56993
  1169
  fixes f :: "real \<Rightarrow> real"
hoelzl@57447
  1170
  assumes [measurable]: "f \<in> borel_measurable borel"
hoelzl@50418
  1171
  assumes f: "\<And>x. x \<in> {a..b} \<Longrightarrow> DERIV F x :> f x" "\<And>x. x \<in> {a..b} \<Longrightarrow> 0 \<le> f x" and "a \<le> b"
hoelzl@57447
  1172
  shows nn_integral_FTC_Icc: "(\<integral>\<^sup>+x. ereal (f x) * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?nn)
hoelzl@57447
  1173
    and has_bochner_integral_FTC_Icc_nonneg:
hoelzl@57447
  1174
      "has_bochner_integral lborel (\<lambda>x. f x * indicator {a .. b} x) (F b - F a)" (is ?has)
hoelzl@57447
  1175
    and integral_FTC_Icc_nonneg: "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?eq)
hoelzl@56993
  1176
    and integrable_FTC_Icc_nonneg: "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is ?int)
hoelzl@50418
  1177
proof -
hoelzl@57447
  1178
  have *: "(\<lambda>x. f x * indicator {a..b} x) \<in> borel_measurable borel" "\<And>x. 0 \<le> f x * indicator {a..b} x"
hoelzl@57447
  1179
    using f(2) by (auto split: split_indicator)
lp15@60615
  1180
hoelzl@57447
  1181
  have "(f has_integral F b - F a) {a..b}"
hoelzl@56181
  1182
    by (intro fundamental_theorem_of_calculus)
hoelzl@56181
  1183
       (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
hoelzl@56181
  1184
             intro: has_field_derivative_subset[OF f(1)] `a \<le> b`)
hoelzl@57447
  1185
  then have i: "((\<lambda>x. f x * indicator {a .. b} x) has_integral F b - F a) UNIV"
hoelzl@57447
  1186
    unfolding indicator_def if_distrib[where f="\<lambda>x. a * x" for a]
hoelzl@57447
  1187
    by (simp cong del: if_cong del: atLeastAtMost_iff)
hoelzl@57447
  1188
  then have nn: "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
hoelzl@57447
  1189
    by (rule nn_integral_has_integral_lborel[OF *])
hoelzl@57447
  1190
  then show ?has
hoelzl@57447
  1191
    by (rule has_bochner_integral_nn_integral[rotated 2]) (simp_all add: *)
hoelzl@57447
  1192
  then show ?eq ?int
hoelzl@57447
  1193
    unfolding has_bochner_integral_iff by auto
hoelzl@57447
  1194
  from nn show ?nn
hoelzl@57447
  1195
    by (simp add: ereal_mult_indicator)
hoelzl@56993
  1196
qed
hoelzl@56993
  1197
hoelzl@57447
  1198
lemma
hoelzl@57447
  1199
  fixes f :: "real \<Rightarrow> 'a :: euclidean_space"
hoelzl@57447
  1200
  assumes "a \<le> b"
hoelzl@57447
  1201
  assumes "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> (F has_vector_derivative f x) (at x within {a .. b})"
hoelzl@57447
  1202
  assumes cont: "continuous_on {a .. b} f"
hoelzl@57447
  1203
  shows has_bochner_integral_FTC_Icc:
hoelzl@57447
  1204
      "has_bochner_integral lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x) (F b - F a)" (is ?has)
hoelzl@57447
  1205
    and integral_FTC_Icc: "(\<integral>x. indicator {a .. b} x *\<^sub>R f x \<partial>lborel) = F b - F a" (is ?eq)
hoelzl@56993
  1206
proof -
hoelzl@57447
  1207
  let ?f = "\<lambda>x. indicator {a .. b} x *\<^sub>R f x"
hoelzl@57447
  1208
  have int: "integrable lborel ?f"
hoelzl@57447
  1209
    using borel_integrable_compact[OF _ cont] by auto
hoelzl@57447
  1210
  have "(f has_integral F b - F a) {a..b}"
hoelzl@57447
  1211
    using assms(1,2) by (intro fundamental_theorem_of_calculus) auto
lp15@60615
  1212
  moreover
hoelzl@57447
  1213
  have "(f has_integral integral\<^sup>L lborel ?f) {a..b}"
hoelzl@57447
  1214
    using has_integral_integral_lborel[OF int]
hoelzl@57447
  1215
    unfolding indicator_def if_distrib[where f="\<lambda>x. x *\<^sub>R a" for a]
hoelzl@57447
  1216
    by (simp cong del: if_cong del: atLeastAtMost_iff)
hoelzl@57447
  1217
  ultimately show ?eq
hoelzl@57447
  1218
    by (auto dest: has_integral_unique)
hoelzl@57447
  1219
  then show ?has
hoelzl@57447
  1220
    using int by (auto simp: has_bochner_integral_iff)
hoelzl@57447
  1221
qed
hoelzl@57447
  1222
hoelzl@57447
  1223
lemma
hoelzl@57447
  1224
  fixes f :: "real \<Rightarrow> real"
hoelzl@57447
  1225
  assumes "a \<le> b"
hoelzl@57447
  1226
  assumes deriv: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> DERIV F x :> f x"
hoelzl@57447
  1227
  assumes cont: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
hoelzl@57447
  1228
  shows has_bochner_integral_FTC_Icc_real:
hoelzl@57447
  1229
      "has_bochner_integral lborel (\<lambda>x. f x * indicator {a .. b} x) (F b - F a)" (is ?has)
hoelzl@57447
  1230
    and integral_FTC_Icc_real: "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?eq)
hoelzl@57447
  1231
proof -
hoelzl@57447
  1232
  have 1: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> (F has_vector_derivative f x) (at x within {a .. b})"
hoelzl@57447
  1233
    unfolding has_field_derivative_iff_has_vector_derivative[symmetric]
hoelzl@57447
  1234
    using deriv by (auto intro: DERIV_subset)
hoelzl@57447
  1235
  have 2: "continuous_on {a .. b} f"
hoelzl@57447
  1236
    using cont by (intro continuous_at_imp_continuous_on) auto
hoelzl@57447
  1237
  show ?has ?eq
hoelzl@57447
  1238
    using has_bochner_integral_FTC_Icc[OF `a \<le> b` 1 2] integral_FTC_Icc[OF `a \<le> b` 1 2]
haftmann@57512
  1239
    by (auto simp: mult.commute)
hoelzl@50418
  1240
qed
hoelzl@50418
  1241
hoelzl@56996
  1242
lemma nn_integral_FTC_atLeast:
hoelzl@50418
  1243
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
  1244
  assumes f_borel: "f \<in> borel_measurable borel"
lp15@60615
  1245
  assumes f: "\<And>x. a \<le> x \<Longrightarrow> DERIV F x :> f x"
hoelzl@50418
  1246
  assumes nonneg: "\<And>x. a \<le> x \<Longrightarrow> 0 \<le> f x"
hoelzl@50418
  1247
  assumes lim: "(F ---> T) at_top"
wenzelm@53015
  1248
  shows "(\<integral>\<^sup>+x. ereal (f x) * indicator {a ..} x \<partial>lborel) = T - F a"
hoelzl@50418
  1249
proof -
hoelzl@50418
  1250
  let ?f = "\<lambda>(i::nat) (x::real). ereal (f x) * indicator {a..a + real i} x"
hoelzl@50418
  1251
  let ?fR = "\<lambda>x. ereal (f x) * indicator {a ..} x"
hoelzl@50418
  1252
  have "\<And>x. (SUP i::nat. ?f i x) = ?fR x"
hoelzl@50418
  1253
  proof (rule SUP_Lim_ereal)
hoelzl@50418
  1254
    show "\<And>x. incseq (\<lambda>i. ?f i x)"
hoelzl@50418
  1255
      using nonneg by (auto simp: incseq_def le_fun_def split: split_indicator)
hoelzl@50418
  1256
hoelzl@50418
  1257
    fix x
hoelzl@50418
  1258
    from reals_Archimedean2[of "x - a"] guess n ..
hoelzl@50418
  1259
    then have "eventually (\<lambda>n. ?f n x = ?fR x) sequentially"
hoelzl@50418
  1260
      by (auto intro!: eventually_sequentiallyI[where c=n] split: split_indicator)
hoelzl@50418
  1261
    then show "(\<lambda>n. ?f n x) ----> ?fR x"
hoelzl@50418
  1262
      by (rule Lim_eventually)
hoelzl@50418
  1263
  qed
hoelzl@56996
  1264
  then have "integral\<^sup>N lborel ?fR = (\<integral>\<^sup>+ x. (SUP i::nat. ?f i x) \<partial>lborel)"
hoelzl@50418
  1265
    by simp
wenzelm@53015
  1266
  also have "\<dots> = (SUP i::nat. (\<integral>\<^sup>+ x. ?f i x \<partial>lborel))"
hoelzl@56996
  1267
  proof (rule nn_integral_monotone_convergence_SUP)
hoelzl@50418
  1268
    show "incseq ?f"
hoelzl@50418
  1269
      using nonneg by (auto simp: incseq_def le_fun_def split: split_indicator)
hoelzl@50418
  1270
    show "\<And>i. (?f i) \<in> borel_measurable lborel"
hoelzl@50418
  1271
      using f_borel by auto
hoelzl@50418
  1272
  qed
hoelzl@54257
  1273
  also have "\<dots> = (SUP i::nat. ereal (F (a + real i) - F a))"
hoelzl@57447
  1274
    by (subst nn_integral_FTC_Icc[OF f_borel f nonneg]) auto
hoelzl@50418
  1275
  also have "\<dots> = T - F a"
hoelzl@50418
  1276
  proof (rule SUP_Lim_ereal)
hoelzl@50418
  1277
    show "incseq (\<lambda>n. ereal (F (a + real n) - F a))"
hoelzl@50418
  1278
    proof (simp add: incseq_def, safe)
hoelzl@50418
  1279
      fix m n :: nat assume "m \<le> n"
hoelzl@50418
  1280
      with f nonneg show "F (a + real m) \<le> F (a + real n)"
hoelzl@50418
  1281
        by (intro DERIV_nonneg_imp_nondecreasing[where f=F])
hoelzl@50418
  1282
           (simp, metis add_increasing2 order_refl order_trans real_of_nat_ge_zero)
lp15@60615
  1283
    qed
hoelzl@50418
  1284
    have "(\<lambda>x. F (a + real x)) ----> T"
hoelzl@50418
  1285
      apply (rule filterlim_compose[OF lim filterlim_tendsto_add_at_top])
hoelzl@50418
  1286
      apply (rule LIMSEQ_const_iff[THEN iffD2, OF refl])
hoelzl@50418
  1287
      apply (rule filterlim_real_sequentially)
hoelzl@50418
  1288
      done
hoelzl@50418
  1289
    then show "(\<lambda>n. ereal (F (a + real n) - F a)) ----> ereal (T - F a)"
hoelzl@50418
  1290
      unfolding lim_ereal
hoelzl@50418
  1291
      by (intro tendsto_diff) auto
hoelzl@50418
  1292
  qed
hoelzl@50418
  1293
  finally show ?thesis .
hoelzl@50418
  1294
qed
hoelzl@50418
  1295
hoelzl@57447
  1296
lemma integral_power:
hoelzl@57447
  1297
  "a \<le> b \<Longrightarrow> (\<integral>x. x^k * indicator {a..b} x \<partial>lborel) = (b^Suc k - a^Suc k) / Suc k"
hoelzl@57447
  1298
proof (subst integral_FTC_Icc_real)
hoelzl@57447
  1299
  fix x show "DERIV (\<lambda>x. x^Suc k / Suc k) x :> x^k"
hoelzl@57447
  1300
    by (intro derivative_eq_intros) auto
hoelzl@57447
  1301
qed (auto simp: field_simps)
hoelzl@57447
  1302
hoelzl@57235
  1303
subsection {* Integration by parts *}
hoelzl@57235
  1304
hoelzl@57235
  1305
lemma integral_by_parts_integrable:
hoelzl@57235
  1306
  fixes f g F G::"real \<Rightarrow> real"
hoelzl@57235
  1307
  assumes "a \<le> b"
hoelzl@57235
  1308
  assumes cont_f[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
hoelzl@57235
  1309
  assumes cont_g[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
hoelzl@57235
  1310
  assumes [intro]: "!!x. DERIV F x :> f x"
hoelzl@57235
  1311
  assumes [intro]: "!!x. DERIV G x :> g x"
hoelzl@57235
  1312
  shows  "integrable lborel (\<lambda>x.((F x) * (g x) + (f x) * (G x)) * indicator {a .. b} x)"
hoelzl@57235
  1313
  by (auto intro!: borel_integrable_atLeastAtMost continuous_intros) (auto intro!: DERIV_isCont)
hoelzl@57235
  1314
hoelzl@57235
  1315
lemma integral_by_parts:
hoelzl@57235
  1316
  fixes f g F G::"real \<Rightarrow> real"
hoelzl@57235
  1317
  assumes [arith]: "a \<le> b"
hoelzl@57235
  1318
  assumes cont_f[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
hoelzl@57235
  1319
  assumes cont_g[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
hoelzl@57235
  1320
  assumes [intro]: "!!x. DERIV F x :> f x"
hoelzl@57235
  1321
  assumes [intro]: "!!x. DERIV G x :> g x"
hoelzl@57235
  1322
  shows "(\<integral>x. (F x * g x) * indicator {a .. b} x \<partial>lborel)
lp15@60615
  1323
            =  F b * G b - F a * G a - \<integral>x. (f x * G x) * indicator {a .. b} x \<partial>lborel"
hoelzl@57235
  1324
proof-
hoelzl@57235
  1325
  have 0: "(\<integral>x. (F x * g x + f x * G x) * indicator {a .. b} x \<partial>lborel) = F b * G b - F a * G a"
lp15@60615
  1326
    by (rule integral_FTC_Icc_real, auto intro!: derivative_eq_intros continuous_intros)
hoelzl@57235
  1327
      (auto intro!: DERIV_isCont)
hoelzl@57235
  1328
hoelzl@57235
  1329
  have "(\<integral>x. (F x * g x + f x * G x) * indicator {a .. b} x \<partial>lborel) =
hoelzl@57235
  1330
    (\<integral>x. (F x * g x) * indicator {a .. b} x \<partial>lborel) + \<integral>x. (f x * G x) * indicator {a .. b} x \<partial>lborel"
hoelzl@57235
  1331
    apply (subst integral_add[symmetric])
hoelzl@57235
  1332
    apply (auto intro!: borel_integrable_atLeastAtMost continuous_intros)
hoelzl@57235
  1333
    by (auto intro!: DERIV_isCont integral_cong split:split_indicator)
hoelzl@57235
  1334
hoelzl@57235
  1335
  thus ?thesis using 0 by auto
hoelzl@57235
  1336
qed
hoelzl@57235
  1337
hoelzl@57235
  1338
lemma integral_by_parts':
hoelzl@57235
  1339
  fixes f g F G::"real \<Rightarrow> real"
hoelzl@57235
  1340
  assumes "a \<le> b"
hoelzl@57235
  1341
  assumes "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
hoelzl@57235
  1342
  assumes "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
hoelzl@57235
  1343
  assumes "!!x. DERIV F x :> f x"
hoelzl@57235
  1344
  assumes "!!x. DERIV G x :> g x"
hoelzl@57235
  1345
  shows "(\<integral>x. indicator {a .. b} x *\<^sub>R (F x * g x) \<partial>lborel)
lp15@60615
  1346
            =  F b * G b - F a * G a - \<integral>x. indicator {a .. b} x *\<^sub>R (f x * G x) \<partial>lborel"
haftmann@57514
  1347
  using integral_by_parts[OF assms] by (simp add: ac_simps)
hoelzl@57235
  1348
hoelzl@57275
  1349
lemma has_bochner_integral_even_function:
hoelzl@57275
  1350
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@57275
  1351
  assumes f: "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x) x"
hoelzl@57275
  1352
  assumes even: "\<And>x. f (- x) = f x"
hoelzl@57275
  1353
  shows "has_bochner_integral lborel f (2 *\<^sub>R x)"
hoelzl@57275
  1354
proof -
hoelzl@57275
  1355
  have indicator: "\<And>x::real. indicator {..0} (- x) = indicator {0..} x"
hoelzl@57275
  1356
    by (auto split: split_indicator)
hoelzl@57275
  1357
  have "has_bochner_integral lborel (\<lambda>x. indicator {.. 0} x *\<^sub>R f x) x"
hoelzl@57275
  1358
    by (subst lborel_has_bochner_integral_real_affine_iff[where c="-1" and t=0])
hoelzl@57275
  1359
       (auto simp: indicator even f)
hoelzl@57275
  1360
  with f have "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x + indicator {.. 0} x *\<^sub>R f x) (x + x)"
hoelzl@57275
  1361
    by (rule has_bochner_integral_add)
hoelzl@57275
  1362
  then have "has_bochner_integral lborel f (x + x)"
hoelzl@57275
  1363
    by (rule has_bochner_integral_discrete_difference[where X="{0}", THEN iffD1, rotated 4])
hoelzl@57275
  1364
       (auto split: split_indicator)
hoelzl@57275
  1365
  then show ?thesis
hoelzl@57275
  1366
    by (simp add: scaleR_2)
hoelzl@57275
  1367
qed
hoelzl@57275
  1368
hoelzl@57275
  1369
lemma has_bochner_integral_odd_function:
hoelzl@57275
  1370
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@57275
  1371
  assumes f: "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x) x"
hoelzl@57275
  1372
  assumes odd: "\<And>x. f (- x) = - f x"
hoelzl@57275
  1373
  shows "has_bochner_integral lborel f 0"
hoelzl@57275
  1374
proof -
hoelzl@57275
  1375
  have indicator: "\<And>x::real. indicator {..0} (- x) = indicator {0..} x"
hoelzl@57275
  1376
    by (auto split: split_indicator)
hoelzl@57275
  1377
  have "has_bochner_integral lborel (\<lambda>x. - indicator {.. 0} x *\<^sub>R f x) x"
hoelzl@57275
  1378
    by (subst lborel_has_bochner_integral_real_affine_iff[where c="-1" and t=0])
hoelzl@57275
  1379
       (auto simp: indicator odd f)
hoelzl@57275
  1380
  from has_bochner_integral_minus[OF this]
hoelzl@57275
  1381
  have "has_bochner_integral lborel (\<lambda>x. indicator {.. 0} x *\<^sub>R f x) (- x)"
lp15@60615
  1382
    by simp
hoelzl@57275
  1383
  with f have "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x + indicator {.. 0} x *\<^sub>R f x) (x + - x)"
hoelzl@57275
  1384
    by (rule has_bochner_integral_add)
hoelzl@57275
  1385
  then have "has_bochner_integral lborel f (x + - x)"
hoelzl@57275
  1386
    by (rule has_bochner_integral_discrete_difference[where X="{0}", THEN iffD1, rotated 4])
hoelzl@57275
  1387
       (auto split: split_indicator)
hoelzl@57275
  1388
  then show ?thesis
hoelzl@57275
  1389
    by simp
hoelzl@57275
  1390
qed
hoelzl@57235
  1391
hoelzl@38656
  1392
end
hoelzl@57447
  1393