Using Fourier Transforms to Multiply Numbers
blog.robertelder.org
blog.robertelder.org
The explanation you gave, of FFT as an alternative representation of a polynomial through its value at selected points, gives that nice intuition about pointwise multiplication, without appealing (directly) to the "convolution-turns-into-multiplication" catchphrase.
But since I never get to actually use that stuff in my just, I always forget the details.
He ties them all to exploiting certain ring homomorphisms, either to compute r s with the help of f(s) f(s) or to compute f(r) f(s) with the help of r s. Karatsuba, Toom, FFT, Schönhage–Strassen...all are using ring homomorphisms to go between what you want to be doing and something that is easier.
Also see his later "Fast multiplication and its applications" [2].
It's pretty interesting--it's actually a recursive multiplication algorithm with log log N levels of recursion and N log N work at each level. And it actually uses another fast multiplication algorithm within it, the Karatsuba algorithm.
If a number is a multiple of two (i.e. n= 2k+0), we call it even, or if n=2k+1 then it's odd. This is interesting because evenness and oddness form an algebraic structure - an amoeba of an algebra with only two elements: even * odd = even, odd * odd = odd, etc...
But a moment's reflection reveals there is nothing special about being a multiple of two. We can just as well consider multiples of three and divide the universe into three groups: if a number is a multiple of three (i.e. n=3k+0) we call it 3-even, or if n=3k+1 then it's 3-odd, or if n=3k+2 then it's 3...blern! Again this is interesting because we have a mini-algebraic structure, this time with three elements. For example, a 3-odd times a 3-blern is (3k+1) * (3j+2) = 3(k3j+k2+j)+2 which is a 3-blern.
Similarly we have multiples of four: 4-even, 4-odd, 4-blern, 4-pop. Making up these names is of course absurd, so we instead invent a notation: modular arithmetic. Traditional even and odd are arithmetic modulo 2 (mod 2 for short); 3-even 3-odd 3-blern are arithmetic mod 3, etc. The mini-algebras are the cyclic groups or the multiplicative groups of integers modulo n.
The key word there being cyclic: we've identified periodic structures in the integers with different 'wavelengths' or periods, which is how long it takes for the even/odd/blern cycle to repeat:
(mod 2) 0 1 .. 2 3 .. 4 5 .. 6 7 .. 8 9 .. 10 11 ..
(mod 3) 0 1 2 .. 3 4 5 .. 6 7 8 .. 9 10 11 ..
(mod 4) 0 1 2 3 .. 4 5 6 7 .. 8 9 10 11 ..
----------Back to the topic of discussion. Typically we represent a number 'locally' with coordinates given wrt a base system, but it seems we might describe a number instead nonlocally, using these cyclic groups. That is, instead of saying 1 * 10^0 + 1 * 10^1 + 0 * 10^2 ... (11) i would say
2-odd: 11 = 2 * 5 + 1
3-blern: 11 = 3 * 3 + 2
4-pop: 11 = 4 * 2 + 3
5-odd: 11 = 5 * 2 + 1
So we're doing a kind of spectral decomposition: examining the number modulo 2, then mod 3, mod 4 etc. The key observation is, if two numbers are represented this way, how do I compute their product? Well its very easy, because i know what happens when i multiply, say, an an odd times a blern.. I get a blern! Multiplication becomes a pointwise operation. My question is this... is this an equivalent encoding to the one being done by the complex roots of unity in the FFT?FFT multiplication is basically a residue number system product on polynomials. Evaluating a polynomial p(x) at a point w_i is the same as computing p(x) modulo (x - w_i), where w_i here is one of the nth roots of unity. So the FFT computes p(x) mod (x - w_0), p(x) mod (x - w_1), ..., multiplies each residue individually, and the inverse FFT recovers the result modulo (x - w_0)(x - w_1)...(x - w_{n-1}) = x^n - 1.
I think directly using algorithms and programs implemented by others would be considered cheating (and these libraries are not presented on the server which checks your answer anyway). In competitive programming, participants compete their own ability and knowledge to implement algorithms.
That’s literally what the FFT does, fast polynomial multiplication.
https://statweb.stanford.edu/~cgates/PERSI/papers/aldous86.p...
It's only useful for VERY large numbers (thousands of digits), which is why most people never encounter it.
If you think of your periodic interval as representing angle measure, and the points in the interval as points on the unit circle in the complex plane, then your trigonometric polynomial can alternately be thought of as a Laurent polynomial in the complex plane. https://en.wikipedia.org/wiki/Laurent_polynomial
What the FFT does is convert between the values of your function at n roots of unity in the complex plane -> the coefficients of the Laurent polynomial interpolating those values.
For instance we glanced over it during my Digital Image Processing course. The professor did introduce it as a form of fast polynomial multiplication but we didn't dive too deep into Cooley-Turkey because frequency analysis was the focus of the work.
First, you learn about the convolution operation that, given any input function x(t), get the output of any linear time-invariant circuit as y(t). The convolution integral is nasty, professors make you feel the pain a bit. Then introduce the Laplace transform to make the computation much easier. Then go to continuous time, continuous frequency Fourier transform. Talk about frequency domain a bunch, learn filter topologies, etc. Circuits class over.
Now comes a signal processing class where you learn about discrete-time signals. First, talk lots about sampling. Then, get introduced discrete time convolution. Now, learn the z-transform and the discrete time Fourier transform (DTFT) for a discrete-time, continuous frequency signal. Mostly discuss filtering and spectral analysis. Intro to signal processing class over.
Learn about sampling the DTFT in the frequency domain. This is the DFT, which is usually presented as a sum that would require O(n^2) operations to compute. Learn that this corresponds to circular convolution and learn about zero padding for traditional convolution. Finally, get presented with Cooley-Tukey FFT algorithm for base-2. Focus is still signal and spectral analysis. Talk lots about windowing. You may get a mention that convolution corresponds to polynomial multiplication here. Or maybe they talk about grade-school multiplication, its really the same thing as polynomial multiplication with a carry. Senior level signal processing class over.
The point isn't what you use the FFT for but what the FFT does. The FFT does fast polynomial multiplication.
Look at a system doing DSP for example. Let's say you have an input RF signal that goes into an analog band-pass filter, a mixer, an analog low-pass filter, a DAC, and a FPGA. The FPGA implements a FIR filter - lets say a Hilbert transform using a distributed arithmetic algorithm. You are getting envelope information out of the FPGA. There's no FFT anywhere in the FPGA to compute this filter output.
You are seeing some weird noise in your DSP output. You dig a little by looking at the output of the DAC and then look at the FFT magnitude log10. You see some suspicious spurs popping up, but at really strange discrete frequencies. You show the spectrum to an RF engineer, then you two go to the lab and put an analog spectrum analyzer on the input to the DAC. Sure enough, there are mixing products of your input carrier, mixer frequency, and sampling clock frequency. The weird spur frequencies make sense now - you are seeing folding of the mixing products from the sampling. You tweak the sampling clock to move the spur digital frequencies.
In that long but real world example, I don't see anywhere here where thinking of things in terms of polynomials would be helpful here. It's also going to lead to confusion of terminology with your RF engineer - they tend to think continuous.