# SAT formula specifying that exactly $k$ of $N$ boolean variables are active using less than $N$-choose-$k$ terms

Is there a way to express the condition that exactly $k$ of $N$ boolean variables are active without writing a disjunction of $N$-choose-$k$ terms, i.e., all possible configurations of the $N$ variables where exactly $k$ are active? Is the same true for specifying that at least $K$ of the $N$ boolean variables are active?

I'm aware that this is a problem dealt with in theoretical computer science but I couldn't find any references.

• Essentially you're looking at $N$ bits and trying to decide if they add up to $k$, so you only need a series of adder circuits that add up the bits plus a comparison circuit to check whether the final sum equals $k$. Converting the circuits to CNF by the usual means produces $O(N)$ clauses. – Kyle Jones Jun 3 '14 at 15:53
• Thank you. I think I can take it from there. What about the more that $k$ active case? You could implement a disjunction of comparisons, but there should be a more succinct solution. – rnegrinho Jun 3 '14 at 16:13
• Same situation except the comparison circuit checks for greater than rather than equivalence. Start with the MSB end of the two numbers to be compared and move right until you find bits that aren't equal. The number with the 1 bit is obviously greater than the number with the 0 bit. – Kyle Jones Jun 3 '14 at 16:28
• This answer is also relevant. – Mangara Mar 20 '17 at 22:52

From a practical perspective, the different schemes have different tradeoffs. If you are trying to encode a $k$-out-of-$N$ constraint in something you are feeding to a SAT solver, you can try each of the different candidate encodings to see which makes the SAT solver run faster; they can have a significant impact on the efficiency of the SAT solver.