Directed-rounding primitives for interval propagation #
TorchLean’s IBP/CROWN code represents bounds as endpoint pairs (lo/hi) inside Box/FlatBox.
To make those bounds meaningful under different numeric semantics, we abstract the primitive
endpoint operations (directed rounding).
Intuition:
- For pure real/interval backends, using ordinary
+/*is already enclosure-safe (because the scalar itself is an interval type with outward rounding). - For finite-precision backends with discrete grids (e.g.
IEEE32Exec), we want directed rounding primitives likeaddDown/addUpandmulDown/mulUpso that interval propagation encloses the corresponding exact real operation.
This file defines a small typeclass BoundOps and some helper combinators. The default instance
is conservative: it just uses the scalar’s ordinary operations (no directed rounding). Specific
backends can override it (e.g. IEEE32Exec).
Integration points in the current codebase #
The intended usage is:
- Keep graphs/layers scalar-polymorphic over
[Context α]. - When a routine propagates bounds (IBP/affine/CROWN), also require
[BoundOps α]and useaddDown/addUp/subDown/subUp/mulDown/mulUpat the endpoints.
Concretely:
NN/MLTheory/CROWN/Core.leanNN.MLTheory.CROWN.Graphbox_add,box_sub,box_mul_elem: endpoint propagation usesBoundOps.
To extend coverage, the next candidates are box_inv, box_sqrt, and the various nonlinearity
propagation rules in NN.MLTheory.CROWN.Runtime.Ops (these may need additional directed math
primitives or an Arb-backed enclosure oracle).
BoundOps α #
BoundOps is intentionally focused: it supplies directed-rounding versions of the arithmetic
primitives that appear in IBP for affine/linear layers and basic arithmetic nodes.
If you want to swap in a quantized backend, the key is to provide an instance of BoundOps for
your scalar type.
- addDown : α → α → α
- addUp : α → α → α
- subDown : α → α → α
- subUp : α → α → α
- mulDown : α → α → α
- mulUp : α → α → α
Instances
Default implementation: no directed rounding (use the scalar’s own arithmetic).
This keeps existing Float/ℝ/Interval instantiations working without extra adapters.
Small helpers built only from Context.decidable_gt.