Skip to content

Commit d86a6e6

Browse files
author
Release Manager
committed
gh-40328: get rid of some "is_commutative" methods, via the category framework Using the idea that, by default, a ring is not commutative unless it belongs to the category of CommutativeRings. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #40328 Reported by: Frédéric Chapoton Reviewer(s):
2 parents c78afba + 3c0d1cd commit d86a6e6

File tree

5 files changed

+50
-65
lines changed

5 files changed

+50
-65
lines changed

src/sage/algebras/clifford_algebra.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,28 @@ def __init__(self, Q, names, category=None):
528528
sage: ba = Cl.basis().keys()
529529
sage: all(FrozenBitset(format(i,'b')[::-1]) in ba for i in range(2**9))
530530
True
531+
532+
Check for the category::
533+
534+
sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])
535+
sage: Cl.<x,y,z> = CliffordAlgebra(Q)
536+
sage: Cl.is_commutative()
537+
False
538+
sage: Q = QuadraticForm(ZZ, 1, [1])
539+
sage: Cl.<x> = CliffordAlgebra(Q)
540+
sage: Cl.is_commutative()
541+
True
531542
"""
532543
self._quadratic_form = Q
533544
R = Q.base_ring()
534545
category = AlgebrasWithBasis(R.category()).Super().Filtered().FiniteDimensional().or_subcategory(category)
546+
547+
if self._quadratic_form.dim() < 2:
548+
category = category.Commutative()
549+
535550
indices = CliffordAlgebraIndices(Q.dim())
536-
CombinatorialFreeModule.__init__(self, R, indices, category=category, sorting_key=tuple)
551+
CombinatorialFreeModule.__init__(self, R, indices, category=category,
552+
sorting_key=tuple)
537553
self._assign_names(names)
538554

539555
def _repr_(self):
@@ -844,19 +860,6 @@ def one_basis(self):
844860
"""
845861
return FrozenBitset()
846862

847-
def is_commutative(self) -> bool:
848-
"""
849-
Check if ``self`` is a commutative algebra.
850-
851-
EXAMPLES::
852-
853-
sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])
854-
sage: Cl.<x,y,z> = CliffordAlgebra(Q)
855-
sage: Cl.is_commutative()
856-
False
857-
"""
858-
return self._quadratic_form.dim() < 2
859-
860863
def quadratic_form(self):
861864
"""
862865
Return the quadratic form of ``self``.

src/sage/algebras/iwahori_hecke_algebra.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ def __init__(self, W, q1, q2, base_ring):
459459
sage: R.<q1,q2> = QQ[]
460460
sage: H = IwahoriHeckeAlgebra("A2", q1, q2=q2, base_ring=Frac(R))
461461
sage: TestSuite(H).run()
462+
463+
TESTS::
464+
465+
sage: T = IwahoriHeckeAlgebra("B2", 1).T()
466+
sage: T.is_commutative()
467+
False
468+
sage: T = IwahoriHeckeAlgebra("A1", 1).T()
469+
sage: T.is_commutative()
470+
True
462471
"""
463472
self._W = W
464473
self._coxeter_type = W.coxeter_type()
@@ -499,7 +508,12 @@ def __init__(self, W, q1, q2, base_ring):
499508
self._category = FiniteDimensionalAlgebrasWithBasis(base_ring)
500509
else:
501510
self._category = AlgebrasWithBasis(base_ring)
502-
Parent.__init__(self, base=base_ring, category=self._category.WithRealizations())
511+
512+
if base_ring.is_commutative() and W.is_commutative():
513+
self._category = self._category.Commutative()
514+
515+
Parent.__init__(self, base=base_ring,
516+
category=self._category.WithRealizations())
503517

504518
self._is_generic = False # needed for initialisation of _KLHeckeBasis
505519

