
This is part 9 of 11 in the Formal Methods 101 series.
Decidable and undecidable problems
There are some problems for which no algorithm can guarantee a correct answer (for example, yes or no). These are called undecidable problems. The problems for which such an algorithm does exist are called decidable problems.
The halting problem
To understand this further, we look at a classic undecidable problem, the halting problem. It involves two programs: Oracle_Program and Recursive_Program.
Oracle_Program predicts whether a program will halt on a given input or loop forever. It takes in a program and its input, returns "Halt" if the program halts and "Loops Forever" if it loops forever. This program is promised to give the correct answer and never the wrong one. We will show that no such program can exist.
Function Oracle_Program(Program, Input)
If (Program(Input) halts)
Return "Halt"
Else
Return "Loops Forever"
Now consider Recursive_Program. It loops forever if the oracle predicts that a given program on a given input will halt, and it returns "Halt" if the oracle predicts that the program will loop forever.
Function Recursive_Program(Program, Input)
If (Oracle_Program(Program, Input) == "Halt")
LoopForever()
Else
Return "Halt"
The contradiction
A contradiction appears when Recursive_Program is passed into itself:
Function Recursive_Program(Recursive_Program, Input)
If (Oracle_Program(Recursive_Program, Input) == "Halt")
LoopForever()
Else
Return "Halt"
- If the oracle predicts that
Recursive_Programwill "Halt", thenRecursive_Programwill loop forever, which contradicts the prediction. - If the oracle predicts that
Recursive_Programwill "Loop Forever", thenRecursive_Programwill halt, which also contradicts the prediction.
These contradictions prove that there is no general algorithm that always tells whether a program will halt.
Decidability and formal systems
Decidability has large implications for formal systems. For example, it is undecidable whether a first-order logic formula is valid, that is, true under all interpretations.
Consider the formula below, where A and B take values from a domain of discourse, with 1 read as true and 0 as false:
A ∧ ¬B
- It is true if, in the domain of discourse, A = 1 and B = 0.
- It is false if A = 1 and B = 1.
The formula alone therefore does not settle whether it is true; one needs an interpretation of the domain of discourse as well.
It turns out, however, that it is decidable whether zero-order (propositional) logic formulas are valid. Algorithms exist for deciding this. A nice quality of SAT problems is that they are always decidable, even though they are NP-hard.
Algorithms that make SAT decidable
- Truth table assignments
- DPLL
- DFS
- and others