Composition of ROBDD

771 Views Asked by At

I am trying to understand how the composition of two ROBDDs works.

F1 = (d? false: (c? (a? false: true): false))
F2 = (d? (b? true: (a? false: true)): (c? (b? true: (a? false: true)): true))

I need to find a formula F3 that is obtained by replacing all occurrences of d by formula F1 in formula F2.

How do I proceed solving this?

1

There are 1 best solutions below

0
On

Substitution, composition of BDDs, variable renaming, cofactors, and evaluation are all the same mathematical operation: substitution. You can do the substitution you are interested in using the Python package dd as follows:

import dd.autoref as _bdd


f1_formula = 'ite(d, FALSE, ite(c, ite(a, FALSE, TRUE), FALSE))'
f2_formula = (
    'ite(d, ite(b, TRUE, ite(a, FALSE, TRUE)), '
    'ite(c, ite(b, TRUE, ite(a, FALSE, TRUE)), TRUE))')
# create a BDD manager and BDDs for the above formulas
bdd = _bdd.BDD()
bdd.declare('a', 'b', 'c', 'd')
f1 = bdd.add_expr(f1_formula)
f2 = bdd.add_expr(f2_formula)
# substitute `f1` for `d` in `f2`
sub = dict(d=f1)
r = bdd.let(sub, f2)
# dump the BDDs to a PNG file
bdd.dump('foo.png', [f1, f2, r])
print(f'f1: {f1}, f2: {f2}, r: {r}')

The above creates the output:

f1: @-7, f2: @14, r: @11

and the file foo.png shown below. For assignments of Boolean values to the variables:

  • f1_formula corresponds to the negated BDD at node 7
  • f2_formula corresponds to the BDD at node 14
  • r (the composition) corresponds to the BDD at node 11.

enter image description here

The "let" method is named after the LET... IN construct in TLA+.