Algorithm Search⌘K

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 Σ\Sigma, variables VV, terms T(Σ,V)T(\Sigma, V), positions as sequences of positive integers, t∣pt|_p and t[s]pt[s]_p, substitutions σ\sigma, rules l→rl \to r, and →∗\to^* for the reflexive transitive closure. For a set EE of equations, ↔E\leftrightarrow_E is one replacement step with an equation of EE in either direction, and ↔E∗\leftrightarrow_E^* its reflexive transitive closure. We treat a set RR of rules as a set of equations when we write ↔E∪R∗\leftrightarrow_{E \cup R}^*. E0E_0 is the input set, BB the step bound and >> the order.

Assumption. >> is a reduction order: a strict order on T(Σ,V)T(\Sigma, V) that is well-founded and closed under contexts (s>ts > t implies u[s]p>u[t]pu[s]_p > u[t]_p) and under substitutions (s>ts > t implies sσ>tσs\sigma > t\sigma). The lexicographic path ordering and the Knuth-Bendix ordering are reduction orders.

Theorem. The procedure stops after at most BB executions of line L5. If it returns SUCCESS(R)\mathrm{SUCCESS}(R), then RR is terminating and confluent, and ↔R∗=↔E0∗\leftrightarrow_R^* = \leftrightarrow_{E_0}^*. If it returns FAIL(s≈t)\mathrm{FAIL}(s \approx t), then s≠ts \ne t, s↔E0∗ts \leftrightarrow_{E_0}^* t, and neither s>ts > t nor t>st > s. If it returns GIVE-UP(R)\mathrm{GIVE\text{-}UP}(R), then RR is terminating and ↔R∗⊆↔E0∗\leftrightarrow_R^* \subseteq \leftrightarrow_{E_0}^*.

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 g→dg \to d in RR satisfies g>dg > d.
  • (I2) ↔E∪R∗=↔E0∗\leftrightarrow_{E \cup R}^* = \leftrightarrow_{E_0}^*.

After line L1, R=∅R = \emptyset and E=E0E = E_0, so both hold. We check that each line keeps them. Write E,RE, R for the sets before the line and E′,R′E', R' for the sets after it.

Two facts about conversions. (F1) If E∪RE \cup R and E′∪R′E' \cup R' are such that each equation of one set is a consequence u↔∗vu \leftrightarrow^* v of the other set, then the two conversions are equal: a step with u≈vu \approx v inside a context w[⋅]pw[\cdot]_p under a substitution σ\sigma is replaced by the conversion u↔∗vu \leftrightarrow^* v in the same context and under the same substitution, and conversions are closed under contexts and substitutions. (F2) If u→R∗u′u \to_R^* u', then u↔R∗u′u \leftrightarrow_R^* u'.

Line L3. It adds to EE critical pairs ⟨u,v⟩\langle u, v \rangle of RR. Each of them comes from a term l1σl_1\sigma with l1σ→Rul_1\sigma \to_R u and l1σ→Rvl_1\sigma \to_R v, so u↔R∗vu \leftrightarrow_R^* v, and (I2) holds by (F1). RR does not change.

Line L5. It replaces s≈ts \approx t by s↓≈t↓s{\downarrow} \approx t{\downarrow}, where s↓s{\downarrow} and t↓t{\downarrow} are normal forms reached with RR. The new equation is a consequence of {s≈t}∪R\{s \approx t\} \cup R by s↓↔R∗s↔t↔R∗t↓s{\downarrow} \leftrightarrow_R^* s \leftrightarrow t \leftrightarrow_R^* t{\downarrow}, and the old one is a consequence of {s↓≈t↓}∪R\{s{\downarrow} \approx t{\downarrow}\} \cup R in the same way. By (F1), (I2) holds. The normal forms exist because RR terminates, which follows from (I1): a rewrite step w[gσ]p→w[dσ]pw[g\sigma]_p \to w[d\sigma]_p goes down in >> by the closure properties, and >> is well-founded.

Line L6. It removes an equation s≈ss \approx s, which is a consequence of the empty set.

Line L7. It moves s≈ts \approx t from EE to RR as s→ts \to t or t→st \to s, chosen so that the left side is the greater one. The set E∪RE \cup R 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 g→dg \to d from RR to EE as g≈dg \approx d. Again E∪RE \cup R does not change as a set of equations, and (I1) holds for the remaining rules.

Line L9. It replaces a rule g→dg \to d by g→d′g \to d', where d→S∗d′d \to_{S}^* d' for the set S=(R∖{g→d})∪{ρ}S = (R \setminus \{g \to d\}) \cup \{\rho\}. All rules of SS satisfy (I1), by the previous lines and because earlier executions of this line keep (I1), as we now show. Each rewrite step with SS goes down in >>, so d>d′d > d' or d=d′d = d'; with g>dg > d and transitivity, g>d′g > d'. For (I2): g≈d′g \approx d' is a consequence of {g≈d}∪S\{g \approx d\} \cup S, by g↔d→S∗d′g \leftrightarrow d \to_S^* d', and g≈dg \approx d is a consequence of {g≈d′}∪S\{g \approx d'\} \cup S, by g↔d′←S∗dg \leftrightarrow d' \leftarrow_S^* d. The rules of SS stay in the system, so (F1) applies.

Line L10. It adds ρ\rho to RR, which it already contains as an equation after line L7, and adds critical pairs to EE, which are consequences of RR 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 RR a proper rewrite rule. Let g>dg > d.

  • gg is not a variable. Suppose g=xg = x. If xx occurs in dd, then d=C[x]d = C[x] for a context CC that is not empty, because x≠dx \ne d by irreflexivity. With σ={x↦d}\sigma = \{x \mapsto d\} and closure under substitutions and contexts we get x>C[x]>C[C[x]]>⋯x > C[x] > C[C[x]] > \cdots, an infinite descending chain, which contradicts well-foundedness. If xx does not occur in dd, then with σ={x↦d}\sigma = \{x \mapsto d\} we get d=xσ>dσ=dd = x\sigma > d\sigma = d, which contradicts irreflexivity.
  • Var(d)⊆Var(g)\mathrm{Var}(d) \subseteq \mathrm{Var}(g). Suppose yy occurs in dd but not in gg. Then d=C[y]d = C[y] for a context CC. With σ={y↦g}\sigma = \{y \mapsto g\} we get g=gσ>dσ=Cσ[g]g = g\sigma > d\sigma = C\sigma[g], where CσC\sigma is CC with σ\sigma applied. If CC is empty this is g>gg > g; otherwise closure under contexts gives g>Cσ[g]>Cσ[Cσ[g]]>⋯g > C\sigma[g] > C\sigma[C\sigma[g]] > \cdots. Both contradict the assumptions on >>.

Termination of the procedure

Line L4 counts the iterations that reach it, and returns when the count exceeds BB. 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 RR, and lines L8 to L10 loop over the finite set RR, 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 SUCCESS(R)\mathrm{SUCCESS}(R) only at line L3, when EE is empty and every critical pair ⟨u,v⟩\langle u, v \rangle of RR satisfies u↓R=v↓Ru{\downarrow}_R = v{\downarrow}_R, with the normal forms computed by line L3. So every critical pair of RR is joinable. By the critical pair lemma, RR is locally confluent. By (I1), RR is terminating, as shown for line L5. By Newman's lemma, RR is confluent. By (I2) with E=∅E = \emptyset, ↔R∗=↔E0∗\leftrightarrow_R^* = \leftrightarrow_{E_0}^*.

Fail. The procedure returns FAIL(s≈t)\mathrm{FAIL}(s \approx t) only at line L7, after line L6 found s≠ts \ne t, and when neither s>ts > t nor t>st > s. The equation s≈ts \approx t was in EE, so s↔E∪R∗ts \leftrightarrow_{E \cup R}^* t, and by (I2), s↔E0∗ts \leftrightarrow_{E_0}^* t.

Give up. The procedure returns GIVE-UP(R)\mathrm{GIVE\text{-}UP}(R) only at line L4. By (I1), RR is terminating, and by (I2), every rule of RR is a consequence of E0E_0, so ↔R∗⊆↔E0∗\leftrightarrow_R^* \subseteq \leftrightarrow_{E_0}^*. ■\blacksquare

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 RR. Line L3 recomputes all critical pairs of the final RR, 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, E0⊨s≈tE_0 \models s \approx t iff s↔E0∗ts \leftrightarrow_{E_0}^* t iff s↓R=t↓Rs{\downarrow}_R = t{\downarrow}_R; the last equivalence holds because RR is confluent and terminating. So the result decides the word problem of E0E_0.

What the theorem does not say. It does not say that a convergent system for E0E_0 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 BB only cuts off runs that do not stop by themselves.

Back to Knuth-Bendix completion