src/HOL/Probability/Lebesgue_Measure.thy
author hoelzl
Thu Jun 12 15:47:36 2014 +0200 (2014-06-12)
changeset 57235 b0b9a10e4bf4
parent 57166 5cfcc616d485
child 57275 0ddb5b755cdc
permissions -rw-r--r--
properties of Erlang and exponentially distributed random variables (by Sudeep Kanav)
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@42067
     4
*)
hoelzl@42067
     5
hoelzl@38656
     6
header {* Lebsegue measure *}
hoelzl@42067
     7
hoelzl@38656
     8
theory Lebesgue_Measure
hoelzl@56993
     9
  imports Finite_Product_Measure Bochner_Integration
hoelzl@38656
    10
begin
hoelzl@38656
    11
hoelzl@50104
    12
lemma absolutely_integrable_on_indicator[simp]:
hoelzl@50104
    13
  fixes A :: "'a::ordered_euclidean_space set"
hoelzl@50104
    14
  shows "((indicator A :: _ \<Rightarrow> real) absolutely_integrable_on X) \<longleftrightarrow>
hoelzl@50104
    15
    (indicator A :: _ \<Rightarrow> real) integrable_on X"
hoelzl@50104
    16
  unfolding absolutely_integrable_on_def by simp
hoelzl@49777
    17
hoelzl@50104
    18
lemma has_integral_indicator_UNIV:
hoelzl@50104
    19
  fixes s A :: "'a::ordered_euclidean_space set" and x :: real
hoelzl@50104
    20
  shows "((indicator (s \<inter> A) :: 'a\<Rightarrow>real) has_integral x) UNIV = ((indicator s :: _\<Rightarrow>real) has_integral x) A"
hoelzl@50104
    21
proof -
hoelzl@50104
    22
  have "(\<lambda>x. if x \<in> A then indicator s x else 0) = (indicator (s \<inter> A) :: _\<Rightarrow>real)"
hoelzl@50104
    23
    by (auto simp: fun_eq_iff indicator_def)
hoelzl@50104
    24
  then show ?thesis
hoelzl@50104
    25
    unfolding has_integral_restrict_univ[where s=A, symmetric] by simp
hoelzl@50104
    26
qed
hoelzl@50104
    27
hoelzl@50104
    28
lemma
hoelzl@50104
    29
  fixes s a :: "'a::ordered_euclidean_space set"
hoelzl@50104
    30
  shows integral_indicator_UNIV:
hoelzl@50104
    31
    "integral UNIV (indicator (s \<inter> A) :: 'a\<Rightarrow>real) = integral A (indicator s :: _\<Rightarrow>real)"
hoelzl@50104
    32
  and integrable_indicator_UNIV:
hoelzl@50104
    33
    "(indicator (s \<inter> A) :: 'a\<Rightarrow>real) integrable_on UNIV \<longleftrightarrow> (indicator s :: 'a\<Rightarrow>real) integrable_on A"
hoelzl@50104
    34
  unfolding integral_def integrable_on_def has_integral_indicator_UNIV by auto
hoelzl@47694
    35
hoelzl@38656
    36
subsection {* Standard Cubes *}
hoelzl@38656
    37
hoelzl@40859
    38
definition cube :: "nat \<Rightarrow> 'a::ordered_euclidean_space set" where
hoelzl@50526
    39
  "cube n \<equiv> {\<Sum>i\<in>Basis. - n *\<^sub>R i .. \<Sum>i\<in>Basis. n *\<^sub>R i}"
hoelzl@40859
    40
hoelzl@49777
    41
lemma borel_cube[intro]: "cube n \<in> sets borel"
hoelzl@49777
    42
  unfolding cube_def by auto
hoelzl@49777
    43
hoelzl@40859
    44
lemma cube_closed[intro]: "closed (cube n)"
hoelzl@40859
    45
  unfolding cube_def by auto
hoelzl@40859
    46
hoelzl@40859
    47
lemma cube_subset[intro]: "n \<le> N \<Longrightarrow> cube n \<subseteq> cube N"
hoelzl@50526
    48
  by (fastforce simp: eucl_le[where 'a='a] cube_def setsum_negf)
hoelzl@50526
    49
hoelzl@50526
    50
lemma cube_subset_iff: "cube n \<subseteq> cube N \<longleftrightarrow> n \<le> N"
immler@56188
    51
  unfolding cube_def subset_box by (simp add: setsum_negf ex_in_conv eucl_le[where 'a='a])
hoelzl@38656
    52
hoelzl@50526
    53
lemma ball_subset_cube: "ball (0::'a::ordered_euclidean_space) (real n) \<subseteq> cube n"
immler@56188
    54
  apply (simp add: cube_def subset_eq mem_box setsum_negf eucl_le[where 'a='a])
hoelzl@50526
    55
proof safe
hoelzl@50526
    56
  fix x i :: 'a assume x: "x \<in> ball 0 (real n)" and i: "i \<in> Basis" 
hoelzl@50526
    57
  thus "- real n \<le> x \<bullet> i" "real n \<ge> x \<bullet> i"
hoelzl@50526
    58
    using Basis_le_norm[OF i, of x] by(auto simp: dist_norm)
hoelzl@38656
    59
qed
hoelzl@38656
    60
hoelzl@38656
    61
lemma mem_big_cube: obtains n where "x \<in> cube n"
hoelzl@50526
    62
proof -
hoelzl@50526
    63
  from reals_Archimedean2[of "norm x"] guess n ..
hoelzl@50526
    64
  with ball_subset_cube[unfolded subset_eq, of n]
hoelzl@50526
    65
  show ?thesis
hoelzl@50526
    66
    by (intro that[where n=n]) (auto simp add: dist_norm)
hoelzl@38656
    67
qed
hoelzl@38656
    68
hoelzl@41689
    69
lemma cube_subset_Suc[intro]: "cube n \<subseteq> cube (Suc n)"
immler@56188
    70
  unfolding cube_def cbox_interval[symmetric] subset_box by (simp add: setsum_negf)
hoelzl@41654
    71
hoelzl@50104
    72
lemma has_integral_interval_cube:
hoelzl@50104
    73
  fixes a b :: "'a::ordered_euclidean_space"
hoelzl@50526
    74
  shows "(indicator {a .. b} has_integral content ({a .. b} \<inter> cube n)) (cube n)"
hoelzl@50104
    75
    (is "(?I has_integral content ?R) (cube n)")
hoelzl@50104
    76
proof -
hoelzl@50104
    77
  have [simp]: "(\<lambda>x. if x \<in> cube n then ?I x else 0) = indicator ?R"
hoelzl@50104
    78
    by (auto simp: indicator_def cube_def fun_eq_iff eucl_le[where 'a='a])
hoelzl@50104
    79
  have "(?I has_integral content ?R) (cube n) \<longleftrightarrow> (indicator ?R has_integral content ?R) UNIV"
hoelzl@50104
    80
    unfolding has_integral_restrict_univ[where s="cube n", symmetric] by simp
hoelzl@50526
    81
  also have "\<dots> \<longleftrightarrow> ((\<lambda>x. 1::real) has_integral content ?R *\<^sub>R 1) ?R"
hoelzl@50526
    82
    unfolding indicator_def [abs_def] has_integral_restrict_univ real_scaleR_def mult_1_right ..
hoelzl@50526
    83
  also have "((\<lambda>x. 1) has_integral content ?R *\<^sub>R 1) ?R"
immler@56188
    84
    unfolding cube_def inter_interval cbox_interval[symmetric] by (rule has_integral_const)
hoelzl@50526
    85
  finally show ?thesis .
hoelzl@50104
    86
qed
hoelzl@50104
    87
hoelzl@47757
    88
subsection {* Lebesgue measure *}
hoelzl@41706
    89
hoelzl@47694
    90
definition lebesgue :: "'a::ordered_euclidean_space measure" where
hoelzl@47694
    91
  "lebesgue = measure_of UNIV {A. \<forall>n. (indicator A :: 'a \<Rightarrow> real) integrable_on cube n}
hoelzl@47694
    92
    (\<lambda>A. SUP n. ereal (integral (cube n) (indicator A)))"
hoelzl@41661
    93
hoelzl@41654
    94
lemma space_lebesgue[simp]: "space lebesgue = UNIV"
hoelzl@41654
    95
  unfolding lebesgue_def by simp
hoelzl@41654
    96
hoelzl@41654
    97
lemma lebesgueI: "(\<And>n. (indicator A :: _ \<Rightarrow> real) integrable_on cube n) \<Longrightarrow> A \<in> sets lebesgue"
hoelzl@41654
    98
  unfolding lebesgue_def by simp
hoelzl@41654
    99
hoelzl@47694
   100
lemma sigma_algebra_lebesgue:
hoelzl@47694
   101
  defines "leb \<equiv> {A. \<forall>n. (indicator A :: 'a::ordered_euclidean_space \<Rightarrow> real) integrable_on cube n}"
hoelzl@47694
   102
  shows "sigma_algebra UNIV leb"
hoelzl@47694
   103
proof (safe intro!: sigma_algebra_iff2[THEN iffD2])
hoelzl@47694
   104
  fix A assume A: "A \<in> leb"
hoelzl@47694
   105
  moreover have "indicator (UNIV - A) = (\<lambda>x. 1 - indicator A x :: real)"
hoelzl@41654
   106
    by (auto simp: fun_eq_iff indicator_def)
hoelzl@47694
   107
  ultimately show "UNIV - A \<in> leb"
hoelzl@47694
   108
    using A by (auto intro!: integrable_sub simp: cube_def leb_def)
hoelzl@41654
   109
next
hoelzl@47694
   110
  fix n show "{} \<in> leb"
hoelzl@47694
   111
    by (auto simp: cube_def indicator_def[abs_def] leb_def)
hoelzl@41654
   112
next
hoelzl@47694
   113
  fix A :: "nat \<Rightarrow> _" assume A: "range A \<subseteq> leb"
hoelzl@47694
   114
  have "\<forall>n. (indicator (\<Union>i. A i) :: _ \<Rightarrow> real) integrable_on cube n" (is "\<forall>n. ?g integrable_on _")
hoelzl@47694
   115
  proof (intro dominated_convergence[where g="?g"] ballI allI)
hoelzl@47694
   116
    fix k n show "(indicator (\<Union>i<k. A i) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
   117
    proof (induct k)
hoelzl@41654
   118
      case (Suc k)
hoelzl@41654
   119
      have *: "(\<Union> i<Suc k. A i) = (\<Union> i<k. A i) \<union> A k"
hoelzl@41654
   120
        unfolding lessThan_Suc UN_insert by auto
hoelzl@41654
   121
      have *: "(\<lambda>x. max (indicator (\<Union> i<k. A i) x) (indicator (A k) x) :: real) =
hoelzl@41654
   122
          indicator (\<Union> i<Suc k. A i)" (is "(\<lambda>x. max (?f x) (?g x)) = _")
hoelzl@41654
   123
        by (auto simp: fun_eq_iff * indicator_def)
hoelzl@41654
   124
      show ?case
hoelzl@47694
   125
        using absolutely_integrable_max[of ?f "cube n" ?g] A Suc
hoelzl@47694
   126
        by (simp add: * leb_def subset_eq)
hoelzl@41654
   127
    qed auto
hoelzl@41654
   128
  qed (auto intro: LIMSEQ_indicator_UN simp: cube_def)
hoelzl@47694
   129
  then show "(\<Union>i. A i) \<in> leb" by (auto simp: leb_def)
hoelzl@41654
   130
qed simp
hoelzl@38656
   131
hoelzl@47694
   132
lemma sets_lebesgue: "sets lebesgue = {A. \<forall>n. (indicator A :: _ \<Rightarrow> real) integrable_on cube n}"
hoelzl@47694
   133
  unfolding lebesgue_def sigma_algebra.sets_measure_of_eq[OF sigma_algebra_lebesgue] ..
hoelzl@47694
   134
hoelzl@47694
   135
lemma lebesgueD: "A \<in> sets lebesgue \<Longrightarrow> (indicator A :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@47694
   136
  unfolding sets_lebesgue by simp
hoelzl@47694
   137
hoelzl@47757
   138
lemma emeasure_lebesgue:
hoelzl@47694
   139
  assumes "A \<in> sets lebesgue"
hoelzl@47694
   140
  shows "emeasure lebesgue A = (SUP n. ereal (integral (cube n) (indicator A)))"
hoelzl@47694
   141
    (is "_ = ?\<mu> A")
hoelzl@47694
   142
proof (rule emeasure_measure_of[OF lebesgue_def])
hoelzl@41654
   143
  have *: "indicator {} = (\<lambda>x. 0 :: real)" by (simp add: fun_eq_iff)
hoelzl@47694
   144
  show "positive (sets lebesgue) ?\<mu>"
hoelzl@47694
   145
  proof (unfold positive_def, intro conjI ballI)
hoelzl@47694
   146
    show "?\<mu> {} = 0" by (simp add: integral_0 *)
hoelzl@47694
   147
    fix A :: "'a set" assume "A \<in> sets lebesgue" then show "0 \<le> ?\<mu> A"
hoelzl@47694
   148
      by (auto intro!: SUP_upper2 Integration.integral_nonneg simp: sets_lebesgue)
hoelzl@41981
   149
  qed
hoelzl@40859
   150
next
hoelzl@47694
   151
  show "countably_additive (sets lebesgue) ?\<mu>"
hoelzl@41654
   152
  proof (intro countably_additive_def[THEN iffD2] allI impI)
hoelzl@47694
   153
    fix A :: "nat \<Rightarrow> 'a set" assume rA: "range A \<subseteq> sets lebesgue" "disjoint_family A"
hoelzl@41654
   154
    then have A[simp, intro]: "\<And>i n. (indicator (A i) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
   155
      by (auto dest: lebesgueD)
