n5 - CS 70 Spring 2008 Invariants Discrete Mathematics for...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 . a Corollary: The robot can never reach position ( 1 , 0 ) . The key idea of this proof was to identify an
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/09/2008 for the course CS 70 taught by Professor Papadimitrou during the Spring '08 term at University of California, Berkeley.

Page1 / 3

n5 - CS 70 Spring 2008 Invariants Discrete Mathematics for...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online