Binary Decision Diagrams (BDDs) Pingqiang Zhou ShanghaiTech University

Similar documents
L4: Binary Decision Diagrams. Reading material

Motivation. CS389L: Automated Logical Reasoning. Lecture 5: Binary Decision Diagrams. Historical Context. Binary Decision Trees

VLSI Logic Test, Validation and Verification Lecture 7 Properties & Applications of Binary Decision Diagrams

Binary Decision Diagrams (BDD)

Lecture Notes on Binary Decision Diagrams

Boolean Representations and Combinatorial Equivalence

Unit 4: Formal Verification

1 Model checking and equivalence checking

EECS 219C: Formal Methods Binary Decision Diagrams (BDDs) Sanjit A. Seshia EECS, UC Berkeley

Formal Verification. Lecture 7: Introduction to Binary Decision Diagrams (BDDs)

Hot X: Algebra Exposed

SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY

ECE 5775 (Fall 17) High-Level Digital Design Automation. Binary Decision Diagrams Static Timing Analysis

Synthesis 1. 1 Figures in this chapter taken from S. H. Gerez, Algorithms for VLSI Design Automation, Wiley, Typeset by FoilTEX 1

1/28/2013. Synthesis. The Y-diagram Revisited. Structural Behavioral. More abstract designs Physical. CAD for VLSI 2

Binary Decision Diagrams

Menu. X + /X=1 and XY+X /Y = X(Y + /Y) = X

Array Dependence Analysis as Integer Constraints. Array Dependence Analysis Example. Array Dependence Analysis as Integer Constraints, cont

CS357 Lecture: BDD basics. David Dill

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

(Refer Slide Time 6:48)

Theory of Integers. CS389L: Automated Logical Reasoning. Lecture 13: The Omega Test. Overview of Techniques. Geometric Description

Recent Results from Analyzing the Performance of Heuristic Search

Name Class Date. Quadratic Functions and Transformations

(Refer Slide Time 3:31)

Introduction to Machine Learning Spring 2018 Note Sparsity and LASSO. 1.1 Sparsity for SVMs

Figure 4.1: The evolution of a rooted tree.

Binary Trees

Advanced Digital Logic Design EECS 303

Advanced VLSI Design Prof. Virendra K. Singh Department of Electrical Engineering Indian Institute of Technology Bombay

(Refer Slide Time: 06:01)

CS 188: Artificial Intelligence Fall Search Gone Wrong?

Binary Decision Diagrams

Chapter 8: Data Abstractions

Synthesis of 2-level Logic Heuristic Method. Two Approaches

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

Model Checking I Binary Decision Diagrams

Binary Decision Diagrams and Symbolic Model Checking

Behavior models and verification Lecture 6

Logic Synthesis & Optimization Lectures 4, 5 Boolean Algebra - Basics

ABC basics (compilation from different articles)

CSE 2123 Recursion. Jeremy Morris

2009 Haskell January Test Binary Decision Diagrams

Jan Rabaey Homework # 7 Solutions EECS141

L3: Representations of functions

VLSI System Design Part II : Logic Synthesis (1) Oct Feb.2007

Algorithms. Deleting from Red-Black Trees B-Trees

Computer Science 210 Data Structures Siena College Fall Topic Notes: Priority Queues and Heaps

1 Definition of Reduction

Efficient filtering of XML documents with XPath expressions

Horn Formulae. CS124 Course Notes 8 Spring 2018

T Parallel and Distributed Systems (4 ECTS)

Symbolic Model Checking

Logic Synthesis and Verification

CSC 220: Computer Organization Unit 10 Arithmetic-logic units

Arithmetic-logic units

Chap5 The Theory of the Simplex Method

Parse Trees. John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA

Headset Research Report:

Postfix (and prefix) notation

Advanced Database Systems

4.1 Review - the DPLL procedure

Steven Skiena. skiena

Parallel Computation: Many computations at once, we measure parallel time and amount of hardware. (time measure, hardware measure)

6.001 Notes: Section 15.1

- Introduction P. Danziger. Linear Algebra. Algebra Manipulation, Solution or Transformation

Intro. Scheme Basics. scm> 5 5. scm>

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

CARLETON UNIVERSITY. Laboratory 2.0

Friday Four Square! 4:15PM, Outside Gates

(Refer Slide Time: 01.26)

MULTIPLE OPERAND ADDITION. Multioperand Addition

Topics Introduction to Microprocessors

Tutorial: Pattern Wizard

COMP 410 Lecture 1. Kyle Dewey

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Recitation 9. Prelim Review

Normal Forms for Boolean Expressions

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 2, 2016