wenzelm@46731
   156
    let ?m = "\<lambda>n i. integral (cube n) (indicator (A i) :: _\<Rightarrow>real)"
wenzelm@46731
   157
    let ?M = "\<lambda>n I. integral (cube n) (indicator (\<Union>i\<in>I. A i) :: _\<Rightarrow>real)"
hoelzl@47694
   158
    have nn[simp, intro]: "\<And>i n. 0 \<le> ?m n i" by (auto intro!: Integration.integral_nonneg)
hoelzl@41654
   159
    assume "(\<Union>i. A i) \<in> sets lebesgue"
hoelzl@41654
   160
    then have UN_A[simp, intro]: "\<And>i n. (indicator (\<Union>i. A i) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@47694
   161
      by (auto simp: sets_lebesgue)
hoelzl@47694
   162
    show "(\<Sum>n. ?\<mu> (A n)) = ?\<mu> (\<Union>i. A i)"
hoelzl@49777
   163
    proof (subst suminf_SUP_eq, safe intro!: incseq_SucI) 
hoelzl@43920
   164
      fix i n show "ereal (?m n i) \<le> ereal (?m (Suc n) i)"
hoelzl@41981
   165
        using cube_subset[of n "Suc n"] by (auto intro!: integral_subset_le incseq_SucI)
hoelzl@41654
   166
    next
hoelzl@43920
   167
      fix i n show "0 \<le> ereal (?m n i)"
hoelzl@41981
   168
        using rA unfolding lebesgue_def
hoelzl@44928
   169
        by (auto intro!: SUP_upper2 integral_nonneg)
hoelzl@41981
   170
    next
hoelzl@43920
   171
      show "(SUP n. \<Sum>i. ereal (?m n i)) = (SUP n. ereal (?M n UNIV))"
haftmann@56218
   172
      proof (intro arg_cong[where f="SUPREMUM UNIV"] ext sums_unique[symmetric] sums_ereal[THEN iffD2] sums_def[THEN iffD2])
hoelzl@41654
   173
        fix n
hoelzl@41654
   174
        have "\<And>m. (UNION {..<m} A) \<in> sets lebesgue" using rA by auto
hoelzl@41654
   175
        from lebesgueD[OF this]
hoelzl@41654
   176
        have "(\<lambda>m. ?M n {..< m}) ----> ?M n UNIV"
hoelzl@41654
   177
          (is "(\<lambda>m. integral _ (?A m)) ----> ?I")
hoelzl@41654
   178
          by (intro dominated_convergence(2)[where f="?A" and h="\<lambda>x. 1::real"])
hoelzl@41654
   179
             (auto intro: LIMSEQ_indicator_UN simp: cube_def)
hoelzl@41654
   180
        moreover
hoelzl@41654
   181
        { fix m have *: "(\<Sum>x<m. ?m n x) = ?M n {..< m}"
hoelzl@41654
   182
          proof (induct m)
hoelzl@41654
   183
            case (Suc m)
hoelzl@41654
   184
            have "(\<Union>i<m. A i) \<in> sets lebesgue" using rA by auto
hoelzl@41654
   185
            then have "(indicator (\<Union>i<m. A i) :: _\<Rightarrow>real) integrable_on (cube n)"
hoelzl@41654
   186
              by (auto dest!: lebesgueD)
hoelzl@41654
   187
            moreover
hoelzl@41654
   188
            have "(\<Union>i<m. A i) \<inter> A m = {}"
hoelzl@41654
   189
              using rA(2)[unfolded disjoint_family_on_def, THEN bspec, of m]
hoelzl@41654
   190
              by auto
hoelzl@41654
   191
            then have "\<And>x. indicator (\<Union>i<Suc m. A i) x =
hoelzl@41654
   192
              indicator (\<Union>i<m. A i) x + (indicator (A m) x :: real)"
hoelzl@41654
   193
              by (auto simp: indicator_add lessThan_Suc ac_simps)
hoelzl@41654
   194
            ultimately show ?case
hoelzl@47694
   195
              using Suc A by (simp add: Integration.integral_add[symmetric])
hoelzl@41654
   196
          qed auto }
hoelzl@56193
   197
        ultimately show "(\<lambda>m. \<Sum>x<m. ?m n x) ----> ?M n UNIV"
hoelzl@41981
   198
          by (simp add: atLeast0LessThan)
hoelzl@41654
   199
      qed
hoelzl@41654
   200
    qed
hoelzl@41654
   201
  qed
hoelzl@47694
   202
qed (auto, fact)
hoelzl@40859
   203
hoelzl@41654
   204
lemma lebesgueI_borel[intro, simp]:
hoelzl@41654
   205
  fixes s::"'a::ordered_euclidean_space set"
hoelzl@40859
   206
  assumes "s \<in> sets borel" shows "s \<in> sets lebesgue"
hoelzl@41654
   207
proof -
hoelzl@47694
   208
  have "s \<in> sigma_sets (space lebesgue) (range (\<lambda>(a, b). {a .. (b :: 'a\<Colon>ordered_euclidean_space)}))"
hoelzl@47694
   209
    using assms by (simp add: borel_eq_atLeastAtMost)
hoelzl@47694
   210
  also have "\<dots> \<subseteq> sets lebesgue"
immler@50244
   211
  proof (safe intro!: sets.sigma_sets_subset lebesgueI)
hoelzl@41654
   212
    fix n :: nat and a b :: 'a
hoelzl@41654
   213
    show "(indicator {a..b} :: 'a\<Rightarrow>real) integrable_on cube n"
hoelzl@50526
   214
      unfolding integrable_on_def using has_integral_interval_cube[of a b] by auto
hoelzl@41654
   215
  qed
hoelzl@47694
   216
  finally show ?thesis .
hoelzl@38656
   217
qed
hoelzl@38656
   218
hoelzl@47757
   219
lemma borel_measurable_lebesgueI:
hoelzl@47757
   220
  "f \<in> borel_measurable borel \<Longrightarrow> f \<in> borel_measurable lebesgue"
hoelzl@47757
   221
  unfolding measurable_def by simp
hoelzl@47757
   222
hoelzl@40859
   223
lemma lebesgueI_negligible[dest]: fixes s::"'a::ordered_euclidean_space set"
hoelzl@40859
   224
  assumes "negligible s" shows "s \<in> sets lebesgue"
immler@56188
   225
  using assms by (force simp: cbox_interval[symmetric] cube_def integrable_on_def negligible_def intro!: lebesgueI)
hoelzl@38656
   226
hoelzl@41654
   227
lemma lmeasure_eq_0:
hoelzl@47694
   228
  fixes S :: "'a::ordered_euclidean_space set"
hoelzl@47694
   229
  assumes "negligible S" shows "emeasure lebesgue S = 0"
hoelzl@40859
   230
proof -
hoelzl@41654
   231
  have "\<And>n. integral (cube n) (indicator S :: 'a\<Rightarrow>real) = 0"
hoelzl@41689
   232
    unfolding lebesgue_integral_def using assms
hoelzl@41689
   233
    by (intro integral_unique some1_equality ex_ex1I)
immler@56188
   234
       (auto simp: cube_def negligible_def cbox_interval[symmetric])
hoelzl@47694
   235
  then show ?thesis
hoelzl@47694
   236
    using assms by (simp add: emeasure_lebesgue lebesgueI_negligible)
hoelzl@40859
   237
qed
hoelzl@40859
   238
hoelzl@40859
   239
lemma lmeasure_iff_LIMSEQ:
hoelzl@47694
   240
  assumes A: "A \<in> sets lebesgue" and "0 \<le> m"
hoelzl@47694
   241
  shows "emeasure lebesgue A = ereal m \<longleftrightarrow> (\<lambda>n. integral (cube n) (indicator A :: _ \<Rightarrow> real)) ----> m"
hoelzl@47694
   242
proof (subst emeasure_lebesgue[OF A], intro SUP_eq_LIMSEQ)
hoelzl@41654
   243
  show "mono (\<lambda>n. integral (cube n) (indicator A::_=>real))"
hoelzl@41654
   244
    using cube_subset assms by (intro monoI integral_subset_le) (auto dest!: lebesgueD)
hoelzl@41981
   245
qed
hoelzl@38656
   246
hoelzl@41654
   247
lemma lmeasure_finite_has_integral:
hoelzl@41654
   248
  fixes s :: "'a::ordered_euclidean_space set"
hoelzl@49777
   249
  assumes "s \<in> sets lebesgue" "emeasure lebesgue s = ereal m"
hoelzl@41654
   250
  shows "(indicator s has_integral m) UNIV"
hoelzl@41654
   251
proof -
hoelzl@41654
   252
  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@49777
   253
  have "0 \<le> m"
hoelzl@49777
   254
    using emeasure_nonneg[of lebesgue s] `emeasure lebesgue s = ereal m` by simp
hoelzl@41654
   255
  have **: "(?I s) integrable_on UNIV \<and> (\<lambda>k. integral UNIV (?I (s \<inter> cube k))) ----> integral UNIV (?I s)"
hoelzl@41654
   256
  proof (intro monotone_convergence_increasing allI ballI)
hoelzl@41654
   257
    have LIMSEQ: "(\<lambda>n. integral (cube n) (?I s)) ----> m"
hoelzl@49777
   258
      using assms(2) unfolding lmeasure_iff_LIMSEQ[OF assms(1) `0 \<le> m`] .
hoelzl@41654
   259
    { fix n have "integral (cube n) (?I s) \<le> m"
hoelzl@41654
   260
        using cube_subset assms
hoelzl@41654
   261
        by (intro incseq_le[where L=m] LIMSEQ incseq_def[THEN iffD2] integral_subset_le allI impI)
hoelzl@41654
   262
           (auto dest!: lebesgueD) }
hoelzl@41654
   263
    moreover
hoelzl@41654
   264
    { fix n have "0 \<le> integral (cube n) (?I s)"
hoelzl@47694
   265
      using assms by (auto dest!: lebesgueD intro!: Integration.integral_nonneg) }
hoelzl@41654
   266
    ultimately
hoelzl@41654
   267
    show "bounded {integral UNIV (?I (s \<inter> cube k)) |k. True}"
hoelzl@41654
   268
      unfolding bounded_def
hoelzl@41654
   269
      apply (rule_tac exI[of _ 0])
hoelzl@41654
   270
      apply (rule_tac exI[of _ m])
hoelzl@41654
   271
      by (auto simp: dist_real_def integral_indicator_UNIV)
hoelzl@41654
   272
    fix k show "?I (s \<inter> cube k) integrable_on UNIV"
hoelzl@41654
   273
      unfolding integrable_indicator_UNIV using assms by (auto dest!: lebesgueD)
hoelzl@41654
   274
    fix x show "?I (s \<inter> cube k) x \<le> ?I (s \<inter> cube (Suc k)) x"
hoelzl@41654
   275
      using cube_subset[of k "Suc k"] by (auto simp: indicator_def)
hoelzl@41654
   276
  next
hoelzl@41654
   277
    fix x :: 'a
hoelzl@41654
   278
    from mem_big_cube obtain k where k: "x \<in> cube k" .
hoelzl@41654
   279
    { fix n have "?I (s \<inter> cube (n + k)) x = ?I s x"
hoelzl@41654
   280
      using k cube_subset[of k "n + k"] by (auto simp: indicator_def) }
hoelzl@41654
   281
    note * = this
hoelzl@41654
   282
    show "(\<lambda>k. ?I (s \<inter> cube k) x) ----> ?I s x"
hoelzl@41654
   283
      by (rule LIMSEQ_offset[where k=k]) (auto simp: *)
hoelzl@41654
   284
  qed
hoelzl@41654
   285
  note ** = conjunctD2[OF this]
hoelzl@41654
   286
  have m: "m = integral UNIV (?I s)"
hoelzl@41654
   287
    apply (intro LIMSEQ_unique[OF _ **(2)])
hoelzl@49777
   288
    using assms(2) unfolding lmeasure_iff_LIMSEQ[OF assms(1) `0 \<le> m`] integral_indicator_UNIV .
hoelzl@41654
   289
  show ?thesis
hoelzl@41654
   290
    unfolding m by (intro integrable_integral **)
hoelzl@38656
   291
qed
hoelzl@38656
   292
hoelzl@47694
   293
lemma lmeasure_finite_integrable: assumes s: "s \<in> sets lebesgue" and "emeasure lebesgue s \<noteq> \<infinity>"
hoelzl@41654
   294
  shows "(indicator s :: _ \<Rightarrow> real) integrable_on UNIV"
hoelzl@47694
   295
proof (cases "emeasure lebesgue s")
hoelzl@41981
   296
  case (real m)
hoelzl@47694
   297
  with lmeasure_finite_has_integral[OF `s \<in> sets lebesgue` this] emeasure_nonneg[of lebesgue s]
hoelzl@41654
   298
  show ?thesis unfolding integrable_on_def by auto
hoelzl@47694
   299
qed (insert assms emeasure_nonneg[of lebesgue s], auto)
hoelzl@38656
   300
hoelzl@41654
   301
lemma has_integral_lebesgue: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
hoelzl@41654
   302
  shows "s \<in> sets lebesgue"
hoelzl@41654
   303
proof (intro lebesgueI)
hoelzl@41654
   304
  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41654
   305
  fix n show "(?I s) integrable_on cube n" unfolding cube_def
hoelzl@41654
   306
  proof (intro integrable_on_subinterval)
hoelzl@41654
   307
    show "(?I s) integrable_on UNIV"
hoelzl@41654
   308
      unfolding integrable_on_def using assms by auto
hoelzl@41654
   309
  qed auto
hoelzl@38656
   310
qed
hoelzl@38656
   311
hoelzl@41654
   312
lemma has_integral_lmeasure: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
hoelzl@47694
   313
  shows "emeasure lebesgue s = ereal m"
hoelzl@41654
   314
