Skip to content

Commit 16353f6

Browse files
committed
avoid Algebra in polynomials and move is_commutative
1 parent 30b3d78 commit 16353f6

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

src/sage/categories/commutative_rings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ class CommutativeRings(CategoryWithAxiom):
4747
4848
"""
4949
class ParentMethods:
50+
def is_commutative(self) -> bool:
51+
"""
52+
Return whether the ring is commutative.
53+
54+
The answer is ``True`` only if the category is a sub-category of
55+
``CommutativeRings``.
56+
57+
It is recommended to use instead ``R in Rings().Commutative()``.
58+
59+
EXAMPLES::
60+
61+
sage: QQ.is_commutative()
62+
True
63+
sage: QQ['x,y,z'].is_commutative()
64+
True
65+
"""
66+
return True
67+
5068
def _test_divides(self, **options):
5169
r"""
5270
Run generic tests on the method :meth:`divides`.

src/sage/categories/rings.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@ def is_ring(self) -> bool:
322322
"""
323323
return True
324324

325+
def is_commutative(self) -> bool:
326+
"""
327+
Return whether the ring is commutative.
328+
329+
The answer is ``True`` only if the category is a sub-category of
330+
``CommutativeRings``.
331+
332+
It is recommended to use instead ``R in Rings().Commutative()``.
333+
334+
EXAMPLES::
335+
336+
sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -1, -1) # needs sage.combinat sage.modules
337+
sage: Q.is_commutative() # needs sage.combinat sage.modules
338+
False
339+
"""
340+
return False
341+
325342
def is_zero(self) -> bool:
326343
"""
327344
Return ``True`` if this is the zero ring.

src/sage/rings/polynomial/polynomial_ring.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@
130130
131131
"""
132132

133-
#*****************************************************************************
133+
# ****************************************************************************
134134
# Copyright (C) 2006 William Stein <[email protected]>
135135
#
136136
# This program is free software: you can redistribute it and/or modify
137137
# it under the terms of the GNU General Public License as published by
138138
# the Free Software Foundation, either version 2 of the License, or
139139
# (at your option) any later version.
140-
# http://www.gnu.org/licenses/
141-
#*****************************************************************************
140+
# https://www.gnu.org/licenses/
141+
# ****************************************************************************
142142

143143

144144
import sys
@@ -148,7 +148,7 @@
148148
import sage.categories as categories
149149
from sage.categories.morphism import IdentityMorphism
150150

151-
from sage.rings.ring import (Algebra, CommutativeAlgebra, IntegralDomain,
151+
from sage.rings.ring import (Ring, IntegralDomain,
152152
PrincipalIdealDomain, is_Ring)
153153
from sage.structure.element import is_RingElement
154154
import sage.rings.rational_field as rational_field
@@ -226,7 +226,7 @@ def is_PolynomialRing(x):
226226

227227
#########################################################################################
228228

229-
class PolynomialRing_general(Algebra):
229+
class PolynomialRing_general(Ring):
230230
"""
231231
Univariate polynomial ring over a ring.
232232
"""
@@ -303,7 +303,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None,
303303
self.Element = self._polynomial_class
304304
self.__cyclopoly_cache = {}
305305
self._has_singular = False
306-
Algebra.__init__(self, base_ring, names=name, normalize=True, category=category)
306+
Ring.__init__(self, base_ring, names=name, normalize=True, category=category)
307307
self._populate_coercion_lists_(convert_method_name='_polynomial_')
308308

309309
def __reduce__(self):
@@ -1709,7 +1709,7 @@ def monics( self, of_degree=None, max_degree=None ):
17091709
raise ValueError("you should pass exactly one of of_degree and max_degree")
17101710

17111711

1712-
class PolynomialRing_commutative(PolynomialRing_general, CommutativeAlgebra):
1712+
class PolynomialRing_commutative(PolynomialRing_general):
17131713
"""
17141714
Univariate polynomial ring over a commutative ring.
17151715
"""

src/sage/rings/ring.pyx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -686,24 +686,6 @@ cdef class Ring(ParentWithGens):
686686
return x
687687
return self._one_element
688688

689-
def is_commutative(self):
690-
"""
691-
Return ``True`` if this ring is commutative.
692-
693-
EXAMPLES::
694-
695-
sage: QQ.is_commutative()
696-
True
697-
sage: QQ['x,y,z'].is_commutative()
698-
True
699-
sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -1, -1) # needs sage.combinat sage.modules
700-
sage: Q.is_commutative() # needs sage.combinat sage.modules
701-
False
702-
"""
703-
if self.is_zero():
704-
return True
705-
raise NotImplementedError
706-
707689
def is_field(self, proof = True):
708690
"""
709691
Return ``True`` if this ring is a field.

0 commit comments

Comments
 (0)