CROWN Core #
CROWN core definitions for TorchLean.
This file defines:
- Box: element-wise lower/upper bounds (intervals) on tensors
- AffineBounds: per-output affine forms w.r.t. input x, and constant
- Utilities for splitting positive/negative parts and safe affine eval
References:
- Zhang et al., "Efficient Neural Network Robustness Certification with General Activation Functions" (CROWN), arXiv:1811.00866.
- Xu et al., "Automatic Perturbation Analysis for Scalable Certified Robustness and Beyond" (auto_LiRPA), NeurIPS 2020, arXiv:2002.12920. This generalizes LiRPA/CROWN to arbitrary computational graphs and introduces techniques (e.g., loss fusion) widely used in scalable certified training.
Interval box lo <= x <= hi over a tensor shape.
This is the fundamental object for interval bound propagation (IBP).
- lo : Spec.Tensor α s
Elementwise lower bound.
- hi : Spec.Tensor α s
Elementwise upper bound.
Instances For
Instances For
Pointwise box center (lo + hi)/2.
Instances For
Pointwise box radius (hi - lo)/2.
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
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.
Boolean a ≤ b using an explicit DecidableRel (· ≤ ·) argument.
Instances For
Boolean containment check using decidable ≤ and a finite fold over indices.
Instances For
Soundness of containsDecBool: if the Boolean checker returns true, then Box.contains
holds.
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.
Affine form y = A*x + c over flat vectors.
This is the representation used by CROWN/DeepPoly-style affine bound propagation.
- A : Spec.Tensor α (Spec.Shape.dim outDim (Spec.Shape.dim inDim Spec.Shape.scalar))
Coefficient matrix; each row is an output affine coefficient vector.
- c : Spec.Tensor α (Spec.Shape.dim outDim Spec.Shape.scalar)
Constant offset vector.
Instances For
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
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).