Methods

Induction

Reading preferences

Optional display controls need JavaScript. All reading content and navigation work without it.

Source file content/methods/induction/induction.tex

Source file content/methods/induction/introduction.tex

Introduction

Induction is an important proof technique which is used, in different forms, in almost all areas of logic, theoretical computer science, and mathematics. It is needed to prove many of the results in logic.

Induction is often contrasted with deduction, and characterized as the inference from the particular to the general. For instance, if we observe many green emeralds, and nothing that we would call an emerald that's not green, we might conclude that all emeralds are green. This is an inductive inference, in that it proceeds from many particular cases (this emerald is green, that emerald is green, etc.) to a general claim (all emeralds are green). Mathematical induction is also an inference that concludes a general claim, but it is of a very different kind than this “simple induction.”

Very roughly, an inductive proof in mathematics concludes that all mathematical objects of a certain sort have a certain property. In the simplest case, the mathematical objects an inductive proof is concerned with are natural numbers. In that case an inductive proof is used to establish that all natural numbers have some property, and it does this by showing that

  1. 00source has the property, and

  2. whenever a number kksource has the property, so does k+1k+1source.

Induction on natural numbers can then also often be used to prove general claims about mathematical objects that can be assigned numbers. For instance, finite sets each have a finite number nnsource of elements, and if we can use induction to show that every number nnsource has the property “all finite sets of size nnsource are dots” then we will have shown something about all finite sets.

Induction can also be generalized to mathematical objects that are inductively defined. For instance, expressions of a formal language such as those of first-order logic are defined inductively. Structural induction is a way to prove results about all such expressions. Structural induction, in particular, is very useful---and widely used---in logic.

Source file content/methods/induction/induction-on-N.tex

Induction on \Natsource

In its simplest form, induction is a technique used to prove results for all natural numbers. It uses the fact that by starting from 00source and repeatedly adding 11source we eventually reach every natural number. So to prove that something is true for every number, we can (1) establish that it is true for 00source and (2) show that whenever it is true for a number nnsource, it is also true for the next number n+1n+1source. If we abbreviate “number nnsource has property PPsource” by P(n)P(n)source (and “number kksource has property PPsource” by P(k)P(k)source, etc.), then a proof by induction that P(n)P(n)source for all nn \in \Natsource consists of:

  1. a proof of P(0)P(0)source, and

  2. a proof that, for any kksource, if P(k)P(k)source then P(k+1)P(k+1)source.

To make this crystal clear, suppose we have both (1) and (2). Then (1) tells us that P(0)P(0)source is true. If we also have (2), we know in particular that if P(0)P(0)source then P(0+1)P(0+1)source, i.e., P(1)P(1)source. This follows from the general statement “for any kksource, if P(k)P(k)source then P(k+1)P(k+1)source” by putting 00source for kksource. So by modus ponens, we have that P(1)P(1)source. From (2) again, now taking 11source for nnsource, we have: if P(1)P(1)source then P(2)P(2)source. Since we've just established P(1)P(1)source, by modus ponens, we have P(2)P(2)source. And so on. For any number nnsource, after doing this nnsource times, we eventually arrive at P(n)P(n)source. So (1) and (2) together establish P(n)P(n)source for any nn \in \Natsource.

Let's look at an example. Suppose we want to find out how many different sums we can throw with nnsource dice. Although it might seem silly, let's start with 00source dice. If you have no dice there's only one possible sum you can “throw”: no dots at all, which sums to 00source. So the number of different possible throws is 11source. If you have only one die, i.e., n=1n=1source, there are six possible values, 11source through 66source. With two dice, we can throw any sum from 22source through 1212source, that's 1111source possibilities. With three dice, we can throw any number from 33source to 1818source, i.e., 1616source different possibilities. 11source, 66source, 1111source, 1616source: looks like a pattern: maybe the answer is 5n+15n+1source? Of course, 5n+15n+1source is the maximum possible, because there are only 5n+15n+1source numbers between nnsource, the lowest value you can throw with nnsource dice (all 11source's) and 6n6nsource, the highest you can throw (all 66source's).

