From 18cef752fb5821c5c532df7cd72c586e29d6537e Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sat, 3 May 2025 23:16:51 +0800 Subject: [PATCH 1/3] doc: add examples for `zeta(s)` --- src/gamma.jl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/gamma.jl b/src/gamma.jl index 5004404d..ede045e8 100644 --- a/src/gamma.jl +++ b/src/gamma.jl @@ -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) +-0.08333333333333338 + +julia> zeta(0) +-0.5 + +julia> zeta(0.5) +-1.4603545088095873 + +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)) From f5adefcc310768e90d6ba14b26671972e61fec2c Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sat, 3 May 2025 23:17:23 +0800 Subject: [PATCH 2/3] test: add more test for `zeta(s)` --- test/gamma.jl | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/test/gamma.jl b/test/gamma.jl index 8c970786..89ded587 100644 --- a/test/gamma.jl +++ b/test/gamma.jl @@ -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) From c05f232557606994f216208fd3db30cd8e1d4e36 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sat, 3 May 2025 23:26:21 +0800 Subject: [PATCH 3/3] doc: update examples for `zeta(s)` --- src/gamma.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gamma.jl b/src/gamma.jl index ede045e8..6e62b3fd 100644 --- a/src/gamma.jl +++ b/src/gamma.jl @@ -418,14 +418,14 @@ Riemann zeta function # Examples ```jldoctest -julia> zeta(-1) +julia> zeta(-1) # -1/12 -0.08333333333333338 julia> zeta(0) -0.5 -julia> zeta(0.5) --1.4603545088095873 +julia> zeta(-10) # zeta(-2n) == 0 +-0.0 julia> zeta(1) NaN