Download n - i-Mathematics

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Corecursion wikipedia , lookup

Transcript
Lecture 6
To apply the Principle of Mathematical
Induction
To solve the Towers of Hanoi puzzle
To define a recurrence relation
RMIT University; Taylor's College
1
Mathematical Induction
 Suppose we have a mathematical
proposition, P(n), about some
integers n.
 We want to know if P(n) is true for
every integer n, from a starting point
onwards.
RMIT University; Taylor's College
2
Mathematical Induction
Example:
Prove that n! > 2n is true for all in positive integer n
Is this sometimes true, never true, always true after a
certain point, or what?
Check some
values:
n!
2n
n=0
1
1
n=1
1
2
n=2
2
4
n=3
6
8
n=4
24
16
n=5
120
32
How could we prove n! > 2n? The idea is
to use Proof by Induction.
At this stage, n! seems to be streaking ahead of
2n at a great rate.
RMIT University; Taylor's College
3
Proof by Induction: 3 Steps
1. Base step: With a starting point n0,
Verify that P(n0) is true.
2. Inductive step: Assume that P(k) is
true, prove that P(k + 1) is also true.
3. Conclusion: Declare that P(n) is true
for every integer n ≥ n0
RMIT University; Taylor's College
4
Example:
Prove by induction that n! > 2n for all n ≥ 4.
Base Step: Verify that P(4) is true.
𝑛=4
LHS = 4! = 24
RHS = 24 = 16
Since 24 > 16,
n! > 2n is true when 𝑛 = 4.
RMIT University; Taylor's College
5
Example:
Prove by induction that n! > 2n for all n ≥ 4.
 Inductive Step:
Assume P(k) : k! > 2k is true.
Prove that P(k + 1): (k + 1)! > 2k+1 is true.
LHS
= 𝑘 + 1 !
= 𝑘 + 1 𝑘 !
RHS
Conclusion:
= 2𝑘+1
= 2 2𝑘
Note that 𝑛 ≥ 4, so 𝑘 + 1 ≥ 5, then 𝑘 + 1 > 2.
∴ P(k + 1): (k + 1)! > 2k+1 is true
n! > 2n for all n ≥ 4.
6
Example:
1
Prove that 1 + 2 + 3 + … + 𝑛 = 𝑛(𝑛 + 1) for
2
every positive integer n.
Base step: Verifying P(1),
𝑛=1
𝐿𝐻𝑆
= 1
𝑅𝐻𝑆
1
= ×1×2
2
=1
∴ 𝑃 𝑛 𝑖𝑠 𝑡𝑟𝑢𝑒 𝑤ℎ𝑒𝑛 𝑛 = 1.
7
Example:
1
Prove that 1 + 2 + 3 + … + 𝑛 = 𝑛(𝑛 + 1) for
2
every positive integer n.
Inductive step:
1
Assume P(k): 1 + 2 + 3 + … + 𝑛 = 2 𝑘 𝑘 + 1 is true.
Prove that P(k + 1) is also true.
LHS
= 1 + 2 + …+ 𝑘 + 𝑘 + 1
1
= 𝑘 𝑘 + 1 + 𝑘+1
2
1
= 𝑘+1
𝑘+1
2
𝑘+2
= 𝑘+1
2
1
= 𝑘+1 𝑘+2
2
RHS
1
= 𝑘+1 𝑘+1 +1
2
1
= 𝑘+1 𝑘+2
2
8
Example:
1
Prove that 1 + 2 + 3 + … + 𝑛 = 𝑛(𝑛 + 1) for
2
every positive integer n.
Conclusion:
The statement
1 + 2 + 3 + …+ 𝑛 =
1
𝑛(𝑛 + 1)
2
is true for every positive integer n.
RMIT University; Taylor's College
9
The Towers of Hanoi
 We need to move all n discs to Pole 3. But we can only
move 1 disc at a time, and a disc must never be placed
on a smaller disc.
 Theorem: This can be solved for all n ≥ 1

Proof: We can use proof by induction
RMIT University; Taylor's College
10
The Towers of Hanoi: Proof

Base step


Inductive step







Suppose we have 1 disc. Pick it up and put it on Pole 3
Suppose we can move (k – 1) discs. ----- (*)
We want to show we can move k discs.
Given k discs, leave the big one at the bottom. Move the other
(k – 1) to Pole 2 instead of Pole 3. (We know this can be done,
by the inductive hypothesis (*))
Move the big disc to Pole 3.
Move the other stack from Pole 2 to Pole 3 (Again, we know
this can be done, by (*).)
We’ve moved the stack of k discs!
Conclusion

For all n, the problem can be solved.
RMIT University; Taylor's College
11
The Towers of Hanoi

How many moves (1 disc at a time) are needed to get the
stack of n discs from Pole 1 to Pole 3? Let this number be fn.

So f1 = 1. (That is, if we only have 1 disc then a single move
takes it to Pole 3.)

Let’s look at the inductive proof that the puzzle can always be
solved. When n = k, fk moves are needed.

So what happens when n = k + 1? The number of moves
needed is fk+1, but this can be expressed in terms of fk.

It takes fk moves to get the top k discs to Pole 2, then 1 move
to get the bottom disc to Pole 3, and then fk moves to get the
stack of k discs from Pole 2 and put it on top of the biggest
disc which is now on Pole 3.
RMIT University; Taylor's College
12
The Towers of Hanoi
 So fk+1 = fk + 1 + fk, i.e. fk + 1 = 2fk + 1
 This equation is an example of a recurrence
relation, where each value of a function can be
determined from previous values (assuming
that we know some initial values).
 Using n instead of k, we have fn+1 = 2fn + 1
with initial condition f1 = 1.
RMIT University; Taylor's College
13
The Towers of Hanoi
We can then construct the following partial table.
n
fn
1
1
2
3
f2 = 2f1 + 1 = 2 + 1 =3
3
7
f3 = 2f2 + 1 = 6 + 1 = 7
4
15
5
31
6
63
RMIT University; Taylor's College
14
The Towers of Hanoi
 But suppose we want to know how many moves are
needed to shift 100 discs. We would need to compute
all the values from f7 up to f99, and then use
f100 = 2f99 + 1
to get the value of f100.
 Clearly it would be better if we had a formula for fn
which only depended on n, rather than on earlier
values of the function.
 Such a formula is called a solution to the recurrence
relation.
 We won’t give a general method for solving
recurrence relations, but rather we’ll look at how to
obtain a solution for this particular example.
RMIT University; Taylor's College
15
The Towers of Hanoi


Do the values in the second column of the table look familiar?
If not, let’s add 1 to every value and also put in some more rows.
n
fn
fn + 1
1
1
2
2
3
4
3
7
8
4
15
16
5
31
32
6
63
64
7
127
128
8
255
256
9
511
512
19
1023
1024
Now it should be clear that the new last column
consists of all the powers of 2 with positive
exponent.
Specifically, fn + 1 = 2n.
Subtracting 1 from both sides gives fn = 2n – 1.
It can be formally proved that this formula gives
the correct answer. (We omit the details.)
RMIT University; Taylor's College
16
The Towers of Hanoi
 Our reasoning here is an example of inductive
reasoning, where we study enough examples
to be able to hypothesize a general result.
 Note that f100 = 2100 – 1, which is a rather big
number!
 264 – 1 = 18, 446, 744, 073, 709, 551, 615
moves!
RMIT University; Taylor's College
17