The Halting Problem Chuck Cusack Solvability Definition A
The Halting Problem Chuck Cusack
Solvability • Definition: A problem is called solvable if there exists an algorithm that can solve it. – In other words, given any instance of a problem, the algorithm will determine the solution in a finite amount of time. • Definition: A problem is called unsolvable if there does not exists an algorithm that can solve it. • Question: Is every problem solvable? • Answer: Maybe surprisingly, the answer is no. • If a problem can be proved to be unsolvable, then there will never be an algorithm to solve it.
A Problem • Have you even written a program that ran much longer than you expected? • Did you kill the program after a while, and still to this day do not know whether or not it would have finished? • Wouldn’t it be nice if there was an algorithm that would tell you whether or not your algorithm would eventually finish, or was going to run forever? • Well, maybe you can!
The Halting Problem • Problem (The halting problem): Given a program A, and input to the program I, does A halt if given input I? • In other words, we want an algorithm H such that, given any program A and input I – H(A, I) = true if A(I) halts (finishes), and – H(A, I) = false if A(I) will never halt (loops forever) • Is the halting problem solvable?
The Halting Problem: Unsolvable • It turns out that the halting problem is unsolvable. • We will show that there isn’t a single algorithm that can determine whether any program will halt. • This does not say we cannot write an algorithm that will determine if some program(s) will halt. • In other words, it is possible to write an algorithm that can determine if some specific programs will halt, but it will not work on all programs.
An Algorithm as Input • Although it may seem odd at first, it is possible to use a program as input to another program. • For instance, there are programs, sometimes called pretty printers, which take a program as input and produce a cleaned-up version of the program. • Every time you edit your programs with a text editor, you are giving your program to another program as input. • Most integrated development environments (IDEs) allow you to run your program—they must take your program as input in order to run it.
Proof Part 1 • We will prove that the halting problem is unsolvable using a proof by contradiction. • Assume the halting problem is solvable. • Then there is an algorithm H such that, given any algorithm A and input I, – H(A, I) = true if A(I) halts, and – H(A, I) = false if A(I) loops forever • We will use this algorithm to produce a contradiction.
Proof Part 2 • Consider the following algorithm which takes a program as input C(Program A) If ( H(A, A) = true ) Loop forever If ( H(A, A) = false ) Return true • Notice that – If A(A) halts – If A(A) loops forever C(A) halts • Notice we are using the “solution” to the halting problem in this algorithm.
Proof Part 3 • What happens if we call C(C)? C(Algorithm A) If ( H(A, A) = true ) Loop forever If ( H(A, A) = false ) Return true • • C(C) If ( H(C, C) = true ) Loop forever If ( H(C, C) = false ) Return true • If H tells us that C(C) halts, then C(C) loops forever • If H tells us that C(C) loops forever, then C(C) halts Thus, H does not work properly on program C. But we assumed H works on all programs This leads to a contradiction. Thus, the algorithm H must not exist.
Unsolvable Problems • • We now know of one unsolvable problem. Of course, the halting problem is of limited use. Are there other unsolvable problems? In particular, are there unsolvable problems which people want solved in practice? • Although there may be, none come to mind. • In other words, – in theory, there are unsolvable problems – in practice, most problems are solvable
References • Kenneth Rosen, “Discrete Mathematics and its Applications, ” 5 th edition, Mc. Graw Hill, 2003 • Anany Levitin, “Introduction to the Design and Analysis of Algorithms, ” Addison-Wesley, 2003 • Eric Gossett, “Discrete Mathematics with Proof, ” Prentice Hall, 2003
- Slides: 11