Skip to content
FloatLib

Verified Floating-Point Arithmetic in Lean

Robert Joseph George1,*, Will Adkisson2,*, Anima Anandkumar1
1California Institute of Technology 2Washington University in St. Louis

* Equal contribution

Overview

FloatLib is a verified arbitrary-precision floating-point arithmetic library in Lean. It supports IEEE binary and decimal, arbitrary-width posits, P3109, small ML formats, and user-defined formats and rounding rules. Each certified software backend is proved equal to its encoded specification, including signed zeros and exceptional values. We built FloatLib to support verified machine learning and numerical software with efficient arithmetic.

Operands in a chosen format pass either through an exact specification or through a certified software backend. A Lean proof establishes that both paths return the same encoded result.
The specification states the result; the backend computes it. A Lean proof connects the two paths for every input.

Key contributions

  • Custom formats and rounding rules. Choose exponent and fraction widths, bias, and encoding policies, or define a new representation. IEEE binary and decimal, small ML formats, arbitrary-width posits, and P3109 share interfaces for arithmetic and mixed-format operations.
  • Numerical proofs connected to code. Correct rounding, half-ulp error bounds, and Sterbenz's lemma describe the arithmetic a program executes. Posits also have exact quire accumulation within capacity and real-rounding proofs for roots, powers, exponentials, and logarithms.
  • Signed zeros, NaNs, infinities, and exception flags. The IEEE model makes their encodings and behavior explicit. Proofs about complete result words preserve distinctions that equality over the reals cannot express.
  • Fast certified execution. The planner chooses among lookup tables, machine-word kernels, and limb algorithms. Every certified choice proves agreement with the same specification; Lean erases proof terms during compilation.

Performance

We benchmarked six arithmetic operations from 2 to 4,096 bits. The guide gives all timings and the separate P3109 comparison.

Six plots compare addition, subtraction, multiplication, division, square root, and fused multiply-add. Blue squares show FloatLib binary and green circles show FloatLib posit. FloatLib outperforms Universal at wide posit widths, while MPFR remains faster for binary arithmetic.
Median nanoseconds per operation across encoded widths, with 5th–95th percentile bands over nine trials on an Intel Xeon Platinum 8488C. Both axes are logarithmic; lower is faster. Full-size plot · Comparison methods and Flocq wrapper details.