Skip to content

beta

beta(a, b): number

Defined in: packages/math-analysis/src/beta.ts:73

The beta function B(a, b) = Γ(a)Γ(b) / Γ(a + b).

The ratio that normalizes a Beta distribution, and through it Student’s t, the F distribution and the binomial. Written out by hand it overflows for shapes far smaller than the ones whose ratio is still perfectly representable, which is the whole reason it is a function rather than an expression.

B decays fast: it underflows to zero from around a + b ≈ 1500. Reach for logBeta at that point, or any time you would immediately take a logarithm of the result.

Relative error is a few ulps while all three gammas are representable. Past that it is bounded below by one ulp of each half-exponent — B(500, 500) has a logarithm of −695, so no binary64 route gets nearer than about 4e-14.

O(1) time, O(1) memory.

number

First shape parameter, positive.

number

Second shape parameter, positive.

number

B(a, b), or NaN when either parameter is non-positive, where the defining ratio has no real value.

beta(2, 3); // 0.08333333333333336 — 1/12
beta(0.5, 0.5); // 3.1415926535897905 — π
beta(500, 500); // 1.4799015991255068e-302
beta(2000, 2000); // 0 — underflowed; use logBeta
```;
## See
- [logBeta](logBeta.md) for shapes whose `B` underflows.
- [The gamma and beta functions](https://anthochamp.pages.grenadine.io/node-essentials/topics/math/functions/gamma/)