TorchLean API

NN.Spec.Core.Context.Rational

The opt-in rational algebraic backend #

Split out of NN.Spec.Core.Context so that only the handful of algebraic tests that open scoped Spec.RationalAlgebraic pay for the rational instances.

Rational Backend #

Context includes transcendental functions and real-valued exponentiation (Pow α α) because many models (softmax, tanh, etc.) need them when instantiated over Float / / interval scalars.

For , most transcendental functions do not map rationals to rationals, so there is no canonical exact interpretation. TorchLean therefore does not install the rational Context globally. Purely algebraic tests can opt in explicitly with:

open scoped Spec.RationalAlgebraic

Current policy:

@[instance_reducible]

Pow ℚ ℚ instance used for the rational backend.

Policy: support x^y only when y is an integer rational (y.den = 1); otherwise return 0. The instance is scoped so it is unavailable unless the caller explicitly opens Spec.RationalAlgebraic.

Instances For
    @[instance_reducible]

    MathFunctions ℚ dictionary for the rational backend.

    Only abs is meaningful; other transcendental functions are defined as 0 in this scoped backend and should not be used for semantic claims. Keeping this scoped makes unsupported transcendental rational models fail at elaboration unless a file deliberately opts into the algebraic-test backend.

    Instances For
      @[instance_reducible]

      Full opt-in Context dictionary for exact rational algebraic fragments.

      Instances For