<<

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 for a

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 of variable nodes of out-degree two

Manas Thakur (IIT Madras) BDDs 11 / 25 An unordered BDD

Introduction Ordered Binary Decision Diagrams (OBDDs)

A BDD is ordered if on all paths through the graph, the variables respect a given linear order.

b1 < b2 < ... < bn

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 variables respect 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 is NP-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 bits increases, leading to fewer necessary nodes (usually)

Canonicity: For every , there is exactly one ROBDD representing it Hence, satisfiability, -check, and equivalence can be tested in deterministic time For Boolean expressions, this problem is NP-Complete

Manas Thakur (IIT Madras) BDDs 15 / 25 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

Constructing ROBDDs Normal forms for Boolean expressions

Disjunctive Normal Form (DNF)

(a1 ∧ a2 ∧ ... ∧ an) ∨ ... ∨ (a1 ∧ a2 ∧ ... ∧ an) Satisfiability: easy; Tautology check: hard

Manas Thakur (IIT Madras) BDDs 16 / 25 Reduction? No hopes since conversion between CNF and DNF is exponential

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

Manas Thakur (IIT Madras) BDDs 16 / 25 No hopes since conversion between CNF and DNF is exponential

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?

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 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)

Constructing ROBDDs If-then-else Normal Form (INF)

An If-then-else Normal Form (INF) is a Boolean expression built from the if-then-else operator and the constants 0 and 1, such that all tests are performed only on variables.

x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1)

Manas Thakur (IIT Madras) BDDs 17 / 25 ¬x = (x → 0, 1) x ∨ y = (x → 1, y) x ∧ y = (x → y, 1) x ⇔ y = x → (y → 1, 0), (y → 0, 1)

Constructing ROBDDs If-then-else Normal Form (INF)

An If-then-else Normal Form (INF) is a Boolean expression built from the if-then-else operator and the constants 0 and 1, such that all tests are performed only on variables.

x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1) More examples x = x → (1, 0)

Manas Thakur (IIT Madras) BDDs 17 / 25 x ∨ y = (x → 1, y) x ∧ y = (x → y, 1) x ⇔ y = x → (y → 1, 0), (y → 0, 1)

Constructing ROBDDs If-then-else Normal Form (INF)

An If-then-else Normal Form (INF) is a Boolean expression built from the if-then-else operator and the constants 0 and 1, such that all tests are performed only on variables.

x → y0, y1 = (x ∧ y0) ∨ (¬x ∧ y1) More examples x = x → (1, 0) ¬x = (x → 0, 1)

Manas Thakur (IIT Madras) BDDs 17 / 25 x ∧ y = (x → y, 1) x ⇔ y = x → (y → 1, 0), (y → 0, 1)

Constructing ROBDDs If-then-else Normal Form (INF)

An If-then-else Normal Form (INF) is a Boolean expression built from the if-then-else operator and the constants 0 and 1, such that all tests are 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)

Manas Thakur (IIT Madras) BDDs 17 / 25 x ⇔ y = x → (y → 1, 0), (y → 0, 1)

Constructing ROBDDs If-then-else Normal Form (INF)

An If-then-else Normal Form (INF) is a Boolean expression built from the if-then-else operator and the constants 0 and 1, such that all tests are 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)

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 from the if-then-else operator and the constants 0 and 1, such that all tests are 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 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0

Manas Thakur (IIT Madras) BDDs 18 / 25 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00

Manas Thakur (IIT Madras) BDDs 18 / 25 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0

Manas Thakur (IIT Madras) BDDs 18 / 25 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000

Manas Thakur (IIT Madras) BDDs 18 / 25 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110

Manas Thakur (IIT Madras) BDDs 18 / 25 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1

Manas Thakur (IIT Madras) BDDs 18 / 25 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0

Manas Thakur (IIT Madras) BDDs 18 / 25 t111 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1

Manas Thakur (IIT Madras) BDDs 18 / 25 Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = 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, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Manas Thakur (IIT Madras) BDDs 18 / 25 t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t00, 0 t00 = x2 → t001, t000 t000 = y2 → 0, 1 t001 = y2 → 1, 0

Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t1 = y1 → t11, 0 t00 = x2 → t001, t000 t11 = x2 → t111, t110 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = y2 → 1, 0

Manas Thakur (IIT Madras) BDDs 19 / 25 Constructing ROBDDs

Example: t = (x1 ⇔ y1) ∧ (x2 ⇔ y2)

t = x1 → t1, t0 t0 = y1 → 0, t00 t = x1 → t1, t0 t1 = y1 → t11, 0 t0 = y1 → 0, t00 t00 = x2 → t001, t000 t1 = y1 → t00, 0 t11 = x2 → t111, t110 t00 = x2 → t001, t000 t000 = y2 → 0, 1 t000 = y2 → 0, 1 t001 = y2 → 1, 0 t001 = y2 → 1, 0 t110 = y2 → 0, 1 t111 = 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 On the board.

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) is represented as:

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) is represented as: On the board.

Manas Thakur (IIT Madras) BDDs 22 / 25 On the Board 1 Represent program information using relations Express relations as BDDs

2 Write program analyses as Datalog queries Express queries as BDD operations

3 Get solutions! Perform operations on BDDs

Applications bddbddb

Cloning-Based Context-Sensitive Pointer Alias Analysis Using Binary Decision Diagrams. John Whaley and Monica S. Lam. PLDI’04.

Manas Thakur (IIT Madras) BDDs 23 / 25 2 Write program analyses as Datalog queries Express queries as BDD operations

3 Get solutions! Perform operations on BDDs

Applications bddbddb

Cloning-Based Context-Sensitive Pointer Alias Analysis Using Binary Decision Diagrams. John Whaley and Monica S. Lam. PLDI’04.

On the Board 1 Represent program information using relations Express relations as BDDs

Manas Thakur (IIT Madras) BDDs 23 / 25 3 Get solutions! Perform operations on BDDs

Applications bddbddb

Cloning-Based Context-Sensitive Pointer Alias Analysis Using Binary Decision Diagrams. John Whaley and Monica S. Lam. PLDI’04.

On the Board 1 Represent program information using relations Express relations as BDDs

2 Write program analyses as Datalog queries Express queries as BDD operations

Manas Thakur (IIT Madras) BDDs 23 / 25 Applications bddbddb

Cloning-Based Context-Sensitive Pointer Alias Analysis Using Binary Decision Diagrams. John Whaley and Monica S. Lam. PLDI’04.

On the Board 1 Represent program information using relations Express relations as BDDs

2 Write program analyses as Datalog queries Express 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 Reif Andersen.

Program Analysis using Binary Decision Diagrams. Ondrej Lhotak’s PhD 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 BDDs are very interesting and useful!

Conclusion Conclusion

Manas Thakur (IIT Madras) BDDs 25 / 25 Conclusion Conclusion

BDDs are very interesting and useful!

Manas Thakur (IIT Madras) BDDs 25 / 25