Skip to content

Commit 85e1310

Browse files
committed
less usage of method .is_commutative
1 parent 30b3d78 commit 85e1310

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

src/sage/combinat/descent_algebra.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from sage.structure.parent import Parent
2020
from sage.structure.unique_representation import UniqueRepresentation
2121
from sage.categories.algebras import Algebras
22+
from sage.categories.commutative_rings import CommutativeRings
2223
from sage.categories.realizations import Realizations, Category_realization_of_parent
2324
from sage.categories.finite_dimensional_algebras_with_basis import FiniteDimensionalAlgebrasWithBasis
2425
from sage.rings.integer_ring import ZZ
@@ -929,7 +930,7 @@ def is_field(self, proof=True):
929930
return self.base_ring().is_field()
930931
return False
931932

932-
def is_commutative(self):
933+
def is_commutative(self) -> bool:
933934
"""
934935
Return whether this descent algebra is commutative.
935936
@@ -942,8 +943,8 @@ def is_commutative(self):
942943
sage: B.is_commutative()
943944
True
944945
"""
945-
return self.base_ring().is_commutative() \
946-
and self.realization_of()._n <= 2
946+
return (self.base_ring() in CommutativeRings()
947+
and self.realization_of()._n <= 2)
947948

948949
@lazy_attribute
949950
def to_symmetric_group_algebra(self):

src/sage/combinat/sf/sfa.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
from sage.rings.polynomial.polynomial_element import Polynomial
222222
from sage.rings.polynomial.multi_polynomial import MPolynomial
223223
from sage.combinat.partition import _Partitions, Partitions, Partitions_n, Partition
224+
from sage.categories.commutative_rings import CommutativeRings
224225
from sage.categories.hopf_algebras import HopfAlgebras
225226
from sage.categories.hopf_algebras_with_basis import HopfAlgebrasWithBasis
226227
from sage.categories.principal_ideal_domains import PrincipalIdealDomains
@@ -428,7 +429,7 @@ def is_field(self, proof=True):
428429
"""
429430
return False
430431

431-
def is_commutative(self):
432+
def is_commutative(self) -> bool:
432433
"""
433434
Return whether this symmetric function algebra is commutative.
434435
@@ -442,7 +443,7 @@ def is_commutative(self):
442443
sage: s.is_commutative()
443444
True
444445
"""
445-
return self.base_ring().is_commutative()
446+
return self.base_ring() in CommutativeRings()
446447

447448
def _repr_(self):
448449
"""
@@ -1050,7 +1051,7 @@ def component(i, g): # == h_g[L_i]
10501051
corresponding_result = corresponding_parent_over_QQ.gessel_reutenauer(lam)
10511052
comp_base_ring = comp_parent.base_ring()
10521053
result = comp_parent.sum_of_terms((nu, comp_base_ring(c))
1053-
for nu, c in corresponding_result)
1054+
for nu, c in corresponding_result)
10541055
return self(result) # just in case comp_parent != self.
10551056

10561057
higher_lie_character = gessel_reutenauer
@@ -1187,8 +1188,8 @@ def lehrer_solomon(self, lam):
11871188

11881189
def component(i, g): # == h_g[L_i] or e_g[L_i]
11891190
L_i = p.sum_of_terms(((_Partitions([d] * (i//d)), R(mu(d)))
1190-
for d in squarefree_divisors(i)),
1191-
distinct=True) / i
1191+
for d in squarefree_divisors(i)),
1192+
distinct=True) / i
11921193
if not i % 2:
11931194
return p(e[g]).plethysm(L_i.omega())
11941195
else:
@@ -1221,7 +1222,7 @@ def component(i, g): # == h_g[L_i] or e_g[L_i]
12211222
corresponding_result = corresponding_parent_over_QQ.lehrer_solomon(lam)
12221223
comp_base_ring = comp_parent.base_ring()
12231224
result = comp_parent.sum_of_terms((nu, comp_base_ring(c))
1224-
for nu, c in corresponding_result)
1225+
for nu, c in corresponding_result)
12251226
return self(result) # just in case comp_parent != self.
12261227

12271228
whitney_homology_character = lehrer_solomon
@@ -1765,11 +1766,11 @@ def is_unit(self):
17651766
return len(m) <= 1 and self.coefficient([]).is_unit()
17661767

17671768

1768-
#SymmetricFunctionsBases.Filtered = FilteredSymmetricFunctionsBases
1769-
#SymmetricFunctionsBases.Graded = GradedSymmetricFunctionsBases
1769+
# SymmetricFunctionsBases.Filtered = FilteredSymmetricFunctionsBases
1770+
# SymmetricFunctionsBases.Graded = GradedSymmetricFunctionsBases
17701771

