Z3Prover / z3

The Z3 Theorem Prover
Other
10.3k stars 1.48k forks source link

simple string-based API ? #6546

Closed pcarbonn closed 1 year ago

pcarbonn commented 1 year ago

Regularly, I wish Z3 would expose a string-based API that would allow me to write a Python program like this:

with session():
    send("(declare-const p Bool)")
    send("(assert (and p (not p)))")
    out = send("(check-sat)")
    if out == "sat":
        ....

In other words, I would send SMTLib2 statements, and get a string result.

I would think it is easy to develop such an API on top of the existing SMTLib2 support. It would then be possible to build a REPL for Z3 (e.g., for education). If every SMT solver supported this API, it would be straightforward to build portfolio solvers.

The performance impact of using string should be minimal. Are there any drawbacks I'm missing?

NikolajBjorner commented 1 year ago

Try the following change to z3.py or something similar outside

def send(cmd, ctx=None):
      ctx = _get_ctx(cx)
      return Z3_eval_smtlib2_string(cmd, ctx.ref())