Documentation

CslibFrontier.Foundations.Algebra.DFT

The discrete Fourier transform over a commutative ring #

For an element ω of a commutative ring R, Cslib.dft ω a is the discrete Fourier transform of a vector a : Fin n → R, that is, the evaluation of the polynomial ∑ i, a i X ^ i at the points ω ^ j for j < n ([CLRS09], Section 30.2). Mathlib's ZMod.dft is the complex-valued transform built on ZMod.stdAddChar. Here the ring is arbitrary and the root of unity is explicit, which covers number-theoretic transforms over ZMod p and the rings used in fast integer multiplication.

Main definitions #

Main results #

References #

def Cslib.dft {R : Type u_1} [CommRing R] {n : ℕ} (ω : R) (a : Fin n → R) (j : Fin n) :
R

The discrete Fourier transform of a : Fin n → R with respect to ω: the vector of values ∑ i, a i * ω ^ (i * j) of the polynomial with coefficient vector a at the points ω ^ j.

theorem Cslib.dft_eq_vandermonde_mulVec {R : Type u_1} [CommRing R] {n : ℕ} (ω : R) (a : Fin n → R) :
dft ω a = (Matrix.vandermonde fun (j : Fin n) => ω ^ ↑j).mulVec a

The DFT is multiplication by the Vandermonde matrix of 1, ω, …, ω ^ (n - 1).

@[simp]
theorem Cslib.dft_fin_one {R : Type u_1} [CommRing R] (ω : R) (a : Fin 1 → R) :
dft ω a = a

A transform of length one is the identity.

theorem Cslib.dft_coeff_eq_eval {R : Type u_1} [CommRing R] {n : ℕ} (ω : R) {p : Polynomial R} (hp : p.natDegree < n) (j : Fin n) :
dft ω (fun (i : Fin n) => p.coeff ↑i) j = Polynomial.eval (ω ^ ↑j) p

The DFT of the coefficient vector of a polynomial of degree less than n evaluates the polynomial at the powers of ω.

def Cslib.cyclicConv {R : Type u_1} [CommRing R] {n : ℕ} (a b : Fin n → R) (k : Fin n) :
R

The cyclic convolution of a b : Fin n → R: k ↦ ∑ i, a i * b (k - i), with the index subtraction taken in Fin n, that is, modulo n.

theorem Cslib.dft_cyclicConv {R : Type u_1} [CommRing R] {n : ℕ} {ω : R} (hω : ω ^ n = 1) (a b : Fin n → R) (j : Fin n) :
dft ω (cyclicConv a b) j = dft ω a j * dft ω b j

Convolution theorem (cyclic form, [CLRS09], Theorem 30.8): the DFT turns cyclic convolution into the pointwise product. Only ω ^ n = 1 is needed.

theorem Cslib.dft_dft_neg {R : Type u_1} [CommRing R] {n : ℕ} [NeZero n] {ω : R} (hω : IsPrincipalRoot ω n) (a : Fin n → R) (j : Fin n) :
dft ω (dft ω a) (-j) = ↑n * a j

DFT inversion: for a principal n-th root of unity ω, applying the transform twice and negating the index multiplies by n. When n is a unit, a = n⁻¹ • (dft ω (dft ω a) ∘ Neg.neg).

theorem Cslib.dft_eq_add_of_lt {R : Type u_1} [CommRing R] {n m : ℕ} (hn : n = 2 * m) (ω : R) (a : Fin n → R) (j : Fin n) (hj : ↑j < m) :
dft ω a j = dft (ω ^ 2) (fun (i : Fin m) => a ⟨2 * ↑i, ⋯⟩) ⟨↑j, hj⟩ + ω ^ ↑j * dft (ω ^ 2) (fun (i : Fin m) => a ⟨2 * ↑i + 1, ⋯⟩) ⟨↑j, hj⟩

Cooley–Tukey splitting, lower half. For n = 2 m and j < m, the transform of length n at j combines the length-m transforms of the even and odd parts with respect to ω ^ 2: dft ω a j = E j + ω ^ j * O j.

theorem Cslib.dft_eq_sub_of_le {R : Type u_1} [CommRing R] {n m : ℕ} (hn : n = 2 * m) {ω : R} (hω : ω ^ m = -1) (a : Fin n → R) (j : Fin n) (hj : m ≤ ↑j) :
dft ω a j = dft (ω ^ 2) (fun (i : Fin m) => a ⟨2 * ↑i, ⋯⟩) ⟨↑j - m, ⋯⟩ - ω ^ (↑j - m) * dft (ω ^ 2) (fun (i : Fin m) => a ⟨2 * ↑i + 1, ⋯⟩) ⟨↑j - m, ⋯⟩

Cooley–Tukey splitting, upper half. For n = 2 m, ω ^ m = -1 and m ≤ j, the transform at j is E (j - m) - ω ^ (j - m) * O (j - m).

theorem Cslib.cyclicConv_coeff {R : Type u_1} [CommRing R] {n : ℕ} {p q : Polynomial R} (hpq : p.natDegree + q.natDegree < n) (k : Fin n) :
cyclicConv (fun (i : Fin n) => p.coeff ↑i) (fun (i : Fin n) => q.coeff ↑i) k = (p * q).coeff ↑k

The cyclic convolution of the coefficient vectors of p and q is the coefficient vector of p * q when natDegree p + natDegree q < n, since then no index wraps around.