Path: blob/master/src/sage/databases/db_modular_polynomials.py
8814 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 = os.path.join(sage.misc.misc.SAGE_SHARE,'kohel')2627def _dbz_to_integer_list(name):28file = os.path.join(dblocation, name)29if not os.path.exists(file):30raise RuntimeError("Modular polynomial database file %s not available"%file)31data = 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 - database_kohel67sage: 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."%level)82elif 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."%N)86modpol = self._dbpath(level)87try:88coeff_list = _dbz_to_integer_list(modpol)89except RuntimeError as msg:90print(msg)91raise RuntimeError("No database entry for modular polynomial of level %s"%level)92if self.model == "Cls":93P = PolynomialRing(IntegerRing(),2,"j")94else:95P = PolynomialRing(IntegerRing(),2,"x,j")96poly = {}97if self.model == "Cls":98if level == 1:99return P({(1,0):1,(0,1):-1})100for cff in coeff_list:101i = cff[0]102j = cff[1]103poly[(i,j)] = Integer(cff[2])104if i != j:105poly[(j,i)] = Integer(cff[2])106else:107for cff in coeff_list:108poly[(cff[0],cff[1])] = Integer(cff[2])109return P(poly)110111class ModularCorrespondenceDatabase(ModularPolynomialDatabase):112def _dbpath(self,level):113(Nlevel,crrlevel) = level114return "PolMod/%s/crr.%s.%s.dbz"%(115self.model, _pad_int(Nlevel,2), _pad_int(crrlevel,3))116117class ClassicalModularPolynomialDatabase(ModularPolynomialDatabase):118"""119The database of classical modular polynomials, i.e. the polynomials120Phi_N(X,Y) relating the j-functions j(q) and j(q^N).121"""122def __init__(self):123"""124Initialize the database.125"""126self.model = "Cls"127128class DedekindEtaModularPolynomialDatabase(ModularPolynomialDatabase):129"""130The database of modular polynomials Phi_N(X,Y) relating a quotient131of Dedekind eta functions, well-defined on X_0(N), relating x(q) and132the j-function j(q).133"""134def __init__(self):135"""136Initialize the database.137"""138self.model = "Eta"139140class DedekindEtaModularCorrespondenceDatabase(ModularCorrespondenceDatabase):141"""142The database of modular correspondences in $X_0(p) \times X_0(p)$, where143the model of the curves $X_0(p) = \PP^1$ are specified by quotients of144Dedekind's eta function.145"""146def __init__(self):147"""148Returns the149"""150self.model = "EtaCrr"151152class AtkinModularPolynomialDatabase(ModularPolynomialDatabase):153"""154The database of modular polynomials Phi(x,j) for $X_0(p)$, where155x is a function on invariant under the Atkin-Lehner invariant,156with pole of minimal order at infinity.157"""158def __init__(self):159"""160Initialize the database.161"""162self.model = "Atk"163164class AtkinModularCorrespondenceDatabase(ModularCorrespondenceDatabase):165def __init__(self):166"""167Initialize the database.168"""169self.model = "AtkCrr"170171172