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