code: private int buildRec(final Formula formula) {
      switch (formula.type()) {
        case FALSE:
          return BDDKernel.BDD_FALSE;
        case TRUE:
          return BDDKernel.BDD_TRUE;
        case LITERAL:
          final Literal lit = (Literal) formula;
          Integer idx = this.var2idx.get(lit.variable());
          if (idx == null) {
            idx = this.var2idx.size();
            this.var2idx.put(lit.variable(), idx);
            this.idx2var.put(idx, lit.variable());
          }
          return lit.phase() ? this.kernel.ithVar(idx) : this.kernel.nithVar(idx);
        case NOT:
          final Not not = (Not) formula;
          return this.kernel.addRef(this.kernel.not(buildRec(not.operand())));
        case IMPL:
          final Implication impl = (Implication) formula;
          return this.kernel.addRef(this.kernel.implication(buildRec(impl.left()), buildRec(impl.right())));
        case EQUIV:
          final Equivalence equiv = (Equivalence) formula;
          return this.kernel.addRef(this.kernel.equivalence(buildRec(equiv.left()), buildRec(equiv.right())));
        case AND:
        case OR:
          final Iterator<Formula> it = formula.iterator();
          int res = buildRec(it.next());
          while (it.hasNext())
            res = formula.type() == AND
                    ? this.kernel.addRef(this.kernel.and(res, buildRec(it.next())))
                    : this.kernel.addRef(this.kernel.or(res, buildRec(it.next())));
          return res;
        case PBC:
          return buildRec(formula.nnf());
        default:
          throw new IllegalArgumentException("Unsupported operator for BDD generation: " + formula.type());
      }
    }
docs: Recursive build procedure for the BDD.
  @param formula the formula
  @return the BDD index