Translating Pseudo-Boolean Constraints Into SAT: Cadence Berkeley Labs, Berkeley, USA
Translating Pseudo-Boolean Constraints Into SAT: Cadence Berkeley Labs, Berkeley, USA
return memo[key]
Figure 3. Building a BDD from the PB-constraint Csps rhs. The functions used in the
code do the following: sign(p) returns the sign of a literal (True for x, False for x); var(p)
returns the underlying variable of a literal (i.e. removes the sign, if any); and ITE(cond,hi,lo) con-
structs an if-then-else gate. The types vec'` (a dynamic vector) and map', ` (a hash table)
are assumed to be passed-by-reference (the reasonable thing to do), whereas primitive datatypes,
such as int, are assumed to be passed-by-value. The BDD construction is initiated by calling
buildBDD() with size set to the number of coefcients in the LHS, sum set to zero, mate-
rial left set to the sum of all coefcients in the LHS, and memo to an empty map.
Denition. A bucket is a bit-vector where each bit has the same value. A
k-bucket is a bucket where each bit has the value k.
Denition. A binary number is a bit-vector where the bits have values in
ascending powers of 2 (the standard representation of numbers in computers).
The translation of PB-constraints to clauses is best explained through an example. Consider
the following constraint:
2a + 13b + 2c + 11d + 13e + 6f + 7g + 15h 12
One way to enforce the constraint is to synthesize a circuit which adds up the activated
coecients of the LHS to a binary number. This number can then be compared with the
binary representation of the RHS (just a lexicographical comparison). The addition and
the corresponding buckets for the above constraint look as follows:
11
N. Een and N. S orensson
00a0
bb0b
00c0
d0dd
ee0e
0ff0
0ggg
+ hhhh
Bucket: Content:
1-bits: [b,d,e,g,h]
2-bits: [a,c,d,f,g,h]
4-bits: [b,e,f,g,h]
8-bits: [b,d,e,h]
The goal is to produce the sum as a binary number. It can be done as follows: Repeatedly
pick three 2
n
-bits from the smallest non-empty bucket and produce, through a full-adder,
one 2
n+1
-bit (the carry) and one 2
n
-bit (the sum). The new bits are put into their respective
buckets, possibly extending the set of buckets. Note that each iteration eliminates one bit
from the union of buckets. When a bucket only has two bits left, a half-adder is used instead
of a full-adder. The last remaining bit of the 2
n
-bucket is removed and stored as the n
th
output bit of the binary sum. It is easy to see that the number of adders is linear in the
combined size of the initial buckets.
Pseudo-code for the algorithm is presented in Figure 5. We note that the buckets can
be implemented using any container, but that choosing a (FIFO) queuewhich inserts and
removes from dierent endswill give a balanced, shallow circuit, whereas using a stack
which inserts and removes from the same endwill give an unbalanced, deep circuit. It is
not clear what is best for a SAT-solver, but MINISAT+ uses a queue.
For the lexicographical comparison between the LHS sum and the RHS constant, it is
trivial to create a linear sized circuit. However, as we expect numbers not to be exceedingly
large, we synthesize a comparison circuit that is quadratic in the number of bits needed to
represent the sum (Figure 6). It has the advantage of not introducing any extra variables
in the SAT-solver, as well as producing fewer (although longer) clauses.
Analysis. Adder networks provide a compact, linear (both in
FA
FA
FA
HA
c s
c s
s c
c s
y
2
y
1
y
0
x
5
x
4
x
3
x
2
x
1
x
0
Figure 4. Adder circuit
for the sum x
0
+ ... + x
5
.
time and space) translation of PB-constraints. However, the gen-
erated CNF does not preserve arc-consistency under unit propa-
gation. Consider the cardinality constraint x
0
+ x
1
... + x
5
4.
The adder network synthesized for the LHS is shown in Figure 4.
The RHS corresponds to asserting y
2
. Now, assume x
0
and x
3
are both False. In this situation, the remaining inputs must all
be True, but no assignment will be derived by unit propagation.
Another drawback of using adder networks is the carry prop-
agation problem. Assume that x
0
and x
3
are now True instead.
The two lower full-adders and the half-adder are summing 1-bits.
Ideally, feeding two True-signals should generate a carry-out to
the top full-adder, which is summing 2-bits. But because it can-
not be determined which of the three outputs to the top full-adder
is going to generate the carry, no propagation takes place.
Related Work. The algorithm described in this section is very
similar to what is used for Dadda Multipliers to sum up the par-
tial products [14]. A more recent treatment on multipliers and adder networks can be found
12
Translating Pseudo-Boolean Constraints into SAT
in [10]. Using adder networks to implement a linear translation of PB-constraint to circuits
has been done before in [33, 3, 31], but the construction presented here uses fewer adders.
5.5 Translation through Sorting Networks
Empirically it has been noted that SAT-solvers tend to perform poorly in the presence of
parity constraints. Because all but one variable must be bound before anything can prop-
agate, parity constraints generate few implications during unit propagation. Furthermore,
they tend to interact poorly with the resolution based conict-clause generation of contem-
porary SAT-solvers. Because full-adders contain Xor (a parity constraint) we might expect
bad results from using them extensively. In the previous section it was shown that translat-
ing cardinality constraints to adder networks does not preserve arc-consistency, which gives
some theoretical support for this claim. Furthermore, the interpretation of a single bit in
a binary number is very weak. If, for example, the third bit of a binary number is set, it
means the number must be 8. But if we want to express 8, or 6 for that matter,
a constraint over several bits must be used. This slows down the learning process of the
SAT-solver, as it does not have the right information entities to express conicts in.
To alleviate the problems inherent to full-adders we propose, as in [4], to represent
numbers in unary instead of in binary. In a unary representation, all bits are counted
equal, and the numerical interpretation of a bit-vector is simply the number of bits set to
True. A bit-vector of size 8, for example, can represent the numbers n [0, 8]. Each such
number will in the construction to follow be connected to a sorting network,
7
which allows
the following predicates to be expressed by asserting a single bit: n 0, n 1, . . ., n 8,
and n 0, n 1, . . ., n 8. Although the unary representation is more verbose than
the binary, we hypothesize that the Xor-free sorters increase the implicativity, and that
the SAT-solver benets from having better information entities at its disposal for conict-
clause generation. The hypothesis is to some extent supported by our experiments, and we
furthermore prove that the sorter-based translation of this section is arc-consistent for the
special case of cardinality constraints.
To demonstrate how sorters can be used to translate PB-constraints, consider the fol-
lowing example:
x
1
+ x
2
+ x
3
+ x
4
+ x
5
+ x
6
+ 2y
1
+ 3y
2
4
The sum of the coecients is 11. For this constraint one could synthesize a sorting network
of size 11, feeding y
1
into two of the inputs, y
2
into three of the inputs, and all the signals
x
i
into one input each. To assert the constraint, one just asserts the fourth output bit of
the sorter.
Now, what if the coecients of the constraint are bigger than in this example? To
generalize the above idea, we propose a method to decompose the constraint into a number
of interconnected sorting networks. The sorters will essentially play the role of adders on
unary numbers. Whereas the adder networks of the previous section worked on binary
numbersrestricting the computation to buckets of 1-bits, 2-bits, 4-bits, and so on for each
power of 2 the unary representation permits us the use of any base for the coecients,
including a mixed radix representation. The rst part of our construction will be to nd a
natural base in which the constraint should be expressed.
7. MINISAT+ uses odd-even merge sorters [9].
13
N. Een and N. S orensson
adderTree(vec'queue'signal `` buckets, vec'signal ` result)
Figure 5. Linear-sized addition tree for the coecient bits. The bits of buckets[] are
summed up and stored in the output vector result[] (to be interpreted as a binary number). Each
vector is dynamic and extends automatically when addressed beyond its current last element. The
queue could be any container type supporting insert() and dequeue() methods. The par-
ticular choice will inuence the shape of the generated circuit. Abbreviations FA and HA stand
for full-adder and half-adder respectively.
// Generates clauses for xs ys, assuming one of them has only constant signals.
lessThanOrEqual (vec'signal ` xs, vec'signal ` ys, SatSolver S)
Figure 6. Compare a binary number xs to the RHS constant ys. One of the input vectors
must only contain the constant signals True and False. If not, the function still works, except
that c is not necessarily a clause when reaching addClause(), so the call has to be replaced
with something that can handle general formulas. Notation: the method push() appends an
element to the end of the vector. In practice, as we put signals into the clause c, we also apply
the Tseitin transformation to convert the transitive fan-in (all logic below) of those signals into
clauses. Those parts of the adder network that are not necessary to assert xs ys will not be put
into the SAT-solver.
14
Translating Pseudo-Boolean Constraints into SAT
Denition. A base B is a sequence of positive integers B
i
, either nite
'B
0
, . . . , B
n1
` or innite.
Denition. A number d in a base B is a nite sequence 'd
0
, . . . , d
m1
` of digits
d
i
[0, B
i
1]. If the base is nite, the sequence of digits can be at most one
element longer than the base. In that case, the last digit has no upper bound.
Denition. Let tail (s) be the sequence s without its rst element. The value
of a number d in base B is recursively dened through:
value(d, B) = d
0
+ B
0
value(tail (d), tail (B))
with the value of an empty sequence d dened as 0.
Example: The number '2, 4, 10` in base '3, 5` should be interpreted as 2 + 3 (4 + 5
10) = 2 1+4 3+10 15 = 164 (bucket values in boldface). Note that numbers may
have one more digit than the size of the base due to the ever-present bucket of 1-bits. Let
us outline the decomposition into sorting networks:
Find a (nite) base B such that the sum of all the digits of the coecients written in
that base, is as small as possible. The sum corresponds to the number of inputs to
the sorters we will synthesize, which in turn roughly estimates their total size.
8
Construct one sorting network for each element B
i
of the base B. The inputs to the
i
th
sorter will be those digits d (from the coecients) where d
i
is non-zero, plus the
potential carry bits from the i-1
th
sorter.
We will explain the details through an example. Consider the constraint:
a + b + 2c + 2d + 3e + 3f + 3g + 3h + 7i 8
Assume the chosen base B is the singleton sequence '3`, meaning we are going to compute
with buckets of 1-bits and 3-bits. For the constraint to be satised, we must either have
at least three 3-bits (the LHS 9), or we must have two 3-bits and two 1-bits (the LHS
= 8). Our construction does not allow the 1-bits to be more than two; that would generate
a carry bit to the 3-bits.
In general, let d
i
be the number in base B representing the coecient C
i
, and d
rhs
the
number for the RHS constant. In our example, we have:
d
0
, d
1
= '1, 0` (digits for the a and b terms)
d
2
, d
3
= '2, 0` (digits for the c and d terms)
d
4
.. d
7
= '0, 1` (digits for the e, f, g, and h terms)
d
8
= '1, 2` (digits for the i term)
d
rhs
= '2, 2` (digits for the RHS constant)
8. In MINISAT+, the base is an approximation of this: the best candidate found by a brute-force search
trying all prime numbers < 20. This is an ad-hoc solution that should be improved in the future. Finding
the optimal base is a challenging optimization problem in its own right.
15
N. Een and N. S orensson
Figure 7. Sorting networks for the constraint a+b +2c +2d+3e +3f +3g +3h+7i 8
in base '3`. Sorters will output 0:s at the top and 1:s at the bottom. In the gure, lhs is the
value of the left-hand side of the PB-constraint, and % denotes the modulo operator. In base
'3`, 8 becomes '2, 2`, which means that the most signicant digit has to be either > 2 (which
corresponds to the signal lhs 9 in the gure), or it has to be = 2 (the lhs 6 signal) and at
the same time the least signicant digit 2 (the (lhs % 3) 2 signal). For clarity this logic is left
out of the gure; adding it will produce the single-output circuit representing the whole constraint.
The following procedure, initiated by genSorters(0, ), recursively generates the sorters
implementing the PB-constraint:
genSorters(n, carries)
- Synthesize a sorter of size: (
i
d
i
n
)+[carries[. Inputs are taken from the elements
of carries and the p
i
:s of the constraint: signal p
i
is fed to d
i
n
inputs of the sorter.
9
- Unless n = [B[: Pick out every B
n
:th output bit and put in new carries (the
outputs: out[B
n
], out[2B
n
], out[3B
n
] etc.). Continue the construction with gen-
Sorters(n + 1, new carries).
Figure 7 shows the result for our example. Ignore for the moment the extra circuitry for
modulo operation (the lhs % 3 2 signal). We count the output pins from 1 instead of 0
to get the semantics out[n] = at least n bits are set.
On the constructed circuit, one still needs to add the logic that asserts the actual
inequality LHS RHS. Just like in the case of adder networks, a lexicographical comparison
is synthesized, but now on the mixed radix base. The most signicant digit can be read
directly from the last sorter generated, but to extract the remaining digits from the other
sorters, bits contributing to carry-outs have to be deducted. This is equivalent to computing
the number of True bits produced from each sorter modulo B
i
. Figure 8 shows pseudo-code
for the complete lexicographical comparison synthesized onto the sorters. In our running
example, the output would be the signal (lhs 9) ((lhs 6) (lhs % 3 2)) (again,
see Figure 7), completing the translation.
Analysis. In base '2` = '2, 2, . . .`, the construction of this section becomes congruent
to the adder based construction described in the previous section. Sorters now work as
adders because of the unary number representation, and as an eect of this, the carry
propagation problem disappears. Any carry bit that can be produced will be produced
9. Implementation note: The sorter can be improved by using the fact that the carries are already sorted.
16
Translating Pseudo-Boolean Constraints into SAT
// Does the sorter output out[1..size] represent
a number lim modulo N?
signal modGE(vec'signal ` out, int N, int lim)
if (lim == 0) return True
result = False
for (j = 0; j < out.size(); j += N)
result [= out[j + lim] & out[j+N]
// let out[n] = False if n is out-of-bounds
return result
signal lexComp(int i)
if (i == 0)
return True
else
i
out = output of sorters[i]
gt = modGE(out, B
i
, d
rhs
i
+ 1)
ge = modGE(out, B
i
, d
rhs
i
)
return gt [ (ge & lexComp(i))
Figure 8. Adding lexicographical comparison. In the code, sorters is the vector of sorters
produced by genSorters()at most one more than [B[, the size of the base used. The procedure
is initialized by calling lexComp(sorters.size()). Let B
i
= +for i = [B[ (in effect removing the
modulus part of modGE() for the most signicant digit). The d
rhs
is the RHS constant written
in the base B. Operators & and [ are used on signals to denote construction of And and Or
gates.
by unit propagation. Moreover, the unary representation provides the freedom to pick any
base to represent a PB-constraint, which recovers some of the space lost due to the more
verbose representation of numbers.
Let us study the size of the construction. An odd-even merge sorter contains nlog n(1+
log n) O(n log
2
n) comparators,
10
where n is the number of inputs. Dividing the inputs
between two sorters cannot increase the total size, and hence we can get an upper bound
by counting the total number of inputs to all sorters and pretend they were all connected
to the same sorter. Now, the base used in our construction minimizes the number of inputs,
including the ones generated from carry-ins, so choosing the specic base '2` can only
increase the number of inputs. In this base, every bit set to 1 in the binary representation
of a coecient will generate an input to a sorter. Call the total number of such inputs N.
On average, every input will generate 1/2 a carry-out, which in turn will generate 1/4 a
carry-out and so forth, bounding the total number of inputs, including carries, to 2N. An
upper limit on the size of our construction is thus O(N log
2
N), where N can be further
bound by log
2
(C
0
)+log
2
(C
1
)+. . . +log
2
(C
n1
), the number of digits of the coecient
in base 2. Counting digits in another base does not aect the asymptotic bound.
By our construction, the cardinality constraint p
1
+. . . +p
n
k translates into a single
sorter with n inputs, p
1
, . . . , p
n
, and n outputs, q
1
, . . . , q
n
(sorted in descending order), where
the k
th
output is forced to True. We claim that unit propagation preserves arc-consistency.
First we prove a simpler case:
Theorem: Assume exactly nk of the inputs p
i
are set to 0, and that all of the outputs
q
1
, . . . , q
k
are set to 1 (not just q
k
), then the remaining unbound inputs will be assigned
to 1 by unit propagation.
Proof: First note that the clauses generated for a single comparator locally preserve
arc-consistency. It allows us to reason about propagation more easily. Further note that
10. A comparator is a two-input, two-output gate which sorts two elements. For boolean inputs, the outputs,
called min and max, corresponds to an And-gate and an Or-gate respectively.
17
N. Een and N. S orensson
p
7
0
p
5
0
p
3
0
p
2
0
1 q
4
0 q
8
0 q
7
0 q
6
0 q
5
p
8
1
p
6
1
p
4
1
p
1
1
q
3
q
2
q
1
Figure 9. Propagation trough an 8-sorter. Forced values are denoted by an arrow; four inputs
are set to 0 and one output is set to 1. The thick solid lines show how the 0s propagate towards
the outputs, the thin dashed lines show how 1 propagate backwards to ll the unassigned inputs.
unit propagation has a unique result, so we are free to consider any propagation order. For
brevity write 1, 0, and X for True, False and unbound signals.
Start by considering the forward propagation of 0s. A comparator receiving two 0s will
output two 0s. A comparator receiving a 0 and an X will output a 0 on the min-output
and an X on the max-output. Essentially, the Xs are behaving like 1s. No 0 is lost, so
they must all reach the outputs. Because the comparators comprise a sorting network, the
0s will appear contiguously at the highest outputs (see Figure 9).
Now all outputs are assigned. Consider the comparators in a topologically sorted order,
from the outputs to the inputs. We show that if both outputs of a comparator are assigned,
then by propagation both inputs must be assigned. From this follows by necessity that the
1s will propagate backwards to ll the Xs of the inputs. For each comparator, there are
two cases (i) both outputs have the same value, in which case propagation will assign both
inputs to that value, and (ii) the min-output of the comparator is 0 and the max-output
is 1. In the latter case, the 0 must have been set during the forward propagation of 0s, so
one of the comparators inputs must be 0, and hence, by propagation, the other input will
be assigned to 1.
To show the more general casethat it is enough to set only the output q
k
to 1takes
a bit more work, but we outline the proof (Figure 9 illustrates the property):
Consider the given sorter where some inputs are forced to 0. Propagate the 0s to
the outputs. Now, remove any comparator (disconnecting the wires) where both
inputs and outputs are 0. For any comparator with both 0 and X inputs (and
outputs), connect the X signals by a wire and remove the comparator. Do the same
transformation if X is replaced by 1. Keep only the network reachable from the
primary inputs not forced to 0. In essence: remove the propagation paths of the 0s.
Properties of the construction: (a) propagations in the new network correspond 1-to-1
with propagations in the original network, (b) the new network is a sorter.
The original problem is now reduced to show that for a sorter of size k, forcing its top
output
11
will propagate 1s to all of its inputs (and hence all signals of the network).
11. Assume the orientation of Figure 9 for up and down.
18
Translating Pseudo-Boolean Constraints into SAT
Assume the opposite, that there exists an assignment of the signals that cannot propa-
gate further, but which contains X. From the set of such assignments, pick a maximal
element, containing as many 1s as possible. An X can only appear in one of the
following four congurations:
x x
1 1
1
x
x
1
x x
x
1
x x
x x
(1) (2) (3) (4)
Assume rst that (3) and (4) do not exist. In such a network, X behaves exactly as
a 0 would do, which means that if we put 0s on the X inputs, they would propagate
to the outputs beneath the asserted 1 at the top, which violates the assumption that
the network is sorting.
One of the situations (3) or (4) must exist. Pick a comparator with such a congura-
tion of Xs and set the lower input to 1. A detailed analysis, considering the four ways
Xs can occur around a comparator, shows that unit propagation can never assign
a value to the X of the upper output of the selected comparator, contradicting the
assumption of the assignment being maximal and containing X. To see this, divide the
possible propagations into forward propagations (from inputs to outputs) and non-
forward propagations (from outputs to inputs/outputs). A non-forward propagation
can only propagate 1s leftwards or downwards. A forward-propagation can never
initiate a non-forward propagation.
Unfortunately, arc-consistency is broken by the duplication of inputs, both to the same
sorter and between sorters. Duplication within sorters can be avoided by using base '2`, but
duplication between sorters will remain. Potentially some improvement to our translation
can re-establish arc-consistency in the general case, but it remains future work.
Related Work. Sorting networks is a well-studied subject, treated thoroughly by Knuth
in [18]. For a brief tutorial on odd-even merge sorters, the reader is referred to [28]. In
[4] an arc-consistent translation of cardinality constraints based on a O(n
2
) sized sorter
(or totalizer by the authors terminology) is presented. The proof above shows that any
sorting network will preserve arc-consistency when used to represent cardinality constraints.
More generally, the idea of using sorting networks to convert non-clausal constraints into
SAT has been applied in [19]. The authors sort not just bits, but words, to be able to
more succinctly express uniqueness between them. Without sorting, a quadratic number
of constraints must be added to force every word to be distinct, whereas the bitonic sorter
used in that work is O(n log
2
n). In [16] a construction similar to the one presented in
this section is used to produce a multiplier where the partial products are added by sorters
computing on unary numbers. Although the aim of the paper is to remove Xors, which may
have a slow implementation in silicon, the idea might be even better suited for synthesis
geared towards SAT-based verication. Finally, in [34], the carry propagation problem of
addition networks is also recognized. The authors solve the problem a bit dierently, by
preprocessing the netlist and extending the underlying SAT-solver, but potentially sorters
can be used in this context too.
19
N. Een and N. S orensson
Small/medium ints. (577 benchmarks)
Solver #solved-to-opt.
bsolo 187
minisat+ 200
PBS4 166
Pueblo 194
sat4jpseudo 139
pb2sat+zcha 150
Big integers (482 benchmarks)
Solver #solved-to-opt.
bsolo 9
minisat+ 26
PBS4 (buggy)
Pueblo N/A
sat4jpseudo 3
pb2sat+zcha 11
Figure 10. PB-evaluation 2005. Problems with objective function, solved to optimality.
6. Evaluation
This section will report on two things:
The performance of MINISAT+ compared to other PB-solvers.
The eect of the dierent translation techniques.
It is not in the scope of this paper to advocate that PB-solving is the best possible solution
for a particular domain specic problem, and no particular application will be studied.
6.1 Relative performance to other solvers
In conjunction with the SAT 2005 Competi-
No optimization function (113 benchmarks)
Solver #solved (sat/unsat)
bsolo 44 ( 8/36)
minisat+ 78 (35/43)
PBS4 89 (28/61)
Pueblo 103 (42/61)
sat4jpseudo 69 (17/52)
pb2sat+zcha 78 (36/42)
Figure 11. PB-evaluation 2005. No objective
function, just satisability (on small integers).
tion, a pseudo-boolean evaluation track was
also arranged.
12
MINISAT+ participated in
this evaluation together with 7 other solvers.
Because not all solvers could handle arbi-
trary precision integers, the benchmark set
was divided into small, medium and big in-
tegers. From the results, it seems that only
the big category was problematic (greater
than 30-bit integers), so we have merged the
other two categories here. Not all problems
had an objective function, so problems were
also divided into optimization and pseudo-
boolean satisability problems.
Out of the the 8 solvers, 3 was found to be unsound, reporting UNSAT for problems
where other solvers found veriable models. However, one of these solver, PBS4, seemed
only to be incorrect for big integers, so we still consider this solver. But the other two,
GALENA and VALLST are excluded from our tables, as they have multiple erroneous UN-
SAT answers, even in the small integer category. The results of the remaining solvers can
be found in Figure 10 and Figure 11. In the evaluation, MINISAT+ selected translation
method using the following ad-hoc heuristic, applied to each constraint: If the BDD trans-
lation is really compact, use that; otherwise, if the sorting network is not extremely large,
use that; otherwise, fall back on adder networks (which are compact).
12. http://www.cril.univ-artois.fr/PB05/ (see also [22, 21, 6, 2, 30, 13])
20
Translating Pseudo-Boolean Constraints into SAT
From the results we conclude that MINISAT+ and PUEBLO were the two strongest solvers
participating in the evaluation. Although it would be interesting to compare these solvers
to commercial LP solvers such as CPLEX, for practical reasons this has not been doneno
LP solver was part of the evaluation, and CPLEX requires a license.
6.2 Eciency of dierent translation techniques
In this section, the three dierent translation techniques are evaluated on a random sample
of benchmarks, drawn from the PB-evaluation set. Each benchmark is evaluated over 9
dierent parameters to MINISAT+:
All constraints are translated using one and the same technique (3 choices).
The objective function is translated using any of the techniques (3 choices).
The reason for treating the objective function separately, is that the optimization constraints
generated from it are often very dierent from the problem constraints. The benchmarks
were selected by the following procedure:
Pick one of the 9 settings for MINISAT+.
Pick one of the 1176 benchmarks from the evaluation set.
If MINISAT+ could solve it within 10 minutes, keep it.
Repeat until 40 benchmarks have been accumulated.
The procedure should give a reasonably unbiased benchmark set.
13
Run-times and trans-
lation sizes (relative to the PB-formulation) are presented in Figure 12. The experiments
were carried out on a cluster of AMD Athlon XP 2800+ machines, each with 1 GB of RAM.
The results indicate that the translation through adders does not work well, either for
the constraints or the objective function. This is particularly interesting as the adder-
translation is the most compact one on average. For the objective function, it seems best
to use the sorter-translation. If it is best combined with BDDs or sorters for the problem
constraints cannot be concluded from the table, but there are instances where the result
of using BDDs dier widely from the result of using sorters. In the table, the translation
blow-up includes the objective function which can be dominating, as seen by comparing the
results of optimization problems with the results of pure satisability problems.
Some remarks about the table: (i) The lower part (below the line) contains problems
without objective function. As conversion of the non-existent objective does not aect the
result, the same gures occur in three places, modulo timing uctuation. (ii) The relative
blow-up is given in logarithmic scale (the x of 10
x
), and so means that the problem
was solved by the parser and pre-processor, producing zero clauses.
13. One benchmark was later detected as a duplicate, and therefore removed.
21
N. Een and N. S orensson
Constraints: Adders BDDs Sorters Adders BDDs Sorters Adders BDDs Sorters
(Obj func.): (Adder) (Adder) (Adder) (BDD) (BDD) (BDD) (Sorter) (Sorter) (Sorter)
aro 293
(2.8)
299
(5.4)
190
(3.3)
936
(4.4)
447
(5.4)
975
(4.8)
470
(2.9)
765
(5.4)
373
(3.5)
sc205 166
(2.4)
3
(2.7)
86
(2.8)
166
(2.4)
3
(2.7)
86
(2.8)
166
(2.4)
3
(2.7)
86
(2.8)
bk4x3 7
(2.4)
4
(2.4)
10
(2.6)
21
(3.9)
32
(4.1)
15
(3.9)
9
(2.9)
6
(2.9)
3
(2.9)
neos1
(1.2)
(1.2)
(0.8)
(1.4)
(1.5)
90
(1.3)
705
(1.2)
195
(1.2)
23
(0.9)
neos20 8
(1.3)
3
(1.3)
14
(1.5)
9
(1.3)
2
(1.3)
13
(1.5)
8
(1.3)
3
(1.3)
14
(1.5)
lseu
(2.6)
(3.0)
(2.9)
(4.2)
(4.2)
(4.2)
235
(3.1)
203
(3.3)
331
(3.4)
misc03 30
(2.2)
(4.8)
33
(2.8)
24
(2.1)
(4.8)
26
(2.8)
27
(2.1)
(4.8)
32
(2.8)
sample2 4
(2.6)
3
(2.7)
6
(2.9)
7
(3.9)
8
(4.1)
5
(3.8)
21
(3.6)
17
(3.5)
17
(3.5)
stein45 20
(0.5)
25
(0.9)
21
(0.7)
16
(0.8)
18
(1.0)
16
(0.9)
20
(0.7)
20
(0.9)
14
(0.7)
enigma 5
(2.3)
122
(4.8)
9
(2.9)
5
(2.3)
122
(4.8)
9
(2.9)
5
(2.3)
123
(4.8)
9
(2.9)
noswot
(3.4)
119
(2.7)
()
(3.4)
131
(2.7)
()
(3.4)
64
(2.7)
()
p0282
(2.4)
(2.5)
(2.7)
360
(2.1)
355
(2.3)
368
(2.6)
(3.1)
732
(3.3)
281
(3.2)
vpm1
(2.4)
830
(3.4)
(2.9)
(2.4)
375
(3.4)
(2.9)
(2.4)
176
(3.4)
(2.9)
sc50b
(2.6)
147
(2.7)
147
(2.8)
(2.6)
39
(2.7)
143
(2.8)
(2.6)
108
(2.7)
139
(3.0)
neos8
(1.6)
359
(1.3)
20
()
(1.7)
263
(1.8)
20
()
(1.6)
266
(1.4)
20
()
maros 12
(3.0)
3
(3.2)
5
(3.2)
77
(4.5)
57
(4.5)
96
(4.6)
10
(3.1)
7
(3.3)
6
(3.4)
l152lav
(2.8)
429
(3.2)
704
(3.2)
(2.8)
110
(3.4)
43
(3.6)
(2.8)
139
(4.4)
324
(4.7)
mod008 570
(3.6)
378
(3.6)
355
(3.7)
30
(5.4)
47
(5.4)
356
(5.9)
28
(4.6)
20
(4.6)
67
(4.6)
clip-b 245
(0.9)
245
(0.9)
245
(0.9)
51
(1.4)
51
(1.4)
51
(1.4)
6
(1.4)
6
(1.4)
6
(1.4)
hanoi5 9
(0.5)
9
(0.5)
9
(0.5)
414
(2.6)
426
(2.6)
426
(2.6)
12
(1.2)
12
(1.2)
12
(1.2)
ii32b3
(0.5)
(0.5)
(0.5)
720
(1.8)
720
(1.8)
721
(1.8)
25
(0.9)
25
(0.9)
25
(0.9)
ii32e4
(0.7)
(0.7)
(0.7)
(1.8)
(1.8)
(1.8)
40
(0.8)
40
(0.8)
40
(0.8)
par16-3 1
(0.7)
1
(0.7)
1
(0.7)
44
(2.5)
44
(2.5)
43
(2.5)
1
(1.4)
1
(1.4)
1
(1.4)
ssa7552-159
(1.0)
(1.0)
(1.0)
(3.0)
(3.0)
(3.0)
21
(1.6)
21
(1.6)
21
(1.6)
s4-4-3-2pb
(1.2)
(1.3)
(1.2)
(2.2)
942
(2.2)
393
(2.2)
131
(1.5)
320
(1.6)
8
(1.4)
s4-4-3-9pb 26
(1.2)
150
(1.2)
23
(1.2)
454
(2.3)
684
(2.2)
153
(2.1)
14
(1.6)
61
(1.7)
9
(1.8)
frb30-15-3
(0.1)
(0.1)
(0.1)
761
(0.7)
761
(0.7)
761
(0.7)
164
(0.3)
164
(0.3)
164
(0.3)
frb35-17-5
(0.1)
(0.1)
(0.1)
(0.5)
(0.5)
(0.5)
811
(0.1)
811
(0.1)
809
(0.1)
woodw 55
()
54
()
55
()
55
()
54
()
55
()
55
()
55
()
55
()
chnl10-11 60
(1.5)
20
(1.4)
32
(1.5)
60
(1.5)
20
(1.4)
32
(1.5)
60
(1.5)
20
(1.4)
32
(1.5)
chnl10-20 24
(1.8)
87
(1.5)
24
(1.6)
24
(1.8)
87
(1.5)
24
(1.6)
24
(1.8)
87
(1.5)
24
(1.6)
fpga35-35
(1.0)
74
(0.9)
3
(1.3)
(1.0)
75
(0.9)
3
(1.3)
(1.0)
75
(0.9)
3
(1.3)
fpga40-40
(1.0)
701
(0.9)
2
(1.1)
(1.0)
700
(0.9)
2
(1.1)
(1.0)
700
(0.9)
2
(1.1)
22s-smv 3
(1.0)
1
(0.7)
20
(1.2)
3
(1.0)
1
(0.7)
20
(1.2)
3
(1.0)
1
(0.7)
20
(1.2)
cache-inv12 36
(0.1)
14
(0.0)
19
(0.2)
36
(0.1)
14
(0.0)
19
(0.2)
36
(0.1)
14
(0.0)
19
(0.2)
burch-dill 16
(0.8)
3
(0.4)
16
(0.9)
16
(0.8)
3
(0.4)
16
(0.9)
16
(0.8)
3
(0.4)
16
(0.9)
ex-br-mem 101
(0.9)
117
(0.6)
407
(1.1)
101
(0.9)
116
(0.6)
407
(1.1)
101
(0.9)
117
(0.6)
407
(1.1)
rf10 28
(0.4)
15
(0.2)
18
(0.4)
28
(0.4)
15
(0.2)
18
(0.4)
28
(0.4)
15
(0.2)
18
(0.4)
tag10 96
(0.5)
5
(0.3)
16
(0.6)
96
(0.5)
5
(0.3)
16
(0.6)
96
(0.5)
5
(0.3)
16
(0.6)
Solv. 100s: 18 17 22 18 19 23 23 24 29
Solv. 1000s: 23 29 28 26 33 33 31 38 37
Figure 12. Runtime of MINISAT+ on a random selection of benchmarks. The upper part
contains optimization problems with an objective function; in the lower part are pure satisability
problems. The numbers state runtime in seconds. A dash indicates timeout at 1000 seconds. The
super-script numbers give the translation blow-up, written as log
10
(clauses / pb-constraints). A
value of 3 means each constraint was translated to 1000 clauses on average. The two top lines
show what translation method was used for the constraints and objective function respectively.
The two bottom lines show the total number of problems solved at a timeout of 100/1000 seconds.
22
Translating Pseudo-Boolean Constraints into SAT
7. Conclusions and Future Work
Coding integer arithmetic into boolean operations in a manner well suited for hardware im-
plementation is a thoroughly studied topic. Contrary to this the focus of this paper lies on
coding arithmetic, in particular the constructs present in PB-constraints, in ways that are
suitable for a SAT-solver. One of the results shown herein is that the compact implemen-
tation of adder networks operating on binary numbers works poorly for SAT compared to
the more verbose implementation using unary numbers. By change of representation SAT
solving could be leveraged into PB solving with very reasonable results, which should have
implications on, for example, how SAT-based circuit verication is carried out on designs
containing arithmetic. Although making domain specic modication to a SAT-solver is an
approach likely to outperform translation based methods in many cases, our belief is that
translation is particularly well suited for the kind of problems where SAT-solvers are already
successful. An example of such a problem might be nding error-traces in circuits with as
many Xs on the inputs as possible. The pragmatics of the approach is also appealing, as
encoding into SAT is often much easier than modifying the core solver.
A theoretical result of our study is a proven better bound on the smallest arc-consistent
translation of cardinality constraints. Furthermore, our studies reinforce the common opin-
ion that lack of carry propagation in adders are bad for SAT solving, and that more generally
high implicativity or arc-consistency is desirable for the subcomponents of a SAT encoding.
In the translation using BDDs, arc-consistency was achieved by adding redundant clauses
to strengthen unit propagation, which further shows that small does not necessarily mean
good when it comes to CNF encodings. In fact, an interesting branch of future research
would be to study how a circuit can be partitioned into chunks that lend themselves to
clausication with high implicativity or arc-consistency, such that (a) the encoding is still
compact, and (b) the interaction of the components still preserves high implicativity. A
more direct future work is to explore the freedom of base-selection in the translation using
sorters, in particular by minimizing the number of duplicated inputs rather than the total
number of inputs, to increase the implicativity.
8. Acknowledgments
The authors wish to express their gratitude to Alan Mishchenko, Armin Biere, Reiner
Hahnle, Mary Sheeran and the reviewers for their careful reading and helpful suggestions
for improvements of the manuscript. We would also like to thank Christian Szegedy who
came up with the generalized version of the proof of arc-consistency of sorters, something
we had hitherto only veried experimentally.
References
[1] P.A. Abdulla, P. Bjesse, and N. Een. Symbolic Reachability Analysis Based
on SAT-Solvers. In Proceedings of the 6
th
International Conference on Tools and
Algorithms for the Construction and Analysis of Systems (TACAS2000), 2000.
[2] F. Aloul, A. Ramani, I. Markov, and K. Sakallah. PBS: A Backtrack Search
Pseudo-Boolean Solver. In Symposium on the Theory and Applications of Satisa-
bility Testing (SAT2002), 2002.
23
N. Een and N. S orensson
[3] F.A. Aloul, A. Ramani, I.L. Markov, and K.A. Sakallah. Generic ILP versus Spe-
cialized 0-1 ILP: An Update. In Proceedings of International Conference on Com-
puter Aided Design (ICCAD2002), 2002.
[4] O. Bailleux and Y. Boufkhad. Ecient CNF encoding of boolean cardinality
constraints. In Proceedings of the 9th International Conference on Principles and
Practice of Constraint Programming, CP 2003, volume 2833. LNCS, 2003.
[5] O. Bailleux and Y. Boufkhad. Problem encoding into SAT : the counting con-
straints case. In Proceedings of The Seventh International Conference on Theory and
Applications of Satisability Testing (SAT2004), 2004.
[6] O. Bailleux, Y. Boufkhad, and O. Roussel. A Translation of Pseudo Boolean
Constraints to SAT. In Journal on Satisability, Boolean Modeling and Computation
(JSAT06), issue 2, pages 183192, 2006.
[7] C.W. Barret, D.L. Dill, and A. Stump. Checking Satisability of First-Order
Formulas by Incremental Translation to SAT. In Proc. of the 14
th
Int. Conf. on
Computer Aided Verication (CAV02), LNCS 2404, 2002.
[8] Peter Barth. A Davis-Putnam Based Enumeration Algorithm for Linear
pseudo-Boolean Optimization. Research Report MPI-I-95-2-003, Max-Planck-
Institut f ur Informatik, Im Stadtwald, D-66123 Saarbr ucken, Germany, January 1995.
[9] K.E. Batcher. Sorting Networks and their Applications. In Proceedings of AFIPS
Spring Joint Computer Conference, volume 32, pages 307314, 1968.
[10] K.C. Bickersta, E.E. Swartzlander, and M.J. Schulte. Analysis of Column Com-
pression Multipliers. In Proceedings of 15
th
IEEE Symposium on Computer Arith-
metic (ARITH-1501), 2001.
[11] M. Bozzano, R. Bruttomesso, A. Cimatti, T. Junttila, P. v. Rossum, S. Schulz, and
R. Sebastiani. The MathSAT 3 System. In Conference on Automated Deduction
(CADE-20), Springer Verlag, 2005.
[12] Randy E. Bryant. Graph-Based Algorithms for Boolean Function Manipula-
tion. In IEEE Transactions on Computers, C-35(8):677-691, 1986.
[13] D. Chai and A. Kuehlmann. A Fast Pseudo-Boolean Constraint Solver. In
Proceedings of Design Automation Conference (DAC03), pages 830835, 2003.
[14] L. Dadda. Some Schemes for Parallel Multipliers. In Alta Frequenza, volume 34,
pages 1417, 1964.
[15] Niklas Een and Niklas S orensson. An extensible SAT solver. In Proceedings of the
6
th
Int. Conference on Theory and Applications of Satisability Testing, 2003.
[16] P.D. Fiore. Parallel Multiplication Using Fast Sorting Networks. In IEEE
Transactions on Computers, vol 48, no 6, 1999.
24
Translating Pseudo-Boolean Constraints into SAT
[17] I.P. Gent. Arc Consistency in SAT. In Proceedings of the Fifteenth European
Conference on Articial Intelligence (ECAI 2002), 2002.
[18] D. E. Knuth. The Art of Computer Programming, volume 3: Sorting and
Searching. Addison Wesley, 1973.
[19] Daniel Kroening and Ofer Strichman. Ecient Computation of Recurrence Di-
ameters. In 4
th
International Conference on Verication, Model Checking, and Ab-
stract Interpretation, volume 2575 of LNCS, 2003.
[20] Cong Liu, Andreas Kuehlmann, and Matthew W. Moskewicz. CAMA: A Multi-
Valued Satisability Solver. In Int. Conf. on Computer Aided Design, 2003.
[21] Vasco M. Manquinho and Jo ao Marques-Silva. On Using Cutting Planes in
Pseudo-Boolean Optimization. In Journal on Satisability, Boolean Modeling and
Computation (JSAT06), issue 2, pages 191210, 2006.
[22] Vasco M. Manquinho and Olivier Roussel. The First Evaluation of Pseudo-
Boolean Solvers. In Journal on Satisability, Boolean Modeling and Computation
(JSAT06), issue 2, pages 97136, 2006.
[23] S. Minato. Fast Factorization Method for Implicit Cube Representation. In
IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems,
volume 15, pages 377384, 1996.
[24] M. W. Moskewicz, C. F. Madigan, Y. Zhao, L. Zhang, and S. Malik. Cha: Engi-
neering an Ecient SAT Solver. In Proceedings of 12
th
International Conference
on Computer Aided Verication, volume 1855 of LNCS, 2001.
[25] Y. Novikov and R. Brinkmann. Foundations of Hierarchical SAT-Solving. In 6
th
Intl. Workshop on Boolean Problems, (extended ver.: ZIB-Report 05-38, 2005), 2004.
[26] D. Plaisted and S. Greenbaum. A Structure-preserving Clause Form Transla-
tion. In Journal on Symbolic Computation 2, 1986.
[27] William Pugh. The Omega Test: a fast and practical integer programming
algorithm for dependence analysis. In Supercomputing, pages 413, 1991.
[28] Mary Sheeran. Describing and reasoning about sorting networks.
In slides from invited talk at the Nordic Workshop on Programming Theory
(http://www.cs.chalmers.se/~ms/Turku.ppt), 2003.
[29] Hossein M. Sheini and Karem A. Sakallah. A SAT-based Decision Procedure
for Mixed Logical/Integer Linear Problems. In International Conference on
Integration of AI and OR Techniques in Constraint Programming for Combinatorial
Optimization Problems (CP-AI-OR05), volume 3524 of LNCS, 2005.
[30] Hossein M. Sheini and Karem A. Sakallah. Pueblo: A Hybrid Pseudo-Boolean
SAT Solver. In Journal on Satisability, Boolean Modeling and Computation
(JSAT06), issue 2, pages 157181, 2006.
25
N. Een and N. S orensson
[31] Carsten Sinz. Towards an Optimal CNF Encoding of Boolean Cardinality
Constraints. In 11
th
Int. Conf. on Principles and Practice of Constraint Prog., 2005.
[32] G. Tseitin. On the complexity of derivation in propositional calculus. Studies
in Constr. Math. and Math. Logic, 1968.
[33] J.P. Warners. A linear-time transformation of linear inequalities into con-
junctive normal form. In Inf. Proc. Letters, 68, ISSN 0169-118X, 1996.
[34] M. Wedler, D. Stoel, and W. Kunz. Arithmetic reasoning in DPLL-based SAT
solving. In Design, Automation and Test in Europe Conference, 2004.
26