proof (intro lmeasure_iff_LIMSEQ[THEN iffD2])
hoelzl@41654
   315
  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41654
   316
  show "s \<in> sets lebesgue" using has_integral_lebesgue[OF assms] .
hoelzl@41654
   317
  show "0 \<le> m" using assms by (rule has_integral_nonneg) auto
hoelzl@41654
   318
  have "(\<lambda>n. integral UNIV (?I (s \<inter> cube n))) ----> integral UNIV (?I s)"
hoelzl@41654
   319
  proof (intro dominated_convergence(2) ballI)
hoelzl@41654
   320
    show "(?I s) integrable_on UNIV" unfolding integrable_on_def using assms by auto
hoelzl@41654
   321
    fix n show "?I (s \<inter> cube n) integrable_on UNIV"
hoelzl@41654
   322
      unfolding integrable_indicator_UNIV using `s \<in> sets lebesgue` by (auto dest: lebesgueD)
hoelzl@41654
   323
    fix x show "norm (?I (s \<inter> cube n) x) \<le> ?I s x" by (auto simp: indicator_def)
hoelzl@41654
   324
  next
hoelzl@41654
   325
    fix x :: 'a
hoelzl@41654
   326
    from mem_big_cube obtain k where k: "x \<in> cube k" .
hoelzl@41654
   327
    { fix n have "?I (s \<inter> cube (n + k)) x = ?I s x"
hoelzl@41654
   328
      using k cube_subset[of k "n + k"] by (auto simp: indicator_def) }
hoelzl@41654
   329
    note * = this
hoelzl@41654
   330
    show "(\<lambda>k. ?I (s \<inter> cube k) x) ----> ?I s x"
hoelzl@41654
   331
      by (rule LIMSEQ_offset[where k=k]) (auto simp: *)
hoelzl@41654
   332
  qed
hoelzl@41654
   333
  then show "(\<lambda>n. integral (cube n) (?I s)) ----> m"
hoelzl@41654
   334
    unfolding integral_unique[OF assms] integral_indicator_UNIV by simp
hoelzl@41654
   335
qed
hoelzl@41654
   336
hoelzl@41654
   337
lemma has_integral_iff_lmeasure:
hoelzl@49777
   338
  "(indicator A has_integral m) UNIV \<longleftrightarrow> (A \<in> sets lebesgue \<and> emeasure lebesgue A = ereal m)"
hoelzl@40859
   339
proof
hoelzl@41654
   340
  assume "(indicator A has_integral m) UNIV"
hoelzl@41654
   341
  with has_integral_lmeasure[OF this] has_integral_lebesgue[OF this]
hoelzl@49777
   342
  show "A \<in> sets lebesgue \<and> emeasure lebesgue A = ereal m"
hoelzl@41654
   343
    by (auto intro: has_integral_nonneg)
hoelzl@40859
   344
next
hoelzl@49777
   345
  assume "A \<in> sets lebesgue \<and> emeasure lebesgue A = ereal m"
hoelzl@41654
   346
  then show "(indicator A has_integral m) UNIV" by (intro lmeasure_finite_has_integral) auto
hoelzl@38656
   347
qed
hoelzl@38656
   348
hoelzl@41654
   349
lemma lmeasure_eq_integral: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV"
hoelzl@47694
   350
  shows "emeasure lebesgue s = ereal (integral UNIV (indicator s))"
hoelzl@41654
   351
  using assms unfolding integrable_on_def
hoelzl@41654
   352
proof safe
hoelzl@41654
   353
  fix y :: real assume "(indicator s has_integral y) UNIV"
hoelzl@41654
   354
  from this[unfolded has_integral_iff_lmeasure] integral_unique[OF this]
hoelzl@47694
   355
  show "emeasure lebesgue s = ereal (integral UNIV (indicator s))" by simp
hoelzl@40859
   356
qed
hoelzl@38656
   357
hoelzl@38656
   358
lemma lebesgue_simple_function_indicator:
hoelzl@43920
   359
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> ereal"
hoelzl@41689
   360
  assumes f:"simple_function lebesgue f"
hoelzl@38656
   361
  shows "f = (\<lambda>x. (\<Sum>y \<in> f ` UNIV. y * indicator (f -` {y}) x))"
hoelzl@47694
   362
  by (rule, subst simple_function_indicator_representation[OF f]) auto
hoelzl@38656
   363
hoelzl@41654
   364
lemma integral_eq_lmeasure:
hoelzl@47694
   365
  "(indicator s::_\<Rightarrow>real) integrable_on UNIV \<Longrightarrow> integral UNIV (indicator s) = real (emeasure lebesgue s)"
hoelzl@41654
   366
  by (subst lmeasure_eq_integral) (auto intro!: integral_nonneg)
hoelzl@38656
   367
hoelzl@47694
   368
lemma lmeasure_finite: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV" shows "emeasure lebesgue s \<noteq> \<infinity>"
hoelzl@41654
   369
  using lmeasure_eq_integral[OF assms] by auto
hoelzl@38656
   370
hoelzl@40859
   371
lemma negligible_iff_lebesgue_null_sets:
hoelzl@47694
   372
  "negligible A \<longleftrightarrow> A \<in> null_sets lebesgue"
hoelzl@40859
   373
proof
hoelzl@40859
   374
  assume "negligible A"
hoelzl@40859
   375
  from this[THEN lebesgueI_negligible] this[THEN lmeasure_eq_0]
hoelzl@47694
   376
  show "A \<in> null_sets lebesgue" by auto
hoelzl@40859
   377
next
hoelzl@47694
   378
  assume A: "A \<in> null_sets lebesgue"
hoelzl@47694
   379
  then have *:"((indicator A) has_integral (0::real)) UNIV" using lmeasure_finite_has_integral[of A]
hoelzl@47694
   380
    by (auto simp: null_sets_def)
hoelzl@41654
   381
  show "negligible A" unfolding negligible_def
hoelzl@41654
   382
  proof (intro allI)
hoelzl@41654
   383
    fix a b :: 'a
immler@56188
   384
    have integrable: "(indicator A :: _\<Rightarrow>real) integrable_on cbox a b"
immler@56188
   385
      by (intro integrable_on_subcbox has_integral_integrable) (auto intro: *)
immler@56188
   386
    then have "integral (cbox a b) (indicator A) \<le> (integral UNIV (indicator A) :: real)"
hoelzl@47694
   387
      using * by (auto intro!: integral_subset_le)
immler@56188
   388
    moreover have "(0::real) \<le> integral (cbox a b) (indicator A)"
hoelzl@41654
   389
      using integrable by (auto intro!: integral_nonneg)
immler@56188
   390
    ultimately have "integral (cbox a b) (indicator A) = (0::real)"
hoelzl@41654
   391
      using integral_unique[OF *] by auto
immler@56188
   392
    then show "(indicator A has_integral (0::real)) (cbox a b)"
hoelzl@41654
   393
      using integrable_integral[OF integrable] by simp
hoelzl@41654
   394
  qed
hoelzl@41654
   395
qed
hoelzl@41654
   396
hoelzl@47694
   397
lemma lmeasure_UNIV[intro]: "emeasure lebesgue (UNIV::'a::ordered_euclidean_space set) = \<infinity>"
hoelzl@47694
   398
proof (simp add: emeasure_lebesgue, intro SUP_PInfty bexI)
hoelzl@41981
   399
  fix n :: nat
hoelzl@41981
   400
  have "indicator UNIV = (\<lambda>x::'a. 1 :: real)" by auto
hoelzl@41981
   401
  moreover
