TorchLean API

FloatLib.Floats.ExecFloat.Conversion.Core

Core conversion capabilities and outcomes #

A source's ExactDecoder gives its exact value. An ExactMap embeds that value into the destination's exact domain, and a Quantizer rounds it under an explicit policy. ConversionOutcome retains the resulting value and flags, or the reason conversion failed.

The entry points are in Conversion.Runtime; their correctness theorems and the laws for composing outcomes are in Conversion.Proof.

Location of an input that prevented a conversion or mixed operation.

  • source : InputPosition

    The sole input of a conversion.

  • left : InputPosition

    The left input of a binary or fused operation.

  • right : InputPosition

    The right input of a binary or fused operation.

  • addend : InputPosition

    The third input of a fused multiply-add.

  • operand (index : ) : InputPosition

    A zero-based input of a user-defined exact expression.

Instances For

    Why an explicit conversion or mixed-format operation produced no destination value.

    Instances For
      @[reducible, inline]

      An exact scalar computation that may reject a non-finite input or an undefined operation.

      Successful expressions contain an unrounded value in the destination's exact domain. Applying roundOnce or roundOnceWith quantizes the result once. The Except alias supports ordinary do notation and stops at the first failure.

      Instances For

        Representation-independent information about a successful quantization.

        Flags describe one conversion. saturated and wrapped distinguish clamping from modular reduction; either can also be inexact. Composing successful outcomes with bind combines their flags with Boolean OR. A failed continuation returns its failure reason without accumulated flags.

        • inexact : Bool

          The stored destination does not denote the exact finite input.

        • overflow : Bool

          The rounded result did not fit the destination's finite range. Binary destinations set this after rounding, in the IEEE 754 sense; each quantizer documents its own rule.

        • underflow : Bool

          The result was tiny. Binary destinations use the IEEE 754 rule, tiny after rounding and inexact; P3109 reports a nonzero exact input below its least positive datum.

        • saturated : Bool

          The result was clamped to a finite endpoint.

        • wrapped : Bool

          The result was reduced modulo a bounded storage width.

        • mappedSpecial : Bool

          A source infinity or exceptional value was mapped to another value class.

        Instances For
          @[inline]

          Combine the flags raised by two successful conversion steps.

          Instances For

            Result of an explicit conversion or destination-driven mixed operation.

            Instances For
              Instances For
                @[instance_reducible]
                @[inline]

                Transform a successful value while preserving status and failure information.

                Instances For
                  @[inline]

                  Continue from a successful value, accumulating status from both successful steps.

                  A failure short-circuits unchanged. Because ConversionOutcome.failure does not carry status, flags from an earlier success are unavailable when a later step fails.

                  Instances For
                    @[inline]

                    Extract a successful destination value.

                    Instances For
                      @[inline]

                      Extract status from a successful conversion.

                      Instances For
                        @[inline]

                        Extract the reason for a failed conversion.

                        Instances For
                          class FloatLib.Floats.ExecFloat.ExactDecoder (Source : Type u) (Exact : outParam (Type v)) :
                          Type (max u v)

                          Executable exact interpretation of a source value.

                          Exact is an output parameter so the source type selects its canonical executable exact domain. For example, configured binary sources select SignedRat to retain signed zero, posit sources select Rat, and a shared-scale block may select Vector Rat lanes.

                          • decode : SourceNumerics.NumericalValue Exact

                            Decode every source value, retaining infinity and exceptional observations.

                          Instances
                            @[instance_reducible]

                            Natural numbers enter explicit conversion as exact finite natural values.

                            @[instance_reducible]

                            Integers enter explicit conversion as exact finite integer values.

                            @[instance_reducible]

                            Rationals enter explicit conversion without an intermediate floating-point approximation.

                            @[instance_reducible]

                            Dyadic values enter explicit conversion with their exact significand and binary exponent.

                            class FloatLib.Floats.ExecFloat.Quantizer (Destination : Type u) (Exact : outParam (Type v)) :
                            Type (max (max 1 u) v)

                            Context-indexed quantization capability for one destination value type.

                            The specification is relational so stochastic, state-indexed, and otherwise nondeterministic mathematics remain expressible even when run chooses one executable result.

                            Exact is an output parameter: a destination has one canonical mathematical input domain. Alternative execution backends must refine that same semantics rather than changing the domain seen by users. Sources with a different exact domain reach it through an explicit ExactMap.

                            Mixed addition and subtraction also consult this context before quantization. The default operations are those of Exact; a signed-zero domain can refine the sign of an exact cancellation without changing its numerical value. Multiplication and division use the exact domain directly.

                            Preservation of the numerical sum and difference is a separate family-specific proof obligation. correct relates run to spec; it does not constrain these arithmetic hooks. The generic prepared-spec theorems compose quantization with the supplied hooks. An arithmetic correctness result also needs their numerical preservation lemmas, as supplied by the binary instances.

                            The relation's content is a separate obligation: choosing Spec.ofFunction run makes correct reflexive and supplies no independent rounding property. A family contract can expose denotation, coefficient, or policy predicates while retaining complete output and status equality. The generic conversion theorems transport precisely the clauses that the installed relation contains.

                            • Context : Type

                              Family-specific context, such as rounding policy, entropy, overflow rule, or block exponent.

                            • run : Context DestinationNumerics.NumericalValue ExactConversionOutcome Destination

                              Executable quantizer.

                            • Mathematical relation implemented by run.

                            • correct : spec.Implements run

                              The executable quantizer always chooses a result permitted by spec.

                            • addExact [Add Exact] : Context DestinationExactExactExact

                              Exact addition under the destination context, including any direction-dependent zero sign.

                              A family overriding this operation must retain the numerical sum in its exact domain.

                            • subExact [Sub Exact] : Context DestinationExactExactExact

                              Exact subtraction under the destination context, including any direction-dependent zero sign.

                              A family overriding this operation must retain the numerical difference in its exact domain.

                            Instances
                              class FloatLib.Floats.ExecFloat.DefaultQuantizer (Destination : Type u) (Exact : outParam (Type v)) [Quantizer Destination Exact] :

                              The default context used when a conversion omits an explicit policy.

                              • defaultContext : Quantizer.Context Destination

                                Context selected by the context-free cast and mixed-operation helpers.

                              Instances