Binary Decision Trees
• Definition: A binary decision tree is a tree whose non-terminal nodes are labelled with boolean variables x, y, z, … and whose terminal nodes are labelled with either 0 or 1. Each non- terminal node has two edges, one dashed line and one solid line.
x
y y
1 0 0 0 1 Binary Decision Trees (continued)
• Definition: Let T be a finite binary decision tree. Then T determines a unique Boolean function of the variables in non-terminal nodes, in the following way. Given an assignment of 0s and 1s to the Boolean variables occurring in T, we start at the root of T and take the dashed line whenever the value at the current node is 0; otherwise, we travel along the solid line. The function value is the value of the terminal node we reach.
2 An example
• f(x, y) = ¬(x + y) x
y y
1 0 0 0
3 Some optimization techniques Binary Decision Diagrams (BDDs)
x
y y
1 0
4 Some optimization techniques (continued)
x
y
1 0
5 A BDD with duplicated sub-BDDs
z
x x
y y y y
0 1
6 After removal of one of the duplicate y-nodes
z
x x
y y y
0 1
7 After removal of another duplicate y-nodes and then a redundant x-decision point
z
x
y y
0 1
8 Three ways of reducing a BDD
• Removal of a duplicate terminals. • Removal of a redundant tests. • Removal of duplicate non-terminals.
9 Directed Acyclic Graphs (DAGs)
• A directed acyclic graph(dag) is a directed graph that does not have any cycles. A node of a dag is initial if there are no edges pointing to that node. A node is terminal if there are no edges out of that node.
10 Binary Decision Diagram (BDD)
• Definition: A binary decision diagram(BDD) is a finite dag with a unique initial node, where all terminal nodes are labeled with 0 or 1 and all non-terminal nodes are labeled with a Boolean variable. Each non-terminal node has exactly two edges from that node to others: one labeled 0 and one labeled 1 ( we represent them as a dashed line and a solid line, respectively). A BDD is said to be reduced if none of the earlier three optimization techniques can be applied (i.e., no more reductions are possible).
11 Ordered Binary Decision Diagrams (OBDDs)
• Definition: Let [x 1, …, x n] be an ordered list of variables without duplications and let B be a BDD all of whose variables occur somewhere in
the list. We say B has the ordering [x 1, …, x n] if all variables labels of B occur in that list and, for
every occurrence of x j followed by x j along any path in B, we have i < j. • An orderedBDD (OBDD) is a BDD which has an ordering for some list of variables.
12 Examples of a BDD (left) and an OBDD (right)
x x
y z y y
x y x z
1 0 1 0
13 Reduced OBDDs as Canonical forms
• Theorem: The reduced OBDD representing a given function f is unique.
That is to say, let B 1 and B 2 be two reduced OBDDs with a compatible
variable orderings. If B 1 and B 2 represent the same boolean function, then they have identical structure.
14 An OBDD for the even parity function for four bits
x
y y
z z
w w
1 0
15 The OBDD for (x + y) . (z + w) . (u + v) with variable ordering [x, y, z, w, u, v]
x
y z
w
u v
0 1
16 The OBDD for (x + y) . (z + w) . (u + v) with variable ordering [x, z, u, y, w, v]
x z z
u u u u
y y y y
w w
v
0 1
17 The importance of canonical representation • Absence of redundant variables. • Test for semantic equivalence. • Test for validity. • Test for implication. • Test for satisfiability.
18 The algorithm reduce in general terms
• If the ordering of B is [x 1, x 2, …, x l], then B has at most l +1 layers. The algorithm reduce now traverses B layers in a bottom-up fashion (beginning with the terminal nodes). In traversing B, it assigns an integer label id(n) to each node n of B, in such a way that subOBDDs with root nodes n and m denote the same boolean function if, and only if, id(n) equals id(m).
19 The algorithm reduce
• Definition: Given a non-terminal node n in a BDD, we define lo(n) to be the node pointed to via the dashed line from n. Dually, hi(n) is the node pointed to via the solid line from n. • Let us assume that reduce has already assigned integer labels to all nodes of a layer > i (i.e., all terminal nodes
and x j-nodes with j > i). We describe how nodes of layer i (i.e., x i-nodes) are being handled as follows.
20 The algorithm reduce (continued)
Given an x i-node n, there are three ways in which it may get its label: • If the label id(lo(n)) is the same as id(hi(n)), then we set id(n) to be that label • If there is another node m such that n and m have the
same variable x i, and id(lo(n)) = id(lo(m)) and id(hi(n)) = id(hi(m)), then we set id(n) to be id(m). • Otherwise, we set id(n) to the next unused integer label.
21 An example execution of the algorithm reduce
#4 #4 x1 x1 #3 #2 x2 #3 x2 x2
#2 #2 #2 x3 x3 x3
0 1 0 1 0 1 #0 #1 #0 #1 #0 #1
22 restrictions of f
• Definition: Let f be a Boolean formula and x a variable. We denote by f[0/x] the Boolean formula obtained by replacing all occurrences of x in f by 0. The formula f[1/x] is defined similarly. The f[0/x] and f[1/x] are called restrictionsof f.
23 The algorithm restrict in general terms
• Given an OBDD B f representing a boolean formula f, the call restrict (0, x, B f) computes the reduced OBDD representing f[ 0/x] using the same variable ordering as
Bf.
24 The algorithm restrict
• The algorithm restrict(0, x, B f) works as follows. For each node n labelled with x, incoming edges are redirected to lo(n) and n is removed. Then we call reduce on the
resulting OBDD. The call restrict(1, x, B f) proceeds similarly, only we now redirect incoming edges to hi(n) .
25 Examples of restrictions of f
• OBDD for f • OBDD for f[0 | x 3] OBDD for f[0 | x 3]
26 The algorithm apply in general terms
• Given OBDDs B f and B g for Boolean formulas f and g, respectively, the call
apply (op, B f, B g) computes the reduced OBDD of the Boolean formula f op g , where op denotes any function from {0, 1} X {0, 1} to {0, 1}.
27 The algorithm apply
The algorithm operates recursively on the structure of the two OBDDs: • Let v be the variable highest in the ordering (=
leftmost in the list) which occurs in B f or B g. • Split the problem into sub-problems for v being 0 and v being 1 and solve recursively; • At the leaves, apply the Boolean operation op directly.
28 Shannon expansion
• Lemma: For all Boolean formulas f and all Boolean variables x (even those not occurring in f) we have f ≡ ¬x . f[0/x] + x . f[1/x]. • The function apply is based on the above lemma for f op g :
f op g ≡ ¬x i . (f[0/x i] op g[0/x i]) + x i . (f[1/x i] op g[1/x i]).
29 Time complexity
Algorithm Input OBDD(s) Output OBDD Time complexity
reduce B reduced B O(|B| . Log |B|)
apply Bf op g (reduced) O(|B f| . |B g|) Bf, B g (reduced )
Bf[0/x] or B f[1/x] restrict Bf (reduced) (reduced) O(|B f| . Log |B f|)
30 Symbolic Model Checking
• Model checking using OBDDs is called symbolic model checking. • The term emphasizes that individual states are not represented; rather, sets of states are represented symbolically, namely, those which satisfy the formula being checked.
31 Representing subsets of the set of states
• Let S be a finite set of states. The task is to represent the various subsets of S as OBDDs. • The way to do this in general is to assign to each element s ε S a ε unique vector of boolean values (v 1, v 2, …, v n), each v i {0, 1}. Then, we represent a subset T by the boolean function f T which ε maps (v 1, v 2, …, v n) onto 1 if s T and maps it onto 0 otherwise. • Note that 2n-1 < |S| ≤ 2n . n → • The function f T :{0, 1} {0, 1} which tells us, for each s, represented by (v 1, v 2, …, v n), whether it is in the set T or not, is called the characteristic functionof T.
32 An example of a Kripke structure (S, R, L)
• S = {s0, s1,s2} • R = {(s0, s1), (s1, s2), (s2, s0), (s2, s2)} • L(s0) = {x1} • L(s 1) = {x 2} • L(s2) = Ø s0 x1 x2 s1
s2
33 Representation of subsets of states of the previous example
set of states representation by boolean representation by boolean values function
Ø 0
{s0} (1,0) x1 .¬x2
{s1} (0,1) ¬x1 .x2
{s2} (0,0) ¬x1 .¬x2
{s0, s1} (1,0), (0,1) x1 .¬x2 + ¬x1 .x2
{s0, s2} (1,0), (0,0) x1 .¬x2 + ¬x1 .¬x2
{s1, s2} (0,1), (00) ¬x1 .x2 + ¬x1 .¬x2
{s0, s1, s2} (1,0), (0,1), (00) x1 .¬x2 + ¬x1 .x2 + ¬x1 .¬x2 34 Two OBDDs for the set {s0, s1} of previous example
x1 x1
x2 x2 x2
0 1 0 1
x1 .¬x2 + ¬x1 .x2 x1 + x2
35 Representing transition relations
• The transition relation R of a Kripke structure (S, R, L) is a subset of S × S. So, as a subset of a given set, it may be represented as an OBDD.
• Thus, a transition (s, s’) ε R can be represented by a pair
of Boolean vectors (v 1, …, v n), (v’ 1, …, v’ n), where (v 1, …, vn) represents s and (v’ 1, …, v’ n) represents s’.
36 The Boolean function representation for the transition relation of the previous example
• fR = x1 .¬x2 . ¬x’1 .x’2 + ¬x1 .x2 .¬x’1 .¬x’2 + ¬x 1 .¬x 2 . ¬x’ 1 .x’ 2 + ¬x 1 .¬x 2 .¬x’ 1 .¬x’ 2
37 The truth table for the transition relation of the previous example with ordering [x1, x2, x’1, x’2]
x1 x2 x’1 x’2 R
0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 1 _ 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 _ 1 0 0 0 0 1 0 0 1 1 1 0 1 0 0 1 0 1 1 _ 1 1 0 0 _ 1 1 0 1 _ 1 1 1 0 _ 1 1 1 1 _
38 The truth table for the transition relation of the previous example with ordering [x1, x’1, x2, x’2]
x1 x’1 x2 x’2 R 0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 _ 0 1 1 0 0 0 1 1 1 _ 1 0 0 0 0 1 0 0 1 1 1 0 1 0 _ _ 1 0 1 1 1 1 0 0 0 1 1 0 1 _ 1 1 1 0 _ 1 1 1 1 _
39 An OBDD for the transition relation of the previous example.
x1
X’1 X’1
x2
X’2 X’2
0 1
40 Computation of the Satisfaction Sets
41