binary decision diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · binary decision...

47
Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South Florida Tampa, FL 33620 Email: [email protected] Phone: (813)974-4757 Fax: (813)974-5456 Hao Zheng (CSE, USF) Comp Sys Verification 1 / 44

Upload: others

Post on 15-Aug-2020

14 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Binary Decision Diagrams

Hao Zheng

Department of Computer Science and EngineeringUniversity of South Florida

Tampa, FL 33620Email: [email protected]: (813)974-4757Fax: (813)974-5456

Hao Zheng (CSE, USF) Comp Sys Verification 1 / 44

Page 2: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

1 Binary Decision Tree

2 Ordered Binary Decision Diagram

3 From BDT to BDDs

4 Variable Ordering

5 Logic Operations by BDDs

Hao Zheng (CSE, USF) Comp Sys Verification 2 / 44

Page 3: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Binary Decision Diagrams

• Binary decision diagrams (BDDs) are graphs representing Booleanfunctions.

• They can be made canonical.

• They can be very compact for many applications.

• They are important since many applications can be converted tosequences of Boolean operations.

• References:• R. Bryant, Graph-Based Algorithms for Boolean Function Manipulation,

IEEE Transactions on Computers, 1986.• R. Bryant Symbolic Boolean Manipulation with Ordered Binary Decision

Diagrams, ACM Computing Surveys, 1992.• Textbook, 6.7.3− 6.7.4

Hao Zheng (CSE, USF) Comp Sys Verification 3 / 44

Page 4: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Representing Switching Functions

• Truth Tables• Satisfiability and equivalence check: easy; boolean operations also easy.• Very space inefficient: 2n entries for n variables.

• Disjunctive Normal Form (DNF)• Satisfiability is easy: find a disjunct without complementary literals.• Negation and conjunction complicated.

• Conjunctive Normal Form (CNF)• Satisfiability problem is NP-complete (Cook’s theorem).• Negation and disjunction complicated.

Hao Zheng (CSE, USF) Comp Sys Verification 4 / 44

Page 5: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Representing Switching Functions

representation compact? sat equ ∧ ∨ ¬truth table never hard hard hard hard hard

DNF sometimes easy hard hard easy hard

CNF sometimes hard hard easy hard hard

propositionalformula often hard hard easy easy easy

reduced orderedbinary decision diagram often easy easy∗ medium medium easy

∗ Provided appropriate implementation techniques are used.

Hao Zheng (CSE, USF) Comp Sys Verification 5 / 44

Page 6: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Symbolic Encoding: An ExampleExample Symbolic Representation of a Transition System

/0 s0 s1

s3 s2

a

ba,b

Switching function: (x1,x2| z s

,x 01,x02| z

s0

) = 1 if and only if s! s0

(x1,x2,x 01,x02) = (¬x1 ^ ¬x2 ^ ¬x 01 ^ x 02)

_ (¬x1 ^ ¬x2 ^ x 01 ^ x 02)_ (¬x1 ^ x2 ^ x 01 ^ ¬x 02)_ . . ._ (x1 ^ x2 ^ x 01 ^ x 02)

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 100 / 155

Switching function: ∆(x1, x2︸ ︷︷ ︸s

, x′1, x′2︸ ︷︷ ︸

s′

) = 1 if and only if s→ s′

∆(x1, x2, x′1, x′2) = (¬x1 ∧ ¬x2 ∧ ¬x′1 ∧ x′2)

∨ (¬x1 ∧ ¬x2 ∧ x′1 ∧ x′2)∨ (¬x1 ∧ x2 ∧ x′1 ∧ ¬x′2)∨ . . .∨ (x1 ∧ x2 ∧ x′1 ∧ x′2)

Hao Zheng (CSE, USF) Comp Sys Verification 6 / 44

Page 7: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Contents

1 Binary Decision Tree

2 Ordered Binary Decision Diagram

3 From BDT to BDDs

4 Variable Ordering

5 Logic Operations by BDDs

Hao Zheng (CSE, USF) Comp Sys Verification 7 / 44

Page 8: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Binary Decision Tree: ExampleTransition Relation as a BDT

x 02

1 0 1 0 1 1 0 0 1 1 1 01 1 10

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02 x 02

x 01

x2

x 02

