-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bv2int and int2bv slow? #1481
Comments
I did another experiment, it seems |
Here is a related query that returns unsat immediately:
Since bv2int is uninterpreted, the "expected" value for ibv (=0x80000000) |
I'm attaching another example based on @kren1 's query where bv2int is probably unsafe to use
|
bv2int is interpreted. It maps bit-vectors to non-negative integers using the formula Sum_i 2^i*x_i, where x_i is the i'th bit. in bit-vector x (least significant bit has index 0). Therefore (assert (= -1 (bv2int ibv))) should be unsat. Therefore we have int2bv(bv2int x) = x, but on the other hand bv2int((_ int2bv N) x) is not the same as x, since it maps integer x to a bit-vector corresponding to x mod 2^N, where N is the bit-width supplied as argument to int2bv. So the bit-blasted version of the bv2int.txt cannot directly afford itself to make simplifications that get rid of int2bv. Even if you restricted the range of the arguments to int2bv to be within the boundaries 0..2^N-1 Z3 would not recognize this in any of its preprocessing or inprocessing. It therefore expands int2bv defining each bit position as a property of its arguments mod 2^j, j = 0...,N. The only way a position into a string can be both # and @ at the same time is when the position does not exist. The semantics of str.indexof sets the position to -1 for non-existing characters. Since the range of bv2int is non-negative you get unsat as expected. There is nothing "wrong" with Z3's behavior on the above example. |
Thanks @NikolajBjorner ! we've used the documentation from z3/src/api/z3_api.h that says bv2int
Just to conclude your remark, I've compared the following 2 tests, which are essentially identical except the bit-vector width. If I understand you correctly, then there should be a time difference in the two queries solution time (and there is: 38 sec vs. 1 sec) because proving (= (bv2int ((_ int2bv N) i)) i) is not an O(1) immediate conclusion (with the corresponding constraints [0...2^N-1])
And:
|
…erpreted, raise in #1481 Signed-off-by: Nikolaj Bjorner <[email protected]>
Thanks, yes that documentation does not correspond to the current state. |
I would like to add to this thread the next two (sat) examples that
With the answer:
And when i is constrained to be positive, the answer is sat too:
With the answer:
Thanks again, this issue can be closed. |
Thanks for clearing this up. |
I have two fairly complex string quires bitblast.txt and bv2int.txt.
They should be the same, except that bv2int.txt uses
bv2int
andint2bv
and bitblast.txt usesite
expressions to bitblast for a couple of integers: 0,1,2,3,4,5,6,30 .For me bitblast.txt terminates in under a second whereas bv2int.txt was running for 17hours, used 3.5GB of memory and then I gave up.
So I'm wondering if
bv2int
andint2bv
are just not supported in this context?I also tried with smt.string_solver=z3str3 , which returned unknown.
The text was updated successfully, but these errors were encountered: