Download Induction - Computing Science and Mathematics

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

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

Document related concepts

Karhunen–Loève theorem wikipedia, lookup

Collatz conjecture wikipedia, lookup

Transcript
Induction
Induction
• Induction is the name given to a problem
solving technique based on
using the solution to small instances of a
problem to solve larger
instances of a problem.
In fact we can solve problems of arbitrary size.
Size
• We need to measure the "size" of an instance of a
problem.
E.g. with matchstick problems, we might call the size
the number of matches.
It is not always obvious what the size should be for
some types of problems.
We will see some examples later.
The size must be non – negative i..e whole numbers 0,
1, 2, …
We call these numbers "natural numbers", as they are
naturally used
for counting.
Zero
Note that some mathematicians do not include 0 in
the natural numbers.
There are good reasons why we should include 0.
Zero has important significance in maths (and the
history of maths).
One reason in when counting the size of sets, the
null set is defined
to have size of 0.
We shall see examples of including 0 later.
Two step process.
• Two step process.
We solve the problem in two steps.
First we solve the problem instance of size 0 (not size 1).
This is usually very easy (often called trivial).
Second, we show how to solve, a problem of size n+1
(where n is an
arbitrary natural number), given we have a solution to a
problem
instance of size n.
i.e. we can solve problems of a size greater by 1.
The first step is called the base case of the basis of
induction.
The second step is the induction step.
Sizes 0, 1, 2, …
•
By this process, we can solve problems of size 0.
We also know how to solve instances of size 1 (as
it is one larger than 0)
We can apply the induction step to solve
problems of size 2 and so on.
i.e. the induction step allows us to solve problems
of size one
greater than the current size problem.
By repeating this process we can solve problems
of any size.
Problem statement – cutting the
plane.
•
Straight lines are drawn across a sheet of
paper, dividing the paper up
into regions.
Show that it is possible to colour each region
black or white, so that
no two adjacent regions have the same colour.
(draw the scenario on board) p86 of book.
Outline
•
The number of lines can be the size of a problem.
We have to show how to solve the problem when
there are zero lines.
We have to show how to solve a problem when
there are n+1 lines,
assuming we can solve the problem with n lines.
Let us call the situation when no two adjacent
regions have the same
colouring "a satisfactory colouring"
Zero case (base case)
•
This is trivial.
With 0 lines, there is one region.
This can be coloured black or white and will be
a satisfactory colouring.
Induction step
•
Assume a number of lines are drawn on the paper, and
the regions have
a satisfactory colouring.
Now add an additional line (draw on board).
This will divide some existing regions into two new
regions,
Which will have the same colour, therefore the
colouring is not satisfactory.
The task is to show how to modify the colouring so
that it does
become satisfactory.
The key, or the trick.
• The key, or the trick.
Inverting any satisfactory colouring will also give a
satisfactory colouring.
i.e. changing black regions for white, and vice versa will also
give
be satisfactory)
Let us call the two sides of the new line left and right.
Inverting colours in either region will still give a satisfactory
colouring in that half (left or right).
Hence, inverting the colours in one half will guarantee a
satisfactory
colouring for the whole piece of paper.
Non- deterministic
•
The algorithm for colouring is non deterministic in several
ways.
1. the initial colouring is not specified (could be black or
white).
2. the ordering of the lines is unspecified (a bit like the
abstraction stage with the chocolate bar).
3. the naming of the left and right regions is not
specified (symmetry).
This mean the final colouring can be arrived at in different
ways, but
it is guaranteed to be satisfactory.
Triominoes – problem statement.
•
A square piece of paper is divided into a grid of
size 2^n by 2^n,
where n is a natural number. Individual squares
are called grid
squares. One grid square is covered. A triomino is
an "L" shape made
of 3 gird squares. Show that it is possible to cover
the remaining grid
squares.
Try this yourself if you like.
Size and Base case
•
The obvious size is n.
The base case is when n=0, and the grid has
size 1 by 1.
This square will of course be covered.
The base case is solved.
Inductive Step
•
Given a gird of 2^(n+1) by 2^(n+1).
Given that we know how to cover a 2^n by
2^n grid,
how do we use this to help us cover a gird size
larger by one.
We make the inductive hypothesis that this is
possible.
The key
•
A grid of size 2^(n+1) by 2^(n+1) can be divided
into 4 girds of size
2^n by 2^n.
By drawing horizontal and vertical lines.
These 4 regions can be called bottom-left,
bottom-right, top-left and
top-right.
One square is already covered,
We may assume this is bottom left – why?
Induction 2
The bottom left grid is of size 2^n by 2^n, of which one square has
already been covered.
By the induction hypothesis, the remaining square in the bottomleft
grid can be covered.
This leaves us having to cover the remaining 3 grids.
None of these have any squares covered.
We can apply the inductive hypothesis if just one of the squares in
each of the 3 remaining grids is covered.
This can be done by placing a triomino at the junction of the 3 grids.
This tells us how the task can be done.
If 1 was the base case.
•
What if we had chosen n = 1 to be our base case?
This is also easy to do. How?
However, our proof has then left out the 0 case,
so we would still
need to prove that separately.
However including 0 provides a slightly deeper
insight.
"Humans" start counting at 1,
Computer Scientists and mathematicians start
counting at 0
6.4 Looking for patterns
•
Induction used in experimental sciences,
refers to the process of
getting general laws by collecting a set of
observed data (think of
Newton and Galileo)
In simple terms, induction is about looking for
patterns.
Laws of Nature
•
Laws based on the process of observation
introduce new knowledge.
In experimental sciences, these laws are only
probably true.
They are tested by prediction and discarded if
the predictions are false.
Deduction
•
In contrast, deduction in the process of inferring
laws from existing laws.
Deductions are guaranteed to be true provided
the laws on which they
are based are true.
(and the deductive process is sound).
These laws add nothing new, in some sense, and
are simply
reformulations of existing laws (can you think of
any examples).
Mathematical Induction
•
Mathematical induction is a combination of induction
and deduction.
It is a process of looking for patterns, making a
conjecture about patterns,
And then testing if the conjecture can be deduced from
existing knowledge.
Guess and verify is a summary of mathematical
induction.
Guessing the formula is a conjecture.
Verification is the process of deducing if the guess is
correct.
Matchsticks again
•
Remember the game where we could remove 1 or 2
matches.
We "discovered" that piles containing 0, 3, 6, matches are
losing positions.
Other positions (1, 2, 4, 5, 7, 8) are winning positions.
There seems to be a pattern.
Losing positions are a multiple of 3, winning positions are
not.
This is a conjecture about all positions from observations
made on
just 9 positions.
We can verify this conjecture by using mathematical
induction.
Size
•
We could measure size by the number of matches.
Let us measure size as the number of matches divided
by 3, rounded
down to the nearest natural number.
i.e. a pile of 0, 1, 2 has size 0; a pile of 3, 4, 5, has size 1
The inductive hypothesis therefore is, a pile of 3n
matches is a
losing position, and a pile of 3n+1 or 3n+2 is a winning
position.
Basis
•
The base case for induction is when n equals
0.
A pile of 0 matches is a losing position. i.e. we
cannot move.
A pile of 1 or 2 matches is a winning position.
Inductive step
•
We assume a pile of 3n matches is a losing
position,
And a pile of 3n+1 or 3n+2 matches is a
winning position.
We have to show that a pile of 3(n+1) matches
is a losing position,
And a pile of 3(n+1) + 1 or 3(n=1) + 2 is a
winning position.
Argument 1
•
Suppose there are 3(n+1) matches.
If we remove 1 or 2 matches, we leave 3(n+1)
-1 or 3(n+1) -2 behind.
i.e. leaving 3n+2 or 3n+1 which are wining
positions.
Hence 3(n+1) is a losing position.
Argument 2
•
Suppose there are 3(n+1)+1 or 3(n+1)+2.
By taking 1 match in the first case and 2 in the
second case,
This leaves 3(n+1) matches which is a losing
position!
Hence, 3(n+1)+1 or 3(n+1)+2 are both winning
positions.
6.5 The need for proof
•
It is vital, when using induction, that a conjecture
is properly verified.
It is tempting to generalize from a few cases, to
form a conjecture
which is not true.
Give the example of Fermat’s last theorem –
when do we stop testing?
There is definitely a need for rigorous proof.
Set the dividing circle as an exercise.
Dividing a circle
•
Draw the diagram.
Given n points on the circumference of a circle,
Chords are drawn between points, forming
regions.
The points are chosen so crossing points are
distinct.
How many regions does the connecting lines
divide the circle.
Number of portions
•
The number of portions is 1, 2, 4, 8, …
Suggesting, in general 2^(n-1)
For n=5, we get 16,
However for n=6 we get 31, did we miscount?
Where did we go wrong
•
We should have begun with n=0.
But this would give us ½ regions!
This does not make sense.
Also the case where n=6 is an exception,
WHY?
Correct formula.
•
The correct formula is difficult to prove, but is here for
the sake of
completeness.
(n^4 -6n^3+23n^2-18n+24)/24
This sequence is 1, 2, 4, 8, 16, 31, 57, 99, 163, 256, 386
Just out of interest, how would you attempt to prove
this?
How would you write a Java program to model the
adding of an extra point?
6.6 From Verification to Construction
•
In maths texts, induction is often used to verify
formula.
Verification is fine once we have a formula to
verify,
But we need a formula to verify in the first place.
Induction in computer science is a fundamental
principle in the
construction of computer programs.
Sum kth powers.
•
We want to sum the kth power of the first n
natural numbers.
The formula is (S.n denotes a function)
S.n = 1 + 2 + 3 + …+ n = ½ n(n+1)
We can also do squares and cubes.
Verification is good if we know the answer, but
what if we do not know
the answer.
Creative Process
• Constructing solutions to non trivial problems involves a
creative process.
This means some "guess work" and intelligent input if
required,
And trial and error cannot be completely eliminated.
However, we can reduce the amount of guesswork by
replacing it by
mathematical calculation.
I imagine that there is no general method or algorithm to
solve this
problem in general.
And I can think of cases where it is impossible. Can you?
Closed Formula
• Closed Formula
We can use induction to construct closed
formulae for summations
The idea is to find a pattern, formulate it
mathematically, and then
verify the pattern.
Zero case. Of course we should also consider
the 0 th case.
(can you write this down?)
Guesswork
•
For the sum of 4th powers, we may guess the closed
formula is of the
form of a 5th degree polynomial (called a quintic). We
then use
induction to calculate the coefficients.
This calculation is quite long, so let us just consider 1st
powers.
You may already know how to derive this formula,
But please be patient, as this is just an illustration.
Conjecture
• Conjecture
We make the conjecture that the required form is
a 2nd degree
polynomial (call a quadratic) a+bn+cn^2 and then
calculate the
coefficients a, b, c.
S.n = 1 + 2 + … + n
S.n means the sum of the numbers up to n.
P.n is the proposition
S.n = a + b.n + cn^2
Calculation of a
•
P.0
{definition of P}
S.0 = a + b.0 + c.0^2
{S.0 = 0 i.e. the sum of an empty set of numbers
is zero}
0=a
Thus, the base case has allowed us to deduce
that a=0.
We make the inductive hypothesis that (n<=0 &&
P.n ) == true.
Calculation of b and c
• Calculation of b and c
P.(n+1)
{definition of P, a = 0}
S.(n+1) = b(n+1) + c(n+1)^2
{S(n+1) = S.n + n + 1}
S.n + n + 1 = b(n+1) + c(n+1)^2
{S.n = b(n) + c(n)^2}
b.n + cn^2 + n + 1 = b(n+1) +c(n+1)^2
{arithmetic}
Cn^2 + (b+1)n + 1 = cn^2 + (b+2c)n + b + c
{compare coefficients of powers of n}
c=c && b+1 = b+2c && b + c
{arithmetic}
½ = c && ½ = b
Summary
•
Thus 1 + 2 + …+ n = 0 + ½ n + ½ n^2
We can see how to calculate sums of other powers
from this.
The steps are
1. postulate a summation is a polynomial in n with
degree m+1
2. use induction with the fact S.0 = 0 and S.(n+1) =
S.n + (n+1)^m, to
determine a system of simultaneous equations in the
coefficients.
3. Finally solve the system of equations.
Remark
•
In the case of 1st powers, there is an easy way
to do this.
Can you do it?
It can also be interpreted graphically.
Fake coin detection Introduction
•
Suppose we are given a number of coins, each
identical, at most one is
fake and the others are genuine.
All genuine coins have the same weight,
And the fake coin has a different weight from the
genuine coins.
How can we use a pair of scales to detect the fake
coin?
This problem is not well defined!!! (think about
the business students)
Problem formulation
•
There are 3 possible outcomes when a pair of scales is
used;
The scales may tip left or right or balance.
With n comparisons, there are 3^n different outcomes.
Given m coins, there are 1+2m possible outcomes.
1 possibility is all coins are genuine.
There are 2 ways each of the m coins can be fake.
1+2m = 3^n
If the number of coins m, is greater than ½ (3^n -1), it
is impossible
to find a fake coin if it exists.
Conjecture
•
Given ½ (3^n -1) coins (of which at most one is
fake), it is possible
to identify the fake coin, if it exists, using at most
n comparisons.
n=0, the conjecture is Jtrue
n=1, the conjecture is false!! If we have one coin,
how can we tell if
it is genuine or not, we have nothing to compare
it with.
Modify conjecture. Additional coin
•
Let us modify our conjecture,
Assume we have an additional reference coin,
that we know to be genuine.
The problem is to construct an algorithm,
which will identify the fake
coin (if it exists), or determine all the coins are
genuine.
6.7.2 Problem solution basis
•
With 0 comparisons, we know all the coins in
a collection of ½ (3^0-1)
are genuine,
The base case, n=0 is solved.
Inductive step
•
Let c.n denote ½ (3^n – 1).
By induction, we may assume that a fake coin
(if it exists), can be
found among c.n coins using a maximum of n
comparisons.
We have to show how to find a fake coin
among c(n+1) coins using at
most n+1 comparisons.
First Comparison 1
•
To be able to gain any information from a comparison,
The number of coins on the left and right scales must
be the same.
If the scales balance, then none of the coins on the
scales is fake.
We can then discard these coins, and look at the coins
on the table.
Hence c.n coins must remain on the table as c.n is the
maximum number
of coins among which a fake coin could be detected
with n comparisons.
First Comparison 2
•
This also tells us how many coins to put on the scales
i.e. the difference between c(n+1) and c.n
c(n+1) = 3c.n+1 (by arithmetic)
so, c.(n+1)-c.n = 3^n
This is an odd number, which we cannot put on the
scales,
However we can make this even by using the reference
coin
(which we have in addition to the c(n+1) coins).
We conclude that in the first comparison, c.n+1 coins
should be put on
each side of the scales.