NZMATH  1.2.0
About: NZMATH is a Python based number theory oriented calculation system.
  Fossies Dox: NZMATH-1.2.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

nzmath.rational.Rational Class Reference
Inheritance diagram for nzmath.rational.Rational:
[legend]
Collaboration diagram for nzmath.rational.Rational:
[legend]

Public Member Functions

def __init__ (self, numerator, denominator=1)
 
def __add__ (self, other)
 
def __sub__ (self, other)
 
def __mul__ (self, other)
 
def __truediv__ (self, other)
 
def __radd__ (self, other)
 
def __rsub__ (self, other)
 
def __rmul__ (self, other)
 
def __rtruediv__ (self, other)
 
def __pow__ (self, index)
 
def __lt__ (self, other)
 
def __le__ (self, other)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __gt__ (self, other)
 
def __ge__ (self, other)
 
def __pos__ (self)
 
def __neg__ (self)
 
def __abs__ (self)
 
def __long__ (self)
 
def __str__ (self)
 
def __repr__ (self)
 
def __nonzero__ (self)
 
def __hash__ (self)
 
def expand (self, base, limit)
 
def trim (self, max_denominator)
 
def compare (self, other)
 
def getRing (self)
 
def __float__ (self)
 
def toFloat (self)
 
def decimalString (self, N)
 
- Public Member Functions inherited from nzmath.ring.QuotientFieldElement
def inverse (self)
 
- Public Member Functions inherited from nzmath.ring.FieldElement
def __init__ (self)
 
def exact_division (self, other)
 
- Public Member Functions inherited from nzmath.ring.CommutativeRingElement
def mul_module_action (self, other)
 
- Public Member Functions inherited from nzmath.ring.RingElement
def __init__ (self, *args, **kwd)
 

Public Attributes

 denominator
 
 numerator
 
- Public Attributes inherited from nzmath.ring.QuotientFieldElement
 numerator
 
 denominator
 

Private Member Functions

def _reduce (self)
 
def _init_by_Rational_Rational (self, numerator, denominator)
 
def _init_by_float_Rational (self, numerator, denominator)
 
def _init_by_int_Rational (self, numerator, denominator)
 
def _init_by_Rational_float (self, numerator, denominator)
 
def _init_by_float_float (self, numerator, denominator)
 
def _init_by_int_float (self, numerator, denominator)
 
def _init_by_Rational_int (self, numerator, denominator)
 
def _init_by_float_int (self, numerator, denominator)
 
def _init_by_int_int (self, numerator, denominator)
 

Static Private Attributes

def __div__ = __truediv__
 
def __floordiv__ = __truediv__
 
def __rdiv__ = __rtruediv__
 
def __rfloordiv__ = __rtruediv__
 
def __int__ = __long__
 

Detailed Description

Rational is the class of rational numbers.

Definition at line 10 of file rational.py.

Constructor & Destructor Documentation

◆ __init__()

def nzmath.rational.Rational.__init__ (   self,
  numerator,
  denominator = 1 
)
Create a rational from:
  * integers,
  * float, or
  * Rational.
Other objects can be converted if they have toRational
methods.  Otherwise raise TypeError.

Reimplemented from nzmath.ring.QuotientFieldElement.

Definition at line 15 of file rational.py.

References nzmath.rational.continued_fraction_expansion().

Member Function Documentation

◆ __abs__()

def nzmath.rational.Rational.__abs__ (   self)

◆ __add__()

def nzmath.rational.Rational.__add__ (   self,
  other 
)
self + other

If other is a rational or an integer, the result will be a
rational.  If other is a kind of float the result is an
instance of other's type.  Otherwise, other would do the
computation.

Reimplemented from nzmath.ring.QuotientFieldElement.

Definition at line 68 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ __eq__()

def nzmath.rational.Rational.__eq__ (   self,
  other 
)

◆ __float__()

def nzmath.rational.Rational.__float__ (   self)

Definition at line 417 of file rational.py.

References nzmath.rational.Rational.decimalString().

◆ __ge__()

def nzmath.rational.Rational.__ge__ (   self,
  other 
)

Definition at line 289 of file rational.py.

References nzmath.rational.Rational.compare().

◆ __gt__()

def nzmath.rational.Rational.__gt__ (   self,
  other 
)

