问题
For the same reasons than described here (user defined uninterpreted function) I want to define my own uninterpreted function
bvredxnor() : xnor over the bits of a given bitvector.
If I follow the example given here (example of universal quantifiers with C API) I don't know what sort to provide to the argument of my function (a bitvector)
I could create a bitvector sort of a given length, but I would like to have it for bitvectors of any length.
Looking at bitvector functions available in the C API, I noticed that the type of all arguments is Z3_ast, so I was thinking I could use the same generic type. But there is no function in the API that generate a Z3_ast sort... (writing this I feel i am touching the difference between types and sorts, but it is still a bit unclear)
Is the solution to use uninterpreted sorts? And if so, in doing that, wouldn't I loose some precision in my model by enlarging the type too much, while this artefact is only for debugging purpose? I mean, if I apply this function to a bitvector, will this work?
Thank you in advance,
AG.
回答1:
SMTLib does not allow bit-vectors with variable lengths. That is, you cannot express problems that are parameterized over the bitvector lengths. The reason for this is that properties about bit-vectors do not necessarily hold parametrically over lengths, due to cardinality issues. To wit, consider:
exists x0, x1, x2, x3, x4. distinct [x0, x1, x2, x3, x4]
This property says there are at least 5 distinct bit-vector values. That is true if the domain of x has length at least 3, but not otherwise. So, the validity of the statement depends on the domain. You can also view this as a limitation of the first-order nature of SMTLib in general.
Of course, the above applies to SMTLib, and not necessarily to Z3. Leo and co have always been ahead of the curve, and Z3 does have many tricks that go beyond what SMTLib calls for. It'd be a pleasant surprise if Z3 does support some notion of parametric bit-vector problems in the way you are describing.
来源:https://stackoverflow.com/questions/10329721/generic-bitvector-type-of-any-length