Church–Rosser theorem

All roads lead to Rome. Do they? The Church–Rosser theorem says so: it guarantees uniqueness of the normal form, whichever paths we take towards it. Admittedly, in a Turing-complete language we may never reach a normal form at all — but if we do reach one, it is unique: whichever way you go, you arrive precisely in Rome.

If MM βN\twoheadrightarrow_\beta N and MM βK\twoheadrightarrow_\beta K, then there is an LL such that NN βL\twoheadrightarrow_\beta L and KK βL\twoheadrightarrow_\beta L. In other words, β\twoheadrightarrow_\beta has the diamond property (confluence):

M\displaystyle M βN,    M\displaystyle \twoheadrightarrow_\beta N,\;\; M βK    \displaystyle \twoheadrightarrow_\beta K \;\;     L:  N\displaystyle \Longrightarrow\;\; \exists L:\; N βL,    K\displaystyle \twoheadrightarrow_\beta L,\;\; K βL\displaystyle \twoheadrightarrow_\beta L
(1.31)

The proof is best carried out via parallel reduction. We need three reduction operators on terms:

  • β\to_\beta — ordinary, single-step β-reduction: MM βN\to_\beta N means one redex in MM is chosen and contracted (one step — one redex);
  • \Rightarrowparallel reduction: MM N\Rightarrow N means an arbitrary set of redexes already present in MM is contracted (zero, one, two — any number), each at most once, and only the existing ones, not their future copies;
  • β\twoheadrightarrow_\betamulti-step reduction (the reflexive-transitive closure of β\to_\beta): MM βN\twoheadrightarrow_\beta N means there is a chain MM β\to_\beta \dots βN\to_\beta N of any length, including zero.
Three diamonds with vertices M, N, K, L: for single-step (a), parallel (b) and multi-step (c) reduction; between b and c — the inclusion sign ⊆
Fig. 1.1. The diamond property for the three reduction operators: a — single-step β-reduction β\to_\beta; b — parallel reduction \Rightarrow; c — multi-step reduction β\twoheadrightarrow_\beta.

Single-step reduction is a special case of parallel reduction, which in turn is a special case of multi-step reduction:

β\displaystyle {\to_\beta} \displaystyle \subseteq {\Rightarrow} β\displaystyle \subseteq {\twoheadrightarrow_\beta}
(1.32)

Why can't the diamond property be proved directly for single-step reduction β\to_\beta (fig. 1.1, a)? Redex copying gets in the way. Take a term with two redexes — an outer and an inner one:

M\displaystyle M (λx.xx)((λy.y)z)\displaystyle \equiv (\lambda x.x\,x)\,\bigl((\lambda y.y)\,z\bigr)

Contract the outer redex — the substitution duplicates the inner one: we get ((λy.y)z)((λy.y)z)\bigl((\lambda y.y)\,z\bigr)\,\bigl((\lambda y.y)\,z\bigr). Contract the inner one — we get (λx.xx)z(\lambda x.x\,x)\,z. The paths have diverged by one step, but they can no longer meet in one step: the second term yields zzz\,z immediately, while the first needs two steps, one per copy. So the single-step diamond property for β\to_\beta is simply false.

Parallel reduction \Rightarrow cures exactly this disease: it contracts all the multiplied copies of a redex at once, in a single tick. For it the diamond property does hold (fig. 1.1, b), and it is proved by Takahashi's trick — via the complete development.

The complete development MM^{*} is the term in which all redexes visible in MM are contracted simultaneously — the greediest parallel step possible. It is defined by induction on the structure of the term:

The first rule: xx^{*} =x= x — a variable develops into itself.

The second rule: (λx.P)(\lambda x.P)^{*} =λx.P= \lambda x.P^{*} — the development goes under the abstraction.

The third rule: (PQ)(P\,Q)^{*} =PQ= P^{*}\,Q^{*} if PQP\,Q is not a redex (PP is not an abstraction): the parts are developed independently.

The fourth rule: ((λx.P)Q)\bigl((\lambda x.P)\,Q\bigr)^{*} =P[x ⁣:= ⁣Q]= P^{*}[x\!:=\!Q^{*}] — the redex itself is contracted, and its parts are developed as well.

Let us develop the counterexample term by these rules:

  • ((λx.xx)((λy.y)z))\bigl((\lambda x.x\,x)\,((\lambda y.y)\,z)\bigr)^{*} =(xx)[x ⁣:= ⁣((λy.y)z)]= (x\,x)^{*}[x\!:=\!((\lambda y.y)\,z)^{*}] — the whole term is a redex, so the fourth rule fires: the outer redex is contracted and both its parts go into development;
  • (xx)(x\,x)^{*} =xx= x^{*}\,x^{*} =xx= x\,x — the application xxx\,x is not a redex: the third rule, then the first for each variable;
  • ((λy.y)z)((\lambda y.y)\,z)^{*} =y[y ⁣:= ⁣z]= y^{*}[y\!:=\!z^{*}] =y[y ⁣:= ⁣z]= y[y\!:=\!z] =z= z — the inner redex: the fourth rule, then the first twice;
  • (xx)[x ⁣:= ⁣z](x\,x)[x\!:=\!z] =zz= z\,z — it remains to perform the substitution.

So MM^{*} =zz= z\,z: the development has contracted both the outer redex and the inner one — before the latter had a chance to multiply. The whole construction rests on the triangle lemma.

Triangle lemma. The complete development cannot be overtaken: whatever the parallel step MM N\Rightarrow N, exactly one parallel step leads from NN to MM^{*}:

M\displaystyle M N    \displaystyle \Rightarrow N \;\;     N\displaystyle \Longrightarrow\;\; N M\displaystyle \Rightarrow M^{*}
Triangle: a parallel step M ⇒ N extends in one step to the complete development M*; right — the diamond property built from two triangles
Fig. 1.2. The triangle lemma (left): any parallel step MM N\Rightarrow N extends by one step to the complete development MM^{*}. Right — the diamond property for \Rightarrow: two triangles sharing the bottom vertex MM^{*}.

A parallel step is not obliged to contract all the redexes — from a single MM the steps \Rightarrow lead to a whole fan of terms, and the complete development is merely the extreme, greediest point of that fan. So the step NN M\Rightarrow M^{*} is in general a real one; it is a zero step only when everything has already been contracted and NN =M= M^{*}.

A reduction that contracts all visible redexes at once, in a single sweep, is called the Gross–Knuth reduction MM GKM\Rightarrow_{\mathrm{GK}} M^{*}. But it is of no interest to us: it has no variability — from a given term such a step leads to exactly one result. And the Church–Rosser theorem is precisely about variability: the paths β\twoheadrightarrow_\beta contract redexes in an arbitrary order, and they cannot be decomposed into rigid Gross–Knuth steps. What is needed is precisely the freedom to contract any subset.

The diamond property follows from the triangle immediately. Suppose MM N\Rightarrow N and MM K\Rightarrow K. By the triangle lemma NN M\Rightarrow M^{*} and KK M\Rightarrow M^{*} — take LL =M= M^{*}, and both sides close in one step (fig. 1.2, right). The common point is the same for all: it depends neither on NN nor on KK.

It remains to lift the diamond property from a single parallel step to multi-step reduction (fig. 1.1, c). The inclusions (1.32) let us read any chain of β\to_\beta-steps as a chain of \Rightarrow-steps and vice versa. So let us write out MM βN\twoheadrightarrow_\beta N and MM βK\twoheadrightarrow_\beta K as two chains of parallel steps, lay them along the sides of a grid and complete it cell by cell — each cell is closed by the diamond property for \Rightarrow.

A grid of diamond cells converging to the common reduct L
Fig. 1.3. A grid of diamond cells: the sides are chains of parallel steps MM \Rightarrow \dots N\Rightarrow N and MM \Rightarrow \dots K\Rightarrow K; each cell (e.g. the shaded one) is the diamond property for \Rightarrow. The bottom vertex is the common reduct LL.

Having filled the whole grid, we obtain at the bottom vertex a term LL where both chains converge. All edges of the grid are parallel steps, and {\Rightarrow} β\subseteq {\twoheadrightarrow_\beta}, so NN βL\twoheadrightarrow_\beta L and KK βL\twoheadrightarrow_\beta L. The Church–Rosser theorem is proved.

The Church–Rosser theorem (1.31) immediately gives the existence of a common reduct: if MM =βN=_\beta N, there is an LL with MM βL\twoheadrightarrow_\beta L and NN βL\twoheadrightarrow_\beta L (induction on the definition of =β=_\beta). Hence the uniqueness of the normal form: a term has at most one β-NF — two paths would meet at a common LL, and an NF does not reduce further, so N1N_1 L\equiv L N2\equiv N_2. Next, reduction to NF: if NN is a normal form of MM, then MM βN\twoheadrightarrow_\beta N (not merely MM =βN=_\beta N). Finally, consistency: distinct normal forms are not β-equal — e.g. true\mathrm{true} and false\mathrm{false} — otherwise uniqueness of the NF would fail; this is how term “inequalities” are proved.

The order of contracting redexes, then, does not change the result — only whether the computation terminates and in how many steps. Choosing that order is the job of reduction strategies.