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)
 
- 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 3451 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 3476 of file z3py.py.

3476  def __add__(self, other):
3477  """Create the Z3 expression `self + other`.
3478 
3479  >>> x = BitVec('x', 32)
3480  >>> y = BitVec('y', 32)
3481  >>> x + y
3482  x + y
3483  >>> (x + y).sort()
3484  BitVec(32)
3485  """
3486  a, b = _coerce_exprs(self, other)
3487  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3488 
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 3568 of file z3py.py.

3568  def __and__(self, other):
3569  """Create the Z3 expression bitwise-and `self & other`.
3570 
3571  >>> x = BitVec('x', 32)
3572  >>> y = BitVec('y', 32)
3573  >>> x & y
3574  x & y
3575  >>> (x & y).sort()
3576  BitVec(32)
3577  """
3578  a, b = _coerce_exprs(self, other)
3579  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3580 
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 3645 of file z3py.py.

3645  def __div__(self, other):
3646  """Create the Z3 expression (signed) division `self / other`.
3647 
3648  Use the function UDiv() for unsigned division.
3649 
3650  >>> x = BitVec('x', 32)
3651  >>> y = BitVec('y', 32)
3652  >>> x / y
3653  x/y
3654  >>> (x / y).sort()
3655  BitVec(32)
3656  >>> (x / y).sexpr()
3657  '(bvsdiv x y)'
3658  >>> UDiv(x, y).sexpr()
3659  '(bvudiv x y)'
3660  """
3661  a, b = _coerce_exprs(self, other)
3662  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3663 
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 3775 of file z3py.py.

