Description
Description
This RFC proposes adding the Hurwitz zeta function, ζ(s, q) = Σ_{k≥0} (q + k)^(−s),1 as @stdlib/math/base/special/hurwitz-zeta, ported from Cephes' zeta( x, q ) (Moshier, double/zeta.c).
Why?
The Hurwitz zeta is standard in the libraries stdlib compares against, and most of them build polygamma on it, through ψ⁽ⁿ⁾(x) = (−1)ⁿ⁺¹ n! ζ(n + 1, x).2 stdlib has riemann-zeta, which follows Boost's zeta.hpp. Boost has no Hurwitz zeta, so Cephes is the reference to follow. SciPy carries Cephes' zeta in a modified copy, in xsf, and builds its polygamma on it.
That route matters for negative x. For negative q, Cephes sums the terms directly until q + k exceeds 9, rather than reflecting, and Moshier's own comment there notes the relation to polygamma. Scored against mpmath over polygamma's two negative-argument fixture sets (1,950 points), SciPy's polygamma reaches at most 92 ULP and 6 ULP. The same expression built on Moshier's original gamma and zeta gives bit-identical results at every one of those points. stdlib's current reflection, which follows Boost, reaches 2,858 and 2,773 ULP.
Caveat
Moshier's direct sum stops once a term is negligible next to the sum, skipping the Euler–Maclaurin correction that follows, which is large when s is near 1 and q is tiny; xsf fixed that one test in 6b236b8d (on SciPy's main, not yet in a release to date), and a port can take the fix with it.
Related Issues
None
Questions
- Is
hurwitz-zetathe right name and namespace, or shouldriemann-zetatake an optionalqthat defaults to 1, as SciPy'szeta( x, q )does? - Should
polygammacall it for x < 0, in the same PR or a follow-up, or shouldpolygammakeep its reflection? - Domain: Cephes takes real s > 1 and real q. For q ≤ 0 it allows only integer s and is infinite at non-positive integer q. Is that domain enough for stdlib?
Other
The polygamma figures are from a scoring of stdlib, Boost, and SciPy at the same inputs against high-precision references.
Implementations in other libraries, and where each one's polygamma uses it:
- Cephes (Moshier):
zeta( x, q )indouble/zeta.c, from netlib's Cephes. The negative-q branch and its comment on polygamma are in the original. - SciPy: a modified copy of Cephes, in xsf's
cephes/zeta.h.scipy.special.polygammais(-1.0)**(n+1) * gamma(n+1.0) * zeta(n+1, x)(_basic.pyL1621, v1.18.1). - Julia, SpecialFunctions.jl:
zeta(s, z)(gamma.jlL202–L233, v2.9.1), which shifts negative z directly as Cephes does (L268–L277). Itspolygammauseszetafor every argument, but for x ≤ 0 it reflects first, as stdlib does (L363–L366). - GSL:
gsl_sf_hzeta_e(specfunc/zeta.cL714, v2.7.0, through a mirror).gsl_sf_psi_n_euses it for x > 0, and is a domain error for x ≤ 0 (specfunc/psi.cL775–L786). - FLINT/Arb:
acb_hurwitz_zeta, whichacb_polygammacalls (src/acb/polygamma.cL16–L31, v3.3.1). - mpmath:
zeta( s, a ), with a Hurwitz branch (functions/zeta.pyL544–L620, 1.4.1). - Boost: none.
zeta.hpphas the Riemann function only, which stdlib'sriemann-zetaports.
Checklist
- I have read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- The issue name begins with
RFC:.
Activity
[-][RFC]: add `@stdlib/math/base/special/hurwitz-zeta[/-][+][RFC]: add `@stdlib/math/base/special/hurwitz-zeta`[/+]Udit-Agarwal20 commentedon Nov 26, 2026
Hi maintainers! I'd like to work on this issue and contribute the Hurwitz zeta function to stdlib.
Proposed approach:
zeta(x, q)to@stdlib/math/base/special/hurwitz-zeta, following stdlib's existing mathematical package architecture.sapproaches 1 andqis small.I would appreciate your guidance regarding the proposed domain restrictions and whether
polygammaintegration should be handled in a separate PR.Could you please assign this issue to me if the proposed approach aligns with the project's expectations?
Thank you!
batpigandme commentedon Nov 26, 2026
Hey @Udit-Agarwal20,
We don’t assign issues here, you’re welcome to work on whatever you like. That said, I’d wait until we get initial feedback from @kgryte on this, since it still needs discussion. It’s possible he’ll want us to hold off on the xsf choice until it’s in a released version of SciPy. But you’re welcome to study it/sketch out a draft in the meantime.