Theorem : any well-formed stack expression s
stack
is equivalent to one of the forms
Base Case : From our stated theorem, the base case s = init, corresponding to an expression of length 1, is true. (For this example, init is the only nullary constructor).
Hypothesis : Suppose that any given stack
expression s of
length n is equivalent to
or init
where
is itself a reduced expression (of length (n - 1)).
What we must
do now is show that the above theorem also holds for all
stack expressions obtained from s of length (n+1), that is for the terms
push(s,
) and pop(s), (
).
Inductive Step : Given that s
stack
(of length n) is a reduced expression.
= push(push
and
since
is immediately
of the form (b).
is a also a reduced expression.
(Remember pop is only defined for non-empty stack values).
Continuing the inductive proof, since all stack expressions of length 2 are
reduced expressions, so are all stack expressions of length 3 derived from
applying legal constructor operations to
.
Hence the two terms
and
are also reduced expressions. Starting from these
reduced expressions, any stack expression of length 4 derived from the
terms of length 3 by applying the constructors push and pop
will also be reduced expressions and so the inductive proof goes on.
To prove that the set of reduced expressions is a canonical set of terms, we must now show that every well-formed stack expression s is equivalent to one and only one of these reduced terms. We have already shown that every well-formed expression s is equivalent to a reduced expression. Furthermore, it cannot be shown using the axioms of Stack, that any one member of the set of reduced expressions is equivalent to another. The only way such a result could be derived was if an axiom were included which related two of the reduced expressions directly, that is an axiom whose outermost left-most operation were an atomic constructor - which is not the case here. Hence each member of the set of reduced expressions is in a different equivalence class.
We have therefore proved that every term is equivalent to a reduced term and that each reduced term is in a different equivalence class. Hence, by definition, the collection of reduced terms constitutes a set of canonical forms.