0% found this document useful (0 votes)
6 views37 pages

Lec 09 BDD

The document discusses Binary Decision Diagrams (BDDs) and their significance in automated reasoning, particularly in SAT solving, which gained prominence in the 1990s. It covers the structure of BDDs, their optimization into Reduced Ordered BDDs (ROBDDs), and various algorithms for constructing and manipulating these data structures. The lecture emphasizes the historical context of BDDs in hardware verification and their eventual decline due to the emergence of faster methods.

Uploaded by

sanchita.iitb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views37 pages

Lec 09 BDD

The document discusses Binary Decision Diagrams (BDDs) and their significance in automated reasoning, particularly in SAT solving, which gained prominence in the 1990s. It covers the structure of BDDs, their optimization into Reduced Ordered BDDs (ROBDDs), and various algorithms for constructing and manipulating these data structures. The lecture emphasizes the historical context of BDDs in hardware verification and their eventual decline due to the emergence of faster methods.

Uploaded by

sanchita.iitb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

CS 433 Automated Reasoning 2025

Lecture 9: Going retro : binary decision diagram

Instructor: Ashutosh Gupta

IITB India

Compile date: 2025-02-08

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 1
Retro technology

Let us go back to 90’s

Commentary: SAT solving had become the focus of research by 90s. Many hard problems such as hardware verification naturally encode into SAT problem. There were
several algorithms and implementations. The first break through came in early 90’s.
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 2
Topic 9.1

Binary Decision Diagrams

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 3
First practical SAT solving

Binary Decision Diagram(BDD) is a data structure that enabled the first practical SAT solver.

BDDs came to prominence in early 90s.

J. R. Burch, E. M. Clarke, K. L. McMillan, D. L. Dill, and J. Hwang.


Symbolic model checking: 1020 states and beyond. Information and Computation, 1992.

