TorchLean API

FloatLib.Floats.Formats.P3109.Projection.Direction

Rounding-direction theorems for P3109 projection #

Format.roundFiniteToPrecision expresses an exact finite dyadic in units of the descriptor quantum 2^Q, with Q = max(floor(log2 |X|), 1 - B) - P + 1, and then chooses between the two integers bracketing the scaled magnitude. This module proves that the deterministic modes make the choice the report prescribes:

The bounds concern rational denotations before saturation and cover every descriptor width, including P = 1. Projection.Selection and Projection.Rational.Selection prove the stochastic selection formulas for every supplied random word.

Quantum exponent selected by P3109 precision rounding for a nonzero finite dyadic.

This is the Q of Section 4.7.4: the selected precision grid has spacing 2^Q before saturation.

Instances For

    The quantum 2^Q as a positive rational.

    Rational sign factor of a dyadic.

    Instances For
      theorem FloatLib.Floats.Formats.P3109.Format.Internal.roundFiniteToPrecision_spec (format : Format) (mode : RoundingMode) (value : Numerics.Dyadic) (hzero : value.significand 0) :
      ∃ (lower : ) (rem : ) (d : ), rem < 2 ^ d value.toRat = signRat value.negative * (lower + rem / 2 ^ d) * 2 ^ format.quantumExponent value ((format.roundFiniteToPrecision mode value).significand = if roundAway format mode value.negative (format.quantumExponent value) lower rem d = true then lower + 1 else lower) (format.roundFiniteToPrecision mode value).toRat = signRat value.negative * (format.roundFiniteToPrecision mode value).significand * 2 ^ format.quantumExponent value

      Structural description of one precision-rounding step.

      The input equals sign * (lower + rem / 2^d) * 2^Q with rem < 2^d, and the result significand is lower or lower + 1 exactly as roundAway decides.

      Precision rounding keeps the selected quantum exponent whenever the result is nonzero.

      The rounded result is an integer multiple of the quantum 2^Q.

      Together with the direction theorems below this pins the result down to one of the two grid points bracketing the input.

      Directed modes #

      towardZero truncates: the result never exceeds the input in magnitude and is within one quantum of it.

      Every grid point no larger in magnitude than the input is no larger than the truncation.

      towardPositive never rounds down and stays within one quantum above the input.

      towardNegative never rounds up and stays within one quantum below the input.

      Every grid point at or above the input is at or above the towardPositive result.

      Every grid point at or below the input is at or below the towardNegative result.

      Nearest modes #

      nearestTiesToAway rounds to within half a quantum of the input.

      On an exact tie, nearestTiesToAway selects the candidate of larger magnitude.

      nearestTiesToEven rounds to within half a quantum of the input.

      theorem FloatLib.Floats.Formats.P3109.Format.roundFiniteToPrecision_nearestTiesToEven_tie (format : Format) (value : Numerics.Dyadic) (htie : |(format.roundFiniteToPrecision RoundingMode.nearestTiesToEven value).toRat - value.toRat| = 2 ^ format.quantumExponent value / 2) :
      ∃ (lower : ), |value.toRat| = (lower + 1 / 2) * 2 ^ format.quantumExponent value (|(format.roundFiniteToPrecision RoundingMode.nearestTiesToEven value).toRat| = lower * 2 ^ format.quantumExponent value format.lowerCodeIsEven (format.quantumExponent value) lower = true)

      On an exact tie, nearestTiesToEven selects the candidate whose P3109 code is even.

      The input is exactly halfway between lower * 2^Q and (lower + 1) * 2^Q in magnitude, and the result has magnitude lower * 2^Q precisely when the lower code is even under the report's CodeIsEven rule (including its P = 1 special case).

      With more than one significand bit, a nearestTiesToEven tie yields an even significand.

      Round to odd #

      toOdd stays within one quantum of the input.

      With more than one significand bit, toOdd returns an odd significand whenever rounding was inexact.