Skip to content

Sum the incomplete gamma function's lower series as DLMF 8.7.3 in the left half-plane - #2088

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
the-incomplete-gamma-function-on-the-negative-axis-by-its-positive-series
Oct 23, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
the-incomplete-gamma-function-on-the-negative-axis-by-its-positive-series

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Evaluates gamma(a, z) in the left half-plane by a series whose terms do not cancel there, and makes each part of the value on the cut accurate to its own size. Part of #2075.

Speed. gamma(a, z) was Gamma(a) less the lower function, summed everywhere as z^a e^(-z) sum_k z^k/(a)_(k + 1) (DLMF 8.7.1). On the negative axis its terms alternate, are e^|z| in size and sum to e^(-|z|). So twice |z|/ln 10 guard digits were carried, and Gamma(a) was computed afresh at that precision. In the left half-plane the lower function is now z^a sum_k (-z)^k/(k! (a + k)) (DLMF 8.7.3), as E_1 already was. Its terms share a sign on that axis, and it loses (|z| + Re z)/ln 10 digits.

at 100 digits master this
gamma(1/3, -143) 9,560 ms 6 ms
gamma(1/2, -100 + 5i) 5,568 ms 9 ms
gamma(-5/2, -60) 2,354 ms 6 ms
gamma(1/3, -30) 1,671 ms 3 ms

The first is the evaluation that made #2087 change a test's sign, e^(c (d + f x)^3) to e^(-c (d + f x)^3), to keep it under a second.

Two defects on the cut, which the guard digits had hidden. Each part of the value should be accurate to its own size, and on the negative axis one part is often exactly Gamma(a) or a multiple of pi.

  • z^a was e^(a ln|z| + i a pi) with a pi rounded, so cos(pi/2) came out as 10^(-W) where it is 0. Times the lower function's e^143, that was the real part of gamma(1/2, -143), which is sqrt(pi). The angle is now reduced exactly before pi multiplies it, and the cosine is exactly 0 at a half-whole a.
  • Past |z| = (P + 5) ln 10 the continued fraction is used, and on the cut its coefficients are real. It converges to e^(i pi a) times a real function, the mean of the two sides, and falls short of the value from above by -i e^(i pi a) sin(pi a) Gamma(a). That is below the precision of the modulus, but it is the whole of the real part at a half-whole a, and of the imaginary part at a = -n, where it is -i (-1)^n pi/n!. On master the real part of gamma(1/2, -500) was 2.9e100, where it is sqrt(pi).

Checked part by part against mpmath at 300 to 500 digits. The grid is 16 orders (half-whole, whole, complex and odd-denominator ones among them) at 20 points of the left half-plane, on both sides of the threshold:

master this
240 points short of the threshold: worst part 9e-98 of its size 9e-98 of its size
80 points past it: parts wrong 18, by up to 1e113 times their size 0
the grid's time 48.4 s 3.4 s

The worst part on either side is gamma(7/3, -5 - 2i)'s, and comes from 7/3 itself being rounded to 100 digits.

Measured on Rubi's suite, with the harness that reads GAMMA, against this branch's base 3dbae246, the whole corpus each side:

3dbae246 this
solved 48,875 of 49,052 48,880
wrong 0 0
timeouts 7 2
rows lost 0

All five gains were timeouts of the harness's own check. After the library answers, it evaluates the answer again at 300 and 2000 digits, and for 6.1.1:205-207 and 6.1.3:98/100 that put gamma(a, z) in the left half-plane. They now finish in 0.08 to 1.9 s. The time per stream is 1.006, 1.005 and 0.922 of the base's. Two rows' allocation grew in the run, 6.1.7:196 and 8.1:302, and alone they are the same on both builds: 1.079 GB each, and 1.406 against 1.408 GB.

Eight tests added: three far into the left half-plane, four past the threshold on the cut, and gamma(1/3, -143) with the real root. The suite passes (16,947), and so do the MCP tests (329).

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

… left half-plane

Gamma(a) - gamma(a, z) summed gamma(a, z) as z^a e^(-z) sum_k z^k/(a)_(k + 1) (DLMF 8.7.1)
everywhere. On the negative axis its terms alternate, are e^|z| in size and sum to e^(-|z|), so
twice |z|/ln 10 guard digits were carried, and at that precision Gamma(a) was computed afresh:
Gamma(1/3, -143) took 9.6 s, Gamma(1/2, -100 + 5i) 5.6 s, Gamma(-5/2, -60) 2.4 s. In the left
half-plane it is now z^a sum_k (-z)^k/(k! (a + k)) (DLMF 8.7.3), as E_1 already was, whose terms
are of one sign on that axis and which loses (|z| + Re z)/ln 10 digits: 6 ms, 9 ms and 6 ms.

The large guard had been hiding two defects on the cut, where each part of the value should be
accurate to its own size:
- z^a was e^(a ln|z| + i a pi) with a pi rounded, so cos(pi/2) was 10^(-W) where it is 0. Times
  e^143, that was the real part of Gamma(1/2, -143), which is sqrt(pi). The angle is reduced
  exactly before pi multiplies it, and is exactly 0 at a half-whole a.
- Past (P + 5) ln 10 the continued fraction, whose coefficients are real there, gives
  e^(i pi a) times a real function, the mean of the two sides. It falls short of the value from
  above by -i e^(i pi a) sin(pi a) Gamma(a). That is below the precision of the modulus, but it is
  the whole of the real part at a half-whole a and of the imaginary part at a = -n. On master
  Gamma(1/2, -300)'s real part was 3e13 times sqrt(pi), Gamma(11/2, -300)'s 1.6e25 times
  Gamma(11/2), and Gamma(-3, -300)'s imaginary part 9e4 times pi/6.

Checked part by part against mpmath at 300-400 digits on 320 points: 16 orders, half-whole,
whole, complex and odd-denominator ones among them, at 20 points of the left half-plane
including both sides of the threshold. Every part agrees to 1e-97 of its own size. On master, 18 of
the 80 cases past the threshold had a part wrong, by up to 1e113 times its size. The grid took
48.4 s on master and 3.4 s here.

Part of #2075.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
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