# Induction by pengxuebo

VIEWS: 68 PAGES: 20

• pg 1
```									Induction

Example: the language of palindromes PAL over
{a,b}
PAL  | a | b | aPALa | bPALb
Example: the natural numbers
0  N; if n  N then n+1 N
Mathematicians call definitions like these inductive
definitions
Computer Scientists call them recursive definitions
Stack data structure

EmptyStack is a stack
Push(o,s) is a stack provided s is a stack and o is an
object that can be pushed onto a stack
Tree data structure

EmptyTree is a tree
Leaf(name) is a tree if name is a name
Tree(name, t1,t2) is a tree if t1 and t2 are trees and
name is a name
Factorial function

factorial(0) = 1
factorial(n) = n * factorial(n-1) if n > 0
Proof by Induction

Three stages
• basis
• induction step(s)
• conclusion
Proof by Induction – 1. prove that the
property holds for the basis

Example: for the language PAL, prove the property
is true for ,a, b
For the natural numbers, prove it is true for 0 (or 1)
For the stack data structures, prove it is true for
EmptyStack
Proof by Induction – 2. induction step(s)

Prove that if the property is true for any objects
formed using k or fewer applications of the rules
in your inductive definition, then that fact
guarantees it will be true for an object formed
using k+1 applications of your rules
Example: proving a property of natural numbers,
need to prove that
if the property is true for any k  N,
then it is also true for k+1
Proof by Induction – 2. induction step(s)

Example: proving a property of the palindromes
over {a,b} - PAL - prove that if the property is
true for every PAL derived using k or fewer
applications of the grammar rules, then it is also
true for aPALa and for bPALb
Example: proving a property of stacks, prove that
if the property is true for all stacks s constructed
using k or fewer applications of push, then it is
also true for push(o,s)
Proof by Induction – 3. conclusion

Having proved the basis(s)
and the induction step(s),
conclude that the property holds for every element
of the set.
A Proof by Induction over N

A set of n elements has 2n subsets
Basis: If n = 0, the only set containing 0 elements is
, which has one subset; but 20 = 1, which
establishes the basis.
A Proof by Induction over N (continued)

Induction step: Suppose that every k element set has
2k subsets. We need to show that
(|A| = k)  (|PA| = 2k) guarantees that
(|A| = k+1)  (|PA| = 2k+1)
Let A = B  {a}, where a  B and |B| = k
PA = {S | S  A, a  S}  {S | S  A, a S}
= {T  {a}|T  B}  {T| T  B}
So | PA| = | PB| + | PB| = 2k + 2k = 2k+1
Which completes the induction step
A Proof by Induction - the conclusion

We have established the basis; if a set contains 0
elements then it has 20 subsets
And we’ve proved the induction step; if every k-
element set has 2k subsets, then every k+1-
element set has 2k+1 subsets
So we can now conclude that every set with n
elements has 2n subsets
Induction again

Consider the inductive definition of A*:
  A*, if a  A and b  A* then ab  A*
And the inductive definition of the length function,
len:A*  N, len()=0,if a  A and b  A* then
len(ab) =1+len(b)
And concatenation,
cat: A*  A*  A*, if a  A*, cat(,a)=a,
if b, g  A*, cat(ab,g) = a(cat(b,g))
Prove by induction that
cat(,b) = cat(b,) = b

Basis: cat (,) =  = cat(,)
Induction step:
Assume cat(,b) = cat(b,) if len(b)  k
Suppose len(b)  k
cat(,ab) = ab= a(cat(,b))
= a(cat(b,)), since len(b)  k = cat(ab,)
which proves the induction step
So we can conclude that
cat(,b) = cat(b,) = b
Prove by induction that
cat(a,cat(b,g)) = cat(cat(a,b),g)

Basis: cat(,cat(b,g)) = cat(b,g) = cat(cat(,b),g)
Induction step: Assume cat(a, cat(b,g)) =
cat(cat(a,b),g) if len(a)  k
Suppose len(a)  k
cat(aa, cat(b,g)) = a(cat(a, cat(b,g)))
= a(cat(cat(a,b),g)), since len(a)  k
= cat(a(cat(a,b)),g)= cat(cat(aa,b),g)
which proves the induction step
Conclusion: cat(a,cat(b,g)) = cat(cat(a,b),g)
Prove by induction that
len(cat(a,b)) = len(a) + len(b)

Basis: cat(,a)=a, so len(cat(,a))=len(a)
=0+len(a)=len()+len(a)
Induction step: Assume that if len(b)  k, then
len(cat(b,g)) = len(b) + len(g)
Let b  A* with len(b)  k; cat(ab,g) = a(cat(b,g))
so len(cat(ab,g)) = len(a(cat(b,g)))
= 1 + len(cat(b,g)) = 1 + len(b) + len(g),
since len(b)  k = len(ab) + len(g)
which proves the induction step
Conclusion: len(cat(a,b)) = len(a) + len(b)
The Principle of Complete Induction

In order to prove a property P(n) for all
n  N, it is sufficient to prove
Basis: P(0) is true
Induction step: If P(j) is true for all
j  k then this guarantees the truth of P(k+1)
Notice the new form taken by the induction step.
The grammar L   | a | b | aLa | bLb
generates all the palindromes over {a,b}

Basis: The palindromes of length 0 and 1 over {a,b}
are
, which is generated by L  
a, generated by L  a
b, generated by L  b
so the grammar generates the palindromes of
lengths 0 and 1 over {a,b}
This establishes the basis.
The grammar L   | a | b | aLa | bLb
generates all the palindromes over {a,b}

Induction step
Assume the grammar generates all the palindromes
of length  k, where k 1
Let a be a palindrome of length k+1 over {a,b}
a either begins and ends with a, or it begins and
ends with b
Suppose a = aba
Then b must be a palindrome with |b|< |a|
so by the induction hypothesis, the grammar
generates b
The grammar L   | a | b | aLa | bLb
generates all the palindromes over {a,b}

Induction step (continued)
Now this means that L *b (that is, we can form a
sequence L,...,bwhere each element of the
sequence is obtained from its predecessor by
replacing a nonterminal by the right side of an
appropriate rule)
But the grammar includes the rule L  aLa; this
means that L  aba, so it generates a
which proves the induction step
Conclusion: the grammar generates all palindromes
over {a,b}

```
To top