JuliaMath / JuliaMath/SpecialFunctions.jl

`zeta(s)` and `eta(s)` return `NaN` or `Inf` for every real s < `-170.62`

Open
#556 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
381
Forks
113
Avg merge
1d 23h
Merged PRs (30d)
1

Description

For example:

```julia
julia> using SpecialFunctions

julia> zeta(-170.0)
-0.0

julia> zeta(-172.0) # true value 0 (trivial zero): https://www.wolframalpha.com/input?i=zeta%28-172%29
NaN

julia> zeta(-180.0) # true value 0 (trivial zero): https://www.wolframalpha.com/input?i=zeta%28-180%29
NaN

julia> zeta(-200.0) # true value 0 (trivial zero): https://www.wolframalpha.com/input?i=zeta%28-200%29
NaN

julia> zeta(-250.0) # true value 0 (trivial zero): https://www.wolframalpha.com/input?i=zeta%28-250%29
NaN

julia> zeta(-175.0) # true value 7.4526910304300896e177: https://www.wolframalpha.com/input?i=zeta%28-175%29
Inf

julia> zeta(-171.0) # true value 1.2819489863517886e172: https://www.wolframalpha.com/input?i=zeta%28-171%29
Inf
```

## Possible Cause (as considered by an AI)

`src/gamma.jl`, `_zeta(s::ComplexOrReal{Float64})`:

```julia
elseif real(s) < 0.5
absim = abs(imag(s))
if abs(real(s)) + absim < 1e-3 # Taylor series for small |s|
...
end
if absim > 12 # amplitude of sinpi(s/2) ≈ exp(imag(s)*π/2)
# avoid overflow/underflow (issue #128)
lg = loggamma(1 - s)
...
else
return zeta(1 - s) * gamma(1 - s) * sinpi(s*0.5) * twoπ^s * invπ
end
```

The `else` branch is the one from issue #128 that "avoids overflow" only when `absim > 12`.
On the real axis `gamma(1 - s)` is `Inf` for all `s < -170.62`, `sinpi(s*0.5)` is `∓0.0` at negative even integers, and `twoπ^s` is a tiny denormal-range factor that would have brought the product back into range had the multiplication been done in log space.

For the second regime, the `@pg_horner` macro (same file) expands to a Horner scheme whose coefficients are `m*(m+1)*…` products; for `m ≈ 5.7e19` the third such product exceeds `floatmax`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/gamma.jl at _zeta(s::ComplexOrReal{Float64}) and inspect both the real-axis branch and the @pg_horner expansion. Reproduce the reported zeta values in Julia, then verify the relevant behavior around the gamma overflow threshold and negative even integers. Done means real inputs below -170.62 no longer incorrectly produce NaN or Inf, including the reported trivial zeros and finite values.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.