Path: blob/master/sage/databases/db_modular_polynomials.py
6915 views
"""1Database of Modular Polynomials2"""34#######################################################################5#6# Sage: System for Algebra and Geometry Experimentation7#8# Copyright (C) 2006 William Stein <[email protected]>9# Copyright (C) 2006 David Kohel <[email protected]>10#11# Distributed under the terms of the GNU General Public License (GPL)12#13# The full text of the GPL is available at:14#15# http://www.gnu.org/licenses/16#######################################################################171819import bz2, os20import sage.misc.misc21from sage.rings.integer import Integer22from sage.rings.integer_ring import IntegerRing23from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing2425dblocation = '%s/kohel'%sage.misc.misc.SAGE_DATA2627def _dbz_to_integer_list(name):28file = '%s/%s'%(dblocation, name)29if not os.path.exists(file):30raise RuntimeError, "Modular polynomial database file %s not available"%file31data = bz2.decompress(open(file).read())32data = "[[" + data.replace("\n","],[").replace(" ",",")[:-2] + "]"33return eval(data)3435def _pad_int(s,n):36return "0"*(n-len(str(s))) + str(s)3738class ModularPolynomialDatabase:39def _dbpath(self,level):40return "PolMod/%s/pol.%s.dbz"%(self.model, _pad_int(level,3))4142def __repr__(self):43if self.model == "Cls":44head = "Classical"45poly = "polynomial"46elif self.model == "Atk":47head = "Atkin"48poly = "polynomial"49elif self.model == "AtkCrr":50head = "Atkin"51poly = "correspondence"52elif self.model == "Eta":53head = "Dedekind eta"54poly = "polynomial"55elif self.model == "EtaCrr":56head = "Dedekind eta"57poly = "correspondence"58return "%s modular %s database"%(head,poly)5960def __getitem__(self,level):61"""62Return the modular polynomial of given level, or an error if63there is no such polynomial in the database.6465EXAMPLES:66sage: DBMP = ClassicalModularPolynomialDatabase() #optional requires database_hohel67sage: f = DBMP[29] #optional68sage: f.degree() #optional695870sage: f.coefficient([28,28]) #optional714001528992046469978402608391287273sage: DBMP[50] #optional74Traceback (most recent call last):75...76RuntimeError: No database entry for modular polynomial of level 5077"""78if self.model in ("Atk","Eta"):79level = Integer(level)80if not level.is_prime():81raise TypeError, "Argument level (= %s) must be prime."%level82elif self.model in ("AtkCrr","EtaCrr"):83N = Integer(level[0])84if not N in (2,3,5,7,13):85raise TypeError, "Argument level (= %s) must be prime."%N86modpol = self._dbpath(level)87try:88coeff_list = _dbz_to_integer_list(modpol)89except RuntimeError, msg:90print msg91raise RuntimeError, \92"No database entry for modular polynomial of level %s"%level93if self.model == "Cls":94P = PolynomialRing(IntegerRing(),2,"j")95else:96P = PolynomialRing(IntegerRing(),2,"x,j")97poly = {}98if self.model == "Cls":99if level == 1:100return P({(1,0):1,(0,1):-1})101for cff in coeff_list:102i = cff[0]103j = cff[1]104poly[(i,j)] = Integer(cff[2])105if i != j:106poly[(j,i)] = Integer(cff[2])107else:108for cff in coeff_list:109poly[(cff[0],cff[1])] = Integer(cff[2])110return P(poly)111112class ModularCorrespondenceDatabase(ModularPolynomialDatabase):113def _dbpath(self,level):114(Nlevel,crrlevel) = level115return "PolMod/%s/crr.%s.%s.dbz"%(116self.model, _pad_int(Nlevel,2), _pad_int(crrlevel,3))117118class ClassicalModularPolynomialDatabase(ModularPolynomialDatabase):119"""120The database of classical modular polynomials, i.e. the polynomials121Phi_N(X,Y) relating the j-functions j(q) and j(q^N).122"""123def __init__(self):124"""125Initialize the database.126"""127self.model = "Cls"128129class DedekindEtaModularPolynomialDatabase(ModularPolynomialDatabase):130"""131The database of modular polynomials Phi_N(X,Y) relating a quotient132of Dedekind eta functions, well-defined on X_0(N), relating x(q) and133the j-function j(q).134"""135def __init__(self):136"""137Initialize the database.138"""139self.model = "Eta"140141class DedekindEtaModularCorrespondenceDatabase(ModularCorrespondenceDatabase):142"""143The database of modular correspondences in $X_0(p) \times X_0(p)$, where144the model of the curves $X_0(p) = \PP^1$ are specified by quotients of145Dedekind's eta function.146"""147def __init__(self):148"""149Returns the150"""151self.model = "EtaCrr"152153class AtkinModularPolynomialDatabase(ModularPolynomialDatabase):154"""155The database of modular polynomials Phi(x,j) for $X_0(p)$, where156x is a function on invariant under the Atkin-Lehner invariant,157with pole of minimal order at infinity.158"""159def __init__(self):160"""161Initialize the database.162"""163self.model = "Atk"164165class AtkinModularCorrespondenceDatabase(ModularCorrespondenceDatabase):166def __init__(self):167"""168Initialize the database.169"""170self.model = "AtkCrr"171172173