TorchLean API

NN.Proofs.RuntimeApprox.Graph.NumericalCertificate

Numerical certificates for TorchLean graphs #

This module joins three existing parts of TorchLean without introducing another graph or another floating-point representation:

A raw certificate is proof-free data that an application may construct or decode using its own artifact format; this module does not prescribe a JSON schema. check does not trust its node ranges. It reconstructs the canonical range trace from the graph and source assumptions, checks every interval for finite ordered endpoints, replans the graph under the named backend profile, and compares the result with the raw artifact. Successful checking returns a CheckedCertificate, whose node ranges carry finite-endpoint and ordering proofs. This executable check does not by itself prove enclosure of the exact-real graph denotation; that evidence is the separate CheckedRealExecution value used by CheckedExecution.errorTrace.

The range trace deliberately starts with operations whose enclosure is already provided by the sound Interval32 core. Unsupported operations fail with the node id and operation name. They are not assigned [-inf,+inf], because that would turn a missing numerical theorem into an apparently successful certificate.

The numerical conventions follow IEEE Std 754-2019. Outward-rounded interval propagation follows IEEE Std 1788-2015 and the standard inclusion principle for interval arithmetic. For the error model that composes local bounds across forward and reverse graphs, see ForwardApprox.lean and BackwardApprox.lean; the organization follows the local-error/global-error distinction in N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd ed., 2002.

Raw and checked source assumptions #

A binary32 range supplied for an input, constant, or explicit random source node.

