Skip to main content

Module numerics

Module numerics 

Source
Expand description

Numerical algorithms for physics simulation.

Provides root finding, quadrature, finite differences, and special functions used throughout the OxiPhysics engine.

Structs§

OnlineStats
Online (streaming) mean and variance using Welford’s algorithm.
RootResult
Result of a root-finding operation.

Functions§

adaptive_integrate
Adaptive Gaussian quadrature (recursive).
bernoulli_numbers
Compute the first n Bernoulli numbers B₀, B₁, …, B_{n-1}.
bessel_j0
Bessel function J0(x) (zeroth order, first kind).
bessel_j1
Bessel function J1(x) (first order, first kind).
beta
Complete beta function B(a, b) = Γ(a)Γ(b)/Γ(a+b).
bilinear_arr
Bilinear interpolation on a 2×2 grid (array form).
bisect
Bisection root finding on interval [a, b].
brent
Brent’s method — robust root finding combining bisection, secant, and inverse quadratic interpolation.
cfl_number
Compute the CFL (Courant–Friedrichs–Lewy) number.
chebyshev_t
Chebyshev polynomial T_n(x) of the first kind.
continued_fraction
Evaluate a generalised continued fraction using the Lentz algorithm.
digamma
Digamma function ψ(x) = d/dx ln(Γ(x)).
dt_from_cfl
Compute the maximum safe time step for a given CFL target.
ei
Exponential integral Ei(x) for x > 0.
erf
Error function erf(x) using a rational approximation.
erfc
Complementary error function erfc(x) = 1 - erf(x).
erfinv
Inverse error function erfinv(y) for y ∈ (-1, 1).
factorial
Factorial n! as f64 (using gamma).
find_x_for_value
Solve f(x) = target by translating to a zero-finding problem via Brent.
finite_diff_central
First derivative of f at x using centered differences with step h.
finite_diff_second
Second derivative of f at x using centered differences.
gamma
Gamma function approximation (Lanczos, g=7).
gauss_legendre5
Gauss-Legendre 5-point quadrature on [-1, 1], mapped to [a, b].
gauss_legendre_n
Gauss-Legendre quadrature of order n on [a, b].
gauss_legendre_nw
Gauss-Legendre nodes and weights for n-point quadrature on [-1, 1].
gradient_3d
Gradient of f: R^3 → R using central differences.
hessian
Hessian of f: R^n → R as a flat n×n matrix using central differences.
horner
Evaluate a polynomial using Horner’s method.
inc_beta
Regularized incomplete beta function I(x; a, b).
legendre
Evaluate a Legendre polynomial P_n(x) via recurrence.
lerp_scalar
Linear interpolation scalar: a + t*(b-a).
lgamma
Log gamma function.
ln_via_cf
Evaluate the natural logarithm via its continued fraction representation.
newton
Newton-Raphson root finding.
normal_cdf
Normal CDF Φ(x).
regula_falsi
Regula falsi (Illinois variant) root finding.
richardson_derivative
Compute the first derivative of f at x using Richardson extrapolation.
richardson_second_derivative
Compute the second derivative of f at x using Richardson extrapolation.
romberg
Romberg integration of f over [a, b].
secant
Secant method root finding.
simpson
Simpson’s rule integration of f over [a, b] with n subintervals (n must be even).
smootherstep
Smoother step (Ken Perlin’s 6th degree).
smoothstep
Smooth Hermite interpolation (smoothstep).
sqrt2_cf
Compute √2 via its continued fraction [1; 2, 2, 2, …].
stirling_factorial
Stirling’s approximation for n! as f64.
stirling_ln_factorial
Stirling’s approximation for ln(n!).
stirling_relative_error
Relative error of Stirling’s approximation vs exact ln(Γ(n+1)).
trapezoid_tabulated
Trapezoidal rule for tabulated data.
trilinear_arr
Trilinear interpolation on a 2×2×2 grid (array form).