Skip to content

Add ligamma and ligamma_lower, the logarithms of tgamma(a, x) and tgamma_lower(a, x) - #1505

Merged
NAThompson merged 4 commits into
developfrom
ligamma
Oct 3, 2026
Merged

NAThompson merged 4 commits into
developfrom
ligamma

Conversation

@NAThompson

Copy link
Copy Markdown
Collaborator

Logs of the non-normalised value, or lgamma plus logs of the regularized one, and a log x - x plus the logged fraction or series where that underflows. Closes #1173.

ulps against Arb (arb_hypgeom_gamma_upper for x >= a, the lower series otherwise): ligamma/ligamma_lower in blue; in orange, log(tgamma)/log(tgamma_lower), or for large a, where those overflow, lgamma(a) + lgamma_q/lgamma_p. Red is -inf or NaN. The missing orange in the last plot is lgamma_p overflowing when P underflows with a < 4x, an existing bug.

ligamma(2.5, x)
ligamma(0.001, x)
ligamma_lower(100, x)
ligamma(1000, x)
ligamma_lower(1e6, x)

🤖 Generated with Claude Code

@NAThompson

Copy link
Copy Markdown
Collaborator Author

reporting/performance/ligamma_performance.cpp, with promote_float<false> and promote_double<false> so each type is timed in its own arithmetic. Ordinary: a log-uniform in [0.5, 30], x/a log-uniform in [0.1, 10]. Large a: a log-uniform in [1e3, 1e5], where tgamma(a, x) overflows. Median of 5 repetitions, Apple M-series, Homebrew clang 23, -O3; long double is double here.

float double long double
ligamma, ordinary 66.7 ns 130 ns 127 ns
log(tgamma), ordinary 62.9 ns 125 ns 125 ns
ligamma, large a 147 ns
lgamma(a) + lgamma_q, large a 132 ns

NAThompson and others added 4 commits October 3, 2026 07:26
…mma_lower(a, x)

Logs of the non-normalised value, or lgamma plus logs of the regularized one, and a log x - x plus the logged fraction or series where that underflows. Closes #1173.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… terms

log(tgamma(a, x)) is a small difference of terms as large as a log(x) and x, so host and device differ by many eps relative to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NAThompson
NAThompson merged commit 4971557 into develop Oct 3, 2026
47 of 48 checks passed
@NAThompson
NAThompson deleted the ligamma branch October 3, 2026 17:51
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.

New special functions: logarithm of incomplete gamma and beta functions

1 participant