Prove the Impossible Sep 28 No program can check whether another program will run into infinite loop. x=0.

Slides:



Advertisements
Similar presentations
The Halting Problem of Turing Machines. Is there a procedure that takes as input a program and the input to that program, and the procedure determines.
Advertisements

Mathematical Induction II Lecture 14: Nov
1 The Limits of Computation Intractable and Non-computable functions.
Sets Lecture 11: Oct 24 AB C. This Lecture We will first introduce some basic set theory before we do counting. Basic Definitions Operations on Sets Set.
1 COMP 382: Reasoning about algorithms Unit 9: Undecidability [Slides adapted from Amos Israeli’s]
Week 7 - Wednesday.  What did we talk about last time?  Set proofs and disproofs  Russell’s paradox.
CSE115/ENGR160 Discrete Mathematics 02/28/12
1 Section 14.1 Computability Some problems cannot be solved by any machine/algorithm. To prove such statements we need to effectively describe all possible.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
Computability and Complexity 13-1 Computability and Complexity Andrei Bulatov The Class NP.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Introduction to Computability Theory
Courtesy Costas Busch - RPI1 A Universal Turing Machine.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
1 Linear Bounded Automata LBAs. 2 Linear Bounded Automata are like Turing Machines with a restriction: The working space of the tape is the space of the.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 19 Instructor: Paul Beame.
CHAPTER 4 Decidability Contents Decidable Languages
Invariant Method Lecture 6: Sep
Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing.
CS 310 – Fall 2006 Pacific University CS310 The Halting Problem Section 4.2 November 15, 2006.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 18 Instructor: Paul Beame.
1 Introduction to Computability Theory Lecture11: The Halting Problem Prof. Amos Israeli.
Lecture , 3.1 Methods of Proof. Last time in 1.5 To prove theorems we use rules of inference such as: p, p  q, therefore, q NOT q, p  q, therefore.
Invariant Method Lecture
Prove the Impossible Lecture 6: Sep 19 (based on slides in MIT 6.042)
Set Theory A B C.
Functions A B f( ) =. This Lecture We will define a function formally, and then in the next lecture we will use this concept in counting. We will also.
Invariant Method
Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
Great Theoretical Ideas in Computer Science about AWESOME Some Generating Functions Probability Infinity Computability With Alan! (not Turing) Mind-
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
A Universal Turing Machine
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
1 Linear Bounded Automata LBAs. 2 Linear Bounded Automata (LBAs) are the same as Turing Machines with one difference: The input string tape space is the.
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
Fundamentals of Informatics Lecture 13 Reduction Bas Luttik.
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 7 Functions Instructor: Hayk Melikyan Today we will review sections 7.3, 7.4 and 7.5.
Donghyun (David) Kim Department of Mathematics and Computer Science North Carolina Central University 1 Chapter 4 Decidability Some slides are in courtesy.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 09a: PROOF STRATEGIES Section 3.1 Jarek Rossignac CS1050:
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
CompSci Today’s Topics Computer Science Noncomputability Upcoming Special Topic: Enabled by Computer -- Decoding the Human Genome Reading Great.
Recursively Enumerable and Recursive Languages. Definition: A language is recursively enumerable if some Turing machine accepts it.
Decidability.
1 A Universal Turing Machine. 2 Turing Machines are “hardwired” they execute only one program A limitation of Turing Machines: Real Computers are re-programmable.
Fifteen Puzzle Move: can move a square adjacent to the empty square to the empty square.
Russell’s Paradox Is W in W? In words, W is the set that contains all the sets that don’t contain themselves. If W is in W, then W contains itself. But.
CSE15 Discrete Mathematics 03/06/17
The Acceptance Problem for TMs
CS 461 – Nov. 2 Sets Prepare for ATM finite vs. infinite Infinite sets
CPSC 121: Models of Computation 2008/9 Winter Term 2
CSE 311 Foundations of Computing I
Mathematical Induction II
Gray Code Can you find an ordering of all the n-bit strings in such a way that two consecutive n-bit strings differed by only one bit? This is called the.
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Busch Complexity Lectures: Undecidable Problems (unsolvable problems)
Andreas Klappenecker [based on slides by Prof. Welch]
CSCE 411 Design and Analysis of Algorithms
Decidable Languages Costas Busch - LSU.
Sets, Sequences, and Summations
Formal Languages, Automata and Models of Computation
CSCI 2670 Introduction to Theory of Computing
Computability and Undecidability
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Turing Machines Everything is an Integer
Intro to Theory of Computation
Presentation transcript:

