Docsity

Structural Induction: Proof Technique for Recursively Defined Sets and Trees - Prof. Marga, Study notes of Discrete Structures and Graph Theory

Toggle sidebar
bg1
Structural Induction
Margaret M. Fleck
13 October 2008
This lecture finishes the discussion of recursive definition and structural
induction (Rosen 4.3)
1 Recursive definition of expressions
At the end of last class, we saw how to define a set of numbers recursively. We
can use the same method to define more interesting sorts of sets. For exam-
ple, we can define all the legal numerical expressions for some programming
language. (These are all intended to be strings of characters.)
1. Any digit or lower-case letter is a numerical expression.
2. If Xand Yare numerical expressions, then so are
(X+Y)
(X−Y)
(X×Y)
(X/Y )
Some sample base-case expressions are b,r, 7, 0. If we apply the inductive
rules one time, we get expressions like (m+n) and (7 + q). If we apply the
inductive rules more than once, we get expressions like (m+ (7/9)) and
((c+d) + ((a+ 5) ×8)). Notice that the parentheses are obligatory, because
that’s how we’ve set up our inductive rules.
This little bitty expression grammar is much simpler than the expression
grammar for any actual programming language. For example, real languages
1
pf3
pf4
pf5

Partial preview of the text

Download Structural Induction: Proof Technique for Recursively Defined Sets and Trees - Prof. Marga and more Study notes Discrete Structures and Graph Theory in PDF only on Docsity!

Structural Induction

Margaret M. Fleck

13 October 2008

This lecture finishes the discussion of recursive definition and structural induction (Rosen 4.3)

1 Recursive definition of expressions

At the end of last class, we saw how to define a set of numbers recursively. We can use the same method to define more interesting sorts of sets. For exam- ple, we can define all the legal numerical expressions for some programming language. (These are all intended to be strings of characters.)

  1. Any digit or lower-case letter is a numerical expression.
  2. If X and Y are numerical expressions, then so are

(X + Y ) (X − Y ) (X × Y ) (X/Y )

Some sample base-case expressions are b, r, 7, 0. If we apply the inductive rules one time, we get expressions like (m + n) and (7 + q). If we apply the inductive rules more than once, we get expressions like (m + (7/9)) and ((c + d) + ((a + 5) × 8)). Notice that the parentheses are obligatory, because that’s how we’ve set up our inductive rules. This little bitty expression grammar is much simpler than the expression grammar for any actual programming language. For example, real languages

allow multi-character numbers and variable names. However, the real gram- mars are defined in a similar way. Let’s show that expressions generated by this grammar always contain equal numbers of left and right parentheses. We’ll use a technique called structural induction. Structural induction is like normal induction, but there’s no visible induction variable n. Rather, the proof follows the structure of the recursive definition. Suppose we want to prove that P (x) is true for every x defined by some recursive definition D.

  • P (x) is true for every x defined in the base case of D.
  • For each recursive case of D, assume the claim is true for all the objects assumed to exist in the recursive case, then show that the claim is true for the new objects constructed by that case.

For example, here’s a proof of our claim about the parentheses:

Proof: by structural induction on the definition of numerical ex- pression. Base: Single digits and lower-case letters do not contain any parentheses, so the number of left parentheses and the number of right parenthese are both zero. Induction: Suppose that the claim is true for X and Y. That is, X contains the same number of left and right parentheses, and so does Y. Suppose that X contains p left parentheses and Y contains q. Then, the expression (X + Y ) contains p left parentheses from X, q from Y , and one new one. That is, p + q + 1 left parentheses. Similarly, it contains p + q + 1 right parentheses. So the two are equal. The same line of reasoning works for the other recursive cases: (X − Y ), (X × Y ), and (X/Y ).

You may be wondering about the missing induction variable n. Didn’t we say that induction needed an integer? If we wanted to make an explicit integer for this example, we would let n be the number of rule applications

Proof by structural induction. Base: If a tree contains only one node, obviously the largest value in the tree lives in the root! Induction: Suppose that the claim is true for trees X and Y. We need to show that the claim is also true for T = X · Y. Let p, q, and r be the root nodes of X, Y , and T. p and q are the children of r. Since T has the heap property, v(r) ≥ v(p) and v(r) ≥ v(q). By the inductive hypothesis, v(p) is ≥ the value in each node of X and v(q) is ≥ the value in each node of Y. So v(r) ≥ the value in each node of X and each node of Y. The nodes of T are the nodes of X, plus the nodes of Y , plus r. So v(r), the value at the root node of T , is at least as big as the value at any node of T.

In the inductive step, notice that we split up the big tree (T ) at its root, producing two smaller subtrees (X) and (Y ). Some students try to do induction on trees by grafting stuff onto the bottom of the tree. This frequently does not work, especially as you get to examples in more advanced courses. Therefore, we will take off points if you do it on homework or tests.

3 An example with 2D points

Consider the following recursive definition of a set S of 2D points:

  1. (3, 5) ∈ S
  2. If (x, y) ∈ S, then (x + 2, y) ∈ S
  3. If (x, y) ∈ S, then (−x, y) ∈ S
  4. If (x, y) ∈ S, then (y, x) ∈ S

What’s in S? Starting with the pair specified in the base case (3, 5), we use rule 3 to add (− 3 , 5). Rule 2 then allows us to add (− 1 , 5) and then (1, 5). If we apply rule 2 repeatedly, we see that S contains all pairs of the form (2n + 1, 5) where x is a natural number. By rule 4, (5, 2 n + 1) must also be in S for every natural number n.

We then apply rules 2 and 3 in the same way, to show that (2m+1, 2 n+1) is in S for every natural numbers m and n. We could make this more formal using a proof by induction, but let’s not bother. The big missing piece of this analysis is showing that S doesn’t contain any other points other than those with odd coordinates. Think of this as proving a set equality. Let T be the set of 2D points with odd coordinates. We’ve shown that T ⊆ S and we still need to show that S ⊆ T. We can do this by structural induction.

Proof by structural induction that all elements of S have both coordinates odd. Base: Both coordinates of (3, 5) are odd. Induction: Suppose that both coordinates of (x, y) are odd. We need to show that both coordinates of (x + 2, y), (−x, y), and (y, x) are odd. But this is (even in the context of this course), obvious.

In this case, the second half of the proof was very easy because we used structural induction. Two things were important. First, it was critical that we did do this second half, otherwise we couldn’t claim to have completely nailed down what’s in S. Second, we needed generate the outline of structural induction and verify the base case and inductive step.

4 Another tree example

I didn’t get to this example in lecture, but it’s a good one to read through. It’s another structural induction on trees, with a slightly more complex claim. Let T be a full binary tree. Suppose that n(T ) is the number of nodes in T and h(T ) is the height of T. Let’s show that n(T ) ≤ 2 h(T^ )+1^ − 1.

Proof by structural induction. Base: Trees containing a single node have no edges and therefore height 0. Notice that n(T ) = 1 and 2h(T^ )+1^ − 1 = 2^1 − 1 = 1. Induction: Let X and Y be full binary trees. Suppose that the claim is true for X and Y. We need to show that the claim is also true for T = X · Y.