Structural induction


Structural induction is a proof method that is used in mathematical logic, computer science, graph theory, and some other mathematical fields. It is a generalization of mathematical induction over natural numbers and can be further generalized to arbitrary Noetherian induction. Structural recursion is a recursion method bearing the same relationship to structural induction as ordinary recursion bears to ordinary mathematical induction.
Structural induction is used to prove that some proposition P holds for all x of some sort of recursively defined structure, such as
formulas, lists, or trees. A well-founded partial order is defined on the structures. The structural induction proof is a proof that the proposition holds for all the minimal structures and that if it holds for the immediate substructures of a certain structure S, then it must hold for S also.
A structurally recursive function uses the same idea to define a recursive function: "base cases" handle each minimal structure and a rule for recursion. Structural recursion is usually proved correct by structural induction; in particularly easy cases, the inductive step is often left out. The length and ++ functions in the example below are structurally recursive.
For example, if the structures are lists, one usually introduces the partial order "<", in which L < M whenever list L is the tail of list M. Under this ordering, the empty list is the unique minimal element. A structural induction proof of some proposition then consists of two parts: A proof that P is true and a proof that if P is true for some list L, and if L is the tail of list M, then P must also be true.
Eventually, there may exist more than one base case and/or more than one inductive case, depending on how the function or structure was constructed. In those cases, a structural induction proof of some proposition then consists of:

Examples

An ancestor tree is a commonly known data structure, showing the parents, grandparents, etc. of a person as far as known. It is recursively defined:
As an example, the property "An ancestor tree extending over g generations shows at most persons" can be proven by structural induction as follows:
Hence, by structural induction, each ancestor tree satisfies the property.
As another, more formal example, consider the following property of lists:
length = length L + length M
Here ++ denotes the list concatenation operation, and L and M are lists.
In order to prove this, we need definitions for length and for the concatenation operation. Let denote a list whose head is h and whose tail is t, and let denote the empty list. The definitions for length and the concatenation operation are:
length = 0
length = 1 + length t
++ list = list
++ list = h :
Our proposition is that EQ is true for all lists M when L is. We want to show that is true for all lists. We will prove this by structural induction on lists.
First we will prove that P is true; that is, EQ is true for all lists M when L happens to be the empty list . Consider EQ:
length = length
= length M
= 0 + length M
= length + length M
= length L + length M
So this part of the theorem is proved; EQ is true for all M, when L is , because the left-hand side and the right-hand side are equal.
Next, consider any nonempty list. Since is nonempty, it has a head item, x, and a tail list, xs, so we can express it as. The induction hypothesis is that EQ is true for all values of M when L is xs:
length = length xs + length M
We would like to show that if this is the case, then EQ is also true for all values of M when =. We proceed as before:
length L + length M = length + length M
= 1 + length xs + length M
= 1 + length
= length
= length
= length
Thus, from structural induction, we obtain that P is true for all lists L.

Well-ordering

Just as standard mathematical induction is equivalent to the well-ordering principle, structural induction is also equivalent to a well-ordering principle. If the set of all structures of a certain kind admits a well-founded partial order, then every nonempty subset must have a minimal element. The significance of the lemma in this context is that it allows us to deduce that if there are any counterexamples to the theorem we want to prove, then there must be a minimal counterexample. If we can show the existence of the minimal counterexample implies an even smaller counterexample, we have a contradiction and so the set of counterexamples must be empty.
As an example of this type of argument, consider the set of all binary trees. We will show that the number of leaves in a full binary tree is one more than the number of interior nodes. Suppose there is a counterexample; then there must exist one with the minimal possible number of interior nodes. This counterexample, C, has n interior nodes and leaves, where. Moreover, C must be nontrivial, because the trivial tree has and and is therefore not a counterexample. C therefore has at least one leaf whose parent node is an interior node. Delete this leaf and its parent from the tree, promoting the leaf's sibling node to the position formerly occupied by its parent. This reduces both n and by 1, so the new tree also has and is therefore a smaller counterexample. But by hypothesis, C was already the smallest counterexample; therefore, the supposition that there were any counterexamples to begin with must have been false. The partial ordering implied by 'smaller' here is the one that says that S < T whenever S has fewer nodes than T.