Complex FFT is not as bad as you think ... Probably.
Hi everyone!
As some of you _might_ already know, I don't like NTT. Primary reasons for this are:
- I don't like modular arithmetic optimizations (Montgomery, etc).
- I don't like NTT mods, and prefer good, old $10^9+7$.
- I do like algebra of complex numbers.
But, to my regret, the overwhelming mainstream in modern competitive programming is NTT. Primary reasons are:
- It's allegedly faster.
- It needs less memory.
- It has no precision issues.
- People don't like algebra of complex numbers.
There is nothing I can do about the last, but today I'll address the first 3. Optimizing complex FFT was on my mind for quite some time, but I didn't really work on it _that much_ until the [blog](https://codeforces.me/blog/entry/142063) by [user:Qwerty1232,2025-04-24] on optimizing NTT has dropped, which motivated me to actually put some serious effort into this.
In this blog, we will primarily focus on optimizations that are specific to complex arithmetic...
essentially it just does the same thing as its scalar version., generally known to be outstandingly stable. But how much stable exactly? Will
just $6$ bits be enough, their negacyclic convolution (i.e. the product modulo $x^n+1$) by computing
just a single imaginary, to FFT, you would recognize that what we're doing here is, really, just using
it on the top level, vector $x[0]+y[0], \dots, x[3]+y[3]$, all in just one assembly instruction., , in essence, we can just multiply relative error components when repeatedly
applying linear, - Take just complex numbers fft/ifft/dot implementation
[here](https://lib.cp-algorithms.com/cp, I will just refer you to [Step F](https://codeforces.me/blog/entry/142063) of
the, If we consider e.g. the error just for the real part, we get, If we look just on how large the numbers can be in the output, the trivial
estimate would be $n C^2, In other words, we can generally just apply most regular arithmetic operations
directly to the, Note that estimating relative error just for $x$ would be fruitless, as $x$
might be $0$, leading, We will get to them in detail later on, but in essence they just process two
FFT layers at once, }$ from around 3 ms to just **0.7 ms**.
Полный текст и комментарии »