Ziv: A Language for Correctly Rounded Math Libraries
Abstract
Developing performant, correctly rounded math libraries is challenging. Such implementations often rely on extended-precision arithmetic for correct rounding and precomputed constants for performance. Existing implementation languages, however, provide limited support for (i) high-level abstractions for such arithmetic and (ii) staged computation to combine precomputation and runtime computation in one program. As a result, existing implementations often miss abstraction opportunities and hard-code constants precomputed using separate programs. These practices make it difficult to write, understand, and modify these libraries. We present Ziv, a programming system for developing correctly rounded math libraries. It consists of a small language, a rich standard library, and a provably sound compiler targeting C. Ziv supports (i) high-level numerical abstractions via types and operations for extended-precision numbers, and (ii) staged computation via compile-time evaluation of expressions known to be input-independent. These features enable high-level code that unifies precomputation and runtime computation. We embed Ziv in Julia and evaluate it by reimplementing 19 functions from two state-of-the-art libraries targeting correct rounding; we achieve competitive performance with 2.63 reductions in lines of code. We also implement three new functions and automatically explore 824,256 variants, achieving 96.5 average speedup over an arbitrary-precision library.
Create a lesson
Metadata
- Categories
- cs.PL, cs.MS
- Comments
- 44 pages, 23 figures, 3 tables, including appendices
Related papers
When Double Rounding is Correct
Shared title terminologycs.PLBrett Saiki, Bill Zorn, Cynthia Richey et al.
Defining the mathematical family tree with a minimal programming language
Shared title terminologycs.PLMax Tegmark
Denotational Results in Compiler Correctness and Comparisons with Operational Approaches
Shared title terminologycs.PLJeremy G. Siek, Matthew Heimerdinger, Tianyu Chen et al.
What Field Enumeration Costs to Compile in C++26: Native Reflection, Structured-Binding Packs, Reflection Libraries and Hand-Written Serializers on GCC 16
Shared title terminologycs.PLDenys Kachalenko
Cache the Knowledge, Not Just the Prompt: Dynamic Datalog as the Action Language for LLM Agents
Shared title terminologycs.PLBruno Rucy Carneiro Alves de Lima, Victor Henrique Cabral Pinheiro
Validating Concurrent Correctness Witnesses with Ghosts by Thread-Modular Abstract Interpretation (Extended Version)
Shared title terminologycs.PLMichael Schwarz, Zhendong Ang, Umang Mathur