Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 37 additions & 50 deletions src/sage/quadratic_forms/special_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
factorial,
fundamental_discriminant,
kronecker as kronecker_symbol)
from sage.misc.functional import denominator
from sage.rings.infinity import infinity
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
Expand All @@ -24,7 +23,7 @@

def gamma__exact(n):
r"""
Evaluates the exact value of the `\Gamma` function at an integer or
Return the exact value of the `\Gamma` function at an integer or
half-integer argument.

EXAMPLES::
Expand Down Expand Up @@ -67,14 +66,13 @@ def gamma__exact(n):
"""
n = QQ(n)

if denominator(n) == 1:
if n.denominator() == 1:
if n <= 0:
return infinity
return factorial(n - 1)

if denominator(n) == 2:
if n.denominator() == 2:
# now n = 1/2 + an integer
from sage.misc.functional import sqrt
from sage.symbolic.constants import pi

ans = QQ.one()
Expand All @@ -86,8 +84,7 @@ def gamma__exact(n):
n += -1
ans *= n

ans *= sqrt(pi)
return ans
return ans * pi.sqrt()

raise TypeError("you must give an integer or half-integer argument")

Expand All @@ -98,8 +95,8 @@ def zeta__exact(n):
r"""
Return the exact value of the Riemann Zeta function.

The argument must be a critical value, namely either positive even
or negative odd.
The argument `n` must be an integer which is a critical value,
namely either positive even or negative odd.

See for example [Iwa1972]_, p13, Special value of `\zeta(2k)`

Expand Down Expand Up @@ -147,18 +144,14 @@ def zeta__exact(n):
- [Was1997]_
"""
if n < 0:
return bernoulli(1-n)/(n-1)
elif n > 1:
if (n % 2 == 0):
return bernoulli(1 - n) / (n - 1)
if n > 1:
if not n % 2:
from sage.symbolic.constants import pi

return ZZ(-1)**(n//2 + 1) * ZZ(2)**(n-1) * pi**n * bernoulli(n) / factorial(n)
else:
raise TypeError("n must be a critical value (i.e. even > 0 or odd < 0)")
elif n == 1:
return infinity
elif n == 0:
return QQ((-1, 2))
return ZZ(-1)**(n // 2 + 1) * ZZ(2)**(n - 1) * pi**n * bernoulli(n) / factorial(n)
raise TypeError("n must be a critical value (i.e. even > 0 or odd < 0)")
return infinity if n == 1 else QQ((-1, 2))


# ---------- Dirichlet L-functions with quadratic characters ----------
Expand Down Expand Up @@ -209,7 +202,7 @@ def quadratic_L_function__exact(n, d):
Return the exact value of a quadratic twist of the Riemann Zeta function
by `\chi_d(x) = \left(\frac{d}{x}\right)`.

The input `n` must be a critical value.
The input `n` must be an integer which is a critical value.

EXAMPLES::

Expand All @@ -234,36 +227,30 @@ def quadratic_L_function__exact(n, d):
- [Was1997]_
"""
if n <= 0:
return QuadraticBernoulliNumber(1-n, d)/(n-1)
elif n >= 1:
# Compute the kind of critical values (p10)
if kronecker_symbol(fundamental_discriminant(d), -1) == 1:
delta = 0
else:
delta = 1

# Compute the positive special values (p17)
if ((n - delta) % 2 == 0):
from sage.misc.functional import sqrt
from sage.symbolic.constants import I, pi
from sage.symbolic.ring import SR

f = abs(fundamental_discriminant(d))
if delta == 0:
GS = sqrt(f)
else:
GS = I * sqrt(f)
ans = SR(ZZ(-1)**(1+(n-delta)/2))
ans *= (2*pi/f)**n
ans *= GS # Evaluate the Gauss sum here! =0
ans *= QQ.one()/(2 * I**delta)
ans *= QuadraticBernoulliNumber(n, d)/factorial(n)
return ans
else:
if delta == 0:
raise TypeError("n must be a critical value (i.e. even > 0 or odd < 0)")
if delta == 1:
raise TypeError("n must be a critical value (i.e. odd > 0 or even <= 0)")
return QuadraticBernoulliNumber(1 - n, d) / (n - 1)

# Compute the kind of critical values (p10)
if kronecker_symbol(fundamental_discriminant(d), -1) == 1:
delta = 0
else:
delta = 1

# Compute the positive special values (p17)
if not (n - delta) % 2:
from sage.symbolic.constants import I, pi

f = abs(fundamental_discriminant(d))
GS = f.sqrt() if delta == 0 else I * f.sqrt()
ans = (2 * pi / f)**n
ans *= ZZ(-1)**(1 + (n - delta) // 2)
ans *= GS # Evaluate the Gauss sum here! =0
ans *= QQ.one() / (2 * I**delta)
ans *= QuadraticBernoulliNumber(n, d) / factorial(n)
return ans

if delta == 0:
raise TypeError("n must be a critical value (i.e. even > 0 or odd < 0)")
raise TypeError("n must be a critical value (i.e. odd > 0 or even <= 0)")


def quadratic_L_function__numerical(n, d, num_terms=1000):
Expand Down
Loading