def bdd2expr(bdd, conj=False):
    """Convert a binary decision diagram into an expression.

    This function will always return an expression in two-level form.
    If *conj* is ``False``, return a sum of products (SOP).
    Otherwise, return a product of sums (POS).

    For example::

       >>> a, b = map(bddvar, 'ab')
       >>> bdd2expr(~a | b)
       Or(~a, And(a, b))
    """
    if conj:
        outer, inner = (And, Or)
        paths = _iter_all_paths(bdd.node, BDDNODEZERO)
    else:
        outer, inner = (Or, And)
        paths = _iter_all_paths(bdd.node, BDDNODEONE)
    terms = list()
    for path in paths:
        expr_point = {exprvar(v.names, v.indices): val
                      for v, val in _path2point(path).items()}
        terms.append(boolfunc.point2term(expr_point, conj))
    return outer(*[inner(*term) for term in terms])