Function reference · Math

binom

Computes a binomial coefficient: the number of ways to choose k items from n.

Notation

binom(n, k)

Write it in an expression: nerdamer('binom(5,2)'), or in the Playground.

nerdamer.binom

nerdamer.binom(n: ExpressionInput, k: ExpressionInput): Expression

A method on the default import. Arguments can be strings, as in Notation.

Parameters

n
The number of items, a nonnegative integer.
k
How many to choose, an integer.

Returns

The exact coefficient, as an integer.

Examples

Choose 2 items from 5.

binom(5,2)
// → 10
Open in Playground

Large results stay exact.

binom(52,5)
// → 2598960
Open in Playground

A k outside 0 to n gives 0.

binom(5,7)
// → 0
Open in Playground

With a symbolic argument, the call is kept as it is.

binom(n,2)
// → binom(n, 2)
Open in Playground

Good to know

  • A negative n is an error.

JavaScript examples

nerdamer.binom(5, 2).text()
// → 10

← Back to Function reference