Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Binary Decision Diagrams
An Introduction and Some Applications
Manas Thakur
PACE Lab, IIT Madras
Manas Thakur (IIT Madras) BDDs 1 / 25
Motivating Example
Binary decision tree for a truth table
Manas Thakur (IIT Madras) BDDs 2 / 25
Motivating Example
Binary decision tree for a truth table
Manas Thakur (IIT Madras) BDDs 3 / 25
Motivating Example
Collapse redundant nodes
Manas Thakur (IIT Madras) BDDs 4 / 25
Motivating Example
Collapse redundant nodes
Manas Thakur (IIT Madras) BDDs 5 / 25
Motivating Example
Collapse redundant nodes
Manas Thakur (IIT Madras) BDDs 6 / 25
Motivating Example
Collapse redundant nodes
Manas Thakur (IIT Madras) BDDs 7 / 25
Motivating Example
Eliminate unnecessary nodes
Manas Thakur (IIT Madras) BDDs 8 / 25
Motivating Example
We got an ROBDD!!
Manas Thakur (IIT Madras) BDDs 9 / 25
Introduction
Overview
1 Motivating Example
2 Introduction
3 Constructing ROBDDs
4 Applications
5 Conclusion
Manas Thakur (IIT Madras) BDDs 10 / 25
Introduction
Binary Decision Diagrams
Definition
A Binary Decision Diagram is a rooted DAG with
One or two terminal nodes of out-degree zero labeled 0 or 1
A set of variable nodes of out-degree two
Manas Thakur (IIT Madras) BDDs 11 / 25
Introduction
Ordered Binary Decision Diagrams (OBDDs)
A BDD is ordered if on all paths through the graph, the variablesrespect a given linear order.
b1 < b2 < ... < bn
An unordered BDD
Manas Thakur (IIT Madras) BDDs 12 / 25
Introduction
Ordered Binary Decision Diagrams (OBDDs)
A BDD is ordered if on all paths through the graph, the variablesrespect a given linear order.
b1 < b2 < ... < bn
An unordered BDD
Manas Thakur (IIT Madras) BDDs 12 / 25
Introduction
Ordered Binary Decision Diagrams (OBDDs)
The size of a BDD depends on the variable ordering
The problem of finding the best variable ordering in OBDDs isNP-Complete
Manas Thakur (IIT Madras) BDDs 13 / 25
Introduction
Reduced Ordered Binary Decision Diagrams (ROBDDs)
Definition
An OBDD is reduced if it satisfies the following properties:
Uniqueness
low(u) = low(v) and high(u) = high(v) implies u = v
Non-redundant tests
low(u) 6= high(u)
We already saw an example of ROBDDs!! See it again
Manas Thakur (IIT Madras) BDDs 14 / 25
Introduction
Properties of ROBDDs
Size is correlated to amount of redundancy, NOT size of relation
Insight: As the relation gets larger, the number of dont-care bitsincreases, leading to fewer necessary nodes (usually)
Canonicity: For every Boolean function, there is exactly one ROBDDrepresenting it
Hence, satisfiability, tautology-check, and equivalence can be tested indeterministic timeFor Boolean expressions, this problem is NP-Complete
Manas Thakur (IIT Madras) BDDs 15 / 25
Constructing ROBDDs
Normal forms for Boolean expressions
Disjunctive Normal Form (DNF)
(a1 ∧ a2 ∧ ... ∧ an) ∨ ... ∨ (a1 ∧ a2 ∧ ... ∧ an)Satisfiability: easy; Tautology check: hard
Conjunctive Normal Form (CNF)
(a1 ∨ a2 ∨ ... ∨ an) ∧ ... ∧ (a1 ∨ a2 ∨ ... ∨ an)Tautology check: easy; Satisfiability: hard
Reduction?
No hopes since conversion between CNF and DNF is exponential
Manas Thakur (IIT Madras) BDDs 16 / 25
Constructing ROBDDs
Normal forms for Boolean expressions
Disjunctive Normal Form (DNF)
(a1 ∧ a2 ∧ ... ∧ an) ∨ ... ∨ (a1 ∧ a2 ∧ ... ∧ an)Satisfiability: easy; Tautology check: hard
Conjunctive Normal Form (CNF)
(a1 ∨ a2 ∨ ... ∨ an) ∧ ... ∧ (a1 ∨ a2 ∨ ... ∨ an)Tautology check: easy; Satisfiability: hard
Reduction?
No hopes since conversion between CNF and DNF is exponential
Manas Thakur (IIT Madras) BDDs 16 / 25
Constructing ROBDDs
Normal forms for Boolean expressions
Disjunctive Normal Form (DNF)
(a1 ∧ a2 ∧ ... ∧ an) ∨ ... ∨ (a1 ∧ a2 ∧ ... ∧ an)Satisfiability: easy; Tautology check: hard
Conjunctive Normal Form (CNF)
(a1 ∨ a2 ∨ ... ∨ an) ∧ ... ∧ (a1 ∨ a2 ∨ ... ∨ an)Tautology check: easy; Satisfiability: hard
Reduction?
No hopes since conversion between CNF and DNF is exponential
Manas Thakur (IIT Madras) BDDs 16 / 25
Constructing ROBDDs
Normal forms for Boolean expressions
Disjunctive Normal Form (DNF)
(a1 ∧ a2 ∧ ... ∧ an) ∨ ... ∨ (a1 ∧ a2 ∧ ... ∧ an)Satisfiability: easy; Tautology check: hard
Conjunctive Normal Form (CNF)
(a1 ∨ a2 ∨ ... ∨ an) ∧ ... ∧ (a1 ∨ a2 ∨ ... ∨ an)Tautology check: easy; Satisfiability: hard
Reduction?
No hopes since conversion between CNF and DNF is exponential
Manas Thakur (IIT Madras) BDDs 16 / 25
Constructing ROBDDs
If-then-else Normal Form (INF)
An If-then-else Normal Form (INF) is a Boolean expression built fromthe if-then-else operator and the constants 0 and 1, such that all testsare performed only on variables.
x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1)
More examples
x = x → (1, 0)¬x = (x → 0, 1)
x ∨ y = (x → 1, y)x ∧ y = (x → y , 1)
x ⇔ y = x → (y → 1, 0), (y → 0, 1)
Manas Thakur (IIT Madras) BDDs 17 / 25
Constructing ROBDDs
If-then-else Normal Form (INF)
An If-then-else Normal Form (INF) is a Boolean expression built fromthe if-then-else operator and the constants 0 and 1, such that all testsare performed only on variables.
x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1)
More examples
x = x → (1, 0)
¬x = (x → 0, 1)x ∨ y = (x → 1, y)x ∧ y = (x → y , 1)
x ⇔ y = x → (y → 1, 0), (y → 0, 1)
Manas Thakur (IIT Madras) BDDs 17 / 25
Constructing ROBDDs
If-then-else Normal Form (INF)
An If-then-else Normal Form (INF) is a Boolean expression built fromthe if-then-else operator and the constants 0 and 1, such that all testsare performed only on variables.
x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1)
More examples
x = x → (1, 0)¬x = (x → 0, 1)
x ∨ y = (x → 1, y)x ∧ y = (x → y , 1)
x ⇔ y = x → (y → 1, 0), (y → 0, 1)
Manas Thakur (IIT Madras) BDDs 17 / 25
Constructing ROBDDs
If-then-else Normal Form (INF)
An If-then-else Normal Form (INF) is a Boolean expression built fromthe if-then-else operator and the constants 0 and 1, such that all testsare performed only on variables.
x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1)
More examples
x = x → (1, 0)¬x = (x → 0, 1)
x ∨ y = (x → 1, y)
x ∧ y = (x → y , 1)x ⇔ y = x → (y → 1, 0), (y → 0, 1)
Manas Thakur (IIT Madras) BDDs 17 / 25
Constructing ROBDDs
If-then-else Normal Form (INF)
An If-then-else Normal Form (INF) is a Boolean expression built fromthe if-then-else operator and the constants 0 and 1, such that all testsare performed only on variables.
x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1)
More examples
x = x → (1, 0)¬x = (x → 0, 1)
x ∨ y = (x → 1, y)x ∧ y = (x → y , 1)
x ⇔ y = x → (y → 1, 0), (y → 0, 1)
Manas Thakur (IIT Madras) BDDs 17 / 25
Constructing ROBDDs
If-then-else Normal Form (INF)
An If-then-else Normal Form (INF) is a Boolean expression built fromthe if-then-else operator and the constants 0 and 1, such that all testsare performed only on variables.
x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1)
More examples
x = x → (1, 0)¬x = (x → 0, 1)
x ∨ y = (x → 1, y)x ∧ y = (x → y , 1)
x ⇔ y = x → (y → 1, 0), (y → 0, 1)
Manas Thakur (IIT Madras) BDDs 17 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0
t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00
t1 = y1 → t11, 0t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000
t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110
t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1
t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0
t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1
t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 18 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t00, 0
t00 = x2 → t001, t000t000 = y2 → 0, 1t001 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 19 / 25
Constructing ROBDDs
Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t11, 0
t00 = x2 → t001, t000t11 = x2 → t111, t110t000 = y2 → 0, 1t001 = y2 → 1, 0t110 = y2 → 0, 1t111 = y2 → 1, 0
t = x1 → t1, t0t0 = y1 → 0, t00t1 = y1 → t00, 0
t00 = x2 → t001, t000t000 = y2 → 0, 1t001 = y2 → 1, 0
Manas Thakur (IIT Madras) BDDs 19 / 25
Applications
Let’s move ahead
1 Motivating Example
2 Introduction
3 Constructing ROBDDs
4 Applications
5 Conclusion
Manas Thakur (IIT Madras) BDDs 20 / 25
Applications
Applications of BDDs
Correctness of Combinational Circuits
Equivalence of Combinational Circuits
Model Checking
And yes, Program Analysis!
Manas Thakur (IIT Madras) BDDs 21 / 25
Applications
BDDs for representing Points-to relation
Points-to analysis using BDDs. Berndl et al. PLDI’03.
Let a,b,c be reference variables and A,B,C be object references.
The points-to relation (a,A),(a,B),(b,A),(b,B),(c,A),(c,B),(c,C) isrepresented as:
On the board.
Manas Thakur (IIT Madras) BDDs 22 / 25
Applications
BDDs for representing Points-to relation
Points-to analysis using BDDs. Berndl et al. PLDI’03.
Let a,b,c be reference variables and A,B,C be object references.
The points-to relation (a,A),(a,B),(b,A),(b,B),(c,A),(c,B),(c,C) isrepresented as:
On the board.
Manas Thakur (IIT Madras) BDDs 22 / 25
Applications
bddbddb
Cloning-Based Context-Sensitive Pointer Alias Analysis Using BinaryDecision Diagrams. John Whaley and Monica S. Lam. PLDI’04.
On the Board
1 Represent program information using relationsExpress relations as BDDs
2 Write program analyses as Datalog queriesExpress queries as BDD operations
3 Get solutions!Perform operations on BDDs
Manas Thakur (IIT Madras) BDDs 23 / 25
Applications
bddbddb
Cloning-Based Context-Sensitive Pointer Alias Analysis Using BinaryDecision Diagrams. John Whaley and Monica S. Lam. PLDI’04.
On the Board
1 Represent program information using relationsExpress relations as BDDs
2 Write program analyses as Datalog queriesExpress queries as BDD operations
3 Get solutions!Perform operations on BDDs
Manas Thakur (IIT Madras) BDDs 23 / 25
Applications
bddbddb
Cloning-Based Context-Sensitive Pointer Alias Analysis Using BinaryDecision Diagrams. John Whaley and Monica S. Lam. PLDI’04.
On the Board
1 Represent program information using relationsExpress relations as BDDs
2 Write program analyses as Datalog queriesExpress queries as BDD operations
3 Get solutions!Perform operations on BDDs
Manas Thakur (IIT Madras) BDDs 23 / 25
Applications
bddbddb
Cloning-Based Context-Sensitive Pointer Alias Analysis Using BinaryDecision Diagrams. John Whaley and Monica S. Lam. PLDI’04.
On the Board
1 Represent program information using relationsExpress relations as BDDs
2 Write program analyses as Datalog queriesExpress queries as BDD operations
3 Get solutions!Perform operations on BDDs
Manas Thakur (IIT Madras) BDDs 23 / 25
Applications
Pointers for the enthusiast
An Introduction to Binary Decision Diagrams. Tutorial by Henrik ReifAndersen.
Program Analysis using Binary Decision Diagrams. Ondrej Lhotak’sPhD Thesis (2006).
Context-Sensitive Pointer Analysis using Binary Decision Diagrams.John Whaley’s PhD Thesis (2007).
Fun with Binary Decision Diagrams. Video lecture by Donald Knuth.
Manas Thakur (IIT Madras) BDDs 24 / 25
Conclusion
Conclusion
BDDs are very interesting anduseful!
Manas Thakur (IIT Madras) BDDs 25 / 25
Conclusion
Conclusion
BDDs are very interesting anduseful!
Manas Thakur (IIT Madras) BDDs 25 / 25