Download presentation
Presentation is loading. Please wait.
1
and Structural Induction
Mathematics for Computer Science MIT 6.042J/18.062J Recursive Definitions and Structural Induction Copyright © Albert Meyer, 2002. Prof. Albert Meyer & Dr. Radhika Nagpal
2
Build something from a simpler version of the same thing:
Recursive Definitions Build something from a simpler version of the same thing: Base case(s) that don’t depend on anything else Induction (Construction) case(s) that depend on simpler cases
3
Example Definition: set E
Define set E Z, recursively: 0 E Base Case If n E, then n + 2 E Induction case If n E, then -n E Induction case E : 0 , 0+2
4
Example Definition: set E
Define set E Z, recursively: 0 E If n E, then n + 2 E If n E, then -n E E : 0, 2, 2+2 , (2+2)+2
5
Example Definition: set E
Define set E Z, recursively: 0 E If n E, then n + 2 E If n E, then -n E E : 0, 2, 4, 6, … All even numbers Also, -2, -4, -6, …
6
Recursive Definition: Extremal Clause
So, E contains the even integers Anything Else? No! 0 E If n E, then n + 2 E If n E, then -n E Implicit part of recursive definition: THAT’S ALL!
7
Example Definition: set E
So E is exactly: The Even Integers
8
Define set of strings, S {a, b}*
Another Example Define set of strings, S {a, b}* l S, (the empty string) If x, y S, then the following are in S: axb bxa xy
9
Proof by Structural Induction on S
Lemma: Every x in S has an equal number of a’s and b’s.
10
Structural Induction on S
Proof: Let EQ ::= {strings with equal # of a’s and b’s} P(s) ::= s S s EQ Base Case: s = l. 0 a’s and 0 b’s. OK
11
Structural Induction on S
Inductive Step Assume: P(x) and P(y) To Prove: P(axb), P(bxa), and P(xy) Case 1: axb has k + 1 a’s and b’s if x has k of each. OK
12
Structural Induction on S
Inductive Step Assume: P(x) and P(y) To Prove: P(axb), P(bxa), and P(xy) Case 2: bxa SAME Case 3: xy has kx + ky of each. OK
13
Theorem: S = EQ Show by strong induction on length of string in EQ.
Proof in Notes 5.
14
In-Class Problem Problem 1
15
Recursive Data Types Rooted Binary Trees
16
Defined recursively as follows: A single node r is in T:
Rooted Binary Trees Defined recursively as follows: A single node r is in T:
17
t t t t’ Rooted Binary Trees
If t, t’ are RBTs, then the following are RBTs Makeleft(t) t Makeright(t) t Makeboth(t,t’) t t’
18
A Rooted Binary Tree Example
19
Recursive Functions on RBT
nodes(t) → Vertex Set of t nodes( )::= { }, nodes(makeleft(t))::= nodes(t){ } Remember, is not supposed to be in Nodes(t) nodes(makeright(t))::= nodes(t){ } nodes(makeboth(t1, t2))::= nodes(t1)nodes(t2){ }
20
Example = {{ }, { }, { }, { }, { }, { }, { }, { }, { } } nodes( )
21
Recursive Functions on RBT
depth(t) → Power Set of t depth( )::= 1 depth(makeleft(t))::= 1 + depth(t) depth(makeright(t))::= 1 + depth(t) depth(makeboth(t1, t2))::= max(depth(t1)+ 1,depth(t2)+ 1)
22
Example depth( ) = 4
23
Proof by Structural Induction
Lemma: |nodes(t)| 2depth(t) Proof by Structural Induction Base Case: t = |nodes(t)| = 1 = 20 = 2depth(t) OK!
24
Induction Case: makeleft(t)
Assume: |nodes(t)| 2depth(t) To Prove:|nodes(makeleft(t))| 2depth(makeleft(t)) |nodes(makeleft(t))| = |nodes(t)| + 1 by def. of makeleft 2depth(t) + 1 by induction hyp. 2depth(t) + 2depth(t) = 2depth(t)+1 = 2depth(makeleft(t)) by def. of depth
25
Induction Case: makeright(t)
Same
26
Induction Case: makeboth(t1, t2)
Assume: |nodes(t1)| 2depth(t1) |nodes(t2)| 2depth(t2) To Prove: |nodes(makeboth(t1, t2))| 2depth(makeboth(t1,t2)) Proof: VERY SIMILAR
27
In-Class Problem Problems 2 & 3
28
Examples so far: But what if the objects are all infinite?
Can reduce structural induction to Strong Induction on SIZE of parts. But what if the objects are all infinite? simple example: recursive definition of the set of functions on real numbers from what is the "size" of the COSINE function?
29
In-Class Problem Problem 4
30
In-Class Problem Problem 5
31
Infinitely Wide Trees … …
32
Infinitely Wide Trees
33
Infinitely Wide Trees
34
Infinitely Wide Trees … …
35
In-Class Problem Problems 6 & 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.