The OpenD Programming Language

binomialCoefficient

Quickly computes binomial coefficient using extended precision floating point type mir.bignum.fp.

binomialCoefficient
(
uint coefficientSize = 128
)
(
ulong n
,
uint k
)
if (
coefficientSize % (size_t.sizeof * 8) == 0 &&
coefficientSize >= (size_t.sizeof * 8)
)

Parameters

n ulong

number elements in the set

k uint

number elements in the subset

Return Value

Type: auto

n choose k Complexity: O(min(k, n - k))

Examples

import mir.bignum.fp: Fp;
import mir.math.common: approxEqual;

static assert(is(typeof(binomialCoefficient(30, 18)) == Fp!128), typeof(binomialCoefficient(30, 18)).stringof);
static assert(cast(double) binomialCoefficient(30, 18) == 86493225);

assert(approxEqual(cast(double) binomialCoefficient(100, 40), 1.374623414580281150126736972e+28));

Meta