Reimplementation of symfpu in Lean 4, with formal proofs of correctness. The project bitblasts IEEE 754 floating point arithmetic operations and proves properties about them.
Floating point definitions follow the paper:
- "An Automatable Formal Semantics for IEEE-754 Floating-Point Arithmetic" by Brain, Tinelli, Ruemmer, Wahl (BTRW15). Available at https://smt-lib.org/papers/BTRW15.pdf
lake buildLean toolchain: leanprover/lean4:nightly-2026-01-14. Dependencies: mathlib4 (via nightly-testing).
After building, run tests via the command-line executable:
lake build && ./.lake/build/bin/fp-lean <test-name>Available test names:
e5m2,e3m4— Full test suites for FP8 formatsaddRat,mulRat,divRat— Rational arithmetic precision testsfpMaxRel,fpMinRel— SMT-LIB relation compliance testsadd,sub,mul,div,min,max,lt,neg,abs,sqrt,rem,roundToInt— Individual operation testsfma_e5m2,fma_e3m4— FMA tests (slow, ternary operation)roundCircuitAgainstSmtLib— Rounding circuit vs SMT-LIB semantics
Fp/Basic.lean— Core types:PackedFloat(sign, exponent bitvec, significand bitvec parameterized by widths),FixedPoint,UnpackedFloatFp/Rounding.lean—RoundingMode(RNA, RNE, RTN, RTP, RTZ) and rounding logicFp/Unpacking.lean— Pack/unpack betweenPackedFloatandUnpackedFloatFp/SmtLibSemantics.lean— Formal semantics following BTRW15, definesExtendedNumbertypeclassFp/UnpackedRound.lean— Rounding on unpacked floatsFp/Addition.lean— Floating point addition circuitFp/Subtraction.lean— Floating point subtractionFp/Multiplication.lean— Floating point multiplication circuitFp/Division.lean— Floating point division circuitFp/Negation.lean— Floating point negationFp/Comparison.lean— Floating point comparison operationsFp/FMA.lean— Fused multiply-addFp/Sqrt.lean— Square rootFp/Remainder.lean— Floating point remainderFp/MulInv.lean— Multiplicative inverseFp/Convert.lean— Conversion operationsFp/Utils.lean— Utility definitionsFp/ForLean/Dyadic.lean— Dyadic rational numbersFp/ForLean/Rat.lean— Rational number utilitiesFp/Tactics/— Custom tactics (Attributes.lean,Simps.lean)Fp/Proofs/— Correctness proofs per operation (Addition, Subtraction, Multiplication, Division, Negation, Basic, Grind)Fp/Theorems/— Higher-level theorems (Packing, RemainderHomogeneous, ExtraTheorems, AgainstSMT)Fp/Tests/— Exhaustive enumeration tests against FloatX/symfpu for bit-for-bit compatibilitythird-party/— FloatX and symfpu reference implementations used for golden testing
- Exponent and significand widths are Nat parameters at the type level (
PackedFloat exWidth sigWidth) - Heavy use of
bv_decideandbv_normalizefor bitvector reasoning - Custom
@[bv_normalize]simp attributes are used throughout - Proofs often use
omega,simp,bv_decide, and the custom tactics inFp/Tactics/ - The
--tstack=4096flag is required (set inlakefile.toml) due to deep tactic stacks - CI exhaustively enumerates all small-bitwidth floats against FloatX and symfpu for correctness