An important issue to keep in mind when applying the rule is
that the substitution for
should not ``capture'' variables.
Consider, for instance, the application
Using the
rule naively, we get
However, the
that comes in to
by the substitution for
is a new
and
should not be confused with the
that is used to define the inner
function. Thus, we should redefine the inner function with a fresh
variable before making the substitution, as follows:
Clearly, changing the name of the variable defining a function does
not affect the definition--there is no difference between the
functions and
.
To formalize this notion we have to define free and
bound variables. Intuitively, a variable is free in an
expression until it is ``bound'' by an abstraction. Thus, in the
expression , both
and
are free. If we abstract
as
,
remains free but
becomes bound. More
formally, we can define two sets
(free variables of
) and
(bound variables of
) inductively, as
follows:
|
|
When we apply the rule to transform
into
, we need to check that no free variable in
clashes with a bound variable in
. In the example above,
is bound in the expression
, while
is free in
the expression
.
In the literature, several approaches have been proposed to deal with
the variable renaming problem that is required for the rule to
work properly. For simplicity, we shall just assume that we always
rename the bound variables in
to avoid ``capturing'' free
variables from
.