CoCalc Shared Filesbook / worksheets / 2017-02-21-135304-convergence.sagews
Author: William A. Stein
Views : 5
%md

$$g(t) = \sum \frac{\log(p)}{p^{n/2}} \cdot \cos(t \log(p ^ n))$$


$g(t) = \sum \frac{\log(p)}{p^{n/2}} \cdot \cos(t \log(p ^ n))$

p = next_prime(10^5)
N(log(p) / sqrt(p) * cos(14*log(p)))

-0.0208754130333620
%time
def data(F, B):
print F
v       = prime_powers(B)
f       = [factor(pn)[0] for pn in v]
v       = [F(pn) for pn in v]
P_log   = [F(p).log() for p,_ in f]
Pn_log  = [pn.log()   for pn in v]
Pn_sqrt = [pn.sqrt()  for pn in v]
#print P_log
#print Pn_sqrt
#print Pn_log

def g(t):
t = F(t)
s = F(0)
for i in range(len(v)):
s += P_log[i]/Pn_sqrt[i] * (t*Pn_log[i]).cos()
return -s

return g

CPU time: 0.00 s, Wall time: 0.00 s
def maxval(v):
ymax = 0
xmax = 0
for x, y in v:
if y > ymax:
xmax = x
ymax = y
return xmax

F = RDF
%time
for i in [1..6]:
g = data(RDF, 10^i)
print "10^%s"%i, maxval([(t, g(t)) for t in [13,F(13+1/100), .., 15]])

Real Double Field 10^1 14.05 Real Double Field 10^2 14.15 Real Double Field 10^3 14.23 Real Double Field 10^4 14.14 Real Double Field 10^5 14.06 Real Double Field 10^6 13.99 CPU time: 8.43 s, Wall time: 8.52 s
F = RealField(200)
for i in [1..5]:
g = data(F, 10^i)
print "10^%s"%i, maxval([(t, g(t)) for t in [13,F(13+1/100), .., 15]])

Real Field with 200 bits of precision 10^1 14.050000000000000000000000000000000000000000000000000000000 Real Field with 200 bits of precision 10^2 14.150000000000000000000000000000000000000000000000000000000 Real Field with 200 bits of precision 10^3 14.230000000000000000000000000000000000000000000000000000000 Real Field with 200 bits of precision 10^4 14.140000000000000000000000000000000000000000000000000000000 Real Field with 200 bits of precision 10^5 14.060000000000000000000000000000000000000000000000000000000
from math import cos, log, sqrt
sum(cos(log(m)) / sqrt(m) for m in [1..1000000])

885.5699235970652