src/HOL/Probability/Lebesgue_Integration.thy
changeset 49775 970964690b3d
parent 47761 dfe747e72fa8
child 49795 9f2fb9b25a77
equal deleted inserted replaced
49774:dfa8ddb874ce 49775:970964690b3d
  1086     apply (subst SUPR_ereal_add[symmetric, OF inc not_MInf]) .
  1086     apply (subst SUPR_ereal_add[symmetric, OF inc not_MInf]) .
  1087   then show ?thesis by (simp add: positive_integral_max_0)
  1087   then show ?thesis by (simp add: positive_integral_max_0)
  1088 qed
  1088 qed
  1089 
  1089 
  1090 lemma positive_integral_cmult:
  1090 lemma positive_integral_cmult:
  1091   assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x" "0 \<le> c"
  1091   assumes f: "f \<in> borel_measurable M" "0 \<le> c"
  1092   shows "(\<integral>\<^isup>+ x. c * f x \<partial>M) = c * integral\<^isup>P M f"
  1092   shows "(\<integral>\<^isup>+ x. c * f x \<partial>M) = c * integral\<^isup>P M f"
  1093 proof -
  1093 proof -
  1094   have [simp]: "\<And>x. c * max 0 (f x) = max 0 (c * f x)" using `0 \<le> c`
  1094   have [simp]: "\<And>x. c * max 0 (f x) = max 0 (c * f x)" using `0 \<le> c`
  1095     by (auto split: split_max simp: ereal_zero_le_0_iff)
  1095     by (auto split: split_max simp: ereal_zero_le_0_iff)
  1096   have "(\<integral>\<^isup>+ x. c * f x \<partial>M) = (\<integral>\<^isup>+ x. c * max 0 (f x) \<partial>M)"
  1096   have "(\<integral>\<^isup>+ x. c * f x \<partial>M) = (\<integral>\<^isup>+ x. c * max 0 (f x) \<partial>M)"
  1099     using positive_integral_linear[OF _ _ `0 \<le> c`, of "\<lambda>x. max 0 (f x)" _ "\<lambda>x. 0"] f
  1099     using positive_integral_linear[OF _ _ `0 \<le> c`, of "\<lambda>x. max 0 (f x)" _ "\<lambda>x. 0"] f
  1100     by (auto simp: positive_integral_max_0)
  1100     by (auto simp: positive_integral_max_0)
  1101 qed
  1101 qed
  1102 
  1102 
  1103 lemma positive_integral_multc:
  1103 lemma positive_integral_multc:
  1104   assumes "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x" "0 \<le> c"
  1104   assumes "f \<in> borel_measurable M" "0 \<le> c"
  1105   shows "(\<integral>\<^isup>+ x. f x * c \<partial>M) = integral\<^isup>P M f * c"
  1105   shows "(\<integral>\<^isup>+ x. f x * c \<partial>M) = integral\<^isup>P M f * c"
  1106   unfolding mult_commute[of _ c] positive_integral_cmult[OF assms] by simp
  1106   unfolding mult_commute[of _ c] positive_integral_cmult[OF assms] by simp
  1107 
  1107 
  1108 lemma positive_integral_indicator[simp]:
  1108 lemma positive_integral_indicator[simp]:
  1109   "A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+ x. indicator A x\<partial>M) = (emeasure M) A"
  1109   "A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+ x. indicator A x\<partial>M) = (emeasure M) A"
  1110   by (subst positive_integral_eq_simple_integral)
  1110   by (subst positive_integral_eq_simple_integral)
  1111      (auto simp: simple_function_indicator simple_integral_indicator)
  1111      (auto simp: simple_integral_indicator)
  1112 
  1112 
  1113 lemma positive_integral_cmult_indicator:
  1113 lemma positive_integral_cmult_indicator:
  1114   "0 \<le> c \<Longrightarrow> A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+ x. c * indicator A x \<partial>M) = c * (emeasure M) A"
  1114   "0 \<le> c \<Longrightarrow> A \<in> sets M \<Longrightarrow> (\<integral>\<^isup>+ x. c * indicator A x \<partial>M) = c * (emeasure M) A"
  1115   by (subst positive_integral_eq_simple_integral)
  1115   by (subst positive_integral_eq_simple_integral)
  1116      (auto simp: simple_function_indicator simple_integral_indicator)
  1116      (auto simp: simple_function_indicator simple_integral_indicator)
  1149     show ?case using insert by auto
  1149     show ?case using insert by auto
  1150   qed simp
  1150   qed simp
  1151 qed simp
  1151 qed simp
  1152 
  1152 
  1153 lemma positive_integral_Markov_inequality:
  1153 lemma positive_integral_Markov_inequality:
  1154   assumes u: "u \<in> borel_measurable M" "AE x in M. 0 \<le> u x" and "A \<in> sets M" and c: "0 \<le> c" "c \<noteq> \<infinity>"
  1154   assumes u: "u \<in> borel_measurable M" "AE x in M. 0 \<le> u x" and "A \<in> sets M" and c: "0 \<le> c"
  1155   shows "(emeasure M) ({x\<in>space M. 1 \<le> c * u x} \<inter> A) \<le> c * (\<integral>\<^isup>+ x. u x * indicator A x \<partial>M)"
  1155   shows "(emeasure M) ({x\<in>space M. 1 \<le> c * u x} \<inter> A) \<le> c * (\<integral>\<^isup>+ x. u x * indicator A x \<partial>M)"
  1156     (is "(emeasure M) ?A \<le> _ * ?PI")
  1156     (is "(emeasure M) ?A \<le> _ * ?PI")
  1157 proof -
  1157 proof -
  1158   have "?A \<in> sets M"
  1158   have "?A \<in> sets M"
  1159     using `A \<in> sets M` u by auto
  1159     using `A \<in> sets M` u by auto
  1421 
  1421 
  1422 lemma integrable_cong:
  1422 lemma integrable_cong:
  1423   "(\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> integrable M f \<longleftrightarrow> integrable M g"
  1423   "(\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> integrable M f \<longleftrightarrow> integrable M g"
  1424   by (simp cong: positive_integral_cong measurable_cong add: integrable_def)
  1424   by (simp cong: positive_integral_cong measurable_cong add: integrable_def)
  1425 
  1425 
       
  1426 lemma integral_mono_AE:
       
  1427   assumes fg: "integrable M f" "integrable M g"
       
  1428   and mono: "AE t in M. f t \<le> g t"
       
  1429   shows "integral\<^isup>L M f \<le> integral\<^isup>L M g"
       
  1430 proof -
       
  1431   have "AE x in M. ereal (f x) \<le> ereal (g x)"
       
  1432     using mono by auto
       
  1433   moreover have "AE x in M. ereal (- g x) \<le> ereal (- f x)"
       
  1434     using mono by auto
       
  1435   ultimately show ?thesis using fg
       
  1436     by (auto intro!: add_mono positive_integral_mono_AE real_of_ereal_positive_mono
       
  1437              simp: positive_integral_positive lebesgue_integral_def diff_minus)
       
  1438 qed
       
  1439 
       
  1440 lemma integral_mono:
       
  1441   assumes "integrable M f" "integrable M g" "\<And>t. t \<in> space M \<Longrightarrow> f t \<le> g t"
       
  1442   shows "integral\<^isup>L M f \<le> integral\<^isup>L M g"
       
  1443   using assms by (auto intro: integral_mono_AE)
       
  1444 
  1426 lemma positive_integral_eq_integral:
  1445 lemma positive_integral_eq_integral:
  1427   assumes f: "integrable M f"
  1446   assumes f: "integrable M f"
  1428   assumes nonneg: "AE x in M. 0 \<le> f x" 
  1447   assumes nonneg: "AE x in M. 0 \<le> f x" 
  1429   shows "(\<integral>\<^isup>+ x. ereal (f x) \<partial>M) = integral\<^isup>L M f"
  1448   shows "(\<integral>\<^isup>+ x. ereal (f x) \<partial>M) = integral\<^isup>L M f"
  1430 proof -
  1449 proof -
  1569 
  1588 
  1570 lemma lebesgue_integral_cmult_nonneg:
  1589 lemma lebesgue_integral_cmult_nonneg:
  1571   assumes f: "f \<in> borel_measurable M" and "0 \<le> c"
  1590   assumes f: "f \<in> borel_measurable M" and "0 \<le> c"
  1572   shows "(\<integral>x. c * f x \<partial>M) = c * integral\<^isup>L M f"
  1591   shows "(\<integral>x. c * f x \<partial>M) = c * integral\<^isup>L M f"
  1573 proof -
  1592 proof -
  1574   { have "c * real (integral\<^isup>P M (\<lambda>x. max 0 (ereal (f x)))) =
  1593   { have "real (ereal c * integral\<^isup>P M (\<lambda>x. max 0 (ereal (f x)))) =
  1575       real (ereal c * integral\<^isup>P M (\<lambda>x. max 0 (ereal (f x))))"
  1594       real (integral\<^isup>P M (\<lambda>x. ereal c * max 0 (ereal (f x))))"
  1576       by simp
       
  1577     also have "\<dots> = real (integral\<^isup>P M (\<lambda>x. ereal c * max 0 (ereal (f x))))"
       
  1578       using f `0 \<le> c` by (subst positive_integral_cmult) auto
  1595       using f `0 \<le> c` by (subst positive_integral_cmult) auto
  1579     also have "\<dots> = real (integral\<^isup>P M (\<lambda>x. max 0 (ereal (c * f x))))"
  1596     also have "\<dots> = real (integral\<^isup>P M (\<lambda>x. max 0 (ereal (c * f x))))"
  1580       using `0 \<le> c` by (auto intro!: arg_cong[where f=real] positive_integral_cong simp: max_def zero_le_mult_iff)
  1597       using `0 \<le> c` by (auto intro!: arg_cong[where f=real] positive_integral_cong simp: max_def zero_le_mult_iff)
  1581     finally have "real (integral\<^isup>P M (\<lambda>x. ereal (c * f x))) = c * real (integral\<^isup>P M (\<lambda>x. ereal (f x)))"
  1598     finally have "real (integral\<^isup>P M (\<lambda>x. ereal (c * f x))) = c * real (integral\<^isup>P M (\<lambda>x. ereal (f x)))"
  1582       by (simp add: positive_integral_max_0) }
  1599       by (simp add: positive_integral_max_0) }
  1583   moreover
  1600   moreover
  1584   { have "c * real (integral\<^isup>P M (\<lambda>x. max 0 (ereal (- f x)))) =
  1601   { have "real (ereal c * integral\<^isup>P M (\<lambda>x. max 0 (ereal (- f x)))) =
  1585       real (ereal c * integral\<^isup>P M (\<lambda>x. max 0 (ereal (- f x))))"
  1602       real (integral\<^isup>P M (\<lambda>x. ereal c * max 0 (ereal (- f x))))"
  1586       by simp
       
  1587     also have "\<dots> = real (integral\<^isup>P M (\<lambda>x. ereal c * max 0 (ereal (- f x))))"
       
  1588       using f `0 \<le> c` by (subst positive_integral_cmult) auto
  1603       using f `0 \<le> c` by (subst positive_integral_cmult) auto
  1589     also have "\<dots> = real (integral\<^isup>P M (\<lambda>x. max 0 (ereal (- c * f x))))"
  1604     also have "\<dots> = real (integral\<^isup>P M (\<lambda>x. max 0 (ereal (- c * f x))))"
  1590       using `0 \<le> c` by (auto intro!: arg_cong[where f=real] positive_integral_cong simp: max_def mult_le_0_iff)
  1605       using `0 \<le> c` by (auto intro!: arg_cong[where f=real] positive_integral_cong simp: max_def mult_le_0_iff)
  1591     finally have "real (integral\<^isup>P M (\<lambda>x. ereal (- c * f x))) = c * real (integral\<^isup>P M (\<lambda>x. ereal (- f x)))"
  1606     finally have "real (integral\<^isup>P M (\<lambda>x. ereal (- c * f x))) = c * real (integral\<^isup>P M (\<lambda>x. ereal (- f x)))"
  1592       by (simp add: positive_integral_max_0) }
  1607       by (simp add: positive_integral_max_0) }
  1613 lemma integral_multc:
  1628 lemma integral_multc:
  1614   assumes "integrable M f"
  1629   assumes "integrable M f"
  1615   shows "(\<integral> x. f x * c \<partial>M) = integral\<^isup>L M f * c"
  1630   shows "(\<integral> x. f x * c \<partial>M) = integral\<^isup>L M f * c"
  1616   unfolding mult_commute[of _ c] integral_cmult[OF assms] ..
  1631   unfolding mult_commute[of _ c] integral_cmult[OF assms] ..
  1617 
  1632 
  1618 lemma integral_mono_AE:
       
  1619   assumes fg: "integrable M f" "integrable M g"
       
  1620   and mono: "AE t in M. f t \<le> g t"
       
  1621   shows "integral\<^isup>L M f \<le> integral\<^isup>L M g"
       
  1622 proof -
       
  1623   have "AE x in M. ereal (f x) \<le> ereal (g x)"
       
  1624     using mono by auto
       
  1625   moreover have "AE x in M. ereal (- g x) \<le> ereal (- f x)"
       
  1626     using mono by auto
       
  1627   ultimately show ?thesis using fg
       
  1628     by (auto intro!: add_mono positive_integral_mono_AE real_of_ereal_positive_mono
       
  1629              simp: positive_integral_positive lebesgue_integral_def diff_minus)
       
  1630 qed
       
  1631 
       
  1632 lemma integral_mono:
       
  1633   assumes "integrable M f" "integrable M g" "\<And>t. t \<in> space M \<Longrightarrow> f t \<le> g t"
       
  1634   shows "integral\<^isup>L M f \<le> integral\<^isup>L M g"
       
  1635   using assms by (auto intro: integral_mono_AE)
       
  1636 
       
  1637 lemma integral_diff[simp, intro]:
  1633 lemma integral_diff[simp, intro]:
  1638   assumes f: "integrable M f" and g: "integrable M g"
  1634   assumes f: "integrable M f" and g: "integrable M g"
  1639   shows "integrable M (\<lambda>t. f t - g t)"
  1635   shows "integrable M (\<lambda>t. f t - g t)"
  1640   and "(\<integral> t. f t - g t \<partial>M) = integral\<^isup>L M f - integral\<^isup>L M g"
  1636   and "(\<integral> t. f t - g t \<partial>M) = integral\<^isup>L M f - integral\<^isup>L M g"
  1641   using integral_add[OF f integral_minus(1)[OF g]]
  1637   using integral_add[OF f integral_minus(1)[OF g]]
  1683     from this assms show ?thesis by (induct S) simp_all
  1679     from this assms show ?thesis by (induct S) simp_all
  1684   qed simp
  1680   qed simp
  1685   thus "?int S" and "?I S" by auto
  1681   thus "?int S" and "?I S" by auto
  1686 qed
  1682 qed
  1687 
  1683 
       
  1684 lemma integrable_bound:
       
  1685   assumes "integrable M f" and f: "AE x in M. \<bar>g x\<bar> \<le> f x"
       
  1686   assumes borel: "g \<in> borel_measurable M"
       
  1687   shows "integrable M g"
       
  1688 proof -
       
  1689   have "(\<integral>\<^isup>+ x. ereal (g x) \<partial>M) \<le> (\<integral>\<^isup>+ x. ereal \<bar>g x\<bar> \<partial>M)"
       
  1690     by (auto intro!: positive_integral_mono)
       
  1691   also have "\<dots> \<le> (\<integral>\<^isup>+ x. ereal (f x) \<partial>M)"
       
  1692     using f by (auto intro!: positive_integral_mono_AE)
       
  1693   also have "\<dots> < \<infinity>"
       
  1694     using `integrable M f` unfolding integrable_def by auto
       
  1695   finally have pos: "(\<integral>\<^isup>+ x. ereal (g x) \<partial>M) < \<infinity>" .
       
  1696 
       
  1697   have "(\<integral>\<^isup>+ x. ereal (- g x) \<partial>M) \<le> (\<integral>\<^isup>+ x. ereal (\<bar>g x\<bar>) \<partial>M)"
       
  1698     by (auto intro!: positive_integral_mono)
       
  1699   also have "\<dots> \<le> (\<integral>\<^isup>+ x. ereal (f x) \<partial>M)"
       
  1700     using f by (auto intro!: positive_integral_mono_AE)
       
  1701   also have "\<dots> < \<infinity>"
       
  1702     using `integrable M f` unfolding integrable_def by auto
       
  1703   finally have neg: "(\<integral>\<^isup>+ x. ereal (- g x) \<partial>M) < \<infinity>" .
       
  1704 
       
  1705   from neg pos borel show ?thesis
       
  1706     unfolding integrable_def by auto
       
  1707 qed
       
  1708 
  1688 lemma integrable_abs:
  1709 lemma integrable_abs:
  1689   assumes "integrable M f"
  1710   assumes f: "integrable M f"
  1690   shows "integrable M (\<lambda> x. \<bar>f x\<bar>)"
  1711   shows "integrable M (\<lambda> x. \<bar>f x\<bar>)"
  1691 proof -
  1712 proof -
  1692   from assms have *: "(\<integral>\<^isup>+x. ereal (- \<bar>f x\<bar>)\<partial>M) = 0"
  1713   from assms have *: "(\<integral>\<^isup>+x. ereal (- \<bar>f x\<bar>)\<partial>M) = 0"
  1693     "\<And>x. ereal \<bar>f x\<bar> = max 0 (ereal (f x)) + max 0 (ereal (- f x))"
  1714     "\<And>x. ereal \<bar>f x\<bar> = max 0 (ereal (f x)) + max 0 (ereal (- f x))"
  1694     by (auto simp: integrable_def positive_integral_0_iff_AE split: split_max)
  1715     by (auto simp: integrable_def positive_integral_0_iff_AE split: split_max)
  1707     using borel by (auto intro!: positive_integral_subalgebra N)
  1728     using borel by (auto intro!: positive_integral_subalgebra N)
  1708   moreover have "f \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable N"
  1729   moreover have "f \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable N"
  1709     using assms unfolding measurable_def by auto
  1730     using assms unfolding measurable_def by auto
  1710   ultimately show ?P ?I
  1731   ultimately show ?P ?I
  1711     by (auto simp: integrable_def lebesgue_integral_def positive_integral_max_0)
  1732     by (auto simp: integrable_def lebesgue_integral_def positive_integral_max_0)
  1712 qed
       
  1713 
       
  1714 lemma integrable_bound:
       
  1715   assumes "integrable M f"
       
  1716   and f: "\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> f x"
       
  1717     "\<And>x. x \<in> space M \<Longrightarrow> \<bar>g x\<bar> \<le> f x"
       
  1718   assumes borel: "g \<in> borel_measurable M"
       
  1719   shows "integrable M g"
       
  1720 proof -
       
  1721   have "(\<integral>\<^isup>+ x. ereal (g x) \<partial>M) \<le> (\<integral>\<^isup>+ x. ereal \<bar>g x\<bar> \<partial>M)"
       
  1722     by (auto intro!: positive_integral_mono)
       
  1723   also have "\<dots> \<le> (\<integral>\<^isup>+ x. ereal (f x) \<partial>M)"
       
  1724     using f by (auto intro!: positive_integral_mono)
       
  1725   also have "\<dots> < \<infinity>"
       
  1726     using `integrable M f` unfolding integrable_def by auto
       
  1727   finally have pos: "(\<integral>\<^isup>+ x. ereal (g x) \<partial>M) < \<infinity>" .
       
  1728 
       
  1729   have "(\<integral>\<^isup>+ x. ereal (- g x) \<partial>M) \<le> (\<integral>\<^isup>+ x. ereal (\<bar>g x\<bar>) \<partial>M)"
       
  1730     by (auto intro!: positive_integral_mono)
       
  1731   also have "\<dots> \<le> (\<integral>\<^isup>+ x. ereal (f x) \<partial>M)"
       
  1732     using f by (auto intro!: positive_integral_mono)
       
  1733   also have "\<dots> < \<infinity>"
       
  1734     using `integrable M f` unfolding integrable_def by auto
       
  1735   finally have neg: "(\<integral>\<^isup>+ x. ereal (- g x) \<partial>M) < \<infinity>" .
       
  1736 
       
  1737   from neg pos borel show ?thesis
       
  1738     unfolding integrable_def by auto
       
  1739 qed
  1733 qed
  1740 
  1734 
  1741 lemma lebesgue_integral_nonneg:
  1735 lemma lebesgue_integral_nonneg:
  1742   assumes ae: "(AE x in M. 0 \<le> f x)" shows "0 \<le> integral\<^isup>L M f"
  1736   assumes ae: "(AE x in M. 0 \<le> f x)" shows "0 \<le> integral\<^isup>L M f"
  1743 proof -
  1737 proof -
  1758 proof (rule integrable_bound)
  1752 proof (rule integrable_bound)
  1759   show "integrable M (\<lambda>x. \<bar>f x\<bar> + \<bar>g x\<bar>)"
  1753   show "integrable M (\<lambda>x. \<bar>f x\<bar> + \<bar>g x\<bar>)"
  1760     using int by (simp add: integrable_abs)
  1754     using int by (simp add: integrable_abs)
  1761   show "(\<lambda>x. max (f x) (g x)) \<in> borel_measurable M"
  1755   show "(\<lambda>x. max (f x) (g x)) \<in> borel_measurable M"
  1762     using int unfolding integrable_def by auto
  1756     using int unfolding integrable_def by auto
  1763 next
  1757 qed auto
  1764   fix x assume "x \<in> space M"
       
  1765   show "0 \<le> \<bar>f x\<bar> + \<bar>g x\<bar>" "\<bar>max (f x) (g x)\<bar> \<le> \<bar>f x\<bar> + \<bar>g x\<bar>"
       
  1766     by auto
       
  1767 qed
       
  1768 
  1758 
  1769 lemma integrable_min:
  1759 lemma integrable_min:
  1770   assumes int: "integrable M f" "integrable M g"
  1760   assumes int: "integrable M f" "integrable M g"
  1771   shows "integrable M (\<lambda> x. min (f x) (g x))"
  1761   shows "integrable M (\<lambda> x. min (f x) (g x))"
  1772 proof (rule integrable_bound)
  1762 proof (rule integrable_bound)
  1773   show "integrable M (\<lambda>x. \<bar>f x\<bar> + \<bar>g x\<bar>)"
  1763   show "integrable M (\<lambda>x. \<bar>f x\<bar> + \<bar>g x\<bar>)"
  1774     using int by (simp add: integrable_abs)
  1764     using int by (simp add: integrable_abs)
  1775   show "(\<lambda>x. min (f x) (g x)) \<in> borel_measurable M"
  1765   show "(\<lambda>x. min (f x) (g x)) \<in> borel_measurable M"
  1776     using int unfolding integrable_def by auto
  1766     using int unfolding integrable_def by auto
  1777 next
  1767 qed auto
  1778   fix x assume "x \<in> space M"
       
  1779   show "0 \<le> \<bar>f x\<bar> + \<bar>g x\<bar>" "\<bar>min (f x) (g x)\<bar> \<le> \<bar>f x\<bar> + \<bar>g x\<bar>"
       
  1780     by auto
       
  1781 qed
       
  1782 
  1768 
  1783 lemma integral_triangle_inequality:
  1769 lemma integral_triangle_inequality:
  1784   assumes "integrable M f"
  1770   assumes "integrable M f"
  1785   shows "\<bar>integral\<^isup>L M f\<bar> \<le> (\<integral>x. \<bar>f x\<bar> \<partial>M)"
  1771   shows "\<bar>integral\<^isup>L M f\<bar> \<le> (\<integral>x. \<bar>f x\<bar> \<partial>M)"
  1786 proof -
  1772 proof -
  1800     using assms by (rule integral_mono[OF integral_zero(1)])
  1786     using assms by (rule integral_mono[OF integral_zero(1)])
  1801   finally show ?thesis .
  1787   finally show ?thesis .
  1802 qed
  1788 qed
  1803 
  1789 
  1804 lemma integral_monotone_convergence_pos:
  1790 lemma integral_monotone_convergence_pos:
  1805   assumes i: "\<And>i. integrable M (f i)" and mono: "\<And>x. mono (\<lambda>n. f n x)"
  1791   assumes i: "\<And>i. integrable M (f i)" and mono: "AE x in M. mono (\<lambda>n. f n x)"
  1806   and pos: "\<And>x i. 0 \<le> f i x"
  1792     and pos: "\<And>i. AE x in M. 0 \<le> f i x"
  1807   and lim: "\<And>x. (\<lambda>i. f i x) ----> u x"
  1793     and lim: "AE x in M. (\<lambda>i. f i x) ----> u x"
  1808   and ilim: "(\<lambda>i. integral\<^isup>L M (f i)) ----> x"
  1794     and ilim: "(\<lambda>i. integral\<^isup>L M (f i)) ----> x"
       
  1795     and u: "u \<in> borel_measurable M"
  1809   shows "integrable M u"
  1796   shows "integrable M u"
  1810   and "integral\<^isup>L M u = x"
  1797   and "integral\<^isup>L M u = x"
  1811 proof -
  1798 proof -
  1812   { fix x have "0 \<le> u x"
  1799   have "(\<integral>\<^isup>+ x. ereal (u x) \<partial>M) = (SUP n. (\<integral>\<^isup>+ x. ereal (f n x) \<partial>M))"
  1813       using mono pos[of 0 x] incseq_le[OF _ lim, of x 0]
  1800   proof (subst positive_integral_monotone_convergence_SUP_AE[symmetric])
  1814       by (simp add: mono_def incseq_def) }
  1801     fix i
  1815   note pos_u = this
  1802     from mono pos show "AE x in M. ereal (f i x) \<le> ereal (f (Suc i) x) \<and> 0 \<le> ereal (f i x)"
  1816 
  1803       by eventually_elim (auto simp: mono_def)
  1817   have SUP_F: "\<And>x. (SUP n. ereal (f n x)) = ereal (u x)"
  1804     show "(\<lambda>x. ereal (f i x)) \<in> borel_measurable M"
  1818     unfolding SUP_eq_LIMSEQ[OF mono] by (rule lim)
  1805       using i by (auto simp: integrable_def)
  1819 
  1806   next
  1820   have borel_f: "\<And>i. (\<lambda>x. ereal (f i x)) \<in> borel_measurable M"
  1807     show "(\<integral>\<^isup>+ x. ereal (u x) \<partial>M) = \<integral>\<^isup>+ x. (SUP i. ereal (f i x)) \<partial>M"
  1821     using i unfolding integrable_def by auto
  1808       apply (rule positive_integral_cong_AE)
  1822   hence "(\<lambda>x. SUP i. ereal (f i x)) \<in> borel_measurable M"
  1809       using lim mono
  1823     by auto
  1810       by eventually_elim (simp add: SUP_eq_LIMSEQ[THEN iffD2])
  1824   hence borel_u: "u \<in> borel_measurable M"
       
  1825     by (auto simp: borel_measurable_ereal_iff SUP_F)
       
  1826 
       
  1827   hence [simp]: "\<And>i. (\<integral>\<^isup>+x. ereal (- f i x) \<partial>M) = 0" "(\<integral>\<^isup>+x. ereal (- u x) \<partial>M) = 0"
       
  1828     using i borel_u pos pos_u by (auto simp: positive_integral_0_iff_AE integrable_def)
       
  1829 
       
  1830   have integral_eq: "\<And>n. (\<integral>\<^isup>+ x. ereal (f n x) \<partial>M) = ereal (integral\<^isup>L M (f n))"
       
  1831     using i positive_integral_positive[of M] by (auto simp: ereal_real lebesgue_integral_def integrable_def)
       
  1832 
       
  1833   have pos_integral: "\<And>n. 0 \<le> integral\<^isup>L M (f n)"
       
  1834     using pos i by (auto simp: integral_positive)
       
  1835   hence "0 \<le> x"
       
  1836     using LIMSEQ_le_const[OF ilim, of 0] by auto
       
  1837 
       
  1838   from mono pos i have pI: "(\<integral>\<^isup>+ x. ereal (u x) \<partial>M) = (SUP n. (\<integral>\<^isup>+ x. ereal (f n x) \<partial>M))"
       
  1839     by (auto intro!: positive_integral_monotone_convergence_SUP
       
  1840       simp: integrable_def incseq_mono incseq_Suc_iff le_fun_def SUP_F[symmetric])
       
  1841   also have "\<dots> = ereal x" unfolding integral_eq
       
  1842   proof (rule SUP_eq_LIMSEQ[THEN iffD2])
       
  1843     show "mono (\<lambda>n. integral\<^isup>L M (f n))"
       
  1844       using mono i by (auto simp: mono_def intro!: integral_mono)
       
  1845     show "(\<lambda>n. integral\<^isup>L M (f n)) ----> x" using ilim .
       
  1846   qed
  1811   qed
  1847   finally show  "integrable M u" "integral\<^isup>L M u = x" using borel_u `0 \<le> x`
  1812   also have "\<dots> = ereal x"
  1848     unfolding integrable_def lebesgue_integral_def by auto
  1813     using mono i unfolding positive_integral_eq_integral[OF i pos]
       
  1814     by (subst SUP_eq_LIMSEQ) (auto simp: mono_def intro!: integral_mono_AE ilim)
       
  1815   finally have "(\<integral>\<^isup>+ x. ereal (u x) \<partial>M) = ereal x" .
       
  1816   moreover have "(\<integral>\<^isup>+ x. ereal (- u x) \<partial>M) = 0"
       
  1817   proof (subst positive_integral_0_iff_AE)
       
  1818     show "(\<lambda>x. ereal (- u x)) \<in> borel_measurable M"
       
  1819       using u by auto
       
  1820     from mono pos[of 0] lim show "AE x in M. ereal (- u x) \<le> 0"
       
  1821     proof eventually_elim
       
  1822       fix x assume "mono (\<lambda>n. f n x)" "0 \<le> f 0 x" "(\<lambda>i. f i x) ----> u x"
       
  1823       then show "ereal (- u x) \<le> 0"
       
  1824         using incseq_le[of "\<lambda>n. f n x" "u x" 0] by (simp add: mono_def incseq_def)
       
  1825     qed
       
  1826   qed
       
  1827   ultimately show "integrable M u" "integral\<^isup>L M u = x"
       
  1828     by (auto simp: integrable_def lebesgue_integral_def u)
  1849 qed
  1829 qed
  1850 
  1830 
  1851 lemma integral_monotone_convergence:
  1831 lemma integral_monotone_convergence:
  1852   assumes f: "\<And>i. integrable M (f i)" and "mono f"
  1832   assumes f: "\<And>i. integrable M (f i)" and mono: "AE x in M. mono (\<lambda>n. f n x)"
  1853   and lim: "\<And>x. (\<lambda>i. f i x) ----> u x"
  1833   and lim: "AE x in M. (\<lambda>i. f i x) ----> u x"
  1854   and ilim: "(\<lambda>i. integral\<^isup>L M (f i)) ----> x"
  1834   and ilim: "(\<lambda>i. integral\<^isup>L M (f i)) ----> x"
       
  1835   and u: "u \<in> borel_measurable M"
  1855   shows "integrable M u"
  1836   shows "integrable M u"
  1856   and "integral\<^isup>L M u = x"
  1837   and "integral\<^isup>L M u = x"
  1857 proof -
  1838 proof -
  1858   have 1: "\<And>i. integrable M (\<lambda>x. f i x - f 0 x)"
  1839   have 1: "\<And>i. integrable M (\<lambda>x. f i x - f 0 x)"
  1859       using f by (auto intro!: integral_diff)
  1840     using f by auto
  1860   have 2: "\<And>x. mono (\<lambda>n. f n x - f 0 x)" using `mono f`
  1841   have 2: "AE x in M. mono (\<lambda>n. f n x - f 0 x)"
  1861       unfolding mono_def le_fun_def by auto
  1842     using mono by (auto simp: mono_def le_fun_def)
  1862   have 3: "\<And>x n. 0 \<le> f n x - f 0 x" using `mono f`
  1843   have 3: "\<And>n. AE x in M. 0 \<le> f n x - f 0 x"
  1863       unfolding mono_def le_fun_def by (auto simp: field_simps)
  1844     using mono by (auto simp: field_simps mono_def le_fun_def)
  1864   have 4: "\<And>x. (\<lambda>i. f i x - f 0 x) ----> u x - f 0 x"
  1845   have 4: "AE x in M. (\<lambda>i. f i x - f 0 x) ----> u x - f 0 x"
  1865     using lim by (auto intro!: tendsto_diff)
  1846     using lim by (auto intro!: tendsto_diff)
  1866   have 5: "(\<lambda>i. (\<integral>x. f i x - f 0 x \<partial>M)) ----> x - integral\<^isup>L M (f 0)"
  1847   have 5: "(\<lambda>i. (\<integral>x. f i x - f 0 x \<partial>M)) ----> x - integral\<^isup>L M (f 0)"
  1867     using f ilim by (auto intro!: tendsto_diff simp: integral_diff)
  1848     using f ilim by (auto intro!: tendsto_diff)
  1868   note diff = integral_monotone_convergence_pos[OF 1 2 3 4 5]
  1849   have 6: "(\<lambda>x. u x - f 0 x) \<in> borel_measurable M"
       
  1850     using f[of 0] u by auto
       
  1851   note diff = integral_monotone_convergence_pos[OF 1 2 3 4 5 6]
  1869   have "integrable M (\<lambda>x. (u x - f 0 x) + f 0 x)"
  1852   have "integrable M (\<lambda>x. (u x - f 0 x) + f 0 x)"
  1870     using diff(1) f by (rule integral_add(1))
  1853     using diff(1) f by (rule integral_add(1))
  1871   with diff(2) f show "integrable M u" "integral\<^isup>L M u = x"
  1854   with diff(2) f show "integrable M u" "integral\<^isup>L M u = x"
  1872     by (auto simp: integral_diff)
  1855     by auto
  1873 qed
  1856 qed
  1874 
  1857 
  1875 lemma integral_0_iff:
  1858 lemma integral_0_iff:
  1876   assumes "integrable M f"
  1859   assumes "integrable M f"
  1877   shows "(\<integral>x. \<bar>f x\<bar> \<partial>M) = 0 \<longleftrightarrow> (emeasure M) {x\<in>space M. f x \<noteq> 0} = 0"
  1860   shows "(\<integral>x. \<bar>f x\<bar> \<partial>M) = 0 \<longleftrightarrow> (emeasure M) {x\<in>space M. f x \<noteq> 0} = 0"
  1991   assumes gt: "AE x in M. X x < Y x" "(emeasure M) (space M) \<noteq> 0"
  1974   assumes gt: "AE x in M. X x < Y x" "(emeasure M) (space M) \<noteq> 0"
  1992   shows "integral\<^isup>L M X < integral\<^isup>L M Y"
  1975   shows "integral\<^isup>L M X < integral\<^isup>L M Y"
  1993   using gt by (intro integral_less_AE[OF int, where A="space M"]) auto
  1976   using gt by (intro integral_less_AE[OF int, where A="space M"]) auto
  1994 
  1977 
  1995 lemma integral_dominated_convergence:
  1978 lemma integral_dominated_convergence:
  1996   assumes u: "\<And>i. integrable M (u i)" and bound: "\<And>x j. x\<in>space M \<Longrightarrow> \<bar>u j x\<bar> \<le> w x"
  1979   assumes u: "\<And>i. integrable M (u i)" and bound: "\<And>j. AE x in M. \<bar>u j x\<bar> \<le> w x"
  1997   and w: "integrable M w"
  1980   and w: "integrable M w"
  1998   and u': "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. u i x) ----> u' x"
  1981   and u': "AE x in M. (\<lambda>i. u i x) ----> u' x"
       
  1982   and borel: "u' \<in> borel_measurable M"
  1999   shows "integrable M u'"
  1983   shows "integrable M u'"
  2000   and "(\<lambda>i. (\<integral>x. \<bar>u i x - u' x\<bar> \<partial>M)) ----> 0" (is "?lim_diff")
  1984   and "(\<lambda>i. (\<integral>x. \<bar>u i x - u' x\<bar> \<partial>M)) ----> 0" (is "?lim_diff")
  2001   and "(\<lambda>i. integral\<^isup>L M (u i)) ----> integral\<^isup>L M u'" (is ?lim)
  1985   and "(\<lambda>i. integral\<^isup>L M (u i)) ----> integral\<^isup>L M u'" (is ?lim)
  2002 proof -
  1986 proof -
  2003   { fix x j assume x: "x \<in> space M"
  1987   have all_bound: "AE x in M. \<forall>j. \<bar>u j x\<bar> \<le> w x"
  2004     from u'[OF x] have "(\<lambda>i. \<bar>u i x\<bar>) ----> \<bar>u' x\<bar>" by (rule tendsto_rabs)
  1988     using bound by (auto simp: AE_all_countable)
  2005     from LIMSEQ_le_const2[OF this]
  1989   with u' have u'_bound: "AE x in M. \<bar>u' x\<bar> \<le> w x"
  2006     have "\<bar>u' x\<bar> \<le> w x" using bound[OF x] by auto }
  1990     by eventually_elim (auto intro: LIMSEQ_le_const2 tendsto_rabs)
  2007   note u'_bound = this
  1991 
  2008 
  1992   from bound[of 0] have w_pos: "AE x in M. 0 \<le> w x"
  2009   from u[unfolded integrable_def]
  1993     by eventually_elim auto
  2010   have u'_borel: "u' \<in> borel_measurable M"
       
  2011     using u' by (blast intro: borel_measurable_LIMSEQ[of M u])
       
  2012 
       
  2013   { fix x assume x: "x \<in> space M"
       
  2014     then have "0 \<le> \<bar>u 0 x\<bar>" by auto
       
  2015     also have "\<dots> \<le> w x" using bound[OF x] by auto
       
  2016     finally have "0 \<le> w x" . }
       
  2017   note w_pos = this
       
  2018 
  1994 
  2019   show "integrable M u'"
  1995   show "integrable M u'"
  2020   proof (rule integrable_bound)
  1996     by (rule integrable_bound) fact+
  2021     show "integrable M w" by fact
       
  2022     show "u' \<in> borel_measurable M" by fact
       
  2023   next
       
  2024     fix x assume x: "x \<in> space M" then show "0 \<le> w x" by fact
       
  2025     show "\<bar>u' x\<bar> \<le> w x" using u'_bound[OF x] .
       
  2026   qed
       
  2027 
  1997 
  2028   let ?diff = "\<lambda>n x. 2 * w x - \<bar>u n x - u' x\<bar>"
  1998   let ?diff = "\<lambda>n x. 2 * w x - \<bar>u n x - u' x\<bar>"
  2029   have diff: "\<And>n. integrable M (\<lambda>x. \<bar>u n x - u' x\<bar>)"
  1999   have diff: "\<And>n. integrable M (\<lambda>x. \<bar>u n x - u' x\<bar>)"
  2030     using w u `integrable M u'`
  2000     using w u `integrable M u'` by (auto intro!: integrable_abs)
  2031     by (auto intro!: integral_add integral_diff integral_cmult integrable_abs)
  2001 
  2032 
  2002   from u'_bound all_bound
  2033   { fix j x assume x: "x \<in> space M"
  2003   have diff_less_2w: "AE x in M. \<forall>j. \<bar>u j x - u' x\<bar> \<le> 2 * w x"
  2034     have "\<bar>u j x - u' x\<bar> \<le> \<bar>u j x\<bar> + \<bar>u' x\<bar>" by auto
  2004   proof (eventually_elim, intro allI)
       
  2005     fix x j assume *: "\<bar>u' x\<bar> \<le> w x" "\<forall>j. \<bar>u j x\<bar> \<le> w x"
       
  2006     then have "\<bar>u j x - u' x\<bar> \<le> \<bar>u j x\<bar> + \<bar>u' x\<bar>" by auto
  2035     also have "\<dots> \<le> w x + w x"
  2007     also have "\<dots> \<le> w x + w x"
  2036       by (rule add_mono[OF bound[OF x] u'_bound[OF x]])
  2008       using * by (intro add_mono) auto
  2037     finally have "\<bar>u j x - u' x\<bar> \<le> 2 * w x" by simp }
  2009     finally show "\<bar>u j x - u' x\<bar> \<le> 2 * w x" by simp
  2038   note diff_less_2w = this
  2010   qed
  2039 
  2011 
  2040   have PI_diff: "\<And>n. (\<integral>\<^isup>+ x. ereal (?diff n x) \<partial>M) =
  2012   have PI_diff: "\<And>n. (\<integral>\<^isup>+ x. ereal (?diff n x) \<partial>M) =
  2041     (\<integral>\<^isup>+ x. ereal (2 * w x) \<partial>M) - (\<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)"
  2013     (\<integral>\<^isup>+ x. ereal (2 * w x) \<partial>M) - (\<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)"
  2042     using diff w diff_less_2w w_pos
  2014     using diff w diff_less_2w w_pos
  2043     by (subst positive_integral_diff[symmetric])
  2015     by (subst positive_integral_diff[symmetric])
  2044        (auto simp: integrable_def intro!: positive_integral_cong)
  2016        (auto simp: integrable_def intro!: positive_integral_cong_AE)
  2045 
  2017 
  2046   have "integrable M (\<lambda>x. 2 * w x)"
  2018   have "integrable M (\<lambda>x. 2 * w x)"
  2047     using w by (auto intro: integral_cmult)
  2019     using w by auto
  2048   hence I2w_fin: "(\<integral>\<^isup>+ x. ereal (2 * w x) \<partial>M) \<noteq> \<infinity>" and
  2020   hence I2w_fin: "(\<integral>\<^isup>+ x. ereal (2 * w x) \<partial>M) \<noteq> \<infinity>" and
  2049     borel_2w: "(\<lambda>x. ereal (2 * w x)) \<in> borel_measurable M"
  2021     borel_2w: "(\<lambda>x. ereal (2 * w x)) \<in> borel_measurable M"
  2050     unfolding integrable_def by auto
  2022     unfolding integrable_def by auto
  2051 
  2023 
  2052   have "limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M) = 0" (is "limsup ?f = 0")
  2024   have "limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M) = 0" (is "limsup ?f = 0")
  2053   proof cases
  2025   proof cases
  2054     assume eq_0: "(\<integral>\<^isup>+ x. max 0 (ereal (2 * w x)) \<partial>M) = 0" (is "?wx = 0")
  2026     assume eq_0: "(\<integral>\<^isup>+ x. max 0 (ereal (2 * w x)) \<partial>M) = 0" (is "?wx = 0")
  2055     { fix n
  2027     { fix n
  2056       have "?f n \<le> ?wx" (is "integral\<^isup>P M ?f' \<le> _")
  2028       have "?f n \<le> ?wx" (is "integral\<^isup>P M ?f' \<le> _")
  2057         using diff_less_2w[of _ n] unfolding positive_integral_max_0
  2029         using diff_less_2w unfolding positive_integral_max_0
  2058         by (intro positive_integral_mono) auto
  2030         by (intro positive_integral_mono_AE) auto
  2059       then have "?f n = 0"
  2031       then have "?f n = 0"
  2060         using positive_integral_positive[of M ?f'] eq_0 by auto }
  2032         using positive_integral_positive[of M ?f'] eq_0 by auto }
  2061     then show ?thesis by (simp add: Limsup_const)
  2033     then show ?thesis by (simp add: Limsup_const)
  2062   next
  2034   next
  2063     assume neq_0: "(\<integral>\<^isup>+ x. max 0 (ereal (2 * w x)) \<partial>M) \<noteq> 0" (is "?wx \<noteq> 0")
  2035     assume neq_0: "(\<integral>\<^isup>+ x. max 0 (ereal (2 * w x)) \<partial>M) \<noteq> 0" (is "?wx \<noteq> 0")
  2064     have "0 = limsup (\<lambda>n. 0 :: ereal)" by (simp add: Limsup_const)
  2036     have "0 = limsup (\<lambda>n. 0 :: ereal)" by (simp add: Limsup_const)
  2065     also have "\<dots> \<le> limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)"
  2037     also have "\<dots> \<le> limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)"
  2066       by (intro limsup_mono positive_integral_positive)
  2038       by (intro limsup_mono positive_integral_positive)
  2067     finally have pos: "0 \<le> limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)" .
  2039     finally have pos: "0 \<le> limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)" .
  2068     have "?wx = (\<integral>\<^isup>+ x. liminf (\<lambda>n. max 0 (ereal (?diff n x))) \<partial>M)"
  2040     have "?wx = (\<integral>\<^isup>+ x. liminf (\<lambda>n. max 0 (ereal (?diff n x))) \<partial>M)"
  2069     proof (rule positive_integral_cong)
  2041       using u'
  2070       fix x assume x: "x \<in> space M"
  2042     proof (intro positive_integral_cong_AE, eventually_elim)
       
  2043       fix x assume u': "(\<lambda>i. u i x) ----> u' x"
  2071       show "max 0 (ereal (2 * w x)) = liminf (\<lambda>n. max 0 (ereal (?diff n x)))"
  2044       show "max 0 (ereal (2 * w x)) = liminf (\<lambda>n. max 0 (ereal (?diff n x)))"
  2072         unfolding ereal_max_0
  2045         unfolding ereal_max_0
  2073       proof (rule lim_imp_Liminf[symmetric], unfold lim_ereal)
  2046       proof (rule lim_imp_Liminf[symmetric], unfold lim_ereal)
  2074         have "(\<lambda>i. ?diff i x) ----> 2 * w x - \<bar>u' x - u' x\<bar>"
  2047         have "(\<lambda>i. ?diff i x) ----> 2 * w x - \<bar>u' x - u' x\<bar>"
  2075           using u'[OF x] by (safe intro!: tendsto_intros)
  2048           using u' by (safe intro!: tendsto_intros)
  2076         then show "(\<lambda>i. max 0 (?diff i x)) ----> max 0 (2 * w x)"
  2049         then show "(\<lambda>i. max 0 (?diff i x)) ----> max 0 (2 * w x)"
  2077           by (auto intro!: tendsto_real_max simp add: lim_ereal)
  2050           by (auto intro!: tendsto_real_max)
  2078       qed (rule trivial_limit_sequentially)
  2051       qed (rule trivial_limit_sequentially)
  2079     qed
  2052     qed
  2080     also have "\<dots> \<le> liminf (\<lambda>n. \<integral>\<^isup>+ x. max 0 (ereal (?diff n x)) \<partial>M)"
  2053     also have "\<dots> \<le> liminf (\<lambda>n. \<integral>\<^isup>+ x. max 0 (ereal (?diff n x)) \<partial>M)"
  2081       using u'_borel w u unfolding integrable_def
  2054       using borel w u unfolding integrable_def
  2082       by (intro positive_integral_lim_INF) (auto intro!: positive_integral_lim_INF)
  2055       by (intro positive_integral_lim_INF) (auto intro!: positive_integral_lim_INF)
  2083     also have "\<dots> = (\<integral>\<^isup>+ x. ereal (2 * w x) \<partial>M) -
  2056     also have "\<dots> = (\<integral>\<^isup>+ x. ereal (2 * w x) \<partial>M) -
  2084         limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)"
  2057         limsup (\<lambda>n. \<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M)"
  2085       unfolding PI_diff positive_integral_max_0
  2058       unfolding PI_diff positive_integral_max_0
  2086       using positive_integral_positive[of M "\<lambda>x. ereal (2 * w x)"]
  2059       using positive_integral_positive[of M "\<lambda>x. ereal (2 * w x)"]
  2104   have "\<And>n. (\<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M) = ereal (\<integral>x. \<bar>u n x - u' x\<bar> \<partial>M)"
  2077   have "\<And>n. (\<integral>\<^isup>+ x. ereal \<bar>u n x - u' x\<bar> \<partial>M) = ereal (\<integral>x. \<bar>u n x - u' x\<bar> \<partial>M)"
  2105     using diff positive_integral_positive[of M]
  2078     using diff positive_integral_positive[of M]
  2106     by (subst integral_eq_positive_integral[of _ M]) (auto simp: ereal_real integrable_def)
  2079     by (subst integral_eq_positive_integral[of _ M]) (auto simp: ereal_real integrable_def)
  2107   then show ?lim_diff
  2080   then show ?lim_diff
  2108     using ereal_Liminf_eq_Limsup[OF trivial_limit_sequentially liminf_limsup_eq]
  2081     using ereal_Liminf_eq_Limsup[OF trivial_limit_sequentially liminf_limsup_eq]
  2109     by (simp add: lim_ereal)
  2082     by simp
  2110 
  2083 
  2111   show ?lim
  2084   show ?lim
  2112   proof (rule LIMSEQ_I)
  2085   proof (rule LIMSEQ_I)
  2113     fix r :: real assume "0 < r"
  2086     fix r :: real assume "0 < r"
  2114     from LIMSEQ_D[OF `?lim_diff` this]
  2087     from LIMSEQ_D[OF `?lim_diff` this]
  2117 
  2090 
  2118     show "\<exists>N. \<forall>n\<ge>N. norm (integral\<^isup>L M (u n) - integral\<^isup>L M u') < r"
  2091     show "\<exists>N. \<forall>n\<ge>N. norm (integral\<^isup>L M (u n) - integral\<^isup>L M u') < r"
  2119     proof (safe intro!: exI[of _ N])
  2092     proof (safe intro!: exI[of _ N])
  2120       fix n assume "N \<le> n"
  2093       fix n assume "N \<le> n"
  2121       have "\<bar>integral\<^isup>L M (u n) - integral\<^isup>L M u'\<bar> = \<bar>(\<integral>x. u n x - u' x \<partial>M)\<bar>"
  2094       have "\<bar>integral\<^isup>L M (u n) - integral\<^isup>L M u'\<bar> = \<bar>(\<integral>x. u n x - u' x \<partial>M)\<bar>"
  2122         using u `integrable M u'` by (auto simp: integral_diff)
  2095         using u `integrable M u'` by auto
  2123       also have "\<dots> \<le> (\<integral>x. \<bar>u n x - u' x\<bar> \<partial>M)" using u `integrable M u'`
  2096       also have "\<dots> \<le> (\<integral>x. \<bar>u n x - u' x\<bar> \<partial>M)" using u `integrable M u'`
  2124         by (rule_tac integral_triangle_inequality) (auto intro!: integral_diff)
  2097         by (rule_tac integral_triangle_inequality) auto
  2125       also note N[OF `N \<le> n`]
  2098       also note N[OF `N \<le> n`]
  2126       finally show "norm (integral\<^isup>L M (u n) - integral\<^isup>L M u') < r" by simp
  2099       finally show "norm (integral\<^isup>L M (u n) - integral\<^isup>L M u') < r" by simp
  2127     qed
  2100     qed
  2128   qed
  2101   qed
  2129 qed
  2102 qed
  2137 proof -
  2110 proof -
  2138   have "\<forall>x\<in>space M. \<exists>w. (\<lambda>i. \<bar>f i x\<bar>) sums w"
  2111   have "\<forall>x\<in>space M. \<exists>w. (\<lambda>i. \<bar>f i x\<bar>) sums w"
  2139     using summable unfolding summable_def by auto
  2112     using summable unfolding summable_def by auto
  2140   from bchoice[OF this]
  2113   from bchoice[OF this]
  2141   obtain w where w: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. \<bar>f i x\<bar>) sums w x" by auto
  2114   obtain w where w: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. \<bar>f i x\<bar>) sums w x" by auto
       
  2115   then have w_borel: "w \<in> borel_measurable M" unfolding sums_def
       
  2116     by (rule borel_measurable_LIMSEQ) (auto simp: borel[THEN integrableD(1)])
  2142 
  2117 
  2143   let ?w = "\<lambda>y. if y \<in> space M then w y else 0"
  2118   let ?w = "\<lambda>y. if y \<in> space M then w y else 0"
  2144 
  2119 
  2145   obtain x where abs_sum: "(\<lambda>i. (\<integral>x. \<bar>f i x\<bar> \<partial>M)) sums x"
  2120   obtain x where abs_sum: "(\<lambda>i. (\<integral>x. \<bar>f i x\<bar> \<partial>M)) sums x"
  2146     using sums unfolding summable_def ..
  2121     using sums unfolding summable_def ..
  2147 
  2122 
  2148   have 1: "\<And>n. integrable M (\<lambda>x. \<Sum>i = 0..<n. f i x)"
  2123   have 1: "\<And>n. integrable M (\<lambda>x. \<Sum>i = 0..<n. f i x)"
  2149     using borel by (auto intro!: integral_setsum)
  2124     using borel by auto
  2150 
  2125 
  2151   { fix j x assume [simp]: "x \<in> space M"
  2126   have 2: "\<And>j. AE x in M. \<bar>\<Sum>i = 0..<j. f i x\<bar> \<le> ?w x"
       
  2127     using AE_space
       
  2128   proof eventually_elim
       
  2129     fix j x assume [simp]: "x \<in> space M"
  2152     have "\<bar>\<Sum>i = 0..< j. f i x\<bar> \<le> (\<Sum>i = 0..< j. \<bar>f i x\<bar>)" by (rule setsum_abs)
  2130     have "\<bar>\<Sum>i = 0..< j. f i x\<bar> \<le> (\<Sum>i = 0..< j. \<bar>f i x\<bar>)" by (rule setsum_abs)
  2153     also have "\<dots> \<le> w x" using w[of x] series_pos_le[of "\<lambda>i. \<bar>f i x\<bar>"] unfolding sums_iff by auto
  2131     also have "\<dots> \<le> w x" using w[of x] series_pos_le[of "\<lambda>i. \<bar>f i x\<bar>"] unfolding sums_iff by auto
  2154     finally have "\<bar>\<Sum>i = 0..<j. f i x\<bar> \<le> ?w x" by simp }
  2132     finally show "\<bar>\<Sum>i = 0..<j. f i x\<bar> \<le> ?w x" by simp
  2155   note 2 = this
  2133   qed
  2156 
  2134 
  2157   have 3: "integrable M ?w"
  2135   have 3: "integrable M ?w"
  2158   proof (rule integral_monotone_convergence(1))
  2136   proof (rule integral_monotone_convergence(1))
  2159     let ?F = "\<lambda>n y. (\<Sum>i = 0..<n. \<bar>f i y\<bar>)"
  2137     let ?F = "\<lambda>n y. (\<Sum>i = 0..<n. \<bar>f i y\<bar>)"
  2160     let ?w' = "\<lambda>n y. if y \<in> space M then ?F n y else 0"
  2138     let ?w' = "\<lambda>n y. if y \<in> space M then ?F n y else 0"
  2161     have "\<And>n. integrable M (?F n)"
  2139     have "\<And>n. integrable M (?F n)"
  2162       using borel by (auto intro!: integral_setsum integrable_abs)
  2140       using borel by (auto intro!: integral_setsum integrable_abs)
  2163     thus "\<And>n. integrable M (?w' n)" by (simp cong: integrable_cong)
  2141     thus "\<And>n. integrable M (?w' n)" by (simp cong: integrable_cong)
  2164     show "mono ?w'"
  2142     show "AE x in M. mono (\<lambda>n. ?w' n x)"
  2165       by (auto simp: mono_def le_fun_def intro!: setsum_mono2)
  2143       by (auto simp: mono_def le_fun_def intro!: setsum_mono2)
  2166     { fix x show "(\<lambda>n. ?w' n x) ----> ?w x"
  2144     show "AE x in M. (\<lambda>n. ?w' n x) ----> ?w x"
  2167         using w by (cases "x \<in> space M") (simp_all add: tendsto_const sums_def) }
  2145         using w by (simp_all add: tendsto_const sums_def)
  2168     have *: "\<And>n. integral\<^isup>L M (?w' n) = (\<Sum>i = 0..< n. (\<integral>x. \<bar>f i x\<bar> \<partial>M))"
  2146     have *: "\<And>n. integral\<^isup>L M (?w' n) = (\<Sum>i = 0..< n. (\<integral>x. \<bar>f i x\<bar> \<partial>M))"
  2169       using borel by (simp add: integral_setsum integrable_abs cong: integral_cong)
  2147       using borel by (simp add: integrable_abs cong: integral_cong)
  2170     from abs_sum
  2148     from abs_sum
  2171     show "(\<lambda>i. integral\<^isup>L M (?w' i)) ----> x" unfolding * sums_def .
  2149     show "(\<lambda>i. integral\<^isup>L M (?w' i)) ----> x" unfolding * sums_def .
  2172   qed
  2150   qed (simp add: w_borel measurable_If_set)
  2173 
  2151 
  2174   from summable[THEN summable_rabs_cancel]
  2152   from summable[THEN summable_rabs_cancel]
  2175   have 4: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>n. \<Sum>i = 0..<n. f i x) ----> (\<Sum>i. f i x)"
  2153   have 4: "AE x in M. (\<lambda>n. \<Sum>i = 0..<n. f i x) ----> (\<Sum>i. f i x)"
  2176     by (auto intro: summable_sumr_LIMSEQ_suminf)
  2154     by (auto intro: summable_sumr_LIMSEQ_suminf)
  2177 
  2155 
  2178   note int = integral_dominated_convergence(1,3)[OF 1 2 3 4]
  2156   note int = integral_dominated_convergence(1,3)[OF 1 2 3 4
       
  2157     borel_measurable_suminf[OF integrableD(1)[OF borel]]]
  2179 
  2158 
  2180   from int show "integrable M ?S" by simp
  2159   from int show "integrable M ?S" by simp
  2181 
  2160 
  2182   show ?integral unfolding sums_def integral_setsum(1)[symmetric, OF borel]
  2161   show ?integral unfolding sums_def integral_setsum(1)[symmetric, OF borel]
  2183     using int(2) by simp
  2162     using int(2) by simp
  2282   then show ?thesis
  2261   then show ?thesis
  2283     using f unfolding lebesgue_integral_def integrable_def
  2262     using f unfolding lebesgue_integral_def integrable_def
  2284     by (auto simp: borel[THEN positive_integral_distr[OF T]])
  2263     by (auto simp: borel[THEN positive_integral_distr[OF T]])
  2285 qed
  2264 qed
  2286 
  2265 
       
  2266 lemma integrable_distr_eq:
       
  2267   assumes T: "T \<in> measurable M M'" "f \<in> borel_measurable M'"
       
  2268   shows "integrable (distr M M' T) f \<longleftrightarrow> integrable M (\<lambda>x. f (T x))"
       
  2269   using T measurable_comp[OF T]
       
  2270   unfolding integrable_def 
       
  2271   by (subst (1 2) positive_integral_distr) (auto simp: comp_def)
       
  2272 
  2287 lemma integrable_distr:
  2273 lemma integrable_distr:
  2288   assumes T: "T \<in> measurable M M'" and f: "integrable (distr M M' T) f"
  2274   assumes T: "T \<in> measurable M M'" shows "integrable (distr M M' T) f \<Longrightarrow> integrable M (\<lambda>x. f (T x))"
  2289   shows "integrable M (\<lambda>x. f (T x))"
  2275   by (subst integrable_distr_eq[symmetric, OF T]) auto
  2290 proof -
       
  2291   from measurable_comp[OF T, of f borel]
       
  2292   have borel: "(\<lambda>x. ereal (f x)) \<in> borel_measurable M'" "(\<lambda>x. ereal (- f x)) \<in> borel_measurable M'"
       
  2293     and "(\<lambda>x. f (T x)) \<in> borel_measurable M"
       
  2294     using f by (auto simp: comp_def)
       
  2295   then show ?thesis
       
  2296     using f unfolding lebesgue_integral_def integrable_def
       
  2297     using borel[THEN positive_integral_distr[OF T]]
       
  2298     by (auto simp: borel[THEN positive_integral_distr[OF T]])
       
  2299 qed
       
  2300 
  2276 
  2301 section {* Lebesgue integration on @{const count_space} *}
  2277 section {* Lebesgue integration on @{const count_space} *}
  2302 
  2278 
  2303 lemma simple_function_count_space[simp]:
  2279 lemma simple_function_count_space[simp]:
  2304   "simple_function (count_space A) f \<longleftrightarrow> finite (f ` A)"
  2280   "simple_function (count_space A) f \<longleftrightarrow> finite (f ` A)"
  2327 lemma positive_integral_count_space_finite:
  2303 lemma positive_integral_count_space_finite:
  2328     "finite A \<Longrightarrow> (\<integral>\<^isup>+x. f x \<partial>count_space A) = (\<Sum>a\<in>A. max 0 (f a))"
  2304     "finite A \<Longrightarrow> (\<integral>\<^isup>+x. f x \<partial>count_space A) = (\<Sum>a\<in>A. max 0 (f a))"
  2329   by (subst positive_integral_max_0[symmetric])
  2305   by (subst positive_integral_max_0[symmetric])
  2330      (auto intro!: setsum_mono_zero_left simp: positive_integral_count_space less_le)
  2306      (auto intro!: setsum_mono_zero_left simp: positive_integral_count_space less_le)
  2331 
  2307 
       
  2308 lemma lebesgue_integral_count_space_finite_support:
       
  2309   assumes f: "finite {a\<in>A. f a \<noteq> 0}" shows "(\<integral>x. f x \<partial>count_space A) = (\<Sum>a | a \<in> A \<and> f a \<noteq> 0. f a)"
       
  2310 proof -
       
  2311   have *: "\<And>r::real. 0 < max 0 r \<longleftrightarrow> 0 < r" "\<And>x. max 0 (ereal x) = ereal (max 0 x)"
       
  2312     "\<And>a. a \<in> A \<and> 0 < f a \<Longrightarrow> max 0 (f a) = f a"
       
  2313     "\<And>a. a \<in> A \<and> f a < 0 \<Longrightarrow> max 0 (- f a) = - f a"
       
  2314     "{a \<in> A. f a \<noteq> 0} = {a \<in> A. 0 < f a} \<union> {a \<in> A. f a < 0}"
       
  2315     "({a \<in> A. 0 < f a} \<inter> {a \<in> A. f a < 0}) = {}"
       
  2316     by (auto split: split_max)
       
  2317   have "finite {a \<in> A. 0 < f a}" "finite {a \<in> A. f a < 0}"
       
  2318     by (auto intro: finite_subset[OF _ f])
       
  2319   then show ?thesis
       
  2320     unfolding lebesgue_integral_def
       
  2321     apply (subst (1 2) positive_integral_max_0[symmetric])
       
  2322     apply (subst (1 2) positive_integral_count_space)
       
  2323     apply (auto simp add: * setsum_negf setsum_Un
       
  2324                 simp del: ereal_max)
       
  2325     done
       
  2326 qed
       
  2327 
  2332 lemma lebesgue_integral_count_space_finite:
  2328 lemma lebesgue_integral_count_space_finite:
  2333     "finite A \<Longrightarrow> (\<integral>x. f x \<partial>count_space A) = (\<Sum>a\<in>A. f a)"
  2329     "finite A \<Longrightarrow> (\<integral>x. f x \<partial>count_space A) = (\<Sum>a\<in>A. f a)"
  2334   apply (auto intro!: setsum_mono_zero_left
  2330   apply (auto intro!: setsum_mono_zero_left
  2335               simp: positive_integral_count_space_finite lebesgue_integral_def)
  2331               simp: positive_integral_count_space_finite lebesgue_integral_def)
  2336   apply (subst (1 2)  setsum_real_of_ereal[symmetric])
  2332   apply (subst (1 2)  setsum_real_of_ereal[symmetric])
  2337   apply (auto simp: max_def setsum_subtractf[symmetric] intro!: setsum_cong)
  2333   apply (auto simp: max_def setsum_subtractf[symmetric] intro!: setsum_cong)
  2338   done
  2334   done
       
  2335 
       
  2336 lemma borel_measurable_count_space[simp, intro!]:
       
  2337   "f \<in> borel_measurable (count_space A)"
       
  2338   by simp
  2339 
  2339 
  2340 section {* Measure spaces with an associated density *}
  2340 section {* Measure spaces with an associated density *}
  2341 
  2341 
  2342 definition density :: "'a measure \<Rightarrow> ('a \<Rightarrow> ereal) \<Rightarrow> 'a measure" where
  2342 definition density :: "'a measure \<Rightarrow> ('a \<Rightarrow> ereal) \<Rightarrow> 'a measure" where
  2343   "density M f = measure_of (space M) (sets M) (\<lambda>A. \<integral>\<^isup>+ x. f x * indicator A x \<partial>M)"
  2343   "density M f = measure_of (space M) (sets M) (\<lambda>A. \<integral>\<^isup>+ x. f x * indicator A x \<partial>M)"
  2458   then have g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x"
  2458   then have g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x"
  2459     using g' by auto
  2459     using g' by auto
  2460   from borel_measurable_implies_simple_function_sequence'[OF g(1)] guess G . note G = this
  2460   from borel_measurable_implies_simple_function_sequence'[OF g(1)] guess G . note G = this
  2461   note G' = borel_measurable_simple_function[OF this(1)] simple_functionD[OF G(1)]
  2461   note G' = borel_measurable_simple_function[OF this(1)] simple_functionD[OF G(1)]
  2462   note G'(2)[simp]
  2462   note G'(2)[simp]
  2463   { fix P have "AE x in M. P x \<Longrightarrow> AE x in M. P x"
       
  2464       using positive_integral_null_set[of _ _ f]
       
  2465       by (auto simp: eventually_ae_filter ) }
       
  2466   note ac = this
       
  2467   with G(4) f g have G_M': "AE x in density M f. (SUP i. G i x) = g x"
  2463   with G(4) f g have G_M': "AE x in density M f. (SUP i. G i x) = g x"
  2468     by (auto simp add: AE_density[OF f(1)] max_def)
  2464     by (auto simp add: AE_density[OF f(1)] max_def)
  2469   { fix i
  2465   { fix i
  2470     let ?I = "\<lambda>y x. indicator (G i -` {y} \<inter> space M) x"
  2466     let ?I = "\<lambda>y x. indicator (G i -` {y} \<inter> space M) x"
  2471     { fix x assume *: "x \<in> space M" "0 \<le> f x" "0 \<le> g x"
  2467     { fix x assume *: "x \<in> space M" "0 \<le> f x" "0 \<le> g x"