Sub topic 3
Many-One Reductions and Proving Them Correct
This chapter assumes you can read decision problems as languages, meaning sets of encoded yes-instances. It also assumes you can write a two-part "if and only if" proof and can read short Python programs. The previous chapter gave the informal idea of a reduction. Here we make it precise and learn how to prove that a given reduction is correct.
The Definition
Let A and B be decision problems over strings. A many-one reduction from A to B, also called a mapping reduction, is a total computable function f such that for every string x:
x ∈ A if and only if f(x) ∈ B.
We write A ≤ₘ B. Each part of the definition matters:
- Total: f produces an output for every input, including strings that do not encode a valid instance of A.
- Computable: some algorithm computes f and always halts. Later chapters also require it to run in polynomial time.
- If and only if: yes-instances map to yes-instances, and no-instances map to no-instances.
If you have a decider for B, you get a decider for A: compute f(x), ask B once, and return B's answer unchanged. That rule of one question and an untransformed answer is what separates many-one reductions from the Turing reductions covered later.
The name "many-one" means f does not have to be injective. Many instances of A may map to the same instance of B. f does not have to be surjective either. Most of B may never be hit.
The Two Directions of Correctness
An "if and only if" claim needs two proofs:
- Completeness (forward): if x ∈ A, then f(x) ∈ B. Usually you take a solution or witness for x and build one for f(x).
- Soundness (backward): if f(x) ∈ B, then x ∈ A. Usually you take a witness for f(x) and pull back a witness for x.
You can also prove the backward direction as its contrapositive: if x ∉ A, then f(x) ∉ B. The two forms are logically equivalent, so use whichever is easier.
That last point is where most errors happen. In the forward direction you control the witness, because you build it. In the backward direction an adversary hands you any witness for f(x), and you have to show that even a strange one gives a solution to x.
A Worked Example: Subset Sum to Partition
- Subset Sum: given nonnegative integers S and a target t, is there a sub-multiset of S whose sum is exactly t?
- Partition: given nonnegative integers P, can P be split into two parts with equal sums?
Let σ be the sum of S. The reduction is:
- If t < 0 or t > σ, output the fixed no-instance [1].
- Otherwise output P = S + [σ + t, 2σ − t].
P has total σ + (σ + t) + (2σ − t) = 4σ, so each half of a partition must sum to 2σ.
Forward. Suppose T ⊆ S sums to t. Put T together with 2σ − t on one side. That side sums to 2σ, so the other side does too. P is a yes-instance.
Backward. Suppose P splits into two halves that each sum to 2σ. If both new elements were on the same side, that side would sum to at least (σ + t) + (2σ − t) = 3σ. Since 3σ > 2σ whenever σ > 0, that is impossible. (If σ = 0, then t = 0 and the empty subset already works.) So 2σ − t is on one side, and the original elements on that side sum to 2σ − (2σ − t) = t. That gives a subset of S summing to t.
Edge cases. When t > σ or t < 0, no subset can reach t, so mapping to a fixed no-instance is correct. Without this branch, 2σ − t could be negative, which is not a valid Partition input. Once the edge-case branch is defined, f is total.
Testing a Reduction Empirically
A proof is what makes a reduction correct. A brute-force test is still a cheap way to catch mistakes before you write the proof. The script below checks that the answer to x equals the answer to f(x) on thousands of random small instances.
import random
def reachable_sums(nums):
sums = {0}
for x in nums:
sums |= {s + x for s in sums}
return sums
def subset_sum(nums, t):
return t in reachable_sums(nums)
def partition(nums):
total = sum(nums)
return total % 2 == 0 and (total // 2) in reachable_sums(nums)
def subset_sum_to_partition(nums, t):
sigma = sum(nums)
if t < 0 or t > sigma:
return [1] # a fixed no-instance of Partition
return list(nums) + [sigma + t, 2 * sigma - t]
random.seed(0)
for _ in range(5000):
nums = [random.randint(0, 9) for _ in range(random.randint(0, 6))]
t = random.randint(-3, 60)
assert subset_sum(nums, t) == partition(subset_sum_to_partition(nums, t)), (nums, t)
print("all instances agree")If you replace 2σ − t with σ − t, the test fails within a few iterations. This is the kind of slip a test catches quickly.
A Proof Template
Most correct many-one reduction proofs follow these steps:
- State f precisely, including what it does on malformed or degenerate inputs.
- Argue that f is computable and always halts. Later you will also bound its running time.
- Forward: assume x ∈ A, name a witness, and construct a witness for f(x).
- Backward: assume f(x) ∈ B, take an arbitrary witness, and extract a witness for x. Handle every case the witness could fall into.
- Check the boundaries: empty input, zero values, and the cases where your construction branches.
| Proof obligation | Typical mistake | How to check |
|---|---|---|
| f is total | Forgetting malformed or out-of-range inputs | Ask what f outputs for garbage and for extreme parameters |
| f is computable | Using a step that secretly solves A | Make sure no step needs the answer to x |
| Forward direction | Building a witness of the wrong size | Recompute sums, sizes, or counts explicitly |
| Backward direction | Assuming the witness has the intended shape | List every way a witness could place the gadget parts |
| Edge cases | Degenerate values break an inequality | Test σ = 0, empty sets, and k = 0 |
Consequences of the Definition
Complements carry over. If f reduces A to B, the same f reduces the complement of A to the complement of B, because "x ∈ A ⟺ f(x) ∈ B" is the same statement as "x ∉ A ⟺ f(x) ∉ B".
Negating the answer is not allowed. A decider that runs B on f(x) and then flips the result is not a many-one reduction. This restriction has real effects. The complement of the halting problem is not many-one reducible to the halting problem, even though one oracle query plus a negation solves it.
Trivial targets. Mapping garbage to a fixed no-instance only works if B has a no-instance. The empty language and the language of all strings can only receive reductions from themselves, so you rarely reduce to them.
Reflexivity. The identity function shows A ≤ₘ A. Composition, covered in a later chapter, gives transitivity.
Exercise
Someone proposes reducing Subset Sum to Partition by outputting S + [|σ − 2t|] whenever 0 ≤ t ≤ σ, and gives only the forward proof. Find the flaw in the backward direction, or a counterexample.
Show answer
Let d = σ − 2t ≥ 0 when t ≤ σ/2. The total is 2σ − 2t, so each half sums to σ − t. The side containing d then has original elements summing to t, and the other side sums to σ − t, which is also a valid subset sum. When t > σ/2 the new element is 2t − σ and the halves sum to t, so the side without the new element sums to t. The construction is actually correct. The point of the exercise is that you have to check the backward direction to know this. A forward proof alone establishes nothing.
Exercise
Explain why "on input x, run a decider for B on f(x) and return the opposite answer" does not show A ≤ₘ B, and say what it does show.
Show answer
A many-one reduction must return B's answer unchanged, so x ∈ A has to match f(x) ∈ B exactly. Flipping the answer shows x ∈ A ⟺ f(x) ∉ B. That means f is a many-one reduction from A to the complement of B. It is also a Turing reduction from A to B.
Exercise
In the Subset Sum to Partition reduction, why does the case t > σ need special handling instead of using the general formula?
Show answer
For t > σ, the value 2σ − t is less than σ and may be negative. A negative value is not a valid Partition input, so f would not be well defined. Even when the value is nonnegative, the backward argument depends on t ≤ σ. Every such instance is a no-instance of Subset Sum, so mapping it to the fixed no-instance [1] keeps the equivalence and makes f total.