Repository navigation
The Catalan numbers compile - #2216
Merged
Merged
Conversation
catalannumber compiles in both compilers, on the interpreter's terms: exact at a whole index up to 1000, by C_(k + 1) = C_k 2 (2k + 1)/(k + 2) in integers and rounded once, -1/2 at -1, 0 at a whole number below it, no value at a negative half-integer, and 4^n Γ(n + 1/2)/(√π Γ(n + 2)) elsewhere. Both compilers agree with evaluation on the combinatorial grid, and both, with evaluation, with mpmath at 1,191 points on the real axis and off it. Part of #2195 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2216 +/- ##
=======================================
Coverage 86.61% 86.61%
=======================================
Files 305 305
Lines 67338 67365 +27
Branches 19544 19550 +6
=======================================
+ Hits 58326 58351 +25
- Misses 4900 4902 +2
Partials 4112 4112
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Oct 30, 2026
Rafael-SOWNet
added a commit
that referenced
this pull request
Oct 30, 2026
The compiled binomial took a whole lower argument as a product of ratios in doubles, (n - i)/(i + 1), each rounded, so binomial(54, 45) came out 5317936259.999995 where evaluation gives 5317936260. Of the 2485 binomials with 0 <= k <= n < 70, 1173 were not the integer. The factorial powers and the double factorial, products of whole factors, rounded at each step once a partial product passed 2^53, and so were off in the last places from there. At whole arguments each is now computed exactly and rounded once: - the binomial by binomial(m, i + 1) = binomial(m, i) (m - i)/(i + 1), whose division leaves no remainder, over the shorter of k and m - k, and for a negative n by (-1)^k binomial(k - n - 1, k); - the products in doubles while each partial product is below 2^53, where every step is exact, and past it in EInteger, rounded by EFloat or, for a negative order's reciprocal, by ERational. The Catalan numbers were computed exactly, in #2216, and rounded by (double)BigInteger, which truncates: 246 of the first 1000 were a unit low in the last place, C_32 = 55534064877048200 coming out 55534064877048190. They are rounded by EFloat now. Nothing else in the library rounds a BigInteger to a double for a result. A factor of 0 is checked for before the product, so a partial product past the doubles' range is known to stay past it, and the loop stops there. Checked against evaluation exactly, as doubles, in both compilers: every two-argument function on a grid of 90 whole first arguments, up to 10^12, and 58 whole second arguments from -12 to 45; the binomial past 2^53 and past the doubles, among others at (60, 30), (1100, 550), (3000, 1500) and (-1, 4001); the double factorial from -301 to 320; and the Catalan numbers from 0 to 1000. The expected value is the exact rational rounded once by ERational, since ToNumerics goes through a decimal whose exponent has a floor, and reads 1/299!! as 0. On master 9 of these tests fail. Part of #2195. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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 #2195, item 3:
catalannumbercompiles in FastExpression and in the LINQ compiler. It follows the interpreter's terms (#2198):C_(k + 1) = C_k 2 (2k + 1)/(k + 2)in integers, where the division leaves no remainder, and rounded once. A product of the ratios in doubles rounds at each step, and gaveC_5 = 41.99999999999999.-1it is-1/2, and at a whole number below that,0.4^n Γ(n + 1/2)/(√π Γ(n + 2)).catalannumberis new since 2.6.0, so its entry says it compiles and there is no 2.6.0 row.Checked against mpmath (dps 30), compiled and evaluated alike, at 1,191 points: the real axis from
-5to5in steps of0.05, except the negative whole numbers and half-integers, which the tests take, and 1,000 random complex points. All agree to1e-9.Tests:
TheCatalanNumbersAreWhatEvaluationSayscompares both compilers with evaluation on the combinatorial grid and at-4,10,30,7/3and-7/3.ACatalanNumberAtAWholeIndexIsExactchecksC_5 = 42andC_30 = 3814986502092304exactly.C_5andC_(-1)in a native build.🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura