Skip to content

Binomial ​

The binomial coefficient (nk)\binom{n}{k}, the number of k-element subsets of an n-element set.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaBinomial coefficientMathWorldBinomialCoefficientWikidataQ209875Encyclopedia of MathematicsBinomial_coefficientsBritannicatopic/binomial-coefficientDLMF26.31.2.iFungrimBinomial✓Fungrim entryOEISA073354Wolfram LanguageBinomial!
Binomial(n, k)the binomial coefficient (nk)\binom{n}{k}.
SageMathbinomial(n, k)!SymPybinomial(n, k)Oscarbinomial(ZZ(n), ZZ(k))Juliabinomial(ZZ(n), ZZ(k))Rustbinomial(n, k)
Typed signatures
TypePackageApplies
(complex | infinity, complex | infinity) -> numberanalyticreplaces compute-enginealways
(complex | infinity, complex | infinity) -> numbercompute-enginealways
(complex | infinity, complex | infinity) -> numbernumber-theoryreplaces analyticalways

Domain: Combinatorics

Details
  • The general definition runs through the Gamma function: (nk)=Γ(n+1)Γ(k+1) Γ(n−k+1)\binom{n}{k} = \frac{\Gamma(n+1)}{\Gamma(k+1)\,\Gamma(n-k+1)}.
  • Symmetric in its arguments: (nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k}.
  • Pascal's rule builds each row from the last: (nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k}.
  • Row sums give ∑k=0n(nk)=2n\sum_{k=0}^{n} \binom{n}{k} = 2^n.
  • compute-engine evaluates only integer n and k: k outside [0,n][0, n] gives 0 for nonnegative n, while a negative n switches to the generalized falling-factorial formula rather than the Gamma form.
  • A Gaussian or otherwise complex n and/or k also evaluates, through the same Gamma-function identity: exact for an integer k, numeric otherwise.

Examples

15 more kept as data, checked against the oracles
Basic #
live ↗
In(52)\binom{5}{2}Out1010
live ↗
In(103)\binom{10}{3}Out120120
live ↗
In(42)\binom{4}{2}Out66

Choosing none of n is always 1 way

live ↗
In(50)\binom{5}{0}Out11

Choosing all of n is always 1 way

live ↗
In(55)\binom{5}{5}Out11
live ↗
In(84)\binom{8}{4}Out7070

Symbolic n: (n0)=1\binom{n}{0} = 1 for any n

live ↗
In(n0)\binom{n}{0}Out11

Symbolic n: (n1)=n\binom{n}{1} = n

live ↗
In(n1)\binom{n}{1}Outnn

(nn−1)=n\binom{n}{n-1} = n for symbolic n

live ↗
In(nn−1)\binom{n}{n-1}Outnn
Scope #

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

live ↗
In([2,3,5,7,11]3)\binom{\bigl\lbrack2, 3, 5, 7, 11\bigr\rbrack}{3}Out[0,1,10,35,165]\bigl\lbrack0, 1, 10, 35, 165\bigr\rbrack

Half-integer arguments evaluate exactly through the Gamma function: here n−k=1n - k = 1, so the answer is just n=92n = \frac{9}{2}

live ↗
In(9272)\binom{\frac{9}{2}}{\frac{7}{2}}Out92\frac{9}{2}

Real arguments evaluate through the Gamma function

live ↗
In(8.5−4.2)\binom{8.5}{-4.2}Out0.000 060 499 248 402 283 480 067 60.000\,060\,499\,248\,402\,283\,480\,067\,6

A real n with integer k: 0.5 (−0.5)(−1.5)3!=0.0625\frac{0.5\,(-0.5)(-1.5)}{3!} = 0.0625, up to the last bignum digit

live ↗
In(0.53)\binom{0.5}{3}Out0.062 50.062\,5

A rational nn with integer kk gives the exact falling-factorial value (1/22)=−18\binom{1/2}{2} = -\frac{1}{8}

live ↗
In(122)\binom{\frac{1}{2}}{2}Out−18-\frac{1}{8}

(−1/23)=−516\binom{-1/2}{3} = -\frac{5}{16}, the central-binomial series coefficient

live ↗
In(−123)\binom{-\frac{1}{2}}{3}Out−516-\frac{5}{16}

(nn)=1\binom{n}{n} = 1 for symbolic n

live ↗
In(nn)\binom{n}{n}Out11

A Gaussian-integer n: (1+i5)=−1+i12\binom{1+i}{5} = -\frac{1+i}{12}, exact

live ↗
In(1+i5)\binom{1+i}{5}Out−112−112i-\frac{1}{12}-\frac{1}{12}i

Complex n and k evaluate through the Gamma function

live ↗
In(2+i7−3i)\binom{2+i}{7-3i}Out−75.468 347 382 223 04+106.815 265 970 790 55i-75.468\,347\,382\,223\,04+106.815\,265\,970\,790\,55i

Interval arithmetic in kk: (1/2k)\binom{1/2}{k} is decreasing here, so the endpoints swap

