TorchLean API

NN.MLTheory.CROWN.Core

CROWN Core #

CROWN core definitions for TorchLean.

This file defines:

References:

structure NN.MLTheory.CROWN.Box (α : Type) (s : Spec.Shape) :

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.width {α : Type} [Context α] {s : Spec.Shape} (b : Box α s) :

    Pointwise box width hi - lo.

    Instances For
      def NN.MLTheory.CROWN.Box.center {α : Type} [Context α] {s : Spec.Shape} (b : Box α s) :

      Pointwise box center (lo + hi)/2.

      Instances For
        def NN.MLTheory.CROWN.Box.radius {α : Type} [Context α] {s : Spec.Shape} (b : Box α s) :

        Pointwise box radius (hi - lo)/2.

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

          Boolean a <= b using only the backend's decidable > from Context.

          This is useful for executable checks in backends that do not provide a decidable <=.

          Instances For

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

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

            Instances For
              def NN.MLTheory.CROWN.Box.contains {α : Type} [Context α] {s : Spec.Shape} :
              Box α sSpec.Tensor α sProp

              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, IEEE32Exec), 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} [Context α] [DecidableRel fun (x1 x2 : α) => x1 x2] {s : Spec.Shape} :
                  Box α sSpec.Tensor α sBool

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

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

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

                    def NN.MLTheory.CROWN.Box.point {α : Type} {s : Spec.Shape} (t : Spec.Tensor α s) :
                    Box α s

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

                    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) (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} [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.compose {α : Type} [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

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

                            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