Administrative info
HW1 solution on Piazza
If you are still on the waitlist, you may need to remove yourself
and then re-add the class. Make sure to do so before the deadline!
Question to think about
There is a children's toy that has rings of various sizes that can
be stacked together. However, they only fit properly if they happen
to be stacked in order, with the largest at the bottom and the
smallest on top. So if we have them stacked in the wrong order, we
can remove them all and stack them in the right order.
This gets boring after a while, so suppose instead that we restrict
ourselves to a single move: we can place our hand under any ring and
flip the entire portion of the stack above our hand. We can repeat
this move as many times as we like. Is it always possible to
properly reorder the stack using just this move?
Review
Proof by induction
Map Coloring
We want to color the countries on a map of the world so that no two
adjacent countries have the same color. That would be bad, since we
wouldn't be able to tell what the border was, which could lead to
wars, illegal immigration, etc.
It turns out that if countries are contiguous, only four colors are
required. This was conjectured in 1852, and many proof attempts were
made in the years following, all erroneous. Then in 1976, it was
finally proven with the help of a computer that checked a large
number of cases (~2000) and was hundreds of pages long. However,
this proof wasn't universally accepted, since it required believing
that the computer program was correct. Finally, a human-readable but
still long and difficult proof was published in 1996.
Let's consider a simpler version that doesn't require hundreds of
pages and a computer. Assume that the map is drawn by drawing n
infinite lines in the plane, dividing it into regions. Then only two
colors are required to color the plane such that no two adjacent
regions have the same color. (Two regions are adjacent if they share
a border, not just a point.)
What should we do induction over? The number of regions? The number
of borders? We can't easily break down a map into a simpler map by
just removing one region or border. Instead, we do induction over
the number of lines used to generate the map.
This illustrates that in a real-world (well, kind of) problem, it's
not always obvious how to express it in math and how to prove it.
There may be many ways to do so, some better than others.
Formally, our claim is ∀n∈N . any map generated using n
lines can be colored using two colors.
[Note that there is a second implicit forall in this statement, so
we could actually further refine the mathematical formulation of
this statement. We also have to be careful to show that all maps
with n lines can be colored.]
Proof:
Base case: P(0)
A map with no lines needs only one color.
Inductive hypothesis: Assume P(k).
Inductive step: Prove P(k+1).
Consider an arbitrary map with k+1 lines. Let's remove a line to
create a map with k lines. Then by the inductive hypothesis, we
know that the resulting map can be colored using just two
colors, say red and blue. Now if we consider the k+1 line again,
it passes through some regions of the smaller map and not
others. Pick one side of the line, and on that side, we flip all
the colors, so what was red becomes blue and vice versa. Now
consider any two adjacent regions in the new map.
Case 1: The two regions are both on the side of the line that
did not have its colors swapped. Then they are the same color
as they were in the smaller map, so they still have different
colors.
Case 2: The two regions are both on the side of the line that
had its colors swapped. Then they have opposite colors as they
did in the smaller map, so when their colors were switched,
they still ended up with different colors.
Case 3: The two regions are on different sides of the line.
Then in the smaller map, they were part of the same region,
since the line that divides them now didn't exist. Thus, they
had the same color, but since we switched the colors on one
side of the line, the region that is on that side now has a
different color than the one on the other side. So the two
regions have different colors.
In all cases, the two adjacent regions have different colors, so
this is a valid coloring of the new map. Thus, any map with k+1
lines can be properly colored using this procedure.
Answer to initial question
Induction! [Briefly discuss proof in class, but not repeated here
since it is a common homework problem.]
Proving something stronger
As you know, Cory Hall isn't the prettiest building on campus.
Suppose we secure funding to renovate the courtyard, so we decide to
re-tile using L-shaped tiles. However, we want to leave a hole in
the center for a nice palm tree to provide shade. Can we do so?
Let's formalize the problem. Let's assume that the courtyard is
square; in fact, it's size is 2^n x 2^n for some n, where our tiles
are 2 x 2 with one missing square. Can we tile the courtyard by
leaving a 1 x 1 square hole in the center?
Let's try to prove by induction that we can tile a 2^n x 2^n
courtyard and leave a center hole.
Proof:
Base case: P(1) states that we can tile a 2^2 courtyard with a
hole in the center. But this just takes one tile.
[Side note: what do we actually mean by a "hole in the center?"
Since no square occupies the center, we mean a hole that has a
corner at the center of the courtyard.]
Inductive hypothesis: Assume P(n), i.e. we can tile a 2^n x 2^n
courtyard with a hole in the center.
Inductive step: Consider a 2^(n+1) x 2^(n+1) courtyard. We can
divide it into four smaller 2^n x 2^n courtyards and apply our
inductive hypothesis. However, each subsquare has a hole in the
middle, which we can't fill using our tiles. Furthermore, the
larger courtyard doesn't have a hole in the center either. What
we need instead are four 2^n x 2^n courtyards with holes at
their corners, so we can cover three of the holes with a single
tile and leave the remaining hole, which is now at the center of
the larger courtyard. But our inductive hypothesis does not let
us assume that we can tile a smaller courtyard with a hole at
the corner.
We're stuck! What do we do?
Once again, we are desperate, so let's do something crazy. Let's try
to prove that we can tile a 2^n x 2^n courtyard with a hole wherever
we want.
Proof:
Base case: P(1) states that we can tile a 2^2 courtyard with a
hole in the anywhere. But this just takes one tile, and we can
rotate the tile as needed.
Inductive hypothesis: Assume P(n), i.e. we can tile a 2^n x 2^n
courtyard with a hole anywhere.
Inductive step: Consider a 2^(n+1) x 2^(n+1) courtyard, with a
hole anywhere. As before, we can divide it into four smaller 2^n
x 2^n courtyards. For the quadrant with the hole, we apply our
inductive hypothesis to get a 2^n x 2^n tiling with a hole in
that exact location. For the remaining three quadrants, we apply
inductive hypothesis to get holes at their shared corner, i.e.
the middle of the original courtyard, and we fill the holes with
a single tile. Thus, we have shown that we can tile a 2^(n+1) x
2^(n+1) courtyard with a hole anywhere.
Why was it easier to prove something stronger than to prove our
original claim? While we have to prove more, we also get to assume
more in our inductive hypothesis, which is what we needed here.
Bad induction
Sometimes, we can make mistakes in our proofs that allow us the show
things that are false. Here is one example.
Theorem: All horses have the same color.
Can state as "In any set of n horses, they all have the same
color."
Proof: By induction over n, the number of horses.
Base case: P(1) is obviously true, since there is only one horse.
Inductive hypothesis: P(k), i.e. any set of k horses consists of
just one color.
Inductive step: Consider an arbitrary set of k+1 horses, call them
h(1), h(2), ..., h(k+1). Consider the subset {h(1),...,h(k)}.
By the inductive hypothesis, all horses in this subset must have
the same color, so horses h(1), ..., h(k) have the same color.
Now consider the subset {h(2),...,h(k+1)}. By the inductive
hypothesis, all horses in this subset must have the same color,
so horses h(2), ..., h(k+1) have the same color. Since h(1),
..., h(k) have the same color and h(k+1) must have the same
color as h(2), it must be that h(1), ..., h(k+1) all have the
same color.
We proved something that is clearly false! Does this mean induction
is broken?
In fact, we messed up in the inductive step, since our reasoning
doesn't hold up for k+1 = 2. In this case, the two subsets do not
overlap, so we haven't proven that the h(1) and h(2) have the same
color.
This is another example of why we have to make sure reasoning holds
for all values of k. In this case, there was just one value of k
where it didn't hold, and the entire proof broke down as a result.
Strong induction
Recall the lemma that we used to prove that there are infinitely
many primes.
Lemma: Every integer n > 1 is either prime or can be written as a
product of two or more primes.
Let's try to prove this using induction.
Proof:
Base case: Prove P(2). 2 is prime.
Inductive hypothesis: Assume P(k), i.e. k is prime or can be
written as a product of two or more primes.
Inductive step: Prove P(k+1). There are two cases.
Case 1: k+1 is prime. Then we are done.
Case 2: k+1 is composite. Now what? How does knowing that k is a
prime or a product of primes help us? In fact, k and k+1 don't
ever share any prime factors!
We are stuck. The induction that we have seen so far doesn't give us
enough to prove the above without some ugly contortions.
Let's go back to our analogy with recursion. Suppose I asked you to
compute the nth Fibonacci number. Recall that the Fibonacci numbers
are defined using the following recurrence relation:
F(n) = { 1 if n = 0 or n = 1
{ F(n-1) + F(n-2) if n > 1
To compute the nth Fibnonacci number, we'd turn the above into a
recursive program.
fibonacci(n):
if (n == 0 || n == 1) then 1
else fibonacci(n-1) + fibonacci(n-2)
Notice that we broke down the n case into two smaller cases, one of
which is even smaller than n-1. (Not by a whole lot, but if we
needed to, we could use something much smaller.) So in recursion,
we're allowed to use any smaller cases, not just the next smallest
one.
We need something similar in induction. If we remember our inductive
chain, we start with P(0), which we proved in our base case. Then
when we prove the inductive step, we rely on the fact that we can
prove P(k) by recursively applying the inductive step as follows:
P(0) => P(1) => ... => P(k)
Thus, we only needed to prove P(k) => P(k+1) to extend the chain.
Notice that in the recursion, we've already done the hard work of
proving P(0), P(1), ..., P(k), but we throw out everything except
for P(k) and use just that. What if we kept that information and
used it to our advantage?
If we do so, we end up with strong induction, which consists of the
following:
(1) Prove P(0) (i.e. the base case).
(2) Prove ∀k∈N . (P(0) ∧ P(1) ∧ ... ∧ P(k)) => P(k+1).
In proving the inductive step (2), we get to assume as our inductive
hypothesis P(0) ∧ P(1) ∧ ... ∧ P(k) for an arbitrary k∈N and then
show that P(k+1) follows.
Let's go back to proving our lemma in order to make this more
concrete.
Proof:
Base case: Prove P(2). 2 is prime.
Inductive hypothesis: Assume P(2) ∧ ... ∧ P(k), i.e. any integer
between 2 and k is prime or can be written as a product of two
or more primes.
Inductive step: Prove P(k+1). There are two cases.
Case 1: k+1 is prime. Then we are done.
Case 2: k+1 is composite. By definition, k+1 = xy for some
integers k+1 > x,y > 1. Then by the inductive hypothesis, x is
prime or can be written as a product of primes and similarly
for y. Thus, k+1 = xy can be written as a product of primes.
In PA1, you will generate a direct proof of the above lemma given a
particular n.
It turns out that strong induction logically isn't any stronger than
simple induction and is just a reformulation of the same principle.
See the course reader for details.
Induction and recursion
As we saw in developing simple induction and then extending it to
strong induction, induction and recursion are very intimately
related. Indeed, one of main uses of induction is to prove facts
about recursive algorithms.
Consider again our function for computing the Fibonacci sequence:
fibonacci(n):
if (n == 0 || n == 1) then 1
else fibonacci(n-1) + fibonacci(n-2)
How many additions A(n) does this algorithm perform in computing
F(n)? Can you prove by induction that A(n) = F(n+1) - 1 for all n?
How many base cases do you need, and what are they? How are they
related to the base cases in fibonacci(), and how are the
applications of the inductive hypothesis related to the recursive
calls in fibonacci()?