z3py

Need help understanding the equation

时光怂恿深爱的人放手 提交于 2019-11-27 06:56:03
问题 Have the equation Pell x*x - 193 * y*y = 1 in z3py: x = BitVec('x',64) y = BitVec('y',64) solve(x*x - 193 * y*y == 1, x > 0, y > 0) Result: [y = 2744248620923429728, x = 8169167793018974721] Why? P.S. Valid answer: [y = 448036604040, x = 6224323426849] 回答1: It is possible to use Bit-vector arithmetic to solve Diophantine equations. The basic idea is to use ZeroExt to avoid the overflows pointed out by Pad. For example, if we are multiplying two bit-vectors x and y of size n , then we must add

Check overflow with Z3

二次信任 提交于 2019-11-27 06:20:33
问题 I'm new to Z3 and I was checking the online python tutorial. Then I thought I could check overflow behavior in BitVecs. I wrote this code: x = BitVec('x', 3) y = Int('y') solve(BV2Int(x) == y, Not(BV2Int(x + 1) == (y + 1))) and I was expecting [y = 7, x = 7] (i.e. when values are equal but successors are not because x + 1 will be 0 and y + 1 will be 8) But Z3 answers [y = 0, x = 0]. What am I doing wrong? 回答1: I don't think you're doing anything wrong, looks like BV2Int is buggy: x = BitVec(

Z3py: how to get the list of variables from a formula?

坚强是说给别人听的谎言 提交于 2019-11-26 17:05:33
问题 In Z3Py, I have a formula. How can I retrieve the list of variables using in the formula? Thanks. 回答1: Vu Nguyen contributed several useful procedures to Z3Py. He implemented a procedure get_vars to collect the list of used variables. This procedure and many others can be found here. His contributions will be available in the next official release. Here is a version of get_vars that can be executed online at rise4fun. # Wrapper for allowing Z3 ASTs to be stored into Python Hashtables. class

(Z3Py) checking all solutions for equation

浪子不回头ぞ 提交于 2019-11-26 08:16:41
问题 In Z3Py, how can I check if equation for given constraints have only one solution? If more than one solution, how can I enumerate them? 回答1: You can do that by adding a new constraint that blocks the model returned by Z3. For example, suppose that in the model returned by Z3 we have that x = 0 and y = 1 . Then, we can block this model by adding the constraint Or(x != 0, y != 1) . The following script does the trick. You can try it online at: http://rise4fun.com/Z3Py/4blB Note that the