Title: In The Name of God
1In The Name of God
By Bijan Alizadeh
2Binary Decision Diagrams
- Classical representation of logic functions
Truth Table, Karnaugh Maps, Sum- of- Products,
critical complexes, etc. - Critical drawbacks
- - May not be a canonical form or is too large
(exponential) for useful functions. Equivalence
and tautology checking is hard - - Operations like complementation may yield a
representation of exponential size
3Binary Decision Diagrams
- Reduced Ordered Binary Decision Diagrams (ROBDDs)
- A canonical form for Boolean functions
- Often substantially more compact than
traditional normal forms - Can be efficiently manipulated
- Introduced mainly by R. E. Bryant (1986).
- Various extensions exist that can be adapted to
the situation at hand (e. g., the type of circuit
to be verified)
4Binary Decision Trees
- A Binary decision Tree (BDT) is a rooted,
directed graph with terminal and nonterminal
vertices - Each nonterminal vertex v is labeled by a
variable var( v) and has two successors - - low( v) corresponds to the case where the
variable v is assigned 0 - - high( v) corresponds to the case where the
variable v is assigned 1 - Each terminal vertex v is labeled by value( v)
. 0, 1
5Binary Decision Trees
- Example BDT for a two- bit comparator, f( a1 ,a2
,b1 ,b2 ) - (a1 ? b1 ) ? (a2 ? b2 )
6Binary Decision Trees
- We can decide if a truth assignment x (x 1 ,
..., x n ) satisfies a formula in BDT in linear
time in the number of variables by traversing the
tree from the root to a terminal vertex - - If var( v) . x is 0, the next vertex on the
path is low( v) - - If var( v) . x is 1, the next vertex on the
path is high( v) - - If v is a terminal vertex then f( x ) f v
(x1 , ..., xn ) value( v) - - If v is a nonterminal vertex with var( v)
xi , then the structure of the tree is obtained
by Shanons expansion - fv (x1 , ..., xn )
- ?xi ? flow(v) (x 1 , ..., x n ) ? xi ?
fhigh(v) (x1 , ..., xn ) - For the comparator, (a1 ? 1, a2 ? 0, b1 ? 1, b2 ?
1) leads to a terminal vertex labeled by 0, i.
e., f( 1, 0, 1, 1) 0 - Binary decision trees are redundant
- - In the comparator, there are 6 subtrees with
roots labeled by b2 , but not all are distinct - Merge isomorphic subtrees
- - Results in a directed acyclic graph (DAG), a
binary decision diagram (BDD)
7(Canonical Form Property)Reduced Ordered BDD
- two Boolean functions are logically equivalent
iff they have isomorphic representations - This simplifies checking equivalence of two
formulas and deciding if a formula is satisfiable - Two BDDs are isomorphic if there exists a
correspondence between the graphs such that - - Terminals are mapped to terminals and
nonterminals are mapped to nonterminals - - For every terminal vertex v there exists a
terminal vertex v , value( v) value( v) ,
and - - For every nonterminal vertex v there exists a
terminal vertex v - var( v) var( v) , low( v) low( v) , and
high(v) high(v) - Bryant (1986) showed that BDDs are a canonical
representation for Boolean - functions under two restrictions
- (1) the variables appear in the same order along
each path from the root to a terminal - (2) there are no isomorphic subtrees or
redundant vertices - Þ Reduced Ordered Binary Decision Diagrams
(ROBDDs)
8Canonical Form Property
- Requirement (1) Apply total order lt on the
variables in the formula - if vertex u has a nonterminal successor v , then
var( u) lt var( v) - Requirement (2) repeatedly apply three
transformation rules - 1. Remove duplicate terminals eliminate all but
one terminal vertex with a given label and
redirect all arcs to the eliminated vertices to
the remaining one
9Canonical Form Property
- 2. Remove duplicate nonterminals if nonterminals
u and v have var( u) var( v) , low( u) low(
v) and high( u) high( v) , eliminate one of the
two vertices and redirect all incoming arcs to
the other vertex
3. Remove redundant tests if nonterminal vertex
v has low( v) high( v) , eliminate v and
redirect all incoming arcs to low( v)
10Canonical Form Property
- A canonical form is obtained by applying the
transformation rules until no further application
is possible - Applications
- -checking equivalence verify isomorphism
between ROBDDs - -non- satisfiability verify if ROBDD has
only one terminal node, labeled by 0 - -tautology verify if ROBDD has only one
terminal node, labeled by 1 - Example
- ROBDD of 2- bit Comparator with variable order
a1 lt b1 lt a2 lt b2
11Variable Ordering Problem
- The size of an ROBDD depends critically on the
variable order - For order a 1 lt a 2 lt b 1 lt b 2 , the comparator
ROBDD becomes
- For an n- bit comparator
- a1 lt b1 lt ... lt an lt bn gives 3n 2 vertices
(linear complexity) - a1 lt ... lt an lt b1 ... lt bn , gives 32n - 1
vertices (exponential complexity!)
12Variable Ordering Problem
- The problem of finding the optimal variable order
is NP- complete - Some Boolean functions have exponential size
ROBDDs for any order (e. g., multiplier) - Heuristics for Variable Ordering
- Heuristics developed for finding a good variable
order (if it exists) - ROBDDs tend to be smaller when related variables
are close together in the order (e. g., ripple-
carry adder) - Variables appearing in a subcircuit are related
they determine the subcircuits output Þ
should usually be close together in the order - Dynamic Variable Ordering
- Useful if no obvious static ordering heuristic
applies - During verification operations (e. g.,
reachability analysis) functions change, hence
initial order is not good later - Good ROBDD packages periodically internally
reorder variables to reduce ROBDD size - Basic approach based on neighboring variable
exchange ... lt a lt b lt ... Þ ...lt b lt a lt ...
13Logic Operations on ROBDDs
- Residual function (cofactor) b Î 0, 1
- f (x1,..., xn ) xi b f( x1 , ..., xi-1 , b,
xi1 , ..., xn ) - ROBDD of f computed by a depth- first traversal
of the ROBDD of f - (1) For any vertex v which has a pointer to a
vertex w such that var( w) xi , replace the
pointer by low(w) if b is 0 and by high(w) if b
is 1. - (2) If not in canonical form, apply Reduce to
obtain ROBDD of - f xi b.
- All 16 two- argument logic operations on Boolean
function implemented efficiently on ROBDDs in
linear time in the size of the argument ROBDDs.
14Logic Operations on ROBDDs
- Based on Shannons expansion
- f Ø x Ù f x 0 Ú x Ù f x 1
- Bryant (1986) gave a uniform algorithm, Apply,
for computing all 16 operations - f f an arbitrary logic operation on Boolean
functions f and f - v and v the roots of the ROBDDs for f and f ,
x var( v) and x var( v) - Consider several cases depending on v and v
- (1) v and v are both terminal vertices f f
value( v) value( v) - (2) x x use Shannons expansion
- f f Ø x Ù (f x 0 f x 0)
Ú x Ù (f x 1 f x 1) - to break the problem into two subproblems, each
is solved recursively - The root is v with var( v) x
- Low( v) is (f x 0 f x 0 )
- High( v) is (f x 1 f x 1 )
15Logic Operations on ROBDDs
- (3) x lt x f x 0 f x 1 f since f
does not depend on x - In this case the Shannons expansion simplifies
to - f f Ø x Ù (f x 0 f) Ú x Ù (f x
1 f), similar to (2) - and compute subproblems recursively,
- (4) x lt x similar to the case above
- Improvement using the if- then- else (ITE)
operator - ITE( F, G, H) F . G F . H where F, G and
H are functions - Recursive algorithm based on the following, v is
the top variable (lowest index) - ITE( F, G, H) v.( F. G F. H)v v.( F. G
F. H)v - v.( Fv .Gv Fv .Hv ) v.( Fv .Gv Fv
.Hv ) - (v, ITE( Fv , Gv , Hv ), ITE( Fv , Gv , Hv
)) - With terminal cases being F ITE( 1, F, G)
ITE( 0, G, F) ITE( F, 1, 0) ITE( G, F, F) -
- we define NOT( F) ITE( F, 0, 1) AND( F, G)
ITE( F, G, 0) - OR( F, G) ITE( F, 1, G) XOR( F, G)
ITE( F, Ø G, G) - etc.
16Logic Operations on ROBDDs
- By using dynamic programming, it is possible to
make the ITE algorithm polynomial - (1) The result must be reduced to ensure that it
is in canonical form - - record constructed nodes ( unique table )
- - before creating a new node, check if it
already exists in this unique hash table
17Logic Operations on ROBDDs
- (2) Record all previously computed functions in
a hash table ( computed table ) - - must be implemented efficiently as it may grow
very quickly in size - - before computing any function, check table for
solution already obtained
18Logic Operations on ROBDDs
- Return Build (t,1)
- function Build (t,i)
- if i ? n then
- if t is false then
- return 0
- else return 1
- else
- ? Build (t0/ , i1)
- ? Build (t1/ , i1)
- return MK(i , , )
- end Build
-
MKT, H(i, l, h) if l h then return l
else if member(H, i, l, h) then return
lookup(H, i, l, h) else u ?
add(T,i,l,h) insert(H, i, l, h, u) return u
unique Table
19Example
20Example
T u ? (i,l,h)
- Return Build (t,1)
- function Build (t,i)
- if i ? n then
- if t is false then
- return 0
- else return 1
- else
- ? Build (t0/ , i1)
- ? Build (t1/ , i1)
- return MK(i , , )
- end Build
MKT, H(i, l, h) if l h then return l
else if member(H, i, l, h) then return
lookup(H, i, l, h) else u ?
add(T,i,l,h) insert(H, i, l, h, u) return u
H (i,l,h) ? u
21Example
T u ? (i,l,h)
22Operations on ROBDD
- Construct the ROBDD resulting from applying op on
u1 and u2 - ApplyT,H(op,u1,u2)
- init(G) //Computed Table
- return APP(u1,u2)
- function APP(u1,u2)
- if G(u1,u2) ? empty then return G(u1,u2)
- else if u1 ? 0,1 and u2 ? 0,1 then u ?
op(u1,u2) - else if var(u1) var(u2) then
- u ? MK( var(u1) , APP( low(u1) , low(u2) ) ,
APP( high(u1) , high(u2) ) ) - else if var(u1) ? var(u2) then
- u ? MK( var(u1) , APP( low(u1) , u2 ) , APP(
high(u1) , u2 ) ) - else //var(u1) ? var(u2)
- u ? MK( var(u2) , APP( u1 , low(u2) ) , APP(
u1 , high(u2) ) ) - G(u1,u2) ? u
- return u
- end APP
23Example of Apply
- Compute AND of two ROBDDs
24Example of Apply
25Example of Apply
T u ? (i,l,h)
G(u1,u2) ? APP(u1,u2)
H (i,l,h) ? u
26Example of Apply
T u ? (i,l,h)
27Operations on ROBDD
- Restrict the ROBDD u according to the truth
assignment b/xj - RESTRICTT,H(u,j,b)
- return res(u)
- function res(u)
- if var(u) ? j then return u
- else if var(u) ? j then return
- MK( var(u), res( low(u) ), res( high(u) ) )
- else ( var(u) j ) if b 0 then
return - res( low(u) )
- else ( var(u) j, b 1 ) return
- res( high(u) )
- end res
28Example of RESTRICT
- F (x1 ? x2) x3 x20 gt j2 b0
T u ? (i,l,h)
H (i,l,h) ? u
29Example of RESTRICT
- After applying RESTRICT algorithm
30Example of RESTRICT
31Example of RESTRICT
T u ? (i,l,h)
H (i,l,h) ? u
32Operations on ROBDD
- SatCountT(u) Return number of valid truth
assignments of u - SatCountT(u)
- return 2var(u)-1 count(u)
- function count(u)
- if u0 then res ? 0
- else if u1 then res ? 1
- else
- res ? 2var(low(u))-var(u)-1 count(low(u))
- 2var(high(u))-var(u)-1 count(high(u))
- Return res
- end count
33Operations on ROBDD
- AnySat(u) Return a satisfying truth assignment
for u - AnySat(u)
- if u0 then Error
- else if u1 then
- else if low(u)0 then return xvar(u) ?1,
AnySat(high(u)) - else return xvar(u) ?0, AnySat(low(u))
34Operations on ROBDD
- AllSat(u) Return all satisfying truth assignment
for u - AllSat(u)
- if u0 then ltgt
- else if u1 then ltgt
- else return
- ltadd xvar(u) ?0 in front of all
truth-assignment in - AllSat(low(u)),
- add xvar(u) ?1 in front of all
truth-assignment in - AllSat(high(u))gt
35Derived Operations
- Compose Given F(x) and G(y), return F(G(y))
- Compose is reduced to two operations Restrict and
three operations Apply
36Derived Operations
- Quantifications
- Given a function F(x1, x2, x3)
- Existential Quantification
- ?x1F(x1, x2, x3) F(0, x2, x3) OR F(1, x2, x3)
- Universal Quantification
- ?x1F(x1, x2, x3) F(0, x2, x3) AND F(1, x2,
x3) - Unique Quantification
- !x1F(x1, x2, x3) F(0, x2, x3) XOR F(1, x2,
x3)
37Logic Operations on ROBDDs
- Complement edges can reduce the size of an ROBDD
by a factor of 2 - - Only one terminal node is labeled 1
- - Edges have an attribute (dot) to indicate if
they are inverting or not - - To maintain canonicity, a dot can appear only
on low( v) edges - - Complementation achieved in O( 1) time by
placing a dot on the function edge - - F and F can share entry in computed table
- - Adaptation of ITE easy
38References
- H.R. Andersen, An Introduction to Binary
Decision Diagrams, Lecture notes 1997. Web
http//www.it.dtu.dk/hra - T. Kropf, Introduction To Formal Verification,
Springer 1999. - K.S. Brace, R.L. Rudell and R.E. Bryant,
Efficient Implementation of a BDD Package, 27th
ACM/IEEE Design Automation Conference 1990, pp.
40. - E. M. Clarke, O. Grumberg and D.A. Peled, Model
Checking, 1999 E.M. Clarke, O. Grumberg and
Lucent Technologies.
39Variable Ordering
- Window Permutation Algorithm
- Example window size k 3 Strating point x2
- k!-1 total variable exchange k(k-1)/2
exchanging to go to best position
40Variable Ordering
- Sifting Algorithm
- Starting point x4
41Variable Ordering
- Group Sifting Algorithm
- is an extension of sifting. It moves a group of
variables at the time, instead of a single
variable. - Symmetric variables
- A boolean function f(x1,x2,,xn) is symmetric in
xi and xj if the interchange of xi and xj leaves
the function identically the same. - Once two variables are identified as symmetric,
they are locked together. This effectively
leads to an algorithm that sifts groups of
variables of varying size.
42Variable Ordering
- Relative Absolute Position (RAP)
- In each iteration do Sifting and Symmetry
checking (Window Permutation) - 1. At each iteration, a variable that has not
been sifted yet is chosen - 2. In each Sifting, Check it against its
neighbor for symmetry - 3. If symmetry is found, a group is formed and
the relative position is fixed -
- References
- 1. Who Are the Variables in Your
Neighborhood, Fabio Somenzi - 2. Dynamic Variable Ordering for Ordered
Binary Decision Diagrams, Richard Rudell