The range of totals obtainable with n dice

With nnsource dice one can throw all 5n+15n+1source possible values between nnsource and 6n6nsource.

Proof

Let P(n)P(n)source be the claim: “It is possible to throw any number between nnsource and 6n6nsource using nnsource dice.” To use induction, we prove:

  1. The induction basis P(1)P(1)source, i.e., with just one die, you can throw any number between 11source and 66source.

  2. The induction step, for all kksource, if P(k)P(k)source then P(k+1)P(k+1)source.

(1) Is proved by inspecting a 66source-sided die. It has all 6 sides, and every number between 11source and 66source shows up one on of the sides. So it is possible to throw any number between 11source and 66source using a single die.

To prove (2), we assume the antecedent of the conditional, i.e., P(k)P(k)source. This assumption is called the inductive hypothesis. We use it to prove P(k+1)P(k+1)source. The hard part is to find a way of thinking about the possible values of a throw of k+1k+1source dice in terms of the possible values of throws of kksource dice plus of throws of the extra k+1k+1source-st die---this is what we have to do, though, if we want to use the inductive hypothesis.

The inductive hypothesis says we can get any number between kksource and 6k6ksource using kksource dice. If we throw a 11source with our (k+1)(k+1)source-st die, this adds 11source to the total. So we can throw any value between k+1k+1source and 6k+16k+1source by throwing kksource dice and then rolling a 11source with the (k+1)(k+1)source-st die. What's left? The values 6k+26k+2source through 6k+66k+6source. We can get these by rolling kksource 66sources and then a number between 22source and 66source with our (k+1)(k+1)source-st die. Together, this means that with k+1k+1source dice we can throw any of the numbers between k+1k+1source and 6(k+1)6(k+1)source, i.e., we've proved P(k+1)P(k+1)source using the assumption P(k)P(k)source, the inductive hypothesis.

Very often we use induction when we want to prove something about a series of objects (numbers, sets, etc.) that is itself defined “inductively,” i.e., by defining the (n+1)(n+1)source-st object in terms of the nnsource-th. For instance, we can define the sum sns_nsource of the natural numbers up to nnsource by

s0=0sn+1=sn+(n+1)s_0 & = 0\\ s_{n+1} & = s_n + (n+1)source

This definition gives:

s0=0,s1=s0+1=1,s2=s1+2=1+2=3s3=s2+3=1+2+3=6, etc.s_0 & = 0,\\ s_1 & = s_0 + 1 && = 1,\\ s_2 & = s_1 + 2 && = 1 + 2 = 3\\ s_3 & = s_2 + 3 && = 1 + 2 + 3 = 6, \text{ etc.}source

Now we can prove, by induction, that sn=n(n+1)/2s_n = n(n+1)/2source.

Closed formula for the partial sums

sn=n(n+1)/2s_n = n(n+1)/2source.

Proof

We have to prove (1) that s0=0·(0+1)/2s_0 = 0\cdot(0 + 1)/2source and (2) if sk=k(k+1)/2s_k = k(k+1)/2source then sk+1=(k+1)(k+2)/2s_{k+1} = (k+1)(k+2)/2source. (1) is obvious. To prove (2), we assume the inductive hypothesis: sk=k(k+1)/2s_k = k(k+1)/2source. Using it, we have to show that sk+1=(k+1)(k+2)/2s_{k+1} = (k+1)(k+2)/2source.

What is sk+1s_{k+1}source? By the definition, sk+1=sk+(k+1)s_{k+1} = s_k + (k+1)source. By inductive hypothesis, sk=k(k+1)/2s_k = k(k+1)/2source. We can substitute this into the previous equation, and then just need a bit of arithmetic of fractions:

sk+1=k(k+1)2+(k+1)==k(k+1)2+2(k+1)2==k(k+1)+2(k+1)2==(k+2)(k+1)2.s_{k+1} & = \frac{k(k+1)}{2} + (k+1) = {}\\ & = \frac{k(k+1)}{2} + \frac{2(k+1)}{2} = {}\\ & = \frac{k(k+1) + 2(k+1)}{2} = {}\\ & = \frac{(k+2)(k+1)}{2}.source

