19 Rewriting theory
We briefly recall the basics of rewrite theory necessary to our exposition, following mostly Baader and Nipkow
[
3
]
, and generally omitting proofs when they can be found there.
We first work in the abstract taking an arbitrary set , with a given equivalence relation over it which we denote . We consider a relation over .
Definition
19.1
We write if holds in , and say that rewrites to (or reduces to) . We further define
as the transitive closure of .
as the reflexive transitive closure of .
as the reflexive transitive and symmetric closure of .
We sometimes write , (resp. etc) to mean (resp. etc), and chain notations, e.g. .
Note that is an equivalence relation and the hope is for it to be equal to , in order to deduce properties of the latter.
One should first note that if even is contained in , then so are and (as it is an equivalence relation), so we will focus on that case. Generally can be seen as a way to compute the relation, as it is directed, in a way to constrain our search space.
However, in general, we cannot deduce the converse, so it may be the case that but neither nor nor even is there a single such that , as the number of “left-right alternations” may be arbitrarily large.
The following properties are going to be very useful to deduce exactly such a converse.
Definition
19.2
We say that is Church-Rosser if whenever , there exists some such that
We say that is confluent if whenever there exists some such that .
We say that is locally confluent if whenever there exists some such that .
We say that (an arbitrary) is in normal form (or is a normal form) if there is no such that , and that is weakly normalizing if for every , there is some such that and is in normal form.
We say that is strongly normalizing if there are no infinite rewrite sequences . In particular, a strongly normalizing is also weakly normalizing.
It turns out that if is strongly normalizing and Church-Rosser, and effective (we can “compute” with it) then the problem of equivalence is decidable! This is because of the following lemma.
Lemma
19.3
If is Church-Rosser, then any normal form is unique.
This means that, in this situation, and reduce to an identical normal form if and only if ! This means that we have the following algorithm to decide (and therefore if these relations coincide):
Repeatedly apply to and until normal forms and are found for them (this is possible because is strongly normalizing).
Compare and for exact equality (sometimes called “syntactic equality”).
If , we can conclude .
If can can conclude that they are not equivalent due to the lemma.
Note that weak normalization does not change much here except at step 1, where we need to pick reductions which eventually bring the elements to normal forms.
The strategy is therefore, for a given to find an which is (strongly) normalizing and Church-Rosser, and such that . This is roughly the goal of the entire field of completion. We call such an complete for .
The task is helped by the following facts, which we state here also without proof.
Theorem
19.4
is Church-Rosser iff it is confluent.
(Newman’s lemma) if is strongly normalizing, then is confluent iff it is locally confluent.
This can be leveraged by looking at the particulars of the equivalence relation of interest, namely quantified equations over syntactic trees as in Chapter 10, and a theory , which we will usually take to be finite (usually it will have a single equation!).
We will therefore consider relations over the set of elements of the free magma , and the aim is to find a rewrite system is complete for .
Certainly is closed over substitutions, and be a congruence: if and under , then under as well.
We therefore consider to be both closed under substitutions and a congruence. A convenient way to represent this is via a rewrite system: simply a set of pairs of words (we typically write ) which represents the smallest congruence, closed by substitutions that contains those pairs.
Naturally, a set of laws can be seen, given a choice of orientation (left-to-right or right-to-left) for each law as such a rewrite system. In this case, it is very clear that the reflexive transitive closure recovers the original equational theory . However, it’s clear that sometimes these systems will either be not strongly normalizing, or confluent, or both.
For example, it’s clear that commutativity (the rule cannot possibly be oriented. Here is a non-confluent example:
We have , but also for any (which are both in normal form).
Knuth and Bendix
[
8
]
described a technique by which a theory or set of equations could be turned into a complete system. The crucial idea is the observation that the non-local-confluence of a rewrite system can be reduced to a finite (if the system is finite) set of “worst offenders” for confluence. If these pairs can be joined (reduced to the same term) then the system is confluent. It is possible to compute such pairs.
The high-level idea is therefore to identify such pairs, and add them as an unoriented equation, to be oriented if possible, and repeating until no un-joinable pairs exist. If this procedure succeeds and terminates, the system is successfully completed, and as a result the theory is decidable, via the completed system as described above.
We use the intuitive notions of “position in a word” and “word at a position ”. We denote by the word with inserted at position .
Definition
19.5
Given a rewrite system and two rules and in , we say that is a critical pair for and if there is some non-variable position in such that unifies with the term at that position. We denote by the most general unifier thus obtained and have and
Note that, in the above setting, , giving us a candidate for non-local-confluence. The next lemma states that these candidates are the most general ones.
Theorem
19.6
Given a rewrite system , if for every critical pair of , there is a term such that , then is locally confluent.
Note that building critical pairs of a finite system is computable. Therefore the only step of the completion process which require genuine creativity is the choice of the orientation of the equations, along with the proof that that orientation is strongly normalizing.
As a capper to this section we can note that even in the event that such an orientation is not found, one can still partially apply the completion procedure, using any well-founded order on terms that is stable by substitution and congruence, to obtain a semi-decision procedure for equality. This process is sometimes called unfailing completion and is at the core of the superposition calculus used in Vampire.