CS357 Lecture: BDD basics. David Dill

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

Unit 4: Formal Verification

Binary Decision Diagrams (BDD)

Boolean Representations and Combinatorial Equivalence

Model Checking I Binary Decision Diagrams

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

Behavior models and verification Lecture 6

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

Symbolic Model Checking

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

Binary Decision Diagrams and Symbolic Model Checking

ABC basics (compilation from different articles)

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

LOGIC SYNTHESIS AND VERIFICATION ALGORITHMS. Gary D. Hachtel University of Colorado. Fabio Somenzi University of Colorado.

Set Manipulation with Boolean Functional Vectors for Symbolic Reachability Analysis

Boolean Functions (Formulas) and Propositional Logic

Binary Decision Diagrams (BDDs) Pingqiang Zhou ShanghaiTech University

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Binary Decision Diagrams

HOL DEFINING HIGHER ORDER LOGIC LAST TIME ON HOL CONTENT. Slide 3. Slide 1. Slide 4. Slide 2 WHAT IS HIGHER ORDER LOGIC? 2 LAST TIME ON HOL 1

Overview. Discrete Event Systems - Verification of Finite Automata. What can finite automata be used for? What can finite automata be used for?

Lecture Notes on Binary Decision Diagrams

L4: Binary Decision Diagrams. Reading material

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

Lecture 5: Predicate Calculus. ffl Predicate Logic ffl The Language ffl Semantics: Structures

Chapter 1.3 Quantifiers, Predicates, and Validity. Reading: 1.3 Next Class: 1.4. Motivation

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

L3: Representations of functions

CS521 \ Notes for the Final Exam

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

BDDC v2 A basic bdd-based logical calculator

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

Decision Procedures in the Theory of Bit-Vectors

Propositional Calculus. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

BDDC v2 A basic bdd-based logical calculator

CSE 20 DISCRETE MATH. Fall

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

NO WARRANTY. Use of any trademarks in this presentation is not intended in any way to infringe on the rights of the trademark holder.

Propositional Calculus. Math Foundations of Computer Science

CMSC th Lecture: Graph Theory: Trees.

Propositional Calculus: Boolean Algebra and Simplification. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

A Satisfiability Procedure for Quantified Boolean Formulae

Ashish Sabharwal Computer Science and Engineering University of Washington, Box Seattle, Washington

Research Collection. Formal background and algorithms. Other Conference Item. ETH Library. Author(s): Biere, Armin. Publication Date: 2001

Propositional Calculus. Math Foundations of Computer Science

CSE 20 DISCRETE MATH. Winter

8.1 Polynomial-Time Reductions

Henry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012

Binary Decision Diagrams

8.1 Polynomial-Time Reductions

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Lecture 6: Arithmetic and Threshold Circuits

Program verification. Generalities about software Verification Model Checking. September 20, 2016

Lecture 2: Symbolic Model Checking With SAT

Variables. Substitution

CS314: FORMAL LANGUAGES AND AUTOMATA THEORY L. NADA ALZABEN. Lecture 1: Introduction

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

2009 Haskell January Test Binary Decision Diagrams

Symbolic Representation with Ordered Function Templates

Normal Forms for Boolean Expressions

ECE260B CSE241A Winter Logic Synthesis

Warm-Up Problem. Let L be the language consisting of as constant symbols, as a function symbol and as a predicate symbol. Give an interpretation where

Binary Decision Diagrams

CS 267: Automated Verification. Lecture 13: Bounded Model Checking. Instructor: Tevfik Bultan

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Today s Topics. What is a set?

! Greed. O(n log n) interval scheduling. ! Divide-and-conquer. O(n log n) FFT. ! Dynamic programming. O(n 2 ) edit distance.

Arithmetic Processing

User s Guide for BDDs in Jython

Chapter 8: Data Abstractions

CMPSCI611: The SUBSET-SUM Problem Lecture 18

Intermediate Code Generation