The important lesson here is that if you're proving something about some inductively defined sequence ana_nsource, induction is the obvious way to go. And even if it isn't (as in the case of the possibilities of dice throws), you can use induction if you can somehow relate the case for k+1k+1source to the case for kksource.

Source file content/methods/induction/strong-induction.tex

Strong Induction

In the principle of induction discussed above, we prove P(0)P(0)source and also if P(k)P(k)source, then P(k+1)P(k+1)source. In the second part, we assume that P(k)P(k)source is true and use this assumption to prove P(k+1)P(k+1)source. Equivalently, of course, we could assume P(k1)P(k-1)source and use it to prove P(k)P(k)source---the important part is that we be able to carry out the inference from any number to its successor; that we can prove the claim in question for any number under the assumption it holds for its predecessor.

There is a variant of the principle of induction in which we don't just assume that the claim holds for the predecessor k1k-1source of kksource, but for all numbers smaller than kksource, and use this assumption to establish the claim for kksource. This also gives us the claim P(n)P(n)source for all nn \in \Natsource. For once we have established P(0)P(0)source, we have thereby established that PPsource holds for all numbers less than 11source. And if we know that if P(l)P(l)source for all l<kl<ksource, then P(k)P(k)source, we know this in particular for k=1k=1source. So we can conclude P(1)P(1)source. With this we have proved P(0)P(0)source and P(1)P(1)source, i.e., P(l)P(l)source for all l<2l<2source, and since we have also the conditional, if P(l)P(l)source for all l<2l<2source, then P(2)P(2)source, we can conclude P(2)P(2)source, and so on.

In fact, if we can establish the general conditional “for all kksource, if P(l)P(l)source for all l<kl<ksource, then P(k)P(k)source,” we do not have to establish P(0)P(0)source anymore, since it follows from it. For remember that a general claim like “for all l<kl<ksource, P(l)P(l)source” is true if there are no l<kl<ksource. This is a case of vacuous quantification: “all AAsources are BBsources” is true if there are no AAsources, x(A(x)B(x))\lforall[x][(!A(x) \lif !B(x))]source is true if no xxsource satisfies A(x)!A(x)source. In this case, the formalized version would be “l(l<kP(l))\lforall[l][(l < k \lif P(l))]source”---and that is true if there are no l<kl < ksource. And if k=0k=0source that's exactly the case: no l<0l<0source, hence “for all l<0l<0source, P(0)P(0)source” is true, whatever PPsource is. A proof of “if P(l)P(l)source for all l<kl<ksource, then P(k)P(k)source” thus automatically establishes P(0)P(0)source.

This variant is useful if establishing the claim for kksource can't be made to just rely on the claim for k1k-1source but may require the assumption that it is true for one or more l<kl<ksource.

Source file content/methods/induction/inductive-definitions.tex

Inductive Definitions

