Add Boost's `tgamma_lower` and `tgamma(a,z)` functions
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
Description
The Math library currently has the normalised incomplete gamma functions (gamma_p and gamma_q), which return values within [0, 1]. The log of the gamma_p function is used for the gamma_lcdf function, but given that gamma_p normalises the result to [0,1], we lose resolution around the boundaries of the LCDF.
If we add the tgamma(a,z) function (incomplete gamma, not normalised), then we can define a log_gamma_p function which should be more numerically stable.
Where the normalised lower incomplete gamma (gamma_p) is defined:
$$
P(a,z) = \frac{\Gamma(a) - \Gamma(a,z)}{\Gamma(a)}
$$
With the tgamma_lower function, we can keep this on the log scale as:
double lgamma_a = lgamma(a);
log_diff_exp(lgamma_a, log(tgamma(a,z)) - lgamma_a;
With an analogous approach for gamma_q and log_gamma_q
Current Version:
v4.4.0
EDIT: The definition should have used tgamma, not tgamma_lower!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing gamma_p and gamma_q implementations and the Boost incomplete-gamma APIs they wrap. Trace how gamma_lcdf and the corresponding log-scale functions use these results. Done means the requested tgamma_lower and tgamma(a,z) functionality supports the more stable log-scale gamma calculations described in the issue, with matching coverage for gamma_p and gamma_q.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100