Repository navigation
Make Spouge's constants from exact ratios and powers of e - #2090
Merged
Rafael-SOWNet merged 1 commit intoOct 23, 2026
Merged
Rafael-SOWNet merged 1 commit into
Rafael-SOWNet merged 1 commit into
Conversation
The factorial of a non-integer is Spouge's approximation, with a = 1.3 P constants at P digits, cached per precision. Each constant c_k = (-1)^(k - 1) (a - k)^(k - 1/2) e^(a - k)/(k - 1)! was made with a power to a non-integer exponent and an exponential, a logarithm and two exponentials at 1.95 P digits for each of the 1.3 P terms. The first factorial at a precision took 0.9 s at 100 digits, 20.5 s at 300 and 218 s at 600. (a - k)^(k - 1)/(k - 1)! is a ratio of exact integers, sqrt(a - k) one square root, and e^(a - k) the running product of e, carried with ten more digits for the a multiplications and rounded back to the constants' precision. The first factorial now takes 0.12 s at 100 digits, 0.57 s at 300, 1.5 s at 600, 5.5 s at 1000 and 30 s at 2000. The values are unchanged. Against mpmath, Gamma(1/3), Gamma(1/3 + i), Gamma(2/7), Gamma(-7/3), Gamma(101/2) and Gamma(-5/2 + 3i) have the same error on both builds at 100 and 300 digits, within 1.3 units of the last digit, and stay within that at 600 and 1000. Once compiled, an evaluation at 100 digits costs the same, 7 to 10 ms, on both. A test of (1/3)! and (1/3 + i)! at 300 digits is added. 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 23, 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.
Builds Spouge's constants for the factorial without a power and an exponential each. The first factorial at a precision is 36 to 145 times faster, with the same digits. Part of #2075.
What was slow. The factorial of a non-integer is Spouge's approximation, with
a = 1.3 Pconstants atPdigits, cached per precision. Each constantc_k = (-1)^(k - 1) (a - k)^(k - 1/2) e^(a - k)/(k - 1)!was made with a power to a non-integer exponent and an exponential. That is a logarithm and two exponentials at1.95 Pdigits for each of the1.3 Pterms.Now.
(a - k)^(k - 1)/(k - 1)!is a ratio of exact integers,sqrt(a - k)one square root, ande^(a - k)the running product ofe. The product is carried with ten more digits and rounded back.The values are unchanged. I checked
Gamma(1/3),Gamma(1/3 + i),Gamma(2/7),Gamma(-7/3),Gamma(101/2)andGamma(-5/2 + 3i)against mpmath. They have the same error on both builds at 100 and 300 digits, within 1.3 units of the last digit, and stay within that at 600 and 1000. Once the constants exist, an evaluation at 100 digits costs the same on both builds, 7 to 10 ms.Measured on Rubi's suite, with the harness that reads
GAMMA, against this branch's base3dbae246, the whole corpus each side:3dbae246The five gains are the timeouts #2088 also ended:
6.1.1:205-207and6.1.3:98/100. The harness checks each answer again at 300 and 2000 digits, which put a gamma function at a new precision. Allocation per stream is 0.9998, 1.0000 and 0.9960 of the base's. The times, 1.04, 1.08 and 0.98, were taken with other builds running on the machine, and the trigonometric family, at 1.08, does not reach this code. Two rows' allocation grew in the run,6.1.7:196and8.1:302. Alone they are the same on both builds: 1.079 GB each, and 1.406 against 1.407 GB.A test of
(1/3)!and(1/3 + i)!at 300 digits is added. The suite passes (16,940), and so do the MCP tests (329).🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura