13.2.1.1 IntegerRing Objects

class IntegerRing
The ring of integers.
IntegerRing( )

In order to introduce the ring $ \mathbf{Z}$ of integers, we illustrate creation, calling a few functions, and working with its elements.

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

We next illustrate basic arithmetic in $ \mathbf{Z}$ :

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

When we divide to integers using /, the result is automatically coerced to the field of rational numbers, even if the result is an integer.

sage: a / b
617/2839
sage: type(a/b)
<type '_rational.Rational'>
sage: a/a
1
sage: type(a/a)
<type '_rational.Rational'>

For floor division, instead using the // operator:

sage: a // b
0
sage: type(a//b)
<type '_integer.Integer'>

Next we illustrate arithmetic with automatic coercion. The types that coerce are: str, int, long, Integer.

sage: a + 17
1251
sage: a * 374
461516
sage: 374 * a
461516
sage: a/19
1234/19
sage: 0 + Z(-64)
-64

Integers can be coerced:

sage: a = Z(-64)
sage: int(a)
-64
sage: long(a)
-64L

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

characteristic,$  $ fraction_field,$  $ is_atomic_repr,$  $ is_field,$  $ is_finite,$  $ krull_dimension,$  $ random,$  $ zeta

Further documentation:

characteristic( )

Return 0 as a Python int.

is_atomic_repr( )

Return True, since elements of the integers do not have to be printed with paranethesis around them, when they are coefficients, e.g., in a polynomial.

is_field( )

Return False.

krull_dimension( )

Return the Krull dimension of the integers, which is 1.

random( [bound=5])

Return a random integer between -bound and bound, including both endpoints.

zeta( )

Return the integer -1, which is the root of unity of largest order in Z.

Instances of class IntegerRing also have the following special methods:

__call__,$  $ __cmp__,$  $ __contains__,$  $ __reduce__,$  $ __repr__,$  $ _coerce_,$  $ _latex_

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