CS357 Lecture: BDD basics David Dill 1. 2 BDDs (Boolean/binary decision diagrams) BDDs are a very successful representation for Boolean functions. A BDD.

Slides:



Advertisements
Similar presentations
Model Checking Lecture 4. Outline 1 Specifications: logic vs. automata, linear vs. branching, safety vs. liveness 2 Graph algorithms for model checking.
Advertisements

Representing Boolean Functions for Symbolic Model Checking Supratik Chakraborty IIT Bombay.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
ECE Synthesis & Verification - L271 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Model Checking basics.
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
SYMBOLIC MODEL CHECKING: STATES AND BEYOND J.R. Burch E.M. Clarke K.L. McMillan D. L. Dill L. J. Hwang Presented by Rehana Begam.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
© 2011 Carnegie Mellon University Binary Decision Diagrams Part Bug Catching: Automated Program Verification and Testing Sagar Chaki September.
ECE 667 Synthesis & Verification - Boolean Functions 1 ECE 667 Spring 2013 ECE 667 Spring 2013 Synthesis and Verification of Digital Circuits Boolean Functions.
ECE Synthesis & Verification - Lecture 18 1 ECE 697B (667) Spring 2006 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Word-level.
Boolean Functions and their Representations
Rolf Drechlser’s slides used
1 CSEP590 – Model Checking and Automated Verification Lecture outline for July 16, 2003.
ECE Synthesis & Verification - L211 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Verification Equivalence checking.
Taylor Expansion Diagrams (TED): Verification EC667: Synthesis and Verification of Digital Systems Spring 2011 Presented by: Sudhan.
Swerve: Semester in Review. Topics  Symbolic pointer analysis  Model checking –C programs –Abstract counterexamples  Symbolic simulation and execution.
ECE Synthesis & Verification - Lecture 10 1 ECE 697B (667) Spring 2006 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Binary.
Lesson 6. Refinement of the Operator Model This page describes formally how we refine Figure 2.5 into a more detailed model so that we can connect it.
 2001 CiesielskiBDD Tutorial1 Decision Diagrams Maciej Ciesielski Electrical & Computer Engineering University of Massachusetts, Amherst, USA
ECE 667 Synthesis & Verification - BDD 1 ECE 667 ECE 667 Synthesis and Verification of Digital Systems Binary Decision Diagrams (BDD)
 2000 M. CiesielskiPTL Synthesis1 Synthesis for Pass Transistor Logic Maciej Ciesielski Dept. of Electrical & Computer Engineering University of Massachusetts,
