Skip to content

Take a compiled binomial of a large whole order through a ratio of gammas - #2340

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-binomial-of-a-huge-whole-order
Nov 3, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
a-compiled-binomial-of-a-huge-whole-order

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

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.

compiled, all three compilers master this PR mpmath
binomial(-5/2, 10^20) 1 7.5225277806367e29 7.5225277806367504928e29
binomial(277.7, 36!) 1 0 2.0e-11027
binomial(5, 10^20) 1 0 0
binomial(-1/2, 10^12) does not return 5.6418958354769e-7 5.6418958354768576325e-7
  • Past the longs: the logarithms of Γ(k + 1) and Γ(n - k + 1), both near k ln k, cancelled to their rounding error.
  • Within the longs: an n whose factors never take the product to 0 ran k steps.

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)).

  • ln Γ(k - n) - ln Γ(k + 1) comes from Stirling's series written as differences, so nothing near k ln k is subtracted.
  • ln(1 + z) is taken by its series where z is small.
  • Every double past 2^53 is even, which gives the sign.
  • A whole n at least 0 below such a k is 0, and so is a negative k, 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 ACompiledBinomialOfALargeWholeOrderTest fail 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

…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>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Nov 3, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.76%. Comparing base (493b7ef) to head (90768f5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ces/AngouriMath/Numerics/CombinatorialFunctions.cs 85.71% 1 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           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     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.31% <85.71%> (+<0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ces/AngouriMath/Numerics/CombinatorialFunctions.cs 92.56% <85.71%> (-1.19%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit d41933e into master Nov 3, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Nov 3, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-compiled-binomial-of-a-huge-whole-order branch November 3, 2026 04:35
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