Trees and Tree Traversals. Binary Trees. COMP 210: Object-Oriented Programming Lecture Notes 8. Based on notes by Logan Mayfield

Section 3.2 Quadratic Functions

y ax bx c y a x h 2 Math 11 Pre-Cal Quadratics Review

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

Lecture 6. Binary Search Trees and Red-Black Trees

CSCI S-Q Lecture #12 7/29/98 Data Structures and I/O

Points Addressed in this Lecture. Standard form of Boolean Expressions. Lecture 4: Logic Simplication & Karnaugh Map

1. What is cos(20 ) csc(70 )? This is a review of the complementary angle theorem that you learned about last time.

CS 31: Intro to Systems Caching. Martin Gagne Swarthmore College March 23, 2017

CMSC424: Database Design. Instructor: Amol Deshpande

Intro. Speed V Growth

We use L i to stand for LL L (i times). It is logical to define L 0 to be { }. The union of languages L and M is given by

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Tree Based Symmetric Key Broadcast Encryption

March 20/2003 Jayakanth Srinivasan,

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 7. (A subset of) the Collections Interface. The Java Collections Interfaces

Solving Linear Recurrence Relations (8.2)

CSE 417 Branch & Bound (pt 4) Branch & Bound

Chapter 20: Binary Trees

B+ Tree Review. CSE332: Data Abstractions Lecture 10: More B Trees; Hashing. Can do a little better with insert. Adoption for insert

CMSC 754 Computational Geometry 1

Transcription:

Binary Decision Diagrams (BDDs) Pingqiang Zhou ShanghaiTech University

Computational Boolean Algera Representations Applying unate recursive paradigm (URP) in solving tautology is a great warm up example. Shows ig idea: Boolean functions as things we manipulate with software. Data structure + operators But URP is not the real way we do it. Let s look at a real, important, elegant way to do this Binary Decision Diagrams: BDDs 2

Binary Decision Diagrams (BDD) Originally studied y several people got practically useful in 1986 Randal Bryant of CMU made reakthrough on Reduced Ordered BDD (ROBDD). http://www.cs.cmu.edu/~ryant/ 3

Binary Decision Diagrams for Truth Tales Big Idea #1: Binary Decision Diagram Turn a truth tale for the Boolean function into a Decision Diagram. In simplest case, graph is just a tree. By convention, don t draw arrows on the edges, we know where they go. Decision Tree x1 x3 x3 x3 x3 x1 x3 f 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 4 0 0 0 1 0 1 0 1

Binary Decision Diagrams Vertex represents a variale. Edge out of a vertex is a decision (0 or 1) on that variale. Follow green dashed line for 0. Follow red solid line for 1. Function value determined y leaf value. x1 x3 x3 x3 x3 x1 x3 f 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 5 0 0 0 1 0 1 0 1

Binary Decision Diagrams Some Terminology The lo pointer to lo child of vertex x1 A variale vertex The hi pointer to hi child of vertex A constant vertex at the leaf of the tree x3 x3 x3 x3 0 0 0 1 0 1 0 1 6 The variale ordering, which is the order in which decisions aout variales are made. Here, it is x1 < < x3.

Ordering Different variale orders are possile. x1 x3 x3 x3 x3 0 0 0 1 0 1 0 1 Order for this sutree is < x3 x1 Order for this sutree is x3 < x3 x3 x3 0 0 0 1 0 0 1 1 7

Binary Decision Diagrams Oservations Each path from root to leaf traverses variales in some order. Each such path constitutes a row of the truth tale, i.e., a decision aout what output is when variales take particular values. However, we have not yet specified anything aout the order of decisions. The decision diagram is NOT unique for this function. 8

Terminology: Canonical form Canonical: Representation that does not depend on gate implementation of a Boolean function. Same function of same variales always produces this exact same representation. Example: a truth tale is canonical (up to variale order). We want a canonical form data structure. 9

Binary Decision Diagrams What s wrong with this diagram representation? It is not canonical, and it is way too ig to e useful (it is as ig as truth tale!) x1 x3 x3 x3 x3 0 0 0 1 0 1 0 1 x1 x3 x3 x3 0 0 0 1 0 0 1 1 10

Binary Decision Diagrams Big idea #2: ordering Restrict gloal ordering of variales. It means: every path from root to a leaf visit variales in the SAME order. Note: it is OK to omit a variale if you don t need to check it to decide which leaf node to reach for final value of function. x1 0 0 0 1 x1 0 0 1 11

Ordering BDD Variales Assign (an aritrary) gloal ordering to vars: x1 < < x3 Variales must appear in this specific order along all paths; ok to skip vars x1 x1 x3 x1 x3 x3 x1 x1 12 Property: No conflicting assignments along path (see each var at most once on path).

