Replies: 2 comments 5 replies
-
|
I realized after writing this that I ought to be able to use Z3_eval_smtlib2_string, which seems to have the semantics I desire (that a sequence of calls to it with strings s1, ..., sn, is like a single call with the concatenation of the si) to do what I want. Where I would do C/C++ API, calls, just convert what I want to do to a string and call Z3_eval_smtlib2_string. But this doesn't quite work. Because Z3_eval_smtlib2_string takes only a Z3_context as argument, not a Z3_solver. I guess it creates a solver whose lifetime is the duration of the call? In any case, this sequence of calls (where c is a Z3_context): yields the desired "unsat" result, while this one (where s is a solver with c as a context): does not; res is sat. Which is obvious in retrospect, because the Z3_eval_smtlib2_string call didn't mention s. This is a problem, because I'd really like to be able to query the model of the solver, treating it something like a debugging session. I can't do that with the first form above, the one that works. So I'm back to tearing my hair out... |
Beta Was this translation helpful? Give feedback.
-
Missing functionality can be added to the C++ API. Or you can call C API functions directly from C++ (with appropriate reference counting). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been banging my head agaist this problem for a couple of days; thought I'd see if anyone has a solution.
I'm trying to write a program verification system (for C++), using Z3 to do the theorem-proving. This would have three kinds of Z3 input:
I would ideally like to do the first two by passing the text representation to Z3. The third would be done via the C++ interface.
My problem is that this just doesn't seem to work. At first I was just looking at the C++ interface, and saw parse_string. I assume this would have side effects on the Z3_context, declaring things. But doing multiple calls to parse_string doesn't work the way I thought it would; things defined in the first string are not defined in the second.
I thought this variant might be relevant:
but I couldn't figure out a way to do one parse_string and retrieve the sorts and decls.
So I looked Z3_api.h, and got excited by Z3_eval_smtlib2_string, which seemed more like what I was looking for. And, indeed, if I do two calls to this, the first with
(define-fun inc ((i Int)) Int (+ i 1))and the second with:
The check-sat yields unsat, as expected.
However, I'm still stuck: I can't figure out how to get the C++ API to recognize the definitions done in the Z3_eval_smtlib2_string calls. If I try to do the second call described above via the C++ interface, as in:
I get sat as the result!
I assume the problem is that the
auto inc = c.function("inc", c.int_sort(), c.int_sort());creates a new, undefined function named "inc" instead of looking up the previously-function with that name. To convince myself of this, and that I wasn't going crazy, I substited this version for "body", essentially inlining the definition of "inc":
auto body = (x + c.int_val(1)) > x;That correctly got unsat.
So, I'm stuck, wondering whether it's possible, in the C or C++ apis, to create a function application that applies a function defined in a previous call to Z3_eval_smtlib2_string. So far I haven't figured anything out.
I'm investigating whether it's possible to do this completely in the C or C++ apis. The C++ api doesn't seem to have a way to give a func_decl a body. The C api does (Z3_add_rec_def) -- but, AFAICT, this forces everything to use the C api, which would be unfortunate. I'll probably try to complete the small experiment with C api, see if that works.
But I'm hoping against hope that someone will point out a misunderstanding I've had, and how this is actually simple :-)...!
Beta Was this translation helpful? Give feedback.
All reactions