author | paulson |
Mon, 08 May 2000 18:20:04 +0200 | |
changeset 8837 | 9ee87bdcba05 |
parent 8836 | 32fe62227ff0 |
child 8842 | b90d653bd089 |
permissions | -rw-r--r-- |
1805
10494d0241cd
Explicitly included add_mult_distrib & add_mult_distrib2
paulson
parents:
1783
diff
changeset
|
1 |
(* Title: HOL/ex/NatSum.ML |
969 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Tobias Nipkow |
969 | 4 |
Copyright 1994 TU Muenchen |
5 |
||
8836 | 6 |
Summing natural numbers, squares, cubes, etc. |
8415 | 7 |
|
8 |
Originally demonstrated permutative rewriting, but add_ac is no longer needed |
|
9 |
thanks to new simprocs. |
|
969 | 10 |
*) |
11 |
||
8493 | 12 |
(*The sum of the first n odd numbers equals n squared.*) |
13 |
Goal "sum (%i. Suc(i+i)) n = n*n"; |
|
14 |
by (induct_tac "n" 1); |
|
15 |
by Auto_tac; |
|
16 |
qed "sum_of_odds"; |
|
969 | 17 |
|
8493 | 18 |
Addsimps [add_mult_distrib, add_mult_distrib2]; |
19 |
||
8770 | 20 |
(*The sum of the first n positive integers equals n(n+1)/2.*) |
21 |
Goal "#2 * sum id (Suc n) = n*Suc(n)"; |
|
22 |
by (induct_tac "n" 1); |
|
23 |
by Auto_tac; |
|
24 |
qed "sum_of_naturals"; |
|
25 |
||
26 |
Goal "#6 * sum (%i. i*i) (Suc n) = n * Suc(n) * Suc(#2*n)"; |
|
27 |
by (induct_tac "n" 1); |
|
28 |
by Auto_tac; |
|
29 |
qed "sum_of_squares"; |
|
30 |
||
31 |
Goal "#4 * sum (%i. i*i*i) (Suc n) = n * n * Suc(n) * Suc(n)"; |
|
32 |
by (induct_tac "n" 1); |
|
33 |
by Auto_tac; |
|
34 |
qed "sum_of_cubes"; |
|
8836 | 35 |
|
36 |
(** Sum of fourth powers requires lemmas **) |
|
37 |
||
38 |
Goal "[| #1 <= (j::nat); k <= m |] ==> k <= j*m"; |
|
39 |
by (dtac mult_le_mono 1); |
|
40 |
by Auto_tac; |
|
41 |
qed "mult_le_1_mono"; |
|
42 |
||
43 |
Addsimps [diff_mult_distrib, diff_mult_distrib2]; |
|
44 |
||
45 |
(*Thanks to Sloane's On-Line Encyclopedia of Integer Sequences, |
|
46 |
http://www.research.att.com/~njas/sequences/*) |
|
47 |
Goal "#30 * sum (%i. i*i*i*i) (Suc n) = \ |
|
48 |
\ n * Suc(n) * Suc(#2*n) * (#3*n*n + #3*n - #1)"; |
|
49 |
by (induct_tac "n" 1); |
|
50 |
by (Simp_tac 1); |
|
51 |
(*Automating this inequality proof would make the proof trivial*) |
|
52 |
by (subgoal_tac "n <= #10 * (n * (n * n)) + (#15 * (n * (n * (n * n))) + \ |
|
53 |
\ #6 * (n * (n * (n * (n * n)))))" 1); |
|
54 |
(*In simplifying we want only the outer Suc argument to be unfolded. |
|
55 |
Thus the result matches the induction hypothesis (also with Suc). *) |
|
56 |
by (asm_simp_tac (simpset() delsimps [sum_Suc] |
|
57 |
addsimps [inst "n" "Suc ?m" sum_Suc]) 1); |
|
58 |
by (rtac ([mult_le_1_mono, le_add1] MRS le_trans) 1); |
|
59 |
by (rtac le_cube 2); |
|
60 |
by (Simp_tac 1); |
|
61 |
qed "sum_of_fourth_powers"; |
|
62 |
||
8837 | 63 |
(** Alternative proof, avoiding the need for inequality reasoning **) |
8836 | 64 |
|
8837 | 65 |
Addsimps [zmult_int RS sym, zadd_zmult_distrib, zadd_zmult_distrib2, |
66 |
zdiff_zmult_distrib, zdiff_zmult_distrib2]; |
|
67 |
||
68 |
Goal "#30 * int (sum (%i. i*i*i*i) (Suc n)) = \ |
|
69 |
\ int n * int(Suc n) * int (Suc(#2*n)) * (int (#3*n*n) + int (#3*n) - #1)"; |
|
70 |
by (induct_tac "n" 1); |
|
71 |
by (Simp_tac 1); |
|
72 |
by (asm_simp_tac (simpset() delsimps [sum_Suc] |
|
73 |
addsimps [inst "n" "Suc ?m" sum_Suc]) 1); |
|
74 |
qed "int_sum_of_fourth_powers"; |
|
75 |
||
76 |