Binary Decision Diagrams OK, now what s wrong with it? Variale ordering simplifies things, ut still too ig, and not canonical. Original Decision Diagram x1 x3 x3 x3 x3 0 0 0 1 0 1 0 1 Equivalent, ut Different Decision Diagram x1 x3 x3 x3 0 0 0 1 0 1 13

Binary Decision Diagrams Big Idea #3: Reduction Identify redundancies in the graph that can remove unnecessary nodes and edges. Removal of node and its children, replace with x3 node is an example of this. x1 x3 x3 x3 x3 0 0 0 1 0 1 0 1 x1 x3 x3 x3 0 0 0 1 0 1 14

Binary Decision Diagrams Reduction Why are we doing this? Graph size: Want result as small as possile. Canonical form: For same function, given same variale order, want there to e exactly one graph that represents this function. 15

Reduction Rules Reduction Rule 1: Merge equivalent leaves Just keep one copy of each constant leaf anything else is totally wasteful. Redirect all edges that went into the redundant leaves into this one kept node. Apply Rule 1 to our example... x1 x1 16 x3 x3 x3 x3 0 0 0 1 0 1 0 1 x3 x3 x3 x3 0 1

Reduction Rules Reduction Rule 2: Merge isomorphic nodes Isomorphic = 2 nodes with same variale and identical children Cannot tell these nodes apart from how they contriute to decisions in graph. Note: means exact same physical child nodes, not just children with same lael. NOT isomorphic x x y z isomorphic x x y z y 0 0 0 1 17

Steps of Merging Isomorphic Nodes 1. Remove redundant node. 2. Redirect all edges that went into the redundant node into the one copy that you kept. For the example elow, edges into right x node now into left as well. x x x y z y z 18

Reduction Rules Apply Rule 2, merging redundant nodes, to our example. x1 x1 x3 x3 x3 x3 0 1 isomorphic x3 0 1 x3 19

Reduction Rules Reduction Rule 3: Eliminate Redundant Tests Redundant test: oth children of a node (x) go to the same node (y) so we don t care what value x node takes. Steps 1. Remove redundant node. 2. Redirect all edges into redundant node (x) into child (y) of the removed node. x y y 20

Reduction Rules Apply Rule 3, eliminating redundant tests, to our example. x1 x1 x3 x3 x3 We are done! 0 1 0 1 21

Reduction Rules The aove is a simple example. The reduction process terminates y applying each rule once. But in real case, you may need to iteratively apply Rule 2 and 3. It is only done when you cannot find any match of rule 2 or 3. Is this how programs really do it? No!! We will talk aout that later 22

Binary Decision Diagrams (BDDs) Big Results Recap: What did we do? Start with a decision diagram in the form of a tree, order the variales, and reduce the diagram Name: Reduced Ordered BDD (ROBDD) 23 Big result: ROBDD is a canonical form data structure for any Boolean function. Same function always generates exactly same graph... for same variale ordering. Two functions identical if and only if ROBDD graphs are isomorphic (i.e., same). Nice property: Simplest form of graph is canonical.

BDDs: Representing Simple Things NOTE: In a ROBDD, a Boolean function is really just a pointer to the root node of the graph. ROBDD for f a,,, z = 0 f ROBDD for f a,,, z = 1 f 0 ROBDD for f a,,, z = a f 1 a 24 0 1

ROBDD for AND f a, = a f f f a a a 0 0 0 1 0 1 0 1 Same graph for f a,,, z = a 25

ROBDD for OR f a, = a + f f f a a a 0 1 1 1 0 1 0 1 Same graph for f a,,, z = a + 26

ROBDD for AND/OR on Multiple Inputs f a,, c, d = acd f f a,, c, d = a + + c + d f a c d a c d 27 0 1 0 1

ROBDD for XOR f a, = a f f a a 0 1 1 0 0 1 Same graph for f a,,, z = a 28

ROBDD for XOR on Multiple Inputs f a,, c, d = a c d f a c d c d 0 1 29

Sharing in BDDs Very important technical point: Every BDD node (not just root) represents some Boolean function in a canonical way. BDDs good at extracting & representing sharing of sufunctions in sugraphs. c d f a,, c, d = a c d f c d a c c d d d 0 1 30

BDD Sharing: Multi-Rooted BDD If we are uilding BDDs for multiple functions, then there may e same sugraphs among different BDDs. Don t represent same things multiple times; share them! As a result of sharing, the BDD can have multiple entry points, or roots. Called a multi-rooted BDD. 31

