author | paulson |
Sun, 23 Apr 2000 11:41:45 +0200 | |
changeset 8770 | bfab4d4b7516 |
parent 8493 | 60c2f892b1d9 |
child 8780 | b0c32189b2c1 |
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 |
||
3269 | 6 |
Summing natural numbers, squares and cubes. Could be continued... |
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 |
|
18 |
(*The sum of the first n positive integers equals n(n+1)/2.*) |
|
8356 | 19 |
Goal "2 * sum id (Suc n) = n*Suc(n)"; |
4246 | 20 |
by (induct_tac "n" 1); |
8356 | 21 |
by Auto_tac; |
969 | 22 |
qed "sum_of_naturals"; |
23 |
||
8493 | 24 |
Addsimps [add_mult_distrib, add_mult_distrib2]; |
25 |
||
8415 | 26 |
Goal "Suc(Suc(Suc(Suc 2))) * sum (%i. i*i) (Suc n) = n * Suc(n) * Suc(2*n)"; |
4246 | 27 |
by (induct_tac "n" 1); |
8356 | 28 |
by Auto_tac; |
969 | 29 |
qed "sum_of_squares"; |
30 |
||
8415 | 31 |
Goal "Suc(Suc 2) * sum (%i. i*i*i) (Suc n) = n * n * Suc(n) * Suc(n)"; |
4246 | 32 |
by (induct_tac "n" 1); |
8356 | 33 |
by Auto_tac; |
969 | 34 |
qed "sum_of_cubes"; |
8770 | 35 |
|
36 |
||
37 |
(** Repeating some of the previous examples using binary numerals **) |
|
38 |
||
39 |
(*The sum of the first n positive integers equals n(n+1)/2.*) |
|
40 |
Goal "#2 * sum id (Suc n) = n*Suc(n)"; |
|
41 |
by (induct_tac "n" 1); |
|
42 |
by Auto_tac; |
|
43 |
qed "sum_of_naturals"; |
|
44 |
||
45 |
Addsimps [add_mult_distrib, add_mult_distrib2]; |
|
46 |
||
47 |
Goal "#6 * sum (%i. i*i) (Suc n) = n * Suc(n) * Suc(#2*n)"; |
|
48 |
by (induct_tac "n" 1); |
|
49 |
by Auto_tac; |
|
50 |
(*12.6 secs, down to 5.9 secs, down to 4 secs*) |
|
51 |
qed "sum_of_squares"; |
|
52 |
||
53 |
Goal "#4 * sum (%i. i*i*i) (Suc n) = n * n * Suc(n) * Suc(n)"; |
|
54 |
by (induct_tac "n" 1); |
|
55 |
by Auto_tac; |
|
56 |
(*27.7 secs, down to 10.9 secs, down to 7.3 secs*) |
|
57 |
qed "sum_of_cubes"; |