Section 6 · 10 min read
Turing machines and undecidability
Turing machines and their variants, recursive, RE and co-RE languages, the halting problem, reductions, Rice's theorem, and the decidability status of standard problems for each language class.
On this page
The question this topic answers
Regular and context-free languages are about how much memory a machine has. Turing machines remove the memory limit, and the question changes: not "can a machine recognize this?" but "can a machine always finish and give the answer?". GATE asks this every year in the form "which of these problems is decidable", plus a question on RE versus recursive and one on Rice's theorem or reductions.
Turing machines
A (deterministic, single-tape) Turing machine is :
- : finite set of states, the start state, the accepting (halting) states
- : input alphabet; : tape alphabet, with blank
- : read a symbol, write a symbol, move one cell
The tape is infinite to the right (or both ways; it does not matter). On input the machine either accepts, rejects, or runs forever. This third outcome is what makes everything here interesting.
Variants with the same power
All of the following accept exactly the same languages as the basic TM:
- multi-tape TMs (simulated with polynomial slowdown)
- two-way infinite tape
- nondeterministic TMs (simulated by breadth-first search over computations, exponential slowdown)
- TMs with a stay-in-place move
- two-stack PDAs, queue automata, two-counter machines
- enumerators (machines that print the strings of the language)
Weaker models: a finite automaton (regular), a one-stack PDA (CFL), and a linear bounded automaton (a nondeterministic TM restricted to the cells holding the input), which accepts exactly the context-sensitive languages.
The Church-Turing thesis states that anything computable by an effective procedure is computable by a Turing machine. It is a thesis, not a theorem, because "effective procedure" is informal.
Recursive, RE and co-RE
| Class | Definition | Machine behaviour |
|---|---|---|
| Recursive (decidable) | some TM accepts and halts on every input | always answers yes or no |
| Recursively enumerable (RE, semi-decidable, Turing-recognizable) | some TM accepts exactly | halts and accepts on members; may loop on non-members |
| co-RE | is RE | can confirm non-members; may loop on members |
The central theorem:
Run the two recognizers in parallel, one step each in turn. Every input is accepted by one of them, so the combination always halts. Consequences:
- If is RE but not recursive, then is not RE.
- Recursive = RE co-RE.
- There are languages that are neither RE nor co-RE, for example .
Hierarchy
Every inclusion is proper.
Countability
TMs have finite descriptions, so there are countably many TMs and therefore countably many RE languages. The set of all languages over even a one-letter alphabet is the power set of a countably infinite set, which is uncountable. So most languages are not RE. This counting argument shows non-RE languages exist without naming one.
The halting problem
and are both RE (simulate on ) and both undecidable.
Diagonal argument (sketch). Suppose decides . Build : on input , run on and do the opposite. Then on accepts if and only if it does not accept. Contradiction.
So and are co-RE and not RE.
Reductions
(many-one reduction) means there is a computable function with .
- If is decidable, then is decidable.
- If is RE, then is RE.
- If is undecidable, then is undecidable.
- If is not RE, then is not RE.
Information flows upward for hardness (from to ) and downward for easiness (from to ). A reduction also works for complements: implies .
To prove a new problem undecidable, reduce a known undecidable problem (usually or ) to .
Rice's theorem
Statement. Let be a property of RE languages (a set of RE languages) that is non-trivial: some RE language has it and some RE language does not. Then is undecidable.
How to apply it:
- Is the question about only, so two machines with the same language always get the same answer? If it is about states, steps, head moves or tape contents, Rice does not apply.
- Is it non-trivial? Find one RE language with the property and one without.
- If both hold, the problem is undecidable.
Rice tells you "undecidable", nothing more. Whether the problem is RE, co-RE or neither needs extra reasoning. A useful guide (the Rice-Shapiro theorem): a property can be RE only if membership is witnessed by a finite set of strings. " is non-empty" is RE; " is infinite" and "" are not.
Decidability of standard problems
D = decidable, U = undecidable. The input is a machine or grammar of the given class.
| Problem | Regular | DCFL | CFL | CSL | Recursive | RE |
|---|---|---|---|---|---|---|
| Membership: is ? | D | D | D | D | D | U |
| Emptiness: is ? | D | D | D | U | U | U |
| Finiteness: is finite? | D | D | D | U | U | U |
| Universality: is ? | D | D | U | U | U | U |
| Equivalence: is ? | D | D | U | U | U | U |
| Containment: is ? | D | U | U | U | U | U |
| Disjointness: is ? | D | U | U | U | U | U |
| Is regular? | D | D | U | U | U | U |
Notes:
- DCFL equivalence was proved decidable in 1997. Older books list it as open; go with the current result.
- DCFL universality is decidable because DCFLs are closed under complement and DCFL emptiness is decidable.
- Ambiguity of a CFG is undecidable. Whether a CFG is LL(1) or LR(k) for a fixed is decidable.
- Membership for CSL is decidable because productions never shorten the sentential form; there are finitely many forms of length at most .
Post Correspondence Problem
Given tiles , is there a non-empty index sequence with ?
- Undecidable in general; RE (enumerate sequences).
- Decidable when the alphabet has one symbol (only lengths matter).
- PCP is the usual source for proving CFG problems undecidable: ambiguity, intersection emptiness of two CFGs, and universality.
Problems that look undecidable but are not
- Does halt on within steps? Simulate steps.
- Does have more than states? Read the description.
- Does ever move left on input ? If it only moves right, after steps it is on blanks with a repeated state and will repeat forever.
- Does visit more than tape cells on ? With cells there are finitely many configurations, so either it leaves the region or it repeats a configuration.
Worked examples
Worked example 1: Applying Rice's theorem
Which of these are decidable for a TM ?
- contains : about the language, non-trivial. Undecidable.
- has an even number of states: not about the language. Decidable.
- is a context-free language: non-trivial ( is CFL, is not). Undecidable.
- is an RE language: every is RE, so the property is trivial. Decidable (always yes).
- halts on within 1000 steps: about running time. Decidable.
Worked example 2: A reduction
Show is undecidable.
Reduce to . Given , build : erase the tape, write , then run . The function is computable, and halts on blank tape exactly when halts on . If were decidable, would be decidable. So is undecidable. Since is RE and is clearly RE as well (simulate), is RE but not recursive.
Worked example 3: Classifying RE and co-RE
Classify each set of TM encodings.
- . Dovetail over all strings and all step counts; accept once 3 acceptances are seen. RE, not recursive (Rice).
- . Complement of "accepts at least one string", which is RE. So is co-RE, not RE.
- . Neither RE nor co-RE. It is not RE by Rice-Shapiro (finiteness is not witnessed by finitely many strings), and its complement " is infinite" is not RE either.
- . The bound is computed from the description of , then a finite simulation answers the question. Decidable. Rice does not apply because two machines with the same language can have different step counts.
Worked example 4: Closure with recursive and RE
is RE and not recursive; is recursive. What can be said about ?
. is not RE. With , the difference is itself, which is not RE. So need not be RE. In contrast, is RE because is recursive.
Common traps
- Rice needs a property of the language. Questions about states, steps, tape cells or head moves are outside Rice and are often decidable.
- Trivial properties are decidable. " is RE" is always true.
- Undecidable is not the same as not RE. is undecidable but RE.
- Reduction direction. Reduce the known hard problem to the new one.
- CFG problems. Membership, emptiness and finiteness are decidable; equivalence, universality, ambiguity and intersection emptiness are not.
- CSL emptiness is undecidable even though CSL membership is decidable.
- Two-stack PDA and multi-tape TM have exactly the power of a TM; an LBA does not.
- Complement of RE. RE is not closed under complement; recursive is.
Quick revision
- Recursive: TM halts on all inputs. RE: TM accepts members, may loop otherwise.
- Recursive RE co-RE.
- , : RE, not recursive. Their complements: co-RE, not RE.
- and " finite": neither RE nor co-RE.
- : decidable gives decidable; undecidable gives undecidable.
- Rice: every non-trivial property of is undecidable.
- Regular: everything decidable. CFL: membership, emptiness, finiteness only. CSL: membership only. RE: nothing in the table.
- PCP: undecidable in general, decidable over a unary alphabet.
- Countably many TMs, uncountably many languages, so non-RE languages exist.