1 / 26

Halting Problem

Halting Problem. Background - Halting Problem. Common error: Program goes into an infinite loop. Wouldn ’ t it be nice to have a tool that would warn us that our program has this bug?. Example. Infinite loop - we get into a loop but for some reason we never get out of it. while x < 3:

bozarth
Download Presentation

Halting Problem

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

  2. Background - Halting Problem • Common error: Program goes into an infinite loop. • Wouldn’t it be nice to have a tool that would warn us that our program has this bug?

  3. Example • Infinite loop - we get into a loop but for some reason we never get out of it. while x < 3: x = x - 1

  4. Definition Design a program, H, that will do the following: • Take as its input a description of a program P. (in binary, say). • Halt eventually and answer "yes" if P will eventually halt, or halt and answer "no" if P will run forever.

  5. Halting Problem In other words, Program H will always halt and give the correct answer no matter what program has been given as input. H P Halts? Yes or No

  6. Proving the Halting Problem • We want to prove that the halting problem is non-computable. • In other words, there is no algorithm that we can use to tell whether or not a program will halt. • We will use proof by contradiction.

  7. Proof by Contradiction • Assume that what we want to prove is false. • Demonstrate that a logical contradiction results. • We can conclude that the thing we were trying to prove must be true. • Example: There is no largest integer.

  8. Proof by Contradiction: • We’ll assume that the Halting Problem CAN be computed. • We’ll develop another program that uses the Halting Problem function. • We’ll find ourselves caught in a paradox (the contradiction). • We’ll have proven that our original assumption is false.

  9. Assume Halting Problem OK • Let H be a program (or sub-program) that determines whether a program will halt. H P Halts? Yes or No

  10. Let’s Build Another Program • Let B be a program that uses H. • For any given program, B will call H and pass it the given program. B H P P

  11. What does P do? • Now, B acts as follows: • B takes a program as input and feeds the program to H as input. • If H answer yes, then B will enter an infinite loop and run forever. • If H answer no, then B will stop.

  12. What Can We Do With P? • Let’s give B a copy of itself as its input. B B loops H Yes B B No B Halts

  13. What if B Halts? B B loops H Yes B B No B Halts

  14. What if B Loops Forever? B B loops H Yes B B No B Halts

  15. The Paradox • If B is a program that halts when given itself as its input, then, when given itself as input, B will go into an infinite loop. • If B is a program that loops indefinitely when given itself as its input, then , when given itself as input, B will halt immediately.

  16. What Went Wrong? • There’s nothing wrong with B. • The problem must be with the assumption that we could write H.

  17. So, Proof by Contradiction: • We assumed that the Halting Problem COULD be computed. • We developed another program that used the Halting Problem function. • We found ourselves caught in a paradox (the contradiction). • We proved that the Halting Problem is not computable.

  18. Conclusions • Rice’s theorem says that “Any nontrivial property of programs is undecidable.” • Thus, we can’t write programs to answer questions about programs.

  19. Intractability • I’ve claimed that the traveling salesperson problem is intractable. • The best algorithm we’ve seen so far is O(N!). • How can we know that there isn’t a better algorithm? Maybe O(N)? • The short answer is that we can’t. • There is a longer answer that leads us to conclude that TSP is very likely intractable…

  20. P and NP • P the set of problems that can be solved in polynomial time by a Turing machine. • NP the set of problems that can be solved in polynomial time by a non-deterministic Turing machine. • Non-deterministic Turing Machine????

  21. Non-Deterministic Turing Machines • Easiest way to describe them is to say that they have the ability to instantly guess an answer, but they need to do the work of verifying that it is correct. • Example: Traveling salesperson decision problem. • Deterministic TM. • Non-deterministic TM.

  22. What’s the Difference? • Everyone who is anyone believes that P and NP are different sets. • In other words, there are some problems that can be solved in polynomial time using non-determinism, but can’t be solved in polynomial time deterministically.

  23. NP-Completeness • It has been proven that the problem SAT is NP-complete. • (The SAT problem is to determine whether or not a given boolean expression can ever be true.) • If we could solve SAT in polynomial time, then we could solve any other problem in NP in polynomial time. (No time for the proof of this.) • It is NP-complete… At least as hard as every other problem in NP.

  24. So What? • This means that it is very very likely that SAT does not have a polynomial time algorithm. • If it does, then P=NP, which no one believes. • What does any of this have to do with TSP?

  25. Reductions • We would like to show a polynomial time reduction from SAT to TSP. • This involves showing how to convert any instance of the SAT into an instance of the TSP problem that has the same solution. • This would mean that any solution to the TSP problem would immediately give us a solution to SAT. • We could conclude that the TSP solution is at least as hard as SAT, and by extension, at least has hard as every other problem in NP.

  26. TSP • How do we reduce TSP to SAT? • It can be done, but it is beyond the scope of this lecture :) • It turns out that many problems are NP-Complete.

More Related