Sub topic 12
Turing Reductions and Oracles
This chapter assumes you have read the earlier chapters on many-one reductions, polynomial-time reductions, and NP-completeness. It also assumes you can read simple Python and are comfortable with the Independent Set problem. A many-one reduction is limited in two ways: it asks the target problem one question, and it must return that answer unchanged. A Turing reduction drops both limits. This chapter defines Turing reductions, shows what they can do that many-one reductions cannot, and explains why the extra power has a cost.
The Oracle Model
An oracle for a language B is a black box that answers any question of the form "is q in B?" in a single step. An oracle Turing machine is an ordinary Turing machine with an extra query tape. It writes a string q on that tape, enters a special query state, and on the next step learns whether q is in B. The machine can do this as many times as it likes, and it can use earlier answers to decide what to ask next.
A language A is Turing-reducible to B, written A ≤_T B, if some oracle Turing machine with an oracle for B decides A. "Decides" means it halts on every input with the correct answer. The idea is "if I could solve B for free, I could solve A."
In code, an oracle is just a function argument. You treat it as a black box and do not ask how it works.
Polynomial-time Turing reductions
If the oracle machine runs in polynomial time, counting each query as one step, you have a polynomial-time Turing reduction, written A ≤_T^p B. It is also called a Cook reduction, after Stephen Cook, who used this notion in 1971. The time bound limits the reduction in two ways. It can make only polynomially many queries, and each query string has polynomial length, because the machine has to write the string out.
Many-One Reductions Are a Special Case
A many-one reduction f is a Turing reduction that computes f(x), makes one query, and outputs the oracle's answer unchanged. A Turing reduction is allowed three things that a many-one reduction is not:
- It can make several queries.
- It can make adaptive queries, where the next question depends on earlier answers.
- It can post-process the answers, for example by negating them or combining them with AND.
| Feature | Many-one (≤_m, Karp) | Turing (≤_T, Cook) |
|---|---|---|
| Number of oracle calls | Exactly one | Any number (polynomial for ≤_T^p) |
| Can negate the answer | No | Yes |
| Adaptive queries | Not applicable | Yes |
| A reduces to its complement | Not in general | Always |
| Preserves membership in NP | Yes | Not known (fails unless NP = coNP) |
| Preserves recognizability | Yes | No |
| Typical use | NP-completeness, undecidability proofs | Search-to-decision, optimization, relative computability |
Worked Example: Using an Independent Set Oracle
Suppose has_is(vertices, edges, k) answers the decision problem "does the graph have an independent set of size at least k?" The code below asks two questions that no single many-one query answers directly. The first is whether the maximum independent set has size exactly k. The second is what the maximum size is. The oracle here is a brute-force function so the code runs. The reductions themselves never look inside it.
from itertools import combinations
def has_is(vertices, edges, k):
"""Brute-force oracle: is there an independent set of size >= k?"""
if k <= 0:
return True
edge_set = {frozenset(e) for e in edges}
for cand in combinations(vertices, k):
if all(frozenset(p) not in edge_set for p in combinations(cand, 2)):
return True
return False
class CountingOracle:
"""Wraps an oracle and counts how many times it is queried."""
def __init__(self, oracle):
self.oracle = oracle
self.calls = 0
def __call__(self, vertices, edges, k):
self.calls += 1
return self.oracle(vertices, edges, k)
def max_is_exactly(vertices, edges, k, oracle):
# Two non-adaptive queries; the second answer is negated.
return oracle(vertices, edges, k) and not oracle(vertices, edges, k + 1)
def max_is_size(vertices, edges, oracle):
# Adaptive binary search: about log2(|V|) queries.
lo, hi = 0, len(vertices) # invariant: answer lies in [lo, hi]
while lo < hi:
mid = (lo + hi + 1) // 2
if oracle(vertices, edges, mid):
lo = mid
else:
hi = mid - 1
return lo
cycle5 = ([1, 2, 3, 4, 5], [(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)])
o = CountingOracle(has_is)
print(max_is_exactly(*cycle5, 2, o)) # True
print(max_is_size(*cycle5, o)) # 2
print("oracle calls:", o.calls) # 2 + 3 = 5max_is_exactly uses all three Turing features at once: two queries, a negation, and an AND. The "exactly k" problem is believed to lie outside both NP and coNP. It belongs to a class called DP, so no many-one reduction to Independent Set is expected to exist. max_is_size is adaptive, because each midpoint depends on earlier answers. It solves an optimization problem in O(log |V|) queries.
What Transfers Through a Turing Reduction
The direction rule from the earlier chapter still holds. If A ≤_T B:
- If B is decidable, then A is decidable. Replace the oracle with a decider for B. Every query halts, so the whole machine halts.
- If A ≤_T^p B and B is in P, then A is in P. Polynomially many polynomial-time calls on polynomial-size inputs still take polynomial time.
- By the contrapositive, hardness moves the other way. If A is undecidable, so is B. If A is not in P, neither is B.
What Does Not Transfer
The ability to negate answers is what breaks the remaining properties.
Every language Turing-reduces to its complement. To decide A with an oracle for the complement of A, ask about x and flip the answer. So the complement of HALT satisfies co-HALT ≤_T HALT, even though co-HALT is not Turing-recognizable while HALT is. Recognizability does not transfer. That is why undecidability proofs that conclude "not recognizable" must use many-one reductions.
NP is not known to be closed under Cook reductions. UNSAT, the set of unsatisfiable formulas, satisfies UNSAT ≤_T^p SAT with one negated query. If NP were closed under Cook reductions, UNSAT would be in NP and NP would equal coNP, which is widely believed false.
Common Errors
- Forgetting that the reduction must halt. A ≤_T B requires the oracle machine to halt on every input. A machine that loops waiting for some condition does not count, even if each individual query is fine.
- Charging nothing for query size. In a polynomial-time Turing reduction, an exponentially long query would take exponential time to write. Check both the number of queries and the length of each one.
- Reading a Turing reduction as a Karp reduction. Two queries combined with AND do not make a many-one reduction, even if the code looks short.
- Assuming the oracle returns solutions. A decision oracle only answers yes or no. Recovering an actual independent set needs extra work, which the chapter on search-to-decision covers.
Where Turing Reductions Are Used
Turing reductions are the natural tool when the goal is "can I solve A if I can solve B?" rather than a fine-grained classification. Typical uses are turning decision procedures into optimization or search algorithms, calling a SAT solver repeatedly in practice, and studying relative computability. For example, the degrees of undecidability are defined by ≤_T. When the goal is to place a problem precisely in NP, or to show it is not recognizable, use many-one reductions.
Exercise
Show that HALT ≤_T co-HALT, where co-HALT is the set of pairs (M, w) such that M does not halt on w. Is there also a many-one reduction from HALT to co-HALT?
Show answer
On input (M, w), query the oracle with (M, w) and output the opposite answer. This makes one query and always halts, so it is a Turing reduction. No many-one reduction exists. If HALT ≤m co-HALT, then complementing both sides gives co-HALT ≤m HALT. HALT is recognizable and many-one reductions preserve recognizability, so co-HALT would be recognizable. Then HALT would be both recognizable and co-recognizable, hence decidable, which is a contradiction.
Exercise
A graph has 100 vertices. How many oracle calls does maxissize make in the worst case, and why is the reduction still polynomial time if each call is on the original graph?
Show answer
The search interval starts with 101 possible values (0 to 100), and each query roughly halves it, so it takes at most ceil(log2 101) = 7 calls. Each query is the original graph plus a number of O(log n) bits, so the query length is polynomial. Seven calls of polynomial size, plus O(1) work per step, take polynomial time.
Exercise
Explain in two or three sentences why UNSAT ≤_T^p SAT does not imply that UNSAT is in NP.
Show answer
The reduction negates the oracle's answer. Membership in NP is preserved by many-one reductions, which return the answer unchanged, but not by negation: a short certificate for "satisfiable" gives no short certificate for "unsatisfiable." If Cook reductions preserved NP, UNSAT would be in NP and NP would equal coNP.