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 __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_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

Rational values.

Definition at line 2803 of file z3py.py.

Member Function Documentation

◆ as_decimal()

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

2869  def as_decimal(self, prec):
2870  """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
2871 
2872  >>> v = RealVal("1/5")
2873  >>> v.as_decimal(3)
2874  '0.2'
2875  >>> v = RealVal("1/3")
2876  >>> v.as_decimal(3)
2877  '0.333?'
2878  """
2879  return Z3_get_numeral_decimal_string(self.ctx_ref(), self.as_ast(), prec)
2880 

◆ as_fraction()

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

2890  def as_fraction(self):
2891  """Return a Z3 rational as a Python Fraction object.
2892 
2893  >>> v = RealVal("1/5")
2894  >>> v.as_fraction()
2895  Fraction(1, 5)
2896  """
2897  return Fraction(self.numerator_as_long(), self.denominator_as_long())
2898 

◆ as_long()

def as_long (   self)

Definition at line 2865 of file z3py.py.

2865  def as_long(self):
2866  _z3_assert(self.is_int_value(), "Expected integer fraction")
2867  return self.numerator_as_long()
2868 

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

◆ as_string()

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

2881  def as_string(self):
2882  """Return a Z3 rational numeral as a Python string.
2883 
2884  >>> v = Q(3,6)
2885  >>> v.as_string()
2886  '1/2'
2887  """
2888  return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
2889 

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

◆ denominator()

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

2821  def denominator(self):
2822  """ Return the denominator of a Z3 rational numeral.
2823 
2824  >>> is_rational_value(Q(3,5))
2825  True
2826  >>> n = Q(3,5)
2827  >>> n.denominator()
2828  5
2829  """
2830  return IntNumRef(Z3_get_denominator(self.ctx_ref(), self.as_ast()), self.ctx)
2831 

Referenced by RatNumRef.denominator_as_long(), and RatNumRef.is_int_value().

◆ denominator_as_long()

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

2845  def denominator_as_long(self):
2846  """ Return the denominator as a Python long.
2847 
2848  >>> v = RealVal("1/3")
2849  >>> v
2850  1/3
2851  >>> v.denominator_as_long()
2852  3
2853  """
2854  return self.denominator().as_long()
2855 

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

◆ is_int()

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

2856  def is_int(self):
2857  return False
2858 

Referenced by RatNumRef.is_int_value().

◆ is_int_value()

def is_int_value (   self)

Definition at line 2862 of file z3py.py.

2862  def is_int_value(self):
2863  return self.denominator().is_int() and self.denominator_as_long() == 1
2864 

Referenced by RatNumRef.as_long().

◆ is_real()

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

2859  def is_real(self):
2860  return True
2861 

◆ numerator()

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

2806  def numerator(self):
2807  """ Return the numerator of a Z3 rational numeral.
2808 
2809  >>> is_rational_value(RealVal("3/5"))
2810  True
2811  >>> n = RealVal("3/5")
2812  >>> n.numerator()
2813  3
2814  >>> is_rational_value(Q(3,5))
2815  True
2816  >>> Q(3,5).numerator()
2817  3
2818  """
2819  return IntNumRef(Z3_get_numerator(self.ctx_ref(), self.as_ast()), self.ctx)
2820 

Referenced by RatNumRef.numerator_as_long().

◆ numerator_as_long()

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

2832  def numerator_as_long(self):
2833  """ Return the numerator as a Python long.
2834 
2835  >>> v = RealVal(10000000000)
2836  >>> v
2837  10000000000
2838  >>> v + 1
2839  10000000000 + 1
2840  >>> v.numerator_as_long() + 1 == 10000000001
2841  True
2842  """
2843  return self.numerator().as_long()
2844 

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

Z3_get_numeral_string
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.
Z3_get_denominator
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.
z3py.is_real
def is_real(a)
Definition: z3py.py:2536
Z3_get_numerator
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.
z3py.is_int_value
def is_int_value(a)
Definition: z3py.py:2560
z3py.is_int
def is_int(a)
Definition: z3py.py:2518
Z3_get_numeral_decimal_string
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.