Z3
Public Member Functions
BitVecRef Class Reference
+ Inheritance diagram for BitVecRef:

Public Member Functions

def sort (self)
 
def size (self)
 
def __add__ (self, other)
 
def __radd__ (self, other)
 
def __mul__ (self, other)
 
def __rmul__ (self, other)
 
def __sub__ (self, other)
 
def __rsub__ (self, other)
 
def __or__ (self, other)
 
def __ror__ (self, other)
 
def __and__ (self, other)
 
def __rand__ (self, other)
 
def __xor__ (self, other)
 
def __rxor__ (self, other)
 
def __pos__ (self)
 
def __neg__ (self)
 
def __invert__ (self)
 
def __div__ (self, other)
 
def __truediv__ (self, other)
 
def __rdiv__ (self, other)
 
def __rtruediv__ (self, other)
 
def __mod__ (self, other)
 
def __rmod__ (self, other)
 
def __le__ (self, other)
 
def __lt__ (self, other)
 
def __gt__ (self, other)
 
def __ge__ (self, other)
 
def __rshift__ (self, other)
 
def __lshift__ (self, other)
 
def __rrshift__ (self, other)
 
def __rlshift__ (self, other)
 
- Public Member Functions inherited from ExprRef
def as_ast (self)
 
def get_id (self)
 
def sort (self)
 
