Repository navigation
The Catalan numbers - #2198
Merged
Merged
The Catalan numbers#2198
Conversation
catalannumber(n) was reserved by name in #2184 and is now Entity.CatalanNumberf, built by MathS.CatalanNumber. For a whole n >= 0 it is binomial(2n, n) / (n + 1), computed exactly up to n = 1000, so 1, 1, 2, 5, 14 from n = 0. Elsewhere it is 4^n Gamma(n + 1/2) / (sqrt(pi) Gamma(n + 2)), as Mathematica's CatalanNumber and SymPy's catalan are. That is -1/2 at -1, where the poles of the two gammas cancel, and 0 at every whole number below it, where the reciprocal of Gamma(n + 2) vanishes. A negative half-integer, a pole of Gamma(n + 1/2), has no value, and any other number is evaluated numerically: catalannumber(1/2) agrees with SymPy's 8/(3 pi) to 1e-25. The recurrence C(n + 1) = sum of C(i) C(n - i) holds. It prints as catalannumber(n), draws as \operatorname{C}_{n} and exports to SymPy's catalan. Part of #2182. 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 #2198 +/- ##
=======================================
Coverage 86.56% 86.56%
=======================================
Files 298 298
Lines 66493 66529 +36
Branches 19292 19300 +8
=======================================
+ Hits 57557 57589 +32
- Misses 4862 4865 +3
- Partials 4074 4075 +1
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.
catalannumber(n)was reserved in #2184. It is now a function. Part of #2182.n>= 0binomial(2n, n) / (n + 1), exact up ton = 1000: 1, 1, 2, 5, 14, …-1-1/2, where the poles of the two gamma functions cancel<= -20, where1/Γ(n + 2)vanishesΓ(n + 1/2)4^n Γ(n + 1/2) / (√π Γ(n + 2)), evaluated numericallyThese match Mathematica's
CatalanNumberand SymPy'scatalan.catalannumber(1/2)agrees with SymPy's8/(3π)to 1e-25, and the tests check the recurrenceC(n + 1) = Σ C(i) C(n − i). LaTeX output is\operatorname{C}_{n}and SymPy output iscatalan."catalannumber(4)".ToEntity().Simplify()4 * catalannumber14"catalannumber(-1)".ToEntity().Simplify()-catalannumber-1/2🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura