Rings

This module provides the abstract base class Ring from which all rings in Sage (used to) derive, as well as a selection of more specific base classes.

Warning

Those classes, except maybe for the lowest ones like CommutativeRing and Field, are being progressively deprecated in favor of the corresponding categories. which are more flexible, in particular with respect to multiple inheritance.

The class inheritance hierarchy is:

Subclasses of CommutativeRing are

Some aspects of this structure may seem strange, but this is an unfortunate consequence of the fact that Cython classes do not support multiple inheritance.

(A distinct but equally awkward issue is that sometimes we may not know in advance whether or not a ring belongs in one of these classes; e.g. some orders in number fields are Dedekind domains, but others are not, and we still want to offer a unified interface, so orders are never instances of the deprecated DedekindDomain class.)

AUTHORS:

  • David Harvey (2006-10-16): changed CommutativeAlgebra to derive from CommutativeRing instead of from Algebra.

  • David Loeffler (2009-07-09): documentation fixes, added to reference manual.

  • Simon King (2011-03-29): Proper use of the category framework for rings.

  • Simon King (2011-05-20): Modify multiplication and _ideal_class_ to support ideals of non-commutative rings.

class sage.rings.ring.Algebra

Bases: Ring

class sage.rings.ring.CommutativeAlgebra

Bases: CommutativeRing

class sage.rings.ring.CommutativeRing

Bases: Ring

Generic commutative ring.

extension(poly, name=None, names=None, **kwds)

Algebraically extend self by taking the quotient self[x] / (f(x)).

INPUT:

  • poly – a polynomial whose coefficients are coercible into self

  • name – (optional) name for the root of \(f\)

Note

Using this method on an algebraically complete field does not return this field; the construction self[x] / (f(x)) is done anyway.

EXAMPLES:

sage: R = QQ['x']
sage: y = polygen(R)
sage: R.extension(y^2 - 5, 'a')                                             # needs sage.libs.pari
Univariate Quotient Polynomial Ring in a over
 Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5
>>> from sage.all import *
>>> R = QQ['x']
>>> y = polygen(R)
>>> R.extension(y**Integer(2) - Integer(5), 'a')                                             # needs sage.libs.pari
Univariate Quotient Polynomial Ring in a over
 Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5

sage: # needs sage.rings.finite_rings
sage: P.<x> = PolynomialRing(GF(5))
sage: F.<a> = GF(5).extension(x^2 - 2)
sage: P.<t> = F[]
sage: R.<b> = F.extension(t^2 - a); R
Univariate Quotient Polynomial Ring in b over
 Finite Field in a of size 5^2 with modulus b^2 + 4*a
>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> P = PolynomialRing(GF(Integer(5)), names=('x',)); (x,) = P._first_ngens(1)
>>> F = GF(Integer(5)).extension(x**Integer(2) - Integer(2), names=('a',)); (a,) = F._first_ngens(1)
>>> P = F['t']; (t,) = P._first_ngens(1)
>>> R = F.extension(t**Integer(2) - a, names=('b',)); (b,) = R._first_ngens(1); R
Univariate Quotient Polynomial Ring in b over
 Finite Field in a of size 5^2 with modulus b^2 + 4*a
fraction_field()

Return the fraction field of self.

EXAMPLES:

sage: R = Integers(389)['x,y']
sage: Frac(R)
Fraction Field of Multivariate Polynomial Ring in x, y over Ring of integers modulo 389
sage: R.fraction_field()
Fraction Field of Multivariate Polynomial Ring in x, y over Ring of integers modulo 389
>>> from sage.all import *
>>> R = Integers(Integer(389))['x,y']
>>> Frac(R)
Fraction Field of Multivariate Polynomial Ring in x, y over Ring of integers modulo 389
>>> R.fraction_field()
Fraction Field of Multivariate Polynomial Ring in x, y over Ring of integers modulo 389
class sage.rings.ring.DedekindDomain

Bases: CommutativeRing

class sage.rings.ring.Field

Bases: CommutativeRing

Generic field

class sage.rings.ring.IntegralDomain

Bases: CommutativeRing

class sage.rings.ring.NoetherianRing

Bases: CommutativeRing

class sage.rings.ring.PrincipalIdealDomain

Bases: CommutativeRing

class sage.rings.ring.Ring

Bases: ParentWithGens

Generic ring class.

base_extend(R)

EXAMPLES:

sage: QQ.base_extend(GF(7))
Traceback (most recent call last):
...
TypeError: no base extension defined
sage: ZZ.base_extend(GF(7))
Finite Field of size 7
>>> from sage.all import *
>>> QQ.base_extend(GF(Integer(7)))
Traceback (most recent call last):
...
TypeError: no base extension defined
>>> ZZ.base_extend(GF(Integer(7)))
Finite Field of size 7
category()

Return the category to which this ring belongs.

Note

This method exists because sometimes a ring is its own base ring. During initialisation of a ring \(R\), it may be checked whether the base ring (hence, the ring itself) is a ring. Hence, it is necessary that R.category() tells that R is a ring, even before its category is properly initialised.

EXAMPLES:

sage: FreeAlgebra(QQ, 3, 'x').category()  # todo: use a ring which is not an algebra!   # needs sage.combinat sage.modules
Category of algebras with basis over Rational Field
>>> from sage.all import *
>>> FreeAlgebra(QQ, Integer(3), 'x').category()  # todo: use a ring which is not an algebra!   # needs sage.combinat sage.modules
Category of algebras with basis over Rational Field

Since a quotient of the integers is its own base ring, and during initialisation of a ring it is tested whether the base ring belongs to the category of rings, the following is an indirect test that the category() method of rings returns the category of rings even before the initialisation was successful:

sage: I = Integers(15)
sage: I.base_ring() is I
True
sage: I.category()
Join of Category of finite commutative rings
    and Category of subquotients of monoids
    and Category of quotients of semigroups
    and Category of finite enumerated sets
>>> from sage.all import *
>>> I = Integers(Integer(15))
>>> I.base_ring() is I
True
>>> I.category()
Join of Category of finite commutative rings
    and Category of subquotients of monoids
    and Category of quotients of semigroups
    and Category of finite enumerated sets
one()

Return the one element of this ring (cached), if it exists.

EXAMPLES:

sage: ZZ.one()
1
sage: QQ.one()
1
sage: QQ['x'].one()
1
>>> from sage.all import *
>>> ZZ.one()
1
>>> QQ.one()
1
>>> QQ['x'].one()
1

The result is cached:

sage: ZZ.one() is ZZ.one()
True
>>> from sage.all import *
>>> ZZ.one() is ZZ.one()
True
order()

The number of elements of self.

EXAMPLES:

sage: GF(19).order()
19
sage: QQ.order()
+Infinity
>>> from sage.all import *
>>> GF(Integer(19)).order()
19
>>> QQ.order()
+Infinity
zero()

Return the zero element of this ring (cached).

EXAMPLES:

sage: ZZ.zero()
0
sage: QQ.zero()
0
sage: QQ['x'].zero()
0
>>> from sage.all import *
>>> ZZ.zero()
0
>>> QQ.zero()
0
>>> QQ['x'].zero()
0

The result is cached:

sage: ZZ.zero() is ZZ.zero()
True
>>> from sage.all import *
>>> ZZ.zero() is ZZ.zero()
True
sage.rings.ring.is_Ring(x)

Return True if x is a ring.

EXAMPLES:

sage: from sage.rings.ring import is_Ring
sage: is_Ring(ZZ)
doctest:warning...
DeprecationWarning: The function is_Ring is deprecated; use '... in Rings()' instead
See https://github.com/sagemath/sage/issues/38288 for details.
True
sage: MS = MatrixSpace(QQ, 2)                                                   # needs sage.modules
sage: is_Ring(MS)                                                               # needs sage.modules
True
>>> from sage.all import *
>>> from sage.rings.ring import is_Ring
>>> is_Ring(ZZ)
doctest:warning...
DeprecationWarning: The function is_Ring is deprecated; use '... in Rings()' instead
See https://github.com/sagemath/sage/issues/38288 for details.
True
>>> MS = MatrixSpace(QQ, Integer(2))                                                   # needs sage.modules
>>> is_Ring(MS)                                                               # needs sage.modules
True