TorchLean API

FloatLib.Floats.ExecFloat.ExactMap

Embeddings between exact domains #

ExactMap Source Target converts exact values between the domains used by numerical families. Binary interchange values, including Lean's native Float32 and Float, use SignedRat, which keeps the sign of zero; posit, fixed-point, logarithmic, and quire values use Rat; OCP E8M0 uses Dyadic; codebooks can use another exact type. The integer, rational, dyadic, and signed-rational embeddings are defined below. Conversion lifts these finite maps over NumericalValue observations.

The map from SignedRat to Rat preserves the rational value and forgets the sign of zero. A conversion through Rat therefore cannot carry a source zero sign to its destination.

Instances must preserve value without rounding, overflow, or a context-dependent choice. The class cannot express that law for arbitrary source and target types, so every non-identity instance needs a separate theorem relating their mathematical interpretations. An arbitrary coercion is insufficient to define an instance.

class FloatLib.Floats.ExecFloat.ExactMap (Source : Type u) (Target : Type v) :
Type (max u v)

Canonical embedding between executable exact domains.

This class is an interoperability capability, not an implicit numerical-promotion rule. User values remain statically typed, and destination rounding still occurs only in an explicit conversion or destination-driven operation. Installing an instance is a semantic commitment; preservation must be justified in the source or target domain's own mathematical model.

  • map : SourceTarget

    Preserve the source's numerical value without rounding.

    Representation metadata can be forgotten: signedRatToRat discards the sign of zero. Preservation of numerical value is justified by separate domain-specific theorems.

Instances
    @[inline]
    def FloatLib.Floats.ExecFloat.ExactMap.run {Source : Type u} {Target : Type v} [self : ExactMap Source Target] (value : Source) :
    Target

    Apply the canonical exact-domain embedding selected for these two types.

    Instances For
      @[instance_reducible, instance 100]
      instance FloatLib.Floats.ExecFloat.ExactMap.identity {Source : Type u} :
      ExactMap Source Source

      Every exact domain embeds into itself without changing a value.

      @[simp]
      theorem FloatLib.Floats.ExecFloat.ExactMap.run_identity {Source : Type u} (value : Source) :
      run value = value

      The identity exact-domain embedding is computationally the identity.

      @[instance_reducible]

      Signed integers embed exactly into rational arithmetic.

      @[simp]

      The signed-integer embedding is Mathlib's exact rational constructor.

      @[instance_reducible]

      Natural numbers embed exactly into rational arithmetic.

      @[simp]

      The natural-number embedding has denominator one.

      @[instance_reducible]

      Exact dyadic values embed into rationals through their mathematical value.

      @[simp]

      The dyadic embedding is the executable exact rational denotation.

      @[instance_reducible]

      Rationals embed into the signed-rational domain; zero receives the positive sign.

      @[simp]

      The rational embedding keeps the value and derives the sign from it.

      @[instance_reducible]

      Signed integers embed into the signed-rational domain.

      @[simp]

      The signed-integer embedding is the rational embedding of the integer.

      @[instance_reducible]

      Natural numbers embed into the signed-rational domain.

      @[simp]

      The natural-number embedding is the rational embedding of the number.

      @[instance_reducible]

      Exact dyadics embed into the signed-rational domain, keeping the sign of zero.

      @[simp]

      The dyadic embedding is the sign-preserving signed-rational denotation.

      @[instance_reducible]

      Signed rationals embed into Rat by forgetting the sign of zero.

      The rational value is preserved, but the target exact domain cannot distinguish the two zero signs. A destination that needs the source zero sign must use a sign-preserving exact domain.

      @[simp]

      The signed-rational embedding into Rat is the value projection.