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

3261  def __add__(self, other):
3262  """Create the Z3 expression `self + other`.
3263 
3264  >>> x = BitVec('x', 32)
3265  >>> y = BitVec('y', 32)
3266  >>> x + y
3267  x + y
3268  >>> (x + y).sort()
3269  BitVec(32)
3270  """
3271  a, b = _coerce_exprs(self, other)
3272  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3273 
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 3353 of file z3py.py.

3353  def __and__(self, other):
3354  """Create the Z3 expression bitwise-and `self & other`.
3355 
3356  >>> x = BitVec('x', 32)
3357  >>> y = BitVec('y', 32)
3358  >>> x & y
3359  x & y
3360  >>> (x & y).sort()
3361  BitVec(32)
3362  """
3363  a, b = _coerce_exprs(self, other)
3364  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3365 
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 3430 of file z3py.py.

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

Referenced by 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 3560 of file z3py.py.

3560  def __ge__(self, other):
3561  """Create the Z3 expression (signed) `other >= self`.
3562 
3563  Use the function UGE() for unsigned greater than or equal to.
3564 
3565  >>> x, y = BitVecs('x y', 32)
3566  >>> x >= y
3567  x >= y
3568  >>> (x >= y).sexpr()
3569  '(bvsge x y)'
3570  >>> UGE(x, y).sexpr()
3571  '(bvuge x y)'
3572  """
3573  a, b = _coerce_exprs(self, other)
3574  return BoolRef(Z3_mk_bvsge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3575 
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 3544 of file z3py.py.

3544  def __gt__(self, other):
3545  """Create the Z3 expression (signed) `other > self`.
3546 
3547  Use the function UGT() for unsigned greater than.
3548 
3549  >>> x, y = BitVecs('x y', 32)
3550  >>> x > y
3551  x > y
3552  >>> (x > y).sexpr()
3553  '(bvsgt x y)'
3554  >>> UGT(x, y).sexpr()
3555  '(bvugt x y)'
3556  """
3557  a, b = _coerce_exprs(self, other)
3558  return BoolRef(Z3_mk_bvsgt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3559 
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 3419 of file z3py.py.

3419  def __invert__(self):
3420  """Create the Z3 expression bitwise-not `~self`.
3421 
3422  >>> x = BitVec('x', 32)
3423  >>> ~x
3424  ~x
3425  >>> simplify(~(~x))
3426  x
3427  """
3428  return BitVecRef(Z3_mk_bvnot(self.ctx_ref(), self.as_ast()), self.ctx)
3429 
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 3512 of file z3py.py.

3512  def __le__(self, other):
3513  """Create the Z3 expression (signed) `other <= self`.
3514 
3515  Use the function ULE() for unsigned less than or equal to.
3516 
3517  >>> x, y = BitVecs('x y', 32)
3518  >>> x <= y
3519  x <= y
3520  >>> (x <= y).sexpr()
3521  '(bvsle x y)'
3522  >>> ULE(x, y).sexpr()
3523  '(bvule x y)'
3524  """
3525  a, b = _coerce_exprs(self, other)
3526  return BoolRef(Z3_mk_bvsle(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3527 
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 3606 of file z3py.py.

3606  def __lshift__(self, other):
3607  """Create the Z3 expression left shift `self << other`
3608 
3609  >>> x, y = BitVecs('x y', 32)
3610  >>> x << y
3611  x << y
3612  >>> (x << y).sexpr()
3613  '(bvshl x y)'
3614  >>> simplify(BitVecVal(2, 3) << 1)
3615  4
3616  """
3617  a, b = _coerce_exprs(self, other)
3618  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3619 
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 3528 of file z3py.py.

3528  def __lt__(self, other):
3529  """Create the Z3 expression (signed) `other < self`.
3530 
3531  Use the function ULT() for unsigned less than.
3532 
3533  >>> x, y = BitVecs('x y', 32)
3534  >>> x < y
3535  x < y
3536  >>> (x < y).sexpr()
3537  '(bvslt x y)'
3538  >>> ULT(x, y).sexpr()
3539  '(bvult x y)'
3540  """
3541  a, b = _coerce_exprs(self, other)
3542  return BoolRef(Z3_mk_bvslt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3543 
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 3473 of file z3py.py.

3473  def __mod__(self, other):
3474  """Create the Z3 expression (signed) mod `self % other`.
3475 
3476  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3477 
3478  >>> x = BitVec('x', 32)
3479  >>> y = BitVec('y', 32)
3480  >>> x % y
3481  x%y
3482  >>> (x % y).sort()
3483  BitVec(32)
3484  >>> (x % y).sexpr()
3485  '(bvsmod x y)'
3486  >>> URem(x, y).sexpr()
3487  '(bvurem x y)'
3488  >>> SRem(x, y).sexpr()
3489  '(bvsrem x y)'
3490  """
3491  a, b = _coerce_exprs(self, other)
3492  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3493 
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 3284 of file z3py.py.

3284  def __mul__(self, other):
3285  """Create the Z3 expression `self * other`.
3286 
3287  >>> x = BitVec('x', 32)
3288  >>> y = BitVec('y', 32)
3289  >>> x * y
3290  x*y
3291  >>> (x * y).sort()
3292  BitVec(32)
3293  """
3294  a, b = _coerce_exprs(self, other)
3295  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3296 
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 3408 of file z3py.py.

3408  def __neg__(self):
3409  """Return an expression representing `-self`.
3410 
3411  >>> x = BitVec('x', 32)
3412  >>> -x
3413  -x
3414  >>> simplify(-(-x))
3415  x
3416  """
3417  return BitVecRef(Z3_mk_bvneg(self.ctx_ref(), self.as_ast()), self.ctx)
3418 
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 3330 of file z3py.py.

3330  def __or__(self, other):
3331  """Create the Z3 expression bitwise-or `self | other`.
3332 
3333  >>> x = BitVec('x', 32)
3334  >>> y = BitVec('y', 32)
3335  >>> x | y
3336  x | y
3337  >>> (x | y).sort()
3338  BitVec(32)
3339  """
3340  a, b = _coerce_exprs(self, other)
3341  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3342 
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 3399 of file z3py.py.

3399  def __pos__(self):
3400  """Return `self`.
3401 
3402  >>> x = BitVec('x', 32)
3403  >>> +x
3404  x
3405  """
3406  return self
3407 

◆ __radd__()

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

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

Definition at line 3274 of file z3py.py.

3274  def __radd__(self, other):
3275  """Create the Z3 expression `other + self`.
3276 
3277  >>> x = BitVec('x', 32)
3278  >>> 10 + x
3279  10 + x
3280  """
3281  a, b = _coerce_exprs(self, other)
3282  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3283 
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two'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 3366 of file z3py.py.

3366  def __rand__(self, other):
3367  """Create the Z3 expression bitwise-or `other & self`.
3368 
3369  >>> x = BitVec('x', 32)
3370  >>> 10 & x
3371  10 & x
3372  """
3373  a, b = _coerce_exprs(self, other)
3374  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3375 
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 3453 of file z3py.py.

3453  def __rdiv__(self, other):
3454  """Create the Z3 expression (signed) division `other / self`.
3455 
3456  Use the function UDiv() for unsigned division.
3457 
3458  >>> x = BitVec('x', 32)
3459  >>> 10 / x
3460  10/x
3461  >>> (10 / x).sexpr()
3462  '(bvsdiv #x0000000a x)'
3463  >>> UDiv(10, x).sexpr()
3464  '(bvudiv #x0000000a x)'
3465  """
3466  a, b = _coerce_exprs(self, other)
3467  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3468 
Z3_ast Z3_API Z3_mk_bvsdiv(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed division.

Referenced by 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 3634 of file z3py.py.

3634  def __rlshift__(self, other):
3635  """Create the Z3 expression left shift `other << self`.
3636 
3637  Use the function LShR() for the right logical shift
3638 
3639  >>> x = BitVec('x', 32)
3640  >>> 10 << x
3641  10 << x
3642  >>> (10 << x).sexpr()
3643  '(bvshl #x0000000a x)'
3644  """
3645  a, b = _coerce_exprs(self, other)
3646  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3647 
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 3494 of file z3py.py.

3494  def __rmod__(self, other):
3495  """Create the Z3 expression (signed) mod `other % self`.
3496 
3497  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3498 
3499  >>> x = BitVec('x', 32)
3500  >>> 10 % x
3501  10%x
3502  >>> (10 % x).sexpr()
3503  '(bvsmod #x0000000a x)'
3504  >>> URem(10, x).sexpr()
3505  '(bvurem #x0000000a x)'
3506  >>> SRem(10, x).sexpr()
3507  '(bvsrem #x0000000a x)'
3508  """
3509  a, b = _coerce_exprs(self, other)
3510  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3511 
Z3_ast Z3_API Z3_mk_bvsmod(Z3_context c, Z3_ast t1, Z3_ast t2)
Two'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 3297 of file z3py.py.

3297  def __rmul__(self, other):
3298  """Create the Z3 expression `other * self`.
3299 
3300  >>> x = BitVec('x', 32)
3301  >>> 10 * x
3302  10*x
3303  """
3304  a, b = _coerce_exprs(self, other)
3305  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3306 
Z3_ast Z3_API Z3_mk_bvmul(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two'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 3343 of file z3py.py.

3343  def __ror__(self, other):
3344  """Create the Z3 expression bitwise-or `other | self`.
3345 
3346  >>> x = BitVec('x', 32)
3347  >>> 10 | x
3348  10 | x
3349  """
3350  a, b = _coerce_exprs(self, other)
3351  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3352 
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 3620 of file z3py.py.

3620  def __rrshift__(self, other):
3621  """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3622 
3623  Use the function LShR() for the right logical shift
3624 
3625  >>> x = BitVec('x', 32)
3626  >>> 10 >> x
3627  10 >> x
3628  >>> (10 >> x).sexpr()
3629  '(bvashr #x0000000a x)'
3630  """
3631  a, b = _coerce_exprs(self, other)
3632  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3633 
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 3576 of file z3py.py.

3576  def __rshift__(self, other):
3577  """Create the Z3 expression (arithmetical) right shift `self >> other`
3578 
3579  Use the function LShR() for the right logical shift
3580 
3581  >>> x, y = BitVecs('x y', 32)
3582  >>> x >> y
3583  x >> y
3584  >>> (x >> y).sexpr()
3585  '(bvashr x y)'
3586  >>> LShR(x, y).sexpr()
3587  '(bvlshr x y)'
3588  >>> BitVecVal(4, 3)
3589  4
3590  >>> BitVecVal(4, 3).as_signed_long()
3591  -4
3592  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3593  -2
3594  >>> simplify(BitVecVal(4, 3) >> 1)
3595  6
3596  >>> simplify(LShR(BitVecVal(4, 3), 1))
3597  2
3598  >>> simplify(BitVecVal(2, 3) >> 1)
3599  1
3600  >>> simplify(LShR(BitVecVal(2, 3), 1))
3601  1
3602  """
3603  a, b = _coerce_exprs(self, other)
3604  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3605 
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 3320 of file z3py.py.

3320  def __rsub__(self, other):
3321  """Create the Z3 expression `other - self`.
3322 
3323  >>> x = BitVec('x', 32)
3324  >>> 10 - x
3325  10 - x
3326  """
3327  a, b = _coerce_exprs(self, other)
3328  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3329 
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 3469 of file z3py.py.

3469  def __rtruediv__(self, other):
3470  """Create the Z3 expression (signed) division `other / self`."""
3471  return self.__rdiv__(other)
3472 

◆ __rxor__()

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

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

Definition at line 3389 of file z3py.py.

3389  def __rxor__(self, other):
3390  """Create the Z3 expression bitwise-xor `other ^ self`.
3391 
3392  >>> x = BitVec('x', 32)
3393  >>> 10 ^ x
3394  10 ^ x
3395  """
3396  a, b = _coerce_exprs(self, other)
3397  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3398 
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 3307 of file z3py.py.

3307  def __sub__(self, other):
3308  """Create the Z3 expression `self - other`.
3309 
3310  >>> x = BitVec('x', 32)
3311  >>> y = BitVec('y', 32)
3312  >>> x - y
3313  x - y
3314  >>> (x - y).sort()
3315  BitVec(32)
3316  """
3317  a, b = _coerce_exprs(self, other)
3318  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3319 
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement subtraction.

◆ __truediv__()

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

Definition at line 3449 of file z3py.py.

3449  def __truediv__(self, other):
3450  """Create the Z3 expression (signed) division `self / other`."""
3451  return self.__div__(other)
3452 

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

3376  def __xor__(self, other):
3377  """Create the Z3 expression bitwise-xor `self ^ other`.
3378 
3379  >>> x = BitVec('x', 32)
3380  >>> y = BitVec('y', 32)
3381  >>> x ^ y
3382  x ^ y
3383  >>> (x ^ y).sort()
3384  BitVec(32)
3385  """
3386  a, b = _coerce_exprs(self, other)
3387  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3388 
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 3250 of file z3py.py.

3250  def size(self):
3251  """Return the number of bits of the bit-vector expression `self`.
3252 
3253  >>> x = BitVec('x', 32)
3254  >>> (x + 1).size()
3255  32
3256  >>> Concat(x, x).size()
3257  64
3258  """
3259  return self.sort().size()
3260 

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

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

3239  def sort(self):
3240  """Return the sort of the bit-vector expression `self`.
3241 
3242  >>> x = BitVec('x', 32)
3243  >>> x.sort()
3244  BitVec(32)
3245  >>> x.sort() == BitVecSort(32)
3246  True
3247  """
3248  return BitVecSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
3249 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.