`NaN` in `digamma` caused by `_cotpi`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
Research direction
Start in src/gamma.jl at the _digamma definition and _cotpi, then compare the proposed behavior with the linked mpmath implementation. Reproduce the large complex-argument example in Julia and verify that the resulting cotangent and digamma calculation no longer produce NaN while retaining the expected value for cot(pi * 500 * exp(im * 3pi/4)).
Written by the indexing model from the issue text.
Description
The definition of _digamma(z::ComplexOrReal{Float64}) contains the formula
https://github.com/JuliaMath/SpecialFunctions.jl/blob/cf35c580aebd3a698f1d3550e2b60ffbd73bdc0c/src/gamma.jl#L29
in which _cotpi is defined as
https://github.com/JuliaMath/SpecialFunctions.jl/blob/cf35c580aebd3a698f1d3550e2b60ffbd73bdc0c/src/gamma.jl#L63
For large complex arguments, _cotpi produces NaN since cospi and sinpi produce Inf. For example,
julia> cospi(500 * exp(im * 3pi/4))
Inf - Inf*im
julia> sinpi(500 * exp(im * 3pi/4))
Inf + Inf*im
julia> cospi(500 * exp(im * 3pi/4)) / sinpi(500 * exp(im * 3pi/4))
NaN + NaN*im
Nevertheless, the ordinary cot gives the correct answer
julia> cot(pi * 500 * exp(im * 3pi/4))
0.0 - 1.0im
A way to avoid NaN is to define cotpi as in mpmath
https://github.com/mpmath/mpmath/blob/b600dbcabf4b7406a61e82b9e607f754a9f12ff9/mpmath/libfp.py#L153-L161
- Dominant language
- Julia
- Stars
- 384
- Forks
- 115
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaMath/SpecialFunctions.jl
-
erfinv(::Float16) and erfcinv(::Float16) are wrong for abs(x) <= 0.75 (erfinv(Float16(0)) == 0.2201)Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
JuliaMath/SpecialFunctions.jl#571 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaMath/SpecialFunctions.jl#570 ·
-
Difficulty 5/5 Over a week Newbie friendliness 40/100
JuliaMath/SpecialFunctions.jl#569 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
JuliaMath/SpecialFunctions.jl#567 ·
-
Difficulty 4/5 1-2 days Newbie friendliness 56/100
JuliaMath/SpecialFunctions.jl#563 ·
All issues in JuliaMath/SpecialFunctions.jl
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
FluxML/Metalhead.jl#407 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
SciML/ModelingToolkit.jl#5371 ·
Maintainers usually reply within 2 days
-
GNNLux MEGNetConv drops the state of stateful sublayersPossibly taken A pull request linked to this issue is open or already merged. Openlux
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
JuliaGraphs/GraphNeuralNetworks.jl#732 ·
Maintainers usually reply within 2 days