Algorithm Search⌘K

Proofs: Narrowing

These are the human proofs of Narrowing, at full length.

Narrowing is sound for every system and complete for convergent systems 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 written after the term, so tστt\sigma\tau means (tσ)τ(t\sigma)\tau, rules l→rl \to r with l∉Vl \notin V and Var(r)⊆Var(l)\mathrm{Var}(r) \subseteq \mathrm{Var}(l), and →R∗\to_R^* for the reflexive transitive closure. The goal s≈ts \approx t is kept as the term e0=eq(s,t)e_0 = \mathrm{eq}(s, t) for a binary symbol eq\mathrm{eq} that does not occur in RR. A node is a triple (e,σ,d)(e, \sigma, d) of a goal e=eq(u,v)e = \mathrm{eq}(u, v), a substitution σ\sigma on the variables X=Var(s)∪Var(t)X = \mathrm{Var}(s) \cup \mathrm{Var}(t), and a depth dd. Line L9 renames each rule apart, with variables that occur nowhere else in the run.

The unifiers that line L4 and line L8 compute are fully applied, so they are idempotent: no variable of the domain occurs in the range. An idempotent most general unifier τ\tau of uu and ll has this property: for every unifier γ\gamma of uu and ll, τγ=γ\tau\gamma = \gamma. Indeed, γ=τγ′\gamma = \tau\gamma' for some γ′\gamma', so τγ=ττγ′=τγ′=γ\tau\gamma = \tau\tau\gamma' = \tau\gamma' = \gamma.

Theorem. Let DD be the depth bound.

  1. Termination. The procedure stops.
  2. Soundness. For every system RR and every answer α\alpha, sα→Rk1ws\alpha \to_R^{k_1} w and tα→Rk2wt\alpha \to_R^{k_2} w for a term ww with k1+k2≤Dk_1 + k_2 \le D.
  3. Completeness. Let RR be terminating and confluent, and let θ\theta be a substitution on XX with xθx\theta in normal form for every x∈Xx \in X and sθ↔R∗tθs\theta \leftrightarrow_R^* t\theta. Let nn be the length of an innermost reduction of eq(sθ,tθ)\mathrm{eq}(s\theta, t\theta) to its normal form. If D≥nD \ge n, the procedure returns an answer α\alpha such that xθ=xαηx\theta = x\alpha\eta for all x∈Xx \in X, for one substitution η\eta.

Termination

Each node (e,σ,d)(e, \sigma, d) has at most ∣e∣⋅∣R∣|e| \cdot |R| children, one per position and rule, and children are created only for d<Dd < D. By induction on dd, finitely many nodes of each depth d≤Dd \le D are created, and none of depth more than DD. Each node is removed from the queue once, and each removal does a finite amount of work. ■\blacksquare

Soundness

Lemma 1. For every node (e,σ,d)(e, \sigma, d) in the queue, e0σ→Rdee_0\sigma \to_R^d e.

Proof. Induction on dd. The node of line L1 has e=e0e = e_0, σ\sigma the identity and d=0d = 0. A child is created at line L9 from (e,σ,d)(e, \sigma, d), a position pp with e∣p∉Ve|_p \notin V, a renamed rule l→rl \to r, and τ\tau with e∣pτ=lτe|_p\tau = l\tau. Then eτ∣p=lτe\tau|_p = l\tau is a redex, and eτ→Reτ[rτ]p=(e[r]p)τe\tau \to_R e\tau[r\tau]_p = (e[r]_p)\tau, which is the child goal. By the induction hypothesis e0σ→Rdee_0\sigma \to_R^d e, and rewriting is closed under substitutions, so e0στ→Rdeτ→R(e[r]p)τe_0\sigma\tau \to_R^d e\tau \to_R (e[r]_p)\tau. The child substitution is στ\sigma\tau on XX. ■\blacksquare

Proof of soundness. An answer comes from a node (eq(u,v),σ,d)(\mathrm{eq}(u, v), \sigma, d) with d≤Dd \le D at line L4, where μ\mu unifies uu and vv, and α=σμ\alpha = \sigma\mu on XX. By Lemma 1 and closure under substitutions, eq(sα,tα)=e0σμ→Rdeq(uμ,vμ)\mathrm{eq}(s\alpha, t\alpha) = e_0\sigma\mu \to_R^d \mathrm{eq}(u\mu, v\mu). Since eq\mathrm{eq} does not occur in RR, no step is at the root, so each step rewrites inside one argument. With w=uμ=vμw = u\mu = v\mu, sα→Rk1ws\alpha \to_R^{k_1} w and tα→Rk2wt\alpha \to_R^{k_2} w with k1+k2=d≤Dk_1 + k_2 = d \le D. Line L4 renames the fresh variables of α\alpha bijectively, which keeps this property. ■\blacksquare

Soundness does not use termination or confluence.

Completeness

A substitution η\eta is normalized on a set YY of variables if yηy\eta is a normal form for every y∈Yy \in Y. A subterm of a normal form is a normal form.

Lemma 2 (lifting). Let (e,σ,d)(e, \sigma, d) be a node with d<Dd < D, and let η\eta be a substitution, normalized on Var(e)\mathrm{Var}(e), with xση=xθx\sigma\eta = x\theta for all x∈Xx \in X. Let eη→Re′e\eta \to_R e' be an innermost step. Then line L9 creates a child (e′′,στ,d+1)(e'', \sigma\tau, d + 1) and there is a substitution η′\eta', normalized on Var(e′′)\mathrm{Var}(e''), with xστη′=xθx\sigma\tau\eta' = x\theta for all x∈Xx \in X and e′′η′=e′e''\eta' = e'.

