Binary Decision Diagrams

Similar documents
Boolean Representations and Combinatorial Equivalence

Behavior models and verification Lecture 6

Model Checking I Binary Decision Diagrams

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

Binary Decision Diagrams (BDD)

Symbolic Model Checking

Binary Decision Diagrams

Unit 4: Formal Verification

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

Lecture Notes on Binary Decision Diagrams

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

L4: Binary Decision Diagrams. Reading material

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

Chapter 8: Data Abstractions

Lecture1: Symbolic Model Checking with BDDs. Edmund M. Clarke, Jr. Computer Science Department Carnegie Mellon University Pittsburgh, PA 15213

Normal Forms for 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.

CS357 Lecture: BDD basics. David Dill

Binary Decision Diagrams

BDDC v2 A basic bdd-based logical calculator

Binary Decision Diagrams and Symbolic Model Checking

BDDC v2 A basic bdd-based logical calculator

Binary Decision Diagrams (BDDs) Pingqiang Zhou ShanghaiTech University

2SAT Andreas Klappenecker

CS 267: Automated Verification. Lecture 6: Binary Decision Diagrams. Instructor: Tevfik Bultan

2009 Haskell January Test Binary Decision Diagrams

8.1 Polynomial-Time Reductions

Formal Verification Methods 2: Symbolic Simulation

A purely functional implementation of ROBDDs in Haskell

ABC basics (compilation from different articles)

Graph-Based Algorithms for Boolean Function Manipulation

Solving Boolean Equations with BDDs and Clause Forms. Gert Smolka

Finite Model Generation for Isabelle/HOL Using a SAT Solver

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

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

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

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

Solving 3-SAT. Radboud University Nijmegen. Bachelor Thesis. Supervisors: Henk Barendregt Alexandra Silva. Author: Peter Maandag s

Boolean Functions (Formulas) and Propositional Logic

Lecture 14: Lower Bounds for Tree Resolution

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

Set Manipulation with Boolean Functional Vectors for Symbolic Reachability Analysis

Symbolic Boolean Manipulation with Ordered Binary Decision Diagrams

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

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

L3: Representations of functions

On Proof Systems Behind Efficient SAT Solvers. DoRon B. Motter and Igor L. Markov University of Michigan, Ann Arbor

On the Relation between SAT and BDDs for Equivalence Checking

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

A Relational View of Subgraph Isomorphism

ND-A FLCT 7 T'a a19m~ Representation and Manipulation of Inductive Boolean Functions

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

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

Solution 3: (a) True. Proof.

CORAL: a modern C++ library for the manipulation of Boolean functions

PROPOSITIONAL LOGIC (2)

Logic Synthesis and Verification

Chapter 8. NP-complete problems

Chapter 10 Part 1: Reduction

8 NP-complete problem Hard problems: demo

8.1 Polynomial-Time Reductions

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

Symbolic Manipulation of Boolean Functions Using a Graphical Representation. Abstract

Local Two-Level And-Inverter Graph Minimization without Blowup

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

Chapter 6: Multilevel Combinational Circuits. Name: Lương Văn Minh No. :

Example of a Demonstration that a Problem is NP-Complete by reduction from CNF-SAT

2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS

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

Unification in Maude. Steven Eker

Tagged BDDs: Combining Reduction Rules from Different Decision Diagram Types

Qualitätssicherung von Software (SWQS)

1

Compiling Bayesian Networks by Symbolic Probability Calculation Based on Zero-suppressed BDDs

TypeChef: Towards Correct Variability Analysis of Unpreprocessed C Code for Software Product Lines

Decision Procedures in First Order Logic

Graph-Based Algorithms for Boolean Function Manipulation 12. Abstract

1 Model checking and equivalence checking

Formal Verification Techniques for Digital Systems

NP-Complete Reductions 2

The Satisfiability Problem [HMU06,Chp.10b] Satisfiability (SAT) Problem Cook s Theorem: An NP-Complete Problem Restricted SAT: CSAT, k-sat, 3SAT

Logic and Computation

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

Horn Formulae. CS124 Course Notes 8 Spring 2018

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd

Combining Decision Diagrams and SAT Procedures for Efficient Symbolic Model Checking

Int. J. Advanced Networking and Applications 1430 Volume:03 Issue:06 Pages: (2012) ISSN :

Having a BLAST with SLAM

Reference Sheet for CO142.2 Discrete Mathematics II

NP and computational intractability. Kleinberg and Tardos, chapter 8

DKT 122/3 DIGITAL SYSTEM 1

CPSC 320 Notes: What's in a Reduction?

Simplified Digital Logic Circuits Using Binary Decision Tree

A Satisfiability Procedure for Quantified Boolean Formulae

Equivalence Checking of Combinational Circuits using Boolean Expression Diagrams

Parallel and Distributed Computing

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

