Documentation

LeanMlir.Proofs.Certificates.LipschitzCertInstance

A concrete instantiation of the Lipschitz-margin certified radius #

REDUCED CERTIFICATE MODEL — this file's concrete net is the 4×4-pooled 49-dim MNIST family (width-8 hidden, /128–/256 rational weights), NOT the canonical 784→512→512→10 mlpVerified; chosen so every margin/norm/SOS check is exact rational arithmetic in-kernel. Canonical surface: Proofs/MlpCanonical.lean.

Closes the "certificate machinery, never instantiated" gap: a fixed-weight network whose Lipschitz constant is PROVED in Lean (Frobenius bound — no power iteration, no hypothesis), whose margin at a concrete input is computed in-kernel, and whose certified radius is provably positive.

Two instances:

noncomputable def Proofs.LipschitzCertDemo.denseE {n k : } (W : Fin kFin n) :

A bias-free dense (linear) layer on Euclidean space: (denseE W x)ᵢ = Σⱼ Wᵢⱼ xⱼ.

Equations
Instances For
    @[simp]
    theorem Proofs.LipschitzCertDemo.denseE_apply {n k : } (W : Fin kFin n) (x : EuclideanSpace (Fin n)) (i : Fin k) :
    (denseE W x).ofLp i = j : Fin n, W i j * x.ofLp j
    theorem Proofs.LipschitzCertDemo.denseE_lipschitzL2 {n k : } (W : Fin kFin n) {C : } (hC : 0 C) (hW : i : Fin k, j : Fin n, W i j ^ 2 C ^ 2) :

    Frobenius bound, proved. If the entrywise square sum of W is at most , the dense layer is C-Lipschitz in L2. This is the certified replacement for the power-iteration estimate specNormW: ‖W‖₂ ≤ ‖W‖_F, so any rational C ≥ ‖W‖_F is a sound Lipschitz constant.

    Coordinatewise ReLU on Euclidean space.

    Equations
    Instances For
      @[simp]
      theorem Proofs.LipschitzCertDemo.reluE_apply {n : } (x : EuclideanSpace (Fin n)) (i : Fin n) :
      (reluE x).ofLp i = max (x.ofLp i) 0
      theorem Proofs.LipschitzCertDemo.mlp_out_eq {n h k : } (W1 : Fin hFin n) (W2 : Fin kFin h) {x : EuclideanSpace (Fin n)} {pre : Fin h} (hpre : ∀ (t : Fin h), (denseE W1 x).ofLp t = pre t) (j : Fin k) :
      ((denseE W2 reluE denseE W1) x).ofLp j = t : Fin h, W2 j t * max (pre t) 0

      A one-hidden-layer net's logits from its hidden pre-activations. Given the exact pre-activations pre of x, each logit of denseE W2 ∘ reluEdenseE W1 is the finite sum the per-image margin and argmax proofs expand; every generated scorecard reads its logits through this.

      √2 ≤ 14143/10000 — the rational majorant the per-image radius checks use.

      theorem Proofs.LipschitzCertDemo.certified_at_eps {n k : } {L m ε : } {f : EuclideanSpace (Fin n)EuclideanSpace (Fin k)} (hf : LipschitzL2 L f) (hL : 0 < L) {x : EuclideanSpace (Fin n)} {i : Fin k} (hmargin : ∀ (j : Fin k), j im (f x).ofLp i - (f x).ofLp j) ( : 14143 / 10000 * L * ε m) (hε0 : 0 ε) (δ : EuclideanSpace (Fin n)) ( : δ < ε) (j : Fin k) :
      j i(f (x + δ)).ofLp j < (f (x + δ)).ofLp i

      Specialize the Tsuzuku certificate to a FIXED radius ε: if the margin clears the rational check (14143/10000)·L·ε ≤ m (kernel-checkable — no √2), every ‖δ‖ < ε leaves class i the strict argmax.

      ReLU is 1-Lipschitz in L2 — coordinatewise |max(a,0) − max(b,0)| ≤ |a − b| summed. The activation contributes factor 1 to the product certificate.

      Fixed 2×2 weight matrix: logits (3x₀, 4x₁). Frobenius norm exactly 5.

      Equations
      Instances For

        The concrete input x = e₀.

        Equations
        Instances For

          Margin computed in-kernel: logits at xlin are (3, 0), so class 0 leads by 3.

          The certified radius is strictly positive — the certificate is non-vacuous. Numerically 3/(√2·5) ≈ 0.424.

          theorem Proofs.LipschitzCertDemo.linear_demo_certified (δ : EuclideanSpace (Fin 2)) ( : δ < 3 / (2 * 5)) (j : Fin 2) :
          j 0(denseE Wlin (xlin + δ)).ofLp j < (denseE Wlin (xlin + δ)).ofLp 0

          The instantiated Tsuzuku certificate (linear). Every L2 perturbation of norm < 3/(√2·5) of the concrete input leaves class 0 the strict argmax of the concrete network x ↦ (3x₀, 4x₁).

          Hidden layer: identity mixing (Frobenius √2 ≤ 2).

          Equations
          Instances For

            Output layer: (2h₀, h₁) (Frobenius √5 ≤ 3).

            Equations
            Instances For

              The per-layer product certificate L = 3·(1·2) = 6, assembled by LipschitzL2.comp from proved Frobenius bounds — the certified analogue of the ∏ᵢ‖Wᵢ‖₂ product the PGD demos compute numerically.

              theorem Proofs.LipschitzCertDemo.mlp_margin (j : Fin 2) :
              j 02 (mlp xlin).ofLp 0 - (mlp xlin).ofLp j

              Margin computed in-kernel through the whole MLP: forward of e₀ is (1,0) ↦ relu (1,0) = (1,0) ↦ (2,0), so class 0 leads by 2.

              theorem Proofs.LipschitzCertDemo.mlp_demo_certified (δ : EuclideanSpace (Fin 2)) ( : δ < 2 / (2 * 6)) (j : Fin 2) :
              j 0(mlp (xlin + δ)).ofLp j < (mlp (xlin + δ)).ofLp 0

              The instantiated Tsuzuku certificate (MLP). Every L2 perturbation of norm < 2/(√2·6) ≈ 0.236 leaves class 0 the strict argmax of the concrete dense→ReLU→dense network — kink and all: the certificate is architecture-agnostic, no smoothness hypotheses needed.

              noncomputable def Proofs.LipschitzCertDemo.W1t :
              Fin 8Fin 49

              Trained hidden-layer weights (8×49), entries k/128.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                noncomputable def Proofs.LipschitzCertDemo.W2t :
                Fin 10Fin 8

                Trained output-layer weights (10×8), entries k/128.

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

                  MNIST test image #1895 (digit 2), 4×4-average-pooled: exact pixel sums over 4080 (= 255·16).

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    noncomputable def Proofs.LipschitzCertDemo.hpreVals :
                    Fin 8

                    Exact hidden pre-activations of xt (denominator 128·4080).

                    Equations
                    Instances For

                      Frobenius² of W1t is ≤ C₁² for C₁ = 2911/200 ≈ ‖W1t‖_F.

                      Product certificate for the trained net: L = C₂·(1·C₁) = 2651921/12500.

                      theorem Proofs.LipschitzCertDemo.xt_margin (j : Fin 10) :
                      j 26953 / 500 (mlpT xt).ofLp 2 - (mlpT xt).ofLp j

                      In-kernel margin: class 2 leads every other class at xt by ≥ 6953/500.

                      theorem Proofs.LipschitzCertDemo.trained_radius_pos :
                      0 < 6953 / 500 / (2 * (2651921 / 12500))
                      theorem Proofs.LipschitzCertDemo.trained_demo_certified (δ : EuclideanSpace (Fin 49)) ( : δ < 6953 / 500 / (2 * (2651921 / 12500))) (j : Fin 10) :
                      j 2(mlpT (xt + δ)).ofLp j < (mlpT (xt + δ)).ofLp 2

                      The Tsuzuku certificate at TRAINED weights. Every L2 perturbation of the pooled MNIST digit-2 with ‖δ‖ < 13.906/(√2·212.154) ≈ 0.0463 leaves class 2 the strict argmax of the trained, rationalized network.

                      theorem Proofs.LipschitzCertDemo.sum_sq_matvec_le {k n : } (M : Fin kFin n) (y : Fin n) :
                      a : Fin k, (∑ b : Fin n, M a b * y b) ^ 2 (∑ a : Fin k, b : Fin n, M a b ^ 2) * b : Fin n, y b ^ 2

                      Row-wise Cauchy–Schwarz summed: ‖Mv‖² ≤ ‖M‖_F²·‖v‖² at the raw-sum level.

                      theorem Proofs.LipschitzCertDemo.denseE_lipschitzL2_gram {n k : } (W : Fin kFin n) (G : Fin kFin k) {B : } (hB : 0 B) (hG : ∀ (a b : Fin k), G a b = j : Fin n, W a j * W b j) (hGF : a : Fin k, b : Fin k, G a b ^ 2 B ^ 4) :

                      Gram (Schatten-4) bound, proved. If G = W·Wᵀ (supplied as data, verified entrywise) and ‖G‖_F² ≤ B⁴, then the dense layer is B-Lipschitz in L2. Since ‖G‖_F = (Σᵢσᵢ⁴)^½, this is ‖W‖₂ ≤ (Σσᵢ⁴)^¼ — strictly tighter than Frobenius (Σσᵢ²)^½ whenever the spectrum has any spread. The Gram matrix is only k×k (output-side), so the kernel arithmetic stays small even for wide layers.

                      theorem Proofs.LipschitzCertDemo.lipschitzL2_lower_euclid {n k : } {L : } {f : EuclideanSpace (Fin n)EuclideanSpace (Fin k)} (hf : LipschitzL2 L f) (hℓ : 0 ) (u w : EuclideanSpace (Fin n)) (hpos : 0 < j : Fin n, (u - w).ofLp j ^ 2) (hray : ^ 2 * j : Fin n, (u - w).ofLp j ^ 2 i : Fin k, (f u - f w).ofLp i ^ 2) :
                      L

                      Certified lower bound on any L2 Lipschitz constant (the power-iteration direction): if ‖f u − f w‖ ≥ ℓ·‖u − w‖ at one concrete pair (verified as a squared-sum inequality in-kernel), then every valid L satisfies ℓ ≤ L. With u the (rationalized) power-iteration singular vector and w = 0, this certifies how close a proven upper bound sits to the true ‖W‖₂.

                      noncomputable def Proofs.LipschitzCertDemo.G1t :
                      Fin 8Fin 8

                      Exact Gram matrix G1t = W1t·W1tᵀ (8×8, denominators 128² = 16384).

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        noncomputable def Proofs.LipschitzCertDemo.G2t :
                        Fin 10Fin 10

                        Exact Gram matrix G2t = W2t·W2tᵀ (10×10).

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem Proofs.LipschitzCertDemo.G1t_eq (a b : Fin 8) :
                          G1t a b = j : Fin 49, W1t a j * W1t b j
                          theorem Proofs.LipschitzCertDemo.G2t_eq (a b : Fin 10) :
                          G2t a b = j : Fin 8, W2t a j * W2t b j

                          Schatten-4 Lipschitz bound for the hidden layer: B₁ = 46/5 ≈ (Σσ⁴)^(1/4).

                          The tightened product certificate: L = B₂·(1·B₁) = 222203/2500.

                          theorem Proofs.LipschitzCertDemo.trained_radius_gram_pos :
                          0 < 6953 / 500 / (2 * (222203 / 2500))
                          theorem Proofs.LipschitzCertDemo.trained_demo_certified_gram (δ : EuclideanSpace (Fin 49)) ( : δ < 6953 / 500 / (2 * (222203 / 2500))) (j : Fin 10) :
                          j 2(mlpT (xt + δ)).ofLp j < (mlpT (xt + δ)).ofLp 2

                          The tightened trained certificate. Same trained net, same margin, the Gram bound in place of Frobenius: every ‖δ‖ < 13.906/(√2·88.88) ≈ 0.1106 (2.4× the Frobenius radius) leaves the prediction fixed.

                          Rationalized power-iteration vector for W1t (top right-singular direction ×1000).

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

                            Rationalized power-iteration vector for W2t.

                            Equations
                            Instances For

                              Certified lower bound: ANY L with LipschitzL2 L (denseE W1t) is ≥ 1863/250. With W1t_lip_gram : LipschitzL2 9.2 …, the true ‖W1t‖₂ is sandwiched in [7.452, 9.2] — the Gram bound is provably ≤ 1.235× optimal.

                              theorem Proofs.LipschitzCertDemo.sum_sq_matTvec_eq {p q : } (A : Fin pFin q) (y : Fin p) (K : Fin pFin p) (hK : ∀ (a b : Fin p), K a b = j : Fin q, A a j * A b j) :
                              j : Fin q, (∑ i : Fin p, A i j * y i) ^ 2 = a : Fin p, y a * b : Fin p, K a b * y b

                              Sum-shuffle: ‖Aᵀy‖² = ⟨y, K y⟩ for K = A·Aᵀ supplied as data. The rearrangement engine both Gram bounds share.

                              theorem Proofs.LipschitzCertDemo.denseE_lipschitzL2_gram2 {n k : } (W : Fin kFin n) (G H : Fin kFin k) {B : } (hB : 0 B) (hG : ∀ (a b : Fin k), G a b = j : Fin n, W a j * W b j) (hH : ∀ (a b : Fin k), H a b = c : Fin k, G c a * G c b) (hHF : a : Fin k, b : Fin k, H a b ^ 2 B ^ 8) :

                              Iterated Gram (Schatten-8) bound, proved. One more squaring: with G = W·Wᵀ and H = Gᵀ·G (= for the symmetric G) supplied as data, ‖H‖_F² ≤ B⁸ gives LipschitzL2 B (denseE W) — i.e. ‖W‖₂ ≤ ‖G²‖_F^(1/4) = (Σσᵢ⁸)^(1/8), one Cauchy–Schwarz level tighter than the Schatten-4 bound.

                              noncomputable def Proofs.LipschitzCertDemo.H1t :
                              Fin 8Fin 8

                              H1t = G1t² (= G1tᵀ·G1t, 8×8, denominators 16384² = 268435456).

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                noncomputable def Proofs.LipschitzCertDemo.H2t :
                                Fin 10Fin 10
                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  theorem Proofs.LipschitzCertDemo.H1t_eq (a b : Fin 8) :
                                  H1t a b = c : Fin 8, G1t c a * G1t c b
                                  theorem Proofs.LipschitzCertDemo.H2t_eq (a b : Fin 10) :
                                  H2t a b = c : Fin 10, G2t c a * G2t c b

                                  Schatten-8 bound: B₁' = 7769/1000 ≈ (Σσ⁸)^(1/8) (true σ₁ ≈ 7.4525).

                                  Schatten-8 product certificate: L = B₂'·(1·B₁') = 63791259/1000000 ≈ 63.79 — vs the certified lower bounds ℓ₁·ℓ₂ = 57.38, provably within 11.2% of the per-layer-optimal product.

                                  theorem Proofs.LipschitzCertDemo.trained_radius_gram2_pos :
                                  0 < 6953 / 500 / (2 * (63791259 / 1000000))
                                  theorem Proofs.LipschitzCertDemo.trained_demo_certified_gram2 (δ : EuclideanSpace (Fin 49)) ( : δ < 6953 / 500 / (2 * (63791259 / 1000000))) (j : Fin 10) :
                                  j 2(mlpT (xt + δ)).ofLp j < (mlpT (xt + δ)).ofLp 2

                                  Schatten-8 trained certificate: radius ≈ 0.1541 (3.3× Frobenius, 1.4× Schatten-4; the true-σ ceiling for the product method is 0.171).