In logic we very often define kinds of objects inductively, i.e., by specifying rules for what counts as an object of the kind to be defined which explain how to get new objects of that kind from old objects of that kind. For instance, we often define special kinds of sequences of symbols, such as the terms and formulas of a language, by induction. For a simple example, consider strings consisting of letters a\mathrm{a}source, b\mathrm{b}source, c\mathrm{c}source, d\mathrm{d}source, the symbol \circsource, and brackets [[source and ]]source, such as “[[cd][[[\mathrm{c} \circ \mathrm{d}][source”, “[a[]][\mathrm{a}[]\circ]source”, “a\mathrm{a}source” or “[[ab]d][[\mathrm{a} \circ \mathrm{b}]\circ \mathrm{d}]source”. You probably feel that there's something “wrong” with the first two strings: the brackets don't “balance” at all in the first, and you might feel that the “\circsource” should “connect” expressions that themselves make sense. The third and fourth string look better: for every “[[source” there's a closing “]]source” (if there are any at all), and for any \circsource we can find “nice” expressions on either side, surrounded by a pair of parentheses.

We would like to precisely specify what counts as a “nice term.” First of all, every letter by itself is nice. Anything that's not just a letter by itself should be of the form “[ts][t \circ s]source” where sssource and ttsource are themselves nice. Conversely, if ttsource and sssource are nice, then we can form a new nice term by putting a \circsource between them and surround them by a pair of brackets. We might use these operations to define the set of nice terms. This is an inductive definition.

Inductive definition of nice terms

[Nice terms] The set of nice terms is inductively defined as follows:

  1. Any letter a\mathrm{a}source, b\mathrm{b}source, c\mathrm{c}source, d\mathrm{d}source is a nice term.

  2. If s1s_1source and s2s_2source are nice terms, then so is [s1s2][s_1 \circ s_2]source.

  3. Nothing else is a nice term.

This definition tells us that something counts as a nice term iff it can be constructed according to the two conditions (1) and (2) in some finite number of steps. In the first step, we construct all nice terms just consisting of letters by themselves, i.e.,

a,b,c,d\mathrm{a}, \mathrm{b}, \mathrm{c}, \mathrm{d}source

In the second step, we apply (2) to the terms we've constructed. We'll get

[aa],[ab],[ba],,[dd][\mathrm{a} \circ \mathrm{a}], [\mathrm{a} \circ \mathrm{b}], [\mathrm{b} \circ \mathrm{a}], \dots, [\mathrm{d} \circ \mathrm{d}]source

for all combinations of two letters. In the third step, we apply (2) again, to any two nice terms we've constructed so far. We get new nice term such as [a[aa]][\mathrm{a} \circ [\mathrm{a} \circ \mathrm{a}]]source---where ttsource is a\mathrm{a}source from step 1 and sssource is [aa][\mathrm{a} \circ \mathrm{a}]source from step 2---and [[bc][db]][[\mathrm{b} \circ \mathrm{c}] \circ [\mathrm{d} \circ \mathrm{b}]]source constructed out of the two terms [bc][\mathrm{b} \circ \mathrm{c}]source and [db][\mathrm{d} \circ \mathrm{b}]source from step 2. And so on. Clause (3) rules out that anything not constructed in this way sneaks into the set of nice terms.

Note that we have not yet proved that every sequence of symbols that “feels” nice is nice according to this definition. However, it should be clear that everything we can construct does in fact “feel nice”: brackets are balanced, and \circsource connects parts that are themselves nice.

The key feature of inductive definitions is that if you want to prove something about all nice terms, the definition tells you which cases you must consider. For instance, if you are told that ttsource is a nice term, the inductive definition tells you what ttsource can look like: ttsource can be a letter, or it can be [s1s2][s_1 \circ s_2]source for some pair of nice terms s1s_1source and s2s_2source. Because of clause (3), those are the only possibilities.

When proving claims about all of an inductively defined set, the strong form of induction becomes particularly important. For instance, suppose we want to prove that for every nice term of length nnsource, the number of [[source in it is <n/2< n/2source. This can be seen as a claim about all nnsource: for every nnsource, the number of [[source in any nice term of length nnsource is <n/2< n/2source.

Opening-bracket bound for nice terms

For any nnsource, the number of [[source in a nice term of length nnsource is <n/2< n/2source.

Proof

To prove this result by (strong) induction, we have to show that the following conditional claim is true:

If for every l<kl < ksource, any nice term of length llsource has <l/2< l/2source [[source's, then any nice term of length kksource has <k/2< k/2source [[source's.

To show this conditional, assume that its antecedent is true, i.e., assume that for any l<kl<ksource, nice terms of length llsource contain <l/2< l/2source [[source's. We call this assumption the inductive hypothesis. We want to show the same is true for nice terms of length kksource.

So suppose ttsource is a nice term of length kksource. Because nice terms are inductively defined, we have two cases: (1) ttsource is a letter by itself, or (2) ttsource is [s1s2][s_1 \circ s_2]source for some nice terms s1s_1source and s2s_2source.

  1. ttsource is a letter. Then k=1k = 1source, and the number of [[source in ttsource is 00source. Since 0<1/20 < 1/2source, the claim holds.

  2. ttsource is [s1s2][s_1 \circ s_2]source for some nice terms s1s_1source and s2s_2source. Let's let l1l_1source be the length of s1s_1source and l2l_2source be the length of s2s_2source. Then the length kksource of ttsource is l1+l2+3l_1+l_2+3source (the lengths of s1s_1source and s2s_2source plus three symbols [[source, \circsource, ]]source). Since l1+l2+3l_1+l_2+3source is always greater than l1l_1source, l1<kl_1 < ksource. Similarly, l2<kl_2 < ksource. That means that the induction hypothesis applies to the terms s1s_1source and s2s_2source: the number m1m_1source of [[source in s1s_1source is <l1/2< l_1/2source, and the number m2m_2source of [[source in s2s_2source is <l2/2< l_2/2source.

    The number of [[source in ttsource is the number of [[source in s1s_1source, plus the number of [[source in s2s_2source, plus 11source, i.e., it is m1+m2+1m_1 + m_2 + 1source. Since m1<l1/2m_1 < l_1/2source and m2<l2/2m_2 < l_2/2source we have:

    m1+m2+1<l12+l22+1=l1+l2+22<l1+l2+32=k/2.m_1 + m_2 + 1 < \frac{l_1}{2} + \frac{l_2}{2} + 1 = \frac{l_1+l_2+2}{2} < \frac{l_1+l_2+3}{2} = k/2.source

In each case, we've shown that the number of [[source in ttsource is <k/2< k/2source (on the basis of the inductive hypothesis). By strong induction, the proposition follows.

Exercise defining and bounding supernice terms

Define the set of supernice terms by

  1. Any letter a\mathrm{a}source, b\mathrm{b}source, c\mathrm{c}source, d\mathrm{d}source is a supernice term.

  2. If sssource is a supernice term, then so is [s][s]source.

  3. If s1s_1source and s2s_2source are supernice terms, then so is [s1s2][s_1 \circ s_2]source.

  4. Nothing else is a supernice term.

Show that the number of [[source in a supernice term ttsource of length nnsource is n/2+1\le n/2 +1source.

Source file content/methods/induction/structural-induction.tex

Structural Induction

So far we have used induction to establish results about all natural numbers. But a corresponding principle can be used directly to prove results about all elements of an inductively defined set. This often called structural induction, because it depends on the structure of the inductively defined objects.

Generally, an inductive definition is given by (a) a list of “initial” elements of the set and (b) a list of operations which produce new elements of the set from old ones. In the case of nice terms, for instance, the initial objects are the letters. We only have one operation: the operations are

o(s1,s2)=[s1s2]o(s_1, s_2) = & [s_1 \circ s_2]source

You can even think of the natural numbers \Natsource themselves as being given by an inductive definition: the initial object is 00source, and the operation is the successor function x+1x + 1source.

In order to prove something about all elements of an inductively defined set, i.e., that every element of the set has a property PPsource, we must:

  1. Prove that the initial objects have PPsource

  2. Prove that for each operation oosource, if the arguments have PPsource, so does the result.

For instance, in order to prove something about all nice terms, we would prove that it is true about all letters, and that it is true about [s1s2][s_1 \circ s_2]source provided it is true of s1s_1source and s2s_2source individually.

Balanced brackets in every nice term

The number of [[source equals the number of ]]source in any nice term ttsource.

Proof

We use structural induction. Nice terms are inductively defined, with letters as initial objects and the operation oosource for constructing new nice terms out of old ones.

  1. The claim is true for every letter, since the number of [[source in a letter by itself is 00source and the number of ]]source in it is also 00source.

  2. Suppose the number of [[source in s1s_1source equals the number of ]]source, and the same is true for s2s_2source. The number of [[source in o(s1,s2)o(s_1, s_2)source, i.e., in [s1s2][s_1 \circ s_2]source, is the sum of the number of [[source in s1s_1source and s2s_2source plus one. The number of ]]source in o(s1,s2)o(s_1, s_2)source is the sum of the number of ]]source in s1s_1source and s2s_2source plus one. Thus, the number of [[source in o(s1,s2)o(s_1, s_2)source equals the number of ]]source in o(s1,s2)o(s_1,s_2)source.

Exercise on the first symbol of a nice term

Prove by structural induction that no nice term starts with ]]source.

Let's give another proof by structural induction: a proper initial segment of a string ttsource of symbols is any string sssource that agrees with ttsource symbol by symbol, read from the left, but ttsource is longer. So, e.g., [a[a \circ {}source is a proper initial segment of [ab][a \circ b]source, but neither are [b[b \circ {}source (they disagree at the second symbol) nor [ab][a \circ b]source (they are the same length).

Proper initial segments contain more opening brackets

Every proper initial segment of a nice term ttsource has more [[source's than ]]source's.

Proof

By induction on ttsource:

  1. ttsource is a letter by itself: Then ttsource has no proper initial segments.

  2. t=[s1s2]t = [s_1 \circ s_2]source for some nice terms s1s_1source and s2s_2source. If rrsource is a proper initial segment of ttsource, there are a number of possibilities:

    1. rrsource is just [[source: Then rrsource has one more [[source than it does ]]source.

    2. rrsource is [r1[r_1source where r1r_1source is a proper initial segment of s1s_1source: Since s1s_1source is a nice term, by induction hypothesis, r1r_1source has more [[source than ]]source and the same is true for [r1[r_1source.

    3. rrsource is [s1[s_1source or [s1[s_1 \circ {}source: By the previous result, the number of [[source and ]]source in s1s_1source are equal; so the number of [[source in [s1[s_1source or [s1[s_1 \circ {}source is one more than the number of ]]source.

    4. rrsource is [s1r2[s_1 \circ r_2source where r2r_2source is a proper initial segment of s2s_2source: By induction hypothesis, r2r_2source contains more [[source than ]]source. By the previous result, the number of [[source and of ]]source in s1s_1source are equal. So the number of [[source in [s1r2[s_1 \circ r_2source is greater than the number of ]]source.

    5. rrsource is [s1s2[s_1 \circ s_2source: By the previous result, the number of [[source and ]]source in s1s_1source are equal, and the same for s2s_2source. So there is one more [[source in [s1s2[s_1 \circ s_2source than there are ]]source.

Source file content/methods/induction/relations.tex

Relations and Functions

When we have defined a set of objects (such as the natural numbers or the nice terms) inductively, we can also define relations on these objects by induction. For instance, consider the following idea: a nice term t1t_1source is a subterm of a nice term t2t_2source if it occurs as a part of it. Let's use a symbol for it: t1t2t_1 \sqsubseteq t_2source. Every nice term is a subterm of itself, of course: ttt \sqsubseteq tsource. We can give an inductive definition of this relation as follows:

Inductive definition of the subterm relation

The relation of a nice term t1t_1source being a subterm of t2t_2source, t1t2t_1 \sqsubseteq t_2source, is defined by induction on t2t_2source as follows:

  1. If t2t_2source is a letter, then t1t2t_1 \sqsubseteq t_2source iff t1=t2t_1 = t_2source.

  2. If t2t_2source is [s1s2][s_1 \circ s_2]source, then t1t2t_1 \sqsubseteq t_2source iff t1=t2t_1 = t_2source, t1s1t_1 \sqsubseteq s_1source, or t1s2t_1 \sqsubseteq s_2source.

This definition, for instance, will tell us that a[ba]\mathrm{a} \sqsubseteq [\mathrm{b} \circ \mathrm{a}]source. For (2) says that a[ba]\mathrm{a} \sqsubseteq [\mathrm{b} \circ \mathrm{a}]source iff a=[ba]\mathrm{a} = [\mathrm{b} \circ \mathrm{a}]source, or ab\mathrm{a} \sqsubseteq bsource, or aa\mathrm{a} \sqsubseteq \mathrm{a}source. The first two are false: a\mathrm{a}source clearly isn't identical to [ba][\mathrm{b} \circ \mathrm{a}]source, and by (1), ab\mathrm{a} \sqsubseteq \mathrm{b}source iff a=b\mathrm{a} = \mathrm{b}source, which is also false. However, also by (1), aa\mathrm{a} \sqsubseteq \mathrm{a}source iff a=a\mathrm{a} = \mathrm{a}source, which is true.

It's important to note that the success of this definition depends on a fact that we haven't proved yet: every nice term ttsource is either a letter by itself, or there are uniquely determined nice terms s1s_1source and s2s_2source such that t=[s1s2]t = [s_1 \circ s_2]source. “Uniquely determined” here means that if t=[s1s2]t = [s_1 \circ s_2]source it isn't also =[r1r2]= [r_1 \circ r_2]source with s1r1s_1 \neq r_1source or s2r2s_2 \neq r_2source. If this were the case, then clause (2) may come in conflict with itself: reading t2t_2source as [s1s2][s_1 \circ s_2]source we might get t1t2t_1 \sqsubseteq t_2source, but if we read t2t_2source as [r1r2][r_1 \circ r_2]source we might get not t1t2t_1 \sqsubseteq t_2source. Before we prove that this can't happen, let's look at an example where it can happen.

Inductive definition of bracketless terms

Define bracketless terms inductively by

  1. Every letter is a bracketless term.

  2. If s1s_1source and s2s_2source are bracketless terms, then s1s2s_1 \circ s_2source is a bracketless term.

  3. Nothing else is a bracketless term.

Bracketless terms are, e.g., a\mathrm{a}source, bd\mathrm{b} \circ \mathrm{d}source, bab\mathrm{b} \circ \mathrm{a} \circ \mathrm{b}source. Now if we defined “subterm” for bracketless terms the way we did above, the second clause would read

If t2=s1s2t_2 = s_1 \circ s_2source, then t1t2t_1 \sqsubseteq t_2source iff t1=t2t_1 = t_2source, t1s1t_1 \sqsubseteq s_1source, or t1s2t_1 \sqsubseteq s_2source.

Now bab\mathrm{b} \circ \mathrm{a} \circ \mathrm{b}source is of the form s1s2s_1 \circ s_2source with

s1=b ands2=ab.It is also of the form r1r2 withr1=ba andr2=b.s_1 & = \mathrm{b} \text{ and} & s_2 & = \mathrm{a} \circ \mathrm{b}. \intertext{It is also of the form $r_1 \circ r_2$ with} r_1 & = \mathrm{b} \circ \mathrm{a} \text{ and} & r_2 &= \mathrm{b}.source

Now is ab\mathrm{a} \circ \mathrm{b}source a subterm of bab\mathrm{b} \circ \mathrm{a} \circ \mathrm{b}source? The answer is yes if we go by the first reading, and no if we go by the second.

The property that the way a nice term is built up from other nice terms is unique is called unique readability. Since inductive definitions of relations for such inductively defined objects are important, we have to prove that it holds.

Unique readability of nice terms

Suppose ttsource is a nice term. Then either ttsource is a letter by itself, or there are uniquely determined nice terms s1s_1source, s2s_2source such that t=[s1s2]t = [s_1 \circ s_2]source.

Proof

If ttsource is a letter by itself, the condition is satisfied. So assume ttsource isn't a letter by itself. We can tell from the inductive definition that then ttsource must be of the form [s1s2][s_1 \circ s_2]source for some nice terms s1s_1source and s2s_2source. It remains to show that these are uniquely determined, i.e., if t=[r1r2]t = [r_1 \circ r_2]source, then s1=r1s_1 = r_1source and s2=r2s_2 = r_2source.

So suppose t=[s1s2]t = [s_1 \circ s_2]source and also t=[r1r2]t = [r_1 \circ r_2]source for nice terms s1s_1source, s2s_2source, r1r_1source, r2r_2source. We have to show that s1=r1s_1 = r_1source and s2=r2s_2 = r_2source. First, s1s_1source and r1r_1source must be identical, for otherwise one is a proper initial segment of the other. But by the proposition on proper initial segments of nice terms, that is impossible if s1s_1source and r1r_1source are both nice terms. But if s1=r1s_1 = r_1source, then clearly also s2=r2s_2 = r_2source.

We can also define functions inductively: e.g., we can define the function ffsource that maps any nice term to the maximum depth of nested [][\dots]source in it as follows:

Inductive definition of depth

The depth of a nice term, f(t)f(t)source, is defined inductively as follows:

f(t)={0 if t is a lettermax(f(s1),f(s2))+1 if t=[s1s2].f(t) = \begin{cases} 0 & \text{ if $t$ is a letter}\\ \max(f(s_1), f(s_2)) + 1 & \text{ if $t = [s_1 \circ s_2]$.} \end{cases}source

For instance

f([ab])=max(f(a),f(b))+1==max(0,0)+1=1, andf([[ab]c])=max(f([ab]),f(c))+1==max(1,0)+1=2.f([\mathrm{a} \circ \mathrm{b}]) & = \max(f(\mathrm{a}),f(\mathrm{b})) + 1 = \\ &= \max(0, 0) + 1 = 1, \text{ and}\\ f([[\mathrm{a} \circ \mathrm{b}] \circ \mathrm{c}]) & = \max(f([\mathrm{a} \circ \mathrm{b}]), f(\mathrm{c})) + 1 = \\ & = \max(1,0) + 1 = 2.source

Here, of course, we assume that s1s_1source an s2s_2source are nice terms, and make use of the fact that every nice term is either a letter or of the form [s1s2][s_1 \circ s_2]source. It is again important that it can be of this form in only one way. To see why, consider again the bracketless terms we defined earlier. The corresponding “definition” would be:

g(t)={0 if t is a lettermax(g(s1),g(s2))+1 if t=s1s2.g(t) = \begin{cases} 0 & \text{ if $t$ is a letter}\\ \max(g(s_1), g(s_2)) + 1 & \text{ if $t = s_1 \circ s_2$.} \end{cases}source

Now consider the bracketless term abcd\mathrm{a} \circ \mathrm{b} \circ \mathrm{c} \circ \mathrm{d}source. It can be read in more than one way, e.g., as s1s2s_1 \circ s_2source with

s1=a ands2=bcd,or as r1r2 withr1=ab andr2=cd.s_1 & = \mathrm{a} \text{ and} & s_2 & = \mathrm{b} \circ \mathrm{c} \circ \mathrm{d}, \intertext{or as $r_1 \circ r_2$ with} r_1 & = \mathrm{a} \circ b \text{ and} & r_2 &= \mathrm{c} \circ \mathrm{d}.source

Calculating ggsource according to the first way of reading it would give

g(s1s2)=max(g(a),g(bcd))+1==max(0,2)+1=3while according to the other reading we getg(r1r2)=max(g(ab),g(cd))+1==max(1,1)+1=2g(s_1 \circ s_2) & = \max(g(\mathrm{a}), g(\mathrm{b} \circ \mathrm{c} \circ \mathrm{d})) + 1 =\\ & = \max(0,2) + 1 = 3 \intertext{while according to the other reading we get} g(r_1 \circ r_2) & = \max(g(\mathrm{a} \circ \mathrm{b}), g(\mathrm{c} \circ \mathrm{d})) + 1=\\ & = \max(1,1) + 1 = 2source

But a function must always yield a unique value; so our “definition” of ggsource doesn't define a function at all.

Exercise defining the length of a nice term

Give an inductive definition of the function llsource, where l(t)l(t)source is the number of symbols in the nice term ttsource.

Exercise comparing depth and length

Prove by structural induction on nice terms ttsource that f(t)<l(t)f(t) < l(t)source (where l(t)l(t)source is the number of symbols in ttsource and f(t)f(t)source is the depth of ttsource as defined in the definition of the depth of a nice term).

Source disclosures