hoelzl@41981
   402
  { have "real n \<le> (2 * real n) ^ DIM('a)"
hoelzl@41981
   403
    proof (cases n)
hoelzl@41981
   404
      case 0 then show ?thesis by auto
hoelzl@41981
   405
    next
hoelzl@41981
   406
      case (Suc n')
hoelzl@41981
   407
      have "real n \<le> (2 * real n)^1" by auto
hoelzl@41981
   408
      also have "(2 * real n)^1 \<le> (2 * real n) ^ DIM('a)"
hoelzl@50526
   409
        using Suc DIM_positive[where 'a='a] 
hoelzl@50526
   410
        by (intro power_increasing) (auto simp: real_of_nat_Suc simp del: DIM_positive)
hoelzl@41981
   411
      finally show ?thesis .
hoelzl@41981
   412
    qed }
hoelzl@43920
   413
  ultimately show "ereal (real n) \<le> ereal (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))"
hoelzl@41981
   414
    using integral_const DIM_positive[where 'a='a]
immler@56188
   415
    by (auto simp: cube_def content_cbox_cases setprod_constant setsum_negf cbox_interval[symmetric])
hoelzl@41981
   416
qed simp
hoelzl@40859
   417
hoelzl@49777
   418
lemma lmeasure_complete: "A \<subseteq> B \<Longrightarrow> B \<in> null_sets lebesgue \<Longrightarrow> A \<in> null_sets lebesgue"
hoelzl@49777
   419
  unfolding negligible_iff_lebesgue_null_sets[symmetric] by (auto simp: negligible_subset)
hoelzl@49777
   420
hoelzl@40859
   421
lemma
hoelzl@40859
   422
  fixes a b ::"'a::ordered_euclidean_space"
hoelzl@47694
   423
  shows lmeasure_atLeastAtMost[simp]: "emeasure lebesgue {a..b} = ereal (content {a..b})"
hoelzl@41654
   424
proof -
hoelzl@41654
   425
  have "(indicator (UNIV \<inter> {a..b})::_\<Rightarrow>real) integrable_on UNIV"
immler@56188
   426
    unfolding integrable_indicator_UNIV by (simp add: integrable_const indicator_def [abs_def] cbox_interval[symmetric])
hoelzl@41654
   427
  from lmeasure_eq_integral[OF this] show ?thesis unfolding integral_indicator_UNIV
immler@56188
   428
    by (simp add: indicator_def [abs_def] cbox_interval[symmetric])
hoelzl@40859
   429
qed
hoelzl@40859
   430
hoelzl@57138
   431
lemma
hoelzl@57138
   432
  fixes a b ::"'a::ordered_euclidean_space"
hoelzl@57138
   433
  shows lmeasure_cbox[simp]: "emeasure lebesgue (cbox a b) = ereal (content (cbox a b))"
hoelzl@57138
   434
proof -
hoelzl@57138
   435
  have "(indicator (UNIV \<inter> {a..b})::_\<Rightarrow>real) integrable_on UNIV"
hoelzl@57138
   436
    unfolding integrable_indicator_UNIV by (simp add: integrable_const indicator_def [abs_def] cbox_interval[symmetric])
hoelzl@57138
   437
  from lmeasure_eq_integral[OF this] show ?thesis unfolding integral_indicator_UNIV
hoelzl@57138
   438
    by (simp add: indicator_def [abs_def] cbox_interval[symmetric])
hoelzl@57138
   439
qed
hoelzl@57138
   440
hoelzl@40859
   441
lemma lmeasure_singleton[simp]:
hoelzl@47694
   442
  fixes a :: "'a::ordered_euclidean_space" shows "emeasure lebesgue {a} = 0"
hoelzl@41654
   443
  using lmeasure_atLeastAtMost[of a a] by simp
hoelzl@40859
   444
hoelzl@49777
   445
lemma AE_lebesgue_singleton:
hoelzl@49777
   446
  fixes a :: "'a::ordered_euclidean_space" shows "AE x in lebesgue. x \<noteq> a"
hoelzl@49777
   447
  by (rule AE_I[where N="{a}"]) auto
hoelzl@49777
   448
hoelzl@40859
   449
declare content_real[simp]
hoelzl@40859
   450
hoelzl@40859
   451
lemma
hoelzl@40859
   452
  fixes a b :: real
hoelzl@40859
   453
  shows lmeasure_real_greaterThanAtMost[simp]:
hoelzl@47694
   454
    "emeasure lebesgue {a <.. b} = ereal (if a \<le> b then b - a else 0)"
hoelzl@49777
   455
proof -
hoelzl@49777
   456
  have "emeasure lebesgue {a <.. b} = emeasure lebesgue {a .. b}"
hoelzl@49777
   457
    using AE_lebesgue_singleton[of a]
hoelzl@49777
   458
    by (intro emeasure_eq_AE) auto
hoelzl@40859
   459
  then show ?thesis by auto
hoelzl@49777
   460
qed
hoelzl@40859
   461
hoelzl@40859
   462
lemma
hoelzl@40859
   463
  fixes a b :: real
hoelzl@40859
   464
  shows lmeasure_real_atLeastLessThan[simp]:
hoelzl@47694
   465
    "emeasure lebesgue {a ..< b} = ereal (if a \<le> b then b - a else 0)"
hoelzl@49777
   466
proof -
hoelzl@49777
   467
  have "emeasure lebesgue {a ..< b} = emeasure lebesgue {a .. b}"
hoelzl@49777
   468
    using AE_lebesgue_singleton[of b]
hoelzl@49777
   469
    by (intro emeasure_eq_AE) auto
hoelzl@41654
   470
  then show ?thesis by auto
hoelzl@49777
   471
qed
hoelzl@41654
   472
hoelzl@41654
   473
lemma
hoelzl@41654
   474
  fixes a b :: real
hoelzl@41654
   475
  shows lmeasure_real_greaterThanLessThan[simp]:
hoelzl@47694
   476
    "emeasure lebesgue {a <..< b} = ereal (if a \<le> b then b - a else 0)"
hoelzl@49777
   477
proof -
hoelzl@49777
   478
  have "emeasure lebesgue {a <..< b} = emeasure lebesgue {a .. b}"
hoelzl@49777
   479
    using AE_lebesgue_singleton[of a] AE_lebesgue_singleton[of b]
hoelzl@49777
   480
    by (intro emeasure_eq_AE) auto
hoelzl@40859
   481
  then show ?thesis by auto
hoelzl@49777
   482
qed
hoelzl@40859
   483
hoelzl@41706
   484
subsection {* Lebesgue-Borel measure *}
hoelzl@41706
   485
hoelzl@47694
   486
definition "lborel = measure_of UNIV (sets borel) (emeasure lebesgue)"
hoelzl@41689
   487
hoelzl@41689
   488
lemma
hoelzl@41689
   489
  shows space_lborel[simp]: "space lborel = UNIV"
hoelzl@41689
   490
  and sets_lborel[simp]: "sets lborel = sets borel"
hoelzl@47694
   491
  and measurable_lborel1[simp]: "measurable lborel = measurable borel"
hoelzl@47694
   492
  and measurable_lborel2[simp]: "measurable A lborel = measurable A borel"
immler@50244
   493
  using sets.sigma_sets_eq[of borel]
hoelzl@47694
   494
  by (auto simp add: lborel_def measurable_def[abs_def])
hoelzl@40859
   495
hoelzl@56993
   496
(* TODO: switch these rules! *)
hoelzl@47694
   497
lemma emeasure_lborel[simp]: "A \<in> sets borel \<Longrightarrow> emeasure lborel A = emeasure lebesgue A"
hoelzl@47694
   498
  by (rule emeasure_measure_of[OF lborel_def])
hoelzl@47694
   499
     (auto simp: positive_def emeasure_nonneg countably_additive_def intro!: suminf_emeasure)
hoelzl@40859
   500
hoelzl@56993
   501
lemma measure_lborel[simp]: "A \<in> sets borel \<Longrightarrow> measure lborel A = measure lebesgue A"
hoelzl@56993
   502
  unfolding measure_def by simp
hoelzl@56993
   503
hoelzl@41689
   504
interpretation lborel: sigma_finite_measure lborel
hoelzl@47694
   505
proof (default, intro conjI exI[of _ "\<lambda>n. cube n"])
hoelzl@47694
   506
  show "range cube \<subseteq> sets lborel" by (auto intro: borel_closed)
hoelzl@47694
   507
  { fix x :: 'a have "\<exists>n. x\<in>cube n" using mem_big_cube by auto }
hoelzl@47694
   508
  then show "(\<Union>i. cube i) = (space lborel :: 'a set)" using mem_big_cube by auto
hoelzl@47694
   509
  show "\<forall>i. emeasure lborel (cube i) \<noteq> \<infinity>" by (simp add: cube_def)
hoelzl@47694
   510
qed
hoelzl@41689
   511
hoelzl@41689
   512
interpretation lebesgue: sigma_finite_measure lebesgue
hoelzl@40859
   513
proof
hoelzl@47694
   514
  from lborel.sigma_finite guess A :: "nat \<Rightarrow> 'a set" ..
hoelzl@47694
   515
  then show "\<exists>A::nat \<Rightarrow> 'a set. range A \<subseteq> sets lebesgue \<and> (\<Union>i. A i) = space lebesgue \<and> (\<forall>i. emeasure lebesgue (A i) \<noteq> \<infinity>)"
hoelzl@47694
   516
    by (intro exI[of _ A]) (auto simp: subset_eq)
hoelzl@40859
   517
qed
hoelzl@40859
   518
hoelzl@57235
   519
interpretation lborel_pair: pair_sigma_finite lborel lborel ..
hoelzl@57235
   520
hoelzl@49777
   521
lemma Int_stable_atLeastAtMost:
hoelzl@49777
   522
  fixes x::"'a::ordered_euclidean_space"
hoelzl@49777
   523
  shows "Int_stable (range (\<lambda>(a, b::'a). {a..b}))"
immler@56188
   524
  by (auto simp: inter_interval Int_stable_def cbox_interval[symmetric])
hoelzl@49777
   525
hoelzl@49777
   526
lemma lborel_eqI:
hoelzl@49777
   527
  fixes M :: "'a::ordered_euclidean_space measure"
hoelzl@49777
   528
  assumes emeasure_eq: "\<And>a b. emeasure M {a .. b} = content {a .. b}"
hoelzl@49777
   529
  assumes sets_eq: "sets M = sets borel"
hoelzl@49777
   530
  shows "lborel = M"
hoelzl@49777
   531
proof (rule measure_eqI_generator_eq[OF Int_stable_atLeastAtMost])
wenzelm@53015
   532
  let ?P = "\<Pi>\<^sub>M i\<in>{..<DIM('a::ordered_euclidean_space)}. lborel"
hoelzl@49777
   533
  let ?E = "range (\<lambda>(a, b). {a..b} :: 'a set)"
hoelzl@49777
   534
  show "?E \<subseteq> Pow UNIV" "sets lborel = sigma_sets UNIV ?E" "sets M = sigma_sets UNIV ?E"
hoelzl@49777
   535
    by (simp_all add: borel_eq_atLeastAtMost sets_eq)
hoelzl@49777
   536
hoelzl@49777
   537
  show "range cube \<subseteq> ?E" unfolding cube_def [abs_def] by auto
hoelzl@49777
   538
  { fix x :: 'a have "\<exists>n. x \<in> cube n" using mem_big_cube[of x] by fastforce }
hoelzl@49777
   539
  then show "(\<Union>i. cube i :: 'a set) = UNIV" by auto
hoelzl@49777
   540
hoelzl@49777
   541
  { fix i show "emeasure lborel (cube i) \<noteq> \<infinity>" unfolding cube_def by auto }
hoelzl@49777
   542
  { fix X assume "X \<in> ?E" then show "emeasure lborel X = emeasure M X"
hoelzl@49777
   543
      by (auto simp: emeasure_eq) }
hoelzl@49777
   544
qed
hoelzl@49777
   545
hoelzl@56993
   546
hoelzl@56993
   547
(* GENEREALIZE to euclidean_spaces *)
hoelzl@56993
   548
lemma lborel_real_affine:
hoelzl@49777
   549
  fixes c :: real assumes "c \<noteq> 0"
hoelzl@49777
   550
  shows "lborel = density (distr lborel borel (\<lambda>x. t + c * x)) (\<lambda>_. \<bar>c\<bar>)" (is "_ = ?D")
hoelzl@49777
   551
proof (rule lborel_eqI)
hoelzl@49777
   552
  fix a b show "emeasure ?D {a..b} = content {a .. b}"
hoelzl@49777
   553
  proof cases
hoelzl@49777
   554
    assume "0 < c"
hoelzl@49777
   555
    then have "(\<lambda>x. t + c * x) -` {a..b} = {(a - t) / c .. (b - t) / c}"
hoelzl@49777
   556
      by (auto simp: field_simps)
hoelzl@49777
   557
    with `0 < c` show ?thesis
hoelzl@49777
   558
      by (cases "a \<le> b")
hoelzl@56996
   559
         (auto simp: field_simps emeasure_density nn_integral_distr nn_integral_cmult
hoelzl@49777
   560
                     borel_measurable_indicator' emeasure_distr)
hoelzl@49777
   561
  next
hoelzl@49777
   562
    assume "\<not> 0 < c" with `c \<noteq> 0` have "c < 0" by auto
hoelzl@49777
   563
    then have *: "(\<lambda>x. t + c * x) -` {a..b} = {(b - t) / c .. (a - t) / c}"
hoelzl@49777
   564
      by (auto simp: field_simps)
hoelzl@49777
   565
    with `c < 0` show ?thesis
hoelzl@49777
   566
      by (cases "a \<le> b")
hoelzl@56996
   567
         (auto simp: field_simps emeasure_density nn_integral_distr
hoelzl@56996
   568
                     nn_integral_cmult borel_measurable_indicator' emeasure_distr)
hoelzl@49777
   569
  qed
hoelzl@49777
   570
qed simp
hoelzl@49777
   571
hoelzl@56996
   572
lemma nn_integral_real_affine:
hoelzl@56993
   573
  fixes c :: real assumes [measurable]: "f \<in> borel_measurable borel" and c: "c \<noteq> 0"
hoelzl@56993
   574
  shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = \<bar>c\<bar> * (\<integral>\<^sup>+x. f (t + c * x) \<partial>lborel)"
hoelzl@56993
   575
  by (subst lborel_real_affine[OF c, of t])
hoelzl@56996
   576
     (simp add: nn_integral_density nn_integral_distr nn_integral_cmult)
hoelzl@56993
   577
hoelzl@56993
   578
lemma lborel_integrable_real_affine:
hoelzl@56993
   579
  fixes f :: "real \<Rightarrow> _ :: {banach, second_countable_topology}"
hoelzl@56993
   580
  assumes f: "integrable lborel f"
hoelzl@56993
   581
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x))"
hoelzl@56993
   582
  using f f[THEN borel_measurable_integrable] unfolding integrable_iff_bounded
hoelzl@56996
   583
  by (subst (asm) nn_integral_real_affine[where c=c and t=t]) auto
hoelzl@56993
   584
hoelzl@56993
   585
lemma lborel_integrable_real_affine_iff:
hoelzl@56993
   586
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   587
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x)) \<longleftrightarrow> integrable lborel f"
hoelzl@56993
   588
  using
hoelzl@56993
   589
    lborel_integrable_real_affine[of f c t]
hoelzl@56993
   590
    lborel_integrable_real_affine[of "\<lambda>x. f (t + c * x)" "1/c" "-t/c"]
hoelzl@56993
   591
  by (auto simp add: field_simps)
hoelzl@56993
   592
hoelzl@56993
   593
lemma lborel_integral_real_affine:
hoelzl@56993
   594
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}" and c :: real
hoelzl@57166
   595
  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
   596
proof cases
hoelzl@57166
   597
  assume f[measurable]: "integrable lborel f" then show ?thesis
hoelzl@57166
   598
    using c f f[THEN borel_measurable_integrable] f[THEN lborel_integrable_real_affine, of c t]
hoelzl@57166
   599
    by (subst lborel_real_affine[OF c, of t]) (simp add: integral_density integral_distr)
hoelzl@57166
   600
next
hoelzl@57166
   601
  assume "\<not> integrable lborel f" with c show ?thesis
hoelzl@57166
   602
    by (simp add: lborel_integrable_real_affine_iff not_integrable_integral_eq)
hoelzl@57166
   603
qed
hoelzl@56993
   604
hoelzl@56993
   605
lemma divideR_right: 
hoelzl@56993
   606
  fixes x y :: "'a::real_normed_vector"
hoelzl@56993
   607
  shows "r \<noteq> 0 \<Longrightarrow> y = x /\<^sub>R r \<longleftrightarrow> r *\<^sub>R y = x"
hoelzl@56993
   608
  using scaleR_cancel_left[of r y "x /\<^sub>R r"] by simp
hoelzl@56993
   609
hoelzl@56993
   610
lemma integrable_on_cmult_iff2:
hoelzl@56993
   611
  fixes c :: real
hoelzl@56993
   612
  shows "(\<lambda>x. c * f x) integrable_on s \<longleftrightarrow> c = 0 \<or> f integrable_on s"
hoelzl@56993
   613
  using integrable_cmul[of "\<lambda>x. c * f x" s "1 / c"] integrable_cmul[of f s c]
hoelzl@56993
   614
  by (cases "c = 0") auto
hoelzl@56993
   615
hoelzl@56993
   616
lemma lborel_has_bochner_integral_real_affine_iff:
hoelzl@56993
   617
  fixes x :: "'a :: {banach, second_countable_topology}"
hoelzl@56993
   618
  shows "c \<noteq> 0 \<Longrightarrow>
hoelzl@56993
   619
    has_bochner_integral lborel f x \<longleftrightarrow>
hoelzl@56993
   620
    has_bochner_integral lborel (\<lambda>x. f (t + c * x)) (x /\<^sub>R \<bar>c\<bar>)"
hoelzl@56993
   621
  unfolding has_bochner_integral_iff lborel_integrable_real_affine_iff
hoelzl@56993
   622
  by (simp_all add: lborel_integral_real_affine[symmetric] divideR_right cong: conj_cong)
hoelzl@49777
   623
hoelzl@41706
   624
subsection {* Lebesgue integrable implies Gauge integrable *}
hoelzl@41706
   625
hoelzl@56993
   626
lemma has_integral_scaleR_left: 
hoelzl@56993
   627
  "(f has_integral y) s \<Longrightarrow> ((\<lambda>x. f x *\<^sub>R c) has_integral (y *\<^sub>R c)) s"
hoelzl@56993
   628
  using has_integral_linear[OF _ bounded_linear_scaleR_left] by (simp add: comp_def)
hoelzl@56993
   629
hoelzl@56993
   630
lemma has_integral_mult_left:
hoelzl@56993
   631
  fixes c :: "_ :: {real_normed_algebra}"
hoelzl@56993
   632
  shows "(f has_integral y) s \<Longrightarrow> ((\<lambda>x. f x * c) has_integral (y * c)) s"
hoelzl@56993
   633
  using has_integral_linear[OF _ bounded_linear_mult_left] by (simp add: comp_def)
hoelzl@56993
   634
hoelzl@56993
   635
(* GENERALIZE Integration.dominated_convergence, then generalize the following theorems *)
hoelzl@56993
   636
lemma has_integral_dominated_convergence:
hoelzl@56993
   637
  fixes f :: "nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real"
hoelzl@56993
   638
  assumes "\<And>k. (f k has_integral y k) s" "h integrable_on s"
hoelzl@56993
   639
    "\<And>k. \<forall>x\<in>s. norm (f k x) \<le> h x" "\<forall>x\<in>s. (\<lambda>k. f k x) ----> g x"
hoelzl@56993
   640
    and x: "y ----> x"
hoelzl@56993
   641
  shows "(g has_integral x) s"
hoelzl@56993
   642
proof -
hoelzl@56993
   643
  have int_f: "\<And>k. (f k) integrable_on s"
hoelzl@56993
   644
    using assms by (auto simp: integrable_on_def)
