binary tree representation
DESCRIPTION
Binary Tree Representation. The recursive Shannon expansion corresponds to a binary tree Example: Each path from the root to a leaf corresponds to a minterm. x. 1. 0. y. y. 1. 0. 0. 1. The root represents the original function f . - PowerPoint PPT PresentationTRANSCRIPT
BDDsBDDs 11
Binary Tree RepresentationBinary Tree RepresentationThe recursive Shannon expansion corresponds to The recursive Shannon expansion corresponds to
a a binary treebinary tree
Example:Example:
Each path from the root to a leaf corresponds to Each path from the root to a leaf corresponds to a minterm.a minterm.
1111
11
00
00
00
xx
yyyy
( ) ( )
x x
xy x y xy x y
f xf x f
x yf y f x yf y f
xyfx yfxy
fx yf
BDDsBDDs 22
The root represents the original function The root represents the original function ff..
The two nodes immediately below the root The two nodes immediately below the root
represent the co-factors of represent the co-factors of ff..
As you go deeper, each node represents a co-As you go deeper, each node represents a co-
factor of the function represented by its parent.factor of the function represented by its parent.
The leaves are the terminal cases representing 0 The leaves are the terminal cases representing 0
and 1 which have no co-factors.and 1 which have no co-factors.
BDDsBDDs 33
ExampleExample
1111
11
00
00
00
11
aa
cc bb
00 1100
11 11
11
00
00
00
11
aa
bb bb
00
1100
11
00
cccc
SplittinSplitting g variablevariable
f ab ac
00 1100
11
BDDsBDDs 44
Implicit Enumeration -Implicit Enumeration - Branch and Bound Branch and Bound
Checking for tautology and many other Checking for tautology and many other theoretically intractable problems (co-NP theoretically intractable problems (co-NP complete) can be complete) can be effectivelyeffectively solved using solved using implicit enumeration:implicit enumeration:
use recursive Shannon expansion to explore Buse recursive Shannon expansion to explore Bn.n.
In (hopefully) large subspaces of BIn (hopefully) large subspaces of Bnn, prune the , prune the binary recursion tree bybinary recursion tree by exploiting properties of the node function fexploiting properties of the node function fcc(v)(v) exploiting heuristic bounding techniquesexploiting heuristic bounding techniques
Even though in the worst case the recursion Even though in the worst case the recursion tree may have 2tree may have 2nn nodes, in practice nodes, in practice (in many (in many cases),cases), we typically encounter a we typically encounter a linearlinear number number of nodes. of nodes.
BDDsBDDs 55
Implicit Enumeration -Implicit Enumeration - Branch and Bound Branch and Bound
Thus we say that the 2Thus we say that the 2nn minterms of f have minterms of f have been been implicitly enumeratedimplicitly enumerated
BDD’s (Binary Decision Diagrams) are BDD’s (Binary Decision Diagrams) are alternate representations in which implicit alternate representations in which implicit enumeration is performed enumeration is performed staticallystatically, and , and nodes with identical path cofactors are nodes with identical path cofactors are identifiedidentified
BDDsBDDs 66
ROBDDsROBDDs
represents a logic function by a directed acyclic represents a logic function by a directed acyclic graph (DAG).graph (DAG). (many logic functions can be (many logic functions can be represented compactly - usually better than SOP’s)represented compactly - usually better than SOP’s)
canonicalcanonical form ( form (importantimportant) ) (only canonical if an (only canonical if an ordering of the variables is given)ordering of the variables is given)
many logic operations can be performed many logic operations can be performed efficientlyefficiently on BDD’s on BDD’s (usually linear in size of result - tautology (usually linear in size of result - tautology and complement are constant time)and complement are constant time)
size of ROBDD critically dependent on variable size of ROBDD critically dependent on variable orderingordering
BDDsBDDs 77
ROBDDsROBDDs one root node per function, two terminals 0,
1 each node, two children, and a variable Shannon co-factoring tree, except reduced
and ordered (ROBDD)Reduced:
any node with two identical children is removed two nodes with isomorphic BDD’s are merged
Ordered: Co-factoring variables (splitting variables) always
follow the same order from a root to a terminalxi1
< xi2 < xi3
< … < xin
BDDsBDDs 88
OBDDOBDDOrdered BDDOrdered BDD ( (OBDDOBDD) ) Input variables are ordered - Input variables are ordered -
each path from root to sink visits nodes with labels each path from root to sink visits nodes with labels ((variablesvariables) in ascending order.) in ascending order.
aa
cc cc
bb
00 11
orderedorderedorder = a,c,border = a,c,b
aa
bb cc
cc
00 11
notnotorderedordered
bb
BDDsBDDs 99
ROBDDROBDD
Reduced Ordered BDD - reduction Reduced Ordered BDD - reduction rules:rules: if the two children of a node are the same, if the two children of a node are the same,
the node is eliminated: f = cf + c’fthe node is eliminated: f = cf + c’f if two nodes have isomorphic graphs, they if two nodes have isomorphic graphs, they
are replaced by one of themare replaced by one of them These two rules added to ordering These two rules added to ordering
mean each node represents a distinct mean each node represents a distinct logic function.logic function.
BDDsBDDs 1010
By tracing paths to the 1 node, we get a By tracing paths to the 1 node, we get a covercover of pairwise of pairwise disjointdisjoint cubes. cubes.
The power of the BDD representation is that it does not explicitly enumerate all paths; rather it represents paths by a graph whose size is measures by its nodes and not paths.
A DAG can represent an exponential A DAG can represent an exponential number of paths with a linear number of number of paths with a linear number of nodes.nodes.
F = b’+a’c’ = ab’+a’cb’+a’c’ (all paths to the 1 node)F = b’+a’c’ = ab’+a’cb’+a’c’ (all paths to the 1 node)
aa
ccbb
00 11
1100
11
110000
ff
ffaa= b’= b’ffa a = cb’+c’= cb’+c’
BDDsBDDs 1111
ExamplesExamplesaa
bb
cc
dd
00 11
11
00
aa
bb
cc
dd
00 11
BDDsBDDs 1212
EXOREXORaa
bb
cc
dd
00 11
dd
cc
bb
a b c d = a’b’c’d +
a’b’cd’ +
a’bc’d’ +
ab’c’d’ +
a’bcd +
ab’cd +
abc’d +
abcd’
Terms in SOP = ???
Nodes in BDD = ???
BDDsBDDs 1313
The Ordering EffectThe Ordering Effect
Two different orderings, same function.Two different orderings, same function.
aa
bb bb
cc cc
dd
00 11
c+bdc+bd bb
root root nodenode
c+dc+dcc
dd
f = ab+a’c+bc’df = ab+a’c+bc’d aa
cc
dd
bb
00 11
c+bdc+bd
d+bd+b
bb
11
00
BDDsBDDs 1414
ExampleExample
f = ad + be + cff = ad + be + cf
There are n! orderings – in this example 6! = There are n! orderings – in this example 6! = 720720
Try orderings:Try orderings:
a,b,c,d,e,fa,b,c,d,e,f
a,d,b,e,c,fa,d,b,e,c,f
BDDsBDDs 1515
TheoremTheorem
Theorem 1Theorem 1 ((Bryant – 1986 posted on course Bryant – 1986 posted on course
pagepage))
ROBDD’s are canonicalROBDD’s are canonical
Thus two functions are the Thus two functions are the samesame iff iff their ROBDD’s are equivalent graphs their ROBDD’s are equivalent graphs ((isomorphicisomorphic). Of course must use ). Of course must use same ordersame order for variables. for variables.
BDDsBDDs 1616
ImplementationImplementation
Each node is a triple (v,gEach node is a triple (v,g00,g,g11) ) representing a functionrepresenting a function
g = v gg = v g00 + v g + v g11
In most implementations, gIn most implementations, g00 and g and g11 are are pointerspointers to other nodes. to other nodes.
BDDsBDDs 1717
ITE OperatorITE OperatorTableTable Subset Subset Expression Expression Equivalent FormEquivalent Form00000000 00 0 0 00
00010001 AND(f, g)AND(f, g) fg fg ite(f, g, ite(f, g, 0)0)
00100010 f > gf > g f fgg ite(f,ite(f,g, 0)g, 0)
00110011 ff f f ff
01000100 f < gf < g fgfg ite(f, 0, g)ite(f, 0, g)
01010101 gg g g gg
01100110 XOR(f, g)XOR(f, g) f f g g ite(f,ite(f,g, g, g)g)
01110111 OR(f, g)OR(f, g) f + g f + g ite(f, 1, g)ite(f, 1, g)
10001000 NOR(f, g)NOR(f, g) f + g f + g ite(f, ite(f, 0,0,g)g)
1001 1001 XNOR(f, g)XNOR(f, g) f f g g ite(f, g,ite(f, g,g)g)
10101010 NOT(g)NOT(g) gg ite(g, 0, 1)ite(g, 0, 1)
10111011 f f g g f + f + gg ite(f, 1, ite(f, 1, g)g)
11001100 NOT(f)NOT(f) ff ite(f, 0, 1)ite(f, 0, 1)
11011101 f f g g f + gf + g ite(f, g, 1)ite(f, g, 1)
11101110 NAND(f, g)NAND(f, g) fg fg ite(f, ite(f, g, 1)g, 1)
11111111 11 1 1 11
BDDsBDDs 1818
Efficient ImplementationEfficient Implementation
Strong canonical form:Strong canonical form: A “unique-id” is A “unique-id” is associated (through a hash table) uniquely associated (through a hash table) uniquely with each element in a with each element in a setset..
With BDD’s the With BDD’s the setset is the set of all logic functions. A BDD is the set of all logic functions. A BDD node is a function. Thus each function has a unique-id node is a function. Thus each function has a unique-id in memory.in memory.
What is a good hash function?What is a good hash function?
vv00 11
ff
ffvv ffvv
BDDsBDDs 1919
Unique Table - Hash TableUnique Table - Hash Table
Before a node (Before a node (v, g, h v, g, h ) is added to BDD data base, it is looked up in the ) is added to BDD data base, it is looked up in the “unique-table”.“unique-table”. If it is there, then existing pointer to node is used to If it is there, then existing pointer to node is used to represent the logic function. Otherwise, a new node is added to the represent the logic function. Otherwise, a new node is added to the unique-table and the new pointer returned.unique-table and the new pointer returned.
Thus a Thus a strong canonical formstrong canonical form is maintained. The node for is maintained. The node for ff = ( = (v, g, h v, g, h ) ) exists exists iffiff((v, g, h v, g, h ) is in the unique-table. There is only one pointer for ) is in the unique-table. There is only one pointer for ((v, g, h v, g, h ) and that is the address to the unique-table entry.) and that is the address to the unique-table entry.
Unique-table allows single multi-rooted DAG to represent all users’ Unique-table allows single multi-rooted DAG to represent all users’ functions:functions:
hash valuehash valueof keyof key
collisioncollisionchainchain
BDDsBDDs 2020
Recursive Formulation of Recursive Formulation of ITEITE
vv = top-most variable among the = top-most variable among the three BDD’s three BDD’s f, g, hf, g, h
( , , )
( ) ( )
( ) ( )
( , ( , , ), ( , , ))
( , ( , , ), ( , , ))
( , , )
v v
v v v v v v v v
v v v v v v
v v v v v v
ite f g h fg f h
v fg f h v fg f h
v f g f h v f g f h
ite v ite f g h ite f g h
v ite f g h ite f g h
v f g
BDDsBDDs 2121
Recursive Formulation of Recursive Formulation of ITEITE
iteite((f, g, hf, g, h) ) if(if(terminalterminal casecase) {) { return result;return result;} else if(} else if(computed-tablecomputed-table has entry ( has entry (ff, , gg, , h h
)) {)) { return result;return result;} else {} else { let let vv be the top variable of ( be the top variable of (ff, , gg, , h h );); f <- f <- iteite((ffvv , g , gvv , , hhv v ););
g <- g <- iteite((ffvv , g , gvv , , hhv v );); if( f equals g ) return g;if( f equals g ) return g; R <- R <- find_or_add_unique_tablefind_or_add_unique_table(v, f, (v, f,
g );g ); insert_computed_tableinsert_computed_table( {( {ff, , gg, , h h }, R);}, R); return R; } }return R; } }
BDDsBDDs 2222
Terminal casesTerminal cases: :
(0,(0, f, g f, g) = ) = gg (1,(1, f f,, g g) =) = f f ite ite ((ff, , gg, , gg) =) = g g
Unique tableUnique table: Used to ensure one : Used to ensure one physical representation for any given physical representation for any given function.function.
Computed tableComputed table: Used to cache : Used to cache results to avoid recomputation.results to avoid recomputation.
BDDsBDDs 2323
ExampleExample
II = = ite ite ((FF,, G G,, H H) )
= (= (aa, , ite ite ((FFaa ,, G Ga a , , HHa a ), ), ite ite ((FFa a ,, G Ga a , , HHa a ))))
= (= (aa, , ite ite (1,(1, C C , , HH ), ), iteite((BB,, 0, 0, H H ))))
= (= (aa, , CC, (, (bb ,, ite ite ((BBb b , 0, 0b b , , HHb b ), ), ite ite ((BBb b ,, 00b b , , HHbb )) ))
= (= (aa, , CC, (, (bb , , ite ite (1,(1, 0, 1), 0, 1), ite ite (0, 0, (0, 0, DD))) )))
= (= (aa, , CC, (, (bb ,, 0, 0, DD))))
== ((aa, , CC, , JJ))
F,G,H,I,J,B,C,DF,G,H,I,J,B,C,Dare pointersare pointers
bb11
11
aa
00
11 00
11 00
FF
BB
11
11
aa
00
11 00
00
GG
cc 00CC
11
bb
00
11 00
00
HH
ddDD
1111
00
aa11 00
00
II
bbJJ
11
CC
DD
BDDsBDDs 2424
Computed TableComputed TableKeep a record of (Keep a record of (FF, , GG, , H H ) triplets already computed by ) triplets already computed by the the iteite operator in a operator in a hash-based cachehash-based cache ( ( “cache” table“cache” table). ). This means that the collision chain is This means that the collision chain is not usednot used ( (if if collision, old entry thrown away collision, old entry thrown away ).).
The above structure is wasteful since the BDD nodes and The above structure is wasteful since the BDD nodes and collision chain can be merged.collision chain can be merged.
BDDsBDDs 2525
Better ImplementationBetter Implementation
BDDsBDDs 2626
Edge ComplementationEdge Complementation
Can combine by making Can combine by making complement edgescomplement edges
00 11
GG
00 11
two differenttwo differentDAGsDAGs
00 11
GGG’G’
only one DAGonly one DAGusing complementusing complementpointerpointer
G’G’
BDDsBDDs 2727
Extension - Complement Extension - Complement EdgesEdges
To maintain the strong canonical form, we need to resolve 4 equivalences:To maintain the strong canonical form, we need to resolve 4 equivalences:
VV VV VV VV
VVVV VVVV
SolutionSolution: Always choose the one on the : Always choose the one on the leftleft, i.e. , i.e. the “1” edge must the “1” edge must not have a complementnot have a complement..
BDDsBDDs 2828
EXOR (revisited)EXOR (revisited)aa
bb
cc
dd
00 11
dd
cc
bb
aa
bb
cc
dd
11