Definition · Subset sumGiven a list of positive integers and a target, is there a sublist adding to the target exactly? The input is the digits of the numbers, which matters for every complexity claim on this page: a list of ten numbers with a thousand digits each is a large input, and a list of ten numbers under 100 is a small one.
The construction
- One column per variable and one per clause, so n + m columns, read in base ten.
- For each variable, a number x true with a 1 in that variable's column and a 1 in every clause column the positive literal satisfies; and a number x false with a 1 in the variable's column and a 1 in every clause column the negative literal satisfies.
- For each clause, two slack numbers with a 1 and a 2 in that clause's column and zeros everywhere else.
- The target has a 1 in every variable column and a 4 in every clause column.
Theorem · The construction is a reductionThe formula is satisfiable if and only if some subset of the constructed numbers adds to the target.
No column can carry, because every column's digits add to at most 6 across all the rows, and 6 is less than 10. So a subset hits the target exactly when it hits each column's digit separately.
A variable column can only be reached by that variable's two numbers, each contributing 1, and the target is 1, so exactly one of the two is chosen: the subset picks an assignment. A clause column receives 1 from each chosen literal number that satisfies the clause, so between 0 and 3, plus whatever the two slack numbers contribute, which is 0, 1, 2 or 3.
The target is 4. If the assignment satisfies the clause, the literal contribution is 1, 2 or 3 and exactly one of the four slack combinations makes up the remaining 3, 2 or 1. If the assignment does not satisfy it, the literal contribution is 0 and the slack numbers can supply at most 3, so the column cannot reach 4. Hence the subsets that hit the target are exactly the satisfying assignments, each with its forced slack choice — which is why the map is not merely sound but a bijection.
□
What the lab built
The loaded formula is (x1 or x2) and (not x1 or x2): two variables, two clauses, so four columns. The panel reports 8 numbers of 4 digits, the target 1144, 2 subsets reaching it, 2 satisfying assignments out of 4, a largest column total of 5 against the base 10, and the verdict that the map is a bijection — sound, surjective and injective, all three computed.
The column totals are 2, 2, 5 and 5. The two variable columns get a 1 from each of the variable's two numbers and nothing else. Each clause column gets a 1 from every literal number satisfying that clause — two of them here — plus 1 and 2 from the slack, which is 5. Five is comfortably under ten and the bar chart draws it against the line.
Beside the enumeration the panel runs the dynamic programme from Dynamic Programming and Optimal Substructure on the same numbers and the same target, and requires the two to agree about whether the target is reachable. Two exhaustive routes that agree is evidence; one clever route is not, and the two routes here share no code.
Example · Both subsets, added in columnsx1 false + x2 true + slack 1.1 + slack 1.2 + slack 2.2 is 1001 + 0111 + 0010 + 0020 + 0002 = 1144, and carries back to x1 = F, x2 = T. The clause-1 column reads 1 from x2 true plus 1 and 2 from the slacks; the clause-2 column reads 1 from x1 false, 1 from x2 true and 2 from a slack. Both reach 4 without help from anywhere else in the number.
Two senses of hard, and why the table does not rescue this
It is tempting to think a problem with a dynamic programme cannot be NP-hard. The table for subset sum has one row per item and one column per value from 0 to the target, so its size is proportional to n times the target. That is polynomial in the target as a NUMBER and exponential in the target as an INPUT, because a target with d digits has magnitude about 10^d. Here d is the number of variables plus the number of clauses, so the table has about 10^(n+m) columns and is not an algorithm anyone can run.
The distinction has a name and a consequence. A problem that is NP-hard but has an algorithm polynomial in the numeric values is weakly NP-hard; one that stays hard even when the numbers are bounded by a polynomial in the input length is strongly NP-hard. Only weakly NP-hard problems can have the kind of approximation scheme built later on this course, and that is not a coincidence: the scheme works by making the numbers small enough for the table to fit.