Complex scalar (TorchLean.Complex α) #
TorchLean is scalar-polymorphic, and some model components (e.g. FFT/FNO-style blocks) want a complex-valued scalar type.
Mathlib’s ℂ is specialized to ℝ and intentionally has no order instance; TorchLean’s generic
Context includes order-like operations (LT/LE, max/min) for ReLU/argmax-style code paths.
To avoid changing mathlib’s global behavior (and to support runtime-friendly backends like
IEEE32Exec), we provide a small parametric complex scalar:
TorchLean.Complex α := α × α with fields re and im.
The provided Context instance is designed to be:
- good enough for TorchLean’s tensor/model surface (arithmetic + common transcendental functions),
- runtime-friendly when
αis runtime-friendly, and - conservative for the few operations that are fundamentally about angles/branches (
log,sqrt): we pick a simple real-part-based approximation that is exact on real inputs (imag part0).
This is not meant to be a full replacement for complex analysis; for deep analytic theorems, use
mathlib’s ℂ directly.
Parametric complex numbers a + i·b over a scalar type α.
- re : α
Real part.
- im : α
Imaginary part.
Instances For
Instances For
Embed a real scalar as a complex scalar with zero imaginary part.
Instances For
Basic algebraic structure #
Division uses the standard formula
(a+bi)/(c+di) = ((ac+bd) + i(bc-ad)) / (c^2 + d^2).
Order is only used in TorchLean for branchy ops like ReLU/max/min. Complex numbers do not have a
canonical order, so we pick a simple real-part order: compare re and ignore im.
This keeps the instance lightweight and avoids polluting mathlib’s ℂ with ad-hoc orderings.
Numeric literals and constants #
Transcendentals #
Real magnitude sqrt(normSq z).