binary decision diagrams part 1

53
© 2011 Carnegie Mellon University Binary Decision Diagrams Part 1 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September 12, 2011

Upload: bishop

Post on 22-Feb-2016

84 views

Category:

Documents


5 download

DESCRIPTION

Binary Decision Diagrams Part 1. 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September 12, 2011. BDDs in a nutshell. Typically mean Reduced Ordered Binary Decision Diagrams (ROBDDs) Canonical representation of Boolean formulas - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Binary  Decision  Diagrams Part 1

© 2011 Carnegie Mellon University

Binary Decision Diagrams Part 1

15-414 Bug Catching: Automated Program Verification and Testing

Sagar ChakiSeptember 12, 2011

Page 2: Binary  Decision  Diagrams Part 1

2Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

BDDs in a nutshell

Typically mean Reduced Ordered Binary Decision Diagrams (ROBDDs)

Canonical representation of Boolean formulas

Often substantially more compact than a traditional normal form

Can be manipulated very efficiently• Conjunction, Disjunction, Negation, Existential Quantification

R. E. Bryant. Graph-based algorithms for boolean function manipulation. IEEE Transactions on Computers, C-35(8), 1986.

Page 3: Binary  Decision  Diagrams Part 1

3Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Running Example: Comparator

Comparator

a1 a2 b1 b2

f = 1 , a1 = b1 Æ a2 = b2

Page 4: Binary  Decision  Diagrams Part 1

4Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Conjunctive Normal Form

(: a1 Ç b1 ) Æ (: b1 Ç a1) Æ (: a2 Ç b2 ) Æ (: b2 Ç a2)

a1 = b1 Æ a2 = b2

a1 ) b1 Æ b1 ) a1 Æ a2 ) b2 Æ b2 ) a2

(: b1 Ç a1 ) Æ (: a1 Ç b1) Æ (: a2 Ç b2 ) Æ (: b2 Ç a2)

Not Canonical

f

Page 5: Binary  Decision  Diagrams Part 1

5Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Truth Table (1)a1 b1 a2 b2 f

0 0 0 0 1

0 0 0 1 0

0 0 1 0 0

0 0 1 1 1

0 1 0 0 0

0 1 0 1 0

0 1 1 0 0

0 1 1 1 0

1 0 0 0 0

1 0 0 1 0

1 0 1 0 0

1 0 1 1 0

1 1 0 0 1

1 1 0 1 0

1 1 1 0 0

1 1 1 1 1

Still Not Canonical

Page 6: Binary  Decision  Diagrams Part 1

6Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Truth Table (2)a1 a2 b1 b2 f

0 0 0 0 1

0 0 0 1 0

0 0 1 0 0

0 0 1 1 0

0 1 0 0 0

0 1 0 1 1

0 1 1 0 0

0 1 1 1 0

1 0 0 0 0

1 0 0 1 0

1 0 1 0 1

1 0 1 1 0

1 1 0 0 0

1 1 0 1 0

1 1 1 0 0

1 1 1 1 1

Canonical if you fix variable order.

But always exponential in # of variables. Let’s try to fix this.

Page 7: Binary  Decision  Diagrams Part 1

7Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Representing a Truth Table using a Graph

a1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0 0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

0

0

0

0 1

1

10

Binary Decision Tree (in this case ordered)

Page 8: Binary  Decision  Diagrams Part 1

8Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Binary Decision Tree: Formal Definition

Balanced binary tree. Length of each path = # of variables

Leaf nodes labeled with either 0 or 1

Internal node v labeled with a Boolean variable var(v)• Every node on a path labeled with a different variable

Internal node v has two children: low(v) and high(v)

Each path corresponds to a (partial) truth assignment to variables• Assign 0 to var(v) if low(v) is in the path, and 1 if high(v) is in the path

Value of a leaf is determined by:• Constructing the truth assignment for the path leading to it from the root• Looking up the truth table with this truth assignment

Page 9: Binary  Decision  Diagrams Part 1

9Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Binary Decision Tree

a1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0 0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

0

0

0

0 1

1

10

v

low(v)high(v)

var(v) = a1

Page 10: Binary  Decision  Diagrams Part 1

10Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Binary Decision Tree

a1

b1

a2

b2

0

0

1

0

The truth assignment corresponding to the path to this leaf is:a1 = ? b1 = ? a2 = ? b2 = ?

Page 11: Binary  Decision  Diagrams Part 1

11Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Binary Decision Tree

a1

b1

a2

b2

0

0

1

0

The truth assignment corresponding to the path to this leaf is:a1 = 0 b1 = 0 a2 = 1 b2 = 0

a1 b1 a2 b2 f

0 0 0 0 1

0 0 0 1 0

0 0 1 0 0

0 0 1 1 1

0 1 0 0 0

