[Overview] [Previous] [Next]

Examples II

Example. Multiplication of two numbers.

The key new feature here is the use of a previously defined function, add, in the definition of a new function. We skip the step of playing around with the pi functions to pick out the right parts, and go right to the simplified form.

multiply(x, s(z(x))) = x
multiply(x, s(y)) = add(x, multiply(x, y))

Example. Predecessor.

The trick here is that we can't drop below zero, so effectively 0-1=0. To show this, we write a dot above the minus sign and call it a monus (and no, you don't need to remember this!). In any case, the function is easy to define:

pred(z(x)) = z(x)
pred(s(x)) = x

(We have taken some liberties with the notation, because the form allowed by the textbook doesn't allow us to define a function of one variable; we would have to define a function of two variables, and just ignore one of them.)

Example. Subtraction.

subtract(x, z(x)) = x
subtract(x, s(y)) = pred(subtract(x, y))

Copyright 1996 by David Matuszek
Last modified Apr 18, 1996