CDCL has outsmarted BDD, but it is worth exploring.

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 4
Partial evaluation
Let us suppose a partial model m s.t. Vars(F ) ̸⊆ dom(m).
We can assign meaning to m(F ), which we will denote with F |m .
Definition 9.1
Let F be a formula and m = {p1 7→ b1 , ..} be a partial model.
(
F [⊤/xi ] if bi = 1
Let F |xi 7→bi ≜
F [⊥/xi ] if bi = 0.

The partial evaluation F |m be F |p1 7→b1 |p2 7→b2 | . . . after some simplifications.

For short hand, we may write F |p for F |p7→1 and F |¬p for F |p7→0 .

Exercise 9.1
Prove (F |p ∧ p) ∨ (F |¬p ∧ ¬p) ≡ F

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 5
Example : partial evaluation

Example 9.1
Consider F = (p ∨ q) ∧ r

F |p = ((p ∨ q) ∧ r )[⊤/p] = (⊤ ∨ q) ∧ r ≡ ⊤ ∧ r ≡ r

Exercise 9.2
Compute
▶ ((p ∨ q) ∧ r )|¬p
▶ ((p1 ⇔ q1 ) ∧ (p2 ⇔ q2 ))|p1 7→0,p2 7→0

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 6
Decision branch
Due to the theorem in exercise 9.1, the following tree may be viewed as representing F .

F |¬p F |p

Dashed arrows represent 0 decisions and solid arrows represent 1 decisions.


Example 9.2
Consider (p ∨ q) ∧ r

q∧r r

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 7
Decision tree

We may further expand F |¬p and F |p until we are left with ⊤ and ⊥ at the leaves. The obtained
tree is called the decision tree for F .
Example 9.3
Consider (p ∨ q) ∧ r

q r

⊥ r ⊥ ⊤

⊥ ⊤

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 8
Binary decision diagram(BDD)
If two nodes represent same formula, we may rewire the incoming edges to only one of the nodes.
Definition 9.2
A BDD is a finite DAG such that
▶ each internal node is labeled with a propositional variable
▶ each internal node has a low (dashed) and a high child (solid)
▶ there are exactly two leaves one is labelled with ⊤ and the other with ⊥

Example 9.4
p

q
The following is a BDD for (p ∨ q) ∧ r r
r

⊥ ⊤
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 9
Topic 9.2

Reduced ordered binary decision diagram (ROBDD)

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 10
Optimize BDD representation

▶ BDD may appear an inefficient representation of formulas.

▶ However, we can optimize BDDs and obtain canonical representation of formulas.

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 11
Ordered BDD (OBDD)
Definition 9.3
A BDD is ordered if there is an order < over variables including ⊤ and ⊥ such that for each node
v , v < low (v ) and v < high(v ).

Example 9.5
p

q r
The following BDD is not an ordered BDD
r q

⊥ ⊤

Exercise 9.3
a. Convert the above BDD into a formula
b. Give an ordered BDD of the formula
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 12
Reduced OBDD (ROBDD)
Definition 9.4
A OBDD is reduced if
▶ for any nodes u and v , if var (u) = var (v ), low (u) = low (v ), high(u) = high(v ) then u = v
▶ for each node u, low (u) ̸= high(u)

Example 9.6
OBDD ROBDD
p p

q q
r r
r

⊥ ⊤ ⊥ ⊤
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 13
Converting to ROBDD

Any OBDD can be converted into ROBDD by iteratively applying the following transformations.

1. If there are nodes u and v such that var (u) = var (v ), low (u) = low (v ), high(u) = high(v )
then remove u and connect all the parents of u to v .

2. If there is a node u such that low (u) = high(u) then remove u and connect all the parents of
u to low (u).

Exercise 9.4
Prove that the above iterations terminate.

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 14
Canonical ROBDD
Theorem 9.1
For a function f : B n → B there is unique ROBDD u with ordering p1 < · · · < pn such that u
represents f (p1 , . . . , pn ).

Proof. Commentary: All instance of f () = 0 and f () = 1 will use the


same node ⊥ and ⊤ respectively. We add nodes in the pool of
We use the induction over the number of parameters. nodes inductively.

base (n=0): There are only two functions f () = 0 and f () = 1, which are represented by nodes ⊥
and ⊤ respectively.

step: We assume, there are unique ROBDDs for functions with less than equal to n parameters.
Consider a function f : B n+1 → B.

Let f0 (p2 , . . . , pn+1 ) ≜ f (0, p2 , . . . , pn+1 ), which is represented by ROBDD u0 .


Let f1 (p2 , . . . , pn+1 ) ≜ f (1, p2 , . . . , pn+1 ), which is represented by ROBDD u1 . ...
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 15
Canonical ROBDD (cond.) II

Proof(contd.)
case u0 = u1 :

Therefore, f = f0 = f1 . Therefore, u0 represents f .

Assume there is u ′ ̸= u0 that represents f .

Therefore, var (u ′ ) = p1 (Why?) , low (u ′ ) = high(u ′ ) = u0 .

Therefore, u ′ is not a ROBDD. ...

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 16
Canonical ROBDD (cond.) III

Proof(contd.)
case u0 ̸= u1 :

Let u be such that var (u) = p1 , low (u) = u0 , and high(u) = u1 .


Commentary: Due to the induction hypothesis, u0 and u1
are maximally sharing nodes, i.e., if two nodes in u0 and u1
Clearly, u is a ROBDD. represent the same function, then they must be the same. There
is no further need of merger of nodes, when constructing u.

Assume there is u ′ ̸= u that represents f . Therefore, var (u ′ ) = p1 (Why?).

Due to induction hypothesis, low (u ′ ) = u0 , and high(u ′ ) = u1 .

Due to the reduced property, u = u ′ .

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 17
Exercise

Exercise 9.5
a. How many nodes are there in a ROBDD of an unsatisfiable formula?
a. How many nodes are there in a ROBDD of a valid formula?

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 18
Satisfiablility via BDD

Build a ROBDD that represents F .


▶ An unsat formula have only one node ⊥.

Benefits of ROBDD
▶ If intermediate ROBDDs are small then the satisfiability check will be efficient.
▶ Cost of computing ROBDDs vs sizes of BDDs
▶ Due to the canonicity property, ROBDD is used as a formula store
▶ Various operations on the ROBDDs are conducive to implementation

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 19
Issues with ROBDD

▶ BDDs are very sensitive to the variable ordering. There are formulas that have exponential
size ROBDDs for some orderings
▶ There is no efficient way to detect good variable orderings

Exercise 9.6
Draw the ROBDD for
(x1 ∧ x2 ) ∨ (x3 ∧ x4 )
with the following ordering on variables x1 < x3 < x2 < x4 .

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 20
Topic 9.3

Algorithms for BDDs

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 21
Algorithms for BDDs

Next we will present algorithms for BDDs to illustrate the convenience of the data structure.

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 22
Global data structures

The algorithms maintain the following two global data structures.

store = (Nodes, low , high, var ) := ({⊥, ⊤}, λx.null, λx.null, λx.null)

reverseMap : (Vars × Nodes × Nodes) → Nodes := λx.null

Commentary: λx.null stands for a map that takes any input and returns null. This notation is borrowed from λ calculus.
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 23
Constructing a BDD node

Algorithm 9.1: MakeNode(p, u0 , u1 )


Input: p ∈ Vars, u0 , u1 ∈ Nodes
if u0 = u1 then
return u0
if reverseMap.exists(p, u0 , u1 ) then
return reverseMap.lookup(p, u0 , u1 )
u := store.add(p, u0 , u1 ); // allocates a new node
reverseMap.add((p, u0 , u1 ), u);
return u

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 24
Constructing BDDs from a formula

Algorithm 9.2: BuildROBDD(F , p1 < · · · < pn )


Input: F (p1 , . . . , pn ) ∈ P, p1 < · · · < pn : an ordering over variables of F
if n = 0 then
if F ≡ ⊥ then return ⊥; else return ⊤;
u0 := BuildROBDD(F |¬p1 , p2 < · · · < pn );
u1 := BuildROBDD(F |p1 , p2 < · · · < pn );
return MakeNode(p1 , u0 , u1 )

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 25
Conjunction of BDDs
Algorithm 9.3: ConjBDDs(u, v )
Input: ROBDDs u and v with same variable ordering
if u = ⊥ or v = ⊤ then return u;
if u = ⊤ or v = ⊥ then return v ;
u0 := low (u);u1 := high(u);pu := var (u);
v0 := low (v );v1 := high(v );pv := var (v );
if pu = pv then
return MakeNode(pu ,ConjBDDs(u0 , v0 ),ConjBDDs(u1 , v1 ))
if pu < pv then
return MakeNode(pu ,ConjBDDs(u0 , v ),ConjBDDs(u1 , v ))
if pu > pv then
return MakeNode(pu ,ConjBDDs(u, v0 ),ConjBDDs(u, v1 ))

Exercise 9.7
Give an algorithm for computing disjunction of BDDs/not of a BDD.
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 26
Exercise: run ConjBDDs

Exercise 9.8
Consider order of variables p1 < p2 . a. Draw ROBDD for p1 ∧ p2 . Let us call the BDD u.
b. Draw ROBDD for ¬p1 . Let us call the BDD v .
c. Run ConjBDDs(u, v )

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 27
Restriction on a value

Algorithm 9.4: Restrict(u, p, b)


Input: ROBDD u with same variable ordering, variable p, b ∈ B
u0 := low (u);u1 := high(u);pu := var (u);
if pu = p and b = 0 then
return Restrict(u0 , p, b)
if pu = p and b = 1 then
return Restrict(u1 , p, b)
if pu < p then
return MakeNode(pu ,Restrict(u0 , p, b),Restrict(u1 , p, b))
if pu > p then
return u

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 28
Impact of BDDs

▶ In 90s, BDDs revolutionized hardware verification

▶ Later other methods were found that are much faster and the fall of BDD was marked by the
following paper,
A. Biere,A. Cimatti,E. Clarke,Y. Zhu,
Symbolic Model Checking without BDDs, TACAS 1999

▶ However, BDDs are still the heart of various software packages

Commentary: Maybe the methods that dominated the scene depend on the available computing power. The discoveries may have been predetermined. Once we reached
computation power of 90’s, we had BDDs. When we reached the computation power of 2000’s, we had CDCL and deep learning. Maybe when we will add a few more zeros
in our computing power, we may have entirely different methods that will dominate the computing scene.
cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 29
Problems with BDDs

▶ Doing more than finding a satisfiable solution

▶ Variable ordering is rigid

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 30
Topic 9.4

Problems

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 31
ROBDDs

Exercise 9.9
Construct ROBDD of the following formula for the order p < q < r < s.

F = (p ∨ (q ⊕ r ) ∨ (p ∨ s))

Let u be the ROBDD node that represents F . Give the output of Restrict(uF , p, b)

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 32
Variable reordering

Exercise 9.10
Let u be an ROBDD with variable ordering p1 < ... < pn . Give an algorithm for transforming u
into a ROBDD with ordering p1 < .. < pi−1 < pi+1 < pi < pi+2 < .. < pn .

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 33
BDD-XOR

Exercise 9.11
Write an algorithm for computing xor of BDDs

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 34
BDD encoding

Exercise 9.12
Consider a and b be 2 bit wide bit-vectors. Write BDD of each of three output bits in bit-vector
addition a + b.

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 35
BDD model counting

Exercise 9.13
a. Give an algorithm for counting models for a given ROBDD.
b. Does this algorithm work for any BDD?

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 36
End of Lecture 9

cbna CS 433 Automated Reasoning 2025 Instructor: Ashutosh Gupta IITB India 37

You might also like