6.2.1 rings.integer_ring - The Integer Ring

The class IntegerRing represents the ring $ \mathbf{Z}$ of (arbitrary precision) integers. Each integer is an instance of the class Integer, which is defined in a Pyrex extension module that wraps GMP integers (the mpz_t type in GMP).

sage: Z = IntegerRing(); Z
Integer Ring
sage: Z.characteristic()
0
sage: Z.is_field()
False

There is a unique instances of class IntegerRing. To create an Integer, coerce either a Python int, long, or a string. Various other types will also coerce to the integers, when it makes sense.

sage: a = Z(1234); b = Z(5678); print a, b
1234 5678
sage: type(a)
<type '_integer.Integer'>
sage: a + b
6912
sage: Z('94803849083985934859834583945394')
94803849083985934859834583945394

The module rings.integer_ring defines the following methods:

crt_basis( X, [xgcd=None])

Compute and return a Chinese Remainder Theorem basis for the list X of coprime integers.

INPUT:
    X -- a list of Integers that are coprime in pairs
OUTPUT:
    E -- a list of Integers such that E[i] = 1 (mod X[i])
         and E[i] = 0 (mod X[j]) for all j!=i.

The E[i] have the property that if A is a list of objects, e.g., integers, vectors, matrices, etc., where A[i] is moduli X[i], then a CRT lift of A is simply sum E[i] * A[i].

ALGORITHM: To compute E[i], compute integers s and t such that

s * X[i] + t * (prod over i!=j of X[j]) = 1. (*)

Then E[i] = t * (prod over i!=j of X[j]). Notice that equation (*) implies that E[i] is congruent to 1 modulo X[i] and to 0 modulo the other X[j] for j!=i.

COMPLEXITY: We compute len(X) extended GCD's.

factor( n)

Return the factorization of the positive integer $ n$ as a list of tuples $ (p_i,e_i)$ such that $ n=\prod p_i^{e_i}$ .

The module rings.integer_ring defines the following classes:

class IntegerRing
The ring of integers.



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