Efficient SAT Solving for Non-Clausal Formulas Using DPLL, Graphs, and Watched Cuts
Total Page:16
File Type:pdf, Size:1020Kb
Efficient SAT Solving for Non-Clausal Formulas Using DPLL, Graphs, and Watched Cuts∗ † Himanshu Jain Edmund M. Clarke Verification Group School of Computer Science Synopsys, Inc. Carnegie Mellon University ABSTRACT tive normal form (CNF). Typical formulas arising in practice are Boolean satisfiability (SAT) solvers are used heavily in hardware not necessarily in CNF. We refer to propositional formulas not in and software verification tools for checking satisfiability of Boolean CNF form as non-clausal formulas (Boolean circuits). As argued formulas. Most state-of-the-art SAT solvers are based on the Davis- by Thiffault et al. [20] converting a non-clausal formula to CNF in- Putnam-Logemann-Loveland (DPLL) algorithm and require the in- troduces overhead in form of a large number of new variables and put formula to be in conjunctive normal form (CNF). We present a may destroy the initial structure of the formula, which can be cru- new SAT solver that operates on the negation normal form (NNF) cial in efficient satisfiability checking. of the given Boolean formulas/circuits. The NNF of a formula is Suppose we are given a non-clausal formula φ. In order to check usually more succinct than the CNF of the formula in terms of the satisfiability of φ using a CNF based SAT solver, φ needs to the number of variables. Our algorithm applies the DPLL algo- be converted to CNF. Let us assume for now that φ is in negation rithm to the graph-based representations of NNF formulas. We normal form (NNF). This means that φ contains only “^” (“AND”), adapt the idea of the two-watched-literal scheme from CNF SAT “_” (“OR”), “:” (“NOT”) operators and the scope of each “:” is solvers in order to efficiently carry out Boolean Constraint Propa- a propositional variable. There are two ways of converting φ to a gation (BCP), a key task in the DPLL algorithm. We evaluate the CNF formula. The first way of converting φ to a CNF formula is by introduction of new variables [21]. This produces a CNF formula new solver on a large collection of Boolean circuit benchmarks ob- 0 tained from formal verification problems. The new solver outper- φ that is equi-satisfiable to φ and is linear in the size of φ. This is forms the top solvers of the SAT 2007 competition and SAT-Race most common and practical way of converting φ to a CNF formula. 2008 in terms of run time on a large majority of the benchmarks. The second method is to expand φ using the distributive proper- ties of ^;_ in order to obtain a CNF formula. Let us denote the Categories and Subject Descriptors: J.6 [Computer Aided Engi- CNF formula obtained by expansion of φ as CNF(φ). For exam- neering]: [Computer-Aided Design] ple let φ be (a ^ :b) _ (c ^ (d _ : f )). Then CNF(φ) is (a _ c) ^ General Terms: Algorithms, Design, Verification (a _ d _ : f ) ^ (:b _ c) ^ (:b _ d _ : f ). Note that CNF(φ) and φ Keywords: Boolean Satisfiability, Verification, DPLL, NNF contain the same set of variables and are logically equivalent. This method of obtaining CNF(φ) from φ is impractical because the size of CNF(φ) can be exponential in the size of φ. 1. INTRODUCTION In this paper we present a new SAT solver that checks the satisfi- The problem of propositional (Boolean) satisfiability (SAT) is ability of φ by applying the DPLL algorithm to the hpgraph [7, 15] to decide whether a given propositional formula is satisfiable. This of φ. Each path in the hpgraph of φ, starting from a root node and problem is of central importance in hardware and software verifica- ending at a leaf node, corresponds to a clause in CNF(φ). That is, tion, logic synthesis, automatic test generation, and artificial intel- the hpgraph of φ implicitly encodes CNF(φ). Fig. 1(a) shows the ligence. Most state-of-the-art SAT procedures [3, 4, 5, 17, 18, 13, hpgraph of the formula (a ^ :b) _ (c ^ (d _ : f )). The size of the 11, 19, 8] are variations of the Davis-Putnam-Logemann-Loveland hpgraph of φ is linear in the size of φ. Thus, the hpgraph compactly (DPLL) algorithm and require the input formula to be in conjunc- represents CNF(φ). By using the hpgraph we avoid explicitly list- ∗ ing out the clauses in CNF(φ), which can require exponential time This research was sponsored by the Semiconductor Research Cor- and space in the size of φ. poration (SRC), the Gigascale Systems Research Center (GSRC), the Office of Naval Research (ONR), the Naval Research Labora- Let us denote the disjunctive normal form (DNF) formula ob- tory (NRL), the Army Research Office (ARO) and General Motors tained by converting φ to DNF by expanding out φ as DNF(φ). Let Lab at CMU. φ be (a^:b)_(c^(d _: f )). Then DNF(φ) is (a^:b)_(c^d)_ †The author did this research as a graduate student at CMU. (c ^ : f ). Once again explicitly listing out DNF(φ) can be expo- nential in the size of φ. Our solver utilizes the vpgraph [7, 15] of φ. The vpgraph of φ implicitly encodes DNF(φ) and is linear in the size of φ. The vpgraph for our example is shown in Fig. 1(b). Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies 1.1 Our Contributions bear this notice and the full citation on the first page. To copy otherwise, to • We present a new SAT solver that checks the satisfiability of a republish, to post on servers or to redistribute to lists, requires prior specific NNF formula φ by applying the DPLL algorithm to the hpgraph permission and/or a fee. DAC 2009, July 26 - 31, 2009, San Francisco, California, USA of φ. Our solver also utilizes the vpgraph of φ in certain steps Copyright 2009 ACM 978-1-60558-497-3 -6/08/0006 ...$5.00. of SAT solving. If the input formula/circuit is not in NNF it is C1 C2 1e+07 1e+06 Y-axis: #Vars in NNF 1 1 1e+06 Y-axis: #Vars in NNF 2 2 100000 a c a c y > x on 440 points 100000 y > x on 0 points 10000 5 5 3 4 3 4 10000 -b d -f -b d -f 1000 1000 y < x on 1677 points (a) (b) 100 100 y < x on 2252 points X-axis: #Vars in CNF Before Pre-processing X-axis: #Vars in CNF After Pre-processing 10 10 Figure 1: Let φ be (a ^ :b) _ (c ^ (d _ : f )). (a) The hpgraph of φ. 10 100 1000 10000 100000 1e+06 1e+07 10 100 1000 10000 100000 1e+06 Two node cuts C1;C2 are shown. (b) The vpgraph of φ. We show the Figure 2: Number of variables comparison. negation of a variable by using a minus sign. 2. PRELIMINARIES A Boolean formula is in negation normal form (NNF) iff it con- first converted to an equi-satisfiable NNF formula as explained tains only the Boolean connectives “^” (“AND”), “_” (“OR”) and in Section 2. “:” (“NOT”), and the scope of each occurrence of “:” is a Boolean • The most crucial component of our DPLL SAT solver is an ef- variable. We also require that there is no structure sharing in a NNF ficient Boolean Constraint Propagation (BCP) algorithm on the formula, that is, output from a gate acts as input to at most one gate. hpgraph. We describe an algorithm for performing BCP on hp- A NNF formula is tree-like, while a circuit can be DAG-like. graph that adapts the two-watched-literal scheme [18] found in Conversion of Boolean Circuits to NNF: Most formulas obtained CNF SAT solvers. In particular, a “watch” in an hpgraph corre- in practice are Boolean circuits. In our work Boolean circuits are sponds to a node cut in the hpgraph. By maintaining two node converted to NNF formulas in two stages. The first stage re-writes cuts for each connected component in the hpgraph we achieve other operators (such as xor, iff, implies, if-then-else) in terms of the same effect as the two watched-literal scheme found in the ^, _, : operators. In order to avoid a blowup in the size of the CNF SAT solvers. Fig. 1(a) shows two node cuts C1;C2 (possi- resulting formula we allow sharing of sub-formulas. Thus, the first ble watches) for a hpgraph. Two node cuts allow watching two stage produces a formula containing ^;_;: gates, possibly with nodes (literals) on each path (clause) in a hpgraph component. structure sharing. The second stage gets rid of the structure sharing The two-watched-literal scheme used in CNF SAT solvers is in order to obtain a NNF formula. This is done by introduction a special case of our algorithm (when the hpgraph represents of new variables. We introduce a new variable for each gate that a CNF formula). As in CNF SAT solvers non-chronological has a fanout greater than one. Once the sharing is removed the backtracking is cheap as the node cuts are not updated when negations can be pushed to the variables using DeMorgans laws. backtracking. (Section 3) Observe that the conversion of a Boolean circuit to a NNF formula can be done in linear time in the size of the Boolean circuit.