hoelzl@56993
   645
  have "(g has_integral (integral s g)) s"
hoelzl@56993
   646
    by (intro integrable_integral dominated_convergence[OF int_f assms(2)]) fact+
hoelzl@56993
   647
  moreover have "integral s g = x"
hoelzl@56993
   648
  proof (rule LIMSEQ_unique)
hoelzl@56993
   649
    show "(\<lambda>i. integral s (f i)) ----> x"
hoelzl@56993
   650
      using integral_unique[OF assms(1)] x by simp
hoelzl@56993
   651
    show "(\<lambda>i. integral s (f i)) ----> integral s g"
hoelzl@56993
   652
      by (intro dominated_convergence[OF int_f assms(2)]) fact+
hoelzl@41654
   653
  qed
hoelzl@56993
   654
  ultimately show ?thesis
hoelzl@56993
   655
    by simp
hoelzl@40859
   656
qed
hoelzl@40859
   657
hoelzl@56996
   658
lemma nn_integral_has_integral:
hoelzl@56993
   659
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@56993
   660
  assumes f: "f \<in> borel_measurable lebesgue" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lebesgue) = ereal r"
hoelzl@56993
   661
  shows "(f has_integral r) UNIV"
hoelzl@56993
   662
using f proof (induct arbitrary: r rule: borel_measurable_induct_real)
hoelzl@56993
   663
  case (set A) then show ?case
hoelzl@56993
   664
    by (auto simp add: ereal_indicator has_integral_iff_lmeasure)
hoelzl@56993
   665
next
hoelzl@56993
   666
  case (mult g c)
hoelzl@56993
   667
  then have "ereal c * (\<integral>\<^sup>+ x. g x \<partial>lebesgue) = ereal r"
hoelzl@56996
   668
    by (subst nn_integral_cmult[symmetric]) auto
hoelzl@56993
   669
  then obtain r' where "(c = 0 \<and> r = 0) \<or> ((\<integral>\<^sup>+ x. ereal (g x) \<partial>lebesgue) = ereal r' \<and> r = c * r')"
hoelzl@56993
   670
    by (cases "\<integral>\<^sup>+ x. ereal (g x) \<partial>lebesgue") (auto split: split_if_asm)
hoelzl@56993
   671
  with mult show ?case
hoelzl@56993
   672
    by (auto intro!: has_integral_cmult_real)
hoelzl@56993
   673
next
hoelzl@56993
   674
  case (add g h)
hoelzl@56993
   675
  moreover
hoelzl@56993
   676
  then have "(\<integral>\<^sup>+ x. h x + g x \<partial>lebesgue) = (\<integral>\<^sup>+ x. h x \<partial>lebesgue) + (\<integral>\<^sup>+ x. g x \<partial>lebesgue)"
hoelzl@56996
   677
    unfolding plus_ereal.simps[symmetric] by (subst nn_integral_add) auto
hoelzl@56993
   678
  with add obtain a b where "(\<integral>\<^sup>+ x. h x \<partial>lebesgue) = ereal a" "(\<integral>\<^sup>+ x. g x \<partial>lebesgue) = ereal b" "r = a + b"
hoelzl@56993
   679
    by (cases "\<integral>\<^sup>+ x. h x \<partial>lebesgue" "\<integral>\<^sup>+ x. g x \<partial>lebesgue" rule: ereal2_cases) auto
hoelzl@56993
   680
  ultimately show ?case
hoelzl@56993
   681
    by (auto intro!: has_integral_add)
hoelzl@56993
   682
next
hoelzl@56993
   683
  case (seq U)
hoelzl@56993
   684
  note seq(1)[measurable] and f[measurable]
hoelzl@40859
   685
hoelzl@56993
   686
  { fix i x 
hoelzl@56993
   687
    have "U i x \<le> f x"
hoelzl@56993
   688
      using seq(5)
hoelzl@56993
   689
      apply (rule LIMSEQ_le_const)
hoelzl@56993
   690
      using seq(4)
hoelzl@56993
   691
      apply (auto intro!: exI[of _ i] simp: incseq_def le_fun_def)
hoelzl@56993
   692
      done }
hoelzl@56993
   693
  note U_le_f = this
hoelzl@56993
   694
  
hoelzl@56993
   695
  { fix i
hoelzl@56993
   696
    have "(\<integral>\<^sup>+x. ereal (U i x) \<partial>lebesgue) \<le> (\<integral>\<^sup>+x. ereal (f x) \<partial>lebesgue)"
hoelzl@56996
   697
      using U_le_f by (intro nn_integral_mono) simp
hoelzl@56993
   698
    then obtain p where "(\<integral>\<^sup>+x. U i x \<partial>lebesgue) = ereal p" "p \<le> r"
hoelzl@56993
   699
      using seq(6) by (cases "\<integral>\<^sup>+x. U i x \<partial>lebesgue") auto
hoelzl@56993
   700
    moreover then have "0 \<le> p"
hoelzl@56996
   701
      by (metis ereal_less_eq(5) nn_integral_nonneg)
hoelzl@56993
   702
    moreover note seq
hoelzl@56993
   703
    ultimately have "\<exists>p. (\<integral>\<^sup>+x. U i x \<partial>lebesgue) = ereal p \<and> 0 \<le> p \<and> p \<le> r \<and> (U i has_integral p) UNIV"
hoelzl@56993
   704
      by auto }
hoelzl@56993
   705
  then obtain p where p: "\<And>i. (\<integral>\<^sup>+x. ereal (U i x) \<partial>lebesgue) = ereal (p i)"
hoelzl@56993
   706
    and bnd: "\<And>i. p i \<le> r" "\<And>i. 0 \<le> p i"
hoelzl@56993
   707
    and U_int: "\<And>i.(U i has_integral (p i)) UNIV" by metis
hoelzl@56993
   708
hoelzl@56993
   709
  have int_eq: "\<And>i. integral UNIV (U i) = p i" using U_int by (rule integral_unique)
hoelzl@56993
   710
hoelzl@56993
   711
  have *: "f integrable_on UNIV \<and> (\<lambda>k. integral UNIV (U k)) ----> integral UNIV f"
hoelzl@56993
   712
  proof (rule monotone_convergence_increasing)
hoelzl@56993
   713
    show "\<forall>k. U k integrable_on UNIV" using U_int by auto
hoelzl@56993
   714
    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
   715
    then show "bounded {integral UNIV (U k) |k. True}"
hoelzl@56993
   716
      using bnd int_eq by (auto simp: bounded_real intro!: exI[of _ r])
hoelzl@56993
   717
    show "\<forall>x\<in>UNIV. (\<lambda>k. U k x) ----> f x"
hoelzl@56993
   718
      using seq by auto
hoelzl@41981
   719
  qed
hoelzl@56993
   720
  moreover have "(\<lambda>i. (\<integral>\<^sup>+x. U i x \<partial>lebesgue)) ----> (\<integral>\<^sup>+x. f x \<partial>lebesgue)"
hoelzl@56996
   721
    using seq U_le_f by (intro nn_integral_dominated_convergence[where w=f]) auto
hoelzl@56993
   722
  ultimately have "integral UNIV f = r"
hoelzl@56993
   723
    by (auto simp add: int_eq p seq intro: LIMSEQ_unique)
hoelzl@56993
   724
  with * show ?case
hoelzl@56993
   725
    by (simp add: has_integral_integral)
hoelzl@40859
   726
qed
hoelzl@40859
   727
hoelzl@56993
   728
lemma has_integral_integrable_lebesgue_nonneg:
hoelzl@56993
   729
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@56993
   730
  assumes f: "integrable lebesgue f" "\<And>x. 0 \<le> f x"
hoelzl@56993
   731
  shows "(f has_integral integral\<^sup>L lebesgue f) UNIV"
hoelzl@56996
   732
proof (rule nn_integral_has_integral)
hoelzl@56993
   733
  show "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) = ereal (integral\<^sup>L lebesgue f)"
hoelzl@56996
   734
    using f by (intro nn_integral_eq_integral) auto
hoelzl@56993
   735
qed (insert f, auto)
hoelzl@56993
   736
hoelzl@56993
   737
lemma has_integral_lebesgue_integral_lebesgue:
hoelzl@56993
   738
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@41981
   739
  assumes f: "integrable lebesgue f"
wenzelm@53015
   740
  shows "(f has_integral (integral\<^sup>L lebesgue f)) UNIV"
hoelzl@56993
   741
using f proof induct
hoelzl@56993
   742
  case (base A c) then show ?case
hoelzl@56993
   743
    by (auto intro!: has_integral_mult_left simp: has_integral_iff_lmeasure)
hoelzl@56993
   744
       (simp add: emeasure_eq_ereal_measure)
hoelzl@56993
   745
next
hoelzl@56993
   746
  case (add f g) then show ?case
hoelzl@56993
   747
    by (auto intro!: has_integral_add)
hoelzl@56993
   748
next
hoelzl@56993
   749
  case (lim f s)
hoelzl@56993
   750
  show ?case
hoelzl@56993
   751
  proof (rule has_integral_dominated_convergence)
hoelzl@56993
   752
    show "\<And>i. (s i has_integral integral\<^sup>L lebesgue (s i)) UNIV" by fact
hoelzl@56993
   753
    show "(\<lambda>x. norm (2 * f x)) integrable_on UNIV"
hoelzl@56993
   754
      using lim by (intro has_integral_integrable[OF has_integral_integrable_lebesgue_nonneg]) auto
hoelzl@56993
   755
    show "\<And>k. \<forall>x\<in>UNIV. norm (s k x) \<le> norm (2 * f x)"
hoelzl@56993
   756
      using lim by (auto simp add: abs_mult)
hoelzl@56993
   757
    show "\<forall>x\<in>UNIV. (\<lambda>k. s k x) ----> f x"
hoelzl@56993
   758
      using lim by auto
hoelzl@56993
   759
    show "(\<lambda>k. integral\<^sup>L lebesgue (s k)) ----> integral\<^sup>L lebesgue f"
hoelzl@57137
   760
      using lim by (intro integral_dominated_convergence[where w="\<lambda>x. 2 * norm (f x)"]) auto
hoelzl@56993
   761
  qed
hoelzl@40859
   762
qed
hoelzl@40859
   763
hoelzl@56996
   764
lemma lebesgue_nn_integral_eq_borel:
hoelzl@41981
   765
  assumes f: "f \<in> borel_measurable borel"
hoelzl@56996
   766
  shows "integral\<^sup>N lebesgue f = integral\<^sup>N lborel f"
hoelzl@41981
   767
proof -
hoelzl@56996
   768
  from f have "integral\<^sup>N lebesgue (\<lambda>x. max 0 (f x)) = integral\<^sup>N lborel (\<lambda>x. max 0 (f x))"
hoelzl@56996
   769
    by (auto intro!: nn_integral_subalgebra[symmetric])
hoelzl@56996
   770
  then show ?thesis unfolding nn_integral_max_0 .
hoelzl@41981
   771
qed
hoelzl@41546
   772
hoelzl@41546
   773
lemma lebesgue_integral_eq_borel:
hoelzl@56993
   774
  fixes f :: "_ \<Rightarrow> _::{banach, second_countable_topology}"
hoelzl@41546
   775
  assumes "f \<in> borel_measurable borel"
hoelzl@41689
   776
  shows "integrable lebesgue f \<longleftrightarrow> integrable lborel f" (is ?P)
wenzelm@53015
   777
    and "integral\<^sup>L lebesgue f = integral\<^sup>L lborel f" (is ?I)
hoelzl@41546
   778
proof -
hoelzl@41689
   779
  have "sets lborel \<subseteq> sets lebesgue" by auto
hoelzl@56993
   780
  from integral_subalgebra[of f lborel, OF _ this _ _]
hoelzl@56993
   781
       integrable_subalgebra[of f lborel, OF _ this _ _] assms
hoelzl@41546
   782
  show ?P ?I by auto
hoelzl@41546
   783
qed
hoelzl@41546
   784
hoelzl@56993
   785
lemma has_integral_lebesgue_integral:
hoelzl@41546
   786
  fixes f::"'a::ordered_euclidean_space => real"
hoelzl@41689
   787
  assumes f:"integrable lborel f"
wenzelm@53015
   788
  shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
hoelzl@41546
   789
proof -
hoelzl@41546
   790
  have borel: "f \<in> borel_measurable borel"
hoelzl@56993
   791
    using f unfolding integrable_iff_bounded by auto
hoelzl@41546
   792
  from f show ?thesis
hoelzl@56993
   793
    using has_integral_lebesgue_integral_lebesgue[of f]
hoelzl@41546
   794
    unfolding lebesgue_integral_eq_borel[OF borel] by simp
hoelzl@41546
   795
qed
hoelzl@41546
   796
hoelzl@56996
   797
lemma nn_integral_bound_simple_function:
hoelzl@56993
   798
  assumes bnd: "\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> f x" "\<And>x. x \<in> space M \<Longrightarrow> f x < \<infinity>"
hoelzl@56993
   799
  assumes f[measurable]: "simple_function M f"
hoelzl@56993
   800
  assumes supp: "emeasure M {x\<in>space M. f x \<noteq> 0} < \<infinity>"
hoelzl@56996
   801
  shows "nn_integral M f < \<infinity>"
hoelzl@56993
   802
proof cases
hoelzl@56993
   803
  assume "space M = {}"
hoelzl@56996
   804
  then have "nn_integral M f = (\<integral>\<^sup>+x. 0 \<partial>M)"
hoelzl@56996
   805
    by (intro nn_integral_cong) auto
hoelzl@56993
   806
  then show ?thesis by simp
hoelzl@56993
   807
next
hoelzl@56993
   808
  assume "space M \<noteq> {}"
hoelzl@56993
   809
  with simple_functionD(1)[OF f] bnd have bnd: "0 \<le> Max (f`space M) \<and> Max (f`space M) < \<infinity>"
