Skip to content

doc,test: add examples and more tests for zeta functions #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,27 @@ Riemann zeta function
\zeta(s) = \sum_{n=1}^\infty \frac{1}{n^s}\quad\text{for}\quad s\in\mathbb{C}.
```

External links: [Wikipedia](https://en.wikipedia.org/wiki/Riemann_zeta_function)
# Examples
```jldoctest
julia> zeta(-1) # -1/12
-0.08333333333333338

julia> zeta(0)
-0.5

julia> zeta(-10) # zeta(-2n) == 0
-0.0

julia> zeta(1)
NaN

julia> zeta(Inf)
1.0
```

External links:
[DLMF 25.2(i)](https://dlmf.nist.gov/25.2#i),
[Wikipedia](https://en.wikipedia.org/wiki/Riemann_zeta_function)
"""
zeta(s::Number) = _zeta(float(s))

Expand Down
29 changes: 24 additions & 5 deletions test/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,37 @@
end

@testset "zeta" begin
# Riemann zeta function
# https://en.wikipedia.org/wiki/Particular_values_of_the_Riemann_zeta_function
@test zeta(0) ≈ -0.5
# Positive integers
@test isnan(zeta(1))
@test zeta(2) ≈ pi^2/6
@test zeta(Complex{Float32}(2)) ≈ zeta(2)
@test zeta(3) ≈ 1.2020569031595942 # Apéry's constant
@test zeta(4) ≈ pi^4/90
@test zeta(1,Float16(2.)) ≈ zeta(1,2.)
@test zeta(1.,Float16(2.)) ≈ zeta(1,2.)
@test zeta(Float16(1.),Float16(2.)) ≈ zeta(1,2.)
@test zeta(6) ≈ pi^6/945
@test zeta(8) ≈ pi^8/9450
# Negative integers
for n in 1:10
# trivial zeros
@test zeta(-2n) == 0
end
@test zeta(-1) ≈ -1/12
@test zeta(-3) ≈ 1/120
@test zeta(-5) ≈ -1/252
@test zeta(-7) ≈ 1/240
# NaN
@test isnan(zeta(NaN))
@test isnan(zeta(1.0e0))
@test isnan(zeta(1.0f0))
@test isnan(zeta(complex(0,Inf)))
@test isnan(zeta(complex(-Inf,0)))
@test isnan(zeta(complex(0, Inf)))
@test isnan(zeta(complex(-Inf, 0)))

# Hurwitz zeta function
@test zeta(1, Float16(2.)) ≈ zeta(1, 2.)
@test zeta(1., Float16(2.)) ≈ zeta(1, 2.)
@test zeta(Float16(1.), Float16(2.)) ≈ zeta(1, 2.)
end

#(compared to Wolfram Alpha)
Expand Down
Loading