def z3_bv_to_int(x): """BitVector to Integer Z3 conversion Parameters ---------- x : z3.BitVecRef or z3.BitVecNumRef BitVector variable to be converted to Int Returns ------- z3.ArithRef z3.ArithRef is an expression that will convert the BitVec into Integer inside Z3 rather than before insertion into the solver. This function wraps Z3 C API functions to allow for a python interpretation of BitVec to Int conversions. The returned object is an expression that Z3 will evaluate as an Int rather than BitVec during solving. Example ------- If you want to convert a BitVec into an Int:: In [1]: import z3 In [2]: from pySym import pyState.z3Helpers In [3]: s = z3.Solver() In [4]: x = z3.BitVec('x',32) In [5]: y = z3.Int('y') In [6]: x = pyState.z3Helpers.z3_bv_to_int(x) In [7]: s.add(x == y) In [8]: s Out[8]: [BV2Int(x) == y] In [9]: s.check() Out[9]: sat """ return z3.ArithRef(z3.Z3_mk_bv2int(x.ctx_ref(), x.as_ast(), 0), x.ctx)
def walk_bv_tonatural(self, formula, args, **kwargs): z3term = z3.Z3_mk_bv2int(self.ctx.ref(), args[0], False) z3.Z3_inc_ref(self.ctx.ref(), z3term) return z3term