Sub topic 11
Proving undecidability by reduction
This chapter assumes you know the formal definition of a Turing machine (TM). It also assumes you know the difference between decidable and semi-decidable languages, and that you have seen the proof that A_TM and the halting problem are undecidable. Reductions are how you spread that single result to many other problems.
The idea
Suppose you already know that problem A is undecidable. You want to show that problem B is undecidable too. You show that a decider for B would give you a decider for A. Since no decider for A exists, no decider for B exists either.
Each decision problem is a language of yes-instances. A many-one reduction from A to B is a computable function f that maps strings to strings such that, for every string w:
- w is in A if and only if f(w) is in B.
We write A ≤m B. The function f must be total and computable, meaning some TM halts on every input and leaves f(w) on its tape. Nothing is required of f beyond that. In particular, f does not need to be one-to-one.
What a reduction tells you
The direction is the main source of mistakes. If A ≤m B, then:
- If B is decidable, A is decidable.
- If A is undecidable, B is undecidable.
- If B is recursively enumerable (RE), A is RE.
- If A is not RE, B is not RE.
The reduction carries difficulty from A to B. B is at least as hard as A. To prove that B is hard, you reduce a known hard problem to B. Reducing B to a known hard problem proves nothing.
| You know | You reduce | You can conclude |
|---|---|---|
| A is undecidable | A ≤m B | B is undecidable |
| B is decidable | A ≤m B | A is decidable |
| A is not RE | A ≤m B | B is not RE |
| B is RE | A ≤m B | A is RE |
| A is undecidable | B ≤m A | nothing about B |
Note that "B is undecidable" does not mean B is not RE. A_TM and HALT are undecidable but RE. Their complements are not RE.
The standard recipe
- Pick a known undecidable problem A. The usual choices are ATM, HALT, or ETM.
- Assume a decider R for your target problem B exists.
- Build a decider S for A that, given an input w, constructs an instance f(w) of B and runs R on it.
- Show that S answers correctly: w is in A exactly when R accepts f(w).
- Since A is undecidable, S cannot exist, so R cannot exist.
The key step is the construction in step 3. S never runs the machine it builds, unless it does so inside the constructed machine. S only writes down a description of that machine. Writing down a description always halts, even if running the machine would loop forever. This is what makes the reduction computable.
Worked example 1: HALT from A_TM
Define the two languages:
- A_TM = { ⟨M, w⟩ : M accepts w }
- HALT = { ⟨M, w⟩ : M halts on w }
Claim: HALT is undecidable. We reduce A_TM to HALT.
Suppose a decider H for HALT exists. Build a decider S for A_TM. On input ⟨M, w⟩:
- Run H on ⟨M, w⟩.
- If H rejects, M loops on w, so M does not accept it. Reject.
- If H accepts, M halts on w. Simulate M on w, which is now safe because it halts. If M accepted, accept. If M rejected, reject.
S decides A_TM, which is impossible. So H does not exist.
In the formal many-one form, f maps ⟨M, w⟩ to ⟨M', w⟩, where M' behaves like M but loops forever wherever M would reject. Then M accepts w exactly when M' halts on w.
Worked example 2: E_TM is undecidable
Define ETM = { ⟨M⟩ : L(M) = ∅ }, the emptiness problem. We show that ATM reduces to the complement of E_TM, which is enough.
Given ⟨M, w⟩, build a machine M_w that works like this on any input x:
- Ignore x.
- Run M on w.
- If M accepts w, accept. Otherwise reject, or loop.
Then:
- If M accepts w, then Mw accepts every x, so L(Mw) = Σ*, which is not empty.
- If M does not accept w, then Mw accepts nothing, so L(Mw) = ∅.
So ⟨M, w⟩ is in ATM exactly when ⟨Mw⟩ is not in ETM. A decider for ETM would let us decide ATM by running it on ⟨Mw⟩ and flipping the answer. Hence E_TM is undecidable.
The machine M_w is only constructed. It is never run during the reduction. This is the pattern for almost every GATE-level reduction.
Worked example 3: EQ_TM is undecidable
Define EQTM = { ⟨M1, M2⟩ : L(M1) = L(M2) }. Reduce ETM to it. Let M∅ be a fixed machine that rejects every input, so L(M∅) = ∅. Given ⟨M⟩, output ⟨M, M∅⟩. Then L(M) = ∅ if and only if ⟨M, M∅⟩ is in EQTM. A decider for EQTM would decide ETM, so EQTM is undecidable.
This is a reduction from one language to another, with no new simulation needed. Once you have a stock of undecidable problems, later proofs get shorter.
Seeing the machine construction in code
The sketch below mirrors the ETM reduction. Programs stand in for TMs. The function `buildMw` returns a new program and never runs it.
def build_Mw(M, w):
"""Return a program M_w that ignores its input and accepts
exactly when M accepts w. M is a callable returning True/False."""
def Mw(x):
return M(w) # ignore x, run M on w
return Mw
def accepts_via_emptiness(M, w, decides_emptiness):
"""Decide whether M accepts w, assuming a decider for emptiness.
decides_emptiness(P) is True when P accepts no input at all."""
Mw = build_Mw(M, w)
return not decides_emptiness(Mw)
# Demonstration with a fake, non-general "emptiness decider" that
# only works because we test it on tiny, always-halting programs.
def toy_emptiness(P):
return not any(P(x) for x in ["", "a", "b"])
def M_even_length(s):
return len(s) % 2 == 0
print(accepts_via_emptiness(M_even_length, "ab", toy_emptiness)) # True
print(accepts_via_emptiness(M_even_length, "abc", toy_emptiness)) # FalseThe toy decider only works because these programs always halt and a finite probe suffices here. No general decides_emptiness can exist, and that is the point of the proof.
Reductions that show a language is not RE
Reductions also prove that a language is not RE. The complement of ATM is not RE. This follows from a fact you already know: a language that is both RE and co-RE is recursive. ATM is RE but not recursive, so its complement cannot be RE.
Now suppose you want to show that some language L is not RE. Reduce the complement of ATM to L. If L were RE, the complement of ATM would be RE, which is false. Equivalently, a reduction A ≤m B implies that the complement of A reduces to the complement of B using the same f. This is why E_TM is co-RE but not RE, while its complement is RE but not recursive.
Edge cases and common errors
- Wrong direction. Reducing the target problem to a known hard one proves nothing. Always ask which problem you are assuming a decider for.
- Running a machine that may loop. Inside S, you cannot simulate M on w and wait, unless you only need the answer if it halts. A reduction must produce its output in finite time. Build the new machine and stop.
- Confusing "undecidable" with "not RE". HALT is undecidable but RE. Check which side a question asks about.
- Non-total f. If your function can loop on some inputs, it is not a many-one reduction.
- Fixed instances are fine. A reduction may output a constant string for some inputs, as in the M∅ example. It must still be computable and correct for every input.
- Malformed inputs. If w is not a valid encoding, f can map it to a fixed string that is not in B. The proof still holds.
Many-one versus Turing reductions
A many-one reduction transforms one input into one input, and answers are passed through unchanged. A Turing reduction is more general: the decider for A may call a decider for B many times and use the answers however it likes. Example 1 above is really a Turing-style argument, because S uses H and then also simulates M. Both styles prove undecidability. Only many-one reductions let you conclude that a language is not RE, since a Turing reduction can flip the answer or call B repeatedly, which breaks the RE argument.
Exercise
A language A satisfies A ≤m B, and you know that B is recursively enumerable. Which of these must be true: (a) A is decidable, (b) A is RE, (c) B is decidable, (d) the complement of A is RE?
Show answer
Only (b). A many-one reduction passes recursive enumerability back from B to A: to semi-decide w in A, compute f(w) and run the semi-decider for B on it. The other statements do not follow, because B may be RE and undecidable, and the complement of A need not be RE.
Exercise
To prove that the language ALLTM = { ⟨M⟩ : L(M) = Σ* } is undecidable, you reduce ATM to it. Given ⟨M, w⟩, describe the machine Mw you output and say when ⟨M, w⟩ is in ATM exactly when ⟨Mw⟩ is in ALLTM.
Show answer
Let Mw ignore its input x, run M on w, and accept if M accepts w. If M accepts w, Mw accepts every input, so L(Mw) = Σ* and ⟨Mw⟩ is in ALLTM. If M does not accept w, Mw accepts nothing, so L(Mw) = ∅ ≠ Σ* and ⟨Mw⟩ is not in ALLTM. So ⟨M, w⟩ is in ATM if and only if ⟨Mw⟩ is in ALLTM. The map is computable because it only writes down M_w.
Exercise
A student says "I will prove problem P undecidable by reducing P to A_TM." What is wrong with this plan?
Show answer
It goes the wrong way. A reduction P ≤m ATM would show that P is no harder than ATM. ATM is undecidable, so this says nothing about P. The correct plan is to reduce a known undecidable problem, such as ATM, to P.