0 1 0 1 0

0 1 1 0 0

0 1 1 1 0

1 0 0 0 0

1 0 0 1 0

1 0 1 0 0

1 0 1 1 0

1 1 0 0 1

1 1 0 1 0

1 1 1 0 0

1 1 1 1 1

Page 12: Binary  Decision  Diagrams Part 1

12Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Binary Decision Tree

a1

b1

a2

b2

0

0

1

0

The truth assignment corresponding to the path to this leaf is:a1 = 0 b1 = 0 a2 = 1 b2 = 0

a1 b1 a2 b2 f

0 0 0 0 1

0 0 0 1 0

0 0 1 0 0

0 0 1 1 1

0 1 0 0 0

0 1 0 1 0

0 1 1 0 0

0 1 1 1 0

1 0 0 0 0

1 0 0 1 0

1 0 1 0 0

1 0 1 1 0

1 1 0 0 1

1 1 0 1 0

1 1 1 0 0

1 1 1 1 1

Page 13: Binary  Decision  Diagrams Part 1

13Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Binary Decision Tree

a1

b1

a2

b2

0

0

0

1

0

The truth assignment corresponding to the path to this leaf is:a1 = 0 b1 = 0 a2 = 1 b2 = 0

a1 b1 a2 b2 f

0 0 0 0 1

0 0 0 1 0

0 0 1 0 0

0 0 1 1 1

0 1 0 0 0

0 1 0 1 0

0 1 1 0 0

0 1 1 1 0

1 0 0 0 0

1 0 0 1 0

1 0 1 0 0

1 0 1 1 0

1 1 0 0 1

1 1 0 1 0

1 1 1 0 0

1 1 1 1 1

Page 14: Binary  Decision  Diagrams Part 1

14Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Binary Decision Tree (BDT)

a1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0 0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

0

0

0

0 1

1

10

Canonical if you fix variable order (i.e., use ordered BDT)

But still exponential in # of variables. Let’s try to fix this.

Page 15: Binary  Decision  Diagrams Part 1

15Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Reduced Ordered BDD

Conceptually, a ROBDD is obtained from an ordered BDT (OBDT) by eliminating redundant sub-diagrams and nodes

Start with OBDT and repeatedly apply the following two operations as long as possible:

1. Eliminate duplicate sub-diagrams. Keep a single copy. Redirect edges into the eliminated duplicates into this single copy.

2. Eliminate redundant nodes. Whenever low(v) = high(v), remove v and redirect edges into v to low(v).

• Why does this terminate?

ROBDD is often exponentially smaller than the corresponding OBDT

Page 16: Binary  Decision  Diagrams Part 1

16Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0 0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

Page 17: Binary  Decision  Diagrams Part 1

17Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0 0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

Duplicate sub-diagram

Page 18: Binary  Decision  Diagrams Part 1

18Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

Page 19: Binary  Decision  Diagrams Part 1

19Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

Page 20: Binary  Decision  Diagrams Part 1

20Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

Page 21: Binary  Decision  Diagrams Part 1

21Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0 0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

Page 22: Binary  Decision  Diagrams Part 1

22Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1 0 0 1

b2 b2

0

a2 a2

b2 b2

0 0 0 0

b2 b2

1 0 0 1

Page 23: Binary  Decision  Diagrams Part 1

23Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1

b2 b2

0

a2 a2

b2 b2 b2 b2

Page 24: Binary  Decision  Diagrams Part 1

24Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1

b2 b2

0

a2 a2

b2 b2 b2 b2

Redundant node

Page 25: Binary  Decision  Diagrams Part 1

25Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1

b2

0

a2 a2

b2 b2 b2 b2

Page 26: Binary  Decision  Diagrams Part 1

26Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

1

b2

0

a2 a2

b2 b2 b2 b2

Page 27: Binary  Decision  Diagrams Part 1

27Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

10

a2 a2

b2 b2 b2 b2

Page 28: Binary  Decision  Diagrams Part 1

28Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2 a2

b2 b2

10

a2 a2

b2 b2 b2 b2

Page 29: Binary  Decision  Diagrams Part 1

29Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2

b2 b2

10

a2 a2

b2 b2 b2 b2

If a1 = 0 and b1 = 1 then f = 0 irrespective of the values of a2

and b2

Page 30: Binary  Decision  Diagrams Part 1

30Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2

b2 b2

10

a2

b2 b2

Page 31: Binary  Decision  Diagrams Part 1

31Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2

b2 b2

10

a2

b2 b2

Page 32: Binary  Decision  Diagrams Part 1

32Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2

b2

10

a2

b2 b2

Page 33: Binary  Decision  Diagrams Part 1

33Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2

b2

10

a2

b2 b2

Page 34: Binary  Decision  Diagrams Part 1

34Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2

b2

10

a2

