Runtime Arithmetic #
Runtime commands may choose native binary32, reference IEEE binary32, or complex arithmetic.
Arithmetic records that semantic choice. FromFloat supplies conversion from Lean binary64
Float literals and scalar-specific rounding for parameter validation.
The generic runtime dispatcher supports all three modes. The public supervised trainer accepts the
two real modes. Explicit complex training uses autograd.complex.grad for a real objective and
nn.sgdStep on complex state; its predictions and Checkpoint.State retain both components.
Model definitions remain polymorphic over the existing Context α interface. The arithmetic choice
does not replace that mathematical interface; it selects a concrete executable element
representation that satisfies it. Proof-only models such as ℝ and rounded-real binary32 are
selected directly in theorems rather than through a command-line flag.
Conversion from Lean Float constants into a selected runtime arithmetic representation.
- ofFloat : Float → α
Convert a Lean binary64
Floatliteral into this runtime element representation. Represent the rounding of
ofFloatin binary64 for parameter-domain checks.The default validates only the supplied binary64 value, preserving custom scalar instances. Finite-precision instances override this to reject values that leave the required domain after conversion. This capability needs no arithmetic or order operations from
Context.
Instances
Float values inject into the same type by identity.
Round binary64 literals to Lean's native binary32 representation.
Inject binary64 literals into the executable IEEE-754 binary32 backend.
Inject binary64 literals into the dual-number backend used by the runtime autograd engine.
We interpret a literal as a primal value with zero tangent/adjoint component.
Arithmetic semantics for runnable executables.
This is a runtime selection mechanism used by example programs; the core library itself is
parametric in the element type α.
Unlike a PyTorch per-tensor dtype, this choice fixes one arithmetic semantics for the complete run:
.nativeuses Lean's nativeFloat32operations on CPU and binary32 CUDA storage on GPU,.ieeeuses FloatLib's configured software IEEE-754 binary32 arithmetic,.complexuses TorchLean's complex representation with binary32 real and imaginary components.
- native : Arithmetic
- ieee : Arithmetic
- complex : Arithmetic
Instances For
Stable spelling used by command-line flags.
Instances For
Log a short description of the selected arithmetic semantics.
Instances For
Parse the value of --arithmetic.
Instances For
Parse and remove --arithmetic, using default when the flag is absent.