Documentation

LeanMlir.Proofs.Certificates.DenseEuclid

The dense Euclidean engine — dense and ReLU layers on EuclideanSpace, and their L2 bounds #

The layers every Lipschitz / interval certificate in Certificates/ is stated about: denseE W (bias-free dense, (Wx)ᵢ) and reluE, with the L2 Lipschitz bounds the product certificate multiplies — Frobenius (denseE_lipschitzL2), the Gram / Schatten-4 bound (denseE_lipschitzL2_gram), Schatten-8 (denseE_lipschitzL2_gram2), and the lower bound a witness vector gives (lipschitzL2_lower_euclid). The upper bounds share one tail (denseE_lipschitzL2_of_sq) and the Gram ones one Cauchy–Schwarz step (sq_le_of_gram_quad, quad_le_of_frob). certified_at_eps specialises the Tsuzuku certificate to a rational radius check. The trained instances are in LipschitzCertInstance; the namespace is theirs, kept so every citation keeps its name.

noncomputable def Proofs.LipschitzCertDemo.denseE {n k : ℕ} (W : Fin k → Fin 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 k → Fin 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.sum_sq_matvec_le {k n : ℕ} (M : Fin k → Fin 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_of_sq {n k : ℕ} (W : Fin k → Fin n → ℝ) {B : ℝ} (hB : 0 ≤ B) (hW : ∀ (d : Fin n → ℝ), ∑ i : Fin k, (∑ j : Fin n, W i j * d j) ^ 2 ≤ B ^ 2 * ∑ j : Fin n, d j ^ 2) :

    The common tail of every dense bound: a raw-sum bound ‖Wd‖² ≤ B²·‖d‖² for every d makes the dense layer B-Lipschitz in L2. The Frobenius and Gram bounds below differ only in how they prove hW.

    theorem Proofs.LipschitzCertDemo.denseE_lipschitzL2 {n k : ℕ} (W : Fin k → Fin 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 C², 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 h → Fin n → ℝ) (W2 : Fin k → Fin 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 ∘ reluE ∘ denseE 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 ≠ i → m ≤ (f x).ofLp i - (f x).ofLp j) (hε : 14143 / 10000 * L * ε ≤ m) (hε0 : 0 ≤ ε) (δ : EuclideanSpace ℝ (Fin n)) (hδ : ‖δ‖ < ε) (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.

      theorem Proofs.LipschitzCertDemo.sum_sq_matTvec_eq {p q : ℕ} (A : Fin p → Fin q → ℝ) (y : Fin p → ℝ) (K : Fin p → Fin 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.quad_le_of_sq_matvec {k : ℕ} (M : Fin k → Fin k → ℝ) (y : Fin k → ℝ) {c : ℝ} (hc : 0 ≤ c) (hM : ∑ a : Fin k, (∑ b : Fin k, M a b * y b) ^ 2 ≤ c ^ 2 * ∑ a : Fin k, y a ^ 2) :
      ∑ a : Fin k, y a * ∑ b : Fin k, M a b * y b ≤ c * ∑ a : Fin k, y a ^ 2

      Cauchy–Schwarz on a quadratic form: ‖My‖² ≤ c²·‖y‖² gives ⟨y, My⟩ ≤ c·‖y‖².

      theorem Proofs.LipschitzCertDemo.quad_le_of_frob {k : ℕ} (M : Fin k → Fin k → ℝ) (y : Fin k → ℝ) {c : ℝ} (hc : 0 ≤ c) (hMF : ∑ a : Fin k, ∑ b : Fin k, M a b ^ 2 ≤ c ^ 2) :
      ∑ a : Fin k, y a * ∑ b : Fin k, M a b * y b ≤ c * ∑ a : Fin k, y a ^ 2

      The Frobenius form of quad_le_of_sq_matvec: ‖M‖_F ≤ c gives ⟨y, My⟩ ≤ c·‖y‖².

      theorem Proofs.LipschitzCertDemo.sq_le_of_gram_quad {n k : ℕ} (W : Fin k → Fin n → ℝ) (G : Fin k → Fin k → ℝ) (hG : ∀ (a b : Fin k), G a b = ∑ j : Fin n, W a j * W b j) (d : Fin n → ℝ) {c : ℝ} (hc : 0 ≤ c) (hq : ∑ a : Fin k, (∑ j : Fin n, W a j * d j) * ∑ b : Fin k, G a b * ∑ j : Fin n, W b j * d j ≤ c * ∑ a : Fin k, (∑ j : Fin n, W a j * d j) ^ 2) :
      ∑ i : Fin k, (∑ j : Fin n, W i j * d j) ^ 2 ≤ c * ∑ j : Fin n, d j ^ 2

      The Gram step: with G = W·Wᵀ and y = Wd, a bound ⟨y, Gy⟩ ≤ c·‖y‖² gives ‖y‖² ≤ c·‖d‖² — because ‖y‖² = ⟨d, Wᵀy⟩ ≤ ‖d‖·‖Wᵀy‖ and ‖Wᵀy‖² = ⟨y, Gy⟩.

      theorem Proofs.LipschitzCertDemo.denseE_lipschitzL2_gram {n k : ℕ} (W : Fin k → Fin n → ℝ) (G : Fin k → Fin 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.denseE_lipschitzL2_gram2 {n k : ℕ} (W : Fin k → Fin n → ℝ) (G H : Fin k → Fin 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 (= 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.

      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‖₂.

      f is certified at radius ε on input x with class i: every perturbation of L2 norm < ε leaves i the strict argmax. The (undecidable — it quantifies over real δ) per-image certificate every scorecard's certifiedC<i> / certifiedU<i> theorems prove.

      Equations
      Instances For