EDIT: This issue started with discussion on the gamma implementation but has moved to discussing the scope of this package and inclusion of other special functions or splitting into smaller packages. Please leave comments on what functions you would like to be included here or if you would like smaller packages.
SPLIT FROM https://github.com/heltonmc/Bessels.jl/pull/26#issuecomment-1200481143
A small note: I was perusing your gamma implementation and I think there are a couple small improvements that could be made, assuming they don't cost precision somehow. For one, if I change the v = x^(0.5*x - 0.25) to v = exp((0.5*x-0.25)*log(x)) in large_gamma, I see a big speedup. And it doesn't seem like the log would make an issue, because you'll never hit that branch when x is zero.
Second, if there's a reason not to do that, then an intermediate method like this seems to be faster when x > 11.5 but it isn't too too large:
function smallish_gamma(x)
_x = min(x, x-ceil(x-11.5))
_g = small_gamma(_x)
while _x < x # use the fact that gamma(x+1) == x*gamma(x)
_g *= _x
_x += one(_x)
end
_g
end
You could then branch on x < 30.0 or something instead and at least hit the large_gamma branch less often.
I haven't checked very hard to see if these tricks introduce new issues, but I wouldn't think that they do.
Originally posted by @cgeoga in https://github.com/heltonmc/Bessels.jl/issues/26#issuecomment-1200481143
EDIT: This issue started with discussion on the
gammaimplementation but has moved to discussing the scope of this package and inclusion of other special functions or splitting into smaller packages. Please leave comments on what functions you would like to be included here or if you would like smaller packages.SPLIT FROM https://github.com/heltonmc/Bessels.jl/pull/26#issuecomment-1200481143
A small note: I was perusing your
gammaimplementation and I think there are a couple small improvements that could be made, assuming they don't cost precision somehow. For one, if I change thev = x^(0.5*x - 0.25)tov = exp((0.5*x-0.25)*log(x))inlarge_gamma, I see a big speedup. And it doesn't seem like thelogwould make an issue, because you'll never hit that branch whenxis zero.Second, if there's a reason not to do that, then an intermediate method like this seems to be faster when
x > 11.5but it isn't too too large:You could then branch on
x < 30.0or something instead and at least hit thelarge_gammabranch less often.I haven't checked very hard to see if these tricks introduce new issues, but I wouldn't think that they do.
Originally posted by @cgeoga in https://github.com/heltonmc/Bessels.jl/issues/26#issuecomment-1200481143