-
Notifications
You must be signed in to change notification settings - Fork 10
Description
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
endYou 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