The pure λ-calculus has no built-in data. To compute functions on integers, we represent integers, booleans and pairs by λ-terms in normal form, and operations on them by terms which reduce correctly when applied to these representations.
11.1 Church numerals and arithmetic
For , the Church numeral is the term
Thus , , .
The numeral is the operation “iterate times”: for all terms . Numerals are distinct normal forms, so by Corollary 10.8 they are pairwise not β-convertible.
A partial function is λ-definable if there is a term such that for all :
- if , then ;
- if , then has no normal form.
By Church–Rosser, the first condition determines uniquely.
The following terms λ-define the successor, addition, multiplication and exponentiation:
Here .
.
.
. Now , and iterating this function times gives after reduction; so the result is .
, which reduces to by induction on , using the case of multiplication.
The shorter term also works for , but , which is not (the two are only η-convertible).
11.2 Booleans, conditionals and pairs
A boolean selects one of its two arguments: and . Hence “” is simply . The term iterates the constant function times on : it reduces to if and to otherwise. Pairs store two terms: and .
11.3 The predecessor
Numerals iterate; they offer no direct way to “undo” an application of . Church himself was for a while unsure whether the predecessor was λ-definable. Kleene found a solution in 1932, based on the following idea: iterate on pairs, keeping the previous value.
Let and
Then and .
By induction on , reduces to : this holds for , and applied to reduces to . Since , the result follows by taking the first component.
11.4 Fixed-point combinators
The λ-calculus has no names: a term cannot refer to itself. Recursion is nonetheless available, thanks to fixed-point combinators.
Let . For every term , . Moreover, Turing’s combinator satisfies the stronger property .
Let . Then , and also ; so both sides reduce to . For , let , so that ; then .
Fixed points allow recursive definitions. To obtain a term with — a function defined in terms of itself — take . For instance, the factorial is
11.5 λ-definability of the partial recursive functions
Every partial recursive function is λ-definable.
We first treat the total recursive functions, which is Kleene’s 1936 theorem, and then reduce the partial case to it with the normal form theorem.
Total functions. By Corollary 8.7, every total recursive function has a derivation from the basic functions by composition, primitive recursion and minimization of regular functions, in which all the functions are total. We show by induction on such a derivation that each of its functions is λ-defined by some term ; since is total, this means for all . Below, stands for .
Basic functions. is λ-defined by , by , and by .
Composition. If λ-define , then satisfies .
Primitive recursion. If and λ-define and , then is λ-defined by iterating on pairs (counter, value), as for the predecessor:
Let be the term above with substituted for . By induction on , reduces to : for because , and for because . Since , taking the second component gives . (For , is replaced by the numeral of the constant.)
Regular minimization. Let with total and regular, λ-defined by . With Turing’s combinator, let
By Theorem 11.6, . If , this reduces to ; otherwise it reduces to , hence to . By induction, for every , which exists by regularity, and finally .
Partial functions. For partial functions the constructions above are not adequate as they stand. For instance, the term for composition may have a normal form even if some diverges, when discards its argument — whereas must then be undefined. The normal form theorem avoids this problem: by Theorem 8.6, proved in the lesson Equivalence of the models by arithmetization of Turing machines (without using the λ-calculus), where and are primitive recursive. Let and λ-define and , let be built from as above, and let
If , the search succeeds at some : then as in the total case, , and . If , it remains to show that has no normal form; by confluence, it suffices to show this for its reduct . Here reduces to for every , and one shows that it has no head normal form: it reduces to no term of the form (one says that it is unsolvable). Moreover, if has no head normal form, then neither has , which therefore has no normal form. We admit these two facts about head normal forms; they are proved in Barendregt’s monograph, in the chapters on solvability and on the representation of computable functions, where this construction is carried out in detail.
Every λ-definable partial function is partial recursive.
Code λ-terms by integers, for instance using de Bruijn indices to avoid α-equivalence issues and the sequence coding of the lesson Coding finite sequences. The following are primitive recursive on codes (we omit the routine verifications): substitution, the predicate ” is in normal form”, the function computing the result of one normal order step, its -th iterate , the code of as a function of , and the predicate ” is a numeral” together with the extraction of its value. If λ-defines , let be the code of ; then
By Theorem 10.9, the search terminates exactly when has a normal form, which is then .
Thus λ-definability coincides with partial recursiveness, and the next lesson shows that both coincide with Turing computability. These equivalences were established by Kleene (1936) and Turing (1936–1937). Together with Turing’s analysis of mechanical computation, they turned Church’s proposal — identifying effective computability with λ-definability — into a widely accepted thesis (see the lesson The Church–Turing thesis).
11.6 Exercises
Define λ-terms , and on the booleans , , and check them.
Solution
, , . For instance and .
Define truncated subtraction and the equality test on numerals.
Solution
iterates the predecessor times on . Then and .
Show that under normal order reduction, and explain what goes wrong with applicative order.
Solution
Write . By the fixed point property, , which reduces to ; continuing down to gives . Since is a normal form, by Corollary 10.8, and normal order reaches it by Theorem 10.9. Normal order contracts the conditional before evaluating the recursive call. Applicative order would first try to normalize the subterm , whose reduction never terminates.
11.7 Notes and references
The definability of the predecessor was found by Kleene in 1932, and the equivalence between λ-definability and general recursiveness (for total functions) was proved by Kleene in 1936. The combinator is due to Turing (1937).
- S. C. Kleene, λ-definability and recursiveness, Duke Mathematical Journal 2 (1936), 340–353.
- A. M. Turing, The p-function in λ-K-conversion, Journal of Symbolic Logic 2 (1937), 164.
- H. P. Barendregt, The Lambda Calculus: Its Syntax and Semantics, North-Holland, 1984.