Although this section and the next are quite technical, and it may be possible to skip them in a first reading, they introduce the concepts of matching and equational simplification that are essential to understand how Maude works. Therefore, we advise the reader to come back to them as needed to gain a better understanding of those concepts.
Recall from Section 4.3 that a functional module defines an
equational theory
in membership equational logic, with
the equations specified as equational attributes in operators (see Section 4.4.1),
and
the (possibly conditional) equations and memberships specified as statements.
Ground terms in the signature
form a
-algebra denoted
. Similarly, equivalence classes
of terms modulo
define the
-algebra denoted
,
which is the initial model for the theory
specified by the
module [60].
Given a set
of variables, we can add them to the signature
as new constants, and get in this way a term algebra
where now the terms may have variables in
.
Given a set
of variables, each having a given kind, a (ground)
substitution
is a kind-preserving function
. Such substitutions may be used to represent assignments of terms
in
to the variables in
, and also assignments of elements in
to such variables by
picking up a representative of
the corresponding
-equivalence class. For example, a very natural
choice is to assign to each
in
a term
which is in
canonical form according to
. Furthermore, under the preregularity,
Church-Rosser, and termination assumptions (more on this below) this canonical form
will have a least sort.
Therefore, we may allow each variable
in
to
have either a kind or a sort assigned to it, and can call the substitution
well-sorted
relative to
if the least sort of
is
smaller or equal to that of
. By substituting terms for variables (as indicated by
) in the usual way, a substitution
is extended to a homomorphic function on terms
that we denote with the same name.
Given a term
, corresponding to the lefthand side of an
oriented equation, and a subject ground term
, we
say that
matches4.13
if there is a substitution
such that
, that is,
and
are syntactically equal terms.
For an oriented
-equation
to be used in equational simplification,
it is required that all variables in the righthand side
also appear among the
variables of the lefthand side
. In the case of a conditional equation
, this requirement is relaxed, so that more
variables can appear in
the condition
, provided that they are introduced by matching equations
according to the admissibility requirements in Section 4.6;
then the variables in the righthand side
must be among those in the
lefthand side
or in the condition
. Under this assumption, given a
theory
a term
rewrites to a term
using such an
equation if there is a subterm
of
at a given position4.14
of
such that
matches
via a well-sorted substitution4.15
and
is obtained from
by
replacing the subterm
with the term
.
In addition, if the equation has a condition
, the substitution
must make the condition provably true according to the equations and
memberships in
, which are assumed to be Church-Rosser and terminating and
are used also from left to right to try to simplify the condition. Note that,
in general, the variables instantiated by
must contain both those in
the lefthand side, and those in the condition (which are incrementally matched
using the matching equations).
We denote this step of equational simplification
by
, where the possible equations for rewriting are chosen
in the set
. The reflexive and transitive closure of the relation
is denoted
.
In many texts, equational simplification is also called (equational) rewriting but, since in Maude we have two very different types of rewriting, rewriting with equations in functional modules, and rewriting with rules in system modules, each with a completely different semantics, to avoid confusion we favor the terminology of equational simplification for the process of rewriting with equations.
A set of equations
is confluent
when
any two rewritings of a term can always be unified by further rewriting:
if
and
, then there
exists a term
such that
and
. This is summarized in Figure 4.1.
A set of equations
is terminating
when there is no infinite sequence
of rewriting steps
If
is both confluent and terminating, a term
can be reduced to a
unique canonical form
, that is, to a unique term that can no
longer be rewritten. Therefore, in order to check semantic equality of two
terms
(that is, that they belong to the same equivalence class),
it is enough to check that their respective canonical forms are equal,
, but, since canonical forms cannot be
rewritten anymore, the last equality is just syntactic coincidence:
.
In membership equational theories a third important property is sort
decreasingness.
Intuitively, this means that, assuming
is confluent and
terminating, the canonical form
of a term
by the
equations
should have the least sort possible among the sorts of all
the terms equivalent to it by the equations
; and it should be possible to
compute this least sort from the canonical form itself, using only the operator
declarations and the memberships. By a Church-Rosser and terminating
theory
we precisely mean one that is confluent, terminating, and
sort-decreasing. For a more detailed treatment of these properties, we refer
the reader to the paper [7].
Since Maude functional modules have an initial algebra semantics, we are primarily
interested in ground terms. Therefore, we can relax the above Church-Rosser
and termination requirements by requiring that they just hold for ground terms,
without losing the desired coincidence between the mathematical and operational
semantics. In this way, we obtain notions of ground Church-Rosser,
terminating, confluent, etc. specifications.
In practice, some perfectly reasonable
Maude functional modules are ground confluent, but fail to be confluent. This
however is not a problem, since ground confluence (together with ground termination)
is just what is needed to ensure uniqueness of canonical forms. Indeed, under the
ground Church-Rosser and termination assumptions, it is easy to prove that we have
the desired isomorphism
Equational specifications
in Maude functional modules (and in the
equational part of system modules), are assumed to be ground Church-Rosser and
terminating up to the context-sensitive strategy specified by the evaluation
strategies declared for the operators in
(see Section 4.4.7).
More precisely, we can view the information about operator evaluation strategies as a
function
that assigns to each operator
with
argument sorts
a string of numbers indicating the argument positions to be evaluated and ended with
a
(that is, the information given in the operator's strat attribute, or,
if no such information is given, the string
). This then defines a
more restricted rewrite relation
where we can only rewrite in
subterms in positions that can be evaluated according to
. If the relation
is (ground) confluent, we call the specification (ground)
-confluent; similarly, if
is (ground) terminating,
we call it (ground)
-terminating. We define the concepts of (ground)
-sort-decreasing and (ground)
-Church-Rosser in the same way.
When we talk about the specification being ``ground Church-Rosser and terminating up
to the context-sensitive strategy specified by the evaluation strategies,'' we exactly
mean that it is ground
-Church-Rosser and ground
-terminating. Of course,
when no such strategies are declared, this specializes to the usual notions of ground
Church-Rosser and ground terminating. Under the ground
-Church-Rosser and ground
-terminating assumptions, the
-canonical forms define a canonical term algebra
(see [45]), which provides a
perfect mathematical model for the module's operational semantics, since its
elements are the values that the user gets when evaluating expressions in such
a module. The question then arises: how is this model related to the module's
mathematical semantics? In general, the quotient map
sending
each
-canonical form to its
-equivalence class is a surjective homomorphism
What are the appropriate notions when we have a theory of the
form
? Then matching must be defined modulo
the equational axioms
, and all the above concepts, including
those for
-rewriting, must be generalized to equational simplification,
confluence, and termination modulo
.
We discuss this in more detail in Section 4.8 below. See also
[45] for a detailed treatment of
-rewriting
and
-semantic completeness modulo axioms
.
As already mentioned, the operational semantics of functional modules is
equational simplification,
that is, equational rewriting of terms until a canonical form is obtained
in the sense explained above. Notice that the system does not check the
ground confluence and termination properties: they are left to the user's
responsibility. However, in some cases it is possible to check these
properties with Maude's Church-Rosser checker and termination tools
[17,30,29].
Similar checkings are also possible for functional modules
with evaluation strategies; for example, the Maude's
MTT termination tool can check
-termination (also
called context-sensitive termination [51]).
Moreover, although the relations between the standard Church-Rosser property
and the
-Church-Rosser property are somewhat subtle
[50,52], the work in [45]
shows how one can use standard tools in conjunction with Maude's Sufficient
Completeness Checker [46] to check both the
-Church-Rosser property and
-semantic completeness.
See Section 9.4 for some examples
of the use of these formal tools.