SpecApprox #
Spec/runtime approximation bridge with explicit error bounds.
This is a spec-level statement: runtime values are mapped into Real and compared
against the spec using a chosen norm.
Trust boundary:
- This file is purely about stating approximation predicates. Turning it into an end-to-end theorem requires per-op approximation lemmas and a composition argument.
- Lean supplies a logical model for
Float, but this file does not yet provide per-operation approximation lemmas for that model. Native execution also requires a separate provider agreement. Neither connection is assumed here. - The intended proof-relevant path is to use rounding-model backends (FloatLib
NF) where rounding error bounds are explicit and can be composed.
PyTorch correspondence / citations #
Conceptually, approxWith / approxTensorWithTol are theorem-level versions of “runtime tensor is
close to spec tensor under a chosen norm”, similar to how PyTorch uses norms and rtol/atol
style checks in
testing/validation.
https://pytorch.org/docs/stable/generated/torch.linalg.vector_norm.html
https://pytorch.org/docs/stable/generated/torch.allclose.html
Convert a runtime tensor into the spec scalar by mapping a scalar function.
Instances For
Linf norm on spec tensors.
Instances For
Approximation predicate with an explicit error bound.
Instances For
Abs+rel approximation predicate with a ApproxTol budget (scaled by max ‖spec‖ ‖runtime‖).
Instances For
Default abs+rel tensor approximation (uses linfNorm).
Instances For
A plain eps bound is an abs-only tolerance bound.
The clamping in Real.toNNReal only ever weakens the claim, so no sign hypothesis on eps is
needed
in this direction; the converse approx_with_tol_absOnly_iff does need one.
The same lift specialized to the default linfNorm tensor relation.
Conversely, a tolerance bound is a plain bound at the tolerance's own evaluated budget.
Tensor approximation is preserved when the tolerance is weakened in any field.
For nonnegative eps the two formulations coincide, so nothing is lost by working with
whichever
is convenient at each step.
Notation #
Use open scoped ApproxTol to enable:
spec ≈ᵀ[toSpec, tol] runtime meaning: approxTensorWithTol toSpec spec runtime tol.
Packaged approximation witness (defaults to Linf on spec tensors).
- toSpec : α → Spec.SpecScalar
Map a runtime scalar into the specification scalar domain.
- spec : Spec.SpecTensor s
Specification tensor.
- runtime : TorchLean.Tensor α s
Runtime tensor being compared with the specification tensor.
- eps : Spec.SpecScalar
Absolute error budget for the Linf comparison.
- bound : approxWith self.toSpec (fun {s : Spec.Shape} => linfNorm) self.spec self.runtime self.eps