Having set up this rather abstract notation for computable functions, let us see an example of how to use it.
Before proceeding, we set up some conventions. Implicitly, lambda
expressions associate to the left. Thus, the expresssion denotes
. Also, if we have an abstraction with
multiple variables at the outermost level, such as
, we can pull out all the variables at the outermost level
into a single sequence such as
.
In set theory, the number is identified, in a sense, with a set
that has nesting level of depth
. For instance, we start with the
emptyset for representing the number 0 and, inductively, use the set
to represent the number
. Thus we have
In the lambda calculus, we encode the number by the number of
times we apply a function to an argument. Thus, the number
is a
lambda expression that takes two arguments and applies the first
argument to the second argument
times. Let
be an
abbreviation for the lambda term denoting
. Then, we have:
This encoding was proposed by Church and terms of the form
are hence called the Church numerals. Concretely, we have
Note that
.
Thus
. So, inside the definition of
, we get
Since
, we have
and
Let us write to denote the term
with
applications of
to
. Then, it is not difficult to show
inductively that
We can now define arithmetic functions such as successor,
plus, .... For instance, successor is
just
. To see how this works, we observe that
Thus, if the function representing successor is applied a term of the right ``type'', it yields the expected answer. We could also apply it to a ``meaningless'' term, in which case we get a ``meaningless'' answer!
Here is a definition for plus:
. We
can verify that
Similarly, we define multiplication and exponentiation as follows: