TCS: Lambda Calculus
Lambda Calculus
Terms and Binding
The untyped -calculus builds programs from variables, function abstraction and function application. Functions are themselves values, so a function can receive another function, return one, or be applied to itself
Let be a countable set of variables. The set of terms is generated by
Here binds in its body , and applies to
These are inductive rules: contains exactly the terms obtainable by finitely many applications of the constructors. This gives a structural induction principle: prove a property for variables, and show that abstraction and application preserve it
The corresponding inference rules can be written with the premises above a horizontal line
A rule with no premises is an axiom. When additional conditions appear beside a rule, they must also hold before the rule can be applied
Subterms
The immediate subterms of are and , and the immediate subterm of is . All subterms are obtained recursively, including the whole term itself
Abbreviations
The fully parenthesized syntax makes the structure explicit, but we usually shorten terms using the following conventions
- Outermost parentheses may be omitted: can be written as
- Application associates to the left: means , rather than
- The body of an abstraction extends as far to the right as possible: means , rather than
- Consecutive abstractions may share one : abbreviates
- An abstraction on the right of an application may omit its surrounding parentheses: abbreviates
For example, combining these conventions gives
Parentheses remain necessary in : removing them would put inside the abstraction’s body and change the term
Free Variables
The free-variable function is defined structurally
A term is closed, or a combinator, when its free-variable set is empty
Binding is a property of an occurrence. In , the occurrence of in the body is bound, while is free. In , the first is free and the last is bound
Some useful closed terms are
Alpha-Conversion and Substitution
Renaming Bound Variables
The choice of a bound variable’s name carries no computational information
An -conversion must preserve binding. For example, cannot be renamed to : the free would become bound
We normally identify terms up to -equivalence and rename bound variables to fresh names whenever necessary
Capture-Avoiding Substitution
Write for the term obtained by replacing the free occurrences of in with
If the condition in the last line fails, first rename to a fresh variable
For example, consider substituting for in . The binder would capture the inserted , so rename it first
The result is not . Its free occurrence of must remain free
Beta-Conversion and Equational Reasoning
Applying an abstraction evaluates its body with the argument substituted for its parameter
The equality relation also permits reflexivity, symmetry, transitivity, and replacement inside applications and abstractions
For example, assuming is fresh for , the constant function discards its second argument
An equation is established by a finite derivation from the equality rules and the rule. The notation records that the equation is derivable in this theory
Equality and computation serve different purposes. Equality allows a step in either direction, whereas an evaluation step contracts an application of an abstraction. We will make this directed relation precise in Lecture 2
The Eta Rule
The term passes its argument directly to . When does not occur freely in , the rule identifies these terms
The side condition matters: is not an -expansion of . Adding this rule gives the theory , expressing an extensional view of functions
Fixed Points and Self-Application
A fixed point of a term is a term satisfying . In the untyped calculus, every term has such a fixed point
Define Curry’s fixed-point combinator
Then for every ,
To verify the equation, put . Both sides reduce to the same term
The useful idea is to turn a request for self-reference into self-application. If should satisfy , define so that and then apply to itself
Turing’s combinator offers a related construction
It satisfies the directed unfolding . For , the fixed-point equation above is stated as -equality; its displayed derivation uses a common reduct
Self-application also explains why evaluation may fail to terminate
The syntax allows recursion and divergence without introducing a separate recursion operator. We will use fixed points to construct recursive programs in Lecture 3