TorchLean API

FloatLib.Numerics.Core.Value

Values of encoded numerical systems #

An encoded numerical system may contain ordinary values, signed infinities, and exceptional bit patterns. These possibilities are not specific to IEEE floating point: posits have NaR, some low-precision formats reserve individual words, and fixed-point systems may have no exceptional values at all.

NumericalValue records this common semantic shape without prescribing a storage layout. The finite value type remains a parameter, so a system may denote real numbers, rational numbers, integers, complex numbers, or another exact mathematical domain.

Why an encoded word has no ordinary numerical value.

Instances For

    The mathematical meaning of one encoded value.

    The sign on infinity is true for negative infinity. Signed finite zero, when a format distinguishes it, should be retained by the finite semantic type. For example, FloatLib's exact Dyadic representation stores the sign of a zero mantissa.

    Instances For
      @[instance_reducible]
      def FloatLib.Numerics.instDecidableEqNumericalValue.decEq {α✝ : Type u_1} [DecidableEq α✝] (x✝ x✝¹ : NumericalValue α✝) :
      Decidable (x✝ = x✝¹)
      Instances For
        Instances For
          @[instance_reducible]
          instance FloatLib.Numerics.instReprNumericalValue {α✝ : Type u_1} [Repr α✝] :
          def FloatLib.Numerics.NumericalValue.map {α : Type u} {β : Type v} (f : αβ) :

          Apply a function to an ordinary value while preserving infinities and exceptional values.

          Instances For
            @[simp]
            theorem FloatLib.Numerics.NumericalValue.map_finite {α : Type u} {β : Type v} (f : αβ) (value : α) :
            map f (finite value) = finite (f value)

            Mapping a finite value applies the supplied function to its mathematical payload.

            @[simp]
            theorem FloatLib.Numerics.NumericalValue.map_infinity {α : Type u} {β : Type v} (f : αβ) (negative : Bool) :
            map f (infinity negative) = infinity negative

            Mapping preserves an infinity, including its sign.

            @[simp]
            theorem FloatLib.Numerics.NumericalValue.map_exceptional {α : Type u} {β : Type v} (f : αβ) (value : ExceptionalValue) :
            map f (exceptional value) = exceptional value

            Mapping preserves an exceptional value because it has no ordinary payload to transform.

            Extract the ordinary value, returning none for infinity or an exceptional encoding.

            Instances For

              Whether this semantic value is ordinary and finite.

              Instances For
                @[simp]
                theorem FloatLib.Numerics.NumericalValue.finite?_finite {α : Type u} (value : α) :
                (finite value).finite? = some value

                Extracting the payload of a finite observation succeeds.

                @[simp]

                Infinity has no finite payload.

                @[simp]

                An exceptional observation has no finite payload.

                @[simp]

                A finite constructor is recognized as finite.

                @[simp]

                Infinity is not finite.

                @[simp]

                An exceptional observation is not finite.

                @[simp]

                Mapping the identity function leaves every numerical value unchanged.

                @[simp]
                theorem FloatLib.Numerics.NumericalValue.map_comp {α : Type u} {β : Type v} {γ : Type w} (f : αβ) (g : βγ) (x : NumericalValue α) :
                map g (map f x) = map (g f) x

                Successive maps fuse into a single map of the composed function.

                @[simp]
                theorem FloatLib.Numerics.NumericalValue.finite?_map {α : Type u} {β : Type v} (f : αβ) (x : NumericalValue α) :

                Extracting a finite payload commutes with mapping its scalar value.