TorchLean API

NN.Proofs.RuntimeApprox.Core.SpecApprox

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:

PyTorch correspondence / citations #

Conceptually, approxWith / approxTTol 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
      def Proofs.RuntimeApprox.approxWith {α : Type} {s : Spec.Shape} (toSpec : αSpec.SpecScalar) (norm : {s : Spec.Shape} → Spec.SpecTensor sSpec.SpecScalar) (spec : Spec.SpecTensor s) (runtime : Spec.Tensor α s) (eps : Spec.SpecScalar) :

      Approximation predicate with an explicit error bound.

      Instances For
        def Proofs.RuntimeApprox.approxWithTol {α : Type} {s : Spec.Shape} (toSpec : αSpec.SpecScalar) (norm : {s : Spec.Shape} → Spec.SpecTensor sSpec.SpecScalar) (spec : Spec.SpecTensor s) (runtime : Spec.Tensor α s) (tol : ApproxTol) :

        Abs+rel approximation predicate with a ApproxTol budget (scaled by max ‖spec‖ ‖runtime‖).

        Instances For
          def Proofs.RuntimeApprox.approxTTol {α : Type} {s : Spec.Shape} (toSpec : αSpec.SpecScalar) (spec : Spec.SpecTensor s) (runtime : Spec.Tensor α s) (tol : ApproxTol) :

          Default abs+rel tensor approximation (uses linf_norm).

          Instances For
            theorem Proofs.RuntimeApprox.approx_with_to_approx_with_tol_absOnly {α : Type} {s : Spec.Shape} {toSpec : αSpec.SpecScalar} {norm : {s : Spec.Shape} → Spec.SpecTensor sSpec.SpecScalar} {spec : Spec.SpecTensor s} {runtime : Spec.Tensor α s} (eps : ) (h : approxWith toSpec (fun {s : Spec.Shape} => norm) spec runtime eps) :
            approxWithTol toSpec (fun {s : Spec.Shape} => norm) spec runtime (ApproxTol.absOnly eps)
            theorem Proofs.RuntimeApprox.approxT_to_approxTTol_absOnly {α : Type} {s : Spec.Shape} {toSpec : αSpec.SpecScalar} {spec : Spec.SpecTensor s} {runtime : Spec.Tensor α s} (eps : ) (h : approxWith toSpec (fun {s : Spec.Shape} => linfNorm) spec runtime eps) :
            approxTTol toSpec spec runtime (ApproxTol.absOnly eps)
            theorem Proofs.RuntimeApprox.approx_with_tol_to_approx_with {α : Type} {s : Spec.Shape} {toSpec : αSpec.SpecScalar} {norm : {s : Spec.Shape} → Spec.SpecTensor sSpec.SpecScalar} {spec : Spec.SpecTensor s} {runtime : Spec.Tensor α s} {tol : ApproxTol} (h : approxWithTol toSpec (fun {s : Spec.Shape} => norm) spec runtime tol) :
            approxWith toSpec (fun {s : Spec.Shape} => norm) spec runtime (approxBound tol (norm spec) (norm (tensorToSpec toSpec runtime)))
            theorem Proofs.RuntimeApprox.approx_with_tol_mono {α : Type} {s : Spec.Shape} {toSpec : αSpec.SpecScalar} {norm : {s : Spec.Shape} → Spec.SpecTensor sSpec.SpecScalar} {spec : Spec.SpecTensor s} {runtime : Spec.Tensor α s} {tol₁ tol₂ : ApproxTol} (habs : tol₁.abs tol₂.abs) (hrel : tol₁.rel tol₂.rel) (hslack : tol₁.slack tol₂.slack) (h : approxWithTol toSpec (fun {s : Spec.Shape} => norm) spec runtime tol₁) :
            approxWithTol toSpec (fun {s : Spec.Shape} => norm) spec runtime tol₂
            theorem Proofs.RuntimeApprox.approx_with_tol_absOnly_iff {α : Type} {s : Spec.Shape} {toSpec : αSpec.SpecScalar} {norm : {s : Spec.Shape} → Spec.SpecTensor sSpec.SpecScalar} {spec : Spec.SpecTensor s} {runtime : Spec.Tensor α s} {eps : } (heps : 0 eps) :
            approxWithTol toSpec (fun {s : Spec.Shape} => norm) spec runtime (ApproxTol.absOnly eps) approxWith toSpec (fun {s : Spec.Shape} => norm) spec runtime eps

            Notation #

            Use open scoped ApproxTol to enable:

            spec ≈ᵀ[toSpec, tol] runtime meaning: approxTTol toSpec spec runtime tol.

            Packaged approximation witness (defaults to Linf on spec tensors).

            Instances For

              Map NeuralFloat tensors to spec scalars.

              Instances For

                Linf bound over NeuralFloat error markers.

                Instances For

                  NeuralFloat runtime approximation to the spec with explicit epsilon bound.

                  Instances For