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

3229  def __add__(self, other):
3230  """Create the Z3 expression `self + other`.
3231 
3232  >>> x = BitVec('x', 32)
3233  >>> y = BitVec('y', 32)
3234  >>> x + y
3235  x + y
3236  >>> (x + y).sort()
3237  BitVec(32)
3238  """
3239  a, b = _coerce_exprs(self, other)
3240  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3241 
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 3321 of file z3py.py.

3321  def __and__(self, other):
3322  """Create the Z3 expression bitwise-and `self & other`.
3323 
3324  >>> x = BitVec('x', 32)
3325  >>> y = BitVec('y', 32)
3326  >>> x & y
3327  x & y
3328  >>> (x & y).sort()
3329  BitVec(32)
3330  """
3331  a, b = _coerce_exprs(self, other)
3332  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3333 
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 3398 of file z3py.py.

3398  def __div__(self, other):
3399  """Create the Z3 expression (signed) division `self / other`.
3400 
3401  Use the function UDiv() for unsigned division.
3402 
3403  >>> x = BitVec('x', 32)
3404  >>> y = BitVec('y', 32)
3405  >>> x / y
3406  x/y
3407  >>> (x / y).sort()
3408  BitVec(32)
3409  >>> (x / y).sexpr()
3410  '(bvsdiv x y)'
3411  >>> UDiv(x, y).sexpr()
3412  '(bvudiv x y)'
3413  """
3414  a, b = _coerce_exprs(self, other)
3415  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3416 
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 3528 of file z3py.py.

