Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/databases/conv.py
6915 views
1
import os
2
3
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
4
from sage.rings.rational_field import RationalField
5
from sage.rings.arith import GCD
6
import sage.misc.db as db
7
from sage.misc.misc import SAGE_ROOT, sage_makedirs
8
9
# TODO:
10
# I messed up and now self.d is i and self.i is d,
11
# i.e., the degree and number are swapped.
12
13
14
PATH = SAGE_ROOT + "/src/tables/modular/gamma0/db/"
15
sage_makedirs(PATH)
16
17
class ModularForm:
18
def __init__(self, N, d, i, Wq, r, charpolys, disc):
19
self.N = N
20
self.d = d
21
self.i = i
22
self.Wq = Wq
23
self.r = r
24
self.charpolys = charpolys
25
self.disc = disc
26
27
def __repr__(self):
28
s = "Modular form: level %s, degree %s, number %s"%(
29
self.N,self.d,self.i) + \
30
", Wq: %s, an rank bnd: %s"%(
31
self.Wq, self.r)
32
return s
33
34
def congruence_multiple(self, f, anemic=True):
35
"""
36
Return an integer C such that any prime of congruence between
37
this modular form and f is a divisor of C.
38
39
If anemic=True (the default), include only coefficients a_p
40
with p coprime to the levels of self and f.
41
42
This function returns the gcd of the resultants of each of the
43
charpolys of coefficients of self and f that are both known.
44
"""
45
C = 0
46
N = self.N * f.N
47
for p in self.charpolys.keys():
48
if p in f.charpolys.keys():
49
if (not anemic) or (anemic and N%p!=0):
50
ap = self.charpolys[p]
51
bp = f.charpolys[p]
52
C = GCD(C, ap.resultant(bp))
53
return C
54
55
def torsion_multiple(self):
56
"""
57
Returns a multiple of the order of the torsion subgroup of the
58
corresponding abelian variety.
59
"""
60
T = 0
61
for p in self.charpolys.keys():
62
if self.N % p != 0:
63
f = self.charpolys[p]
64
T = GCD(T, long(f(p+1)))
65
return T
66
67
68
def conv(N):
69
file = "data/%s"%N
70
if not os.path.exists(file):
71
raise RuntimeError, "Data for level %s does not exist."%N
72
73
F = open(file).read()
74
i = F.find(":=")
75
if i == -1:
76
raise RuntimeError, "Syntax error in file for level %s."%N
77
F = F[i+2:]
78
TRANS = [("[*", "["), ("*]", "]"), ("<","["), (">","]"), \
79
(";",""), ("\n",""), ("^","**")]
80
for z,w in TRANS:
81
F = F.replace(z,w)
82
X = []
83
# Define x so the eval below works.
84
R = PolynomialRing(RationalField())
85
x = R.gen()
86
print "starting eval."
87
#print "F = ", F
88
for f in eval(F):
89
print "creating object from f=",f[:4]
90
cp = {}
91
disc = 0
92
for z in f[5]:
93
g = R(z[1])
94
disc = GCD(disc,g.discriminant())
95
cp[z[0]] = g
96
X.append(ModularForm(f[0],f[1],f[2],f[3],f[4],cp,disc))
97
return X
98
99
100
def newforms(N, recompute=False):
101
if N <= 10:
102
return []
103
p = "%s/%s"%(PATH,N)
104
if os.path.exists(p + ".bz2") and not recompute:
105
return db.load(p,bzip2=True)
106
c = conv(N)
107
db.save(c,p, bzip2=True)
108
return c
109
110
111
def withdisc(v, degree, D):
112
ans = []
113
for N in v:
114
for f in newforms(N):
115
if f.d == degree and f.disc % D == 0:
116
print f
117
ans.append(f)
118
if N%100==0:
119
print N
120
return ans
121
122
123
# 1 - x^2 - x^3 - x^4 + x^6 --> x^3 - 4*x - 1, disc 122
124
# 1 - x^3 - x^4 - x^5 + x^8 --> x^4 - 4*x^2 - x + 1 disc 1957
125
# 1 + x - x^3 - x^4 - x^5 - x^6 - x^7 + x^9 + x^10 --> x^5 + x^4 - 5*x^3 - 5*x^2 + 4*x + 3 disc 36497
126
127
128
def convert(Nstart, Nstop, recompute=False):
129
for N in range(Nstart, Nstop):
130
print N
131
try:
132
newforms(N, recompute=recompute)
133
except:
134
print "Error for N=",N
135
136
137