A BDT representing for our example using ordering x1 < x2 < x 01 < x 02.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 110 / 155

• The BDT for function f on ~x = x1, . . . , xn has depth n.

• Every node is labeled with a variable.• Every node labeled with xi has two outgoing edges.

• 0-edge: xi = 0 (dashed) and,• 1-edge: xi = 1 (solid).

Hao Zheng (CSE, USF) Comp Sys Verification 8 / 44

Page 9: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Binary Decision Tree: ExampleTransition Relation as a BDT

x 02

1 0 1 0 1 1 0 0 1 1 1 01 1 10

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02 x 02

x 01

x2

x 02

A BDT representing for our example using ordering x1 < x2 < x 01 < x 02.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 110 / 155

• Every non-terminal node n has two successor nodes.• low(n): the node at the end of the 0-edge of node n.• high(n): the node at the end of the 1-edge of node n.

Hao Zheng (CSE, USF) Comp Sys Verification 8 / 44

Page 10: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Binary Decision Tree: ExampleTransition Relation as a BDT

x 02

1 0 1 0 1 1 0 0 1 1 1 01 1 10

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02 x 02

x 01

x2

x 02

A BDT representing for our example using ordering x1 < x2 < x 01 < x 02.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 110 / 155

• The edge labelings of a path from the root to a terminal is anevaluation s = [x1 = b1, . . . , xm = bm], where bi ∈ 0, 1.

• The labeling of the terminal node is the output of f(s).

Hao Zheng (CSE, USF) Comp Sys Verification 8 / 44

Page 11: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Binary Decision Tree: ExampleTransition Relation as a BDT

x 02

1 0 1 0 1 1 0 0 1 1 1 01 1 10

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02 x 02

x 01

x2

x 02

A BDT representing for our example using ordering x1 < x2 < x 01 < x 02.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 110 / 155

The subtree of node v at level i for variable ordering x1 < . . . < xnrepresents:

fv = f |x1=b1,...,xi−1=bi−1

which is a switching function over xi, . . . , xn and where x1 = b1, . . . ,xi−1 = bi−1 are the decisions made along the path from root to node v.

Hao Zheng (CSE, USF) Comp Sys Verification 8 / 44

Page 12: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Binary Decision Tree

• The BDT for function f on Var = z1, . . . , zm has depth m withoutgoing edges for node at level i stand for zi = 0 (dashed) and zi = 1(solid).

• For evaluation s = [z1 = b1, . . . , zm = bm], f(s) is the value of the leafreached by traversing the BDT from the root using branch zi = bi.

• The subtree of node v at level i for variable ordering z1 < . . . < zmrepresents:

fv = f |z1=b1,...,zi−1=bi−1

which is a switching function over zi, . . . , zm and where z1 = b1, . . . ,zi−1 = bi−1 are the decisions made along the path from root to node v.

Hao Zheng (CSE, USF) Comp Sys Verification 9 / 44

Page 13: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Considerations on BDTs

• BDTs are a different form of truth tables.

• BDTs are not compact:• A BDT for switching function f on n variables has 2n leafs.• The size of a BDT does not change if the variable order changes.⇒ They are as space inefficient as truth tables!

• BDTs contain a lot of redundancy:• All leafs with value one (zero) could be collapsed into a single leaf.• A similar scheme could be adopted for isomorphic subtrees.

Two graphs rooted at nodes u and v are isomorphic, denoted asu ≡ v when both following conditions hold.

• value(u) = value(v) if u and v are terminals.

• low(u) ≡ low(v) ∧ high(u) ≡ high(v), otherwise.

Hao Zheng (CSE, USF) Comp Sys Verification 10 / 44

Page 14: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Contents

1 Binary Decision Tree

2 Ordered Binary Decision Diagram

3 From BDT to BDDs

4 Variable Ordering

5 Logic Operations by BDDs

Hao Zheng (CSE, USF) Comp Sys Verification 11 / 44

Page 15: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Ordered Binary Decision Diagram (OBDD)

• OBDDs rely on compactions of BDT representations.

• Idea: skip redundant fragments of BDT representations.

• Collapse subtrees with all terminals having same value.

• Identify nodes with isomorphic subtrees.

• This yields directed acyclic graphs with outdegree two.

• Inner nodes are labeled with variables.

• Leafs are labeled with function values (zero and one).

• A unique variable ordering is followed by every path.

• Each variable is assigned an unique index.

• Each BDD node v has an index index(v) which is the index of thevariable labeled in v.• index(v) < index(low(v)) if low(v) is a non-terminal,• index(v) < index(high(v)) if high(v) is a non-terminal.

Hao Zheng (CSE, USF) Comp Sys Verification 12 / 44

Page 16: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Transition Relation as a BDTTransition Relation as a BDT

x 02

1 0 1 0 1 1 0 0 1 1 1 01 1 10

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02 x 02

x 01

x2

x 02

A BDT representing for our example using ordering x1 < x2 < x 01 < x 02.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 110 / 155

A BDT representing ∆ for our example using ordering x1 < x2 < x′1 < x′2.

Hao Zheng (CSE, USF) Comp Sys Verification 13 / 44

Page 17: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Transition Relation as a BDDTransition Relation as an ROBDD

1

x 01

0

x1

x2 x2

x 01x 01

x 02x 02

An example ROBDD representing for our example using x1 < x2 < x 01 < x 02.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 120 / 155A BDT representing ∆ for our example using ordering x1 < x2 < x′1 < x′2.

Hao Zheng (CSE, USF) Comp Sys Verification 14 / 44

Page 18: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

OBBDs and Boolean Functions

• Let ℘ be a variable ordering for Var where ℘ = (z1, . . . , zm).

• Every OBDD is defined wrt a given variable ordering.• The nodes in every path are labeled with variables in the order as in ℘.

• A terminal node represents a constant Boolean function either 1 or 0.

• For a non-terminal node n labeled with z representing a Booleanfunction fn, its two successor nodes represent Boolean functions:• Node at the end of the 0-edge (low(n)): fn|z=0.• Node at the end of the 1-edge (high(n)): fn|z=1.

Therefore,fn = ¬z ∧ fn|z=0 ∨ z ∧ fn|z=1

• A OBDD is reduced (i.e. ROBDD) if for every pair (v, w) of nodes,

v 6= w implies fv 6= fw.

Hao Zheng (CSE, USF) Comp Sys Verification 15 / 44

Page 19: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Universality and Canonicity Theorem

[Fortune, Hopcroft & Schmidt, 1978]

Let ~x be a finite set of Boolean variables and ℘ a variable ordering for ~x.

(a) For each switching function f for ~x there exists a ℘-ROBDD OBDDwith fOBDD = f .

(b) For any ℘-ROBDDs G and H with fG = fH , G and H are isomorphic,i.e., agree up to renaming of the nodes.• ROBDDs are canonical for a fixed variable ordering.

Hao Zheng (CSE, USF) Comp Sys Verification 16 / 44

Page 20: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

The Importance of Canonicity

• Absence of redundant vertices:

If fB does not depend on xi, ROBDD B does not contain an xi node.

• Test for equivalence: f(x1, . . . , xn) ≡ g(x1, . . . , xn)?

Generate ROBDDs Bf and Bg, and check isomorphism.

• Test for validity: f(x1, . . . , xn) = 1?

Generate ROBDD Bf and check whether it only consists of a 1-leaf.

• Test for implication: f(x1, . . . , xn)→ g(x1, . . . , xn)?

Generate ROBDD Bf ∧ ¬g and check if it just consists of a 0-leaf.

• Test for satisfiability:

f is satisfiable if and only if Bf has a reachable 1-leaf.

Hao Zheng (CSE, USF) Comp Sys Verification 17 / 44

Page 21: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Contents

1 Binary Decision Tree

2 Ordered Binary Decision Diagram

3 From BDT to BDDs

4 Variable Ordering

5 Logic Operations by BDDs

Hao Zheng (CSE, USF) Comp Sys Verification 18 / 44

Page 22: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Reducing OBDDs

• Generate an OBDD (or BDT) for a boolean expression, then reduce bymeans of a recursive descent over the OBDD.

• Elimination rule:

If low(v) = high(v) = w, eliminate v and redirect all incoming edges to v tonode w.

• Isomorphism rule:• If v 6= w are roots of isomorphic subtrees, remove v, and redirect all