3528  def __ge__(self, other):
3529  """Create the Z3 expression (signed) `other >= self`.
3530 
3531  Use the function UGE() for unsigned greater than or equal to.
3532 
3533  >>> x, y = BitVecs('x y', 32)
3534  >>> x >= y
3535  x >= y
3536  >>> (x >= y).sexpr()
3537  '(bvsge x y)'
3538  >>> UGE(x, y).sexpr()
3539  '(bvuge x y)'
3540  """
3541  a, b = _coerce_exprs(self, other)
3542  return BoolRef(Z3_mk_bvsge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3543 
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 3512 of file z3py.py.

3512  def __gt__(self, other):
3513  """Create the Z3 expression (signed) `other > self`.
3514 
3515  Use the function UGT() for unsigned greater than.
3516 
3517  >>> x, y = BitVecs('x y', 32)
3518  >>> x > y
3519  x > y
3520  >>> (x > y).sexpr()
3521  '(bvsgt x y)'
3522  >>> UGT(x, y).sexpr()
3523  '(bvugt x y)'
3524  """
3525  a, b = _coerce_exprs(self, other)
3526  return BoolRef(Z3_mk_bvsgt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3527 
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 3387 of file z3py.py.

3387  def __invert__(self):
3388  """Create the Z3 expression bitwise-not `~self`.
3389 
3390  >>> x = BitVec('x', 32)
3391  >>> ~x
3392  ~x
3393  >>> simplify(~(~x))
3394  x
3395  """
3396  return BitVecRef(Z3_mk_bvnot(self.ctx_ref(), self.as_ast()), self.ctx)
3397 
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 3480 of file z3py.py.

3480  def __le__(self, other):
3481  """Create the Z3 expression (signed) `other <= self`.
3482 
3483  Use the function ULE() for unsigned less than or equal to.
3484 
3485  >>> x, y = BitVecs('x y', 32)
3486  >>> x <= y
3487  x <= y
3488  >>> (x <= y).sexpr()
3489  '(bvsle x y)'
3490  >>> ULE(x, y).sexpr()
3491  '(bvule x y)'
3492  """
3493  a, b = _coerce_exprs(self, other)
3494  return BoolRef(Z3_mk_bvsle(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3495 
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 3574 of file z3py.py.

3574  def __lshift__(self, other):
3575  """Create the Z3 expression left shift `self << other`
3576 
3577  >>> x, y = BitVecs('x y', 32)
3578  >>> x << y
3579  x << y
3580  >>> (x << y).sexpr()
3581  '(bvshl x y)'
3582  >>> simplify(BitVecVal(2, 3) << 1)
3583  4
3584  """
3585  a, b = _coerce_exprs(self, other)
3586  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3587 
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 3496 of file z3py.py.

3496  def __lt__(self, other):
3497  """Create the Z3 expression (signed) `other < self`.
3498 
3499  Use the function ULT() for unsigned less than.
3500 
3501  >>> x, y = BitVecs('x y', 32)
3502  >>> x < y
3503  x < y
3504  >>> (x < y).sexpr()
3505  '(bvslt x y)'
3506  >>> ULT(x, y).sexpr()
3507  '(bvult x y)'
3508  """
3509  a, b = _coerce_exprs(self, other)
3510  return BoolRef(Z3_mk_bvslt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3511 
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 3441 of file z3py.py.

3441  def __mod__(self, other):
3442  """Create the Z3 expression (signed) mod `self % other`.
3443 
3444  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3445 
3446  >>> x = BitVec('x', 32)
3447  >>> y = BitVec('y', 32)
3448  >>> x % y
3449  x%y
3450  >>> (x % y).sort()
3451  BitVec(32)
3452  >>> (x % y).sexpr()
3453  '(bvsmod x y)'
3454  >>> URem(x, y).sexpr()
3455  '(bvurem x y)'
3456  >>> SRem(x, y).sexpr()
3457  '(bvsrem x y)'
3458  """
3459  a, b = _coerce_exprs(self, other)
3460  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3461 
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 3252 of file z3py.py.

3252  def __mul__(self, other):
3253  """Create the Z3 expression `self * other`.
3254 
3255  >>> x = BitVec('x', 32)
3256  >>> y = BitVec('y', 32)
3257  >>> x * y
3258  x*y
3259  >>> (x * y).sort()
3260  BitVec(32)
3261  """
3262  a, b = _coerce_exprs(self, other)
3263  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3264 
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 3376 of file z3py.py.

3376  def __neg__(self):
3377  """Return an expression representing `-self`.
3378 
3379  >>> x = BitVec('x', 32)
3380  >>> -x
3381  -x
3382  >>> simplify(-(-x))
3383  x
3384  """
3385  return BitVecRef(Z3_mk_bvneg(self.ctx_ref(), self.as_ast()), self.ctx)
3386 
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 3298 of file z3py.py.

3298  def __or__(self, other):
3299  """Create the Z3 expression bitwise-or `self | other`.
3300 
3301  >>> x = BitVec('x', 32)
3302  >>> y = BitVec('y', 32)
3303  >>> x | y
3304  x | y
3305  >>> (x | y).sort()
3306  BitVec(32)
3307  """
3308  a, b = _coerce_exprs(self, other)
3309  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3310 
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 3367 of file z3py.py.

3367  def __pos__(self):
3368  """Return `self`.
3369 
3370  >>> x = BitVec('x', 32)
3371  >>> +x
3372  x
3373  """
3374  return self
3375 

◆ __radd__()

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

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

Definition at line 3242 of file z3py.py.

3242  def __radd__(self, other):
3243  """Create the Z3 expression `other + self`.
3244 
3245  >>> x = BitVec('x', 32)
3246  >>> 10 + x
3247  10 + x
3248  """
3249  a, b = _coerce_exprs(self, other)
3250  return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3251 
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 3334 of file z3py.py.

3334  def __rand__(self, other):
3335  """Create the Z3 expression bitwise-or `other & self`.
3336 
3337  >>> x = BitVec('x', 32)
3338  >>> 10 & x
3339  10 & x
3340  """
3341  a, b = _coerce_exprs(self, other)
3342  return BitVecRef(Z3_mk_bvand(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3343 
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 3421 of file z3py.py.

3421  def __rdiv__(self, other):
3422  """Create the Z3 expression (signed) division `other / self`.
3423 
3424  Use the function UDiv() for unsigned division.
3425 
3426  >>> x = BitVec('x', 32)
3427  >>> 10 / x
3428  10/x
3429  >>> (10 / x).sexpr()
3430  '(bvsdiv #x0000000a x)'
3431  >>> UDiv(10, x).sexpr()
3432  '(bvudiv #x0000000a x)'
3433  """
3434  a, b = _coerce_exprs(self, other)
3435  return BitVecRef(Z3_mk_bvsdiv(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3436 
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 3602 of file z3py.py.

3602  def __rlshift__(self, other):
3603  """Create the Z3 expression left shift `other << self`.
3604 
3605  Use the function LShR() for the right logical shift
3606 
3607  >>> x = BitVec('x', 32)
3608  >>> 10 << x
3609  10 << x
3610  >>> (10 << x).sexpr()
3611  '(bvshl #x0000000a x)'
3612  """
3613  a, b = _coerce_exprs(self, other)
3614  return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3615 
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 3462 of file z3py.py.

3462  def __rmod__(self, other):
3463  """Create the Z3 expression (signed) mod `other % self`.
3464 
3465  Use the function URem() for unsigned remainder, and SRem() for signed remainder.
3466 
3467  >>> x = BitVec('x', 32)
3468  >>> 10 % x
3469  10%x
3470  >>> (10 % x).sexpr()
3471  '(bvsmod #x0000000a x)'
3472  >>> URem(10, x).sexpr()
3473  '(bvurem #x0000000a x)'
3474  >>> SRem(10, x).sexpr()
3475  '(bvsrem #x0000000a x)'
3476  """
3477  a, b = _coerce_exprs(self, other)
3478  return BitVecRef(Z3_mk_bvsmod(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3479 
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 3265 of file z3py.py.

3265  def __rmul__(self, other):
3266  """Create the Z3 expression `other * self`.
3267 
3268  >>> x = BitVec('x', 32)
3269  >>> 10 * x
3270  10*x
3271  """
3272  a, b = _coerce_exprs(self, other)
3273  return BitVecRef(Z3_mk_bvmul(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3274 
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 3311 of file z3py.py.

3311  def __ror__(self, other):
3312  """Create the Z3 expression bitwise-or `other | self`.
3313 
3314  >>> x = BitVec('x', 32)
3315  >>> 10 | x
3316  10 | x
3317  """
3318  a, b = _coerce_exprs(self, other)
3319  return BitVecRef(Z3_mk_bvor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3320 
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 3588 of file z3py.py.

3588  def __rrshift__(self, other):
3589  """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3590 
3591  Use the function LShR() for the right logical shift
3592 
3593  >>> x = BitVec('x', 32)
3594  >>> 10 >> x
3595  10 >> x
3596  >>> (10 >> x).sexpr()
3597  '(bvashr #x0000000a x)'
3598  """
3599  a, b = _coerce_exprs(self, other)
3600  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3601 
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 3544 of file z3py.py.

3544  def __rshift__(self, other):
3545  """Create the Z3 expression (arithmetical) right shift `self >> other`
3546 
3547  Use the function LShR() for the right logical shift
3548 
3549  >>> x, y = BitVecs('x y', 32)
3550  >>> x >> y
3551  x >> y
3552  >>> (x >> y).sexpr()
3553  '(bvashr x y)'
3554  >>> LShR(x, y).sexpr()
3555  '(bvlshr x y)'
3556  >>> BitVecVal(4, 3)
3557  4
3558  >>> BitVecVal(4, 3).as_signed_long()
3559  -4
3560  >>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
3561  -2
3562  >>> simplify(BitVecVal(4, 3) >> 1)
3563  6
3564  >>> simplify(LShR(BitVecVal(4, 3), 1))
3565  2
3566  >>> simplify(BitVecVal(2, 3) >> 1)
3567  1
3568  >>> simplify(LShR(BitVecVal(2, 3), 1))
3569  1
3570  """
3571  a, b = _coerce_exprs(self, other)
3572  return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3573 
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 3288 of file z3py.py.

3288  def __rsub__(self, other):
3289  """Create the Z3 expression `other - self`.
3290 
3291  >>> x = BitVec('x', 32)
3292  >>> 10 - x
3293  10 - x
3294  """
3295  a, b = _coerce_exprs(self, other)
3296  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3297 
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 3437 of file z3py.py.

3437  def __rtruediv__(self, other):
3438  """Create the Z3 expression (signed) division `other / self`."""
3439  return self.__rdiv__(other)
3440 

◆ __rxor__()

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

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

Definition at line 3357 of file z3py.py.

3357  def __rxor__(self, other):
3358  """Create the Z3 expression bitwise-xor `other ^ self`.
3359 
3360  >>> x = BitVec('x', 32)
3361  >>> 10 ^ x
3362  10 ^ x
3363  """
3364  a, b = _coerce_exprs(self, other)
3365  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3366 
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 3275 of file z3py.py.

3275  def __sub__(self, other):
3276  """Create the Z3 expression `self - other`.
3277 
3278  >>> x = BitVec('x', 32)
3279  >>> y = BitVec('y', 32)
3280  >>> x - y
3281  x - y
3282  >>> (x - y).sort()
3283  BitVec(32)
3284  """
3285  a, b = _coerce_exprs(self, other)
3286  return BitVecRef(Z3_mk_bvsub(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3287 
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 3417 of file z3py.py.

3417  def __truediv__(self, other):
3418  """Create the Z3 expression (signed) division `self / other`."""
3419  return self.__div__(other)
3420 

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

3344  def __xor__(self, other):
3345  """Create the Z3 expression bitwise-xor `self ^ other`.
3346 
3347  >>> x = BitVec('x', 32)
3348  >>> y = BitVec('y', 32)
3349  >>> x ^ y
3350  x ^ y
3351  >>> (x ^ y).sort()
3352  BitVec(32)
3353  """
3354  a, b = _coerce_exprs(self, other)
3355  return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3356 
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 3218 of file z3py.py.

3218  def size(self):
3219  """Return the number of bits of the bit-vector expression `self`.
3220 
3221  >>> x = BitVec('x', 32)
3222  >>> (x + 1).size()
3223  32
3224  >>> Concat(x, x).size()
3225  64
3226  """
3227  return self.sort().size()
3228 

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

3207  def sort(self):
3208  """Return the sort of the bit-vector expression `self`.
3209 
3210  >>> x = BitVec('x', 32)
3211  >>> x.sort()
3212  BitVec(32)
3213  >>> x.sort() == BitVecSort(32)
3214  True
3215  """
3216  return BitVecSortRef(Z3_get_sort(self.ctx_ref(), self.as_ast()), self.ctx)
3217 
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a)
Return the sort of an AST node.