Instances For

    Bitwise equality for executable binary32 intervals.

    Bitwise equality is intentional: it distinguishes signed zero and preserves the exact endpoints written in a certificate. NaNs are rejected separately by Interval32.Valid.

    Instances For

      Executable counterpart of Interval32.Valid.

      Instances For

        IEEE comparison between finite values implies the corresponding order on their real interpretations. This lemma is intentionally finite: IEEE comparisons involving NaN are unordered, and toReal is not the semantic interface for infinities.

        Negation of a finite executable binary32 value decodes to real negation.

        The executable validity test accepts exactly finite, ordered intervals.

        Real semantics of the arithmetic transfers #

        The executable checker propagates binary32 endpoints, while the graph specification is normally read over real scalars. RealEncloses is the bridge between those views. Runtime rounding error is then composed separately by FwdGraph.eval_approx and RevGraph.backprop_approx; keeping these two claims separate prevents an interval enclosure from silently standing in for a floating-point error theorem.

        A real scalar lies between the real interpretations of an executable interval's endpoints.

        Instances For
          theorem Proofs.RuntimeApprox.NumericalCertificate.realEncloses_of_eReal_bounds {interval : TorchLean.Floats.IEEE754.IEEE32Exec.Interval32} {value : } (valid : interval.Valid) (bounds : interval.lo.toEReal value value interval.hi.toEReal) :
          RealEncloses interval value

          Convert the extended-real endpoint form used by the interval soundness library into an ordinary real interval when the output endpoints are finite.

          Sound real enclosure for the canonical addition transfer.

          Sound real enclosure for the canonical subtraction transfer.

          Sound real enclosure for the canonical multiplication transfer.

          Sound real enclosure for the canonical reciprocal transfer.

          Every scalar entry of a shape-indexed real tensor lies in one interval.

          Instances For

            Executable test for a finite endpoint's nonnegative IEEE sign. Both signed zeros are accepted; all other accepted values have a clear sign bit. Finiteness is supplied by interval validity.

            Instances For

              The stable real vector softmax is enclosed by the certificate transfer [0,1].

              Sound real enclosure for the canonical ReLU interval transfer.

              Sound real enclosure for the canonical absolute-value interval transfer.

              A directed lower square-root endpoint lies below the exact real square root. Signed zero is handled separately because IEEE preserves its sign, while the general directed-rounding theorem is stated for sign-bit-false inputs.

              Sound real enclosure for directed interval square root.

              theorem Proofs.RuntimeApprox.NumericalCertificate.tensor_map_enclosed (op : ) (input output : TorchLean.Floats.IEEE754.IEEE32Exec.Interval32) (sound : ∀ {x : }, RealEncloses input xRealEncloses output (op x)) {shape : Spec.Shape} {x : Spec.Tensor shape} :

              Lift a sound unary scalar transfer to tensors of arbitrary rank.

              Tensor-level soundness of the ReLU interval transfer.

              Tensor-level soundness of the absolute-value interval transfer.

              Lift a sound binary scalar transfer to tensors of arbitrary rank.

              Tensor-level soundness of outward-rounded interval addition.

              Tensor-level soundness of outward-rounded interval subtraction.

              Tensor-level soundness of outward-rounded interval multiplication.

              Replay against bit-level graph execution #

              Executable check that every binary32 tensor entry lies in an interval.

              Instances For

                The executable tensor range check is exact for the IEEE comparison semantics.

                From checked ranges to explicit error bounds #

                Decode an executable tensor entrywise and state that the resulting real tensor lies in an interval. Unlike IEEETensorEnclosed, this predicate talks directly about the real values used by the approximation layer.

                Instances For

                  A successful IEEE range check decodes to an ordinary real enclosure. Finiteness is an explicit part of IEEETensorEnclosed, so this theorem never assigns a real meaning to NaN or infinity.

                  Pointwise absolute error between a real specification tensor and an executable binary32 tensor. The shape index is shared, so no runtime shape cast is hidden in the relation.

                  Instances For

                    Width of a finite executable interval, interpreted in the reals.

                    Instances For

                      A valid interval has nonnegative real width.

                      Two tensors enclosed by the same interval differ entrywise by at most its width.

                      This is the elementary bridge from range analysis to approximation analysis. It is deliberately pointwise; a later norm theorem can package the same statement as an L∞ bound without changing the checker or its certificate format.

                      theorem Proofs.RuntimeApprox.NumericalCertificate.tensor_error_le_width_of_check {interval : TorchLean.Floats.IEEE754.IEEE32Exec.Interval32} (valid : interval.Valid) {shape : Spec.Shape} {exact : Spec.Tensor shape} {computed : Spec.Tensor TorchLean.Floats.IEEE754.IEEE32Exec shape} (hexact : TensorEnclosed interval exact) (hcheck : tensorWithinRange interval computed = true) :
                      TensorErrorLe (intervalWidth interval) exact computed

                      A successful executable range check and a real enclosure proof yield a concrete pointwise error bound. This theorem is the tensor-level core used by graph-wide numerical certificates.

                      Check source ranges once, rejecting malformed intervals and duplicate node ids.

                      Instances For

                        Find the checked assumption for a source node.

                        Instances For

                          Whether a graph node obtains its enclosure directly from a certificate source assumption.

                          Instances For

                            Reject source assumptions that do not name a source-like node in the checked graph.

                            Unused assumptions do not make interval propagation unsound, but they make artifacts ambiguous: an exporter may have attached a valid range to the wrong node id without noticing. Requiring every row to be consumed gives source arrays one canonical interpretation and catches that error before range propagation begins.

                            Instances For

                              Canonical local transfer rules #

                              How a node enclosure was obtained from source assumptions or earlier nodes.

                              The rule is recorded to make certificate diagnostics useful. It is not accepted on faith: check reconstructs the rule and endpoints from the graph.

                              Instances For

                                Proof-free data for one graph node's numerical range.

                                Instances For

                                  Check a dynamic graph value against the declared shape and interval of one certificate row.

                                  Instances For

                                    A real dynamic graph value has the shape declared by a certificate row and is enclosed by its interval. The equality witness makes the dependent tensor cast explicit.

                                    Instances For

                                      Pointwise approximation relation for real and IEEE dynamic graph values at one certificate row.

                                      Instances For

                                        One successful dynamic replay row yields a pointwise error bound whenever the corresponding real graph value has the proved enclosure.

                                        List-level replay check. Its structural recursion is also the proof interface for composing per-node numerical guarantees over a complete execution trace.

                                        Instances For

                                          Check every value produced by IR.Graph.denoteAll against the corresponding certificate row.

                                          Instances For

                                            Graph-wide pointwise approximation evidence, one row per intermediate value.

                                            Instances For

                                              Compose real enclosure proofs and successful IEEE replay checks into an error trace.

                                              Array-facing whole-trace theorem used by checked graph executions.

                                              Compare a checked canonical row with untrusted raw certificate data.

                                              Instances For

                                                Read a previously checked parent enclosure. Graph well-formedness guarantees that successful lookups refer only to earlier rows; the explicit error still protects this API when called alone.

                                                Instances For

                                                  Read the complete checked row for a parent node.

                                                  Instances For

                                                    Outward-rounded left-fold range for a sum of count values from one enclosure. The initial point interval at positive zero matches Tensor.sumSpec.

                                                    Instances For

                                                      Left-fold mean range, using the same binary32 conversion of the divisor as the tensor context.

                                                      Instances For

                                                        Numerical policy selected for a runtime-relevant graph node.

                                                        Instances For

                                                          Reductions are propagated only when the selected capsule promises the same fixed left fold as the canonical tensor semantics. Other schedules need the order-independent reduction bound from NN.Floats.IEEEExec.Reductions and are rejected here rather than mislabeled as deterministic.

                                                          Instances For

                                                            Inner accumulation length for the rank-2 and batched rank-3 matrix products implemented by IR.Graph.denoteAll. The graph shape checker has already validated matching dimensions; retaining the checks here gives callers of deriveNodeRange a precise error instead of relying on that ambient invariant.

                                                            Instances For

                                                              Graph range contracts #

                                                              Architectures do not participate in range propagation directly. They lower to NN.IR.Graph, and each graph node is handled by a reusable operation contract. This keeps MLPs, convolutional networks, transformers, and future model families on one checker path: adding a model requires no new certificate traversal, while adding a genuinely new primitive requires one local contract.

                                                              The registry is an explicit value rather than global mutable state. Certificate generation and checking therefore use the same inspectable rule set, and downstream projects may extend it without changing TorchLean's graph walker.

                                                              Stable key for a numerical range contract.

                                                              Input-like nodes share the source contract, detach uses the structural identity contract, and runtime operations use the same BackendOp vocabulary as kernel capsules and execution plans.

                                                              Instances For

                                                                Classify an IR operation for numerical-contract lookup.

                                                                Instances For

                                                                  Read-only state supplied to one local range transfer.

                                                                  Instances For
                                                                    @[reducible, inline]

                                                                    Result computed by one numerical operation contract.

                                                                    Instances For

                                                                      Executable range transfer for one operation family.

                                                                      The proof-facing meaning of the resulting row remains RealDValEnclosed; local soundness lemmas for interval arithmetic and NF approximation are kept in their mathematical modules. The contract contains only executable dispatch and a stable key, so serializable certificates cannot inject proof evidence.

                                                                      Instances For

                                                                        Deterministic registry used by graph certificate generation and replay.

                                                                        Instances For

                                                                          Empty named registry for downstream composition.

                                                                          Instances For

                                                                            Find the unique contract associated with a numerical operation key.

                                                                            Instances For

                                                                              Add one contract, rejecting duplicate keys so dispatch never depends on list order.

                                                                              Instances For

                                                                                Build a registry while checking key uniqueness.

                                                                                Instances For

                                                                                  One graph node for which a numerical registry has no local transfer.

                                                                                  Instances For

                                                                                    Architecture-independent coverage report obtained after lowering a model to NN.IR.Graph.

                                                                                    Instances For

                                                                                      Inspect contract coverage without attempting interval propagation.

                                                                                      Instances For

                                                                                        Reject a graph before propagation when any primitive lacks a numerical contract.

                                                                                        Instances For

                                                                                          Standard diagnostic for a contract whose graph arity does not match its operation.

                                                                                          Instances For

                                                                                            Shared source-node contract. The source interval remains an explicit certificate assumption.

                                                                                            Instances For

                                                                                              Reusable contract constructor for value-preserving graph operations.

                                                                                              Instances For

                                                                                                Reusable contract for operations whose output is enclosed by the hull of their parents.

                                                                                                Instances For

                                                                                                  Max pooling without padding selects existing values and therefore preserves the input hull.

                                                                                                  Instances For

                                                                                                    Padded max pooling may additionally select the padding value zero.

                                                                                                    Instances For

                                                                                                      Shared average-pooling contract constructor.

                                                                                                      Instances For

                                                                                                        Reciprocal contract with an explicit nonzero-domain check.

                                                                                                        Instances For

                                                                                                          Whole-tensor fixed-left sum contract.

                                                                                                          Instances For

                                                                                                            Axis reduction contract shared by sum and mean.

                                                                                                            Instances For

                                                                                                              Matrix multiplication contract using the selected fixed-left accumulation schedule.

                                                                                                              Instances For

                                                                                                                Mean-squared-error contract with nonnegativity restored after dependent squaring.

                                                                                                                Instances For

                                                                                                                  Pure LayerNorm contract over an arbitrary normalized suffix.

                                                                                                                  Instances For

                                                                                                                    Softmax contract: exact-real outputs lie in the unit interval on every nonempty axis.

                                                                                                                    Instances For

                                                                                                                      Absolute-value interval contract.

                                                                                                                      Instances For

                                                                                                                        Square-root contract with a checked nonnegative domain.

                                                                                                                        Instances For

                                                                                                                          Built-in numerical contracts. Grouping is by operation semantics, never by architecture.

                                                                                                                          Instances For

                                                                                                                            TorchLean's built-in numerical registry. Construction is checked once at use sites so a future duplicate produces an explicit configuration failure.

                                                                                                                            Instances For

                                                                                                                              Compute one node range using an explicit numerical contract registry.

                                                                                                                              Instances For

                                                                                                                                Compute one node range using TorchLean's built-in registry.

                                                                                                                                Instances For

                                                                                                                                  Construct and validate the canonical range trace using an explicit contract registry.

                                                                                                                                  Instances For

                                                                                                                                    Construct and validate the canonical range trace using TorchLean's built-in contracts.

                                                                                                                                    Instances For

                                                                                                                                      Erase validity proofs from a checked trace.

                                                                                                                                      Instances For

                                                                                                                                        Compare a canonical checked trace with untrusted raw rows.

                                                                                                                                        Instances For

                                                                                                                                          Backend-linked graph certificates #

                                                                                                                                          Untrusted certificate data.

                                                                                                                                          The audit field records the data selected by backend planning. The checker replans the graph under profileName and compares the complete audit, so an artifact cannot choose its own provider, trust level, or evidence classification.

                                                                                                                                          Instances For

                                                                                                                                            Proof-carrying result returned by check. Raw endpoint data has been replaced by the canonical trace reconstructed from the graph, and backendPlan contains the acceptance-gate proof.

                                                                                                                                            Instances For

                                                                                                                                              Result of executing the canonical IR with bit-level binary32 semantics and replaying every intermediate value against a checked numerical certificate.

                                                                                                                                              Instances For

                                                                                                                                                Convert an accepted backend plan and checked range trace into raw certificate data.

                                                                                                                                                Instances For

                                                                                                                                                  Obtain an accepted backend plan or report the acceptance-gate failures.

                                                                                                                                                  Instances For

                                                                                                                                                    Generate a canonical certificate using an explicit numerical operation registry.

                                                                                                                                                    Instances For

                                                                                                                                                      Generate a canonical certificate using TorchLean's built-in numerical contracts.

                                                                                                                                                      Instances For

                                                                                                                                                        Check an untrusted certificate with an explicit numerical operation registry.

                                                                                                                                                        Instances For

                                                                                                                                                          Check an untrusted certificate using TorchLean's built-in numerical contracts.

                                                                                                                                                          Instances For

                                                                                                                                                            Generate and immediately check a certificate. This is convenient for in-process callers and ensures examples exercise exactly the same checker used for imported artifacts.

                                                                                                                                                            Instances For

                                                                                                                                                              Generate and immediately check with one explicit registry.

                                                                                                                                                              Instances For

                                                                                                                                                                Execute a graph under IEEE32Exec and check all intermediate tensors against the certificate.

                                                                                                                                                                This reference replay path gives imported runtime artifacts a bit-level oracle. The backend audit records the capsules and numerical policies selected when the graph is replanned. The audit is not runtime provenance and does not prove that those kernels produced the imported values.

                                                                                                                                                                Instances For

                                                                                                                                                                  Exact-real execution evidence for the graph stored in a checked certificate.

                                                                                                                                                                  The numerical checker reconstructs interval transfers, while a semantic proof establishes that the real graph trace lies in those intervals. Keeping this proof separate prevents successful endpoint replay from being mistaken for a theorem about an unsupported real operation.

                                                                                                                                                                  Instances For

                                                                                                                                                                    Pair a checked IEEE replay with a proved real enclosure trace to obtain a graph-wide, pointwise error trace. Each node's error budget is the width of its checked outward interval.