Repository navigation
The polygamma functions, and the derivative of the factorial - #2068
Merged
Merged
Conversation
polygamma(n, z) is psi^(n)(z), the (n + 1)-th derivative of ln Gamma(z), and digamma(z) is polygamma(0, z) and prints so. Both are parsed and printed in text, LaTeX and SymPy; neither name was recognised, so digamma(1) was the variable digamma, and polygamma(1, 1) did not parse. Each order differentiates to the next, and an order that depends on the variable declines. The derivative of x! is x! digamma(x + 1), where it declined (#958), so gamma(x) differentiates to (x - 1)! digamma(x). It is evaluated to the working precision anywhere in the complex plane but at 0, -1, -2, ..., its poles: reflected left of Re z = 1/2 (DLMF 5.15.6), with the derivatives of cot(pi z) as polynomials in cot; moved by the recurrence (5.15.5) to Re w at least the working digits; and summed by the asymptotic series (5.11.2, 5.15.8), with the Bernoulli numbers exact from the tangent numbers by Brent and Harvey's recurrence. It agrees with mpmath to the last digit at 100, 300 and 2000 digits. Special values stay as written, since digamma(1) = -gamma wants a symbol for Euler's constant. Two derivative tests used the factorial as the node that cannot be differentiated; they use a polygamma function of a varying order. Part of #171. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
The server's syntax document lists every function the grammar reads, and its test fails on a name the grammar accepts that the document does not. Part of #171. 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 #171.
The polygamma functions are nodes.
polygamma(n, z)ispsi^(n)(z), the(n + 1)-th derivative ofln Gamma(z).digamma(z)ispolygamma(0, z), and prints that way.\psi,\psi^{(n)}) and SymPy (digamma,polygamma). Before,digamma(1)was read as the variabledigammatimes 1, andpolygamma(1, 1)did not parse.0, -1, -2, ....x! * digamma(x + 1), where it declined (Differentiating a factorial or gamma answers NaN, which claims the derivative does not exist #958). Sogamma(x)differentiates to(x - 1)! * digamma(x).Evaluation is to the working precision, for every complex argument but the poles, where it is NaN.
Re z = 1/2. Reflection (DLMF 5.15.6), with the derivatives ofcot(pi z)as polynomials incot.Re w >= R, withRthe working digits plusn. Then the asymptotic series (5.11.2, 5.15.8) is summed to the working precision.Results:
The 300- and 2000-digit points are
digamma(3/2),polygamma(3, 7/3)anddigamma(-7/3 + 2i).Not in this PR.
digamma(1) = -gammawants a symbol for Euler's constant, which the library does not have.int psi(x) dx = ln Gamma(x)and the rest are not here.x! = yhas no closed-form inverse, and an equation in either function is left as the set ofxfor which it holds.PolygammaTestcovers:7.53670601059080…;Results:
c614b2c8), is 48,305 of 48,305, with no row moved and no answer's allocation grown.🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura