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

    Pointwise box width hi - lo.

    Instances For

      Pointwise box center (lo + hi)/2.

      Instances For

        Pointwise box radius (hi - lo)/2.

        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.

                @[inline]
                def NN.MLTheory.CROWN.Box.leDecBool {α : Type} [Context α] [DecidableRel fun (x1 x2 : α) => x1 x2] (a b : α) :

                Boolean a ≤ b using an explicit DecidableRel (· ≤ ·) argument.

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

                  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

                            We primarily target vector inputs/outputs for CROWN in this initial integration. To avoid over-generalizing shapes, we use a specialized variant for 1D (flat) vectors.

                            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
                              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.compose {α : Type} [TorchLean.Storage α] [Context α] {n h m : } (aff2 : AffineVec α h m) (aff1 : AffineVec α n h) :
                                  AffineVec α n m

                                  Compose two affine forms: (aff2 ∘ aff1)(x) = aff2(aff1(x)).

                                  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

                                      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