Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Parent instead of Algebra in finite_gca #37302

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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))

Check warning on line 168 in src/sage/algebras/finite_gca.py

View check run for this annotation

Codecov / codecov/patch

src/sage/algebras/finite_gca.py#L168

Added line #L168 was not covered by tests
elif isinstance(names, str):
names = tuple(names.split(','))
n = len(names)
Expand Down Expand Up @@ -194,7 +194,6 @@
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 @@
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 @@
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 @@
"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 @@
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 @@
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 @@
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 @@
'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 @@
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 @@
'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 @@
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 @@
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 @@
y
sage: A.gen(2)
z

"""
return self.gens()[i]

Expand All @@ -534,7 +522,6 @@
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
Loading