TorchLean API

FloatLib.Floats.Formats.P3109.Runtime

P3109 formats #

P3109 descriptors have four parameters from the interim report: bit width, precision, signedness, and finite or extended domain. Every valid descriptor produces an exact-width codebook and an ExecFloat carrier.

This module covers representation and exact decoding. The arithmetic and projection modules supply operations and rounding policies.

The finite magnitude formula agrees with ordinary binary scientific notation after fields have been extracted. Classification does not: P3109 unsigned formats omit the sign bit, while signed formats use the midpoint code for their single NaN and mirror finite magnitudes across the upper half of the code space. P3109 also admits field widths excluded by BinaryInterchange.FloatFormat, so it needs its own field classification.

Reference #

Whether a P3109 format represents negative finite values.

Instances For

    Whether a P3109 format represents infinities as well as finite values and NaN.

    Instances For

      A validated descriptor for the complete four-parameter P3109 format family.

      One value of this structure selects a profile; there is no separate Lean type or decoder for each bit width. The proof fields rule out precisely the invalid (K, P, signedness) combinations from the report before any value can be constructed.

      Instances For
        @[inline]

        Number of explicitly stored trailing significand bits.

        Instances For
          @[inline]

          Width of the biased exponent field.

          Unsigned formats gain the bit that a signed format uses to divide positive and negative codes.

          Instances For
            @[inline]

            P3109 exponent bias, derived from the exponent-field width.

            Instances For
              @[inline]

              Smallest leading exponent used by a normal finite value.

              Instances For
                @[inline]

                Quantum exponent of the smallest positive finite value.

                Instances For
                  @[inline]

                  Number of code points in the format.

                  Instances For
                    @[inline]

                    First code in the negative half of a signed format.

                    Instances For
                      @[inline]

                      Code point assigned to the format's single NaN.

                      Instances For
                        @[inline]

                        Code point assigned to positive infinity when the domain is extended.

                        Instances For
                          @[inline]

                          Code point assigned to negative infinity in a signed extended format.

                          Instances For
                            @[inline]
                            def FloatLib.Floats.Formats.P3109.Format.signed (bitWidth precision : ) (domain : Domain) (bitWidth_gt_two : 2 < bitWidth := by decide) (precision_pos : 0 < precision := by decide) (precision_lt_bitWidth : precision < bitWidth := by decide) :

                            Construct a signed P3109 descriptor.

                            Instances For
                              @[inline]
                              def FloatLib.Floats.Formats.P3109.Format.unsigned (bitWidth precision : ) (domain : Domain) (bitWidth_gt_two : 2 < bitWidth := by decide) (precision_pos : 0 < precision := by decide) (precision_le_bitWidth : precision bitWidth := by decide) :

                              Construct an unsigned P3109 descriptor.

                              Instances For
                                @[inline]
                                def FloatLib.Floats.Formats.P3109.Format.ofParameters? (bitWidth precision : ) (signedness : Signedness) (domain : Domain) :

                                Validate parameters supplied at runtime and construct the corresponding P3109 descriptor.

                                Use signed or unsigned when the parameters are fixed in Lean code and their constraints can be discharged at elaboration time. This checked constructor is for parsers, generated format matrices, and other callers whose parameters are ordinary runtime values.

                                Instances For
                                  @[inline]

                                  Exact positive finite value decoded from one in-range magnitude.

                                  Informally, row zero is subnormal and uses the stored trailing bits directly. Every other row prepends the implicit leading bit and subtracts the descriptor's exponent bias. Exceptional-code classification and negative mirroring happen in decodeNat, outside this shared mathematical formula.

                                  Instances For
                                    @[inline]

                                    Decode an in-range natural-number code point according to P3109 Section 4.7.2.

                                    Callers with arbitrary natural numbers should first construct a BitVec format.bitWidth; the public decode and ExecFloat.P3109.ofNatBits functions do this automatically.

                                    Instances For
                                      @[inline]

                                      Exact P3109 denotation of one width-bounded code point.

                                      Instances For

                                        Complete codebook induced by a P3109 descriptor.

                                        Instances For

                                          P3109 as a family-independent exact numerical system.

                                          Instances For
                                            @[reducible, inline]

                                            Executable exact-width carrier for any valid P3109 descriptor.

                                            Generic exact-expression operations can use this type as a destination through its conversion capability. The representation layer does not install a separate arithmetic interface.

                                            Instances For
                                              @[inline]

                                              Construct P3109's unique zero without exposing its stored word.

                                              Instances For
                                                @[inline]

                                                Construct P3109's sole NaN without exposing its descriptor-dependent code point.

                                                Instances For
                                                  @[inline]

                                                  Construct positive infinity when the descriptor has an extended domain.

                                                  Using this function with a statically finite-only descriptor fails during elaboration.

                                                  Instances For
                                                    @[inline]

                                                    Construct negative infinity when the descriptor is both signed and extended.

                                                    Using this function with an unsigned or finite-only descriptor fails during elaboration.

                                                    Instances For
                                                      @[inline]
                                                      def FloatLib.Floats.ExecFloat.P3109.ofFiniteFields? {format : Formats.P3109.Format} (negative : Bool) (biasedExponent trailing : ) :
                                                      Option (P3109 format)

                                                      Construct a finite P3109 value from named representation fields.

                                                      biasedExponent and trailing are checked against the descriptor widths. The constructor also rejects a negative request for an unsigned format and every field combination reserved for NaN or infinity. It is the structured alternative to ofNatBits when an application already has decoded P3109 fields; it does not perform numerical rounding.

                                                      Instances For
                                                        @[inline]

                                                        Construct a P3109 value from the low K bits of a serialized word.

                                                        Prefer the named semantic constructors or ofFiniteFields? in ordinary code.

                                                        Instances For
                                                          @[inline]

                                                          Read a P3109 value as its natural-number code point.

                                                          Instances For
                                                            @[inline]

                                                            Decode a P3109 value to its exact finite, infinity, or NaN semantics.

                                                            Instances For