The idea: one graph per Boolean function
A binary decision diagram (BDD) stores a Boolean function as a graph. Each circle tests one variable. You follow the 0-edge (red) or the 1-edge (green) and end at a leaf, 0 or 1. Fix the order of the variables, remove every repeated or useless test, and you get the reduced ordered BDD (ROBDD). For a fixed order it is canonical: one function has exactly one ROBDD. That makes it a good tool for checking circuits.
Pick a function and an order. Build makes the ROBDD level by level. Reduce Tree draws the full tree first and shrinks it. Count SAT counts the assignments that make the function true. The unique table on the right lists every node as (variable, low child, high child).
Shannon expansion and the decision tree
Any function can be split on one variable x: f = ¬x·f|x=0 + x·f|x=1. The two parts are the cofactors: f with x set to 0, and f with x set to 1. This is the Shannon expansion. Split again on the next variable, and again, until no variable is left. The result is a decision tree. With n variables it has 2n − 1 tests and 2n leaves. For f = a1·b1 + a2·b2 that is 15 + 16 = 31 nodes (Demo 1). A tree for 6 variables would have 127 nodes, and one for 40 variables more than a trillion.
The two reduction rules and the unique table
- Merge equal nodes. Two nodes that test the same variable and have the same low and the same high child compute the same thing. Keep one.
- Delete a useless test. If a node's low and high child are the same, the test does not matter. Its parent can point straight at the child.
Applied from the bottom up, the 16 leaves become two. On the b2 level, the 8 tests of the tree become one node (b2, #0, #1). Most were useless: when a1·b1 is already 1, both edges go to leaf 1. Level by level, 31 nodes shrink to 6 (Demo 1).
A real BDD package never builds the tree. Every node is made by one function, mk(var, low, high). If low = high it returns low (rule 2). Otherwise it looks the key (var, low, high) up in a hash table, the unique table. If the key is there, it returns that node (rule 1). If not, it makes a new one. So the graph is always reduced, and functions built in the same table share nodes.
The variable order decides the size
Take f = a1·b1 + a2·b2 + a3·b3. With the order a1 < b1 < a2 < b2 < a3 < b3, each pair is tested together. The graph needs one node per variable: 6 tests + 2 leaves = 8 nodes (Demo 2). With a1 < a2 < a3 < b1 < b2 < b3, the graph must remember which a's were 1 until their b's come. The levels hold 1, 2, 4, 4, 2, 1 nodes: 14 tests + 2 leaves = 16 nodes (Demo 3).
For n pairs the good order gives 2n + 2 nodes and the bad one 2n+1. The best order depends on the function: h = (a1 + a2)·(b1 + b2) is smaller with the a's first (6 nodes against 8). Finding the best order is NP-hard. Tools use rules of thumb (keep related inputs close) and sifting, which moves one variable at a time to its best level. Some functions, such as the middle output bit of a multiplier, have no small BDD in any order.
| function | a1 b1 a2 b2 (a3 b3) | a1 a2 (a3) b1 b2 (b3) | true for |
|---|---|---|---|
| f = a1·b1 + a2·b2 | 6 nodes | 8 nodes | 7 of 16 |
| f = a1·b1 + a2·b2 + a3·b3 | 8 nodes | 16 nodes | 37 of 64 |
| h = (a1 + a2)·(b1 + b2) | 8 nodes | 6 nodes | 9 of 16 |
| p = a1 + b1 | 4 nodes | 4 nodes | 12 of 16 |
Operations on BDDs: ITE
You don't build a BDD from a truth table: that would need 2n rows. You build it from the circuit, gate by gate, with operations on BDDs. They all come from one operation, ITE (if-then-else): ITE(f, g, h) = f·g + ¬f·h. AND is ITE(f, g, 0), OR is ITE(f, 1, g), NOT is ITE(f, 0, 1).
ITE splits on the top variable x of its three operands: ITE(f, g, h) = mk(x, ITE(f|x=0, g|x=0, h|x=0), ITE(f|x=1, g|x=1, h|x=1)). A cofactor is cheap: it is just the low or high child when the node tests x, and the node itself when it doesn't. Simple cases stop at once: ITE(1, g, h) = g, ITE(0, g, h) = h, ITE(f, g, g) = g. A computed table remembers every call, so the work is at most the product of the two graph sizes. For p = a1 + b1 and q = a2 + b2, p·q takes only 2 real calls and adds 2 new nodes; the rest of the result is q itself (Demo 4).
Checking that two circuits are equal
Build both circuits in the same unique table with the same order. Because the ROBDD is canonical, they compute the same function exactly when their roots are the same node. The check is one pointer comparison. g = (a1 + a2·b2)·(b1 + a2·b2) looks different from f = a1·b1 + a2·b2, but building it adds no row at all: every node is found, and its root is f's root (Demo 5).
If the roots differ, a counterexample exists: an input on which the two circuits disagree. For h = (a1 + a2)·(b1 + b2), the input a1 = 0, b1 = 1, a2 = 1, b2 = 0 gives f = 0 but h = 1 (Demo 6). They differ on 2 of the 16 inputs. A real tool finds one by following any path to 1 in the BDD of f XOR h. Equivalence checkers in chip design do this after synthesis, to check that the optimised netlist still computes what the RTL said. See Technology Mapping for one such step.
Counting satisfying assignments
DPLL looks for one satisfying assignment. A BDD can count all of them, in time linear in its size. Give leaf 1 the count 1 and leaf 0 the count 0. A node's count is count(low) + count(high), but an edge that skips k levels is worth 2k times more, because each skipped variable can be 0 or 1. Work from the bottom up. For f = a1·b1 + a2·b2 + a3·b3 the root gets 37: 37 of the 64 inputs make f true (Demo 7). Check: f is false only when no pair is 1·1, which leaves 3 choices per pair, 3 × 3 × 3 = 27 = 64 − 37.
The same pass gives probabilities. Give each variable a probability and weight each edge by it instead of 2k. That is how fault tree tools get the exact top-event probability without inclusion–exclusion.
Where BDDs are used
Bryant's 1986 paper made ROBDDs the standard tool for hardware verification: combinational equivalence checking, symbolic model checking of state machines (sets of states as BDDs), logic synthesis and test generation. They are also used in fault tree analysis and for product configuration rules. Their weak point is size: a bad order, or a hard function, can make the graph explode, and then SAT solvers are used instead.
See also SAT Solving with DPLL for finding one satisfying assignment, Karnaugh Maps and The Quine–McCluskey Method for a minimal sum of products, Fault Tree Analysis for the cut sets and probabilities that BDDs compute exactly, Multilevel Logic and Bubble Pushing for circuits that look different but compute the same function, and Stuck-At Fault Testing for test inputs that tell a good circuit from a faulty one.
See also Stuck-at Faults and Test Generation, where a redundant fault shows logic that can be removed without changing the function.
See also Algebraic Factoring, a synthesis step whose result has to be checked for equivalence with the original logic.
What the page leaves out
Complement edges (a flag on an edge that means NOT, used by every real package); garbage collection and reference counts; dynamic reordering by sifting; existential quantification, relational product and image computation for model checking; zero-suppressed BDDs (ZDDs) for sparse sets; multi-terminal BDDs; and functions with no small BDD in any order, such as integer multiplication.