Rings#
- class sage.categories.rings.Rings(base_category)#
Bases:
CategoryWithAxiom_singleton
The category of rings
Associative rings with unit, not necessarily commutative
EXAMPLES:
sage: Rings() Category of rings sage: sorted(Rings().super_categories(), key=str) [Category of rngs, Category of semirings] sage: sorted(Rings().axioms()) ['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse', 'AdditiveUnital', 'Associative', 'Distributive', 'Unital'] sage: Rings() is (CommutativeAdditiveGroups() & Monoids()).Distributive() True sage: Rings() is Rngs().Unital() True sage: Rings() is Semirings().AdditiveInverse() True
Todo
(see github issue #sage_trac/wiki/CategoriesRoadMap)
Make Rings() into a subcategory or alias of Algebras(ZZ);
A parent P in the category
Rings()
should automatically be in the categoryAlgebras(P)
.
- Commutative#
alias of
CommutativeRings
- Division#
alias of
DivisionRings
- class ElementMethods#
Bases:
object
- inverse_of_unit()#
Return the inverse of this element if it is a unit.
OUTPUT:
An element in the same ring as this element.
EXAMPLES:
sage: R.<x> = ZZ[] sage: S = R.quo(x^2 + x + 1) # optional - sage.libs.pari sage: S(1).inverse_of_unit() # optional - sage.libs.pari 1
This method fails when the element is not a unit:
sage: 2.inverse_of_unit() Traceback (most recent call last): ... ArithmeticError: inverse does not exist
The inverse returned is in the same ring as this element:
sage: a = -1 sage: a.parent() Integer Ring sage: a.inverse_of_unit().parent() Integer Ring
Note that this is often not the case when computing inverses in other ways:
sage: (~a).parent() Rational Field sage: (1/a).parent() Rational Field
- is_unit()#
Return whether this element is a unit in the ring.
Note
This is a generic implementation for (non-commutative) rings which only works for the one element, its additive inverse, and the zero element. Most rings should provide a more specialized implementation.
EXAMPLES:
sage: MS = MatrixSpace(ZZ, 2) # optional - sage.modules sage: MS.one().is_unit() # optional - sage.modules True sage: MS.zero().is_unit() # optional - sage.modules False sage: MS([1,2,3,4]).is_unit() # optional - sage.modules False
- class MorphismMethods#
Bases:
object
- extend_to_fraction_field()#
Return the extension of this morphism to fraction fields of the domain and the codomain.
EXAMPLES:
sage: S.<x> = QQ[] sage: f = S.hom([x + 1]); f Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 sage: g = f.extend_to_fraction_field(); g # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x + 1 sage: g(x) # optional - sage.libs.singular x + 1 sage: g(1/x) # optional - sage.libs.singular 1/(x + 1)
If this morphism is not injective, it does not extend to the fraction field and an error is raised:
sage: f = GF(5).coerce_map_from(ZZ) # optional - sage.rings.finite_rings sage: f.extend_to_fraction_field() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the morphism is not injective
- is_injective()#
Return whether or not this morphism is injective.
EXAMPLES:
sage: R.<x,y> = QQ[] sage: R.hom([x, y^2], R).is_injective() # optional - sage.libs.singular True sage: R.hom([x, x^2], R).is_injective() # optional - sage.libs.singular False sage: S.<u,v> = R.quotient(x^3*y) # optional - sage.libs.singular sage: R.hom([v, u], S).is_injective() # optional - sage.libs.singular False sage: S.hom([-u, v], S).is_injective() # optional - sage.libs.singular True sage: S.cover().is_injective() # optional - sage.libs.singular False
If the domain is a field, the homomorphism is injective:
sage: K.<x> = FunctionField(QQ) sage: L.<y> = FunctionField(QQ) sage: f = K.hom([y]); f Function Field morphism: From: Rational function field in x over Rational Field To: Rational function field in y over Rational Field Defn: x |--> y sage: f.is_injective() True
Unless the codomain is the zero ring:
sage: codomain = Integers(1) sage: f = QQ.hom([Zmod(1)(0)], check=False) sage: f.is_injective() False
Homomorphism from rings of characteristic zero to rings of positive characteristic can not be injective:
sage: R.<x> = ZZ[] sage: f = R.hom([GF(3)(1)]); f # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 3 Defn: x |--> 1 sage: f.is_injective() # optional - sage.rings.finite_rings False
A morphism whose domain is an order in a number field is injective if the codomain has characteristic zero:
sage: K.<x> = FunctionField(QQ) sage: f = ZZ.hom(K); f Composite map: From: Integer Ring To: Rational function field in x over Rational Field Defn: Conversion via FractionFieldElement_1poly_field map: From: Integer Ring To: Fraction Field of Univariate Polynomial Ring in x over Rational Field then Isomorphism: From: Fraction Field of Univariate Polynomial Ring in x over Rational Field To: Rational function field in x over Rational Field sage: f.is_injective() True
A coercion to the fraction field is injective:
sage: R = ZpFM(3) # optional - sage.rings.padics sage: R.fraction_field().coerce_map_from(R).is_injective() # optional - sage.rings.padics True
- class ParentMethods#
Bases:
object
- bracket(x, y)#
Return the Lie bracket \([x, y] = x y - y x\) of \(x\) and \(y\).
INPUT:
x
,y
– elements ofself
EXAMPLES:
sage: F = AlgebrasWithBasis(QQ).example() # optional - sage.combinat sage.modules sage: F # optional - sage.combinat sage.modules An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field sage: a, b, c = F.algebra_generators() # optional - sage.combinat sage.modules sage: F.bracket(a, b) # optional - sage.combinat sage.modules B[word: ab] - B[word: ba]
This measures the default of commutation between \(x\) and \(y\). \(F\) endowed with the bracket operation is a Lie algebra; in particular, it satisfies Jacobi’s identity:
sage: (F.bracket(F.bracket(a,b), c) + F.bracket(F.bracket(b,c), a) # optional - sage.combinat sage.modules ....: + F.bracket(F.bracket(c,a), b)) 0
- characteristic()#
Return the characteristic of this ring.
EXAMPLES:
sage: QQ.characteristic() 0 sage: GF(19).characteristic() # optional - sage.rings.finite_rings 19 sage: Integers(8).characteristic() 8 sage: Zp(5).characteristic() # optional - sage.rings.padics 0
- free_module(base=None, basis=None, map=True)#
Return a free module \(V\) over the specified subring together with maps to and from \(V\).
The default implementation only supports the case that the base ring is the ring itself.
INPUT:
base
– a subring \(R\) so that this ring is isomorphic to a finite-rank free \(R\)-module \(V\)basis
– (optional) a basis for this ring over the basemap
– boolean (defaultTrue
), whether to return \(R\)-linear maps to and from \(V\)
OUTPUT:
A finite-rank free \(R\)-module \(V\)
An \(R\)-module isomorphism from \(V\) to this ring (only included if
map
isTrue
)An \(R\)-module isomorphism from this ring to \(V\) (only included if
map
isTrue
)
EXAMPLES:
sage: R.<x> = QQ[[]] sage: V, from_V, to_V = R.free_module(R) # optional - sage.modules sage: v = to_V(1 + x); v # optional - sage.modules (1 + x) sage: from_V(v) # optional - sage.modules 1 + x sage: W, from_W, to_W = R.free_module(R, basis=(1 - x)) # optional - sage.modules sage: W is V # optional - sage.modules True sage: w = to_W(1 + x); w # optional - sage.modules (1 - x^2) sage: from_W(w) # optional - sage.modules 1 + x + O(x^20)
- ideal(*args, **kwds)#
Create an ideal of this ring.
Note
The code is copied from the base class
Ring
. This is because there are rings that do not inherit from that class, such as matrix algebras. See github issue #7797.INPUT:
An element or a list/tuple/sequence of elements.
coerce
(optional bool, defaultTrue
): First coerce the elements into this ring.side
, optional string, one of"twosided"
(default),"left"
,"right"
: determines whether the resulting ideal is twosided, a left ideal or a right ideal.
EXAMPLES:
sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules sage: isinstance(MS, Ring) # optional - sage.modules False sage: MS in Rings() # optional - sage.modules True sage: MS.ideal(2) # optional - sage.modules Twosided Ideal ( [2 0] [0 2] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: MS.ideal([MS.0, MS.1], side='right') # optional - sage.modules Right Ideal ( [1 0] [0 0], [0 1] [0 0] ) of Full MatrixSpace of 2 by 2 dense matrices over Rational Field
- ideal_monoid()#
The monoid of the ideals of this ring.
Note
The code is copied from the base class of rings. This is since there are rings that do not inherit from that class, such as matrix algebras. See github issue #7797.
EXAMPLES:
sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules sage: isinstance(MS, Ring) # optional - sage.modules False sage: MS in Rings() # optional - sage.modules True sage: MS.ideal_monoid() # optional - sage.modules Monoid of ideals of Full MatrixSpace of 2 by 2 dense matrices over Rational Field
Note that the monoid is cached:
sage: MS.ideal_monoid() is MS.ideal_monoid() # optional - sage.modules True
- is_ring()#
Return
True
, since this in an object of the category of rings.EXAMPLES:
sage: Parent(QQ,category=Rings()).is_ring() True
- is_zero()#
Return
True
if this is the zero ring.EXAMPLES:
sage: Integers(1).is_zero() True sage: Integers(2).is_zero() False sage: QQ.is_zero() False sage: R.<x> = ZZ[] sage: R.quo(1).is_zero() True sage: R.<x> = GF(101)[] # optional - sage.rings.finite_rings sage: R.quo(77).is_zero() # optional - sage.rings.finite_rings True sage: R.quo(x^2 + 1).is_zero() # optional - sage.rings.finite_rings False
- quo(I, names=None, **kwds)#
Quotient of a ring by a two-sided ideal.
Note
This is a synonym for
quotient()
.EXAMPLES:
sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules sage: I = MS * MS.gens() * MS # optional - sage.modules
MS
is not an instance ofRing
.However it is an instance of the parent class of the category of rings. The quotient method is inherited from there:
sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules False sage: isinstance(MS, Rings().parent_class) # optional - sage.modules True sage: MS.quo(I, names=['a','b','c','d']) # optional - sage.modules Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal ( [1 0] [0 0], [0 1] [0 0], [0 0] [1 0], [0 0] [0 1] )
A test with a subclass of
Ring
:sage: R.<x,y> = PolynomialRing(QQ, 2) # optional - sage.libs.singular sage: S.<a,b> = R.quo((x^2, y)) # optional - sage.libs.singular sage: S # optional - sage.libs.singular Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) sage: S.gens() # optional - sage.libs.singular (a, 0) sage: a == b # optional - sage.libs.singular False
- quotient(I, names=None, **kwds)#
Quotient of a ring by a two-sided ideal.
INPUT:
I
– A twosided ideal of this ring.names
– (optional) names of the generators of the quotient (if there are multiple generators, you can specify a single character string and the generators are named in sequence starting with 0).further named arguments that may be passed to the quotient ring constructor.
EXAMPLES:
Usually, a ring inherits a method
sage.rings.ring.Ring.quotient()
. So, we need a bit of effort to make the following example work with the category framework:sage: F.<x,y,z> = FreeAlgebra(QQ) # optional - sage.combinat sage.modules sage: from sage.rings.noncommutative_ideals import Ideal_nc # optional - sage.combinat sage.modules sage: from itertools import product sage: class PowerIdeal(Ideal_nc): # optional - sage.combinat sage.modules ....: def __init__(self, R, n): ....: self._power = n ....: Ideal_nc.__init__(self, R, [R.prod(m) ....: for m in product(R.gens(), repeat=n)]) ....: def reduce(self, x): ....: R = self.ring() ....: return add([c*R(m) for m, c in x ....: if len(m) < self._power], R(0)) sage: I = PowerIdeal(F, 3) # optional - sage.combinat sage.modules sage: Q = Rings().parent_class.quotient(F, I); Q # optional - sage.combinat sage.modules Quotient of Free Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) sage: Q.0 # optional - sage.combinat sage.modules xbar sage: Q.1 # optional - sage.combinat sage.modules ybar sage: Q.2 # optional - sage.combinat sage.modules zbar sage: Q.0*Q.1 # optional - sage.combinat sage.modules xbar*ybar sage: Q.0*Q.1*Q.0 # optional - sage.combinat sage.modules 0
An example with polynomial rings:
sage: R.<x> = PolynomialRing(ZZ) sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: S = R.quotient(I, 'a') sage: S.gens() (a,) sage: R.<x,y> = PolynomialRing(QQ, 2) sage: S.<a,b> = R.quotient((x^2, y)) # optional - sage.libs.singular sage: S # optional - sage.libs.singular Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) sage: S.gens() # optional - sage.libs.singular (a, 0) sage: a == b # optional - sage.libs.singular False
- quotient_ring(I, names=None, **kwds)#
Quotient of a ring by a two-sided ideal.
Note
This is a synonym for
quotient()
.INPUT:
I
– an ideal of \(R\)names
– (optional) names of the generators of the quotient. (If there are multiple generators, you can specify a single character string and the generators are named in sequence starting with 0.)further named arguments that may be passed to the quotient ring constructor.
OUTPUT:
R/I
– the quotient ring of \(R\) by the ideal \(I\)
EXAMPLES:
sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules sage: I = MS * MS.gens() * MS # optional - sage.modules
MS
is not an instance ofRing
, but it is an instance of the parent class of the category of rings. The quotient method is inherited from there:sage: isinstance(MS, sage.rings.ring.Ring) # optional - sage.modules False sage: isinstance(MS, Rings().parent_class) # optional - sage.modules True sage: MS.quotient_ring(I, names=['a','b','c','d']) # optional - sage.modules Quotient of Full MatrixSpace of 2 by 2 dense matrices over Rational Field by the ideal ( [1 0] [0 0], [0 1] [0 0], [0 0] [1 0], [0 0] [0 1] )
A test with a subclass of
Ring
:sage: R.<x> = PolynomialRing(ZZ) sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: S = R.quotient_ring(I, 'a') sage: S.gens() (a,) sage: R.<x,y> = PolynomialRing(QQ,2) # optional - sage.libs.singular sage: S.<a,b> = R.quotient_ring((x^2, y)) # optional - sage.libs.singular sage: S # optional - sage.libs.singular Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y) sage: S.gens() # optional - sage.libs.singular (a, 0) sage: a == b # optional - sage.libs.singular False
- class SubcategoryMethods#
Bases:
object
- Division()#
Return the full subcategory of the division objects of
self
.A ring satisfies the division axiom if all non-zero elements have multiplicative inverses.
EXAMPLES:
sage: Rings().Division() Category of division rings sage: Rings().Commutative().Division() Category of fields
- NoZeroDivisors()#
Return the full subcategory of the objects of
self
having no nonzero zero divisors.A zero divisor in a ring \(R\) is an element \(x \in R\) such that there exists a nonzero element \(y \in R\) such that \(x \cdot y = 0\) or \(y \cdot x = 0\) (see Wikipedia article Zero_divisor).
EXAMPLES:
sage: Rings().NoZeroDivisors() Category of domains