3
$\begingroup$

Anyone know a fast and concise way of calculating the Beta $B(a,b)$ function for smallish (<10) real $a$ and $b$.

For integer $a$ and $b$ I have:

$B(a,b) = \prod\limits_{j=1}^b \frac{j}{a+j}$

which has tiny code and is also pretty fast. I've see some methods that rely on the Gamma or log Gamma function:

$\log B(a,b) = \log \Gamma(a) + \log \Gamma(b) - \log \Gamma(a+b)$

using approximations of $\log \Gamma$, but I was wondering if there was a more direct way.

$\endgroup$
6
  • $\begingroup$ "Numerical Recipes in C" (highly recommended) says to use the Gamma function. $\endgroup$
    – Stopple
    Aug 2, 2011 at 18:12
  • 3
    $\begingroup$ I beg to differ: Numerical recipes in C is one of the banes of human existence, and has led to many, many bad implementations being used. $\endgroup$
    – Igor Rivin
    Aug 2, 2011 at 18:20
  • $\begingroup$ try out: netlib.org/slatec esp. netlib.org/slatec/src/dgamln.f $\endgroup$
    – Suvrit
    Aug 2, 2011 at 18:35
  • $\begingroup$ Fortran eugh. ;) $\endgroup$
    – Lucas
    Aug 2, 2011 at 19:33
  • 1
    $\begingroup$ Good idea Suvrit. Looking at source now. I'm sure Fortran is pretty damn efficient, it's just that I'm not really familiar with it, mainly because I find it ugly. From a practical point of view I'm sure it's great. $\endgroup$
    – Lucas
    Aug 2, 2011 at 22:09

1 Answer 1

2
$\begingroup$

There's nothing more straightforward than using the gamma function relationship, I believe (perhaps using Lanczos's approximation to compute the gamma functions). Of course, for integer arguments, the product representation is much faster. You could probably also consider the special case when one of the beta function's arguments is a semi-integer, and accordingly construct the appropriate product representation (involving $\sqrt{\pi}$).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.