TorchLean API

FloatLib.Floats.Formats.P3109.Projection.Rational.Semantics

Exact rational meaning of report precision rounding #

The executable scale, quotient, and remainder represent the report's scaled magnitude, floor, and fractional part exactly. The resulting formula is uniform in the rounding mode, including each supplied stochastic word. Binary exponent bounds characterize the selected logarithm without approximating it by a real-valued computation.

Reference: P3109 unapproved interim report 4.0.3, revision 34f5964, §4.7.4.

theorem FloatLib.Floats.Formats.P3109.RationalRounding.quotientFloor_lt_precision (precision : ) (minimumNormalExponent : ) (numerator denominator : ) (hnumerator : numerator 0) (hdenominator : denominator 0) :
have leading := Numerics.RationalBinary.floorLog2 numerator denominator; have quantum := max leading minimumNormalExponent - Int.ofNat precision + 1; have scaled := Numerics.RationalBinary.scaleByPowerOfTwo numerator denominator (-quantum); scaled.1 / scaled.2 < 2 ^ precision

At the precision quantum, the exact quotient is below 2^precision. Clamping the leading exponent to the minimum normal exponent can only decrease the quotient. The bound depends on these two parameters, not on an encoding or saturation policy.

Apply the sign of the input to a nonnegative candidate.

Instances For

    The report's real-valued significand, which is rational for a rational input.

    Instances For
      def FloatLib.Floats.Formats.P3109.RationalRounding.codeEven (precision bias : ) (quantum : ) (lower : ) :

      Report parity of the lower code, including its exceptional precision-one rule.

      Instances For

        Report selection between the two adjacent integer significands.

        Instances For
          def FloatLib.Floats.Formats.P3109.RationalRounding.roundAt (mode : RoundingMode) (quantum : ) (parity : Bool) (value : ) :

          Precision rounding at a specified quantum, expressed by mathematical floor and fraction.

          Instances For

            The report quantum uses the actual precision and exponent bias.

            Instances For

              Mathematical report precision rounding of a finite rational.

              Instances For

                The absolute numerator and positive denominator represent the magnitude exactly.

                The stored numerator sign is exactly the sign of the rational input.

                theorem FloatLib.Floats.Formats.P3109.RationalRounding.scaleByPowerOfTwo_rat (numerator denominator : ) (exponent : ) :
                (Numerics.RationalBinary.scaleByPowerOfTwo numerator denominator exponent).1 / (Numerics.RationalBinary.scaleByPowerOfTwo numerator denominator exponent).2 = numerator / denominator * 2 ^ exponent

                Moving a binary exponent into an integer quotient preserves its exact rational value.

                The executable scaled quotient is the report's scaled magnitude.

                The quotient is exactly the lower adjacent integer in the report.

                The remainder ratio is exactly the fractional part, not an approximation to it.

                theorem FloatLib.Floats.Formats.P3109.RationalRounding.select_eq_roundedInteger (mode : RoundingMode) (value : ) (quantum : ) (parity : Bool) :
                have scaled := Numerics.RationalBinary.scaleByPowerOfTwo value.num.natAbs value.den (-quantum); have lower := scaled.1 / scaled.2; (if Format.Internal.roundRationalAwayWithParity mode (decide (value.num < 0)) (parity lower) (scaled.1 % scaled.2) scaled.2 = true then lower + 1 else lower) = roundedInteger mode (decide (value.num < 0)) parity (scaledMagnitude value quantum)

                All runtime rounding modes select the report's integer candidate at the given quantum.

                theorem FloatLib.Floats.Formats.P3109.RationalRounding.normalized_toRat (negative : Bool) (significand : ) (exponent : ) :
                (if significand = 0 then Numerics.Dyadic.zero else { negative := negative, significand := significand, exponent := exponent }).toRat = signed negative (significand * 2 ^ exponent)

                Canonicalizing a zero significand does not change the mathematical rounded value.

                @[simp]
                theorem FloatLib.Floats.Formats.P3109.RationalRounding.roundAt_zero (mode : RoundingMode) (quantum : ) (parity : Bool) :
                roundAt mode quantum parity 0 = 0

                Zero is preserved by every mode and every supplied random word.

                theorem FloatLib.Floats.Formats.P3109.RationalRounding.leadingExponent_bounds (value : ) (hvalue : value 0) :
                have leading := Numerics.RationalBinary.floorLog2 value.num.natAbs value.den; 2 ^ leading |value| |value| < 2 ^ (leading + 1)

                The executable logarithm is characterized by the two consecutive enclosing powers of two.

                theorem FloatLib.Floats.Formats.P3109.Format.lowerCodeIsEven_eq (format : Format) (quantum : ) (lower : ) :
                format.lowerCodeIsEven quantum lower = RationalRounding.codeEven format.precision format.exponentBias quantum lower

                Executable code parity agrees with the report, including precision one and the zero code.

                Every finite rational runtime result is the report's exact precision-rounding formula.