Definition at line 286 of file rational.py.

References nzmath.rational.Rational.compare().

◆ __hash__()

◆ __le__()

def nzmath.rational.Rational.__le__ (   self,
  other 
)

Definition at line 267 of file rational.py.

References nzmath.rational.Rational.compare().

◆ __long__()

def nzmath.rational.Rational.__long__ (   self)

◆ __lt__()

def nzmath.rational.Rational.__lt__ (   self,
  other 
)

Definition at line 264 of file rational.py.

References nzmath.rational.Rational.compare().

◆ __mul__()

def nzmath.rational.Rational.__mul__ (   self,
  other 
)
self * other

If other is a rational or an integer, the result will be a
rational.  If other is a kind of float the result is an
instance of other's type.  Otherwise, other would do the
computation.

Reimplemented from nzmath.ring.QuotientFieldElement.

Definition at line 116 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ __ne__()

def nzmath.rational.Rational.__ne__ (   self,
  other 
)
Inequality test.

Reimplemented from nzmath.ring.RingElement.

Definition at line 283 of file rational.py.

References nzmath.rational.Rational.compare().

◆ __neg__()

def nzmath.rational.Rational.__neg__ (   self)

◆ __nonzero__()

def nzmath.rational.Rational.__nonzero__ (   self)

Definition at line 316 of file rational.py.

References nzmath.rational.Rational.numerator.

◆ __pos__()

def nzmath.rational.Rational.__pos__ (   self)

◆ __pow__()

def nzmath.rational.Rational.__pow__ (   self,
  index 
)

◆ __radd__()

def nzmath.rational.Rational.__radd__ (   self,
  other 
)
other + self

If other is an integer, the result will be a rational.  If
other is a kind of float the result is an instance of other's
type.  Otherwise, other would do the computation.

Definition at line 171 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ __repr__()

◆ __rmul__()

def nzmath.rational.Rational.__rmul__ (   self,
  other 
)
other * self

If other is an integer, the result will be a rational.  If
other is a kind of float the result is an instance of other's
type.  Otherwise, other would do the computation.

Definition at line 209 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ __rsub__()

def nzmath.rational.Rational.__rsub__ (   self,
  other 
)
other - self

If other is an integer, the result will be a rational.  If
other is a kind of float the result is an instance of other's
type.  Otherwise, other would do the computation.

Reimplemented from nzmath.ring.QuotientFieldElement.

Definition at line 190 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ __rtruediv__()

def nzmath.rational.Rational.__rtruediv__ (   self,
  other 
)
other / self
other // self

If other is an integer, the result will be a rational.  If
other is a kind of float the result is an instance of other's
type.  Otherwise, other would do the computation.

Reimplemented from nzmath.ring.QuotientFieldElement.

Definition at line 228 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ __str__()

def nzmath.rational.Rational.__str__ (   self)

◆ __sub__()

def nzmath.rational.Rational.__sub__ (   self,
  other 
)
self - other

If other is a rational or an integer, the result will be a
rational.  If other is a kind of float the result is an
instance of other's type.  Otherwise, other would do the
computation.

Reimplemented from nzmath.ring.QuotientFieldElement.

Definition at line 92 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ __truediv__()

def nzmath.rational.Rational.__truediv__ (   self,
  other 
)
self / other
self // other

If other is a rational or an integer, the result will be a
rational.  If other is a kind of float the result is an
instance of other's type.  Otherwise, other would do the
computation.

Reimplemented from nzmath.ring.QuotientFieldElement.

Definition at line 140 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.toFloat().

◆ _init_by_float_float()

def nzmath.rational.Rational._init_by_float_float (   self,
  numerator,
  denominator 
)
private
Initialize by a float numbers.

Definition at line 474 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_float_int()

def nzmath.rational.Rational._init_by_float_int (   self,
  numerator,
  denominator 
)
private
Initialize by a float number and an integer.

Definition at line 500 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_float_Rational()

def nzmath.rational.Rational._init_by_float_Rational (   self,
  numerator,
  denominator 
)
private
Initialize by a float number and a rational number.

Definition at line 449 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_int_float()

def nzmath.rational.Rational._init_by_int_float (   self,
  numerator,
  denominator 
)
private
Initailize by an integer and a float

