Repository navigation
The upper incomplete gamma function - #2077
Merged
Merged
Conversation
gamma(a, z) with a second argument is the upper incomplete gamma function Gamma(a, z) = int_z^oo t^(a - 1) e^(-t) dt, as Mathematica's Gamma[a, z] and mpmath's gammainc(a, z) are; with one, gamma is still Gamma(x), and a second argument was a parse error. z^a takes its principal branch, so the cut is the negative real axis, which keeps the value from above. It is printed so, in LaTeX as \Gamma(a, z) and in SymPy as uppergamma, and its derivative in z is -z^(a - 1) e^(-z); a parameter that varies declines. A whole a >= 1 is (n - 1)! e^(-z) times a polynomial (DLMF 8.4.8), a half is sqrt(pi) erfc(sqrt(z)) (8.4.6), and Gamma(a, 0) is Gamma(a). It is evaluated to the working precision for any complex a and z. Where |z| > 2|a| + 10, in the right half-plane or past (P + 5) ln 10, it is Legendre's continued fraction (8.9.2) by the modified Lentz algorithm; elsewhere it is Gamma(a) less the lower one's series (8.7.1), with twice |z|/ln 10 guard digits and more where the difference shows it cancelled more; and at a whole a <= 0, where Gamma(a) has a pole, E_1(z) by its series and the recurrence (8.4.15). It is real exactly where it is real: for a positive z, and for a whole a >= 1 at any real z. It agrees with mpmath at 168 points to 1e-90 at a hundred digits and at 54 to 1e-290 at three hundred, near the poles and on the cut. Part of #2075. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
This was referenced Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #2075.
The node. With a second argument,
gamma(a, z)is the upper incomplete gamma functionGamma(a, z) = int_z^oo t^(a - 1) e^(-t) dt, as Mathematica'sGamma[a, z]and mpmath'sgammainc(a, z)are. With one argument,gammais stillGamma(x). A second argument used to be aFunctionArgumentCountException.z^atakes its principal branch, so the cut is the negative real axis, which keeps the value from above.\Gamma\left(a, z\right), and in SymPyuppergamma.zit is-z^(a - 1) e^(-z). If the parameter varies, it declines.a >= 1is(n - 1)! e^(-z)times a polynomial (DLMF 8.4.8).a = 1/2issqrt(pi) erfc(sqrt(z))(8.4.6).Gamma(a, 0)isGamma(a)for a positivea.Evaluation is to the working precision for any complex
aandz. Which method runs:|z| > 2|a| + 10, either in the right half-plane or past(P + 5) ln 10. Near the negative real axis at a moderate|z|it stops short of the value:Gamma(1/2, -10)was wrong in its fourth digit. With|a|large against|z|it converges slowly:Gamma(100, 1/10 - 10 i)had the wrong imaginary part. Both cases were measured, and both go to the series.Gamma(a)less the lower function's series (8.7.1), with twice|z|/ln 10guard digits, and more where the difference shows it cancelled more.a <= 0, whereGamma(a)has a pole:E_1(z)by its series, and the recurrence (8.4.15).z, and for a wholea >= 1at any realz.Gamma(1/2, 300)is3e-132, andGamma(100, -5 + i/10)has an imaginary part1e-86of its real part.Against mpmath's
gammainc:1e-90(worst3.8e-100)1e-2901e-30of a pole, both sides of the cut, `Cost: about 5 ms per evaluation at a hundred digits. At three hundred digits, an order near a pole costs tens of seconds the first time, mostly in setting up
Gamma(a)at each new precision.Not here: the integration rules, and the corpus harness reading Rubi's file 8.6. Those are #2075's next steps.
IncompleteGammaTestcovers:Results:
MathS.IncompleteGamma.🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura