TCS: Programming in Lambda Calculus
Programming in Lambda Calculus
Reduction and Normal Forms
A -redex is a subterm of the form . Contracting it replaces that subterm by , using capture-avoiding substitution
The one-step relation permits contraction anywhere inside a term
Write for zero or more reduction steps, and for the equivalence relation generated by reduction
For example, implements identity
Three Termination Properties
- A term is in normal form when it contains no -redex
- A term is normalizable when at least one reduction sequence reaches a normal form
- A term is strongly normalizable when every reduction sequence terminates
The distinction is visible in . Contracting the outer redex immediately produces , but repeatedly reducing the argument gives an infinite sequence
Normal-order reduction contracts the leftmost outermost redex, including redexes under abstractions when computing a full normal form. If a term has a normal form, this strategy eventually finds it
This theorem explains why evaluating an unused argument first can lose termination. Programming-language call-by-name is related to normal order, but usually stops before reducing beneath an unapplied abstraction
Church-Rosser Theorem
Different choices of redex can produce different intermediate terms. Confluence says that these choices remain compatible
If and , then some satisfies
Consequently, a term has at most one -normal form up to -equivalence
Confluence does not assert termination. The term still has an infinite reduction sequence and no normal form
One-step reduction itself need not have the diamond property. Contracting a redex may duplicate an argument, after which reducing its two copies requires two steps rather than one
Parallel Reduction
The proof introduces , which contracts several redexes together
Two ingredients make the argument work
- Substitution respects parallel reduction: if and , then
- Parallel reduction has the diamond property, proved by structural induction and a case analysis of the application rules
The substitution lemma handles the case where one derivation contracts an outer redex while the other reduces its body or argument. The induction hypothesis provides compatible reducts of the subterms
Finally,
Thus the two relations have the same reflexive transitive closure, and the diamond property of parallel reduction yields confluence of -reduction
As an application, and are distinct -normal forms when . They are not -equal, although the rule identifies them. Therefore is an additional equation
Encoding Booleans
A Boolean can be represented as a function choosing between two arguments
Then and . The selector itself implements branching
Boolean operators can be defined without new syntax
For instance, selects without needing to evaluate under normal order
Church Numerals
The numeral for applies a function times to an initial value
In particular,
The same term can serve different encodings: and are -equivalent. In the untyped calculus, the surrounding program determines the intended interpretation
Arithmetic by Iteration
Successor adds one application of . Addition composes applications with applications. Multiplication iterates the function , which itself performs applications, a total of times
For example,
Exponentiation reverses the order in which the numerals are applied
On Church numerals, , taking , including the convention for this operation
Zero Test and Predecessor
A zero test starts with true and replaces it by false whenever the numeral performs an iteration
For predecessor, keep a pair of consecutive values. Starting from , repeatedly update to . After iterations the first component is
Using the pair operations developed in Lecture 3, this gives
Currying and Representation
Every abstraction binds one variable. A function of several arguments is represented by nested abstractions, so applying it to fewer arguments returns another function
This is partial application: the resulting term adds four to its next numeral argument
More generally, a term represents when, for every input tuple,
Correctness therefore connects an operation on encoded values with ordinary mathematical computation