@@ -767,19 +781,6 @@ def is_field(self, proof=True):
767781
"""
768782
return False
769783

770-
def is_commutative(self) -> bool:
771-
"""
772-
Return whether this Iwahori-Hecke algebra is commutative.
773-
774-
EXAMPLES::
775-
776-
sage: T = IwahoriHeckeAlgebra("B2", 1).T()
777-
sage: T.is_commutative()
778-
False
779-
"""
780-
return self.base_ring().is_commutative() \
781-
and self.realization_of().coxeter_group().is_commutative()
782-
783784
@cached_method
784785
def one_basis(self):
785786
r"""

src/sage/algebras/quatalg/quaternion_algebra.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -560,19 +560,6 @@ def inner_product_matrix(self):
560560
M.set_immutable()
561561
return M
562562

563-
def is_commutative(self) -> bool:
564-
"""
565-
Return ``False`` always, since all quaternion algebras are
566-
noncommutative.
567-
568-
EXAMPLES::
569-
570-
sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3,-7)
571-
sage: Q.is_commutative()
572-
False
573-
"""
574-
return False
575-
576563
def is_division_algebra(self) -> bool:
577564
"""
578565
Check whether this quaternion algebra is a division algebra,
@@ -871,6 +858,12 @@ def __init__(self, base_ring, a, b, names='i,j,k'):
871858
Traceback (most recent call last):
872859
...
873860
ValueError: 2 is not invertible in Integer Ring
861+
862+
Check for category::
863+
864+
sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3,-7)
865+
sage: Q.is_commutative()
866+
False
874867
"""
875868
cat = Algebras(base_ring).Division().FiniteDimensional()
876869
Parent.__init__(self, base=base_ring, names=names, category=cat)

src/sage/combinat/chas/wqsym.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,14 @@ def __init__(self, R):
471471
472472
sage: A = algebras.WQSym(QQ)
473473
sage: TestSuite(A).run() # long time
474+
475+
sage: M = algebras.WQSym(ZZ).M()
476+
sage: M.is_commutative()
477+
False
474478
"""
475479
category = HopfAlgebras(R).Graded().Connected()
480+
if R.is_zero():
481+
category = category.Commutative()
476482
Parent.__init__(self, base=R, category=category.WithRealizations())
477483

478484
def _repr_(self):
@@ -2041,18 +2047,6 @@ def is_field(self, proof=True):
20412047
"""
20422048
return False
20432049

2044-
def is_commutative(self):
2045-
"""
2046-
Return whether ``self`` is commutative.
2047-
2048-
EXAMPLES::
2049-
2050-
sage: M = algebras.WQSym(ZZ).M()
2051-
sage: M.is_commutative()
2052-
False
2053-
"""
2054-
return self.base_ring().is_zero()
2055-
20562050
def one_basis(self):
20572051
"""
20582052
Return the index of the unit.

src/sage/combinat/fqsym.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,14 @@ def __init__(self, R):
363363
364364
sage: F = algebras.FQSym(QQ)
365365
sage: TestSuite(F).run() # long time (3s)
366+
367+
sage: F = algebras.FQSym(ZZ).F()
368+
sage: F.is_commutative()
369+
False
366370
"""
367371
category = HopfAlgebras(R).Graded().Connected()
372+
if R.is_zero():
373+
category = category.Commutative()
368374
Parent.__init__(self, base=R, category=category.WithRealizations())
369375

370376
# Bases
@@ -1350,18 +1356,6 @@ def is_field(self, proof=True):
13501356
"""
13511357
return False
13521358

1353-
def is_commutative(self):
1354-
"""
1355-
Return whether this `FQSym` is commutative.
1356-
1357-
EXAMPLES::
1358-
1359-
sage: F = algebras.FQSym(ZZ).F()
1360-
sage: F.is_commutative()
1361-
False
1362-
"""
1363-
return self.base_ring().is_zero()
1364-
13651359
def some_elements(self):
13661360
"""
13671361
Return some elements of the free quasi-symmetric functions.

0 commit comments

Comments
 (0)