Path: blob/master/src/sage/modular/abvar/constructor.py
8820 views
"""1Constructors for certain modular abelian varieties23AUTHORS:45- William Stein (2007-03)6"""78###########################################################################9# Copyright (C) 2007 William Stein <[email protected]> #10# Distributed under the terms of the GNU General Public License (GPL) #11# http://www.gnu.org/licenses/ #12###########################################################################1314import weakref1516from sage.rings.integer import Integer1718from sage.modular.arithgroup.all import is_CongruenceSubgroup, Gamma019from sage.modular.modsym.space import is_ModularSymbolsSpace20from abvar_newform import ModularAbelianVariety_newform21import sage.modular.modform.element22import abvar2324_cache = {}2526def _get(key):27"""28Returns the cached abelian variety with given key. This is used29internally by the abelian varieties constructor.3031INPUT:323334- ``key`` - hashable353637EXAMPLE::3839sage: sage.modular.abvar.constructor._saved('a', J0(37))40Abelian variety J0(37) of dimension 241sage: sage.modular.abvar.constructor._get('a')42Abelian variety J0(37) of dimension 243sage: sage.modular.abvar.constructor._get('b')44Traceback (most recent call last):45...46ValueError: element not in cache47"""48if _cache.has_key(key):49z = _cache[key]()50if z is not None:51return z52raise ValueError, "element not in cache"5354def _saved(key, J):55"""56Returns the cached abelian variety with given key. This is used57internally by the abelian varieties constructor.5859INPUT:606162- ``key`` - hashable6364- ``J`` - modular abelian variety656667OUTPUT:686970- ``J`` - returns the modabvar, to make code that uses71this simpler727374EXAMPLES::7576sage: sage.modular.abvar.constructor._saved('37', J0(37))77Abelian variety J0(37) of dimension 278"""79_cache[key] = weakref.ref(J)80return J818283def J0(N):84"""85Return the Jacobian `J_0(N)` of the modular curve86`X_0(N)`.8788EXAMPLES::8990sage: J0(389)91Abelian variety J0(389) of dimension 329293The result is cached::9495sage: J0(33) is J0(33)96True97"""98key = 'J0(%s)'%N99try:100return _get(key)101except ValueError:102from sage.modular.arithgroup.all import Gamma0103J = Gamma0(N).modular_abelian_variety()104return _saved(key, J)105106def J1(N):107"""108Return the Jacobian `J_1(N)` of the modular curve109`X_1(N)`.110111EXAMPLES::112113sage: J1(389)114Abelian variety J1(389) of dimension 6112115"""116key = 'J1(%s)'%N117try:118return _get(key)119except ValueError:120from sage.modular.arithgroup.all import Gamma1121return _saved(key, Gamma1(N).modular_abelian_variety())122123def JH(N, H):124"""125Return the Jacobian `J_H(N)` of the modular curve126`X_H(N)`.127128EXAMPLES::129130sage: JH(389,[16])131Abelian variety JH(389,[16]) of dimension 64132"""133key = 'JH(%s,%s)'%(N,H)134try:135return _get(key)136except ValueError:137from sage.modular.arithgroup.all import GammaH138return _saved(key, GammaH(N, H).modular_abelian_variety())139140def AbelianVariety(X):141"""142Create the abelian variety corresponding to the given defining143data.144145INPUT:146147148- ``X`` - an integer, string, newform, modsym space,149congruence subgroup or tuple of congruence subgroups150151152OUTPUT: a modular abelian variety153154EXAMPLES::155156sage: AbelianVariety(Gamma0(37))157Abelian variety J0(37) of dimension 2158sage: AbelianVariety('37a')159Newform abelian subvariety 37a of dimension 1 of J0(37)160sage: AbelianVariety(Newform('37a'))161Newform abelian subvariety 37a of dimension 1 of J0(37)162sage: AbelianVariety(ModularSymbols(37).cuspidal_submodule())163Abelian variety J0(37) of dimension 2164sage: AbelianVariety((Gamma0(37), Gamma0(11)))165Abelian variety J0(37) x J0(11) of dimension 3166sage: AbelianVariety(37)167Abelian variety J0(37) of dimension 2168sage: AbelianVariety([1,2,3])169Traceback (most recent call last):170...171TypeError: X must be an integer, string, newform, modsym space, congruence subgroup or tuple of congruence subgroups172"""173if isinstance(X, (int, long, Integer)):174X = Gamma0(X)175if is_CongruenceSubgroup(X):176X = X.modular_symbols().cuspidal_submodule()177elif isinstance(X, str):178from sage.modular.modform.constructor import Newform179f = Newform(X, names='a')180return ModularAbelianVariety_newform(f, internal_name=True)181elif isinstance(X, sage.modular.modform.element.Newform):182return ModularAbelianVariety_newform(X)183184if is_ModularSymbolsSpace(X):185return abvar.ModularAbelianVariety_modsym(X)186187if isinstance(X, (tuple,list)) and all([is_CongruenceSubgroup(G) for G in X]):188return abvar.ModularAbelianVariety(X)189190raise TypeError, "X must be an integer, string, newform, modsym space, congruence subgroup or tuple of congruence subgroups"191192193