52 1. Knowledge Representation and Classical Logic
decide; this will be discussed later. Another topic is completion for equational rewrit-
ing, adding rules to convert an equational rewriting system into a logically equivalent
equational rewriting system with desired confluence properties. This is discussed by
Peterson and Stickel [205] and also by Jouannaud and Kirchner [130]; for earlier work
along this line see [151, 152].
AC rewriting
We now consider the special case of rewriting relative to the associative and com-
mutative axioms E ={f(x,y) = f (y, x), f (f (x, y), z) = f(x,f (y,z))} for a
function symbol f . Special efficient methods exist for this case. One idea is to mod-
ify the term structure so that R, E rewriting can be used rather than R/E rewriting.
This is done by flattening, that is a term f(s
1
,f(s
2
,...,f(s
n−1
,s
n
)...)), where none
of the s
i
have f as a top-level function symbol, is represented as f(s
1
,s
2
,...,s
n
).
Here f is a vary-adic symbol, which can take a variable number of arguments. Simi-
larly, f(f(s
1
,s
2
), s
3
) is represented as f(s
1
,s
2
,s
3
). This represents all terms that are
equivalent up to the associative equation f (f (x, y), z) = f (x,f (y,z)) by the same
term. Also, terms that are equivalent up to permutation of arguments of f are also
considered as identical. This means that each E-equivalence class is represented by a
single term. This also means that all members of a given E-equivalence class have the
same term structure, making R, E rewriting seem more of a possibility. Note however
that the subterm structure has been changed; f(s
1
,s
2
) is a subterm of f(f(s
1
,s
2
), s
3
)
but there is no corresponding subterm of f(s
1
,s
2
,s
3
). This means that R, E rewriting
does not simulate R/E rewriting on the original system. For example, consider the
systems R/E and R, E where R is {a ∗ b → d} and E consists of the associative and
commutative axioms for ∗. Suppose s is (a ∗ b) ∗ c and t is d ∗ c. Then s →
R/E
t;in
fact, s →
R,E
t. However, if one flattens the terms, then s becomes ∗(a,b,c)and s no
longer rewrites to t since the subterm a ∗ b has disappeared.
To overcome this, one adds extensions to rewrite rules to simulate their effect on
flattened terms. The extension of the rule {a ∗ b → d} is {∗(x,a,b) →∗(x, d)},
where x is a new variable. With this extended rule, ∗(a,b,c) rewrites to d ∗ c.The
general idea, then, is to flatten terms, and extend R by adding extensions of rewrite
rules to it. Then, extended rewriting on flattened terms using the extended R is equiv-
alent to class rewriting on the original R. Formally, suppose s and t are terms and
s
and t
are their flattened forms. Suppose R is a term rewriting system and R
is
R with the extensions added. Suppose E is associativity and commutativity. Then
s →
R/E
t iff s
→
R
,E
t
. The extended R is obtained by adding, for each rule of
the form f(r
1
,r
2
,...,r
n
) → s where f is associative and commutative, an extended
rule of the form f(x,r
1
,r
2
,...,r
n
) → f(x,s), where x is a new variable. The origi-
nal rule is also retained. This idea does not always work on other equational theories,
however. Note that some kind of associative–commutative matching is needed for ex-
tended rewriting. This can be fairly expensive, since there are so many permutations to
consider, but it is fairly straightforward to implement. Completion relative to associa-
tivity and commutativity can be done with the flattened representation; a method for
this is given in [205]. This method requires associative–commutative unification (see
Section 1.3.6).