Multi-Rooted BDD: Example Build BDDs for two functions f 1 x 1, x 2, x 3 = x 1 x 2 x 3 f 2 x 1, x 2, x 3 = x 1 + x 2 x 3 f 1 f 2 f 1 f 2 x1 x1 Shaded parts are same Can e shared! x1 x1 x3 x3 x3 0 1 0 1 0 1 32

Review Binary decision diagram (BDD) Big idea #1: Decision diagrams Big idea #2: Assign gloal ordering to variales. Big idea #3: Reduction Merge equivalent leaves Merge isomorphic nodes Eliminate redundant tests Result: Reduced Ordered Binary Decision Diagram (ROBDD) 33

Review ROBDD is a canonical form data structure for any Boolean function. Same function always generates exactly same graph... for same variale ordering. Nice property: Simplest form of graph is canonical. Sharing in BDDs Every BDD node (not just root) represents some Boolean function in a canonical way. We can uild a multi-rooted BDD for multiple functions. 34

Multi-Rooted BDD: Example Look at sum S3 and carry out Cout [Ro Ruentar] 35

Multi-Rooted BDD: Example Don t represent it twice! BDD can have multiple entry points, or roots Called a multi-rooted BDD Recall Every node in a BDD represents some Boolean function Multi-rooting idea just explicitly exploits this to etter share stuff 36 [Ro Ruentar]

Multi-Rooted BDD: Example Why stop at 2 roots? Sharing among sets of functions (several separate BDDs) reduces the size of BDD! Real example: Adders Separately 4-it adder: 51 nodes 64-it adder: 12,481 nodes Shared 4-it adder: 31 nodes 64-it adder: 571 nodes 37

BDD for OP of Functions g a h f = OR(g, h) Order: a < < c c? 0 1 0 1 38

BDD and Cofactors f f x x f x What are these two functions? 39

How to Implement OP? Example: op = AND f = g h BDD and cofactors: g h x x g h x Therefore, we only need to otain BDDs for g h x and 40 g h x Property of cofactors: g h x = g x h x g h x = g x h x Since we are given BDDs for g and h, it is easy to get BDDs for g x, g x, h x, and h x. We recursively apply op on (g x, h x ) and (g x, h x ) first.

How Are BDDs Really Implemented? Recursively! Cofactor and divide-and-conquer are two keys. Note: Boolean function can e decomposed: f = op(g, h) op can e either AND, OR, XOR, NOT, Idea: uild ROBDD for g and ROBDD for h, then uild ROBDD for f from the previous two ROBDDs. op looks like: BDD op(bdd g, BDD h); BDDs for g, h, and f can share. Start from the ase cases: ROBDDs for constants 0 and 1 and a single variale. f g h 41

