FLINT3.7.0-dev
Algorithm

Discrete Fourier transforms over a generic ring

Cost
O(nlog⁡n)O(n \log n) ring operations for every nn over rings with roots of unity of all orders (Bluestein for prime factors above 19); otherwise O(n∑ipi)O(n \sum_i p_i) for n=∏ipin = \prod_i p_i, using direct kernels for the prime factors.

The module gr_dft computes the discrete Fourier transform

Xk=∑j=0n−1xjwjk,0≤k<n,X_k = \sum_{j=0}^{n-1} x_j w^{jk}, \qquad 0 \le k < n,

of a vector x∈Rnx \in R^n over an arbitrary commutative ring RR, given an element w∈Rw \in R with wn=1w^n = 1. Unlike the transforms of fft_small and fft, which are specialised to particular rings and lengths, it works with any length and only uses the ring operations of gr, so the same code serves complex balls, exact algebraic numbers, Z/mZ\mathbb{Z}/m\mathbb{Z}, finite fields and fixed-point numbers. The classical references are the survey of Duhamel and Vetterli [DV1990] and the book of Nussbaumer [Nus1982]; transforms over general rings are treated by von zur Gathen and Gerhard [GG2003, §8.2], Pollard [Pol1971] and Bernstein [Ber2001].

Roots of unity in a ring#

Over C\mathbb{C} the fast algorithms use identities of the roots of unity such as wn/2=−1w^{n/2} = -1 and 1+v+⋯+vp−1=01 + v + \cdots + v^{p-1} = 0 for a root vv of order pp. In a general ring these identities do not follow from ww having order nn, because the ring can have zero divisors.

Definition 1. An element w∈Rw \in R is a principal nn-th root of unity if wn=1w^n = 1 and wk−1w^k - 1 is not a zero divisor for 1≤k<n1 \le k < n.

Lemma 2. ww is a principal nn-th root of unity if and only if wn=1w^n = 1 and wn/p−1w^{n/p} - 1 is not a zero divisor for every prime p∣np \mid n. If RR is an integral domain, this holds if and only if ww has order exactly nn.

Proof. One direction is clear. Conversely, let 1≤k<n1 \le k < n and d=gcd⁡(k,n)d = \gcd(k, n), a proper divisor of nn, so d∣n/pd \mid n/p for some prime p∣np \mid n. If a=bca = bc in RR and aa is not a zero divisor, then neither is bb, since bx=0bx = 0 implies ax=0ax = 0. Now wd−1w^d - 1 divides wn/p−1w^{n/p} - 1, so it is not a zero divisor. Choose u≥1u \ge 1 with uk≡d(modn)uk \equiv d \pmod n; then wd−1=wuk−1w^d - 1 = w^{uk} - 1 is a multiple of wk−1w^k - 1, which is therefore not a zero divisor either. In an integral domain the nonzero elements are exactly the non-zero-divisors.

Over Z/mZ\mathbb{Z}/m\mathbb{Z} the lemma says that ww must have order exactly nn modulo every prime factor of mm. Over Z/pZ\mathbb{Z}/p\mathbb{Z} with pp prime, such roots exist exactly when n∣p−1n \mid p - 1.

Lemma 3 (Orthogonality). If ww is a principal nn-th root of unity and k≢0(modn)k \not\equiv 0 \pmod n, then ∑j=0n−1wjk=0\sum_{j=0}^{n-1} w^{jk} = 0. For every prime p∣np \mid n, the element v=wn/pv = w^{n/p} is a principal pp-th root of unity, so 1+v+⋯+vp−1=01 + v + \cdots + v^{p-1} = 0; in particular wn/2=−1w^{n/2} = -1 if nn is even.

Proof. Let S=∑jwjkS = \sum_j w^{jk} with 0<k<n0 < k < n. Then (wk−1)S=wnk−1=0(w^k - 1) S = w^{nk} - 1 = 0, and wk−1w^k - 1 is not a zero divisor, so S=0S = 0. For 1≤k<p1 \le k < p, vk−1=wkn/p−1v^k - 1 = w^{kn/p} - 1 with kn/p<nkn/p < n, so vv is principal, and the first part applies to vv with k=1k = 1.

