Path: blob/master/src/sage/quadratic_forms/special_values.py
8817 views
"""1Routines for computing special values of L-functions23- :func:`gamma__exact` -- Exact values of the `\Gamma` function at integers and half-integers4- :func:`zeta__exact` -- Exact values of the Riemann `\zeta` function at critical values5- :func:`quadratic_L_function__exact` -- Exact values of the Dirichlet L-functions of quadratic characters at critical values6- :func:`quadratic_L_function__numerical` -- Numerical values of the Dirichlet L-functions of quadratic characters in the domain of convergence7"""89from sage.combinat.combinat import bernoulli_polynomial10from sage.misc.functional import denominator11from sage.rings.all import RealField12from sage.rings.arith import kronecker_symbol, bernoulli, factorial, fundamental_discriminant13from sage.rings.infinity import infinity14from sage.rings.integer_ring import ZZ15from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing16from sage.rings.rational_field import QQ17from sage.rings.real_mpfr import is_RealField18from sage.symbolic.constants import pi19from sage.symbolic.pynac import I2021# ---------------- The Gamma Function ------------------2223def gamma__exact(n):24"""25Evaluates the exact value of the `\Gamma` function at an integer or26half-integer argument.2728EXAMPLES::2930sage: gamma__exact(4)31632sage: gamma__exact(3)33234sage: gamma__exact(2)35136sage: gamma__exact(1)3713839sage: gamma__exact(1/2)40sqrt(pi)41sage: gamma__exact(3/2)421/2*sqrt(pi)43sage: gamma__exact(5/2)443/4*sqrt(pi)45sage: gamma__exact(7/2)4615/8*sqrt(pi)4748sage: gamma__exact(-1/2)49-2*sqrt(pi)50sage: gamma__exact(-3/2)514/3*sqrt(pi)52sage: gamma__exact(-5/2)53-8/15*sqrt(pi)54sage: gamma__exact(-7/2)5516/105*sqrt(pi)5657TESTS::5859sage: gamma__exact(1/3)60Traceback (most recent call last):61...62TypeError: you must give an integer or half-integer argument63"""64from sage.all import sqrt65# SANITY CHECK66if (not n in QQ) or (denominator(n) > 2):67raise TypeError("you must give an integer or half-integer argument")6869if denominator(n) == 1:70if n <= 0:71return infinity72if n > 0:73return factorial(n-1)74else:75ans = QQ(1)76while (n != QQ(1)/2):77if n < 0:78ans *= QQ(1)/n79n += 180elif n > 0:81n += -182ans *= n8384ans *= sqrt(pi)85return ans8687# ------------- The Riemann Zeta Function --------------8889def zeta__exact(n):90r"""91Returns the exact value of the Riemann Zeta function9293The argument must be a critical value, namely either positive even94or negative odd.9596See for example [Iwasawa]_, p13, Special value of `\zeta(2k)`9798EXAMPLES:99100Let us test the accuracy for negative special values::101102sage: RR = RealField(100)103sage: for i in range(1,10):104... print "zeta(" + str(1-2*i) + "): ", RR(zeta__exact(1-2*i)) - zeta(RR(1-2*i))105zeta(-1): 0.00000000000000000000000000000106zeta(-3): 0.00000000000000000000000000000107zeta(-5): 0.00000000000000000000000000000108zeta(-7): 0.00000000000000000000000000000109zeta(-9): 0.00000000000000000000000000000110zeta(-11): 0.00000000000000000000000000000111zeta(-13): 0.00000000000000000000000000000112zeta(-15): 0.00000000000000000000000000000113zeta(-17): 0.00000000000000000000000000000114115Let us test the accuracy for positive special values::116117sage: all(abs(RR(zeta__exact(2*i))-zeta(RR(2*i))) < 10**(-28) for i in range(1,10))118True119120TESTS::121122sage: zeta__exact(5)123Traceback (most recent call last):124...125TypeError: n must be a critical value (i.e. even > 0 or odd < 0)126127REFERENCES:128129.. [Iwasawa] Iwasawa, *Lectures on p-adic L-functions*130.. [IreRos] Ireland and Rosen, *A Classical Introduction to Modern Number Theory*131.. [WashCyc] Washington, *Cyclotomic Fields*132"""133if n < 0:134return bernoulli(1-n)/(n-1)135elif n > 1:136if (n % 2 == 0):137return ZZ(-1)**(n/2 + 1) * ZZ(2)**(n-1) * pi**n * bernoulli(n) / factorial(n)138else:139raise TypeError("n must be a critical value (i.e. even > 0 or odd < 0)")140elif n==1:141return infinity142elif n==0:143return -1/2144145# ---------- Dirichlet L-functions with quadratic characters ----------146147def QuadraticBernoulliNumber(k, d):148r"""149Compute `k`-th Bernoulli number for the primitive150quadratic character associated to `\chi(x) = \left(\frac{d}{x}\right)`.151152EXAMPLES:153154Let us create a list of some odd negative fundamental discriminants::155156sage: test_set = [d for d in range(-163, -3, 4) if is_fundamental_discriminant(d)]157158In general, we have `B_{1, \chi_d} = -2 h/w` for odd negative fundamental159discriminants::160161sage: all(QuadraticBernoulliNumber(1, d) == -len(BinaryQF_reduced_representatives(d)) for d in test_set)162True163164REFERENCES:165166- [Iwasawa]_, pp 7-16.167"""168# Ensure the character is primitive169d1 = fundamental_discriminant(d)170f = abs(d1)171172# Make the (usual) k-th Bernoulli polynomial173x = PolynomialRing(QQ, 'x').gen()174bp = bernoulli_polynomial(x, k)175176# Make the k-th quadratic Bernoulli number177total = sum([kronecker_symbol(d1, i) * bp(i/f) for i in range(f)])178total *= (f ** (k-1))179180return total181182def quadratic_L_function__exact(n, d):183r"""184Returns the exact value of a quadratic twist of the Riemann Zeta function185by `\chi_d(x) = \left(\frac{d}{x}\right)`.186187The input `n` must be a critical value.188189EXAMPLES::190191sage: quadratic_L_function__exact(1, -4)1921/4*pi193sage: quadratic_L_function__exact(-4, -4)1945/2195196TESTS::197198sage: quadratic_L_function__exact(2, -4)199Traceback (most recent call last):200...201TypeError: n must be a critical value (i.e. odd > 0 or even <= 0)202203REFERENCES:204205- [Iwasawa]_, pp 16-17, Special values of `L(1-n, \chi)` and `L(n, \chi)`206- [IreRos]_207- [WashCyc]_208"""209from sage.all import SR, sqrt210if n <= 0:211return QuadraticBernoulliNumber(1-n,d)/(n-1)212elif n >= 1:213# Compute the kind of critical values (p10)214if kronecker_symbol(fundamental_discriminant(d), -1) == 1:215delta = 0216else:217delta = 1218219# Compute the positive special values (p17)220if ((n - delta) % 2 == 0):221f = abs(fundamental_discriminant(d))222if delta == 0:223GS = sqrt(f)224else:225GS = I * sqrt(f)226ans = SR(ZZ(-1)**(1+(n-delta)/2))227ans *= (2*pi/f)**n228ans *= GS # Evaluate the Gauss sum here! =0229ans *= 1/(2 * I**delta)230ans *= QuadraticBernoulliNumber(n,d)/factorial(n)231return ans232else:233if delta == 0:234raise TypeError("n must be a critical value (i.e. even > 0 or odd < 0)")235if delta == 1:236raise TypeError("n must be a critical value (i.e. odd > 0 or even <= 0)")237238def quadratic_L_function__numerical(n, d, num_terms=1000):239"""240Evaluate the Dirichlet L-function (for quadratic character) numerically241(in a very naive way).242243EXAMPLES:244245First, let us test several values for a given character::246247sage: RR = RealField(100)248sage: for i in range(5):249... 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)250L(1, (-4/.)): 0.000049999999500000024999996962707251L(3, (-4/.)): 4.99999970000003...e-13252L(5, (-4/.)): 4.99999922759382...e-21253L(7, (-4/.)): ...e-29254L(9, (-4/.)): ...e-29255256This procedure fails for negative special values, as the Dirichlet257series does not converge here::258259sage: quadratic_L_function__numerical(-3,-4, 10000)260Traceback (most recent call last):261...262ValueError: the Dirichlet series does not converge here263264Test for several characters that the result agrees with the exact265value, to a given accuracy ::266267sage: for d in range(-20,0): # long time (2s on sage.math 2014)268....: if abs(RR(quadratic_L_function__numerical(1, d, 10000) - quadratic_L_function__exact(1, d))) > 0.001:269....: 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))270"""271# Set the correct precision if it is given (for n).272if is_RealField(n.parent()):273R = n.parent()274else:275R = RealField()276277if n < 0:278raise ValueError('the Dirichlet series does not converge here')279280d1 = fundamental_discriminant(d)281ans = R(0)282for i in range(1,num_terms):283ans += R(kronecker_symbol(d1,i) / R(i)**n)284return ans285286287