TorchLean API

NN.Floats.IEEEExec.BridgeFP32.DyadicRounding

IEEE32Exec and FP32: Dyadic Rounding Helpers #

Exact dyadic addition (used by op-level refinement theorems) #

IEEE-754 addition is “exact add, then round”. To connect an executable add to the FP32 model, we factor the refinement into two steps:

  1. perform an exact addition in an unbounded format (here: dyadics with integer exponents), and
  2. apply float32 rounding.

addDyadic is our exact step (it aligns exponents, adds signed mantissas, and normalizes), and the lemmas in this section show that its real interpretation is literally real addition.

Instances For
    theorem TorchLean.Floats.IEEE754.IEEE32Exec.dyadicToReal_zero (sign : Bool) :
    dyadicToReal { sign := sign, mant := 0, exp := 0 } = 0

    addDyadic is exact with respect to dyadicToReal.

    Informal: addDyadic aligns exponents, adds signed mantissas, and normalizes; decoding the result gives the sum of the decoded inputs.

    For a nonzero dyadic, neural_magnitude matches the expected “power-of-two interval” characterization: mag = ⌊logb 2 (mant)⌋ + exp + 1.

    We use this as a key link between the FP32 rounding model (defined using neural_magnitude) and the executable kernel (which naturally computes Nat.log2 mant + exp from the decoded dyadic).

    theorem TorchLean.Floats.IEEE754.IEEE32Exec.fract_real_div_nat (n den : ) (hden : den 0) :
    n / den - ↑(n / den) = ↑(n % den) / den
    theorem TorchLean.Floats.IEEE754.IEEE32Exec.div_lt_half_iff (r den : ) (hden : den 0) :
    r / den < 2⁻¹ 2 * r < den
    theorem TorchLean.Floats.IEEE754.IEEE32Exec.half_lt_div_iff (r den : ) (hden : den 0) :
    2⁻¹ < r / den den < 2 * r