Skip to content

[RFC]: add @stdlib/math/base/special/hurwitz-zeta #16834

Backlog

Description

@batpigandme

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

  1. Is hurwitz-zeta the right name and namespace, or should riemann-zeta take an optional q that defaults to 1, as SciPy's zeta( x, q ) does?
  2. Should polygamma call it for x < 0, in the same PR or a follow-up, or should polygamma keep its reflection?
  3. 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:

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.

Footnotes

  1. NIST Digital Library of Mathematical Functions, Release 1.2.8 of 2026-09-15, eq. 25.11.1, for ℜs > 1 and q ≠ 0, −1, −2, … (DLMF writes a for q). ↩

  2. NIST Digital Library of Mathematical Functions, Release 1.2.8 of 2026-09-15, eq. 25.11.12, for n = 1, 2, 3, … (DLMF writes a for x). ↩

Activity

  1. changed the title [-][RFC]: add `@stdlib/math/base/special/hurwitz-zeta[/-] [+][RFC]: add `@stdlib/math/base/special/hurwitz-zeta`[/+] on Nov 26, 2026
  2. added
    RFC
    Feature
    Needs Discussion
    on Nov 26, 2026
  3. Udit-Agarwal20 commented on Nov 26, 2026

    @Udit-Agarwal20

    Hi maintainers! I'd like to work on this issue and contribute the Hurwitz zeta function to stdlib.

    Proposed approach:

    • Port Cephes' zeta(x, q) to @stdlib/math/base/special/hurwitz-zeta, following stdlib's existing mathematical package architecture.
    • Incorporate the SciPy/xsf correction for numerical accuracy when s approaches 1 and q is small.
    • Handle domain restrictions, singularities, negative arguments, and floating-point edge cases.
    • Add JavaScript and C implementations, comprehensive unit tests using high-precision mpmath reference values, benchmarks, TypeScript declarations, and API documentation.
    • Follow stdlib's [package development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/packages.md) and ensure all relevant tests and lint checks pass.

    I would appreciate your guidance regarding the proposed domain restrictions and whether polygamma integration 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!

  4. batpigandme commented on Nov 26, 2026

    @batpigandme
    MemberAuthor

    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.

  5. added
    Math
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureMathNeeds DiscussionRFC

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions