Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions
RatNumRef Class Reference
+ Inheritance diagram for RatNumRef:

Public Member Functions

def numerator
 
def denominator
 
def numerator_as_long
 
def denominator_as_long
 
def as_decimal
 
def as_string
 
def as_fraction
 
- Public Member Functions inherited from ArithRef
def sort
 
def is_int
 
def is_real
 
def __add__
 
def __radd__
 
def __mul__
 
def __rmul__
 
def __sub__
 
def __rsub__
 
def __pow__
 
def __rpow__
 
def __div__
 
def __truediv__
 
def __rdiv__
 
def __rtruediv__
 
def __mod__
 
def __rmod__
 
def __neg__
 
def __pos__
 
def __le__
 
def __lt__
 
def __gt__
 
def __ge__
 
- Public Member Functions inherited from ExprRef
def as_ast
 
def get_id
 
def sort
 
def sort_kind
 
def __eq__
 
def __ne__
 
def decl
 
def num_args
 
def arg
 
def children
 
- Public Member Functions inherited from AstRef
def __init__
 
def __del__
 
def __str__
 
def __repr__
 
def sexpr
 
def as_ast
 
def get_id
 
def ctx_ref
 
def eq
 
def translate
 
def hash
 
- Public Member Functions inherited from Z3PPObject
def use_pp
 

Additional Inherited Members

- Data Fields inherited from AstRef
 ast
 
 ctx
 

Detailed Description

Rational values.

Definition at line 2521 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 2574 of file z3py.py.

2575  def as_decimal(self, prec):
2576  """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
2577 
2578  >>> v = RealVal("1/5")
2579  >>> v.as_decimal(3)
2580  '0.2'
2581  >>> v = RealVal("1/3")
2582  >>> v.as_decimal(3)
2583  '0.333?'
2584  """
2585  return Z3_get_numeral_decimal_string(self.ctx_ref(), self.as_ast(), prec)
def as_decimal
Definition: z3py.py:2574
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 as_ast
Definition: z3py.py:296
def ctx_ref
Definition: z3py.py:304
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 2595 of file z3py.py.

2596  def as_fraction(self):
2597  """Return a Z3 rational as a Python Fraction object.
2598 
2599  >>> v = RealVal("1/5")
2600  >>> v.as_fraction()
2601  Fraction(1, 5)
2602  """
2603  return Fraction(self.numerator_as_long(), self.denominator_as_long())
def numerator_as_long
Definition: z3py.py:2550
def as_fraction
Definition: z3py.py:2595
def denominator_as_long
Definition: z3py.py:2563
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 2586 of file z3py.py.

2587  def as_string(self):
2588  """Return a Z3 rational numeral as a Python string.
2589 
2590  >>> v = Q(3,6)
2591  >>> v.as_string()
2592  '1/2'
2593  """
2594  return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
Z3_string Z3_API Z3_get_numeral_string(Z3_context c, Z3_ast a)
Return numeral value, as a string of a numeric constant term.
def as_ast
Definition: z3py.py:296
def as_string
Definition: z3py.py:2586
def ctx_ref
Definition: z3py.py:304
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 2539 of file z3py.py.

2540  def denominator(self):
2541  """ Return the denominator of a Z3 rational numeral.
2542 
2543  >>> is_rational_value(Q(3,5))
2544  True
2545  >>> n = Q(3,5)
2546  >>> n.denominator()
2547  5
2548  """
2549  return IntNumRef(Z3_get_denominator(self.ctx_ref(), self.as_ast()), self.ctx)
def denominator
Definition: z3py.py:2539
def as_ast
Definition: z3py.py:296
def ctx_ref
Definition: z3py.py:304
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 2563 of file z3py.py.

Referenced by RatNumRef.as_fraction().

2564  def denominator_as_long(self):
2565  """ Return the denominator as a Python long.
2566 
2567  >>> v = RealVal("1/3")
2568  >>> v
2569  1/3
2570  >>> v.denominator_as_long()
2571  3
2572  """
2573  return self.denominator().as_long()
def denominator
Definition: z3py.py:2539
def denominator_as_long
Definition: z3py.py:2563
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 2524 of file z3py.py.

2525  def numerator(self):
2526  """ Return the numerator of a Z3 rational numeral.
2527 
2528  >>> is_rational_value(RealVal("3/5"))
2529  True
2530  >>> n = RealVal("3/5")
2531  >>> n.numerator()
2532  3
2533  >>> is_rational_value(Q(3,5))
2534  True
2535  >>> Q(3,5).numerator()
2536  3
2537  """
2538  return IntNumRef(Z3_get_numerator(self.ctx_ref(), self.as_ast()), self.ctx)
def numerator
Definition: z3py.py:2524
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 as_ast
Definition: z3py.py:296
def ctx_ref
Definition: z3py.py:304
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 2550 of file z3py.py.

Referenced by RatNumRef.as_fraction().

2551  def numerator_as_long(self):
2552  """ Return the numerator as a Python long.
2553 
2554  >>> v = RealVal(10000000000)
2555  >>> v
2556  10000000000
2557  >>> v + 1
2558  10000000000 + 1
2559  >>> v.numerator_as_long() + 1 == 10000000001
2560  True
2561  """
2562  return self.numerator().as_long()
def numerator_as_long
Definition: z3py.py:2550
def numerator
Definition: z3py.py:2524