Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/databases/db_modular_polynomials.py
8814 views
1
"""
2
Database of Modular Polynomials
3
"""
4
5
#######################################################################
6
#
7
# Sage: System for Algebra and Geometry Experimentation
8
#
9
# Copyright (C) 2006 William Stein <[email protected]>
10
# Copyright (C) 2006 David Kohel <[email protected]>
11
#
12
# Distributed under the terms of the GNU General Public License (GPL)
13
#
14
# The full text of the GPL is available at:
15
#
16
# http://www.gnu.org/licenses/
17
#######################################################################
18
19
20
import bz2, os
21
import sage.misc.misc
22
from sage.rings.integer import Integer
23
from sage.rings.integer_ring import IntegerRing
24
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
25
26
dblocation = os.path.join(sage.misc.misc.SAGE_SHARE,'kohel')
27
28
def _dbz_to_integer_list(name):
29
file = os.path.join(dblocation, name)
30
if not os.path.exists(file):
31
raise RuntimeError("Modular polynomial database file %s not available"%file)
32
data = bz2.decompress(open(file).read())
33
data = "[[" + data.replace("\n","],[").replace(" ",",")[:-2] + "]"
34
return eval(data)
35
36
def _pad_int(s,n):
37
return "0"*(n-len(str(s))) + str(s)
38
39
class ModularPolynomialDatabase:
40
def _dbpath(self,level):
41
return "PolMod/%s/pol.%s.dbz"%(self.model, _pad_int(level,3))
42
43
def __repr__(self):
44
if self.model == "Cls":
45
head = "Classical"
46
poly = "polynomial"
47
elif self.model == "Atk":
48
head = "Atkin"
49
poly = "polynomial"
50
elif self.model == "AtkCrr":
51
head = "Atkin"
52
poly = "correspondence"
53
elif self.model == "Eta":
54
head = "Dedekind eta"
55
poly = "polynomial"
56
elif self.model == "EtaCrr":
57
head = "Dedekind eta"
58
poly = "correspondence"
59
return "%s modular %s database"%(head,poly)
60
61
def __getitem__(self,level):
62
"""
63
Return the modular polynomial of given level, or an error if
64
there is no such polynomial in the database.
65
66
EXAMPLES:
67
sage: DBMP = ClassicalModularPolynomialDatabase() # optional - database_kohel
68
sage: f = DBMP[29] #optional
69
sage: f.degree() #optional
70
58
71
sage: f.coefficient([28,28]) #optional
72
400152899204646997840260839128
73
74
sage: DBMP[50] #optional
75
Traceback (most recent call last):
76
...
77
RuntimeError: No database entry for modular polynomial of level 50
78
"""
79
if self.model in ("Atk","Eta"):
80
level = Integer(level)
81
if not level.is_prime():
82
raise TypeError("Argument level (= %s) must be prime."%level)
83
elif self.model in ("AtkCrr","EtaCrr"):
84
N = Integer(level[0])
85
if not N in (2,3,5,7,13):
86
raise TypeError("Argument level (= %s) must be prime."%N)
87
modpol = self._dbpath(level)
88
try:
89
coeff_list = _dbz_to_integer_list(modpol)
90
except RuntimeError as msg:
91
print(msg)
92
raise RuntimeError("No database entry for modular polynomial of level %s"%level)
93
if self.model == "Cls":
94
P = PolynomialRing(IntegerRing(),2,"j")
95
else:
96
P = PolynomialRing(IntegerRing(),2,"x,j")
97
poly = {}
98
if self.model == "Cls":
99
if level == 1:
100
return P({(1,0):1,(0,1):-1})
101
for cff in coeff_list:
102
i = cff[0]
103
j = cff[1]
104
poly[(i,j)] = Integer(cff[2])
105
if i != j:
106
poly[(j,i)] = Integer(cff[2])
107
else:
108
for cff in coeff_list:
109
poly[(cff[0],cff[1])] = Integer(cff[2])
110
return P(poly)
111
112
class ModularCorrespondenceDatabase(ModularPolynomialDatabase):
113
def _dbpath(self,level):
114
(Nlevel,crrlevel) = level
115
return "PolMod/%s/crr.%s.%s.dbz"%(
116
self.model, _pad_int(Nlevel,2), _pad_int(crrlevel,3))
117
118
class ClassicalModularPolynomialDatabase(ModularPolynomialDatabase):
119
"""
120
The database of classical modular polynomials, i.e. the polynomials
121
Phi_N(X,Y) relating the j-functions j(q) and j(q^N).
122
"""
123
def __init__(self):
124
"""
125
Initialize the database.
126
"""
127
self.model = "Cls"
128
129
class DedekindEtaModularPolynomialDatabase(ModularPolynomialDatabase):
130
"""
131
The database of modular polynomials Phi_N(X,Y) relating a quotient
132
of Dedekind eta functions, well-defined on X_0(N), relating x(q) and
133
the j-function j(q).
134
"""
135
def __init__(self):
136
"""
137
Initialize the database.
138
"""
139
self.model = "Eta"
140
141
class DedekindEtaModularCorrespondenceDatabase(ModularCorrespondenceDatabase):
142
"""
143
The database of modular correspondences in $X_0(p) \times X_0(p)$, where
144
the model of the curves $X_0(p) = \PP^1$ are specified by quotients of
145
Dedekind's eta function.
146
"""
147
def __init__(self):
148
"""
149
Returns the
150
"""
151
self.model = "EtaCrr"
152
153
class AtkinModularPolynomialDatabase(ModularPolynomialDatabase):
154
"""
155
The database of modular polynomials Phi(x,j) for $X_0(p)$, where
156
x is a function on invariant under the Atkin-Lehner invariant,
157
with pole of minimal order at infinity.
158
"""
159
def __init__(self):
160
"""
161
Initialize the database.
162
"""
163
self.model = "Atk"
164
165
class AtkinModularCorrespondenceDatabase(ModularCorrespondenceDatabase):
166
def __init__(self):
167
"""
168
Initialize the database.
169
"""
170
self.model = "AtkCrr"
171
172