Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/quadratic_forms/special_values.py
4058 views
1
"""
2
Routines for computing special values of L-functions
3
"""
4
5
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
6
from sage.rings.arith import kronecker_symbol, bernoulli, factorial, fundamental_discriminant
7
from sage.rings.all import RealField
8
from sage.combinat.combinat import bernoulli_polynomial
9
from sage.rings.rational_field import QQ
10
from sage.rings.integer_ring import ZZ
11
from sage.symbolic.constants import pi
12
from sage.symbolic.pynac import I
13
from sage.rings.real_mpfr import is_RealField
14
from sage.misc.functional import denominator
15
from sage.rings.infinity import infinity
16
17
18
## ---------------- The Gamma Function ------------------
19
20
def gamma__exact(n):
21
"""
22
Evaluates the exact value of the gamma function at an integer or
23
half-integer argument.
24
25
EXAMPLES::
26
27
sage: gamma__exact(4)
28
6
29
sage: gamma__exact(3)
30
2
31
sage: gamma__exact(2)
32
1
33
sage: gamma__exact(1)
34
1
35
36
sage: gamma__exact(1/2)
37
sqrt(pi)
38
sage: gamma__exact(3/2)
39
1/2*sqrt(pi)
40
sage: gamma__exact(5/2)
41
3/4*sqrt(pi)
42
sage: gamma__exact(7/2)
43
15/8*sqrt(pi)
44
45
sage: gamma__exact(-1/2)
46
-2*sqrt(pi)
47
sage: gamma__exact(-3/2)
48
4/3*sqrt(pi)
49
sage: gamma__exact(-5/2)
50
-8/15*sqrt(pi)
51
sage: gamma__exact(-7/2)
52
16/105*sqrt(pi)
53
54
"""
55
from sage.all import sqrt
56
## SANITY CHECK
57
if (not n in QQ) or (denominator(n) > 2):
58
raise TypeError, "Oops! You much give an integer or half-integer argument."
59
60
if (denominator(n) == 1):
61
if n <= 0:
62
return infinity
63
if n > 0:
64
return factorial(n-1)
65
else:
66
ans = QQ(1)
67
while (n != QQ(1)/2):
68
if (n<0):
69
ans *= QQ(1)/n
70
n = n + 1
71
elif (n>0):
72
n = n - 1
73
ans *= n
74
75
ans *= sqrt(pi)
76
return ans
77
78
79
80
## ------------- The Riemann Zeta Function --------------
81
82
def zeta__exact(n):
83
r"""
84
Returns the exact value of the Riemann Zeta function
85
86
References:
87
88
- Iwasawa's "Lectures on p-adic L-functions", p13, "Special value of `\zeta(2k)`"
89
- Ireland and Rosen's "A Classical Introduction to Modern Number Theory"
90
- Washington's "Cyclotomic Fields"
91
92
EXAMPLES::
93
94
sage: ## Testing the accuracy of the negative special values
95
sage: RR = RealField(100)
96
sage: for i in range(1,10):
97
... print "zeta(" + str(1-2*i) + "): ", RR(zeta__exact(1-2*i)) - zeta(RR(1-2*i))
98
zeta(-1): 0.00000000000000000000000000000
99
zeta(-3): 0.00000000000000000000000000000
100
zeta(-5): 0.00000000000000000000000000000
101
zeta(-7): 0.00000000000000000000000000000
102
zeta(-9): 0.00000000000000000000000000000
103
zeta(-11): 0.00000000000000000000000000000
104
zeta(-13): 0.00000000000000000000000000000
105
zeta(-15): 0.00000000000000000000000000000
106
zeta(-17): 0.00000000000000000000000000000
107
108
sage: RR = RealField(100)
109
sage: for i in range(1,10):
110
... print "zeta(" + str(1-2*i) + "): ", RR(zeta__exact(1-2*i)) - zeta(RR(1-2*i))
111
zeta(-1): 0.00000000000000000000000000000
112
zeta(-3): 0.00000000000000000000000000000
113
zeta(-5): 0.00000000000000000000000000000
114
zeta(-7): 0.00000000000000000000000000000
115
zeta(-9): 0.00000000000000000000000000000
116
zeta(-11): 0.00000000000000000000000000000
117
zeta(-13): 0.00000000000000000000000000000
118
zeta(-15): 0.00000000000000000000000000000
119
zeta(-17): 0.00000000000000000000000000000
120
121
"""
122
if n<0:
123
k = 1-n
124
return -bernoulli(k)/k
125
elif n>1:
126
if (n % 2 == 0):
127
return ZZ(-1)**(n/2 + 1) * ZZ(2)**(n-1) * pi**n * bernoulli(n) / factorial(n)
128
else:
129
raise TypeError, "n must be a critical value! (I.e. even > 0 or odd < 0.)"
130
elif n==1:
131
return infinity
132
elif n==0:
133
return -1/2
134
135
## ---------- Dirichlet L-functions with quadratic characters ----------
136
137
def QuadraticBernoulliNumber(k, d):
138
r"""
139
Compute k-th Bernoulli number for the primitive
140
quadratic character associated to `\chi(x) = \left(\frac{d}{x}\right)`.
141
142
Reference: Iwasawa's "Lectures on p-adic L-functions", pp7-16.
143
144
EXAMPLES::
145
146
sage: ## Makes a set of odd fund discriminants < -3
147
sage: Fund_odd_test_set = [D for D in range(-163, -3, 4) if is_fundamental_discriminant(D)]
148
149
sage: ## In general, we have B_{1, \chi_d} = -2h/w for odd fund disc < 0
150
sage: for D in Fund_odd_test_set:
151
... if len(BinaryQF_reduced_representatives(D)) != -QuadraticBernoulliNumber(1, D):
152
... print "Oops! There is an error at D = ", D
153
"""
154
## Ensure the character is primitive
155
d1 = fundamental_discriminant(d)
156
f = abs(d1)
157
158
## Make the (usual) k-th Bernoulli polynomial
159
x = PolynomialRing(QQ, 'x').gen()
160
bp = bernoulli_polynomial(x, k)
161
162
## Make the k-th quadratic Bernoulli number
163
total = sum([kronecker_symbol(d1, i) * bp(i/f) for i in range(f)])
164
total *= (f ** (k-1))
165
166
return total
167
168
169
def quadratic_L_function__exact(n, d):
170
r"""
171
Returns the exact value of a quadratic twist of the Riemann Zeta function
172
by `\chi_d(x) = \left(\frac{d}{x}\right)`.
173
174
References:
175
176
- Iwasawa's "Lectures on p-adic L-functions", p16-17, "Special values of
177
`L(1-n, \chi)` and `L(n, \chi)`
178
- Ireland and Rosen's "A Classical Introduction to Modern Number Theory"
179
- Washington's "Cyclotomic Fields"
180
181
EXAMPLES::
182
183
sage: bool(quadratic_L_function__exact(1, -4) == pi/4)
184
True
185
186
"""
187
from sage.all import SR, sqrt
188
if n<=0:
189
k = 1-n
190
return -QuadraticBernoulliNumber(k,d)/k
191
elif n>=1:
192
## Compute the kind of critical values (p10)
193
if kronecker_symbol(fundamental_discriminant(d), -1) == 1:
194
delta = 0
195
else:
196
delta = 1
197
198
## Compute the positive special values (p17)
199
if ((n - delta) % 2 == 0):
200
f = abs(fundamental_discriminant(d))
201
if delta == 0:
202
GS = sqrt(f)
203
else:
204
GS = I * sqrt(f)
205
ans = SR(ZZ(-1)**(1+(n-delta)/2))
206
ans *= (2*pi/f)**n
207
ans *= GS ## Evaluate the Gauss sum here! =0
208
ans *= 1/(2 * I**delta)
209
ans *= QuadraticBernoulliNumber(n,d)/factorial(n)
210
return ans
211
else:
212
if delta == 0:
213
raise TypeError, "n must be a critical value!\n" + "(I.e. even > 0 or odd < 0.)"
214
if delta == 1:
215
raise TypeError, "n must be a critical value!\n" + "(I.e. odd > 0 or even <= 0.)"
216
217
218
219
def quadratic_L_function__numerical(n, d, num_terms=1000):
220
"""
221
Evaluate the Dirichlet L-function (for quadratic character) numerically
222
(in a very naive way).
223
224
EXAMPLES::
225
226
sage: ## Test several values for a given character
227
sage: RR = RealField(100)
228
sage: for i in range(5):
229
... print "L(" + str(1+2*i) + ", (-4/.)): ", RR(quadratic_L_function__exact(1+2*i, -4)) - quadratic_L_function__numerical(RR(1+2*i),-4, 10000)
230
L(1, (-4/.)): 0.000049999999500000024999996962707
231
L(3, (-4/.)): 4.99999970000003...e-13
232
L(5, (-4/.)): 4.99999922759382...e-21
233
L(7, (-4/.)): ...e-29
234
L(9, (-4/.)): ...e-29
235
236
sage: ## Testing the accuracy of the negative special values
237
sage: ## ---- THIS FAILS SINCE THE DIRICHLET SERIES DOESN'T CONVERGE HERE! ----
238
239
sage: ## Test several characters agree with the exact value, to a given accuracy.
240
sage: for d in range(-20,0):
241
... if abs(RR(quadratic_L_function__numerical(1, d, 10000) - quadratic_L_function__exact(1, d))) > 0.001:
242
... print "Oops! We have a problem at d = ", d, " exact = ", RR(quadratic_L_function__exact(1, d)), " numerical = ", RR(quadratic_L_function__numerical(1, d))
243
...
244
245
"""
246
## Set the correct precision if it's given (for n).
247
if is_RealField(n.parent()):
248
R = n.parent()
249
else:
250
R = RealField()
251
252
d1 = fundamental_discriminant(d)
253
ans = R(0)
254
for i in range(1,num_terms):
255
ans += R(kronecker_symbol(d1,i) / R(i)**n)
256
return ans
257
258