JuliaMath / SpecialFunctions.jl

Special mathematical functions in Julia

Home Page:https://specialfunctions.juliamath.org/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accuracy of `digamma` function can be improved

KlausC opened this issue · comments

There are systematic errors in the digamma and trigamma functions.
The plots below show the situation and possible improvements.

julia> using SpecialFunctions

julia> using Plots

julia> X = 0.3:0.01:10
0.3:0.01:10.0

julia> plot(X, (digamma.(Float64.(X)) .- digamma.(BigFloat.(X))))

plot_1

That seems to be not optimal in the argument area below 8.0.

It can be easily improved by increasing the constant 7 to 8, as demonstrated below:

plot_2

The error figures are now symmetric to zero and the peaks at all integer values have disappeared.

Similar outputs for the relative errors in trigamma:

plot_6

The straight lines are +-eps(), the smooth lines show the systematic error (obtained by high precision execution of the same algorithm; rounding errors are suppressed)

plot_29

The smooth lines show the algorithmic situation for parameter values 8, 9, and 10.