Special functions
Beyond the elementary functions, formulas may use the gamma function and its relatives, the Bessel functions of the first kind, the sine integral and the Fresnel integrals. Each has a certified enclosure at a rational point and over an interval, a Float64 version for previews, and a derivative, so values, ranges, integrals, zeros and extrema work as for any other formula.
| in a formula | meaning | direct call |
|---|---|---|
| gamma(x) | Γ(x), exact at positive integers; poles at 0, −1, −2, … | enclose.gamma(x, bits) |
| lgamma(x) | log Γ(x) for x > 0 | enclose.lgamma |
| digamma(x), trigamma(x) | Γ′/Γ and its derivative | enclose.digamma, enclose.polygamma(m, x) |
| beta(a, b) | Γ(a)Γ(b)/Γ(a+b), written out as it is read | enclose.beta(a, b) |
| besselJ(n, x) | J_n(x) for a whole number n | enclose.besselJ(n, x) |
| Si(x) | ∫₀ˣ sin(t)/t dt | enclose.Si |
| fresnelS(x), fresnelC(x) | ∫₀ˣ sin(πt²/2) dt and ∫₀ˣ cos(πt²/2) dt | enclose.fresnelS, enclose.fresnelC |
| P(a, x) and Q(a, x) = 1 − P, the regularized incomplete gamma functions | enclose.gammaP(a, x), enclose.gammaQ(a, x) | |
| I_x(a, b), the regularized incomplete beta function | enclose.betaI(x, a, b) | |
| erfc(x) | 1 − erf(x), written out as it is read | enclose.erfc |
Gamma by Stirling's series
For large y,
and for real y > 0 the error R_n is smaller than the first term left out. The series does not converge, but its terms shrink until k is about πy, so y is first raised by Γ(x) = Γ(x + N)/(x(x+1)⋯(x+N−1)) until the smallest term is below the precision asked for. The Bernoulli numbers B₂ₖ are exact rationals (bernoulli(m)). The polygamma functions use the derivative of the same series.
Over an interval between two poles, |Γ| is log-convex, so its maximum is at an end, and ψ = Γ′/Γ increases. The mean value form Γ(m) + Γ(X)·ψ(X)·(X − m) then gives an enclosure that tightens as the interval shrinks.
Entire functions by their power series
J_n, Si and the Fresnel integrals are sums of power series that converge everywhere:
The terms are built in fixed point, each rounded both down and up, with as many guard bits as the largest term needs (about 1.45·|x| bits, since the terms reach e^|x| before they fall). Once they more than halve, the rest of the series is below twice the last term. This is exact about what it claims, but it limits the range: |x| ≤ 4096 for J_n and Si, |x| ≤ 43 for the Fresnel integrals. Over an interval, each of these has a derivative bounded by 1, so the value at the midpoint, give or take the radius, is an enclosure.
Incomplete gamma and beta functions
These are the gamma and beta integrals stopped part of the way, divided by the whole:
They are the cumulative probabilities of the gamma, chi-square, beta, t and F distributions, which is what @ratmath/stats uses them for. Both come from series whose terms are all positive, so nothing cancels:
The terms are carried as intervals rounded outward. Once the ratio of one term to the one before is below some ρ < 1 for good, the rest of the series is at most the last term times ρ/(1 − ρ). For the beta function with x > 1/2 the reflection I_x(a, b) = 1 − I_(1−x)(b, a) is used first, so the ratios tend to at most 1/2. Far to the right, where 1 − P(a, x) is smaller than the precision asked for, the bound Γ(a, x) ≤ x^(a−1)e^(−x)·x/(x − a + 1) settles the answer without the series.
The parameters a and b are exact positive rationals; x may be a point or an interval, since both functions increase with x. The precision is absolute: the enclosure is about 2^(−bits) wide wherever the value lies in [0, 1].
What works with them
Taylor models do not know these functions, so integral switches to Taylor series in fixed point on halved pieces (the via line says so), and ranges and zero searches use interval evaluation. The Bessel functions carry their neighbours along: the series of J_n needs J_(n−1) and J_(n+1) one order lower, from J_n′ = (J_(n−1) − J_(n+1))/2. Limits at infinity and improper tails do not follow special functions.
The gamma function also appears without being named: Γ(5/2) is fn("t^(3/2)*exp(-t)", { variable: "t" }).improperIntegral(0, "inf"), and the two enclosures agree.
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.