Decision Procedures for Equality Logic. Daniel Kroening and Ofer Strichman 1

NP-Completeness. Algorithms

4.1 Review - the DPLL procedure

Transcription:

5-44 Bug Catching: Automated Program Verification and Testing based on slides by SagarChaki 2 Carnegie Mellon University

BDDs in a nutshell Typically mean Reduced Ordered (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), 986. 2

Running Example: Comparator a a 2 b b 2 Comparator f =,a = b Æa 2 = b 2 3

Conjunctive Normal Form f a = b Æ a 2 = b 2 a )b Æb )a Æ a 2 )b 2 Æb 2 )a 2 (:a Çb ) Æ(:b Ça ) Æ(:a 2 Çb 2 ) Æ(:b 2 Ça 2 ) (:b Ça ) Æ(:a Çb ) Æ(:a 2 Çb 2 ) Æ(:b 2 Ça 2 ) Not Canonical 4

Truth Table () a b a 2 b 2 f Still Not Canonical 5

Truth Table (2) a a 2 b b 2 f Canonical if you fix variable order. But always exponential in # of variables. Let s try to fix this. 6

Shannon s / Boole s Expansion Every Boolean formula f(a, a,, a n ) can be written as (a Æf(true, a,, a n )) Ç(:a Æf(false, a,, a n )) or, simply, ITE (a, f(true, a,, a n ), f(false, a,, a n )) where ITE stands for If-Then-Else The formula f(true, a,, a n ) is called the cofactorof f w.r.t. a The formula f(false, a,, a n ) is called the cofactorof f w.r.t. :a 7

Representing a Truth Table using a Graph a a 2 a 2 a 2 a 2 Binary Decision Tree (in this case ordered) 8

Binary Decision Tree: Formal Definition Balanced binary tree. Length of each path = # of variables Leaf nodes labeled with either or 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 to var(v) if low(v) is in the path, and 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 9

Binary Decision Tree low(v) v a var(v) = a high(v) a 2 a 2 a 2 a 2

Binary Decision Tree a b a 2 b 2 The truth assignment corresponding to the path to this leaf is: a =? b =? a 2 =? b 2 =?

Binary Decision Tree a b a 2 b 2 f a b a 2 b 2 The truth assignment corresponding to the path to this leaf is: a = b = a 2 = b 2 = 2

Binary Decision Tree a b a 2 b 2 f a b a 2 b 2 The truth assignment corresponding to the path to this leaf is: a = b = a 2 = b 2 = 3

Binary Decision Tree a b a 2 b 2 f a b a 2 b 2 The truth assignment corresponding to the path to this leaf is: a = b = a 2 = b 2 = 4

Binary Decision Tree (BDT) a a 2 a 2 a 2 a 2 Canonical if you fix variable order (i.e., use ordered BDT) But still exponential in # of variables. Let s try to fix this. 5

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

OBDT to ROBDD a a 2 a 2 a 2 a 2 7

OBDT to ROBDD a a 2 a 2 a 2 a 2 Duplicate subdiagram 8

OBDT to ROBDD a a 2 a 2 a 2 a 2 9

OBDT to ROBDD a a 2 a 2 a 2 a 2 2

OBDT to ROBDD a a 2 a 2 a 2 a 2 2

OBDT to ROBDD a a 2 a 2 a 2 a 2 22

OBDT to ROBDD a a 2 a 2 a 2 a 2 23

OBDT to ROBDD a a 2 a 2 a 2 a 2 24

OBDT to ROBDD a a 2 a 2 a 2 a 2 Redundant node 25

OBDT to ROBDD a a 2 a 2 a 2 a 2 b 2 26

OBDT to ROBDD a a 2 a 2 a 2 a 2 b 2 27

OBDT to ROBDD a a 2 a 2 a 2 a 2 28

OBDT to ROBDD a a 2 a 2 a 2 a 2 29

OBDT to ROBDD a If a = and b = then f = irrespective of the values of a 2 and b 2 a 2 a 2 a 2 3

OBDT to ROBDD a a 2 a 2 3

OBDT to ROBDD a a 2 a 2 32

OBDT to ROBDD a a 2 a 2 b 2 33

OBDT to ROBDD a a 2 a 2 b 2 34

OBDT to ROBDD a a 2 a 2 b 2 b 2 35

OBDT to ROBDD a a 2 a 2 b 2 b 2 36

OBDT to ROBDD a Let s move things around a little bit so that the BDD looks nicer. a 2 b 2 b 2 37

OBDT to ROBDD a Bryant gave a linear-time algorithm (called Reduce) to convert OBDT to ROBDD. b 2 a 2 b 2 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? 38

ROBDD (a.k.a. BDD) Summary BDDs are canonical representations of Boolean formulas f = f 2,? 39

