From 8acc12795b5d00d59bec9e2ad13441e29e684955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 25 Jan 2024 15:53:53 +0100 Subject: [PATCH] moving modular stuff to "CommutativeRing" class --- src/sage/modular/hecke/algebra.py | 39 +++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/sage/modular/hecke/algebra.py b/src/sage/modular/hecke/algebra.py index e0f539a507b..2f314e5d3ef 100644 --- a/src/sage/modular/hecke/algebra.py +++ b/src/sage/modular/hecke/algebra.py @@ -26,14 +26,16 @@ # # https://www.gnu.org/licenses/ # **************************************************************************** +from typing import Iterator -import sage.rings.infinity +from sage.rings.infinity import infinity +from sage.categories.algebras import Algebras from sage.matrix.constructor import matrix from sage.arith.functions import lcm from sage.arith.misc import gcd from sage.misc.latex import latex from sage.matrix.matrix_space import MatrixSpace -from sage.rings.ring import CommutativeAlgebra +from sage.rings.ring import CommutativeRing from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ from sage.structure.element import Element @@ -42,7 +44,7 @@ from sage.structure.richcmp import richcmp_method, richcmp -def is_HeckeAlgebra(x): +def is_HeckeAlgebra(x) -> bool: r""" Return ``True`` if x is of type HeckeAlgebra. @@ -105,7 +107,7 @@ def _heckebasis(M): @richcmp_method -class HeckeAlgebra_base(CachedRepresentation, CommutativeAlgebra): +class HeckeAlgebra_base(CachedRepresentation, CommutativeRing): """ Base class for algebras of Hecke operators on a fixed Hecke module. @@ -163,7 +165,7 @@ def __classcall__(cls, M): pass return super().__classcall__(cls, M) - def __init__(self, M): + def __init__(self, M) -> None: """ Initialization. @@ -179,7 +181,9 @@ def __init__(self, M): if not module.is_HeckeModule(M): raise TypeError("M (=%s) must be a HeckeModule" % M) self.__M = M - CommutativeAlgebra.__init__(self, M.base_ring()) + cat = Algebras(M.base_ring()).Commutative() + CommutativeRing.__init__(self, base_ring=M.base_ring(), + category=cat) def _an_element_(self): r""" @@ -319,12 +323,13 @@ def ngens(self): sage: CuspForms(1, 12).anemic_hecke_algebra().ngens() +Infinity """ - return sage.rings.infinity.infinity + return infinity - def is_noetherian(self): + def is_noetherian(self) -> bool: """ - Return ``True`` if this Hecke algebra is Noetherian as a ring. This is true - if and only if the base ring is Noetherian. + Return ``True`` if this Hecke algebra is Noetherian as a ring. + + This is true if and only if the base ring is Noetherian. EXAMPLES:: @@ -343,9 +348,9 @@ def matrix_space(self): sage: CuspForms(3, 24, base_ring=Qp(5)).anemic_hecke_algebra().matrix_space() Full MatrixSpace of 7 by 7 dense matrices over 5-adic Field with capped relative precision 20 """ - return sage.matrix.matrix_space.MatrixSpace(self.base_ring(), self.module().rank()) + return MatrixSpace(self.base_ring(), self.module().rank()) - def _latex_(self): + def _latex_(self) -> str: r""" LaTeX representation of self. @@ -569,7 +574,7 @@ class HeckeAlgebra_full(HeckeAlgebra_base): A full Hecke algebra (including the operators `T_n` where `n` is not assumed to be coprime to the level). """ - def _repr_(self): + def _repr_(self) -> str: r""" String representation of self. @@ -580,7 +585,7 @@ def _repr_(self): """ return "Full Hecke algebra acting on %s" % self.module() - def __richcmp__(self, other, op): + def __richcmp__(self, other, op) -> bool: r""" Compare self to other. @@ -631,7 +636,7 @@ class HeckeAlgebra_anemic(HeckeAlgebra_base): r""" An anemic Hecke algebra, generated by Hecke operators with index coprime to the level. """ - def _repr_(self): + def _repr_(self) -> str: r""" EXAMPLES:: @@ -639,7 +644,7 @@ def _repr_(self): """ return "Anemic Hecke algebra acting on %s" % self.module() - def __richcmp__(self, other, op): + def __richcmp__(self, other, op) -> bool: r""" Compare self to other. @@ -689,7 +694,7 @@ def is_anemic(self) -> bool: """ return True - def gens(self): + def gens(self) -> Iterator: r""" Return a generator over all Hecke operator `T_n` for `n = 1, 2, 3, \ldots`, with `n` coprime to the