Skip to content

Commit 68db8f4

Browse files
committed
use Parent instead of Algebra in finite_gca
1 parent 0c390a0 commit 68db8f4

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

src/sage/algebras/finite_gca.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
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
29+
from sage.structure.parent import Parent
2930

3031

31-
class FiniteGCAlgebra(CombinatorialFreeModule, Algebra):
32+
class FiniteGCAlgebra(CombinatorialFreeModule, Parent):
3233
r"""
3334
Finite dimensional graded commutative algebras.
3435
@@ -165,7 +166,7 @@ def __classcall_private__(cls, base, names=None, degrees=None,
165166
raise ValueError("You must specify names or degrees")
166167
else:
167168
n = len(degrees)
168-
names = tuple('x{}'.format(i) for i in range(n))
169+
names = tuple(f'x{i}' for i in range(n))
169170
elif isinstance(names, str):
170171
names = tuple(names.split(','))
171172
n = len(names)
@@ -194,7 +195,6 @@ def __init__(self, base, names, degrees, max_degree,
194195
sage: TestSuite(A).run()
195196
sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z','t'), [1,2,3,4], max_degree=10)
196197
sage: TestSuite(A).run()
197-
198198
"""
199199
from sage.arith.misc import gcd
200200

@@ -220,7 +220,7 @@ def __init__(self, base, names, degrees, max_degree,
220220
sorting_key=sorting_key,
221221
category=category)
222222

223-
def _valid_index(self, w):
223+
def _valid_index(self, w) -> bool:
224224
r"""
225225
Return whether ``w`` is a valid index; no multiple powers in odd
226226
degrees.
@@ -234,11 +234,10 @@ def _valid_index(self, w):
234234
True
235235
sage: A._valid_index(w2)
236236
False
237-
238237
"""
239-
return not any(i > 1 for i, d in zip(w, self._degrees) if is_odd(d))
238+
return not any(i > 1 for i, d in zip(w, self._degrees) if d % 2)
240239

241-
def _repr_(self):
240+
def _repr_(self) -> str:
242241
"""
243242
Return the string representation of ``self``.
244243
@@ -249,7 +248,6 @@ def _repr_(self):
249248
"Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8"
250249
sage: A # indirect doctest
251250
Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8
252-
253251
"""
254252
desc = f'Graded commutative algebra with generators {self._names} in '
255253
desc += f'degrees {self._degrees} with maximal degree {self._max_deg}'
@@ -264,7 +262,6 @@ def ngens(self):
264262
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
265263
sage: A.ngens()
266264
3
267-
268265
"""
269266
return self.__ngens
270267

@@ -327,7 +324,6 @@ def product_on_basis(self, w1, w2):
327324
x*y^2*z
328325
sage: A.product_on_basis(w2, w1)
329326
-x*y^2*z
330-
331327
"""
332328
grading = self._weighted_vectors.grading
333329
deg_left = grading(w1)
@@ -375,11 +371,10 @@ def degree_on_basis(self, i):
375371
sage: i = A._weighted_vectors([1,1,0])
376372
sage: A.degree_on_basis(i)
377373
6
378-
379374
"""
380375
return self._weighted_vectors.grading(i)
381376

382-
def _repr_term(self, w):
377+
def _repr_term(self, w) -> str:
383378
r"""
384379
Return the string representation of basis with index ``w``.
385380
@@ -400,7 +395,6 @@ def _repr_term(self, w):
400395
'x⌣y^2⌣z'
401396
sage: x*y^2*z # indirect doctest
402397
x⌣y^2⌣z
403-
404398
"""
405399
# Trivial case:
406400
if sum(w) == 0:
@@ -416,7 +410,7 @@ def _repr_term(self, w):
416410
terms.append(self._names[i] + f'^{w[i]}')
417411
return self._mul_symbol.join(terms)
418412

419-
def _latex_term(self, w):
413+
def _latex_term(self, w) -> str:
420414
r"""
421415
Return the LaTeX representation of basis with index ``w``.
422416
@@ -436,7 +430,6 @@ def _latex_term(self, w):
436430
'x\\smile y^{2}\\smile z'
437431
sage: latex(x*y^2*z) # indirect doctest
438432
x\smile y^{2}\smile z
439-
440433
"""
441434
# Trivial case:
442435
if sum(w) == 0:
@@ -463,10 +456,8 @@ def algebra_generators(self):
463456
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
464457
sage: A.algebra_generators()
465458
Family (x, y, z)
466-
467459
"""
468460
from sage.sets.family import Family
469-
470461
return Family(self.gens())
471462

472463
@cached_method
@@ -483,7 +474,6 @@ def one_basis(self):
483474
1
484475
sage: A.one() # indirect doctest
485476
1
486-
487477
"""
488478
n = len(self._degrees)
489479
return self._weighted_vectors([0 for _ in range(n)])
@@ -521,7 +511,6 @@ def gen(self, i):
521511
y
522512
sage: A.gen(2)
523513
z
524-
525514
"""
526515
return self.gens()[i]
527516

@@ -534,7 +523,6 @@ def maximal_degree(self):
534523
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)
535524
sage: A.maximal_degree()
536525
8
537-
538526
"""
539527
return self._max_deg
540528

0 commit comments

Comments
 (0)