Keywords: cuddIntro

Next: Basic ADD Manipulation Up: User's Manual Previous: Creating Variables

## Basic BDD Manipulation

Common manipulations of BDDs can be accomplished by calling Cudd_bddIte. This function takes three BDDs, f, g, and h, as arguments and computes . Like all the functions that create new BDDs or ADDs, Cudd_bddIte returns a result that must be explicitly referenced by the caller. Cudd_bddIte can be used to implement all two-argument boolean functions. However, the package also provides Cudd_bddAnd as well as the other two-operand boolean functions, which are slightly more efficient when a two-operand function is called for. The following fragment of code illustrates how to build the BDD for the function .

            DdManager *manager;
            DdNode *f, *var, *tmp;
            int i;

            ...

            f = Cudd_ReadOne(manager);
            Cudd_Ref(f);
            for (i = 3; i >= 0; i--) {
                var = Cudd_bddIthVar(manager,i);
                tmp = Cudd_bddAnd(manager,Cudd_Not(var),f);
                Cudd_Ref(tmp);
                Cudd_RecursiveDeref(manager,f);
                f = tmp;
            }

This example illustrates the following points:

- Intermediate results must be ``referenced" and ``dereferenced." However, `var` is a projection function, and its reference count is always greater than 0. Therefore, there is no call to Cudd_Ref .
- The new `f` must be assigned to a temporary variable (`tmp` in this example). If the result of Cudd_bddAnd were assigned directly to `f`, the old `f` would be lost, and there would be no way to free its nodes.
- The statement `f = tmp` has the same effect as:

                  f = tmp;
                  Cudd_Ref(f);
                  Cudd_RecursiveDeref(manager,tmp);

  but is more efficient. The reference is ``passed" from `tmp` to `f`, and `tmp` is now ready to be reutilized.
- It is normally more efficient to build BDDs ``bottom-up." This is why the loop goes from 3 to 0. Notice, however, that after variable reordering, higher index does not necessarily mean ``closer to the bottom." Of course, in this simple example, efficiency is not a concern.
- Had we wanted to conjoin the variables in a bottom-up fashion even after reordering, we should have used Cudd_ReadInvPerm . One has to be careful, though, to fix the order of conjunction before entering the loop. Otherwise, if reordering takes place, it is possible to use one variable twice and skip another variable.

Next: Basic ADD Manipulation Up: User's Manual Previous: Creating Variables