hoelzl@56993
   810
    by (subst Max_less_iff) (auto simp: Max_ge_iff)
hoelzl@56993
   811
  
hoelzl@56996
   812
  have "nn_integral M f \<le> (\<integral>\<^sup>+x. Max (f`space M) * indicator {x\<in>space M. f x \<noteq> 0} x \<partial>M)"
hoelzl@56996
   813
  proof (rule nn_integral_mono)
hoelzl@56993
   814
    fix x assume "x \<in> space M"
hoelzl@56993
   815
    with f show "f x \<le> Max (f ` space M) * indicator {x \<in> space M. f x \<noteq> 0} x"
hoelzl@56993
   816
      by (auto split: split_indicator intro!: Max_ge simple_functionD)
hoelzl@56993
   817
  qed
hoelzl@56993
   818
  also have "\<dots> < \<infinity>"
hoelzl@56996
   819
    using bnd supp by (subst nn_integral_cmult) auto
hoelzl@56993
   820
  finally show ?thesis .
hoelzl@56993
   821
qed
hoelzl@56993
   822
hoelzl@56993
   823
hoelzl@56993
   824
lemma
hoelzl@47757
   825
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@49777
   826
  assumes f_borel: "f \<in> borel_measurable lebesgue" and nonneg: "\<And>x. 0 \<le> f x"
hoelzl@47757
   827
  assumes I: "(f has_integral I) UNIV"
hoelzl@56993
   828
  shows integrable_has_integral_lebesgue_nonneg: "integrable lebesgue f"
hoelzl@56993
   829
    and integral_has_integral_lebesgue_nonneg: "integral\<^sup>L lebesgue f = I"
hoelzl@47757
   830
proof -
hoelzl@49777
   831
  from f_borel have "(\<lambda>x. ereal (f x)) \<in> borel_measurable lebesgue" by auto
hoelzl@47757
   832
  from borel_measurable_implies_simple_function_sequence'[OF this] guess F . note F = this
hoelzl@47757
   833
hoelzl@56996
   834
  have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) = (SUP i. integral\<^sup>N lebesgue (F i))"
hoelzl@47757
   835
    using F
hoelzl@56996
   836
    by (subst nn_integral_monotone_convergence_SUP[symmetric])
hoelzl@56996
   837
       (simp_all add: nn_integral_max_0 borel_measurable_simple_function)
hoelzl@47757
   838
  also have "\<dots> \<le> ereal I"
hoelzl@47757
   839
  proof (rule SUP_least)
hoelzl@47757
   840
    fix i :: nat
hoelzl@47757
   841
hoelzl@47757
   842
    { fix z
hoelzl@47757
   843
      from F(4)[of z] have "F i z \<le> ereal (f z)"
haftmann@54863
   844
        by (metis SUP_upper UNIV_I ereal_max_0 max.absorb2 nonneg)
hoelzl@47757
   845
      with F(5)[of i z] have "real (F i z) \<le> f z"
hoelzl@47757
   846
        by (cases "F i z") simp_all }
hoelzl@47757
   847
    note F_bound = this
hoelzl@47757
   848
hoelzl@47757
   849
    { fix x :: ereal assume x: "x \<noteq> 0" "x \<in> range (F i)"
hoelzl@47757
   850
      with F(3,5)[of i] have [simp]: "real x \<noteq> 0"
hoelzl@47757
   851
        by (metis image_iff order_eq_iff real_of_ereal_le_0)
hoelzl@47757
   852
      let ?s = "(\<lambda>n z. real x * indicator (F i -` {x} \<inter> cube n) z) :: nat \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@47757
   853
      have "(\<lambda>z::'a. real x * indicator (F i -` {x}) z) integrable_on UNIV"
hoelzl@47757
   854
      proof (rule dominated_convergence(1))
hoelzl@47757
   855
        fix n :: nat
hoelzl@47757
   856
        have "(\<lambda>z. indicator (F i -` {x} \<inter> cube n) z :: real) integrable_on cube n"
hoelzl@47757
   857
          using x F(1)[of i]
hoelzl@47757
   858
          by (intro lebesgueD) (auto simp: simple_function_def)
hoelzl@47757
   859
        then have cube: "?s n integrable_on cube n"
hoelzl@47757
   860
          by (simp add: integrable_on_cmult_iff)
hoelzl@47757
   861
        show "?s n integrable_on UNIV"
hoelzl@47757
   862
          by (rule integrable_on_superset[OF _ _ cube]) auto
hoelzl@47757
   863
      next
hoelzl@47757
   864
        show "f integrable_on UNIV"
hoelzl@47757
   865
          unfolding integrable_on_def using I by auto
hoelzl@47757
   866
      next
hoelzl@47757
   867
        fix n from F_bound show "\<forall>x\<in>UNIV. norm (?s n x) \<le> f x"
hoelzl@47757
   868
          using nonneg F(5) by (auto split: split_indicator)
hoelzl@47757
   869
      next
hoelzl@47757
   870
        show "\<forall>z\<in>UNIV. (\<lambda>n. ?s n z) ----> real x * indicator (F i -` {x}) z"
hoelzl@47757
   871
        proof
hoelzl@47757
   872
          fix z :: 'a
hoelzl@47757
   873
          from mem_big_cube[of z] guess j .
hoelzl@47757
   874
          then have x: "eventually (\<lambda>n. ?s n z = real x * indicator (F i -` {x}) z) sequentially"
hoelzl@47757
   875
            by (auto intro!: eventually_sequentiallyI[where c=j] dest!: cube_subset split: split_indicator)
hoelzl@47757
   876
          then show "(\<lambda>n. ?s n z) ----> real x * indicator (F i -` {x}) z"
hoelzl@47757
   877
            by (rule Lim_eventually)
hoelzl@47757
   878
        qed
hoelzl@47757
   879
      qed
hoelzl@47757
   880
      then have "(indicator (F i -` {x}) :: 'a \<Rightarrow> real) integrable_on UNIV"
hoelzl@47757
   881
        by (simp add: integrable_on_cmult_iff) }
hoelzl@47757
   882
    note F_finite = lmeasure_finite[OF this]
hoelzl@47757
   883
hoelzl@56993
   884
    have F_eq: "\<And>x. F i x = ereal (norm (real (F i x)))"
hoelzl@56993
   885
      using F(3,5) by (auto simp: fun_eq_iff ereal_real image_iff eq_commute)
hoelzl@56993
   886
    have F_eq2: "\<And>x. F i x = ereal (real (F i x))"
hoelzl@56993
   887
      using F(3,5) by (auto simp: fun_eq_iff ereal_real image_iff eq_commute)
hoelzl@56993
   888
hoelzl@56993
   889
    have int: "integrable lebesgue (\<lambda>x. real (F i x))"
hoelzl@56993
   890
      unfolding integrable_iff_bounded
hoelzl@56993
   891
    proof
hoelzl@56993
   892
      have "(\<integral>\<^sup>+x. F i x \<partial>lebesgue) < \<infinity>"
hoelzl@56996
   893
      proof (rule nn_integral_bound_simple_function)
hoelzl@56993
   894
        fix x::'a assume "x \<in> space lebesgue" then show "0 \<le> F i x" "F i x < \<infinity>"
hoelzl@56993
   895
          using F by (auto simp: image_iff eq_commute)
hoelzl@56993
   896
      next
hoelzl@56993
   897
        have eq: "{x \<in> space lebesgue. F i x \<noteq> 0} = (\<Union>x\<in>F i ` space lebesgue - {0}. F i -` {x} \<inter> space lebesgue)"
hoelzl@56993
   898
          by auto
hoelzl@56993
   899
        show "emeasure lebesgue {x \<in> space lebesgue. F i x \<noteq> 0} < \<infinity>"
hoelzl@56993
   900
          unfolding eq using simple_functionD[OF F(1)]
hoelzl@56993
   901
          by (subst setsum_emeasure[symmetric])
hoelzl@56993
   902
             (auto simp: disjoint_family_on_def setsum_Pinfty F_finite)
hoelzl@56993
   903
      qed fact
hoelzl@56993
   904
      with F_eq show "(\<integral>\<^sup>+x. norm (real (F i x)) \<partial>lebesgue) < \<infinity>" by simp
hoelzl@56993
   905
    qed (insert F(1), auto intro!: borel_measurable_real_of_ereal dest: borel_measurable_simple_function)
hoelzl@56993
   906
    then have "((\<lambda>x. real (F i x)) has_integral integral\<^sup>L lebesgue (\<lambda>x. real (F i x))) UNIV"
hoelzl@56993
   907
      by (rule has_integral_lebesgue_integral_lebesgue)
hoelzl@56993
   908
    from this I have "integral\<^sup>L lebesgue (\<lambda>x. real (F i x)) \<le> I"
hoelzl@47757
   909
      by (rule has_integral_le) (intro ballI F_bound)
hoelzl@56996
   910
    moreover have "integral\<^sup>N lebesgue (F i) = integral\<^sup>L lebesgue (\<lambda>x. real (F i x))"
hoelzl@56996
   911
      using int F by (subst nn_integral_eq_integral[symmetric])  (auto simp: F_eq2[symmetric] real_of_ereal_pos)
hoelzl@56996
   912
    ultimately show "integral\<^sup>N lebesgue (F i) \<le> ereal I"
hoelzl@56993
   913
      by simp
hoelzl@47757
   914
  qed
hoelzl@56993
   915
  finally show "integrable lebesgue f"
hoelzl@56993
   916
    using f_borel by (auto simp: integrable_iff_bounded nonneg)
hoelzl@56993
   917
  from has_integral_lebesgue_integral_lebesgue[OF this] I
hoelzl@56993
   918
  show "integral\<^sup>L lebesgue f = I"
hoelzl@56993
   919
    by (metis has_integral_unique)
hoelzl@47757
   920
qed
hoelzl@47757
   921
hoelzl@56993
   922
lemma has_integral_iff_has_bochner_integral_lebesgue_nonneg:
hoelzl@49777
   923
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@56993
   924
  shows "f \<in> borel_measurable lebesgue \<Longrightarrow> (\<And>x. 0 \<le> f x) \<Longrightarrow>
hoelzl@56993
   925
    (f has_integral I) UNIV \<longleftrightarrow> has_bochner_integral lebesgue f I"
hoelzl@56993
   926
  by (metis has_bochner_integral_iff has_integral_unique has_integral_lebesgue_integral_lebesgue
hoelzl@56993
   927
            integrable_has_integral_lebesgue_nonneg)
hoelzl@49777
   928
hoelzl@56993
   929
lemma
hoelzl@47757
   930
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@56993
   931
  assumes "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(f has_integral I) UNIV"
hoelzl@56993
   932
  shows integrable_has_integral_nonneg: "integrable lborel f"
hoelzl@56993
   933
    and integral_has_integral_nonneg: "integral\<^sup>L lborel f = I"
hoelzl@56993
   934
  by (metis assms borel_measurable_lebesgueI integrable_has_integral_lebesgue_nonneg lebesgue_integral_eq_borel(1))
hoelzl@56993
   935
     (metis assms borel_measurable_lebesgueI has_integral_lebesgue_integral has_integral_unique integrable_has_integral_lebesgue_nonneg lebesgue_integral_eq_borel(1))
hoelzl@49777
   936
hoelzl@49777
   937
subsection {* Equivalence between product spaces and euclidean spaces *}
hoelzl@49777
   938
hoelzl@50526
   939
definition e2p :: "'a::ordered_euclidean_space \<Rightarrow> ('a \<Rightarrow> real)" where
hoelzl@50526
   940
  "e2p x = (\<lambda>i\<in>Basis. x \<bullet> i)"
hoelzl@49777
   941
hoelzl@50526
   942
definition p2e :: "('a \<Rightarrow> real) \<Rightarrow> 'a::ordered_euclidean_space" where
hoelzl@50526
   943
  "p2e x = (\<Sum>i\<in>Basis. x i *\<^sub>R i)"
hoelzl@49777
   944
hoelzl@49777
   945
lemma e2p_p2e[simp]:
hoelzl@50526
   946
  "x \<in> extensional Basis \<Longrightarrow> e2p (p2e x::'a::ordered_euclidean_space) = x"
hoelzl@49777
   947
  by (auto simp: fun_eq_iff extensional_def p2e_def e2p_def)
hoelzl@49777
   948
hoelzl@49777
   949
lemma p2e_e2p[simp]:
hoelzl@49777
   950
  "p2e (e2p x) = (x::'a::ordered_euclidean_space)"
hoelzl@50526
   951
  by (auto simp: euclidean_eq_iff[where 'a='a] p2e_def e2p_def)
hoelzl@49777
   952
hoelzl@49777
   953
interpretation lborel_product: product_sigma_finite "\<lambda>x. lborel::real measure"
hoelzl@49777
   954
  by default
hoelzl@49777
   955
hoelzl@50526
   956
interpretation lborel_space: finite_product_sigma_finite "\<lambda>x. lborel::real measure" "Basis"
hoelzl@49777
   957
  by default auto
hoelzl@49777
   958
hoelzl@49777
   959
lemma sets_product_borel:
hoelzl@49777
   960
  assumes I: "finite I"
wenzelm@53015
   961
  shows "sets (\<Pi>\<^sub>M i\<in>I. lborel) = sigma_sets (\<Pi>\<^sub>E i\<in>I. UNIV) { \<Pi>\<^sub>E i\<in>I. {..< x i :: real} | x. True}" (is "_ = ?G")
hoelzl@49777
   962
proof (subst sigma_prod_algebra_sigma_eq[where S="\<lambda>_ i::nat. {..<real i}" and E="\<lambda>_. range lessThan", OF I])
wenzelm@53015
   963
  show "sigma_sets (space (Pi\<^sub>M I (\<lambda>i. lborel))) {Pi\<^sub>E I F |F. \<forall>i\<in>I. F i \<in> range lessThan} = ?G"
