Leticia-maria / QuantumFoca.jl

A repository for calculating Molecular Integrals, based on O-ohata method (1966) and Macmurchie-Davidson (1971)
https://leticia-maria.github.io/QuantumFoca.jl/dev/
MIT License
45 stars 3 forks source link

Implement ```gamma``` #22

Closed Leticia-maria closed 2 years ago

Leticia-maria commented 2 years ago

Try something with Flux (?) - just a reminder, don't need to say that it doesn't make sense, because it does

Leticia-maria commented 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).

Implementation by

schneiderfelipe commented 2 years ago

Why not use the one from SpecialFunctions.jl?

https://github.com/JuliaMath/SpecialFunctions.jl/blob/7461b517bcecd28800eef4fe7d4d263ea1ff66a6/src/gamma.jl#L567-L589

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 πŸ˜„.)

Leticia-maria commented 2 years ago

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.❀️

https://rosettacode.org/wiki/Gamma_function