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_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)
 
def from_string (self, s)
 
def serialize (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 __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (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 3533 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 3558 of file z3py.py.

3558  def __add__(self, other):
3559  """Create the Z3 expression `self + other`.
3560 
3561  >>> x = BitVec('x', 32)
3562  >>> y = BitVec('y', 32)
3563  >>> x + y
3564  x + y
3565  >>> (x + y).sort()
3566  BitVec(32)
3567  """
3568  a, b = _coerce_exprs(self, other)
3569  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3570 
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 3650 of file z3py.py.

3650  def __and__(self, other):
3651  """Create the Z3 expression bitwise-and `self & other`.
3652 
3653  >>> x = BitVec('x', 32)
3654  >>> y = BitVec('y', 32)
3655  >>> x & y
3656  x & y
3657  >>> (x & y).sort()
3658  BitVec(32)
3659  """
3660  a, b = _coerce_exprs(self, other)
3661  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3662 
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 3727 of file z3py.py.

3727  def __div__(self, other):
3728  """Create the Z3 expression (signed) division `self / other`.
3729 
3730  Use the function UDiv() for unsigned division.
3731 
3732  >>> x = BitVec('x', 32)
3733  >>> y = BitVec('y', 32)
3734  >>> x / y
3735  x/y
3736  >>> (x / y).sort()
3737  BitVec(32)
3738  >>> (x / y).sexpr()
3739  '(bvsdiv x y)'
3740  >>> UDiv(x, y).sexpr()
3741  '(bvudiv x y)'
3742  """
3743  a, b = _coerce_exprs(self, other)
3744  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3745 
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.

Referenced by ArithRef.__truediv__(), BitVecRef.__truediv__(), and FPRef.__truediv__().

◆ __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 3857 of file z3py.py.

3857  def __ge__(self, other):
3858  """Create the Z3 expression (signed) `other >= self`.
3859 
3860  Use the function UGE() for unsigned greater than or equal to.
3861 
3862  >>> x, y = BitVecs('x y', 32)
3863  >>> x >= y
3864  x >= y
3865  >>> (x >= y).sexpr()
3866  '(bvsge x y)'
3867  >>> UGE(x, y).sexpr()
3868  '(bvuge x y)'
3869  """
3870  a, b = _coerce_exprs(self, other)
3871  return BoolRef(Z3_mk_bvsge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3872 
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 3841 of file z3py.py.

3841  def __gt__(self, other):
3842  """Create the Z3 expression (signed) `other > self`.
3843 
3844  Use the function UGT() for unsigned greater than.
3845 
3846  >>> x, y = BitVecs('x y', 32)
3847  >>> x > y
3848  x > y
3849  >>> (x > y).sexpr()
3850  '(bvsgt x y)'
3851  >>> UGT(x, y).sexpr()
3852  '(bvugt x y)'
3853  """
3854  a, b = _coerce_exprs(self, other)
3855  return BoolRef(Z3_mk_bvsgt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3856 
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 3716 of file z3py.py.

3716  def __invert__(self):
3717  """Create the Z3 expression bitwise-not `~self`.
3718 
3719  >>> x = BitVec('x', 32)
3720  >>> ~x
3721  ~x
3722  >>> simplify(~(~x))
3723  x
3724  """
3725  return BitVecRef(Z3_mk_bvnot(self.ctx_ref(), self.as_ast()), self.ctx)
3726 
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 3809 of file z3py.py.

3809  def __le__(self, other):
3810  """Create the Z3 expression (signed) `other <= self`.
3811 
3812  Use the function ULE() for unsigned less than or equal to.
3813 
3814  >>> x, y = BitVecs('x y', 32)
3815  >>> x <= y
3816  x <= y
3817  >>> (x <= y).sexpr()
3818  '(bvsle x y)'
3819  >>> ULE(x, y).sexpr()
3820  '(bvule x y)'
3821  """
3822  a, b = _coerce_exprs(self, other)
3823  return BoolRef(Z3_mk_bvsle(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3824 
Z3_ast Z3_API Z3_mk_bvsle(Z3_context c, Z3_ast t1, Z3_ast t2)
Two'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 3903 of file z3py.py.

3903  def __lshift__(self, other):
3904  """Create the Z3 expression left shift `self << other`
3905 
3906  >>> x, y = BitVecs('x y', 32)
3907  >>> x << y
3908  x << y
3909  >>> (x << y).sexpr()
3910  '(bvshl x y)'
3911  >>> simplify(BitVecVal(2, 3) << 1)
3912  4
3913  """
3914  a, b = _coerce_exprs(self, other)
3915  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3916 
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 3825 of file z3py.py.

3825  def __lt__(self, other):
3826  """Create the Z3 expression (signed) `other < self`.
3827 
3828  Use the function ULT() for unsigned less than.
3829 
3830  >>> x, y = BitVecs('x y', 32)
3831  >>> x < y
3832  x < y
3833  >>> (x < y).sexpr()
3834  '(bvslt x y)'
3835  >>> ULT(x, y).sexpr()
3836  '(bvult x y)'
3837  """
3838  a, b = _coerce_exprs(self, other)
3839  return BoolRef(Z3_mk_bvslt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3840 
Z3_ast Z3_API Z3_mk_bvslt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two'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 3770 of file z3py.py.

3770  def __mod__(self, other):
3771  """Create the Z3 expression (signed) mod `self % other`.
3772 
3773  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3774 
3775  >>> x = BitVec('x', 32)
3776  >>> y = BitVec('y', 32)
3777  >>> x % y
3778  x%y
3779  >>> (x % y).sort()
3780  BitVec(32)
3781  >>> (x % y).sexpr()
3782  '(bvsmod x y)'
3783  >>> URem(x, y).sexpr()
3784  '(bvurem x y)'
3785  >>> SRem(x, y).sexpr()
3786  '(bvsrem x y)'
3787  """
3788  a, b = _coerce_exprs(self, other)
3789  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3790 
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two'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 3581 of file z3py.py.

3581  def __mul__(self, other):
3582  """Create the Z3 expression `self * other`.
3583 
3584  >>> x = BitVec('x', 32)
3585  >>> y = BitVec('y', 32)
3586  >>> x * y
3587  x*y
3588  >>> (x * y).sort()
3589  BitVec(32)
3590  """
3591  a, b = _coerce_exprs(self, other)
3592  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3593 
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement multiplication.

◆ __neg__()

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

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

Definition at line 3705 of file z3py.py.

3705  def __neg__(self):
3706  """Return an expression representing `-self`.
3707 
3708  >>> x = BitVec('x', 32)
3709  >>> -x
3710  -x
3711  >>> simplify(-(-x))
3712  x
3713  """
3714  return BitVecRef(Z3_mk_bvneg(self.ctx_ref(), self.as_ast()), self.ctx)
3715 
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two'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 3627 of file z3py.py.

3627  def __or__(self, other):
3628  """Create the Z3 expression bitwise-or `self | other`.
3629 
3630  >>> x = BitVec('x', 32)
3631  >>> y = BitVec('y', 32)
3632  >>> x | y
3633  x | y
3634  >>> (x | y).sort()
3635  BitVec(32)
3636  """
3637  a, b = _coerce_exprs(self, other)
3638  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3639 
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 3696 of file z3py.py.

3696  def __pos__(self):
3697  """Return `self`.
3698 
3699  >>> x = BitVec('x', 32)
3700  >>> +x
3701  x
3702  """
3703  return self
3704 

◆ __radd__()

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

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

Definition at line 3571 of file z3py.py.

3571  def __radd__(self, other):
3572  """Create the Z3 expression `other + self`.
3573 
3574  >>> x = BitVec('x', 32)
3575  >>> 10 + x
3576  10 + x
3577  """
3578  a, b = _coerce_exprs(self, other)
3579  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3580 

◆ __rand__()

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

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

Definition at line 3663 of file z3py.py.

3663  def __rand__(self, other):
3664  """Create the Z3 expression bitwise-or `other & self`.
3665 
3666  >>> x = BitVec('x', 32)
3667  >>> 10 & x
3668  10 & x
3669  """
3670  a, b = _coerce_exprs(self, other)
3671  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3672 

◆ __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 3750 of file z3py.py.

3750  def __rdiv__(self, other):
3751  """Create the Z3 expression (signed) division `other / self`.
3752 
3753  Use the function UDiv() for unsigned division.
3754 
3755  >>> x = BitVec('x', 32)
3756  >>> 10 / x
3757  10/x
3758  >>> (10 / x).sexpr()
3759  '(bvsdiv #x0000000a x)'
3760  >>> UDiv(10, x).sexpr()
3761  '(bvudiv #x0000000a x)'
3762  """
3763  a, b = _coerce_exprs(self, other)
3764  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3765 

Referenced by ArithRef.__rtruediv__(), BitVecRef.__rtruediv__(), and FPRef.__rtruediv__().

◆ __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 3931 of file z3py.py.

3931  def __rlshift__(self, other):
3932  """Create the Z3 expression left shift `other << self`.
3933 
3934  Use the function LShR() for the right logical shift
3935 
3936  >>> x = BitVec('x', 32)
3937  >>> 10 << x
3938  10 << x
3939  >>> (10 << x).sexpr()
3940  '(bvshl #x0000000a x)'
3941  """
3942  a, b = _coerce_exprs(self, other)
3943  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3944 
3945 

◆ __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 3791 of file z3py.py.

3791  def __rmod__(self, other):
3792  """Create the Z3 expression (signed) mod `other % self`.
3793 
3794  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3795 
3796  >>> x = BitVec('x', 32)
3797  >>> 10 % x
3798  10%x
3799  >>> (10 % x).sexpr()
3800  '(bvsmod #x0000000a x)'
3801  >>> URem(10, x).sexpr()
3802  '(bvurem #x0000000a x)'
3803  >>> SRem(10, x).sexpr()
3804  '(bvsrem #x0000000a x)'
3805  """
3806  a, b = _coerce_exprs(self, other)
3807  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3808 

◆ __rmul__()

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

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

Definition at line 3594 of file z3py.py.

3594  def __rmul__(self, other):
3595  """Create the Z3 expression `other * self`.
3596 
3597  >>> x = BitVec('x', 32)
3598  >>> 10 * x
3599  10*x
3600  """
3601  a, b = _coerce_exprs(self, other)
3602  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3603 

◆ __ror__()

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

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

Definition at line 3640 of file z3py.py.

3640  def __ror__(self, other):
3641  """Create the Z3 expression bitwise-or `other | self`.
3642 
3643  >>> x = BitVec('x', 32)
3644  >>> 10 | x
3645  10 | x
3646  """
3647  a, b = _coerce_exprs(self, other)
3648  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3649 

◆ __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 3917 of file z3py.py.

3917  def __rrshift__(self, other):
3918  """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3919 
3920  Use the function LShR() for the right logical shift
3921 
3922  >>> x = BitVec('x', 32)
3923  >>> 10 >> x
3924  10 >> x
3925  >>> (10 >> x).sexpr()
3926  '(bvashr #x0000000a x)'
3927  """
3928  a, b = _coerce_exprs(self, other)
3929  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3930 
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 3873 of file z3py.py.

3873  def __rshift__(self, other):
3874  """Create the Z3 expression (arithmetical) right shift `self >> other`
3875 
3876  Use the function LShR() for the right logical shift
3877 
3878  >>> x, y = BitVecs('x y', 32)
3879  >>> x >> y
3880  x >> y
3881  >>> (x >> y).sexpr()
3882  '(bvashr x y)'
3883  >>> LShR(x, y).sexpr()
3884  '(bvlshr x y)'
3885  >>> BitVecVal(4, 3)
3886  4
3887  >>> BitVecVal(4, 3).as_signed_long()
3888  -4
3889  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3890  -2
3891  >>> simplify(BitVecVal(4, 3) >> 1)
3892  6
3893  >>> simplify(LShR(BitVecVal(4, 3), 1))
3894  2
3895  >>> simplify(BitVecVal(2, 3) >> 1)
3896  1
3897  >>> simplify(LShR(BitVecVal(2, 3), 1))
3898  1
3899  """
3900  a, b = _coerce_exprs(self, other)
3901  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3902 

◆ __rsub__()

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

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

Definition at line 3617 of file z3py.py.

3617  def __rsub__(self, other):
3618  """Create the Z3 expression `other - self`.
3619 
3620  >>> x = BitVec('x', 32)
3621  >>> 10 - x
3622  10 - x
3623  """
3624  a, b = _coerce_exprs(self, other)
3625  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3626 
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.

◆ __rtruediv__()

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

Definition at line 3766 of file z3py.py.

3766  def __rtruediv__(self, other):
3767  """Create the Z3 expression (signed) division `other / self`."""
3768  return self.__rdiv__(other)
3769 

◆ __rxor__()

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

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

Definition at line 3686 of file z3py.py.

3686  def __rxor__(self, other):
3687  """Create the Z3 expression bitwise-xor `other ^ self`.
3688 
3689  >>> x = BitVec('x', 32)
3690  >>> 10 ^ x
3691  10 ^ x
3692  """
3693  a, b = _coerce_exprs(self, other)
3694  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3695 
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 3604 of file z3py.py.

3604  def __sub__(self, other):
3605  """Create the Z3 expression `self - other`.
3606 
3607  >>> x = BitVec('x', 32)
3608  >>> y = BitVec('y', 32)
3609  >>> x - y
3610  x - y
3611  >>> (x - y).sort()
3612  BitVec(32)
3613  """
3614  a, b = _coerce_exprs(self, other)
3615  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3616 

◆ __truediv__()

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

Definition at line 3746 of file z3py.py.

3746  def __truediv__(self, other):
3747  """Create the Z3 expression (signed) division `self / other`."""
3748  return self.__div__(other)
3749 

◆ __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 3673 of file z3py.py.

3673  def __xor__(self, other):
3674  """Create the Z3 expression bitwise-xor `self ^ other`.
3675 
3676  >>> x = BitVec('x', 32)
3677  >>> y = BitVec('y', 32)
3678  >>> x ^ y
3679  x ^ y
3680  >>> (x ^ y).sort()
3681  BitVec(32)
3682  """
3683  a, b = _coerce_exprs(self, other)
3684  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3685 

◆ 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 3547 of file z3py.py.

3547  def size(self):
3548  """Return the number of bits of the bit-vector expression `self`.
3549 
3550  >>> x = BitVec('x', 32)
3551  >>> (x + 1).size()
3552  32
3553  >>> Concat(x, x).size()
3554  64
3555  """
3556  return self.sort().size()
3557 

Referenced by ParamDescrsRef.__len__(), Goal.__len__(), BitVecNumRef.as_signed_long(), and BitVecSortRef.subsort().

◆ 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

Reimplemented from ExprRef.

Definition at line 3536 of file z3py.py.

3536  def sort(self):
3537  """Return the sort of the bit-vector expression `self`.
3538 
3539  >>> x = BitVec('x', 32)
3540  >>> x.sort()
3541  BitVec(32)
3542  >>> x.sort() == BitVecSort(32)
3543  True
3544  """
3545  return BitVecSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
3546 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

Referenced by FPNumRef.as_string(), ArrayRef.domain(), ArrayRef.domain_n(), FPRef.ebits(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), FPRef.sbits(), BitVecRef.size(), and ExprRef.sort_kind().