Title: Binary Decision Diagrams BDDs A Graph Application
1Binary Decision Diagrams (BDDs)A Graph
Application
2Boolean Expressions(propositional logic)
- Boolean expressions are generated from the
following grammar t x 0 1 not t t1
or t2 t1 and t2 t1 --gt t2 t1 lt--gt t2where
x is a boolean variable, and t is a boolean
expression. - A boolean expression t (x1,, xn) denotes a
truth value for each assignment of truth values
to x1,,xn, according to the standard truth
tables defining the boolean operators.
3Truth Tables of boolean operators
0 1
0 1
0 0 1 1 1 1
or
and
not 0 1 1 0
0 0 0 1 0 1
0 1
0 1 0 1 0 1
lt--gt
0 1
0 1 1 1 0 1
--gt
4Boolean Expressions
- If we fix the ordering of the variables in the
boolean expression, we get a function from Bn
to B. - f(x1, x2, , xn) 0,1
- f is satisfiable if f(x1, , xn) 1 for some
truth assignments to x1, , x2. - f is a tautology if f(x1, , xn) 1 for all
truth assignments to x1, , x2. - Ex
- ((x1 or x2) and x3) is satisfiable (ex
x1/1, x3/1) - ( x or not x) is a tautology.
- t1 and t2 are equivalent if f1 (x1, , xn) f2
(x1, , xn) for all truth assignment to x1, , xn.
5Binary Decision DiagramsIf-then-else operator
- Define a new boolean operator if-then-else
- if x (is true) then y0, else (x is false) then y1
- x y0, y1 ((x and y0) or (not x
and y1)) - In general for x - a boolean variable and t0,
t1 - boolean expressions - x t0, t1 is true if either x and t0 are
true, or x is false and t1 is true. - Always true t x t(1/x),
t(0,x) Shannon Expansion
6Binary Decision DiagramsIf-then-else operator
- Claim
- All boolean operators can be be expressed with
the if-then-else operator and constants 0,1, with
the following restrictions - tests are performed only over (positive)
variable. - variables appear only in the test part of the
expression.
7If-the-else operator
- Examples Basic boolean operators
- (x or y) x --gt 1, y--gt1,0
- can be written x --gt 1, t0 t0 --gt1,
0 - (x and y) x --gt (y --gt1,0),0
- (not x) x --gt 0,1
- (x lt--gt y) x --gt (y --gt 1,0), (y --gt 0,1)
8If-then-else operator
- An if-then-else normal form (INF) is a boolean
expression built entirely from the if-then-else
operator and the constants 0 and 1, such that all
tests are performed only on (not negated)
variables. - Claim
- Any boolean expression is equivalent to an INF
expression.
9If-the-else operator
- Example t ((x1 lt--gty1) and (x2 lt--gt
y2))Choose an ordering for the variables, to
order the INF expansion, then t x1 --gt
t1, t0 t0 y1 --gt 0, t00
t1 y1 --gt t11,0 t00
x2 --gt t001, t000 t11 x2 --gt
t111, t110 t000 y2 --gt 0,1
t001 y2 --gt 1,0 t110 y2
--gt 0,1 t111 y2 --gt 1,0
I
t x1 --gt t1, t0
t0 y1 --gt 0, t00 t1 y1 --gt
t11,0 t00 x2 --gt t001, t000
t11 x2 --gt t001, t000 t000 y2
--gt 0,1 t001 y2 --gt 1,0
II
10If-the-else operator
t x1 --gt t1, t0 t0
y1 --gt 0, t00 t1 y1 --gt t00,0
t00 x2 --gt t001, t000 t000
y2 --gt 0,1 t001 y2 --gt 1,0
III
11A Decision Tree
x1
t t0 y1
t1 y1 x2 t00
t11 x2 t000
y2 t001 y2 t111 y2
t110 y2 1 0 0 1
0 0 1 0 0
1
t x1 --gt t1, t0 t0
y1 --gt 0, t00 t1 y1 --gt t11,0
t00 x2 --gt t001, t000 t11
x2 --gt t111, t110 t000
y2 --gt 0,1 t001 y2 --gt 1,0
t110 y2 --gt 0,1 t111
y2 --gt 1,0
x 0 x1
12Binary Decision Diagram (BDD)
If we identify all identical expressions (or
subtrees), we get a directed acyclic graph
(DAG), which is called a Binary Decision
Diagram, or BDD.
13Binary Decision Diagram
A BDD for t ((x1 lt--gty1) and (x2 lt--gt
y2))with variable ordering x1ltx2lty1lty2
x1
t t0 y1
t1 y1 x2 t00
t11 x2 t000
y2 t001 y2
1 0 0 1 0
0
x1
t t0 y1
t1 y1 x2 t00
t000 y2 t001
y2 1
0
14Reduced, Ordered Binary Decision Diagrams(ROBDDs)
- A reduced, ordered binary decision diagram, is a
directed acyclic graph G satisfying - (maximum of) two terminal nodes, representing
values 1 and 0. - Nonterminal nodes are labeled with a variable v,
and pntrs to low(v) and high(v) (maximal out
degree 2) - In all paths variables have the same ordering.
(O) - For all nodes u,v in G
- var(v) var(u), low(v) low(u), high(v)
low(u) implies v u - low(u) not high(u) (R)
15Reducedness
16Canonicity of ROBDDs
- ClaimFor any function f Bn ---gt B and
ordering x1lt x2ltltxn on the variables of f,
there is exactly one ROBDD b such thatbv1/x1,
, vn/xn t(v1, , vn)for all (v1, , vn) in
Bn - Consequence
- b is a tautology if and only if b 1
- b is satisfiable if and only if b 0
17ROBDDs
- ROBDD give a compact representation of boolean
expressions (functions). - Fast for evaluating equivalence of boolean
expressions. - Efficient algorithm for boolean expressions over
the ROBDD representations. - Variable ordering has a great influence on the
size of an ROBDD associated with a boolean
expression.
18Constructing ROBDDs
- The challenge is to build an OBDD which is
already reduced, or reducing during construction. - Representation
- Nodes - represented as numbers 0,1,2, where 0,1
are reserved for the terminal nodes. - Variables, ordered x1lt x2lt .. lt xn are
represented by their indices 1,2,,n. - An ROBDD is stored in an array T, where each
entry represents a node u, with vu, lowu and
highu all indices, namely - T u --gt (v, low, high)
19Array Implementation
(var ) 1
node var low high
T
0 7 1 7 2 5
1 0 3 6 0
1 4 4 2
3 5 2 4 0 6
3 0 4 7 1
5 6
x1 7
x2 5
x3 6 x4 4
x5 2 3
x6 1 0
20Using a Hash table to ensure Reducedness
- To construct a reduced OBDD b, need to know for
any given (v,low, high) whether a node with
these 3-values is already in b? - To get an efficient reply, maintain a hash table
H (v, l, h) u mapping triples to
nodes. - Note
- H is the inverse of the node table T u (v,
l, h) (not hashed. Direct access by node ).
21Makenode and Build ROBDD
- T u (i, l, h)
- init(T)
initialize node table - u add (T, i, l, h)
allocate a new node in table - H (i, l, h) u
- init (H)
initialize hash table - b member(H, i, l, h) check if
(i,l,h) already in T - u lookup (H, i, l, h) find u
with (i,l,h) - insert (H, i, l, h, u)
make (i,l,h) map to u in
22Make a New Node
mk checks whether a node with (i,l,h) already
exists, constructs one if not, and returns the
node (u) O(1)
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
23Build an ROBDD
Building an ROBDD from a boolean expression t,
using the ordering x1
lt x2 lt lt xn
build T,H (t, i) if i gt n then if
t false return 0 else return 1
else v0 build (t0/xi, i1) v1
build (t1/xi, i1) return mk(i,v0,v1)
Initiation buildT,H (t,1)