CoCalc Shared Fileswww / cgi-bin / mfd / mfd_pullin.py
Author: William A. Stein
1# mfd_pullin.py -- code concerned with pulling data into mfd from
2#                  the "Magma Database" and elsewhere.
3
4import constants, mfd, misc, os, pari, string
5
6def mdb_newform_weight2(N):
7    M = mfd.ModSym(N,2)
8    if M.howmany_iso_classes() > 0:
9        f = M.get_iso_class(1)
10        if f.tamagawa_numbers_odd() != constants.not_computed:
11            print "Level",N," probably already pulled in, so skipping."
12            #return
13
14    mdb = os.popen2("mdb -k newform_weight2")
15    mdb[0].write(str(N))
16    mdb[0].close()
18    data = string.replace(data,' ','')
19    data = string.replace(data,'\n','')
20
21    iso_class = 0
22    i = string.find(data,'<')
23    while i != -1:
24        iso_class = iso_class + 1
25        data = data[i+1:]
26        j = string.find(data,',');  d = data[:j]; data = data[j+1:]
27        j = string.find(data,'],'); wq = data[:j+1]; data = data[j+2:]
28        j = string.find(data,',');  L = data[:j]; data = data[j+1:]
29        j = string.find(data,',');  T_upper = data[:j]; data = data[j+1:]
30        j = string.find(data,',');  T_lower = data[:j]; data = data[j+1:]
31        j = string.find(data,',');  sha_lower = data[:j]; data = data[j+1:]
32        j = string.find(data,',');  degphi = data[:j]; data = data[j+1:]
33        j = string.find(data,'],');  cplist = data[:j+1]; data = data[j+2:]
34        label = "%s%s"%(N,misc.ToIsogenyCode(iso_class))
35        print "----%s----"%label
36        print "d       = ", d
37        print "wq      = ", wq
38        print "L       = ", L
39        print "T_upper = ", T_upper
40        print "T_lower = ", T_lower
41        print "sha_low = ", sha_lower
42        print "degphi  = ", degphi
43        print "cplist  = ", cplist;
44        f = mfd.ModSym(N,2,iso_class)
45        if f.aplist_maxp() == constants.not_computed:
46            print "WARNING: aplist not known!"
47
48        if f.dimension() != int(d):
49            print "ERROR: Dimension mismatch!"
50            return
51
52        if f.atkin_lehner() != constants.not_computed:
53            if f.atkin_lehner() != wq:
54                print "ERROR: Atkin-Lehner mismatch!"
55                return
56        else:
57            f.set_atkin_lehner(wq)
58
59        if f.lratio_odd_k2() != constants.not_computed:
60            if f.lratio_odd_k2() != L:
61                print "ERROR: L-Ratio mismatch!"
62                return
63        else:
64            f.set_lratio_odd_k2(L)
65
66        if f.torsion_size() == constants.not_computed:
67            f.set_torsion_lower_bound(T_lower)
68            # DO NOT set the upper bound, because really it's only
69            # the odd part of the upper bound, hence bullshit!!
70            # f.set_torsion_upper_bound(T_upper)
71
72        if f.modular_degree_odd() != constants.not_computed:
73            if f.modular_degree_odd() != degphi:
74                print "ERROR: modular degree mismatch!"
75                return
76        else:
77            f.set_modular_degree_odd(degphi)
78
79        if f.tamagawa_numbers() == constants.not_computed and \
80           f.tamagawa_numbers_odd() == constants.not_computed:
81            tam=[]; k=0
82            cplist = string.replace(cplist,",","','")
83            cplist = string.replace(cplist,"[","['")
84            cplist = string.replace(cplist,"]","']")
85            cplist = eval(cplist)
86            for fac in pari.factor(N):
87                if fac[1] == 1:     # semistable primes
88                    tam.append(cplist[k])
89                    k=k+1
90                else:
91                    tam.append(0)
92            tam = string.replace(str(tam),"'","")
93            f.set_tamagawa_numbers_odd(tam)
94
95        if f.sha_an_odd_lower_bound() == constants.not_computed and sha_lower != "0":
96            f.set_sha_an_odd_lower_bound(sha_lower)
97
98        i = string.find(data,'<')
99
100
101def mdb_newform_weight2_torsion(N):
102    M = mfd.ModSym(N,2)
103    if M.howmany_iso_classes() > 0:
104        f = M.get_iso_class(1)
105        if f.torsion_odd_upper_bound() != constants.not_computed:
106            print "Level",N," already pulled in; (NOT) skipping."
107            return
108
109    mdb = os.popen2("mdb -k newform_weight2")
110    mdb[0].write(str(N))
111    mdb[0].close()
113    data = string.replace(data,' ','')
114    data = string.replace(data,'\n','')
115
116    iso_class = 0
117    i = string.find(data,'<')
118    while i != -1:
119        iso_class = iso_class + 1
120        data = data[i+1:]
121        j = string.find(data,',');  d = data[:j]; data = data[j+1:]
122        j = string.find(data,'],'); wq = data[:j+1]; data = data[j+2:]
123        j = string.find(data,',');  L = data[:j]; data = data[j+1:]
124        j = string.find(data,',');  T_upper = data[:j]; data = data[j+1:]
125        j = string.find(data,',');  T_lower = data[:j]; data = data[j+1:]
126        j = string.find(data,',');  sha_lower = data[:j]; data = data[j+1:]
127        j = string.find(data,',');  degphi = data[:j]; data = data[j+1:]
128        j = string.find(data,'],');  cplist = data[:j+1]; data = data[j+2:]
129        label = "%s%s"%(N,misc.ToIsogenyCode(iso_class))
130        print "----%s----"%label
131        print "T_upper = ", T_upper
132        f = mfd.ModSym(N,2,iso_class)
133        f.set_torsion_odd_upper_bound(T_upper)
134        i = string.find(data,'<')
135
136
137def compute_charpolys(N,k=2,maxp=17):
138    cmd = 'echo "[%s,%s,%s]" | mdb charpoly'%(N,k,maxp)
140    out = string.replace(out,"<","[")
141    out = string.replace(out,", x", ", 'x")
142    out = string.replace(out,", 1>",", '1>")
143    out = string.replace(out,">","']")
144    out = eval(out)
145    M = mfd.ModSym(N,k,0)
146    for dat in out:
147        M.set_charpoly(dat[0],dat[1])
148
149def j0n_torsion_bound(N):
150    cmd = 'echo "[%s,17]" | mdb torsion_bound'%N