Expand description
Scalar special-function primitives shared across the workspace.
These are pure (std/libm-only) numeric kernels with no upward crate
dependencies, so they live in the lowest crate (gam-math) and can be
consumed by any term/basis/inference code without inducing an SCC edge.
Functions§
- bessel_
i0_ centered_ second_ log_ derivative_ from_ log_ abs - Second log-scale derivative of the centered Bessel primitive:
d²/d(log η)²[log I0(η) − η], i.e. the derivative of the third termd1returned bybessel_i0_centered_terms(d1 = η d/dη[log I0(η) − η]). - bessel_
i0_ centered_ terms - Overflow-free centered Bessel value, ratio, and log-scale derivative.
- bessel_
i0_ centered_ terms_ from_ log_ abs - Stable centered Bessel terms when only
log(|eta|)is representable. - bessel_
i0_ log_ and_ ratio - Overflow-free
(log I0(eta), I1(|eta|) / I0(|eta|)). - bessel_
i0_ log_ minus_ abs_ and_ ratio - Overflow-free
(log I0(eta) - |eta|, I1(|eta|) / I0(|eta|)). - binomial_
coefficient_ f64 - Numerically stable
C(n,k) = n! / (k!·(n−k)!)asf64. Uses the symmetryC(n,k) = C(n, n−k)to keep the loop countmin(k, n−k)and the multiplicative recurrenceC(n,j+1) = C(n,j)·(n−j)/(j+1), avoiding the overflow of separate factorial evaluations. Returns0.0fork > nand exact integer results within2^53. - digamma
- Digamma
ψ(x) = d/dx ln Γ(x), forx > 0;NaNotherwise. - gauss_
legendre - Gauss-Legendre nodes and weights on
[-1, 1]fornpoints, computed via Newton iteration on the Legendre-polynomial roots (Bonnet’s three-term recurrence, cosine initial guess). Returns(nodes, weights)with nodes ascending; for oddnthe central node is exactly0.0. - pentagamma
- Pentagamma
ψ₃(x) = d⁴/dx⁴ ln Γ(x), forx > 0;NaNotherwise. - stable_
polynomial_ times_ exp_ neg - Evaluate
(Σ_k coeffs[k]·x^k) · exp(−x)without overflow. For moderatex ≤ 600uses Horner +exp(−x)directly; for very largexrewritesxᵈ · exp(−x) = exp(d·ln x − x)and runs Horner in1/x, which keeps both the polynomial sum and its multiplier inside double range. Returns0.0for non-finitexor emptycoeffs. - tetragamma
- Tetragamma
ψ₂(x) = d³/dx³ ln Γ(x), forx > 0;NaNotherwise. - trigamma
- Trigamma
ψ₁(x) = d²/dx² ln Γ(x), forx > 0;NaNotherwise.