Z3
 
Loading...
Searching...
No Matches
BitVecRef Class Reference
+ Inheritance diagram for BitVecRef:

Public Member Functions

 sort (self)
 
 size (self)
 
 __add__ (self, other)
 
 __radd__ (self, other)
 
 __mul__ (self, other)
 
 __rmul__ (self, other)
 
 __sub__ (self, other)
 
 __rsub__ (self, other)
 
 __or__ (self, other)
 
 __ror__ (self, other)
 
 __and__ (self, other)
 
 __rand__ (self, other)
 
 __xor__ (self, other)
 
 __rxor__ (self, other)
 
 __pos__ (self)
 
 __neg__ (self)
 
 __invert__ (self)
 
 __div__ (self, other)
 
 __truediv__ (self, other)
 
 __rdiv__ (self, other)
 
 __rtruediv__ (self, other)
 
 __mod__ (self, other)
 
 __rmod__ (self, other)
 
 __le__ (self, other)
 
 __lt__ (self, other)
 
 __gt__ (self, other)
 
 __ge__ (self, other)
 
 __rshift__ (self, other)
 
 __lshift__ (self, other)
 
 __rrshift__ (self, other)
 
 __rlshift__ (self, other)
 
- Public Member Functions inherited from ExprRef
 as_ast (self)
 
 get_id (self)
 
 sort_kind (self)
 
 __eq__ (self, other)
 
 __hash__ (self)
 
 __ne__ (self, other)
 
 params (self)
 
 decl (self)
 
 num_args (self)
 
 arg (self, idx)
 
 children (self)
 
 from_string (self, s)
 
 serialize (self)
 
- Public Member Functions inherited from AstRef
 __init__ (self, ast, ctx=None)
 
 __del__ (self)
 
 __deepcopy__ (self, memo={})
 
 __str__ (self)
 
 __repr__ (self)
 
 __nonzero__ (self)
 
 __bool__ (self)
 
 sexpr (self)
 
 ctx_ref (self)
 
 eq (self, other)
 
 translate (self, target)
 
 __copy__ (self)
 
 hash (self)
 
- Public Member Functions inherited from Z3PPObject
 use_pp (self)
 

Data Fields

 ctx = _coerce_exprs(self, other)
 
- Data Fields inherited from ExprRef
 ctx
 
- Data Fields inherited from AstRef
 ast = ast
 
 ctx = _get_ctx(ctx)
 

Additional Inherited Members

- Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)
 

Detailed Description

Bit-vector expressions.

Definition at line 3533 of file z3py.py.

Member Function Documentation

◆ __add__()

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

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x + y
x + y
>>> (x + y).sort()
BitVec(32)

Definition at line 3558 of file z3py.py.

