Reading and Reducing Lambda Terms

Lambda calculus lets you study evaluation using a small symbolic language. Instead of arithmetic instructions or assignment statements, you work with variables, functions, and function application. For programming-language analysis, the central task is to read a term's structure and follow valid replacements. Here you will use the untyped system, where terms have no type annotations and evaluation need not terminate.

Reading the structure

Every term has one of three forms. Using MM and NN as placeholders for arbitrary terms, the grammar is


M::=x∣(λx.M)∣(M N).M ::= x \mid (\lambda x.M) \mid (M\,N).


A variable is a name such as xx. The expression λx.M\lambda x.M supplies a parameter and a body. An application M NM\,N applies the function represented by MM to the argument represented by NN.


Application groups to the left, while a lambda's body extends as far right as the surrounding parentheses permit. These are standard parsing conventions, not evaluation steps.


Written term

Explicit grouping

Structural point

a b ca\,b\,c

(a b) c(a\,b)\,c

Application groups left

a (b c)a\,(b\,c)

a (b c)a\,(b\,c)

Parentheses change the argument

λa.a b\lambda a.a\,b

λa.(a b)\lambda a.(a\,b)

The application lies inside the body


A syntax tree groups b applied to c as the argument of a.


A bound occurrence gets its meaning from an enclosing binder. A free occurrence does not. In λx.x y\lambda x.x\,y, the occurrence of xx in the body is bound and the occurrence of yy is free. Classify occurrences rather than names globally: a name can appear both free and bound in one larger term.

Replacing an application

Beta reduction replaces an application of a lambda expression by its body with the argument substituted for the parameter:


(λx.M) N→βM[x:=N].(\lambda x.M)\,N \to_\beta M[x:=N].


Here M[x:=N]M[x:=N] denotes capture-avoiding substitution. Replace every free occurrence of the parameter in the body; do not replace occurrences controlled by another binder for that same name.


Example: Applying the identity expression gives (λp.p) a→βa(\lambda p.p)\,a \to_\beta a. The argument replaces the single parameter occurrence. If the parameter does not occur in the body, the argument disappears instead.



A subterm of the form (λx.M) N(\lambda x.M)\,N is called a redex. A term may contain several redexes, including ones inside lambda bodies.

Keeping variable meaning intact

Substitution requires free occurrences in the argument to remain free. For example, directly replacing hh by qq in λq.h\lambda q.h would produce λq.q\lambda q.q. That would incorrectly turn the incoming free occurrence into a bound one.


First use alpha conversion: rename the binder to a fresh name, such as rr. Then


(λh.λq.h) q≡α(λh.λr.h) q→βλr.q.(\lambda h.\lambda q.h)\,q \equiv_\alpha (\lambda h.\lambda r.h)\,q \to_\beta \lambda r.q.


The free qq survives, and changing the bound name has not changed the function's meaning.



Normal forms and choosing steps

A normal form contains no beta redex anywhere, including inside lambda bodies. Reaching one completes beta reduction, although free variables may remain.


With normal-order reduction, you choose an outer application before a redex contained within it. If a term has a beta normal form, this strategy reaches it. Other choices can spend forever reducing an argument that an outer application would discard.


Termination is not guaranteed for every term. The expression


(λg.g g)(λg.g g)(\lambda g.g\,g)(\lambda g.g\,g)


reduces to itself in one beta step, so repeating that step never reaches a normal form. A reduction step therefore need not make a term shorter or visibly different.


What to remember

  • Parse application and binder scope before replacing anything.
  • Substitute only for the parameter's free occurrences in the body.
  • Rename bound variables when necessary to prevent capture.
  • Check the entire term for redexes before declaring a normal form.
  • A reduction strategy can determine whether evaluation reaches an available normal form.

Example: Checking a Symbolic Evaluator

Example: You are testing a symbolic evaluator with the input


E=((λf.λy.f y)(λu.y)) r.E=((\lambda f.\lambda y.f\,y)(\lambda u.y))\,r.


The evaluator uses capture-avoiding substitution: replacing a parameter preserves the free status of occurrences arriving from the argument. For the reductions below, use normal order, and use vv whenever a fresh replacement for the inner bound name yy is needed. Count beta reductions separately from bound-variable renaming.


