Numerical certificates for TorchLean graphs #
This module joins three existing parts of TorchLean without introducing another graph or another floating-point representation:
NN.IR.Graphremains the program being analysed;IEEE32Exec.Interval32supplies executable, outward-rounded binary32 intervals;NN.Backend.ExecutionAuditrecords the kernel capsules selected by backend planning.
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.
- nodeId : ℕ
- enclosure : TorchLean.Floats.IEEE754.IEEE32Exec.Interval32
Instances For
Instances For
A source range after the checker has established finite, ordered endpoints.
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
Interval32.leB decides the proposition-level IEEE non-strict order.
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.
Flipping the sign bit preserves finiteness.
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
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
The exact executable interval [0,1].
Instances For
The exact executable interval [-1,1].
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.
Upper counterpart of toReal_sqrtDown_le.
Sound real enclosure for directed interval square root.
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.
Tensor-level soundness of directed interval square root.
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
Proposition expressed by tensorWithinRange.
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.
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.
- source : RangeRule
- preserve (parent : ℕ) : RangeRule
- add (left right : ℕ) : RangeRule
- sub (left right : ℕ) : RangeRule
- mul (left right : ℕ) : RangeRule
- inv (parent : ℕ) : RangeRule
- hull (parents : List ℕ) : RangeRule
- hullZero (parent : ℕ) : RangeRule
- sumLeft (parent count : ℕ) : RangeRule
- meanLeft (parent count : ℕ) : RangeRule
- matmulLeft (left right innerDim : ℕ) : RangeRule
- averageWindowLeft (parent windowSize : ℕ) (includesPadding : Bool) : RangeRule
- mseLeft (prediction target count : ℕ) : RangeRule
- layerNormLeft (parent axis normalizedSize : ℕ) : RangeRule
- softmaxUnit (parent axis : ℕ) : RangeRule
- relu (parent : ℕ) : RangeRule
- abs (parent : ℕ) : RangeRule
- sqrtNonnegative (parent : ℕ) : RangeRule
- unitBound (parent : ℕ) : RangeRule
- signedUnitBound (parent : ℕ) : RangeRule
Instances For
Instances For
Instances For
Proof-free data for one graph node's numerical range.
- nodeId : ℕ
- outShape : Spec.Shape
- rule : RangeRule
- enclosure : TorchLean.Floats.IEEE754.IEEE32Exec.Interval32
Instances For
Instances For
A node range whose executable interval has passed the finite/order check.
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
Proof-level meaning of a complete successful IEEE replay trace.
Graph-wide pointwise approximation evidence, one row per intermediate value.
- nil : ExecutionErrorTrace [] [] []
- cons {range : CheckedNodeRange} {ranges : List CheckedNodeRange} {exact : NN.IR.DVal ℝ} {exacts : List (NN.IR.DVal ℝ)} {computed : NN.IR.DVal TorchLean.Floats.IEEE754.IEEE32Exec} {computeds : List (NN.IR.DVal TorchLean.Floats.IEEE754.IEEE32Exec)} : DValErrorLe range exact computed → ExecutionErrorTrace ranges exacts computeds → ExecutionErrorTrace (range :: ranges) (exact :: exacts) (computed :: computeds)
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
Hull of a nonempty list of parent ranges.
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.
- source : NumericalOpKey
- structural : NumericalOpKey
- wholeSum : NumericalOpKey
- maxPool : NumericalOpKey
- maxPoolPad : NumericalOpKey
- averagePool : NumericalOpKey
- averagePoolPad : NumericalOpKey
- backend (op : NN.Backend.BackendOp) : NumericalOpKey
- unclassified : NumericalOpKey
Instances For
Instances For
Instances For
Classify an IR operation for numerical-contract lookup.
Instances For
Read-only state supplied to one local range transfer.
- sources : Array CheckedSourceRange
- plan : NN.Backend.AcceptedGraphPlan
- ranges : Array CheckedNodeRange
Instances For
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.
- key : NumericalOpKey
- name : String
- derive : NumericalRangeContext → NN.IR.Node → Except String RangeTransferResult
Instances For
Deterministic registry used by graph certificate generation and replay.
- name : String
- contracts : List GraphRangeContract
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.
- nodeId : ℕ
- operation : String
- key : NumericalOpKey
Instances For
Architecture-independent coverage report obtained after lowering a model to NN.IR.Graph.
- registryName : String
- nodeCount : ℕ
- coveredCount : ℕ
- missing : List MissingNumericalContract
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
Structural identity used by detach.
Instances For
Reusable contract constructor for value-preserving graph operations.
Instances For
Reusable contract constructor for pointwise binary interval 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
ReLU interval contract.
Instances For
Absolute-value interval contract.
Instances For
Square-root contract with a checked nonnegative domain.
Instances For
Constructor for bounded transcendental contracts.
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.
- profileName : String
- registryName : String
- sources : Array SourceRange
- audit : NN.Backend.ExecutionAudit
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.
- graph : NN.IR.Graph
The exact graph whose ranges and backend plan were reconstructed by the checker.
The untrusted artifact supplied to the checker, retained for inspection and serialization.
- sources : Array CheckedSourceRange
Source assumptions whose interval endpoints have been proved finite and ordered.
- ranges : Array CheckedNodeRange
The canonical node-by-node range trace reconstructed from the graph.
- backendPlan : NN.Backend.AcceptedGraphPlan
The backend plan accepted when the checker replanned
graph. Proof that the reconstructed trace matches every range row claimed by
raw.Proof that the accepted plan's audit is the one stored in
raw.
Instances For
Result of executing the canonical IR with bit-level binary32 semantics and replaying every intermediate value against a checked numerical certificate.
- certificate : CheckedCertificate
- values : Array (NN.IR.DVal TorchLean.Floats.IEEE754.IEEE32Exec)
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.
- payload : NN.IR.Payload ℝ
Real-valued constants and external tensors used by the graph execution.
- input : NN.IR.DVal ℝ
Real-valued graph input.
- values : Array (NN.IR.DVal ℝ)
Complete real-valued node trace, in graph order.
Evidence that
valuesis exactly the graph's denotational execution trace.- enclosed : List.Forall₂ RealDValEnclosed certificate.ranges.toList self.values.toList
Pointwise evidence that every real node value lies in its checked interval.
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.