live ↗
In(12Interval(0.5,0.6))\binom{\frac{1}{2}}{\mathrm{Interval}(0.5, 0.6)}OutInterval(0.928 145 553 850 705 4,1)\mathrm{Interval}(0.928\,145\,553\,850\,705\,4, 1)

Non-integer arguments are fine, evaluated to 20 digits

live ↗
InN((7315),20)N(\binom{\frac{7}{3}}{\frac{1}{5}}, 20)Out1.333 125 424 465 028 652 21.333\,125\,424\,465\,028\,652\,2

A symbolic top with integer bottom expands to a polynomial in nn

live ↗
In(n4)\binom{n}{4}Out124(n×(n−3)(n−2)(n−1))\frac{1}{24}(n×(n-3)(n-2)(n-1))

Applied to a matrix, a polynomial in the matrix with exact entries

live ↗
InMatrixFunction(()↦(_1⁡2),[[5π6,0],[3π2,−π2]])\mathrm{MatrixFunction}(()↦\binom{\operatorname{\_1}}{2}, \bigl\lbrack\bigl\lbrack\frac{5π}{6}, 0\bigr\rbrack, \bigl\lbrack\frac{3π}{2}, -\frac{π}{2}\bigr\rbrack\bigr\rbrack)Out[[172(5π(5π−6)),0],[164(5π(5π−6))−164(9π(2+π)),π(2+π)8]]\bigl\lbrack\bigl\lbrack\frac{1}{72}(5π(5π-6)), 0\bigr\rbrack, \bigl\lbrack\frac{1}{64}(5π(5π-6))-\frac{1}{64}(9π(2+π)), \frac{π(2+π)}{8}\bigr\rbrack\bigr\rbrack
Applications #

The number of distinct 5-card hands dealt from a standard 52-card deck

live ↗
In(525)\binom{52}{5}Out2 598 9602\,598\,960

The probability of exactly 3 heads in 10 fair coin tosses

live ↗
In(103)210\frac{\binom{10}{3}}{2^{10}}Out15128\frac{15}{128}
Properties #

Symmetry: (nk)=(nn−k)\binom{n}{k} = \binom{n}{n-k}

live ↗
In(103)=(107)\binom{10}{3}=\binom{10}{7}OutTrue\mathrm{True}

Pascal's rule: (n−1k−1)+(n−1k)=(nk)\binom{n-1}{k-1} + \binom{n-1}{k} = \binom{n}{k}

live ↗
In(92)+(93)=(103)\binom{9}{2}+\binom{9}{3}=\binom{10}{3}OutTrue\mathrm{True}

Row sums give ∑k(nk)=2n\sum_k \binom{n}{k} = 2^n, here at n=4n = 4

live ↗
In(40)+(41)+(42)+(43)+(44)=24\binom{4}{0}+\binom{4}{1}+\binom{4}{2}+\binom{4}{3}+\binom{4}{4}=2^4OutTrue\mathrm{True}

Sum of squares along a row: ∑k(nk)2=(2nn)\sum_k \binom{n}{k}^2 = \binom{2n}{n}

live ↗
In∑k=06(6k)2=(126)\sum_{k=0}^6\binom{6}{k}^2=\binom{12}{6}OutTrue\mathrm{True}

Vandermonde's identity: ∑k(mk)(nr−k)=(m+nr)\sum_k \binom{m}{k}\binom{n}{r-k} = \binom{m+n}{r}

live ↗
In∑k=03(5k)(43−k)=(93)\sum_{k=0}^3\binom{5}{k}\binom{4}{3-k}=\binom{9}{3}OutTrue\mathrm{True}

The alternating row sum vanishes: ∑k(−1)k(nk)=0\sum_k (-1)^k \binom{n}{k} = 0 for n>0n > 0

live ↗
In∑k=06(−1)k(6k)\sum_{k=0}^6(-1)^{k}\binom{6}{k}Out00

The factorial form (nk)=n!k! (n−k)!\binom{n}{k} = \frac{n!}{k!\,(n-k)!}. See Factorial

live ↗
In(73)=7!3!×4!\binom{7}{3}=\frac{7!}{3!×4!}OutTrue\mathrm{True}
live ↗
In(12−12)+(1212)\binom{\frac{1}{2}}{-\frac{1}{2}}+\binom{\frac{1}{2}}{\frac{1}{2}}Out32\frac{3}{2}

Known value · Wolfram MathematicalFunctionData, Binomial, Pascal's rule

live ↗
In∑k=02(2k)2(k+2k)2\sum_{k=0}^2\binom{2}{k}^2\binom{k+2}{k}^2Out7373

Known value · Wolfram MathematicalFunctionData, Binomial, Apéry's numbers

live ↗
In∑k=0⌊12⌋(22k+1)×2k\sum_{k=0}^{\lfloor\frac{1}{2}\rfloor}\binom{2}{2k+1}×2^{k}Out22

