1. Lambda calculus
Draft
Three kinds of term and one rule
At its core, computation is substitution. Instead of giving a function a separate name, write down its rule directly: \(\lambda x.\, M\) denotes the function that takes an input \(x\) and produces \(M\) (abstraction), and placing a function beside an argument, \((\lambda x.\, M)\,N\), feeds \(N\) into that function (application). Computing the result takes a single rule, β-reduction: replace every free occurrence of \(x\) in \(M\) with \(N\). The untyped lambda calculus builds all of its expressions, the lambda terms, from variables using only abstraction and application, and evaluates them using β-reduction alone. Nothing else is built in: no numbers, no booleans, no memory cells, and no loops. Even so, it can compute everything that any computer can compute. In the figure below, both the number 2 and addition itself are encoded purely as lambda terms, and evaluating 2 + 2 to 4 takes six substitutions. A series about checking formal proofs begins here because Lean represents every proof as an enriched lambda term, and checking a proof relies on computing with such terms.
term 2 + 2 on Church numerals: plus is λm n f x. m f (n f x), and 2 is λf x. f (f x)
rule (λx. M) N → M[x := N]; in brackets, the redex that normal order contracts next
steps nodes
0 [(λm n f x. m f (n f x)) (λf x. f (f x))] (λf x. f (f x)) 29
1 [(λn f x. (λf x. f (f x)) f (n f x)) (λf x. f (f x))] 26
2 λf x. [(λf x. f (f x)) f] ((λf x. f (f x)) f x) 23
3 λf x. [(λx. f (f x)) ((λf x. f (f x)) f x)] 20
4 λf x. f (f ([(λf x. f (f x)) f] x)) 17
5 λf x. f (f ([(λx. f (f x)) x])) 14
6 λf x. f (f (f (f x))) no redex left: the numeral 4 11
orders normal order (the leftmost outermost redex first) 6 steps; applicative order (the leftmost innermost) 6 steps
others (λx. y) ((λz. z z) (λw. w)): 1 step in normal order, 3 in applicative K I Ω: 2 steps, or no end
the factorial of 3 by a fixed point: 661 steps, the term going from 85 nodes up to 1,108 and down to 15
Lean #reduce prints fun f x => f (f (f (f x))) for 2 + 2 and refuses the other five terms (Lean 4.35.0, recorded)
(the live figure needs JavaScript; it loads no data)
Representing a proof as a concrete object is the first of the five steps outlined in the introduction, spanning Sections 1 through 4. Before types or logic enter the picture, this part isolates pure computation: β-reduction is the primary calculation rule inside Lean's kernel, the small program that performs proof checking (Section 6).
A proof checker that relies on rewriting expressions has to ask three things of its rewriting rule: first, that a machine can carry out substitution mechanically without confusing variables that happen to share a name (Section 1.2); second, that choosing a different order of steps never changes the final answer (Section 1.4); and third, that rewriting eventually halts. In the untyped calculus, the first two hold and the third fails: the very freedom that lets pure functions encode arithmetic and general recursion (Section 1.3), and thus every mechanically computable function (Section 1.5), also creates self-applying terms that run forever, with no algorithm able to tell in advance which terms halt. Section 2 introduces types specifically to repair that failure.
Every operation on lambda terms works recursively over how a term is constructed, and the grammar has just three clauses.
Definition 1.1.1 (lambda terms). Fix a countably infinite set of variables, written \(x, y, z\) and so on. The lambda terms are generated by three clauses: a variable is a term; if \(M\) and \(N\) are terms, so is the application \((M\,N)\); if \(M\) is a term and \(x\) a variable, so is the abstraction \((\lambda x.\, M)\).
Three conventions spare parentheses, and the figures follow them. Application associates to the left, so \(M\,N\,P\) means \((M\,N)\,P\): apply \(M\) to \(N\), then apply the resulting function to \(P\). The body of a \(\lambda\) extends as far to the right as parentheses allow, so \(\lambda x.\, M\,N\) means \(\lambda x.\, (M\,N)\) rather than \((\lambda x.\, M)\,N\). Multi-argument functions take their inputs one at a time, so \(\lambda x\,y.\, M\) abbreviates \(\lambda x.\, \lambda y.\, M\), a function that takes \(x\) and returns a function waiting for \(y\).
Analyzing how terms compute requires names for five basic notions: a subexpression ready to be contracted, a single rewrite step, a sequence of steps, a fully simplified result, and the equivalence linking two terms that rewrite to a common expression.
Definition 1.1.2 (β-reduction). A term of the form \((\lambda x.\, M)\,N\) is a β-redex (a reducible expression). Contracting it replaces it by \(M[x := N]\), the body \(M\) with \(N\) substituted for \(x\) (Definition 1.2.2 makes this exact). Write \(P \to_\beta Q\) when \(Q\) comes from \(P\) by contracting one redex anywhere in \(P\), and \(P \twoheadrightarrow_\beta Q\) when \(Q\) comes from \(P\) by zero or more such steps; \(Q\) is then a reduct of \(P\). Two terms are convertible, \(P =_\beta Q\), when a chain of steps, each taken forwards or backwards, links them. A term with no redex is in normal form, and \(P\) has a normal form if one of its reducts is in normal form.
A normal form is a finished result, a term containing no remaining β-redexes, such as the numeral 4 at the bottom of the first figure. When a term contains more than one redex, Definition 1.1.2 allows contracting any of them, and a small example shows how much that choice affects the path.
Example 1.1.3 (one term, two orders). The term \((\lambda x.\, y)\,((\lambda z.\, z\,z)\,(\lambda w.\, w))\) contains two redexes: the outer application itself, whose function \(\lambda x.\, y\) ignores its input \(x\), and the inner argument \(((\lambda z.\, z\,z)\,(\lambda w.\, w))\). Contracting the outer redex discards the unused argument immediately and yields \(y\) in one step. Contracting the inner argument first takes three steps:
\[(\lambda x.\, y)\,((\lambda z.\, z\,z)\,(\lambda w.\, w)) \;\to_\beta\; (\lambda x.\, y)\,((\lambda w.\, w)\,(\lambda w.\, w)) \;\to_\beta\; (\lambda x.\, y)\,(\lambda w.\, w) \;\to_\beta\; y .\]Three phenomena show up in those two runs.The example and its morals are from P. Selinger, "Lecture notes on the lambda calculus", arXiv 0804.3434 (version 2, 2013), §2.4, p. 17. Several examples of this part come from these notes. First, a step can create a brand-new redex that was not present before: substituting \(\lambda w.\, w\) for \(z\) inside \(z\,z\) produces \((\lambda w.\, w)\,(\lambda w.\, w)\). Second, a step can erase redexes wholesale whenever the bound variable does not appear in the body. Third, the number of steps depends on which redex is contracted first; that the final normal form never changes is a theorem, proved in Section 1.4. ◁
An evaluator therefore commits to a deterministic reduction strategy for choosing the next redex. Two standard strategies appear throughout the figures. Normal order always contracts the leftmost, outermost redex (the one whose \(\lambda\) stands furthest to the left), applying a function before inspecting its argument. Applicative order contracts the leftmost, innermost redex (one that contains no smaller redexes inside it), reducing an argument completely before handing it to a function. On Example 1.1.3, normal order takes one step and applicative order takes three; on 2 + 2, both take six.
For a mathematician trained in set theory, this untyped notion of function is a sharp departure. In standard analysis, a function is a graph, a set of input-output pairs between a domain and a codomain fixed beforehand; because no set belongs to itself in standard set theory, a function never sits inside its own domain, so \(f(f)\) is meaningless. Here a function is purely an operational rule that applies to whatever term it is handed, itself included: for \(\mathsf{I} = \lambda x.\, x\), the self-application \(\mathsf{I}\,\mathsf{I}\) steps cleanly to \(\mathsf{I}\), satisfying \(f(f) = f\). Alonzo Church invented the lambda calculus around 1928 as the core of a foundation for logic built on functions rather than sets,F. Cardone and J. R. Hindley, "History of lambda-calculus and combinatory logic", Swansea University Mathematics Department Research Report MRRS-05-06, 2006 (the first author's copy), §4.1, pp. 6 to 7: the calculus "was invented in about 1928 by Alonzo Church, and was first published in [Church, 1932]". The papers are A. Church, "A set of postulates for the foundation of logic", Annals of Mathematics 33 (1932), pp. 346 to 366, and 34 (1933), pp. 839 to 864. and on the second page of his 1941 monograph he explained what he was setting aside.
In particular it is not excluded that one of the elements of the range of arguments of a function f should be the function f itself. This possibility has frequently been denied, and indeed, if a function is defined as a correspondence between two previously given ranges, the reason for the denial is clear. Here, however, we regard the operation or rule of correspondence, which constitutes the function, as being first given, and the range of arguments then determined as consisting of the things to which the operation is applicable. This is a departure from the point of view usual in mathematics, but it is a departure which is natural in passing from consideration of functions in a special domain to the consideration of function in general, and it finds support in consistency theorems which will be proved below.
—Alonzo Church, The Calculi of Lambda-Conversion (1941). Annals of Mathematics Studies 6, Princeton University Press, chapter I, §1, p. 2. The page before defines a function as "a rule of correspondence by which when anything is given (as argument) another thing (the value of the function for that argument) may be obtained".
Both halves of Church's remark return shortly. The consistency theorem he points to is confluence (Section 1.4), while the traditional view he sets aside here, treating a function as a correspondence between input and output ranges fixed beforehand, is the discipline of types, which Church himself adopted for logic in 1940 (Section 2).
The entire calculus fits on one summary plate. Alongside β-reduction sit two structural equivalences that perform no calculation on their own: α-conversion, the renaming of a bound variable (Section 1.2), and η-conversion, which identifies a function \(M\) with the wrapper \(\lambda x.\, M\,x\) that merely passes an input straight to \(M\) (Remark 1.4.4).
The whole calculus: three kinds of term, three conversionsa row to a thing: first the three ways to build a term, then the three ways to pass from one term to another; in ink, how each is written
1.1variable a kind of term
A letter that stands for a term to be supplied later. There is nothing else to start from: no numbers, no constants.
x
1.1abstraction a kind of term
The function that sends x to M, written as its rule and given no name. The λ binds every x of M that no inner λx has taken.
λx. M
in Lean: fun x => M
1.1application a kind of term
M used as a function on the argument N. Nothing requires M to be a function or N to be of the right kind: any term may be applied to any term, itself included.
M N
in Lean: M N
1.2α, renaming a conversion
The name of a bound variable carries no information. Terms that differ only in such names are the same term, and a substitution may rename a binder to keep a variable from being captured.
λx. x is λy. y
1.1β, substitution the rule of computation
An abstraction applied to an argument becomes its body, with the argument put for the bound variable. Every computation of this part is a sequence of these steps.
(λx. M) N → M[x := N]
1.4η, unwrapping a conversion
An abstraction that only hands its argument on to M does what M does, and η lets it reduce to M. The rule does not follow from β.
λx. M x → M
if x is not free in M
green: the one rule that computes
Definition 1.1.2 left the substitution operation \(M[x := N]\) informal, and a proof checker, being a program, needs substitution defined without ambiguity.
Names are a nuisance
Replacing \(x\) with \(N\) inside \(M\) looks like simple find-and-replace, yet naive text replacement is where handwritten implementations of the lambda calculus first break. The trap arises when two distinct binders reuse the same variable name. In the reduction below, the argument \(N = \lambda z.\, x\,z\) refers to an outer \(\lambda x\), and substituting \(N\) into \(\lambda y.\, \lambda x.\, y\,x\) drops that \(x\) underneath a second, unrelated inner \(\lambda x\).
step one β-step of λx. (λy. λx. y x) (λz. x z): the redex is (λy. λx. y x) N with the argument N = λz. x z,
and the x of N is bound by the first λx, outside the redex
with names
1 λx. (λy. λx. y x) (λz. x z)
2 λx. λx. (λz. x z) x N copied as it stands: its x is captured, it now means the second λx
3 λx. λx'. (λz. x z) x' the binder renamed first: the x of N still means the first λx
with indices: a variable is the number of binders between it and its own, counted from 0
4 λ. (λ. λ. 1 0) (λ. 1 0)
5 λ. λ. (λ. 2 0) 0 no names, nothing to rename: the copy crossed 1 binder, its loose index 1 became 2
6 lam x (lam x (app (lam z (app (bvar 2) (bvar 0))) (bvar 0))) row 5 as Lean 4.35.0 stores it: the binders
keep a name for printing only, and Lean prints
fun (x : A) (x_1 : A) => (fun (z : A) => x z) x_1
(the live figure needs JavaScript; it loads no data)
In \(\lambda x.\, M\), the prefix \(\lambda x\) is a binder that governs occurrences of \(x\) inside \(M\). Like the integration variable \(x\) in \(\int_0^1 f(x)\,dx\), a bound variable is purely a local placeholder recording which \(\lambda\) owns each position, so \(\lambda x.\, x\) and \(\lambda y.\, y\) denote the exact same function. By contrast, a variable occurrence with no enclosing \(\lambda\) inside a subterm is free in that subterm, pointing to some outer scope. If naive substitution copies a term containing a free \(x\) underneath an inner \(\lambda x\), that free \(x\) suddenly falls under the inner \(\lambda x\) and changes meaning. This accident is called variable capture. Excluding capture can be done in two ways: rename clashing binders to fresh variable names not yet in use, or eliminate variable names altogether.
The renaming approach requires defining first which variables appear free in a term (and are therefore vulnerable to capture), and second when two terms differ only by harmless choices of bound variable names.
Definition 1.2.1 (free variables, α-equivalence). The free variables of a term are given by \(\mathrm{FV}(x) = \{x\}\), \(\mathrm{FV}(M\,N) = \mathrm{FV}(M) \cup \mathrm{FV}(N)\) and \(\mathrm{FV}(\lambda x.\, M) = \mathrm{FV}(M) \setminus \{x\}\). An occurrence of a variable that is not free is bound, and a term without free variables is closed. α-equivalence is the smallest equivalence relation on terms that is compatible with application and abstraction and identifies \(\lambda x.\, M\) with \(\lambda y.\, M\{y/x\}\) for every variable \(y\) that does not occur in \(M\), where \(M\{y/x\}\) is \(M\) with \(y\) written for \(x\) throughout. Terms that are α-equivalent are regarded as the same term.
With free variables and α-equivalence fixed, capture-avoiding substitution \(M[x := N]\) can be defined recursively so that an inner binder is renamed whenever its name clashes with a free variable of \(N\).
Definition 1.2.2 (substitution). The substitution \(M[x := N]\) of \(N\) for the free occurrences of \(x\) in \(M\) is defined by recursion on \(M\), for variables \(y \neq x\):
\[\begin{aligned} x[x := N] &= N, \\ y[x := N] &= y, \\ (M\,P)[x := N] &= (M[x := N])\,(P[x := N]), \\ (\lambda x.\, M)[x := N] &= \lambda x.\, M, \\ (\lambda y.\, M)[x := N] &= \lambda y.\, (M[x := N]) && \text{if } y \notin \mathrm{FV}(N), \\ (\lambda y.\, M)[x := N] &= \lambda y^{\prime}.\, (M\{y^{\prime}/y\}[x := N]) && \text{if } y \in \mathrm{FV}(N), \text{ with } y^{\prime} \text{ fresh}. \end{aligned}\]The last clause leaves the choice of \(y^{\prime}\) open, so the result is determined up to α-equivalence.
Look at the three \(\lambda\) clauses in Definition 1.2.2: the fourth stops when an inner \(\lambda x\) shadows the outer \(x\); the fifth is the ordinary safe case where \(y\) does not occur free in \(N\); and the sixth is the capture-avoiding repair that renames \(y\) to a fresh \(y^{\prime}\) first. The step in the figure above is the textbook trigger for that sixth clause, evaluating \((\lambda x.\, y\,x)[y := \lambda z.\, x\,z]\) inside an outer \(\lambda x\).Selinger's notes, §2.3, p. 16, for the six clauses, the remark on the last one and the example; §2.2 for α-equivalence.
Working with named variables forces a computer implementation to invent fresh names continually and to compare terms up to α-renaming. The second approach removes variable names at the root. In 1972 N. G. de Bruijn, needing fast mechanical substitution for his AUTOMATH proof checker, replaced every bound variable name with a natural number counting how many \(\lambda\) binders lie strictly between the variable occurrence and the \(\lambda\) that binds it. Pushing an argument \(S\) underneath an inner \(\lambda\) then increases the distance from every externally bound ("loose") variable inside \(S\) to its original outer binder by \(1\), while locally bound variables inside \(S\) keep their internal distances unchanged; a small index-shifting helper \(\uparrow^{d}_{c}\) with depth cutoff \(c\) automates that bookkeeping.
Definition 1.2.3 (nameless terms). A nameless term is an index \(k = 0, 1, 2, \dots\), an application \(M\,N\) or an abstraction \(\lambda.\, M\). The index \(k\) refers to the binder reached by going outward from it past \(k\) other binders: 0 is the nearest \(\lambda\) around it, 1 the next, so that \(\lambda x.\, \lambda y.\, x\,y\) is \(\lambda.\, \lambda.\, 1\,0\). An index with too few binders around it inside a term is loose in that term: it refers to a binder outside. The shift \(\uparrow^{d}_{c}\) adds \(d\) to every index that is at least the cutoff \(c\),
\[\uparrow^{d}_{c} k = \begin{cases} k & \text{if } k < c \\ k + d & \text{if } k \ge c \end{cases}, \qquad \uparrow^{d}_{c} (\lambda.\, M) = \lambda.\, \uparrow^{d}_{c+1} M, \qquad \uparrow^{d}_{c} (M\,N) = (\uparrow^{d}_{c} M)\,(\uparrow^{d}_{c} N),\]the substitution of a term \(S\) for the index \(j\) is
\[k[j := S] = \begin{cases} \uparrow^{j}_{0} S & \text{if } k = j \\ k & \text{if } k < j \\ k - 1 & \text{if } k > j \end{cases}, \qquad (\lambda.\, M)[j := S] = \lambda.\, M[j + 1 := S], \qquad (M\,N)[j := S] = (M[j := S])\,(N[j := S]),\]and the rule β reads \((\lambda.\, M)\,N \to_\beta M[0 := N]\).
With de Bruijn indices, renaming disappears and capture becomes impossible: whenever a copied term \(S\) crosses \(d\) binders, \(\uparrow^{d}_{0} S\) adds \(d\) to its loose indices so they keep pointing to the exact same outer binders (while indices above \(j\) in \(M\) decrease by \(1\) because contracting the redex removes one \(\lambda\)). Two named terms are α-equivalent if and only if their nameless forms match symbol for symbol, turning α-equivalence into plain structural comparison. Only human readability pays a price, since one variable is written as different numbers at different nesting depths. Tracing the capture example by these rules shows both the mechanical gain and the visual cost.
Example 1.2.4 (the step, by the rules). Inside the figure's outer \(\lambda\), the redex is \((\lambda.\, \lambda.\, 1\,0)\,(\lambda.\, 1\,0)\). In its argument \(S = \lambda.\, 1\,0\), index \(0\) is bound by \(S\)'s own \(\lambda\), whereas index \(1\) reaches past \(S\)'s \(\lambda\) to the outermost binder of the whole term, making \(1\) loose in \(S\). Evaluating \((\lambda.\, 1\,0)[0 := S]\) steps under one inner \(\lambda\), which increments the target index from \(0\) to \(1\):
\[(\lambda.\, 1\,0)[0 := S] \;=\; \lambda.\, (1[1 := S])\,(0[1 := S]) \;=\; \lambda.\, (\uparrow^{1}_{0} S)\,0 \;=\; \lambda.\, (\lambda.\, 2\,0)\,0 .\]Because \(S\) crossed one inner binder, \(\uparrow^{1}_{0} S\) shifted its loose index \(1\) up to \(2\) (exceeding cutoff \(1\) inside \(S\)'s own \(\lambda\)) while leaving its locally bound \(0\) unchanged. Leaving that \(1\) unshifted would have pointed it at the inner \(\lambda\) instead, reproducing the capture bug. ◁
De Bruijn was exact about who the notation is for.
Manipulations in the lambda calculus are often troublesome because of the need for re-naming bound variables. For example, if a free variable in an expesssion has to be replaced by a second expression, the danger arises that some free variable of the second expression bears the same name as a bound variable in the first one, with the effect that binding is introduced where it is not intended. Another case of re-naming arises if we want to establish the equivalence of two expressions in those situations where the only difference lies in the names of the bound variables (i.e. when the equivalence is so-called α-equivalence).
In particular in machine-manipulated lambda calculus this re-naming activity involves a great deal of labour, both in machine time as in programming effort. It seems to be worth-while to try to get rid of the re-naming, or, rather, to get rid of names altogether.
Consider the following three criteria for a good notation: (i) easy to write and easy to read for the human reader; (ii) easy to handle in metalingual discussion; (iii) easy for the computer and for the computer programmer.
The system we shall develop here is claimed to be good for (ii) and good for (iii). It is not claimed to be very good for (i); this means that for computer work we shall want automatic translation from one of the usual systems to our present system at the input stage, and backwards at the output stage.
—N. G. de Bruijn, "Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem" (1972). Indagationes Mathematicae 34, pp. 381 to 392 (the Automath archive's copy), §1; the misprint in the second sentence is the paper's. The application to AUTOMATH is its §13, and its example of metalingual discussion is the main part of a proof of the theorem of Section 1.4, written without names.
The last sentence describes Lean. Its sources (Lean/Expr.lean) define a term as a value of the type Expr, which has twelve constructors (Section 6.1 lists them), and three of the twelve are the three kinds of term of this part: bvar (deBruijnIndex : Nat) for a bound variable, app (fn : Expr) (arg : Expr) for an application, and lam (binderName : Name) (binderType : Expr) (body : Expr) (binderInfo : BinderInfo) for an abstraction.
Lean's bvar indices count upward from 0 as in Definition 1.2.3 (de Bruijn's 1972 paper counted from 1). Although each lam node retains a binderName field, the equality == defined on Expr in the same file ignores binder names completely, implementing α-equivalence directly: fun (x : Nat) => x and fun (y : Nat) => y are equal kernel expressions, and the equation between them is accepted with nothing left to compute (Section 1.6). Binder names exist solely for pretty-printing. Asked to display row 5 of the figure, Lean sees two nested binders named x and prints the inner one as x_1, carrying out de Bruijn's backwards translation at the output stage. Each binder also carries a type binderType, introduced in Section 2. Lean implements nameless β-substitution \(M[0 := N]\) as Expr.instantiate1; across the four terms offered in the figure and 458 further small test terms, Expr.instantiate1 returns the exact term computed in the page.
Substitution is now exact enough for a machine. Next comes the claim that variables, abstraction, and application alone can build data, arithmetic, and general recursion.
Everything computable
With neither numbers nor loops built into the syntax, the calculus manufactures both out of pure functions. In Church's encoding, a natural number \(n\) is represented not as static data, but as an iterator: the higher-order function that takes any step function \(f\) and starting value \(x\) and applies \(f\) successively \(n\) times to \(x\).
Definition 1.3.1 (Church numerals). The numeral of a natural number \(n\) is the closed term \(\overline{n} = \lambda f\,x.\, f^{n}\,x\), where \(f^{n}\,x\) stands for \(f\,(f\,(\cdots(f\,x)\cdots))\) with \(n\) occurrences of \(f\); so \(\overline{0} = \lambda f\,x.\, x\) and \(\overline{2} = \lambda f\,x.\, f\,(f\,x)\). Successor, sum and product are the terms
\[\mathsf{succ} = \lambda n\,f\,x.\, f\,(n\,f\,x), \qquad \mathsf{plus} = \lambda m\,n\,f\,x.\, m\,f\,(n\,f\,x), \qquad \mathsf{times} = \lambda m\,n\,f.\, m\,(n\,f),\]and for \(n \ge 1\) the power \(m^{n}\) is the application \(\overline{n}\,\overline{m}\), which the term \(\mathsf{exp} = \lambda m\,n.\, n\,m\) forms from the two numerals.Church's own numerals stood for the positive integers and began at 1, with \(\lambda f\,x.\, f\,x\). Zero as \(\lambda f\,x.\, x\) is later usage, and it is not a term of the calculus of his book, in which an abstraction must use its variable (Cardone and Hindley, §4.1, p. 7). With zero admitted, the power needs its condition: \(\overline{0}\,\overline{m}\) reduces to \(\lambda x.\, x\), which is the numeral 1 only up to the rule η of Remark 1.4.4. The term \(\lambda m\,n.\, n\,(\mathsf{times}\,m)\,\overline{1}\) is right at \(n = 0\) as well.
Each arithmetic term translates directly into the language of repeated function application. Applying \(f\) a total of \(m + n\) times means applying \(f\) first \(n\) times to \(x\) to get \(n\,f\,x\), and then applying \(f\) another \(m\) times to that result. Applying \(f\) a total of \(m \cdot n\) times means forming the \(n\)-fold jump \(n\,f\) and repeating that compound jump \(m\) times via \(m\,(n\,f)\). And because \(\overline{n}\) maps any function \(g\) to its \(n\)-fold iterate, applying \(\overline{n}\) to \(\overline{m}\) iterates the "\(m\)-fold iteration" operator \(n\) times, producing \(\overline{m^{n}}\). Church's monograph credits the three definitions to his student Rosser, grounding multiplication in the observation that the product of two positive integers "in the sense of the product of transformations is the same as their product in the arithmetic sense".The Calculi of Lambda-Conversion, chapter III, §8, p. 30.
Asking in Section 1.5 which numerical functions can be computed by lambda terms requires a precise definition of what it means for a term to compute a function on \(\mathbb{N}\).
Definition 1.3.2 (λ-definable function). A function \(f : \mathbb{N}^{k} \to \mathbb{N}\) is λ-definable if there is a term \(M\) such that \(M\,\overline{n_1} \cdots \overline{n_k} \twoheadrightarrow_\beta \overline{f(n_1, \dots, n_k)}\) for all \(n_1, \dots, n_k\).
By Definition 1.3.2, successor, addition, multiplication, and positive exponentiation are λ-definable. Because proof checking computes by reducing terms, the practical next question is how much work those reductions actually perform.
cost of arithmetic on Church numerals as the numeral n grows: each term reduced to its normal form in the page,
in normal order unless said; the last column is the formula that holds at every n tried (16 values of n
up to 32; up to 10 and 11 for 2 ^ n), a fit and not a theorem
n 1 2 4 8 16 32
β-steps
succ n 3 3 3 3 3 3 3
n + n 6 6 6 6 6 6 6
n · n 5 7 11 19 35 67 2n + 3
pred n 7 9 13 21 37 69 2n + 5
2 ^ n 4 8 32 512 . . 2ⁿ⁺¹
2 ^ n, applicative 4 7 13 25 . . 3n + 1
nodes copied by those steps
succ n 7 10 16 28 52 100 3n + 4
n + n 22 30 46 78 142 270 8n + 14
n · n 19 48 178 894 5,494 38,118 n³ + 5n² + 7n + 6
pred n 22 50 130 386 1,282 4,610 4n² + 16n + 2
pred n, applicative 18 36 78 186 498 1,506 n² + 15n + 2
reach 2 ^ n is measured up to n = 10 in normal order (2,048 steps) and up to n = 11 in applicative order (34 steps);
past that the page stops, at 2,500 steps or at a term of 5,000 nodes
(the live figure needs JavaScript; it loads no data and measures for about a second)
Remark 1.3.3 (a β-step is not a unit of work). Counting β-steps can look like counting machine instructions, yet a single β-step may copy an arbitrarily large argument into several places at once. At every \(n\) tested in the figure, the sum \(n + n\) took six β-steps, while the syntax-tree nodes copied across those six steps grew linearly as \(8n + 14\) in normal order, counting an argument's nodes once for each place a substitution writes it. (The nodes of a term are its variables, abstractions, and applications; the numeral \(\overline{n}\) has \(2n + 3\) nodes.) Step counts also depend sharply on the strategy: the power \(2^{n}\), written as \(\mathsf{exp}\,\overline{2}\,\overline{n}\), took \(2^{n+1}\) steps in normal order versus \(3n + 1\) steps in applicative order, whose first two steps pass the numerals into \(\mathsf{exp}\). Every formula in the final column matches all inputs measured, \(n\) up to 32 and, for \(2^{n}\), up to 10 in normal order and 11 in applicative order; they are empirical fits, not theorems.
One asymmetry in the table carries a famous history: at every \(n\) tested, successor took three steps whereas its inverse, the predecessor, took \(2n + 5\) steps (and \(n \cdot n\) similarly pays \(2n + 3\) steps). Definition 1.3.1 explains why. A Church numeral knows only how to iterate forward; it offers no direct handle to peel off one application of \(f\). Subtracting one therefore requires counting all the way up from zero while trailing one step behind: start from the pair \((0, 0)\), iterate the step \((a, b) \mapsto (b, b + 1)\) a total of \(n\) times to reach \((n - 1, n)\) for \(n \ge 1\), and extract the first component. Stephen Kleene hit upon this lagging-pair trick in early 1932 as Church's doctoral student; he had first proposed an alternative numeral encoding with an immediate predecessor, which Church had turned down.
Soon after returning to Church’s identification, one day late in January or early in February 1932, while in a dentist’s office, it came to me that I could λ-define the predecessor function […] When I brought this result to Church, he told me that he had just about convinced himself that there is no λ-definition of the predecessor function.
The discovery that the predecessor function is after all λ-definable excited our interest in what functions are not just definable in the full system but actually λ-definable. The exploration of this became a major subproject for my Ph.D. thesis. Of course, I did develop a great deal of theory of positive integers in Church’s formalism, using many λ-definitions in the process.
—Stephen C. Kleene, "Origins of recursive function theory" (1981). Annals of the History of Computing 3(1), pp. 56 to 57. The cut is where Kleene gives the construction, which runs on triples and on numerals that begin at 1.
Implemented directly with Church-encoded pairs, that sliding-window predecessor took \(10n + 6\) normal-order steps at every \(n\) tested; the shorter term labeled pred in the figure achieves the same one-step lag in \(2n + 5\) steps by wrapping \(f\) so the first step discards \(f\) and the remaining \(n - 1\) steps apply it. Lean's own natural numbers are not Church numerals. Lean defines Nat as an inductive type generated from zero and succ, so the predecessor of succ n reduces to n immediately by definition: the theorem Nat.pred_succ, stating ∀ (n : Nat), n.succ.pred = n, has the proof fun n => rfl, where rfl proves two expressions equal because they compute to the same term. Section 6 revisits the cost of unary succ numerals inside Lean's kernel.
Booleans and pairs admit the same trick of encoding data by how it acts on functions: true is \(\lambda x\,y.\, x\) (choose the first branch), false is \(\lambda x\,y.\, y\) (choose the second branch), and a pair holds two terms waiting to pass both to a chooser. Testing whether a numeral is zero is then \(\mathsf{iszero} = \lambda n.\, n\,(\lambda x.\, \mathsf{false})\,\mathsf{true}\): zero iterations return true, while one or more iterations overwrite the result with false.
Data as termsa row to a kind of data: what its term does when it is applied, and in ink the terms themselves
1.3a number iterates
The numeral n applies a function n times. A sum iterates n times and then m times more, a product iterates an iteration, and a power is one numeral applied to another.
2 is λf x. f (f x)
plus is λm n f x. m f (n f x)
1.3a truth value chooses
A truth value takes two terms and gives back the first or the second, so it is its own if-then-else: b M N reduces to M when b is true and to N when b is false.
true is λx y. x
false is λx y. y
1.3a pair waits for a chooser
A pair holds two terms until it is handed a term to apply to them. Handed true it gives back the first, handed false the second.
pair is λx y s. s x y
fst is λp. p true
snd is λp. p false
1.3a recursive definition is a fixed point
A definition that mentions itself is an equation N = F N, and every term F has a solution, built from a term applied to itself.
Θ is (λx y. y (x x y)) (λx y. y (x x y))
Θ F reduces to F (Θ F)
green: the one that needs a term applied to itself
With numbers, booleans, pairs, and iszero encoded, only general recursion appears missing. A recursive equation such as \(\mathrm{fact}(n) = 1\) if \(n = 0\) and \(n \cdot \mathrm{fact}(n - 1)\) otherwise calls \(\mathrm{fact}\) by name inside its own right-hand side, whereas an anonymous lambda term has no name to call itself by. Abstracting out that self-call as a parameter \(f\) yields the non-recursive step generator \(F = \lambda f\,n.\, \mathsf{iszero}\,n\,\overline{1}\,(\mathsf{times}\,n\,(f\,(\mathsf{pred}\,n)))\), turning the recursive definition into an equation \(\mathrm{fact} = F\,\mathrm{fact}\). Any term \(N\) satisfying \(F\,N =_\beta N\) solves that equation by feeding \(N\) back into \(F\) on each unfolding; such a solution is a fixed point of \(F\), and in the untyped lambda calculus every term has one.
Theorem 1.3.4 (fixed points). For every term \(F\) there is a term \(N\) with \(F\,N =_\beta N\). One such term is \(\Theta\,F\), where \(\Theta = A\,A\) and \(A = \lambda x\,y.\, y\,(x\,x\,y)\).
Proof. Two steps: \(\Theta\,F = A\,A\,F \to_\beta (\lambda y.\, y\,(A\,A\,y))\,F \to_\beta F\,(A\,A\,F) = F\,(\Theta\,F)\). ∎
In ordinary arithmetic over \(\mathbb{N}\) universal fixed points are impossible, since \(n \mapsto n + 1\) fixes no number. Here \(\Theta\,\mathsf{succ}\) is a legal lambda term rather than a numeral: instead of representing a finite number, it unfolds endlessly into \(\mathsf{succ}\,(\Theta\,\mathsf{succ})\) and has no normal form.Selinger's notes, Theorem 3.1, p. 22, call the theorem "perhaps the first surprising fact about the lambda calculus". A closed term that gives a fixed point of every \(F\), as \(\Theta\) does, is a fixed-point combinator. \(\Theta\) is Turing's, of 1937, and the first to be published. The better-known \(\mathsf{Y} = \lambda f.\, (\lambda x.\, f\,(x\,x))\,(\lambda x.\, f\,(x\,x))\) has often been called Curry's, though Curry gave no explicit fixed-point combinator before 1958; a term convertible with it was printed in 1950. Nor does recursion on the numbers need such a term: Kleene's λ-definitions of the recursive functions, of 1936, use none (Cardone and Hindley, §4.1, pp. 8 to 9). \(\mathsf{Y}\,F\) is convertible with \(F\,(\mathsf{Y}\,F)\) but does not in general reduce to it, where \(\Theta\,F\) reduces to \(F\,(\Theta\,F)\) (H. Barendregt and G. Manzonetto, "Turing's contributions to lambda calculus", preprint of 2011, the first author's copy, §1).
Because \(\Theta\,F\) reduces in two steps to \(F\,(\Theta\,F)\), duplicating \(A\) on demand to pass \(\Theta\,F\) into \(F\) as its own recursive callback, evaluating a recursive function comes down to reducing \(\Theta\,F\) on an input, provided the reduction strategy does not unfold \(\Theta\,F\) endlessly inside an unused branch.
Example 1.3.5 (the factorial of 3). Expanding every named definition inside \(\Theta\,F\,\overline{3}\) produces an 85-node lambda term for \(3!\). Reduced in normal order in the browser, it reaches the numeral 6 (15 nodes) in 661 β-steps, expanding along the way to 1,108 nodes before collapsing down. Under applicative order, the exact same starting term never even tests for zero: because applicative order insists on reducing innermost arguments before applying iszero, it repeatedly contracts the fresh copy of \(A\,A\) inside the recursive branch, passing 4,000 nodes before the page stops it after 784 steps. ◁
Strip away the outer step function \(F\) from self-application and what remains is the minimal non-terminating term \(\Omega = (\lambda x.\, x\,x)\,(\lambda x.\, x\,x)\), which reduces in one β-step to itself and to nothing else. Self-application powers untyped recursion, and it wrecks untyped logic. When lambda terms also stand for logical propositions, as in Church's original foundation, applying a fixed-point construction to negation \(N\) yields \((\lambda y.\, N\,(y\,y))\,(\lambda y.\, N\,(y\,y))\), a proposition convertible with its own negation that Church already noted in his 1932 account of Russell's paradox. Church's initial logical system quickly proved contradictory, and in 1935 Kleene and Rosser proved even his pared-down version inconsistent.S. C. Kleene and J. B. Rosser, "The inconsistency of certain formal logics", Annals of Mathematics 36 (1935), pp. 630 to 636; their contradiction is a variant of the Richard paradox. Cardone and Hindley, §4.1, pp. 7 to 9, who add that the pure calculus, "which had at first seemed shallow, turned out to be surprisingly rich". Pure equational reasoning on untyped lambda terms survived intact, in a precise sense that Section 1.4 establishes next; rescuing logic required outlawing \(x\,x\) by giving every term a type, the subject of Section 2.
First comes an operational question left open by Example 1.3.5: changing the reduction order decided whether evaluation ended, and nothing yet guarantees that two halting runs cannot end at two different answers.
Order matters and yet does not
Example 1.1.3 reached the same normal form \(y\) along two paths of different lengths. A proof checker that compares terms by reducing them needs the final result to be identical along every possible path. For 2 + 2, the full graph of reduction paths is small enough to draw.
graph every term that 2 + 2 reduces to, numbered: 13 terms; an arrow is one β-step, 18 steps in all
0 (λm n f x. m f (n f x)) (λf x. f (f x)) (λf x. f (f x)) the start
1 (λn f x. (λf x. f (f x)) f (n f x)) (λf x. f (f x))
2 λf x. (λf x. f (f x)) f ((λf x. f (f x)) f x)
3 (λn f x. (λx. f (f x)) (n f x)) (λf x. f (f x))
4 λf x. (λx. f (f x)) ((λf x. f (f x)) f x)
5 λf x. (λf x. f (f x)) f ((λx. f (f x)) x)
6 (λn f x. f (f (n f x))) (λf x. f (f x))
7 λf x. f (f ((λf x. f (f x)) f x))
8 λf x. (λx. f (f x)) ((λx. f (f x)) x)
9 λf x. (λf x. f (f x)) f (f (f x))
10 λf x. f (f ((λx. f (f x)) x))
11 λf x. (λx. f (f x)) (f (f x))
12 λf x. f (f (f (f x))) the normal form, the numeral 4: no step leads out of it
paths normal order 0 → 1 → 2 → 4 → 7 → 10 → 12 6 steps
applicative order 0 → 1 → 3 → 6 → 7 → 10 → 12 6 steps; the two part at 1 and meet again at 7
the other steps 2 → 5 3 → 4 4 → 8 5 → 8 5 → 9 8 → 10 8 → 11 9 → 11 11 → 12
others (λx. x x) ((λy. y) z): 6 terms, normal order 3 steps, applicative 2 2 ^ 3: 414 terms, 1,469 steps, 16 and 10
K I Ω: 3 terms, one of them normal; applicative order turns on the second for ever
(the live figure needs JavaScript; it loads no data)
rfl is recorded.No matter which redexes of 2 + 2 are contracted first, all 13 reachable intermediate terms funnel down into the single normal form 4 at the bottom, with the six-step trace of Section 1.1 forming one path through the graph. In 1936 Church and Rosser proved that diverging reduction paths from any term can always be rejoined downstream.
Theorem 1.4.1 (Church and Rosser, 1936). If \(M \twoheadrightarrow_\beta N\) and \(M \twoheadrightarrow_\beta P\), then there is a term \(Z\) with \(N \twoheadrightarrow_\beta Z\) and \(P \twoheadrightarrow_\beta Z\).A. Church and J. B. Rosser, "Some properties of conversion", Transactions of the American Mathematical Society 39 (1936), pp. 472 to 482. The statement is given as in Selinger's notes, §4.2, p. 28, which prove it for β and for β together with η.
This rejoining property is called confluence, and its immediate consequences turn β-reduction into a coherent notion of value.
Corollary 1.4.2. (i) Convertible terms have a common reduct: if \(M =_\beta N\), there is a \(Z\) with \(M \twoheadrightarrow_\beta Z\) and \(N \twoheadrightarrow_\beta Z\). (ii) If \(M =_\beta N\) and \(N\) is in normal form, then \(M \twoheadrightarrow_\beta N\). (iii) A term has at most one normal form, and of two convertible terms both have the same normal form or neither has one. (iv) Different normal forms are not convertible; for instance \(\lambda x\,y.\, x \neq_\beta \lambda x\,y.\, y\).
Proof. A conversion is a zigzag of reductions, and the theorem turns a peak into a valley; (i) follows by induction on the length of the zigzag. In (ii) the common reduct is a reduct of the normal form \(N\), so it is \(N\). A normal form reduces only to itself, which gives (iii) and (iv) from (ii). ∎
Part (iv) gives the untyped calculus its equational consistency: β-conversion does not collapse all terms into a single equivalence class (for instance, the Church booleans \(\lambda x\,y.\, x\) and \(\lambda x\,y.\, y\) stay distinct). That is the consistency theorem appealed to in the 1941 passage quoted in Section 1.1, and it stood firm when Church's surrounding logic collapsed. Parts (ii) and (iii) underpin mechanical proof checking: to test whether two terms possessing normal forms are convertible, reduce both to their unique normal forms along any convenient paths and check whether the results match. Once the binders are annotated with types, Lean's rfl accepts each of the 13 terms in the 2 + 2 graph as equal to the numeral 4, and each of the 414 terms reachable from \(\mathsf{exp}\,\overline{2}\,\overline{3}\) (the power \(2^{3}\)) as equal to the numeral 8; Section 6.3 states the full equality rules decided by Lean's kernel.
The idea of the proof. A natural first plan is to show that any two single β-steps out of a term \(M\) can be rejoined, and then induct on reduction lengths. Two obstacles defeat that plan. First, two single steps out of \(M\) cannot always be rejoined in single steps, because one step may duplicate an unreduced redex: from \((\lambda x.\, x\,x)\,((\lambda y.\, y)\,z)\), contracting the inner redex gives \((\lambda x.\, x\,x)\,z\) (one step from \(z\,z\)), whereas contracting the outer redex duplicates the argument into \(((\lambda y.\, y)\,z)\,((\lambda y.\, y)\,z)\), which needs two steps to meet the first branch at \(z\,z\). Second, merely rejoining single-step forks by multi-step reductions (local confluence), while true for β, fails to carry an induction when infinite loops exist: on four states with transitions \(a \leftarrow b \rightleftarrows c \to d\), every one-step fork closes via the \(b \rightleftarrows c\) cycle, yet \(b\) reaches the two dead ends \(a\) and \(d\) with no common target. Call (a) full confluence, (b) local confluence (single-step forks rejoin in multi-step reductions), and (c) the strict diamond property (single-step forks rejoin in single steps). Selinger's notes lay out the trap using those three labels.
A naive attempt to prove the Church-Rosser Theorem might proceed as follows: First, prove that the relation →β satisfies property (b) (this is relatively easy to prove); then use an inductive argument to conclude that it also satisfies property (a).
Unfortunately, this does not work: the reason is that in general, property (b) does not imply property (a)! An example of a relation that satisfies property (b) but not property (a) is shown in Figure 2. In other words, a proof of property (b) is not sufficient in order to prove property (a).
On the other hand, property (c), the diamond property, does imply property (a). This is very easy to prove by induction, and the proof is illustrated in Figure 3. But unfortunately, β-reduction does not satisfy property (c), so again we are stuck.
—Peter Selinger, "Lecture notes on the lambda calculus" (2013). §4.3, p. 30; the two figures are the notes' own. The proof sketched next is their §§4.3 to 4.4. That forks which close locally do give confluence when no reduction is infinite is Newman's lemma (1942), which is of no help for β.
The escape, due to William Tait and Per Martin-Löf, widens what counts as a single step so that duplicated copies of a redex can be contracted together and the strict diamond property (c) holds.Tait presented the idea, for combinatory logic, a sister calculus without bound variables, at a seminar at Stanford in 1965 and did not publish it; in the autumn of 1968 he showed it to Martin-Löf, who adapted it to β and put the proof in a manuscript of 1971. The steps are called parallel reductions after M. Takahashi, "Parallel reductions in λ-calculus", Journal of Symbolic Computation 7 (1989), pp. 113 to 123. Cardone and Hindley, §7.2, p. 21. A parallel step \(M \triangleright M^{\prime}\) contracts any subset of the redexes already visible in \(M\) simultaneously. Formally, \(\triangleright\) is the smallest relation satisfying \(x \triangleright x\); \(\lambda x.\, N \triangleright \lambda x.\, N^{\prime}\) whenever \(N \triangleright N^{\prime}\); and both \(P\,N \triangleright P^{\prime}\,N^{\prime}\) and \((\lambda x.\, P)\,N \triangleright P^{\prime}[x := N^{\prime}]\) whenever \(P \triangleright P^{\prime}\) and \(N \triangleright N^{\prime}\). Because every single β-step is a parallel step and every parallel step can be carried out as a sequence of single β-steps, chaining \(\triangleright\) generates the exact same multi-step relation \(\twoheadrightarrow_\beta\). Crucially, parallel steps obey the diamond property (c) for a transparent reason: every term \(M\) has a complete development \(M^{\ast}\) in which all redexes currently visible in \(M\) are contracted at once, and whichever visible redexes a partial step \(M \triangleright M^{\prime}\) left uncontracted (even if duplicated into multiple copies) can all be finished in one follow-up parallel step \(M^{\prime} \triangleright M^{\ast}\). Any two parallel reducts of \(M\) therefore meet at \(M^{\ast}\) in one step each, and tiling a grid with unit diamonds yields full confluence (a). On the duplicating fork above, \(M^{\ast}\) is \(z\,z\), which both branches reach in one parallel step.
Confluence guarantees that if a reduction reaches a normal form, it reaches the only one possible. It does not guarantee that every reduction strategy gets there when diverging subterms are present, so an evaluator still needs a strategy guaranteed to succeed whenever any halting path exists.
Theorem 1.4.3 (leftmost reduction). If \(M\) has a normal form, then normal order, the repeated contraction of the leftmost redex, reaches it.H. Barendregt and E. Barendsen, "Introduction to lambda calculus", revised edition, 2000 (the first author's copy), Theorem 4.22: "If M has a normal form, then iterated contraction of the leftmost redex leads to that normal form." They refer for the proof to H. P. Barendregt, The Lambda Calculus, its Syntax and Semantics (North-Holland, 1984), Theorem 13.2.2. It follows from the standardization theorem, by which every reduction can be rearranged to work from left to right, and which first appeared for this calculus in H. B. Curry and R. Feys, Combinatory Logic, volume I (1958).
Consider \(\mathsf{K}\,\mathsf{I}\,\Omega\), where \(\mathsf{K} = \lambda x\,y.\, x\) returns its first input and discards its second. Normal order contracts the outer \(\mathsf{K}\) applications without inspecting \(\Omega\), reaching \(\mathsf{I}\) in two steps. Applicative order refuses to pass an argument before reducing it, spinning on \(\Omega \to_\beta \Omega\) forever while the normal form \(\mathsf{I}\) remains a single outer step away at every moment. Even when a term has infinitely many reducts, every one of them can sit a step or two from the normal form, with only the choice of redex deciding whether evaluation terminates.
Normal order is complete in the sense of Theorem 1.4.3, though often longer when arguments are actually used: passing an unreduced argument into a function that mentions its variable several times forces every duplicated copy to be reduced separately. On \(\mathsf{exp}\,\overline{2}\,\overline{3}\), normal order takes 16 steps and applicative order 10, the longest and shortest paths through its graph of 414 terms, echoing the \(2^{n+1}\) versus \(3n + 1\) step counts of Section 1.3 (keeping Remark 1.3.3 in mind on steps versus work). Programmers know this split roughly as lazy versus eager evaluation: most languages evaluate arguments before a call, accepting that expressions like \(\mathsf{K}\,\mathsf{I}\,\Omega\) loop. In the page's reducer, normal order and applicative order share the exact same recursive walk over a syntax tree with a single line moved: normal order tests for a redex at the current node before descending into subterms, whereas applicative order descends into subterms first and tests the current node afterward.
function findNormal(t, R, path) {
if (R.std && NF.has(t)) return null;
if (ruleAt(t, R)) return path;
const ks = KIDS[t.k];
for (let i = 0; i < ks.length; i++) { path.push(i); if (findNormal(t[ks[i]], R, path)) return path; path.pop(); }
if (R.std) NF.add(t);
return null;
}
function findApplicative(t, R, path) {
if (R.std && NF.has(t)) return null;
const ks = KIDS[t.k];
for (let i = 0; i < ks.length; i++) { path.push(i); if (findApplicative(t[ks[i]], R, path)) return path; path.pop(); }
if (ruleAt(t, R)) return path;
if (R.std) NF.add(t);
return null;
}
Here ruleAt says whether a rule applies at the root of t, KIDS names the fields that hold its subterms, and NF remembers the subterms already found to hold no redex.
Section 1.1 listed η-conversion apart from β-reduction; Corollary 1.4.2 makes it immediate why η does not follow from β alone.
Remark 1.4.4 (η is a separate rule). Whenever \(x\) does not occur free in \(M\), the wrapper \(\lambda x.\, M\,x\) and \(M\) behave identically on every argument \(N\): \((\lambda x.\, M\,x)\,N \to_\beta M\,N\). Yet the rule η, which reduces \(\lambda x.\, M\,x\) to \(M\), cannot be derived from β: \(y\) and \(\lambda x.\, y\,x\) are distinct β-normal forms, so Corollary 1.4.2 (iv) gives \(y \neq_\beta \lambda x.\, y\,x\). Adopting η is therefore an explicit design choice. Lean adopts it: Lean accepts rfl as a proof that fun x => f x equals f, and η sits among the definitional equality rules of Section 6.3.
Theorem 1.4.3 begins with an "if": normal order finds the normal form if \(M\) has one. Whether an arbitrary term has a normal form at all is the question still open.
What is effectively calculable
Hand the reducer of Section 1.1 the term \((\lambda x.\, x\,x\,x)\,(\lambda x.\, x\,x\,x)\) and it stops after 570 steps once the term passes 4,000 nodes, unable to tell whether continuing further would eventually finish. Hand it \(\Omega\) and it reports immediately that the reduction never ends, because \(\Omega\) steps back to \(\Omega\) itself. Stopping at a step cap is an admission of ignorance rather than a proof of non-termination, so it is natural to ask for an analyzer that always knows: a mechanical procedure that decides, for any term \(M\), whether \(M\) has a normal form. In 1936 Church proved that no such procedure can exist, and proving that impossibility required something mathematics had never previously formulated: a rigorous definition of what any finite mechanical procedure can compute.
The definition came out of this calculus. By 1933 Church's students had found a term for every function on numbers they tried, and Church proposed that this was no accident: a function is effectively calculable, that is, computable by a finite mechanical procedure in the informal sense of the words, exactly when it is λ-definable.J. B. Rosser, "Highlights of the history of the lambda-calculus", Annals of the History of Computing 6(4), 1984, pp. 344 to 345. Rosser was the one spoken to, late in 1933, and recalls that Church "did not say it with any firm conviction". The proposal was printed in an abstract of 1935 and in the paper of 1936; the name "Church's thesis" is Kleene's. Within three years the same class of functions had been reached from two other sides, and that agreement, unlike the proposal, is a theorem.
Theorem 1.5.1 (three definitions, one class). For a function \(f : \mathbb{N}^{k} \to \mathbb{N}\) the following are equivalent: \(f\) is λ-definable; \(f\) is general recursive, that is, each of its values can be derived from one finite system of equations; \(f\) is computable by one of Turing's machines, a finite table of instructions that reads and writes one square at a time on an unbounded tape.S. C. Kleene, "λ-definability and recursiveness", Duke Mathematical Journal 2 (1936), pp. 340 to 353; A. Church, "An unsolvable problem of elementary number theory", American Journal of Mathematics 58 (1936), pp. 345 to 363, whose footnote 3 credits the proof that the first two are equivalent chiefly to Kleene; A. M. Turing, "On computable numbers, with an application to the Entscheidungsproblem", Proceedings of the London Mathematical Society (2) 42 (1936–37), pp. 230 to 265, appendix, and "Computability and λ-definability", Journal of Symbolic Logic 2 (1937), pp. 153 to 163. General recursiveness is due to Herbrand and Gödel. The papers speak of functions of positive integers.
Church's thesis is the claim that this one class is the class of the effectively calculable functions. That a λ-definable function is effectively calculable is plain: reduce the term. The converse cannot be proved, because one of its two sides is not a mathematical notion, and Church does not offer it as a theorem. His paper of 1936 sets it down as a definition: it defines the notion "of an effectively calculable function of positive integers by identifying it with the notion of a recursive function of positive integers (or of a λ-definable function of positive integers)"."An unsolvable problem of elementary number theory", §7, p. 356, and, for the footnote quoted next, p. 346: both as quoted in B. J. Copeland, "The Church-Turing Thesis", Stanford Encyclopedia of Philosophy (revision of 18 December 2023), §1.5 and §4.1. A scan of the paper, of which only the text layer could be read, agrees as far as that layer is legible (it gives the λ as a letter A and damages one word); the rest of the passage is left unquoted for that reason. For the definition he gives reasons, and he sets the equivalence of the first two definitions of Theorem 1.5.1 beside them: the fact, he writes in a footnote, that "two such widely different and (in the opinion of the author) equally natural definitions of effective calculability turn out to be equivalent" adds to the strength of his reasons "for believing that they constitute as general a characterization of this notion as is consistent with the usual intuitive understanding of it".
A mathematician's immediate objection comes from Cantor's diagonal argument. Enumerate all closed lambda terms mechanically as \(M_0, M_1, M_2, \dots\), and define \(g(n)\) to be one more than the number computed by \(M_n\,\overline{n}\); why isn't \(g\) a computable function missing from the list? Kleene tried this diagonalization in 1933 and, by Rosser's account, "became overnight a supporter of the thesis".Rosser, p. 345, citing S. C. Kleene, "Origins of recursive function theory" (1981), p. 59, where Kleene says that he saw the diagonalization could not be carried out effectively. The catch is that \(M_n\,\overline{n}\) reduces to a numeral only for some indices \(n\). If \(g(n)\) simply reduces \(M_n\,\overline{n}\) and adds \(1\) when it halts, then \(g\) itself fails to halt at non-terminating indices, making \(g\) only a partial function; if \(g\) appears on the list as \(M_k\), then at \(n = k\) neither \(g(k)\) nor \(g(k) + 1\) has a value, so no contradiction arises. Conversely, patching \(g(n)\) into a total function by returning \(0\) whenever \(M_n\,\overline{n}\) fails to halt would require an algorithm that decides in finite time whether \(M_n\,\overline{n}\) has a normal form. Terms without normal forms are precisely what blocks Cantor's diagonal.
Kurt Gödel was unconvinced by a bare formal definition; by Church's own report, Gödel initially "regarded as thoroughly unsatisfactory" identifying computability with λ-definability. What persuaded him, it seems, was Alan Turing's 1936 paper, which begins not from equations or functions, but by analyzing what a human calculator actually does with pencil and paper and building an abstract machine that performs those atomic steps and nothing else, as The painted rock recounts. Turing stated plainly what kind of argument such an identification requires.
No attempt has yet been made to show that the "computable" numbers include all numbers which would naturally be regarded as computable. All arguments which can be given are bound to be, fundamentally, appeals to intuition, and for this reason rather unsatisfactory mathematically. The real question at issue is "What are the possible processes which can be carried out in computing a number?"
The arguments which I shall use are of three kinds. (a) A direct appeal to intuition. (b) A proof of the equivalence of two definitions (in case the new definition has a greater intuitive appeal). (c) Giving examples of large classes of numbers which are computable.
—A. M. Turing, "On computable numbers, with an application to the Entscheidungsproblem" (1936). §9, p. 249. The paper was received on 28 May 1936; its appendix, which proves in outline that the machines and λ-definability give the same class, is dated 28 August 1936.
In 1946 Gödel said what Turing's analysis had gained: "with this concept one has for the first time succeeded in giving an absolute definition of an interesting epistemological notion, i.e., one not depending on the formalism chosen".Both remarks as quoted in Copeland's entry in the Stanford Encyclopedia of Philosophy: Church's report, of 1935, from Kleene's article of 1981 (§1.6 of the entry, where Kleene adds "It seems" to Gödel's change of mind), and Gödel's sentence from his remarks of 1946 (§4.1).
That contrast between relative provability and absolute computability underpins machine-checked mathematics. Provability is relative to the formal system chosen: a theorem proved in Lean is a theorem of Lean's logic, whereas weaker or stronger logics prove different things. Computability is absolute: a finite mechanical check is the exact same check regardless of what programming language or machine executes it, which is why an exported Lean proof can be verified all over again by a standalone checker that somebody else wrote (Section 13). Church's thesis also lets negative claims beginning "no procedure can…" become rigorous theorems.
Theorem 1.5.2 (Church, 1936). Number the terms in an effective way. No general recursive function tells from the number of a term whether the term has a normal form, and none tells from the numbers of two terms whether they are convertible.Theorems XVIII and XIX of "An unsolvable problem of elementary number theory", §8, pp. 360 to 363, stated there for Church's own calculus, in which an abstraction must use its variable, and for recursive functions of a formula, that is, of the number that codes it. The sketch that follows is in the terms of this part and for its calculus.
The idea of a proof. Turn the diagonal construction against any hypothetical halting decider. Write \(\ulcorner M \urcorner\) for the Church numeral of the code number of \(M\). Because elementary operations on code numbers (such as computing the code of \(M\,N\) from the codes of \(M\) and \(N\)) are mechanical and hence λ-definable by Theorem 1.5.1, the fixed-point trick of Theorem 1.3.4 can be repeated one level down on quoted syntax: every term \(F\) has a term \(X\) satisfying \(X =_\beta F\,\ulcorner X \urcorner\), handing \(X\) its own code number. Suppose a general recursive function decided whether terms have normal forms. By Theorem 1.5.1, some lambda term \(D\) would compute that test on codes, reducing \(D\,\ulcorner M \urcorner\) to \(\mathsf{true}\) when \(M\) has a normal form and to \(\mathsf{false}\) when it has none. Apply the syntax fixed point to \(F = \lambda n.\, D\,n\,\Omega\,\mathsf{I}\) to get \(X =_\beta D\,\ulcorner X \urcorner\,\Omega\,\mathsf{I}\). If \(X\) has a normal form, \(D\,\ulcorner X \urcorner\) reduces to \(\mathsf{true}\) and selects the first branch \(\Omega\), giving \(X =_\beta \Omega\), which has no normal form; if \(X\) has no normal form, \(D\,\ulcorner X \urcorner\) reduces to \(\mathsf{false}\) and selects \(\mathsf{I}\), giving \(X =_\beta \mathsf{I}\), which is already in normal form. Either case contradicts Corollary 1.4.2 (iii). Replacing "has a normal form" with "is convertible with \(\mathsf{I}\)" makes the exact same term \(X\) refute any decider for \(=_\beta\).
Notice the one-sidedness of halting. The terms that do have a normal form can be enumerated mechanically by dovetailing: advance the normal-order reductions of \(M_0, M_1, \dots\) in interleaved rounds, printing each term as soon as its reduction finishes. By a corollary in Church's same 1936 paper, the terms that have no normal form cannot be enumerated (otherwise running both enumerations side by side would decide halting for every term). A run that ends proves termination, whereas a run still going after 570 steps proves nothing, explaining the gap between the two status reports that opened this section. From the undecidability of \(=_\beta\), Church immediately deduced in a companion 1936 note a negative answer to Hilbert's Entscheidungsproblem: no algorithm decides for every formula of first-order logic whether it is provable.A. Church, "A note on the Entscheidungsproblem", Journal of Symbolic Logic 1 (1936), pp. 40 to 41. Turing's paper reaches the same conclusion with machines.
For a proof checker, Theorem 1.5.2 is an immovable design constraint. Checking types requires deciding whether two expressions compute to the same result, and across arbitrary untyped lambda terms no algorithm can decide \(=_\beta\). Lean's way out begins in Section 2: admit only terms that carry a valid type, in a calculus where well-typed reductions are guaranteed to halt. For the same reason, Lean cannot ask an oracle whether a recursive definition terminates; it requires a structural or well-founded termination proof that it can verify, and Section 1.6 shows Lean's refusal when none can be found.
In Lean
How much of this part Lean retains can be tested directly in Lean 4.35.0. A function in Lean is a lambda term whose binders carry types: fun x => M writes \(\lambda x.\, M\), and function application is juxtaposition with the left-associative conventions of Section 1.1. Below are the Church numeral two and plus from Section 1.1, specialized to iterate functions from Nat to Nat.
def Church : Type := (Nat → Nat) → Nat → Nat
def two : Church := fun f x => f (f x)
def plus : Church → Church → Church := fun m n f x => m f (n f x)
#reduce plus two two
#reduce plus two two Nat.succ 0
example : plus two two = fun f x => f (f (f (f x))) := rfl
Lean, here and below in version 4.35.0, answers the two #reduce lines with
fun f x => f (f (f (f x)))
4
The first output is the Church numeral 4 as a lambda expression, the second feeds Lean's own Nat.succ and 0 into that numeral to obtain 4, and the example (an unnamed theorem) is accepted in silence: rfl reduces both sides to the exact same normal form, relying on Corollary 1.4.2. As its docstring in Lean's standard library (Init/Notation.lean) states, #reduce turns normal-form rewriting directly into an interactive command.
/--
`#reduce <expression>` reduces the expression `<expression>` to its normal form. This
involves applying reduction rules until no further reduction is possible.
-- ...
-/
syntax (name := reduceCmd) "#reduce" reduceConfig term : command
Lean's nameless internal representation (Expr.bvar) also shows up directly when checking α-equivalence with rfl and reducing the capture-prone step of Section 1.2 with types added.
example : (fun (x : Nat) => x) = (fun (y : Nat) => y) := rfl
#reduce fun (x : Nat → Nat) => (fun (y : Nat → Nat) (x : Nat) => y x) (fun z => x z)
fun x x_1 => x x_1
Lean accepts the first line immediately because fun (x : Nat) => x and fun (y : Nat) => y build the identical de Bruijn term once variable names are erased. The second line evaluates the capture benchmark of Section 1.2 to its normal form and prints a fresh x_1 for the inner binder so the outer x stays distinct. What Lean refuses is the untyped half of this part: self-application and unguarded non-terminating recursion.
example (α β : Type) := fun (x : α → β) => x x
def loop (n : Nat) : Nat := loop n + 1
With the three blocks in one file, here Lambda.lean, and a blank line between them, these are its lines 13 and 14, and Lean refuses both.
Lambda.lean:13:45: error: Application type mismatch: The argument
x
has type
α → β
but is expected to have type
α
in the application
x x
Lambda.lean:14:4: error: fail to show termination for
loop
with errors
failed to infer structural recursion:
Not considering parameter n of loop:
it is unchanged in the recursive calls
no parameters suitable for structural recursion
well-founded recursion cannot be used, `loop` does not take any (non-fixed) arguments
Self-application has no simple type: if x has function type α → β, its argument must have type α, whereas the second x has type α → β rather than α. That single check banishes \(\Omega\) and Turing's \(\Theta\), requiring recursive functions to be declared by name and accompanied by a termination proof (Section 8.3). Nor is rejecting loop mere pedantry. Had Lean accepted def loop (n : Nat) : Nat := loop n + 1, unfolding it at 0 would yield loop 0 = loop 0 + 1, a number equal to its own successor, from which every falsehood follows. Lean rejects theorem oops : False := oops with the exact same fail to show termination error: in a logic where proofs are terms (Section 4), allowing a non-terminating term at type False would let an infinite loop stand as a proof of a contradiction.
A function is a rule, to compute is to substitute, and three kinds of term with that one rule compute everything that can be computed. The same freedom makes terms that never stop, and no procedure can tell which they are; Lean keeps the rule and gives up the freedom, by admitting only terms that have a type.
Section 2 asks what a type is, whether it buys the ending that this part could not promise, and at what cost.