TorchLean API

NN.Proofs.Analysis.Fft

Discrete Fourier Transform (DFT) theorems over mathlib #

TorchLean’s runtime FFT building blocks (NN.Runtime.Autograd.TorchLean.Fft) implement FFT/IFFT by explicit DFT matrices. This file proves the corresponding exact math facts over mathlib’s complex numbers :

We prove these statements in the mathlib Matrix world first. That choice is deliberate: primitive roots of unity, conjugate transposes, geometric sums, and matrix inverse facts already live cleanly in mathlib for .

The TorchLean runtime FFT code uses shape-indexed tensors and scalar-polymorphic twiddle factors written with cos/sin. Connecting that runtime representation to these exact matrices is a separate transport theorem in NN.Proofs.Analysis.FftBridge. Keeping the files split avoids making the pure DFT algebra import the runtime/autograd stack.

References:

DFT / IDFT matrices #

noncomputable def Proofs.Fft.ζ (n : ) :

Primitive n-th root of unity: ζₙ = exp(2π i / n).

Instances For
    noncomputable def Proofs.Fft.ω (n : ) :

    The “negative-frequency” root used by the DFT: ωₙ = ζₙ⁻¹ = exp(-2π i / n).

    Instances For
      noncomputable def Proofs.Fft.dftMatrix (n : ) :
      Matrix (Fin n) (Fin n)

      DFT matrix F : n×n (frequency × spatial), with entries:

      F[k,j] = ωₙ^(j*k).

      This matches the usual exp(-2π i j*k/n) convention (since ωₙ = exp(-2π i / n)).

      Instances For
        noncomputable def Proofs.Fft.idftMatrix (n : ) :
        Matrix (Fin n) (Fin n)

        Inverse DFT matrix F⁻¹ : n×n (spatial × frequency), with entries:

        F⁻¹[j,k] = ζₙ^(j*k) / n.

        This matches the classical inverse scaling 1/n.

        Instances For

          Inversion theorem #

          The proof follows the textbook orthogonality argument. The (i,k) entry of IDFT * DFT is

          (1/n) * ∑ j, (ζ^i * (ζ^k)⁻¹)^j.

          If i = k, the ratio is 1 and the sum is n. If i ≠ k, the ratio is a nontrivial n-th root of unity, so the geometric sum is 0.

          theorem Proofs.Fft.idft_mul_dft (n : ) (hn : n 0) :

          Main algebraic identity: IDFT * DFT = 1 (over ), for n ≠ 0.

          This is the standard DFT inversion theorem.

          Orthogonality / unitary form #

          On , the inverse DFT matrix is a scaled conjugate transpose of the DFT matrix:

          F⁻¹ = (1/n) • Fᴴ.

          Orthogonality identity (unitary form): Fᴴ * F = n • 1.

          Equivalently, the DFT columns form an orthogonal basis with squared norm n.

          theorem Proofs.Fft.dft_mul_idft (n : ) (hn : n 0) :

          Right-inverse form: DFT * IDFT = 1 (for n ≠ 0).

          Vector form #

          noncomputable def Proofs.Fft.dft (n : ) (x : Fin n) :
          Fin n

          DFT as a linear operator on Fin n → ℂ.

          Instances For
            noncomputable def Proofs.Fft.idft (n : ) (x : Fin n) :
            Fin n

            Inverse DFT as a linear operator on Fin n → ℂ.

            Instances For
              theorem Proofs.Fft.idft_dft (n : ) (hn : n 0) (x : Fin n) :
              idft n (dft n x) = x

              Vector inversion theorem: idft (dft x) = x, for n ≠ 0.

              theorem Proofs.Fft.dft_idft (n : ) (hn : n 0) (x : Fin n) :
              dft n (idft n x) = x

              Vector inversion theorem (other direction): dft (idft x) = x, for n ≠ 0.