Title: Computation Engines: BDDs and SAT part 1
1Computation Engines BDDs and SAT(part 1)
290N The Unknown Component Problem Lecture 7
2Outline
- Formulation and computation
- Representations of Boolean functions
- Canonicity of a representation
- Binary decision diagrams (BDDs)
- Definition, properties, applications, etc
- Boolean operations using BDDs
- Deriving BDDs from the circuit
- Satisfiability (SAT)
- Search, implications, branch-and-bound, etc
- Boolean operations using SAT
- Deriving CNF from the circuit
3Formulation and Computation
- Formulation
- Uses formalisms (such as automata theory, etc)
- Requires some statements to be proved
- Is not always concerned with how practical it is
- Computation
- Relies on formulation
- Looks into algorithms and data structures
- Is important for practical applications
4Computation in Discrete Domain
- Is performed by a variety of applications in
computer science and engineering - Represents and manipulates various discrete
objects (functions, relations, sets, automata,
FSMs, etc.) - The most fundamental object seems to be a
completely specified Boolean function - Boolean functions can be represented and
manipulated in a variety of ways - There is no single best representation
5Boolean Functions
- A completely specified Boolean function is a
mapping Bn ? B, where B 0,1 - All other types of Boolean and multi-valued
functions and relations can be represented using
completely specified Boolean functions
6Representations of Boolean Functions
x1x2
x3
7Representations of Boolean Functions
- Sum-of-products (DNF)
- F x1x2x3 x1x2x3 x1x2x3
- Product-of-sums (CNF)
- F (x1x2x3) (x1x2x3)
- (x1x2x3) (x1x2x3)
- (x1x2x3)
- Exclusive sum-of-products
- F x3 ? x1x2x3
- Factored form
- F x3 (x1x2)
x1
x2
X3
x3
X1
X2
1
0
8Canonicity of a Representation
- A representation is canonical if for each
function under certain conditions there exists
only one representation - Examples
- Truth table is canonical
- given the ordering of minterms
- BDD is canonical
- given the ordering of input variables
- SOP is not canonical
- but under some conditions it becomes canonical
- the set of all minterms
- the set of all primes
- ISOP computed using Minato-Morreale algorithm
when the ordering of variables is fixed
9Binary Decision Diagrams
- Formal definition
- Informal definition
- Deriving BDD using the definition
- Deriving BDD from the truth table
- The effect of variable ordering
- Boolean operations on the BDD
- Computing BDD from the Circuit
- BDD package
10Formal Definition
- Definition. Let f 0,1n? 0,1 be a Boolean
function where the arguments to f are denoted by
a set of variables V, such that Vn. Let ? V
?1,,n be a bijection indicating a total
ordering of these variables. That is, we consider
variable x and y to be ordered x lt y when ?(x) lt
?(y). An Ordered Binary Decision Diagram (OBDD) P
for f with respect to the given ordering ? is a
directed acyclic graph consisting of nonterminal
nodes labeled by the variables in V and terminal
nodes labeled by the Boolean constants 1 and 0.
Each nonterminal node has two outgoing edges the
1-edge and the 0-edge. The OBDD has a starting
node called the root. The computation of f(a)
follows a path from the root to a terminal node,
where at a node labeled by x, if a(x) 1, the
path follows the 1-edge, and otherwise it follows
the 0-edge. The value of the reached terminal
node determines the value of f(a). On a path from
the root to the sink, each variable occurs at
most once. The variables on every path from the
root to a terminal node respect ordering ?. That
is, for an edge leading from a node labeled by x
to one labeled by y, we must have ?(x) lt ?(y).
- R. E. Bryant, and C. Meinel, Ordered Binary
Decision Diagrams,'' in Logic Synthesis and
Verification, S. Hassoun and T. Sasao, eds.,
Kluwer Academic Publishers, 2001.
11Informal Definition
- Negative (positive) cofactor of F(x,y,z) w.r.t. x
is the result of substituting 0(1) into F(x,y,z)
instead of variable x - F0 F(0,y,z) F1 F(1,y,z)
- Binary decision diagram of function F is a direct
acyclic graph, in which - Each node stands for a function and two incoming
edges of this node represent cofactors of this
function w.r.t. a variable. - The leaves of the graph represent constant
functions, while the root represents function F - The same variable order is used for all paths
- The graph is reduced
12Examples of BDDs
a
a1
a
a1
b
b1
b1
0
1
0
1
a2
F a
F ab
a2
b2
a
1
b2
a
F1
b
0
1
0
1
0
1
0
1
Fa1b1 a2b2
Fa1b1a2b2
F a?
F ab
13Shannon Expansion
- Shannon expansion is
- F(x, y, z) x F0 x F1
- Shannon expansion is canonical
- For the given function F and variable x, the
cofactors F0 and F1 are uniquely determined - Another informal definition of BDD
- The Shannon expansion is recursively applied to
the function and its cofactors - A new node is added to mark each expansion
- The same variable order is used for all paths
- The graph is reduced
14Deriving BDD using Shannon Expansion
F
F x3 (x1x2) F0 Fx10 x2x3 F1
Fx11 x3
F
x1
x1
F1
F0
x3
F0
x2
1
0
F01
x3
F0
F0 x2x3 F00x20 0 F01x21 x3
x2
F00
F00
F01
1
0
x3
0
1
0
15Deriving BDD from Truth Table
x1
1
0
x2
x2
0
1
1
0
x3
x3
x3
x3
1
0
0
1
0
1
0
1
1
1
0
1
0
0
0
0
16Reduction of a Decision Tree
Rule 1 Isomorphic nodes are merged
Rule 2 Redundant nodes are removed
a
a
a
a
b
b
b
b
b
b
17Example of Decision Tree Reduction
x1
x2
x2
x3
x3
x3
x3
1
0
1
1
0
0
0
0
18Example of Decision Tree Reduction
x1
x1
x1
x2
x2
x2
x2
x2
x3
x3
x3
x3
x3
x3
x3
1
0
1
0
1
0
reduction
Decision tree
BDD
19Parts of a BDD (and their meaning)
- Nodes (Boolean functions)
- Terminal nodes (constant Boolean functions)
- Edges (function/co-factor relationship)
- Paths (true/false variable assignments)
- Cuts (variable partitions)
- Nodes pointed to under a cut (the set of
different cofactors of the function w.r.t.
variables above the cut) - Derived parameters
- Number of nodes (complexity of the function)
- Average path length (speed of evaluation of the
function)
x1
x2
x3
1
0
20Effect of Variable Ordering on the BDD size
F(x1, x2, y1, y2) (x1 y1) (x2 y2)
x1 lt y1 lt x2 lt y2 x1 lt x2 lt y1 lt y2
x1
x1
y1
y1
x2
x2
x2
y1
y1
y1
y1
y2
y2
y2
y2
1
0
1
0
21Another Example
Fa1b1 a2b2
a1
a1
b1
a2
a2
a2
b1
b1
b2
b2
0
1
0
1
a1ltb1lta2lt b2
a1lta2ltb1lt b2
22Operations on BDDs
- Apply NOT, AND, OR, EXOR, etc.
- Quantification (existential, universal, unique)
- Substitute variables
- Compose
- Specialized operators
- Generalized cofactor (constrain)
- Restrict
- Compatible projection
- etc.
23IF-THEN-ELSE (ITE) Operator
- ITE operator
- ITE( F, G, H ) F G F H
- It can be shown that a cofactor of ITE is the ITE
of cofactors - ITE( F, G, H )x 0 ITE(F0, G0, H0)
- Computation of Boolean operations is based on the
Shannon expansion - ITE(F,G,H)
- ITE(x, ITE(F, G, H)x 0, ITE(F, G, G)x
1 ) - ITE(x, ITE(F0, G0, H0), ITE(F1, G1, H1) )
24APPLY operator
- APPLY( F, G ) operator is a shorthand for any
two-variable Boolean operation - APPLY is reducible to ITE
- Example AND( F, G ) ITE( F, G, 0 )
- It follows that APPLY can be computed recursively
just like ITE - APPLY(F,G) x APPLY(F0, G0)
- x APPLY(F1, G1)
25APPLY Pseudocode
- procedure Apply( bdd F, bdd G )
-
- if ( IsAlreadyComputed( F, G ) ) return result
- if ( F ? 0,1 G ? 0,1 ) return APPLY_TABLE(
F, G ) - if ( Var( F ) Var( G ) )
- u CreateNode( Var(F), Apply(Fx,Gx),
Apply(Fx,Gx)) - else if ( Var( F ) lt Var( G ) )
- u CreateNode( Var(F) , Apply(Fx,G ),
Apply(Fx,G )) - else / if ( Var( F ) gt Var( G ) ) /
- u CreateNode( Var(G) , Apply(F,Gx ),
Apply(F,Gx )) - InsertComputed( F,G,u )
- return u
26Facbcd Gacd FG ?
A1,B1
A1
B1
a
a
A2,B2
A2
b
A6,B2
A6,B5
A6
B5
c
c
B2
A3,B2
A5,B2
A3
A3,B4
d
d
A4,B3
A5,B4
0
1
0
1
B3
B4
A4
A5
27Quantification
- Given a function F(x1, x2, x3)
- Existential quantification of F w.r.t. x1 is
- ?x1 F(x1, x2, x3) F(0, x2, x3) F(1, x2,
x3) - Universal quantification of F w.r.t. x1 is
- ?x1 F(x1, x2, x3) F(0, x2, x3) F(1, x2,
x3) - Unique quantification of F w.r.t. x1 is
- !x1 F(x1, x2, x3) F(0, x2, x3) ? F(1, x2,
x3) - Quantification is generalized to a set of
variables by applying it w.r.t each variable in
the set
28Example of Quantification
F(a,b,c,d) a?c cd abd
G(c,d)?abF(a,b,c,d)
H(c,d)?abF(a,b,c,d)
G
F
H
29Deriving BDDs from the Circuit
- The nodes of the circuit are visited recursively
starting from the POs - If the node is a PI, its global function is an
elementary variable - If the node is an internal node
- the computation is performed recursively for the
fanins - the global function of the node is computed by
composing its local function with the global
functions of the fanins
o2
o3
o1
Fi
F1
F2
g
h
b
a
c
d
e
f
30Properties of BDDs
- Small size
- for many practical functions
- Fast manipulation
- the smaller the faster
- Canonicity
- ease of caching
- useful for verification
- Large size
- for complex functions (i.e. multipliers)
- Slow manipulation
- the larger, the slower
31Implicit Computation
- With BDDs it is possible to construct and
manipulate sets of discrete objects (cubes,
states, etc.) in an implicit manner (without
explicitly enumerating individual elements). - As a result, BDDs may allow for an efficient
computation when explicit methods fail - Reachability analysis
- Symbolic model checking
- Sequential equivalence checking
- Exact SOP minimization
- Heuristic ESOP minimization
- Computation of symmetries of Boolean functions
- Computation of spectra (Walsh, Haar, Reed-Muller,
etc) - Manipulation of discrete matrices
32BDD Package
- Stores nodes in the hash table
- The cofactoring variable and the two cofactors
are used as a key for hashing the node - The computed tables stores the results of
intermediate computations - Reduces the complexity of computation from
exponential to linear - Periodically performs garbage collections and
dynamic variable reordering
33Introduction to BDDs References
- R. E. Bryant. Symbolic Boolean Manipulation with
Ordered Binary Decision Diagrams. ACM Computing
Surveys, Vol. 24, No. 3 (September, 1992), pp.
293-318. - Henrik Reif Andersen. An Introduction to Binary
Decision Diagrams. Dept. of Information
Technology, Technical University of Denmark,
1997. - http//www.itu.dk/people/hra/notes-index.ht
ml - F. Somenzi. Binary Decision Diagrams (Tutorial),
University of Colorado, 1999, http//citeseer.nj.n
ec.com/somenzi99binary.html
34Boolean Satisfiability
- Definition
- Search for a satisfying assignment
- Computation using SAT
- Computing CNF from the Circuit
- SAT solver
35Definition
- Given a CNF formula ? representing a Boolean
function f(x1,,xn), the satisfiability problem
is - identifying a assignment to the formula
variables, x1 v1, x2 v2, , xn vn, such
that all clauses are satisfied, i.e. f(v1,,vn)
1, - or proving that such assignment does not exist
36Example
CNF
ab
(a b c) (a b c) (a b c) (a c
d) (a c d) (a c d) (b c d) (b
c d)
cd
Cube bcd
Clause b c d
37Comment
- Such a simple problem and so much effort to solve
it - because the size of CNF used in practice is very
large - The best known solution is Davis-Logemann-Loveland
(DLL) procedure, which perform exhaustive search
with back-tracking - This procedure is efficient because of a
combination of good heuristics and smart data
structures - Conflict analysis with clause recording
- Non-chronological backtracking
- Variable selection heuristics
- Random restarts
- Two literal clause watching, etc
38Search for a Satisfying Assignment
a
b
b
c
c
c
d
d
d
d
d
Courtesy Karem Sakallah, University of Michigan
39Computation using SAT
- The classical SAT is a yes/no thing
- It returns one satisfying assignment, or no
assignment if the problem is UNSAT - If a conflict occurs during search, SAT solver
generates a conflict clause and continues
exploring the search space - It is possible to have SAT enumerate through the
satisfying assignments of the problem - for this, each satisfying assignment is treated
similar to a conflict - a new clause (blocking clause) is added and
search continues - For large boolean spaces, it is very important to
generate satisfying assignments in the form of
cubes rather than minterms - There are several methods for doing this
40Boolean operations using SAT
- Complement
- Enumerate through the satisfying assignments and
collect all blocking clauses - Boolean AND
- put CNF clauses of arguments together
- Other Boolean operations
- reducible to complement and Boolean AND
- Composition
- renaming variables and appending clauses
- Universal quantification
- omitting the quantified variables in all CNF
clauses - Existential quantification
- reduced to universal and two complements
41Deriving CNF from the Circuit
- The CNF formula for each node is computed
- One way of computing a CNF for the node is
applying de Morgan rule to the SOP of the off-set
of the nodes function - Another way is to use AND/INV graph
representation of the nodes on-set, and add
clauses for each gate in the graph - The CNF of the network is derived by putting
together (ANDing) the CNFs for each node - For single output circuits, if only the positive
(negative) phase of the circuit function is
needed, the literal p (p) is added to the CNF,
where p (p) is the positive (negative) phase of
the output variable of the PO node
42SAT Solver
- Stores clauses as arrays of integers
- Makes decisions and propagates implications
- When conflict occurs, adds a conflict clause to
the problem - When a satisfying assignment is found, while
enumerating through all satisfying assignments,
adds a breaking clause to the problem - Periodically removes inactive clauses
- Implements restarts
- Surprise A state-of-the-art SAT solver can be
implemented in 600 lines of C code!!!
43Introduction to SAT References
- J.P. Marques-Silva, K.A. Sakallah GRASP A
Search Algorithm for Propositional
Satisfiability'' in IEEE Transactions on
Computers, vol 48, pp. 506--521, 1999. - W. Kunz, J. Marques-Silva, S. Malik. SAT and
ATPG Algorithms for Boolean Decision Problems,
in Logic Synthesis and Verification, S. Hassoun
and T. Sasao, eds., Kluwer Academic Publishers,
2001. - N. Eén, N.Sörensson. An Extensible SAT-solver.
SAT 2003. http//www.cs.chalmers.se/een/Satzoo/An
_Extensible_SAT-solver.ps.gz