hoelzl@49777
   964
    by (intro arg_cong2[where f=sigma_sets]) (auto simp: space_PiM image_iff bchoice_iff)
immler@54775
   965
qed (auto simp: borel_eq_lessThan eucl_lessThan reals_Archimedean2)
hoelzl@49777
   966
hoelzl@50003
   967
lemma measurable_e2p[measurable]:
wenzelm@53015
   968
  "e2p \<in> measurable (borel::'a::ordered_euclidean_space measure) (\<Pi>\<^sub>M (i::'a)\<in>Basis. (lborel :: real measure))"
hoelzl@49777
   969
proof (rule measurable_sigma_sets[OF sets_product_borel])
wenzelm@53015
   970
  fix A :: "('a \<Rightarrow> real) set" assume "A \<in> {\<Pi>\<^sub>E (i::'a)\<in>Basis. {..<x i} |x. True} "
wenzelm@53015
   971
  then obtain x where  "A = (\<Pi>\<^sub>E (i::'a)\<in>Basis. {..<x i})" by auto
immler@54775
   972
  then have "e2p -` A = {y :: 'a. eucl_less y (\<Sum>i\<in>Basis. x i *\<^sub>R i)}"
immler@54775
   973
    using DIM_positive by (auto simp add: set_eq_iff e2p_def eucl_less_def)
hoelzl@49777
   974
  then show "e2p -` A \<inter> space (borel::'a measure) \<in> sets borel" by simp
hoelzl@49777
   975
qed (auto simp: e2p_def)
hoelzl@49777
   976
hoelzl@50003
   977
(* FIXME: conversion in measurable prover *)
hoelzl@50385
   978
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@50385
   979
lemma lborelD[measurable (raw)]: "A \<in> sets borel \<Longrightarrow> A \<in> sets lborel" by simp
hoelzl@50003
   980
hoelzl@50003
   981
lemma measurable_p2e[measurable]:
wenzelm@53015
   982
  "p2e \<in> measurable (\<Pi>\<^sub>M (i::'a)\<in>Basis. (lborel :: real measure))
hoelzl@49777
   983
    (borel :: 'a::ordered_euclidean_space measure)"
hoelzl@49777
   984
  (is "p2e \<in> measurable ?P _")
hoelzl@49777
   985
proof (safe intro!: borel_measurable_iff_halfspace_le[THEN iffD2])
hoelzl@50526
   986
  fix x and i :: 'a
hoelzl@50526
   987
  let ?A = "{w \<in> space ?P. (p2e w :: 'a) \<bullet> i \<le> x}"
hoelzl@50526
   988
  assume "i \<in> Basis"
wenzelm@53015
   989
  then have "?A = (\<Pi>\<^sub>E j\<in>Basis. if i = j then {.. x} else UNIV)"
hoelzl@50123
   990
    using DIM_positive by (auto simp: space_PiM p2e_def PiE_def split: split_if_asm)
hoelzl@49777
   991
  then show "?A \<in> sets ?P"
hoelzl@49777
   992
    by auto
hoelzl@49777
   993
qed
hoelzl@49777
   994
hoelzl@49777
   995
lemma lborel_eq_lborel_space:
wenzelm@53015
   996
  "(lborel :: 'a measure) = distr (\<Pi>\<^sub>M (i::'a::ordered_euclidean_space)\<in>Basis. lborel) borel p2e"
hoelzl@49777
   997
  (is "?B = ?D")
hoelzl@49777
   998
proof (rule lborel_eqI)
hoelzl@49777
   999
  show "sets ?D = sets borel" by simp
wenzelm@53015
  1000
  let ?P = "(\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel)"
hoelzl@49777
  1001
  fix a b :: 'a
wenzelm@53015
  1002
  have *: "p2e -` {a .. b} \<inter> space ?P = (\<Pi>\<^sub>E i\<in>Basis. {a \<bullet> i .. b \<bullet> i})"
hoelzl@50123
  1003
    by (auto simp: eucl_le[where 'a='a] p2e_def space_PiM PiE_def Pi_iff)
hoelzl@49777
  1004
  have "emeasure ?P (p2e -` {a..b} \<inter> space ?P) = content {a..b}"
hoelzl@49777
  1005
  proof cases
hoelzl@49777
  1006
    assume "{a..b} \<noteq> {}"
hoelzl@49777
  1007
    then have "a \<le> b"
immler@56188
  1008
      by (simp add: eucl_le[where 'a='a])
hoelzl@50526
  1009
    then have "emeasure lborel {a..b} = (\<Prod>x\<in>Basis. emeasure lborel {a \<bullet> x .. b \<bullet> x})"
immler@56188
  1010
      by (auto simp: eucl_le[where 'a='a] content_closed_interval
hoelzl@49777
  1011
               intro!: setprod_ereal[symmetric])
hoelzl@49777
  1012
    also have "\<dots> = emeasure ?P (p2e -` {a..b} \<inter> space ?P)"
hoelzl@49777
  1013
      unfolding * by (subst lborel_space.measure_times) auto
hoelzl@49777
  1014
    finally show ?thesis by simp
hoelzl@49777
  1015
  qed simp
hoelzl@49777
  1016
  then show "emeasure ?D {a .. b} = content {a .. b}"
hoelzl@49777
  1017
    by (simp add: emeasure_distr measurable_p2e)
hoelzl@49777
  1018
qed
hoelzl@49777
  1019
hoelzl@49777
  1020
lemma borel_fubini_positiv_integral:
hoelzl@49777
  1021
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> ereal"
hoelzl@49777
  1022
  assumes f: "f \<in> borel_measurable borel"
hoelzl@56996
  1023
  shows "integral\<^sup>N lborel f = \<integral>\<^sup>+x. f (p2e x) \<partial>(\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel)"
hoelzl@56996
  1024
  by (subst lborel_eq_lborel_space) (simp add: nn_integral_distr measurable_p2e f)
hoelzl@49777
  1025
hoelzl@49777
  1026
lemma borel_fubini_integrable:
hoelzl@56993
  1027
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> _::{banach, second_countable_topology}"
wenzelm@53015
  1028
  shows "integrable lborel f \<longleftrightarrow> integrable (\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel) (\<lambda>x. f (p2e x))"
hoelzl@56993
  1029
  unfolding integrable_iff_bounded
hoelzl@56993
  1030
proof (intro conj_cong[symmetric])
hoelzl@56993
  1031
  show "((\<lambda>x. f (p2e x)) \<in> borel_measurable (Pi\<^sub>M Basis (\<lambda>i. lborel))) = (f \<in> borel_measurable lborel)"
hoelzl@56993
  1032
  proof
hoelzl@56993
  1033
    assume "((\<lambda>x. f (p2e x)) \<in> borel_measurable (Pi\<^sub>M Basis (\<lambda>i. lborel)))"
hoelzl@56993
  1034
    then have "(\<lambda>x. f (p2e (e2p x))) \<in> borel_measurable borel"
hoelzl@56993
  1035
      by measurable
hoelzl@56993
  1036
    then show "f \<in> borel_measurable lborel"
hoelzl@56993
  1037
      by simp
hoelzl@56993
  1038
  qed simp
hoelzl@56993
  1039
qed (simp add: borel_fubini_positiv_integral)
hoelzl@49777
  1040
hoelzl@49777
  1041
lemma borel_fubini:
hoelzl@56993
  1042
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> _::{banach, second_countable_topology}"
hoelzl@56993
  1043
  shows "f \<in> borel_measurable borel \<Longrightarrow>
hoelzl@56993
  1044
    integral\<^sup>L lborel f = \<integral>x. f (p2e x) \<partial>((\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel))"
hoelzl@56993
  1045
  by (subst lborel_eq_lborel_space) (simp add: integral_distr)
hoelzl@47757
  1046
hoelzl@50418
  1047
lemma integrable_on_borel_integrable:
hoelzl@50418
  1048
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@56993
  1049
  shows "f \<in> borel_measurable borel \<Longrightarrow> (\<And>x. 0 \<le> f x) \<Longrightarrow> f integrable_on UNIV \<Longrightarrow> integrable lborel f"
hoelzl@56993
  1050
  by (metis borel_measurable_lebesgueI integrable_has_integral_nonneg integrable_on_def
hoelzl@56993
  1051
            lebesgue_integral_eq_borel(1))
hoelzl@50418
  1052
hoelzl@50418
  1053
subsection {* Fundamental Theorem of Calculus for the Lebesgue integral *}
hoelzl@50418
  1054
hoelzl@57138
  1055
lemma emeasure_bounded_finite:
hoelzl@57138
  1056
  assumes "bounded A" shows "emeasure lborel A < \<infinity>"
hoelzl@57138
  1057
proof -
hoelzl@57138
  1058
  from bounded_subset_cbox[OF `bounded A`] obtain a b where "A \<subseteq> cbox a b"
hoelzl@57138
  1059
    by auto
hoelzl@57138
  1060
  then have "emeasure lborel A \<le> emeasure lborel (cbox a b)"
hoelzl@57138
  1061
    by (intro emeasure_mono) auto
hoelzl@57138
  1062
  then show ?thesis
hoelzl@57138
  1063
    by auto
hoelzl@57138
  1064
qed
hoelzl@57138
  1065
hoelzl@57138
  1066
lemma emeasure_compact_finite: "compact A \<Longrightarrow> emeasure lborel A < \<infinity>"
hoelzl@57138
  1067
  using emeasure_bounded_finite[of A] by (auto intro: compact_imp_bounded)
hoelzl@57138
  1068
hoelzl@57138
  1069
lemma borel_integrable_compact:
hoelzl@57138
  1070
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@57138
  1071
  assumes "compact S" "continuous_on S f"
hoelzl@57138
  1072
  shows "integrable lborel (\<lambda>x. indicator S x *\<^sub>R f x)"
hoelzl@57138
  1073
proof cases
hoelzl@57138
  1074
  assume "S \<noteq> {}"
hoelzl@57138
  1075
  have "continuous_on S (\<lambda>x. norm (f x))"
hoelzl@57138
  1076
    using assms by (intro continuous_intros)
hoelzl@57138
  1077
  from continuous_attains_sup[OF `compact S` `S \<noteq> {}` this]
hoelzl@57138
  1078
  obtain M where M: "\<And>x. x \<in> S \<Longrightarrow> norm (f x) \<le> M"
hoelzl@57138
  1079
    by auto
hoelzl@57138
  1080
hoelzl@57138
  1081
  show ?thesis
hoelzl@57138
  1082
  proof (rule integrable_bound)
hoelzl@57138
  1083
    show "integrable lborel (\<lambda>x. indicator S x * M)"
hoelzl@57138
  1084
      using assms by (auto intro!: emeasure_compact_finite borel_compact integrable_mult_left)
hoelzl@57138
  1085
    show "(\<lambda>x. indicator S x *\<^sub>R f x) \<in> borel_measurable lborel"
hoelzl@57138
  1086
      using assms by (auto intro!: borel_measurable_continuous_on_indicator borel_compact)
hoelzl@57138
  1087
    show "AE x in lborel. norm (indicator S x *\<^sub>R f x) \<le> norm (indicator S x * M)"
hoelzl@57138
  1088
      by (auto split: split_indicator simp: abs_real_def dest!: M)
hoelzl@57138
  1089
  qed
hoelzl@57138
  1090
qed simp
hoelzl@57138
  1091
hoelzl@50418
  1092
lemma borel_integrable_atLeastAtMost:
hoelzl@56993
  1093
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
  1094
  assumes f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
hoelzl@50418
  1095
  shows "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is "integrable _ ?f")
hoelzl@57138
  1096
proof -
hoelzl@57138
  1097
  have "integrable lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x)"
hoelzl@57138
  1098
  proof (rule borel_integrable_compact)
hoelzl@57138
  1099
    from f show "continuous_on {a..b} f"
hoelzl@57138
  1100
      by (auto intro: continuous_at_imp_continuous_on)
hoelzl@57138
  1101
  qed simp
hoelzl@57138
  1102
  then show ?thesis
hoelzl@57138
  1103
    by (auto simp: mult_commute)
hoelzl@57138
  1104
qed
hoelzl@50418
  1105
hoelzl@56181
  1106
lemma has_field_derivative_subset:
hoelzl@56181
  1107
  "(f has_field_derivative y) (at x within s) \<Longrightarrow> t \<subseteq> s \<Longrightarrow> (f has_field_derivative y) (at x within t)"
hoelzl@56181
  1108
  unfolding has_field_derivative_def by (rule has_derivative_subset)
hoelzl@56181
  1109
hoelzl@50418
  1110
lemma integral_FTC_atLeastAtMost:
hoelzl@50418
  1111
  fixes a b :: real
hoelzl@50418
  1112
  assumes "a \<le> b"
hoelzl@50418
  1113
    and F: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> DERIV F x :> f x"
hoelzl@50418
  1114
    and f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
wenzelm@53015
  1115
  shows "integral\<^sup>L lborel (\<lambda>x. f x * indicator {a .. b} x) = F b - F a"
hoelzl@50418
  1116
proof -
hoelzl@50418
  1117
  let ?f = "\<lambda>x. f x * indicator {a .. b} x"
hoelzl@50418
  1118
  have "(?f has_integral (\<integral>x. ?f x \<partial>lborel)) UNIV"
hoelzl@50418
  1119
    using borel_integrable_atLeastAtMost[OF f]
hoelzl@56993
  1120
    by (rule has_integral_lebesgue_integral)
hoelzl@50418
  1121
  moreover
hoelzl@50418
  1122
  have "(f has_integral F b - F a) {a .. b}"
hoelzl@56181
  1123
    by (intro fundamental_theorem_of_calculus)
hoelzl@56181
  1124
       (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
hoelzl@56181
  1125
             intro: has_field_derivative_subset[OF F] assms(1))
hoelzl@50418
  1126
  then have "(?f has_integral F b - F a) {a .. b}"
hoelzl@50418
  1127
    by (subst has_integral_eq_eq[where g=f]) auto
hoelzl@50418
  1128
  then have "(?f has_integral F b - F a) UNIV"
hoelzl@50418
  1129
    by (intro has_integral_on_superset[where t=UNIV and s="{a..b}"]) auto
wenzelm@53015
  1130
  ultimately show "integral\<^sup>L lborel ?f = F b - F a"
hoelzl@50418
  1131
    by (rule has_integral_unique)
hoelzl@50418
  1132
qed
hoelzl@50418
  1133
hoelzl@50418
  1134
text {*
hoelzl@50418
  1135
hoelzl@50418
  1136
For the positive integral we replace continuity with Borel-measurability. 
hoelzl@50418
  1137
hoelzl@50418
  1138
*}
hoelzl@50418
  1139
hoelzl@56993
  1140
lemma
hoelzl@56993
  1141
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
  1142
  assumes f_borel: "f \<in> borel_measurable borel"
hoelzl@50418
  1143
  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@56993
  1144
  shows integral_FTC_Icc_nonneg: "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?eq)
hoelzl@56993
  1145
    and integrable_FTC_Icc_nonneg: "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is ?int)
hoelzl@50418
  1146
proof -
hoelzl@50418
  1147
  have i: "(f has_integral F b - F a) {a..b}"
hoelzl@56181
  1148
    by (intro fundamental_theorem_of_calculus)
hoelzl@56181
  1149
       (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
hoelzl@56181
  1150
             intro: has_field_derivative_subset[OF f(1)] `a \<le> b`)
hoelzl@50418
  1151
  have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) {a..b}"
