Skip to content
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

Gamma special function #625

Merged
merged 18 commits into from
Jun 13, 2022
Merged

Conversation

Jim-215-Fisher
Copy link
Contributor

During implementing the gamma probability distribution(#278), I realized there is a need for gamma function and log_gamma with complex argument as well as incomplete gamma functions. So here is the PR for gamma special function. The gamma and log_gamma functions with complex argument was coded for single and double precision. All implemented functions were tested against available multi-precision package version with satisfactory results. This PR includes the following:

  1. an extension of gamma function to integer/complex argument,
  2. an extension of log_gamma function to integer/complex argument,
  3. a log_factorial function for integer argument,
  4. lower/upper incomplete gamma functions,
  5. normalized lower/upper incomplete gamma functions (P and Q).

Please test it and provide any comment and suggestion.

Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. It looks already good to me, while I am not a user of such functions. A main question is why not all functions support all kinds of reals.

doc/specs/stdlib_specialfunctions_gamma.md Outdated Show resolved Hide resolved
doc/specs/stdlib_specialfunctions_gamma.md Outdated Show resolved Hide resolved
doc/specs/stdlib_specialfunctions_gamma.md Outdated Show resolved Hide resolved
doc/specs/stdlib_specialfunctions_gamma.md Outdated Show resolved Hide resolved

### Description

Due to the different branch cut structures and a different principal branch, natural logarithm of gamma function log_gamma(z) with complex argument is different from the ln(Gamma(z)). The two have the same real part but different imaginary part.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain first the aim of this function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to move these sentences to the section Returned value.

src/stdlib_specialfunctions_gamma.fypp Show resolved Hide resolved
src/stdlib_specialfunctions_gamma.fypp Show resolved Hide resolved
src/stdlib_specialfunctions_gamma.fypp Show resolved Hide resolved
@Jim-215-Fisher
Copy link
Contributor Author

Thank you. It looks already good to me, while I am not a user of such functions. A main question is why not all functions support all kinds of reals.

Very good question. Short answer is limits of precision. Detailed answer is as follows. During the calculation of most special functions such as Gamma, Bessel functions, there are no finite analytical formulae to exactly calculate the function values. Those functions have to be approximated by using various techniques, which introducing truncation error and rounding error. These errors are more pronouncing during complex value multiplication and division arithmetic of the special functions. Because of the propagation of these errors, the calculated results will have much less significant digits or even incorrect value if the same precision as calculated result is used during calculation. By using higher precision during calculation, the desired precision digits are guaranteed to be correct. So single precision uses double precision for calculation, double precision uses quadruple precision for calculation. Extended precision calculation may need higher precision a little over quadruple, while quadruple precision calculation need much higher precision not available right now. If there is a package for arbitrary precision, all kinds of reals can be supported.

@jvdp1 jvdp1 requested review from ivan-pi and a team March 19, 2022 18:20
Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (only a minor comment). Thank you.

doc/specs/stdlib_specialfunctions_gamma.md Show resolved Hide resolved
Copy link
Member

@milancurcic milancurcic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants