-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lambda.py
307 lines (253 loc) · 8.2 KB
/
Lambda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
from sage.misc.all import cputime
from sage.rings.all import Integer, ZZ
from psage.number_fields.sqrt5 import *
from psage.ellcurve.lseries.aplist_sqrt5 import aplist
from psage.modform.hilbert.sqrt5.hmf import *
import mpmath
R=RealField(170)
sigma2, sigma = F.embeddings(RR)
phi = R(sigma(a))
phibar = R(sigma2(a))
#V is an EllipticCurveFactor
def Lambda(V,r, bound=300):
"""
INPUT:
- V is an EllipticCurveFactor
- r is a whole number
- bound?
OUTPUT:
- value of the completed L-function at 1
"""
if r==1:
return Lambda1(V,bound)
elif r==2:
return Lambda2(V,bound)
def Lambda1(V, bound):
N = make_tot_pos(V.conductor().gens_reduced()[0])
anlist = anlist_(V, bound)
rootN = R(sqrt(sigma(N)))
rootNbar = R(sqrt(sigma2(N)))
rootD = R(sqrt(5)) #specific to our F
D = 5 #specific to our F
PI = R(pi)
S = R(0)
for (norm, n, nbar, an) in anlist:
X = 0
for k in srange(-10, 10):
A = R(2 * PI * n * phi^(2*k + 1)/(rootN * rootD))
B = R(-2 * PI * nbar * phibar^(2*k + 1)/(rootNbar * rootD))
X = X + (-log(phi)*G(0,A)*G(0,B/phi)+G(0,A)*G(1,B/phi)+G(1,A)*G(0,B/phi)-log(phi)*G(0,A)*G(0,B*phi)-G(0,A)*G(1,B*phi)-G(1,A)*G(0,B*phi))/(A*B)
S = S + an*X
#print norm, S
#sys.stdout.flush()
return 2 * S
def Lambda2(V, bound):
N = make_tot_pos(V.conductor().gens_reduced()[0])
anlist = anlist_(V, bound)
rootN = R(sqrt(sigma(N)))
rootNbar = R(sqrt(sigma2(N)))
rootD = R(sqrt(5)) #specific to our F
D = 5 #specific to our F
PI = R(pi)
S = R(0)
for (norm, n, nbar, an) in anlist:
X = 0
for k in srange(-15, 15):
A = R(2 * PI * n * phi^(2*k + 1)/(rootN * rootD))
B = R(-2 * PI * nbar * phibar^(2*k + 1)/(rootNbar * rootD))
X = X + (-log(phi)*G(0,A)*G(1,B/phi)-log(phi)*G(1,A)*G(0,B/phi)+G(0,A)*G(2,B/phi)+G(1,A)*G(1,B/phi)+G(2,A)*G(0,B/phi)-log(phi)*G(0,A)*G(1,B*phi)-log(phi)*G(1,A)*G(0,B*phi)-G(0,A)*G(2,B*phi)-G(1,A)*G(1,B*phi)-G(2,A)*G(0,B/phi))/(A*B)
S = S + an*X
#print norm, S
#sys.stdout.flush()
return 4 * S
def make_tot_pos(n):
"""
Given an element n of Q(sqrt5), return a totally positive unit multiple
of n; i.e. return m such that m/n is a unit and m is taken to a positive
number under both embeddings of K into R.
"""
if sigma(n) > 0:
if sigma2(n) < 0:
return n * a
else:
return n
else:
if sigma2(n) < 0:
return n * a * (1 - a)
else:
return n * (1 - a)
def apn(a, p, n):
"""
This is a little silly, and we should do this better.
"""
if n == 0:
return 0
if n == 1:
return a
if n == 2:
return a^2 - p
if n == 3:
return a^3 - 2*a*p
if n == 4:
return a^4 - 3*a^2*p + p^2
if n == 5:
return a^5 - 4*a^3*p + 3*a*p^2
if n == 6:
return a^6 - 5*a^4*p + 6*a^2*p^2 - p^3
if n == 7:
return a^7 - 6*a^5*p + 10*a^3*p^2 - 4*a*p^3
if n == 8:
return a^8 - 7*a^6*p + 15*a^4*p^2 - 10*a^2*p^3 + p^4
if n == 9:
return a^9 - 8*a^7*p + 21*a^5*p^2 - 20*a^3*p^3 + 5*a*p^4
if n == 10:
return a^10 - 9*a^8*p + 28*a^6*p^2 - 35*a^4*p^3 + 15*a^2*p^4 - p^5
def anlist_(V, bound=2000):
level = V.conductor()
primes = [make_tot_pos(p.sage_ideal().gens_reduced()[0]) for p in primes_of_bounded_norm(bound)]
aps = V.aplist(bound)
bad_primes = [ [p.norm(), sigma(p), sigma2(p), ap] for p, ap in zip(primes, aps) if F.ideal(p).divides(level)]
primes = [ [p.norm(), sigma(p), sigma2(p), ap] for p, ap in zip(primes, aps)]
prime_powers = [ [p,] for p in primes]
for P in prime_powers:
norm = P[0][0]
ap = P[0][3]
if P[0] in bad_primes:
while P[0][0] * P[-1][0] < bound:
P.append( [x*y for (x,y) in zip(P[0], P[-1])] )
else:
while P[0][0] * P[-1][0] < bound:
P.append( [x*y for (x,y) in zip(P[0], P[-1])] )
for n in range(len(P)):
P[n][3] = apn(ap, norm, n+1)
L = [[1, 1.0, 1.0, 1]]
for P in prime_powers:
L2 = [l for l in L]
for p in P:
for n in L:
if n[0] * p[0] < bound:
L2.append([x*y for (x,y) in zip(p,n)])
else:
break
L2.sort()
L = L2
return L
#I found some code in Gr_series.py
def Qr_poly(r, R=RDF):
"""
Q_r(t) polynomial from AMEC p.44
"""
Rt,t = PolynomialRing(R, 't').objgen()
if r==0:
return Rt(1)
if r==1:
return t
tt = PowerSeriesRing(R, 'tt').gen()
ps = sum((-1)**n * zeta(R(n))/n * tt**n for n in range(2,r+1)).exp(r+1)
return sum( ps[r-i] * t**i/factorial(i) for i in range(0,r+1) )
def Pr_poly(r, R=RDF):
"""
P_r(t) polynomial from AMEC p.44
"""
Qr = Qr_poly(r, R)
t = parent(Qr).gen()
gamma = R(euler_gamma)
return Qr(t-gamma)
#This was in Gr_series.py, but Cohen says not to use this for x>10, instead I implemented what Cremona implemented in C++
#def Gr_series(r, R=RDF, prec=None, MAX=20):
# """
# power series part of G_r(x), defined as
# .. math::
#
# CG_r(x) = \sum_{n=1}^{\infty} \frac{{-1}^{n-r}}{n^r\cdot n!}\,x^n
#
# see AMEC p.44
# """
# t = cputime()
# MAX = R(MAX)
# x = PowerSeriesRing(R, 'x').gen()
# if prec is None:
# ser = 0
# ser_max = R(0)
# for n in range(1, 1000):
# ser += (-x)**n / (-n)**r / factorial(n)
# next = ser(MAX)
# # test if the last term makes a difference for evaluating at MAX
# if next == ser_max:
# verbose("Computed Gr_series(%d) to precision %d" % (r,n), t)
# return ser + O(x**n)
# ser_max = next
# else:
# raise RuntimeError, "Reached end of loop in Gr_series!"
# else:
# return sum( (-x)**n / (-n)**r / factorial(n) for n in range(1,prec)) + O(x**prec)
def is_approx_zero(x):
return abs(x) < 10^(-20)
def CG(r,x): #Cohen's G_r(x), used for small x
emx=exp(-x)
ans=x
term=x
Av=[1]
for j in [1..r]:
Av.append(1)
n=1
while (not is_approx_zero(emx*term*Av[r])):
n += 1
for j in [1..r]:
Av[j] += (Av[j-1]/n) #update Av vector
term *= (x/n)
ans += (Av[r]*term)
return emx*ans
# Slow...
def Gsmall(r, x):
"""
G_r function, defined as G_r(x) = P_r(-log(x)) + CG_r(x)
"""
R = parent(x)
return Pr_poly(r, R) (x) + GC(r,x)
@cached_function
def Gsmall_fast_float(r, MAX=20):
from sage.ext.fast_eval import fast_float_arg, fast_float_constant, fast_float_func
x = fast_float_arg(0)
return Pr_poly(r, RDF) (-log(x)) + CG(r,x)
# precache G_0, G_1, G_2, G_3, G_4
Gsmall_fast_float(0)
Gsmall_fast_float(1)
Gsmall_fast_float(2)
Gsmall_fast_float(3)
Gsmall_fast_float(4)
def G(r,x):
"""
INPUT:
- r is a whole number, G(r,x) is used to compute the r^th derivative
- x is a real number
OUTPUT:
- the value of Cohen's Gamma_r(1,x), choosing how to compute it depending on how large x is and using an implemented function when r=0, 1
"""
if r==0:
return (-x).exp()
elif r==1:
E1 = lambda t : RR(mpmath.expint(1, t)) #E1 = exponential_integral_1
return E1(x)
elif 0 < x < 50:
return Gsmall(r,x)
elif x >= 50:
return Glarge(r,x)
else:
raise ValueError, "Everything should be totally positive, but there is a negative value of x coming up"
#The choice of x < 50 should be appropriate to get Gamma_r to 18 significant digits, see discussion on page 582.
def Glarge(r,x): #Cohen's Gamma_r(x) for large x
emx=exp(-x)
ans=0
term=-1/x
Cv=[1]
for j in [1..r]:
Cv.append(0)
n=0
while (not is_approx_zero(emx*term)):
n = n + 1
for j in [1..r]:
Cv[-j] = Cv[-j] + (Cv[-j-1]/n) #update Cv vector
term = term * (-n/x)
ans = ans + (Cv[r]*term)
return 2*emx*ans