Alessandro Artale (FM First Semester 2009/2010) p. 1/38 FORMAL METHODS LECTURE VI BINARY DECISION DIAGRAMS (BDD S) Alessandro Artale Faulty of Computer Siene Free University of Bolzano artale@inf.unibz.it http://www.inf.unibz.it/ artale/ Some material (text, figures) displayed in these slides is ourtesy of: M. Benereetti, A. Cimatti, M. Fisher, F. Giunhiglia, M. Pistore, M. Roveri, R.Sebastiani.
Alessandro Artale (FM First Semester 2009/2010) p. 2/38 Summary of Leture VI Motivations. Ordered Binary Deision Diagrams (OBDD). OBDD s as Canonial Forms. Building OBDD s.
Alessandro Artale (FM First Semester 2009/2010) p. 3/38 State Spae Explosion The bottlenek: Exhaustive analysis may require to store all the states of the Kripke struture, and to explore them one-by-one. The state spae may be exponential in the number of omponents and variables (E.g., 300 boolean vars up to 2 300 10 100 states!) State Spae Explosion: Too muh memory required; Too muh CPU time required to explore eah state. A solution: Symboli Model Cheking.
Alessandro Artale (FM First Semester 2009/2010) p. 4/38 Symboli Model Cheking: Intuitions Symboli representation of Set of states by formulae in propositional logi. manipulation of sets of states, rather than single states; manipulation of sets of transitions, rather than single transitions.
Alessandro Artale (FM First Semester 2009/2010) p. 5/38 Summary Motivations. Ordered Binary Deision Diagrams (OBDD). OBDD s as Canonial Forms. Building OBDD s
Alessandro Artale (FM First Semester 2009/2010) p. 6/38 Ordered Binary Deision Diagrams (OBDD) Ordered Binary Deision Diagrams (OBDD) are used to represent formulae in propositional logi. A simple version: Binary Deision Trees: Non-Terminal nodes labeled with boolean variables/propositions; Leaves (terminal nodes) are labeled with either 0 or 1; Two kinds of lines: dashed and solid; Paths leading to 1 represent models, while paths leading to 0 represent ounter-models.
Alessandro Artale (FM First Semester 2009/2010) p. 7/38 Binary Deision Trees: An Example BDT representing the formula: ϕ = x y. x y y 1 0 0 0 The assignment, x = 0,y = 0, makes true the formula.
Alessandro Artale (FM First Semester 2009/2010) p. 8/38 Binary Deision Trees (BDT) Let T be a BDT, then T determines a unique boolean formula in the following way: Fixed an assignment for the variables in T we start at the root and: If the value of the variable in the urrent node is 1 we follow the solid line; Otherwise, we follow the dashed line; The truth value of the formula is given by the value of the leaf we reah.
Alessandro Artale (FM First Semester 2009/2010) p. 9/38 Binary Deision Trees (Cont.) BDT s with multiple ourrenes of a variable along a path are: 1. Rather ineffiient (Redundant paths); 2. Diffiult to hek whether they represent the same formula (equivalene test). Example of two equivalent BDT s x x y z y y x 1 y x 0 1 0 1 0 1 0 1 z 1 0 1
Ordered Deision Trees Ordered Deision Tree (OBDT): from root to leaves variables are enountered always in the same order without repetitions along paths. Example: Ordered Deision tree for ϕ = (a b) ( d) a b b d d d d d d d d 0 0 0 1 0 0 0 1 0 0 0 1 1 1 1 1 Alessandro Artale (FM First Semester 2009/2010) p. 10/38
Alessandro Artale (FM First Semester 2009/2010) p. 11/38 Summary Motivations. Ordered Binary Deision Diagrams (OBDD). OBDD s as Canonial Forms. Building OBDD s
Alessandro Artale (FM First Semester 2009/2010) p. 12/38 Reduing the size of Ordered Deision Trees OBDT s are still exponential in the number of variables: Given n variables the OBDT s will have 2 n+1 1 nodes! We an redue the size of OBDT s by a reursive appliations of the following redutions: Remove Redundanies: Nodes with same left and right hildren an be eliminated; Share Subnodes: Roots of struturally idential sub-trees an be ollapsed.
Alessandro Artale (FM First Semester 2009/2010) p. 13/38 Redution: Example a b b d d d d d d d d 0 0 0 1 0 0 0 1 0 0 0 1 1 1 1 1
Alessandro Artale (FM First Semester 2009/2010) p. 14/38 Redution: Example (Cont.) Detet redundaies: a b b d d d d d d d d 0 0 0 1 0 0 0 1 0 0 0 1 1 1 1 1
Alessandro Artale (FM First Semester 2009/2010) p. 15/38 Redution: Example (Cont.) Remove redundaies: a b b 0 d 0 d 0 d 1 1 0 1 0 1 0 1
Alessandro Artale (FM First Semester 2009/2010) p. 16/38 Redution: Example (Cont.) Remove redundaies: a b b 1 0 d 0 d 0 d 0 1 0 1 0 1
Alessandro Artale (FM First Semester 2009/2010) p. 17/38 Redution: Example (Cont.) Share idential nodes: a b b 1 0 d 0 d 0 d 0 1 0 1 0 1
Alessandro Artale (FM First Semester 2009/2010) p. 18/38 Redution: Example (Cont.) Share idential nodes: a b b 0 d 1
Alessandro Artale (FM First Semester 2009/2010) p. 19/38 Redution: Example (Cont.) Detet redundanies: a b b 0 d 1
Alessandro Artale (FM First Semester 2009/2010) p. 20/38 Redution: Example (Cont.) Remove redundanies: a b 0 d 1 Final OBDD!
Alessandro Artale (FM First Semester 2009/2010) p. 21/38 OBDD s as Canonial Forms Definition. Given two OBDD s, B ϕ,b ψ, they have a ompatible variable ordering if there are no variables x,y suh that x < y in B ϕ while y < x in B ψ. Theorem. A Redued OBDD is a Canonial Form of a boolean formula: One a variable ordering is established (i.e., OBDD s have ompatible variable ordering), equivalent formulas are represented by the same OBDD: ϕ 1 ϕ 2 iff OBDD(ϕ 1 ) OBDD(ϕ 2 )
Alessandro Artale (FM First Semester 2009/2010) p. 22/38 Importane of OBDD s Canonial forms for OBDD s allow us to perform in an effiient way the following tests: Equivalene hek is simple: We test whether the redued and order ompatible OBDD s have idential struture. Validity hek requires onstant time! ϕ iff the redued OBDD B ϕ B (un)satisfiability hek requires onstant time! ϕ iff the redued OBDD B ϕ B The set of the paths from the root to 1 represent all the models of the formula; The set of the paths from the root to 0 represent all the ounter-models of the formula.
Alessandro Artale (FM First Semester 2009/2010) p. 23/38 Importane of Variable Ordering Changing the ordering of variables may inrease the size of OBDD s. Example, two OBDD s for the formula: ϕ = (a1 b1) (a2 b2) (a3 b3) a1 a1 b1 b1 a2 a2 a2 a3 a3 a3 a3 b2 b2 b1 b1 b1 b1 b1 b1 b1 b1 a3 b2 b2 b2 b2 b3 b3 b3 b3 True False True False Linear size Exponential size
Alessandro Artale (FM First Semester 2009/2010) p. 24/38 Summary Motivations. Ordered Binary Deision Diagrams (OBDD). OBDD s as Canonial Forms. Building OBDD s.
Alessandro Artale (FM First Semester 2009/2010) p. 25/38 The REDUCE Algorithm Notation. Given a non-terminal node, n, then lo(n) denotes the node pointed via the dashed line, while hi(n) denotes the node pointed by the solid line. Given an OBDD, REDUCE proeeds bottom-up assigning an integer label, id(n), to eah node: 1. Assign label 0 to all 0-terminals and label 1 to all 1-terminals. Given now a non-terminal node for x i, say n, then: 2. If id(lo(n)) = id(hi(n)), then id(n) = id(lo(n)); 3. If there is another node for x i, say m, suh that id(lo(n)) = id(lo(m)) and id(hi(n)) = id(hi(m)), then, id(n) =id(m); 4. Otherwise we set id(n) to the next unused integer.
Alessandro Artale (FM First Semester 2009/2010) p. 26/38 The Redue Algorithm (Cont) REDUCE Final Step: Collapsing nodes with the same label and redireting edges aordingly with the node ollapsing. Example: See Figure 6.14 from the book.
Alessandro Artale (FM First Semester 2009/2010) p. 27/38 Reursive struture of OBDD s Given a formula ϕ and a variable ordering X = {x 1,x 2,...,x n }, the algorithm to build OBDD s from formulas, OBDD(ϕ,X), operates reursively: 1. If ϕ =, then, OBDD(,X) = B = 1; 2. If ϕ =, then, OBDD(,X) = B = 0; 3. If ϕ = x i, then, OBDD(x i,x) = B xi x i 1 0 4. If ϕ = ϕ 1, then, OBDD( ϕ 1,X) is obtained by negating the terminal nodes of OBDD(ϕ 1,X); 5. If ϕ = ϕ 1 op ϕ 2 (op a binary boolean operator), then, OBDD(ϕ 1 op ϕ 2,X) =apply(op,obdd(ϕ 1,X),OBDD(ϕ 2,X)).
Alessandro Artale (FM First Semester 2009/2010) p. 28/38 The algorithm APPLY Given two OBDD s, B ϕ,b ψ, the all apply(op,b ϕ,b ψ ) omputes the redued OBDD of the formula ϕ op ψ. The algorithms operates reursively on the struture of the two OBDD s: 1. Let x be the variable highest in the ordering whih ours in B ϕ or B ψ, then 2. Split the problem in two sub-problems: one for x being true and the other for x being false and solve reursively; 3. At the leaves, apply the boolean operation diretly.
Alessandro Artale (FM First Semester 2009/2010) p. 29/38 The algorithm APPLY (Cont.) Definition. Let ϕ be a formula and x a variable. We denote by ϕ[0/x] (ϕ[1/x]) the formula obtained by replaing all ourrenes of x in ϕ by 0 (1). This allow us to split boolean formulas in simpler ones. Lemma [Shannon Expansion]. Let ϕ be a formula and x a variable, then: ϕ (x ϕ[1/x]) ( x ϕ[0/x]) The funtion APPLY is based on the Shannon Expansion: ϕopψ (x (ϕ[1/x]opψ[1/x])) ( x (ϕ[0/x]opψ[0/x]))
Alessandro Artale (FM First Semester 2009/2010) p. 30/38 The algorithm APPLY (Cont.) Apply(op,B ϕ,b ψ ) proeeds from the roots downward. Let r ϕ,r ψ the roots of B ϕ,b ψ respetively: 1. If both r ϕ,r ψ are terminal nodes, then, Apply(op,B ϕ,b ψ ) =B (rϕ op r ψ ); 2. If both roots are x i -nodes, then reate an x i -node with a dashed line to Apply(op,B lo(rϕ ),B lo(rψ )) and a solid line to Apply(op,B hi(rϕ ),B hi(rψ )); 3. If r ϕ is an x i -node, but r ψ is a terminal node or an x j -node with j > i (i.e., ψ[0/x i ] ψ[1/x i ] ψ), then reate an x i -node with dashed line to Apply(op,B lo(rϕ ),B ψ ) and solid line to Apply(op,B hi(rϕ ),B ψ ); 4. If r ψ is an x i -node, but r ϕ is a terminal node or an x j -node with j > i, is handled as above.
Alessandro Artale (FM First Semester 2009/2010) p. 31/38 OBBD Inremental Building: An Example ϕ = (A 1 A 2 ) (A 1 A 2 ) ( A 1 A 2 ) ( A 1 A 2 ) (A1 v A2) (A1 v A2) ( A1 v A2) ( A2 v A2) A1 A1 A1 A1 A2 A2 A2 A2 T F T F T F T F (A1 v A2) ^ (A1 v A2) ( A1 v A2) ^ ( A1 v A2) A1 A1 T F T F (A1 v A2) ^ (A1 v A2) ( A1 v A2) ^ ( A1 v A2) ^ F
Alessandro Artale (FM First Semester 2009/2010) p. 32/38 Boolean Quantifiation Quantifying over boolean variables is a ruial operation to ompute Preimages (i.e., the next-time operator). If x is a boolean variable, then x.ϕ ϕ[0/x] ϕ[1/x] x.ϕ ϕ[0/x] ϕ[1/x] Let W = {w 1,...,w n ). Multi-variable quantifiation: W.ϕ (w 1,...,w n ).ϕ w 1... w n.ϕ
Alessandro Artale (FM First Semester 2009/2010) p. 33/38 The RESTRICT Algorithm To ompute the OBDD for x.ϕ we need to ompute the OBDD for both ϕ[0/x] and ϕ[1/x]. B ϕ[0/x] = RESTRICT(0,x,B ϕ ). For eah node n labeled with x, then: 1. Inoming edges are redireted to lo(n); 2. n is removed. B ϕ[1/x] = RESTRICT(1,x,B ϕ ). As above, only rediret inoming edges to hi(n).
Alessandro Artale (FM First Semester 2009/2010) p. 34/38 Boolean Quantifiation (Cont.) B x.ϕ = APPLY(, RESTRICT(0,x,B ϕ ), RESTRICT(1,x,B ϕ )) x 1 x 1 x 1 y 1 y 1 y 1 x 2 x 2 x 2 y 2 y 2 y 2 x 3 y 3 y 3 0 1 0 1 0 1 B ϕ RESTRICT(0,x 3,B ϕ ) RESTRICT(1,x 3,B ϕ )
Alessandro Artale (FM First Semester 2009/2010) p. 35/38 Boolean Quantifiation (Cont.) B x.ϕ = APPLY(, RESTRICT(0,x,B ϕ ), RESTRICT(1,x,B ϕ )) x 1 x 1 x 1 y 1 y 1 y 1 x 2 x 2 x 2 y 2 y 2 y 2 y 3 y 3 0 1 0 1 0 1 RESTRICT(0,x 3,B ϕ ) RESTRICT(1,x 3,B ϕ ) x 3.B ϕ
Alessandro Artale (FM First Semester 2009/2010) p. 36/38 Time Complexity Algorithm Time-Complexity REDUCE(B) O( B log B ) APPLY(op,B ϕ,b ψ ) O( B ϕ B ψ ) N.B. The above omplexity results depend from the size of the input OBDD s: The size of OBDD s may grow exponentially wrt. the number of variables in worst-ase. Example: there exist no polynomial-size OBDD representing the eletroni iruit of a bitwise multiplier.
Alessandro Artale (FM First Semester 2009/2010) p. 37/38 OBDD Summary Require setting a variable ordering a priori (ritial!) Normal representation of a boolean formula. One built, logial operations (satisfiability, validity, equivalene) immediate. Represents all models and ounter-models of the formula. Require exponential spae in worst-ase.
Alessandro Artale (FM First Semester 2009/2010) p. 38/38 Summary of Leture VI Motivations. Ordered Binary Deision Diagrams (OBDD). OBDD s as Canonial Forms. Building OBDD s.