# Is subset sum problem with multiplicities NP-complete?

To be specific, the problem is formalized as follows.

Given a set of integers $\{a_1,\ldots,a_n\}$, determine whether there exist non-negative integers $x_1,\ldots,x_n$ such that $a_1x_1+\cdots+a_nx_n=0$ and at least one of $x_1,\ldots,x_n$ is positive.

Note this is not a duplicate of this problem. In that problem, the target sum is given as input, while in our problem, the target sum is fixed to be $0$.

I tried to follow the idea of the answer to that question to come up with a new reduction, but since a basic idea of that answer is to use big elements as well as big target to prevent an element from being chosen multiple times, while in our problem the target sum is $0$, I failed.

Related question: Is the following Subset Sum variant NP-complete?

The problem can be solved in polynomial time.

If any of the $a_i$ are zero, then the answer is "yes" (you can set the corresponding $x_i$ to 1, and all other $x_j$ to 0). So let's assume all of the $a_i$ are non-zero.

If all of the $a_i$ are strictly positive, then the answer is "no" (if $x_i$ is the one that's set to something non-zero, then $x_i>0$ and $a_i>0$, so $a_1 x_1 + \dots + a_n x_n \ge a_i x_i > 0$). So we can assume at least one of the $a_i$ is strictly negative.

If all of the $a_i$ are strictly negative, then the answer is "no" (if $x_i$ is the one that's set to something non-zero, then $x_i>0$ and $a_i<0$, so $a_1 x_1 + \dots + a_n x_n \le a_i x_i < 0$). So we can assume at least one of the $a_i$ is strictly negative.

If at least one of the $a_i$ is strictly positive and at least one is strictly negative, say $a_i>0$ and $a_j<0$, then the answer is "yes" (you can take $x_i=-a_j$, $x_j=a_i$, and set all other $x$'s to zero; then $a_1 x_1 + \dots + a_n x_n = a_i x_i + a_j x_j = -a_i a_j + a_i a_j = 0$).

These cases cover all the possibilities: at least one of the above cases must hold. So, we obtain a polynomial-time algorithm for the original problem.

Credit: I got the key idea from Discrete lizard.

This problem lies in P.

To see this, formulate this problem it as an integer linear program (ILP):

For $x\in \mathbb{Z}^n$, maximize $\sum_{i=1}^n x_i$ under the constraint $\sum_{i=1}^n a_ix_i = 0$ and $x_i\geq 0$ for all $i\in \{1,\ldots,n\}$.

Let's have a look at the relaxed version of this ILP:

For $x\in \mathbb{R}^n$, maximize $\sum_{i=1}^n x_i$ under the constraint $\sum_{i=1}^n a_ix_i = 0$ and $x_i\geq 0$ for all $i\in \{1,\ldots,n\}$.

Observe that if $x$ is a solution of the relaxed LP, then $x\in \mathbb{Q}^n$, as $\sum_{i=1}^n a_ix_i = 0$ and all $a_i$'s are integral. Furthermore, if $x\in \mathbb{Q}^n$ is a solution, then $x'$ such that $x'_i = c\cdot x_i$ is also a solution for any $c\in \mathbb{Z}$. Therefore, if the relaxed LP has a (non-zero) solution, there also exists a non-zero solution to the LP in $\mathbb{Z}^n$ (take $c$ as the least common multiple of all denominators).

So, if there is a non-zero solution to the relaxed LP, our ILP has a non-zero solution and therefore there exists a solution to your input. Since we can solve LP's over $\mathbb{R}^n$ in polynomial time, we have a polynomial algorithm for this problem.

Note that, as @D.W. mentioned, solving LP's in polynomial time can be a tricky business. Fortunately, (existence of a non-zero solution for) this LP can be solved by hand, as shown in this answer. In particular, there exists such a solution if and only if at least one of the $a_i$'s is positive and at least one is negative.

• I'm not exactly sure if I've captured the 'not-all-zero' part well here. If this doesn't work, it can most certainly be done by for instance solving $n$ LP's maximising only $x_i$. This will give a non-zero solution if one exists, but I'm not sure if this is necessary. – Discrete lizard Mar 11 '18 at 15:30
• Clever approach! Does this require a strongly polynomial time algorithm for linear programming? – D.W. Mar 11 '18 at 17:34
• @D.W. Good question! I have no idea. Wikipedia seems to claim that Karamakar's algorithm runs in time polynomial in $L$ and $n$, which would imply solving this particular RLP can be done in time polynomial in the input size (under reasonable encoding). But this appears (I think?) to contradict the fact that a strong poly-time algorithm is open. – Discrete lizard Mar 11 '18 at 18:06
• @D.W. Wait, I think that this problem is even simpler than I thought. I think the answer is 'YES' precisely when at least one of the $a_i$'s is strictly positive! I'll have to work this one out. – Discrete lizard Mar 11 '18 at 18:17
• Oh, lovely observation! Based on that idea, I think I worked out a solution. I hope I didn't pre-empt you. – D.W. Mar 11 '18 at 18:38