Simple example of a Turing reduction:
showing that the no-input Halting problem is undecidable
\[ \probHALT_\emptystring = \setbuild{\encoding{M}}{M \text{ is a Turing machine and } M(\emptystring) halts} \]
Theorem: \(\probHALT_\emptystring\) is undecidable.
Proof:
Suppose that \(\probHALT_\emptystring\) is decidable by an algorithm:
from typing import Callable
def H_๐(M: Callable[[str], bool]) -> bool: raise NotImplementedError()
We can use this to decide \(\probHALT\) as follows:
def H(M: Callable[[str], bool], w: str) -> bool:
# Create a new algorithm T_Mw that ignores its input
# and has the original input w "hardcoded".
def T_Mw(x: str) -> bool: # This is algorithm is never actually run!!!
M(w) # Executing these lines merely *defines* T_Mw.
return H_๐(T_Mw) # ... but instead is *analyzed* by H_๐.
M(w) halts, then:
T_Mw halts on every input (including \(\emptystring\)).H_๐(T_Mw)returns True.M(w) loops (doesnโt halt), then:
T_Mw loops on every input (including \(\emptystring\)).H_๐(T_Mw) returns False.H decides \(\probHALT\), a contradiction.The previous argument follows a pattern we will use to show that many other questions we might ask about an algorithmโs eventual behavior are undecidable.
We prove that an algorithm \(A\) deciding that other question cannot exist by showing it can be used to solve the Halting problem.
We will use it to solve \(\probHALTe\), which is slightly more convenient than \(\probHALT\). (one fewer variable)
The steps to construct an algorithm for \(\probHALTe\) are:
We did (essentially) this when reducing \(\probHALT\) to \(\probHALTe\) by:
Letโs apply this recipe to the following problem:
\[ \probAccepts = \setbuild{\encoding{M, w}}{M \text{ is a Turing machine that accepts } w} \]
Theorem: \(\probAccepts\) is undecidable.
Proof:
Suppose that \(\probAccepts\) is decidable by alg. A:
def A(M, w): raise NotImplementedError()
We can use A to decide \(\probHALTe\) as follows:
def H_๐(M):
# Create a new algorithm T_M that accepts any input
# if and only if M halts on the empty string.
def T_M(w): # Input is ignored!
M('')
return True
return A(T_M, '011') # Analyze T_M using hypothetical decider A
M('') halts, then:
T_M accepts all inputs (including \(011\)).A(T_M, w) and H_๐ return True.M('') loops (does not halt), then:
T_M never reaches the return, so accepts no inputs (including \(011\)).A(T_M, w) and H_๐ return False.H_๐ decides \(\probHALTe\),\[ \probEmpty = \setbuild{\encoding{M}}{M \text{ is a Turing machine and } L(M) = \emptyset} \]
In other words: \(M\) accepts no inputs.
Theorem: \(\probEmpty\) is undecidable.
Proof:
Suppose that \(\probEmpty\) is decidable by algorithm E:
def E(M): raise NotImplementedError()
We can use E to decide \(\probHALTe\) as follows:
def H_๐(M):
# Create a new algorithm that accepts a string
# if and only if M halts on the empty string.
def T_M(w):
M('')
return True
return not E(T_M) # Analyze T_M using hypothetical decider E
M('') halts, then:
T_M accepts all inputs, so \(L(T_M) \ne \emptyset\).E(T_M) returns False, soH_๐ returns True.M('') loops, then:
T_M never reaches the return, so accepts no inputs, so \(L(T_M) = \emptyset\).E(T_M) returns True, soH_๐ returns False.H_๐ decides \(\probHALTe\),Could we instead make T_M return False and H_๐ return E(T_M)?
\[ \probRejects = \setbuild{\encoding{M}}{M \text{ is a Turing machine that rejects at least one input}} \]
Theorem: \(\probRejects\) is undecidable.
Proof:
Suppose that \(\probRejects\) is decidable by algorithm R:
def R(M): raise NotImplementedError()
We can use R to decide \(\probHALTe\) as follows:
def H_๐(M):
# Create a new algorithm that rejects a string
# if and only if M halts on the empty string.
def T_M(w):
M('')
return False
return R(T_M) # Analyze T_M using hypothetical decider R
M('') halts, then:
T_M rejects all inputs.R(T_M) returns True, soH_๐ returns True.M('') does not halt, then:
T_M never reaches the return, so rejects no inputs.R(T_M) returns False, soH_๐ returns False.H_๐ decides \(\probHALTe\),return without a subroutine call?f (whether or not it is ever called)?Which of the following problems, about program \(P\) (and possibly input \(x\)) is decidable?