TorchLean API

NN.Proofs.RuntimeApprox.NF.Linalg

NF Linear Algebra #

Forward (runtime→spec) approximation lemmas for non-elementwise linear algebra ops over NF.

This extends NN.Proofs.RuntimeApprox.NF.Ops with bounds for the core sum-of-products patterns that appear in linear layers and matrix multiplication.

The central trick is to separate proof-friendly scalar fold bounds for dot products from tensor-level wrappers that turn those fold bounds into approxTensor theorems and graph nodes.

PyTorch correspondence / citations #

This is the proof analogue of linear algebra building blocks used throughout PyTorch models: matrix-vector/matrix-matrix multiplication (torch.matmul) and linear layers (torch.nn.functional.linear). https://pytorch.org/docs/stable/generated/torch.matmul.html https://pytorch.org/docs/stable/generated/torch.nn.functional.linear.html

Extract matrix entry (i,j) from a runtime matrix tensor as an NF scalar.

Instances For
    theorem Proofs.RuntimeApprox.NFBackend.approxTensor_unsqueeze_spec {β : FloatLib.Numerics.Radix} {fexp : } {rnd : } {shape : Spec.Shape} {xS : Spec.SpecTensor shape} {xR : TorchLean.Tensor (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) shape} {eps : } (axis : ) (hAxis : axis shape.rank) (hx : approxTensor toSpec xS xR eps) :

    Inserting a singleton axis is a reindexing operation and adds no numerical error.

    Swapping any pair of adjacent axes preserves the approximation error budget.

    noncomputable def Proofs.RuntimeApprox.NFBackend.dotStep {β : FloatLib.Numerics.Radix} {fexp : } [FloatLib.Floats.Formats.Flocq.ValidExp fexp] {rnd : } {n : } (epsa epsb : ) (aR bR : Fin nFloatLib.Floats.Formats.Flocq.NF β fexp rnd) :

    One fold step for building a dot-product and tracking a forward error bound.

    This is used to bound the error of foldl (fun acc k => acc + aR k * bR k) compared to the corresponding spec (real) dot-product.

    Instances For
      noncomputable def Proofs.RuntimeApprox.NFBackend.dotBound {β : FloatLib.Numerics.Radix} {fexp : } [FloatLib.Floats.Formats.Flocq.ValidExp fexp] {rnd : } {n : } (epsa epsb : ) (aR bR : Fin nFloatLib.Floats.Formats.Flocq.NF β fexp rnd) :

      Closed-form bound for a runtime dot-product over List.finRange n.

      dot_bound epsa epsb aR bR is the accumulated eps component produced by folding dotStep starting from 0.

      Instances For

        Per-output bound tensor for matVecMulSpec.

        Entry i is a dot-product bound for row i of A dotted with v, using dotBound.

        Instances For

          Forward approximation bound for matrix-vector multiplication.

          In words: if A and v are each approximated by runtime AR/vR within epsA/epsV, then mat_vec_mul_spec AS vS is approximated by mat_vec_mul_spec AR vR, with error bounded by linf_norm (mat_vec_mul_bound_tensor epsA epsV AR vR).

          Per-entry bound tensor for matMulSpec.

          Entry (i,j) is a dot-product bound for row i of A dotted with column j of B, using dotBound.

          Instances For

            Forward approximation bound for matrix-matrix multiplication.

            In words: if A and B are approximated by runtime matrices AR/BR within epsA/epsB, then mat_mul_spec AS BS is approximated by mat_mul_spec AR BR, with error bounded by linf_norm (mat_mul_bound_tensor epsA epsB AR BR).

            FwdNode for matrix transpose.

            This lifts approxTensor_swapAdjacentAxes at depth zero into the FwdGraph interface so transposes can be used inside larger verified graphs.

            Instances For

              FwdNode for matrix-vector multiplication.

              The bound is computed by matVecMulBoundTensor and then reduced to a scalar budget via linfNorm.

              Instances For

                FwdNode for matrix-matrix multiplication.

                The bound is computed by matMulBoundTensor and then reduced to a scalar budget via linfNorm.

                Instances For