hoelzl@50418
  1152
    by (rule has_integral_eq[OF _ i]) auto
hoelzl@50418
  1153
  have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) UNIV"
hoelzl@50418
  1154
    by (rule has_integral_on_superset[OF _ _ i]) auto
hoelzl@56993
  1155
  from i f f_borel show ?eq
hoelzl@56993
  1156
    by (intro integral_has_integral_nonneg) (auto split: split_indicator)
hoelzl@56993
  1157
  from i f f_borel show ?int
hoelzl@56993
  1158
    by (intro integrable_has_integral_nonneg) (auto split: split_indicator)
hoelzl@56993
  1159
qed
hoelzl@56993
  1160
hoelzl@56996
  1161
lemma nn_integral_FTC_atLeastAtMost:
hoelzl@56993
  1162
  assumes "f \<in> borel_measurable borel" "\<And>x. x \<in> {a..b} \<Longrightarrow> DERIV F x :> f x" "\<And>x. x \<in> {a..b} \<Longrightarrow> 0 \<le> f x" "a \<le> b"
hoelzl@56993
  1163
  shows "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
hoelzl@56993
  1164
proof -
hoelzl@56993
  1165
  have "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)"
hoelzl@56993
  1166
    by (rule integrable_FTC_Icc_nonneg) fact+
hoelzl@56993
  1167
  then have "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = (\<integral>x. f x * indicator {a .. b} x \<partial>lborel)"
hoelzl@56996
  1168
    using assms by (intro nn_integral_eq_integral) (auto simp: indicator_def)
hoelzl@56993
  1169
  also have "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
hoelzl@56993
  1170
    by (rule integral_FTC_Icc_nonneg) fact+
hoelzl@56993
  1171
  finally show ?thesis
hoelzl@56993
  1172
    unfolding ereal_indicator[symmetric] by simp
hoelzl@50418
  1173
qed
hoelzl@50418
  1174
hoelzl@56996
  1175
lemma nn_integral_FTC_atLeast:
hoelzl@50418
  1176
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
  1177
  assumes f_borel: "f \<in> borel_measurable borel"
hoelzl@50418
  1178
  assumes f: "\<And>x. a \<le> x \<Longrightarrow> DERIV F x :> f x" 
hoelzl@50418
  1179
  assumes nonneg: "\<And>x. a \<le> x \<Longrightarrow> 0 \<le> f x"
hoelzl@50418
  1180
  assumes lim: "(F ---> T) at_top"
wenzelm@53015
  1181
  shows "(\<integral>\<^sup>+x. ereal (f x) * indicator {a ..} x \<partial>lborel) = T - F a"
hoelzl@50418
  1182
proof -
hoelzl@50418
  1183
  let ?f = "\<lambda>(i::nat) (x::real). ereal (f x) * indicator {a..a + real i} x"
hoelzl@50418
  1184
  let ?fR = "\<lambda>x. ereal (f x) * indicator {a ..} x"
hoelzl@50418
  1185
  have "\<And>x. (SUP i::nat. ?f i x) = ?fR x"
hoelzl@50418
  1186
  proof (rule SUP_Lim_ereal)
hoelzl@50418
  1187
    show "\<And>x. incseq (\<lambda>i. ?f i x)"
hoelzl@50418
  1188
      using nonneg by (auto simp: incseq_def le_fun_def split: split_indicator)
hoelzl@50418
  1189
hoelzl@50418
  1190
    fix x
hoelzl@50418
  1191
    from reals_Archimedean2[of "x - a"] guess n ..
hoelzl@50418
  1192
    then have "eventually (\<lambda>n. ?f n x = ?fR x) sequentially"
hoelzl@50418
  1193
      by (auto intro!: eventually_sequentiallyI[where c=n] split: split_indicator)
hoelzl@50418
  1194
    then show "(\<lambda>n. ?f n x) ----> ?fR x"
hoelzl@50418
  1195
      by (rule Lim_eventually)
hoelzl@50418
  1196
  qed
hoelzl@56996
  1197
  then have "integral\<^sup>N lborel ?fR = (\<integral>\<^sup>+ x. (SUP i::nat. ?f i x) \<partial>lborel)"
hoelzl@50418
  1198
    by simp
wenzelm@53015
  1199
  also have "\<dots> = (SUP i::nat. (\<integral>\<^sup>+ x. ?f i x \<partial>lborel))"
hoelzl@56996
  1200
  proof (rule nn_integral_monotone_convergence_SUP)
hoelzl@50418
  1201
    show "incseq ?f"
hoelzl@50418
  1202
      using nonneg by (auto simp: incseq_def le_fun_def split: split_indicator)
hoelzl@50418
  1203
    show "\<And>i. (?f i) \<in> borel_measurable lborel"
hoelzl@50418
  1204
      using f_borel by auto
hoelzl@50418
  1205
    show "\<And>i x. 0 \<le> ?f i x"
hoelzl@50418
  1206
      using nonneg by (auto split: split_indicator)
hoelzl@50418
  1207
  qed
hoelzl@54257
  1208
  also have "\<dots> = (SUP i::nat. ereal (F (a + real i) - F a))"
hoelzl@56996
  1209
    by (subst nn_integral_FTC_atLeastAtMost[OF f_borel f nonneg]) auto
hoelzl@50418
  1210
  also have "\<dots> = T - F a"
hoelzl@50418
  1211
  proof (rule SUP_Lim_ereal)
hoelzl@50418
  1212
    show "incseq (\<lambda>n. ereal (F (a + real n) - F a))"
hoelzl@50418
  1213
    proof (simp add: incseq_def, safe)
hoelzl@50418
  1214
      fix m n :: nat assume "m \<le> n"
hoelzl@50418
  1215
      with f nonneg show "F (a + real m) \<le> F (a + real n)"
hoelzl@50418
  1216
        by (intro DERIV_nonneg_imp_nondecreasing[where f=F])
hoelzl@50418
  1217
           (simp, metis add_increasing2 order_refl order_trans real_of_nat_ge_zero)
hoelzl@50418
  1218
    qed 
hoelzl@50418
  1219
    have "(\<lambda>x. F (a + real x)) ----> T"
hoelzl@50418
  1220
      apply (rule filterlim_compose[OF lim filterlim_tendsto_add_at_top])
hoelzl@50418
  1221
      apply (rule LIMSEQ_const_iff[THEN iffD2, OF refl])
hoelzl@50418
  1222
      apply (rule filterlim_real_sequentially)
hoelzl@50418
  1223
      done
hoelzl@50418
  1224
    then show "(\<lambda>n. ereal (F (a + real n) - F a)) ----> ereal (T - F a)"
hoelzl@50418
  1225
      unfolding lim_ereal
hoelzl@50418
  1226
      by (intro tendsto_diff) auto
hoelzl@50418
  1227
  qed
hoelzl@50418
  1228
  finally show ?thesis .
hoelzl@50418
  1229
qed
hoelzl@50418
  1230
hoelzl@57235
  1231
subsection {* Integration by parts *}
hoelzl@57235
  1232
hoelzl@57235
  1233
lemma integral_by_parts_integrable:
hoelzl@57235
  1234
  fixes f g F G::"real \<Rightarrow> real"
hoelzl@57235
  1235
  assumes "a \<le> b"
hoelzl@57235
  1236
  assumes cont_f[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
hoelzl@57235
  1237
  assumes cont_g[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
hoelzl@57235
  1238
  assumes [intro]: "!!x. DERIV F x :> f x"
hoelzl@57235
  1239
  assumes [intro]: "!!x. DERIV G x :> g x"
hoelzl@57235
  1240
  shows  "integrable lborel (\<lambda>x.((F x) * (g x) + (f x) * (G x)) * indicator {a .. b} x)"
hoelzl@57235
  1241
  by (auto intro!: borel_integrable_atLeastAtMost continuous_intros) (auto intro!: DERIV_isCont)
hoelzl@57235
  1242
hoelzl@57235
  1243
lemma integral_by_parts:
hoelzl@57235
  1244
  fixes f g F G::"real \<Rightarrow> real"
hoelzl@57235
  1245
  assumes [arith]: "a \<le> b"
hoelzl@57235
  1246
  assumes cont_f[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
hoelzl@57235
  1247
  assumes cont_g[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
hoelzl@57235
  1248
  assumes [intro]: "!!x. DERIV F x :> f x"
hoelzl@57235
  1249
  assumes [intro]: "!!x. DERIV G x :> g x"
hoelzl@57235
  1250
  shows "(\<integral>x. (F x * g x) * indicator {a .. b} x \<partial>lborel)
hoelzl@57235
  1251
            =  F b * G b - F a * G a - \<integral>x. (f x * G x) * indicator {a .. b} x \<partial>lborel" 
hoelzl@57235
  1252
proof-
hoelzl@57235
  1253
  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@57235
  1254
    by (rule integral_FTC_atLeastAtMost, auto intro!: derivative_eq_intros continuous_intros) 
hoelzl@57235
  1255
      (auto intro!: DERIV_isCont)
hoelzl@57235
  1256
hoelzl@57235
  1257
  have "(\<integral>x. (F x * g x + f x * G x) * indicator {a .. b} x \<partial>lborel) =
hoelzl@57235
  1258
    (\<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
  1259
    apply (subst integral_add[symmetric])
hoelzl@57235
  1260
    apply (auto intro!: borel_integrable_atLeastAtMost continuous_intros)
hoelzl@57235
  1261
    by (auto intro!: DERIV_isCont integral_cong split:split_indicator)
hoelzl@57235
  1262
hoelzl@57235
  1263
  thus ?thesis using 0 by auto
hoelzl@57235
  1264
qed
hoelzl@57235
  1265
hoelzl@57235
  1266
lemma integral_by_parts':
hoelzl@57235
  1267
  fixes f g F G::"real \<Rightarrow> real"
hoelzl@57235
  1268
  assumes "a \<le> b"
hoelzl@57235
  1269
  assumes "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
hoelzl@57235
  1270
  assumes "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
hoelzl@57235
  1271
  assumes "!!x. DERIV F x :> f x"
hoelzl@57235
  1272
  assumes "!!x. DERIV G x :> g x"
hoelzl@57235
  1273
  shows "(\<integral>x. indicator {a .. b} x *\<^sub>R (F x * g x) \<partial>lborel)
hoelzl@57235
  1274
            =  F b * G b - F a * G a - \<integral>x. indicator {a .. b} x *\<^sub>R (f x * G x) \<partial>lborel" 
hoelzl@57235
  1275
  using integral_by_parts[OF assms] by (simp add: mult_ac)
hoelzl@57235
  1276
hoelzl@57235
  1277
lemma integral_tendsto_at_top:
hoelzl@57235
  1278
  fixes f :: "real \<Rightarrow> real"
hoelzl@57235
  1279
  assumes [simp, intro]: "\<And>x. isCont f x"
hoelzl@57235
  1280
  assumes [simp, arith]: "\<And>x. 0 \<le> f x"
hoelzl@57235
  1281
  assumes [simp]: "integrable lborel f"
hoelzl@57235
  1282
  assumes [measurable]: "f \<in> borel_measurable borel"
hoelzl@57235
  1283
  shows "((\<lambda>x. \<integral>xa. f xa * indicator {0..x} xa \<partial>lborel) ---> \<integral>xa. f xa * indicator {0..} xa \<partial>lborel) at_top"
hoelzl@57235
  1284
  apply (auto intro!: borel_integrable_atLeastAtMost monoI integral_mono tendsto_at_topI_sequentially  
hoelzl@57235
  1285
    split:split_indicator)
hoelzl@57235
  1286
  apply (rule integral_dominated_convergence[where w = " \<lambda>x. f x * indicator {0..} x"])
hoelzl@57235
  1287
  unfolding LIMSEQ_def  
hoelzl@57235
  1288
  apply (auto intro!: AE_I2 tendsto_mult integrable_mult_indicator split: split_indicator)
hoelzl@57235
  1289
  by (metis ge_natfloor_plus_one_imp_gt less_imp_le)
hoelzl@57235
  1290
hoelzl@38656
  1291
end