1
votes

I am using Z3 with SMT2 via C API/JNA/Scala and seems to work pretty well.

I want to try incremental solving. So at first I translate this by using Z3_parse_smtlib2_string:

(declare-fun x () Int)
(assert (>= x 0))
(check-sat)
(get-model)

Then I get back an Z3_ast, put it into a solver via Z3_solver_assert, check it with Z3_solver_check and retrieve a model via Z3_solver_get_model (if the check returned satisfiable, which is the case in this example). So far there is no problem.

But when I want to assert something additionally like this:

(assert (= x 1))

I get stuck at the point where Z3_parse_smtlib2_string is called, because it complains, that x is an unknown constant. If I add also add the declare-fun to the second snippet I get an invalid argument error. Shouldn't this variable exist already in the environment? Do I have to set the additional parameters of Z3_parse_smtlib2_string? How can I get those out of the previsously parsed formula?

Also using (set-option :global-decls true) did not work as Z3 tells me that this option value cannot be modified after initialization.

Does anybody have a clue how to solve this problem?

1
Shameless plug: have you tried https://github.com/psuter/ScalaZ3? (disclosure: I'm the main author.).Philippe

1 Answers

3
votes

Z3_parse_smtlib2_string can take as extra arguments lists of existing sorts and constants. The second time you call it you can therefore tell it that you already know what x stands for.

To recover the declared constants and sorts from the first parsing pass, you can use Z3_get_smtlib_num_decls, Z3_get_smtlib_decl and similarly for sorts.