feanor_math::integer

Function binomial

Source
pub fn binomial<I>(n: El<I>, k: &El<I>, ring: I) -> El<I>
where I: RingStore + Copy, I::Type: IntegerRing,
Expand description

Computes the binomial coefficient of n and k, defined as n(n - 1)...(n - k + 1)/k!.

The above definition works for any n and k >= 0. If k < 0, we define the binomial coefficient to be zero. This function will not overflow, if the integer rings supports number up to binomial(n, k) * k.

§Example

// the binomial coefficient is equal to the number of combinations of fixed size
assert_eq!(
    binomial(10, &3, StaticRing::<i64>::RING) as usize,
    multiset_combinations(&[1; 10], 3, |_| ()).count()
);

§Availability

This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.