Closed Leticia-maria closed 2 years ago
@doc raw""" gamma(z)
Compute the gamma function for complex z
, defined by
\Gamma(z)
:=
\begin{cases}
n!
& \text{for} \quad z = n+1 \;, n = 0,1,2,\dots
\\
\int_0^\infty t^{z-1} {\mathrm e}^{-t} \, {\mathrm d}t
& \text{for} \quad \Re(z) > 0
\end{cases}
and by analytic continuation in the whole complex plane.
External links: DLMF, Wikipedia.
See also: [loggamma(z)
](@ref SpecialFunctions.loggamma) for \log \Gamma(z)
and
[gamma(a,z)
](@ref SpecialFunctions.gamma(::Number,::Number)) for
the upper incomplete gamma function \Gamma(a,z)
.
Why not use the one from SpecialFunctions.jl?
It has direct support for float32 and float64 (using libm), supports float16 by converting back and forth from float32, supports complex and bigfloat the way you said, has a short circuit for integer types (using a factorial table up to n = 20), and works for all other numbers by converting to floats.
I couldn't find how scipy does it, but it certainly wrappers some Fortran or C code. I found two implementations of the gamma function in the official repo, one in C and the other one in Fortran. (One cool thing about the C implementation is their use of Stirling's approximation for large inputs, which made me smile π.)
Thank you so much, my friend @schneiderfelipe πβ€οΈ Your comments are super valid and it always helps me a lot. I already know SpecialFunctions.jl (Yesterday, I said that for you in person. Do you remember? π ) and i knew that you would reply my issue exactly like this πππππ this is funny. And yes, scipy wrappers a C code. I have checked it yesterday. I will share with you an interesting link, with several implementations of gamma function in multiple languages (even ALGOLπ€―) IT COMPLETELY SHOCKED ME....HAHAHAH Just kidding.β€οΈ
Try something with Flux (?) - just a reminder, don't need to say that it doesn't make sense, because it does