TorchLean API

NN.Proofs.RuntimeApprox.NF.Ops.Plumbing

NF Tensor Approximation Plumbing #

Shape-generic lemmas for approxTensor and linfNorm. The later NF proof files use these lemmas to turn scalar absolute-error facts into tensor-level forward-error bounds.

Tensor Approximation Plumbing #

theorem Proofs.RuntimeApprox.approxTensor_mono {α : Type} {toSpec : αSpec.SpecScalar} {s : Spec.Shape} {xS : Spec.SpecTensor s} {xR : TorchLean.Tensor α s} {eps eps' : Spec.SpecScalar} (h : approxTensor toSpec xS xR eps) (hle : eps eps') :
approxTensor toSpec xS xR eps'

Enlarge an existing tensor approximation budget.

Composed operators often prove a row- or coordinate-level estimate and then embed it into a global infinity-norm budget. This lemma records that monotonicity once, without unfolding the tensor distance predicate at every use site.

linfNorm is always nonnegative.

Componentwise bound for linfNorm on a dimensioned tensor.

The norm of any component t[i] is bounded by the norm of the whole tensor.

Scalar characterization of approxTensor on scalar tensors.

This rewrites approxTensor (Tensor.scalar x) (Tensor.scalar xR) eps into the usual absolute-error inequality |toSpec xR - x| ≤ eps.

Scalar characterization of approxTensor stated for arbitrary rank-zero tensors.

theorem Proofs.RuntimeApprox.approxTensor_dim_get {α : Type} {toSpec : αSpec.SpecScalar} {n : } {s : Spec.Shape} {xS : Spec.SpecTensor (Spec.Shape.dim n s)} {xR : TorchLean.Tensor α (Spec.Shape.dim n s)} {eps : Spec.SpecScalar} (h : approxTensor toSpec xS xR eps) (i : Fin n) :

Projection lemma for approxTensor on dimensioned tensors.

If xS approximates xR within eps, then each component xS[i] approximates xR[i] within eps.

theorem Proofs.RuntimeApprox.approxTensor_eps_nonneg {α : Type} {toSpec : αSpec.SpecScalar} {s : Spec.Shape} {xS : Spec.SpecTensor s} {xR : TorchLean.Tensor α s} {eps : Spec.SpecScalar} (hx : approxTensor toSpec xS xR eps) :
0 eps

Every valid tensor approximation has a nonnegative error budget.

This fact is independent of the executable scalar type. Keeping it at the plumbing layer avoids repeating the same norm argument in each backend-specific development.

theorem Proofs.RuntimeApprox.approxTensor_dim_of_forall {α : Type} {toSpec : αSpec.SpecScalar} {n : } {s : Spec.Shape} {xS : Spec.SpecTensor (Spec.Shape.dim n s)} {xR : TorchLean.Tensor α (Spec.Shape.dim n s)} {eps : Spec.SpecScalar} ( : 0 eps) (h : ∀ (i : Fin n), approxTensor toSpec (TorchLean.Tensor.unstack xS i) (xR.unstack i) eps) :
approxTensor toSpec xS xR eps

Assemble a dimensioned tensor approximation from uniform componentwise approximations.

The premise uses one common infinity-norm budget for every component. This is the converse of approxTensor_dim_get and is deliberately polymorphic in the runtime element representation, so NF, IEEE execution, interval, and future quantized backends can share the same structural proof.

theorem Proofs.RuntimeApprox.approxTensor_map_spec_of_scalar_bound {α : Type} {toSpec : αSpec.SpecScalar} {s : Spec.Shape} (fS : Spec.SpecScalarSpec.SpecScalar) (fR : αα) (bnd : Spec.SpecScalarSpec.SpecScalarSpec.SpecScalar) {xS : Spec.SpecTensor s} {xR : TorchLean.Tensor α s} {eps : Spec.SpecScalar} :
approxTensor toSpec xS xR eps(∀ {x : Spec.SpecScalar} {xR : α}, |toSpec xR - x| eps|toSpec (fR xR) - fS x| bnd (toSpec xR) eps)approxTensor toSpec (TorchLean.Tensor.mapSpec fS xS) (TorchLean.Tensor.mapSpec fR xR) (linfNorm (TorchLean.Tensor.mapSpec (fun (a : Spec.SpecScalar) => bnd a eps) (tensorToSpec toSpec xR)))

