TorchLean API

FloatLib.Numerics.Quantization.Affine.Real

Affine quantization over the reals #

RealAffineQuantizer describes a positive-scale integer grid with bounded storage. Its rounding function is supplied by the caller: order preservation, integer round trips, and error bounds each require only the corresponding property of that function. In particular, the error result is not restricted to nearest-even rounding.

AffineQuantizer.toReal embeds the executable rational quantizer's parameters without changing the code interval. toReal_quantize and toReal_roundedValue transport any agreement between rational and real integer rounding to the complete saturated operation. The Flocq rounding adapter specializes this agreement to nearest-even; executable clients can continue importing Affine alone without loading real-number theory.

A bounded affine grid with real-valued spacing and caller-supplied integer rounding.

  • scale :

    Distance between adjacent reconstructed values.

  • zeroPoint :

    Integer code whose reconstruction is zero. It need not be inside the storage interval.

  • qmin :

    Smallest stored code.

  • qmax :

    Largest stored code.

  • scale_pos : 0 < self.scale

    The grid spacing is strictly positive.

  • codeRange : self.qmin self.qmax

    The storage interval is nonempty.

Instances For

    Saturate an integer to the storage interval using the shared clamp.

    Instances For

      Integer code before saturation.

      Instances For

        Round onto the affine grid and saturate to the storage interval.

        Instances For

          Reconstruct the real value denoted by an integer code.

          Instances For

            Reconstructed value after rounding and saturation.

            Instances For

              Saturation always produces a code in the declared interval.

              @[simp]

              Saturation fixes every code already in the storage interval.

              Every quantized value lies in the storage interval, independently of the rounding rule.

              @[simp]

              The zero point reconstructs to zero, even if it lies outside the storage interval.

              A monotone integer rounder gives monotone saturated quantization.

              Reconstruction preserves integer-code order because the scale is positive.

              @[simp]
              theorem FloatLib.Numerics.Quantization.RealAffineQuantizer.quantize_dequantize (q : RealAffineQuantizer) {rnd : } (hfix : ∀ (n : ), rnd n = n) {code : } (hlo : q.qmin code) (hhi : code q.qmax) :
              q.quantize rnd (q.dequantize code) = code

              A rounder that fixes integers preserves in-range codes under reconstruction and rounding.

              theorem FloatLib.Numerics.Quantization.RealAffineQuantizer.dequantize_rawCode_error_le (q : RealAffineQuantizer) (rnd : ) (x ε : ) (hround : |(rnd (x / q.scale)) - x / q.scale| ε) :
              |q.dequantize (q.rawCode rnd x) - x| q.scale * ε

              An integer-rounding error bound scales by the spacing of the affine grid.

              theorem FloatLib.Numerics.Quantization.RealAffineQuantizer.dequantize_quantize_error_le (q : RealAffineQuantizer) (rnd : ) (x ε : ) (hround : |(rnd (x / q.scale)) - x / q.scale| ε) (hlo : q.qmin q.rawCode rnd x) (hhi : q.rawCode rnd x q.qmax) :
              |q.roundedValue rnd x - x| q.scale * ε

              Without clipping, an integer-rounding error bound scales by the grid spacing.

              theorem FloatLib.Numerics.Quantization.RealAffineQuantizer.dequantize_quantize_error_le_half (q : RealAffineQuantizer) (rnd : ) (x : ) (hround : |(rnd (x / q.scale)) - x / q.scale| 1 / 2) (hlo : q.qmin q.rawCode rnd x) (hhi : q.rawCode rnd x q.qmax) :
              |q.roundedValue rnd x - x| q.scale / 2

              Without clipping, nearest integer rounding reconstructs within half a grid step.

              View an executable rational grid as a real grid with the same integer codes.

              Instances For
                @[simp]

                Reconstruction commutes with the exact rational-to-real embedding.

                theorem FloatLib.Numerics.Quantization.AffineQuantizer.toReal_quantize (q : AffineQuantizer) (rnd : ) (hround : ∀ (x : ), rnd x = roundRatEven x) (x : ) :
                q.toReal.quantize rnd x = q.quantize x

                Agreement of integer rounding lifts to affine quantization, including saturation.

                theorem FloatLib.Numerics.Quantization.AffineQuantizer.toReal_roundedValue (q : AffineQuantizer) (rnd : ) (hround : ∀ (x : ), rnd x = roundRatEven x) (x : ) :
                q.toReal.roundedValue rnd x = (q.roundedValue x)

                Reconstruction commutes with exact embedding whenever integer rounding does.