TorchLean API

NN.MLTheory.CROWN.Graph.Engine.Base

Shared definitions for the graph CROWN engine.

This file contains the rank-one tensor representation, parameter stores, interval boxes, shape permutation helpers, and tensor casts used by the IBP, derivative, affine, CROWN, and backward objective passes.

An existentially sized rank-one tensor used by the flat LiRPA engine.

Graph nodes carry dimensions discovered while lowering, so the dimension cannot always appear in the surrounding static type. The field n is the hidden tensor dimension, not duplicate runtime storage.

Instances For

    Geometry shared by all concat transfers, preserving parent occurrences in list order.

    • leading : Spec.Shape

      Dimensions before the selected axis.

    • trailing : Spec.Shape

      Dimensions after the selected axis.

    • lengths : List ℕ

      Selected-axis length of each parent occurrence, including zero lengths.

    Instances For

      Shape of one parent occurrence.

      Instances For

        Shape of the concatenated output.

        Instances For

          Bijection between parent scalar coordinates and concatenated scalar coordinates.

          Instances For

            Read every output from its unique parent coordinate, without scalar arithmetic.

            Instances For

              Pull output coefficients back to one parent occurrence using the same coordinate bijection.

              Instances For

                Validate concat geometry against the IR contract and its declared output shape.

                Instances For

                  Validate and collect every concat parent; missing ids are rejected before reading payloads.

                  Instances For

                    Concatenate flat values after checking every parent payload length.

                    Instances For

                      Concatenate interval endpoints through the value coordinate map, without rounding.

                      Instances For
                        def NN.MLTheory.CROWN.Graph.concatNodeBoxes? {α : Type} [TorchLean.Storage α] [Context α] (nodes : Array Node) (boxes : Array (Option (FlatBox α))) (node : Node) (axis : ℕ) :

                        Shared concat rule for value, first-derivative and mixed-second-derivative interval passes.

                        Instances For

                          Parameters for a linear layer y = W*x + b in flattened form.

                          m is the output dimension and n is the input dimension.

                          Instances For

                            Matrix parameters for bias-free matmul: y = W x.

                            Instances For

                              Coordinate on axis corresponding to a row-major flat index.

                              Instances For

                                Eval BatchNorm scale for one channel.

                                Instances For

                                  Eval-mode BatchNorm bias after folding one channel's running statistics into an affine map.

                                  Instances For

                                    Build the exact diagonal affine form for eval-mode BatchNorm on an arbitrary channel axis.

                                    The graph records the channel axis while the payload stores one scale and bias per channel. A malformed axis or mismatched channel extent has no verifier transfer rule.

                                    Instances For

                                      Parameters keyed by node id (weights, biases, constants, and seeded input boxes).

                                      This is kept compact: it is the graph interpreter used to run IBP/CROWN on a pure Graph without pulling in a heavyweight runtime.

                                      Instances For

                                        Insert an input interval box for a graph node.

                                        Instances For
                                          def NN.MLTheory.CROWN.Graph.ParamStore.seedLInfBall {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] {s : Spec.Shape} (ps : ParamStore α) (inputId : ℕ) (center : TorchLean.Tensor α s) (eps : α) :

                                          Seed a graph input with a uniform ℓ∞ box around a shaped tensor.

                                          Instances For
                                            def NN.MLTheory.CROWN.Graph.planConvTransfer? {α : Type} [TorchLean.Storage α] (configuration : IR.ConvConfig) (parameters : IR.ConvParams α) (parentShape outShape : Spec.Shape) :

                                            Validate convolution geometry and return its leading batch shape.

                                            The canonical IR contract checks channels, groups, dilation, stride, padding and spatial rank. The payload and declared output must agree with the same geometry before any CROWN transfer runs.

                                            Instances For

                                              Check the graph-level semantic restrictions imposed by the current CROWN engine.

                                              Convolution payloads must match the declared geometry; LayerNorm payloads must match the entire normalized suffix. Custom computations are unsupported without verification transfer rules. This predicate checks the common shape contract; individual transfers also check their arithmetic and derivative requirements.

                                              Instances For

                                                Whether every node in a graph is interpreted exactly by the current CROWN engine.

                                                Instances For

                                                  Read a node's interval box from an IBP-style result array.

                                                  Instances For
                                                    @[instance_reducible]

                                                    Default inhabitant for FlatBox (a 0-dimensional box at 0).

                                                    Elementwise product of two FlatBoxes (interval product per component). Requires equal dims.

                                                    Instances For

                                                      Convert a dependent Box of shape .dim n .scalar into a FlatBox with dim := n.

                                                      Instances For

                                                        Convert a FlatBox to a dependent Box at shape .dim B.dim .scalar.

                                                        Instances For

                                                          Add two flat interval boxes coordinatewise; dimension mismatches preserve the left box.

                                                          Instances For

                                                            Interval subtraction on FlatBox endpoints (sound enclosure).

                                                            Instances For

                                                              Sum all coordinates of a flat box with directed accumulation.

                                                              Instances For

                                                                Apply ReLU to both endpoints of a FlatBox (monotone activation, so endpoints suffice).

                                                                Instances For

                                                                  Componentwise absolute value bounds using directed negation at negative endpoints.

                                                                  Instances For
                                                                    def NN.MLTheory.CROWN.Graph.boxUnaryEnclosure? {α : Type} [TorchLean.Storage α] [Context α] (enclose : α → α → Option (α × α)) (B : FlatBox α) :

                                                                    Apply a scalar interval enclosure coordinatewise to a flat box.

                                                                    Instances For

                                                                      Componentwise square-root bounds using the scalar backend's domain checks.

                                                                      The supplied real and native-float backends clamp negative lower endpoints to zero and reject wholly negative intervals. A backend may also reject an operation it does not support.

                                                                      Instances For

                                                                        Softplus bounds, applied independently at every tensor coordinate.

                                                                        Instances For

                                                                          SafeLog bounds with one shared scalar epsilon interval.

                                                                          The epsilon parent must contain one scalar. Keeping this check here makes direct graph construction follow the same contract as the typed builder and IR shape inference.

                                                                          Instances For

                                                                            Componentwise reciprocal bounds, failing when an input coordinate interval crosses zero.

                                                                            Instances For

                                                                              Derivative range for log; log' x = 1/x on a strictly positive interval.

                                                                              Instances For

                                                                                Second-derivative range for log; log'' x = -1/x² on a positive interval.

                                                                                Instances For

                                                                                  Negate an interval box by swapping and negating its endpoints.

                                                                                  Instances For
                                                                                    def NN.MLTheory.CROWN.Graph.flatAxisPermutation? (sourceShape : Spec.Shape) (perm : Array ℕ) (n : ℕ) :
                                                                                    Option (Fin n → Fin n)

                                                                                    Return the flat-coordinate permutation induced by an axis permutation.

                                                                                    perm follows the tensor convention used by Shape.permute?: output axis i is read from input axis perm[i]. The resulting function therefore maps each output flat coordinate to the input flat coordinate from which its value is taken. Invalid permutations and inconsistent dimensions are rejected.

                                                                                    Instances For

                                                                                      Componentwise max bounds: max(x,y) over interval boxes.

                                                                                      Instances For

                                                                                        Componentwise min bounds: min(x,y) over interval boxes.

                                                                                        Instances For

                                                                                          Componentwise square of an interval box, with downward-rounded lower endpoint squares and upward-rounded upper endpoint squares. The minimum is 0 when the interval crosses 0.

                                                                                          The body is exposed because the proof layer theorem module unfolds this executable rule when proving dimension preservation and pointwise enclosure.

                                                                                          Instances For
                                                                                            def NN.MLTheory.CROWN.Graph.intervalMul {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] (aLo aHi bLo bHi : α) :
                                                                                            α × α

                                                                                            Interval multiplication for scalar endpoints: given [aLo,aHi] and [bLo,bHi], return bounds on the product.

                                                                                            Instances For

                                                                                              Directed contraction with the same scalar indexing and sum order as Graph.matmulFlat.

                                                                                              Instances For
                                                                                                def NN.MLTheory.CROWN.Graph.ibpBinaryMatmul? {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] (leftShape rightShape : Spec.Shape) (left right : FlatBox α) :

                                                                                                Binary matmul with batch broadcasting, vector promotion, and directed endpoint arithmetic.

                                                                                                Instances For

                                                                                                  Reinterpret a flattened tensor as shape s when the element counts agree.

                                                                                                  Instances For

                                                                                                    IBP rule for broadcasting a flattened input box to a target shape.

                                                                                                    Instances For

                                                                                                      Sum one axis with downward lower accumulation and upward upper accumulation.

                                                                                                      Instances For

                                                                                                        Format-independent softmax enclosure on a flattened tensor.

                                                                                                        A singleton row is exactly one. Every coordinate of a longer row lies in [0,1]. This deliberately forgoes a tighter exponential relaxation so executable checking does not assume a directed transcendental implementation that its scalar backend has not supplied.

                                                                                                        Instances For

                                                                                                          Hard-masked softmax IBP (last axis) #

                                                                                                          Blocked coordinates have weight zero. An allowed coordinate lies in [0,1], and it has weight one when it is the only allowed coordinate in its row. These bounds do not evaluate exp or division, so they remain valid for executable endpoint types whose BoundOps instance covers only directed arithmetic. A tighter transfer rule requires separately certified directed bounds for transcendental operations.

                                                                                                          Conservative interval bounds for hard-masked softmax along the last tensor axis.

                                                                                                          Instances For

                                                                                                            LayerNorm interval propagation #

                                                                                                            Normalization acts independently on each row of the configured trailing shape. Its directed transfer bounds the mean, variance, stabilized denominator, and affine scale and bias.

                                                                                                            Uniform finite enclosure for normalization over a trailing shape.

                                                                                                            For a row of length n, exact LayerNorm without affine scale or bias satisfies |yᵢ| ≤ sqrt n; a singleton row is identically zero. Backends provide the outward-rounded bound through NonlinearBoundOps.layerNormAbsBound. Returning none is preferable to evaluating the normalization with unqualified host division and square root.

                                                                                                            Instances For
                                                                                                              def NN.MLTheory.CROWN.Graph.checkedFiniteBounds? {α : Type} [Context α] (bounds : α × α) :
                                                                                                              Option (α × α)

                                                                                                              Validate an interval before using it in a nonlinear transfer. Self-subtraction rejects infinite and NaN IEEE endpoints; finite exact-real endpoints satisfy these checks as well.

                                                                                                              Instances For
                                                                                                                def NN.MLTheory.CROWN.Graph.ibpBatchNormEval? {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] [NonlinearBoundOps α] (parentShape : Spec.Shape) (channelAxis : ℕ) (config : IR.BatchNormEvalParams α) (input : FlatBox α) :

                                                                                                                Enclose eval-mode BatchNorm without treating rounded normalization coefficients as exact.

                                                                                                                The running statistics are fixed, but their stabilized square root and division still need directed bounds. Coordinates use the denominator interval for their channel.

                                                                                                                Instances For
                                                                                                                  def NN.MLTheory.CROWN.Graph.directedRowMean? {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] [NonlinearBoundOps α] {n : ℕ} (bounds : Fin n → α × α) :
                                                                                                                  Option (α × α)

                                                                                                                  Directed mean bounds for one nonempty row. The denominator encloses the exact row length, including lengths that cannot be represented exactly by the scalar format.

                                                                                                                  Instances For

                                                                                                                    Average a nonempty flat box, enclosing both the sum and the exact coordinate count.

                                                                                                                    Instances For

                                                                                                                      Average one axis using directed sums and division. The denominator encloses the exact axis length, so a rounded natural-number conversion cannot silently narrow the result.

                                                                                                                      Instances For

                                                                                                                        Directed bounds for one LayerNorm row with explicit affine parameters.

                                                                                                                        The order follows Spec.layerNorm: center the input, center again inside reduceVar, square, average, clamp variance to zero, add epsilon, take a square root, and divide the first centered values directly. Each coordinate is then multiplied by its gamma and shifted by its beta; negative gamma reverses the interval endpoints.

                                                                                                                        Epsilon must be finite and positive, and the row and affine parameters must be finite. Division and square root use the selected nonlinear backend. Invalid or non-finite intermediate intervals return none. Proofs.LayerNormEnclosure proves enclosure of the real row under the backend's arithmetic laws. Agreement with native arithmetic requires its own numerical correspondence.

                                                                                                                        Instances For

                                                                                                                          Enclose a LayerNorm payload over the trailing shape starting at axis.

                                                                                                                          The matrix view and affine suffix are checked by the same helpers used in IR evaluation. Bounds are propagated separately for each row, then flattened back into the graph's storage order. Every payload, including one with default parameter values, uses the directed normalization sequence with its stored affine parameters and epsilon.

                                                                                                                          Instances For

                                                                                                                            Use the backend's uniform LayerNorm range when available; otherwise propagate the supplied input box through the directed normalization sequence over the suffix beginning at axis. Omitting axis selects the final axis.

                                                                                                                            Instances For

                                                                                                                              Cast a 1D Box along an equality of dimensions.

                                                                                                                              Instances For
                                                                                                                                def NN.MLTheory.CROWN.Graph.castAffineIn {α : Type} [TorchLean.Storage α] {n n' m : ℕ} (h : n = n') (a : AffineVec α n m) :
                                                                                                                                AffineVec α n' m

                                                                                                                                Cast the input dimension of an affine map across a proven equality.

                                                                                                                                Instances For
                                                                                                                                  def NN.MLTheory.CROWN.Graph.castAffineOut {α : Type} [TorchLean.Storage α] {n m m' : ℕ} (h : m = m') (a : AffineVec α n m) :
                                                                                                                                  AffineVec α n m'

                                                                                                                                  Cast the output dimension of an affine map across a proven equality.

                                                                                                                                  Instances For
                                                                                                                                    @[reducible, inline]

                                                                                                                                    Cast a dim-scalar tensor across an equality of dimensions.

                                                                                                                                    We keep this as an abbrev so it unfolds aggressively in simp-based soundness proofs.

                                                                                                                                    Instances For
                                                                                                                                      @[simp]

                                                                                                                                      Casting a flat vector tensor along an equality from a dimension to itself changes no data.

                                                                                                                                      IBP propagation through explicit linear parameters.

                                                                                                                                      Instances For
                                                                                                                                        def NN.MLTheory.CROWN.Graph.ibpLinear {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] (id : ℕ) (ps : ParamStore α) (Xin : FlatBox α) :

                                                                                                                                        IBP propagation for a .linear node using ParamStore.linearWB.

                                                                                                                                        Instances For
                                                                                                                                          def NN.MLTheory.CROWN.Graph.ibpMatmul {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] (id : ℕ) (ps : ParamStore α) (Xin : FlatBox α) :

                                                                                                                                          IBP propagation for a .matmul node (bias-free) using ParamStore.matmulW.

                                                                                                                                          Instances For
                                                                                                                                            def NN.MLTheory.CROWN.Graph.ibpConvNode {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] (configuration : IR.ConvConfig) (parentShape outShape : Spec.Shape) (id : ℕ) (ps : ParamStore α) (Xin : FlatBox α) :

                                                                                                                                            IBP transfer for a supported convolution node whose parameters are stored in ParamStore.convCfg.

                                                                                                                                            Instances For

                                                                                                                                              Apply a monotone SomeTensor operation independently to both interval endpoints.

                                                                                                                                              Instances For
                                                                                                                                                def NN.MLTheory.CROWN.Graph.ibpAvgPool? {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] [NonlinearBoundOps α] (config : IR.WindowConfig) (parentShape outShape : Spec.Shape) (input : FlatBox α) :

                                                                                                                                                Average-pool bounds with directed window sums, counts, and division.

                                                                                                                                                The shared pooling plan validates the spatial suffix and preserves every leading axis. Windows follow the spec's row-major coordinates and padded-cell lookup; padded zeros still contribute to the denominator. Unavailable or nonfinite arithmetic and inconsistent declared shapes return none.

                                                                                                                                                Instances For