b2

Page 35: Binary  Decision  Diagrams Part 1

35Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

a2

b2

10

a2

b2

Page 36: Binary  Decision  Diagrams Part 1

36Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

b2

10

a2

b2

Let’s move things around a little bit so that the BDD looks

nicer.

Page 37: Binary  Decision  Diagrams Part 1

37Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

OBDT to ROBDDa1

b1 b1

b2

10

a2

b2

Bryant gave a linear-time algorithm (called Reduce) to convert OBDT to ROBDD.

In practice, BDD packages don’t use Reduce directly. They apply the two reductions on-the-fly as new BDDs are constructed from existing ones. Why?

Page 38: Binary  Decision  Diagrams Part 1

38Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD (a.k.a. BDD) Summary

BDDs are canonical representations of Boolean formulas• f1 = f2 , ?

Page 39: Binary  Decision  Diagrams Part 1

39Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD (a.k.a. BDD) Summary

BDDs are canonical representations of Boolean formulas• f1 = f2 , BDD(f1) and BDD(f2) are isomorphic• f is unsatisfiable , ?

Page 40: Binary  Decision  Diagrams Part 1

40Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD (a.k.a. BDD) Summary

BDDs are canonical representations of Boolean formulas• f1 = f2 , BDD(f1) and BDD(f2) are isomorphic• f is unsatisfiable , BDD(f) is the leaf node “0”• f is valid , ?

Page 41: Binary  Decision  Diagrams Part 1

41Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD (a.k.a. BDD) Summary

BDDs are canonical representations of Boolean formulas• f1 = f2 , BDD(f1) and BDD(f2) are isomorphic• f is unsatisfiable , BDD(f) is the leaf node “0”• f is valid , BDD(f) is the leaf node “1”• BDD packages do these operations in constant time

Logical operations can be performed efficiently on BDDs• Polynomial in argument size• More details in next lecture

BDD size depends critically on the variable ordering• Some formulas have exponentially large sizes for all ordering• Others are polynomial for some ordering and exponential for others

Page 42: Binary  Decision  Diagrams Part 1

42Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2 b2

1 0 0 0

b2 b2

0 1 0 0

b1 b1

b2 b2

0 0 1 0

b2 b2

0 0 0 1

Page 43: Binary  Decision  Diagrams Part 1

43Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2 b2 b2 b2

1 0

b1 b1

b2 b2 b2 b2

Page 44: Binary  Decision  Diagrams Part 1

44Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2 b2

1 0

b1 b1

b2 b2

Page 45: Binary  Decision  Diagrams Part 1

45Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2 b2

1 0

b1 b1

b2 b2

Page 46: Binary  Decision  Diagrams Part 1

46Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2

1 0

b1 b1

b2 b2

Page 47: Binary  Decision  Diagrams Part 1

47Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2

1 0

b1 b1

b2 b2

Page 48: Binary  Decision  Diagrams Part 1

48Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2

1 0

b1 b1

b2

Let’s move things around a little bit so that the BDD looks

nicer.

Page 49: Binary  Decision  Diagrams Part 1

49Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

a2 a2

b1 b1

b2

1 0

b1 b1

b2

a1

b1 b1

b2

10

a2

b2

11 nodes8 nodes

a1 < a2 < b1 < b2a1 < b1 < a2 < b2

Page 50: Binary  Decision  Diagrams Part 1

50Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

an an

b1 b1

bn

1 0

b1 b1

bn

a1

b1 b1

bn

10

an

bn

? £ 2n – 1 nodes

? £ n + 2 nodes

a1 < … < an < b1 < … < bna1 < b1 < … < an < bn

Page 51: Binary  Decision  Diagrams Part 1

51Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

ROBDD and variable orderinga1

an an

b1 b1

bn

1 0

b1 b1

bn

a1

b1 b1

bn

10

an

bn

3 £ 2n – 1 nodes

3 £ n + 2 nodes

a1 < … < an < b1 < … < bna1 < b1 < … < an < bn

Page 52: Binary  Decision  Diagrams Part 1

52Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Next Class

BDD recap

BDD operations

BDD applications

Next homework

See you then …

Page 53: Binary  Decision  Diagrams Part 1

53Binary Decision Diagrams – Part 1Sagar Chaki, Sep 12, 2011© 2011 Carnegie Mellon University

Questions?

Sagar ChakiSenior Member of Technical StaffRTSS ProgramTelephone: +1 412-268-1436Email: [email protected]

U.S. MailSoftware Engineering InstituteCustomer Relations4500 Fifth AvenuePittsburgh, PA 15213-2612USA

Webwww.sei.cmu.edu/staff/chaki

Customer RelationsEmail: [email protected]: +1 412-268-5800SEI Phone: +1 412-268-5800SEI Fax: +1 412-268-6257