(formula, env=None, do_simplify=True, preserve_equivalence=True)
return res.simplify() if do_simplify else res
Propagates the toplevel definitions and returns an equivalent formula.
    It considers three kinds of definitions:
    1) variable = constant
    2) variable = variable
    3) constant = constant
Propagates the toplevel definitions and returns an equivalent formula.
    It considers three kinds of definitions:
    1) variable = constant
    2) variable = variable
    3) constant = constant
Propagates the toplevel definitions and returns an equivalent formula . It considers three kinds of definitions : 1 ) variable = constant 2 ) variable = variable 3 ) constant = constant
def propagate_toplevel(formula, env=None, do_simplify=True, preserve_equivalence=True):
    """ Propagates the toplevel definitions and returns an equivalent formula.
    It considers three kinds of definitions:
    1) variable = constant
    2) variable = variable
    3) constant = constant
    """
    if env is None:
        import pysmt.environment
        env = pysmt.environment.get_env()
    mgr = env.formula_manager

    # comparison function for ranking
    def compare(a, b):
        if a.node_id() == b.node_id():
            return 0
        if a.is_constant() and b.is_constant():
            return a.constant_value() - b.constant_value()
        if a.is_constant():
            return -1
        if b.is_constant():
            return 1
        return a.node_id() - b.node_id()

    disjoint_set = DisjointSet(compare_fun=compare)
    relevant = set()

    for c in conjunctive_partition(formula):
        if c.is_equals():
            l, r = c.args()
            if l.is_array_value() or r.is_array_value():
                # skipping constant arrays
                continue
            if (l.is_symbol() or l.is_constant()) and\
               (r.is_symbol() or r.is_constant()):
                relevant.add(l)
                relevant.add(r)
                disjoint_set.add(l, r)

    # check and build the mapping
    sigma = {}
    for k in relevant:
        v = disjoint_set.find(k)
        if k.node_id() != v.node_id():
            # early detection of a conflict
            if k.is_constant() and v.is_constant() and\
               k.constant_value() != v.constant_value():
                return mgr.FALSE()
            else:
                sigma[k] = v

    res = formula.substitute(sigma)
    if preserve_equivalence:
        res = mgr.And(res, mgr.And([mgr.Equals(k, sigma[k]) for k in sigma]))
    return res.simplify() if do_simplify else res
def propagate_toplevel ( formula , env = None , do_simplify = True , preserve_equivalence = True ) : if env is None : import pysmt . environment env = pysmt . environment . get_env ( ) mgr = env . formula_manager # comparison function for ranking def compare ( a , b ) : if a . node_id ( ) == b . node_id ( ) : return 0 if a . is_constant ( ) and b . is_constant ( ) : return a . constant_value ( ) - b . constant_value ( ) if a . is_constant ( ) : return - 1 if b . is_constant ( ) : return 1 return a . node_id ( ) - b . node_id ( ) disjoint_set = DisjointSet ( compare_fun = compare ) relevant = set ( ) for c in conjunctive_partition ( formula ) : if c . is_equals ( ) : l , r = c . args ( ) if l . is_array_value ( ) or r . is_array_value ( ) : # skipping constant arrays continue if ( l . is_symbol ( ) or l . is_constant ( ) ) and ( r . is_symbol ( ) or r . is_constant ( ) ) : relevant . add ( l ) relevant . add ( r ) disjoint_set . add ( l , r ) # check and build the mapping sigma = { } for k in relevant : v = disjoint_set . find ( k ) if k . node_id ( ) != v . node_id ( ) : # early detection of a conflict if k . is_constant ( ) and v . is_constant ( ) and k . constant_value ( ) != v . constant_value ( ) : return mgr . FALSE ( ) else : sigma [ k ] = v res = formula . substitute ( sigma ) if preserve_equivalence : res = mgr . And ( res , mgr . And ( [ mgr . Equals ( k , sigma [ k ] ) for k in sigma ] ) ) return res . simplify ( ) if do_simplify else res