def sort_kind (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __ne__ (self, other)
 
def params (self)
 
def decl (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (self)
 
- Public Member Functions inherited from AstRef
def __init__ (self, ast, ctx=None)
 
def __del__ (self)
 
def __deepcopy__ (self, memo={})
 
def __str__ (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (self)
 
def ctx_ref (self)
 
def eq (self, other)
 
def translate (self, target)
 
def __copy__ (self)
 
def hash (self)
 
- Public Member Functions inherited from Z3PPObject
def use_pp (self)
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Bit-vector expressions.

Definition at line 3215 of file z3py.py.

Member Function Documentation

◆ __add__()

def __add__ (   self,
  other 
)
Create the Z3 expression `self + other`.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x + y
x + y
>>> (x + y).sort()
BitVec(32)

Definition at line 3240 of file z3py.py.

3240  def __add__(self, other):
3241  """Create the Z3 expression `self + other`.
3242 
3243  >>> x = BitVec('x', 32)
3244  >>> y = BitVec('y', 32)
3245  >>> x + y
3246  x + y
3247  >>> (x + y).sort()
3248  BitVec(32)
3249  """
3250  a, b = _coerce_exprs(self, other)
3251  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3252 
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.

◆ __and__()

def __and__ (   self,
  other 
)
Create the Z3 expression bitwise-and `self & other`.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x & y
x & y
>>> (x & y).sort()
BitVec(32)

Definition at line 3332 of file z3py.py.

3332  def __and__(self, other):
3333  """Create the Z3 expression bitwise-and `self & other`.
3334 
3335  >>> x = BitVec('x', 32)
3336  >>> y = BitVec('y', 32)
3337  >>> x & y
3338  x & y
3339  >>> (x & y).sort()
3340  BitVec(32)
3341  """
3342  a, b = _coerce_exprs(self, other)
3343  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3344 
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.

◆ __div__()

def __div__ (   self,
  other 
)
Create the Z3 expression (signed) division `self / other`.

Use the function UDiv() for unsigned division.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x / y
x/y
>>> (x / y).sort()
BitVec(32)
>>> (x / y).sexpr()
'(bvsdiv x y)'
>>> UDiv(x, y).sexpr()
'(bvudiv x y)'

Definition at line 3409 of file z3py.py.

3409  def __div__(self, other):
3410  """Create the Z3 expression (signed) division `self / other`.
3411 
3412  Use the function UDiv() for unsigned division.
3413 
3414  >>> x = BitVec('x', 32)
3415  >>> y = BitVec('y', 32)
3416  >>> x / y
3417  x/y
3418  >>> (x / y).sort()
3419  BitVec(32)
3420  >>> (x / y).sexpr()
3421  '(bvsdiv x y)'
3422  >>> UDiv(x, y).sexpr()
3423  '(bvudiv x y)'
3424  """
3425  a, b = _coerce_exprs(self, other)
3426  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3427 
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.

◆ __ge__()

def __ge__ (   self,
  other 
)
Create the Z3 expression (signed) `other >= self`.

Use the function UGE() for unsigned greater than or equal to.

>>> x, y = BitVecs('x y', 32)
>>> x >= y
x >= y
>>> (x >= y).sexpr()
'(bvsge x y)'
>>> UGE(x, y).sexpr()
'(bvuge x y)'

Definition at line 3539 of file z3py.py.

3539  def __ge__(self, other):
3540  """Create the Z3 expression (signed) `other >= self`.
3541 
3542  Use the function UGE() for unsigned greater than or equal to.
3543 
3544  >>> x, y = BitVecs('x y', 32)
3545  >>> x >= y
3546  x >= y
3547  >>> (x >= y).sexpr()
3548  '(bvsge x y)'
3549  >>> UGE(x, y).sexpr()
3550  '(bvuge x y)'
3551  """
3552  a, b = _coerce_exprs(self, other)
3553  return BoolRef(Z3_mk_bvsge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3554 
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.

◆ __gt__()

def __gt__ (   self,
  other 
)
Create the Z3 expression (signed) `other > self`.

Use the function UGT() for unsigned greater than.

>>> x, y = BitVecs('x y', 32)
>>> x > y
x > y
>>> (x > y).sexpr()
'(bvsgt x y)'
>>> UGT(x, y).sexpr()
'(bvugt x y)'

Definition at line 3523 of file z3py.py.

3523  def __gt__(self, other):
3524  """Create the Z3 expression (signed) `other > self`.
3525 
3526  Use the function UGT() for unsigned greater than.
3527 
3528  >>> x, y = BitVecs('x y', 32)
3529  >>> x > y
3530  x > y
3531  >>> (x > y).sexpr()
3532  '(bvsgt x y)'
3533  >>> UGT(x, y).sexpr()
3534  '(bvugt x y)'
3535  """
3536  a, b = _coerce_exprs(self, other)
3537  return BoolRef(Z3_mk_bvsgt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3538 
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.

◆ __invert__()

def __invert__ (   self)
Create the Z3 expression bitwise-not `~self`.

>>> x = BitVec('x', 32)
>>> ~x
~x
>>> simplify(~(~x))
x

Definition at line 3398 of file z3py.py.

3398  def __invert__(self):
3399  """Create the Z3 expression bitwise-not `~self`.
3400 
3401  >>> x = BitVec('x', 32)
3402  >>> ~x
3403  ~x
3404  >>> simplify(~(~x))
3405  x
3406  """
3407  return BitVecRef(Z3_mk_bvnot(self.ctx_ref(), self.as_ast()), self.ctx)
3408 
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.

◆ __le__()

def __le__ (   self,
  other 
)
Create the Z3 expression (signed) `other <= self`.

Use the function ULE() for unsigned less than or equal to.

>>> x, y = BitVecs('x y', 32)
>>> x <= y
x <= y
>>> (x <= y).sexpr()
'(bvsle x y)'
>>> ULE(x, y).sexpr()
'(bvule x y)'

Definition at line 3491 of file z3py.py.

3491  def __le__(self, other):
3492  """Create the Z3 expression (signed) `other <= self`.
3493 
3494  Use the function ULE() for unsigned less than or equal to.
3495 
3496  >>> x, y = BitVecs('x y', 32)
3497  >>> x <= y
3498  x <= y
3499  >>> (x <= y).sexpr()
3500  '(bvsle x y)'
3501  >>> ULE(x, y).sexpr()
3502  '(bvule x y)'
3503  """
3504  a, b = _coerce_exprs(self, other)
3505  return BoolRef(Z3_mk_bvsle(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3506 
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two&#39;s complement signed less than or equal to.

◆ __lshift__()

def __lshift__ (   self,
  other 
)
Create the Z3 expression left shift `self << other`

>>> x, y = BitVecs('x y', 32)
>>> x << y
x << y
>>> (x << y).sexpr()
'(bvshl x y)'
>>> simplify(BitVecVal(2, 3) << 1)
4

Definition at line 3585 of file z3py.py.

3585  def __lshift__(self, other):
3586  """Create the Z3 expression left shift `self << other`
3587 
3588  >>> x, y = BitVecs('x y', 32)
3589  >>> x << y
3590  x << y
3591  >>> (x << y).sexpr()
3592  '(bvshl x y)'
3593  >>> simplify(BitVecVal(2, 3) << 1)
3594  4
3595  """
3596  a, b = _coerce_exprs(self, other)
3597  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3598 
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.

◆ __lt__()

def __lt__ (   self,
  other 
)
Create the Z3 expression (signed) `other < self`.

Use the function ULT() for unsigned less than.

>>> x, y = BitVecs('x y', 32)
>>> x < y
x < y
>>> (x < y).sexpr()
'(bvslt x y)'
>>> ULT(x, y).sexpr()
'(bvult x y)'

Definition at line 3507 of file z3py.py.

3507  def __lt__(self, other):
3508  """Create the Z3 expression (signed) `other < self`.
3509 
3510  Use the function ULT() for unsigned less than.
3511 
3512  >>> x, y = BitVecs('x y', 32)
3513  >>> x < y
3514  x < y
3515  >>> (x < y).sexpr()
3516  '(bvslt x y)'
3517  >>> ULT(x, y).sexpr()
3518  '(bvult x y)'
3519  """
3520  a, b = _coerce_exprs(self, other)
3521  return BoolRef(Z3_mk_bvslt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3522 
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two&#39;s complement signed less than.

◆ __mod__()

def __mod__ (   self,
  other 
)
Create the Z3 expression (signed) mod `self % other`.

Use the function URem() for unsigned remainder, and SRem() for signed remainder.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x % y
x%y
>>> (x % y).sort()
BitVec(32)
>>> (x % y).sexpr()
'(bvsmod x y)'
>>> URem(x, y).sexpr()
'(bvurem x y)'
>>> SRem(x, y).sexpr()
'(bvsrem x y)'

Definition at line 3452 of file z3py.py.

3452  def __mod__(self, other):
3453  """Create the Z3 expression (signed) mod `self % other`.
3454 
3455  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3456 
3457  >>> x = BitVec('x', 32)
3458  >>> y = BitVec('y', 32)
3459  >>> x % y
3460  x%y
3461  >>> (x % y).sort()
3462  BitVec(32)
3463  >>> (x % y).sexpr()
3464  '(bvsmod x y)'
3465  >>> URem(x, y).sexpr()
3466  '(bvurem x y)'
3467  >>> SRem(x, y).sexpr()
3468  '(bvsrem x y)'
3469  """
3470  a, b = _coerce_exprs(self, other)
3471  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3472 
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two&#39;s complement signed remainder (sign follows divisor).

◆ __mul__()

def __mul__ (   self,
  other 
)
Create the Z3 expression `self * other`.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x * y
x*y
>>> (x * y).sort()
BitVec(32)

Definition at line 3263 of file z3py.py.

3263  def __mul__(self, other):
3264  """Create the Z3 expression `self * other`.
3265 
3266  >>> x = BitVec('x', 32)
3267  >>> y = BitVec('y', 32)
3268  >>> x * y
3269  x*y
3270  >>> (x * y).sort()
3271  BitVec(32)
3272  """
3273  a, b = _coerce_exprs(self, other)
3274  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3275 
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two&#39;s complement multiplication.

◆ __neg__()

def __neg__ (   self)
Return an expression representing `-self`.

>>> x = BitVec('x', 32)
>>> -x
-x
>>> simplify(-(-x))
x

Definition at line 3387 of file z3py.py.

3387  def __neg__(self):
3388  """Return an expression representing `-self`.
3389 
3390  >>> x = BitVec('x', 32)
3391  >>> -x
3392  -x
3393  >>> simplify(-(-x))
3394  x
3395  """
3396  return BitVecRef(Z3_mk_bvneg(self.ctx_ref(), self.as_ast()), self.ctx)
3397 
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two&#39;s complement unary minus.

◆ __or__()

def __or__ (   self,
  other 
)
Create the Z3 expression bitwise-or `self | other`.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x | y
x | y
>>> (x | y).sort()
BitVec(32)

Definition at line 3309 of file z3py.py.

3309  def __or__(self, other):
3310  """Create the Z3 expression bitwise-or `self | other`.
3311 
3312  >>> x = BitVec('x', 32)
3313  >>> y = BitVec('y', 32)
3314  >>> x | y
3315  x | y
3316  >>> (x | y).sort()
3317  BitVec(32)
3318  """
3319  a, b = _coerce_exprs(self, other)
3320  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3321 
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.

◆ __pos__()

def __pos__ (   self)
Return `self`.

>>> x = BitVec('x', 32)
>>> +x
x

Definition at line 3378 of file z3py.py.

3378  def __pos__(self):
3379  """Return `self`.
3380 
3381  >>> x = BitVec('x', 32)
3382  >>> +x
3383  x
3384  """
3385  return self
3386 

◆ __radd__()

def __radd__ (   self,
  other 
)
Create the Z3 expression `other + self`.

>>> x = BitVec('x', 32)
>>> 10 + x
10 + x

Definition at line 3253 of file z3py.py.

3253  def __radd__(self, other):
3254  """Create the Z3 expression `other + self`.
3255 
3256  >>> x = BitVec('x', 32)
3257  >>> 10 + x
3258  10 + x
3259  """
3260  a, b = _coerce_exprs(self, other)
3261  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3262 
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two&#39;s complement addition.

◆ __rand__()

def __rand__ (   self,
  other 
)
Create the Z3 expression bitwise-or `other & self`.

>>> x = BitVec('x', 32)
>>> 10 & x
10 & x

Definition at line 3345 of file z3py.py.

3345  def __rand__(self, other):
3346  """Create the Z3 expression bitwise-or `other & self`.
3347 
3348  >>> x = BitVec('x', 32)
3349  >>> 10 & x
3350  10 & x
3351  """
3352  a, b = _coerce_exprs(self, other)
3353  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3354 
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.

◆ __rdiv__()

def __rdiv__ (   self,
  other 
)
Create the Z3 expression (signed) division `other / self`.

Use the function UDiv() for unsigned division.

>>> x = BitVec('x', 32)
>>> 10 / x
10/x
>>> (10 / x).sexpr()
'(bvsdiv #x0000000a x)'
>>> UDiv(10, x).sexpr()
'(bvudiv #x0000000a x)'

Definition at line 3432 of file z3py.py.

3432  def __rdiv__(self, other):
3433  """Create the Z3 expression (signed) division `other / self`.
3434 
3435  Use the function UDiv() for unsigned division.
3436 
3437  >>> x = BitVec('x', 32)
3438  >>> 10 / x
3439  10/x
3440  >>> (10 / x).sexpr()
3441  '(bvsdiv #x0000000a x)'
3442  >>> UDiv(10, x).sexpr()
3443  '(bvudiv #x0000000a x)'
3444  """
3445  a, b = _coerce_exprs(self, other)
3446  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3447 
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two&#39;s complement signed division.

◆ __rlshift__()

def __rlshift__ (   self,
  other 
)
Create the Z3 expression left shift `other << self`.

Use the function LShR() for the right logical shift

>>> x = BitVec('x', 32)
>>> 10 << x
10 << x
>>> (10 << x).sexpr()
'(bvshl #x0000000a x)'

Definition at line 3613 of file z3py.py.

3613  def __rlshift__(self, other):
3614  """Create the Z3 expression left shift `other << self`.
3615 
3616  Use the function LShR() for the right logical shift
3617 
3618  >>> x = BitVec('x', 32)
3619  >>> 10 << x
3620  10 << x
3621  >>> (10 << x).sexpr()
3622  '(bvshl #x0000000a x)'
3623  """
3624  a, b = _coerce_exprs(self, other)
3625  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3626 
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.

◆ __rmod__()

def __rmod__ (   self,
  other 
)
Create the Z3 expression (signed) mod `other % self`.

Use the function URem() for unsigned remainder, and SRem() for signed remainder.

>>> x = BitVec('x', 32)
>>> 10 % x
10%x
>>> (10 % x).sexpr()
'(bvsmod #x0000000a x)'
>>> URem(10, x).sexpr()
'(bvurem #x0000000a x)'
>>> SRem(10, x).sexpr()
'(bvsrem #x0000000a x)'

Definition at line 3473 of file z3py.py.

3473  def __rmod__(self, other):
3474  """Create the Z3 expression (signed) mod `other % self`.
3475 
3476  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3477 
3478  >>> x = BitVec('x', 32)
3479  >>> 10 % x
3480  10%x
3481  >>> (10 % x).sexpr()
3482  '(bvsmod #x0000000a x)'
3483  >>> URem(10, x).sexpr()
3484  '(bvurem #x0000000a x)'
3485  >>> SRem(10, x).sexpr()
3486  '(bvsrem #x0000000a x)'
3487  """
3488  a, b = _coerce_exprs(self, other)
3489  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3490 
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two&#39;s complement signed remainder (sign follows divisor).

◆ __rmul__()

def __rmul__ (   self,
  other 
)
Create the Z3 expression `other * self`.

>>> x = BitVec('x', 32)
>>> 10 * x
10*x

Definition at line 3276 of file z3py.py.

3276  def __rmul__(self, other):
3277  """Create the Z3 expression `other * self`.
3278 
3279  >>> x = BitVec('x', 32)
3280  >>> 10 * x
3281  10*x
3282  """
3283  a, b = _coerce_exprs(self, other)
3284  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3285 
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two&#39;s complement multiplication.

◆ __ror__()

def __ror__ (   self,
  other 
)
Create the Z3 expression bitwise-or `other | self`.

>>> x = BitVec('x', 32)
>>> 10 | x
10 | x

Definition at line 3322 of file z3py.py.

3322  def __ror__(self, other):
3323  """Create the Z3 expression bitwise-or `other | self`.
3324 
3325  >>> x = BitVec('x', 32)
3326  >>> 10 | x
3327  10 | x
3328  """
3329  a, b = _coerce_exprs(self, other)
3330  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3331 
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.

◆ __rrshift__()

def __rrshift__ (   self,
  other 
)
Create the Z3 expression (arithmetical) right shift `other` >> `self`.

Use the function LShR() for the right logical shift

>>> x = BitVec('x', 32)
>>> 10 >> x
10 >> x
>>> (10 >> x).sexpr()
'(bvashr #x0000000a x)'

Definition at line 3599 of file z3py.py.

3599  def __rrshift__(self, other):
3600  """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3601 
3602  Use the function LShR() for the right logical shift
3603 
3604  >>> x = BitVec('x', 32)
3605  >>> 10 >> x
3606  10 >> x
3607  >>> (10 >> x).sexpr()
3608  '(bvashr #x0000000a x)'
3609  """
3610  a, b = _coerce_exprs(self, other)
3611  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3612 
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.

◆ __rshift__()

def __rshift__ (   self,
  other 
)
Create the Z3 expression (arithmetical) right shift `self >> other`

Use the function LShR() for the right logical shift

>>> x, y = BitVecs('x y', 32)
>>> x >> y
x >> y
>>> (x >> y).sexpr()
'(bvashr x y)'
>>> LShR(x, y).sexpr()
'(bvlshr x y)'
>>> BitVecVal(4, 3)
4
>>> BitVecVal(4, 3).as_signed_long()
-4
>>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
-2
>>> simplify(BitVecVal(4, 3) >> 1)
6
>>> simplify(LShR(BitVecVal(4, 3), 1))
2
>>> simplify(BitVecVal(2, 3) >> 1)
1
>>> simplify(LShR(BitVecVal(2, 3), 1))
1

Definition at line 3555 of file z3py.py.

3555  def __rshift__(self, other):
3556  """Create the Z3 expression (arithmetical) right shift `self >> other`
3557 
3558  Use the function LShR() for the right logical shift
3559 
3560  >>> x, y = BitVecs('x y', 32)
3561  >>> x >> y
3562  x >> y
3563  >>> (x >> y).sexpr()
3564  '(bvashr x y)'
3565  >>> LShR(x, y).sexpr()
3566  '(bvlshr x y)'
3567  >>> BitVecVal(4, 3)
3568  4
3569  >>> BitVecVal(4, 3).as_signed_long()
3570  -4
3571  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3572  -2
3573  >>> simplify(BitVecVal(4, 3) >> 1)
3574  6
3575  >>> simplify(LShR(BitVecVal(4, 3), 1))
3576  2
3577  >>> simplify(BitVecVal(2, 3) >> 1)
3578  1
3579  >>> simplify(LShR(BitVecVal(2, 3), 1))
3580  1
3581  """
3582  a, b = _coerce_exprs(self, other)
3583  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3584 
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.

◆ __rsub__()

def __rsub__ (   self,
  other 
)
Create the Z3 expression `other - self`.

>>> x = BitVec('x', 32)
>>> 10 - x
10 - x

Definition at line 3299 of file z3py.py.

3299  def __rsub__(self, other):
3300  """Create the Z3 expression `other - self`.
3301 
3302  >>> x = BitVec('x', 32)
3303  >>> 10 - x
3304  10 - x
3305  """
3306  a, b = _coerce_exprs(self, other)
3307  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3308 
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two&#39;s complement subtraction.

◆ __rtruediv__()

def __rtruediv__ (   self,
  other 
)
Create the Z3 expression (signed) division `other / self`.

Definition at line 3448 of file z3py.py.

3448  def __rtruediv__(self, other):
3449  """Create the Z3 expression (signed) division `other / self`."""
3450  return self.__rdiv__(other)
3451 

◆ __rxor__()

def __rxor__ (   self,
  other 
)
Create the Z3 expression bitwise-xor `other ^ self`.

>>> x = BitVec('x', 32)
>>> 10 ^ x
10 ^ x

Definition at line 3368 of file z3py.py.

3368  def __rxor__(self, other):
3369  """Create the Z3 expression bitwise-xor `other ^ self`.
3370 
3371  >>> x = BitVec('x', 32)
3372  >>> 10 ^ x
3373  10 ^ x
3374  """
3375  a, b = _coerce_exprs(self, other)
3376  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3377 
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.

◆ __sub__()

def __sub__ (   self,
  other 
)
Create the Z3 expression `self - other`.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x - y
x - y
>>> (x - y).sort()
BitVec(32)

Definition at line 3286 of file z3py.py.

3286  def __sub__(self, other):
3287  """Create the Z3 expression `self - other`.
3288 
3289  >>> x = BitVec('x', 32)
3290  >>> y = BitVec('y', 32)
3291  >>> x - y
3292  x - y
3293  >>> (x - y).sort()
3294  BitVec(32)
3295  """
3296  a, b = _coerce_exprs(self, other)
3297  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3298 
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two&#39;s complement subtraction.

◆ __truediv__()

def __truediv__ (   self,
  other 
)
Create the Z3 expression (signed) division `self / other`.

Definition at line 3428 of file z3py.py.

3428  def __truediv__(self, other):
3429  """Create the Z3 expression (signed) division `self / other`."""
3430  return self.__div__(other)
3431 

◆ __xor__()

def __xor__ (   self,
  other 
)
Create the Z3 expression bitwise-xor `self ^ other`.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x ^ y
x ^ y
>>> (x ^ y).sort()
BitVec(32)

Definition at line 3355 of file z3py.py.

3355  def __xor__(self, other):
3356  """Create the Z3 expression bitwise-xor `self ^ other`.
3357 
3358  >>> x = BitVec('x', 32)
3359  >>> y = BitVec('y', 32)
3360  >>> x ^ y
3361  x ^ y
3362  >>> (x ^ y).sort()
3363  BitVec(32)
3364  """
3365  a, b = _coerce_exprs(self, other)
3366  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3367 
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.

◆ size()

def size (   self)
Return the number of bits of the bit-vector expression `self`.

>>> x = BitVec('x', 32)
>>> (x + 1).size()
32
>>> Concat(x, x).size()
64

Definition at line 3229 of file z3py.py.

3229  def size(self):
3230  """Return the number of bits of the bit-vector expression `self`.
3231 
3232  >>> x = BitVec('x', 32)
3233  >>> (x + 1).size()
3234  32
3235  >>> Concat(x, x).size()
3236  64
3237  """
3238  return self.sort().size()
3239 

◆ sort()

def sort (   self)
Return the sort of the bit-vector expression `self`.

>>> x = BitVec('x', 32)
>>> x.sort()
BitVec(32)
>>> x.sort() == BitVecSort(32)
True

Definition at line 3218 of file z3py.py.

Referenced by BitVecRef.__add__(), BitVecRef.__and__(), BitVecRef.__div__(), BitVecRef.__mod__(), BitVecRef.__mul__(), BitVecRef.__or__(), BitVecRef.__sub__(), and BitVecRef.__xor__().

3218  def sort(self):
3219  """Return the sort of the bit-vector expression `self`.
3220 
3221  >>> x = BitVec('x', 32)
3222  >>> x.sort()
3223  BitVec(32)
3224  >>> x.sort() == BitVecSort(32)
3225  True
3226  """
3227  return BitVecSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
3228 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.