Proof. The step uses a rule l→rl \to r at a position pp of eηe\eta with eη∣p=lρe\eta|_p = l\rho. It is innermost, so every proper subterm of lρl\rho is a normal form; since ll is not a variable, xρx\rho is a proper subterm of lρl\rho for each x∈Var(l)x \in \mathrm{Var}(l), so ρ\rho is normalized on Var(l)\mathrm{Var}(l).

The position pp is a position of ee with e∣p∉Ve|_p \notin V. Otherwise pp is at or below an occurrence of a variable yy of ee, and lρl\rho is a subterm of yηy\eta, which is a normal form, but lρl\rho is a redex. Also pp is not the root, since eq\mathrm{eq} does not occur in RR.

At line L9 the procedure tries the position pp and the rule l→rl \to r, renamed apart. We may assume that l→rl \to r is this renamed copy, with ρ\rho adjusted; its variables occur neither in ee nor in the range of σ\sigma nor in the domain of η\eta. Let γ=η∪ρ\gamma = \eta \cup \rho, which is well defined because the domains are disjoint. Then e∣pγ=e∣pη=lρ=lγe|_p\gamma = e|_p\eta = l\rho = l\gamma, so e∣pe|_p and ll unify, line L8 finds the idempotent most general unifier τ\tau, and line L9 creates the child with e′′=(e[r]p)τe'' = (e[r]_p)\tau and substitution στ\sigma\tau. By the property of idempotent most general unifiers, τγ=γ\tau\gamma = \gamma. Set η′=γ\eta' = \gamma. Then:

  • e′′η′=e[r]pτγ=e[r]pγ=eη[rρ]p=e′e''\eta' = e[r]_p\tau\gamma = e[r]_p\gamma = e\eta[r\rho]_p = e'.
  • For x∈Xx \in X: xστη′=xσγ=xση=xθx\sigma\tau\eta' = x\sigma\gamma = x\sigma\eta = x\theta, because the variables of xσx\sigma are not variables of the rule.
  • Let y∈Var(e′′)y \in \mathrm{Var}(e''). Then yy occurs in zτz\tau for some z∈Var(e[r]p)⊆Var(e)∪Var(l)z \in \mathrm{Var}(e[r]_p) \subseteq \mathrm{Var}(e) \cup \mathrm{Var}(l). So yγy\gamma is a subterm of zτγ=zγz\tau\gamma = z\gamma, which is zηz\eta or zρz\rho, a normal form. So yη′y\eta' is a normal form. ■\blacksquare

Proof of completeness. RR is confluent and sθ↔R∗tθs\theta \leftrightarrow_R^* t\theta, so sθs\theta and tθt\theta have the same normal form ww. Since eq\mathrm{eq} does not occur in RR, the normal form of e0θe_0\theta is eq(w,w)\mathrm{eq}(w, w), and RR is terminating, so an innermost reduction e0θ=f0→Rf1→R⋯→Rfn=eq(w,w)e_0\theta = f_0 \to_R f_1 \to_R \cdots \to_R f_n = \mathrm{eq}(w, w) exists.

We show by induction on i≤ni \le n: there is a node (ei,σi,i)(e_i, \sigma_i, i) that the procedure creates, and a substitution ηi\eta_i normalized on Var(ei)\mathrm{Var}(e_i), with xσiηi=xθx\sigma_i\eta_i = x\theta for x∈Xx \in X and eiηi=fie_i\eta_i = f_i. For i=0i = 0 take the node of line L1 and η0=θ\eta_0 = \theta, which is normalized on Var(e0)=X\mathrm{Var}(e_0) = X. For the step from ii to i+1i + 1, the step fi→Rfi+1f_i \to_R f_{i+1} is an innermost step of eiηie_i\eta_i, and i<n≤Di < n \le D, so Lemma 2 applies.

Every created node is eventually removed at line L3, since the queue is first in, first out and the procedure terminates. When line L4 runs on the node (en,σn,n)(e_n, \sigma_n, n) with en=eq(u,v)e_n = \mathrm{eq}(u, v), ηn\eta_n unifies uu and vv because enηn=eq(w,w)e_n\eta_n = \mathrm{eq}(w, w). So the most general unifier μ\mu exists and μηn=ηn\mu\eta_n = \eta_n. The answer is α=σnμ\alpha = \sigma_n\mu on XX, and for x∈Xx \in X, xαηn=xσnμηn=xσnηn=xθx\alpha\eta_n = x\sigma_n\mu\eta_n = x\sigma_n\eta_n = x\theta. Line L4 renames the fresh variables of α\alpha by a bijection π\pi, which gives the answer απ\alpha\pi with xθ=xαππ−1ηnx\theta = x\alpha\pi\pi^{-1}\eta_n; if the same answer was found before, it is already in the list. Take η=π−1ηn\eta = \pi^{-1}\eta_n. ■\blacksquare

Remarks

Why normalized solutions. The theorem covers only solutions θ\theta whose values are normal forms. For a convergent RR this is no loss: replacing each xθx\theta by its normal form gives a normalized solution that is equal modulo RR. Without the condition the lifting fails: with R={f(a)→b}R = \{ f(a) \to b \}, the goal x≈bx \approx b has the solution x↦f(a)x \mapsto f(a), and the only answer is x↦bx \mapsto b, of which f(a)f(a) is not an instance.

Why the innermost reduction. Lemma 2 needs ρ\rho to be normalized, so that the new η′\eta' is normalized again. An innermost step gives this for free. The depth needed is the length nn of an innermost reduction, so a breadth-first search with D≥nD \ge n finds the answer.

Without termination or confluence. Soundness holds for every system. Completeness fails without confluence: for R={a→b, a→c}R = \{ a \to b,\ a \to c \}, the goal b≈cb \approx c holds modulo RR, but bb and cc are normal forms with no common reduct, and narrowing finds nothing.

Back to Narrowing