Model-Based Theory Combination: Leonardo de Moura Nikolaj Bjørner
Model-Based Theory Combination: Leonardo de Moura Nikolaj Bjørner
Abstract
Traditional methods for combining theory solvers rely on capabilities of the solvers to produce all implied
equalities or a pre-processing step that introduces additional literals into the search space. This paper
introduces a combination method that incrementally reconciles models maintained by each theory. We
evaluate the practicality and efficiency of this approach.
1 Introduction
A core problem of Satisfiability Modulo Theories is combining separate theory
solvers for theories T 1 and T 2 to a combined solver for the union T 1 ∪ T 2 . The
Nelson-Oppen combination method identifies sufficient conditions for combining two
theories over disjoint signatures: only (disjunctions of) equalities over shared vari-
ables that are implied by one of the theories need to be communicated. Most existing
implementations and optimizations of this method seek to efficiently implement the
trigger:
if T i ∪ Γi |= u ' v then propagate u ' v,
to exhaustively enumerating all implied (disjunctions of) equalities for a theory T i
and constraints Γi that are asserted in its context. Another method [1] to obtain
completeness is by enumerating equalities corresponding to the cross-product of all
shared variable pairs and use the SAT solver for non-deterministically choosing a
partition based on the cross-product. Common to these methods is that they are
pessimistic about which equalities are propagated. A more optimistic approach is
by inspecting a candidate model Mi for one of the theories T i and propagate all
equalities implied by the candidate model, hedging that other theories will agree.
1 Email: leonardo@microsoft.comu
2 Email: nbjorner@microsoft.com
This paper is electronically published in
Electronic Notes in Theoretical Computer Science
URL: www.elsevier.nl/locate/entcs
de Moura, Bjørner
If not, use backtracking to fix the model. Thus, Model-based Theory Combination
is based on a trigger of the form:
if Mi |= T i ∪ Γi ∪ {u ' v} then propagate u ' v .
The rationale for Model-based Theory Combination is practical: It tends to be
much cheaper to enumerate equalities that are implied in a particular model than
of all models; the number of inter-theory equalities that really matter is small in
practice (intra-theory equality propagation on the other hand does matter); back-
tracking is relatively cheap with modern DPLL solvers; and finally, one may limit
the number of equalities implied by a model by model mutation.
2 Background
A signature Σ is a set of function and predicate symbols. Each symbol is associated
with a nonnegative integer, called the arity. If arity(g) = 0, then g is a constant
symbol. We assume that the binary equality predicate ' to be always present in
any signature Σ. We use the standard notion of Σ-structure M, that is, a support
set endowed with an arity-matching interpretation of the function and predicate
symbols from Σ. We use f M (pM ) to denote the interpretation of the function
symbol f (predicate symbol p) in the structure M. The truth of a Σ-formula in M
is defined in the standard ways. A formula φ is satisfiable in M iff its existential
closure is true in M. In this case, we say M is a model for φ. A sentence is a
first-order formula with no free variables. A (first-order) theory T over a signature
Σ is a set of (deductively closed) sentences over Σ. We say two theories T 1 and
T 2 have disjoint signatures when Σ1 ∩ Σ2 = {'}. A theory T is stably infinite
if every satisfiable quantifier free formula is satisfiable in an infinite model. A
theory T is convex [2] iff for all finite sets Γ of literals and for all non-empty
W W
disjunctions i∈I ui ' vi of variables, Γ |=T i∈I ui ' vi iff Γ |=T ui ' vi for some
i ∈ I. Intuitively, a theory is convex if for every satisfiable set of literals there
is a model where variables not implied to be equal have a distinct interpretation.
For example, linear integer arithmetic is not convex, because the set of literals
{0 ≤ x1 ≤ 1, 0 ≤ x2 ≤ 1, 0 ≤ x3 ≤ 1} is satisfiable, no equality xi ' xj for i 6= j is
implied, but there is no model where x1 , x2 and x3 are all distinct.
3 Related Work
3.1 Convex theories only
For convex theories it is sufficient to propagate all implied equalities between shared
variables. For instance, theories that admit canonizers solve equality propagation
by rewriting. In general, a theory T i is canonizing (as coined in [4]) if it admits a
function ↓ , such that:
tional assumption that may be tool specific to MathSat, but are pervasive in the
results from [8]: all literals used by the SAT solver must be present in the input to
the SAT solver. At the current time of writing CVC3 [9], Verifun [10], Yices [11],
and our tool Z3 all support dynamically added literals.
Our approach, presented later, appeals to an SMT solver that allows introducing
literals on the fly. If this is not possible, the approach boils down to a branching
heuristic on top of DTC.
3.3 Ackermannization
N
^
(pi ∨ xi ' v0 ) ∧ (¬pi ∨ xi ' v1 ) ∧ (pi ∨ yi ' v0 ) ∧ (¬pi ∨ yi ' v1 ),
i=1
f (xN , . . . , f (x2 , x1 ) . . .) 6' f (yN , . . . , f (y2 , y1 ) . . .) (3)
This performance problem reflects a limitation in the current congruence closure
algorithms used in SMT solvers, and it is not related with the theory combination
problem. In fact, the formula above uses only one theory. In [11], an approach,
called Dynamic Ackermannization, is proposed to cope with this problem. There,
clauses corresponding to Ackermann’s reduction are added when a congruence rule
participates in a conflict.
M-Propagate
u, v ∈ V, (u ' v) 6∈ L
M, Γ || F =⇒ d
M, Γ(u ' v) || F if u Mi = v Mi
add (u ' v) to L
M-Mutate n
M, Γ || F =⇒ M0 , Γ || F if M0 is some variant of M
additional expense to the theory solver are always propagated eagerly. Section 5
gives an example of opportunistic equality propagation.
(ii) Postponing model-based equality propagation: we delay applying the rule
M-Propagate until case splits on already existing literals have been performed.
(iii) Model mutators, the idea is to use a function δ(Mk ) that returns a more diverse
model. More formally, |classes(RMk )| ≤ |classes(Rδ(Mk ) )|
where B and N denote the set of basic and nonbasic variables, respectively. In
addition to this tableau, the solver state stores upper and lower bounds li and ui
for every variable xi and a mapping β that assigns a rational value β(xi ) to every
variable xi . The bounds on nonbasic variables are always satisfied by β, that is, the
following invariant is maintained
∀xj ∈ N , lj ≤ β(xj ) ≤ uj .
Bounds constraints for basic variables are not necessarily satisfied by β, so for
instance, it may be the case that li > β(xi ) for some basic variable xi , but pivoting
steps can be used to fix bounds violations, or detect an infeasible tableau. We hope
it does not come as a total surprise that the current model for the simplex solver
is given by β. Enumerating the equalities implied by β is simple: enumerate all
the values of β(xi ), inserting each value into a hash table. The expected time of
enumerating all equalities is then O(|B ∪ N |).
li ≤ xi ≤ ui , lj ≤ xj ≤ uj =⇒ xi ' xj if li = ui = lj = uj
EqRow
xi ' xj + P =⇒ xi ' xj if P is fixed, and β(P ) = 0
EqOffsetRows
xi ' xk + P1 P1 and P2 are fixed, and
=⇒ xi ' xj if
xj ' xk + P2 β(P ) = β(P )
1 2
EqRows
xi ' P + P1 P1 and P2 are fixed, and
=⇒ xi ' xj if
xj ' P + P2 β(P ) = β(P )
1 2
The first rule can be implemented using a mapping from values to fixed variables,
the second rule can be easily checked when a row is updated during a pivoting step.
The rule EqOffsetRows is a simpler and less expensive version of EqRows. It can
be implemented using a mapping (xk , v) 7→ xi , where xk and xi are variables, and
v is a value. In our implementation, the first three rules are eagerly applied, and
the last one is only applied before M-Propagate. We also aggressively remove fixed
variables from the basis.
These rules can miss some implied equalities. For instance, from the con-
straints (4), the rules detect the implied equality z ' w, but miss the equality
x ' y, because z is not a fixed variable. Fortunately, the bound propagation tech-
nique described in [17] can be used imply the bound 0 ≤ w, making w a fixed
variable, and enabling the application of the rule EqRow.
x ' y + w + s, z ' w + s, 0 ≤ z, w ≤ 0, 0≤s≤0 (4)
update(xj , v)
foreach xi ∈ B, β(xi ) := β(xi ) + aij (v − β(xj ))
β(xj ) := v
7
de Moura, Bjørner
Freedom intervals can be used to produce a more diverse β without performing any
pivoting operation. A simple greedy heuristic seems to be quite effective: for each
non-basic variable xj , execute update(xj , v), if there is a value v ∈ [Lj , Uj ] such that
|classes(Rβ )| < |classes(Rβ 0 )|, where β 0 denotes β after the update operation.
6 Experimental Evaluation
The experiments were conducted using a 32bit Pentium 4 processor running at
3.6Ghz, 2Gb of memory, and 2Mb of cache. The timeout was set to 10 minutes. We
compared our approach against other SMT solvers and against different strategies
within our solver Z3. We used the same benchmarks used in [13]. The benchmarks
were translated to the SMT-LIB format, and are available for download in our
website 3 . We also included, for N ∈ [1, 99] the examples from (3) and the following
simple family of satisfiable formulas in the comparison for N ∈ [2, 99]:
N
^
ϕ= f (xi ) ≥ 0 ∧ xi ≥ 0 ∧ xi 6' xi+1 (5)
i=1
All benchmarks but the Ackermann suite use the theories of uninterpreted functions
and linear arithmetic. Tables 1 and 2 summarize the results obtained in our ex-
periments. Each cell has the accumulated time, in seconds, used by each solver to
solve a family of benchmarks. It does not include the time spent in instances where
the solver produced the unknown result. A solver is considered to have produced
the unknown result when it times out or crashes. The number of unknown results
is displayed using parenthesis. MathSAT-dtc denotes the MathSAT solver with the
command line option -DTC that forces it to use Delayed Theory Combination. We
used Yices version 1.0.8 in the experiments. Yices is also based on DTC, but the
shared equalities are lazily generated, and it uses a filtering mechanism to avoid
the generation of unnecessary shared equalities [11]. Yices and Z3 implement Dy-
namic Ackermannization suggested in [11]. Six different versions of our Z3 solver
were used: Z3-dtc uses delayed theory combination and the additional equalities be-
tween shared variables are eagerly generated; Z3-dtc* is similar to Z3-dtc but uses
the current model to implement a branching heuristic for the generated equalities;
Z3-ack uses Ackermann’s reduction as a pre-processing step; Z3-neq, Z3-ndack and
Z3 all use Model Based Theory Combination, but Z3-neq does not use opportunis-
tic equality propagation, and Z3-ndack does not use Dynamic Ackermannization.
Notice that our implementation of Z3-dtc does not include several optimizations
that may be useful for a DTC framework. It does not take advantage of theory
propagation for arithmetic.
The benchmarks in the EufLaArithmetic family are trivial if the linear arithmetic
solver performs some form of opportunistic equality propagation. The Simple family
described above was used to demonstrate that DTC is not robust. Yices performs
poorly on most satisfiable instances in the RandomCoupled and RandomDecoupled
families.
Model based theory combination seems to be more robust than DTC or Ack-
ermann’s reduction. In these benchmarks, the average number of shared equalities
3 http://research.microsoft.com/∼leonardo/SMT07
8
de Moura, Bjørner
Table 1
Experimental results
Table 2
Experimental results (only Z3)
7 Conclusions
This paper introduced a new approach for dealing with equality propagation in
the context of convex theories where equality deduction is expensive and more
generally, in the context of non-convex theories. Both in theory, and as we validated
experimentally, the approach solves a number of practical deficiencies with other
known solutions to integrating theories.
Model-based Theory Combination requires that a decidable theory maintains a
notion of a model that supports efficiently answering queries of the form uM = v M .
The Wisa benchmark set is used in [13] to illustrate the usefulness of Ackermann’s
reduction in contrast with DTC. With Model-based Theory Combination, Acker-
mann’s reduction does not help on these set of benchmarks. We therefore believe
they reflect more the problems with DTC than the advantages of Ackermann’s
reduction. On the other hand, the synthetic Ackermann benchmarks, one can ob-
serve the utility of the reduction. Dynamic Ackermann reduction is not without
an overhead: new literals are added to the search space, and the new literals cause
T-Propagate to spend additional overhead of walking use-lists. Future work includes
investigating whether it is a practical advantage to build in the propagation directly
into a congruence closure algorithm.
9
de Moura, Bjørner
8 Acknowledgment
The authors would like to thank Alberto Griggio for providing the latest version of
MathSAT and adding a command line option for enabling Delayed Theory Combi-
nation.
References
[1] Bozzano, M., Bruttomesso, R., Cimatti, A., Junttila, T.A., van Rossum, P., Schulz, S., Sebastiani, R.:
The MathSAT 3 System. In Nieuwenhuis, R., ed.: CADE. Volume 3632 of Lecture Notes in Computer
Science., Springer (2005) 315–321
[2] Oppen, D.C.: Complexity, convexity and combinations of theories. Theor. Comput. Sci. 12 (1980)
291–302
[3] Nelson, G., Oppen, D.C.: Simplification by cooperating decision procedures. ACM Transactions on
Programming Languages and Systems 1(2) (1979) 245–257
[4] Shostak, R.E.: Deciding combinations of theories. J. ACM 31(1) (1984) 1–12
[5] Rueß, H., Shankar, N.: Solving linear arithmetic constraints. Technical Report SRI-CSL-04-01, SRI
International (2004)
[6] Detlefs, D., Nelson, G., Saxe, J.B.: Simplify: a theorem prover for program checking. J. ACM 52(3)
(2005) 365–473
[7] Bozzano, M., Bruttomesso, R., Cimatti, A., Junttila, T.A., Ranise, S., van Rossum, P., Sebastiani, R.:
Efficient theory combination via boolean search. Inf. Comput. 204(10) (2006) 1493–1525
[8] Bruttomesso, R., Cimatti, A., Franzén, A., Griggio, A., Sebastiani, R.: Delayed Theory Combination vs.
Nelson-Oppen for Satisfiability Modulo Theories: A Comparative Analysis. In: LPAR. (2006) 527–541
[9] Barrett, C., Tinelli, C.: CVC3. In: CAV ’07. (2007) to appear.
[10] Flanagan, C., Joshi, R., Saxe, J.B.: An explicating theorem prover for quantified formulas. Technical
Report HPL-2004-199, HP Laboratories, Palo Alto (2004)
[11] Dutertre, B., de Moura, L.: The Yices SMT Solver. http://yices.csl.sri.com/tool-paper.pdf (2006)
[12] Ackermann, W.: Solvable cases of the decision problem. Studies in Logic and the Foundation of
Mathematics (1954)
[13] Bruttomesso, R., Cimatti, A., Franzén, A., Griggio, A., Santuari, A., Sebastiani, R.: To Ackermann-ize
or Not to Ackermann-ize? On Efficiently Handling Uninterpreted Function Symbols in UF(E). In:
LPAR. (2006) 557–571
[14] Nieuwenhuis, R., Oliveras, A.: Fast Congruence Closure and Extensions. Inf. Comput. 2005(4) (2007)
557–580
[15] Ganzinger, H., Hagen, G., Nieuwenhuis, R., Oliveras, A., Tinelli, C.: DPLL(T): Fast decision
procedures. In: CAV 04. LNCS 3114 (2004) 175–188
[16] Nieuwenhuis, R., Oliveras, A., Tinelli, C.: Solving SAT and SAT Modulo Theories: From an abstract
Davis–Putnam–Logemann–Loveland procedure to DPLL(T). J. ACM 53(6) (2006) 937–977
[17] Dutertre, B., de Moura, L.: A Fast Linear-Arithmetic Solver for DPLL(T). In: CAV’06. LNCS 4144,
Springer-Verlag (2006) 81–94
[18] Sheini, H.M., Sakallah, K.A.: SMT(LU): a step toward scalability in system verification. In Hassoun,
S., ed.: ICCAD, ACM (2006) 844–851
10
de Moura, Bjørner
A A presentation of DPLL(T M )
Fig. A.1 repeats from [16] the presentation of DPLL(T ) as an abstract transition
system. We have added M to each sequent to emphasize that the current state
during proof-search also carries a model. In contrast to [16], we use a set L of literals
to choose case split candidates from. We assume L is a super-set of the literals
occurring in the set of clauses F . Besides the fresh equality literals introduced by
the rule M-Propagate, non-convex theory implementations, such as an integer linear
solver may introduce fresh literals as a side-effect of performing branch-and bound
search.
11
de Moura, Bjørner
UnitPropagate
Γ |= ¬C
M, Γ || F, C ∨ ` =⇒ M, Γ` || F, C ∨ ` if
` is undefined in Γ
Decide
` occurs in L
M, Γ || F =⇒ M, Γ`d || F if
` is undefined in Γ
Fail
Γ |= ¬C
M, Γ || F, C =⇒ fail if
Γ contains no decision variables
Backjump
Γ`d Γ0 |= ¬C,
there is a clause C 0 ∨ `0 such that
M, Γ`d Γ0 || F, C =⇒ M, Γ`0 || F, C if F, C |= C 0 ∨ `0 and Γ |= ¬C 0 ;
`0 is undefined in Γ;
0
` or ¬`0 occurs in F or in `d Γ0
T-Propagate
Γ |=T `
M, Γ || F =⇒ M, Γ` || F if ` occurs in L
` is undefined in Γ
Learn
all atoms of C occur in L
M, Γ || F =⇒ M, Γ || F, C if
F |= C
T
Forget n
M, Γ || F, C =⇒ M, Γ || F, C if F |=T C
Restart
M, Γ || F =⇒ M, ∅ || F
12