Prove the Impossible Sep 28 No program can check whether another program will run into infinite loop. x=0

Today’s Plan Halting Problem Fifteen Puzzle Checker Jumping

Halting Problem Now we study the most famous problem in computer science. The halting problem: Can we write a program which detects infinite loop? We want a program H that given any program P and input I: H(P,I) returns “halt” if P will terminate given input I; H(P,I) returns “loop forever” if P will not terminate given input I. The halting problem: Does such a program H exist? Note that the program H can not just simulate the program P on input I; if P halts on I, then H can return halt successfully; but if P loops forever on I, then H will also loop forever.

Halting Problem We want a program H that given any program P and input I: H(P,I) returns “halt” if P will terminate given input I; H(P,I) returns “loop forever” if P will not terminate given input I. The halting problem: Does such a program H exist? Prove by contradiction: Suppose, by contradiction, that H exists. Both P and I are binary strings. H should be able to determine if P will terminate given itself as the input. That is, H(P,P) will either returns “halt” or “loop forever”.

Halting Problem Construct an “inverter” program K which does the following given input P: if H(P,P) returns “halt”, then K(P) will “loop forever” ; if H(P,P) returns “loop forever”, then K(P) will “halt”. Inverter: Do the opposite to what H says. H(P,I) K(P) Input for K(P) program P P:=P I:=P Input for program H(P,I) output H(P,P) If H(P,P)=halt Loop forever If H(P,P)= loop forever halt

Halting Problem H(P,I) K(P) Input for K(P) program P P:=P I:=P Input for program H(P,I) output H(P,P) If H(P,P)=halt Loop forever If H(P,P)= loop forever halt What happen if K is the input to K? What is K(K)?

Halting Problem What happen if K is the input to K? What is K(K)? H(P,I) K(K) Input for K(K) program K P:=K I:=K Input for program H(P,I) output H(K,K) If H(K,K)=halt Loop forever If H(K,K)= loop forever halt Case 1: Suppose H(K,K) says “halt”, that is H determines K(K) will “halt”. But then K(K) will “loop forever”, which is exactly the opposite to the answer.

Halting Problem Case 2: Suppose H(K,K) says “loop forever”, that is H determines K(K) will “loop”, But then K(K) will “halt”, which is exactly the opposite to the answer. What happen if K is the input to K? What is K(K)? H(P,I) K(K) Input for K(K) program K P:=K I:=K Input for program H(P,I) output H(K,K) If H(K,K)=halt Loop forever If H(K,K)= loop forever halt

Halting Problem In either case, H outputs wrong answer to K(K), this contradicts that such a program exists. The proof is due to Alan Turing (1936); you will learn more in CSC Intuitively, no program can determine whether K halts when given input K, because the program K will do the opposite “after” you give an answer. Q.E.D.

Today’s Plan Halting Problem Fifteen Puzzle Checker Jumping

Invariant Method 1.Find properties (the invariants) that are satisfied throughout the whole process. 2.Show that the target do not satisfy the properties. 3.Conclude that the target is not achievable.

Prove the Possible The secret. Is it always possible to fill in the board by dominos, if two squares of different colors are taken out?

Prove the Possible The secret. The two squares will break the long cycle into two paths, but since they are of different colors both paths will be of even length.

Fifteen Puzzle Move: can move a square adjacent to the empty square to the empty square.

Fifteen Puzzle Initial configuration Target configuration Is there a sequence of moves that allows you to start from the initial configuration to the target configuration?

Invariant Method 1.Find properties (the invariants) that are satisfied throughout the whole process. 2.Show that the target do not satisfy the properties. 3.Conclude that the target is not achievable. What is an invariant in this game?? This is usually the hardest part of the proof.

Hint Initial configuration Target configuration ((1,2,3,…,14,15),(4,4)) ((1,2,3,…,15,14),(4,4)) Hint: the two states have different parity.

