TorchLean API

NN.MLTheory.CROWN.BoundOps

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:

This file defines two small numeric interfaces:

There is intentionally no generic fallback for BoundOps: ordinary finite-precision arithmetic is not directed rounding and must not silently enter a sound bound-propagation path. The nonlinear interface does have a conservative fallback for bounded activations, but operations with unbounded ranges return none unless the scalar backend supplies an implementation. Soundness is a separate obligation, recorded by LawfulNonlinearBoundOps.

Integration points in the current codebase #

The intended usage is:

Concretely:

The distinction matters for executable certificate replay. A backend may support directed binary arithmetic without having a correctly rounded exp or log; in that case the graph checker leaves the corresponding node unresolved instead of treating an ordinary library call as an enclosure.

BoundOps α #

BoundOps 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 : ααα
  • supportsExactAffineReassociation : Bool

    Whether ordinary scalar algebra may be reassociated without a rounding error.

Instances

    Real-semantic enclosure laws for BoundOps.

    The executable interface above is intentionally available without this class: a backend may be useful for diagnostics before its arithmetic has been connected to a proof. Sound CROWN theorems require LawfulBoundOps in addition to BoundOps. The interpretation toReal says what a scalar endpoint means mathematically, and the laws compare each directed operation with exact arithmetic on those real values. This is stronger than merely surrounding the backend's ordinary rounded operation.

    There is a global instance for . There is deliberately no global instance for Lean Float or for all IEEE32Exec bit patterns. Host Float is a trusted runtime boundary, while IEEE-754 NaNs, infinities, and overflow require finite-path hypotheses; those facts are stated at the IEEE semantics layer rather than hidden in an invalid ordered-ring instance.

    Instances
      @[inline]
      def NN.MLTheory.CROWN.BoundOps.min2 {α : Type} [Context α] (a b : α) :
      α

      Minimum of two scalar endpoints.

      Instances For
        @[inline]
        def NN.MLTheory.CROWN.BoundOps.max2 {α : Type} [Context α] (a b : α) :
        α

        Maximum of two scalar endpoints.

        Instances For

          Nonlinear enclosure operations #

          Each method consumes a closed interval [lo, hi]. A successful result is another endpoint pair; none means that this backend does not implement a finite transfer for the requested operation. Division receives both numerator and denominator intervals. The executable result alone makes no soundness claim; LawfulNonlinearBoundOps supplies that claim when a theorem needs it.

          The interface is deliberately operational, like BoundOps. The proof layer establishes soundness for the concrete implementations used by checked workflows; an external instance without a lawful instance remains part of the backend trust boundary.

          • divBounds : ααααOption (α × α)
          • expBounds : ααOption (α × α)
          • logBounds : ααOption (α × α)
          • sqrtBounds : ααOption (α × α)
          • sigmoidBounds : ααOption (α × α)
          • tanhBounds : ααOption (α × α)
          • sinBounds : ααOption (α × α)
          • cosBounds : ααOption (α × α)
          • layerNormAbsBound : Option α

            Uniform absolute bound for one last-axis layer-normalization row.

          • supportsIdealCoupledDerivatives : Bool

            Whether coupled softmax/layer-normalization derivative formulas use exact scalar arithmetic.

          Instances
            def NN.MLTheory.CROWN.UnaryEnclosure {α : Type} [Context α] [BoundOps α] [LawfulBoundOps α] (f : ) (transfer : ααOption (α × α)) :

            Soundness predicate for a unary interval transfer.

            Returning none is always permitted. If the transfer returns endpoints, every real input between the interpreted input endpoints must map between the interpreted output endpoints.

            Instances For
              def NN.MLTheory.CROWN.BinaryEnclosure {α : Type} [Context α] [BoundOps α] [LawfulBoundOps α] (f : ) (transfer : ααααOption (α × α)) :

              Soundness predicate for a binary interval transfer.

              Instances For

                Real-semantic enclosure laws for NonlinearBoundOps.

                This class is deliberately separate from the executable transfer table. A backend may implement a transfer for testing before proving it; sound verification entrypoints can require this class and therefore cannot silently promote an unchecked implementation into a theorem.

                Instances
                  def NN.MLTheory.CROWN.NonlinearBoundOps.min4 {α : Type} [Context α] (a b c d : α) :
                  α

                  Minimum of four endpoints.

                  Instances For
                    def NN.MLTheory.CROWN.NonlinearBoundOps.max4 {α : Type} [Context α] (a b c d : α) :
                    α

                    Maximum of four endpoints.

                    Instances For

                      The denominator interval avoids zero.

                      Instances For
                        @[implicit_reducible, instance 100]

                        Conservative nonlinear ranges available for every scalar context.

                        Sigmoid, tanh, sine, and cosine have format-independent codomain bounds. Unbounded operations and layer normalization remain unavailable until a concrete backend provides directed implementations.

                        Exact real arithmetic needs no rounding, so its lower and upper operations coincide.

                        @[implicit_reducible]
                        @[implicit_reducible]

                        Exact real endpoint arithmetic satisfies the directed-operation enclosure laws.

                        @[implicit_reducible]

                        Exact nonlinear interval transfers over the real numbers.

                        Host binary64 endpoints #

                        Lean's Float operations round to nearest on the host binary64 format. For executable checking we widen every finite result by one adjacent representable value. This is deliberately an explicit instance rather than a generic fallback: its soundness depends on the host IEEE-754 arithmetic boundary documented by Lean, whereas instBoundOpsReal is exact and the IEEE32Exec instance is connected to TorchLean's bit-level binary32 proofs.

                        Adjacent binary64 value above x, with the usual IEEE behavior at infinities and zeros.

                        Instances For

                          Adjacent binary64 value below x, with the usual IEEE behavior at infinities and zeros.

                          Instances For
                            @[implicit_reducible]

                            Outward-widened host binary64 operations.

                            This instance is suitable for executable certificate replay under the trusted host-Float boundary. Use IEEE32Exec when the binary32 endpoint calculation itself must be connected to Lean proofs.

                            @[implicit_reducible]

                            Nonlinear enclosures supplied by host binary64 arithmetic.

                            Division and square root use hardware operations widened by one adjacent binary64 value. We do not make the same claim for host transcendental-library calls, so exp and log remain unsupported.