Lecture 19
Lecture 19
Structural Induction
Emina Torlak and Kevin Zatloukal
1
Topics
Homework 6 advice
Start early!
Recursively defined sets
Recursive definitions of sets.
Structural induction
A method for proving properties of recursive structures.
Using structural induction
Example proofs about recursively defined numbers, strings, and trees.
2
Homework 6 advice
Start early!
3
Homework 6 isn’t necessarily harder …
But you may find it to be more work than most other assignments.
So please start early :)
Pay special attention to Problem 6.4.
Requires keeping careful track of
(1) what you know and
(2) what you need to prove.
4
Recursively defined sets
Recursive definitions of sets.
5
Giving a recursive definition of a set
A recursive definition of a set S has the following parts:
Basis step specifies one or more initial members of S.
Recursive step specifies the rule(s) for constructing new elements of S
from the existing elements.
Exclusion (or closure) rule states that every element in S follows from
the basis step and a finite number of recursive steps.
6
Giving a recursive definition of a set
A recursive definition of a set S has the following parts:
Basis step specifies one or more initial members of S.
Recursive step specifies the rule(s) for constructing new elements of S
from the existing elements.
Exclusion (or closure) rule states that every element in S follows from
the basis step and a finite number of recursive steps.
6
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
Recursive: if x ∈ S, then x + 2 ∈ S
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
Recursive: if x ∈ S, then x + 2 ∈ S
Powers of 3
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
Recursive: if x ∈ S, then x + 2 ∈ S
Powers of 3
Basis: 1 ∈ S
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
Recursive: if x ∈ S, then x + 2 ∈ S
Powers of 3
Basis: 1 ∈ S
Recursive: if x ∈ S, then 3x ∈ S
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
Recursive: if x ∈ S, then x + 2 ∈ S
Powers of 3
Basis: 1 ∈ S
Recursive: if x ∈ S, then 3x ∈ S
Fibonacci numbers
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
Recursive: if x ∈ S, then x + 2 ∈ S
Powers of 3
Basis: 1 ∈ S
Recursive: if x ∈ S, then 3x ∈ S
Fibonacci numbers
Basis: (0, 0) ∈ S, (1, 1) ∈ S
7
Examples of recursively defined sets
Natural numbers
Basis: 0 ∈ S
Recursive: if n ∈ S, then n+ 1 ∈ S
Even natural numbers
Basis: 0 ∈ S
Recursive: if x ∈ S, then x + 2 ∈ S
Powers of 3
Basis: 1 ∈ S
Recursive: if x ∈ S, then 3x ∈ S
Fibonacci numbers
Basis: (0, 0) ∈ S, (1, 1) ∈ S
Recursive: if (n− 1, x) ∈ S and (n− 2, y) ∈ S, then (n, x + y) ∈ S
7
More examples of recursively defined sets
Strings
An alphabet Σ is any finite set of characters.
The set Σ∗ of strings over the alphabet Σ is defined as follows.
Basis: ε ∈ Σ∗ , where ε is the empty string.
Recursive: if w ∈ Σ∗ and a ∈ Σ, then wa ∈ Σ∗
8
More examples of recursively defined sets
Strings
An alphabet Σ is any finite set of characters.
The set Σ∗ of strings over the alphabet Σ is defined as follows.
Basis: ε ∈ Σ∗ , where ε is the empty string.
Recursive: if w ∈ Σ∗ and a ∈ Σ, then wa ∈ Σ∗
Palindromes (strings that are the same forwards and backwards)
8
More examples of recursively defined sets
Strings
An alphabet Σ is any finite set of characters.
The set Σ∗ of strings over the alphabet Σ is defined as follows.
Basis: ε ∈ Σ∗ , where ε is the empty string.
Recursive: if w ∈ Σ∗ and a ∈ Σ, then wa ∈ Σ∗
Palindromes (strings that are the same forwards and backwards)
Basis: ε ∈ S and a ∈ S for every a ∈ Σ
8
More examples of recursively defined sets
Strings
An alphabet Σ is any finite set of characters.
The set Σ∗ of strings over the alphabet Σ is defined as follows.
Basis: ε ∈ Σ∗ , where ε is the empty string.
Recursive: if w ∈ Σ∗ and a ∈ Σ, then wa ∈ Σ∗
Palindromes (strings that are the same forwards and backwards)
Basis: ε ∈ S and a ∈ S for every a ∈ Σ
Recursive: if p ∈ S, then apa ∈ S for every a ∈ Σ
8
More examples of recursively defined sets
Strings
An alphabet Σ is any finite set of characters.
The set Σ∗ of strings over the alphabet Σ is defined as follows.
Basis: ε ∈ Σ∗ , where ε is the empty string.
Recursive: if w ∈ Σ∗ and a ∈ Σ, then wa ∈ Σ∗
Palindromes (strings that are the same forwards and backwards)
Basis: ε ∈ S and a ∈ S for every a ∈ Σ
Recursive: if p ∈ S, then apa ∈ S for every a ∈ Σ
All binary strings with no 1’s before 0’s
8
More examples of recursively defined sets
Strings
An alphabet Σ is any finite set of characters.
The set Σ∗ of strings over the alphabet Σ is defined as follows.
Basis: ε ∈ Σ∗ , where ε is the empty string.
Recursive: if w ∈ Σ∗ and a ∈ Σ, then wa ∈ Σ∗
Palindromes (strings that are the same forwards and backwards)
Basis: ε ∈ S and a ∈ S for every a ∈ Σ
Recursive: if p ∈ S, then apa ∈ S for every a ∈ Σ
All binary strings with no 1’s before 0’s
Basis: ε ∈ S
8
More examples of recursively defined sets
Strings
An alphabet Σ is any finite set of characters.
The set Σ∗ of strings over the alphabet Σ is defined as follows.
Basis: ε ∈ Σ∗ , where ε is the empty string.
Recursive: if w ∈ Σ∗ and a ∈ Σ, then wa ∈ Σ∗
Palindromes (strings that are the same forwards and backwards)
Basis: ε ∈ S and a ∈ S for every a ∈ Σ
Recursive: if p ∈ S, then apa ∈ S for every a ∈ Σ
All binary strings with no 1’s before 0’s
Basis: ε ∈ S
Recursive: if x ∈ S, then 0x ∈ S and x1 ∈ S
8
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
a ∈ Σ, then wa ∈ Σ∗
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
Concatenation
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
Concatenation
x ∙ ε = x for x ∈ Σ∗
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
Concatenation
x ∙ ε = x for x ∈ Σ∗
x ∙ (wa) = (x ∙ w)a for x, w ∈ Σ∗ , a ∈ Σ
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
Concatenation
x ∙ ε = x for x ∈ Σ∗
x ∙ (wa) = (x ∙ w)a for x, w ∈ Σ∗ , a ∈ Σ
Number of c’s in a string
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
Concatenation
x ∙ ε = x for x ∈ Σ∗
x ∙ (wa) = (x ∙ w)a for x, w ∈ Σ∗ , a ∈ Σ
Number of c’s in a string
#c (ε) = 0
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
Concatenation
x ∙ ε = x for x ∈ Σ∗
x ∙ (wa) = (x ∙ w)a for x, w ∈ Σ∗ , a ∈ Σ
Number of c’s in a string
#c (ε) = 0
#c (wc) = #c (w) + 1 for w ∈ Σ∗
9
Functions on recursively defined sets
Length Define Σ∗ by
𝗅𝖾𝗇(ε) = 0 Basis: ε ∈ Σ∗ , where ε is the
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1 for w ∈ Σ∗ , a ∈ Σ empty string.
Recursive: if w ∈ Σ∗ and
Reversal a ∈ Σ, then wa ∈ Σ∗
ε𝖱 = ε
(wa)𝖱 = aw𝖱 for w ∈ Σ∗ , a ∈ Σ
Concatenation
x ∙ ε = x for x ∈ Σ∗
x ∙ (wa) = (x ∙ w)a for x, w ∈ Σ∗ , a ∈ Σ
Number of c’s in a string
#c (ε) = 0
#c (wc) = #c (w) + 1 for w ∈ Σ∗
#c (wa) = #c (w) for w ∈ Σ∗ , a ∈ Σ , a ≠ c
9
Rooted binary trees and functions on them
Rooted binary trees
Basis: ∙ ∈ S
Recursive: if L ∈ S and R ∈ S, then 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
L R
10
Rooted binary trees and functions on them
Rooted binary trees
Basis: ∙ ∈ S
Recursive: if L ∈ S and R ∈ S, then 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size of a rooted binary tree
L R
10
Rooted binary trees and functions on them
Rooted binary trees
Basis: ∙ ∈ S
Recursive: if L ∈ S and R ∈ S, then 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size of a rooted binary tree
|∙|= 1 L R
10
Rooted binary trees and functions on them
Rooted binary trees
Basis: ∙ ∈ S
Recursive: if L ∈ S and R ∈ S, then 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size of a rooted binary tree
|∙|= 1 L R
|𝖳𝗋𝖾𝖾(∙, L, R)| = 1 + |L| + |R|
10
Rooted binary trees and functions on them
Rooted binary trees
Basis: ∙ ∈ S
Recursive: if L ∈ S and R ∈ S, then 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size of a rooted binary tree
|∙|= 1 L R
|𝖳𝗋𝖾𝖾(∙, L, R)| = 1 + |L| + |R|
Height of a rooted binary tree
10
Rooted binary trees and functions on them
Rooted binary trees
Basis: ∙ ∈ S
Recursive: if L ∈ S and R ∈ S, then 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size of a rooted binary tree
|∙|= 1 L R
|𝖳𝗋𝖾𝖾(∙, L, R)| = 1 + |L| + |R|
Height of a rooted binary tree
⌈∙⌉ = 0
10
Rooted binary trees and functions on them
Rooted binary trees
Basis: ∙ ∈ S
Recursive: if L ∈ S and R ∈ S, then 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size of a rooted binary tree
|∙|= 1 L R
|𝖳𝗋𝖾𝖾(∙, L, R)| = 1 + |L| + |R|
Height of a rooted binary tree
⌈∙⌉ = 0
⌈𝖳𝗋𝖾𝖾(∙, L, R)⌉ = 1 + max(⌈L⌉, ⌈R⌉)
10
Structural induction
A method for proving properties of recursive structures.
11
How can we prove properties of recursive structures?
Suppose that S is a recursively defined set.
And we want to prove that every element of S satisfies a predicate P.
Can we use ordinary induction to prove ∀x ∈ S. P(x)?
12
How can we prove properties of recursive structures?
Suppose that S is a recursively defined set.
And we want to prove that every element of S satisfies a predicate P.
Can we use ordinary induction to prove ∀x ∈ S. P(x)?
Yes! Define Q(n) to be “for all x ∈ S that can be constructed in at most n
recursive steps, P(x) is true.”
12
How can we prove properties of recursive structures?
Suppose that S is a recursively defined set.
And we want to prove that every element of S satisfies a predicate P.
Can we use ordinary induction to prove ∀x ∈ S. P(x)?
Yes! Define Q(n) to be “for all x ∈ S that can be constructed in at most n
recursive steps, P(x) is true.”
12
Proving ∀x ∈ S. P(x) by structural induction
Let P(x) be [ definition of P(x) ]. Recursive definition of S
We will show that P(x) is true for every x ∈ S by structural Basis step:
induction. s0 ∈ S, … , sm ∈ S.
Base cases: Recursive step:
[ Proof of P(s0 ), … , P(sm ) . ] if y0 , … , yk ∈ S, then
Inductive hypothesis: y ∈ S.
Assume that P(y0 ), … , P(yk ) are true for some arbitrary
y0 , … , yk ∈ S.
Inductive step:
We want to prove that P(y) is true.
[ Proof of P(y) . The proof must invoke the structural
inductive hypothesis. ]
The result follows for all x ∈ S by structural induction.
13
Proving ∀x ∈ S. P(x) by structural induction
Let P(x) be [ definition of P(x) ]. Recursive definition of S
We will show that P(x) is true for every x ∈ S by structural Basis step:
induction. s0 ∈ S, … , sm ∈ S.
Base cases: Recursive step:
[ Proof of P(s0 ), … , P(sm ) . ] if y0 , … , yk ∈ S, then
Inductive hypothesis: y ∈ S.
Assume that P(y0 ), … , P(yk ) are true for some arbitrary
y0 , … , yk ∈ S. If the recursive step of S
Inductive step: includes multiple rules for
We want to prove that P(y) is true. constructing new elements
[ Proof of P(y) . The proof must invoke the structural from existing elements, then
inductive hypothesis. ] assume P for the existing
elements in every rule, and
The result follows for all x ∈ S by structural induction.
prove P for the new
element in every rule.
13
Using structural induction
Example proofs about recursively defined numbers, strings, and trees.
14
Prove that every x ∈ S is divisible by 3
Define S by
Basis: 6 ∈ S, 15 ∈ S.
Recursive: if x, y ∈ S, then
x + y ∈ S.
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
x + y ∈ S.
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
Base cases (x = 6 , x = 15): x + y ∈ S.
3|6 so P(6) holds, and 3|15 so P(15) holds.
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
Base cases (x = 6 , x = 15): x + y ∈ S.
3|6 so P(6) holds, and 3|15 so P(15) holds.
Inductive hypothesis:
Assume that P(x), P(y) are true for some arbitrary
x, y ∈ S.
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
Base cases (x = 6 , x = 15): x + y ∈ S.
3|6 so P(6) holds, and 3|15 so P(15) holds.
Inductive hypothesis:
Assume that P(x), P(y) are true for some arbitrary
x, y ∈ S.
Inductive step:
We want to prove that P(x + y) is true.
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
Base cases (x = 6 , x = 15): x + y ∈ S.
3|6 so P(6) holds, and 3|15 so P(15) holds.
Inductive hypothesis:
Assume that P(x), P(y) are true for some arbitrary
x, y ∈ S.
Inductive step:
We want to prove that P(x + y) is true.
By the inductive hypothesis, 3|x and 3|y , so x = 3i and
y = 3j for some i, j ∈ ℤ .
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
Base cases (x = 6 , x = 15): x + y ∈ S.
3|6 so P(6) holds, and 3|15 so P(15) holds.
Inductive hypothesis:
Assume that P(x), P(y) are true for some arbitrary
x, y ∈ S.
Inductive step:
We want to prove that P(x + y) is true.
By the inductive hypothesis, 3|x and 3|y , so x = 3i and
y = 3j for some i, j ∈ ℤ . Therefore,
x + y = 3i + 3j = 3(i + j) so 3|(x + y).
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
Base cases (x = 6 , x = 15): x + y ∈ S.
3|6 so P(6) holds, and 3|15 so P(15) holds.
Inductive hypothesis:
Assume that P(x), P(y) are true for some arbitrary
x, y ∈ S.
Inductive step:
We want to prove that P(x + y) is true.
By the inductive hypothesis, 3|x and 3|y , so x = 3i and
y = 3j for some i, j ∈ ℤ . Therefore,
x + y = 3i + 3j = 3(i + j) so 3|(x + y). Hence,
P(x + y) is true.
15
Prove that every x ∈ S is divisible by 3
Let P(x) be 3|x. Define S by
We will show that P(x) is true for every x ∈ S by Basis: 6 ∈ S, 15 ∈ S.
structural induction. Recursive: if x, y ∈ S, then
Base cases (x = 6 , x = 15): x + y ∈ S.
3|6 so P(6) holds, and 3|15 so P(15) holds.
Inductive hypothesis:
Assume that P(x), P(y) are true for some arbitrary
x, y ∈ S.
Inductive step:
We want to prove that P(x + y) is true.
By the inductive hypothesis, 3|x and 3|y , so x = 3i and
y = 3j for some i, j ∈ ℤ . Therefore,
x + y = 3i + 3j = 3(i + j) so 3|(x + y). Hence,
P(x + y) is true.
The result follows for all x ∈ S by structural induction.
15
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Define Σ∗ by
Basis: ε ∈ Σ∗ .
Recursive:
if w ∈ Σ∗ and a ∈ Σ,
then wa ∈ Σ∗
Length
𝗅𝖾𝗇(ε) = 0
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Concatenation
x∙ε= x
x ∙ (wa) = (x ∙ w)a
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Define Σ∗ by
What object (x or y) to do structural induction on?
Basis: ε ∈ Σ∗ .
Recursive:
if w ∈ Σ∗ and a ∈ Σ,
then wa ∈ Σ∗
Length
𝗅𝖾𝗇(ε) = 0
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Concatenation
x∙ε= x
x ∙ (wa) = (x ∙ w)a
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
then wa ∈ Σ∗
Length
𝗅𝖾𝗇(ε) = 0
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Concatenation
x∙ε= x
x ∙ (wa) = (x ∙ w)a
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
Base case (y = ε): then wa ∈ Σ∗
For every x ∈ Σ∗ , 𝗅𝖾𝗇(x ∙ ε) = 𝗅𝖾𝗇(x) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(ε) since Length
𝗅𝖾𝗇(ε) = 0. So P(ε) is true. 𝗅𝖾𝗇(ε) = 0
𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Concatenation
x∙ε= x
x ∙ (wa) = (x ∙ w)a
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
Base case (y = ε): then wa ∈ Σ∗
For every x ∈ Σ∗ , 𝗅𝖾𝗇(x ∙ ε) = 𝗅𝖾𝗇(x) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(ε) since Length
𝗅𝖾𝗇(ε) = 0. So P(ε) is true. 𝗅𝖾𝗇(ε) = 0
Inductive hypothesis: 𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Assume that P(w) is true for some arbitrary w ∈ Σ∗ . Concatenation
x∙ε= x
x ∙ (wa) = (x ∙ w)a
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
Base case (y = ε): then wa ∈ Σ∗
For every x ∈ Σ∗ , 𝗅𝖾𝗇(x ∙ ε) = 𝗅𝖾𝗇(x) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(ε) since Length
𝗅𝖾𝗇(ε) = 0. So P(ε) is true. 𝗅𝖾𝗇(ε) = 0
Inductive hypothesis: 𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Assume that P(w) is true for some arbitrary w ∈ Σ∗ . Concatenation
x∙ε= x
Inductive step: x ∙ (wa) = (x ∙ w)a
We want to prove that P(wa) is true for every a ∈ Σ.
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
Base case (y = ε): then wa ∈ Σ∗
For every x ∈ Σ∗ , 𝗅𝖾𝗇(x ∙ ε) = 𝗅𝖾𝗇(x) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(ε) since Length
𝗅𝖾𝗇(ε) = 0. So P(ε) is true. 𝗅𝖾𝗇(ε) = 0
Inductive hypothesis: 𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Assume that P(w) is true for some arbitrary w ∈ Σ∗ . Concatenation
x∙ε= x
Inductive step: x ∙ (wa) = (x ∙ w)a
We want to prove that P(wa) is true for every a ∈ Σ.
Let a ∈ Σ and x ∈ Σ∗ be arbitrary. Then
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
Base case (y = ε): then wa ∈ Σ∗
For every x ∈ Σ∗ , 𝗅𝖾𝗇(x ∙ ε) = 𝗅𝖾𝗇(x) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(ε) since Length
𝗅𝖾𝗇(ε) = 0. So P(ε) is true. 𝗅𝖾𝗇(ε) = 0
Inductive hypothesis: 𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Assume that P(w) is true for some arbitrary w ∈ Σ∗ . Concatenation
x∙ε= x
Inductive step: x ∙ (wa) = (x ∙ w)a
We want to prove that P(wa) is true for every a ∈ Σ.
Let a ∈ Σ and x ∈ Σ∗ be arbitrary. Then
𝗅𝖾𝗇(x ∙ wa) = 𝗅𝖾𝗇((x ∙ w)a) by defn of ∙
= 𝗅𝖾𝗇(x ∙ w) + 1 by defn of 𝗅𝖾𝗇
= 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(w) + 1 by IH
= 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(wa) by defn of 𝗅𝖾𝗇
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
Base case (y = ε): then wa ∈ Σ∗
For every x ∈ Σ∗ , 𝗅𝖾𝗇(x ∙ ε) = 𝗅𝖾𝗇(x) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(ε) since Length
𝗅𝖾𝗇(ε) = 0. So P(ε) is true. 𝗅𝖾𝗇(ε) = 0
Inductive hypothesis: 𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Assume that P(w) is true for some arbitrary w ∈ Σ∗ . Concatenation
x∙ε= x
Inductive step: x ∙ (wa) = (x ∙ w)a
We want to prove that P(wa) is true for every a ∈ Σ.
Let a ∈ Σ and x ∈ Σ∗ be arbitrary. Then
𝗅𝖾𝗇(x ∙ wa) = 𝗅𝖾𝗇((x ∙ w)a) by defn of ∙
= 𝗅𝖾𝗇(x ∙ w) + 1 by defn of 𝗅𝖾𝗇
= 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(w) + 1 by IH
= 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(wa) by defn of 𝗅𝖾𝗇
So 𝗅𝖾𝗇(x ∙ wa) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(wa) for all x ∈ Σ∗ , and P(wa) is true.
16
Prove 𝗅𝖾𝗇(x ∙ y) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(y) for all x, y ∈ Σ∗
Let P(y) be ∀x ∈ Σ∗ . 𝗅 𝖾 𝗇 (x ∙ y) = 𝗅 𝖾 𝗇 (x) + 𝗅 𝖾 𝗇 (y) . Define Σ∗ by
We will show that P(y) is true for every y ∈ Σ∗ by structural Basis: ε ∈ Σ∗ .
induction. Recursive:
if w ∈ Σ∗ and a ∈ Σ,
Base case (y = ε): then wa ∈ Σ∗
For every x ∈ Σ∗ , 𝗅𝖾𝗇(x ∙ ε) = 𝗅𝖾𝗇(x) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(ε) since Length
𝗅𝖾𝗇(ε) = 0. So P(ε) is true. 𝗅𝖾𝗇(ε) = 0
Inductive hypothesis: 𝗅𝖾𝗇(wa) = 𝗅𝖾𝗇(w) + 1
Assume that P(w) is true for some arbitrary w ∈ Σ∗ . Concatenation
x∙ε= x
Inductive step: x ∙ (wa) = (x ∙ w)a
We want to prove that P(wa) is true for every a ∈ Σ.
Let a ∈ Σ and x ∈ Σ∗ be arbitrary. Then
𝗅𝖾𝗇(x ∙ wa) = 𝗅𝖾𝗇((x ∙ w)a) by defn of ∙
= 𝗅𝖾𝗇(x ∙ w) + 1 by defn of 𝗅𝖾𝗇
= 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(w) + 1 by IH
= 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(wa) by defn of 𝗅𝖾𝗇
So 𝗅𝖾𝗇(x ∙ wa) = 𝗅𝖾𝗇(x) + 𝗅𝖾𝗇(wa) for all x ∈ Σ∗ , and P(wa) is true.
The result follows for all y ∈ Σ∗ by structural induction.
16
⌈t⌉+ 1
Prove |t| ≤ 2 − 1 for every rooted binary tree t
Define S by
Basis: ∙ ∈ S.
Recursive:
if L, R ∈ S, then
𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size
|∙|= 1
|𝖳𝗋𝖾𝖾(∙, L, R)| =
1 + |L| + |R|
Height
⌈∙⌉ = 0
⌈𝖳𝗋𝖾𝖾(∙, L, R))⌉ =
1 + max(⌈L⌉, ⌈R⌉
17
⌈t⌉+ 1
Prove |t| ≤ 2 − 1 for every rooted binary tree t
Let P(t) be |t| ≤ 2⌈t⌉+ 1 − 1. Define S by
We will show that P(t) is true for every t ∈ S by structural induction. Basis: ∙ ∈ S.
Recursive:
if L, R ∈ S, then
𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size
|∙|= 1
|𝖳𝗋𝖾𝖾(∙, L, R)| =
1 + |L| + |R|
Height
⌈∙⌉ = 0
⌈𝖳𝗋𝖾𝖾(∙, L, R))⌉ =
1 + max(⌈L⌉, ⌈R⌉
17
⌈t⌉+ 1
Prove |t| ≤ 2 − 1 for every rooted binary tree t
Let P(t) be |t| ≤ 2⌈t⌉+ 1 − 1. Define S by
We will show that P(t) is true for every t ∈ S by structural induction. Basis: ∙ ∈ S.
Recursive:
Base case (t = ∙ ): if L, R ∈ S, then
| ∙ | = 1 = 21 − 1 = 20+ 1 − 1 = 2⌈∙⌉+ 1 − 1 so P(∙) is true. 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Size
|∙|= 1
|𝖳𝗋𝖾𝖾(∙, L, R)| =
1 + |L| + |R|
Height
⌈∙⌉ = 0
⌈𝖳𝗋𝖾𝖾(∙, L, R))⌉ =
1 + max(⌈L⌉, ⌈R⌉
17
⌈t⌉+ 1
Prove |t| ≤ 2 − 1 for every rooted binary tree t
Let P(t) be |t| ≤ 2⌈t⌉+ 1 − 1. Define S by
We will show that P(t) is true for every t ∈ S by structural induction. Basis: ∙ ∈ S.
Recursive:
Base case (t = ∙ ): if L, R ∈ S, then
| ∙ | = 1 = 21 − 1 = 20+ 1 − 1 = 2⌈∙⌉+ 1 − 1 so P(∙) is true. 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Inductive hypothesis: Size
|∙|= 1
Assume that P(L) and P(R) are true for some arbitrary L, R ∈ S.
|𝖳𝗋𝖾𝖾(∙, L, R)| =
1 + |L| + |R|
Height
⌈∙⌉ = 0
⌈𝖳𝗋𝖾𝖾(∙, L, R))⌉ =
1 + max(⌈L⌉, ⌈R⌉
17
⌈t⌉+ 1
Prove |t| ≤ 2 − 1 for every rooted binary tree t
Let P(t) be |t| ≤ 2⌈t⌉+ 1 − 1. Define S by
We will show that P(t) is true for every t ∈ S by structural induction. Basis: ∙ ∈ S.
Recursive:
Base case (t = ∙ ): if L, R ∈ S, then
| ∙ | = 1 = 21 − 1 = 20+ 1 − 1 = 2⌈∙⌉+ 1 − 1 so P(∙) is true. 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Inductive hypothesis: Size
|∙|= 1
Assume that P(L) and P(R) are true for some arbitrary L, R ∈ S.
|𝖳𝗋𝖾𝖾(∙, L, R)| =
Inductive step: 1 + |L| + |R|
We want to prove that P(𝖳𝗋𝖾𝖾(∙, L, R)) is true. Height
⌈∙⌉ = 0
⌈𝖳𝗋𝖾𝖾(∙, L, R))⌉ =
1 + max(⌈L⌉, ⌈R⌉
17
⌈t⌉+ 1
Prove |t| ≤ 2 − 1 for every rooted binary tree t
Let P(t) be |t| ≤ 2⌈t⌉+ 1 − 1. Define S by
We will show that P(t) is true for every t ∈ S by structural induction. Basis: ∙ ∈ S.
Recursive:
Base case (t = ∙ ): if L, R ∈ S, then
| ∙ | = 1 = 21 − 1 = 20+ 1 − 1 = 2⌈∙⌉+ 1 − 1 so P(∙) is true. 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Inductive hypothesis: Size
|∙|= 1
Assume that P(L) and P(R) are true for some arbitrary L, R ∈ S.
|𝖳𝗋𝖾𝖾(∙, L, R)| =
Inductive step: 1 + |L| + |R|
We want to prove that P(𝖳𝗋𝖾𝖾(∙, L, R)) is true. Height
|𝖳𝗋𝖾𝖾(∙, L, R)| = 1 + |L| + |R| by defn of || ⌈∙⌉ = 0
≤ 1 + (2⌈L⌉+ 1 − 1) + (2⌈R⌉+ 1 − 1) by IH ⌈𝖳𝗋𝖾𝖾(∙, L, R))⌉ =
≤ 2⌈L⌉+ 1 + 2⌈R⌉+ 1 − 1 algebra 1 + max(⌈L⌉, ⌈R⌉
≤ 2(2max(⌈L⌉,⌈R⌉)+ 1 ) − 1 by defn of max
= 2(2⌈𝖳𝗋𝖾𝖾(∙,L,R)⌉ ) − 1 by defn of ⌈⌉
= 2⌈𝖳𝗋𝖾𝖾(∙,L,R)⌉+ 1 − 1 which is the desired result.
17
⌈t⌉+ 1
Prove |t| ≤ 2 − 1 for every rooted binary tree t
Let P(t) be |t| ≤ 2⌈t⌉+ 1 − 1. Define S by
We will show that P(t) is true for every t ∈ S by structural induction. Basis: ∙ ∈ S.
Recursive:
Base case (t = ∙ ): if L, R ∈ S, then
| ∙ | = 1 = 21 − 1 = 20+ 1 − 1 = 2⌈∙⌉+ 1 − 1 so P(∙) is true. 𝖳𝗋𝖾𝖾(∙, L, R) ∈ S
Inductive hypothesis: Size
|∙|= 1
Assume that P(L) and P(R) are true for some arbitrary L, R ∈ S.
|𝖳𝗋𝖾𝖾(∙, L, R)| =
Inductive step: 1 + |L| + |R|
We want to prove that P(𝖳𝗋𝖾𝖾(∙, L, R)) is true. Height
|𝖳𝗋𝖾𝖾(∙, L, R)| = 1 + |L| + |R| by defn of || ⌈∙⌉ = 0
≤ 1 + (2⌈L⌉+ 1 − 1) + (2⌈R⌉+ 1 − 1) by IH ⌈𝖳𝗋𝖾𝖾(∙, L, R))⌉ =
≤ 2⌈L⌉+ 1 + 2⌈R⌉+ 1 − 1 algebra 1 + max(⌈L⌉, ⌈R⌉
≤ 2(2max(⌈L⌉,⌈R⌉)+ 1 ) − 1 by defn of max
= 2(2⌈𝖳𝗋𝖾𝖾(∙,L,R)⌉ ) − 1 by defn of ⌈⌉
= 2⌈𝖳𝗋𝖾𝖾(∙,L,R)⌉+ 1 − 1 which is the desired result.
The result follows for all t ∈ S by structural induction.
17
Summary
To define a set recursively, specify its basis and recursive step.
Recursive set definitions assume the exclusion rule.
We use recursive functions to operate on elements of recursive sets.
Use structural induction to prove properties of recursive structures.
Structural induction follows from ordinary induction but is easier to use.
To prove ∀x ∈ S. P(x) using structural induction:
Show that P holds for the elements in the basis step of S.
Assume P for every existing element of S named in the recursive step.
Prove P for every new element of S created in the recursive step.
18