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. is a list of rules with and . A position of is a redex if for some and ; it is outermost if no proper prefix of 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 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 is defined by: comes before iff is a proper prefix of , or and with . This is the lexicographic order on positions with a prefix coming first, and it is a strict total order on .
Lemma 1 (the search visits positions in preorder). Line L3 pops the positions of 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 . When it pops and finds no rule, it pushes , so is on top. We show by induction on the size of that, from the moment is on top of the stack, the search pops exactly the positions of the subtree at , in preorder, before it pops any position that was below on the stack (unless it stops at a redex). For a leaf this is immediate. Otherwise it pops , pushes the children with on top, and by induction finishes the subtree of in preorder before comes to the top, and so on. The concatenation , subtree of , ..., subtree of is the preorder of the subtree at . Applied to , the search visits all of in preorder.
Lemma 2 (the first redex in preorder is the leftmost-outermost redex). If has a redex, the least redex in preorder is outermost, and it is -least among the outermost redexes.
Proof. Each proper prefix of comes before in preorder, so it is not a redex, by the choice of . Hence is outermost. Let be another outermost redex. Neither is a prefix of the other. Since comes before in preorder and is not a prefix of , the two positions first differ at some index where has the smaller number, so .
Lemma 3 (one step). If line L3 returns the path to , the rule index and , then after line L6 the current term is , the result of the leftmost-outermost step.
Proof. By Lemmas 1 and 2, is the leftmost-outermost redex, and the search tries the rules at in list order, so is the first rule that matches , with the match ; matching returns the unique on with , and the substitution function builds . The path lists the pairs for each proper prefix with a prefix of , from the root down. Line L6 goes up the path and replaces argument of by the current value. By induction on the number of pairs processed, after processing the pair of the value is , where . After the root pair it is .
Theorem. On input and , the algorithm makes exactly the leftmost-outermost steps from , in order. If this sequence is finite with steps, it returns its last term, which is a normal form, together with . If it is infinite, the algorithm does not stop. With a bound , it returns exactly when the sequence has more than steps.
Proof. By induction on the number of iterations of the loop of line L2, using Lemma 3: after iterations that did not return, the current term is the -th term of the leftmost-outermost sequence and the counter is . 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 when , that is, when a -st step is about to be made. Every step is a step of , so the returned term satisfies .
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 has a normal form (O'Donnell 1977); the page states this result and gives a counterexample without left-normality.