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

Public Member Functions

 numerator (self)
 
 denominator (self)
 
 numerator_as_long (self)
 
 denominator_as_long (self)
 
 is_int (self)
 
 is_real (self)
 
 is_int_value (self)
 
 as_long (self)
 
 as_decimal (self, prec)
 
 as_string (self)
 
 as_fraction (self)
 
 py_value (self)
 
- Public Member Functions inherited from ArithRef
 sort (self)
 
 __add__ (self, other)
 
 __radd__ (self, other)
 
 __mul__ (self, other)
 
 __rmul__ (self, other)
 
 __sub__ (self, other)
 
 __rsub__ (self, other)
 
 __pow__ (self, other)
 
 __rpow__ (self, other)
 
 __div__ (self, other)
 
 __truediv__ (self, other)
 
 __rdiv__ (self, other)
 
 __rtruediv__ (self, other)
 
 __mod__ (self, other)
 
 __rmod__ (self, other)
 
 __neg__ (self)
 
 __pos__ (self)
 
 __le__ (self, other)
 
 __lt__ (self, other)
 
 __gt__ (self, other)
 
 __ge__ (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)
 
 kind (self)
 
 num_args (self)
 
 arg (self, idx)
 
 children (self)
 
 update (self, *args)
 
 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)
 
 __eq__ (self, other)
 
 __hash__ (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)
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast = ast
 
 ctx = _get_ctx(ctx)
 
- Protected Member Functions inherited from Z3PPObject
 _repr_html_ (self)
 

Detailed Description

Rational values.

Definition at line 3138 of file z3py.py.

Member Function Documentation

◆ as_decimal()

as_decimal ( self,
prec )
 Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.

>>> v = RealVal("1/5")
>>> v.as_decimal(3)
'0.2'
>>> v = RealVal("1/3")
>>> v.as_decimal(3)
'0.333?'

Definition at line 3204 of file z3py.py.

3204 def as_decimal(self, prec):
3205 """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3206
3207 >>> v = RealVal("1/5")
3208 >>> v.as_decimal(3)
3209 '0.2'
3210 >>> v = RealVal("1/3")
3211 >>> v.as_decimal(3)
3212 '0.333?'
3213 """
3214 return Z3_get_numeral_decimal_string(self.ctx_ref(), self.as_ast(), prec)
3215
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision)
Return numeral as a string in decimal notation. The result has at most precision decimal places.

◆ as_fraction()

as_fraction ( self)
Return a Z3 rational as a Python Fraction object.

>>> v = RealVal("1/5")
>>> v.as_fraction()
Fraction(1, 5)

Definition at line 3225 of file z3py.py.

3225 def as_fraction(self):
3226 """Return a Z3 rational as a Python Fraction object.
3227
3228 >>> v = RealVal("1/5")
3229 >>> v.as_fraction()
3230 Fraction(1, 5)
3231 """
3232 return Fraction(self.numerator_as_long(), self.denominator_as_long())
3233

◆ as_long()

as_long ( self)

Definition at line 3200 of file z3py.py.

3200 def as_long(self):
3201 _z3_assert(self.is_int_value(), "Expected integer fraction")
3202 return self.numerator_as_long()
3203

Referenced by BitVecNumRef.as_signed_long(), denominator_as_long(), numerator_as_long(), and BitVecNumRef.py_value().

◆ as_string()

as_string ( self)
Return a Z3 rational numeral as a Python string.

>>> v = Q(3,6)
>>> v.as_string()
'1/2'

Definition at line 3216 of file z3py.py.

3216 def as_string(self):
3217 """Return a Z3 rational numeral as a Python string.
3218
3219 >>> v = Q(3,6)
3220 >>> v.as_string()
3221 '1/2'
3222 """
3223 return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
3224
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a decimal string of a numeric constant term.

Referenced by BitVecNumRef.as_long().

◆ denominator()

denominator ( self)
 Return the denominator of a Z3 rational numeral.

>>> is_rational_value(Q(3,5))
True
>>> n = Q(3,5)
>>> n.denominator()
5

Definition at line 3156 of file z3py.py.

