1 / 32

Prove the Impossible

x=0. Prove the Impossible. No program can check whether another program will run into infinite loop. Sep 28. Today’s Plan. Halting Problem Fifteen Puzzle Checker Jumping. Halting Problem. Now we study the most famous problem in computer science.

bakera
Télécharger la présentation

Prove the Impossible

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Today’s Plan • Halting Problem • Fifteen Puzzle • Checker Jumping

  3. 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.

  4. 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”.

  5. Halting Problem Inverter: Do the opposite to what H says. • 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”. Loop forever H(P,I) If H(P,P)=halt output P:=P Input for K(P) H(P,P) If H(P,P)= loop forever program P halt I:=P Input for program H(P,I) K(P)

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

  7. Halting Problem What happen if K is the input to K? What is K(K)? 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. Loop forever H(P,I) If H(K,K)=halt output P:=K Input for K(K) H(K,K) If H(K,K)= loop forever program K halt I:=K Input for program H(P,I) K(K)

  8. Halting Problem What happen if K is the input to K? What is K(K)? 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. Loop forever H(P,I) If H(K,K)=halt output P:=K Input for K(K) H(K,K) If H(K,K)= loop forever program K halt I:=K Input for program H(P,I) K(K)

  9. Halting Problem In either case, H outputs wrong answer to K(K), this contradicts that such a program exists. Q.E.D. 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. The proof is due to Alan Turing (1936); you will learn more in CSC 3130.

  10. Today’s Plan • Halting Problem • Fifteen Puzzle • Checker Jumping

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

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

  13. Prove the Possible 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. The secret.

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

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

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

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

  18. Parity Given a sequence, a pair is “out-of-order” if the first element is larger. More formally, given a sequence (a1,a2,…,an), a pair (i,j) is out-of-order if i<j but ai > aj. 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

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

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

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

  22. Proving the Invariant Parity of S = (number of out-of-order pairs + row) mod 2 Claim: Any move will preserve the parity of the state. 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).

  23. Proving the Invariant Parity of S = (number of out-of-order pairs + row) mod 2 Claim: Any move will preserve the parity of the state. 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.

  24. Proving the Invariant Parity of S = (number of out-of-order pairs + row) mod 2 Claim: Any move will preserve the parity of the state. 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.)

  25. Proving the Invariant Parity of S = (number of out-of-order pairs + row) mod 2 Claim: Any move will preserve the parity of the state. Row number has changed by 1 Difference is 1 or 3. 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. So the parity stays the same! We’ve proved the claim.

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

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

  28. Today’s Plan • Halting Problem • Fifteen Puzzle • Checker Jumping

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

  30. K=5 This can also be solved by the invariant method. 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.

  31. 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 http://www.cs.cmu.edu/afs/cs/academic/class/15859-f01/www/notes/15-puzzle.pdf Another interesting application of the invariant method is the Nim game. See http://en.wikipedia.org/wiki/Nim. The solution of the checker jumping problem is from “Mathematical Gems II”, which is available in our university library.

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

More Related