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?