Documentation

LeanCert.ML.Optimized.IntervalArray

Optimized Interval Arrays (Structure-of-Arrays Layout) #

This module implements a cache-friendly interval vector representation using Structure-of-Arrays (SoA) layout instead of Array-of-Structures (AoS).

Key Optimization: SoA Layout #

Instead of:

Array IntervalDyadic = [⟨lo₁, hi₁⟩, ⟨lo₂, hi₂⟩, ...]

We store:

IntervalArray = { lo: Array Dyadic, hi: Array Dyadic }
            = { lo: [lo₁, lo₂, ...], hi: [hi₁, hi₂, ...] }

Why SoA? When computing lower bounds of a layer output, we mostly access lo values. Keeping them contiguous in memory improves cache hit rates by ~5x.

Main Definitions #

Structure-of-Arrays interval representation. Stores lower and upper bounds in separate contiguous arrays for cache efficiency.

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[inline]

      Access lower bound at index i

      Equations
      Instances For
        @[inline]

        Access upper bound at index i

        Equations
        Instances For

          Get the i-th interval as an IntervalDyadic

          Equations
          Instances For

            A real vector is a member of an interval array if each component is in bounds

            Equations
            Instances For

              Create an interval array from a function

              Equations
              Instances For
                def LeanCert.ML.Optimized.IntervalArray.mk' {n : } (lo hi : Array Core.Dyadic) (hlo : lo.size = n) (hhi : hi.size = n) :

                Create from separate lo/hi arrays (with proof of validity)

                Equations
                Instances For

                  Empty interval array (for n = 0)

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Singleton interval array

                    Equations
                    Instances For

                      Point-wise addition of interval arrays (exact, no rounding)

                      Equations
                      Instances For

                        Point-wise negation of interval array

                        Equations
                        Instances For

                          Point-wise subtraction of interval arrays

                          Equations
                          Instances For

                            Apply ReLU (max(0, x)) to each interval component

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For

                              Soundness Theorems #

                              theorem LeanCert.ML.Optimized.IntervalArray.mem_add {n : } {x y : Fin n} {a b : IntervalArray n} (hx : x a) (hy : y b) :
                              (fun (i : Fin n) => x i + y i) a.add b

                              Addition is sound: if x ∈ a and y ∈ b, then x + y ∈ add a b

                              theorem LeanCert.ML.Optimized.IntervalArray.mem_neg {n : } {x : Fin n} {a : IntervalArray n} (hx : x a) :
                              (fun (i : Fin n) => -x i) a.neg

                              Negation is sound: if x ∈ a, then -x ∈ neg a

                              theorem LeanCert.ML.Optimized.IntervalArray.mem_sub {n : } {x y : Fin n} {a b : IntervalArray n} (hx : x a) (hy : y b) :
                              (fun (i : Fin n) => x i - y i) a.sub b

                              Subtraction is sound

                              theorem LeanCert.ML.Optimized.IntervalArray.mem_relu {n : } {x : Fin n} {a : IntervalArray n} (hx : x a) :
                              (fun (i : Fin n) => max 0 (x i)) a.relu

                              ReLU is sound: if x ∈ a, then max(0, x) ∈ relu a

                              Conversion #

                              Convert from list-based IntervalVector

                              Equations
                              Instances For

                                Convert to list-based IntervalVector

                                Equations
                                Instances For