Binar Decision Diagrams Ma 3, 2004 1
Overview Boolean functions Possible representations Binar decision trees Binar decision diagrams Ordered binar decision diagrams Reduced ordered binar decision diagrams Operations on ordered binar decision diagrams Validit, satisfiabilit, function equivalence Function composition operations 2
Boolean functions A boolean function maps boolean inputs (0s and 1s) to a boolean result (0 or 1). Basic functions: 0 = 1, 1 = 0 (complementation). + = 0 = = 0 (disjunction, like addition). = 1 = = 1 (conjunction, like multiplication). = 1 (eclusive or). Comple functions: h(,, ) = + ( ) Function composition: h = f + g Goal: represent models and CTL formulas. 3
Representing boolean functions Goal: efficientl implement useful operations: Validit Satisfiabilit Equivalence of functions Approaches: Truth tables. Propositional formulas. Propositional formulas in a canonical form. (e.g. CNF, DNF) 4
Binar decision trees Truth-table representation: ( + ) 1 1 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 Tree representation: 0 0 Evaluation: Use the dotted edge if the variable is 0. Use the solid edge if the variable is 1. Structure depends on the input/output relation, not on the formula definition. 5
Problems Trees no more efficient than truth tables. Tree structure depends on the variable ordering: 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 Repeated variables can create unreachable edges. 6
Binar decision diagrams (BDDs) BDDs: Trees with sharing (DAGs). Reduction: Eliminate redundant information from a BDD. Share redundant subgraphs. 7
Reduction rules Multiple 0 s and 1 s clearl redundant. Eample: 0 0 becomes: 8
Reduction rules, contd. If a node has the same child at both outgoing edges, the node is redundant. If two nodes represent the same variable and have the same descendants, one is redundant. 9
Variable ordering Reduction opportunities depend on variable ordering. Eamples: 0 0 0 0 0 1 10
Summar Reduction rules: Coalescing duplicate terminal nodes. Removal of redundant tests. Coalescing duplicate non-terminals. No rules introduce terminals, so the first rule can be applied all at once. Otherwise, one application can make opportunities for others: = The rules are confluent. 11
Operations on BDDs Desirable predicates: Validit Satisfiabilit Equivalence of functions Desirable operations: f f + g f g f g 12
Predicates Validit: Is the result alwas 1? Satisfiabilit: Is the result ever 1? Ideall: Validit: check for absence of 0. Satisfiabilit: check for presence of 1. Problem: Repeated variables impl that some edges might be unreachable. Eample: BDD for + : Solution: Evaluate on all inputs (truth-table approach). 13
Equivalence of functions Ideall: Check whether BDDs have the same structure. Problem: structure sensitive to: Variable ordering Repeated variables Redundant nodes Solution: Evaluate both functions on all inputs (again, the truth-table solution). 14
Operations f: interchange 0 s and 1 s. f + g: If 1 reached in f, return 1. Otherwise, check g. Replace the 0 nodes of B f b B g. : : 1 0 + : 1 1 0 f g: If 0 reached in f, return 0. Otherwise, check g. Replace the 1 nodes of B f b B g. Calculations efficient, but variables occur multipl in resulting paths. 15
Ordered BDDs (OBDDs) Problems with BDDs: Repeated variables cause inaccessible edges. Structure depends on variable ordering. Solution: Require a fied order for all paths. Ordered: [,, ]: Not ordered: 0 0 0 1 0 0 0 1 An BDD can be converted to an order. 16
Properties of OBDDs No duplication implies no inaccessible edges. Validit: absence of 0. Satisfiabilit: presence of 1. Implication: f g f g (f g). Check f g for validit. Equivalentl, check that f g has no 1 (alwas false). 17
Properties of reduced OBDDs Absence of redundant variables: A reduced OBDD contains no redundant variables. Eample: OBDD: non-obdd: Equivalence of functions: Reduced OBDDs must be identical. Compleit linear in OBDD sie. 18
Properties of reduced OBDDs, contd. Validit: Reduced OBDD equivalent to 1. Satisfiabilit: Reduced OBDD not equivalent to 0. Implication: f g iff reduced OBDD of f g is equivalent to 0. Constant time operations. 19
OBDDs and variable ordering Variable ordering affects reduced OBDD sie, which affects manipulation costs. ( 1 + 2 ) ( 3 + 4 ) ( 5 + 6 ) [ 1, 2, 3, 4, 5, 6 ] : [ 1, 3, 5, 2, 4, 6 ] : 1 2 3 4 5 6 1 3 3 5 5 5 5 2 2 2 2 4 4 6 1 0 For ( 1 + 2 ) ( 3 + 4 )... ( 2n 1 + 2n ): [ 1, 2,..., 2n ] 2n + 2 nodes. [ 1, 3,..., 2n 1, 2, 4,... 2n ] 2 n+1 nodes. Problem: the same ordering must be used for all functions. 20
Reduction for OBDDs Efficient bottom-up algorithm. Idea: label nodes, giving redundant nodes the same label. Labeling allows efficient comparison of subgraphs. Terminolog: l(n): the child at the dotted edge of n. h(n): the child at the solid edge of n. 21
Labeling algorithm 1. Label all 0 s with 1, all 1 s with 1. 2. If l(n) = h(n), label n with l(n). 3. If there is a node m with the same variable such that l(n) = l(m) and h(n) = h(m), label n with m s label. 4. Otherwise, pick a fresh label for n. 4 3 2 0 2 2 2 00 00 01 01 01 Appl reduction rules, bottom-up. If two children have the same label, the are the same. 22
Compleit Visit each node: O(n) Check whether children identical: O(1) Search for a predecessor with the same variable and the same children. B first sorting: O(log n) 23
Boolean functions Goal: combine OBDDs so that the result is an OBDD. Operations: f + g, f g, f g. Observation: f op g trivial if f and g are constant functions. Eample: f = 0, g = 1 f + g = 0 + 1 = 0 Inductive strateg: Compute f op g on n variables in terms of f op g on n 1 variables. Eventuall reach a constant function. 24
Shannon epansion Law of the ecluded middle: = 0 or = 1. f[0/], f[1/] have fewer variables than f. Idea: redefine f in terms of f[0/] and f[1/]: + combines, but f[0/] + f[1/] is wrong. Drop the component that does not use s value. α: = 0 drop α. = 1 keep α. α: = 0 keep α. = 1 drop α. f = f[0/] + f[1/] f op g = (f op g)[0/] + (f op g)[1/] = (f[0/] op g[0/]) + (f[1/] op g[1/]) 25
Implementing appl(op, B f, B g ) f op g = (f[0/] op g[0/])+ (f[1/] op g[1/]) Construct OBDDs for f[0/], f[1/] from an OBDD for f. If is at the root: f[0/]: the target of the dotted edge. f[1/]: the target of the solid edge. Inductive algorithm eliminates all variables, so choose the root each time. OBDDs, so f and g variables in the same order. 26
appl algorithm Cases: Both roots are terminals: Appl op directl. Both roots associated with : app(op, l(r f ), l(r g )) app(op, h(r f ), h(r g )) Incompatible roots: deferred. These rules are sufficient if all paths contain all variables. Result: a full binar tree. Reduction required. 27
Connection to Shannon epansion f op g = f[0/] op g[0/] + f[1/] op g[1/] BDDs: : 1 0 : f[0/] op g[0/] : f[1/] op g[1/] : app(op, l(r f ), l(r g )) 0 0 app(op, h(r f ), h(r g )) Final sum: app(op, l(r f ), l(r g )) 0 app(op, h(r f ), h(r g )) 28
Eample Compute product: : 1 a : 1 b 2 a 3 a 0 4 a 1 5 a 2 b 3 b 0 4 b 1 5 b 29
Completing the appl algorithm Remaining cases: One root a variable, the other a constant. The two roots represent different variables. OBDD propert: If the variable earlier in the ordering is not the root of one tree, it is not in that tree. Idea: Rules: r f < r g : op op app(op, l(r f ), r g ) app(op, h(r f ), r g ) r g < r f : app(op, r f, l(r g )) app(op, r f, h(r g )) 30
Eample Compute product: 1 a 3 a 0 4 a 1 5 a 1 b 3 b 2 b 0 4 b 1 5 b 31
Compleit Observation: appl algorithm often creates a full binar tree. 2 n nodes, for n variables. Problems: Repeated computations. Distinct computations give the same result. Memoisation addresses the first problem. Onl compute each app(op, n, m) once. Compleit O( B f B g ). 32
Quantifiers (.f)( 1,..., n ) = 1 iff: f returns 1 for these values when = 0, or f returns 1 for these values when = 1. Encoding:.f = f[0/] + f[1/] (.f)( 1,..., n ) = 1 iff: f returns 1 for these values when = 0, and f returns 1 for these values when = 1. Encoding:.f = f[0/] f[1/] 33
Computing restrict(c,, B) For appl, is alwas the root variable. f[0/] is the left child of the root. f[1/] is the right child of the root. For restrict, can be an variable. For each, connect all incoming edges to c child. Eample: ( ) : [0/] : 34
Implementing quantification.f = app(+, restrict(0,, B f ), restrict(1,, B f )).f = app(, restrict(0,, B f ), restrict(1,, B f )) Eample, d.f: a b c d e Restrictions: a a b c e b c e Sum: b l + b r = b c l + c r = c a 0 + 0 = 0 e l + e r = e 1 + 1 = 1 0 + e r = e 35
Improving efficienc Most of the tree is not affected b restrictions. Thus most of the tree is duplicated in the result (e.g. b l + b r ). More efficient approach: replace quantified node b the sum of the children. Eample: b a c d e a b c e Nested quantification NP-complete. 36
Compleit summar input time compleit reduce B O( B log B ) appl Br f, Br g O( Br f Br g ) restrict Br O( Br log Br ) eists Br NP-complete Br: a reduced OBDD. 37
Comparison with other approaches Compact Sat. Val. Prop. formulas + DNF formulas 0 + CNF formulas 0 + Truth tables Reduced OBDDs + + + + Prop. formulas + + + DNF formulas + CNF formulas + Truth tables Reduced OBDDs 0 0 + 38