# Prime-factor FFT algorithm

The prime-factor algorithm (PFA), also called the Good–Thomas algorithm (1958/1963), is a fast Fourier transform (FFT) algorithm that re-expresses the discrete Fourier transform (DFT) of a size N = N$_1$N$_2$ as a two-dimensional N$_1$×N$_2$ DFT, but only for the case where N$_1$ and N$_2$ are relatively prime. These smaller transforms of size N$_1$ and N$_2$ can then be evaluated by applying PFA recursively or by using some other FFT algorithm.
PFA should not be confused with the mixed-radix generalization of the popular Cooley–Tukey algorithm, which also subdivides a DFT of size N = N$_1$N$_2$ into smaller transforms of size N$_1$ and N$_2$. The latter algorithm can use any factors (not necessarily relatively prime), but it has the disadvantage that it also requires extra multiplications by roots of unity called twiddle factors, in addition to the smaller transforms. On the other hand, PFA has the disadvantages that it only works for relatively prime factors (e.g. it is useless for power-of-two sizes) and that it requires more complicated re-indexing of the data based on the additive group isomorphisms. Note, however, that PFA can be combined with mixed-radix Cooley–Tukey, with the former factorizing N into relatively prime components and the latter handling repeated factors.
PFA is also closely related to the nested Winograd FFT algorithm, where the latter performs the decomposed N$_1$ by N$_2$ transform via more sophisticated two-dimensional convolution techniques. Some older papers therefore also call Winograd's algorithm a PFA FFT.
(Although the PFA is distinct from the Cooley–Tukey algorithm, Good's 1958 work on the PFA was cited as inspiration by Cooley and Tukey in their 1965 paper, and there was initially some confusion about whether the two algorithms were different. In fact, it was the only prior FFT work cited by them, as they were not then aware of the earlier research by Gauss and others.)

## Algorithm

Let $a(x)$ be a polynomial and $\omega _{n}$ be a principal $n$-th root of unity. We define the DFT of $a(x)$ as the $n$-tuple $({\hat {a}}_{j})=(a(\omega _{n}^{j}))$. In other words, ${\hat {a}}_{j}=\sum _{i=0}^{n-1}a_{i}\omega _{n}^{ij}\quad {\text{ for all }}j=0,1,\dots ,n-1.$ For simplicity, we denote the transformation as ${\text{DFT}}_{\omega _{n}}$.
The PFA relies on a coprime factorization of n=∏$_{d=0}$$^{D−1}$n$_d${\textstyle n=\prod _{d=0}^{D-1}n_{d}} and turns ${\text{DFT}}_{\omega _{n}}$ into ⨂$_d$DFT$_{ωnd}${\textstyle \bigotimes _{d}{\text{DFT}}_{\omega _{n_{d}}}} for some choices of $\omega _{n_{d}}$'s where ⨂{\textstyle \bigotimes } is the tensor product.

### Mapping Based on CRT

For a coprime factorization n=∏$_{d=0}$$^{D−1}$n$_d${\textstyle n=\prod _{d=0}^{D-1}n_{d}}, we have the Chinese remainder map $m\mapsto (m{\bmod {n}}_{d})$ from $\mathbb {Z} _{n}$ to ∏$_{d=0}$$^{D−1}$Z$_{nd}${\textstyle \prod _{d=0}^{D-1}\mathbb {Z} _{n_{d}}} with (m$_d$)↦∑$_{d=0}$$^{D−1}$e$_d$m$_d${\textstyle (m_{d})\mapsto \sum _{d=0}^{D-1}e_{d}m_{d}} as its inverse where $e_{d}$'s are the central orthogonal idempotent elements with ∑$_{d=0}$$^{D−1}$e$_d$=1(modn){\textstyle \sum _{d=0}^{D-1}e_{d}=1{\pmod {n}}}. Choosing $\omega _{n_{d}}=\omega _{n}^{e_{d}}$ (therefore, ∏$_{d=0}$$^{D−1}$ω$_{nd}$=ω$_n$$^{∑d=0D−1ed}$=ω$_n${\textstyle \prod _{d=0}^{D-1}\omega _{n_{d}}=\omega _{n}^{\sum _{d=0}^{D-1}e_{d}}=\omega _{n}}), we rewrite ${\text{DFT}}_{\omega _{n}}$ as follows: ${\hat {a}}_{j}=\sum _{i=0}^{n-1}a_{i}\omega _{n}^{ij}=\sum _{i=0}^{n-1}a_{i}\left(\prod _{d=0}^{D-1}\omega _{n_{d}}\right)^{ij}=\sum _{i=0}^{n-1}a_{i}\prod _{d=0}^{D-1}\omega _{n_{d}}^{(i{\bmod {n}}_{d})(j{\bmod {n}}_{d})}=\sum _{i_{0}=0}^{n_{0}-1}\cdots \sum _{i_{D-1}=0}^{n_{D-1}-1}a_{\sum _{d=0}^{D-1}e_{d}i_{d}}\prod _{d=0}^{D-1}\omega _{n_{d}}^{i_{d}(j{\bmod {n}}_{d})}.$ Finally, define $a_{i_{0},\dots ,i_{D-1}}=a_{\sum _{d=0}^{D-1}i_{d}e_{d}}$ and ${\hat {a}}_{j_{0},\dots ,j_{D-1}}={\hat {a}}_{\sum _{d=0}^{D-1}j_{d}e_{d}}$, we have ${\hat {a}}_{j_{0},\dots ,j_{D-1}}=\sum _{i_{0}=0}^{n_{0}-1}\cdots \sum _{i_{D-1}=0}^{n_{D-1}-1}a_{i_{0},\dots ,i_{D-1}}\prod _{d=0}^{D-1}\omega _{n_{d}}^{i_{d}j_{d}}.$ Therefore, we have the multi-dimensional DFT, $\otimes _{d=0}^{D-1}{\text{DFT}}_{\omega _{n_{d}}}$.

### As Algebra Isomorphisms

PFA can be stated in a high-level way in terms of algebra isomorphisms. We first recall that for a commutative ring $R$ and a group isomorphism from $G$ to ∏$_d$G$_d${\textstyle \prod _{d}G_{d}}, we have the following algebra isomorphism $R[G]\cong \bigotimes _{d}R[G_{d}]$ where $\bigotimes$ refers to the tensor product of algebras.
To see how PFA works, we choose $G=(\mathbb {Z} _{n},+,0)$ and $G_{d}=(\mathbb {Z} _{n_{d}},+,0)$ be additive groups. We also identify $R[G]$ as R[x]/⟨x$^n$−1⟩ {\textstyle {\frac {R[x]}{\langle x^{n}-1\rangle }}} and $R[G_{d}]$ as R[x$_d$]/⟨x$_d$n$_d$−1⟩ {\textstyle {\frac {R[x_{d}]}{\langle x_{d}^{n_{d}}-1\rangle }}}. Choosing $\eta =a\mapsto (a{\bmod {n}}_{d})$ as the group isomorphism G≅∏$_d$G$_d${\textstyle G\cong \prod _{d}G_{d}}, we have the algebra isomorphism η$^∗$:R[G]≅⨂$_d$R[G$_d$]{\textstyle \eta ^{*}:R[G]\cong \bigotimes _{d}R[G_{d}]}, or alternatively, $\eta ^{*}:{\frac {R[x]}{\langle x^{n}-1\rangle }}\cong \bigotimes _{d}{\frac {R[x_{d}]}{\langle x_{d}^{n_{d}}-1\rangle }}.$ Now observe that ${\text{DFT}}_{\omega _{n}}$ is actually an algebra isomorphism from R[x]/⟨x$^n$−1⟩ {\textstyle {\frac {R[x]}{\langle x^{n}-1\rangle }}} to ∏$_i$ R[x]/⟨x−ω$_n$$^i$⟩ {\textstyle \prod _{i}{\frac {R[x]}{\langle x-\omega _{n}^{i}\rangle }}} and each ${\text{DFT}}_{\omega _{n_{d}}}$ is an algebra isomorphism from R[x]/⟨x$_d$n$_d$−1⟩ {\textstyle {\frac {R[x]}{\langle {x_{d}}^{n_{d}}-1\rangle }}} to ∏$_{id}$ R[x$_d$]/⟨x$_d$−ω$_{nd}$$^{id}$⟩ {\textstyle \prod _{i_{d}}{\frac {R[x_{d}]}{\langle x_{d}-\omega _{n_{d}}^{i_{d}}\rangle }}}, we have an algebra isomorphism $\eta '$ from ⨂$_d$∏$_{id}$ R[x$_d$]/⟨x$_d$−ω$_{nd}$$^{id}$⟩ {\textstyle \bigotimes _{d}\prod _{i_{d}}{\frac {R[x_{d}]}{\langle x_{d}-\omega _{n_{d}}^{i_{d}}\rangle }}} to ∏$_i$ R[x]/⟨x−ω$_n$$^i$⟩ {\textstyle \prod _{i}{\frac {R[x]}{\langle x-\omega _{n}^{i}\rangle }}}. What PFA tells us is that DFT$_{ωn}$=η$^′$∘⨂$_d$DFT$_{ωnd}$∘η$^∗${\textstyle {\text{DFT}}_{\omega _{n}}=\eta '\circ \bigotimes _{d}{\text{DFT}}_{\omega _{n_{d}}}\circ \eta ^{*}} where $\eta ^{*}$ and $\eta '$ are re-indexing without actual arithmetic in $R$.

