Lecture Notes on ``Binary Decision Diagrams`` (PPT Slides)
Download
Report
Transcript Lecture Notes on ``Binary Decision Diagrams`` (PPT Slides)
ENGG3190
Logic Synthesis
“Binary Decision Diagrams”
BDDs
Winter 2014
S. Areibi
School of Engineering
University of Guelph
Outline
• Binary Decision Diagrams (BDDs)
– Ordering
– Reduction
•
•
•
•
•
2
Canonical Form
Equivalency
Usefulness of BDDs
Operations on BDDs
Applications
ROBDD’s
•
•
•
•
Directed acyclic graph (DAG)
One root node, two terminal nodes 0, 1 (sinks)
Each node has exactly two children, associated with 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 along all paths
x i < x i < x i < … < x in
1
2
3
3
0
0
0
1
0
1
0
1
BDD Construction – naïve way
• Ordered BDD
a b c
f
0
0
0
0
1
1
1
1
0
0
0
1
0
1
0
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Truth table
f = ac + bc
1 edge
0 edge
f
a
b
b
c
0
c
0
0
c
1
0
c
1
0
1
Decision tree
6
Binary Decision Diagrams (BDD)
f
a
• Based on recursive Shannon expansion
f = a fa + a’ fa’
b
b
c
0
c
0
0
c
1
0
c
1
0
1
• Compact data structure for Boolean logic
– can represents sets of objects (states) encoded as Boolean
functions
• Canonical representation
– reduced ordered BDDs (ROBDD) are canonical
– essential for verification
8
Theorem
Theorem 1 (Bryant - 1986)
ROBDD’s are canonical
Thus two functions are the same iff their ROBDD’s are equivalent
graphs (isomorphic). Of course must use same order for
variables.
9
Onset is Given by all Paths to “1”
F = b’+a’c’ = ab’+a’cb’+a’c’
BDD encodes all paths to the 1 node
0
fa = cb’+c’ c
a
1
1
fa= b’
b
0
1
0
f
0
1
Notes:
•
By tracing paths to the 1 node, we get a cover of pairwise disjoint 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 measured by the
number of the nodes, and not paths.
A DAG can represent an exponential number of paths with a linear size (number
of nodes) in terms of its variables.
•
10
Any reason why Order X1, X2, X3?
The lower tree is a different tree and
that is going to be a PROBLEM!!
0
0
1
1
BDD Example
f = ab+a’c+bc’d
Root node
a
a
1
c+bd
c+bd
c
b
c+d
c
b
b
c
0
d*b
d
c
b
b
d
d
0
1
0
1
Two different orderings, same function.
13
Every path from the root to a leaf visits the variables in the SAME ORDER
Wrong and Stupid!
If we say we insist on x1, x2, x3 order, now what?
Figure on Left is ok
Figure on right is also ok (different but equivalent). Why?
PROBLEM!! Even though they are equivalent they are not canonical
Some Benefits of BDDs
• Check for tautology is trivial.
– BDD is a constant 1.
• Complementation.
– Given a BDD for a function f, the BDD for f’ can
be obtained by interchanging the terminal nodes.
• Equivalence check.
– Two functions f and g are equivalent if their BDDs
(under the same variable ordering) are the same.
BDDs: Reduction Rules
Reduction Rules for BDDs.
Reduced Ordered BDDs ROBDD.
We will reduce the Diagrams ROBDDs
Idea #1: Hey lets use Decision Diagrams
Idea #2: Lets impose a global variable ordering
Idea #3: Reduction
ROBDD
Ordered BDD (OBDD): Input variables are ordered - each path from root to
sink visits nodes with labels (variables) in the same order.
Not reduced !
a
c
a
ordered {a,c,b}
c
b
b
1
c
b
c
0
not ordered
0
1
Reduced Ordered BDD (ROBDD) - reduction rules:
– if the two children of a node are the same, the node is eliminated:
f = v f + v’ f
– if two nodes have isomorphic (identical) graphs, they are replaced by
one of them
These two rules make it so that each node represents a distinct logic function.
20
We will use Reduction Rules:
Rule #1 (simple) keep one copy of each constant leaf!
So the result is we got rid of all the redundancy of the leaf nodes.
But can we do better? We still have one X1 node, two X2 nodes, four X3 nodes!!
X
Y
Z
X1
X2
X2
X3
X3
0
1
BDD Reduction Rule -2
• Merge duplicate nodes (isomorphic subgraphs)
•
Nodes must be unique
f1
f
f2
a
a
g
a
h
b
c
f1 = fa’ g(b) + fa h(c) = f2
h
g
b
c
f = f1 = f2
24
Y
BDD Reduction Rules -3
• Eliminate redundant nodes
(with both edges pointing to same node)
f
a
g
g
b
b
f = a g(b) + a’ g(b) = g(b)
26
BDD Construction – Example
f
f
a
a
b
b
c
c
0
f = (a+b)c
c
c
1
1. Merge terminal nodes
a
b
b
c
c
0
1
2. Merge
duplicate nodes
b
c
0
1
3. Remove
redundant nodes
28
We started with a Decision Diagram which is big
We reduced it and have now ROBDD
RESULT: ROBDD is a Canonical Form (data structure) for any Boolean Function!
Great property to have, the simplest form of a graph is a canonical form
… Reduced Binary Decision Diagrams …
Reduced Binary Decision Diagrams …
v1 is the root; index(v1)=1 meaning that v1 is related to first variable in the order i.e. x1=a
BDDs: Sharing
Sharing in BDDs.
Advantages of Sharing.
f
x
F points to 0
0
0
f
F points to 1
1
• So far we showed how to construct a Reduced Ordered BDD
• What can we do with it? Represent any Boolean Function
• We can Share nodes in BDDs
1
x1 xor x2 xor x3 xor x4
X1X4 + X2X4
Make X1=1, X2=1, X3=1, X4=0 will lead to a 1
G = x2x4
x3 xor x4
x3 xnor x4
x4‘
The big grey boxes of S3 and Cout are the same shared function (identical)
Question: Do we have to build the grey stuff twice?? (BDD for S3 and BDD for Cout)
The Answer should be NO since it is inefficient
S
Cout
shared
BDDs: Applications
How are BDDs really implemented?
Applications:
Are two complicated logic circuits equivalent?
If not, how are they different?
How you can make a complicated Boolean
function equal 1.
How can ordering help?
H
F
G
H
We cannot implement and build BDDs flat! Not practical.
Is there a better way? Always start with reduced ordered BDDs
We use recursive methods (DIVIDE & CONQUER)
BDD packages are implemented using different functions.
H
• Simple calls to operators (AND, OR, …) creates the Binary Decision Diagram Incrementally
• Can this work for more complicated networks? YES (using BDD Packages)
• However, we have to think of “What are we going to do with variable ordering”?
Shared BDDs
F
G
What values for H
which make it “1”
Remember that Boolean functions represent different pieces of logic.
Remember also that ROBDD are canonical .
Since we are building shared BDDs they will be exactly the same, you get the same graph.
What inputs make functions F, G different?
In reality we can connect all variables to inputs of two blocks and the output connected to XOR
Application to Verification
• Equivalence Checking of combinational circuits
• Canonicity property of BDDs:
– if F and G are equivalent, their BDDs are identical (for the same
ordering of variables)
a F = a’bc + abc + ab’c
b
a
b
c
0
1
G = ac + bc
c
0
1
43
f
1
if
X1=1,
X2=don’t care,
X3=don’t care,
X4=1
If we can prove that the function F points to the 1 node then we can easily say it is a Tautology!
How about statisfiability?
In example on right hand side: Satisfiability is achieved if X1=1, X2=don’t care, X3=don’t care, X4=1
Or another path would be X1=0, X2=1, X3=don’t care and X4=1
Another operator in BDD package (satisfiability)
Application to SAT
• Functional test generation
– SAT, Boolean satisfiability
analysis
– to test for H = 1 (0), find a path
in the BDD to terminal 1 (0)
– the path, expressed in function
variables, gives a satisfying
solution (test vector)
H
a
b
ab
c
• Problem:?? size explosion!!!
0
ab’c
1
45
Logic Manipulation using BDDs
Useful operators
F’
F
¬
– Complement ¬ F = F’
(switch the terminal nodes)
– Restrict: F|x=b = F(x=b)
where b = const
•
To restrict variable x to 1, reconnect all
incoming edges to nodes x to their 1-nodes
•
To restrict variable x to 0, reconnect all
incoming edges to nodes x to their 0-nodes
0
1
1
0
F(y)
F(x,y)
Restrict
0
1
x=b
0
1
46
Restrict Operator ( f (c=0, d=1) )
f = (a+d)(b+c)+a’d’bc
fc’ = (a+d)b
a
fc’d= (a+1)b = b
a
d
a
b
b
b
c
0
Original BDD
fc’d = b
d
c
d
b
b
b
1
0
1
b
c
1
0
Set c = 0
Set d = 1
0
1
Restricted BDD
47
Apply Operation
Concept
Basic technique for building OBDD from Boolean formula.
A
op
B
a
A op B
a
b
c
|
d
0
c
– 48 –
b
c
d
d
1
0
0
1
Arguments A, B, op
a
A and B: Boolean Functions
Represented as OBDDs
op: Boolean Operation (e.g., ^, &, |)
1
Result
OBDD representing
composite function
A op B
The APPLY Operation
This is the most important of all the operations that can be performed on the BDDs.
The APPLY operation
provides the basic method for creating the representation of
a function according to the operators in a Boolean expression or logic gate network.
APPLY
takes graphs representing functions f1 and f2 , a binary operator <op> and
produces a reduced graph representing the function f1 <op> f2 defined as :
[f1 <op> f2 ] ( x1, x2, … , xn ) = f1(x1, x2, … , xn ) <op> f2 (x1, x2, … , xn )
The
algorithm proceeds from the roots of the 2 argument graphs downward,
creating vertices in the result graph at the branching points of the 2 argument
graphs.
The
control structure of the algorithm is based on the Shannon’s expansion
equation/theorem given below:
f1 <op> f2 = ~xi . ( f1|xi = 0 <op> f2 |xi = 0 ) + xi . ( f1|xi = 1 <op> f2 |xi = 1 )
– 49 –
The ITE Operator
This
is based on the Shannon’s expansion theorem and this is called the
‘If-Then-Else’ operator. This is a ternary operator defined as follows:
ITE( F, G, H ) = F.G + ~F.H
where F, G , H are 3 arbitrary switching functions.
A very
important property of the ITE operator which is of great interest for
this presentation, and for BDD in general, is that all two-argument operators
can be expressed in terms of the ITE operator .
The
above mentioned property gives great power to manipulate switching
functions and hence are used extensively in manipulating the BDD.
50
The ITE operator - Example
ITE( F, G, H) = F.G + ~F.H
For sake of simplicity, assume F = x and G = y as the input functions on which
manipulations are to be done.
Consider ITE( F, 1, G) :
ITE( F, 1, G ) =
F.1 + ~F.G
= x + ~x . y
= x+y
Consider ITE( F,G,0 ):
ITE( F, G, 0 ) = F.G + ~F.0
= x.y + 0
= x.y
The
above 2 examples show the powerfulness of, and the simplicity with which ITE
operator can be used to express 2 argument operators.
51
The ITE Operator Table
Name
Expression
Equivalent Form
0
0
0
AND(F,G)
F.G
ITE( F, G, 0 )
F >G
F. ~G
ITE( F, ~G, 0)
F
F
F
F<G
~F . G
ITE( F, 0 , G)
G
G
G
XOR( F, G )
F (+) G
ITE( F, ~G, G )
OR( F, G )
F+G
ITE( F, 1, G )
NOR( F, G )
~( F + G )
ITE( F, 0 , ~G )
XNOR( F, G )
~( F (+) G )
ITE( F, G, ~G )
NOT( G )
~G
ITE( G, 0, 1 )
F >= G
F+ ~G
ITE( F, 1, ~G )
NOT( F)
~F
ITE( F, 0, 1 )
F <= G
~F + G
ITE( F, G, 1 )
NAND( F, G )
~(F.G )
ITE( F, ~G, 1 )
1
1
1
52
APPLY* using ITE operator
An Example
ITE operators are used as they give a straight forward implementation of
the APPLY operation.
Ex: We want to find ~( a.c ) + b.c using APPLY.
Given F = ~(a.c) and G = b .c in the form of a BDD.
~( a . c )
+
b.c
a
b
c
c
1
0
0
1
53
APPLY Example Contd..
Assume ordering is a < b < c.
ITE( ~(a.c) , 1, bc )
a
0
1
ITE( 1, 1 , bc )
= ( 1.1 + 0.bc )
ITE( ~c , 1, bc )
b
1
0
ITE( ~c, 1, c )
ITE( ~c, 1, 0 )
1
c
0
ITE( 1, 1, 0 )
= ( 1.1. + 0.0 )
1
1
0
ITE( 0, 1, 0 )
= ( 0.1 + 1.0 )
0
ITE( 1, 1, 0 )
= ( 1.1 + 0.0 )
1
1
ITE( 0, 1, 1 )
= ( 0.1 + 1.1 )
1
54
linear growth
O(n)
Why too good to be true?
Because you can say “I can take any complicated problem profoundly exponentially computer science problem and use
BDDs to solve it”?
Variable Ordering matters!!’
The figure on the left has linear growth O(n)
But figure on the right is exponential (bad ordering)
So BDD will have efficient solutions if you have good ordering. But that is not always the case!
1. Multipliers are not good candidates to make a BDD
2. Adders on the other hand are good candidates
ai.bi can together
determine the
F()
Worst Order!
all a’s first then
b’s!!
This makes the
Tree fatter and more
complicated!
60
Useful BDD Operators – Apply Operation
• Basic operator for efficient BDD manipulation (structural)
• Based on recursive Shannon expansion
F <op> G = x (Fx <op> Gx) + x’(Fx’ <op> Gx’)
where <op> = binary operations: OR, AND, XOR, etc
61
APPLY Operator
• Apply: F
G, any Boolean operation
(AND, OR, XOR, )
F
G
F
1
G
=
0
0
1
0
1
• Useful in constructing BDD for arbitrary Boolean logic
• Any logic operation can be expressed using Apply (ITE)
• Efficient algorithms, work directly on BDD graphs
62
Apply Operation (cont’d)
• Apply: F
where
G
stands for any Boolean operator (AND, OR, XOR, etc)
F
G
F
1
G
=
0
0
1
0
1
• Any logic operation can be expressed using only Restrict and Apply
• Efficient algorithms, work directly on BDDs
• Apply can be used to construct a BDD bottom-up
•
From primary inputs, through internal logic gates, to output
63
Apply Execution Example
Argument A
Argument B
A1 a
|
A3 d
1 A5
– 64 –
Dynamic programming
Early termination rules
A6,B2 A6,B5
c B5
B2 d
Optimizations
A2,B2
Operation
c A6
A1,B1
a B1
A2 b
A4 0
Recursive Calls
B3 0
A3,B2
A5,B2 A3,B4
1 B4 A4,B3 A5,B4
Apply Result Generation
Recursive Calls
Without Reduction
A1,B1
b
b
A6,B2 A6,B5
– 65 –
c
A5,B2 A3,B4
A4,B3 A5,B4
a
a
A2,B2
A3,B2
With Reduction
d
0
1
1
c
c
1
d
0
1
Recursive calling structure implicitly defines unreduced BDD
Apply reduction rules bottom-up as return from recursive calls
Apply Operation - AND
F G = x (Fx Gx) + x’(Fx’ Gx’)
a AND c
ac
a 2.3
a 2
=
0
1
1.3 c
c 3
AND
0
1
03
1 0
1 1
a
=
c
0
1
66
Apply Operation - OR
F + G = x (Fx + Gx) + x’(Fx’ +Gx’)
f = ac+bc
ac
bc
a 4
OR
c
0
1
b 6
5
c
0
a
a 4+6
1
6+5 b
0+6
7
=
0+7 0+5 7+5 c
0+0
0
1
b
=
c
0
1
67
Some History
Origins
Lee 1959, Akers 1976
Idea of representing Boolean function as BDD
Hopcroft, Fortune, Schmidt 1978
Recognized that ordered BDDs were like finite state machines
Polynomial algorithm for equivalence
Bryant 1986
Proposed as useful data structure + efficient algorithms
McMillan 1993
Developed symbolic model checking
Method for verifying complex sequential systems
Bryant 1991
Proved that multiplication has exponential BDD
No matter how variables are ordered
– 68 –