TorchLean API

FloatLib.Floats.Formats.Posit.Rounding.Direct.Proof

Correctness of direct exact-dyadic posit packing #

The one-pass scale, regime, exponent, fraction, guard, and sticky calculation in Direct.Runtime refines the exact posit rounding specification at every width. It covers regimes that consume the payload, appended-bit threshold ties, finite-endpoint saturation, and negative results obtained through posit negation.

Direct packing avoids the reference rounder's search. Their equality gives both algorithms the same semantics at every configured width.

Complete arbitrary-width rounding #

Direct positive rounding selects exactly the shared exact-dyadic code.

Shift-with-jam preservation #

theorem FloatLib.Floats.Formats.Posit.Model.DirectDyadicPacking.roundPositiveCode_shiftRightJam (format : Format) (window : ) (hwindow : 2 window) (hpayload : format.payloadBits window) (significand shift : ) (exponent : ) (hlower : 2 ^ (shift + window) significand) (hupper : significand < 2 ^ (shift + window + 1)) (hjammedUpper : Numerics.shiftRightJam significand shift < 2 ^ (window + 1)) :
roundPositiveCode format { negative := false, significand := Numerics.shiftRightJam significand shift, exponent := exponent + Int.ofNat shift } = roundPositiveCode format { negative := false, significand := significand, exponent := exponent }

Retaining a normalized leading window and jamming every discarded one into its low bit preserves the complete direct Posit code.

The theorem is independent of a storage carrier. The retained value has its leading one at index window, so it occupies window + 1 bits. The bounds 2 ≤ window and format.payloadBits ≤ window leave room for the rounding information. The dyadic exponent increases by the discarded shift.

Direct positive rounding always returns a nonnegative finite code.

Direct positive result packing is extensionally the shared dyadic rounder.

Every direct signed code is a valid complete Posit encoding.

Re-encoding the direct code gives the model-valued direct rounder.

Complete direct exact-dyadic rounding equals the exact model rounder.

Complete direct rounding therefore equals exact rational Posit Standard rounding.