Chapter 8. NP and Computational Intractability. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Symbolic and Concolic Execution of Programs

1 Overview. 2 Applications of submodular maximization. AM 221: Advanced Optimization Spring 2016

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

A Toolbox for Counter-Example Analysis and Optimization

Efficiently Reasoning about Programs

MATHEMATICAL STRUCTURES FOR COMPUTER SCIENCE

Chapter 3. Gate-Level Minimization. Outlines

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

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

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Relational Calculus. Lecture 4B Kathleen Durant Northeastern University

Static Program Checking

Equivalence Checking of Combinational Circuits using Boolean Expression Diagrams

Advanced Digital Logic Design EECS 303

Combining Decision Diagrams and SAT Procedures for Efficient Symbolic Model Checking

About the Author. Dependency Chart. Chapter 1: Logic and Sets 1. Chapter 2: Relations and Functions, Boolean Algebra, and Circuit Design

Logic Synthesis and Verification

Introduction to Software Testing Chapter 3, Sec# 1 & 2 Logic Coverage

On Resolution Proofs for Combinational Equivalence Checking

COPYRIGHTED MATERIAL INDEX

Deductive Methods, Bounded Model Checking

Computation Club: Gödel s theorem

Transcription:

CS357 Lecture: BDD basics David Dill

BDDs (Boolean/binary decision diagrams) BDDs are a very successful representation for Boolean functions. A BDD represents a Boolean function on variables x, 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" 2

Ordered decision tree x x x 2 x 3 f x 3 x 2 x 3 x 3 x 2 x 3 Crucial constraint: There is a global total order on the variables. Variables appear in this order along all paths in the BDD. 3

Space optimization : share identical subtrees x x x 2 x 2 x 2 x 2 x 3 x 3 x 3 x 3 x 3 x 3 Nodes can be merged bottom-up 4

Space optimization 2: delete nodes with identical children x x x 2 x 2 x 2 x 3 x 3 x 3 5

Multiplexer tree interpretation output x x 2 x 2 BDDs can be regarded as digital circuits 6

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 (= ) Unsatisfiability (= ) 7

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

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(<var, thenbdd, elsebdd>, b); return b; }; 9

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 =. This is the function you get if you replace x i by everywhere in an expression for f f x i is the cofactor of f when x i =. 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.

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

Logical operations on BDDs. AND(b, b2): if b = or b2 = return ; else if b = return b2; else if b2 = return b; else if b.var = b2.var return make_bdd(b.var, AND(b.t, b2.t), AND(b.e, b2.e)); else if b.var < b2.var return make_bdd(b.var, AND(b.t, b2), AND(b.e, b2)); else if b2.var < b.var return make_bdd(b2.var, AND(b, b2.t), AND(b, b2.e)); 3

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(b, b2):... if lookup_in_and_table(b, b2) return old value; else build new BDD "b" insert_in_and_table(<b, b2>, b); 4

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(b, b2, b3) - "if then else". 5

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. 6

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

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,... 8

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

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. 2

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. 2

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

Symmetric function example Majority function: output is majority value of three inputs. Parity: iff odd number of true variables. x x x 2 x 2 x 2 x 2 x 3 x 3 x 3 x 4 x 4 Intuition: BDD nodes only need to remember number of variables that are. 23

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 24

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 25

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. 26

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. 27

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

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 fixedlength all variable and expression types are finite 29

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. 3

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 =y ) (x =y )... (x n =y n ) 3

Quantifiers Boolean quantification operations (previous lecture) can be extended to vectors of variables. x.p(x,y) = x x...p(x, x,, y, y, ) Existential quantification is projection P(x,y) x x y y y 2 x.p(x,y) y y y 2 y y y 2 32

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. 33

Symbolic Breadth-First Search Search a graph without explicitly representing any vertices. G = <V, E> 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 (x) = I(x) R n+ (x) = R n (x) y (x=y x [ R n (x) R(x,y) ]) Continue until R n+ (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