Radix-2 Cooley–Tukey FFT recursion
DefinitionFastFourierTransform_fftThe radix-2 Cooley–Tukey fast Fourier transform on sample points, as a recursion on the exponent :
where transforms the even-indexed subsequence and the odd-indexed one, and is the twiddle factor of the merge stage. The definition is purely algorithmic: it never mentions the DFT. The index is an arbitrary natural number and the sub-transforms are evaluated at the reduced index .
import Mathlib
namespace FastFourierTransform
/-- The radix-2 Cooley–Tukey fast Fourier transform on `2 ^ p` sample points.
`fft 0 x` is the constant map `x 0`; `fft (p + 1) x k` combines the transforms of the
even-indexed and odd-indexed subsequences with the twiddle factor
`exp (-2 π i k / 2 ^ (p + 1))`. -/
noncomputable def fft : ℕ → (ℕ → ℂ) → ℕ → ℂ
| 0, x, _ => x 0
| (p + 1), x, k =>
fft p (fun m => x (2 * m)) (k % 2 ^ p)
+ Complex.exp (-(2 * (Real.pi : ℂ) * Complex.I * (k : ℂ) / ((2 : ℂ) ^ (p + 1))))
* fft p (fun m => x (2 * m + 1)) (k % 2 ^ p)
end FastFourierTransform
Read-back
What the Lean code literally says, in plain math · Aristotle (Harmonic)
Provenance note (please read first). This read-back is not blind and is not independent testimony. It was written by the same agent that drafted the Lean statement it describes, with full knowledge of the intended meaning, of the source material, and of the mission's pitch. It therefore cannot serve the purpose an independent auditor's read-back serves — catching a gap between what the author meant and what the code says — and no reviewer should treat it as independent corroboration.
This declaration introduces, by recursion on a natural number , a function that takes , a function from the natural numbers to the complex numbers, and a natural number , and returns a complex number, written below.
The two clauses are:
Here is the subsequence of even-indexed samples and the subsequence of odd-indexed samples; is the remainder of the natural number on division by ; is the real constant pi regarded as a complex number; is regarded as a complex number; and in the exponent is the complex number raised to the natural-number power .
Points worth making explicit. The base clause ignores entirely: for the output is the constant function with value . The recursion is on only, and at each step the two recursive calls are evaluated at the reduced index , while the exponential factor uses the unreduced . The definition refers to no discrete Fourier transform and no sum over samples; it is purely this recursion. The function is total, and the index is an arbitrary natural number, unrestricted by . The value depends only on the values of at , since each unfolding halves the index range.