From d7ab7f541f2a1a79f59759d80c99cc7f3d4d8b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 14 Dec 2025 09:40:03 +0100 Subject: [PATCH 1/3] a few minor details in special_values.py --- src/sage/quadratic_forms/special_values.py | 54 +++++++++------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/sage/quadratic_forms/special_values.py b/src/sage/quadratic_forms/special_values.py index 0b865877525..c27abf0d6b4 100644 --- a/src/sage/quadratic_forms/special_values.py +++ b/src/sage/quadratic_forms/special_values.py @@ -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 @@ -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:: @@ -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() @@ -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") @@ -147,17 +144,17 @@ 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) + 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: + if n == 1: return infinity - elif n == 0: + if n == 0: return QQ((-1, 2)) @@ -234,8 +231,8 @@ def quadratic_L_function__exact(n, d): - [Was1997]_ """ if n <= 0: - return QuadraticBernoulliNumber(1-n, d)/(n-1) - elif n >= 1: + return QuadraticBernoulliNumber(1 - n, d) / (n - 1) + if n >= 1: # Compute the kind of critical values (p10) if kronecker_symbol(fundamental_discriminant(d), -1) == 1: delta = 0 @@ -243,27 +240,22 @@ def quadratic_L_function__exact(n, d): delta = 1 # Compute the positive special values (p17) - if ((n - delta) % 2 == 0): - from sage.misc.functional import sqrt + if not (n - delta) % 2: 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 + 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) + 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)") + + 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)") def quadratic_L_function__numerical(n, d, num_terms=1000): From 9491657bbedac215f3f56ed236bc82c0f85aea61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 15 Dec 2025 16:19:57 +0100 Subject: [PATCH 2/3] suggested simplifications --- src/sage/quadratic_forms/special_values.py | 59 ++++++++++------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/sage/quadratic_forms/special_values.py b/src/sage/quadratic_forms/special_values.py index c27abf0d6b4..5c0b1415b8b 100644 --- a/src/sage/quadratic_forms/special_values.py +++ b/src/sage/quadratic_forms/special_values.py @@ -95,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)` @@ -152,10 +152,7 @@ def zeta__exact(n): 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)") - if n == 1: - return infinity - if n == 0: - return QQ((-1, 2)) + return infinity if n == 1 else QQ((-1, 2)) # ---------- Dirichlet L-functions with quadratic characters ---------- @@ -206,7 +203,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:: @@ -232,30 +229,30 @@ def quadratic_L_function__exact(n, d): """ if n <= 0: return QuadraticBernoulliNumber(1 - n, d) / (n - 1) - if 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)") - if delta == 1: - raise TypeError("n must be a critical value (i.e. odd > 0 or even <= 0)") + + # 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)") + if delta == 1: + 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): From 4e7490dc8a8f41dff8222817a22a79042ac78c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 15 Dec 2025 16:22:05 +0100 Subject: [PATCH 3/3] further simplifications --- src/sage/quadratic_forms/special_values.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/sage/quadratic_forms/special_values.py b/src/sage/quadratic_forms/special_values.py index 5c0b1415b8b..ed7619e616f 100644 --- a/src/sage/quadratic_forms/special_values.py +++ b/src/sage/quadratic_forms/special_values.py @@ -150,8 +150,7 @@ def zeta__exact(n): 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)") + raise TypeError("n must be a critical value (i.e. even > 0 or odd < 0)") return infinity if n == 1 else QQ((-1, 2)) @@ -251,8 +250,7 @@ def quadratic_L_function__exact(n, d): 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)") + 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):