Definition at line 484 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_int_int()

def nzmath.rational.Rational._init_by_int_int (   self,
  numerator,
  denominator 
)
private
Initailize by an integers.

Definition at line 509 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_int_Rational()

def nzmath.rational.Rational._init_by_int_Rational (   self,
  numerator,
  denominator 
)
private
Initailize by an integer and a rational number.

Definition at line 458 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_Rational_float()

def nzmath.rational.Rational._init_by_Rational_float (   self,
  numerator,
  denominator 
)
private
Initialize by a rational number and a float.

Definition at line 465 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_Rational_int()

def nzmath.rational.Rational._init_by_Rational_int (   self,
  numerator,
  denominator 
)
private
Initialize by a rational number and integer.

Definition at line 493 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _init_by_Rational_Rational()

def nzmath.rational.Rational._init_by_Rational_Rational (   self,
  numerator,
  denominator 
)
private
Initialize by a rational numbers.

Definition at line 442 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

◆ _reduce()

def nzmath.rational.Rational._reduce (   self)
private

◆ compare()

◆ decimalString()

def nzmath.rational.Rational.decimalString (   self,
  N 
)
Return a string of the number to N decimal places.

Definition at line 423 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, and nzmath.rational.Rational.numerator.

Referenced by nzmath.rational.Rational.__float__().

◆ expand()

def nzmath.rational.Rational.expand (   self,
  base,
  limit 
)
r.expand(k, limit) returns the nearest rational number whose
denominator is a power of k and at most limit, if k > 0.  if
k==0, it returns the nearest rational number whose denominator
is at most limit, i.e. r.expand(0, limit) == r.trim(limit).

Definition at line 334 of file rational.py.

References nzmath.rational.Rational.denominator, nzmath.module.Module.denominator, nzmath.rational.isIntegerObject(), nzmath.rational.Rational.numerator, and nzmath.rational.Rational.trim().

◆ getRing()

◆ toFloat()

◆ trim()

def nzmath.rational.Rational.trim (   self,
  max_denominator 
)

Member Data Documentation

◆ __div__

def nzmath.rational.Rational.__div__ = __truediv__
staticprivate

Definition at line 168 of file rational.py.

◆ __floordiv__

def nzmath.rational.Rational.__floordiv__ = __truediv__
staticprivate

Definition at line 169 of file rational.py.

◆ __int__

def nzmath.rational.Rational.__int__ = __long__
staticprivate

Definition at line 308 of file rational.py.

◆ __rdiv__

def nzmath.rational.Rational.__rdiv__ = __rtruediv__
staticprivate

Definition at line 250 of file rational.py.

◆ __rfloordiv__

def nzmath.rational.Rational.__rfloordiv__ = __rtruediv__
staticprivate

Definition at line 251 of file rational.py.

◆ denominator

nzmath.rational.Rational.denominator

Definition at line 60 of file rational.py.

