Article
Problems no computer can solve
Imagine a perfect bug detector. You give it any program, and it tells you whether that program will ever get stuck in an endless loop. It would be very useful. It is also impossible, and mathematicians have proved it. The reason is not that we are not clever enough yet. Such a detector can never be built.
Decidable problems
A decidable problem is a decision problem (yes or no) for which an algorithm exists that gives the correct answer for every input. The algorithm always finishes, and it is always right.
- "Is this number even?" is decidable. The algorithm is: divide by 2 and look at the remainder.
- "Does this list contain the number 42?" is decidable. Check every element.
- "Is there a route through all the towns shorter than 22 km?" is decidable too. Try every route. That is very slow for many towns, but it finishes and it is correct.
That last example matters. Decidable does not mean fast. A problem can need an unreasonable amount of time and still be decidable.
Undecidable problems
An undecidable problem is a decision problem for which no algorithm can ever exist that gives a correct yes-or-no answer for every input. This is true in principle, however fast the computer is and however clever the programmer is.
Compare the two cases carefully:
Three kinds of problem
Reasonable time
- an algorithm exists and it is fast
- example: is the number even?
Unreasonable time
- an algorithm exists but takes far too long
- heuristics can help
- example: the shortest route through 25 towns
No algorithm at all
- undecidable
- no algorithm can ever solve every instance
- example: the halting problem
Check your understanding
What does it mean to say that a problem is undecidable?
The halting problem
The best-known undecidable problem is the halting problem: given any program and its input, will the program eventually stop (halt), or will it run forever?
For many programs you can tell by looking:
REPEAT 3 TIMES
{
DISPLAY("hello")
}This stops after three lines. But this one never stops, because x only gets bigger and x < 0 never becomes true:
x ← 1
REPEAT UNTIL(x < 0)
{
x ← x + 1
}The problem is to find one algorithm that answers correctly for every program. Why is that impossible? Here is the idea, with no formulas.
Suppose a perfect checker did exist. Call it willStop. Use it to build a tricky program called Contrary. Contrary asks willStop about itself, and then does the opposite:
What willStop says about Contrary | What Contrary then does | So willStop was |
|---|---|---|
| "Contrary will stop" | runs forever | wrong |
| "Contrary will run forever" | stops at once | wrong |
Either answer is wrong. So a perfect willStop cannot exist. (Alan Turing proved this in 1936, before modern computers were built.)
It can still work for some instances
"Undecidable" means that no algorithm works for every instance. It does not mean that every instance is hopeless. We just saw two programs where we could say "stops" and "never stops". A tool can also check many real programs. What is impossible is a checker that is always correct, for all programs.
Here is a short program that nobody has fully worked out. It takes a starting number (a positive whole number) and repeats: if the number is even, halve it, otherwise multiply by 3 and add 1. It stops when it reaches 1. Try different starts:
Every number that anyone has tried reaches 1, but nobody has proved that all starting numbers do. The loop here is capped at 1000 steps, so that your browser can never get stuck.
Check your understanding
A student says: "The halting problem is undecidable, so I can never tell whether any program will stop." Which reply is correct?
Worked example
Sort each of these into decidable and fast, decidable but unreasonable time, or undecidable.
| Problem | Answer | Why |
|---|---|---|
| Is 91 a multiple of 7? | decidable and fast | One division gives the answer. |
| Is there a route through 30 towns shorter than 100 km? | decidable but unreasonable time | Trying every route works, but takes far too long. A heuristic can find a good route. |
| Given any program, will it ever stop? | undecidable | No algorithm is correct for all programs. |
Common mistakes
- "Undecidable means very slow." No. Slow problems are decidable. Undecidable means that no algorithm exists.
- "Undecidable means nobody has solved it yet." No. It has been proved that no algorithm can exist.
- "A faster computer, or a smarter programmer, will fix it." No. Speed and cleverness do not change a proof.
- "No instance of an undecidable problem can be answered." Some instances can. What cannot be done is one algorithm for all of them.
- "A heuristic solves undecidable problems." A heuristic gives a good answer when an exact algorithm is too slow. For an undecidable problem there is no exact algorithm at all.
On the exam
Expect statements to judge as true or false. A decidable problem has an algorithm that is correct for all inputs. An undecidable problem has none, but may have algorithms that answer correctly for some inputs. The halting problem is the usual example. Do not mix up "undecidable" with "takes unreasonable time".
Key words
Decidable problem: a decision problem for which an algorithm exists that is correct for every input.
Undecidable problem: a decision problem for which no algorithm can be correct for every input.
Halting problem: deciding, for any program and input, whether the program will eventually stop. It is undecidable.