### Counting the Number of Multi-Dimensional Transformations

Notice that the condition for transforming ${\text{DFT}}_{\omega _{n}}$ into η$^′$∘⨂$_d$DFT$_{ωnd}$∘η$^∗${\textstyle \eta '\circ \bigotimes _{d}{\text{DFT}}_{\omega _{n_{d}}}\circ \eta ^{*}} relies on "an" additive group isomorphism $\eta$ from $(\mathbb {Z} _{n},+,0)$ to ∏$_d$(Z$_{nd}$, +, 0){\textstyle \prod _{d}(\mathbb {Z} _{n_{d}}, +, 0)}. Any additive group isomorphism will work. To count the number of ways transforming ${\text{DFT}}_{\omega _{n}}$ into η$^′$∘⨂$_d$DFT$_{ωnd}$∘η$^∗${\textstyle \eta '\circ \bigotimes _{d}{\text{DFT}}_{\omega _{n_{d}}}\circ \eta ^{*}}, we only need to count the number of additive group isomorphisms from $(\mathbb {Z} _{n},+,0)$ to ∏$_d$(Z$_{nd}$, +, 0){\textstyle \prod _{d}(\mathbb {Z} _{n_{d}}, +, 0)}, or alternative, the number of additive group automorphisms on $(\mathbb {Z} _{n},+,0)$. Since $(\mathbb {Z} _{n},+,0)$ is cyclic, any automorphism can be written as $1\mapsto g$ where $g$ is a generator of $(\mathbb {Z} _{n},+,0)$. By the definition of $(\mathbb {Z} _{n},+,0)$, $g$'s are exactly those coprime to $n$. Therefore, there are exactly $\varphi (n)$ many such maps where $\varphi$ is the Euler's totient function. The smallest example is $n=6$ where $\varphi (n)=2$, demonstrating the two maps in the literature: the "CRT mapping" and the "Ruritanian mapping".