incoming edges to v to node w.• (Special case) Combine all 0/1-leaves, redirect all incoming edges.

Hao Zheng (CSE, USF) Comp Sys Verification 19 / 44

Page 23: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

From BDT to ROBDDTransition Relation as a BDT

x 02

1 0 1 0 1 1 0 0 1 1 1 01 1 10

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02 x 02

x 01

x2

x 02

A BDT representing for our example using ordering x1 < x2 < x 01 < x 02.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 110 / 155

An OBDD representing ∆ for our example using ordering x1 < x2 < x′1 < x′2.

Hao Zheng (CSE, USF) Comp Sys Verification 20 / 44

Page 24: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

From BDT to ROBDDTransition Relation as a OBDD

0 1 0 1 1 0 00

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02 x 02

x 01

x2

x 02x 02

11 1 0 11

Isomorphism rule.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 127 / 155

After isomorphism ruleNext, elimination rule

Hao Zheng (CSE, USF) Comp Sys Verification 21 / 44

Page 25: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

From BDT to ROBDDTransition Relation as a OBDD

x 02 x 02 x 02 x 02

x 01 x 01

x2

x1

x 01

x 02

x 01

x2

x 02

101010 10 101 1 0 1

Elimination rule.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 128 / 155

Next, isomorphism rule

Hao Zheng (CSE, USF) Comp Sys Verification 22 / 44

Page 26: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

From BDT to ROBDDTransition Relation as a OBDD

x 02 x 02

x 01 x 01

x2

x1

x 01 x 01

x2

x 02

10 101 1 0 1

Isomorphism rule.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 129 / 155

Next, elimination rule

Hao Zheng (CSE, USF) Comp Sys Verification 23 / 44

Page 27: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

From BDT to ROBDDTransition Relation as a OBDD

x 02 x 02

x 01

x2

x1

x 01 x 01

x2

x 02

10 101 1 0 1

Elimination rule.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 130 / 155

Next, isomorphism rule

Hao Zheng (CSE, USF) Comp Sys Verification 24 / 44

Page 28: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

From BDT to ROBDDTransition Relation as a OBDD

x 02

x 01

x2

x1

x 01 x 01

x2

x 02

10 1 1 0 1

Isomorphism rule.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 131 / 155

Next, isomorphism rule

Hao Zheng (CSE, USF) Comp Sys Verification 25 / 44

Page 29: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

From BDT to ROBDDTransition Relation as an ROBDD

1

x 01

0

x1

x2 x2

x 01x 01

x 02x 02

Isomorphism rule.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 132 / 155

Final reduced BDD

Hao Zheng (CSE, USF) Comp Sys Verification 26 / 44

Page 30: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Contents

1 Binary Decision Tree

2 Ordered Binary Decision Diagram

3 From BDT to BDDs

4 Variable Ordering

5 Logic Operations by BDDs

Hao Zheng (CSE, USF) Comp Sys Verification 27 / 44

Page 31: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Variable Ordering Variable Ordering

(b) ordering x1 <0 x 01 <0 x2 <0 x 02

x1

x2

x 02

x 01

0

x 02

1

x 01

x 01

0

x1

x2 x2

x 01x 01

x 02x 02

1

(a) ordering x1 < x2 < x 01 < x 02

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 133 / 155

Hao Zheng (CSE, USF) Comp Sys Verification 28 / 44

Page 32: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Variable Ordering and Size of BDDs

• The size of the ROBDD crucially depends on the variable ordering.

• # nodes in ROBDD OBDD = # of ℘-consistent co-factors of f .

• Some switching functions have linear and exponential ROBDDs.

e.g., the addition function, or the stable function.

• Some switching functions only have polynomial ROBDDs.• This holds, e.g., for symmetric functions.• Examples f(. . .) = x1⊕ . . .⊕ xn, or f(. . .) = 1 iff ≥ k variables xi are true.

• Some switching functions only have exponential ROBDDs.

This holds, e.g., for the middle bit of the multiplication function.

Hao Zheng (CSE, USF) Comp Sys Verification 29 / 44

Page 33: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

The Function Stable with Exponential ROBDDThe Function Stable with Exponential ROBDD

x3 x3x3

y2

y3

y2 y2 y2

y1y1 y1 y1 y1 y1 y1 y1

x1

1

y3

x2 x2

x3

The ROBDD of fstab(x ,y) = (x1$ y1) ^ . . . ^ (xn$ yn)

has 3·2n1 vertices under ordering x1 < .. . < xn < y1 < .. . < yn.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 135 / 155

The ROBDD of fstab(x, y) = (x1 ↔ y1) ∧ . . . ∧ (xn ↔ yn)

has 3·2n − 1 vertices under ordering x1 < . . . < xn < y1 < . . . < yn.

Hao Zheng (CSE, USF) Comp Sys Verification 30 / 44

Page 34: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

The Function Stable with Linear ROBDDThe Function Stable with Linear ROBDD

x3

y3

1

y3

x1

y1 y1

x2

y2 y2

The ROBDD of fstab(x ,y) = (x1$ y1) ^ . . . ^ (xn$ yn)

has 3·n +2 vertices under ordering x1 < y1 < .. . < xn < yn.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 136 / 155

The ROBDD of fstab(x, y) = (x1 ↔ y1) ∧ . . . ∧ (xn ↔ yn)

has 3·n + 2 vertices under ordering x1 < y1 < . . . < xn < yn.

Hao Zheng (CSE, USF) Comp Sys Verification 31 / 44

Page 35: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Another Function with an Exponential ROBDD

Another Function with an Exponential ROBDD

z1

0 1

z2 z2

z3 z3 z3 z3

y1 y1 y1 y1

y2 y2

y3

ROBDD for f3(z,y) = (z1 ^ y1) _ (z2 ^ y2) _ (z3 ^ y3)

for the variable ordering z1 < z2 < z3 < y1 < y2 < y3.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 137 / 155

ROBDD for f3(~z, ~y) = (z1 ∧ y1) ∨ (z2 ∧ y2) ∨ (z3 ∧ y3)

for the variable ordering z1 < z2 < z3 < y1 < y2 < y3.

Hao Zheng (CSE, USF) Comp Sys Verification 32 / 44

Page 36: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

An Optimal Linear ROBDDAn Optimal Linear ROBDD

z1

1 0

y1

z2

y2

z3

y3

ROBDD for f3(·) = (z1^ y1)_ (z2^ y2)_ (z3^ y3).

For ordering z1 < y1 < z2 < y2 < z3 < y3.

As all variables are essential, this ROBDD is optimal.

For no variable ordering, a smaller ROBDD exists.

Chris J. Myers (Lecture 6: CTL) Verification of Cyber-Physical Systems 138 / 155

• ROBDD for f3(·) = (z1 ∧ y1)∨ (z2 ∧ y2)∨ (z3 ∧ y3).

• For ordering z1 < y1 < z2 < y2 < z3 < y3.

• As all variables are essential, this ROBDD is optimal.

• For no variable ordering, a smaller ROBDD exists.

Hao Zheng (CSE, USF) Comp Sys Verification 33 / 44

Page 37: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

The Multiplication Function

• Consider two n-bit integers:

Let bn−1bn−2 . . . b0 and cn−1cn−2 . . . c0 where bn−1 is the most significantbit, and b0 the least significant bit.

• Multiplication yields a 2n-bit integer:

The ROBDD OBDDfn−1has at least 1.09n vertices where fn−1 denotes

the (n−1)-st output bit of the multiplication.

Hao Zheng (CSE, USF) Comp Sys Verification 34 / 44

Page 38: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Optimal Variable Ordering

• The size of ROBDDs is dependent on the variable ordering.

• Is it possible to determine ℘ such that the ROBDD has minimal size?• To check whether a variable ordering is optimal is NP-hard.• Polynomial reduction from the 3SAT problem. [Bollig & Wegener, 1996]

• There are many switching functions with large ROBDDs:

For almost all switching functions the minimal size is in Ω( 2n

n ).

• How to deal with this problem in practice?• Guess a variable ordering in advance.• Rearrange the variable ordering during the ROBDD manipulations.• Not necessary to test all n! orderings, best known algorithm in O(3n·n2).

Hao Zheng (CSE, USF) Comp Sys Verification 35 / 44

Page 39: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Dynamic Re-ordering

• Finding an optimal ordering is NP-hard.

