1
votes

I need a solver for a specific logic that supports push and pop. So I generate a one using the SolverFor() function. Since some of the assertions are just constant assertions, like a == 2, I'd like to use the propagate-values tactic to simplify before I call solver.check(). So my question is:

is there a way to apply a tactic on a solver?

I know that I can do that for a Goal. But it seems to me that Goal does not support push and pop.

Any comment is appreciated. Thanks.

1

1 Answers

2
votes

Tactic objects only support non-incremental solving. They also do not provide push and pop methods. They are mainly intended for solving non-trivial problems. For convenience, we provide an API that wraps a tactic object as a solver object. The wrapping is very basic, the wrapper object keeps a stack of assertions, and every check is solved from scratch using the wrapped tactic.

The default Solver object in Z3 is a general purpose solver. By default, it performs constant propagation. We can control the behavior of this solver setting parameters. In future versions, we will provide additional control to solver objects. We will be able to use a subset of the available tactics to customize solver objects.

That being said, you are correct, the Goal object does not support push and pop. Internally, Goal objects support a copy operation that runs in constant time. Internally, shared data-structures are used to save memory. I will explicitly expose this functionality in future versions. Note that, this functionality is just saving space/memory. The effort to solve each goal will not be saved. I said "explicitly expose" because the functionality can be simulated with the following trick:

def copy_goal(g):
  return Tactic('skip')(g)[0]

x = Int('x')
g = Goal()
g.add(x < 10)
g.add(x > 0)
g1 = copy_goal(g)
g1.add(x != 5)
print g
print g1

The example above is available at: http://rise4fun.com/Z3Py/O3RO

Remark: the tactic smt implements the general purpose solver I mentioned above.