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