Sub topic 7
Chaining Reductions Together
This chapter assumes you know what a many-one reduction is, how to prove one correct in both directions, and what polynomial-time (Karp) reductions are. It also uses the Clique, Independent Set, and Vertex Cover reductions from the earlier chapters.
Why chaining matters
You will rarely reduce a new problem straight from SAT. Most hardness proofs start from whichever known hard problem looks most like the new one. That only works if reductions compose: if A reduces to B and B reduces to C, then A must reduce to C. This property is called transitivity. It turns the collection of known reductions into a connected web. A new link anywhere in the web extends what you already know.
The composition theorem
Suppose f is a polynomial-time reduction from A to B, and g is one from B to C. Define h(x) = g(f(x)). Two facts make h a reduction from A to C.
| Property | Why it holds |
|---|---|
| Correctness | x ∈ A ⇔ f(x) ∈ B ⇔ g(f(x)) ∈ C. Each equivalence comes from one reduction. |
| Polynomial time | If f runs in time p(n), its output has length at most p(n). Then g runs in time q(p(n)), and a polynomial of a polynomial is still a polynomial. |
Most errors in this proof come from the running-time step. People bound g's time by q(n), as though g received the original input. But g receives f(x), which can be much larger than x. The bound has to use the output size of f.
Composing reductions in code
The code below chains Clique ≤p Independent Set ≤p Vertex Cover into one reduction from Clique to Vertex Cover. It then checks the composed map against brute-force solvers on random small graphs.
import random
from itertools import combinations
def complement_edges(vertices, edges):
present = {frozenset(e) for e in edges}
return [(u, v) for u, v in combinations(vertices, 2)
if frozenset((u, v)) not in present]
def clique_to_independent_set(vertices, edges, k):
return vertices, complement_edges(vertices, edges), k
def independent_set_to_vertex_cover(vertices, edges, k):
return vertices, edges, len(vertices) - k
def compose(*reductions):
def h(*instance):
for r in reductions:
instance = r(*instance)
return instance
return h
clique_to_vertex_cover = compose(clique_to_independent_set,
independent_set_to_vertex_cover)
def has_clique(vertices, edges, k):
es = {frozenset(e) for e in edges}
return any(all(frozenset(p) in es for p in combinations(s, 2))
for s in combinations(vertices, k))
def has_vertex_cover(vertices, edges, k):
if k < 0:
return False
size = min(k, len(vertices))
return any(all(u in c or v in c for u, v in edges)
for c in map(set, combinations(vertices, size)))
random.seed(0)
for _ in range(300):
n = random.randint(1, 6)
vertices = list(range(n))
edges = [e for e in combinations(vertices, 2) if random.random() < 0.5]
k = random.randint(0, n)
assert has_clique(vertices, edges, k) == \
has_vertex_cover(*clique_to_vertex_cover(vertices, edges, k))
print("composed reduction agrees on all tests")The composed map answers "is there a k-clique in G?" with "is there a vertex cover of size at most |V| − k in the complement of G?" Neither single step says this. It falls out of the chain.
How long a chain can be
The same reasoning applies to other kinds of reduction. Computable reductions compose because a composition of computable functions is computable. Log-space reductions also compose, but the proof is harder. The middle output can be too large to store, so you recompute each of its bits whenever g asks for one.
Exercises
Exercise
Reduction f runs in time O(n^2) and produces output of length O(n^2). Reduction g runs in time O(m^3) on inputs of length m. Give a running-time bound for g ∘ f.
Show answer
Computing f takes O(n^2). Then g runs on input of length m = O(n^2), which takes O((n^2)^3) = O(n^6). The total is O(n^6), which is polynomial.
Exercise
You know A ≤p B and C ≤p B. Can you conclude anything about how A relates to C?
Show answer
No. Transitivity needs the reductions to line up end to end, as in A ≤p B ≤p C. Here both arrows point into B, so they do not chain. Neither A ≤p C nor C ≤p A follows.