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 logical and accumulator forms of the one- and two-limb loops equal and registers the accumulator direction with @[csimp].

The compiled scaled quotient also tries a floating-point candidate, checked in exact integer arithmetic, before the loop. Its certificate uses the loop's arithmetic specification from Quotient.Proof, imported here privately so executable clients get the rewrite without re-exporting that 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 accumulator agrees with the logical loop 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.