Skip to content

CatalanNumber ​

The nth Catalan number CnC_n, counting balanced bracket sequences, binary trees, polygon triangulations, and many other structures of size n.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaCatalan numberMathWorldCatalanNumberWikidataQ270513nLabCatalan numberDLMF26.5.E1OEISA000108Wolfram LanguageCatalanNumber!
CatalanNumber(n)the nth Catalan number CnC_n.
SageMathcatalan_number(n)!SymPycatalan(n)JuliaCombinatorics.catalannum(n)
Typed signatures
TypePackageApplies
(integer) -> integercompute-enginealways
(number) -> numberanalyticreplaces compute-enginealways
(any) -> anynumber-theoryreplaces analyticalways

Domain: Combinatorics

Details
  • The Catalan numbers have the closed form Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}.
  • They satisfy the recurrence Cn+1=∑i=0nCi Cn−iC_{n+1} = \sum_{i=0}^{n} C_i\,C_{n-i} with C0=1C_0 = 1.
  • CnC_n is the number of monotonic lattice paths from one corner of an n×nn \times n grid to the opposite corner that stay below the diagonal.
  • compute-engine extends CnC_n to real and complex arguments through the Binomial gamma-function form Cn=Γ(2n+1)/(Γ(n+1) Γ(n+2))C_n = \Gamma(2n+1)/(\Gamma(n+1)\,\Gamma(n+2)). At a negative integer it instead follows Wolfram's own Cn=(2nn)−(2nn+1)C_n = \binom{2n}{n} - \binom{2n}{n+1} with (nk)=0\binom{n}{k} = 0 for a negative integer kk, giving C−1=−1C_{-1} = -1 and Cn=0C_n = 0 for every integer n≤−2n \le -2 (the smooth Gamma-ratio limit disagrees at n=−1n=-1, giving −12-\tfrac12 -- see the divergence note on that example).

Examples

2 more kept as data, checked against the oracles
Basic #
live ↗
InCatalanNumber(0)\mathrm{CatalanNumber}(0)Out11
live ↗
InCatalanNumber(1)\mathrm{CatalanNumber}(1)Out11
live ↗
InCatalanNumber(5)\mathrm{CatalanNumber}(5)Out4242
live ↗
InCatalanNumber(10)\mathrm{CatalanNumber}(10)Out16 79616\,796
live ↗
InCatalanNumber(30)\mathrm{CatalanNumber}(30)Out3 814 986 502 092 3043\,814\,986\,502\,092\,304
Scope #

C−1=−1C_{-1} = -1, from (2nn)−(2nn+1)\binom{2n}{n} - \binom{2n}{n+1} at n=−1n=-1 ((−2−1)−(−20)=0−1\binom{-2}{-1} - \binom{-2}{0} = 0 - 1)

live ↗
InCatalanNumber(−1)\mathrm{CatalanNumber}(-1)Out−1-1

Cn=0C_n = 0 for every integer n≤−2n \le -2 -- both (2nn)\binom{2n}{n} and (2nn+1)\binom{2n}{n+1} have a negative lower index there

live ↗
InCatalanNumber(−2)\mathrm{CatalanNumber}(-2)Out00
live ↗
InCatalanNumber(−5)\mathrm{CatalanNumber}(-5)Out00

Threads element-wise over a list, as Wolfram's Listable heads do

live ↗
InCatalanNumber([1,2,3,4])\mathrm{CatalanNumber}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack)Out[1,2,5,14]\bigl\lbrack1, 2, 5, 14\bigr\rbrack

Half-integer arguments evaluate exactly through Cn=Γ(2n+1)Γ(n+1) Γ(n+2)C_n = \frac{\Gamma(2n+1)}{\Gamma(n+1)\,\Gamma(n+2)}

live ↗
InCatalanNumber(52)\mathrm{CatalanNumber}(\frac{5}{2})Out1 024105π\frac{1\,024}{105π}

Real arguments evaluate as Γ(2n+1)Γ(n+1) Γ(n+2)\frac{\Gamma(2n+1)}{\Gamma(n+1)\,\Gamma(n+2)}

live ↗
InCatalanNumber(2.3)\mathrm{CatalanNumber}(2.3)Out2.590 352 154 019 323 32.590\,352\,154\,019\,323\,3

Complex arguments evaluate through the same Gamma form

live ↗
InCatalanNumber(1.2+i)\mathrm{CatalanNumber}(1.2+i)Out0.730 728 624 207 283 9+0.569 846 406 969 342 5i0.730\,728\,624\,207\,283\,9+0.569\,846\,406\,969\,342\,5i

C1/2=83πC_{1/2} = \frac{8}{3\pi} by analytic continuation

live ↗
InCatalanNumber(12)\mathrm{CatalanNumber}(\frac{1}{2})Out83π\frac{8}{3π}

An Interval argument gives an enclosing Interval

live ↗
InCatalanNumber(Interval(0.5,0.6))\mathrm{CatalanNumber}(\mathrm{Interval}(0.5, 0.6))OutInterval(0.848 826 363 156 775 1,0.862 540 968 873 452 3)\mathrm{Interval}(0.848\,826\,363\,156\,775\,1, 0.862\,540\,968\,873\,452\,3)
Applications #

