TorchLean API

FloatLib.Floats.Formats.FixedPoint.Bounded.Configured.Conversion.Proof

Bounded fixed-point conversion proofs #

The fixed-integer codec theorems connect each conversion policy to its signed coefficient: rejecting conversion preserves an in-range coefficient, wrapping takes centered reduction, and saturation clamps to the signed range. These relations retain the complete outcome and status.

theorem FloatLib.Floats.ExecFloat.BoundedFixedPoint.Conversion.coefficient_ofRat_wrap {radix : Numerics.Radix} {fractionalDigits width : ℕ} (exact : ℚ) :
coefficient (ofRat exact OverflowPolicy.wrap) = (Numerics.roundRatEven (exact * ↑(Formats.FixedPoint.scale radix fractionalDigits))).bmod (2 ^ width)

Wrapping delivers the centered remainder of the nearest-even coefficient.

An in-range coefficient is preserved, including the sole zero-width coefficient.

Saturating conversion delivers the clamped nearest-even coefficient at every width.

@[simp]
theorem FloatLib.Floats.ExecFloat.BoundedFixedPoint.Conversion.run_finite {radix : Numerics.Radix} {fractionalDigits width : ℕ} (policy : OverflowPolicy) (exact : ℚ) :

Finite observations are handled by the selected bounded-overflow policy.

@[simp]

Bounded fixed point has no infinity code.

@[simp]

Bounded fixed point has no exceptional code.

run meets spec: its outcomes satisfy the coefficient, range, and status clauses.

For each policy and input, spec admits at most one outcome.

theorem FloatLib.Floats.ExecFloat.BoundedFixedPoint.Conversion.spec_iff_eq_run {radix : Numerics.Radix} {fractionalDigits width : ℕ} (policy : OverflowPolicy) (input : Numerics.NumericalValue ℚ) (outcome : ConversionOutcome (BoundedFixedPoint radix fractionalDigits width)) :
spec policy input outcome ↔ outcome = run policy input

An outcome meets spec exactly when it is the outcome of run.

@[simp]

The installed decoder exposes the exact stored rational.

Rejecting conversion reports outOfRange exactly when the rejecting constructor fails.