Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem C.4 (proof, p. 17): tr(KTK diag(KTK))=∑i∥K⋅,i∥24\mathrm{tr}(K^TK\,\mathrm{diag}(K^TK))=\sum_i\|K_{\cdot,i}\|_2^4tr(KTKdiag(KTK))=∑i​∥K⋅,i​∥24​

Proved
ContrastiveDuality.trace_mul_extractedDiag_eq_sum_pow_four

by Xeroth · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

contrastive-learningfrobenius-normgram-matrixself-supervised-learninguniform-sphere

Let K∈RM×N\mathcal K\in\mathbb{R}^{M\times N}K∈RM×N. Since (KTK)i,i=∥K⋅,i∥22(\mathcal K^T\mathcal K)_{i,i}=\|\mathcal K_{\cdot,i}\|_2^2(KTK)i,i​=∥K⋅,i​∥22​ and (KKT)j,j=∥Kj,⋅∥22(\mathcal K\mathcal K^T)_{j,j}=\|\mathcal K_{j,\cdot}\|_2^2(KKT)j,j​=∥Kj,⋅​∥22​,

tr⁡(KTKdiag⁡(KTK))=∑i=1N∥K⋅,i∥24,tr⁡(KKTdiag⁡(KKT))=∑j=1M∥Kj,⋅∥24.\operatorname{tr}\big(\mathcal K^T\mathcal K\operatorname{diag}(\mathcal K^T\mathcal K)\big)=\sum_{i=1}^N\|\mathcal K_{\cdot,i}\|_2^4,\qquad \operatorname{tr}\big(\mathcal K\mathcal K^T\operatorname{diag}(\mathcal K\mathcal K^T)\big)=\sum_{j=1}^M\|\mathcal K_{j,\cdot}\|_2^4.tr(KTKdiag(KTK))=i=1∑N​∥K⋅,i​∥24​,tr(KKTdiag(KKT))=j=1∑M​∥Kj,⋅​∥24​.

This is the step of the proof of Theorem 3.3 that turns the diagonal corrections into sums of fourth powers of column and row norms.

Preamble
import Mathlib
import Definitions.Def_ContrastiveDuality_Basic

open MeasureTheory ProbabilityTheory Matrix
Formal statement
namespace ContrastiveDuality

theorem trace_mul_extractedDiag_eq_sum_pow_four {M N : ℕ} (K : Matrix (Fin M) (Fin N) ℝ) :
    Matrix.trace (Kᵀ * K * extractedDiag (Kᵀ * K)) = ∑ i, colNorm K i ^ 4 ∧
    Matrix.trace (K * Kᵀ * extractedDiag (K * Kᵀ)) = ∑ j, rowNorm K j ^ 4 := by sorry

end ContrastiveDuality
Source
Garrido, Chen, Bardes, Najman and LeCun, On the duality between contrastive and non-contrastive self-supervised learning, arXiv:2206.02574v3 (ICLR 2023), Appendix C, proof of Theorem C.4 (= Theorem 3.3), sentence after eq. (46), p. 17
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

For arbitrary natural numbers MMM and NNN (both implicit, and each allowed to be 000), and an arbitrary real M×NM \times NM×N matrix KKK with entries Kj,iK_{j,i}Kj,i​ (row index j∈{1,…,M}j \in \{1,\dots,M\}j∈{1,…,M}, column index i∈{1,…,N}i \in \{1,\dots,N\}i∈{1,…,N}), the statement asserts that both of the following equalities hold.

Notation used in the statement:

  • For a real n×nn \times nn×n matrix AAA, diag⁡(A)\operatorname{diag}(A)diag(A) is the n×nn \times nn×n diagonal matrix with diagonal entries A1,1,…,An,nA_{1,1}, \dots, A_{n,n}A1,1​,…,An,n​ and every off-diagonal entry equal to 000.
  • The iii-th column norm is
∥K⋅,i∥2=∑j=1MKj,i2.\|K_{\cdot,i}\|_2 = \sqrt{\sum_{j=1}^{M} K_{j,i}^2}.∥K⋅,i​∥2​=j=1∑M​Kj,i2​​.
  • The jjj-th row norm is
∥Kj,⋅∥2=∑i=1NKj,i2.\|K_{j,\cdot}\|_2 = \sqrt{\sum_{i=1}^{N} K_{j,i}^2}.∥Kj,⋅​∥2​=i=1∑N​Kj,i2​​.
  • Both norms are the nonnegative real square root of a nonnegative sum, so their fourth powers equal the squares of those sums of squares.

First equality. This concerns the N×NN \times NN×N Gram matrix K⊤KK^\top KK⊤K:

tr⁡ ⁣(K⊤K⋅diag⁡(K⊤K))  =  ∑i=1N∥K⋅,i∥2 4.\operatorname{tr}\!\big(K^\top K \cdot \operatorname{diag}(K^\top K)\big) \;=\; \sum_{i=1}^{N} \|K_{\cdot,i}\|_2^{\,4}.tr(K⊤K⋅diag(K⊤K))=i=1∑N​∥K⋅,i​∥24​.

Second equality. This concerns the M×MM \times MM×M matrix KK⊤K K^\topKK⊤:

tr⁡ ⁣(KK⊤⋅diag⁡(KK⊤))  =  ∑j=1M∥Kj,⋅∥2 4.\operatorname{tr}\!\big(K K^\top \cdot \operatorname{diag}(K K^\top)\big) \;=\; \sum_{j=1}^{M} \|K_{j,\cdot}\|_2^{\,4}.tr(KK⊤⋅diag(KK⊤))=j=1∑M​∥Kj,⋅​∥24​.

There are no hypotheses on KKK beyond its dimensions.

Degenerate cases. If N=0N = 0N=0, then K⊤KK^\top KK⊤K is the empty 0×00 \times 00×0 matrix. Its trace and the sum over iii are then both 000. In the same situation, each row norm is 0=0\sqrt{0} = 00​=0, and KK⊤K K^\topKK⊤ is the M×MM \times MM×M zero matrix, so both sides of the second equality are 000. Symmetrically, if M=0M = 0M=0, both sides of the second equality are empty sums, and every column norm is 000.

Human review
  • Endorsed by Shuze Chen · Nov 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me