Download Notes for Recitation 3 1 Well-Ordering

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

Division by zero wikipedia , lookup

Parity of zero wikipedia , lookup

Collatz conjecture wikipedia , lookup

Transcript
6.042/18.062J Mathematics for Computer Science
Tom Leighton and Ronitt Rubinfeld
September 15, 2006
Notes for Recitation 3
1
Well-Ordering
Here is a statement that appears, at first glance, to be as useless as it is obvious.
Well-Ordering Principle.
smallest element.
Every nonempty subset of the natural numbers has a
The first glance is deceiving! As for obvious, note that the well-ordering principle would
be false if the natural numbers were replaced by, say, the real numbers, the integers, or
even the nonnegative rational numbers. So the well-ordering principle is capturing something special about the natural numbers.
As for useless, everything provable with ordinary or strong induction can equally well
be proved with the well-ordering principle! Thus, well-ordering is as powerful as the
most important proof technique used in computer science. Let’s do an example to demonstrate its utility.
Theorem 1. There is no solution over the positive integers to the equation:
4a3 + 2b3 = c3
Proof. We use contradiction and the well-ordering principle. Let S be the set of all positive
integers a such that there exist positive integers b and c that satisfy the equation.
Assume for the purpose of obtaining a contradiction that S is nonempty. Then S contains a smallest element a0 by the well-ordering principle. By the definition of S, there
exist corresponding positive integers b0 and c0 such that:
4a30 + 2b30 = c30
The left side of this equation is even, so c30 is even, so c0 is even. Thus, there exists an
integer c1 such that c0 = 2c1 . Substituting into the preceding equation and then dividing
both sides by 2 gives:
2a30 + b30 = 4c31
Recitation 3
2
Now b30 must be even, so b0 is even. Thus, there exists an integer b1 such that b0 = 2b1 .
Substituting into the preceding equation and dividing both sides by 2 again gives:
a30 + 4b31 = 2c31
From this equation, we know that a30 is even, so a0 is even. Thus, there exists an integer
a1 such that a0 = 2a1 . Substituting into the previous equation one last time and dividing
by 2 one last time gives:
4a31 + 2b31 = c31
Evidently, a = a1 , b = b1 , and c = c1 is another solution to the original equation, and
so a1 is an element of S. But this is a contradiction, because a1 < a0 and a0 was defined
to be the smallest element of S. Therefore, our assumption was wrong, and the original
equation has no solutions over the positive integers.
√
This argument is quite similar to the proof that 2 is irrational. In fact, looking back,
we implicitly relied on the well-ordering principle in that proof when we claimed that
a rational number could be written as a fraction in lowest terms. We’ve been using the
well-ordering principle on the sly since Day 1!
Induction, strong induction, and well-ordering are logically equivalent, so the best
choice for a particular application is the one that you think gives the clearest proof. In
practice, induction and strong induction are more
√ commonly used than well-ordering.
But for the occasional problem, like proving that 2 is irrational, an argument based on
well-ordering may be much nicer.
Recitation 3
2
3
Problem: The Temple of Forever
Each monk entering the Temple of Forever is given a bowl with 15 red beads and 12 green
beads. Each time the Gong of Time rings, a monk must do one of two things:
1. If he has at least 3 red beads in his bowl, then he may remove 3 red beads and add
2 green beads.
2. He may replace each green bead in his bowl with a red bead and replace each red
bead in his bowl with a green bead. That is, if he starts with i red beads and j green
beads, then after he performs this operation, he will have j red beads and i green
beads.
A monk may leave the Temple of Forever only when he has exactly 5 red beads and 5
green beads in his bowl.
Theorem. No one ever leaves the Temple of Forever.
Prove this theorem by induction. Begin by searching for an invariant that holds initially and is maintained by each operation, but would be violated by the condition required for departure.
Solution.
Proof. We use induction on the number of gong rings. Let P (n) be the proposition that
after n rings, the number of red beads in the monk’s bowl minus the number of green
beads is equal to 5k + 2 or 5k + 3 for some integer k.
Base case: P (0) is true because initially (after zero rings) the number of red beads minus
the number of green beads is 15 − 12 = 5 · 0 + 3.
Inductive step: Now assume that P (n) holds after n gong rings, where n ≥ 0. Let r denote
the number of red beads in the monk’s bowl, and let g denote the number of green beads.
In these terms, we are assuming that r − g is equal to 5k + 2 or 5k + 3 for some integer k.
After n + 1 gong rings, there are two cases to consider, depending on the monk’s action:
1. If r ≥ 3, then the monk may have replaced 3 red beads with 2 green beads. Thus,
the number of red beads minus the number of green becomes:
(r − 3) − (g + 2) = (r − g) − 5
This is equal to either 5(k − 1) + 2 or 5(k − 1) + 3, so P (n + 1) is true.
2. Alternatively, the monk may have exchanged every red bead for a green bead and
vice versa. In this case, the number of reds minus the number of greens becomes
g − r. If r − g = 5k + 3, then g − r = 5(−k) − 3 = 5(−k − 1) + 2. If r − g = 5k + 2,
then g − r = 5(−k) − 2 = 5(−k − 1) + 3. Thus, P (n + 1) is again true.
Recitation 3
4
Therefore, P (n) implies P (n + 1) for all n ≥ 0.
By the induction principle, P (n) is true for all n ≥ 0. Since the number of red beads
minus the number of greens is always of the form 5k + 2 or 5k + 3 and the difference
required to leave the temple does not match either form, no monk can ever leave the
Temple of Forever.
Recitation 3
3
5
The 15-puzzle
Here is the original 15-puzzle. There are 15 lettered tiles and a blank square arranged in
a 4 × 4 grid. Any lettered tile adjacent to the blank square can be slid into the blank. For
example, a sequence of two moves is illustrated below:
A B C D
E F G H
I J K L
M O N
→
A B C D
E F G H
I J K L
M O
N
→
A B C D
E F G H
I J
L
M O K N
In the leftmost configuration shown above, the O and N tiles are out of order. Using
only legal moves, is it possible to swap the N and the O, while leaving all the other tiles
in their original position and the blank in the bottom right corner? In this problem, you
will prove the following theorem stating that the answer is “no”.
Theorem 2. No sequence of moves transforms the board below on the left into the board below on
the right.
A B C D
A B C D
E F G H
E F G H
I J K L
I J K L
M O N
M N O
1. Can a row move change the order of the tiles?
Solution. No, via the same reasoning as in the 8-game.
2. How many pairs of tiles will have their relative order changed by a column move?
Prove your answer correct.
Solution. A column move changes the relative order of exactly 3 pairs of tiles.
Sliding a tile down moves it after the next three tiles in the order. Sliding a tile up
moves it before the previous three tiles in the order. Either way, the relative order
changes between the moved tile and each of the three it crosses.
3. Can a row move change the parity of the number of inversions?
Solution. A row move never changes the parity of the number of inversions.
4. Can a column move change the parity of the number of inversions? Justify your
answer.
Solution. A column move always changes the parity of the number of inversions.
A column move changes the relative order of exactly 3 pairs of tiles. Thus, an inverted pair becomes uninverted and vice versa. Thus, one exchange flips the total
number of inversions to the opposite parity, a second exhange flips it back to the
original parity, and a third exchange flips it to the opposite parity again.
Recitation 3
6
5. The previous problem part implies that we must make an odd number of column
moves in order to exchange just one pair of tiles (14 and 15, say). But this is problematic, because each column move also knocks the blank square up or down one
row. So after an odd number of column moves, the blank can not possibly be back
in the last row, where it belongs! Now we can bundle up all these observations
and state an invariant, a property of the puzzle that never changes, which holds no
matter how you slide the tiles around.
Lemma 3. In every configuration reachable from the position shown below, the parity of the
number of inversions is different from the parity of the row containing the blank square.
row 1
row 2
row 3
row 4
A B C D
E F G H
I J K L
M O N
Prove this lemma.
Solution.
We use induction. Let P (n) be the proposition that after n moves, the parity of the
number of inversions is different from the parity of the row containing the blank
square.
Base case: After zero moves, exactly one pair of tiles is inverted (O and N), which
is an odd number. And the blank square is in row 4, which is an even number.
Therefore, P (0) is true.
Inductive step: Now we must prove that P (n) implies P (n + 1) for all n ≥ 0. So
assume that P (n) is true; that is, after n moves the parity of the number of inversions
is different from the parity of the row containing the blank square. There are two
cases:
(a) Suppose move n + 1 is a row move. Then the parity of the total number of
inversions does not change. The parity of the row containing the blank square
does not change either, since the blank remains in the same row. Therefore,
these two parities are different after n + 1 moves as well, so P (n + 1) is true.
(b) Suppose move n + 1 is a column move. Then the parity of the total number
of inversions changes. However, the parity of the row containing the blank
square also changes, since the blank moves up or down one row. Thus, the
parities remain different after n + 1 moves, and so P (n + 1) is again true.
Thus, P (n) implies P (n + 1) for all n ≥ 0.
By the principle of induction, P (n) is true for all n ≥ 0.
6. Prove the theorem that we originally set out to prove.
Recitation 3
7
Solution. In the target configuration on the right, the total number of inversions is
zero, which is even, and the blank square is in row 4, which is also even. Therefore,
by Lemma 3, the target configuartion is unreachable.