torsh-special
Special mathematical functions for ToRSh, leveraging scirs2-special for optimized implementations.
Overview
This crate provides a comprehensive collection of 135+ special mathematical functions organized into 19 mathematical families:
- Bessel Functions: J₀, J₁, Jₙ, Y₀, Y₁, Yₙ, I₀, I₁, Iₙ, K₀, K₁, Kₙ (cylindrical), spherical Bessel, Hankel functions
- Gamma Functions: Gamma, log-gamma, digamma, polygamma, beta
- Error Functions: erf, erfc, erfcx, erfinv, Fresnel integrals
- Elliptic Functions: Complete and incomplete elliptic integrals (K, E, F), Jacobi functions (sn, cn, dn), Weierstrass functions, theta functions
- Exponential Integrals: Ei, Eₙ, logarithmic integral, sine/cosine integrals
- Hypergeometric Functions: ₁F₁, ₂F₁, pFq, Meijer G, Appell F₁
- Orthogonal Polynomials: Legendre, Chebyshev, Hermite, Laguerre, Jacobi, Gegenbauer
- Advanced Functions: Riemann zeta, polylogarithm, Hurwitz zeta, Dirichlet eta, Barnes G
- Advanced Special: Dawson, Kelvin (ber, bei, ker, kei), parabolic cylinder, Spence, Struve, Voigt
- Airy Functions: Ai, Bi and their derivatives
- Coulomb Wave Functions: F_L(η,ρ), G_L(η,ρ) for quantum scattering
- Mathieu Functions: ce_n, se_n, characteristic values for periodic boundaries
- Lommel Functions: s_μ,ν, S_μ,ν for diffraction theory
- Spheroidal Wave Functions: Prolate and oblate angular/radial functions for electromagnetic scattering
- Lambert W Functions: Principal and secondary branches with applications
- Statistical Functions: Normal, Student's t, chi-squared, F-distribution CDFs/PDFs, incomplete beta
- Complex Functions: Complex gamma, zeta, erf, Bessel functions with branch cuts
- Performance Optimizations: SIMD-accelerated, fast approximations, smart caching, lookup tables
- Visualization Tools: Function analysis, accuracy comparison, ASCII plotting
Usage
Bessel Functions
use *;
use *;
// Bessel functions of the first kind
let x = tensor!;
let j0 = j0?; // J₀(x)
let j1 = j1?; // J₁(x)
let jn = jn?; // J₃(x)
// Bessel functions of the second kind
let y0 = y0?; // Y₀(x)
let y1 = y1?; // Y₁(x)
let yn = yn?; // Y₃(x)
// Modified Bessel functions
let i0 = i0?; // I₀(x)
let i1 = i1?; // I₁(x)
let k0 = k0?; // K₀(x)
let k1 = k1?; // K₁(x)
// Spherical Bessel functions
let j0_spherical = spherical_jn?;
let y0_spherical = spherical_yn?;
Gamma and Related Functions
// Gamma function
let x = tensor!;
let gamma_x = gamma?;
// Log-gamma function (more stable for large values)
let lgamma_x = lgamma?;
// Digamma (psi) function - derivative of log-gamma
let digamma_x = digamma?;
// Polygamma functions
let trigamma = polygamma?; // ψ'(x)
let tetragamma = polygamma?; // ψ''(x)
// Beta function
let a = tensor!;
let b = tensor!;
let beta_ab = beta?;
// Incomplete gamma functions
let lower_gamma = gammainc?; // γ(a,x)
let upper_gamma = gammaincc?; // Γ(a,x)
let regularized = gammaincp?; // P(a,x)
Error Functions
// Error function and complementary error function
let x = tensor!;
let erf_x = erf?;
let erfc_x = erfc?;
// Scaled complementary error function (for large x)
let erfcx_x = erfcx?; // exp(x²) * erfc(x)
// Inverse error functions
let p = tensor!;
let erfinv_p = erfinv?;
let erfcinv_p = erfcinv?;
// Fresnel integrals
let = fresnel?; // S(x) and C(x)
Elliptic Functions
// Complete elliptic integrals
let k = tensor!;
let ellipk = ellipk?; // K(k)
let ellipe = ellipe?; // E(k)
// Incomplete elliptic integrals
let phi = tensor!;
let ellipf = ellipf?; // F(φ,k)
let ellipe_inc = ellipeinc?; // E(φ,k)
// Jacobi elliptic functions
let u = tensor!;
let m = tensor!;
let = ellipj?;
Exponential and Logarithmic Integrals
// Exponential integral
let ei = expi?; // Ei(x)
// Exponential integral E_n(x)
let e1 = expn?; // E₁(x)
let e2 = expn?; // E₂(x)
// Logarithmic integral
let li = li?; // li(x)
// Sine and cosine integrals
let si = sici?.0; // Si(x)
let ci = sici?.1; // Ci(x)
// Hyperbolic sine and cosine integrals
let shi = shichi?.0; // Shi(x)
let chi = shichi?.1; // Chi(x)
Other Special Functions
// Riemann zeta function
let s = tensor!;
let zeta_s = zeta?;
// Airy functions
let x = tensor!;
let = airy?;
// Struve functions
let h0 = struve?; // H₀(x)
let h1 = struve?; // H₁(x)
// Hypergeometric functions
let a = tensor!;
let b = tensor!;
let c = tensor!;
let z = tensor!;
let hyp2f1 = hyp2f1?;
// Legendre polynomials
let n = 3;
let x = tensor!;
let pn = legendre?;
// Associated Legendre functions
let m = 1;
let pmn = lpmv?;
Spheroidal Wave Functions
use ;
// Prolate spheroidal wave functions (electromagnetic scattering)
let n = 2; // Degree
let m = 0; // Order
let c = 2.0; // Spheroidicity parameter
// Angular function S_nm(c, η) where η ∈ [-1, 1]
let eta = 0.5;
let s_value = prolate_angular?;
// Radial function R_nm(c, ξ) where ξ ∈ [1, ∞)
let xi = 2.0;
let r_value = prolate_radial?;
// Oblate spheroidal wave functions (acoustic cavities)
let xi_oblate = 0.5; // ξ ∈ [0, 1] for oblate
let s_oblate = oblate_angular?;
let r_oblate = oblate_radial?;
// Eigenvalues λ_nm(c)
let lambda_0 = spheroidal_eigenvalue?; // Spherical limit
let lambda = spheroidal_eigenvalue?; // Spheroidal
Batch Operations
All functions support batched operations:
// Batch computation on 2D tensors
let batch_x = randn; // 32 batches of 100 elements
let batch_gamma = gamma?;
let batch_erf = erf?;
// Broadcasting
let x = randn;
let y = randn;
let beta_xy = beta?; // Shape: [10, 20]
Complex Number Support
Some functions support complex inputs:
Integration with SciRS2
This crate fully leverages scirs2-special for:
- Optimized implementations of all special functions
- Hardware acceleration where available
- Consistent numerical accuracy
- Efficient vectorized operations
Numerical Considerations
- Functions are implemented with high numerical accuracy
- Appropriate algorithms are chosen for different input ranges
- Special care is taken near singularities and branch points
- Error bounds are documented for each function
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.