Reduced Ordered Binary Decision Diagrams Lecture #12 of Advanced Model Checking Joost-Pieter Katoen Lehrstuhl 2: Software Modeling & Verification E-mail: katoen@cs.rwth-aachen.de December 13, 2016 c JPK
Symbolic CTL model checking Explicit representation of transition system: state explosion problem Idea: reformulate model-checking in a symbolic way Concept: represent sets of states and transitions symbolically Approach: binary encoding of states + switching functions for sets Compact representation of switching functions by binary decision diagrams Alternative: conjunctive normal form (basis for SAT-based model checking) c JPK 1
Basic approach let TS = (S,,I, AP,L) be a large finite transition system the set of actions is irrelevant here and has been omitted, i.e., S S For n log S, let injective function enc : S {0,1} n note: enc(s) = {0,1} n is no restriction, as all elements {0,1} n \ enc(s) can be treated as the encoding of pseudo states that are unreachable Identify the states s S = enc 1 ({0,1} n ) with enc(s) {0,1} n And T S by its characteristic function χ T : {0,1} n {0,1} that is χ T (enc(s)) = 1 if and only if s T And S S by the Boolean function : {0,1} 2n {0,1} such that ( enc(s), enc(s ) ) = 1 if and only if s s c JPK 2
Switching functions Let Var = {z 1,...,z m } be a finite set of Boolean variables, m 0 An evaluation is a function η : Var {0,1} let Eval(z 1,...,z m ) denote the set of evaluations for z 1,...,z m shorthand [z 1 = b 1,...,z m = b m ] for η(z 1 ) = b 1,...,η(z m ) = b m f : Eval(Var) {0,1} is a switching function for Var = {z 1,...,z m } Logical operations and quantification are defined as expected f 1 ( ) f 2 ( ) = min{f 1 ( ),f 2 ( )} f 1 ( ) f 2 ( ) = max{f 1 ( ),f 2 ( )} z.f( ) = f( ) z=0 f( ) z=1, and z.f( ) = f( ) z=0 f( ) z=1 c JPK 3
Polynomial-size data structure impossible There is no poly-size data structure for all switching functions Eval(z 1,...,z m ) = 2 m, so #functions Eval(z 1,...,z m ) {0,1} is 2 2m Suppose there is a data structure that can represent K m switching functions by at most 2 m 1 bits Then K m 2 m 1 i=0 2 i = 2 2m 1 +1 1 < 2 2m 1 +1 But then there are at least ( ) 2 2m 2 2m 1 +1 = 2 2m 1 +1 2 2m 2 m 1 1 1 ( ) = 2 2m 1 +1 2 2m 1 1 1 switching functions whose representation needs more than 2 m 1 bits c JPK 4
Possible representations of switching functions Truth tables very space inefficient: 2 n entries for n variables satisfiability and equivalence check: easy; boolean operations also easy... but have to consider exponentially many lines (so are hard)... in Disjunctive Normal Form (DNF) satisfiability is easy: find a disjunct that does have complementary literals negation and conjunction complicated equivalence checking (f = g?) is conp-complete... in Conjunctive Normal Form (CNF) satisfiability problem is NP-complete (Cook s theorem) negation and disjunction complicated c JPK 5
Representing switching functions representation compact? sat equi propositional formula often hard hard easy easy easy DNF sometimes easy hard hard easy hard CNF sometimes hard hard easy hard hard (ordered) truth table never hard hard hard hard hard c JPK 6
There is hope... perhaps Nevertheless there are data structures which yield compact representations for many switching functions that appear in practical applications for hardware circuits, ordered binary decision diagrams (OBDDs) are successful c JPK 7
Representing boolean functions representation compact? sat equ propositional formula often hard hard easy easy easy DNF sometimes easy hard hard easy hard CNF sometimes hard hard easy hard hard (ordered) truth table never hard hard hard hard hard reduced ordered binary decision diagram often easy easy medium medium easy provided appropriate implementation techniques are used c JPK 8
Binary decision tree The BDT for function f on Var = {z 1,...,z m } has depth m outgoing edges for node at level i stand for z i = 0 (dashed) and z i = 1 (solid) For evaluation s = [z 1 = b 1,...,z m = b m ], f(s) is the value of the leaf reached by traversing the BDT from the root using branch z i = b i for at level i The subtree of node v at level i for variable ordering z 1 <... < z m represents f v = f z1 =b 1,...,z i 1 =b i 1 which is a switching function over {z i,...,z m } and where z 1 = b 1,...,z i 1 = b i 1 is the sequence of decisions made along the path from the root to node v c JPK 9
Symbolic representation of a transition system s 0 s 1 a Switching function: (x 1,x 2 s 3 s 2 {a,b},x }{{} 1,x 2) = 1 if and only if s s }{{} s s (x 1,x 2,x 1,x 2 ) = ( x 1 x 2 x 1 x 2 ) ( x 1 x 2 x 1 x 2 ) ( x 1 x 2 x 1 x 2 )... (x 1 x 2 x 1 x 2 ) b c JPK 10
Transition relation as a BDT x 1 x 2 x 2 x 1 x 1 x 1 x 1 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1 1 A BDT representing for our example using ordering x 1 < x 2 < x 1 < x 2 c JPK 11
Facts about BDTs BDTs are not compact a BDT for switching function f on n variables has 2 n leafs they are as space inefficient as truth tables! BDTs contain quite some redundancy all leafs with value one (zero) could be collapsed into a single leaf a similar scheme could be adopted for isomorphic subtrees The size of a BDT does not change if the variable order changes c JPK 12
Ordered Binary Decision Diagram OBDDs rely on compactifying BDT representations Idea: skip redundant fragments of BDT representations Collapse subtrees with all terminals having same value Identify nodes with isomorphic sub-trees This yields directed acyclic graphs with out-degree two Inner nodes are labeled with variables Leafs are labeled with function values (zero and one) c JPK 13
Ordered Binary Decision Diagram Let be a (total) variable ordering for Var where = (z 1,...,z m ). An -OBDD is a tuple B = (V,V I,V T, succ 0, succ 1, var, val,v 0 ) with a finite set V of nodes, partitioned into V I (inner) and V T (terminals) and a distinguished root (node) v 0 V successor functions succ 0, succ 1 : V I V such that each node v V \ {v 0 } has at least one predecessor i.e., all nodes of the OBDD B are reachable from the root a labeling functions var : V I Var and val : V T {0,1} satisfying for = (z 1,...,z m ) and v V I : var(v) = z i w { succ 0 (v), succ 1 (v)} V I var(w) = z j for j > i c JPK 14
Some example OBDDs c JPK 15
Transition relation as an OBDD x 1 x 2 x 2 x 1 x 1 x 1 x 1 x 2 x 2 x 2 x 2 0 1 0 1 1 0 1 1 An example OBDD representing f for our example using x 1 < x 2 < x 1 < x 2 c JPK 16
Semantics of an OBDD The semantics of -OBDD B is the switching function f B where f B ([z 1 = b 1,...,z m = b m ]) is the value of the resulting leaf when traversing B starting in v 0 and branching according to the evaluation [z 1 = b 1,...,z m = b m ] c JPK 17
Intermezzo: OBDDs versus DFA x 1 0 1 x 1 x 1 1 0 x 2 0 0 1 x 2 x 2 0 1 1 1 0 0 1 each OBDD B is a deterministic automaton A B with f 1 B (1) = L(A B) c JPK 18
Bottom-up characterization of f B Let B be a -OBDD. Switching function f v for node v V : If v V T, then f v is the constant switching function with value val(v) Ifv V I with var(v) = z, thenf v = ( ( ) z f succ0 (v)) z fsucc1 (v) }{{} Shannon expansion Furthermore, f B = f v0 for the root v 0 of B c JPK 19
Consistent co-factors in OBDDs Let f be a switching function for Var Let = (z 1,...,z m ) a variable ordering for Var, i.e., z 1 <... < z m Switching function g is a -consistent cofactor of f if g = f z1 =b 1,...,z i =b i for some i {0,1,...,m} It holds that: 1. for each node v of an -OBDD B, f v is a -consistent cofactor of f B 2. for each -consistent cofactor g of f B there is a node v B with f v = g c JPK 20
Reduced OBDDs A -OBDD B is reduced if for every pair (v,w) of nodes in B: v w implies f v f w (A reduced -OBDD is abbreviated as -ROBDD) In -ROBDDs any -consistent cofactor is represented by exactly one node c JPK 21
Example ROBDDs c JPK 22
Transition relation as an OBDD x 1 x 2 x 2 x 1 x 1 x 1 x 1 x 2 x 2 x 2 x 2 0 1 0 1 1 0 1 1 An example OBDD representing f for our example using x 1 < x 2 < x 1 < x 2 c JPK 23
Transition relation as an ROBDD x 1 x 1 x 2 x 2 x 1 x 1 x 1 x 1 x 1 x 2 x 2 x 2 x 2 x 2 0 1 0 1 (a) ordering x 1 < x 2 < x 1 < x 2 (b) ordering x 1 < x 1 < x 2 < x 2 c JPK 24
Universality and canonicity theorem [Fortune, Hopcroft & Schmidt, 1978] For finite set Var of Boolean variables and a variable ordering for Var: (a) For each switching function f on Var there exists a -ROBDD B with f B = f (b) For any -ROBDDs B and C with f B = f C, B and C are isomorphic, i.e., agree up to renaming of nodes c JPK 25
Proof c JPK 26
The importance of canonicity Absence of redundant vertices if f B does not depend on x i, ROBDD B does not contain an x i node Test for equivalence: f(x 1,...,x n ) g(x 1,...,x n )? generate ROBDDs B f and B g, and check isomorphism Test for validity: for all x 1,...,x n, is f(x 1,...,x n ) = 1? generate ROBDD B f and check whether it only consists of a 1-leaf Test for implication: f(x 1,...,x n ) g(x 1,...,x n )? generate ROBDD B f g and check if it just consists of a 0-leaf Test for satisfiability f is satisfiable if and only if B f has a reachable 1-leaf c JPK 27
Minimality of ROBDDs Let B be an -OBDD for f. Then: B is reduced iff size(b) size(c) for each -OBDD C for f. This follows from the fact that: 1. Each -consistent cofactor of f is represented in any -OBDD for f by at least one node, and 2. A -OBDD B for f is reduced iff there is a 1-to-1 correspondence between the nodes in B and the -consistent cofactors of B. c JPK 28
Reducing OBDDs Generate an OBDD (or BDT) for a boolean expression, then reduce by means of a recursive descent over the OBDD Elimination of duplicate leafs for a duplicate 0-leaf (or 1-leaf), redirect all incoming edges to just one of them Elimination of don t care (non-leaf) vertices if succ 0 (v) = succ 1 (v) = w, delete v and redirect all its incoming edges to w Elimination of isomorphic subtrees if v w are roots of isomorphic subtrees, remove w and redirect all incoming edges to w to v note that the first reduction is a special case of the latter c JPK 29
How to reduce an OBDD? becomes 1 0 0 1 1 0 (special case of) isomorphism rule c JPK 30
How to reduce an OBDD? v w v becomes 0 1 0 1 isomorphism rule c JPK 31
How to reduce an OBDD? v becomes w w elimination rule c JPK 32
Example c JPK 33
Soundness of reduction rules if C arises from a -OBDD B by the elimination or isomorphism rule, then: C is a -OBDD with f B = f C Elimination rule for v with var(v) = z, and w = succ 0 (v) = succ 1 (v): f v = ( ) z f succ0 (v) ( ) z f succ1 (v) Isomorphism rule for v, w with var(v) = var(w) = z yields: f v = = = f w = ( z f w ) (z f w ) = f w ( ) ( ) z f succ0 (v) z f ( ) ( succ1 (v) ) z f succ0 (w) z f succ1 (w) as each reduction rule decreases the # nodes, repeatedly applying them terminates c JPK 34
Completeness of reduction rules -OBDD B is reduced if and only if no reduction rule is applicable to B c JPK 35