src/HOL/ex/NatSum.ML
author paulson
Sun, 23 Apr 2000 11:41:45 +0200
changeset 8770 bfab4d4b7516
parent 8493 60c2f892b1d9
child 8780 b0c32189b2c1
permissions -rw-r--r--
new, but still slow, proofs using binary numerals
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1805
10494d0241cd Explicitly included add_mult_distrib & add_mult_distrib2
paulson
parents: 1783
diff changeset
     1
(*  Title:      HOL/ex/NatSum.ML
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1266
diff changeset
     3
    Author:     Tobias Nipkow
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994 TU Muenchen
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
     5
3269
eca2a3634acd Function "sum" now defined using primrec
paulson
parents: 1805
diff changeset
     6
Summing natural numbers, squares and cubes.  Could be continued...
8415
paulson
parents: 8356
diff changeset
     7
paulson
parents: 8356
diff changeset
     8
Originally demonstrated permutative rewriting, but add_ac is no longer needed
paulson
parents: 8356
diff changeset
     9
  thanks to new simprocs.
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    10
*)
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    11
8493
60c2f892b1d9 re-ordered the theorems
paulson
parents: 8415
diff changeset
    12
(*The sum of the first n odd numbers equals n squared.*)
60c2f892b1d9 re-ordered the theorems
paulson
parents: 8415
diff changeset
    13
Goal "sum (%i. Suc(i+i)) n = n*n";
60c2f892b1d9 re-ordered the theorems
paulson
parents: 8415
diff changeset
    14
by (induct_tac "n" 1);
60c2f892b1d9 re-ordered the theorems
paulson
parents: 8415
diff changeset
    15
by Auto_tac;
60c2f892b1d9 re-ordered the theorems
paulson
parents: 8415
diff changeset
    16
qed "sum_of_odds";
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    17
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    18
(*The sum of the first n positive integers equals n(n+1)/2.*)
8356
paulson
parents: 5206
diff changeset
    19
Goal "2 * sum id (Suc n) = n*Suc(n)";
4246
c539e702e1d2 Now uses induct_tac
paulson
parents: 3842
diff changeset
    20
by (induct_tac "n" 1);
8356
paulson
parents: 5206
diff changeset
    21
by Auto_tac;
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    22
qed "sum_of_naturals";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    23
8493
60c2f892b1d9 re-ordered the theorems
paulson
parents: 8415
diff changeset
    24
Addsimps [add_mult_distrib, add_mult_distrib2];
60c2f892b1d9 re-ordered the theorems
paulson
parents: 8415
diff changeset
    25
8415
paulson
parents: 8356
diff changeset
    26
Goal "Suc(Suc(Suc(Suc 2))) * sum (%i. i*i) (Suc n) = n * Suc(n) * Suc(2*n)";
4246
c539e702e1d2 Now uses induct_tac
paulson
parents: 3842
diff changeset
    27
by (induct_tac "n" 1);
8356
paulson
parents: 5206
diff changeset
    28
by Auto_tac;
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    29
qed "sum_of_squares";
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    30
8415
paulson
parents: 8356
diff changeset
    31
Goal "Suc(Suc 2) * sum (%i. i*i*i) (Suc n) = n * n * Suc(n) * Suc(n)";
4246
c539e702e1d2 Now uses induct_tac
paulson
parents: 3842
diff changeset
    32
by (induct_tac "n" 1);
8356
paulson
parents: 5206
diff changeset
    33
by Auto_tac;
969
b051e2fc2e34 converted ex with curried function application
clasohm
parents:
diff changeset
    34
qed "sum_of_cubes";
8770
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    35
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    36
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    37
(** Repeating some of the previous examples using binary numerals **)
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    38
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    39
(*The sum of the first n positive integers equals n(n+1)/2.*)
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    40
Goal "#2 * sum id (Suc n) = n*Suc(n)";
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    41
by (induct_tac "n" 1);
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    42
by Auto_tac;
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    43
qed "sum_of_naturals";
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    44
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    45
Addsimps [add_mult_distrib, add_mult_distrib2];
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    46
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    47
Goal "#6 * sum (%i. i*i) (Suc n) = n * Suc(n) * Suc(#2*n)";
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    48
by (induct_tac "n" 1);
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    49
by Auto_tac;
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    50
(*12.6 secs, down to 5.9 secs, down to 4 secs*)
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    51
qed "sum_of_squares";
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    52
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    53
Goal "#4 * sum (%i. i*i*i) (Suc n) = n * n * Suc(n) * Suc(n)";
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    54
by (induct_tac "n" 1);
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    55
by Auto_tac;
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    56
(*27.7 secs, down to 10.9 secs, down to 7.3 secs*)
bfab4d4b7516 new, but still slow, proofs using binary numerals
paulson
parents: 8493
diff changeset
    57
qed "sum_of_cubes";