Algorithm for Implementing OP BDD op(bdd g, BDD h) { if (g is a leaf or h is a leaf) // termination condition: // either g = 0 or 1, or h = 0 or 1 return proper BDD; var x = min(root(g), root(h)) // get the lowest order var BDD flo = op( negcofbdd(g, x), negcofbdd(h, x) ); BDD fhi = op( poscofbdd(g, x), poscofbdd(h, x) ); return cominebdd(x, flo, fhi); } 42 negcofbdd g, x = g x = poscofbdd g, x = g x = g if x < root(g) lo(g) if x = root(g) g if x < root(g) hi(g) if x = root(g)

Example of OP g a Otain f = OR(g, h). Order: a < < c Cofactor on variale a h c 0 1 h a 0 1 h a g a g a 0 c c 43 0 1 0 1 0 1

Example of OP (cont.) Recursively compute OR(g a, h a) g a h a c We otain: OR(g a, h a) 0 0 1 c Termination condition 0 1 44

Example of OP (cont.) Recursively compute OR(g a, h a ) h a g a Cofactor on variale c 0 1 0 1 h a g a g a h a c 45 0 1 0 0 1

Example of OP (cont.) Recursively compute OR(g a, h a ) Recursively compute OR(g a, h a ) h a g a h a g a c 0 0 1 0 1 Termination condition OR(g a, h a ) Termination condition OR(g a, h a ) 0 1 46

Example of OP (cont.) OR(g a, h a ) OR(g a, h a ) 0 1 Based on the recursion results, otain OR g a, h a Note: we cofactor on. OR(g a, h a ) 0 1 47

Example of OP (cont.) Based on the recursion results, otain OR g, h Note: we cofactor on a. OR(g a, h a) 0 c 1 OR(g a, h a ) 0 1 OR(g, h) 0 a c 1 48 Done!

BDDs: Build Up Incrementally 49 For a gate-level network, uild the BDD for the output incrementally. a c A B C AND AND OR Each input is a BDD, each gate ecomes an operator op that produces a new output BDD. Build BDD for F as a script of calls to asic BDD operators. Stick to a gloal ordering. D E F BDD operator script 1. A = CreateVar( a ) 2. B = CreateVar( ) 3. C = CreateVar( c ) 4. D = AND(A, B) 5. E = AND(B, C) 6. F = OR(D, E)

Example: Build BDD Incrementally a c A B C AND AND D OR Gloal ordering: a < < c E BDD operator script 1. A = CreateVar( A ) 2. B = CreateVar( B ) 3. C = CreateVar( C ) 4. D = AND(A, B) 5. E = AND(B, C) 6. F = OR(D, E) 1. A 2. B 3. C 4. D 5. F E a c a 0 1 0 1 0 1 c 50 0 1 0 1

Example: Build BDD Incrementally a c A B C AND AND D E OR Gloal ordering: a < < c 6. F F BDD operator script 1. A = CreateVar( A ) 2. B = CreateVar( B ) 3. C = CreateVar( C ) 4. D = AND(A, B) 5. E = AND(B, C) 6. F = OR(D, E) a c 51 0 1

Application of BDD Tautology checking Solution: Build BDD for f. Check if the BDD is just the BDD for f = 1. f 1 52

Application of BDD Satisfiaility (SAT) Satisfiaility (SAT): Does there exist an input pattern for variales that lets F = 1? If yes, return one pattern. Recall: In network repair prolem, we want to find (d 0, d 1, d 2, d 3 ) so that a z d 0, d 1, d 2, d 3 = 1 Solution: If the BDD for F is not the BDD for f = 0. Then, SAT answer is yes. If yes, any path from root to 1 leaf is a solution. x1 x4 0 1 SAT? Yes. SAT pattern: x 1, x 2, x 3, x 4 = 0,1,, 1 (1,,, 1) 53

Application of BDD Comparing Logic Implementations Are two given Boolean functions F and G the same? Solution #1: Build BDD for F. Build BDD for G Compare pointers to roots of F and G If and only if pointers are same, F = G. 54 Solution #2: Build BDD for function F G Check if the BDD is just the BDD for f = 1. f 1

Application of BDD Comparing Logic Implementations What inputs make functions F and G give different answers? Solution: Build BDD for H = F G. Ask SAT question for H. 55

BDDs: Seem Too Good To Be True?! Prolem : Variale ordering matters. Example: a1 1 + a2 2 + a3 3 Good ordering:a1 < 1 < a2 < 2 < a3 < 3 Bad ordering: a1 < a2 < a3 < 1 < 2 < 3 56

Variale Ordering: How to Handle? Variale ordering heuristics: make nice BDDs for reasonale prolems. Characterization: know which prolems never make simple BDDs (e.g., multipliers) Dynamic ordering: let the BDD software package pick the order on the fly. 57

Variale Ordering: Intuition Rules of thum for BDD ordering Related inputs should e near each other in order. Groups of inputs that can determine function y themselves should e (i) close together, and (ii) near top of BDD. Example: a1 1 + a2 2 + a3 3 Good ordering: a1 < 1 < a2 < 2 < a3 < 3 Why? a i and i together can determine the function value 58

Variale Ordering: Intuition Rules of thum for BDD ordering Related inputs should e near each other in order. Groups of inputs that can determine function y themselves should e (i) close together, and (ii) near top of BDD. Example: a1 1 + a2 2 + a3 3 Bad ordering: a1 < a2 < a3 < 1 < 2 < 3 Why? We need to rememer a1, a2, a3 efore we see any s. 59

Variale Ordering: Practice 60 Arithmetic circuits are important logic; how are their BDDs? Many carry chain circuits have easy linear sized ROBDD orderings: Adders, Sutractors, Comparators. Rule is alternate variales in the BDD order: a0, 0, a1, 1, a2, 2,, an, n. Are all arithmetic circuits easy? No! Multiplication is exponential in numer of nodes for any order. General experience with BDDs Many tasks have reasonale ROBDD sizes; algorithms are practical to aout 100M nodes. People spend a lot of effort to find orderings that work

BDD Summary Reduced, Ordered, Binary Decision Diagrams, ROBDDs Canonical form a data structure for Boolean functions. Two Boolean functions the same if and only if they have identical BDD. A Boolean function is just a pointer to the root node of the BDD graph. Every node in a (shared) BDD represents some function. Basis for much of today s general manipulation or Boolean stuff. 61 Prolems Variale ordering matters; sometimes BDD is just too ig. Often, we just want to know SAT don t need to uild the whole function.