6.4.2.1 Rational Objects

class Rational
Instances of class Rational have the following methods (in addition to inherited methods and special methods):

additive_order,$  $ copy,$  $ denom,$  $ denominator,$  $ factor,$  $ height,$  $ is_one,$  $ is_zero,$  $ mod_ui,$  $ multiplicative_order,$  $ numer,$  $ numerator,$  $ set_si,$  $ set_str,$  $ sqrt,$  $ square_root,$  $ str

Further documentation:

additive_order( )

Return the additive order of self.

sage: QQ(0).additive_order()
1
sage: QQ(1).additive_order()
Infinity

height( )

The max absolute value of the numerator and denominator of self, as an Integer.

multiplicative_order( )

Return the multiplicative order of self, if self is a unit, or raise codeArithmeticError otherwise.

sage: QQ(1).multiplicative_order()
1
sage: QQ('1/-1').multiplicative_order()
2
sage: QQ(0).multiplicative_order()
Traceback (most recent call last):
...
ArithmeticError: no power of 0 is a unit
sage: QQ('2/3').multiplicative_order()
Traceback (most recent call last):
...
ArithmeticError: no power of 2/3 is a unit

sqrt( )

Returns the positive square root of self as a real number to the given number of bits of precision if self is nonnegative, and raises a ValueError exception otherwise.

square_root( )

Return the positive rational square root of self, or raises a ValueError if self is not a perfect square.

Instances of class Rational also have the following special methods:

__abs__,$  $ __add,$  $ __add__,$  $ __cmp__,$  $ __div,$  $ __div__,$  $ __eq__,$  $ __float__,$  $ __ge__,$  $ __gt__,$  $ __int__,$  $ __invert__,$  $ __le__,$  $ __long__,$  $ __lt__,$  $ __mod__,$  $ __mul,$  $ __mul__,$  $ __ne__,$  $ __neg__,$  $ __pos__,$  $ __pow__,$  $ __radd__,$  $ __rdiv__,$  $ __reduce__,$  $ __repr__,$  $ __rmod__,$  $ __rmul__,$  $ __rpow__,$  $ __rsub__,$  $ __set_value,$  $ __sub,$  $ __sub__,$  $ _gcd,$  $ _latex_,$  $ _lcm,$  $ _mpfr_,$  $ _pari_

Further documentation:

_gcd( )

Returns the least common multiple, in the rational numbers, of self and other. This function returns either 0 or 1 (as a rational number).

_lcm( )

Returns the least common multiple, in the rational numbers, of self and other. This function returns either 0 or 1 (as a rational number).

See About this document... for information on suggesting changes.