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)
 
def py_value (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)
 
def __abs__ (self)
 
- 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 kind (self)
 
def num_args (self)
 
def arg (self, idx)
 
def children (self)
 
def update (self, args)
 
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)
 
def py_value (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 3149 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 3215 of file z3py.py.

3215  def as_decimal(self, prec):
3216  """ Return a Z3 rational value as a string in decimal notation using at most `prec` decimal places.
3217 
3218  >>> v = RealVal("1/5")
3219  >>> v.as_decimal(3)
3220  '0.2'
3221  >>> v = RealVal("1/3")
3222  >>> v.as_decimal(3)
3223  '0.333?'
3224  """
3225  return Z3_get_numeral_decimal_string(self.ctx_ref(), self.as_ast(), prec)
3226 
def as_ast(self)
Definition: z3py.py:419
def as_decimal(self, prec)
Definition: z3py.py: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...
def ctx_ref(self)
Definition: z3py.py:427
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 3236 of file z3py.py.

3236  def as_fraction(self):
3237  """Return a Z3 rational as a Python Fraction object.
3238 
3239  >>> v = RealVal("1/5")
3240  >>> v.as_fraction()
3241  Fraction(1, 5)
3242  """
3243  return Fraction(self.numerator_as_long(), self.denominator_as_long())
3244 
def as_fraction(self)
Definition: z3py.py:3236
def denominator_as_long(self)
Definition: z3py.py:3191
def numerator_as_long(self)
Definition: z3py.py:3178
def as_long (   self)

Definition at line 3211 of file z3py.py.

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

3211  def as_long(self):
3212  _z3_assert(self.is_int_value(), "Expected integer fraction")
3213  return self.numerator_as_long()
3214 
def is_int_value(self)
Definition: z3py.py:3208
def numerator_as_long(self)
Definition: z3py.py:3178
def as_long(self)
Definition: z3py.py:3211
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 3227 of file z3py.py.

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

3227  def as_string(self):
3228  """Return a Z3 rational numeral as a Python string.
3229 
3230  >>> v = Q(3,6)
3231  >>> v.as_string()
3232  '1/2'
3233  """
3234  return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
3235 
def as_ast(self)
Definition: z3py.py:419
def as_string(self)
Definition: z3py.py:3227
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:427
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 3167 of file z3py.py.

3167  def denominator(self):
3168  """ Return the denominator of a Z3 rational numeral.
3169 
3170  >>> is_rational_value(Q(3,5))
3171  True
3172  >>> n = Q(3,5)
3173  >>> n.denominator()
3174  5
3175  """
3176  return IntNumRef(Z3_get_denominator(self.ctx_ref(), self.as_ast()), self.ctx)
3177 
def as_ast(self)
Definition: z3py.py:419
def denominator(self)
Definition: z3py.py:3167
def ctx_ref(self)
Definition: z3py.py:427
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 3191 of file z3py.py.

Referenced by RatNumRef.as_fraction().

3192  """ Return the denominator as a Python long.
3193 
3194  >>> v = RealVal("1/3")
3195  >>> v
3196  1/3
3197  >>> v.denominator_as_long()
3198  3
3199  """
3200  return self.denominator().as_long()
3201 
def denominator_as_long(self)
Definition: z3py.py:3191
def denominator(self)
Definition: z3py.py:3167
def as_long(self)
Definition: z3py.py:3211
def is_int (   self)

Definition at line 3202 of file z3py.py.

3202  def is_int(self):
3203  return False
3204 
def is_int(self)
Definition: z3py.py:3202
def is_int_value (   self)

Definition at line 3208 of file z3py.py.

Referenced by RatNumRef.as_long().

3208  def is_int_value(self):
3209  return self.denominator().is_int() and self.denominator_as_long() == 1
3210 
def is_int_value(self)
Definition: z3py.py:3208
def denominator_as_long(self)
Definition: z3py.py:3191
def denominator(self)
Definition: z3py.py:3167
def is_int(self)
Definition: z3py.py:3202
def is_real (   self)

Definition at line 3205 of file z3py.py.

3205  def is_real(self):
3206  return True
3207 
def is_real(self)
Definition: z3py.py:3205
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 3152 of file z3py.py.

3152  def numerator(self):
3153  """ Return the numerator of a Z3 rational numeral.
3154 
3155  >>> is_rational_value(RealVal("3/5"))
3156  True
3157  >>> n = RealVal("3/5")
3158  >>> n.numerator()
3159  3
3160  >>> is_rational_value(Q(3,5))
3161  True
3162  >>> Q(3,5).numerator()
3163  3
3164  """
3165  return IntNumRef(Z3_get_numerator(self.ctx_ref(), self.as_ast()), self.ctx)
3166 
def as_ast(self)
Definition: z3py.py:419
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:427
def numerator(self)
Definition: z3py.py:3152
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 3178 of file z3py.py.

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

3179  """ Return the numerator as a Python long.
3180 
3181  >>> v = RealVal(10000000000)
3182  >>> v
3183  10000000000
3184  >>> v + 1
3185  10000000000 + 1
3186  >>> v.numerator_as_long() + 1 == 10000000001
3187  True
3188  """
3189  return self.numerator().as_long()
3190 
def numerator_as_long(self)
Definition: z3py.py:3178
def numerator(self)
Definition: z3py.py:3152
def as_long(self)
Definition: z3py.py:3211
def py_value (   self)

Definition at line 3245 of file z3py.py.

3245  def py_value(self):
3246  return Z3_get_numeral_double(self.ctx_ref(), self.as_ast())
3247 
3248 
def as_ast(self)
Definition: z3py.py:419
def py_value(self)
Definition: z3py.py:3245
double Z3_API Z3_get_numeral_double(Z3_context c, Z3_ast a)
Return numeral as a double.
def ctx_ref(self)
Definition: z3py.py:427