ROBDD (a.k.a. BDD) Summary BDDs are canonical representations of Boolean formulas f = f 2,BDD(f ) and BDD(f 2 ) are isomorphic f is unsatisfiable,? 4

ROBDD (a.k.a. BDD) Summary BDDs are canonical representations of Boolean formulas f = f 2,BDD(f ) and BDD(f 2 ) are isomorphic f is unsatisfiable,bdd(f) is the leaf node f is valid,? 4

ROBDD (a.k.a. BDD) Summary BDDs are canonical representations of Boolean formulas f = f 2,BDD(f ) and BDD(f 2 ) are isomorphic f is unsatisfiable,bdd(f) is the leaf node f is valid,bdd(f) is the leaf node BDD packages do these operations in constant time Logical operations can be performed efficiently on BDDs Polynomial in argument size 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 42

ROBDD and variable ordering a a 2 a 2 43

ROBDD and variable ordering a a 2 a 2 44

ROBDD and variable ordering a a 2 a 2 45

ROBDD and variable ordering a a 2 a 2 46

ROBDD and variable ordering a a 2 a 2 b 2 47

ROBDD and variable ordering a a 2 a 2 b 2 48

ROBDD and variable ordering a Let s move things around a little bit so that the BDD looks nicer. a 2 a 2 b 2 b 2 49

ROBDD and variable ordering a 8 nodes a nodes a 2 a 2 a 2 b 2 b 2 b 2 b 2 a < b < a 2 < b 2 a < a 2 < b < b 2 5

ROBDD and variable ordering a? n + 2 nodes a? 2 n nodes a n a n a n b n b n b n b n a < b < < a n < b n a < < a n < b < < b n 5

ROBDD and variable ordering a 3 n + 2 nodes a 3 2 n nodes a n a n a n b n b n b n b n a < b < < a n < b n a < < a n < b < < b n 52

BDD Operations True : BDD(TRUE) False: BDD(FALSE) Var: v BDD(v) Not : BDD(f) BDD(:f) And : BDD(f ) BDD(f 2 ) BDD(f Æf 2 ) Or : BDD(f ) BDD(f 2 ) BDD(f Çf 2 ) Exists : BDD(f) v BDD(9 v. f) 53

Basic BDD Operations True False Var(v) v 54

BDD Operations: Not O() O() v 55

BDD Operations: Not O() O() v O(n) Swap and 56

BDD Operations: And Suppose this is the BDD for f What formula does this represent? v What formula does this represent? 57

BDD Operations: And Suppose this is the BDD for f f v= v f v= f v= and f v= are known as the co-factors of f w.r.t. v f = (X Æf v= ) Ç(Y Æf v= ) 58

BDD Operations: And Suppose this is the BDD for f f v= v f v= f v= and f v= are known as the co-factors of f w.r.t. v f = (:v Æf v= ) Ç(v Æf v= ) 59

BDD Operations: And (Simple Cases) And (f, ) = And (f, ) = f And (,f ) = f And (,f) = 6

BDD Operations: And (Complex Case) v Æ v 2 f f g g (:v Æf ) Ç(v Æf ) Æ (:v 2 Æg ) Ç(v 2 Æg ) 6

BDD Operations: And (Complex Case ) v = v 2 v Æ v f f g g (:v Æf ) Ç(v Æf ) Æ (:v Æg ) Ç(v Æg ) 62

BDD Operations: And (Complex Case ) v = v 2 (:v ÆX) Ç(v ÆY) (:v Æf ) Ç(v Æf ) Æ (:v Æg ) Ç(v Æg ) 63

BDD Operations: And (Complex Case ) v = v 2 Compute recursively (:v Æ(f Æg )) Ç(v Æ(f Æg )) (:v Æf ) Ç(v Æf ) Æ (:v Æg ) Ç(v Æg ) 64

BDD Operations: And (Complex Case ) v = v 2 What if f Æg = f Æg? v Return f Æg f Æg f Æg (:v Æ(f Æg )) Ç(v Æ(f Æg )) (:v Æf ) Ç(v Æf ) Æ (:v Æg ) Ç(v Æg ) 65

BDD Operations: And (Complex Case 2) v < v 2 v appears before v 2 in the variable ordering v Æ v 2 g f f g g (:v Æf ) Ç(v Æf ) Æ (:v 2 Æg ) Ç(v 2 Æg ) 66

BDD Operations: And (Complex Case 2) v < v 2 What if f Æg= f Æg? v Return f Æg f Æg f Æg (:v Æ(f Æg)) Ç(v Æ(f Æg)) (:v Æf ) Ç(v Æf ) Æ g O(n n 2 ) 67

