Z3 4.0 Z3_parse_smtlib2_string(Z3 4.0 Z3_parse_smt

2019-06-25 12:39发布

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?

Answer 1:

Z3_parse_smtlib2_string可以利用现有的排序和常量作为额外的参数列表。 你怎么称呼它的第二次,你可以因此告诉它,你已经知道什么x代表。

要恢复从第一解析通的常量和排序,你可以使用Z3_get_smtlib_num_declsZ3_get_smtlib_decl同样地,对于排序。



文章来源: Z3 4.0 Z3_parse_smtlib2_string
标签: z3