3558 def __add__(self, other):
3559 """Create the Z3 expression `self + other`.
3560
3561 >>> x = BitVec('x', 32)
3562 >>> y = BitVec('y', 32)
3563 >>> x + y
3564 x + y
3565 >>> (x + y).sort()
3566 BitVec(32)
3567 """
3568 a, b = _coerce_exprs(self, other)
3569 return BitVecRef(Z3_mk_bvadd(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3570
Z3_ast Z3_API Z3_mk_bvadd(Z3_context c, Z3_ast t1, Z3_ast t2)
Standard two's complement addition.

◆ __and__()

__and__ ( self,
other )
Create the Z3 expression bitwise-and `self & other`.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x & y
x & y
>>> (x & y).sort()
BitVec(32)

Definition at line 3650 of file z3py.py.

3650 def __and__(self, other):
3651 """Create the Z3 expression bitwise-and `self & other`.
3652
3653 >>> x = BitVec('x', 32)
3654 >>> y = BitVec('y', 32)
3655 >>> x & y
3656 x & y
3657 >>> (x & y).sort()
3658 BitVec(32)
3659 """
3660 a, b = _coerce_exprs(self, other)
3661 return BitVecRef(Z3_mk_bvand(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3662
Z3_ast Z3_API Z3_mk_bvand(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise and.

◆ __div__()

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

Use the function UDiv() for unsigned division.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x / y
x/y
>>> (x / y).sort()
BitVec(32)
>>> (x / y).sexpr()
'(bvsdiv x y)'
>>> UDiv(x, y).sexpr()
'(bvudiv x y)'

Definition at line 3727 of file z3py.py.

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

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

◆ __ge__()

__ge__ ( self,
other )
Create the Z3 expression (signed) `other >= self`.

Use the function UGE() for unsigned greater than or equal to.

>>> x, y = BitVecs('x y', 32)
>>> x >= y
x >= y
>>> (x >= y).sexpr()
'(bvsge x y)'
>>> UGE(x, y).sexpr()
'(bvuge x y)'

Definition at line 3857 of file z3py.py.

3857 def __ge__(self, other):
3858 """Create the Z3 expression (signed) `other >= self`.
3859
3860 Use the function UGE() for unsigned greater than or equal to.
3861
3862 >>> x, y = BitVecs('x y', 32)
3863 >>> x >= y
3864 x >= y
3865 >>> (x >= y).sexpr()
3866 '(bvsge x y)'
3867 >>> UGE(x, y).sexpr()
3868 '(bvuge x y)'
3869 """
3870 a, b = _coerce_exprs(self, other)
3871 return BoolRef(Z3_mk_bvsge(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3872
Z3_ast Z3_API Z3_mk_bvsge(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than or equal to.

◆ __gt__()

__gt__ ( self,
other )
Create the Z3 expression (signed) `other > self`.

Use the function UGT() for unsigned greater than.

>>> x, y = BitVecs('x y', 32)
>>> x > y
x > y
>>> (x > y).sexpr()
'(bvsgt x y)'
>>> UGT(x, y).sexpr()
'(bvugt x y)'

Definition at line 3841 of file z3py.py.

3841 def __gt__(self, other):
3842 """Create the Z3 expression (signed) `other > self`.
3843
3844 Use the function UGT() for unsigned greater than.
3845
3846 >>> x, y = BitVecs('x y', 32)
3847 >>> x > y
3848 x > y
3849 >>> (x > y).sexpr()
3850 '(bvsgt x y)'
3851 >>> UGT(x, y).sexpr()
3852 '(bvugt x y)'
3853 """
3854 a, b = _coerce_exprs(self, other)
3855 return BoolRef(Z3_mk_bvsgt(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3856
Z3_ast Z3_API Z3_mk_bvsgt(Z3_context c, Z3_ast t1, Z3_ast t2)
Two's complement signed greater than.

◆ __invert__()

__invert__ ( self)
Create the Z3 expression bitwise-not `~self`.

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

Definition at line 3716 of file z3py.py.

3716 def __invert__(self):
3717 """Create the Z3 expression bitwise-not `~self`.
3718
3719 >>> x = BitVec('x', 32)
3720 >>> ~x
3721 ~x
3722 >>> simplify(~(~x))
3723 x
3724 """
3725 return BitVecRef(Z3_mk_bvnot(self.ctx_ref(), self.as_ast()), self.ctx)
3726
Z3_ast Z3_API Z3_mk_bvnot(Z3_context c, Z3_ast t1)
Bitwise negation.

◆ __le__()

__le__ ( self,
other )
Create the Z3 expression (signed) `other <= self`.

Use the function ULE() for unsigned less than or equal to.

>>> x, y = BitVecs('x y', 32)
>>> x <= y
x <= y
>>> (x <= y).sexpr()
'(bvsle x y)'
>>> ULE(x, y).sexpr()
'(bvule x y)'

Definition at line 3809 of file z3py.py.

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

◆ __lshift__()

__lshift__ ( self,
other )
Create the Z3 expression left shift `self << other`

>>> x, y = BitVecs('x y', 32)
>>> x << y
x << y
>>> (x << y).sexpr()
'(bvshl x y)'
>>> simplify(BitVecVal(2, 3) << 1)
4

Definition at line 3903 of file z3py.py.

3903 def __lshift__(self, other):
3904 """Create the Z3 expression left shift `self << other`
3905
3906 >>> x, y = BitVecs('x y', 32)
3907 >>> x << y
3908 x << y
3909 >>> (x << y).sexpr()
3910 '(bvshl x y)'
3911 >>> simplify(BitVecVal(2, 3) << 1)
3912 4
3913 """
3914 a, b = _coerce_exprs(self, other)
3915 return BitVecRef(Z3_mk_bvshl(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3916
Z3_ast Z3_API Z3_mk_bvshl(Z3_context c, Z3_ast t1, Z3_ast t2)
Shift left.

◆ __lt__()

__lt__ ( self,
other )
Create the Z3 expression (signed) `other < self`.

Use the function ULT() for unsigned less than.

>>> x, y = BitVecs('x y', 32)
>>> x < y
x < y
>>> (x < y).sexpr()
'(bvslt x y)'
>>> ULT(x, y).sexpr()
'(bvult x y)'

Definition at line 3825 of file z3py.py.

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

◆ __mod__()

__mod__ ( self,
other )
Create the Z3 expression (signed) mod `self % other`.

Use the function URem() for unsigned remainder, and SRem() for signed remainder.

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x % y
x%y
>>> (x % y).sort()
BitVec(32)
>>> (x % y).sexpr()
'(bvsmod x y)'
>>> URem(x, y).sexpr()
'(bvurem x y)'
>>> SRem(x, y).sexpr()
'(bvsrem x y)'

Definition at line 3770 of file z3py.py.

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

◆ __mul__()

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

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x * y
x*y
>>> (x * y).sort()
BitVec(32)

Definition at line 3581 of file z3py.py.

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

◆ __neg__()

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

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

Definition at line 3705 of file z3py.py.

3705 def __neg__(self):
3706 """Return an expression representing `-self`.
3707
3708 >>> x = BitVec('x', 32)
3709 >>> -x
3710 -x
3711 >>> simplify(-(-x))
3712 x
3713 """
3714 return BitVecRef(Z3_mk_bvneg(self.ctx_ref(), self.as_ast()), self.ctx)
3715
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast t1)
Standard two's complement unary minus.

◆ __or__()

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

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x | y
x | y
>>> (x | y).sort()
BitVec(32)

Definition at line 3627 of file z3py.py.

3627 def __or__(self, other):
3628 """Create the Z3 expression bitwise-or `self | other`.
3629
3630 >>> x = BitVec('x', 32)
3631 >>> y = BitVec('y', 32)
3632 >>> x | y
3633 x | y
3634 >>> (x | y).sort()
3635 BitVec(32)
3636 """
3637 a, b = _coerce_exprs(self, other)
3638 return BitVecRef(Z3_mk_bvor(self.ctx_ref(), a.as_ast(), b.as_ast()), self.ctx)
3639
Z3_ast Z3_API Z3_mk_bvor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise or.

◆ __pos__()

__pos__ ( self)
Return `self`.

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

Definition at line 3696 of file z3py.py.

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

◆ __radd__()

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

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

Definition at line 3571 of file z3py.py.

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

◆ __rand__()

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

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

Definition at line 3663 of file z3py.py.

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

◆ __rdiv__()

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

Use the function UDiv() for unsigned division.

>>> x = BitVec('x', 32)
>>> 10 / x
10/x
>>> (10 / x).sexpr()
'(bvsdiv #x0000000a x)'
>>> UDiv(10, x).sexpr()
'(bvudiv #x0000000a x)'

Definition at line 3750 of file z3py.py.

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

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

◆ __rlshift__()

__rlshift__ ( self,
other )
Create the Z3 expression left shift `other << self`.

Use the function LShR() for the right logical shift

>>> x = BitVec('x', 32)
>>> 10 << x
10 << x
>>> (10 << x).sexpr()
'(bvshl #x0000000a x)'

Definition at line 3931 of file z3py.py.

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

◆ __rmod__()

__rmod__ ( self,
other )
Create the Z3 expression (signed) mod `other % self`.

Use the function URem() for unsigned remainder, and SRem() for signed remainder.

>>> x = BitVec('x', 32)
>>> 10 % x
10%x
>>> (10 % x).sexpr()
'(bvsmod #x0000000a x)'
>>> URem(10, x).sexpr()
'(bvurem #x0000000a x)'
>>> SRem(10, x).sexpr()
'(bvsrem #x0000000a x)'

Definition at line 3791 of file z3py.py.

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

◆ __rmul__()

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

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

Definition at line 3594 of file z3py.py.

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

◆ __ror__()

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

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

Definition at line 3640 of file z3py.py.

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

◆ __rrshift__()

__rrshift__ ( self,
other )
Create the Z3 expression (arithmetical) right shift `other` >> `self`.

Use the function LShR() for the right logical shift

>>> x = BitVec('x', 32)
>>> 10 >> x
10 >> x
>>> (10 >> x).sexpr()
'(bvashr #x0000000a x)'

Definition at line 3917 of file z3py.py.

3917 def __rrshift__(self, other):
3918 """Create the Z3 expression (arithmetical) right shift `other` >> `self`.
3919
3920 Use the function LShR() for the right logical shift
3921
3922 >>> x = BitVec('x', 32)
3923 >>> 10 >> x
3924 10 >> x
3925 >>> (10 >> x).sexpr()
3926 '(bvashr #x0000000a x)'
3927 """
3928 a, b = _coerce_exprs(self, other)
3929 return BitVecRef(Z3_mk_bvashr(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3930
Z3_ast Z3_API Z3_mk_bvashr(Z3_context c, Z3_ast t1, Z3_ast t2)
Arithmetic shift right.

◆ __rshift__()

__rshift__ ( self,
other )
Create the Z3 expression (arithmetical) right shift `self >> other`

Use the function LShR() for the right logical shift

>>> x, y = BitVecs('x y', 32)
>>> x >> y
x >> y
>>> (x >> y).sexpr()
'(bvashr x y)'
>>> LShR(x, y).sexpr()
'(bvlshr x y)'
>>> BitVecVal(4, 3)
4
>>> BitVecVal(4, 3).as_signed_long()
-4
>>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
-2
>>> simplify(BitVecVal(4, 3) >> 1)
6
>>> simplify(LShR(BitVecVal(4, 3), 1))
2
>>> simplify(BitVecVal(2, 3) >> 1)
1
>>> simplify(LShR(BitVecVal(2, 3), 1))
1

Definition at line 3873 of file z3py.py.

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

◆ __rsub__()

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

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

Definition at line 3617 of file z3py.py.

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

◆ __rtruediv__()

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

Definition at line 3766 of file z3py.py.

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

◆ __rxor__()

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

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

Definition at line 3686 of file z3py.py.

3686 def __rxor__(self, other):
3687 """Create the Z3 expression bitwise-xor `other ^ self`.
3688
3689 >>> x = BitVec('x', 32)
3690 >>> 10 ^ x
3691 10 ^ x
3692 """
3693 a, b = _coerce_exprs(self, other)
3694 return BitVecRef(Z3_mk_bvxor(self.ctx_ref(), b.as_ast(), a.as_ast()), self.ctx)
3695
Z3_ast Z3_API Z3_mk_bvxor(Z3_context c, Z3_ast t1, Z3_ast t2)
Bitwise exclusive-or.

◆ __sub__()

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

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x - y
x - y
>>> (x - y).sort()
BitVec(32)

Definition at line 3604 of file z3py.py.

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

◆ __truediv__()

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

Definition at line 3746 of file z3py.py.

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

◆ __xor__()

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

>>> x = BitVec('x', 32)
>>> y = BitVec('y', 32)
>>> x ^ y
x ^ y
>>> (x ^ y).sort()
BitVec(32)

Definition at line 3673 of file z3py.py.

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

◆ size()

size ( self)
Return the number of bits of the bit-vector expression `self`.

>>> x = BitVec('x', 32)
>>> (x + 1).size()
32
>>> Concat(x, x).size()
64

Definition at line 3547 of file z3py.py.

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

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

◆ sort()

sort ( self)
Return the sort of the bit-vector expression `self`.

>>> x = BitVec('x', 32)
>>> x.sort()
BitVec(32)
>>> x.sort() == BitVecSort(32)
True

Reimplemented from ExprRef.

Definition at line 3536 of file z3py.py.

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

Referenced by ArrayRef.domain(), ArrayRef.domain_n(), ArithRef.is_int(), ArithRef.is_real(), ArrayRef.range(), BitVecRef.size(), and ExprRef.sort_kind().

Field Documentation

◆ ctx

ctx = _coerce_exprs(self, other)

Definition at line 3545 of file z3py.py.

Referenced by ArithRef.__add__(), BitVecRef.__add__(), BitVecRef.__and__(), FuncDeclRef.__call__(), AstMap.__contains__(), AstRef.__copy__(), AstVector.__copy__(), FuncInterp.__copy__(), Goal.__copy__(), ModelRef.__copy__(), AstMap.__deepcopy__(), AstRef.__deepcopy__(), AstVector.__deepcopy__(), Datatype.__deepcopy__(), FuncEntry.__deepcopy__(), FuncInterp.__deepcopy__(), Goal.__deepcopy__(), ModelRef.__deepcopy__(), ParamDescrsRef.__deepcopy__(), ParamsRef.__deepcopy__(), Statistics.__deepcopy__(), AstMap.__del__(), AstRef.__del__(), AstVector.__del__(), Context.__del__(), FuncEntry.__del__(), FuncInterp.__del__(), Goal.__del__(), ModelRef.__del__(), ParamDescrsRef.__del__(), ParamsRef.__del__(), ScopedConstructor.__del__(), ScopedConstructorList.__del__(), Solver.__del__(), Statistics.__del__(), ArithRef.__div__(), BitVecRef.__div__(), ExprRef.__eq__(), ArithRef.__ge__(), BitVecRef.__ge__(), AstMap.__getitem__(), AstVector.__getitem__(), ModelRef.__getitem__(), Statistics.__getitem__(), ArithRef.__gt__(), BitVecRef.__gt__(), BitVecRef.__invert__(), ArithRef.__le__(), BitVecRef.__le__(), AstMap.__len__(), AstVector.__len__(), ModelRef.__len__(), Statistics.__len__(), BitVecRef.__lshift__(), ArithRef.__lt__(), BitVecRef.__lt__(), ArithRef.__mod__(), BitVecRef.__mod__(), ArithRef.__mul__(), BitVecRef.__mul__(), BoolRef.__mul__(), ExprRef.__ne__(), ArithRef.__neg__(), BitVecRef.__neg__(), BitVecRef.__or__(), ArithRef.__pow__(), ArithRef.__radd__(), BitVecRef.__radd__(), BitVecRef.__rand__(), ArithRef.__rdiv__(), BitVecRef.__rdiv__(), AstMap.__repr__(), ParamDescrsRef.__repr__(), ParamsRef.__repr__(), Statistics.__repr__(), BitVecRef.__rlshift__(), ArithRef.__rmod__(), BitVecRef.__rmod__(), ArithRef.__rmul__(), BitVecRef.__rmul__(), BitVecRef.__ror__(), ArithRef.__rpow__(), BitVecRef.__rrshift__(), BitVecRef.__rshift__(), ArithRef.__rsub__(), BitVecRef.__rsub__(), BitVecRef.__rxor__(), AstMap.__setitem__(), AstVector.__setitem__(), ArithRef.__sub__(), BitVecRef.__sub__(), BitVecRef.__xor__(), DatatypeSortRef.accessor(), ExprRef.arg(), FuncEntry.arg_value(), FuncInterp.arity(), Goal.as_expr(), Solver.assert_and_track(), Goal.assert_exprs(), Solver.assert_exprs(), QuantifierRef.body(), Solver.check(), Goal.convert_model(), AstRef.ctx_ref(), ExprRef.decl(), ModelRef.decls(), ArrayRef.default(), RatNumRef.denominator(), Goal.depth(), Goal.dimacs(), FuncDeclRef.domain(), ArraySortRef.domain_n(), FuncInterp.else_value(), FuncInterp.entry(), AstMap.erase(), ModelRef.eval(), Goal.get(), ParamDescrsRef.get_documentation(), ModelRef.get_interp(), Statistics.get_key_value(), ParamDescrsRef.get_kind(), ParamDescrsRef.get_name(), ModelRef.get_sort(), ModelRef.get_universe(), Goal.inconsistent(), AstMap.keys(), Statistics.keys(), Solver.model(), SortRef.name(), QuantifierRef.no_pattern(), FuncEntry.num_args(), FuncInterp.num_entries(), Solver.num_scopes(), ModelRef.num_sorts(), FuncDeclRef.params(), QuantifierRef.pattern(), AlgebraicNumRef.poly(), Solver.pop(), Goal.prec(), AstVector.push(), Solver.push(), QuantifierRef.qid(), ArraySortRef.range(), FuncDeclRef.range(), DatatypeSortRef.recognizer(), Context.ref(), AstMap.reset(), Solver.reset(), AstVector.resize(), ParamsRef.set(), Solver.set(), AstVector.sexpr(), Goal.sexpr(), ModelRef.sexpr(), Goal.size(), ParamDescrsRef.size(), QuantifierRef.skolem_id(), AstRef.translate(), AstVector.translate(), Goal.translate(), ModelRef.translate(), ParamsRef.validate(), FuncEntry.value(), QuantifierRef.var_name(), and QuantifierRef.var_sort().