pub fn beta_inc(a: f64, b: f64, x: f64) -> f64Expand description
The regularized incomplete beta function $I_{x}(a, b) = \frac{1}{B(a, b)} \int_{0}^{x} u^{a-1} (1 - u)^{b-1}, du$, $a, b > 0$, $x \in [0, 1]$: the distribution function of a $\mathrm{Beta}(a, b)$ variable, and the binomial tail $P(X \ge k) = I_{p}(k, n - k + 1)$ of $X \sim \mathrm{Bin}(n, p)$. The continued fraction of Press et al. (Numerical Recipes, §6.4) by the modified Lentz method, on $I_{1-x}(b, a) = 1 - I_{x}(a, b)$ when $x > (a + 1)/(a + b + 2)$, where it converges faster; relative error about $10^{-14}$.
§Examples
use comnum_math::beta_inc;
// I_x(a, 1) = x^a, and Beta(a, a) is symmetric about 1/2
assert!((beta_inc(3.0, 1.0, 0.7) - 0.343).abs() < 1e-15);
assert!((beta_inc(4.5, 4.5, 0.5) - 0.5).abs() < 1e-15);
assert!((beta_inc(3.5, 4.5, 0.4) - 0.429_090_217_274_695_76).abs() < 1e-14);