Lift a scalar approximation bound to an elementwise mapSpec.

Given a scalar bound of the form |toSpec (fR xR) - fS x| ≤ bnd (toSpec xR) eps and an input approximation approxTensor xS xR eps, this produces an approximation bound for map_spec fS xS vs map_spec fR xR, with an output epsilon computed by taking the linfNorm of the pointwise bound.

theorem Proofs.RuntimeApprox.approxTensor_map_spec_of_scalar_bound_of_forall {α : Type} {toSpec : αSpec.SpecScalar} {s : Spec.Shape} (predicate : Spec.SpecScalarProp) (fS : Spec.SpecScalarSpec.SpecScalar) (fR : αα) (bnd : Spec.SpecScalarSpec.SpecScalarSpec.SpecScalar) {xS : Spec.SpecTensor s} {xR : TorchLean.Tensor α s} {eps : Spec.SpecScalar} :
approxTensor toSpec xS xR epsTorchLean.Tensor.Forall predicate xS(∀ {x : Spec.SpecScalar} {xR : α}, predicate x|toSpec xR - x| eps|toSpec (fR xR) - fS x| bnd (toSpec xR) eps)approxTensor toSpec (TorchLean.Tensor.mapSpec fS xS) (TorchLean.Tensor.mapSpec fR xR) (linfNorm (TorchLean.Tensor.mapSpec (fun (a : Spec.SpecScalar) => bnd a eps) (tensorToSpec toSpec xR)))

Lift a domain-restricted scalar approximation bound to an elementwise mapSpec.

The predicate is carried by Tensor.Forall, so callers can certify operations such as square root once at the scalar level without rebuilding an elementwise tensor proof for every operation.

theorem Proofs.RuntimeApprox.approxTensor_map_spec_of_runtime_scalar_bound {α : Type} {toSpec : αSpec.SpecScalar} {s : Spec.Shape} (fS : Spec.SpecScalarSpec.SpecScalar) (fR : αα) (bnd : αSpec.SpecScalarSpec.SpecScalar) {xS : Spec.SpecTensor s} {xR : TorchLean.Tensor α s} {eps : Spec.SpecScalar} :
approxTensor toSpec xS xR eps(∀ {x : Spec.SpecScalar} {xR : α}, |toSpec xR - x| eps|toSpec (fR xR) - fS x| bnd xR eps)approxTensor toSpec (TorchLean.Tensor.mapSpec fS xS) (TorchLean.Tensor.mapSpec fR xR) (linfNorm (TorchLean.Tensor.map (fun (a : α) => bnd a eps) xR))

Lift a scalar approximation bound that depends on the original runtime scalar.

This variant is useful when the certified budget observes representation-specific runtime intermediates that cannot be reconstructed from toSpec xR.

theorem Proofs.RuntimeApprox.approxTensor_map2_spec_of_scalar_bound {α : Type} {toSpec : αSpec.SpecScalar} {s : Spec.Shape} (fS : Spec.SpecScalarSpec.SpecScalarSpec.SpecScalar) (fR : ααα) (bnd : Spec.SpecScalarSpec.SpecScalarSpec.SpecScalarSpec.SpecScalarSpec.SpecScalar) {xS yS : Spec.SpecTensor s} {xR yR : TorchLean.Tensor α s} {epsx epsy : Spec.SpecScalar} :
approxTensor toSpec xS xR epsxapproxTensor toSpec yS yR epsy(∀ {x y : Spec.SpecScalar} {xR yR : α}, |toSpec xR - x| epsx|toSpec yR - y| epsy|toSpec (fR xR yR) - fS x y| bnd (toSpec xR) (toSpec yR) epsx epsy)approxTensor toSpec (TorchLean.Tensor.map2Spec fS xS yS) (TorchLean.Tensor.map2Spec fR xR yR) (linfNorm (TorchLean.Tensor.map2Spec (fun (a b : Spec.SpecScalar) => bnd a b epsx epsy) (tensorToSpec toSpec xR) (tensorToSpec toSpec yR)))

Lift a scalar approximation bound to an elementwise map2Spec.

This is the binary analogue of approxTensor_map_spec_of_scalar_bound, used for elementwise arithmetic (add, sub, mulElem, etc.).