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

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

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

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

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

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

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

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

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

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

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

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

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

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

3610  def __pos__(self):
3611  """Return `self`.
3612 
3613  >>> x = BitVec('x', 32)
3614  >>> +x
3615  x
3616  """
3617  return self
3618 

◆ __radd__()

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

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

Definition at line 3485 of file z3py.py.

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

◆ __rand__()

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

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

Definition at line 3577 of file z3py.py.

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

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

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

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

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

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

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

◆ __rmul__()

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

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

Definition at line 3508 of file z3py.py.

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

◆ __ror__()

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

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

Definition at line 3554 of file z3py.py.

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

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

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

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

◆ __rsub__()

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

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

Definition at line 3531 of file z3py.py.

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

3680  def __rtruediv__(self, other):
3681  """Create the Z3 expression (signed) division `other / self`."""
3682  return self.__rdiv__(other)
3683 

◆ __rxor__()

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

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

Definition at line 3600 of file z3py.py.

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

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

◆ __truediv__()

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

Definition at line 3660 of file z3py.py.

3660  def __truediv__(self, other):
3661  """Create the Z3 expression (signed) division `self / other`."""
3662  return self.__div__(other)
3663 

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

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

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

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

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

3450  def sort(self):
3451  """Return the sort of the bit-vector expression `self`.
3452 
3453  >>> x = BitVec('x', 32)
3454  >>> x.sort()
3455  BitVec(32)
3456  >>> x.sort() == BitVecSort(32)
3457  True
3458  """
3459  return BitVecSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
3460 
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().