Using Church numerals and the definitions of add and pred developed in Gordon, prove the following equivalence.
pred 2 = add 0 1
Exercise 2.2
Show the reduction of
Y (f . n . if (zero?n) 0 (f (sub1n))) 1
to 0. Expand Y, but leave other abbreviations intact, reducing applications of abbreviated functions in one step. For example: (sub1 1) -> 0.
Exercise 2.3
Define a lambda calculus encoding for Lisp cons cells, consisting of expressions for the following:
null, a constant
cons, a function that takes two arguments and returns a cons cell
null?, a function that returns true if its argument is null, false if it is a cons cell
car, a function that takes a cons cell and returns its first element
cdr, a function that takes a cons cell and returns its second element
Your encoding must satisfy the following equations:
(null? null) = true
(null? (consx y)) = false
(car (consx y)) = x
(cdr (consx y)) = y
Since we consider expressions such as (car null) or (car cons) to be nonsense, your encoding need not equate such expressions with anything in particular.
Exercise 2.4
Using your encoding from the previous exercise, define length, which takes a list of booleans and returns the number of cons cells in the list. A list of booleans is either null, or (consb l) where b is true or false and l is a list.
Exercise 2.5
Translate the following functions to the lambda calculus, assuming pre-existing definitions for true, false, if, not, fst, snd, add1, sub1, zero?, Y, and positive integers.
The fib function:
fib(0) = 1
fib(1) = 1
fib(n) = f(n-1) + f(n-2), if n >= 2
The triven function:
triven(n) = true if n is evenly divisible by 3
triven(n) = false if n is not evenly divisible by 3
Hint: The strategy we used for even/odd in class can be expanded to work with three functions.
Last update: Monday, January 17th, 2000mflatt@cs.utah.edu