| author | wenzelm |
| Fri, 29 Oct 1999 20:18:34 +0200 | |
| changeset 7978 | 1b99ee57d131 |
| parent 5206 | a3f26b19cd7e |
| child 8356 | 14d89313c66c |
| 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... |
7 |
Demonstrates permutative rewriting. |
|
| 969 | 8 |
*) |
9 |
||
| 4558 | 10 |
Delsimprocs nat_cancel; |
| 3269 | 11 |
Addsimps add_ac; |
12 |
Addsimps [add_mult_distrib, add_mult_distrib2]; |
|
| 969 | 13 |
|
14 |
(*The sum of the first n positive integers equals n(n+1)/2.*) |
|
| 5069 | 15 |
Goal "2*sum (%i. i) (Suc n) = n*Suc(n)"; |
| 1266 | 16 |
by (Simp_tac 1); |
| 4246 | 17 |
by (induct_tac "n" 1); |
| 1266 | 18 |
by (Simp_tac 1); |
19 |
by (Asm_simp_tac 1); |
|
| 969 | 20 |
qed "sum_of_naturals"; |
21 |
||
| 5206 | 22 |
Goal "Suc(Suc(Suc(Suc 2)))*sum (%i. i*i) (Suc n) = n*Suc(n)*Suc(2*n)"; |
| 1266 | 23 |
by (Simp_tac 1); |
| 4246 | 24 |
by (induct_tac "n" 1); |
| 1266 | 25 |
by (Simp_tac 1); |
26 |
by (Asm_simp_tac 1); |
|
| 969 | 27 |
qed "sum_of_squares"; |
28 |
||
| 5206 | 29 |
Goal "Suc(Suc 2)*sum (%i. i*i*i) (Suc n) = n*n*Suc(n)*Suc(n)"; |
| 1266 | 30 |
by (Simp_tac 1); |
| 4246 | 31 |
by (induct_tac "n" 1); |
| 1266 | 32 |
by (Simp_tac 1); |
33 |
by (Asm_simp_tac 1); |
|
| 969 | 34 |
qed "sum_of_cubes"; |
35 |
||
36 |
(*The sum of the first n odd numbers equals n squared.*) |
|
| 5069 | 37 |
Goal "sum (%i. Suc(i+i)) n = n*n"; |
| 4246 | 38 |
by (induct_tac "n" 1); |
| 1266 | 39 |
by (Simp_tac 1); |
40 |
by (Asm_simp_tac 1); |
|
| 969 | 41 |
qed "sum_of_odds"; |
42 |