Skip to main content

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​

FunctionSymbolDomainImplementation
GammaGamma(x)x > 0 (or x not in Z-)Lanczos approximation
Log-Gammaln(Gamma(x))x > 0Direct Lanczos (avoids overflow)
Riemann Zetazeta(s)Re(s) > 1Direct summation
Hurwitz Zetazeta(s, q)Re(s) > 1, q > 0Direct summation
Error Functionerf(x)all xAbramowitz-Stegun approximation
Bessel JJ_n(x)all x, n >= 0Miller's backward recurrence
Bessel YY_n(x)x > 0, n >= 0Forward recurrence
Modified Bessel II_n(x)all xBackward recurrence
Modified Bessel KK_n(x)x > 0Forward recurrence
Fresnel S, CS(x), C(x)all xRational approximation
Airy Ai, BiAi(x), Bi(x)all xPower series / asymptotic
Elliptic KK(m)0 ≀ m < 1AGM iteration
Elliptic EE(m)0 ≀ m ≀ 1AGM iteration
Legendre PP_n(x)|x| ≀ 1Three-term recurrence
Hermite HH_n(x)all xThree-term recurrence
Laguerre LL_n(x)x β‰₯ 0Three-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​

FunctionMethodTypical PrecisionDomain Limitations
GammaLanczos (g=7, 9 terms)~15 digitsPoles at 0, -1, -2, ...
Log-GammaDirect Lanczos~15 digitsx > 0
ZetaDirect sum (50 terms)~10 digitsRe(s) > 1 only
erfRational approx~7 digitsAll x
Bessel JBackward recurrence~12 digits|x| < 50 recommended
Elliptic KAGM (25 iterations)~15 digits0 ≀ m < 1
Legendre PThree-term recurrenceExact for n < 20|x| ≀ 1
Hermite HThree-term recurrenceExact for n < 15Overflow 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​

  1. 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.
  2. 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.
  3. Lanczos, C. "A Precision Approximation of the Gamma Function." SIAM Journal on Numerical Analysis 1, pp. 86--96, 1964.
  4. Riemann, B. "Ueber die Anzahl der Primzahlen unter einer gegebenen Grosse." Monatsberichte der Berliner Akademie, pp. 671--680, 1859.
  5. Edwards, H. M. Riemann's Zeta Function. Dover Publications, 2001.
  6. Watson, G. N. A Treatise on the Theory of Bessel Functions. Cambridge University Press, 2nd edition, 1944.
  7. Borwein, J. M. and Borwein, P. B. Pi and the AGM: A Study in Analytic Number Theory and Computational Complexity. Wiley, 1987.
  8. Szego, G. Orthogonal Polynomials. American Mathematical Society Colloquium Publications 23, 4th edition, 1975.
  9. Temme, N. M. Special Functions: An Introduction to the Classical Functions of Mathematical Physics. Wiley, 1996.

phi^2 + 1/phi^2 = 3 = TRINITY