Here's how you can code this using z3py, for the purposes of this example, I took S
to be 40
and Val
to be 2
, but you can modify those values easily below in the corresponding lines for s.add
:
from z3 import *
S = BitVec ('S', 64)
X = BitVec ('X', 64)
Val = BitVec ('Val', 64)
s = Solver()
s.add (S == 40)
s.add (Val == 2)
s.add (S == Val * X * X * X - Val * X * X + Val * X - Val)
res = s.check()
if res == sat:
print s.model()
elif res == unsat:
print "No solution"
else:
print "Solver returned: " + res
When I run it, I get:
$ python b.py
[X = 4611686018427387907, Val = 2, S = 40]
This might look surprising, but remember that bit-vector arithmetic is modular; if you do the computation, you'll see that it indeed satisfies your equation.