© 2011 carnegie mellon university binary decision diagrams part 2 15-414 bug catching: automated...
Post on 19-Dec-2015
213 views
TRANSCRIPT
![Page 1: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/1.jpg)
© 2011 Carnegie Mellon University
Binary Decision Diagrams Part 2
15-414 Bug Catching: Automated Program Verification and Testing
Sagar ChakiSeptember 14, 2011
![Page 2: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/2.jpg)
2
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDDs Recap
Typically mean Reduced Ordered Binary Decision Diagrams (ROBDDs)• Can be viewed as reduced forms of Ordered Binary Decision Trees
• Obtained by eliminating duplicate nodes and redundant nodes• Often substantially smaller than the OBDT
Canonical representation of Boolean formulas• Unlike other normal forms like CNF and DNF
Size of BDD depends critically on variable ordering
In practice, BDDs are built up from their components• Via (efficient) Boolean operations• Dynamic variable ordering used to manage BDD size
![Page 3: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/3.jpg)
3
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Running Example: Comparator
Comparator
a1 a2 b1 b2
(A) f = 1 , a1 = b1 Æ a2 = b2
(B) f = 1 , a1 = b1 Ç a2 = b2
![Page 4: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/4.jpg)
4
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Conjunctive Normal Form
(: a1 Ç b1 ) Æ (: b1 Ç a1) Æ (: a2 Ç b2 ) Æ (: b2 Ç a2)
(: b1 Ç a1 ) Æ (: a1 Ç b1) Æ (: a2 Ç b2 ) Æ (: b2 Ç a2)
(b1 Ç a1 ) Æ (: a1 Ç : b1) Æ (: a2 Ç b2 ) Æ (: b2 Ç a2)
(: a1 Ç b1 ) Æ (: b1 Ç a1) Æ (: a2 Ç : b2 ) Æ (b2 Ç a2)
![Page 5: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/5.jpg)
5
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Truth TableRow# a1 b1 a2 b2 f
0 0 0 0 0 0
1 0 0 0 1 1
2 0 0 1 0 0
3 0 0 1 1 1
4 0 1 0 0 0
5 0 1 0 1 1
6 0 1 1 0 0
7 0 1 1 1 0
8 1 0 0 0 0
9 1 0 0 1 1
10 1 0 1 0 1
11 1 0 1 1 0
12 1 1 0 0 1
13 1 1 0 1 0
14 1 1 1 0 0
15 1 1 1 1 0
![Page 6: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/6.jpg)
6
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Representing a Truth Table using a Graph
a1
b1 b1
a2 a2
b1 b2 b2 b2
a2 b2
b2 b2 a2 a2
![Page 7: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/7.jpg)
7
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Representing a Truth Table using a Graph
a1
b1 b1
a2 a2
b2 b2
1 0 1 1
b2 b2
1 0 0 0
a2 a2
b2 b2
1 0 0 0
b2 b2
0 0 0 0
![Page 8: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/8.jpg)
8
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
OBDT to ROBDD
a1
b1 b1
a2
b2 b2
10
a2
b2 b2
A B C D
Which pairs are isomorphic?
(1) {A,B} and {C,D}
(2) {A,C} and {B,D}
(3) {A,D} and {B,C}
![Page 9: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/9.jpg)
9
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
OBDT to ROBDD
a1
b1 b1
b2
10
a2
b2
Is this a ROBDD?
(1) YES
(2) NO
![Page 10: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/10.jpg)
10
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
OBDT to ROBDD
a1
b1 b1
b2
10
a2
b2
What function does X represent?
(1) a2 = b2 (2) a2 = (: b2)
(3) a2 ) b2 (4) a2 © b2
(5) :(a2 © b2)
(6) (a2 Æ b2) Ç (: a2 Æ : b2)
X1,5,6
![Page 11: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/11.jpg)
11
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
ROBDD (a.k.a. BDD) Summary
If BDD(f1) and BDD(f2) are isomorphic then:
1. f1 = f2
2. f1 and f2 have the same variables
3. BDD(f1) and BDD(f2) have the same variable ordering
If BDD(f) is the leaf node “1” then f is: 4. Satisfiable5. Unsatisfiable6. Valid
![Page 12: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/12.jpg)
12
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
ROBDD and variable ordering
a1
a2 a2
b1 b1
b2
1 0
b1 b1
b2 b2
Is this a ROBDD?
(1) YES
(2) NO
![Page 13: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/13.jpg)
13
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
ROBDD and variable ordering
a1
a2 a2
b1 b1
b2
1 0
b1 b1
b2
Is this a ROBDD?
(1) YES
(2) NO
![Page 14: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/14.jpg)
14
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
ROBDD and variable ordering
There exists a function whose BDD grows polynomially in the number of variables for some ordering and exponentially for others?• TRUE
There exists a function whose BDD grows exponentially for all variable orderings?• TRUE
There exists a function whose BDD grows linearly for all variable orderings?• TRUE
![Page 15: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/15.jpg)
15
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations
True : BDD(TRUE)
False: BDD(FALSE)
Var : v BDD(v)
Not : BDD(f) BDD(:f)
And : BDD(f1) £ BDD(f2) BDD(f1 Æ f2)
Or : BDD(f1) £ BDD(f2) BDD(f1 Ç f2)
Exist : BDD(f) £ v BDD(9 v. f)
![Page 16: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/16.jpg)
16
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Basic BDD Operations
True False
Var(v)
1 0
10
v
![Page 17: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/17.jpg)
17
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Not
1 00 1
10
v
O(1) O(1)
![Page 18: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/18.jpg)
18
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Not
1 00 1
01
v
Swap “0” and “1”
O(1) O(1)
O(n)
![Page 19: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/19.jpg)
19
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And
vWhat formula does this
represent?
What formula does this
represent?
Suppose this is the BDD for f
![Page 20: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/20.jpg)
20
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And
vfv=0
Suppose this is the BDD for f
fv=1
fv=0 and fv=1 are known as the co-factors of f w.r.t. v
f = (X Æ fv=0) Ç (Y Æ fv=1)
![Page 21: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/21.jpg)
21
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And
vfv=0
Suppose this is the BDD for f
fv=1
fv=0 and fv=1 are known as the co-factors of f w.r.t. v
f = (: v Æ fv=0) Ç (v Æ fv=1)
![Page 22: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/22.jpg)
22
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Simple Cases)
And (f, ) = 0 0
And (f, ) = 1 f
And ( ,f ) = 1 f
And ( ,f ) = 0 0
![Page 23: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/23.jpg)
23
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Complex Case)
v1
f1 g1
v2
f2 g2
(: v1 Æ f1) Ç (v1 Æ g1) (: v
2 Æ f2) Ç (v2 Æ g2)
ÆÆ
![Page 24: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/24.jpg)
24
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Complex Case 1)
v1
f1 g1
v1
f2 g2
(: v1 Æ f1) Ç (v1 Æ g1) (: v
1 Æ f2) Ç (v1 Æ g2)
ÆÆ
v1 = v2
![Page 25: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/25.jpg)
25
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Complex Case 1)
(: v1 Æ f1) Ç (v1 Æ g1) (: v
1 Æ f2) Ç (v1 Æ g2)Æ
v1 = v2
(: v1 Æ X) Ç (v1 Æ Y)
![Page 26: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/26.jpg)
26
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Complex Case 1)
(: v1 Æ f1) Ç (v1 Æ g1) (: v
1 Æ f2) Ç (v1 Æ g2)Æ
v1 = v2
(: v1 Æ (f1 Æ f2)) Ç (v1 Æ (g1 Æ g2))
Compute recursivelyCompute recursively
![Page 27: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/27.jpg)
27
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Complex Case 1)
(: v1 Æ f1) Ç (v1 Æ g1) (: v
1 Æ f2) Ç (v1 Æ g2)Æ
v1 = v2
(: v1 Æ (f1 Æ f2)) Ç (v1 Æ (g1 Æ g2))
v1
f1 Æ f2 g1 Æ g2
What if f1 Æ f2 = g1 Æ g2 ?
Return f1 Æ f2
![Page 28: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/28.jpg)
28
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Complex Case 2)
v1
f1 g1
v2
f2 g2
(: v1 Æ f1) Ç (v1 Æ g1) (: v
2 Æ f2) Ç (v2 Æ g2)
ÆÆ
v1 < v2
v1 appears before v2 in the variable
ordering
d2
![Page 29: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/29.jpg)
29
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: And (Complex Case 2)
(: v1 Æ f1) Ç (v1 Æ g1) d2Æ
v1 < v2
(: v1 Æ (f1 Æ d2)) Ç (v1 Æ (g1 Æ d2))
v1
f1 Æ d2 g1 Æ d2
What if f1 Æ d2 = g1 Æ d2 ?
Return f1 Æ d2
O(n1 £ n2)
![Page 30: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/30.jpg)
30
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Or
Or(d1,d2)
=
Not ( And ( Not(d1), Not(d2) ) )
O(n1 £ n2)
![Page 31: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/31.jpg)
31
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Exist
Exist(“0”,v) = ?
![Page 32: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/32.jpg)
32
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Exist
Exist(“0”,v) = “0”
Exist(“1”,v) = ?
![Page 33: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/33.jpg)
33
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Exist
Exist(“0”,v) = “0”
Exist(“1”,v) = “1”
Exist((: v Æ f) Ç (v Æ g) , v) = ?
![Page 34: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/34.jpg)
34
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Exist
Exist(“0”,v) = “0”
Exist(“1”,v) = “1”
Exist((: v Æ f) Ç (v Æ g) , v) = Or(f,g)
Exist((: v’ Æ f) Ç (v’ Æ g) , v) = ?
![Page 35: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/35.jpg)
35
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Operations: Exist
Exist(“0”,v) = “0”
Exist(“1”,v) = “1”
Exist((: v Æ f) Ç (v Æ g) , v) = Or(f,g)
Exist((: v’ Æ f) Ç (v’ Æ g) , v) =
(: v’ Æ Exist(f,v)) Ç (v’ Æ Exist(g,v))
O(n2)
But f is SAT iff 9 V. f is not “0”. So why doesn’t this imply P = NP?
Because the BDD size changes!
![Page 36: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/36.jpg)
36
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
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?
Or if your problem involves computing a fixed point• Set of nodes reachable from a given node in a graph
![Page 37: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/37.jpg)
37
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Application: Counting Sudoku Solutions
1
3 2
1 2 3 4
1
2
3
4
How many ways can you solve this puzzle?
![Page 38: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/38.jpg)
38
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Application: Counting Sudoku Solutions
0 3 1 2
2 1 0 3
3 0 2 1
1 2 3 0
1 2 3 4
1
2
3
4
How many ways can you solve this puzzle? At least 2.
![Page 39: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/39.jpg)
39
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Application: Counting Sudoku Solutions
0 3 1 2
1 2 0 3
3 0 2 1
2 1 3 0
1 2 3 4
1
2
3
4
How many ways can you solve this puzzle? At least 2.
![Page 40: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/40.jpg)
40
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Application: Counting Sudoku Solutions
1
3 2
1 2 3 4
1
2
3
4
a11,b11
a44,b44
![Page 41: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/41.jpg)
41
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Application: Counting Sudoku Solutions
1
3 2
1 2 3 4
1
2
3
4
: a13 Æ b13
a33 Æ : b33
a31 Æ b31
![Page 42: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/42.jpg)
42
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
BDD Application: Counting Sudoku Solutions
1
3 2
1 2 3 4
1
2
3
4
Distinct Elements
a11 © a12 Ç b11 © b12
Æ
a11 © a13 Ç b11 © b13
Æ
a11 © a14 Ç b11 © b14
Æ
a12 © a13 Ç b12 © b13
Æ
a12 © a14 Ç b12 © b14
Æ
a13 © a14 Ç b13 © b14
Repeat for each row, column and sub-square
Construct BDD
Count number of solutions
![Page 43: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/43.jpg)
43
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Which nodes are reachable from “7”?
{2,3,5,6,7}
But what if the graph has trillions of nodes?
![Page 44: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/44.jpg)
44
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Use three Boolean variables (a,b,c) to encode each node?
: a Æ : b Æ : ca Æ b Æ c
![Page 45: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/45.jpg)
45
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Use three Boolean variables (a,b,c) to encode each node?
: a Æ : b Æ : ca Æ b Æ c
a Æ : b Æ : c
![Page 46: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/46.jpg)
46
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Use three Boolean variables (a,b,c) to encode each node?
: a Æ : b Æ : ca Æ b Æ c
a Æ : b Æ : c
a Æ : b Æ c
![Page 47: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/47.jpg)
47
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Key Idea 1: Every Boolean formula represents a set of nodes!
a Æ b Æ : c = ?
The nodes whose encodings satisfy the formula.
![Page 48: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/48.jpg)
48
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Key Idea 1: Every Boolean formula represents a set of nodes!
a Æ b Æ : c = {6}
![Page 49: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/49.jpg)
49
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Key Idea 1: Every Boolean formula represents a set of nodes!
a Æ b = ?
![Page 50: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/50.jpg)
50
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Key Idea 1: Every Boolean formula represents a set of nodes!
a Æ b = {6,7}
![Page 51: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/51.jpg)
51
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Key Idea 1: Every Boolean formula represents a set of nodes!
a © b = ?
![Page 52: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/52.jpg)
52
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
Key Idea 1: Every Boolean formula represents a set of nodes!
a © b = {2,3,4,5}
![Page 53: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/53.jpg)
53
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
• 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’)
![Page 54: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/54.jpg)
54
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
: a Æ : b Æ : c Æ : a’ Æ : b’ Æ c’
Key Idea 2: Edges can also be represented by Boolean formulas
![Page 55: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/55.jpg)
55
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
a Æ : b Æ c Æ : a’ Æ b’ Æ : c’
Key Idea 2: Edges can also be represented by Boolean formulas
![Page 56: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/56.jpg)
56
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
a Æ : b Æ c Æ : a’ Æ b’ Æ : c’
Ç
: a Æ : b Æ : c Æ : a’ Æ : b’ Æ c’
Key Idea 2: Edges can also be represented by Boolean formulas
a Æ : b Æ c Æ : a’ Æ b’ Æ : c’
Ç
: a Æ : b Æ : c Æ : a’ Æ : b’ Æ c’
![Page 57: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/57.jpg)
57
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Graph Reachability
0
1
2
3
4
5
6
7
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
Image(S,R) =
(9 a,b,c . (S Æ R)) [ a \ a’, b \ b’, c \ c’]
Variable renaming : replace a’ with a
![Page 58: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/58.jpg)
58
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
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 1020 nodes.
![Page 59: © 2011 Carnegie Mellon University Binary Decision Diagrams Part 2 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki September](https://reader030.vdocument.in/reader030/viewer/2022032800/56649d2e5503460f94a055bd/html5/thumbnails/59.jpg)
59
Binary Decision Diagrams – Part 2Sagar Chaki, Sep 14, 2011
© 2011 Carnegie Mellon University
Questions?
Sagar ChakiSenior Member of Technical StaffRTSS ProgramTelephone: +1 412-268-1436Email: [email protected]
U.S. MailSoftware Engineering InstituteCustomer Relations4500 Fifth AvenuePittsburgh, PA 15213-2612USA
Webwww.sei.cmu.edu/staff/chaki
Customer RelationsEmail: [email protected]: +1 412-268-5800SEI Phone: +1 412-268-5800SEI Fax: +1 412-268-6257