What this calculator does
This tool evaluates the lower incomplete beta function, defined as the definite integral \(B_x(a,b) = \int_{0}^{x} t^{a-1}(1-t)^{b-1}\, dt\). The integrand \(t^{a-1}(1-t)^{b-1}\) is the kernel of the beta and beta-binomial distributions. When the upper limit \(x = 1\) (with lower limit 0), the result equals the complete beta function \(B(a,b) = \Gamma(a)\Gamma(b)/\Gamma(a+b)\).
How to use it
Enter the two shape parameters: a (variable a) and b. Both should be positive. Set the integration interval lower bound and the upper bound x (typically between 0 and 1). Choose the number of divisions n — the count of Gauss-Legendre nodes. Higher n gives more accuracy; n = 20 is plenty for smooth integrands. Leave the interval at [0, 1] to obtain the complete beta function.
The formula explained
The integral is computed with Gauss-Legendre quadrature. Standard nodes \(x_i\) and weights \(w_i\) on [-1, 1] are generated as roots of the Legendre polynomial \(P_n\) using Newton's method, then linearly mapped to the chosen interval \([c, d]\): $$t_i = \frac{d-c}{2}\cdot x_i + \frac{d+c}{2}.$$ The integral is then approximated by $$\frac{d-c}{2}\cdot \sum w_i\, f(t_i).$$ Because Gauss-Legendre integrates polynomials of degree up to \(2n-1\) exactly, it converges extremely fast for smooth integrands.
Worked example
With a = 3, b = 5, interval [0, 1] and n = 20, the result is the complete beta function $$B(3,5) = \frac{2! \cdot 4!}{7!} = \frac{48}{5040} = 0.0095238095\ldots = \frac{1}{105}.$$ The quadrature reproduces this to full double precision.
Known Beta Function Values for Checking Results
The complete beta function is \(B(a,b)=\dfrac{\Gamma(a)\,\Gamma(b)}{\Gamma(a+b)}\). Setting x = 1 in this calculator should reproduce the values below. Use them to check your inputs and the quadrature accuracy.
| a | b | Calculation | B(a,b) exact | Decimal |
|---|---|---|---|---|
| 1 | 1 | \(\Gamma(1)\Gamma(1)/\Gamma(2)=1\) | 1 | 1.000000 |
| 2 | 2 | \(1\cdot 1/3!\) | 1/6 | 0.166667 |
| 2 | 3 | \(1\cdot 2/4!\) | 1/12 | 0.083333 |
| 3 | 3 | \(2\cdot 2/5!\) | 1/30 | 0.033333 |
| 3 | 5 | \(2\cdot 24/7!=48/5040\) | 1/105 | 0.009524 |
| 0.5 | 0.5 | \(\Gamma(1/2)^2/\Gamma(1)=\pi\) | π | 3.141593 |
| 1 | b | \(\int_0^1 (1-t)^{b-1}dt\) | 1/b | – |
| a | 1 | \(\int_0^1 t^{a-1}dt\) | 1/a | – |
Identities for verification
- Symmetry: \(B_x(a,b)+B_{1-x}(b,a)=B(a,b)\). Compute both incomplete values and check that they sum to the complete value.
- Special case b = 1: \(B_x(a,1)=\dfrac{x^{a}}{a}\). For example, \(B_{0.5}(2,1)=0.25/2=0.125\).
- Complete case: \(B_1(a,b)=B(a,b)\) and \(B_0(a,b)=0\).
Accuracy vs. Number of Nodes and Parameter Choice
An n-point Gauss-Legendre rule integrates polynomials up to degree 2n−1 exactly. When a and b are positive integers, the integrand \(t^{a-1}(1-t)^{b-1}\) is a polynomial of degree a+b−2, so a modest n already gives the exact answer up to rounding. When a < 1 or b < 1, the integrand is singular at an endpoint and the rule converges only algebraically.
| Scenario | Exact value | Integrand | Nodes needed / behaviour | Expected absolute error |
|---|---|---|---|---|
| a=3, b=5, x=1 | 1/105 ≈ 0.0095238 | Polynomial, degree 6 | Exact once 2n−1 ≥ 6, so n ≥ 4. Any of n = 10, 20, 50, 100 qualifies. | Near machine precision (about 10−16 or below) |
| a=2, b=2, x=0.5 | 1/12 ≈ 0.0833333 | \(t(1-t)\), degree 2 | Exact for n ≥ 2, so n = 10 to 100 all agree. | Near machine precision |
| a=0.5, b=0.5, x=1, n=10 | π ≈ 3.1415927 | \(1/\sqrt{t(1-t)}\), singular at both ends | Slow algebraic convergence | Large; of order 10−1 or somewhat less |
| a=0.5, b=0.5, x=1, n=20 | π | Same | Error roughly halves | Roughly ∝ 1/n |
| a=0.5, b=0.5, x=1, n=50 | π | Same | Error shrinks only about 2.5× from n = 20 | Roughly ∝ 1/n |
| a=0.5, b=0.5, x=1, n=100 | π | Same | Result approaches π, but only to about 2 to 3 digits | Roughly ∝ 1/n, about 10× smaller than at n = 10 |
Why the difference? Gauss-Legendre error depends on how smooth the integrand is on the whole interval. For an endpoint singularity \(t^{\alpha}\) with −1 < α < 0, the error decays like \(n^{-2(\alpha+1)}\). With α = −1/2 (a = 0.5) that is about \(n^{-1}\). The error figures for the singular case are scaling estimates, not exact outputs, so the last digits you see may differ. Smooth cases (a, b ≥ 1 as integers) reach near machine precision, which is about 15 to 16 significant digits in double precision.
Practical tip: if a or b is below 1, increase n as far as the tool allows. You can also check the result against the exact value from the Gamma function, or against the symmetry identity.
Definitions & Glossary
- Lower incomplete beta function \(B_x(a,b)\)
- The integral \(B_x(a,b)=\int_0^x t^{a-1}(1-t)^{b-1}\,dt\) for 0 ≤ x ≤ 1. This tool allows a general lower limit c, so it integrates from c to x.
- Complete beta function \(B(a,b)\)
- The same integral over [0, 1], i.e. \(B_1(a,b)\). It equals \(\Gamma(a)\Gamma(b)/\Gamma(a+b)\).
- Regularized incomplete beta \(I_x(a,b)\)
- The ratio \(I_x(a,b)=B_x(a,b)/B(a,b)\), which runs from 0 to 1. It is the cumulative distribution function of the Beta(a, b) distribution.
- Shape parameters a and b
- Positive real numbers that control the integrand. The exponent a−1 sets the behaviour near t = 0 and b−1 sets it near t = 1. Values below 1 make the integrand blow up at that endpoint.
- Gauss-Legendre nodes and weights
- On [−1, 1], the nodes \(x_i\) are the n roots of the Legendre polynomial \(P_n\). The weights are \(w_i=\dfrac{2}{(1-x_i^2)\,[P_n'(x_i)]^2}\). For an interval [c, d] the nodes map to \(t_i=\tfrac{d-c}{2}x_i+\tfrac{d+c}{2}\), and the integral is approximated by \(\tfrac{d-c}{2}\sum w_i f(t_i)\). The rule is exact for polynomials up to degree 2n−1.
- Legendre polynomial \(P_n\)
- The degree-n polynomial from the family orthogonal on [−1, 1] with weight 1, normalised so that \(P_n(1)=1\). Examples: \(P_1=x\) and \(P_2=(3x^2-1)/2\).
- Integrable singularity
- A point where the integrand becomes infinite but the integral still converges. Here this happens at t = 0 when 0 < a < 1, and at t = 1 when 0 < b < 1. Quadrature rules for smooth functions converge slowly in this case.
- Gamma function relation
- \(B(a,b)=\Gamma(a)\Gamma(b)/\Gamma(a+b)\), where \(\Gamma(n)=(n-1)!\) for positive integers and \(\Gamma(1/2)=\sqrt{\pi}\). This gives exact reference values for checking numerical results.
FAQ
What if \(0 < a < 1\) or \(0 < b < 1\)? The integrand has an integrable singularity at an endpoint. Gauss-Legendre nodes are interior, so the result stays finite, but accuracy drops — raise n.
How do I get the regularized incomplete beta \(I_x(a,b)\)? Divide this result by the complete beta function (compute it by setting the interval to [0, 1]).
Why is the result negative sometimes? If the upper limit is below the lower limit, the signed integral is negative, which is mathematically correct.