CS 70
Discrete Mathematics for CS
Spring 2008
David Wagner
Note 5
Invariants
We have a robot that lives on an infinite grid. Initially, it is at position
(
0
,
0
)
. At any point, it can take a
single step in one of four directions: northeast, northwest, southwest, or southeast. In other words, if it is at
position
(
x
,
y
)
, it can move to one of the four positions
(
x
+
1
,
y
+
1
)
,
(
x
−
1
,
y
+
1
)
,
(
x
−
1
,
y
−
1
)
,
(
x
+
1
,
y
−
1
)
in a single step. Can the robot ever reach position
(
1
,
0
)
?
A bit of experimentation will suggest that the robot can never reach position
(
1
,
0
)
, no matter how many
steps it takes. Let’s prove this.
Theorem:
If the robot can reach position
(
x
,
y
)
, then
x
+
y
is even.
Proof
: We will prove this by induction on the number
n
of steps the robot has taken. Let
P
(
n
)
denote the
proposition that after any sequence of
n
steps, the robot can only reach positions of the form
(
x
,
y
)
such that
x
+
y
is even.
Base case:
After 0 steps, the robot can only be at the position
(
0
,
0
)
, and 0
+
0 is indeed even. Therefore
P
(
0
)
is true.
Inductive hypothesis:
Suppose that
P
(
n
)
is true. In other words, after any sequence of
n
steps, the robot can
only reach positions
(
x
,
y
)
where
x
+
y
is even.
Induction step:
Consider any sequence of
n
+
1 steps. Let
(
x
,
y
)
denote the position of the robot after the
first
n
of these steps, and
(
x
′
,
y
′
)
denote its position after the
n
+
1
st
step. By the induction hypothesis,
x
+
y
is even. Now there are four cases, corresponding to which direction the robot moved in the
n
+
1
st
step:
1.
(
x
′
,
y
′
) = (
x
+
1
,
y
+
1
)
: then
x
′
+
y
′
=
x
+
y
+
2, which is the sum of two even numbers (namely,
x
+
y
and 2) and hence is even.
2.
(
x
′
,
y
′
) = (
x
−
1
,
y
+
1
)
: then
x
′
+
y
′
=
x
+
y
, which is even.
3.
(
x
′
,
y
′
) = (
x
−
1
,
y
−
1
)
: then
x
′
+
y
′
=
x
+
y
−
2, which is even.
4.
(
x
′
,
y
′
) = (
x
+
1
,
y
−
1
)
: then
x
′
+
y
′
=
x
+
y
, which is even.
Consequently, after any sequence of
n
+
1 steps, the robot is at some position
(
x
′
,
y
′
)
such that
x
′
+
y
′
is even.
In other words, we have proven that
P
(
n
+
1
)
follows from
P
(
n
)
. By induction,
P
(
n
)
is true for all
n
∈
N
.
a50
Corollary:
The robot can never reach position
(
1
,
0
)
.
The key idea of this proof was to identify an
invariant
. An invariant is a boolean proposition whose truth
value does not change throughout the process. In this case, the invariant is the property that
x
+
y
is even.
In general, an invariant is a property that is initially true, and where if the invariant is true before a single
step of the process, then it will remain true after that step. If these two conditions are met, it will follow by
induction on the number of steps of the process, that the invariant is forever true.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 PAPADIMITROU
 Mathematical Induction, Natural number

Click to edit the document details