ECE 667 Synthesis and Verification of Digital Systems
Computing with Finite Automata (part 2) 290N: The Unknown Component Problem Lecture 10.
IT University of Copenhagen Lecture 8: Binary Decision Diagrams 1. Classical Boolean expression representations 2. If-then-else Normal Form (INF) 3. Binary.
Fast Spectral Transforms and Logic Synthesis DoRon Motter August 2, 2001.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Digitaalsüsteemide verifitseerimise kursus1 Formal verification: BDD BDDs applied in equivalence checking.
B. Alizadeh Advanced Logic Design (2008) 1 / 55 Decision Diagrams.
Systems Architecture I1 Propositional Calculus Objective: To provide students with the concepts and techniques from propositional calculus so that they.
Identifying Reversible Functions From an ROBDD Adam MacDonald.
Binary Decision Diagrams (BDDs)
November,2000University of Southern California1 Introduction to Binary Decision Diagrams - Shesha Shayee K. Raghunathan.
CS1Q Computer Systems Lecture 8
Multiway Trees. Trees with possibly more than two branches at each node are know as Multiway trees. 1. Orchards, Trees, and Binary Trees 2. Lexicographic.
1 Boolean Algebra & Logic Gates. 2 Objectives Understand the relationship between Boolean logic and digital computer circuits. Learn how to design simple.
CS 267: Automated Verification Lecture 6: Binary Decision Diagrams Instructor: Tevfik Bultan.
Logic (continuation) Boolean Logic and Bit Operations.
Algorithmic Software Verification V &VI. Binary decision diagrams.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View BDDs.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
1 P P := the class of decision problems (languages) decided by a Turing machine so that for some polynomial p and all x, the machine terminates after at.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View BDDs.
Mathematical Preliminaries
Verifying Programs with BDDs Topics Representing Boolean functions with Binary Decision Diagrams Application to program verification class-bdd.ppt
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CS1Q Computer Systems Lecture 8
Fall 2008Programming Development Techniques 1 Topic 17 Assignment, Local State, and the Environment Model of Evaluation Section 3.1 & 3.2.
1 Class Presentation on Binary Moment Diagrams by Krishna Chillara Base Paper: “Verification of Arithmetic Circuits with Binary Moment Diagrams” by Randal.
BDDs1 Binary Tree Representation The recursive Shannon expansion corresponds to a binary tree Example: Each path from the root to a leaf corresponds to.
Boolean Functions 1 ECE 667 ECE 667 Synthesis and Verification of Digital Circuits Boolean Functions Basics Maciej Ciesielski Univ.
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Binary Decision Diagrams Prof. Shobha Vasudevan ECE, UIUC ECE 462.
IT 60101: Lecture #121 Foundation of Computing Systems Lecture 13 Trees: Part VIII.
Fundamentals & Ethics of Information Systems IS 201
Propositional Calculus: Boolean Algebra and Simplification
Fast Computation of Symmetries in Boolean Functions Alan Mishchenko
The Metacircular Evaluator
Binary Decision Diagrams
Gate Level Minimization
CSCI1600: Embedded and Real Time Software
Binary Decision Diagrams
Dr. Clincy Professor of CS
Discrete Controller Synthesis
A logic function f in n inputs x1, x2, ...xn and
Binary Decision Diagrams
A logic function f in n inputs x1, x2, ...xn and
Verifying Programs with BDDs Sept. 22, 2006
Presentation transcript:

CS357 Lecture: BDD basics David Dill 1

2 BDDs (Boolean/binary decision diagrams) BDDs are a very successful representation for Boolean functions. A BDD represents a Boolean function on variables x 1, x 2,... x n. BDDs have many applications in CAD for digital systems, and formal verification (and current context-sensitive analysis, according to Alex). Boolean functions are fundamental to computation, so there are many other applications as well. Don Knuth: "one of the only really fundamental data structures that came out in the last twenty-five years"

3 Ordered decision tree x1x1 x2x2 x3x x1x1 x2x2 x2x2 x3x3 x3x3 x3x3 x3x Crucial constraint: There is a global total order on the variables. Variables appear in this order along all paths in the BDD.

4 Space optimization 1: share identical subtrees 10 x1x1 x2x2 x2x2 x3x3 x3x3 x3x3 x3x x1x1 x2x2 x2x2 x3x3 x3x3 01 Nodes can be merged bottom-up

5 Space optimization 2: delete nodes with identical children 10 x1x1 x2x2 x3x x2x2 x2x2 x3x3 x3x3 01 x1x1

6 Multiplexer tree interpretation x1x1 x2x2 x2x BDDs can be regarded as digital circuits output

7 Canonicity of BDDs A BDD is a canonical representation of a Boolean function. –There is only one BDD for a Boolean function –Boolean expressions are not canonical: (a  b)  (a  c) is same as (a  (b  c)) –Easy to check for Boolean equivalence (same BDD) Tautology (= 1) Unsatisfiability (= 0)

8 Implementation BDD data structure is either "0", "1" or pointer to a record with var, thenbdd, elsebdd. BDDs are constructed bottom-up. For subtree sharing, maintain a hash table that maps to bddptr

