Z3
Public Member Functions
RatNumRef Class Reference
+ Inheritance diagram for RatNumRef:

Public Member Functions

def numerator (self)
 
def denominator (self)
 
def numerator_as_long (self)
 
def denominator_as_long (self)
 
def is_int (self)
 
def is_real (self)
 
def is_int_value (self)
 
def as_long (self)
 
def as_decimal (self, prec)
 
def as_string (self)
 
def as_fraction (self)
 
- Public Member Functions inherited from ArithRef
def sort (self)
 
def is_int (self)
 
def is_real (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 __pow__ (self, other)
 
def __rpow__ (self, other)
 
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 __neg__ (self)
 
def __pos__ (self)
 
def __le__ (self, other)
 
def __lt__ (self, other)
 
def __gt__ (self, other)
 
def __ge__ (self, other)
 
- Public Member Functions inherited from ExprRef
def as_ast (self)
 
def get_id (self)
 
def sort (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)
 
def from_string (self, s)
 
def serialize (self)
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__ (self)
 
def __deepcopy__
 
def __str__ (self)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __hash__ (self)
 
def __nonzero__ (self)
 
def __bool__ (self)
 
def sexpr (self)
 
def as_ast (self)
 
def get_id (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

Rational values.

Definition at line 2988 of file z3py.py.

Member Function Documentation

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

3054  def as_decimal(self, prec):
3055  """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3056 
3057  >>> v = RealVal("1/5")
3058  >>> v.as_decimal(3)
3059  '0.2'
3060  >>> v = RealVal("1/3")
3061  >>> v.as_decimal(3)
3062  '0.333?'
3063  """
3064  return Z3_get_numeral_decimal_string(self.ctx_ref(), self.as_ast(), prec)
3065 
def as_ast(self)
Definition: z3py.py:392
def as_decimal(self, prec)
Definition: z3py.py:3054
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...
def ctx_ref(self)
Definition: z3py.py:400
def 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 3075 of file z3py.py.

3075  def as_fraction(self):
3076  """Return a Z3 rational as a Python Fraction object.
3077 
3078  >>> v = RealVal("1/5")
3079  >>> v.as_fraction()
3080  Fraction(1, 5)
3081  """
3082  return Fraction(self.numerator_as_long(), self.denominator_as_long())
3083 
3084 
def as_fraction(self)
Definition: z3py.py:3075
def denominator_as_long(self)
Definition: z3py.py:3030
def numerator_as_long(self)
Definition: z3py.py:3017
def as_long (   self)

Definition at line 3050 of file z3py.py.

Referenced by BitVecNumRef.as_signed_long().

3050  def as_long(self):
3051  _z3_assert(self.is_int_value(), "Expected integer fraction")
3052  return self.numerator_as_long()
3053 
def is_int_value(self)
Definition: z3py.py:3047
def numerator_as_long(self)
Definition: z3py.py:3017
def as_long(self)
Definition: z3py.py:3050
def as_string (   self)
Return a Z3 rational numeral as a Python string.

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

Definition at line 3066 of file z3py.py.

Referenced by BitVecNumRef.as_long(), and FiniteDomainNumRef.as_long().

3066  def as_string(self):
3067  """Return a Z3 rational numeral as a Python string.
3068 
3069  >>> v = Q(3,6)
3070  >>> v.as_string()
3071  '1/2'
3072  """
3073  return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
3074 
def as_ast(self)
Definition: z3py.py:392
def as_string(self)
Definition: z3py.py:3066
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.
def ctx_ref(self)
Definition: z3py.py:400
def 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 3006 of file z3py.py.

3006  def denominator(self):
3007  """ Return the denominator of a Z3 rational numeral.
3008 
3009  >>> is_rational_value(Q(3,5))
3010  True
3011  >>> n = Q(3,5)
3012  >>> n.denominator()
3013  5
3014  """
3015  return IntNumRef(Z3_get_denominator(self.ctx_ref(), self.as_ast()), self.ctx)
3016 
def as_ast(self)
Definition: z3py.py:392
def denominator(self)
Definition: z3py.py:3006
def ctx_ref(self)
Definition: z3py.py:400
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.
def 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 3030 of file z3py.py.

Referenced by RatNumRef.as_fraction().

3031  """ Return the denominator as a Python long.
3032 
3033  >>> v = RealVal("1/3")
3034  >>> v
3035  1/3
3036  >>> v.denominator_as_long()
3037  3
3038  """
3039  return self.denominator().as_long()
3040 
def denominator_as_long(self)
Definition: z3py.py:3030
def denominator(self)
Definition: z3py.py:3006
def as_long(self)
Definition: z3py.py:3050
def is_int (   self)

Definition at line 3041 of file z3py.py.

3041  def is_int(self):
3042  return False
3043 
def is_int(self)
Definition: z3py.py:3041
def is_int_value (   self)

Definition at line 3047 of file z3py.py.

Referenced by RatNumRef.as_long().

3047  def is_int_value(self):
3048  return self.denominator().is_int() and self.denominator_as_long() == 1
3049 
def is_int_value(self)
Definition: z3py.py:3047
def denominator_as_long(self)
Definition: z3py.py:3030
def denominator(self)
Definition: z3py.py:3006
def is_int(self)
Definition: z3py.py:3041
def is_real (   self)

Definition at line 3044 of file z3py.py.

3044  def is_real(self):
3045  return True
3046 
def is_real(self)
Definition: z3py.py:3044
def 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 2991 of file z3py.py.

2991  def numerator(self):
2992  """ Return the numerator of a Z3 rational numeral.
2993 
2994  >>> is_rational_value(RealVal("3/5"))
2995  True
2996  >>> n = RealVal("3/5")
2997  >>> n.numerator()
2998  3
2999  >>> is_rational_value(Q(3,5))
3000  True
3001  >>> Q(3,5).numerator()
3002  3
3003  """
3004  return IntNumRef(Z3_get_numerator(self.ctx_ref(), self.as_ast()), self.ctx)
3005 
def as_ast(self)
Definition: z3py.py:392
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.
def ctx_ref(self)
Definition: z3py.py:400
def numerator(self)
Definition: z3py.py:2991
def 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 3017 of file z3py.py.

Referenced by RatNumRef.as_fraction(), and RatNumRef.as_long().

3018  """ Return the numerator as a Python long.
3019 
3020  >>> v = RealVal(10000000000)
3021  >>> v
3022  10000000000
3023  >>> v + 1
3024  10000000000 + 1
3025  >>> v.numerator_as_long() + 1 == 10000000001
3026  True
3027  """
3028  return self.numerator().as_long()
3029 
def numerator_as_long(self)
Definition: z3py.py:3017
def numerator(self)
Definition: z3py.py:2991
def as_long(self)
Definition: z3py.py:3050