Create a CUDD manager, build a function, count its minterms, and release every reference.
Every BDD a CUDD function returns, except a projection variable from Cudd_bddIthVar and a constant, needs Cudd_Ref before the next call that could free it, and Cudd_RecursiveDeref once you are done with it. Cudd_CheckZeroRef counts the nodes still referenced, apart from the constants and the projection variables: after every release, it returns 0.
Cudd_bddIthVar
Cudd_Ref
Cudd_RecursiveDeref
Cudd_CheckZeroRef
Take g = x0 ^ x1 | x2 over the three variables x0, x1 and x2. Cudd_CountMinterm(dd, g, 3) counts the assignments that make it 1.
g = x0 ^ x1 | x2
x0
x1
x2
Cudd_CountMinterm(dd, g, 3)
Count by hand first: with x2 = 1, all 4 assignments of x0 and x1 make g 1; with x2 = 0, g is x0 ^ x1, which is 1 on 2 of them. So g has 6 minterms.
x2 = 1
g
x2 = 0
x0 ^ x1
Building g takes two calls: Cudd_bddXor for x0 ^ x1, then Cudd_bddOr. Each result is referenced as soon as it returns; x0 ^ x1 is released once g is built, and g once it is counted.
Cudd_bddXor
Cudd_bddOr
After both releases only the variables and the constants are left, which Cudd_CheckZeroRef does not count, so it returns 0.
Write double first_manager(void). It creates a CUDD manager with four BDD variables, x0 to x3 (indices 0 to 3), and builds f = x0 & x1 | x2 ^ x3. It counts the minterms of f over the four variables with Cudd_CountMinterm, releases f, and checks with Cudd_CheckZeroRef that no reference is left. Then it shuts the manager down with Cudd_Quit and returns the count, or -1 when Cudd_CheckZeroRef finds a reference left.
double first_manager(void)
x3
f = x0 & x1 | x2 ^ x3
f
Cudd_CountMinterm
Cudd_Quit
A C file that includes cudd.h and defines double first_manager(void), with that name and no parameters. The check compiles your file with a hidden test program against CUDD 3.0.0, runs it with AddressSanitizer and UndefinedBehaviorSanitizer, and says which test failed.
cudd.h
first_manager returns the number of minterms of f over x0 to x3.
Releases every reference it takes, so Cudd_CheckZeroRef returns 0 before Cudd_Quit.
Watch the conditions: the first waits until the file defines first_manager; the count and the references are decided when you press Check answer.
first_manager
Count the minterms of f by hand, as the example does for g, so you know the number first_manager must return.
Pair every call that returns a new BDD with one Cudd_Ref and one Cudd_RecursiveDeref, and check that nothing is used after its release.
Kata 5.1 of Binary Decision Diagrams with CUDD on formal.org. The site checks the answer when you press Check answer; sign in to keep your progress.