-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect result for gamma functions of pure imaginary argument #729
Comments
@banana-bred Thank you for reporting this bug. Could it be a special case when |
I think so. The cases you mentioned seem to be handled appropriately, but z%re = 0 currently gets treated the same as z%re < 0, which is probably (?) not intended and is what seems to cause this issue. |
Ok. Thank you for the clarification. Would you like to submit a PR with the
appropriate fix and test, please?
Le lun. 14 août 2023 à 22:16, banana-bred ***@***.***> a
écrit :
… I think so. The cases you mentioned seem to be handled appropriately, but
z%re = 0 currently gets treated the same as z%re < 0, which is probably (?)
not intended and is what seems to cause this issue.
—
Reply to this email directly, view it on GitHub
<#729 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD5RO7EA7ZPICKQX62JDWJTXVKBTHANCNFSM6AAAAAA3QCLKCU>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
sure |
PR related to #729, gamma function of pure imaginary returns correct value
Fixed by #730 |
Description
The gamma function implemented in
cgamma_csp
andcgamma_cdp
in modulestdlib_specialfunctions_gamma
produce the wrong output when the argument is a pure imaginary. They return the complex conjugate of the output instead.Expected Behaviour
An example where the stdlib implementation of
gamma
returns the complex conjugate of the expected result. The expected result here is calculated (with worse accuracy) by the user-defined functiongammaWeierstrass
, which implementshttps://en.wikipedia.org/wiki/Gamma_function#19th_century:_Gauss,_Weierstrass_and_Legendre ,
and by
exp(log_gamma(z))
. The latter two agree up to some low accuracy, but are both different thangamma(z)
.This is not expected, as
exp(log_gamma(z))
should be the same asgamma(z)
.test.f90:
output:
Compiler: gfortran 13.2.1
Version of stdlib
a4ff2f0
Platform and Architecture
Artix Linux x86_64
Additional Information
It seems like this comes from the imaginary axis not being included in the right complex half-plane ( z % re > 0 ).
This causes the argument to be complex conjugated, which then conjugates (*) the output because Γ(z*) = Γ(z)*.
Suggested fix: include the imaginary axis in the right complex half-plane in gamma_cdp and gamma_csp.
This format of defining the left half-plane with a strict inequality, i.e.
if(z % re < zero_k1)
, mirrors the behavior inl_gamma_cdp
andl_gamma_csp
, which is why log_gamma seems to not have this issue.The text was updated successfully, but these errors were encountered: