diff --git a/src/sage/modular/modform/space.py b/src/sage/modular/modform/space.py index 202ea687953..6d2f5e2c11d 100644 --- a/src/sage/modular/modform/space.py +++ b/src/sage/modular/modform/space.py @@ -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 @@ -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. @@ -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:: diff --git a/src/sage/modular/modsym/ambient.py b/src/sage/modular/modsym/ambient.py index 56e01e8c106..afe98f94e42 100644 --- a/src/sage/modular/modsym/ambient.py +++ b/src/sage/modular/modsym/ambient.py @@ -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``. @@ -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): """ diff --git a/src/sage/modular/modsym/manin_symbol_list.py b/src/sage/modular/modsym/manin_symbol_list.py index ebc40022031..23a0cdbd872 100644 --- a/src/sage/modular/modsym/manin_symbol_list.py +++ b/src/sage/modular/modsym/manin_symbol_list.py @@ -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 @@ -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. @@ -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 diff --git a/src/sage/modular/modsym/space.py b/src/sage/modular/modsym/space.py index a77d9279a6b..25665bdfd96 100644 --- a/src/sage/modular/modsym/space.py +++ b/src/sage/modular/modsym/space.py @@ -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 @@ -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: @@ -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. @@ -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 @@ -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: @@ -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): diff --git a/src/sage/modular/modsym/subspace.py b/src/sage/modular/modsym/subspace.py index e814602226a..191cabcaf45 100644 --- a/src/sage/modular/modsym/subspace.py +++ b/src/sage/modular/modsym/subspace.py @@ -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): @@ -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. @@ -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): """ diff --git a/src/sage/modular/ssmod/ssmod.py b/src/sage/modular/ssmod/ssmod.py index 9913e554a02..f0a10229aee 100644 --- a/src/sage/modular/ssmod/ssmod.py +++ b/src/sage/modular/ssmod/ssmod.py @@ -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 @@ -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 @@ -522,16 +524,10 @@ def dimension(self): - Iftikhar Burhanuddin -- burhanud@usc.edu """ - 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 @@ -607,6 +603,7 @@ def weight(self): """ return 2 + @cached_method def supersingular_points(self): r""" Compute the supersingular j-invariants over the @@ -647,10 +644,6 @@ def supersingular_points(self): - Iftikhar Burhanuddin -- burhanud@usc.edu """ - try: - return (self._ss_points_dic, self._ss_points) - except AttributeError: - pass Fp2 = self.__finite_field level = self.__level prime = Fp2.characteristic()