Forward graph approximation #
FwdGraph.eval_approx composes the local bounds supplied by FwdNode.sound. Each node receives
a heterogeneous context of tensors and an aligned EList of scalar error bounds. Shape lists
describe context entries; they do not replace tensor storage.
The framework is backend-independent and allows noncomputable rounding models such as FloatLib's
NF. An explicit propagated bound need not be an executable numerical calculation. Instantiating
the node contracts with native arithmetic requires separate per-operation correspondence proofs.
Scalar error bounds aligned with a context shape list.
- nil : EList []
- cons {s : Spec.Shape} {ss : List Spec.Shape} : ℝ → EList ss → EList (s :: ss)
Instances For
Cast an error list along an equality of shape lists.
Instances For
Casting along rfl is the identity.
EList.cast composes as expected.
Append a scalar error bound to the end of an error list.
Instances For
Split an error list aligned with ss ++ [τ] into its prefix and last scalar.
Instances For
Get the ith scalar bound from an error list.
Instances For
Erase shape indices while retaining bounds in context order.
This is the reporting boundary used by architecture-independent numerical traces. Proofs continue
to use EList; UI and serialization code receives an array only after propagation has
finished.
Instances For
Flattening an error list to an array keeps one entry per shape.
Tensor-level approximation under a toSpec : α → ℝ mapping.
Instances For
Scoped notation for tensor approximation (approxTensor).
open scoped RuntimeApprox
spec ≈ᵀ[toSpec] runtime : eps
Instances For
Monotonicity of approxTensorWithTol: if you only loosen tolerances, an approximation stays valid.
approxTensorWithTol specialized to an absolute-only tolerance is equivalent to approxTensor.
This is mostly a convenience lemma for switching between the "tolerance" API and the plain
eps : ℝ API.
Context-level approximation with a per-entry error list.
Instances For
Scoped notation for approxCtx.
open scoped RuntimeApprox
-- `ΓS` is an approximate view of `ΓR` with per-entry bounds `eps`:
ΓS ≈ᶜ[toSpec] ΓR : eps
The notation is scoped to avoid polluting unrelated code.
Instances For
Transport a context approximation across an equality of shape lists.
This is used any time we need to reassociate Γ ++ ss type indices (casts are unavoidable in this
List Shape-indexed encoding).
Extend a context approximation by appending one more approximated tensor.
This is the core "composition" step used when evaluating a snoc-graph: if the previous context is
approximated, and the new node output is approximated with some bound e, then the extended context
is approximated with the extended error list.
Extract a single entry approximation from approxCtx.
approxCtx_get expressed in terms of approxTensorWithTol with an absolute-only tolerance.
Many downstream theorems are stated using a tolerance record (ApproxTol) rather than a bare
eps : ℝ. For absolute-only bounds, this lemma gives the bridge.
Split a context approximation for ss ++ [τ] into:
- a prefix context approximation for
ss, and - a single-tensor approximation for the last entry of shape
τ.
Lookup the epsilon entry associated to an index Idx Γ s.
Instances For
Read an indexed tensor approximation with its aligned scalar error bound.
A single SSA/DAG node with a local forward approximation lemma.
Fields:
forwardSpec/forwardRuntime: the spec vs runtime semantics of the node.bound: computes an explicit scalar error bound for the node’s output, given current context bounds and the runtime context (to allow data-dependent bounds).sound: the “local theorem” that justifiesbound.
Informally: if the whole input context is approximated (approxCtx), then this node’s output is
approximated (approxTensor) with error at most bound.
- forwardSpec : TorchLean.TensorPack Spec.SpecScalar Γ → Spec.SpecTensor τ
Specification-level semantics of this node.
- forwardRuntime : TorchLean.TensorPack α Γ → TorchLean.Tensor α τ
Runtime semantics of this node.
- bound : EList Γ → TorchLean.TensorPack α Γ → Spec.SpecScalar
Error bound computed from the current context bounds and runtime values.
- sound (xS : TorchLean.TensorPack Spec.SpecScalar Γ) (xR : TorchLean.TensorPack α Γ) (eps : EList Γ) : approxCtx toSpec xS xR eps → approxTensor toSpec (self.forwardSpec xS) (self.forwardRuntime xR) (self.bound eps xR)
Local approximation theorem for this node.
Instances For
Forward-only SSA/DAG graph (nodes appended in topological order).
The type parameter ss : List Shape tracks the shapes of intermediate values produced by the
graph; evaluating a graph returns an extended context of shape list Γ ++ ss.
- nil {α : Type} [TorchLean.Storage α] {toSpec : α → Spec.SpecScalar} {Γ : List Spec.Shape} : FwdGraph toSpec Γ []
- snoc {α : Type} [TorchLean.Storage α] {toSpec : α → Spec.SpecScalar} {Γ ss : List Spec.Shape} {τ : Spec.Shape} : FwdGraph toSpec Γ ss → FwdNode toSpec (Γ ++ ss) τ → FwdGraph toSpec Γ (ss ++ [τ])
Instances For
Evaluate a forward graph in the spec semantics.
Result type: an extended context Γ ++ ss containing the original inputs and all intermediate
values produced by the graph.
Instances For
Evaluate a forward graph in the runtime semantics.
This mirrors evalSpec, but uses the backend α tensors and the node runtime closures.
Instances For
Propagate an input error list epsIn through the whole graph, producing output bounds for
Γ ++ ss.
Each node can compute its own output bound from the current context bounds and the runtime context;
evalBounds just composes those local transformers over the snoc-list DAG.
Instances For
End-to-end forward approximation theorem for FwdGraph.
Informally:
assume every input tensor in the runtime context xR is within the provided per-entry bounds
epsIn of the corresponding spec tensor in xS. Then evaluating the whole graph preserves that
approximation relation, with output bounds given by evalBounds.
Proof idea: induction over the snoc-list graph; at each step, apply the node's local bound/soundness
theorem (FwdNode.sound) and then extend the context approximation via approxCtx_snoc.