Skip to content

Commit

Permalink
more uses of cached_method in modular folder
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Dec 31, 2024
1 parent c9dd1e8 commit 6fce017
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 58 deletions.
20 changes: 9 additions & 11 deletions src/sage/modular/modform/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ def cuspidal_submodule(self):
else:
assert S.dimension() == self.dimension()
self.__is_cuspidal = True
S.__is_eisenstein = (S.dimension() == 0)
S.is_eisenstein.set_cache(S.dimension() == 0)
S.__is_cuspidal = True
return S

Expand Down Expand Up @@ -1592,7 +1592,8 @@ def is_cuspidal(self):
"""
return (self.cuspidal_submodule() == self)

def is_eisenstein(self):
@cached_method
def is_eisenstein(self) -> bool:
r"""
Return ``True`` if this space is Eisenstein.
Expand Down Expand Up @@ -1726,28 +1727,25 @@ def eisenstein_submodule(self):
sage: W.eisenstein_submodule()
Modular Forms subspace of dimension 0 of Modular Forms space of dimension 11 for Congruence Subgroup Gamma0(6) of weight 10 over Rational Field
"""
try:
if self.__is_eisenstein:
return self
except AttributeError:
pass
if self.is_eisenstein.cache is True:
return self

if self.is_ambient():
raise NotImplementedError("ambient modular forms spaces must override eisenstein_submodule")
A = self.ambient_module().eisenstein_submodule()
E = self.intersection(A)
if E.dimension() < self.dimension():
self.__is_eisenstein = False
self.is_eisenstein.set_cache(False)
else:
assert E.dimension() == self.dimension()
self.__is_eisenstein = True
self.is_eisenstein.set_cache(True)
E.__is_cuspidal = (E.dimension() == 0)
E.__is_eisenstein = True
E.is_eisenstein.set_cache(True)
return E

def eisenstein_subspace(self):
"""
Synonym for eisenstein_submodule.
Synonym for Eisenstein_submodule.
EXAMPLES::
Expand Down
11 changes: 4 additions & 7 deletions src/sage/modular/modsym/ambient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,8 @@ def is_cuspidal(self):
self.__is_cuspidal = (S.dimension() == self.dimension())
return self.__is_cuspidal

def is_eisenstein(self):
@cached_method
def is_eisenstein(self) -> bool:
r"""
Return ``True`` if this space is Eisenstein, else ``False``.
Expand All @@ -1814,12 +1815,8 @@ def is_eisenstein(self):
sage: S.is_eisenstein()
False
"""
try:
return self.__is_eisenstein
except AttributeError:
S = self.ambient_hecke_module().eisenstein_submodule()
self.__is_eisenstein = self.dimension() == S.dimension()
return self.__is_eisenstein
S = self.ambient_hecke_module().eisenstein_submodule()
return self.dimension() == S.dimension()

def manin_symbols_basis(self):
"""
Expand Down
10 changes: 3 additions & 7 deletions src/sage/modular/modsym/manin_symbol_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from sage.rings.integer import Integer
from sage.structure.parent import Parent
from sage.misc.persist import register_unpickle_override
from sage.misc.cachefunc import cached_method
from sage.structure.richcmp import richcmp_method, richcmp
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets

Expand Down Expand Up @@ -283,6 +284,7 @@ def index(self, x):
except KeyError:
return -1

@cached_method
def manin_symbol_list(self):
"""
Return all the Manin symbols in ``self`` as a list.
Expand Down Expand Up @@ -312,13 +314,7 @@ def manin_symbol_list(self):
[X^2,(3,1)],
[X^2,(3,2)]]
"""
import copy
try:
return copy.copy(self.__manin_symbol_list)
except AttributeError:
self.__manin_symbol_list = [self.manin_symbol(i)
for i in range(len(self))]
return copy.copy(self.__manin_symbol_list)
return [self.manin_symbol(i) for i in range(len(self))]

list = manin_symbol_list

Expand Down
18 changes: 4 additions & 14 deletions src/sage/modular/modsym/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,7 @@ def modular_symbols_of_sign(self, sign, bound=None):
# Cuspidal torsion groups
#########################################################

@cached_method
def abvarquo_cuspidal_subgroup(self):
"""
Compute the rational subgroup of the cuspidal subgroup (as an
Expand All @@ -2186,10 +2187,6 @@ def abvarquo_cuspidal_subgroup(self):
sage: [A.abvarquo_cuspidal_subgroup().invariants() for A in D]
[(), (), ()]
"""
try:
return self.__abvarquo_cuspidal_subgroup
except AttributeError:
pass
if self.base_ring() != QQ:
raise ValueError("base ring must be QQ")
if self.weight() != 2:
Expand All @@ -2198,7 +2195,7 @@ def abvarquo_cuspidal_subgroup(self):
phi = self.integral_period_mapping()

# Make a list of all the finite cusps.
P = [c for c in M.cusps() if not c.is_infinity()]
P = (c for c in M.cusps() if not c.is_infinity())

# Compute the images of the cusp classes (c)-(oo) in the
# rational homology of the quotient modular abelian variety.
Expand All @@ -2209,11 +2206,9 @@ def abvarquo_cuspidal_subgroup(self):

# The cuspidal subgroup is then the quotient of that module +
# H_1(A) by H_1(A)
C = (A.ambient_module() + A) / A.ambient_module()

self.__abvarquo_cuspidal_subgroup = C
return C
return (A.ambient_module() + A) / A.ambient_module()

@cached_method
def abvarquo_rational_cuspidal_subgroup(self):
r"""
Compute the rational subgroup of the cuspidal subgroup (as an
Expand Down Expand Up @@ -2277,10 +2272,6 @@ def abvarquo_rational_cuspidal_subgroup(self):
sage: [A.abelian_variety().rational_torsion_subgroup().multiple_of_order() for A in D]
[1, 5, 5]
"""
try:
return self.__abvarquo_rational_cuspidal_subgroup
except AttributeError:
pass
if self.base_ring() != QQ:
raise ValueError("base ring must be QQ")
if self.weight() != 2:
Expand Down Expand Up @@ -2332,7 +2323,6 @@ def abvarquo_rational_cuspidal_subgroup(self):
if CQ.cardinality() == 1:
break # done -- no point in wasting more time shrinking CQ

self.__abvarquo_rational_cuspidal_subgroup = CQ
return CQ

def _matrix_of_galois_action(self, t, P):
Expand Down
12 changes: 5 additions & 7 deletions src/sage/modular/modsym/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sage.modular.hecke.all as hecke
import sage.structure.factorization
import sage.modular.modsym.space
from sage.misc.cachefunc import cached_method


class ModularSymbolsSubspace(sage.modular.modsym.space.ModularSymbolsSpace, hecke.HeckeSubmodule):
Expand Down Expand Up @@ -353,7 +354,8 @@ def _set_is_cuspidal(self, t):
"""
self.__is_cuspidal = t

def is_eisenstein(self):
@cached_method
def is_eisenstein(self) -> bool:
"""
Return ``True`` if ``self`` is an Eisenstein subspace.
Expand All @@ -364,12 +366,8 @@ def is_eisenstein(self):
sage: ModularSymbols(22,6).eisenstein_submodule().is_eisenstein()
True
"""
try:
return self.__is_eisenstien
except AttributeError:
C = self.ambient_hecke_module().eisenstein_subspace()
self.__is_eisenstein = self.is_submodule(C)
return self.__is_eisenstein
C = self.ambient_hecke_module().eisenstein_subspace()
return self.is_submodule(C)

def _compute_sign_subspace(self, sign, compute_dual=True):
"""
Expand Down
17 changes: 5 additions & 12 deletions src/sage/modular/ssmod/ssmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from sage.arith.misc import kronecker, next_prime
from sage.categories.fields import Fields
from sage.matrix.matrix_space import MatrixSpace
from sage.misc.cachefunc import cached_method
from sage.misc.lazy_import import lazy_import
from sage.modular.arithgroup.all import Gamma0
from sage.modular.hecke.module import HeckeModule_free_module
Expand Down Expand Up @@ -487,6 +488,7 @@ def free_module(self):
"""
return ZZ**self.dimension()

@cached_method
def dimension(self):
r"""
Return the dimension of the space of modular forms of weight 2
Expand Down Expand Up @@ -522,16 +524,10 @@ def dimension(self):
- Iftikhar Burhanuddin -- [email protected]
"""
try:
return self.__dimension
except AttributeError:
pass
if self.__level == 1:
G = Gamma0(self.__prime)
self.__dimension = G.dimension_modular_forms(2)
else:
raise NotImplementedError
return self.__dimension
return G.dimension_modular_forms(2)
raise NotImplementedError

rank = dimension

Expand Down Expand Up @@ -607,6 +603,7 @@ def weight(self):
"""
return 2

@cached_method
def supersingular_points(self):
r"""
Compute the supersingular j-invariants over the
Expand Down Expand Up @@ -647,10 +644,6 @@ def supersingular_points(self):
- Iftikhar Burhanuddin -- [email protected]
"""
try:
return (self._ss_points_dic, self._ss_points)
except AttributeError:
pass
Fp2 = self.__finite_field
level = self.__level
prime = Fp2.characteristic()
Expand Down

0 comments on commit 6fce017

Please sign in to comment.