Documentation

LeanCert.ML.Network

Verified Neural Network Propagation #

This file defines neural network layers and provides verified interval propagation, enabling robustness verification for neural networks.

Main definitions #

Main theorems #

Design Notes #

We keep the network definition simple by using lists. Dimension compatibility is checked at runtime and encoded in theorem hypotheses. This avoids complex dependent types while still providing verified soundness.

A dense layer: y = ReLU(W·x + b) weights is a list of rows, each row has inputDim elements bias has outputDim elements (= number of rows in weights)

  • weights : List (List )

    Weight matrix (outputDim × inputDim), stored as list of rows

  • bias : List

    Bias vector (outputDim elements)

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

      Input dimension (number of columns in weight matrix)

      Equations
      Instances For

        Output dimension (number of rows in weight matrix)

        Equations
        Instances For

          A layer is well-formed if all rows have the same length and bias matches output

          Equations
          Instances For

            Forward pass through a layer (real values): y = ReLU(W·x + b)

            Equations
            Instances For

              Forward pass through a layer (interval arithmetic)

              Equations
              Instances For

                Length of real forward pass output

                Length of interval forward pass output

                theorem LeanCert.ML.Layer.mem_forwardInterval {l : Layer} {xs : List } {Is : IntervalVector} (hwf : l.WellFormed) (hdim : l.inputDim = List.length Is) (hxlen : xs.length = List.length Is) (hmem : ∀ (i : ) (hi : i < List.length Is), xs[i] Is[i]) (prec : ) (hprec : prec 0 := by norm_num) (i : ) (hi : i < min l.outputDim l.bias.length) :
                (l.forwardReal xs)[i] (l.forwardInterval Is prec)[i]

                Soundness of layer forward pass. If x ∈ I (component-wise), then forwardReal(x) ∈ forwardInterval(I).

                A two-layer network for simple examples

                Instances For

                  Forward pass through two layers

                  Equations
                  Instances For

                    Interval forward pass through two layers

                    Equations
                    Instances For

                      Network is well-formed if layers are well-formed and dimensions match

                      Equations
                      Instances For
                        theorem LeanCert.ML.TwoLayerNet.mem_forwardInterval {net : TwoLayerNet} {xs : List } {Is : IntervalVector} (hwf : net.WellFormed) (hdim : net.layer1.inputDim = List.length Is) (hxlen : xs.length = List.length Is) (hmem : ∀ (i : ) (hi : i < List.length Is), xs[i] Is[i]) (prec : ) (hprec : prec 0 := by norm_num) (i : ) (hi : i < min net.layer2.outputDim net.layer2.bias.length) :
                        (net.forwardReal xs)[i] (net.forwardInterval Is prec)[i]

                        Soundness theorem for two-layer network