Assignment 3
Due on Oct 9 before lecture.
Please bring a hardcopy of your solutions to lecture. Or submit a hardcopy
of your solutions to Paul Darga before lecture.
Problem 1
Recall Church numerals from Chapter 5 of the Pierce book. They use unary
representation for natural numbers. Suppose we want to use binary
representation instead. One way to encode natural numbers is as follows:
- 0 = \i. \o. \t. ot
- 1 = \i. \o. \t. it
- 2 = \i. \o. \t. i(ot)
- 3 = \i. \o. \t. i(it)
- 4 = \i. \o. \t. i(o(ot))
- 5 = \i. \o. \t. i(o(it))
- 6 = \i. \o. \t. i(i(ot))
- 7 = \i. \o. \t. i(i(it))
- 8 = \i. \o. \t. i(o(o(ot)))
- 9 = \i. \o. \t. i(o(o(it)))
- 10 = \i. \o. \t. i(o(i(ot)))
- 11 = \i. \o. \t. i(o(i(it)))
- ...
Intuitively, a natural number n is a function that takes three parameters,
i as the bit 1, o as the bit 0, and t as the sequence terminator, and
returns the sequence of applications representing the binary encoding of n.
Problem 1a (4 Points)
Write a combinator double n that multiplies a
natural number n by 2. (A combinator is a lambda term without free
variables.)
Problem 1b (4 Points)
Recall the definition of Church booleans from Chapter 5 of the Pierce book:
- true = \t. \f. t
- false = \t. \f. f
Write a combinator iszero n that returns the
Church boolean true if n is zero, and returns the Church boolean false
otherwise.