def _tseitin(ex, auxvarname, auxvars=None):
    """
    Convert a factored expression to a literal, and a list of constraints.
    """
    if isinstance(ex, Literal):
        return ex, list()
    else:
        if auxvars is None:
            auxvars = list()

        lits = list()
        constraints = list()
        for x in ex.xs:
            lit, subcons = _tseitin(x, auxvarname, auxvars)
            lits.append(lit)
            constraints.extend(subcons)

        auxvarindex = len(auxvars)
        auxvar = exprvar(auxvarname, auxvarindex)
        auxvars.append(auxvar)

        f = ASTOPS[ex.ASTOP](*lits)
        constraints.append((auxvar, f))
        return auxvar, constraints
def _tseitin ( ex , auxvarname , auxvars = None ) : if isinstance ( ex , Literal ) : return ex , list ( ) else : if auxvars is None : auxvars = list ( ) lits = list ( ) constraints = list ( ) for x in ex . xs : lit , subcons = _tseitin ( x , auxvarname , auxvars ) lits . append ( lit ) constraints . extend ( subcons ) auxvarindex = len ( auxvars ) auxvar = exprvar ( auxvarname , auxvarindex ) auxvars . append ( auxvar ) f = ASTOPS [ ex . ASTOP ] ( * lits ) constraints . append ( ( auxvar , f ) ) return auxvar , constraints
Convert a factored expression to a literal, and a list of constraints.