Parity Given a sequence, a pair is “out-of-order” if the first element is larger. For example, the sequence (1,2,4,5,3) has two out-of-order pairs, (4,3) and (5,3). Given a state S = ((a1,a2,…,a15),(i,j)) Parity of S = (number of out-of-order pairs + row) mod 2 row number of the empty square More formally, given a sequence (a 1,a 2,…,a n ), a pair (i,j) is out-of-order if i a j.

Hint Initial configuration Target configuration ((1,2,3,…,14,15),(4,4)) ((1,2,3,…,15,14),(4,4)) Clearly, the two states have different parity. Parity of S = (number of out-of-order pairs + row) mod 2

Invariant Method 1.Find properties (the invariants) that are satisfied throughout the whole process. 2.Show that the target do not satisfy the properties. 3.Conclude that the target is not achievable. Invariant = parity of state Claim: Any move will preserve the parity of the state. Proving the claim will finish the impossibility proof. Parity is even Parity is odd

Proving the Invariant Claim: Any move will preserve the parity of the state. Parity of S = (number of out-of-order pairs + row) mod 2 ???? ?a? ???? ???? ???? ?a? ???? ???? Horizontal movement does not change anything…

Proving the Invariant Claim: Any move will preserve the parity of the state. Parity of S = (number of out-of-order pairs + row) mod 2 ???? ?ab1b2 b3?? ???? ???? ?b1b2 b3a?? ???? Row number has changed by 1 To count the change on the number of out-of-order pairs, we can distinguish 4 cases, depending on the relative order of a among (a,b1,b2,b3).

Proving the Invariant Claim: Any move will preserve the parity of the state. Parity of S = (number of out-of-order pairs + row) mod 2 ???? ?ab1b2 b3?? ???? ???? ?b1b2 b3a?? ???? Row number has changed by 1 Case 1: when a is largest, then the number of out-of-order pairs will decrease by three, and since the row number is changed by one, the parity is still the same.

Proving the Invariant Claim: Any move will preserve the parity of the state. Parity of S = (number of out-of-order pairs + row) mod 2 ???? ?ab1b2 b3?? ???? ???? ?b1b2 b3a?? ???? Row number has changed by 1 Case 2: when a is the second largest, then the number of out-of-order pairs will decrease by one, and since the row number is changed by one, the parity is still the same. (The remaining case analysis is the same.)

Proving the Invariant Claim: Any move will preserve the parity of the state. Parity of S = (number of out-of-order pairs + row) mod 2 ???? ?ab1b2 b3?? ???? ???? ?b1b2 b3a?? ???? If there are (0,1,2,3) out-of-order pairs in the current state, there will be (3,2,1,0) out-of-order pairs in the next state. Row number has changed by 1 So the parity stays the same! We’ve proved the claim. Difference is 1 or 3.

Fifteen Puzzle Initial configuration Target configuration Is there a sequence of moves that allows you to start from the initial configuration to the target configuration?

Fifteen Puzzle Initial configuration Target configuration Number of out-of-order pairs = 0 Row of empty square = 4 Parity is even. Number of out-of-order pairs = … + 1 = 14(13)/2 = 91 Row of empty square = 4 Parity is odd. Impossible!

Today’s Plan Halting Problem Fifteen Puzzle Checker Jumping

K=4 x=0 Remember the checker game that we have seen before?

K=5 Sorry there are no slides for this proof. The proof can be found in “Mathematical Gems II” by Honsberger. There are three books on Mathematical Gems and all are excellent. This can also be solved by the invariant method.

Remarks and References The argument used in the halting problem is called the “diagonalization” method. This is originally used by Canton to prove that real numbers are “more” than Integers (see the next slide). This method has many other applications in theoretical computer science. For the fifteen puzzle, one can prove that as long as the two states are of the same parity, then one state can reach the other. See Another interesting application of the invariant method is the Nim game. See The solution of the checker jumping problem is from “Mathematical Gems II”, which is available in our university library.

Question: Is the set of real number countable? Theorem: No surjection mapping positive integers to real numbers. (Appendix) Real Numbers vs Positive Integers The string map to the first natural number The string map to the fifth natural number The opposite of the diagonal It can not be in any row i because its i-th bit is different, and so this string is not mapped!