Implementing the Transcendental Functions in Ivy
10 days ago
- #programming
- #mathematics
- #Go
- The author began writing Ivy, a pseudo-APL language in Go, in 2014 as a distraction.
- Ivy expanded over the years to include capabilities like designing floating-point printing algorithms.
- High-precision floating point in Go's libraries presented mathematical challenges, requiring revisiting rusty math skills.
- Ivy uses ASCII tokens and exact arithmetic (big ints and exact rationals), making it useful for cryptographic work.
- Ivy became the first mobile application written in Go, thanks to contributions from Hana Kim and David Crawshaw.
- APL's model involves monadic (unary) and dyadic (binary) operators, with right-to-left evaluation and no operator precedence.
- Ivy handles fluid typing, changing between integers, fractions, scalars, vectors, and matrices dynamically.
- The author implemented high-precision transcendental functions (sine, cosine, exponential) using Taylor series and identities.
- Arctangent (atan) was particularly challenging, requiring creative use of identities for convergence.
- Logarithms and arbitrary powers were implemented, leveraging exact arithmetic and high-precision constants like log(2).
- The gamma function was implemented using Lanczos and Spouge approximations, with significant effort to achieve high precision.
- The Spouge approximation, refined by Causley, allowed tuning for accuracy, achieving over 50 digits of precision.