Known value · Wolfram MathematicalFunctionData, Binomial, Pell numbers

live ↗
In(1212)+(1232)\binom{\frac{1}{2}}{\frac{1}{2}}+\binom{\frac{1}{2}}{\frac{3}{2}}Out11

Known value · Wolfram MathematicalFunctionData, Binomial, FunctionalEquations

Possible issues #

Choosing more elements than available (k>nk > n) gives 0, not an error

live ↗
In(57)\binom{5}{7}Out00

A negative k also gives 0

live ↗
In(5−1)\binom{5}{-1}Out00

A negative n uses the generalized formula (nk)=n(n−1)⋯(n−k+1)k!\binom{n}{k} = \frac{n(n-1)\cdots(n-k+1)}{k!} rather than 0

live ↗
In(−52)\binom{-5}{2}Out1515

Both arguments negative integers: the limiting definition gives (−3−5)=(−32)=6\binom{-3}{-5} = \binom{-3}{2} = 6, not 0

live ↗
In(−3−5)\binom{-3}{-5}Out66
Neat examples #

The central binomial coefficient (10050)\binom{100}{50} has 30 digits

live ↗
In(10050)\binom{100}{50}Out100 891 344 545 564 193 334 812 497 256100\,891\,344\,545\,564\,193\,334\,812\,497\,256
About
Examples55
Checked againstWolfram Language 53 agree1 differSageMath 38 agree2 differ2 errorSymPy 47 agree5 differ2 unevaluatedmathlib4 14 agree18 errorOscar 26 agree2 differ8 errorJulia 17 agree3 differ7 errorRust 16 agree13 differ7 error
CrosswalkWikipediaMathWorldWikidataEncyclopedia of MathematicsBritannicaDLMF ×2FungrimFungrim entry ×23OEISWolfram LanguageSageMathSymPyOscarJuliaRust

Implementation

mappedwolframpackages/oracle/src/mappings.ts

Wolfram's (and compute-engine's) Binomial extends to negative n and k via the reflection identities in its docs (e.g. Binomial[5,-2] = 0, Binomial[-7,2] = 28, Binomial[-5,-7] = 15); the crates behind sage/oscar/julia/rust bottom out at unsigned or non-negative-only integer types and diverge there — a convention gap, not a bug on either side. Verified against wolframscript.

mappedsympypackages/oracle/src/mappings.ts

Wolfram's (and compute-engine's) Binomial extends to negative n and k via the reflection identities in its docs (e.g. Binomial[5,-2] = 0, Binomial[-7,2] = 28, Binomial[-5,-7] = 15); the crates behind sage/oscar/julia/rust bottom out at unsigned or non-negative-only integer types and diverge there — a convention gap, not a bug on either side. Verified against wolframscript.

mappedsagepackages/oracle/src/mappings.ts

Wolfram's (and compute-engine's) Binomial extends to negative n and k via the reflection identities in its docs (e.g. Binomial[5,-2] = 0, Binomial[-7,2] = 28, Binomial[-5,-7] = 15); the crates behind sage/oscar/julia/rust bottom out at unsigned or non-negative-only integer types and diverge there — a convention gap, not a bug on either side. Verified against wolframscript.

mappedoscarpackages/oracle/src/mappings.ts

Wolfram's (and compute-engine's) Binomial extends to negative n and k via the reflection identities in its docs (e.g. Binomial[5,-2] = 0, Binomial[-7,2] = 28, Binomial[-5,-7] = 15); the crates behind sage/oscar/julia/rust bottom out at unsigned or non-negative-only integer types and diverge there — a convention gap, not a bug on either side. Verified against wolframscript.

mappedjuliapackages/oracle/src/mappings.ts

Wolfram's (and compute-engine's) Binomial extends to negative n and k via the reflection identities in its docs (e.g. Binomial[5,-2] = 0, Binomial[-7,2] = 28, Binomial[-5,-7] = 15); the crates behind sage/oscar/julia/rust bottom out at unsigned or non-negative-only integer types and diverge there — a convention gap, not a bug on either side. Verified against wolframscript.

mappedmathlib4packages/oracle/src/mappings.ts

Wolfram's (and compute-engine's) Binomial extends to negative n and k via the reflection identities in its docs (e.g. Binomial[5,-2] = 0, Binomial[-7,2] = 28, Binomial[-5,-7] = 15); the crates behind sage/oscar/julia/rust bottom out at unsigned or non-negative-only integer types and diverge there — a convention gap, not a bug on either side. Verified against wolframscript.

mappedrustpackages/oracle/src/mappings.ts

Wolfram's (and compute-engine's) Binomial extends to negative n and k via the reflection identities in its docs (e.g. Binomial[5,-2] = 0, Binomial[-7,2] = 28, Binomial[-5,-7] = 15); the crates behind sage/oscar/julia/rust bottom out at unsigned or non-negative-only integer types and diverge there — a convention gap, not a bug on either side. Verified against wolframscript.

See also: Factorial, Multinomial, Pochhammer