Referenced by nzmath.rational.Rational.__abs__(), nzmath.rational.Rational.__add__(), nzmath.ring.QuotientFieldElement.__add__(), nzmath.round2.ModuleWithDenominator.__add__(), nzmath.poly.ratfunc.RationalFunction.__call__(), nzmath.rational.Rational.__eq__(), nzmath.ring.QuotientFieldElement.__eq__(), nzmath.rational.Rational.__hash__(), nzmath.ring.QuotientFieldElement.__hash__(), nzmath.poly.ratfunc.RationalFunction.__init__(), nzmath.rational.Rational.__long__(), nzmath.rational.Rational.__mul__(), nzmath.ring.QuotientFieldElement.__mul__(), nzmath.round2.ModuleWithDenominator.__mul__(), nzmath.rational.Rational.__neg__(), nzmath.ring.QuotientFieldElement.__neg__(), nzmath.rational.Rational.__pos__(), nzmath.rational.Rational.__pow__(), nzmath.ring.QuotientFieldElement.__pow__(), nzmath.rational.Rational.__radd__(), nzmath.poly.ratfunc.RationalFunction.__repr__(), nzmath.rational.Rational.__repr__(), nzmath.rational.Rational.__rmul__(), nzmath.rational.Rational.__rsub__(), nzmath.ring.QuotientFieldElement.__rsub__(), nzmath.rational.Rational.__rtruediv__(), nzmath.ring.QuotientFieldElement.__rtruediv__(), nzmath.poly.ratfunc.RationalFunction.__str__(), nzmath.rational.Rational.__str__(), nzmath.rational.Rational.__sub__(), nzmath.ring.QuotientFieldElement.__sub__(), nzmath.rational.Rational.__truediv__(), nzmath.ring.QuotientFieldElement.__truediv__(), nzmath.round2.ModuleWithDenominator.__truediv__(), nzmath.rational.Rational._init_by_float_float(), nzmath.rational.Rational._init_by_float_int(), nzmath.rational.Rational._init_by_float_Rational(), nzmath.rational.Rational._init_by_int_float(), nzmath.rational.Rational._init_by_int_int(), nzmath.rational.Rational._init_by_int_Rational(), nzmath.rational.Rational._init_by_Rational_float(), nzmath.rational.Rational._init_by_Rational_int(), nzmath.rational.Rational._init_by_Rational_Rational(), nzmath.rational.Rational._reduce(), nzmath.rational.Rational.compare(), nzmath.rational.Rational.decimalString(), nzmath.round2.ModuleWithDenominator.determinant(), nzmath.rational.Rational.expand(), nzmath.round2.ModuleWithDenominator.get_polynomials(), nzmath.round2.ModuleWithDenominator.get_rationals(), nzmath.ring.QuotientFieldElement.inverse(), nzmath.rational.Rational.toFloat(), and nzmath.rational.Rational.trim().

◆ numerator

nzmath.rational.Rational.numerator

Definition at line 273 of file rational.py.

Referenced by nzmath.rational.Rational.__abs__(), nzmath.rational.Rational.__add__(), nzmath.ring.QuotientFieldElement.__add__(), nzmath.poly.ratfunc.RationalFunction.__call__(), nzmath.ring.QuotientFieldElement.__eq__(), nzmath.rational.Rational.__hash__(), nzmath.ring.QuotientFieldElement.__hash__(), nzmath.poly.ratfunc.RationalFunction.__init__(), nzmath.rational.Rational.__long__(), nzmath.rational.Rational.__mul__(), nzmath.ring.QuotientFieldElement.__mul__(), nzmath.rational.Rational.__neg__(), nzmath.ring.QuotientFieldElement.__neg__(), nzmath.rational.Rational.__nonzero__(), nzmath.rational.Rational.__pos__(), nzmath.rational.Rational.__pow__(), nzmath.ring.QuotientFieldElement.__pow__(), nzmath.rational.Rational.__radd__(), nzmath.poly.ratfunc.RationalFunction.__repr__(), nzmath.rational.Rational.__repr__(), nzmath.rational.Rational.__rmul__(), nzmath.rational.Rational.__rsub__(), nzmath.ring.QuotientFieldElement.__rsub__(), nzmath.rational.Rational.__rtruediv__(), nzmath.ring.QuotientFieldElement.__rtruediv__(), nzmath.poly.ratfunc.RationalFunction.__str__(), nzmath.rational.Rational.__str__(), nzmath.rational.Rational.__sub__(), nzmath.ring.QuotientFieldElement.__sub__(), nzmath.rational.Rational.__truediv__(), nzmath.ring.QuotientFieldElement.__truediv__(), nzmath.rational.Rational._init_by_float_float(), nzmath.rational.Rational._init_by_float_int(), nzmath.rational.Rational._init_by_float_Rational(), nzmath.rational.Rational._init_by_int_float(), nzmath.rational.Rational._init_by_int_int(), nzmath.rational.Rational._init_by_int_Rational(), nzmath.rational.Rational._init_by_Rational_float(), nzmath.rational.Rational._init_by_Rational_int(), nzmath.rational.Rational._init_by_Rational_Rational(), nzmath.rational.Rational._reduce(), nzmath.rational.Rational.compare(), nzmath.rational.Rational.decimalString(), nzmath.rational.Rational.expand(), nzmath.poly.ratfunc.RationalFunction.getRing(), nzmath.ring.QuotientFieldElement.inverse(), nzmath.rational.Rational.toFloat(), and nzmath.rational.Rational.trim().


The documentation for this class was generated from the following file: