Skip to content

Commit

Permalink
let the categories handle "is_commutative" for rings
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Jan 9, 2025
1 parent 1be0a58 commit f6d8ca8
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/sage/algebras/clifford_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def one_basis(self):
"""
return FrozenBitset()

def is_commutative(self):
def is_commutative(self) -> bool:
"""
Check if ``self`` is a commutative algebra.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def is_associative(self):
return True

@cached_method
def is_commutative(self):
def is_commutative(self) -> bool:
"""
Return ``True`` if ``self`` is commutative.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/algebras/iwahori_hecke_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def is_field(self, proof=True):
"""
return False

def is_commutative(self):
def is_commutative(self) -> bool:
"""
Return whether this Iwahori-Hecke algebra is commutative.
Expand Down
6 changes: 4 additions & 2 deletions src/sage/algebras/steenrod/steenrod_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2827,10 +2827,12 @@ def gen(self, i=0):
tot += 1
return test

def is_commutative(self):
def is_commutative(self) -> bool:
r"""
Return ``True`` if ``self`` is graded commutative, as determined by the
profile function. In particular, a sub-Hopf algebra of the
profile function.
In particular, a sub-Hopf algebra of the
mod 2 Steenrod algebra is commutative if and only if there is
an integer `n>0` so that its profile function `e` satisfies
Expand Down
11 changes: 11 additions & 0 deletions src/sage/categories/commutative_rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ class CommutativeRings(CategoryWithAxiom):
sage: GroupAlgebra(CyclicPermutationGroup(3), QQ) in CommutativeRings() # not implemented, needs sage.groups sage.modules
True
Some tests for the method ``is_commutative``::
sage: QQ.is_commutative()
True
sage: ZpCA(7).is_commutative() # needs sage.rings.padics
True
sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A # needs sage.combinat sage.modules
Quaternion Algebra (-1, -3) with base ring Rational Field
sage: A.is_commutative() # needs sage.combinat sage.modules
False
"""
class ParentMethods:
def is_commutative(self) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/finite_dimensional_algebras_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ def is_identity_decomposition_into_orthogonal_idempotents(self, l):
for f in l[:i]))

@cached_method
def is_commutative(self):
def is_commutative(self) -> bool:
"""
Return whether ``self`` is a commutative algebra.
Expand All @@ -1158,7 +1158,7 @@ def is_commutative(self):
True
"""
B = list(self.basis())
try: # See if 1 is a basis element, if so, remove it
try: # See if 1 is a basis element, if so, remove it
B.remove(self.one())
except ValueError:
pass
Expand Down
7 changes: 4 additions & 3 deletions src/sage/categories/lie_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,11 @@ def is_abelian(self):
zero = self.zero()
return all(x._bracket_(y) == zero for x in G for y in G)

def is_commutative(self):
def is_commutative(self) -> bool:
"""
Return if ``self`` is commutative. This is equivalent to ``self``
being abelian.
Return if ``self`` is commutative.
This is equivalent to ``self`` being abelian.
EXAMPLES::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/magmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def is_field(self, proof=True):
class Commutative(CategoryWithAxiom):

class ParentMethods:
def is_commutative(self):
def is_commutative(self) -> bool:
"""
Return ``True``, since commutative magmas are commutative.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/quotient_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def _latex_(self):
"""
return "%s/%s" % (latex.latex(self.cover_ring()), latex.latex(self.defining_ideal()))

def is_commutative(self):
def is_commutative(self) -> bool:
"""
Tell whether this quotient ring is commutative.
Expand Down
3 changes: 2 additions & 1 deletion src/sage/rings/real_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField):
sage: TestSuite(R).run()
"""
from sage.categories.fields import Fields
Field.__init__(self, self, category=Fields().Infinite().Metric().Complete())
Field.__init__(self, self,
category=Fields().Infinite().Metric().Complete())
self._populate_coercion_lists_(init_no_parent=True,
convert_method_name='_real_double_')

Expand Down
23 changes: 2 additions & 21 deletions src/sage/rings/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,9 @@ cdef class CommutativeRing(Ring):
sage: Integers(389)['x,y']
Multivariate Polynomial Ring in x, y over Ring of integers modulo 389
"""
try:
if not base_ring.is_commutative():
raise TypeError("base ring %s is no commutative ring" % base_ring)
except AttributeError:
if base_ring is not self and base_ring not in _CommutativeRings:
raise TypeError("base ring %s is no commutative ring" % base_ring)

# This is a low-level class. For performance, we trust that
# the category is fine, if it is provided. If it isn't, we use
# the category of commutative rings.
Expand Down Expand Up @@ -830,23 +828,6 @@ cdef class CommutativeRing(Ring):
except (NotImplementedError,TypeError):
return coercion_model.division_parent(self)

def is_commutative(self):
"""
Return ``True``, since this ring is commutative.
EXAMPLES::
sage: QQ.is_commutative()
True
sage: ZpCA(7).is_commutative() # needs sage.rings.padics
True
sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A # needs sage.combinat sage.modules
Quaternion Algebra (-1, -3) with base ring Rational Field
sage: A.is_commutative() # needs sage.combinat sage.modules
False
"""
return True

def krull_dimension(self):
"""
Return the Krull dimension of this commutative ring.
Expand Down

0 comments on commit f6d8ca8

Please sign in to comment.