The 5 ways to balance 3 pairs of parentheses

live ↗
InCatalanNumber(3)\mathrm{CatalanNumber}(3)Out55

The 14 triangulations of a hexagon, and the 14 binary trees with 4 leaves. See Binomial

live ↗
InCatalanNumber(4)\mathrm{CatalanNumber}(4)Out1414
live ↗
InAssuming(n∈Z∧n≥0,FullSimplify(CatalanNumber(n)=22n+1(2n−1)!!(2n+2)!!))\mathrm{Assuming}(n∈ℤ∧n≥0, \mathrm{FullSimplify}(\mathrm{CatalanNumber}(n)=\frac{2^{2n+1}(2n-1)!!}{(2n+2)!!}))OutCatalanNumber(n)=(2n−1)!!×22n+1(2n+2)!!\mathrm{CatalanNumber}(n)=\frac{(2n-1)!!×2^{2n+1}}{(2n+2)!!}
Properties #

Closed form Cn=1n+1(2nn)C_n = \frac{1}{n+1}\binom{2n}{n}, here at n=5n = 5

live ↗
In(2×55)5+1\frac{\binom{2×5}{5}}{5+1}Out4242

Equivalently Cn=(2nn)−(2nn+1)C_n = \binom{2n}{n} - \binom{2n}{n+1}

live ↗
In(105)−(106)\binom{10}{5}-\binom{10}{6}Out4242

The consecutive ratio is Cn+1Cn=2(2n+1)n+2\frac{C_{n+1}}{C_n} = \frac{2(2n+1)}{n+2}

live ↗
InCatalanNumber(6)CatalanNumber(5)\frac{\mathrm{CatalanNumber}(6)}{\mathrm{CatalanNumber}(5)}Out227\frac{22}{7}

Segner's recurrence Cn+1=∑i=0nCi Cn−iC_{n+1} = \sum_{i=0}^{n} C_i\,C_{n-i}, here at n=3n = 3

live ↗
InCatalanNumber(4)=∑i=03CatalanNumber(i)CatalanNumber(3−i)\mathrm{CatalanNumber}(4)=\sum_{i=0}^3\mathrm{CatalanNumber}(i)\mathrm{CatalanNumber}(3-i)OutTrue\mathrm{True}

The Catalan generating function 1−1−4x2x\frac{1-\sqrt{1-4x}}{2x}

live ↗
InGeneratingFunction(CatalanNumber(n),n,x)\mathrm{GeneratingFunction}(\mathrm{CatalanNumber}(n), n, x)Out1−1−4x2x\frac{1-\sqrt{1-4x}}{2x}

Zero at negative integers

live ↗
InCatalanNumber(−10)\mathrm{CatalanNumber}(-10)Out00

Known value · Wolfram MathematicalFunctionData, CatalanNumber

Negative index gives zero, not a pole

live ↗
InCatalanNumber(−9)\mathrm{CatalanNumber}(-9)Out00

Known value · Wolfram MathematicalFunctionData, CatalanNumber

Vanishes for a negative integer index

live ↗
InCatalanNumber(−8)\mathrm{CatalanNumber}(-8)Out00

Known value · Wolfram MathematicalFunctionData, CatalanNumber

Catalan numbers are zero below index 0

live ↗
InCatalanNumber(−7)\mathrm{CatalanNumber}(-7)Out00

Known value · Wolfram MathematicalFunctionData, CatalanNumber

Another negative index, another zero

live ↗
InCatalanNumber(−6)\mathrm{CatalanNumber}(-6)Out00

Known value · Wolfram MathematicalFunctionData, CatalanNumber

Negative arguments give 0

live ↗
InCatalanNumber(−4)\mathrm{CatalanNumber}(-4)Out00

Known value · Wolfram MathematicalFunctionData, CatalanNumber

Zero at every negative integer, not just −1-1

live ↗
InCatalanNumber(−3)\mathrm{CatalanNumber}(-3)Out00

Known value · Wolfram MathematicalFunctionData, CatalanNumber

live ↗
InDifferenceRootReduce(CatalanNumber(k),k)\mathrm{DifferenceRootReduce}(\mathrm{CatalanNumber}(k), k)OutDifferenceRoot((y,n)↦{(n+2)y(n+1)−2(2n+1)y(n)=0y(0)=1)⊲k\mathrm{DifferenceRoot}((y, n)↦\begin{cases}(n+2)y(n+1)-2(2n+1)y(n)=0\\y(0)=1\end{cases})\lhd k
Neat examples #

They grow fast: C15C_{15} already passes nine million

live ↗
InCatalanNumber(15)\mathrm{CatalanNumber}(15)Out9 694 8459\,694\,845
About
Examples33
Checked againstWolfram Language 31 agree1 differ1 unevaluatedSageMath 22 agree2 differ4 errorSymPy 27 agree3 differmpmath 27 agree1 errormathlib4 10 agreeJulia 13 agree1 differ14 errorOscar 3 agreeRust 3 agree1 differ
CrosswalkWikipediaMathWorldWikidatanLabDLMFOEISWolfram LanguageSageMathSymPyJulia

Implementation

mappedwolframpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts
mappedmathlib4packages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts

binomial(2n, n)/(n + 1), continued by the gamma function.

See also: Binomial, BellNumber