Due: Wednesday, September 12, 2001.
``Peano was one of the first to use what we now call symbolic logic. He introduced, for instance, the use of the symbols `(E x)' to mean `there is an x such that'; and he habitually wrote out all of his lecture notes in his new symbolism. He was teaching at a military academy at the time, and his students were so incensed by his formalistic approach to mathematics that they rebelled (despite his promises to pass them all) and got him fired. Subsequently he found a more congenial setting at the University of Turin.'' -- Rudy Rucker, Goedel's Incompleteness Theorems, p. 289.
The functions (1+ n) and (1- n), which add and subtract 1 from an integer, are provided in the file initdr.scm
Write a function (peano+ x y), using only 1+ and 1- to perform arithmetic, according to the following definition:
peano+(x, y) = | x | , if y = 0 |
peano+(x + 1, y - 1) | , otherwise. |
Although the factorial function could be used in implementing n choose k, this would be inefficient for large values of n and small k. We can algebraically rewrite the definition into the following form for k > 0:
Write a function (choose n k), using a tail-recursive auxiliary function, to compute n choose k without using the factorial function. Can you prove that the result of your auxiliary function is always an integer? This would be a good invariant for your recursive function: although non-integer intermediate results will work in Lisp, they would not work in most languages.