Theorem 4 (Inversion). If ww is a principal nn-th root of unity, then so is w−1=wn−1w^{-1} = w^{n-1}, and applying the transform with w−1w^{-1} to the transform of xx with ww gives nxn x.

Proof. The first claim follows from the definition, since w−k−1=−w−k(wk−1)w^{-k} - 1 = -w^{-k}(w^k - 1). The composition maps xx to ∑kw−jk∑lxlwlk=∑lxl∑kw(l−j)k\sum_k w^{-jk} \sum_l x_l w^{lk} = \sum_l x_l \sum_k w^{(l - j)k}, and by Lemma 3 the inner sum is nn for l=jl = j and 0 otherwise.

The inverse transform of gr_dft is therefore the transform with w−1w^{-1} followed by a division by nn, and it fails with GR_DOMAIN when the ring cannot divide by nn. The same computation shows that the transform maps cyclic convolution to pointwise multiplication.

The algorithms below need less than principality to compute the forward transform as defined. Their derivations use only the following identities:

AlgorithmIdentities used
naive, prime factorwn=1w^n = 1
radix-2, split-radix, four-stepwn/2=−1w^{n/2} = -1
mixed-radix, direct kernel for the prime ppwn=1w^n = 1 and 1+v+⋯+vp−1=01 + v + \cdots + v^{p-1} = 0 for v=wn/pv = w^{n/p}
Bluesteinwn=1w^n = 1 and nn odd; division by NN and a principal root of order N=2k≥2n−1N = 2^k \ge 2n - 1

