Subset sum #
SubsetSum is the set of instances x : SubsetSumInstance of a list x.numbers of natural
numbers, possibly with repetitions, and a target x.target such that some sub-multiset of
x.numbers sums to x.target Sipser, Section 7.3. All numbers are encoded in
binary (Turing.MultiTapeTM.encNat, digits least significant first); the NP-hardness proved here
is for this encoding and is not strong NP-hardness. A certificate is a mask selecting entries of
x.numbers (Cslib.Complexity.maskSelect), and the verifier adds the selected numbers in binary.
Sipser's reduction from 3SAT Sipser, Theorem 7.56 gives each of the n variables
of a formula, numbered by first occurrence (Cslib.Logic.PL.CNF.distinctVars), and each of its m
clauses a digit position. Each variable has two literal numbers, with digit one at the position of
the variable and at the positions of the clauses containing the literal (ThreeSAT.literalDigits);
each clause has two slack numbers with digit one at its position only. The target has digit one
at every variable position and three at every clause position. At each position, all numbers
together have at most five digits one, so no subfamily produces carries in any base above five
(Cslib.Complexity.sum_sum_pow_eq_iff). We use base 8 rather than Sipser's base 10, so that
digits are blocks of three bits; every number has at most n + m base-8 digits
(ThreeSAT.lt_of_mem_digitNumbers, ThreeSAT.digitTarget_lt). Variable labels only enter through
their order of first occurrence, so large binary labels do not enlarge the numbers. A literal
repeated in a clause counts once, and a clause containing both literals of a variable is covered
by both of its literal numbers. Formulas with a clause of more than three literals are not in
ThreeSAT and are mapped to an instance without solutions.
Main definitions #
Cslib.Complexity.SubsetSumInstance,Cslib.Complexity.SubsetSum,Cslib.Complexity.encSubsetSum,Cslib.Complexity.SubsetSum.verifier.Cslib.Complexity.ThreeSAT.literalDigits,Cslib.Complexity.ThreeSAT.digitNumbers,Cslib.Complexity.ThreeSAT.digitTarget.Cslib.Complexity.ThreeSAT.toSubsetSum: Sipser's reduction.
Main results #
Cslib.Complexity.mem_SubsetSum_iff_sublist: solutions are subsequences of the numbers.Cslib.Complexity.SubsetSum.isVerifier,Cslib.Complexity.SubsetSum.mem_NP:SubsetSum ∈ NP encSubsetSum.Cslib.Complexity.ThreeSAT.digit_mem_SubsetSum_iff_counts,Cslib.Complexity.ThreeSAT.counts_iff_satisfiable: the digit construction has a solution exactly when the digit positions can be filled, exactly when the formula is satisfiable.Cslib.Complexity.ThreeSAT.toSubsetSum_mem_iff: correctness of Sipser's reduction.Cslib.Complexity.ThreeSAT.lt_of_mem_digitNumbers,Cslib.Complexity.ThreeSAT.digitTarget_lt: the numbers haveO(n + m)digits.Cslib.Complexity.ThreeSAT.computableInPolyTime_toSubsetSum: the reduction is polynomial-time.Cslib.Complexity.polyTimeReducible_ThreeSAT_SubsetSum,Cslib.Complexity.SubsetSum_npHard,Cslib.Complexity.SubsetSum_npComplete:SubsetSumisNP-complete.
References #
Instances For
Instances For
Instances ⟨a, t⟩ of SubsetSum: the list a, framed, each of its numbers framed, then the
target t; all numbers in binary.
Instances For
The instances of subset sum: some sub-multiset of x.numbers sums to x.target [Kar72],
Sipser, Chapter 7.
Instances For
A sub-multiset of the values of a duplicate-free list sums to t exactly when a subset of
the list does.
The verifier for SubsetSum, a mask verifier (Cslib.Complexity.maskVerifier): the numbers
selected by the certificate mask sum to the target.
Instances For
SubsetSum.verifier verifies SubsetSum with certificates as long as the encoded
instance.
The SubsetSum verifier is polynomial-time: it selects the masked numbers, adds them in
binary and compares the sum with the target.
SubsetSum belongs to NP.
The digit construction #
Whether clause j of φ contains the literal of sign b of variable number i of
φ.distinctVars.
Instances For
The digit positions of the number of a literal: the position i of its variable, and the
position φ.distinctVars.length + j of every clause j containing it.
Instances For
The number whose base-8 digits are one at the positions ps and zero elsewhere, for distinct
positions.
Instances For
The numbers of the digit construction: two literal numbers for each variable, and two slack numbers with the single digit of each clause.
Instances For
The target of the digit construction: digit one at each variable position and digit three at each clause position.
Instances For
Sipser's reduction from ThreeSAT to SubsetSum: the digit construction for formulas whose
clauses have at most three literals, and an instance without solutions otherwise.
Instances For
Correctness #
Clause j covers the literal number (i, b) when it contains a literal of sign b whose
variable is number i of φ.distinctVars.
The items of the digit construction: literal numbers (i, b) and slack numbers (j, c).
Instances For
Size of the digit construction. Every number has at most
φ.distinctVars.length + φ.length base-8 digits, that is, three binary digits per variable and
per clause.
The target has at most φ.distinctVars.length + φ.length base-8 digits.
The digit construction in terms of column counts: a solution chooses literal numbers A and
slack numbers B so that each variable position holds one chosen literal number and each clause
position three chosen numbers.
Column counts as in digit_mem_SubsetSum_iff_counts exist exactly when the formula is
satisfiable: the chosen literal numbers are the true literals, and slack numbers fill each clause
position up to three.
Correctness of Sipser's reduction. A formula belongs to ThreeSAT exactly when its
digit construction has a sub-multiset summing to the target.
Polynomial time #
Testing whether a clause contains a literal is polynomial-time.
Listing the digit positions of a literal number is polynomial-time.
Composition rule for literalDigits.
A number with digits zero and one is computed in binary from its unary digit positions.
The numbers of the digit construction are computed in polynomial time.
The target of the digit construction is computed in polynomial time.
Sipser's reduction is computable in polynomial time.
ThreeSAT reduces to SubsetSum in polynomial time by Sipser's digit construction.
Subset sum is NP-complete, with the numbers and the target in binary [Kar72], Sipser, Theorem 7.56.