Sub topic 3
Many-One Reductions and Proving Them Correct
This chapter assumes you know the decision-problem view from earlier chapters: a problem is a set of encoded instances, and the yes-instances form a language. You should also be comfortable writing short "if and only if" proofs and reading Python.
The definition
A many-one reduction from problem A to problem B is a total, computable function f that maps every instance x of A to an instance f(x) of B such that:
x is a yes-instance of A if and only if f(x) is a yes-instance of B.
We write A ≤ₘ B. The name "many-one" means that f may send many different inputs to the same output. f does not need to be injective or surjective. It must be defined on every input, including malformed ones, and it must always halt.
To decide A with this reduction, compute f(x), run a decider for B on the result, and return its answer unchanged. You call B exactly once and never change its answer.
A worked example: Partition to Subset Sum
Partition asks whether a list of nonnegative integers can be split into two parts with equal sums. Subset Sum asks whether some sublist of a given list sums exactly to a target t.
The construction works like this. If the total S is even, output the same list with t = S/2. If S is odd, no equal split can exist, so output a fixed no-instance of Subset Sum.
from itertools import combinations
def subsets(nums):
for r in range(len(nums) + 1):
yield from combinations(nums, r)
def partition(nums):
total = sum(nums)
return any(2 * sum(c) == total for c in subsets(nums))
def subset_sum(nums, t):
return any(sum(c) == t for c in subsets(nums))
def partition_to_subset_sum(nums):
total = sum(nums)
if total % 2 == 1:
return [], 1 # fixed no-instance: empty list cannot reach 1
return list(nums), total // 2
tests = [[1, 5, 11, 5], [1, 2, 3], [2, 3], [], [7], [3, 1, 1, 2, 2, 1]]
for nums in tests:
assert partition(nums) == subset_sum(*partition_to_subset_sum(nums))
print("reduction agrees on all tests")The brute-force checkers only test the reduction on small inputs. The proof is what shows it is correct for every input.
Proving correctness: the two-direction template
Every correctness proof has three parts.
- f is total and computable. Here f adds up the list and divides by 2, which always halts.
- Yes maps to yes (completeness). Suppose the list splits into P and Q with sum(P) = sum(Q). Then S = 2·sum(P) is even, so f outputs (list, S/2), and P is a sublist that sums to S/2.
- Yes comes only from yes (soundness). Suppose f(x) is a yes-instance. It cannot be the fixed instance ([], 1), so S was even and some sublist P sums to S/2. The remaining elements then sum to S − S/2 = S/2, which gives an equal split.
You can prove step 3 directly, as above, or by its contrapositive: every no-instance of A maps to a no-instance of B. Both forms are valid. Skipping step 3 is the most common error.
Common errors
| Error | Symptom | Fix |
|---|---|---|
| Proving one direction only | A trivial f would also pass | Prove both directions, or prove the contrapositive of soundness |
| f undefined on some inputs | The odd-total case is not handled | Map such inputs to a fixed no-instance (or a fixed yes-instance) |
| f calls a solver for B | f is really an oracle algorithm | f must only translate instances. Oracle use is covered in the Turing reductions chapter |
| f uses the unknown answer | "If x is a yes-instance, output..." | f may branch only on properties it can compute |
Exercise
Someone proposes reducing Partition to Subset Sum with f(nums) = (nums, sum(nums) // 2), with no special case for odd totals. Give a counterexample and say which direction of the proof fails.
Show answer
Take nums = [1, 2], whose total is 3. Partition answers no because 1 ≠ 2. But f outputs ([1, 2], 1), and the sublist [1] sums to 1, so Subset Sum answers yes. Soundness fails: a yes-instance of B came from a no-instance of A.
Exercise
Is f(nums) = (nums + [0], sum(nums) // 2) for even totals, with the same odd-total case as before, still a correct reduction? Justify both directions briefly.
Show answer
Yes. Adding 0 changes no subset sum. Completeness: an equal split P of nums still sums to S/2 inside nums + [0]. Soundness: a sublist reaching S/2 either contains the 0 or does not, and with the 0 removed it is a sublist of nums with sum S/2, so its complement in nums also sums to S/2.