Proofs: Knuth-Bendix completion
These are the human proofs of Knuth-Bendix completion, at full length.
Completion is sound, and a success result is a convergent system for the input equations full
This proof shows: correctness.
We use the pseudocode of the page and the notation of the term rewriting pages: a signature , variables , terms , positions as sequences of positive integers, and , substitutions , rules , and for the reflexive transitive closure. For a set of equations, is one replacement step with an equation of in either direction, and its reflexive transitive closure. We treat a set of rules as a set of equations when we write . is the input set, the step bound and the order.
Assumption. is a reduction order: a strict order on that is well-founded and closed under contexts ( implies ) and under substitutions ( implies ). The lexicographic path ordering and the Knuth-Bendix ordering are reduction orders.
Theorem. The procedure stops after at most executions of line L5. If it returns , then is terminating and confluent, and . If it returns , then , , and neither nor . If it returns , then is terminating and .
Invariants
We show that the following two statements hold each time line L2 starts an iteration, and also when the procedure returns.
- (I1) Every rule in satisfies .
- (I2) .
After line L1, and , so both hold. We check that each line keeps them. Write for the sets before the line and for the sets after it.
Two facts about conversions. (F1) If and are such that each equation of one set is a consequence of the other set, then the two conversions are equal: a step with inside a context under a substitution is replaced by the conversion in the same context and under the same substitution, and conversions are closed under contexts and substitutions. (F2) If , then .
Line L3. It adds to critical pairs of . Each of them comes from a term with and , so , and (I2) holds by (F1). does not change.
Line L5. It replaces by , where and are normal forms reached with . The new equation is a consequence of by , and the old one is a consequence of in the same way. By (F1), (I2) holds. The normal forms exist because terminates, which follows from (I1): a rewrite step goes down in by the closure properties, and is well-founded.
Line L6. It removes an equation , which is a consequence of the empty set.
Line L7. It moves from to as or , chosen so that the left side is the greater one. The set is the same as a set of equations, so (I2) holds, and the new rule satisfies (I1). If neither side is greater, the procedure returns; we treat this case below.
Line L8. It moves rules from to as . Again does not change as a set of equations, and (I1) holds for the remaining rules.
Line L9. It replaces a rule by , where for the set . All rules of satisfy (I1), by the previous lines and because earlier executions of this line keep (I1), as we now show. Each rewrite step with goes down in , so or ; with and transitivity, . For (I2): is a consequence of , by , and is a consequence of , by . The rules of stay in the system, so (F1) applies.
Line L10. It adds to , which it already contains as an equation after line L7, and adds critical pairs to , which are consequences of as for line L3.
Line L4 changes neither set. So (I1) and (I2) hold at every iteration and at each return.
A rule never has a variable left side or a new variable on the right
These two facts follow from (I1) alone, and they make every rule of a proper rewrite rule. Let .
- is not a variable. Suppose . If occurs in , then for a context that is not empty, because by irreflexivity. With and closure under substitutions and contexts we get , an infinite descending chain, which contradicts well-foundedness. If does not occur in , then with we get , which contradicts irreflexivity.
- . Suppose occurs in but not in . Then for a context . With we get , where is with applied. If is empty this is ; otherwise closure under contexts gives . Both contradict the assumptions on .
Termination of the procedure
Line L4 counts the iterations that reach it, and returns when the count exceeds . Each iteration that does not reach line L4 returns at line L3. Each other line runs a finite number of times per iteration: line L5 normalizes with a terminating , and lines L8 to L10 loop over the finite set , whose critical pairs are finite in number because each left side has finitely many positions and a most general unifier is unique up to renaming. So the procedure stops.
The three results
Success. The procedure returns only at line L3, when is empty and every critical pair of satisfies , with the normal forms computed by line L3. So every critical pair of is joinable. By the critical pair lemma, is locally confluent. By (I1), is terminating, as shown for line L5. By Newman's lemma, is confluent. By (I2) with , .
Fail. The procedure returns only at line L7, after line L6 found , and when neither nor . The equation was in , so , and by (I2), .
Give up. The procedure returns only at line L4. By (I1), is terminating, and by (I2), every rule of is a consequence of , so .
Remarks
Why line L3 checks all critical pairs. Line L10 adds the critical pairs of each new rule, and line L5 later deletes those that become joinable. But line L8 may remove a rule after its critical pairs were computed, and line L9 may change a right side, so a critical pair that was joinable earlier is not obviously joinable for the final . Line L3 recomputes all critical pairs of the final , so the success case needs no argument about the history of the run. A run that never needs line L3 to add a pair pays only the cost of the check.
Consequence for the word problem. On success, by the Birkhoff completeness theorem, iff iff ; the last equivalence holds because is confluent and terminating. So the result decides the word problem of .
What the theorem does not say. It does not say that a convergent system for does not exist when the procedure fails or gives up. A different order, or a different choice of equation at line L5, may succeed. The bound only cuts off runs that do not stop by themselves.