Boost logo

Boost Users :

Subject: Re: [Boost-users] [Math] Fractional binomial_coefficient
From: ajb_at_[hidden]
Date: 2009-08-31 20:42:51


G'day Ralf.

Quoting "Ralf M." <rm_at_[hidden]>:

> the binomial coefficients are usually used with integers,
> but it is also possible to get the binomial coefficient
> of real values (cf. http://en.wikipedia.org/wiki/Binomial_coefficient ).
>
> Maybe this could be added to the boost math library.
> Here's a sample implementation using standard g++:
>
> template <class T> T Choose(T n, T k)
> {
> return exp(lgamma(n + 1.0) - lgamma(k + 1.0) - lgamma(n - k + 1.0));
> }

Boost.Math almost has it:

#include <boost/math/special_functions/beta.hpp>

template<typename RealType>
RealType
binomial(RealType n, RealType k)
{
     return 1.0 / ((n+1) * boost::math::beta(n - k + 1, k + 1));
}

There is also binomial_distribution and beta_distribution if that's
what you're really after.

Cheers,
Andrew Bromage


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net