Multiplying two polynomials from their coefficients is the familiar O(n²)convolution — every coefficient times every coefficient. But there’s a second way to describe a polynomial: by its values at enough points. In that value form, multiplying two polynomials is trivially O(n) — just multiply the values pointwise. The catch is converting between the two forms. The Fast Fourier Transform does exactly that conversion in O(n log n), by evaluating at cleverly chosen points — the complex roots of unity — using divide-and-conquer. So the whole multiply becomes: FFT both, multiply pointwise, inverse-FFT back — and convolution drops from O(n²) to O(n log n). Run the pipeline.
O(n log n) polynomial multiply & convolution · coeff ⇄ value form via roots of unity
coefficient form
A polynomial as its list of coefficients [a₀, a₁, …]. Multiply = O(n²) convolution.
value form
A polynomial as its values at n points. Multiply = O(n) pointwise.
roots of unity
The special evaluation points that make the transform recursive and fast.
FFT / inverse FFT
Convert coefficients → values (FFT) and back (inverse FFT), each O(n log n).
fft.js — evaluate, multiply, interpolate
Ready
Multiplying two polynomials A and B. The slow way is O(n²) convolution. FFT’s way: convert both to value form, multiply pointwise (O(n)), then convert back. Step through the pipeline.
1/4
stage
8
FFT size
O(n log n)
vs O(n²)
How it works
Two facts combine. First, a polynomial of degree < n is uniquely determined by its values at any n distinct points — so you can represent it either by coefficients or by a value table, and multiplying in value form is just multiplying the tables entry by entry. Second, if you choose the evaluation points to be the n-th roots of unity (evenly spaced complex numbers on the unit circle), the evaluation has a beautiful recursive structure: a size-n transform splits into two size-n/2 transforms on the even-indexed and odd-indexed coefficients, combined with a “butterfly” step. That divide-and-conquer gives O(n log n). The inverse transform is almost identical (conjugate roots and divide by n), so you convert back just as fast. Net: pad to a power of two, FFT both polynomials, multiply the value tables pointwise, inverse-FFT, and read off the product coefficients.
1
Pad to a power of two
To hold the product of degrees d₁ and d₂, use size n ≥ d₁+d₂+1 rounded up to a power of two. Pad both coefficient arrays with zeros to length n.
2
FFT both — go to value form
Evaluate each polynomial at the n roots of unity via the FFT’s divide-and-conquer. Each is now a table of n complex values, computed in O(n log n).
3
Multiply pointwise
Multiply the two value tables entry by entry — O(n). This is the value-form product of the two polynomials.
✓
Inverse FFT — back to coefficients
Run the inverse FFT on the product table (conjugate roots, divide by n) to recover the product’s coefficients — again O(n log n). Round to integers for integer inputs.
Multiply
O(n log n)
Naive
O(n²)
Value-form mult
O(n)
Points
roots of unity
The code
# multiply two polynomials via FFT, O(n log n)def multiply(A, B):
n = next_pow2(len(A) + len(B) - 1)
fa = fft(pad(A, n)) # coefficients -> values, O(n log n)
fb = fft(pad(B, n))
fc = [fa[i] * fb[i] for i in range(n)] # pointwise multiply, O(n)
c = ifft(fc) # values -> coefficients, O(n log n)return [round(x.real) for x in c[:len(A)+len(B)-1]]
# fft splits even/odd coefficients and recurses on the roots of unity
Quick check
1. Why is multiplying polynomials in value form fast?
If both polynomials are sampled at the same points, their product’s value at each point is just the product of their two values there. So value-form multiplication is O(n) pointwise, versus O(n²) to convolve coefficients.
2. What does the FFT actually compute?
The FFT evaluates a polynomial at the n roots of unity — converting coefficients to values — in O(n log n) via divide-and-conquer. The inverse FFT converts back. The multiply itself happens pointwise in between.
3. Why choose the roots of unity as the evaluation points?
The n-th roots of unity have a recursive relationship (the even and odd index subproblems reuse the (n/2)-th roots), which is exactly what enables the divide-and-conquer split and the O(n log n) running time.
FAQ
What is the Fast Fourier Transform?
An O(n log n) algorithm to compute the Discrete Fourier Transform (evaluating a polynomial/signal at the n roots of unity) and its inverse. The naive DFT is O(n²); the FFT splits a size-n transform into two size-n/2 transforms on even/odd inputs to reach O(n log n).
How does the FFT speed up polynomial multiplication?
Coefficient multiplication is O(n²) convolution, but value-form multiplication is O(n) pointwise. The FFT converts between the forms in O(n log n), so the multiply becomes: FFT both, multiply pointwise, inverse FFT — making convolution and big-number multiplication O(n log n).
What is the FFT used for beyond polynomials?
A huge range: audio/image processing (spectral analysis, filtering, JPEG/MP3 compression), communications (OFDM in Wi-Fi/cellular), fast big-integer and polynomial multiplication, solving PDEs, and convolution/correlation in ML — the standard tool for moving between the time/space and frequency domains quickly.
What is the number-theoretic transform (NTT)?
A variant of the FFT over a finite field (integers mod a prime) using a primitive root of unity there, instead of complex numbers. It gives exact integer convolutions with no floating-point error, so competitive programming and cryptography often use the NTT for polynomial multiplication modulo a prime.
The picture: coefficients, values, coefficients
The product of A = 1 + 2x + 3x² and B = 4 + 5x + 6x², padded to length 8. Only the middle step, multiplying the values, is cheap on its own; the two transforms around it are what the divide-and-conquer pays for. The lower half shows why a transform is fast: splitting by even and odd position halves the problem, and the halves share work through a butterfly step.
Worked example, step by step
Multiply A = [1, 2, 3] by B = [4, 5, 6]. The product has 3 + 3 − 1 = 5 coefficients, so pad both to length 8, the next power of two. The eight evaluation points are the 8th roots of unity ωk. Each row shows one point: the polynomials’ values there, their product, and the coefficient the inverse transform returns for index k. Values are rounded to three decimals; “i” is the imaginary unit.
k
ω<sup>k</sup>
A(ω<sup>k</sup>)
B(ω<sup>k</sup>)
A·B at ω<sup>k</sup>
Coefficient k of A·B
0
1.000
6.000
15.000
90.000
4
1
0.707 + 0.707i
2.414 + 4.414i
7.536 + 9.536i
-23.899 + 56.284i
13
2
0.000 + 1.000i
-2.000 + 2.000i
-2.000 + 5.000i
-6.000 − 14.000i
28
3
-0.707 + 0.707i
-0.414 − 1.586i
0.464 − 2.464i
-4.101 + 0.284i
27
4
-1.000
2.000
5.000
10.000
18
5
-0.707 − 0.707i
-0.414 + 1.586i
0.464 + 2.464i
-4.101 − 0.284i
0
6
0.000 − 1.000i
-2.000 − 2.000i
-2.000 − 5.000i
-6.000 + 14.000i
0
7
0.707 − 0.707i
2.414 − 4.414i
7.536 − 9.536i
-23.899 − 56.284i
0
The right-hand column is 4, 13, 28, 27, 18 followed by three zeros, matching the 9 multiplications of the schoolbook method. Two patterns in the table are worth noticing. Rows k and 8 − k are complex conjugates (row 1 and row 7, row 3 and row 5), because the inputs are real; implementations can use that to halve the work. And at k = 0 the value is simply the sum of the coefficients: 1+2+3 = 6, 4+5+6 = 15, and 6 × 15 = 90, which equals the sum of the answer, 4+13+28+27+18.
Complexity and trade-offs
Case
Time
Space
Why
FFT multiply (floating point)
O(n log n)
O(n)
Two polynomials of 1,024 terms need three transforms of size 2,048, which took 33,792 butterfly steps in total, against 1,048,576 multiplications for the schoolbook method.
Schoolbook multiply
O(n²)
O(n) for the result
Every coefficient times every coefficient: 1,048,576 multiplications at 1,024 terms. Simple, exact, and fine for short polynomials.
Karatsuba
O(n1.585)
O(n)
Three half-size products instead of four. At 1,024 terms it makes 59,049 single multiplications: well under schoolbook, well over FFT.
Number-theoretic transform (NTT)
O(n log n)
O(n)
The same algorithm over integers modulo a prime such as 998244353 (which is 119 · 2²³ + 1), so there is no rounding at all, but results are only correct modulo that prime.
FFT precision limit
—
—
With 1,024-term inputs, coefficients below 1,000,000 came back within 0.094 of the exact values; with coefficients below a billion, the worst error was about 98,304 and 1,604 of 2,047 results were wrong after rounding.
These are operation counts, not timings: the FFT has a larger constant factor than a plain loop, so for short polynomials the schoolbook method is the practical choice. The speed-up grows with size, but only while the numbers stay small enough for double precision. Past that point you either split coefficients into smaller pieces, or move to the NTT for exact modular arithmetic.
Common mistakes
Padding to the input length instead of the product length
The product of two 3-term polynomials has 5 terms. Transforming at size 4 makes the high terms wrap around and add onto the low ones: [1,2,3] × [4,5,6] at size 4 returns [22, 13, 28, 27] instead of [4, 13, 28, 27, 18]. Use a size of at least len(A) + len(B) − 1, rounded up to a power of two.
Forgetting to divide by n in the inverse
The inverse transform uses conjugate roots and divides every entry by n. Skip the division and every coefficient is n times too big: for n = 8 the example returns 32, 104, 224, 216, 144 instead of 4, 13, 28, 27, 18.
Truncating instead of rounding
Floating-point results are close to the integers, not equal to them. Taking the floor turns a result just under 6 into 5: multiplying [2,2,2,0] by [2,9,9,3], coefficient 5 comes back as 5 instead of 6. Round to the nearest integer. The exact error depends on how the roots of unity are computed, which is why this is a bug that appears on some inputs and not others.
Feeding it a length that is not a power of two
The even/odd split needs an even length at every level. Length 6 splits to 3, and 3 cannot be halved, so a radix-2 implementation breaks (the one used to build this page’s numbers threw an error). Zero-pad to the next power of two first.
Trusting doubles for large coefficients
Rounding only fixes error below 0.5. At 1,024 terms and coefficients up to a billion the worst error here was about 98,304. When values or lengths are large, split numbers into small pieces or use an NTT.
Where this shows up
Multiplying very large integers
Treat the digits as polynomial coefficients, multiply, then carry. The numbers 123 and 456, written least-significant digit first, are [3, 2, 1] and [6, 5, 4]. Their product is 18, 27, 28, 13, 4 before carrying; carrying from the left end gives 56,088, which is 123 × 456.
Pattern matching and counting matches
Correlating a text with a pattern, one letter at a time, counts how many positions match at every alignment in one pass. For text abcab and pattern ab this gave 2, 0, 0, 2 matches for the four alignments, computed with the same transform.
Filtering and convolution
Applying a long filter to a signal is a convolution, which is exactly the polynomial product. Transforming both sides, multiplying, and transforming back is how long filters are applied efficiently.
Frequency analysis
The values the transform produces are the signal’s content at evenly spaced frequencies. The same algorithm that multiplies polynomials is the one used to see which frequencies are present in sampled audio or sensor data.
SOLVE IT YOURSELF
Solve it: multiply polynomials with the FFT
Multiplying two n-term polynomials the obvious way is n² multiplications. But in value form — the polynomial sampled at enough points — you just multiply the samples pointwise, n of them. The FFT is the O(n log n) round trip between the two forms. Python or TypeScript.
YOUR TASK
Implement fft(a, invert) and multiply(a, b), where the inputs are integer coefficient lists (lowest degree first). Return exact integer coefficients.
HINTS — 8 IDEAS
A degree-<n polynomial is pinned down by its values at n distinct points. Multiplying in that form is pointwise — one multiplication per point instead of n².
The points that make the transform fast are the n-th roots of unity. Their symmetry is what lets one transform of size n be built from two of size n/2.
Split the coefficients into even and odd indices, transform each half, then recombine: out[k] = E[k] + wk·O[k] and out[k+n/2] = E[k] − wk·O[k].
Those two lines share one multiplication because wk+n/2 = −wk. That cancellation is the entire speedup.
The split only works when n is a power of two, so pad first — to at least len(a) + len(b), or the result wraps around and corrupts the low coefficients.
The inverse transform is the same routine with the angle negated, then everything divided by n.
Round at the end. The answer is integral, but floating-point roots of unity will hand you 5.999999999999998.
Wrap-around is the classic bug and it is silent: pad to len(a)+len(b)-1 exactly and the top coefficient quietly folds onto the bottom one.