SComb.Math (scomb v0.3.0)

Copy Markdown View Source

Some useful math functions. These are generally used internally by the library.

Summary

Functions

Returns the binomial coefficient, the number of ways to choose k elements from n

Returns the factorial of a number. Highly optimized for n < 30

Returns the multinomial coefficient, the number of ways to arrange groups of counts interchangeable elements in a row

Functions

binomial(n, k)

@spec binomial(non_neg_integer(), non_neg_integer()) :: non_neg_integer()

Returns the binomial coefficient, the number of ways to choose k elements from n

Example

iex> binomial 5, 2
10

iex> binomial 2, 5
0

factorial(n)

@spec factorial(non_neg_integer()) :: pos_integer()

Returns the factorial of a number. Highly optimized for n < 30

Example

iex> factorial 5
120

multinomial(counts)

@spec multinomial([non_neg_integer()]) :: pos_integer()

Returns the multinomial coefficient, the number of ways to arrange groups of counts interchangeable elements in a row

Example

iex> multinomial [2, 1]
3