BDD Operations: And BDD bddand (BDD f, BDD g) if (f == g f == True) return g if (g == True) return f if (f == False g == False) return False v = (var(f) < var(g))? var(f) : var(g) f = (v == var(f))? low(f) : f f = (v == var(f))? high(f) : f g = (v == var(g))? low (g) : g g = (v == var(g))? high (g) : g T = bddand (f, g); E = bddand (f, g) if (T == E) return T return mkunique (v, T, E) returns unique BDD for ite(v,t,e) 68

BDD Operations: Or Or(f,g) = Not ( And ( Not(f), Not(g) ) ) O(n n 2 ) 69

BDD Operations: Exists Exists(,v) =? 7

BDD Operations: Exists Exists(,v) = Exists(,v) =? 7

BDD Operations: Exists Exists(,v) = Exists(,v) = Exists((:v Æf) Ç(v Æg), v) =? 72

BDD Operations: Exists Exists(,v) = Exists(,v) = Exists((:v Æf) Ç(v Æg), v) = Or(f,g) Exists((:v Æf) Ç(v Æg), v) =? 73

BDD Operations: Exists O(n 2 ) Exists(,v) = Exists(,v) = Exists((:v Æf) Ç(v Æg), v) = Or(f,g) Exists((:v Æf) Ç(v Æg), v) = (:v ÆExists(f,v)) Ç(v ÆExists(g,v)) But f is SAT iff9v. f is not. So why doesn t this imply P = NP? Because the BDD size changes! 74

BDD Applications SAT is great if you are interested to know if a solution exists BDDs are great if you are interested in the set of all solutions How many solutions are there? How do you do this on a BDD? BDDs are great for computing a fixed points Set of nodes reachable from a given node in a graph 75

Graph Reachability 3 5 7 2 4 6 Which nodes are reachable from 7? {2,3,5,6,7} But what if the graph has trillions of nodes? 76

Graph Reachability 3 5 7 2 4 6 :a Æ:b Æ:c a Æb Æc Use three Boolean variables (a,b,c) to encode each node? 77

Graph Reachability 3 5 7 2 4 6 :a Æ:b Æ:c a Æb Æc a Æ:b Æ:c Use three Boolean variables (a,b,c) to encode each node? 78

Graph Reachability a Æ:b Æc 3 5 7 2 4 6 :a Æ:b Æ:c a Æb Æc a Æ:b Æ:c Use three Boolean variables (a,b,c) to encode each node? 79

Graph Reachability 3 5 7 2 4 6 a Æb Æ:c =? Key Idea : Every Boolean formula represents a set of nodes! The nodes whose encodings satisfy the formula. 8

Graph Reachability 3 5 7 2 4 6 a Æb Æ:c = {6} Key Idea : Every Boolean formula represents a set of nodes! 8

Graph Reachability 3 5 7 2 4 6 a Æ b =? Key Idea : Every Boolean formula represents a set of nodes! 82

Graph Reachability 3 5 7 2 4 6 a Æ b = {6,7} Key Idea : Every Boolean formula represents a set of nodes! 83

Graph Reachability 3 5 7 2 4 6 a xorb =? Key Idea : Every Boolean formula represents a set of nodes! 84

Graph Reachability 3 5 7 2 4 6 a xorb = {2,3,4,5} Key Idea : Every Boolean formula represents a set of nodes! 85

Graph Reachability 3 5 7 2 4 6 Key Idea 2: Edges can also be represented by Boolean formulas An edge is just a pair of nodes Introduce three new variables: a, b, c Formula represents all pairs of nodes (n,n ) that satisfy when n is encoded using (a,b,c) and n is encoded using (a,b,c ) 86

Graph Reachability 3 5 7 2 4 6 :a Æ:b Æ:c Æ:a Æ:b Æc Key Idea 2: Edges can also be represented by Boolean formulas 87

Graph Reachability 3 5 7 2 4 6 a Æ:b Æc Æ:a Æb Æ:c Key Idea 2: Edges can also be represented by Boolean formulas 88

Graph Reachability 3 5 7 2 4 6 a Æ:b Æc Æ:a Æb Æ:c Ç :a Æ:b Æ:c Æ:a Æ:b Æc Key Idea 2: Edges can also be represented by Boolean formulas 89

Graph Reachability 3 5 7 2 4 6 Variable renaming : replace a with a Image(S,R) = (9a,b,c. (S ÆR)) [ a \a, b \b, c \ c ] Key Idea 3: Given the BDD for a set of nodes S, and the BDD for the set of all edges R, the BDD for all the nodes that are adjacent to S can be computed using the BDD operations 9

Graph Reachability Algorithm S = BDD for initial set of nodes; R = BDD for all the edges of the graph; while (true) { I = Image(S,R); // compute adjacent nodes to S if (And(Not(S),I) == False) // no new nodes found break; S = Or(S,I); // add newly discovered nodes to result } return S; Symbolic Model Checking. Has been done for graphs with 2 nodes. 9