a) Identify the free variable names in the complete input EE.


Inspect each part before combining the results. In λf.λy.f y\lambda f.\lambda y.f\,y, both body occurrences are controlled by enclosing binders, so that subterm has no free variable names.


In the argument λu.y\lambda u.y, the binder names uu and does not control the occurrence of y. The trailing argument contributes the free variable name r. Application combines these contributions:


FV⁡(E)=∅∪{y}∪{r}={y,r}.\operatorname{FV}(E) =\varnothing\cup\{y\}\cup\{r\} =\{y,r\}.


The free variable names in the complete input are yy and rr. The inner binder named yy in the first function does not extend over either of its external arguments.


b) Prepare the first normal-order beta reduction by renaming any conflicting binder, then perform that one reduction.


The first selected redex is (λf.λy.f y)(λu.y)(\lambda f.\lambda y.f\,y)(\lambda u.y). Its argument contains a free occurrence of yy. Directly placing that argument inside the body λy.f y\lambda y.f\,y would capture this occurrence.


Rename the inner binder to the fresh name ________, changing the occurrence it controls as well:


E≡α((λf.λv.f v)(λu.y)) r.E\equiv_\alpha ((\lambda f.\lambda v.f\,v)(\lambda u.y))\,r.


Now replace the free occurrence of ff in λv.f v\lambda v.f\,v by the entire argument λu.y\lambda u.y:


E→β(λv.(λu.y) v) r.E\to_\beta (\lambda v.(\lambda u.y)\,v)\,r.


After one beta reduction, the complete term is (λv.(λu.y) v) r(\lambda v.(\lambda u.y)\,v)\,r. The incoming yy remains free because the enclosing binder now names vv.


c) Continue in normal order to a normal form and state the total number of beta reductions from the original input.


Normal order next selects the outer application of λv.(λu.y) v\lambda v.(\lambda u.y)\,v to rr. Replace its body occurrence of vv by rr:


(λv.(λu.y) v) r→β(λu.y) r.(\lambda v.(\lambda u.y)\,v)\,r \to_\beta (\lambda u.y)\,r.


For the remaining application, the body of λu.y\lambda u.y contains no occurrence of uu. Its unchanged body is yy, so the supplied argument is discarded:


(λu.y) r→βy.(\lambda u.y)\,r\to_\beta y.


The variable yy contains no beta redex and is therefore the normal form. There was ________ beta reduction in part b and ________ more here:


1+2=3 beta reductions.1+2=3\text{ beta reductions}.


The final result is yy, reached in three beta reductions. The alpha conversion does not count as a beta reduction. The original free name rr disappears because its argument is ultimately discarded; capture avoidance preserves binding relationships, not the presence of every free name in the final result.

An interpreter reads the term (λj.j) k ℓ(\lambda j.j)\,k\,\ell using standard lambda-calculus conventions. Which fully parenthesized expression preserves its structure before any reduction occurs?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

An interpreter test uses Church booleans, lambda terms that select one of two arguments. The following names abbreviate the displayed terms:


T=λa.λb.a,F=λa.λb.b.T = \lambda a.\lambda b.a, \qquad F = \lambda a.\lambda b.b.


Treat red\mathrm{red}, blue\mathrm{blue} and green\mathrm{green} as distinct free variables. Application associates to the left. Reduce each expression to a normal form and fill in its remaining variable name.


For T (F red blue) greenT\,(F\,\mathrm{red}\,\mathrm{blue})\,\mathrm{green}, the normal form is .


For F (T red blue) greenF\,(T\,\mathrm{red}\,\mathrm{blue})\,\mathrm{green}, the normal form is .

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

You are documenting the checks performed by a symbolic lambda-calculus evaluator. Match each technical term to the description that correctly states its role during evaluation or inspection.

Match each term
A.

Consistently changes a binder's name and the occurrences it controls without changing meaning

B.

Replaces an application of a lambda expression by its body with capture-avoiding substitution of the argument

C.

A term containing no subexpression of the shape (λx.M) N(\lambda x.M)\,N

D.

A use of a variable name that is not controlled by any enclosing binder

Alpha conversion

Free occurrence

Beta reduction

Normal form

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice