Commit 7748a719 authored by Marek Chalupa's avatar Marek Chalupa
Browse files

Revert "improve hard solving"

This reverts commit 38d5a278.
It breaks things. We must do that part by part and check for
regressions.
parent 276fc210
Loading
Loading
Loading
Loading
+13 −33
Original line number Original line Diff line number Diff line
@@ -283,29 +283,9 @@ def _sort_subs(subs):




def try_solve_incrementally(assumptions, exprs, em, to1=3000, to2=1000):
def try_solve_incrementally(assumptions, exprs, em, to1=3000, to2=1000):
    # check if we can evaluate some expression syntactically
    for a in assumptions:
        exprs = [em.substitute(e, (a, em.getTrue())) for e in exprs]
    # filter out expressions that are 'true'
    exprs = [e for e in exprs if not (e.is_concrete() and bool(e.value()))]

    solver = IncrementalSolver()
    solver.add(*assumptions)
    if assumptions:
    if assumptions:
        # try to subsume the implied expressions
        # First try to rewrite the formula into simpler form
        # assert solver.is_sat() is True # otherwise we'll subsume everything
        expr1 = em.conjunction(*exprs).rewrite_polynomials(assumptions)
        exprs = [e for e in exprs if solver.try_is_sat(500, em.Not(e)) is not False]
        r = solver.try_is_sat(1000, *exprs)
        if r is not None:
            return r
    else:
        # this will allow us to rewrite expressions
        assumptions = exprs

    # Now try to rewrite the formula into a simpler form
    expr1 = em.conjunction(*exprs)
    if not expr1.is_concrete():
        expr1 = expr1.rewrite_polynomials(assumptions)
        A = []
        A = []
        for i in range(len(assumptions)):
        for i in range(len(assumptions)):
            a = assumptions[i]
            a = assumptions[i]
@@ -313,12 +293,12 @@ def try_solve_incrementally(assumptions, exprs, em, to1=3000, to2=1000):
                a.rewrite_polynomials([x for n, x in enumerate(assumptions) if n != i])
                a.rewrite_polynomials([x for n, x in enumerate(assumptions) if n != i])
            )
            )
        assumptions = A
        assumptions = A
    solver = IncrementalSolver()
        r = IncrementalSolver().try_is_sat(to1, *assumptions, expr1)
    solver.add(*assumptions)
    r = solver.try_is_sat(to1, expr1)
        if r is not None:
        if r is not None:
            return r
            return r
        expr = em.conjunction(*assumptions, expr1)
        expr = em.conjunction(*assumptions, expr1)
    else:
        expr = em.conjunction(*assumptions, *exprs)


    ###
    ###
    # Now try abstractions
    # Now try abstractions
@@ -328,7 +308,7 @@ def try_solve_incrementally(assumptions, exprs, em, to1=3000, to2=1000):
        solver = IncrementalSolver()
        solver = IncrementalSolver()
        solver.add(rexpr.rewrite_and_simplify())
        solver.add(rexpr.rewrite_and_simplify())
        for placeholder, e in _sort_subs(subs):
        for placeholder, e in _sort_subs(subs):
            if solver.try_is_sat(to2) is False:
            if solver.is_sat() is False:
                return False
                return False
            solver.add(em.Eq(e, placeholder))
            solver.add(em.Eq(e, placeholder))
        # solve the un-abstracted expression
        # solve the un-abstracted expression
+4 −13
Original line number Original line Diff line number Diff line
@@ -99,10 +99,12 @@ class SEState(ExecutionState):
        if r is not None:
        if r is not None:
            return r
            return r


        conj = self.expr_manager().conjunction
        expr = conj(*e)
        r = try_solve_incrementally(self.constraints(), e, self.expr_manager())
        r = try_solve_incrementally(self.constraints(), e, self.expr_manager())
        if r is not None:
        if r is not None:
            return r
            return r
        return self._solver.is_sat(self.expr_manager().conjunction(*e))
        return self._solver.is_sat(expr)


    def try_is_sat(self, timeout, *e):
    def try_is_sat(self, timeout, *e):
        return self._solver.try_is_sat(timeout, *e)
        return self._solver.try_is_sat(timeout, *e)
@@ -112,18 +114,7 @@ class SEState(ExecutionState):
        Solve the PC and return True if it is sat. Handy in the cases
        Solve the PC and return True if it is sat. Handy in the cases
        when the state is constructed manually.
        when the state is constructed manually.
        """
        """
        C = self.constraints()
        return self.is_sat(*self.constraints())
        if not C:
            return True
        r = self._solver.try_is_sat(1000, *C)
        if r is not None:
            return r

        em = self.expr_manager()
        r = try_solve_incrementally([], C, em)
        if r is not None:
            return r
        return self._solver.is_sat(em.conjunction(*C))


    def concretize(self, *e):
    def concretize(self, *e):
        return self._solver.concretize(self.constraints(), *e)
        return self._solver.concretize(self.constraints(), *e)