Discrete Fourier transforms over a generic ring
- Cost
- ring operations for every over rings with roots of unity of all orders (Bluestein for prime factors above 19); otherwise for , using direct kernels for the prime factors.
The module gr_dft computes the discrete Fourier transform
of a vector over an arbitrary commutative ring , given an element with . 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, , 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 the fast algorithms use identities of the roots of unity such as and for a root of order . In a general ring these identities do not follow from having order , because the ring can have zero divisors.
Definition 1. An element is a principal -th root of unity if and is not a zero divisor for .
Lemma 2. is a principal -th root of unity if and only if and is not a zero divisor for every prime . If is an integral domain, this holds if and only if has order exactly .
Proof. One direction is clear. Conversely, let and , a proper divisor of , so for some prime . If in and is not a zero divisor, then neither is , since implies . Now divides , so it is not a zero divisor. Choose with ; then is a multiple of , which is therefore not a zero divisor either. In an integral domain the nonzero elements are exactly the non-zero-divisors.
Over the lemma says that must have order exactly modulo every prime factor of . Over with prime, such roots exist exactly when .
Lemma 3 (Orthogonality). If is a principal -th root of unity and , then . For every prime , the element is a principal -th root of unity, so ; in particular if is even.
Proof. Let with . Then , and is not a zero divisor, so . For , with , so is principal, and the first part applies to with .
Theorem 4 (Inversion). If is a principal -th root of unity, then so is , and applying the transform with to the transform of with gives .
Proof. The first claim follows from the definition, since . The composition maps to , and by Lemma 3 the inner sum is for and 0 otherwise.
The inverse transform of gr_dft is therefore the transform with followed by a division by , and it fails with GR_DOMAIN when the ring cannot divide by . 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:
| Algorithm | Identities used |
|---|---|
| naive, prime factor | |
| radix-2, split-radix, four-step | |
| mixed-radix, direct kernel for the prime | and for |
| Bluestein | and odd; division by and a principal root of order |
The prime factor algorithm passes the roots and to its sub-plans, which need their own identities. For , the condition already implies orthogonality: for with odd and , the terms and of cancel, because . So for powers of two is all that is needed.
gr_dft_precomp_init_root checks for even and for odd primes , 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, does not imply , 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 with the exponent updated incrementally. It performs calls to the root multiplication (those with exponent 0 are copies), is correct for any with , 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 , splitting the input into halves (decimation in frequency, [GS1966]) gives
because and by and . Since , the two halves are transforms of the same kind with root , and induction gives the algorithm of Cooley and Tukey [CT1965].
Input: with , and with .
Output: in position , where reverses the bits of .
- For , with and : for each block with and each , replace by .
- Return .
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, for ) on bit-reversed input, so a scrambled forward transform followed by a scrambled inverse transform gives times the identity without any permutation. There are butterflies, each with one multiplication by a root; those with need none, and in complex mode those with 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 with root into one transform of length (the even entries) and two transforms , of length (the entries and ). With , and ,
for , which again uses only . Each step costs two multiplications by general roots per plus one by , which plays the role of and is free in complex mode. The total is about general multiplications instead of . In complex mode, with three real multiplications per general root and two per eighth root, it uses real multiplications, which is minimal for [Win1978] and close to the lower bound of Heideman and Burrus [HB1986] for larger . 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 with , Bailey's four-step algorithm [Bai1990] writes , and
which gives transforms of length , twiddle multiplications by , transforms of length (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 with prime and root , split the input into its residue classes modulo and let be the transform of length , with root , of the class . Then
so after twiddling by , each requires a transform of prime length with root . GR_DFT_ALG_MIXED applies this recursively, one prime factor of 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 be prime, and . For let be the index with and . Then
Proof. As runs over , so does , hence , and subtracting from the left side changes nothing. The term has , and the term vanishes.
The output for is , so the kernel takes multiplications instead of . For , for example, and . With the twiddles per kernel, a transform of length costs at most multiplications, which is only for bounded . For with , the transforms of length use Bluestein's algorithm instead when it is available.
The prime factor algorithm#
If with , the Chinese remainder theorem removes the twiddle factors altogether. This is the algorithm of Good [Goo1958] and Thomas [Tho1963].
Theorem 6 (Good–Thomas). Let with and . Let be the integers in with , , and . Then for all and ,
and both index maps are bijections between and .
Proof. The maps are bijections by the Chinese remainder theorem, since and is invertible modulo , and symmetrically. Let , so that and . Then , and since the exponent can be reduced modulo to , and likewise to .
The right side is a two-dimensional transform: transforms of length with root followed by transforms of length with root , with a gather before and a scatter after but no multiplications in between. If is principal, so are and , since . GR_DFT_ALG_PFA takes to be the full power of the smallest prime factor of and plans 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 to a cyclic convolution, which can then be computed with transforms of a convenient length.
Theorem 7. Let be odd, and . With and ,
and is even and -periodic: .
Proof. Since , , and gives . Periodicity holds because .
The cyclic convolution of length is embedded in one of length : the vector is padded with zeros, and the kernel is for , for and 0 otherwise. Because the two parts do not overlap, and for the cyclic convolution of length agrees with that of length by the evenness of .
Precomputation: a radix-2 plan of length with a principal root of order , in scrambled order, and .
- for , and for .
- , in scrambled order.
- for .
- the unscaled inverse transform of , from scrambled order.
- Return for .
The chirps and are entries of the root table of , and is in the same scrambled order as , so no permutation is needed. The inverse transform of length is computed as the forward transform of , since . The cost is chirp multiplications, pointwise products and two transforms of length ; the precomputation costs one more transform. The convolution needs a root of order , unrelated to , which gr_dft obtains from gr_dft_default_root. Over rings without default roots, such as (even when has roots of order ), 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 instead of 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 to a cyclic convolution of length by means of a primitive root modulo , 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 , with a principal -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 , with no twiddle factors, in operations for , where is the cost of a transform of length . Plans are shared between axes of equal length, and the inverse divides by once. By Theorem 6, a cyclic transform of coprime length is a product transform up to permutations of the input and the output.
The group of Dirichlet characters modulo is isomorphic to , which the Conrey decomposition writes as a product of cyclic groups with generators of orders . If has logarithms and the character is indexed by the logarithms of , then , and the transform is the product transform over the in the lexicographic order of the logarithms. gr_dft_dirichlet adds the permutation between this order and the order of the residues .
Complex mode#
When the ring is with elements stored as pairs of elements of and , 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 ):
- : swaps and negations of the parts;
- for odd equals with , so that, for example, takes two real multiplications;
- for a general root , the product with is with : three real multiplications and three additions with the precomputed , and , instead of four multiplications and two additions. This form is attributed to Gauss [Knu1997, §4.6.4].
The last trick pays when multiplications in 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 can reach 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 of the inverse can, with GR_DOMAIN, as can the division by 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#
| Algorithm | Lengths | Multiplications by roots | Conditions |
|---|---|---|---|
| naive | any | nontrivial | |
| radix-2 | |||
| split-radix | , | about general ones | |
| four-step | , | radix-2 counts plus | |
| mixed-radix | any | for and each prime | |
| prime factor | distinct primes | those of the sub-plans | those of the sub-plans |
| Bluestein | odd | with | default root of order ; division by |
Referenced from#
- acb_dft.h (module)
- Rigorous numerical DFTs in fixed point (algorithm)
- The matrix Fourier algorithm (algorithm)
- Schönhage–Strassen multiplication (algorithm)
- Truncated FFTs (algorithm)
- gr_dft.h (module)
- Algorithms, complex mode and threads
- Constructing plans
- Multidimensional transforms
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- 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
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).
@misc{flint-doc-algorithms-fft-dft-algorithms,
author = {{The FLINT team}},
title = {{Discrete Fourier transforms over a generic ring}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/fft/dft-algorithms.html},
note = {Generated 2026-11-02}
}