3156 def denominator(self):
3157 """ Return the denominator of a Z3 rational numeral.
3158
3159 >>> is_rational_value(Q(3,5))
3160 True
3161 >>> n = Q(3,5)
3162 >>> n.denominator()
3163 5
3164 """
3165 return IntNumRef(Z3_get_denominator(self.ctx_ref(), self.as_ast()), self.ctx)
3166
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.

Referenced by denominator_as_long(), and is_int_value().

◆ denominator_as_long()

denominator_as_long ( self)
 Return the denominator as a Python long.

>>> v = RealVal("1/3")
>>> v
1/3
>>> v.denominator_as_long()
3

Definition at line 3180 of file z3py.py.

3180 def denominator_as_long(self):
3181 """ Return the denominator as a Python long.
3182
3183 >>> v = RealVal("1/3")
3184 >>> v
3185 1/3
3186 >>> v.denominator_as_long()
3187 3
3188 """
3189 return self.denominator().as_long()
3190

Referenced by as_fraction(), and is_int_value().

◆ is_int()

is_int ( self)
Return `True` if `self` is an integer expression.

>>> x = Int('x')
>>> x.is_int()
True
>>> (x + 1).is_int()
True
>>> y = Real('y')
>>> (x + y).is_int()
False

Reimplemented from ArithRef.

Definition at line 3191 of file z3py.py.

3191 def is_int(self):
3192 return False
3193

Referenced by is_int_value().

◆ is_int_value()

is_int_value ( self)

Definition at line 3197 of file z3py.py.

3197 def is_int_value(self):
3198 return self.denominator().is_int() and self.denominator_as_long() == 1
3199

Referenced by as_long().

◆ is_real()

is_real ( self)
Return `True` if `self` is an real expression.

>>> x = Real('x')
>>> x.is_real()
True
>>> (x + 1).is_real()
True

Reimplemented from ArithRef.

Definition at line 3194 of file z3py.py.

3194 def is_real(self):
3195 return True
3196

◆ numerator()

numerator ( self)
 Return the numerator of a Z3 rational numeral.

>>> is_rational_value(RealVal("3/5"))
True
>>> n = RealVal("3/5")
>>> n.numerator()
3
>>> is_rational_value(Q(3,5))
True
>>> Q(3,5).numerator()
3

Definition at line 3141 of file z3py.py.

3141 def numerator(self):
3142 """ Return the numerator of a Z3 rational numeral.
3143
3144 >>> is_rational_value(RealVal("3/5"))
3145 True
3146 >>> n = RealVal("3/5")
3147 >>> n.numerator()
3148 3
3149 >>> is_rational_value(Q(3,5))
3150 True
3151 >>> Q(3,5).numerator()
3152 3
3153 """
3154 return IntNumRef(Z3_get_numerator(self.ctx_ref(), self.as_ast()), self.ctx)
3155
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a)
Return the numerator (as a numeral AST) of a numeral AST of sort Real.

Referenced by numerator_as_long().

◆ numerator_as_long()

numerator_as_long ( self)
 Return the numerator as a Python long.

>>> v = RealVal(10000000000)
>>> v
10000000000
>>> v + 1
10000000000 + 1
>>> v.numerator_as_long() + 1 == 10000000001
True

Definition at line 3167 of file z3py.py.

3167 def numerator_as_long(self):
3168 """ Return the numerator as a Python long.
3169
3170 >>> v = RealVal(10000000000)
3171 >>> v
3172 10000000000
3173 >>> v + 1
3174 10000000000 + 1
3175 >>> v.numerator_as_long() + 1 == 10000000001
3176 True
3177 """
3178 return self.numerator().as_long()
3179

Referenced by as_fraction(), and as_long().

◆ py_value()

py_value ( self)
Return a Python value that is equivalent to `self`.

Reimplemented from AstRef.

Definition at line 3234 of file z3py.py.

3234 def py_value(self):
3235 return Z3_get_numeral_double(self.ctx_ref(), self.as_ast())
3236
3237
double Z3_API Z3_get_numeral_double(Z3_context c, Z3_ast a)
Return numeral as a double.