17
17
# https://www.gnu.org/licenses/
18
18
# ****************************************************************************
19
19
from __future__ import annotations
20
- from sage . combinat . free_module import CombinatorialFreeModule
20
+
21
21
from sage .categories .algebras import Algebras
22
- from sage .misc . cachefunc import cached_method
22
+ from sage .combinat . free_module import CombinatorialFreeModule
23
23
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
28
26
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
29
30
30
31
31
- class FiniteGCAlgebra (CombinatorialFreeModule , Algebra ):
32
+ class FiniteGCAlgebra (CombinatorialFreeModule , Parent ):
32
33
r"""
33
34
Finite dimensional graded commutative algebras.
34
35
@@ -165,7 +166,7 @@ def __classcall_private__(cls, base, names=None, degrees=None,
165
166
raise ValueError ("You must specify names or degrees" )
166
167
else :
167
168
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 ))
169
170
elif isinstance (names , str ):
170
171
names = tuple (names .split (',' ))
171
172
n = len (names )
@@ -194,7 +195,6 @@ def __init__(self, base, names, degrees, max_degree,
194
195
sage: TestSuite(A).run()
195
196
sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z','t'), [1,2,3,4], max_degree=10)
196
197
sage: TestSuite(A).run()
197
-
198
198
"""
199
199
from sage .arith .misc import gcd
200
200
@@ -220,7 +220,7 @@ def __init__(self, base, names, degrees, max_degree,
220
220
sorting_key = sorting_key ,
221
221
category = category )
222
222
223
- def _valid_index (self , w ):
223
+ def _valid_index (self , w ) -> bool :
224
224
r"""
225
225
Return whether ``w`` is a valid index; no multiple powers in odd
226
226
degrees.
@@ -234,11 +234,10 @@ def _valid_index(self, w):
234
234
True
235
235
sage: A._valid_index(w2)
236
236
False
237
-
238
237
"""
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 )
240
239
241
- def _repr_ (self ):
240
+ def _repr_ (self ) -> str :
242
241
"""
243
242
Return the string representation of ``self``.
244
243
@@ -249,7 +248,6 @@ def _repr_(self):
249
248
"Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8"
250
249
sage: A # indirect doctest
251
250
Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8
252
-
253
251
"""
254
252
desc = f'Graded commutative algebra with generators { self ._names } in '
255
253
desc += f'degrees { self ._degrees } with maximal degree { self ._max_deg } '
@@ -264,7 +262,6 @@ def ngens(self):
264
262
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
265
263
sage: A.ngens()
266
264
3
267
-
268
265
"""
269
266
return self .__ngens
270
267
@@ -327,7 +324,6 @@ def product_on_basis(self, w1, w2):
327
324
x*y^2*z
328
325
sage: A.product_on_basis(w2, w1)
329
326
-x*y^2*z
330
-
331
327
"""
332
328
grading = self ._weighted_vectors .grading
333
329
deg_left = grading (w1 )
@@ -375,11 +371,10 @@ def degree_on_basis(self, i):
375
371
sage: i = A._weighted_vectors([1,1,0])
376
372
sage: A.degree_on_basis(i)
377
373
6
378
-
379
374
"""
380
375
return self ._weighted_vectors .grading (i )
381
376
382
- def _repr_term (self , w ):
377
+ def _repr_term (self , w ) -> str :
383
378
r"""
384
379
Return the string representation of basis with index ``w``.
385
380
@@ -400,7 +395,6 @@ def _repr_term(self, w):
400
395
'x⌣y^2⌣z'
401
396
sage: x*y^2*z # indirect doctest
402
397
x⌣y^2⌣z
403
-
404
398
"""
405
399
# Trivial case:
406
400
if sum (w ) == 0 :
@@ -416,7 +410,7 @@ def _repr_term(self, w):
416
410
terms .append (self ._names [i ] + f'^{ w [i ]} ' )
417
411
return self ._mul_symbol .join (terms )
418
412
419
- def _latex_term (self , w ):
413
+ def _latex_term (self , w ) -> str :
420
414
r"""
421
415
Return the LaTeX representation of basis with index ``w``.
422
416
@@ -436,7 +430,6 @@ def _latex_term(self, w):
436
430
'x\\smile y^{2}\\smile z'
437
431
sage: latex(x*y^2*z) # indirect doctest
438
432
x\smile y^{2}\smile z
439
-
440
433
"""
441
434
# Trivial case:
442
435
if sum (w ) == 0 :
@@ -463,10 +456,8 @@ def algebra_generators(self):
463
456
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
464
457
sage: A.algebra_generators()
465
458
Family (x, y, z)
466
-
467
459
"""
468
460
from sage .sets .family import Family
469
-
470
461
return Family (self .gens ())
471
462
472
463
@cached_method
@@ -483,7 +474,6 @@ def one_basis(self):
483
474
1
484
475
sage: A.one() # indirect doctest
485
476
1
486
-
487
477
"""
488
478
n = len (self ._degrees )
489
479
return self ._weighted_vectors ([0 for _ in range (n )])
@@ -521,7 +511,6 @@ def gen(self, i):
521
511
y
522
512
sage: A.gen(2)
523
513
z
524
-
525
514
"""
526
515
return self .gens ()[i ]
527
516
@@ -534,7 +523,6 @@ def maximal_degree(self):
534
523
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)
535
524
sage: A.maximal_degree()
536
525
8
537
-
538
526
"""
539
527
return self ._max_deg
540
528
0 commit comments