TorchLean API

NN.MLTheory.CROWN.Core

CROWN Core #

CROWN core definitions for TorchLean.

This file defines:

References:

Interval box lo <= x <= hi over a tensor shape.

This is the fundamental object for interval bound propagation (IBP).

Instances For
    def NN.MLTheory.CROWN.Box.leBool {α : Type} [Context α] (a b : α) :

    Boolean a <= b using the backend's strict order and Boolean equality.

    Reflexivity guards reject NaNs even on backends whose strict comparison uses a total implementation order. For a logical containment theorem, use containsDecBool.

    Instances For

      Executable containment check: returns true iff every component is within bounds.

      This uses leBool and is therefore available for any Context α.

      Instances For

        Logical containment: every component of x lies between lo and hi.

        Instances For

          containsBool above is a minimal Context-only checker that avoids requiring decidable ≤.

          For backends that do provide decidable ≤ (e.g. ℝ, Float, ExecFloat.Binary 8 23), we also expose a checker that uses ≤ directly. We implement it by structural recursion (rather than decide (Box.contains ...)) so it remains executable.

          def NN.MLTheory.CROWN.Box.containsDecBool {α : Type} [TorchLean.Storage α] [Context α] [DecidableRel fun (x1 x2 : α) => x1 ≤ x2] {s : Spec.Shape} :
          Box α s → TorchLean.Tensor α s → Bool

          Boolean containment check using decidable ≤ and a finite fold over indices.

          Instances For
            theorem NN.MLTheory.CROWN.Box.containsDecBool_sound {α : Type} [TorchLean.Storage α] [Context α] [DecidableRel fun (x1 x2 : α) => x1 ≤ x2] {s : Spec.Shape} (b : Box α s) (x : TorchLean.Tensor α s) :

            Soundness of containsDecBool: if the Boolean checker returns true, then Box.contains holds.

            Degenerate (Dirac) box with lo = hi = t.

            Instances For
              theorem NN.MLTheory.CROWN.Box.contains_point_self {α : Type} [TorchLean.Storage α] [Context α] [Std.Refl fun (x1 x2 : α) => x1 ≤ x2] {s : Spec.Shape} (t : TorchLean.Tensor α s) :

              A tensor is contained in its own degenerate box.

              Cast the lower endpoint to a checked vector dimension.

              Instances For

                Cast the upper endpoint to a checked vector dimension.

                Instances For

                  View a flattened interval box as a shape-indexed vector box after checking the dimension.

                  Most CROWN affine evaluators expect a Box α (.dim m .scalar), while graph propagation stores runtime-shaped FlatBox values. This helper keeps the dependent casts in one place.

                  Instances For

                    CROWN affine bounds use one matrix row per output scalar and one column per input scalar. A tensor of shape s contributes s.size coordinates to this flat representation. Graph nodes retain their tensor shapes, and each transfer checks its operator's shape contract.

                    Graph matmul uses the canonical IR contract, including vector promotion and broadcasting of leading batch axes. The matrix sign-splitting and affine evaluation below operate on the flattened coefficient matrix; they do not restrict the original graph operands to that matrix shape.

                    structure NN.MLTheory.CROWN.AffineVec (α : Type) [TorchLean.Storage α] (inDim outDim : ℕ) :

                    Affine form y = A*x + c over flat vectors.

                    This is the representation used by CROWN/DeepPoly-style affine bound propagation.

                    Instances For

                      Positive part of a weight matrix, W⁺ = max(W, 0), used by sign-split bound rules.

                      Instances For

                        Negative part of a weight matrix, W⁻ = min(W, 0), used by sign-split bound rules.

                        Instances For

                          Interval bound propagation for a linear layer.

                          Given interval inputs xB and bB, this returns an interval box for W*x + b by:

                          • computing per-coefficient endpoint products with directed rounding (BoundOps.mulDown/mulUp), and
                          • summing with directed rounding (addDown/addUp).
                          Instances For
                            def NN.MLTheory.CROWN.AffineVec.evalOnBox {α : Type} [TorchLean.Storage α] [Context α] {inDim outDim : ℕ} [BoundOps α] (aff : AffineVec α inDim outDim) (B : Box α (Spec.Shape.dim inDim Spec.Shape.scalar)) :

                            Evaluate an affine form on an input box, producing an output box.

                            This performs the standard interval evaluation for linear forms by taking, per coefficient a, the appropriate endpoint (lo or hi) to minimize/maximize a*x.

                            Instances For
                              def NN.MLTheory.CROWN.AffineVec.evalOnFlatBox {α : Type} [TorchLean.Storage α] [Context α] {inDim outDim : ℕ} [BoundOps α] (aff : AffineVec α inDim outDim) (B : FlatBox α) (h : B.dim = inDim) :

                              Evaluate an affine form on a flattened graph box after checking the input dimension.

                              Graph-level CROWN stores boxes as FlatBox; affine evaluation works over vector-shaped boxes. This helper keeps that cast at the CROWN boundary instead of repeating it in verifier workflows.

                              Instances For
                                def NN.MLTheory.CROWN.AffineVec.ofLinear {α : Type} [TorchLean.Storage α] {inDim outDim : ℕ} (W : TorchLean.Tensor α [outDim, inDim]) (b : TorchLean.Tensor α [outDim]) :
                                AffineVec α inDim outDim

                                Build an affine form from a linear layer y = W*x + b.

                                Instances For