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))))
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:
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
:
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)
The smooth lines show the algorithmic situation for parameter values 8, 9, and 10.