Repository navigation
A compiled gamma ratio past the doubles is taken in logarithms - #2251
Merged
Merged
Conversation
A compiled binomial coefficient, falling or rising factorial or Catalan number at an argument that is not whole is a ratio of gamma functions. Past 170! a factorial is past the doubles where the ratio need not be, so the ratio was oo/oo, NaN: binomial(216, pi) is about 2954596.68, fallingfactorial(300, 1/2) about 17.33, catalannumber(2017/5) about 5.16e238, and each was NaN. A ratio whose terms are under the doubles was 0/0, as binomial(-601/2, 7/3) was, which is about 109419.24. Where the ratio does not come out as a number, it is now the exponential of the difference of the factorials' logarithms. SpecialFunctions.LogFactorial is the logarithm of Gamma(z + 1), by the Lanczos approximation the compiled gamma function already uses, and by reflection below 1/2. At a real argument its imaginary part is a multiple of pi, odd where the factorial is negative, which gives the ratio's sign. None of the ratios is 0 away from a pole, which the callers answer first, so a ratio that came out as a number is kept as it was, to the last place. GammaRatioCompilationTest compares ten values with mpmath 1.3.0's at 50 digits, under both compilers and over double, and all ten fail on master. Two of them are past the doubles, binomial(2000, 1001/2) and catalannumber(1001), and are +oo. Evaluation is NaN for three of the ten, binomial(10, 601/2), binomial(2000, 1001/2) and catalannumber(-2017/5), and EvalNumerical throws CannotEvalException for catalannumber(1001). The last two of the three are past 1e200 or under 1e-200, the decimal range #1498 is about. Those are evaluation's, and not changed here. Found by work/compilesweep. Fixes #2248. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2251 +/- ##
==========================================
- Coverage 86.71% 86.69% -0.02%
==========================================
Files 310 310
Lines 67785 67800 +15
Branches 19664 19671 +7
==========================================
+ Hits 58781 58782 +1
- Misses 4892 4903 +11
- Partials 4112 4115 +3
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 coefficient, falling or rising factorial or Catalan number at an argument that is not whole is a ratio of gamma functions. Past
170!a factorial is past the doubles, though the ratio need not be, so the compiled value was∞/∞, which isNaN. Where the ratio doesn't come out as a number, it is now taken as the exponential of the difference of the factorials' logarithms. A ratio that does come out as a number is unchanged, to the last place.binomial(216, pi)NaN2954596.67906177652954596.679061264fallingfactorial(300, 1/2)NaN17.3277…17.32772645443628catalannumber(2017/5)NaN5.1595508663051626E+2385.159550866305278e+238binomial(-601/2, 7/3)NaN109419.239…109419.2391603972catalannumber(1001)NaN+oo8.17e597SpecialFunctions.LogFactorialis the logarithm ofΓ(z + 1). It uses the Lanczos approximation the compiled gamma function already uses, with reflection below 1/2. At a real argument its imaginary part is a multiple of π, which gives the ratio's sign.GammaRatioCompilationTestchecks ten values against mpmath under both compilers and overdouble. All ten fail on master. Evaluation has no value for three of them, andEvalNumericalthrows forcatalannumber(1001); that is evaluation's, and is left as it is (see #1498).Suite 18177 passed. The F# wrapper suite, the Mcp, Terminal and InteractiveWrapper suites and the AOT smoke test pass.
Fixes #2248.
🤖 Generated with Claude Code