Church’s λ-calculus (1932–1936) takes a different view of computation. There are no machines and no numbers: the only objects are functions, and the only operations are forming a function by abstracting over a variable, and applying a function to an argument. Computation is the simplification of expressions by substituting arguments for variables. The λ-calculus is the theoretical basis of functional programming languages and of the proofs-as-programs correspondence in logic.
In the λ-calculus, functions take functions as arguments and return functions. Numbers, booleans and data structures must therefore be encoded as functions; this is the subject of the next lesson. Here we study the calculus itself.
10.1 Terms
Fix an infinite set of variables
The set of λ-terms is defined inductively:
- every variable is a term;
- if and are terms, then is a term, the application of to ;
- if is a term and a variable, then is a term, the abstraction of over .
The intended meaning of is the function . We use the following conventions to omit parentheses: outermost parentheses are dropped; application associates to the left, so stands for ; the body of an abstraction extends as far right as possible, so stands for ; and abbreviates .
A function of several arguments is represented as a function returning a function (currying): takes and returns the function .
Some terms that will recur:
10.2 Free variables and substitution
The set of free variables of is defined by
Occurrences of in within are bound. A term without free variables is closed, or a combinator.
For instance , and are closed.
Substituting a term for a variable must not change the meaning of the free variables of . In , substituting for naively would give , the identity, whereas is a constant function. The bound variable must be renamed first.
The substitution of for the free occurrences of in is defined by induction on the size of (renaming a bound variable does not change the size):
- , and for ;
- ;
- ;
- if and ( or );
- if , and , where is a variable not occurring in or .
The last clause renames the bound variable to avoid capturing the free of .
Two terms are α-equivalent if one is obtained from the other by renaming bound variables, that is, by replacing subterms by with .
From now on, α-equivalent terms are identified: and are the same term. We also adopt the variable convention: in any discussion, bound variables are chosen different from the free variables. With this convention the last clause of Definition 10.3 is never needed.
10.3 β-reduction
A β-redex is a term of the form ; its contractum is . The one-step β-reduction holds if is obtained from by replacing one occurrence of a redex by its contractum. Formally, is the smallest relation such that
- ;
- if then , and .
We write for its reflexive transitive closure (reduction) and for the equivalence relation it generates (β-conversion).
A term is in β-normal form if it contains no β-redex. A term has a normal form if for some in normal form.
Examples:
- , and (with ).
- (see the first exercise for the individual steps).
- . The only reduction sequence from is infinite, and has no normal form: it is the λ-calculus analogue of a non-terminating computation.
- reduces to the normal form by contracting the outer redex, but also reduces to itself by contracting . Some reduction sequences from this term are infinite, although it has a normal form.
10.4 Confluence
A term may contain several redexes, so reduction is not deterministic. The fundamental theorem of the λ-calculus states that the choices do not matter for the final result.
The relation is confluent: if and , there exists with and .
We sketch the proof of Tait and Martin-Löf. The one-step relation itself does not satisfy the “diamond property” (a single step on each side need not be joinable in one step each), because contracting a redex may duplicate other redexes. One introduces parallel reduction , the smallest relation such that
- ;
- if then ;
- if and then ;
- if and then .
Intuitively, contracts any set of redexes present in , simultaneously. One checks that , so the reflexive transitive closure of is . The key lemma, proved by induction on the derivation of , is that and imply . From it one deduces the diamond property: if and , then and for some — in fact one can take for the term obtained by contracting all redexes of . A relation with the diamond property has a confluent transitive closure, by a “tiling” argument: given two sequences of -steps from , complete the grid of diamonds. The details are in Barendregt’s monograph (chapter 3).
- A term has at most one normal form.
- If , then and reduce to a common term.
- Distinct normal forms are not β-convertible. In particular is not trivial: .
- If and with normal, confluence gives with ; since normal forms do not reduce, .
- By induction on the length of a chain of reductions and expansions connecting and , using confluence to merge consecutive peaks.
- If two normal forms are convertible, by 2 they reduce to a common term, hence are equal.
10.5 Reduction strategies
Which redex should be contracted? Two natural strategies are:
- normal order: always contract the leftmost outermost redex (the one whose λ appears first from the left);
- applicative order: always contract a leftmost innermost redex, i.e. evaluate arguments before passing them.
On , normal order terminates immediately with , while applicative order loops forever on .
If a term has a normal form, the normal order reduction sequence starting from it is finite and ends with this normal form.
We admit this theorem; a proof is in Curry and Feys, or in Barendregt’s monograph (chapter 13). It shows that normal order is a deterministic algorithm computing normal forms whenever they exist: a λ-term is evaluated like a program, which runs forever exactly when the term has no normal form.
The relation , for , expresses extensionality: both terms behave identically when applied to an argument. The theory of -conversion also satisfies the Church–Rosser theorem. We will not need it.
10.6 Exercises
Reduce to normal form, writing every step, and check that for every .
Solution
. Then .
Show that the term has no normal form, and that its reducts grow in size.
Solution
Let . Then : the only redex of ( copies) is the leftmost , whose contraction gives copies. Every reduction sequence is therefore infinite.
Prove the substitution lemma: if and , then .
Solution
By induction on , using the variable convention. If , both sides are . If , the left side is and the right side is since . If is another variable, both sides are . Applications follow directly from the induction hypothesis. If with distinct from and not free in , both sides push the substitutions inside the abstraction and the induction hypothesis applies.
10.7 Notes and references
The λ-calculus was introduced by Church in the early 1930s as part of a foundational system that turned out to be inconsistent; the pure calculus survived. The confluence theorem is due to Church and Rosser; the proof by parallel reduction is due to Tait and Martin-Löf. Barendregt’s monograph is the standard reference.
- A. Church, J. B. Rosser, Some properties of conversion, Transactions of the American Mathematical Society 39 (1936), 472–482.
- H. B. Curry, R. Feys, Combinatory Logic, volume I, North-Holland, 1958, for the standardization theorem.
- H. P. Barendregt, The Lambda Calculus: Its Syntax and Semantics, North-Holland, 1984.