Download presentation
Presentation is loading. Please wait.
1
Introduction to BDDs
2
Overview Decision trees and reduction rules
Building already reduced diagrams Dynamic variable reordering BDD operators Implementations issues (Dis)advantages of BDDs 2019年4月10日星期三
3
Truth Table, DNF, and CNF DNF (sum-of-products) CNF (product-of-sums)
F = x1’x2x3 + x1x2’x3 + x1x2x3 CNF (product-of-sums) F = (x1+x2+x3) & (x1+x2+x3’) & (x1+x2’+x3) & (x1’+x2+x3) & (x1’+x2’+x3) x1 x2 x3 F 1 2019年4月10日星期三
4
Truth Table and Decision Tree
x1 1 x2 x3 F x1 1 x2 x2 1 1 x3 x3 x3 x3 1 1 1 1 1 1 1 2019年4月10日星期三
5
Examples F = a F = ab F=a1b1+ a2b2 F=a1b1+a2+b2 F = a F = a+b a a1 a
1 b1 1 F = a a2 F = ab a2 a b2 b2 a b 1 1 1 1 F=a1b1+ a2b2 F=a1b1+a2+b2 F = a F = a+b 2019年4月10日星期三
6
Reduction of Decision Tree
Rule 2: Elimination Rule: Redundant tests should not be present Rule 1: Merging Rule: Nodes must be unique a a a a b b b b b b 2019年4月10日星期三
7
Example of Decision Tree Reduction
1 1 1 reduction Decision tree BDD 2019年4月10日星期三
8
BDD Construction Typically done using APPLY operator Reduction rules
remove duplicate terminals merge duplicate nodes (isomorphic subgraphs) remove redundant nodes Redundant nodes: nodes with identical children a b f 1 b c 2019年4月10日星期三
9
BDD Construction – your first BDD
Construction of a Reduced Ordered BDD 1 edge 0 edge f = ac + bc 1 a b c f a b c f Truth table Decision tree 2019年4月10日星期三
10
BDD Construction – cont’d
1 a b c f f 1 a b c f = (a+b)c 1 a b c 1. Remove duplicate terminals 2. Merge duplicate nodes 3. Remove redundant nodes 2019年4月10日星期三
11
Application to Verification
Equivalence of combinational circuits Canonicity property of BDDs: if F and G are equivalent, their BDDs are identical (for the same ordering of variables) F = a’bc + abc +ab’c 1 a b c G = ac +bc 1 a b c 2019年4月10日星期三
12
Application to Verification, cont’d
Functional test generation SAT, Boolean satisfiability analysis to test for H = 1 (0), find a path in the BDD to terminal 1 (0) the path, expressed in function variables, gives a satisfying solution (test vector) H 1 a b c ab ab’c 2019年4月10日星期三
13
Logic Manipulation using BDDs
Useful operators 1 F F’ Complement ¬ F = F’ (switch the terminal nodes) 1 F(x,y) x=b F(y) Restrict Restrict: F|x=b = F(x=b) where b = const 2019年4月10日星期三
14
Useful BDD Operators - cont’d
Apply: F G where stands for any Boolean operator (AND, OR, XOR, ) = F G 1 Any logic operation can be expressed using only Restrict and Apply Efficient algorithms, work directly on BDDs 2019年4月10日星期三
15
Apply Operation Basic operator for efficient BDD manipulation (structural) Based on recursive Shannon expansion F OP G = x (Fx OP Gx) + x’(Fx’ OP Gx’) where OP = OR, AND, XOR, etc 2019年4月10日星期三
16
Apply Operation - AND = = a AND c ac a c 1 a 2 1 a c 2.3 c 1 3 1.3 0.3
a 2 1 a c 2.3 = = c 1 3 c 1.3 AND 0.3 1.0 1.1 2019年4月10日星期三
17
Apply Operation - OR = = f = ac+bc ac bc a b c 1 a c 4 5 1 a b c 1 b c
a c 4 5 1 a b c bc 1 b c 6 7 c 4+6 0+0 a 7+5 1 0+6 b 6+5 0+5 0+7 OR = = 2019年4月10日星期三
18
Building Already Reduced Tree
assuming variable ordering x1 < x2 < x3 < … < xn function Build ( F, i ) if ( i > n ) if (F == 0) return Node0 else return Node1; else v0 = Build ( F(xi=0), i+1 ); v1 = Build ( F(xi=1), i+1 ); return CreateNode ( i, v0, v1 ); 2019年4月10日星期三
19
Creating a Unique Node assuming there is a node table and
functions CheckExists(), Insert(), and Hash() function CreateNode( Var, LowF, HighF ) if ( LowF == HighF ) return LowF; else if ( CheckExists( Var, LowF, HighF ) ) return the existing node; else Insert( Var, LowF, HighF ); return the new node; 2019年4月10日星期三
20
Variable Ordering F(x1, x2, y1, y2) = (x1 = y1) & (x2 = y2)
x1 < y1 < x2 < y x1 < x2 < y1 < y2 x1 x1 y1 y1 x2 x2 x2 y1 y1 y1 y1 y2 y2 y2 y2 1 1 2019年4月10日星期三
21
Dynamic Variable Reordering
F F F0 F1 x1 x2 x2 x2 F0 F1 x2 x2 x1 x1 x3 x3 x3 x3 x3 x3 x3 x3 Variable reordering is a local operation 2019年4月10日星期三
22
Characteristic Functions: Example
Problem: Given the set {p1, p2, p3, p4, p5, p6 }, create the characteristic function of the subset {p1, p3, p4} and represent it using BDDs Step 1: Introduce an encoding of the set p1 – p2 – p3 – p4 – p5 – p6 – Step 2: Define a function over the encoding variables (x1, x2, x3) such that it will be equal to 1 for minterms encoding the subset {p1, p3, p4}. 2019年4月10日星期三
23
Characteristic Functions: Example (continued)
{p1, p3, p4} ( x0, x1, x2 ) = = Step 3: Represent this function as a BDD x2 x1 x0 1 2019年4月10日星期三
24
Set Manipulation Operations on combinatorial sets can be reduced to boolean operations on characteristic functions Empty set: = 0 Union of sets: S T= S + T Intersection of sets: S T= S & T Difference of sets: S - T= S & T’ Subset relation (S T): S - T = S & T’ = 0 2019年4月10日星期三
25
Relations for Logic Blocks
Suppose variables (x1,x2,x3,…) and (y1,y2,y3,) are inputs and outputs of a logic block. Then, we can define a relation over variables (x1,x2,x3,…) and (y1,y2,y3,…). Suppose variables are related in the following way. Assignments (y1,y2,y3,…) correspond to values, which outputs take when values (x1,x2,x3,…) are applied at the inputs. 2019年4月10日星期三
26
Relations for Logic Blocks: Example
y1 y2 1 x1 y1 x2 y2 x3 2019年4月10日星期三
27
Example (continued) x1 x2 x3 y1 y2 1 other x1 x2 x3 y1 y2 F 1
1 x1 x2 x3 y1 y2 1 other 2019年4月10日星期三
28
Relations for FSMs: Example
Ins CS CSC NS NSC A 00 B 10 0,1 1 C 01 C 1 B A 1 0,1 2019年4月10日星期三
29
Example (continued) Relation = i'a1‘a2‘b1b2‘+ a1‘a2'b1'b2' + i'a1a2'b1b2' + ia1a2'b1'b2' + i'a1a2'b1b2' + ia1a2'b1'b2' i a1 b1 a2 b2 1 2019年4月10日星期三
30
Efficient Operations on BDDs
Apply – NOT, AND, OR, EXOR, etc. Quantification (existential, universal) Replace Compose Specialized operators Generalized cofactor (constrain, restrict) Compatible projection, etc. 2019年4月10日星期三
31
Components of BDDs and Their Use
Nodes (represent functions; complexity) Terminal nodes (constant functions) Edges (relationship between functions) Paths (true and false var. assignments) Cuts (variable partitions and subsets) 2019年4月10日星期三
32
Properties of BDDs Canonicity Compactness (with some exceptions)
Represent a variety of discrete objects Boolean functions Compositional sets Encodings and labelings Facilitate symbolic methods Two-level minimization State traversal of FSMs … 2019年4月10日星期三
33
(Dis)Advantages of BDDs
Universal (for discrete data only) Save memory (not always) Speed-up computation (not always) Attractive coding style (it depends…) Implicit computation (what about good old classical methods?) 2019年4月10日星期三
34
Overview ITE operator APPLY operator RESTRICT operator
Derived operators The effect of variable ordering Deriving the Upper Bound on BDD Size for Boolean Functions Dynamic variable reordering 2019年4月10日星期三
35
IF-THEN-ELSE (ITE) Operator
Boolean operations over 2 arguments can be expressed as ITE of F, G, and constants ITE( F, G, H ) = F & G + F’ & H Example: AND( F, G ) = ITE( F, G, 0 ) Computation of boolean operations is based on the Shannon expansion ITE(F,G,H) = ITE(x, ITE(Fx’,Gx’,Hx’), ITE(Fx,Gx,Gx) ) 2019年4月10日星期三
36
APPLY operator APPLY( F, G ) operator is a shorthand for any two-variable boolean operator APPLY is reducible to ITE It follows that APPLY can be computed recursively just like ITE APPLY(F,G) = x’ & APPLY(Fx’,Gx’) + x & APPLY(Fx ,Gx ) 2019年4月10日星期三
37
Pseudocode for APPLY operator
function Apply( F, G ) if ( AlreadyComputed( F, G ) ) return the result; else if ( F=={0,1} && G=={0,1} ) return oper( F, G ); else if ( Var( F ) == Var( G ) ) u = CreateNode( Var(F), Apply(Fx’,Gx’), Apply(Fx,Gx)); else if ( Var( F ) < Var( G ) ) u = CreateNode( Var(F) , Apply(Fx’,G ), Apply(Fx,G )); else /* if ( Var( F ) > Var( G ) ) */ u = CreateNode( Var(F) , Apply(F,Gx’ ), Apply(F,Gx )); InsertComputed( F,G,u ); return u; 2019年4月10日星期三
38
F=ac+bc+d G=ac’+d F+G = ?
A1,B1 A1 B1 a a A2,B2 A2 b + A6,B2 A6,B5 A6 c B5 c A3 B2 A3,B2 A5,B2 A3,B4 d d A4,B3 1 1 A5,B4 A4 A5 B3 B4 2019年4月10日星期三
39
F=ac+bc+d G=ac’+d F+G=a+bc+d
1 1 A4,B3 A5,B4 1 1 2019年4月10日星期三
40
Pseudocode for RESTRICT operator
function Restrict( F, var, value ) if ( AlreadyComputed( F, var, value ) ) return result; else if ( Var( F ) > var ) return F; else if ( Var( F ) < var ) u = CreateNode( Var(F), Restrict(Fx’, var, value), Restrict(Fx, var, value) ); InsertComputed(F, var, value, u ); return u; else /* ( Var( F ) == var */ if ( value == 0 ) return = Restrict(Fx’, var, value); else /* ( Var( F ) == var && value == 1 ) */ return = Restrict(Fx , var, value); 2019年4月10日星期三
41
F=bc+ab’c’ F(b=1) = ? a a b b b b c c c c c 1 1 1 2019年4月10日星期三
42
Derived Operations: COMPOSE
Given F(x) and G(y), find F(G(y)) Using Shannon Expansion F(x) = x’ & Fx’ x & Fx F(G(y)) = G’(y) & Fx’ + G(y) & Fx COMPOSE is reduced to two operations RESTRICT and three operations APPLY 2019年4月10日星期三
43
Derived Operations: Quantification
Given a function F(x1, x2, x3) Existential quantification of F w.r.t. x1 is x1 F(x1, x2, x3) = F(0, x2, x3) + F(1, x2, x3) Universal quantification of F w.r.t. x1 is x1 F(x1, x2, x3) = F(0, x2, x3) & F(1, x2, x3) Unique quantification of F w.r.t. x1 is !x1 F(x1, x2, x3) = F(0, x2, x3) F(1, x2, x3) 2019年4月10日星期三
44
Summery of Operations on BDDs
Apply – NOT, AND, OR, EXOR, etc. Restrict Compose (Replace) Quantification (existential, universal) Specialized operators Generalized cofactor (constrain, restrict) Compatible projection, etc. 2019年4月10日星期三
45
Worst-Case Complexity
CreateNode - O(1) Build - O(2n) APPLY - O(|F|*|G|) RESTRICT - O(|F|) COMPOSE - O(|F|2 *|G|2) 2019年4月10日星期三
46
Variable Ordering for F=a1b1+ a2b2
1 1 a1<b1<a2< b2 a1<a2<b1< b2 2019年4月10日星期三
47
Dynamic Variable Reordering
F F F0 F1 x1 x2 x2 x2 F0 F1 x2 x2 x1 x1 x3 x3 x3 x3 x3 x3 x3 x3 Variable reordering is a local operation 2019年4月10日星期三
48
Introduction to BDDs: References
Henrik Reif Andersen. An Introduction to Binary Decision Diagrams. Dept. of Information Technology, Technical University of Denmark, 1997. R. E. Bryant. Symbolic Boolean Manipulation with Ordered Binary Decision Diagrams. ACM Computing Surveys, Vol. 24, No. 3 (September, 1992), pp R. E. Bryant. Graph-Based Algorithms for Boolean Function Manipulation. IEEE Transactions on Computers, Vol. C-35, No. 8 (August, 1986), pp Reprinted in M. Yoeli, Formal Verification of Hardware Design, IEEE Computer Society Press, 1990, pp 2019年4月10日星期三
49
Existential Quantification
Existential quantification (abstraction) x f = f |x=0 + f |x=1 Example: x (x y + z) = y + z Note: x f does not depend on x (smoothing) Useful in symbolic image computation (sets of states) 2019年4月10日星期三
50
Existential Quantification - cont’d
Function can be existentially quantified w.r.to a vector: X = x1x2… X f = x1x2... f = x1 x2 ... f Can be done efficiently directly on a BDD Very useful in computing sets of states Image computation: next states Pre-Image computation: previous states from a given set of initial states 2019年4月10日星期三
51
Image Computation Computing set of next states from a given initial state (or set of states) Img( S,R ) = u S(u) • R(u,v) Img(v) R(u,v) S(u) FSM: when transitions are labeled with input predicates x, quantify w.r.to all inputs (primary inputs and state var) Img( S,R ) = x u S(u) • R(x,u,v) 2019年4月10日星期三
52
Image Computation - example
Compute a set of next states from state s1 Encode the states: s1=00, s2=01, s3=10, s4=11 Write transition relations for the encoded states: R = (ax’y’X’Y + a’x’y’XY’ + xy’XY + ….) s1 s2 s3 s4 a a’ 00 01 10 11 a xy XY ………. 2019年4月10日星期三
53
Example - cont’d Compute Image from s1 under R
Img( s1,R ) = a xy s1(x,y) • R(a,x,y,X,Y) = a xy (x’y’) • (ax’y’X’Y + a’x’y’XY’ + xy’XY + ….) = axy (ax’y’X’Y + a’x’y’XY’ ) = (X’Y + XY’ ) = {01, 10} = {s2,s3} s1 s2 s3 s4 a a’ 00 01 10 11 Result: a set of next states for all inputs s1 {s2, s3} 2019年4月10日星期三
54
Pre-Image Computation
Computing a set of present states from a given next state (or set of states) Pre-Img( S’,R) = v R(u,v) )• S’(v) S’(v) R(u,v) Pre-Img(u) Similar to Image computation, except that quantification is done w.r.to next state variables The result: a set of states backward reachable from state set S’, expressed in present state variables u Useful in computing CTL formulas: AF, EF 2019年4月10日星期三
55
Model Checking Example
Traffic light controller (simplified) G2 Y2 R2 G1 Y1 R1 C Timer T sensor Road 2 Road 1 R1 G2 Y1 R2 G1 R2 R1 Y2 C ’+ T ’ C T C T ’ C ’+ T G1 R2 Y1 R2 R1 G2 R1 Y2 C = car sensor T = timer
56
Traffic light controller - Model Checking
Model Checking task: check safety condition fairness conditions Safety condition: no green lights on both roads at the same time A G ¬ (G1 G2 ) Fairness condition: eventually one road has green light E F (G1 G2) R1 G2 Y1 R2 G1 R2 R1 Y2 C ’+T ’ C T C T ’ C ’+T 2019年4月10日星期三
57
Explicit Model Checking - complexity
CTL model checking is linear in the size of the formula and the size of the structure M Not a good news: what if you have 1050 states? Number of states grows exponentially with number of variables Explicit model checking limited to … 109 states Symbolic model checking can do much better 2019年4月10日星期三
58
Symbolic Model Checking
operates on entire sets rather than individual states Uses BDD for efficient representation represent Kripke structure manipulate Boolean formulas RESTRICT and APPLY logic operators Quantification operators Existential: x f = f |x=0 + f |x=1 (smoothing) Universal: x f = f |x=0 • f |x=1 (consensus) 2019年4月10日星期三
59
Symbolic Model Checking - example Traffic Light Controller
Encode the atomic propositions (G1,R1,Y1, G2,Y2,R2): use [a b c d] for present state, [v x y z] for next state R1 G2 Y1 R2 G1 R2 R1 Y2 s1 s3 s4 s2 11 10 10 01 01 10 10 11 a b c d G Y R G Y R 2019年4月10日星期三
60
Example - cont’d Represent the set of states as Boolean formula Q: Q = abcd’ + a’bcd’ + ab’cd + ab’c’d R1 G2 Y1 R2 G1 R2 R1 Y2 s1 s3 s4 s2 11 10 10 01 01 10 10 11 Store Q in a BDD (It will be used to perform logic operations, such as S(G1) S(G2) 2019年4月10日星期三
61
Example - cont’d Write a characteristic function R for the transition relation R =abcd’vxyz’ + abcd’v’xyz’ + … + ab’c’dvxyz’ (6 terms) R1 G2 Y1 R2 G1 R2 R1 Y2 s1 s3 s4 s2 11 10 10 01 01 10 10 11 abcd vxyz R Store R in a BDD. It will be used for Pre-Image computation for EF. 2019年4月10日星期三
62
Example - Fairness Condition
Check fairness condition: E F (G1 G2 ) Step 1: compute S(G1), S(G2) using RESTRICT operator S(G1): ab·Restrict Q(G1) = ab Q|ab = abcd’ = {s1} S(G2): cd·Restrict Q(G2) = cd Q|cd = ab’cd = {s3} Step 2: compute S(G1) S(G2 ) using APPLY operator Construct BDD for (abcd’ + ab’cd) = {s1, s3}, set of states labeled with G1 or G2 2019年4月10日星期三
63
Example – cont’d s’ {s1’,s3’} • R(s,s’) ) =
Step 3: compute S(EF (G1 G2 )) using Pre-Image computation (quanitfy w.r.to next state variables) Recall: R = abcd’vxyz’ + abcd’v’xyz’+ … + ab’c’dvxyz’ s’ {s1’,s3’} • R(s,s’) ) = = vxyz(vxyz’ + vx’yz) • R(a,b,c,d;v,x,y,z) = vxyz(abcd’vxyz’ + a’bcd’vx’yz + ab’cdvx’yz + ab’c’dvxyz’) = (abcd’ + a’bcd’ + ab’cd + ab’c’d) = {s1, s2, s3, s4} Compare to the result of explicit algoritm 2019年4月10日星期三
64
Example – Interpretation
Pre-Img(s1’,s3’,R) eliminates those transitions which do not reach {s1,s3} R1 G2 Y1 R2 G1 R2 R1 Y2 s1 s3 s4 s2 11 10 10 01 01 10 10 11 abcd vxyz R X Quantification w.r.to next state variables (v,x,y,z) gives the encoded present states {s1,s2,s3,s4} 2019年4月10日星期三
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.