FloatLib: Verified Floating-Point Arithmetic in Lean

Robert Joseph George, Will Adkisson, Anima AnandkumararXiv 2026

TL;DR

FloatLib is a new open-source library written in Lean 4 that provides mathematically verified, arbitrary-precision floating-point arithmetic. It is the first framework to successfully unify diverse formats—including standard IEEE binary/decimal, posits, and custom machine learning formats—under a single umbrella that guarantees both mathematical correctness and high execution efficiency.

What Problem Does This Paper Address?

Numerical bugs are notoriously difficult to catch and can silently degrade or crash critical software systems, including popular deep learning frameworks like PyTorch and TensorFlow. As modern machine learning increasingly relies on mixed-precision arithmetic (such as FP8, posits, and custom microscaled formats) to save memory and speed up hardware, verifying the correctness of these operations has become a massive challenge.

Existing formal verification tools are highly fragmented: some handle only standard IEEE formats, others are too slow to execute practically, and very few bridge the gap between abstract mathematical real numbers and concrete bit-level software implementations. FloatLib addresses this gap by providing a unified, executable, and fully verified library for arbitrary-precision arithmetic.

Methods

FloatLib leverages the Lean 4 proof assistant to decouple abstract mathematical specifications from highly optimized execution backends using a technique called backend refinement. This allows developers to run fast software implementations while retaining absolute mathematical certainty that the results match the exact reference specifications.

The framework is organized into four functional layers:

  1. Numerics: Defines exact arithmetic, rounding, and quantization contracts.
  2. Kernels: Implements optimized word and limb arithmetic (e.g., UInt64/UInt128 operations).
  3. Formats: Models specific layouts like IEEE binary, decimal, and posits.
  4. Execution: Contains the selection planner that chooses the most efficient certified backend for a given task.
FloatLib's four functional layers mapping definitions to proofs.

To achieve high performance without sacrificing correctness, FloatLib introduces several novel optimization strategies:

  • Exhaustive Certified Tables: For tiny formats (like 4-to-8-bit floats), the library precomputes and verifies every possible operation pair.
  • Guard-and-Sticky Invariants (Jamming): For wider formats, it uses bit-shifting with "jamming" to safely discard low-order bits without altering final rounding decisions.
  • Certified Quotient Checking: Instead of verifying a complex division algorithm directly, FloatLib runs a fast, unverified algorithm and uses a lightweight, formally verified checker to confirm the quotient and remainder are correct before accepting them.

Datasets

Because FloatLib is an arithmetic library, it was evaluated using extensive synthetic workloads and rigorous conformance test suites rather than traditional datasets:

  • TestFloat: The authors performed over 102 million evaluations to verify strict conformance with the IEEE 754 binary floating-point standard.
  • SoftPosit & Universal: Used as baselines to benchmark and cross-check the accuracy of posit arithmetic across various bit widths.

Key Insights and Ideas

  • Verification Doesn't Mean Slow Execution: By separating specification from execution via refinement proofs, FloatLib proves that verified software can be optimized using standard low-level tricks (like word/limb kernels) without losing mathematical rigor.
  • Result Checking > Algorithm Verification: The success of "certified quotient checking" highlights that verifying a checker (e.g., confirming division via a quick multiplication) is often much simpler and more computationally efficient than formally verifying the generation algorithm itself.
  • Uncovering Hidden Bugs: During independent conformance testing, FloatLib successfully identified previously unnoticed rounding and exponent-packing bugs in the widely used SoftPosit generic reference routines.

Key Results

  • Speedups: FloatLib achieves substantial performance gains over existing multi-format software libraries, running up to 1.46× faster than FLoPS and up to 116× faster than Universal on matched posit workloads.
  • Flawless Conformance: The library achieved zero differences across more than 102 million TestFloat evaluations, proving perfect adherence to standard IEEE relations.
  • Broad Extensibility: It successfully unified highly diverse formats (IEEE 754, P3109, Posits, and custom ML codebooks) under a single verified framework.

Limitations and Future Work

  • Performance vs. Native Hardware: While exceptionally fast for a verified software library, FloatLib is still slower than highly optimized, hardware-native libraries like MPFR for standard binary arithmetic.
  • Compiler Dependency: The proofs verify the Lean code itself but do not extend down to the external machine instructions generated by the compiler or the underlying hardware execution.
  • Future Directions: The authors suggest expanding the library to support automated whole-program roundoff analysis and further optimizing transcendental/elementary functions (like exp and log).

Summary updated

BibTeX
@misc{george2026floatlib,
  author = {Robert Joseph George and Will Adkisson and Anima Anandkumar},
  title = {{FloatLib: Verified Floating-Point Arithmetic in Lean}},
  year = {2026},
  eprint = {2609.19352},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.19352},
}
Figure