CoCalc Public Fileswww / cgi-bin / mfd / magma.py
Author: William A. Stein
Compute Environment: Ubuntu 18.04 (Deprecated)
1
#
2
# magma.py -- compute things using system calls to MAGMA
3
#
4
# William Stein, 10/30/2000
5
#
6
7
import os, string
8
import misc, constants
9
10
MAGMA='%s/gomagma'%constants.bin
11
12
def magma(cmd, gocmd=MAGMA):
13
cmd=cmd+";"
14
file = misc.newtempfile()
15
outname = misc.newtempfilename()
16
cmd = 'Attach("/var/www/%s/magma.m");\n'%constants.CGIROOT + cmd
17
cmd = cmd + 'if not assigned ans then ans := \$1; end if; \n fprintf Open(\"' + outname + '\","w"), \"%o\", ans;'
18
file.write(cmd)
19
file.close()
20
os.system(MAGMA + ' < ' + file.name + ' > %s/magma.errors'%constants.home )
21
if not os.path.exists(outname):
22
return "An error occured while running the computation. "+\
23
24
"If you're sure that it is valid but the computation still "+\
25
"won't run, you may want to email "+\
26
"William Stein at <a href=\"mailto:[email protected]\">"+\
27
"[email protected]</a>.";
28
ansfile = open(outname,'r')
29
30
ansfile.close()
31
os.remove(file.name)
32
os.remove(ansfile.name)
33
return ans
34
35
def genusX0(N):
36
cmd = "ans := DimensionCuspFormsGamma0(" + str(N) + ",2);ans;";
37
return magma(cmd)
38
39
def dimension_cuspforms_gamma0(N,k):
40
cmd = "ans := DimensionCuspFormsGamma0(%s, %s);ans;"%(N,k);
41
return magma(cmd)
42
43
def dimension_new_cuspforms_gamma0(N,k):
44
cmd = "ans := DimensionNewCuspFormsGamma0(%s, %s);ans;"%(N,k);
45
return magma(cmd)
46
47
def dimension_cuspforms(N,k,eps):
48
if eps == "1":
49
return dimension_cuspforms_gamma0(N,k)
50
cmd = "eps := DirichletGroup(%s,CyclotomicField(EulerPhi(%s)))!%s; "%(N,N,eps) + \
51
"ans := DimensionCuspForms(eps, %s);ans;"%k;
52
return magma(cmd)
53
54
def dimension_new_cuspforms(N,k,eps):
55
if eps == "1":
56
return dimension_new_cuspforms_gamma0(N,k)
57
cmd = "eps := DirichletGroup(%s,CyclotomicField(EulerPhi(%s)))!%s; "%(N,N,eps) + \
58
"ans := DimensionNewCuspForms(eps, %s);ans;"%k;
59
return magma(cmd)
60
61
def charpoly_gamma0(N,k,p):
62
cmd = "N := " + str(N) + "; k := " + str(k) + "; p := " + str(p) + ";" +\
63
"""R<x> := PolynomialRing(Rationals());
64
M := ModularSymbols(N,k,+1);
65
S := CuspidalSubspace(M);
66
ans := CharacteristicPolynomialOfHeckeOperator(S,p :
67
Proof := false);
68
"""
69
return magma(cmd)
70
71
def character_data(N):
72
cmd = 'N := '+str(N)+';\n'+\
73
'G := DirichletGroup(N, CyclotomicField(EulerPhi(N)));\n'+\
74
'C := GaloisConjugacyRepresentatives(G);\n'+\
75
'ans := [<N, Eltseq(e), Order(e), Conductor(e), '+\
76
' IsEven(e) select 1 else -1> : e in C];';
77
out = magma(cmd)
78
out = string.replace(out,'\n','')
79
out = string.replace(out,'[<','')
80
out = string.replace(out,'>]','')
81
out = string.replace(out,' ','')
82
dat = string.split(out,'>,<')
83
ans = []
84
for d in dat:
85
eps = [str(N)]
86
dd = d[string.find(d,'['):]
87
s = string.find(dd,']')+1
88
eps.append(dd[:s])
89
dd = dd[s+1:]
90
for r in string.split(dd,','):
91
eps.append(r)
92
ans.append(eps)
93
ans[0][1] = '1'
94
return ans
95
96
def aplist_to_qexpansion(aplist, N, k, eps, prec):
97
cmd = 'R<x> := PolynomialRing(RationalField());\n' + \
98
'ans := aplist_to_qexpansion(%s,%s,%s,%s,%s);\n'%(aplist,N,k,eps,prec)
99
return magma(cmd)
100
101
# an eight tuple: [order_of_root, num_twists, generators, fixed_field, fixed_degree, hilbert_sym, endo_alg, has_cm]
102
103
def inner_twists_data(N, aplist):
104
cmd = 'a := %s; ans := inner_twists_data(%s,a[1],a[3],a[2]);\n'%(aplist,N)
105
data = magma(cmd)
106
data = string.replace(data,'\n','')
107
data = string.split(data,'|')
108
data[2] = string.replace(data[2],' ','')
109
data[6] = string.replace(data[6],' ','')
110
return data
111
112
113
def aplist_to_q_integral_basis(aplist, N, k, eps, prec):
114
cmd = 'R<x> := PolynomialRing(RationalField());\n' + \
115
'ans := aplist_to_q_integral_basis(%s,%s,%s,%s,%s);\n'%(aplist,N,k,eps,prec)
116
data = magma(cmd)
117
data = data[:-1]
118
data = string.replace(data,'\n','')
119
data = string.replace(data,'[','')
120
data = string.replace(data,']','')
121
data = string.split(data,'|')
122
return data
123
124
def index_in_saturation(N1, N2, B):
125
BB = '['
126
for i in range(len(B)):
127
BB = BB + str(B[i])
128
if i < len(B)-1:
129
BB = BB + ', '
130
BB = BB + ']'
131
cmd = 'R<q> := PowerSeriesRing(Integers()); \n' + \
132
'ans := Invariants(IndexGroupInSaturation(%s*%s,%s) );\n'%(N1,N2,BB)
133
return magma(cmd)
134
135
def congruence_group(N1, N2, B1, B2):
136
return index_in_saturation(N1, N2, B1+B2)
137
138
def torsion_upper_bound(aplist, N, prec):
139
cmd = 'R<x> := PolynomialRing(RationalField());\n' + \
140
'ans := torsion_upper_bound(%s,%s,%s);\n'%(aplist,N,prec) + \
141
'print "ans = ", ans;\n'
142
return magma(cmd)
143
144
145