text‹
Summing natural numbers, squares, cubes, etc.
Thanks to Sloane's On-Line Encyclopedia of Integer Sequences, 🚫‹https://oeis.org›. ›
lemmas [simp] =
ring_distribs
diff_mult_distrib diff_mult_distrib2 🍋‹for type nat›
text‹🚫 The sum of the first ‹n› odd numbers equals ‹n› squared.›
lemma sum_of_odds: "(\i=0.. by (induct n) auto
text‹🚫 The sum of the first ‹n› odd squares.›
lemma sum_of_odd_squares: "3 * (\i=0.. by (induct n) auto
text‹🚫 The sum of the first ‹n› odd cubes.›
lemma sum_of_odd_cubes: "(\i=0..
n * n * (2 * n * n - 1)" by (induct n) auto
text‹🚫 The sum of the first ‹n› positive integers equals ‹n (n + 1) / 2›.›
lemma sum_of_naturals: "2 * (\i=0..n. i) = n * Suc n" by (induct n) auto
lemma sum_of_squares: "6 * (\i=0..n. i * i) = n * Suc n * Suc (2 * n)" by (induct n) auto
lemma sum_of_cubes: "4 * (\i=0..n. i * i * i) = n * n * Suc n * Suc n" by (induct n) auto
text‹🚫 A cute identity:›
lemma sum_squared: "(\i=0..n. i)^2 = (\i=0..n. i^3)"for n :: nat proof (induct n) case 0 show ?caseby simp next case (Suc n) have"(\i = 0..Suc n. i)^2 =
(∑i = 0..n. i^3) + (2*(∑i = 0..n. i)*(n+1) + (n+1)^2)"
(is"_ = ?A + ?B") using Suc by (simp add: eval_nat_numeral) alsohave"?B = (n+1)^3" using sum_of_naturals by (simp add: eval_nat_numeral) alsohave"?A + (n+1)^3 = (\i=0..Suc n. i^3)"by simp finallyshow ?case . qed
text‹🚫 Sum of fourth powers: three versions.›
lemma sum_of_fourth_powers: "30 * (\i=0..n. i * i * i * i) =
n * Suc n * Suc (2 * n) * (3 * n * n + 3 * n - 1)" proof (induct n) case 0 show ?caseby simp next case (Suc n) thenshow ?case by (cases n) 🍋‹eliminates the subtraction›
simp_all qed
text‹
Two alternative proofs, with a change of variables and much more
subtraction, performed using the integers. ›
lemma int_sum_of_fourth_powers: "30 * int (\i=0..
int m * (int m - 1) * (int(2 * m) - 1) *
(int(3 * m * m) - int(3 * m) - 1)" by (induct m) simp_all
lemma of_nat_sum_of_fourth_powers: "30 * of_nat (\i=0..
of_nat m * (of_nat m - 1) * (of_nat (2 * m) - 1) *
(of_nat (3 * m * m) - of_nat (3 * m) - (1::int))" by (induct m) simp_all
text‹🚫 Sums of geometric series: ‹2›, ‹3›and the general case.›
lemma sum_of_2_powers: "(\i=0.. by (induct n) auto
lemma sum_of_3_powers: "2 * (\i=0.. by (induct n) auto
lemma sum_of_powers: "0 < k \ (k - 1) * (\i=0.. for k :: nat by (induct n) auto
end
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.