9 Implementation Assumes var < any vars appearing in thenbdd, elsebdd make_bdd(var, thenbdd, elsebdd): if thenbdd = elsebdd return thenbdd; else if (lookup(var, thenbdd, elsebdd)) return old bdd from hash table; else { b = new_node(var, thenbdd, elsebdd); inserthash(, b); return b; };

10 Cofactors and Shannon decomposition Cofactoring a Boolean function restricts the function to a particular value of a variable. f  x i is the cofactor of f when x i = 1. This is the function you get if you replace x i by 1 everywhere in an expression for f f  x i is the cofactor of f when x i = 0. x i does not appear in f  x i or in f  x i

Shannon decomposition Allows recursive decomposition of functions f = ite(x i,, (f  x i ), (f  x i )) This identity holds regardless of where x i appears in the variable order, but Shannon decomposition is a lot faster when applied to the top-most variable. 11

12 Logical operations on BDDs. All propositional connectives are implemented in the following way (many other operations are, too). 1. Use Shannon decomposition to define a recursive function (on trees). 2. Save and reuse intermediate results (“memo-ize”).

13 Logical operations on BDDs. AND(b1, b2): if b1 = 0 or b2 = 0 return 0; else if b1 = 1 return b2; else if b2 = 1 return b1; else if b1.var = b2.var return make_bdd(b1.var, AND(b1.t, b2.t), AND(b1.e, b2.e)); else if b1.var < b2.var return make_bdd(b1.var, AND(b1.t, b2), AND(b1.e, b2)); else if b2.var < b1.var return make_bdd(b2.var, AND(b1, b2.t), AND(b1, b2.e));

14 Logical operations on BDDs. However, time to do this is proportional to tree size, which might be exponentially more than DAG size. So, use dynamic programming ("memo-ization"). AND(b1, b2):.... if lookup_in_AND_table(b1, b2) return old value; else build new BDD "b" insert_in_AND_table(, b);

15 Logical operations on BDDs. After this optimization, cost is proportional to product of BDD sizes. Same approach can be used for OR, NAND, XOR, etc. Also, for ite(b1, b2, b3) - "if then else".

16 Logical operations on BDDs. Translation from a logical expression to a BDD: Bottom-up evaluation of expression, using BDD operations. BDD_trans(f): if f is a variable, build and return the BDD for it. else if f = g & h, return AND(BDD_trans(g), BDD_trans(h)); etc.

17 BDD size Conversion from expression to BDD can cause exponential blowup –Each logical operation can result in a BDD that is product of input BDDs (details depend on how you measure size). –n operations on BDD’s of size 2: O(2 k ) –Any smaller result would have exciting implications for NP completeness. –Sometimes, BDD’s are small Usually, you have to work at it!

18 BDD size BDD size is strongly influenced by variable order –BDD’s are almost never small unless variable order is good. Some functions always have small BDDs –Symmetric functions (order of inputs doesn’t matter). –Addition –Bitwise equivalence “Most” functions have large BDDs –Multiplication (any output bit). –FFT, division,...

Variable order A good variable order is usually essential for compact BDDs Static variable ordering: Use heuristics to find a good order, i.e. –Interleave bits of operands of operators –Operand-specific orders (e.g., addition low-order to high-order or vice versa) –Put “control variables” at the top of the order (e.g. variables in conditionals that totally change functional behavior). 19

Dynamic Variable Ordering Variable ordering can also be done dynamically as BDD operations proceed. Optimal variable order problem is NP-complete. Many heuristics proposed. 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. Sifting is enabled by fast “swapping” of two adjacent variables in a BDD. 20

Dynamic Variable Ordering Enabled a leap in BDD effectiveness. Can be SLOW. Feels like garbage collection (BDD operations stop while it reorders), but slower. Sometimes, for a particular problem, you can save the order found by sifting and reuse it effectively. 21

22 BDDs for symmetric functions symmetric: function is the same even if variables change. Examples: – AND(x1, x2,..., xn) [OR, NAND, NOR] –PARITY(x1, x2,..., xn) [n-ary XOR] –Threshhold functions (at least k out of n bits are 1) Size is same regardless of variable ordering (why?)

23 Symmetric function example x1x1 x2x2 x2x2 x3x3 10 x1x1 10 x2x2 x2x2 x3x3 x3x3 x4x4 x4x4 Intuition: BDD nodes only need to “remember” number of variables that are 1. Majority function: output is majority value of three inputs. Parity: 1 iff odd number of true variables.

24 Boolean quantification  x. f(x, y) is equivalent to “f(x, y) holds for some value of x”  x. f(x, y) is equivalent to “f(x, y) holds for all values of x” Boolean quantifiers can be regarded as BDD operations:  x. f(x,y) = f  x  f  x  x. f(x,y) = f  x  f  x

25 Boolean Quantification Implementation BDD_exists(x, f) : if (f.var != x) then make_bdd(f.var, BDD_exists(x, b.t), BDD_exists(x, b.e)) else bdd_OR(b.t, b.e)); (but memo-ize, of course) forall(x,f) is similar

26 Predicates and Relations For many applications, it is more convenient to use “word-level” notation. For this, we can use “vector variables”, which are fixed-length vectors of BDD variables (notation: x) Bit-vector expressions can be represented as vectors of BDDs, F(x) This is just like bit-blasting with SAT.

27 Predicates and Relations A binary relation on Q is a subset of Q x Q. We can represent by creating two copies of the variables: x ("present state vars) and x' ("next state vars"). Then BDD R(x, x') can represent the relation. Notation: P(x) -- predicate on vectors of free variables (BDD vars) x returns a single-bit value.

28 Predicates and Relations Example relation: x = x', where x is a vector of Boolean variables: x = x' is  1  i  n ( x i  x i ' ) “  ” is “iff” = “not xor”

29 Fake First-order logic Use vectors variables and vectors of BDDs. Functions, predicates, and quantifiers can be defined on vectors. Universal and existential quantifiers Not really first-order because vectors are fixed- length –all variable and expression types are finite

30 Operations on BDD vectors Bitwise logical operations: e.g. a  b a, b must be of same length Result is bitvector of XORs of corresponding bits from a and b. Same idea can be used for all other Boolean operators: AND, OR, NAND, etc.

31 Predicates Def: Support of a Boolean function is set of variables that can affect value (i.e. vars appearing in BDD). Notation: P(x,y): x,y are vectors of variables containing superset of support of P. P(y) is P(x) with y variables substituted for corresponding x variables. Equality: x = y: (x 0 =y 0 )  (x 1 =y 1 ) ...  (x n =y n )

32 Quantifiers Boolean quantification operations (previous lecture) can be extended to vectors of variables.  x.P(x,y) =  x 0  x 1...P(x 0, x 1, …, y 0, y 1,…) Existential quantification is projection x000001x x100111x y000110y y101010y y200010y y000110y y101010y y200010y y00011y00011 y10101y10101 y20001y20001 P(x,y)  x.P(x,y)

33 Variable renaming Variables in BDD predicate can be renamed using the equality relation and existential quantification. P(y) =  x. (x = y)  P(x) Note that this makes logical sense (when should P(y) hold?), but also describes BDD operations.

Symbolic Breadth-First Search Search a graph without explicitly representing any vertices. G = V represented with bitvectors of sufficient length. E is a binary relation in V  V Reachability: Find the set of all vertices that are reachable from an arbitrary vertex i. 34

Symbolic breadth first search Encode graph. For convenience, considerV be the set of all bitvectors of length k. E(x, y) holds if there is an edge from x to y. I(x) says “x is an initial vertex.” Reachability: –R 0 (x) = I(x) –R n+1 (x) = R n (x)   y (x=y   x [ R n (x)  R(x,y) ]) –Continue until R n+1 (x) = R n (x) = all reachable states. Computing the last thing (the “image computation”) efficiently is the central computational challenge in many verification problems. 35