Special Mathematical Functions
Trinity implements a comprehensive library of special functions in src/sacred/special.zig. These functions appear throughout mathematical physics, probability theory, and signal processing. This page documents each function family, its mathematical definition, implementation approach, and connection to Trinity's architecture.
Overviewβ
| Function | Symbol | Domain | Implementation |
|---|---|---|---|
| Gamma | Gamma(x) | x > 0 (or x not in Z-) | Lanczos approximation |
| Log-Gamma | ln(Gamma(x)) | x > 0 | Direct Lanczos (avoids overflow) |
| Riemann Zeta | zeta(s) | Re(s) > 1 | Direct summation |
| Hurwitz Zeta | zeta(s, q) | Re(s) > 1, q > 0 | Direct summation |
| Error Function | erf(x) | all x | Abramowitz-Stegun approximation |
| Bessel J | J_n(x) | all x, n >= 0 | Miller's backward recurrence |
| Bessel Y | Y_n(x) | x > 0, n >= 0 | Forward recurrence |
| Modified Bessel I | I_n(x) | all x | Backward recurrence |
| Modified Bessel K | K_n(x) | x > 0 | Forward recurrence |
| Fresnel S, C | S(x), C(x) | all x | Rational approximation |
| Airy Ai, Bi | Ai(x), Bi(x) | all x | Power series / asymptotic |
| Elliptic K | K(m) | 0 β€ m < 1 | AGM iteration |
| Elliptic E | E(m) | 0 β€ m β€ 1 | AGM iteration |
| Legendre P | P_n(x) | |x| β€ 1 | Three-term recurrence |
| Hermite H | H_n(x) | all x | Three-term recurrence |
| Laguerre L | L_n(x) | x β₯ 0 | Three-term recurrence |
Source: src/sacred/special.zig (31,758 bytes)
Gamma Functionβ
Definition
Gamma(x) = integral from 0 to infinity of t^(x-1) * e^(-t) dt
For positive integers: Gamma(n) = (n-1)!
Propertiesβ
Gamma(1) = 1
Gamma(1/2) = sqrt(pi)
Gamma(x+1) = x * Gamma(x) (recurrence)
Gamma(x) * Gamma(1-x) = pi / sin(pi*x) (reflection formula)
Implementation: Lanczos Approximationβ
The Lanczos approximation (1964) provides a rapidly converging series:
Gamma(z+1) = sqrt(2*pi) * (z + g + 0.5)^(z+0.5) * e^(-(z+g+0.5)) * A(z)
where g = 7 and A(z) is a rational function with precomputed coefficients. Trinity uses the standard 9-coefficient Lanczos series achieving approximately 15 digits of precision across the entire domain.
For negative arguments, the reflection formula is applied:
Gamma(z) = pi / (sin(pi*z) * Gamma(1-z))
Connection to Trinityβ
The Gamma function connects to ternary computing through:
- Radix economy: The function x/ln(x) (whose minimum at x=e justifies base 3) is related to Gamma via the digamma function psi(x) = d/dx ln(Gamma(x))
- Volume of n-spheres: V_n(r) = pi^(n/2) / Gamma(n/2 + 1) * r^n. The concentration of measure on ternary hyperspheres (Theorem 11) uses this formula
Reference: Lanczos, C. "A Precision Approximation of the Gamma Function." SIAM Journal on Numerical Analysis 1, pp. 86--96, 1964.
Riemann Zeta Functionβ
Definition
zeta(s) = sum from n=1 to infinity of 1/n^s
Converges for Re(s) > 1. Has analytic continuation to all of C except s = 1 (simple pole).
Propertiesβ
zeta(2) = pi^2 / 6 (Basel problem, Euler 1734)
zeta(4) = pi^4 / 90
zeta(2k) = (-1)^(k+1) * B_{2k} * (2*pi)^(2k) / (2*(2k)!) (Bernoulli connection)
zeta(-1) = -1/12 (Ramanujan summation)
Euler Productβ
zeta(s) = product over primes p of 1/(1 - p^(-s))
This connects the zeta function to the distribution of prime numbers -- one of the deepest connections in mathematics.
Implementationβ
Trinity uses direct summation with convergence acceleration for Re(s) > 1. The Hurwitz generalization zeta(s, q) = sum(1/(n+q)^s) is also implemented.
Connection to Trinityβ
- Bernoulli numbers B_n connect zeta to the number sequences in
src/sacred/sequences.zig - The value zeta(2) = pi^2/6 appears in the sacred formula engine's parameter search
- The functional equation zeta(s) = 2^s * pi^(s-1) * sin(pi*s/2) * Gamma(1-s) * zeta(1-s) unifies all sacred constants (2, pi, Gamma) in a single identity
Reference: Riemann, B. "Ueber die Anzahl der Primzahlen unter einer gegebenen Grosse." Monatsberichte der Berliner Akademie, pp. 671--680, 1859. Edwards, H. M. Riemann's Zeta Function. Dover Publications, 2001.
Bessel Functionsβ
Definition
Bessel functions are solutions to Bessel's differential equation:
x^2 * y'' + x * y' + (x^2 - n^2) * y = 0
Two linearly independent solutions: J_n(x) (first kind) and Y_n(x) (second kind).
Bessel Functions of the First Kind J_n(x)β
J_n(x) = sum from k=0 to infinity of (-1)^k / (k! * Gamma(n+k+1)) * (x/2)^(n+2k)
Modified Bessel Functions I_n(x) and K_n(x)β
Solutions to the modified equation x^2y'' + xy' - (x^2 + n^2)*y = 0:
I_n(x) = i^(-n) * J_n(i*x) (exponentially growing)
K_n(x) (exponentially decaying)
Implementationβ
- J_n: Miller's backward recurrence (numerically stable)
- Y_n: Forward recurrence from J_n via Neumann's formula
- I_n: Backward recurrence (analogous to J_n)
- K_n: Forward recurrence
Connection to Trinityβ
Bessel functions model cylindrical wave propagation and appear in:
- Vibration modes of circular membranes (FPGA clock distribution analysis)
- Diffraction patterns (optical computing)
- The zeros of J_0(x) appear at approximately 2.405, 5.520, 8.654... -- these are not simply related to phi or pi, serving as a reminder that not all mathematical constants reduce to the sacred formula
Reference: Watson, G. N. A Treatise on the Theory of Bessel Functions. Cambridge University Press, 2nd edition, 1944.
Error Functionsβ
Definition
erf(x) = (2/sqrt(pi)) * integral from 0 to x of e^(-t^2) dt
erfc(x) = 1 - erf(x)
Propertiesβ
erf(0) = 0
erf(infinity) = 1
erf(-x) = -erf(x) (odd function)
erf(1) β 0.8427
Implementationβ
Abramowitz and Stegun (1964) rational approximation with maximum error < 1.5e-7:
erf(x) β 1 - (a1*t + a2*t^2 + a3*t^3) * e^(-x^2)
where t = 1/(1 + 0.47047*x)
Connection to Trinityβ
The error function is central to VSA noise analysis:
- When bundling k noisy vectors, the probability of correct recovery at each coordinate is:
P(correct) = (1 + erf(sqrt(k) * (1-2p) / sqrt(4p(1-p)))) / 2
where p is the per-trit noise probability. This connects Theorem 14 (bundle convergence) to the Gaussian approximation via the CLT.
Reference: Abramowitz, M. and Stegun, I. A. Handbook of Mathematical Functions. Dover Publications, 1964. National Bureau of Standards, Applied Mathematics Series 55.
Elliptic Integralsβ
Definition
Complete elliptic integral of the first kind:
K(m) = integral from 0 to pi/2 of 1/sqrt(1 - m*sin^2(theta)) d(theta)
Complete elliptic integral of the second kind:
E(m) = integral from 0 to pi/2 of sqrt(1 - m*sin^2(theta)) d(theta)
where 0 β€ m < 1 is the parameter (m = k^2 where k is the modulus).
Propertiesβ
K(0) = pi/2
E(0) = pi/2
E(1) = 1
K(m) β infinity as m β 1 (logarithmic singularity)
Legendre's Relationβ
E(m) * K(1-m) + E(1-m) * K(m) - K(m) * K(1-m) = pi/2
This identity connects the two elliptic integrals in a way reminiscent of the golden ratio's self-referential properties.
Implementationβ
Arithmetic-Geometric Mean (AGM) iteration -- one of the fastest converging algorithms in numerical mathematics:
a_0 = 1, b_0 = sqrt(1-m)
a_(n+1) = (a_n + b_n) / 2
b_(n+1) = sqrt(a_n * b_n)
K(m) = pi / (2 * a_infinity)
Converges quadratically (doubles correct digits each step).
Connection to Trinityβ
- Elliptic integrals compute arc lengths of ellipses, connecting to the sacred geometry module
- The AGM iteration itself is an example of iterative normalization (like Ricci flow and bundle) -- two sequences converging to the same limit
Reference: Borwein, J. M. and Borwein, P. B. Pi and the AGM. Wiley, 1987. This monograph provides the definitive treatment of the AGM and its connections to elliptic functions, pi computation, and number theory.
Orthogonal Polynomialsβ
Legendre Polynomials P_n(x)β
Definition (Legendre)
Solutions to Legendre's equation on [-1, 1]:
(1-x^2) y'' - 2x y' + n(n+1) y = 0
Recurrence: (n+1) P_(n+1)(x) = (2n+1) x P_n(x) - n P_(n+1)(x)
P_0(x) = 1
P_1(x) = x
P_2(x) = (3x^2 - 1) / 2
P_3(x) = (5x^3 - 3x) / 2
Orthogonality: integral from -1 to 1 of P_m(x) P_n(x) dx = 2/(2n+1) * delta_mn
Hermite Polynomials H_n(x)β
Definition (Hermite)
Solutions to the Hermite equation:
y'' - 2x y' + 2n y = 0
Recurrence: H_(n+1)(x) = 2x H_n(x) - 2n H_(n+1)(x)
H_0(x) = 1
H_1(x) = 2x
H_2(x) = 4x^2 - 2
H_3(x) = 8x^3 - 12x
Weight function: w(x) = e^(-x^2) on (-infinity, infinity). Hermite polynomials are the natural basis for Gaussian-weighted function spaces -- directly relevant to the CLT analysis of bundle operations.
Laguerre Polynomials L_n(x)β
Definition (Laguerre)
Solutions to Laguerre's equation on [0, infinity):
x y'' + (1-x) y' + n y = 0
Recurrence: (n+1) L_(n+1)(x) = (2n+1-x) L_n(x) - n L_(n+1)(x)
L_0(x) = 1
L_1(x) = 1 - x
L_2(x) = (x^2 - 4x + 2) / 2
Weight function: w(x) = e^(-x) on [0, infinity). Laguerre polynomials appear in quantum mechanics (radial wavefunctions of hydrogen) and in the analysis of queuing systems.
Connection to Trinityβ
Orthogonal polynomial families provide complete bases for function approximation on different domains. They connect to Trinity through:
- Fourier-like analysis: any function on the ternary hypersphere can be expanded in spherical harmonics (related to Legendre polynomials)
- Quantum mechanics: the hydrogen atom's energy levels are computed using Laguerre polynomials, connecting to the sacred formula's particle physics constants
- Three-term recurrences: all orthogonal polynomials satisfy three-term recurrences, echoing the ternary structure
Reference: Szego, G. Orthogonal Polynomials. American Mathematical Society Colloquium Publications 23, 4th edition, 1975.
Fresnel Integrals and Airy Functionsβ
Fresnel Integralsβ
S(x) = integral from 0 to x of sin(pi*t^2/2) dt
C(x) = integral from 0 to x of cos(pi*t^2/2) dt
These describe the intensity pattern of light diffracted by a straight edge (Fresnel diffraction). They spiral toward (1/2, 1/2) as x β infinity, tracing the Cornu spiral -- a curve whose curvature increases linearly with arc length.
Airy Functionsβ
Ai(x) -- decays exponentially for x > 0, oscillates for x < 0
Bi(x) -- grows exponentially for x > 0, oscillates for x < 0
Solutions to the Airy equation y'' - x*y = 0. They describe the transition between oscillatory and exponential behavior in quantum tunneling and WKB approximation.
Reference: Olver, F. W. J. et al., eds. NIST Digital Library of Mathematical Functions. https://dlmf.nist.gov/, Release 1.2.1, 2024. The definitive modern reference for all special functions, superseding Abramowitz and Stegun.
Accuracy Summaryβ
| Function | Method | Typical Precision | Domain Limitations |
|---|---|---|---|
| Gamma | Lanczos (g=7, 9 terms) | ~15 digits | Poles at 0, -1, -2, ... |
| Log-Gamma | Direct Lanczos | ~15 digits | x > 0 |
| Zeta | Direct sum (50 terms) | ~10 digits | Re(s) > 1 only |
| erf | Rational approx | ~7 digits | All x |
| Bessel J | Backward recurrence | ~12 digits | |x| < 50 recommended |
| Elliptic K | AGM (25 iterations) | ~15 digits | 0 β€ m < 1 |
| Legendre P | Three-term recurrence | Exact for n < 20 | |x| β€ 1 |
| Hermite H | Three-term recurrence | Exact for n < 15 | Overflow for large n |
All implementations can be found in src/sacred/special.zig.
Explore with TRI CLIβ
tri math exotic # Apery zeta(3), Catalan G, Feigenbaum delta/alpha
tri math physical # 12 fundamental physics constants
tri math chaos # Feigenbaum constants + logistic map demo
tri math all # Display ALL 76+ constants
Referencesβ
- Abramowitz, M. and Stegun, I. A., eds. Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. National Bureau of Standards, Applied Mathematics Series 55, 1964. The classical reference for special functions, used for implementation coefficients.
- Olver, F. W. J. et al., eds. NIST Digital Library of Mathematical Functions. https://dlmf.nist.gov/. The modern successor to Abramowitz and Stegun, with comprehensive error bounds and computational advice.
- Lanczos, C. "A Precision Approximation of the Gamma Function." SIAM Journal on Numerical Analysis 1, pp. 86--96, 1964.
- Riemann, B. "Ueber die Anzahl der Primzahlen unter einer gegebenen Grosse." Monatsberichte der Berliner Akademie, pp. 671--680, 1859.
- Edwards, H. M. Riemann's Zeta Function. Dover Publications, 2001.
- Watson, G. N. A Treatise on the Theory of Bessel Functions. Cambridge University Press, 2nd edition, 1944.
- Borwein, J. M. and Borwein, P. B. Pi and the AGM: A Study in Analytic Number Theory and Computational Complexity. Wiley, 1987.
- Szego, G. Orthogonal Polynomials. American Mathematical Society Colloquium Publications 23, 4th edition, 1975.
- Temme, N. M. Special Functions: An Introduction to the Classical Functions of Mathematical Physics. Wiley, 1996.
phi^2 + 1/phi^2 = 3 = TRINITY