3.1.2 rings.integer - Elements of the Integer Ring

Module Author: William A. Stein (was@math.harvard.edu)
Section Author: William A. Stein (was@math.harvard.edu)

The integer module has the following method:

factorial( n)
Return the factorial $n!=1 \cdot 2 \cdot 3 \cdots n$. The input integer $n$ must fit in an unsigned long int.

The class Integer is defined rings.integer. Integers have the following methods:

copy( )
Return a copy of the integer.

crt( y, m, n)
Return the unique integer between $0$ and $mn$ that is congruent to the integer modulo $m$ and to $y$ modulo $n$. We assume that $m$ and $n$ are coprime.

denominator( )
Return the denominator of the integer.

factor( )
Return the prime factorization of the integer as a list of pairs $(p,e)$, where $p$ is prime and $e$ is a positive integer.

gcd( n)
Return the greatest common divisor of the integer and $n$.

inverse_mod( n)
Returns the inverse of the integer modulo $n$, if this inverse exists. Otherwise, raises a ZeroDivisionError exception.

is_one( )
Returns True if the integers is $1$, otherwise False.

is_zero( )
Returns True if the integers is $0$, otherwise False.

lcm( n)
Returns the least common multiple of the integer and $n$.

parent( )
Return the ring $\mathbf{Z}$ of integers.

sqrt( )
Returns the floor of the square root of the integer.

str( base=10)
Return the string representation of self in the given base.

set_si( n)
Coerces $n$ to a C signed integer if possible, and sets the integer equal to $n$.
Note: Note that integers are mutable. According to the implementors of gmpy, another wrapper of GMP for Python, this is ``bad''. If you don't like it, don't use these functions.

set_str( s, base=10)
Set the integer equal to the number defined by the string $s$ in the given base.

xgcd( n)
Return a triple $g, s, t \in\mathbf{Z}$ such that $
g = s \cdot \mbox{\rm self} + t \cdot n.
$

Integers also support the standard arithmetic operations, such as +,-,*,/, abs, mod, float

Note: The class Integer is implemented in Pyrex, as a wrapper of the GMP mpz_t integer type.

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