Skip to main content

Module special

Module special 

Source
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§

binomial_coefficient_f64
Numerically stable C(n,k) = n! / (k!·(n−k)!) as f64. Uses the symmetry C(n,k) = C(n, n−k) to keep the loop count min(k, n−k) and the multiplicative recurrence C(n,j+1) = C(n,j)·(n−j)/(j+1), avoiding the overflow of separate factorial evaluations. Returns 0.0 for k > n and exact integer results within 2^53.
stable_polynomial_times_exp_neg
Evaluate (Σ_k coeffs[k]·x^k) · exp(−x) without overflow. For moderate x ≤ 600 uses Horner + exp(−x) directly; for very large x rewrites xᵈ · exp(−x) = exp(d·ln x − x) and runs Horner in 1/x, which keeps both the polynomial sum and its multiplier inside double range. Returns 0.0 for non-finite x or empty coeffs.