Z3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 2496 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 2549 of file z3py.py.

2550  def as_decimal(self, prec):
2551  """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
2552 
2553  >>> v = RealVal("1/5")
2554  >>> v.as_decimal(3)
2555  '0.2'
2556  >>> v = RealVal("1/3")
2557  >>> v.as_decimal(3)
2558  '0.333?'
2559  """
2560  return Z3_get_numeral_decimal_string(self.ctx_ref(), self.as_ast(), prec)
def as_decimal
Definition: z3py.py:2549
Z3_string Z3_API Z3_get_numeral_decimal_string(__in Z3_context c, __in Z3_ast a, __in 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:305
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 2570 of file z3py.py.

2571  def as_fraction(self):
2572  """Return a Z3 rational as a Python Fraction object.
2573 
2574  >>> v = RealVal("1/5")
2575  >>> v.as_fraction()
2576  Fraction(1, 5)
2577  """
2578  return Fraction(self.numerator_as_long(), self.denominator_as_long())
def numerator_as_long
Definition: z3py.py:2525
def as_fraction
Definition: z3py.py:2570
def denominator_as_long
Definition: z3py.py:2538
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 2561 of file z3py.py.

Referenced by BitVecNumRef.as_long().

2562  def as_string(self):
2563  """Return a Z3 rational numeral as a Python string.
2564 
2565  >>> v = Q(3,6)
2566  >>> v.as_string()
2567  '1/2'
2568  """
2569  return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
def as_ast
Definition: z3py.py:296
def as_string
Definition: z3py.py:2561
Z3_string Z3_API Z3_get_numeral_string(__in Z3_context c, __in Z3_ast a)
Return numeral value, as a string of a numeric constant term.
def ctx_ref
Definition: z3py.py:305
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 2514 of file z3py.py.

2515  def denominator(self):
2516  """ Return the denominator of a Z3 rational numeral.
2517 
2518  >>> is_rational_value(Q(3,5))
2519  True
2520  >>> n = Q(3,5)
2521  >>> n.denominator()
2522  5
2523  """
2524  return IntNumRef(Z3_get_denominator(self.ctx_ref(), self.as_ast()), self.ctx)
Z3_ast Z3_API Z3_get_denominator(__in Z3_context c, __in Z3_ast a)
Return the denominator (as a numeral AST) of a numeral AST of sort Real.
def denominator
Definition: z3py.py:2514
def as_ast
Definition: z3py.py:296
def ctx_ref
Definition: z3py.py:305
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 2538 of file z3py.py.

Referenced by RatNumRef.as_fraction().

2539  def denominator_as_long(self):
2540  """ Return the denominator as a Python long.
2541 
2542  >>> v = RealVal("1/3")
2543  >>> v
2544  1/3
2545  >>> v.denominator_as_long()
2546  3
2547  """
2548  return self.denominator().as_long()
def denominator
Definition: z3py.py:2514
def denominator_as_long
Definition: z3py.py:2538
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 2499 of file z3py.py.

2500  def numerator(self):
2501  """ Return the numerator of a Z3 rational numeral.
2502 
2503  >>> is_rational_value(RealVal("3/5"))
2504  True
2505  >>> n = RealVal("3/5")
2506  >>> n.numerator()
2507  3
2508  >>> is_rational_value(Q(3,5))
2509  True
2510  >>> Q(3,5).numerator()
2511  3
2512  """
2513  return IntNumRef(Z3_get_numerator(self.ctx_ref(), self.as_ast()), self.ctx)
def numerator
Definition: z3py.py:2499
Z3_ast Z3_API Z3_get_numerator(__in Z3_context c, __in 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:305
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 2525 of file z3py.py.

Referenced by RatNumRef.as_fraction().

2526  def numerator_as_long(self):
2527  """ Return the numerator as a Python long.
2528 
2529  >>> v = RealVal(10000000000)
2530  >>> v
2531  10000000000
2532  >>> v + 1
2533  10000000000 + 1
2534  >>> v.numerator_as_long() + 1 == 10000000001
2535  True
2536  """
2537  return self.numerator().as_long()
def numerator_as_long
Definition: z3py.py:2525
def numerator
Definition: z3py.py:2499