Skip to content

Commit

Permalink
sagemathgh-37302: use Parent instead of Algebra in finite_gca
Browse files Browse the repository at this point in the history
    
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: sagemath#37302
Reported by: Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Feb 17, 2024
2 parents 86321b9 + e018ff4 commit 74f84bc
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/sage/algebras/finite_gca.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations
from sage.combinat.free_module import CombinatorialFreeModule

from sage.categories.algebras import Algebras
from sage.misc.cachefunc import cached_method
from sage.combinat.free_module import CombinatorialFreeModule
from sage.combinat.integer_vector_weighted import WeightedIntegerVectors
from sage.rings.ring import Algebra
from sage.misc.functional import is_odd, is_even
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.condition_set import ConditionSet
from sage.misc.cachefunc import cached_method
from sage.misc.functional import is_even
from sage.rings.integer_ring import ZZ
from sage.sets.condition_set import ConditionSet
from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets


class FiniteGCAlgebra(CombinatorialFreeModule, Algebra):
class FiniteGCAlgebra(CombinatorialFreeModule):
r"""
Finite dimensional graded commutative algebras.
Expand Down Expand Up @@ -165,7 +165,7 @@ def __classcall_private__(cls, base, names=None, degrees=None,
raise ValueError("You must specify names or degrees")
else:
n = len(degrees)
names = tuple('x{}'.format(i) for i in range(n))
names = tuple(f'x{i}' for i in range(n))
elif isinstance(names, str):
names = tuple(names.split(','))
n = len(names)
Expand Down Expand Up @@ -194,7 +194,6 @@ def __init__(self, base, names, degrees, max_degree,
sage: TestSuite(A).run()
sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z','t'), [1,2,3,4], max_degree=10)
sage: TestSuite(A).run()
"""
from sage.arith.misc import gcd

Expand All @@ -220,7 +219,7 @@ def __init__(self, base, names, degrees, max_degree,
sorting_key=sorting_key,
category=category)

def _valid_index(self, w):
def _valid_index(self, w) -> bool:
r"""
Return whether ``w`` is a valid index; no multiple powers in odd
degrees.
Expand All @@ -234,11 +233,10 @@ def _valid_index(self, w):
True
sage: A._valid_index(w2)
False
"""
return not any(i > 1 for i, d in zip(w, self._degrees) if is_odd(d))
return not any(i > 1 for i, d in zip(w, self._degrees) if d % 2)

def _repr_(self):
def _repr_(self) -> str:
"""
Return the string representation of ``self``.
Expand All @@ -249,7 +247,6 @@ def _repr_(self):
"Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8"
sage: A # indirect doctest
Graded commutative algebra with generators ('x', 'y', 'z') in degrees (1, 2, 3) with maximal degree 8
"""
desc = f'Graded commutative algebra with generators {self._names} in '
desc += f'degrees {self._degrees} with maximal degree {self._max_deg}'
Expand All @@ -264,7 +261,6 @@ def ngens(self):
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
sage: A.ngens()
3
"""
return self.__ngens

Expand Down Expand Up @@ -327,7 +323,6 @@ def product_on_basis(self, w1, w2):
x*y^2*z
sage: A.product_on_basis(w2, w1)
-x*y^2*z
"""
grading = self._weighted_vectors.grading
deg_left = grading(w1)
Expand Down Expand Up @@ -375,11 +370,10 @@ def degree_on_basis(self, i):
sage: i = A._weighted_vectors([1,1,0])
sage: A.degree_on_basis(i)
6
"""
return self._weighted_vectors.grading(i)

def _repr_term(self, w):
def _repr_term(self, w) -> str:
r"""
Return the string representation of basis with index ``w``.
Expand All @@ -400,7 +394,6 @@ def _repr_term(self, w):
'x⌣y^2⌣z'
sage: x*y^2*z # indirect doctest
x⌣y^2⌣z
"""
# Trivial case:
if sum(w) == 0:
Expand All @@ -416,7 +409,7 @@ def _repr_term(self, w):
terms.append(self._names[i] + f'^{w[i]}')
return self._mul_symbol.join(terms)

def _latex_term(self, w):
def _latex_term(self, w) -> str:
r"""
Return the LaTeX representation of basis with index ``w``.
Expand All @@ -436,7 +429,6 @@ def _latex_term(self, w):
'x\\smile y^{2}\\smile z'
sage: latex(x*y^2*z) # indirect doctest
x\smile y^{2}\smile z
"""
# Trivial case:
if sum(w) == 0:
Expand All @@ -463,10 +455,8 @@ def algebra_generators(self):
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)
sage: A.algebra_generators()
Family (x, y, z)
"""
from sage.sets.family import Family

return Family(self.gens())

@cached_method
Expand All @@ -483,7 +473,6 @@ def one_basis(self):
1
sage: A.one() # indirect doctest
1
"""
n = len(self._degrees)
return self._weighted_vectors([0 for _ in range(n)])
Expand Down Expand Up @@ -521,7 +510,6 @@ def gen(self, i):
y
sage: A.gen(2)
z
"""
return self.gens()[i]

Expand All @@ -534,7 +522,6 @@ def maximal_degree(self):
sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)
sage: A.maximal_degree()
8
"""
return self._max_deg

Expand Down

0 comments on commit 74f84bc

Please sign in to comment.