4.2.2.1 Integer Objects

class Integer
The Integer class represents arbitrary precision integers. It derives from the Element class, so integers can be used as ring elements anywhere in SAGE.

Note: The class Integer is implemented in Pyrex, as a wrapper of the GMP mpz_t integer type.
Instances of class Integer have the following methods (in addition to inherited methods and special methods):

copy,$  $ crt,$  $ denominator,$  $ factor,$  $ gcd,$  $ inverse_mod,$  $ is_one,$  $ is_square_free,$  $ is_zero,$  $ isqrt,$  $ lcm,$  $ parent,$  $ powermod,$  $ set_si,$  $ set_str,$  $ sqrt,$  $ str,$  $ xgcd

These methods are defined as follows:

copy( )

Return a copy of the integer.

crt( )

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( )

Return the greatest common divisor of self and $ n$ .

inverse_mod( )

Returns the inverse of self modulo $ n$ , if this inverse exists. Otherwise, raises a exceptionZeroDivisionError exception.

INPUT:
   self -- Integer
   n -- Integer
OUTPUT:
   x -- Integer such that x*self = 1 (mod m), or
        raises ZeroDivisionError.
IMPLEMENTATION:
   Call the mpz_invert GMP library function.

sage: a = Integer(189)
sage: a.inverse_mod(10000)
4709
sage: a.inverse_mod(-10000)
4709
sage: a.inverse_mod(1890)
Traceback (most recent call last):
...
ZeroDivisionError: Inverse does not exist.
sage: a = Integer(19)**100000
sage: b = a*a
sage: c=a.inverse_mod(b)
Traceback (most recent call last):
...
ZeroDivisionError: Inverse does not exist.

is_one( )

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

is_square_free( )

Returns True if this integer is not divisible by the square of any prime and False otherwise.

is_zero( )

Returns True if the integers is 0 , otherwise False.

isqrt( )

Returns the integer floor of the square root of self, or raises an ValueError if self is negative.

EXAMPLE:

sage: a = Integer(5)
sage: a.isqrt()
2

lcm( )

Returns the least common multiple of self and $ n$ .

parent( )

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

powermod( )

powermod(self, Integer exp, Integer mod): Compute self**exp modulo mod.

set_si( )

Coerces $ n$ to a C signed integer if possible, and sets self equal to $ n$ .

set_str( )

Set self equal to the number defined by the string s in the given base.

sqrt( )

Returns the square root of self if self is a perfect square, or raises a ValueError exception otherwise.

EXAMPLE:

sage: a = Integer(4)
sage: a.sqrt()
2.0

str( )

Return the string representation of self in the given base.

Note: String representation of integers with more than about four million digits is not available in bases other than a power of 2. This is because of a bug in GMP. To obtain the base-$ b$ expansion of an integer $ n$ use n.str(b).

xgcd( )

Return a triple $ g, s, t \in\mathbf{Z}$ such that

$\displaystyle g = s \cdot$   self$\displaystyle + t \cdot n.
$

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