TorchLean API

FloatLib.Kernels.FixedWord.Quotient.Compiler

Compiler certificates for restoring quotient loops #

The logical restoring loop is convenient for proofs, while the primitive-word accumulator avoids allocating a state at every generated quotient bit. This module proves the one- and two-limb loops extensionally equal and registers the optimized direction with @[csimp].

Keeping this certificate separate from Quotient.Proof matters for executable clients: they can enable the verified compiler rewrite without importing the much larger rational-arithmetic proof development.

theorem FloatLib.Numerics.FixedWord.RestoringQuotient.quotientStepsWords_eq (den : UInt64) (n : ) (quotient remainder : UInt64) :
quotientStepsWords den n quotient remainder = quotientSteps den n { quotient := quotient, remainder := remainder }

The unboxed one-word accumulators preserve every step of the restoring recurrence.

The one-word implementation agrees for every state and iteration count.

@[csimp]

Compile one-word restoring division through primitive accumulators.

@[csimp]

Compile scaled quotient rounding through the same accumulator.

This equation also replaces calls whose original body was compiled before the loop certificate was imported.

The primitive-word accumulator implements the logical two-limb restoring recurrence.

@[csimp]

Compile the logical two-limb quotient loop through its verified word accumulator.