Skip to content

Commit 2416d61

Browse files
author
Release Manager
committed
gh-37302: use Parent instead of Algebra in finite_gca This is removing one usage of the auld-class `Algebra` in the modified file Also changing a few minor details in doc and code there, and sorting the imports. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #37302 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 2e9c575 + e018ff4 commit 2416d61

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

src/sage/algebras/finite_gca.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
# https://www.gnu.org/licenses/
1818
# ****************************************************************************
1919
from __future__ import annotations
20-
from sage.combinat.free_module import CombinatorialFreeModule
20+
2121
from sage.categories.algebras import Algebras
22-
from sage.misc.cachefunc import cached_method
22+
from sage.combinat.free_module import CombinatorialFreeModule
2323
from sage.combinat.integer_vector_weighted import WeightedIntegerVectors
24-
from sage.rings.ring import Algebra
25-
from sage.misc.functional import is_odd, is_even
26-
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
27-
from sage.sets.condition_set import ConditionSet
24+
from sage.misc.cachefunc import cached_method
25+
from sage.misc.functional import is_even
2826
from sage.rings.integer_ring import ZZ
27+
from sage.sets.condition_set import ConditionSet
28+
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
2929

3030

31-
class FiniteGCAlgebra(CombinatorialFreeModule, Algebra):
31+
class FiniteGCAlgebra(CombinatorialFreeModule):
3232
r"""
3333
Finite dimensional graded commutative algebras.
3434
@@ -165,7 +165,7 @@ def __classcall_private__(cls, base, names=None, degrees=None,
165165
raise ValueError("You must specify names or degrees")
166166
else:
167167
n = len(degrees)
168-
names = tuple('x{}'.format(i) for i in range(n))
168+
names = tuple(f'x{i}' for i in range(n))
169169
elif isinstance(names, str):
170170
names = tuple(names.split(','))
171171
n = len(names)
@@ -194,7 +194,6 @@ def __init__(self, base, names, degrees, max_degree,
194194
sage: TestSuite(A).run()
195195
sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z','t'), [1,2,3,4], max_degree=10)
196196
sage: TestSuite(A).run()
197-
198197
"""
199198
from sage.arith.misc import gcd
200199

@@ -220,7 +219,7 @@ def __init__(self, base, names, degrees, max_degree,
220219
sorting_key=sorting_key,
221220
category=category)
222221

223-
def _valid_index(self, w):
222+
def _valid_index(self, w) -> bool:
224223
r"""
225224
Return whether ``w`` is a valid index; no multiple powers in odd
226225
degrees.
@@ -234,11 +233,10 @@ def _valid_index(self, w):
234233
True
235234
sage: A._valid_index(w2)
236235
False
237-
238236
"""
239-
return not any(i > 1 for i, d in zip(w, self._degrees) if is_odd(d))
237+
return not any(i > 1 for i, d in zip(w, self._degrees) if d % 2)
240238

241-
def _repr_(self):
239+
def _repr_(self) -> str:
242240
"""
243241
Return the string representation of ``self``.
244242
@@ -249,7 +247,6 @@ def _repr_(self):
249247
"Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8"
250248
sage: A # indirect doctest
251249
Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8
252-
253250
"""
254251
desc = f'Graded commutative algebra with generators {self._names} in '
255252
desc += f'degrees {self._degrees} with maximal degree {self._max_deg}'
@@ -264,7 +261,6 @@ def ngens(self):
264261
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
265262
sage: A.ngens()
266263
3
267-
268264
"""
269265
return self.__ngens
270266

@@ -327,7 +323,6 @@ def product_on_basis(self, w1, w2):
327323
x*y^2*z
328324
sage: A.product_on_basis(w2, w1)
329325
-x*y^2*z
330-
331326
"""
332327
grading = self._weighted_vectors.grading
333328
deg_left = grading(w1)
@@ -375,11 +370,10 @@ def degree_on_basis(self, i):
375370
sage: i = A._weighted_vectors([1,1,0])
376371
sage: A.degree_on_basis(i)
377372
6
378-
379373
"""
380374
return self._weighted_vectors.grading(i)
381375

382-
def _repr_term(self, w):
376+
def _repr_term(self, w) -> str:
383377
r"""
384378
Return the string representation of basis with index ``w``.
385379
@@ -400,7 +394,6 @@ def _repr_term(self, w):
400394
'x⌣y^2⌣z'
401395
sage: x*y^2*z # indirect doctest
402396
x⌣y^2⌣z
403-
404397
"""
405398
# Trivial case:
406399
if sum(w) == 0:
@@ -416,7 +409,7 @@ def _repr_term(self, w):
416409
terms.append(self._names[i] + f'^{w[i]}')
417410
return self._mul_symbol.join(terms)
418411

419-
def _latex_term(self, w):
412+
def _latex_term(self, w) -> str:
420413
r"""
421414
Return the LaTeX representation of basis with index ``w``.
422415
@@ -436,7 +429,6 @@ def _latex_term(self, w):
436429
'x\\smile y^{2}\\smile z'
437430
sage: latex(x*y^2*z) # indirect doctest
438431
x\smile y^{2}\smile z
439-
440432
"""
441433
# Trivial case:
442434
if sum(w) == 0:
@@ -463,10 +455,8 @@ def algebra_generators(self):
463455
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
464456
sage: A.algebra_generators()
465457
Family (x, y, z)
466-
467458
"""
468459
from sage.sets.family import Family
469-
470460
return Family(self.gens())
471461

472462
@cached_method
@@ -483,7 +473,6 @@ def one_basis(self):
483473
1
484474
sage: A.one() # indirect doctest
485475
1
486-
487476
"""
488477
n = len(self._degrees)
489478
return self._weighted_vectors([0 for _ in range(n)])
@@ -521,7 +510,6 @@ def gen(self, i):
521510
y
522511
sage: A.gen(2)
523512
z
524-
525513
"""
526514
return self.gens()[i]
527515

@@ -534,7 +522,6 @@ def maximal_degree(self):
534522
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)
535523
sage: A.maximal_degree()
536524
8
537-
538525
"""
539526
return self._max_deg
540527

0 commit comments

Comments
 (0)