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:
absis exact.pow x yis supported only whenyis an integer rational (y.den = 1); otherwise it returns0.- Other transcendental functions are defined as
0only in this explicitly scoped algebraic backend. This makes accidental softmax/GELU/tanh-over-ℚuse a typeclass error by default.
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
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
Full opt-in Context dictionary for exact rational algebraic fragments.