17711772
#####################################################################
1772-
## ABC for bases of the symmetric functions
1773+
# ABC for bases of the symmetric functions
17731774

17741775
class SymmetricFunctionAlgebra_generic(CombinatorialFreeModule):
17751776
r"""
@@ -5885,7 +5886,7 @@ def hl_creation_operator(self, nu, t=None):
58855886
elif isinstance(nu, list) and all(isinstance(a, (int,Integer)) for a in nu):
58865887
return P(s.sum(t**la.size() * c * d * s(la) *
58875888
s._repeated_bernstein_creation_operator_on_basis(ga, nu)
5888-
for ((la,mu),c) in s(self).coproduct()
5889+
for ((la, mu), c) in s(self).coproduct()
58895890
for (ga, d) in s(mu).plethysm((1-t)*s[1]) ))
58905891
else:
58915892
raise ValueError("nu must be a list of integers")

src/sage/modules/free_module.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@
186186
import sage.rings.integer
187187
import sage.rings.integer_ring
188188
import sage.rings.rational_field
189-
from sage.rings.ring import IntegralDomain, is_Ring
189+
from sage.rings.ring import IntegralDomain
190+
from sage.categories.commutative_rings import CommutativeRings
190191
from sage.categories.fields import Fields
191192
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
192193
from sage.categories.integral_domains import IntegralDomains
@@ -266,16 +267,16 @@ def create_object(self, version, key):
266267
from sage.modules.free_quadratic_module import FreeQuadraticModule
267268
return FreeQuadraticModule(base_ring, rank, inner_product_matrix=inner_product_matrix, sparse=sparse)
268269

269-
if not isinstance(sparse,bool):
270+
if not isinstance(sparse, bool):
270271
raise TypeError("Argument sparse (= %s) must be True or False" % sparse)
271272

272-
if not (hasattr(base_ring,'is_commutative') and base_ring.is_commutative()):
273+
if base_ring not in CommutativeRings():
273274
warn("You are constructing a free module\n"
274275
"over a noncommutative ring. Sage does not have a concept\n"
275276
"of left/right and both sided modules, so be careful.\n"
276277
"It's also not guaranteed that all multiplications are\n"
277278
"done from the right side.")
278-
#raise TypeError, "The base_ring must be a commutative ring."
279+
# raise TypeError("The base_ring must be a commutative ring.")
279280

280281
if not sparse and isinstance(base_ring, sage.rings.abc.RealDoubleField):
281282
return RealDoubleVectorSpace_class(rank)
@@ -727,7 +728,7 @@ def span(gens, base_ring=None, check=True, already_echelonized=False):
727728
TypeError: generators must be lists of ring elements
728729
or free module elements!
729730
"""
730-
if is_Ring(gens):
731+
if gens in CommutativeRings():
731732
# we allow the old input format with first input the base_ring.
732733
# Do we want to deprecate it?..
733734
base_ring, gens = gens, base_ring
@@ -1966,7 +1967,7 @@ def __init__(self, base_ring, rank, degree, sparse=False,
19661967
<class 'sage.modules.free_module_element.FreeModuleElement_generic_sparse'>
19671968
19681969
"""
1969-
if not base_ring.is_commutative():
1970+
if base_ring not in CommutativeRings():
19701971
warn("You are constructing a free module\n"
19711972
"over a noncommutative ring. Sage does not have a concept\n"
19721973
"of left/right and both sided modules, so be careful.\n"

src/sage/modules/free_quadratic_module.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@
6767
# ****************************************************************************
6868
import weakref
6969

70-
import sage.matrix.matrix_space
71-
import sage.misc.latex as latex
72-
from sage.rings.ring import Field, IntegralDomain
70+
from sage.categories.commutative_rings import CommutativeRings
7371
from sage.categories.principal_ideal_domains import PrincipalIdealDomains
7472
from sage.modules import free_module
73+
from sage.rings.ring import Field, IntegralDomain
74+
import sage.matrix.matrix_space
75+
import sage.misc.latex as latex
7576

7677
# #############################################################################
7778
#
@@ -157,7 +158,7 @@ def FreeQuadraticModule(base_ring, rank, inner_product_matrix,
157158
if M is not None:
158159
return M
159160

160-
if not base_ring.is_commutative():
161+
if base_ring not in CommutativeRings():
161162
raise TypeError("base_ring must be a commutative ring")
162163

163164
# elif not sparse and isinstance(base_ring,sage.rings.real_double.RealDoubleField_class):

0 commit comments

Comments
 (0)