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