Algorithm Search⌘K

Proofs: Outermost (leftmost-outermost) reduction

These are the human proofs of Outermost (leftmost-outermost) reduction, at full length.

The preorder search finds the leftmost-outermost redex full

This proof shows: correctness.

We use the pseudocode of the page and the notation of the term rewriting pages. RR is a list of rules l1→r1,…,lm→rml_1 \to r_1, \ldots, l_m \to r_m with lj∉Vl_j \notin V and Var(rj)⊆Var(lj)\mathrm{Var}(r_j) \subseteq \mathrm{Var}(l_j). A position pp of tt is a redex if t∣p=ljτt|_p = l_j\tau for some jj and τ\tau; it is outermost if no proper prefix of pp is a redex. Two distinct outermost redexes are not prefixes of each other, so they are ordered from left to right by the lexicographic order <lex<_{\mathrm{lex}} of positions. The leftmost-outermost step contracts the least outermost redex in this order, with the first rule of the list that matches there.

Preorder. The preorder of the positions of tt is defined by: pp comes before qq iff pp is a proper prefix of qq, or p=u i vp = u\,i\,v and q=u j wq = u\,j\,w with i<ji < j. This is the lexicographic order on positions with a prefix coming first, and it is a strict total order on Pos(t)\mathrm{Pos}(t).

Lemma 1 (the search visits positions in preorder). Line L3 pops the positions of tt in preorder, and checks the rules at each of them, until it finds a redex.

Proof. The search keeps a stack of positions, starting with ε\varepsilon. When it pops pp and finds no rule, it pushes p n,…,p 1p\,n, \ldots, p\,1, so p 1p\,1 is on top. We show by induction on the size of t∣pt|_p that, from the moment pp is on top of the stack, the search pops exactly the positions of the subtree at pp, in preorder, before it pops any position that was below pp on the stack (unless it stops at a redex). For a leaf this is immediate. Otherwise it pops pp, pushes the children with p 1p\,1 on top, and by induction finishes the subtree of p 1p\,1 in preorder before p 2p\,2 comes to the top, and so on. The concatenation pp, subtree of p 1p\,1, ..., subtree of p np\,n is the preorder of the subtree at pp. Applied to ε\varepsilon, the search visits all of Pos(t)\mathrm{Pos}(t) in preorder. □\square

Lemma 2 (the first redex in preorder is the leftmost-outermost redex). If tt has a redex, the least redex pp in preorder is outermost, and it is <lex<_{\mathrm{lex}}-least among the outermost redexes.

Proof. Each proper prefix of pp comes before pp in preorder, so it is not a redex, by the choice of pp. Hence pp is outermost. Let q≠pq \ne p be another outermost redex. Neither is a prefix of the other. Since pp comes before qq in preorder and is not a prefix of qq, the two positions first differ at some index where pp has the smaller number, so p<lexqp <_{\mathrm{lex}} q. □\square

Lemma 3 (one step). If line L3 returns the path to pp, the rule index jj and v=rjτv = r_j\tau, then after line L6 the current term is t[rjτ]pt[r_j\tau]_p, the result of the leftmost-outermost step.

Proof. By Lemmas 1 and 2, pp is the leftmost-outermost redex, and the search tries the rules at pp in list order, so jj is the first rule that matches t∣pt|_p, with the match τ\tau; matching returns the unique τ\tau on Var(lj)\mathrm{Var}(l_j) with ljτ=t∣pl_j\tau = t|_p, and the substitution function builds rjτr_j\tau. The path lists the pairs (t∣p′,i)(t|_{p'}, i) for each proper prefix p′p' with p′ ip'\,i a prefix of pp, from the root down. Line L6 goes up the path and replaces argument ii of t∣p′t|_{p'} by the current value. By induction on the number of pairs processed, after processing the pair of p′p' the value is t∣p′[rjτ]qt|_{p'}[r_j\tau]_{q}, where p=p′ qp = p'\,q. After the root pair it is t[rjτ]pt[r_j\tau]_p. □\square

Theorem. On input tt and RR, the algorithm makes exactly the leftmost-outermost steps from tt, in order. If this sequence is finite with kk steps, it returns its last term, which is a normal form, together with kk. If it is infinite, the algorithm does not stop. With a bound BB, it returns ⊥\bot exactly when the sequence has more than BB steps.

Proof. By induction on the number of iterations of the loop of line L2, using Lemma 3: after ii iterations that did not return, the current term is the ii-th term of the leftmost-outermost sequence and the counter is ii. In an iteration, if line L3 finds no redex, Lemma 1 says that every position was checked, so the current term is a normal form and line L4 returns it. Otherwise, with a bound, line L5 returns ⊥\bot when i=Bi = B, that is, when a (B+1)(B+1)-st step is about to be made. Every step is a step of →R\to_R, so the returned term vv satisfies t→R∗vt \to_R^* v. ■\blacksquare

Remark. The theorem says nothing about whether the sequence is finite. That depends on the system. For left-normal orthogonal systems, the leftmost-outermost sequence is finite whenever tt has a normal form (O'Donnell 1977); the page states this result and gives a counterexample without left-normality.

Back to Outermost (leftmost-outermost) reduction