12867
|
1 |
(* Title: ZF/ex/Natsum.thy
|
9647
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow & Lawrence C Paulson
|
|
4 |
|
|
5 |
A summation operator. sum(f,n+1) is the sum of all f(i), i=0...n.
|
|
6 |
|
|
7 |
Note: n is a natural number but the sum is an integer,
|
|
8 |
and f maps integers to integers
|
12867
|
9 |
|
|
10 |
Summing natural numbers, squares, cubes, etc.
|
|
11 |
|
|
12 |
Originally demonstrated permutative rewriting, but add_ac is no longer needed
|
|
13 |
thanks to new simprocs.
|
|
14 |
|
|
15 |
Thanks to Sloane's On-Line Encyclopedia of Integer Sequences,
|
|
16 |
http://www.research.att.com/~njas/sequences/
|
9647
|
17 |
*)
|
|
18 |
|
|
19 |
|
16417
|
20 |
theory NatSum imports Main begin
|
12867
|
21 |
|
|
22 |
consts sum :: "[i=>i, i] => i"
|
9647
|
23 |
primrec
|
|
24 |
"sum (f,0) = #0"
|
|
25 |
"sum (f, succ(n)) = f($#n) $+ sum(f,n)"
|
|
26 |
|
12867
|
27 |
declare zadd_zmult_distrib [simp] zadd_zmult_distrib2 [simp]
|
|
28 |
declare zdiff_zmult_distrib [simp] zdiff_zmult_distrib2 [simp]
|
|
29 |
|
|
30 |
(*The sum of the first n odd numbers equals n squared.*)
|
|
31 |
lemma sum_of_odds: "n \<in> nat ==> sum (%i. i $+ i $+ #1, n) = $#n $* $#n"
|
|
32 |
by (induct_tac "n", auto)
|
|
33 |
|
|
34 |
(*The sum of the first n odd squares*)
|
|
35 |
lemma sum_of_odd_squares:
|
|
36 |
"n \<in> nat ==> #3 $* sum (%i. (i $+ i $+ #1) $* (i $+ i $+ #1), n) =
|
|
37 |
$#n $* (#4 $* $#n $* $#n $- #1)"
|
|
38 |
by (induct_tac "n", auto)
|
|
39 |
|
|
40 |
(*The sum of the first n odd cubes*)
|
|
41 |
lemma sum_of_odd_cubes:
|
|
42 |
"n \<in> nat
|
|
43 |
==> sum (%i. (i $+ i $+ #1) $* (i $+ i $+ #1) $* (i $+ i $+ #1), n) =
|
|
44 |
$#n $* $#n $* (#2 $* $#n $* $#n $- #1)"
|
|
45 |
by (induct_tac "n", auto)
|
|
46 |
|
|
47 |
(*The sum of the first n positive integers equals n(n+1)/2.*)
|
|
48 |
lemma sum_of_naturals:
|
|
49 |
"n \<in> nat ==> #2 $* sum(%i. i, succ(n)) = $#n $* $#succ(n)"
|
|
50 |
by (induct_tac "n", auto)
|
|
51 |
|
|
52 |
lemma sum_of_squares:
|
|
53 |
"n \<in> nat ==> #6 $* sum (%i. i$*i, succ(n)) =
|
|
54 |
$#n $* ($#n $+ #1) $* (#2 $* $#n $+ #1)"
|
|
55 |
by (induct_tac "n", auto)
|
|
56 |
|
|
57 |
lemma sum_of_cubes:
|
|
58 |
"n \<in> nat ==> #4 $* sum (%i. i$*i$*i, succ(n)) =
|
|
59 |
$#n $* $#n $* ($#n $+ #1) $* ($#n $+ #1)"
|
|
60 |
by (induct_tac "n", auto)
|
|
61 |
|
|
62 |
(** Sum of fourth powers **)
|
|
63 |
|
|
64 |
lemma sum_of_fourth_powers:
|
|
65 |
"n \<in> nat ==> #30 $* sum (%i. i$*i$*i$*i, succ(n)) =
|
|
66 |
$#n $* ($#n $+ #1) $* (#2 $* $#n $+ #1) $*
|
|
67 |
(#3 $* $#n $* $#n $+ #3 $* $#n $- #1)"
|
|
68 |
by (induct_tac "n", auto)
|
|
69 |
|
|
70 |
end
|