Proofs: Innermost reduction
These are the human proofs of Innermost reduction, at full length.
The stack machine performs exactly the leftmost-innermost reduction 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 , each with and . For a term whose arguments are all normal forms, the root rule of is the first in the list with a match , , if there is one.
Leftmost-innermost reduction. A redex of is a position such that is an instance of some left side. It is innermost if no position strictly below is a redex. Two different innermost redexes are not prefixes of each other, so they are ordered from left to right by the lexicographic order of positions. The leftmost-innermost step contracts the leftmost innermost redex with the first rule of the list that matches there. Write for the sequence of leftmost-innermost steps from ; it is finite and ends in a normal form, or it is infinite.
Lemma 1 (decomposition). Let . Then is the concatenation of: placed at position ; if it ends in , then placed at position ; and so on; and, if all of them end, with : nothing if is a normal form, otherwise the root step by the root rule of followed by .
Proof. Let be least such that is not a normal form. Every redex of is either the root or below some position . The root is not innermost, since has a redex. A redex with lies to the right of every redex , and has an innermost redex , which is innermost in too, because the positions below in are those below in . Redexes below do not exist. So the leftmost-innermost redex of is followed by the leftmost-innermost redex of , with the same rule, and the step changes only the argument . Repeating this, is reduced inside exactly as reduces , as long as that sequence goes on. If it ends, we continue with the next argument that is not a normal form. When all arguments are normal forms, the only possible redex is the root, which is then innermost; the step uses the root rule.
Lemma 2 (substituted values are normal). If all arguments of are normal forms and with , then is a normal form for each .
Proof. occurs in at some position , since is not a variable. Then is a subterm of an argument of , and a subterm of a normal form is a normal form.
The machine. A task asks for the normal form of , where every value of is a normal form (for the input term, is empty; a variable of the input is a normal form, because no left side is a variable). The position is where sits in the whole term, and is used only for the trace.
Lemma 3 (one task). Suppose the machine pops with task stack below it and value stack . Then, before the task stack returns to , the machine makes exactly the steps of , each at followed by the position of the step in , and with the same rule. If is finite and ends in , the machine reaches the state with task stack and value stack . If it is infinite, the task stack never returns to . (With a bound , the machine stops at line L9 when it is about to make its -st step; up to that moment the same statement holds for the steps made.)
Proof. We show, for each , that the first steps the machine makes during the task (if it makes that many) are the first steps of , and that the finite-case conclusion holds whenever has fewer than steps. This is by induction on , and inside it by induction on the size of .
If is a variable, line L4 pushes , which is a normal form, and makes no step: is empty, and the claim holds.
If , line L5 pushes and the tasks with on top. The machine pops first. Since is smaller than , the inner induction hypothesis applies: the machine makes the steps of at , and if they end in , it pushes and goes on with , and so on. If one of these sequences is infinite, the machine never pops the task, and by Lemma 1 is that same infinite sequence after the finite ones before it. Otherwise the machine pops with on top of in this order; line L6 takes them off and forms . Line L7 finds the root rule of . If there is none, is a normal form, line L8 pushes it, and by Lemma 1 the steps made are exactly , which ends in . If there is one, with match , line L10 makes the root step at , which is the next step of by Lemma 1, and pushes . By Lemma 2 the values of are normal forms, so this task has the required form. The machine has already made at least one step during the task, so fewer than steps remain to be compared, and the outer induction hypothesis (for a smaller , with arbitrary) applies to the new task: its steps are those of at , and if they end in , it pushes and the task stack is again. By Lemma 1 this is the rest of .
The bound only stops the machine before a step, so it does not change the steps made before it.
Theorem. On input , and no bound, the algorithm returns exactly when is finite with steps and ends in the normal form , and the recorded trace is . If is infinite, the algorithm does not stop. With a bound , it returns when has steps, and it returns after exactly steps otherwise.
Proof. Line L1 starts with the single task , and empty. Apply Lemma 3. In the finite case the task stack becomes empty with , the loop of line L2 ends, and line L11 returns and the step count, which line L10 increased once per step. In the infinite case the task stack never empties. With a bound , line L9 returns exactly when a -st step is about to be made, that is, when has more than steps. The returned is a normal form of because each step is a step of , and the end of has no redex.