The prime factor algorithm passes the roots wn2w^{n_2} and wn1w^{n_1} to its sub-plans, which need their own identities. For n=2dn = 2^d, the condition wn/2=−1w^{n/2} = -1 already implies orthogonality: for k=2sk′k = 2^s k' with k′k' odd and s<ds < d, the terms jj and j+n/2s+1j + n/2^{s+1} of ∑jwjk\sum_j w^{jk} cancel, because wkn/2s+1=(wn/2)k′=−1w^{k n / 2^{s+1}} = (w^{n/2})^{k'} = -1. So for powers of two wn/2=−1w^{n/2} = -1 is all that is needed.

gr_dft_precomp_init_root checks wn/2=−1w^{n/2} = -1 for even nn and wn/p≠1w^{n/p} \ne 1 for odd primes p∣np \mid n, as far as the ring can decide them with gr_is_neg_one and gr_is_one. The second check is necessary but not sufficient: over a ring with zero divisors, wn/p≠1w^{n/p} \ne 1 does not imply 1+v+⋯+vp−1=01 + v + \cdots + v^{p-1} = 0, and the mixed-radix kernel then returns a wrong result without an error. Example: a root that is not principal gives an example modulo 91.

The naive algorithm#

GR_DFT_ALG_NAIVE evaluates the definition, accumulating xjwjk mod nx_j w^{jk \bmod n} with the exponent updated incrementally. It performs n(n−1)n(n-1) calls to the root multiplication (those with exponent 0 are copies), is correct for any ww with wn=1w^n = 1, and serves as the reference in the tests. For powers of two it also supports the bit-reversed order of GR_DFT_SCRAMBLED.

Radix-2 Cooley–Tukey#

For n=2dn = 2^d, splitting the input into halves (decimation in frequency, [GS1966]) gives

X2k=∑j<n/2(xj+xj+n/2)(w2)jk,X2k+1=∑j<n/2(xj−xj+n/2)wj(w2)jk,X_{2k} = \sum_{j < n/2} (x_j + x_{j + n/2}) (w^2)^{jk}, \qquad X_{2k+1} = \sum_{j < n/2} (x_j - x_{j + n/2}) w^j (w^2)^{jk},

because w(j+n/2)⋅2k=w2jkw^{(j + n/2) \cdot 2k} = w^{2jk} and w(j+n/2)(2k+1)=−wj(2k+1)w^{(j + n/2)(2k + 1)} = -w^{j(2k+1)} by wn=1w^n = 1 and wn/2=−1w^{n/2} = -1. Since (w2)n/4=wn/2=−1(w^2)^{n/4} = w^{n/2} = -1, the two halves are transforms of the same kind with root w2w^2, and induction gives the algorithm of Cooley and Tukey [CT1965].

Algorithm 1: Radix-2 decimation in frequency

Input: x0,…,xn−1x_0, \ldots, x_{n-1} with n=2dn = 2^d, and ww with wn/2=−1w^{n/2} = -1.

Output: Xrev(k)X_{\mathrm{rev}(k)} in position kk, where rev\mathrm{rev} reverses the dd bits of kk.

  1. For s=d,d−1,…,1s = d, d - 1, \ldots, 1, with m=2sm = 2^s and r=n/mr = n/m: for each block [b,b+m)[b, b + m) with b≡0(modm)b \equiv 0 \pmod m and each 0≤j<m/20 \le j < m/2, replace (xb+j,xb+j+m/2)(x_{b+j}, x_{b+j+m/2}) by (xb+j+xb+j+m/2, wjr(xb+j−xb+j+m/2))(x_{b+j} + x_{b+j+m/2},\ w^{jr}(x_{b+j} - x_{b+j+m/2})).
  2. Return xx.

The forward transform of gr_dft uses Algorithm 1 followed by a bit-reversal permutation, which GR_DFT_SCRAMBLED skips. The inverse transform runs the transposed algorithm (decimation in time, (a,b)↦(a+w−jrb,a−w−jrb)(a, b) \mapsto (a + w^{-jr} b, a - w^{-jr} b) for s=1,…,ds = 1, \ldots, d) on bit-reversed input, so a scrambled forward transform followed by a scrambled inverse transform gives nn times the identity without any permutation. There are n2d\frac{n}{2} d butterflies, each with one multiplication by a root; those with j=0j = 0 need none, and in complex mode those with jr∈{n/8,n/4,3n/8}jr \in \{n/8, n/4, 3n/8\} are cheap (Complex mode). The integer FFTs of fft (The ring) and fft_small (FFTs modulo word-size primes in floating point) are built on the same recursion, specialised to their rings, and truncate it so that only the needed values are computed (Truncated FFTs).

Split-radix#

The split-radix algorithm of Yavne [Yav1968] and Duhamel and Hollmann [DH1984] splits a transform of length mm with root vv into one transform UU of length m/2m/2 (the even entries) and two transforms ZZ, Z′Z' of length m/4m/4 (the entries ≡1\equiv 1 and ≡3(mod4)\equiv 3 \pmod 4). With t=vkZkt = v^k Z_k, t′=v3kZk′t' = v^{3k} Z'_k and ι=vm/4\iota = v^{m/4},

Xk=Uk+(t+t′),Xk+m/2=Uk−(t+t′),Xk+m/4=Uk+m/4+ι(t−t′),Xk+3m/4=Uk+m/4−ι(t−t′),X_k = U_k + (t + t'), \quad X_{k + m/2} = U_k - (t + t'), \quad X_{k + m/4} = U_{k + m/4} + \iota (t - t'), \quad X_{k + 3m/4} = U_{k + m/4} - \iota (t - t'),

for 0≤k<m/40 \le k < m/4, which again uses only vm/2=−1v^{m/2} = -1. Each step costs two multiplications by general roots per kk plus one by ι\iota, which plays the role of −i-i and is free in complex mode. The total is about n3log⁡2n\frac{n}{3} \log_2 n general multiplications instead of n2log⁡2n\frac{n}{2} \log_2 n. In complex mode, with three real multiplications per general root and two per eighth root, it uses nlog⁡2n−3n+4n \log_2 n - 3n + 4 real multiplications, which is minimal for n≤16n \le 16 [Win1978] and close to the lower bound of Heideman and Burrus [HB1986] for larger nn. Later variants reduce the number of additions further [JF2007]; they are not used. gr_dft computes split-radix recursively, out of place, in natural order.

The four-step algorithm#

For n=n1n2n = n_1 n_2 with n1=2⌊d/2⌋n_1 = 2^{\lfloor d/2 \rfloor}, Bailey's four-step algorithm [Bai1990] writes j=j1+n1j2j = j_1 + n_1 j_2, k=k2+n2k1k = k_2 + n_2 k_1 and

Xk2+n2k1=∑j1(wn2)j1k1 wj1k2∑j2xj1+n1j2(wn1)j2k2,X_{k_2 + n_2 k_1} = \sum_{j_1} (w^{n_2})^{j_1 k_1}\, w^{j_1 k_2} \sum_{j_2} x_{j_1 + n_1 j_2} (w^{n_1})^{j_2 k_2},

which gives n1n_1 transforms of length n2n_2, nn twiddle multiplications by wj1k2w^{j_1 k_2}, n2n_2 transforms of length n1n_1 (all radix-2 sub-plans) and a transposition, which GR_DFT_SCRAMBLED skips. The method and its variants are described in The matrix Fourier algorithm. In gr_dft it is available as GR_DFT_ALG_BAILEY but not chosen automatically.

Mixed-radix Cooley–Tukey#

For a transform of length ℓ=pm\ell = pm with pp prime and root uu, split the input into its pp residue classes modulo pp and let YbY_b be the transform of length mm, with root upu^p, of the class bb. Then

Xq+mr=∑b=0p−1vbr(ubqYb(q)),v=um, 0≤q<m, 0≤r<p,X_{q + m r} = \sum_{b=0}^{p-1} v^{br} \bigl(u^{bq} Y_b(q)\bigr), \qquad v = u^m,\ 0 \le q < m,\ 0 \le r < p,

so after twiddling by ubqu^{bq}, each qq requires a transform of prime length pp with root vv. GR_DFT_ALG_MIXED applies this recursively, one prime factor of nn per level, with all exponents taken in the root table of the top-level plan. The transforms of prime length use the following kernel.

Lemma 5 (Direct prime kernel). Let pp be prime, vp=1v^p = 1 and 1+v+⋯+vp−1=01 + v + \cdots + v^{p-1} = 0. For 0<r<p0 < r < p let b∗b^* be the index with b∗r≡p−1(modp)b^* r \equiv p - 1 \pmod p and eb=br mod pe_b = br \bmod p. Then

∑b=0p−1vbrzb=(z0−zb∗)+∑b≠0, b∗veb(zb−zb∗).\sum_{b=0}^{p-1} v^{br} z_b = (z_0 - z_{b^*}) + \sum_{b \ne 0,\, b^*} v^{e_b} (z_b - z_{b^*}).

Proof. As bb runs over 0,…,p−10, \ldots, p-1, so does ebe_b, hence ∑bveb=0\sum_b v^{e_b} = 0, and subtracting zb∗∑bvebz_{b^*} \sum_b v^{e_b} from the left side changes nothing. The term b=0b = 0 has e0=0e_0 = 0, and the term b=b∗b = b^* vanishes.

The output for r=0r = 0 is ∑bzb\sum_b z_b, so the kernel takes (p−1)(p−2)(p-1)(p-2) multiplications instead of (p−1)2(p-1)^2. For p=3p = 3, for example, X1=(x0−x2)+v(x1−x2)X_1 = (x_0 - x_2) + v(x_1 - x_2) and X2=(x0−x1)+v(x2−x1)X_2 = (x_0 - x_1) + v(x_2 - x_1). With the (p−1)(p - 1) twiddles per kernel, a transform of length pep^e costs at most e pe−1(p−1)2e\, p^{e-1} (p-1)^2 multiplications, which is O(nlog⁡n)O(n \log n) only for bounded pp. For n=pen = p^e with p>19p > 19, the transforms of length pp use Bluestein's algorithm instead when it is available.

The prime factor algorithm#

If n=n1n2n = n_1 n_2 with gcd⁡(n1,n2)=1\gcd(n_1, n_2) = 1, the Chinese remainder theorem removes the twiddle factors altogether. This is the algorithm of Good [Goo1958] and Thomas [Tho1963].

Theorem 6 (Good–Thomas). Let n=n1n2n = n_1 n_2 with gcd⁡(n1,n2)=1\gcd(n_1, n_2) = 1 and wn=1w^n = 1. Let a,ba, b be the integers in [0,n)[0, n) with a≡1(modn1)a \equiv 1 \pmod{n_1}, a≡0(modn2)a \equiv 0 \pmod{n_2}, b≡0(modn1)b \equiv 0 \pmod{n_1} and b≡1(modn2)b \equiv 1 \pmod{n_2}. Then for all k1<n1k_1 < n_1 and k2<n2k_2 < n_2,

X(ak1+bk2) mod n=∑j1<n1∑j2<n2x(n2j1+n1j2) mod n (wn2)j1k1(wn1)j2k2,X_{(a k_1 + b k_2) \bmod n} = \sum_{j_1 < n_1} \sum_{j_2 < n_2} x_{(n_2 j_1 + n_1 j_2) \bmod n}\, (w^{n_2})^{j_1 k_1} (w^{n_1})^{j_2 k_2},

and both index maps are bijections between [0,n1)×[0,n2)[0, n_1) \times [0, n_2) and [0,n)[0, n).

Proof. The maps are bijections by the Chinese remainder theorem, since n2j1+n1j2≡n2j1(modn1)n_2 j_1 + n_1 j_2 \equiv n_2 j_1 \pmod{n_1} and n2n_2 is invertible modulo n1n_1, and symmetrically. Let k=ak1+bk2k = a k_1 + b k_2, so that k≡k1(modn1)k \equiv k_1 \pmod{n_1} and k≡k2(modn2)k \equiv k_2 \pmod{n_2}. Then w(n2j1+n1j2)k=(wn2)j1k(wn1)j2kw^{(n_2 j_1 + n_1 j_2) k} = (w^{n_2})^{j_1 k} (w^{n_1})^{j_2 k}, and since (wn2)n1=wn=1(w^{n_2})^{n_1} = w^n = 1 the exponent j1kj_1 k can be reduced modulo n1n_1 to j1k1j_1 k_1, and likewise j2kj_2 k to j2k2j_2 k_2.

The right side is a two-dimensional transform: n1n_1 transforms of length n2n_2 with root wn1w^{n_1} followed by n2n_2 transforms of length n1n_1 with root wn2w^{n_2}, with a gather before and a scatter after but no multiplications in between. If ww is principal, so are wn2w^{n_2} and wn1w^{n_1}, since (wn2)n1/p−1=wn/p−1(w^{n_2})^{n_1/p} - 1 = w^{n/p} - 1. GR_DFT_ALG_PFA takes n1n_1 to be the full power of the smallest prime factor of nn and plans n2n_2 automatically, so a general length is reduced to its prime power factors. With the default root, its sub-plans build their own tables and the plan itself stores none.

Bluestein's algorithm#

Bluestein's algorithm [Blu1970], also known as the chirp z-transform [RSR1969], reduces a transform of any odd length nn to a cyclic convolution, which can then be computed with transforms of a convenient length.

Theorem 7. Let nn be odd, wn=1w^n = 1 and t=(n+1)/2t = (n + 1)/2. With cj=wtj2c_j = w^{t j^2} and hj=w−tj2h_j = w^{-t j^2},

Xk=ck∑j=0n−1(cjxj) h(k−j) mod n,X_k = c_k \sum_{j=0}^{n-1} (c_j x_j)\, h_{(k - j) \bmod n},

and hh is even and nn-periodic: h−j=hj=hj+nh_{-j} = h_j = h_{j+n}.

Proof. Since 2t=n+1≡1(modn)2t = n + 1 \equiv 1 \pmod n, jk≡t⋅2jk=t(j2+k2−(k−j)2)(modn)jk \equiv t \cdot 2jk = t(j^2 + k^2 - (k - j)^2) \pmod n, and wn=1w^n = 1 gives wjk=cjckhk−jw^{jk} = c_j c_k h_{k-j}. Periodicity holds because (j+n)2≡j2(modn)(j + n)^2 \equiv j^2 \pmod n.

The cyclic convolution of length nn is embedded in one of length N=2⌈log⁡2(2n−1)⌉N = 2^{\lceil \log_2(2n - 1) \rceil}: the vector (cjxj)(c_j x_j) is padded with zeros, and the kernel is hj′=hjh'_j = h_j for 0≤j<n0 \le j < n, hN−j′=hjh'_{N - j} = h_j for 1≤j<n1 \le j < n and 0 otherwise. Because N≥2n−1N \ge 2n - 1 the two parts do not overlap, and for 0≤k<n0 \le k < n the cyclic convolution of length NN agrees with that of length nn by the evenness of hh.

Algorithm 2: Bluestein

Precomputation: a radix-2 plan of length NN with a principal root of order NN, in scrambled order, and h^=1NDFTN(h′)\hat h = \frac{1}{N} \mathrm{DFT}_N(h').

  1. zj←cjxjz_j \gets c_j x_j for j<nj < n, and zj←0z_j \gets 0 for n≤j<Nn \le j < N.
  2. Z←DFTN(z)Z \gets \mathrm{DFT}_N(z), in scrambled order.
  3. Zk←Zkh^kZ_k \gets Z_k \hat h_k for k<Nk < N.
  4. y←y \gets the unscaled inverse transform of ZZ, from scrambled order.
  5. Return Xk=ckykX_k = c_k y_k for k<nk < n.

The chirps cjc_j and hjh_j are entries of the root table of ww, and h^\hat h is in the same scrambled order as ZZ, so no permutation is needed. The inverse transform of length nn is computed as the forward transform of x(n−j) mod nx_{(n - j) \bmod n}, since ∑jxjw−jk=∑jx(n−j) mod nwjk\sum_j x_j w^{-jk} = \sum_j x_{(n-j) \bmod n} w^{jk}. The cost is 2n2n chirp multiplications, NN pointwise products and two transforms of length N<4nN < 4n; the precomputation costs one more transform. The convolution needs a root of order NN, unrelated to ww, which gr_dft obtains from gr_dft_default_root. Over rings without default roots, such as Z/mZ\mathbb{Z}/m\mathbb{Z} (even when mm has roots of order NN), the algorithm is therefore not available, and mixed-radix plans fall back to the direct kernel. Over the fixed-point contexts the kernel is scaled by 1/(2N)1/(2N) instead of 1/N1/N to keep the intermediate values below 1, and the outputs are doubled at the end.

Remark 8. Rader's algorithm [Rad1968] reduces a transform of prime length pp to a cyclic convolution of length p−1p - 1 by means of a primitive root modulo pp, and Winograd's algorithm [Win1978] combines it with short convolution algorithms. gr_dft uses neither: Bluestein's convolution length is always a power of two, which suits the radix-2 transforms.

Products of cyclic groups and Dirichlet characters#

The DFT on Z/c0Z×⋯×Z/cr−1Z\mathbb{Z}/c_0\mathbb{Z} \times \cdots \times \mathbb{Z}/c_{r-1}\mathbb{Z}, Xk=∑jxj∏awajakaX_k = \sum_j x_j \prod_a w_a^{j_a k_a} with waw_a a principal cac_a-th root of unity, factors over the axes. It is computed by transforming all lines along each axis in turn with a cyclic plan of length cac_a, with no twiddle factors, in ∑a(n/ca)C(ca)\sum_a (n / c_a) C(c_a) operations for n=∏can = \prod c_a, where C(m)C(m) is the cost of a transform of length mm. Plans are shared between axes of equal length, and the inverse divides by nn once. By Theorem 6, a cyclic transform of coprime length n1n2n_1 n_2 is a product transform up to permutations of the input and the output.

The group of Dirichlet characters modulo qq is isomorphic to (Z/qZ)×(\mathbb{Z}/q\mathbb{Z})^\times, which the Conrey decomposition writes as a product of cyclic groups with generators of orders φk\varphi_k. If xx has logarithms bkb_k and the character χa\chi_a is indexed by the logarithms aka_k of aa, then χa(x)=∏ke2πiakbk/φk\chi_a(x) = \prod_k e^{2\pi i a_k b_k / \varphi_k}, and the transform v^a=∑xχa(x)‾vx\hat v_a = \sum_x \overline{\chi_a(x)} v_x is the product transform over the φk\varphi_k in the lexicographic order of the logarithms. gr_dft_dirichlet adds the permutation between this order and the order of the residues xx.

Complex mode#

When the ring is C=R[i]C = R[i] with elements stored as pairs of elements of RR and w=e−2πi/nw = e^{-2\pi i/n}, multiplications by roots can be specialised from the exponent alone, without inspecting values (which over balls could not prove that a computed value is exactly −i-i):

  • wjn/4∈{1,−i,−1,i}w^{jn/4} \in \{1, -i, -1, i\}: swaps and negations of the parts;
  • wjn/8w^{jn/8} for odd jj equals c(1±i)c(1 \pm i) with c=±2/2c = \pm\sqrt{2}/2, so that, for example, c(1+i)(x+iy)=c(x−y)+i c(x+y)c(1 + i)(x + iy) = c(x - y) + i\, c(x + y) takes two real multiplications;
  • for a general root c+dic + di, the product with x+iyx + iy is k1−y(d+c)+i (k1+x(d−c))k_1 - y(d + c) + i\,(k_1 + x(d - c)) with k1=c(x+y)k_1 = c(x + y): three real multiplications and three additions with the precomputed cc, d−cd - c and d+cd + c, instead of four multiplications and two additions. This form is attributed to Gauss [Knu1997, §4.6.4].

The last trick pays when multiplications in RR are expensive compared to additions, so gr_dft uses it over exact rings and when the real precision is at least 1024 bits; below that, a native complex multiplication is faster. In fixed point the entries d±cd \pm c can reach 2\sqrt 2 and do not fit the representation, so complex products use the schoolbook formula below 22 limbs and a carry-extended three-product variant from 22 limbs.

Error handling#

The algorithms only call gr operations and combine their status codes with |. Over exact rings the forward transforms cannot fail, but the division by nn of the inverse can, with GR_DOMAIN, as can the division by NN in the Bluestein precomputation. Over inexact rings the root checks may be inconclusive (T_UNKNOWN), in which case the root is accepted. Over the fixed-point contexts, an overflow during a transform returns GR_UNABLE; Rigorous numerical DFTs in fixed point shows how to scale the input so that this cannot happen and bounds the rounding errors.

Summary#

AlgorithmLengthsMultiplications by rootsConditions
naiveany(n−1)2(n - 1)^2 nontrivialwn=1w^n = 1
radix-22d2^dn2d\frac{n}{2} dwn/2=−1w^{n/2} = -1
split-radix2d2^d, d≥2d \ge 2about n3d\frac{n}{3} d general oneswn/2=−1w^{n/2} = -1
four-step2d2^d, d≥2d \ge 2radix-2 counts plus nnwn/2=−1w^{n/2} = -1
mixed-radixany n≥2n \ge 2∑levelsn(pi−1)2/pi\sum_{\text{levels}} n (p_i - 1)^2 / p_i∑i<pvi=0\sum_{i<p} v^i = 0 for v=wn/pv = w^{n/p} and each prime p∣np \mid n
prime factor≥2\ge 2 distinct primesthose of the sub-plansthose of the sub-plans
Bluesteinodd n≥3n \ge 3O(Nlog⁡N)O(N \log N) with 2n−1≤N<4n2n - 1 \le N < 4ndefault root of order NN; division by NN

Referenced from#

References#

  • [DV1990] P. Duhamel and M. Vetterli. Fast Fourier transforms: a tutorial review and a state of the art. Signal Processing 19:4 (1990), 259–299. https://doi.org/10.1016/0165-1684(90)90158-U
  • [Nus1982] H. J. Nussbaumer. Fast Fourier Transform and Convolution Algorithms, second edition. Springer, 1982. https://doi.org/10.1007/978-3-642-81897-4
  • [GG2003] J. von zur Gathen and J. Gerhard, Modern Computer Algebra, second edition, Cambridge University Press (2003)
  • [Pol1971] J. M. Pollard. The fast Fourier transform in a finite field. Mathematics of Computation 25 (1971), 365–374.
  • [Ber2001] D. J. Bernstein. Multidigit multiplication for mathematicians. Preprint, 2001, https://cr.yp.to/papers/m3.pdf
  • [GS1966] W. M. Gentleman and G. Sande. Fast Fourier transforms – for fun and profit. AFIPS Fall Joint Computer Conference 29 (1966), 563–578.
  • [CT1965] J. W. Cooley and J. W. Tukey. An algorithm for the machine calculation of complex Fourier series. Mathematics of Computation 19 (1965), 297–301.
  • [Yav1968] R. Yavne. An economical method for calculating the discrete Fourier transform. AFIPS Fall Joint Computer Conference (1968), 115–125. https://doi.org/10.1145/1476589.1476610
  • [DH1984] P. Duhamel and H. Hollmann. Split radix FFT algorithm. Electronics Letters 20:1 (1984), 14–16. https://doi.org/10.1049/el:19840012
  • [Win1978] S. Winograd. On computing the discrete Fourier transform. Mathematics of Computation 32 (1978), 175–199. https://doi.org/10.1090/S0025-5718-1978-0468306-4
  • [HB1986] M. T. Heideman and C. S. Burrus. On the number of multiplications necessary to compute a length-2n2^n DFT. IEEE Transactions on Acoustics, Speech, and Signal Processing 34:1 (1986), 91–95. https://doi.org/10.1109/TASSP.1986.1164785
  • [JF2007] S. G. Johnson and M. Frigo. A modified split-radix FFT with fewer arithmetic operations. IEEE Transactions on Signal Processing 55:1 (2007), 111–119. https://doi.org/10.1109/TSP.2006.882087
  • [Bai1990] D. H. Bailey. FFTs in external or hierarchical memory. The Journal of Supercomputing 4 (1990), 23–35.
  • [Goo1958] I. J. Good. The interaction algorithm and practical Fourier analysis. Journal of the Royal Statistical Society, Series B 20:2 (1958), 361–372.
  • [Tho1963] L. H. Thomas. Using a computer to solve problems in physics. In Applications of Digital Computers, Ginn, Boston, 1963, 44–45.
  • [Blu1970] L. I. Bluestein. A linear filtering approach to the computation of discrete Fourier transform. IEEE Transactions on Audio and Electroacoustics 18:4 (1970), 451–455. https://doi.org/10.1109/TAU.1970.1162132
  • [RSR1969] L. R. Rabiner, R. W. Schafer and C. M. Rader. The chirp z-transform algorithm. IEEE Transactions on Audio and Electroacoustics 17:2 (1969), 86–92. https://doi.org/10.1109/TAU.1969.1162034
  • [Rad1968] C. M. Rader. Discrete Fourier transforms when the number of data samples is prime. Proceedings of the IEEE 56:6 (1968), 1107–1108. https://doi.org/10.1109/PROC.1968.6477
  • [Knu1997] Knuth, D. E. The Art of Computer Programming, volume 2: Seminumerical algorithms, 1997
Cite this page

The FLINT team, “Discrete Fourier transforms over a generic ring,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/fft/dft-algorithms.html (generated 2026-11-02).