Skip to content

Evaluate the incomplete gamma function's series faster - #2079

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
evaluate-the-incomplete-gamma-function-faster
Oct 22, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
evaluate-the-incomplete-gamma-function-faster

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Makes the upper incomplete gamma function's series several times cheaper. Part of #2075.

Gamma(a, z) by its series is Gamma(a) - gamma(a, z), and Gamma(a) was computed by Spouge's approximation on every evaluation: six of the nine milliseconds at a hundred digits.

  • Gamma(a) is remembered, per order and precision. A function the integrator samples at points is asked it at one a for every z.
  • A real a and z sum the series in real arithmetic. That is one product and one quotient a term, where the complex arithmetic took nineteen operations.
  • The logarithm on the cut takes pi from the cache rather than computing it afresh.

Measured on one machine, 40 evaluations each, at the default hundred digits, against master b21f0138:

master this
gamma(2.91, -3.3) 9.52 ms 0.92 ms
gamma(2.91, 3.3) 9.37 ms 0.82 ms
gamma(12/5, -30) 16.53 ms 2.04 ms
gamma(7.71, 2.1) 9.13 ms 0.78 ms
gamma(1/3, 2) 23.02 ms 2.15 ms
gamma(37/10, -7/3 + 2i) 10.52 ms 2.30 ms
gamma(1/2 + i, 2 + 3i) 11.76 ms 2.74 ms
gamma(0, -30), the exponential integral's series 2.48 ms 2.25 ms
gamma(5/2, 40), the continued fraction 3.58 ms 3.63 ms

Values are unchanged: the 37 tests against mpmath's gammainc at 55 digits pass, and so does the suite (16,890) and the MCP tests (329).

Found by #2075's next integration rule. Its answers carry the function, and one declined integral sampled them three thousand times.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Gamma(a, z) by its series is Gamma(a) - gamma(a, z), and Gamma(a) was computed
by Spouge's approximation on every evaluation: six of the nine milliseconds at a
hundred digits. It is remembered now, per order and precision, since a function
the integrator samples at points is asked it at one a for every z. A real a and z
sum the series in real arithmetic, one product and one quotient a term where the
complex arithmetic took nineteen operations, and the logarithm on the cut takes pi
from the cache rather than computing it afresh.

gamma(2.91, -3.3) 9.52 -> 0.92 ms, gamma(1/3, 2) 23.0 -> 2.2 ms,
gamma(1/2 + i, 2 + 3i) 11.8 -> 2.7 ms; the continued fraction and the exponential
integral's series are unchanged. Found by #2075's next integration rule, whose
answers one declined integral sampled three thousand times.

Part of #2075.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet
Rafael-SOWNet merged commit c73cc68 into master Oct 22, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant