1645 |
1645 |
1646 lemma arith_series_int: |
1646 lemma arith_series_int: |
1647 "2 * (\<Sum>i\<in>{..<n}. a + int i * d) = int n * (a + (a + int(n - 1)*d))" |
1647 "2 * (\<Sum>i\<in>{..<n}. a + int i * d) = int n * (a + (a + int(n - 1)*d))" |
1648 by (fact arith_series_general) (* FIXME: duplicate *) |
1648 by (fact arith_series_general) (* FIXME: duplicate *) |
1649 |
1649 |
1650 lemma sum_diff_distrib: |
1650 lemma sum_diff_distrib: "\<forall>x. Q x \<le> P x \<Longrightarrow> (\<Sum>x<n. P x) - (\<Sum>x<n. Q x) = (\<Sum>x<n. P x - Q x :: nat)" |
1651 fixes P::"nat\<Rightarrow>nat" |
1651 by (subst setsum_subtractf_nat) auto |
1652 shows |
|
1653 "\<forall>x. Q x \<le> P x \<Longrightarrow> |
|
1654 (\<Sum>x<n. P x) - (\<Sum>x<n. Q x) = (\<Sum>x<n. P x - Q x)" |
|
1655 proof (induct n) |
|
1656 case 0 show ?case by simp |
|
1657 next |
|
1658 case (Suc n) |
|
1659 |
|
1660 let ?lhs = "(\<Sum>x<n. P x) - (\<Sum>x<n. Q x)" |
|
1661 let ?rhs = "\<Sum>x<n. P x - Q x" |
|
1662 |
|
1663 from Suc have "?lhs = ?rhs" by simp |
|
1664 moreover |
|
1665 from Suc have "?lhs + P n - Q n = ?rhs + (P n - Q n)" by simp |
|
1666 moreover |
|
1667 from Suc have |
|
1668 "(\<Sum>x<n. P x) + P n - ((\<Sum>x<n. Q x) + Q n) = ?rhs + (P n - Q n)" |
|
1669 by (subst diff_diff_left[symmetric], |
|
1670 subst diff_add_assoc2) |
|
1671 (auto simp: diff_add_assoc2 intro: setsum_mono) |
|
1672 ultimately |
|
1673 show ?case by simp |
|
1674 qed |
|
1675 |
1652 |
1676 lemma nat_diff_setsum_reindex: "(\<Sum>i<n. f (n - Suc i)) = (\<Sum>i<n. f i)" |
1653 lemma nat_diff_setsum_reindex: "(\<Sum>i<n. f (n - Suc i)) = (\<Sum>i<n. f i)" |
1677 by (rule setsum.reindex_bij_witness[where i="\<lambda>i. n - Suc i" and j="\<lambda>i. n - Suc i"]) auto |
1654 by (rule setsum.reindex_bij_witness[where i="\<lambda>i. n - Suc i" and j="\<lambda>i. n - Suc i"]) auto |
1678 |
1655 |
1679 subsection {* Products indexed over intervals *} |
1656 subsection {* Products indexed over intervals *} |