Repository navigation
Take a compiled binomial of a large whole order through a ratio of gammas - #2340
Merged
Merged
Conversation
…mmas A compiled binomial(n, k) with a whole k is a product of k factors while k fits a long, and past that it went through the gamma function. Past the longs the logarithms of Γ(k + 1) and Γ(n - k + 1), both near k ln k, cancelled to their rounding error, and all three compilers answered 1: binomial(-5/2, 10^20) is 7.52e29, and binomial(277.7, 36!) is 2e-11027, which is 0 in a double. Within the longs, an n whose factors never take the product to 0 ran k steps: binomial(-1/2, 10^12) did not return. From an order of a million, with |n| at most half of it and n not a whole number at least 0, the binomial is now (-1)^k Γ(k - n)/(Γ(k + 1) Γ(-n)), with ln Γ(k - n) - ln Γ(k + 1) from Stirling's series written as differences, so that nothing near k ln k is subtracted, and ln(1 + z) by its series where z is small. Every double past 2^53 is even. A whole n at least 0 below such a k, and a negative k, are 0, as they are within the longs. 2.6.0 did not compile the binomial. The values in the test are mpmath's. Found by compilesweep at seed 13; no issue was filed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2340 +/- ##
=======================================
Coverage 86.76% 86.76%
=======================================
Files 312 312
Lines 68598 68620 +22
Branches 19962 19971 +9
=======================================
+ Hits 59519 59539 +20
Misses 4914 4914
- Partials 4165 4167 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
A compiled
binomial(n, k)with a wholekis a product ofkfactors whilekfits a long, and past that it went through the gamma function.binomial(-5/2, 10^20)17.5225277806367e297.5225277806367504928e29binomial(277.7, 36!)102.0e-11027binomial(5, 10^20)100binomial(-1/2, 10^12)5.6418958354769e-75.6418958354768576325e-7Γ(k + 1)andΓ(n - k + 1), both neark ln k, cancelled to their rounding error.nwhose factors never take the product to 0 ranksteps.From an order of a million, with
|n|at most half of it andnnot a whole number at least 0, the binomial is now(-1)^k Γ(k - n)/(Γ(k + 1) Γ(-n)).ln Γ(k - n) - ln Γ(k + 1)comes from Stirling's series written as differences, so nothing neark ln kis subtracted.ln(1 + z)is taken by its series wherezis small.nat least 0 below such akis 0, and so is a negativek, as within the longs.2.6.0 did not compile the binomial, so there is no BREAKING entry. Found by compilesweep at seed 13. No issue was filed.
Tests: seven of the ten rows in
ACompiledBinomialOfALargeWholeOrderTestfail on master, two of them by the 30 s cap. The suite (18753), the five test projects and the eight harnesses pass, with 0 warnings.🤖 Generated with Claude Code