3775  def __ge__(self, other):
3776  """Create the Z3 expression (signed) `other >= self`.
3777 
3778  Use the function UGE() for unsigned greater than or equal to.
3779 
3780  >>> x, y = BitVecs('x y', 32)
3781  >>> x >= y
3782  x >= y
3783  >>> (x >= y).sexpr()
3784  '(bvsge x y)'
3785  >>> UGE(x, y).sexpr()
3786  '(bvuge x y)'
3787  """
3788  a, b = _coerce_exprs(self, other)
3789  return BoolRef(Z3_mk_bvsge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3790 
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 3759 of file z3py.py.

3759  def __gt__(self, other):
3760  """Create the Z3 expression (signed) `other > self`.
3761 
3762  Use the function UGT() for unsigned greater than.
3763 
3764  >>> x, y = BitVecs('x y', 32)
3765  >>> x > y
3766  x > y
3767  >>> (x > y).sexpr()
3768  '(bvsgt x y)'
3769  >>> UGT(x, y).sexpr()
3770  '(bvugt x y)'
3771  """
3772  a, b = _coerce_exprs(self, other)
3773  return BoolRef(Z3_mk_bvsgt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3774 
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 3634 of file z3py.py.

3634  def __invert__(self):
3635  """Create the Z3 expression bitwise-not `~self`.
3636 
3637  >>> x = BitVec('x', 32)
3638  >>> ~x
3639  ~x
3640  >>> simplify(~(~x))
3641  x
3642  """
3643  return BitVecRef(Z3_mk_bvnot(self.ctx_ref(), self.as_ast()), self.ctx)
3644 
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 3727 of file z3py.py.

3727  def __le__(self, other):
3728  """Create the Z3 expression (signed) `other <= self`.
3729 
3730  Use the function ULE() for unsigned less than or equal to.
3731 
3732  >>> x, y = BitVecs('x y', 32)
3733  >>> x <= y
3734  x <= y
3735  >>> (x <= y).sexpr()
3736  '(bvsle x y)'
3737  >>> ULE(x, y).sexpr()
3738  '(bvule x y)'
3739  """
3740  a, b = _coerce_exprs(self, other)
3741  return BoolRef(Z3_mk_bvsle(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3742 
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 3821 of file z3py.py.

3821  def __lshift__(self, other):
3822  """Create the Z3 expression left shift `self << other`
3823 
3824  >>> x, y = BitVecs('x y', 32)
3825  >>> x << y
3826  x << y
3827  >>> (x << y).sexpr()
3828  '(bvshl x y)'
3829  >>> simplify(BitVecVal(2, 3) << 1)
3830  4
3831  """
3832  a, b = _coerce_exprs(self, other)
3833  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3834 
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 3743 of file z3py.py.

3743  def __lt__(self, other):
3744  """Create the Z3 expression (signed) `other < self`.
3745 
3746  Use the function ULT() for unsigned less than.
3747 
3748  >>> x, y = BitVecs('x y', 32)
3749  >>> x < y
3750  x < y
3751  >>> (x < y).sexpr()
3752  '(bvslt x y)'
3753  >>> ULT(x, y).sexpr()
3754  '(bvult x y)'
3755  """
3756  a, b = _coerce_exprs(self, other)
3757  return BoolRef(Z3_mk_bvslt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3758 
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 3688 of file z3py.py.

3688  def __mod__(self, other):
3689  """Create the Z3 expression (signed) mod `self % other`.
3690 
3691  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3692 
3693  >>> x = BitVec('x', 32)
3694  >>> y = BitVec('y', 32)
3695  >>> x % y
3696  x%y
3697  >>> (x % y).sort()
3698  BitVec(32)
3699  >>> (x % y).sexpr()
3700  '(bvsmod x y)'
3701  >>> URem(x, y).sexpr()
3702  '(bvurem x y)'
3703  >>> SRem(x, y).sexpr()
3704  '(bvsrem x y)'
3705  """
3706  a, b = _coerce_exprs(self, other)
3707  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3708 
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 3499 of file z3py.py.

3499  def __mul__(self, other):
3500  """Create the Z3 expression `self * other`.
3501 
3502  >>> x = BitVec('x', 32)
3503  >>> y = BitVec('y', 32)
3504  >>> x * y
3505  x*y
3506  >>> (x * y).sort()
3507  BitVec(32)
3508  """
3509  a, b = _coerce_exprs(self, other)
3510  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3511 
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 3623 of file z3py.py.

3623  def __neg__(self):
3624  """Return an expression representing `-self`.
3625 
3626  >>> x = BitVec('x', 32)
3627  >>> -x
3628  -x
3629  >>> simplify(-(-x))
3630  x
3631  """
3632  return BitVecRef(Z3_mk_bvneg(self.ctx_ref(), self.as_ast()), self.ctx)
3633 
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 3545 of file z3py.py.

3545  def __or__(self, other):
3546  """Create the Z3 expression bitwise-or `self | other`.
3547 
3548  >>> x = BitVec('x', 32)
3549  >>> y = BitVec('y', 32)
3550  >>> x | y
3551  x | y
3552  >>> (x | y).sort()
3553  BitVec(32)
3554  """
3555  a, b = _coerce_exprs(self, other)
3556  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3557 
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 3614 of file z3py.py.

3614  def __pos__(self):
3615  """Return `self`.
3616 
3617  >>> x = BitVec('x', 32)
3618  >>> +x
3619  x
3620  """
3621  return self
3622 

◆ __radd__()

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

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

Definition at line 3489 of file z3py.py.

3489  def __radd__(self, other):
3490  """Create the Z3 expression `other + self`.
3491 
3492  >>> x = BitVec('x', 32)
3493  >>> 10 + x
3494  10 + x
3495  """
3496  a, b = _coerce_exprs(self, other)
3497  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3498 

◆ __rand__()

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

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

Definition at line 3581 of file z3py.py.

3581  def __rand__(self, other):
3582  """Create the Z3 expression bitwise-or `other & self`.
3583 
3584  >>> x = BitVec('x', 32)
3585  >>> 10 & x
3586  10 & x
3587  """
3588  a, b = _coerce_exprs(self, other)
3589  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3590 

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

3668  def __rdiv__(self, other):
3669  """Create the Z3 expression (signed) division `other / self`.
3670 
3671  Use the function UDiv() for unsigned division.
3672 
3673  >>> x = BitVec('x', 32)
3674  >>> 10 / x
3675  10/x
3676  >>> (10 / x).sexpr()
3677  '(bvsdiv #x0000000a x)'
3678  >>> UDiv(10, x).sexpr()
3679  '(bvudiv #x0000000a x)'
3680  """
3681  a, b = _coerce_exprs(self, other)
3682  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3683 

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

3849  def __rlshift__(self, other):
3850  """Create the Z3 expression left shift `other << self`.
3851 
3852  Use the function LShR() for the right logical shift
3853 
3854  >>> x = BitVec('x', 32)
3855  >>> 10 << x
3856  10 << x
3857  >>> (10 << x).sexpr()
3858  '(bvshl #x0000000a x)'
3859  """
3860  a, b = _coerce_exprs(self, other)
3861  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3862 
3863 

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

3709  def __rmod__(self, other):
3710  """Create the Z3 expression (signed) mod `other % self`.
3711 
3712  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3713 
3714  >>> x = BitVec('x', 32)
3715  >>> 10 % x
3716  10%x
3717  >>> (10 % x).sexpr()
3718  '(bvsmod #x0000000a x)'
3719  >>> URem(10, x).sexpr()
3720  '(bvurem #x0000000a x)'
3721  >>> SRem(10, x).sexpr()
3722  '(bvsrem #x0000000a x)'
3723  """
3724  a, b = _coerce_exprs(self, other)
3725  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3726 

◆ __rmul__()

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

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

Definition at line 3512 of file z3py.py.

3512  def __rmul__(self, other):
3513  """Create the Z3 expression `other * self`.
3514 
3515  >>> x = BitVec('x', 32)
3516  >>> 10 * x
3517  10*x
3518  """
3519  a, b = _coerce_exprs(self, other)
3520  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3521 

◆ __ror__()

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

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

Definition at line 3558 of file z3py.py.

3558  def __ror__(self, other):
3559  """Create the Z3 expression bitwise-or `other | self`.
3560 
3561  >>> x = BitVec('x', 32)
3562  >>> 10 | x
3563  10 | x
3564  """
3565  a, b = _coerce_exprs(self, other)
3566  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3567 

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

3835  def __rrshift__(self, other):
3836  """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3837 
3838  Use the function LShR() for the right logical shift
3839 
3840  >>> x = BitVec('x', 32)
3841  >>> 10 >> x
3842  10 >> x
3843  >>> (10 >> x).sexpr()
3844  '(bvashr #x0000000a x)'
3845  """
3846  a, b = _coerce_exprs(self, other)
3847  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3848 
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 3791 of file z3py.py.

3791  def __rshift__(self, other):
3792  """Create the Z3 expression (arithmetical) right shift `self >> other`
3793 
3794  Use the function LShR() for the right logical shift
3795 
3796  >>> x, y = BitVecs('x y', 32)
3797  >>> x >> y
3798  x >> y
3799  >>> (x >> y).sexpr()
3800  '(bvashr x y)'
3801  >>> LShR(x, y).sexpr()
3802  '(bvlshr x y)'
3803  >>> BitVecVal(4, 3)
3804  4
3805  >>> BitVecVal(4, 3).as_signed_long()
3806  -4
3807  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3808  -2
3809  >>> simplify(BitVecVal(4, 3) >> 1)
3810  6
3811  >>> simplify(LShR(BitVecVal(4, 3), 1))
3812  2
3813  >>> simplify(BitVecVal(2, 3) >> 1)
3814  1
3815  >>> simplify(LShR(BitVecVal(2, 3), 1))
3816  1
3817  """
3818  a, b = _coerce_exprs(self, other)
3819  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3820 

◆ __rsub__()

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

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

Definition at line 3535 of file z3py.py.

3535  def __rsub__(self, other):
3536  """Create the Z3 expression `other - self`.
3537 
3538  >>> x = BitVec('x', 32)
3539  >>> 10 - x
3540  10 - x
3541  """
3542  a, b = _coerce_exprs(self, other)
3543  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3544 
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 3684 of file z3py.py.

3684  def __rtruediv__(self, other):
3685  """Create the Z3 expression (signed) division `other / self`."""
3686  return self.__rdiv__(other)
3687 

◆ __rxor__()

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

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

Definition at line 3604 of file z3py.py.

3604  def __rxor__(self, other):
3605  """Create the Z3 expression bitwise-xor `other ^ self`.
3606 
3607  >>> x = BitVec('x', 32)
3608  >>> 10 ^ x
3609  10 ^ x
3610  """
3611  a, b = _coerce_exprs(self, other)
3612  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3613 
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 3522 of file z3py.py.

3522  def __sub__(self, other):
3523  """Create the Z3 expression `self - other`.
3524 
3525  >>> x = BitVec('x', 32)
3526  >>> y = BitVec('y', 32)
3527  >>> x - y
3528  x - y
3529  >>> (x - y).sort()
3530  BitVec(32)
3531  """
3532  a, b = _coerce_exprs(self, other)
3533  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3534 

◆ __truediv__()

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

Definition at line 3664 of file z3py.py.

3664  def __truediv__(self, other):
3665  """Create the Z3 expression (signed) division `self / other`."""
3666  return self.__div__(other)
3667 

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

3591  def __xor__(self, other):
3592  """Create the Z3 expression bitwise-xor `self ^ other`.
3593 
3594  >>> x = BitVec('x', 32)
3595  >>> y = BitVec('y', 32)
3596  >>> x ^ y
3597  x ^ y
3598  >>> (x ^ y).sort()
3599  BitVec(32)
3600  """
3601  a, b = _coerce_exprs(self, other)
3602  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3603 

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

3465  def size(self):
3466  """Return the number of bits of the bit-vector expression `self`.
3467 
3468  >>> x = BitVec('x', 32)
3469  >>> (x + 1).size()
3470  32
3471  >>> Concat(x, x).size()
3472  64
3473  """
3474  return self.sort().size()
3475 

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

3454  def sort(self):
3455  """Return the sort of the bit-vector expression `self`.
3456 
3457  >>> x = BitVec('x', 32)
3458  >>> x.sort()
3459  BitVec(32)
3460  >>> x.sort() == BitVecSort(32)
3461  True
3462  """
3463  return BitVecSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
3464 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.

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