diff --git a/src/sage/algebras/clifford_algebra.py b/src/sage/algebras/clifford_algebra.py index 92ad6c34d64..091f5e0d559 100644 --- a/src/sage/algebras/clifford_algebra.py +++ b/src/sage/algebras/clifford_algebra.py @@ -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. diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py index 3ba4bc658cb..66b3943b7d0 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py @@ -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. diff --git a/src/sage/algebras/iwahori_hecke_algebra.py b/src/sage/algebras/iwahori_hecke_algebra.py index 01390f1a5a4..ecc6788979b 100644 --- a/src/sage/algebras/iwahori_hecke_algebra.py +++ b/src/sage/algebras/iwahori_hecke_algebra.py @@ -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. diff --git a/src/sage/algebras/steenrod/steenrod_algebra.py b/src/sage/algebras/steenrod/steenrod_algebra.py index 540cb6ee92d..337e50f700c 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra.py +++ b/src/sage/algebras/steenrod/steenrod_algebra.py @@ -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 diff --git a/src/sage/categories/commutative_rings.py b/src/sage/categories/commutative_rings.py index 6c47efacfe0..f67990df978 100644 --- a/src/sage/categories/commutative_rings.py +++ b/src/sage/categories/commutative_rings.py @@ -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: diff --git a/src/sage/categories/finite_dimensional_algebras_with_basis.py b/src/sage/categories/finite_dimensional_algebras_with_basis.py index 187fe3d675a..20ec2f2747a 100644 --- a/src/sage/categories/finite_dimensional_algebras_with_basis.py +++ b/src/sage/categories/finite_dimensional_algebras_with_basis.py @@ -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. @@ -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 diff --git a/src/sage/categories/lie_algebras.py b/src/sage/categories/lie_algebras.py index f134cfded5b..3a3e1a7cd5b 100644 --- a/src/sage/categories/lie_algebras.py +++ b/src/sage/categories/lie_algebras.py @@ -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:: diff --git a/src/sage/categories/magmas.py b/src/sage/categories/magmas.py index ea491b2caf7..5bad4ffb775 100644 --- a/src/sage/categories/magmas.py +++ b/src/sage/categories/magmas.py @@ -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. diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 7e3dd8c6d53..ad36ef60eb1 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -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. diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 129603749d3..5efa0c87b65 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -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_') diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index 0891853efba..2cf3f40b99f 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -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. @@ -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.