Free and Bound Variables
Bound vs free occurrences. Which variables belong to which lambda.
Before we can define substitution correctly, we need to know which
variables "belong" to which λ. Getting this wrong is the most common
source of errors in lambda calculus.
What Makes a Variable Bound?
A variable occurrence is bound if there is a λ in the expression
that binds it. It is free if no λ claims it.
In λx.x y:
xis bound —λxcaptures ityis free — no enclosingλybinds it
The same variable name can be free in one place and bound in another:
(λx.x) x — the first x is bound (inside λx), the second x
is free (outside).
What Makes a Variable Free?
A variable occurrence is free if no enclosing λ binds it. It
references something outside the current term.
In λx.x y:
yis free — noλyappears anywhere enclosing itxis bound —λxencloses it
Free does not mean "undefined" or "error." A free variable is
simply a reference to something the current term does not control.
The term y by itself is perfectly valid — y is free, and that
is fine.
Free or Bound?
To determine whether a variable occurrence is free or bound, look for
an enclosing λ with the same name:
- Bound: a
λwith that name wraps around the occurrence - Free: no such
λexists
In λx.x y: x is bound (enclosed by λx), y is free (no λy).
In (λx.x) y: x is bound, y is free.
In λy.x: x is free (no λx), y is not even an occurrence in
the body — it only appears as the parameter name.
Same Name, Different Status
The same variable name can appear both free and bound in a single
expression. What matters is which occurrence you are looking at
and whether a λ with that name encloses that particular occurrence.
In (λx.x) x:
- The first
x(insideλx) is bound - The second
x(outsideλx) is free
The name x does not have a single status. Each occurrence is
evaluated independently based on its position.
Why Free Variables Matter
When we apply (λx.M) N, we substitute N for x in M. But
crucially, substitution only replaces free occurrences of x
in M. Any x that is bound by an inner λx is left untouched.
Example: (λx.x (λx.x)) a
- The outer
xin the body is free with respect to the innerλx - The inner
xis bound by its ownλx - Result:
a (λx.x)— only the freexwas replaced
This is why the free/bound distinction exists: it tells substitution which occurrences to replace and which to protect.
Counting Free Occurrences
To count free variable occurrences, examine each variable in the term
individually. For each one, check whether an enclosing λ with the
same name exists. If not, that occurrence is free.
Remember: count occurrences, not distinct names.
In x y x:
- Three variable occurrences, all free (no
λanywhere) - Free occurrences: 3
In λx.x y:
xis bound (enclosed byλx),yis free- Free occurrences: 1
No Matching Binder Means Free
A common mistake: seeing a λ in the expression and assuming all
variables must be bound. But a λ only binds variables with the
same name. Other variables are unaffected.
In λx.y:
yis free — the onlyλhere isλx, which bindsx, noty
In λx.λy.z:
zis free — neitherλxnorλybindsz
The presence of lambdas in a term does not make all variables bound.
Each variable needs its own λ to be bound.
The Binder Must Enclose
A λx only binds occurrences of x that are inside its body —
the part after the dot. An x that appears outside the scope of
that λ is not bound by it, even if the names match.
In (λx.x) x:
- The
xinsideλx.xis bound (it is in the body) - The
xafter the closing parenthesis is free (it is outside)
In x (λx.x):
- The first
xis free (theλxhas not started yet) - The second
xis bound (inside theλxbody)
Position matters. The λ must wrap around the occurrence.
Terms with No Lambdas
A term with no λ at all has no binders. Since every variable needs
an enclosing λ with its name to be bound, and there are none, every
variable in such a term is free.
x y z — three variable occurrences, all free.
f x — two variable occurrences, both free.
These are valid lambda terms. Applications and variables are two of
the three term forms — no λ is required. The variables simply refer
to things defined elsewhere.
Listing Free Variables
The free variables of a term are the set of variable names that have at least one free occurrence. We write FV(M) for this set.
Examples:
- FV(
x y) = {x, y} — no lambdas, both are free - FV(
λx.x y) = {y} —xis bound,yis free - FV(
λx.λy.x y) = {} — both variables are bound - FV(
λx.y z) = {y, z} — onlyxhas a binder
A term with no free variables is called closed (or a combinator).
Ready to test your understanding?
Bitwit uses spaced repetition to help you truly master concepts like this—not just read about them. Each card generates with different values, so you can't just memorize answers.
Practice Free and Bound Variables →