Reductions

An engineer and a mathematician are out for a walk and spot a house on fire. There is a garden hose lying in the yard; the engineer quickly hooks it up and puts out the fire.

They continue walking and see a home where a couple is washing a car in their driveway.

The mathematician detaches their hose and sets their house on fire, thus reducing the situation to a previously solved problem.

We proved that ATMA_\mathrm{TM} is undecidable using a tricky proof by contradiction. If we want to prove that other languages are undecidable, we can try to find similar tricks. But a simpler strategy is to leverage what we have already proved, a method known as reduction.

Definition

Given problems PP and QQ, we say that PP reduces to QQ, written

PQP \leq Q

if a solution to QQ would let us solve PP as well.

The notation is odd at first glance. The best way to think about PQP \leq Q is that it refers to difficulty; PP is easier (or at least, no harder) than QQ if solving QQ also tells us how to solve PP.

Not surprisingly, any formal language that is harder to decide than an undecidable language is also undecidable.

Example

The language

HALT={ M,w  M halts on input w }\mathit{HALT} = \{\ \langle M,w\rangle\ |\ M \mathrm{~halts~on~input~} w\ \}

is semidecidable, but not decidable.

Proof of Semidecidability: To show that HALT\mathit{HALT} is semidecidable, we can just give the algorithm for a semidecider, namely:

def semidecide_Halt(M, w):
    simulate(M, w)
    return True

That is, a semidecider for HALT\mathit{HALT} can simulate the given machine on the given input. If this halts then (whether it accepts or rejects) the semidecider accepts the pair. If the machine runs forever on that input, the semidecider returns no answer.

Proof of Undecidability: We will show that ATMHALTA_\mathrm{TM} \leq \mathit{HALT}, i.e. that if we could decide HALT\mathit{HALT} then we could decide ATMA_\mathrm{TM}. Since we know ATMA_\mathrm{TM} is not decidable, it follows that HALT\mathit{HALT} is not decidable either.

In other words, as soon as we prove that HALT\mathit{HALT} is at least as hard as the undecidable ATMA_\mathrm{TM}, we know that HALT\mathit{HALT} is undecidable too.

Here is why ATMHALTA_\mathrm{TM} \leq \mathit{HALT}:

Suppose we could build a decider decide_Halt for HALT\mathit{HALT}.

Then we could build a decider decide_Atm for ATMA_\mathrm{TM} as follows:

def decide_Atm(M, w):
    if decide_Halt(M, w):
        return simulate(M, w)
    else:
        return False

That is, to correctly predict whether MM will accept ww, we first check whether MM will halt on ww. If so, we can run MM on ww and be sure we will see it accept or reject in a finite amount of time. If not, we know MM does not accept ww and can report that immediately.

Proving Reductions

Decidability Reduction Proofs (L1L2L_1\leq L_2)

What does a proof look like?

A typical decidability reduction proof that L1L2L_1\leq L_2 goes as follows:

Assume there is a decider for L2L_2.
[Show an algorithm for deciding L1L_1.]
Therefore L1L_1 reduces to L2L_2. QED.

The direction is important. We assume the right-hand-side is decidable, and show that, if so, the left-hand-side is decidable.

Why is this useful?

A successful proof guarantees that

“if L2L_2 is decidable, then L1L_1 then is decidable.”

This direction is easiest to prove, but the logically equivalent contrapositive is more useful, namely

“if L1L_1 is not decidable, then L2L_2 is not decidable.”

This means that if we do a reduction proof where L1L_1 is a language like ATMA_\mathrm{TM} that we already know is not decidable, then our reduction proof guarantees that L2L_2 is not decidable.

For example, in the example above we proved that ATMHALTA_\mathrm{TM} \leq \mathit{HALT} (i.e., if ATMA_\mathrm{TM} is not decidable, then HALT\mathit{HALT} is not decidable). It immediately follows that HALT\mathit{HALT} is not decidable. So then if we manage to prove HALTL\mathit{HALT}\leq L' for some other language LL', it will immediately follow that LL' is not decidable either. In this way, we can use reduction to prove that more and more languages are not decidable.

Example

Aprime:={ M,w  M accepts w & Ms code has a prime number of states }A\mathrm{prime} := \{\ \langle M,w\rangle\ | \ M\mathrm{~accepts~} w \mathrm{~\&~} M\mathrm{'s~code~has~a~prime~number~of~states}\ \}

We can show AprimeA\mathrm{prime} is undecidable by proving ATMAprimeA_\mathrm{TM} \leq A\mathrm{prime}.

Proof 1
Suppose there were a decider decide_Aprime for AprimeA\mathrm{prime}. Then we could decide ATMA_\mathrm{TM} as follows:

Suppose we want to know if M,wATM\langle M,w\rangle\in A_\mathrm{TM}.\

  1. Construct a TM MM' that is exactly like MM plus enough extra dummy/unreachable/useless states so that it has a prime number of states.

    We haven’t changed the essential functionality of the TM, so L(M)=L(M)L(M) = L(M'), and MM accepts ww iff MM' accepts ww.

  2. We can run decide_Aprime on MM' and ww to find out whether MM' accepts ww and has a prime number of states.

  3. Since MM' has a prime number of states by construction, the result (true or false) tells us whether MM' accepts ww, and hence whether MM accepts ww.

Proof 2
Suppose there were a decider decide_Aprime for AprimeA\mathrm{prime}. Then we could decide ATMA_\mathrm{TM} as follows:

Suppose we want to know if M,wATM\langle M,w\rangle\in A_\mathrm{TM}.

  1. Let nn be the number of states in MM.

  2. Construct TMs M0,M1,,MnM_0, M_1, \ldots, M_n such that MiM_i is just like MM but with ii extra dummy/unreachable states.

  3. A bit of number theory (for any n1n\geq 1, there is a prime number between nn and 2n2n) guarantees that at least one of the MiM_i’s has a prime number of states.

  4. Run decide_Aprime on MiM_i and ww for all i0..ni\in 0..n.

  5. If at least one answer is “yes” then MM accepts ww. Otherwise, MM does not accept ww.

Semidecidability Reduction Proofs (L1L2L_1\leq L_2)

What does a proof look like?

A typical semidecidability reduction proof that L1L2L_1\leq L_2 goes as follows:

Assume there is a semidecider for L2L_2.
[Show an algorithm for semideciding L1L_1.]
Therefore L1L_1 reduces to L2L_2. QED.

Why is this useful?

A successful proof guarantees that

“if L1L_1 is not semidecidable, then L2L_2 is not semidecidable.”

This means that if we do a reduction proof where L1L_1 is a language like ¬ATM\lnot A_\mathrm{TM} that we already know is not semidecidable, then our reduction proof guarantees that L2L_2 is not semidecidable.

What’s up with the notation?

Irritatingly, the notation L1L2L_1\leq L_2 and terminology ”L1L_1 reduces to L2L_2” can either mean “if L2L_2 is decidable then so is L1L_1” or “if L2L_2 is semidecidable then so is L1L_1,” and these are not equivalent statements. Context usually tells us which meaning is intended.