content="Data-structures and algorithms in Standard ML. Notes from a lecture course given by Michael Fourman at the University of West Australia, Spring 1994." /> rel="start" type="text/html" href="/mfourman/index.html" title="Michael Fourman" /> More Reasoning

## More Reasoning

October 31, 2006

### 1 Structural Induction

In previous lecture notes we have seen how to carry out inductive proofs on lists and trees. To re-cap, here are the datatype definitions, and the associated inductive proof rules:

 datatype ’a list = nil                   | :: of ’a * ’a list

→∀l φ(l)

 datatype ’a tree = Leaf                   | Node of ’a tree * ’a * ’a tree;

→∀t φ(t)

You should be able to start noticing a pattern here. In both datatypes we can build larger instances of the structure by applying a constructor to smaller instances (using :: and Node). There are also constructors that act as a base case (nil and Leaf). The format of the associated induction rules mirrors the way these structures are built. Let’s examine the datatype bexp, which represents simple Boolean expressions.

 datatype Bexp = V of string                   | /\ of Bexp * Bexp                   | \/ of Bexp * Bexp                   | ~  of Bexp;

This datatype has more constructors than trees or lists, but the basic idea is the same. We have some constructors for building expressions out of existing types (in this case V) and some constructors for building expressions out of smaller expressions (in this case /\, \/ and ~). The format of the associated inductive rule shouldn’t be too surprising:

→∀c φ(c)

You should be able to follow the pattern to produce induction rules for many datatypes of this form. Try to do this for some of the variations of the tree datatype illustrated in earlier notes. This kind of induction is known as structural induction. Most finite datatypes admit this kind of inductive proof technique, although in some cases the form of the inductive rule can be a bit messy. For example, consider a tree datatype where we allow an arbitrary number of children at each node:

 datatype ’a tree = Node of ’a * (’a tree list);

Can you write down the structural induction rule for this type?

The technique does not work on datatypes built from functional values. For example, consider

 datatype funny = F of funny -> funny;

We cannot get a structural induction rule for this datatype, and so we cannot use induction to prove that a property φ holds for all objects of type funny. Dealing with datatypes such as this is outside the scope of the course. However, most datatypes do not make use of such functional values, and so this limitation is not particularly serious.

### 2 Well-founded induction

A binary relation is well-founded if there exist no infinite decreasing chains

The ordering < on the natural numbers is well-founded, but < on the integers isn’t, and neither is < on the rational numbers. The following infinite chains provide the evidence:
Note that we can’t just say that < is well-founded — we have to state the domain of the relation. Another example of a well-founded relation is the lexicographic ordering of pairs of natural numbers, defined by
We can extend this ordering to tuples, quadruples and so forth. If f is a function into the natural numbers, then there is a well-founded relation f defined by
A function f used for this purpose is known as a measure function.

Why all this interest in well-founded relations? Suppose is a well-founded relation over some type α, and φ(x) a property to be proved for all x of type α. The technique of well-founded induction can be used to prove this. The induction rule may be written as

In other words it suffices to prove, for all y, the following induction step:

All of the induction rules we have seen up to this point can be obtained from this rule by suitable choice of the well-founded relation. If is

• < on the natural numbers we get complete induction.
• N, where m Nn just if m + 1 = n then we get (after some simplification) mathematical induction.
• L, where l Nljust if h :: l = lfor some h, then we get structural induction on lists.

A well-founded relation given by a measure function yields induction on the size of an object.

### 3 Well-founded recursion

Let be a well-founded relation over some type α. If f is a function with formal parameter x that makes recursive calls f(y) only if y x, then f(x) terminates for all x. In this case, we say that f is defined by well-founded recursion on . Informally, f(x) terminates because, since there are no infinite decreasing chains in , there can be no infinite recursion.

Proving that a function terminates suggests a useful form of induction for it. If a function is defined by well-founded recursion on , then its properties can often be proved by well-founded induction on .