Sub topic 16
Common Mistakes and How to Check a Reduction
This chapter assumes you have worked through the earlier chapters on many-one and polynomial-time reductions, NP-completeness, the 3-SAT to Independent Set gadget, and Turing reductions. You should be comfortable reading Python and brute-force search code.
A reduction proof often looks right even when it is wrong. Most errors fall into a small number of patterns. This chapter lists those patterns, explains why each one breaks the proof, and gives you a routine you can use to check any reduction, including testing it by machine on small instances.
What a correct reduction must satisfy
A many-one reduction from A to B is a function f with these properties:
- Totality. f is defined on every input string, including malformed ones.
- Efficiency. f runs in time polynomial in the input length. This applies only to Karp reductions. For undecidability you need computability, not speed.
- Completeness. If x is a yes-instance of A, then f(x) is a yes-instance of B.
- Soundness. If f(x) is a yes-instance of B, then x is a yes-instance of A. This is the contrapositive of "no maps to no".
- Uniformity. f sees only x. It does not see a certificate, the answer, or any hint that depends on the answer.
Every mistake below breaks one of these five conditions.
Mistake 1: Reducing in the wrong direction
To show a new problem X is NP-hard, you reduce a known hard problem to X. A common slip is to reduce X to SAT and then conclude that X is hard. That reduction proves X is in NP, or at least that X is no harder than SAT. It says nothing about X being hard, because easy problems reduce to SAT too.
A quick test: in "A ≤ B", hardness flows from A to B and algorithms flow from B to A. Write down which problem you already know something about. That problem must be on the side the knowledge flows out of.
Mistake 2: Proving only one direction of correctness
Completeness is usually the easy direction. You take a satisfying assignment, point at the matching structure in the constructed instance, and you are finished. Soundness is where reductions fail. The constructed instance may have unintended solutions that do not correspond to any solution of the original.
In 3-SAT to Independent Set, suppose you forget the triangle edges inside each clause gadget. Completeness still holds. Soundness fails: an independent set of size m can now take two literals from one clause and none from another, so it no longer certifies that every clause is satisfied. Suppose you forget the conflict edges instead. Then an independent set can contain both x and ¬x, which does not correspond to any assignment.
Mistake 3: Letting the reduction solve the problem
The map f has to be computed without knowing the answer. Watch for these errors:
- Using the certificate. A phrase like "given a satisfying assignment, construct the graph..." is wrong. The reduction receives only the formula.
- Branching on the answer. "If the formula is satisfiable, output a triangle; otherwise output an edge" is a correct many-one map, but computing it takes as long as solving SAT. It breaks the efficiency condition.
- Hidden exponential work. Enumerating all assignments, all subsets, or all paths inside f is an exponential search, even if each step looks harmless.
Mistake 4: Size and number blowup
Polynomial time is measured in the length of the encoding, and numbers are written in binary. A reduction that outputs the number 2ⁿ is fine, since that takes n + 1 bits. A reduction that outputs 2ⁿ objects, or that writes a number in unary when its value is exponential, is not polynomial.
This distinction decides results. Subset Sum is NP-complete with binary numbers, but it has a pseudo-polynomial dynamic program. A reduction to Subset Sum that only works when the numbers are written in unary proves nothing about the binary version. Composition can also cause trouble. Applying one polynomial reduction a constant number of times is fine. A reduction that calls itself recursively and doubles the instance at each of n levels is not.
Mistake 5: Parameter and inequality mismatches
Threshold parameters are easy to get wrong:
- Independent Set asks for size at least k, and Vertex Cover asks for size at most |V| − k. If you write |V| − k + 1, or flip ≤ and ≥, one direction of the proof fails.
- Optimization problems must be turned into decision versions consistently. "Minimum cover size" and "is there a cover of size ≤ k" are different objects.
- In gadget reductions, k usually equals the number of gadgets, here m clauses. Check that the bound forces exactly one choice per gadget.
Mistake 6: Violating the target problem's restrictions
If you reduce to a restricted problem such as 3-SAT, Planar Graph Coloring, or Max-Degree-3 Vertex Cover, every output instance must meet the restriction. Clauses with two literals, repeated literals, or non-planar crossings make the output an instance of a different problem.
The source side has the matching error. If you reduce from a restricted variant, that variant must itself be proved hard. "Reduce from 3-SAT where each variable appears twice" is only valid if that version is NP-complete. (It is not. Restricted to at most two occurrences per variable, 3-SAT becomes polynomial-time solvable.)
Mistake 7: Confusing Turing and many-one reductions
A Turing reduction may call the oracle many times and post-process the answers, including negating them. Under Turing reductions, a problem and its complement reduce to each other trivially. So a Turing reduction from SAT to X shows X is NP-hard in the Turing sense, but it does not give the Karp-style NP-completeness that the standard definition requires. If your proof calls a decision procedure for X more than once, or flips its output, you have a Turing reduction.
Mistake 8: Forgetting half of NP-completeness
NP-complete means in NP and NP-hard. Proofs often skip the membership half. You need a polynomial-size certificate and a polynomial-time verifier. Some problems, such as deciding whether a graph has exactly k maximum cliques, are NP-hard but probably not in NP.
Summary table
| Mistake | Condition broken | How to catch it |
|---|---|---|
| Wrong direction | Logic of transfer | Write "known ≤ new" and confirm the known-hard problem is on the left |
| One-sided proof | Soundness | Start from an arbitrary target solution and decode it |
| Reduction uses answer or certificate | Uniformity, efficiency | List f's inputs; time each step |
| Exponential blowup | Efficiency | Bound output length by the input length in bits |
| Wrong threshold | Completeness or soundness | Test boundary values k, k ± 1 |
| Output breaks target restrictions | Validity of output | Run a validator on every output |
| Multiple oracle calls or negation | Many-one form | Count oracle calls in the proof |
| Missing NP membership | Definition | Write the verifier explicitly |
| f undefined on garbage input | Totality | Map malformed inputs to a fixed no-instance |
A routine for checking a reduction
Test by machine on small instances
A proof is required, but a brute-force test finds most bugs in seconds. Solve both the source and target instances by exhaustive search and compare the answers on many random small cases.
import random
from itertools import combinations, product
def three_sat_to_independent_set(clauses):
vertices, edges = [], []
for i, clause in enumerate(clauses):
nodes = [(i, j, lit) for j, lit in enumerate(clause)]
vertices.extend(nodes)
edges.extend(combinations(nodes, 2)) # clause triangle
for a, b in combinations(vertices, 2):
if a[2] == -b[2]:
edges.append((a, b)) # conflict edge
return vertices, edges, len(clauses)
def sat_brute(clauses):
vs = sorted({abs(l) for c in clauses for l in c})
for bits in product([False, True], repeat=len(vs)):
a = dict(zip(vs, bits))
if all(any(a[abs(l)] == (l > 0) for l in c) for c in clauses):
return True
return False
def has_independent_set(vertices, edges, k):
adj = {frozenset(e) for e in edges}
for s in combinations(vertices, k):
if all(frozenset(p) not in adj for p in combinations(s, 2)):
return True
return False
def random_3cnf(n_vars, n_clauses, rng):
out = []
for _ in range(n_clauses):
vs = rng.sample(range(1, n_vars + 1), 3)
out.append(tuple(v if rng.random() < 0.5 else -v for v in vs))
return out
rng = random.Random(0)
for _ in range(300):
f = random_3cnf(rng.randint(3, 4), rng.randint(1, 6), rng)
V, E, k = three_sat_to_independent_set(f)
assert sat_brute(f) == has_independent_set(V, E, k), f
print("all 300 instances agree")Make sure the test includes no-instances. Random small formulas are mostly satisfiable, and a reduction that always outputs yes would pass a test made only of those. Add known unsatisfiable formulas. For example, all eight sign patterns over variables 1, 2, 3 give an unsatisfiable formula. Then delete one line of the reduction and confirm the test fails.
Exercises
Exercise
A student shows that a scheduling problem X is NP-hard by giving a polynomial-time map from X instances to SAT formulas, satisfiable exactly when the schedule exists. What is wrong, and what does the argument actually prove?
Show answer
The reduction goes the wrong way. Showing X ≤ SAT proves only that X is no harder than SAT. Together with polynomial time, that places X in NP. To prove hardness, the student must reduce a known NP-hard problem, such as SAT, to X.
Exercise
In the 3-SAT to Independent Set reduction, remove the conflict edges between x and ¬x but keep the clause triangles. Which correctness direction fails? Give a formula that shows it.
Show answer
Soundness fails. Completeness still holds. For the formula (x1 ∨ x1' ...) take two clauses (1, 2, 3) and (-1, -2, -3) together with all other sign patterns on variables 1, 2, 3. The full set of eight clauses is unsatisfiable. Without conflict edges, you can pick one vertex from each triangle freely, so an independent set of size 8 exists and the map sends a no-instance to a yes-instance.
Exercise
A reduction from Partition outputs, for input numbers a1..an, a list of 2^n items, one per subset. Explain why this is not a valid Karp reduction even though each item is computed quickly.
Show answer
The output has 2^n items, so writing it takes exponential time in the input length. Polynomial time per item does not help, because the total output size must be polynomial in the number of input bits.