Download presentation

Presentation is loading. Please wait.

Published byKenny Bassett Modified over 2 years ago

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

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

6
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)?

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

8
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

9
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 3130. 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.

10
Today’s Plan Halting Problem Fifteen Puzzle Checker Jumping

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

12
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?

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

14
Fifteen Puzzle 1234 5678 9101112 131415 Move: can move a square adjacent to the empty square to the empty square.

15
Fifteen Puzzle 1234 5678 9101112 131415 1234 5678 9101112 131514 Initial configuration Target configuration Is there a sequence of moves that allows you to start from the initial configuration to the target configuration?

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

17
Hint 1234 5678 9101112 131415 1234 5678 9101112 131514 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.

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

19
Hint 1234 5678 9101112 131415 1234 5678 9101112 131514 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

20
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

21
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…

22
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).

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

24
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.)

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

26
Fifteen Puzzle 1234 5678 9101112 131415 141312 111098 7654 321 Initial configuration Target configuration Is there a sequence of moves that allows you to start from the initial configuration to the target configuration?

27
Fifteen Puzzle 1234 5678 9101112 131415 141312 111098 7654 321 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 = 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 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.

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
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!

Similar presentations

OK

CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.

CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on precautions of tsunami in japan Liquid crystal on silicon display ppt online Ppt on time management for teachers Ppt on 2 stroke ic engine cooling Ppt on call center management system Convert pdf to ppt online download Ppt on eisenmenger syndrome and pregnancy Download ppt on smart note taker Ppt on gir national park Ppt on file system in unix script