Capture-avoiding substitutions
This section describes how capture-avoiding substitutions are implemented in mCRL2, using the data expression grammar from the data expressions section of the data library overview.
Substitutions
A substitution is a function that maps variables to expressions.
It is assumed that
has finite support, in other words there is a
finite number of variables
for which
. We
define the substitution update
as follows:
The capture avoiding substitution
Let be a substitution that maps variables to data expressions, and
let
be an arbitrary data expression. Let
be the free
variables in
, and let
be the free variables in the
right-hand sides of
. More precisely,
We define a function that computes the capture-avoiding substitution
using
. The function
is recursively defined as follows:
where , where
is an
arbitrary variable such that
and
,
and where
.
Caution
The extension of to assignments given below is not correct and does
not match the actual implementation.
The function can be extended to assignments as follows:
Example
Let
and let
. Then
.
Capture-avoiding substitutions with an identifier generator
Let be a substitution that maps variables to data expressions. In
this section a substitution is defined that is more efficient than the
capture-avoiding substitution of the previous section because it does not require
the calculation of a set
of variables.
It does require that can indicate efficiently whether a variable
occurs in
(with
) for some variable
. Furthermore, it requires an identifier generator that can generate
variable names that are guaranteed to be fresh in the sense that they do not
occur in any term.
This substitution has been implemented as
replace_variables_capture_avoiding_with_an_identifier_generator.
We use ,
and
as defined in the previous section.
The substitution is defined as that calculates
using
recursively as follows:
where , where
is a
fresh variable such that
and
. The identifier
generator is used to generate the name for
.
In the examples below is the substitution mapping each variable onto
itself and
is the substitution mapping all variables onto
itself, except that
is mapped to
.
Example
Let
and let
. Then
where
is a fresh variable.
Example
It is necessary that above is chosen such that
. We provide two
examples to show what goes wrong if this condition is not satisfied.
If
is not required, the following is possible:
.
If
is not required, it is possible that:
.
Example
In a where clause the substitutions applied to the equations after the where can remain unchanged. For example,
In an expression the variable
at
the left-hand side of the
is a local variable, whereas the
at the right-hand side is globally bound.