• Static ordering does not work well across different applications, or forBDDs that need to be transformed during different stages of anapplication.

• Automated dynamic re-ordering rearranges the variable ordersperiodically to reduce the size of BDDs.

• Rudell’s “sifting” is widely used.• Try moving a variable to all other positions, leaving the others fixed. Then

place variable in the position that minimizes BDD size.• Do this for all variables.

Hao Zheng (CSE, USF) Comp Sys Verification 36 / 44

Page 40: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Dynamic Re-ordering

• Greatly improved effectiveness of BDDs.

• It is usually performed in the background.

• It may slow down the performance.• BDD operations stop when re-ordering is activated.

• It makes a difference between success and failure in complete anapplication.

• Some functions are inherently hard, e.g. outputs of integer multiplier.

Hao Zheng (CSE, USF) Comp Sys Verification 37 / 44

Page 41: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Contents

1 Binary Decision Tree

2 Ordered Binary Decision Diagram

3 From BDT to BDDs

4 Variable Ordering

5 Logic Operations by BDDs

Hao Zheng (CSE, USF) Comp Sys Verification 38 / 44

Page 42: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Logic Operations on BDDs

• Restriction f [b/x]: replacing variable x with a value 0 or 1.• if b = 0, direct all incoming edges of node labeled with x to low(v), or• if b = 1, direct all incoming edges of node labeled with x to high(v),• remove node x and its outgoing edges.

• The result of restriction is a cofactor of f .

a

0 1

b

c

a

0 1

c

f f[1/b]

Hao Zheng (CSE, USF) Comp Sys Verification 39 / 44

Page 43: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Logical Operations on BDDs (cont’d)

• Negation is a constant time operation with OBDDs.• Swap terminal nodes.

• The binary operations are based on the Shannon expansion.

f g = x · (f [0/x] g[0/x]) ∨ x · (f [1/x] g[1/x]).

where is some binary logic operator.

• Both BDDs must have the same variable ordering.• The new BDD for f g is constructed as follows.

• The root of f g is the root of f or g with the smaller index.• For any node in f g,

low(v) = f [0/x] g[0/x], and high(v) = f [1/x] g[1/x]

• Repeat the above step for low(v) and high(v) until either of them becomesterminal.

• Reduce the constructed BDD to make it canonical.

Hao Zheng (CSE, USF) Comp Sys Verification 40 / 44

Page 44: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Logical Operations on BDDs — Example

a

c

1 0

b

c

0 1

g = b ^ c

a

c

1 0

b

cf |a=1

f = ¬(a ^ c)

f |a=1 _ g

f |a=1 _ g |b=0 f |a=1 _ g |b=1

f _ g

Hao Zheng (CSE, USF) Comp Sys Verification 41 / 44

Page 45: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Logical Operations on BDDs — Example

a

c

1 0

b

c

f |a=1 _ g

f |a=1 _ g |b=0 f |a=1 _ g |b=1

a

1 0

b

c

f |a=1 _ g

f |a=1 _ g |b=0

f _ gf _ g

Hao Zheng (CSE, USF) Comp Sys Verification 42 / 44

Page 46: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Variants of BDDs

• Various kinds of BDDs for compactness or different applications.

• Compactness• Multi-rooted BDDs, free BDDs, partitioned OBDDs, etc

• Arithmetic operations• Multi-terminal BDDs (ADDs), edge-valued BDDs, binary moment diagrams

(BMDs), etc.

Hao Zheng (CSE, USF) Comp Sys Verification 43 / 44

Page 47: Binary Decision Diagrams - cse.usf.eduhaozheng/teach/cda5416/slides/bdd.pdf · Binary Decision Diagrams Hao Zheng Department of Computer Science and Engineering University of South

Implementation: Shared OBDDs

A shared ℘-OBDD is an OBDD with multiple roots.

10

Shared OBDD representing z1 ∧ ¬z2︸ ︷︷ ︸f1

, ¬z2︸︷︷︸f2

, z1 ⊕ z2︸ ︷︷ ︸f3

and ¬z1 ∨ z2︸ ︷︷ ︸f4

.

Main underlying idea: combine several OBDDs with same variable ordering

such that common ℘-consistent co-factors are shared.

Hao Zheng (CSE, USF) Comp Sys Verification 44 / 44