When I still have FFT, write a blog and keep it for later. . . . . .
FFT is used to solve polynomial multiplication, then first we must know what polynomial is.
This is an n-1 degree polynomial (the highest term is \ (x ^ {n-1} \) ), \ (a_0, a_1, ··· a_ {n-1} \) is the coefficient of each item, the polynomial Can be written as:
A polynomial can be determined by a set of coefficients, and the vector formed by this set of coefficients is also called the coefficient vector (such as \ (A (x) \) . The coefficient vector is: [ \ (a_0 \ \ \ a_1 \ ··· \ a_ {n-1} \) ]), the way of expressing a polynomial through the coefficient vector is called coefficient notation
Polynomial multiplication is that we know two polynomials: \ (A (x), B (x) \) , which are polynomials of degree n-1 and m-1, respectively.
Now talk about multiplying these two polynomials to get a polynomial of degree n + m-1 highest:
Then solving \ (C (x) \) is to find its coefficient vector : [ \ (c_0 \ \ c1 \ \ ··· \ \ c_j \ \ ··· \ \ c_n + m-1 \) ]
If we traverse each item of \ (A (x), B (x) \) directly is \ (O (n * m) \) , we need a faster algorithm, which is what we are discussing: fast Fourier Transform (FFT)
Front cheese:
Point value notation
For a known polynomial \ (A (x) \) , substitute \ (x_0 \) to get a definite \ (y_0 \) , and you can think of \ ((x_0, y_0) \) as coordinates A point on the tie. Further, any number of unequal independent variables can be substituted into \ ((x_1, x_2, ···) \) to get more points: \ ((x_1, y_1), (x_2, y_2), ·· · \)
We know that through two (different) points, the first-degree polynomial can be resolved \ ((ax + b) \) , and through three different points the second-order polynomial can be resolved \ ((ax ^ 2 + bx + c) \) , So it can be further deduced that n + 1 polynomials can be solved through n + 1 different points
Through n + 1 different points \ (\ left \ {(x_1, y_1), (x_2, y_2), ··· \ right \} \) , uniquely determine a polynomial of degree n, this method is also called polynomial point Value notation
We were surprised to find that the multiplication of two polynomials represented by point values has a complexity of \ (O (n) \) ! Specific method: \ (C (x_i) = A (x_i) × B (x_i) \) , so O \ ((n) \) enumeration \ (x_i \) is enough.
If we convert two polynomials into point value representations, then multiply, and then convert the new point value representations into polynomials, wouldn't it be possible to \ (O (n) \) solve polynomial multiplication!
... Unfortunately, obviously, the naive algorithm that converts polynomials into point-value representations is \ (O (n ^ 2) \) . In addition, even if you might not—the plain “interpolation algorithm” that converts point-value representations to polynomials is also \ (O (n ^ 2) \) .
But you can find bottlenecks large integer multiplication complexity may be "converted into a polynomial point value represents" This step (and the reverse operation), as long as this is done you can \ (O (n) \) seeking answers. If only this step can be optimized.
So I introduced two other front cheeses
Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT), the formula is as follows:
In the above two formulas, \ (i \) is the imaginary root ( \ (i ^ 2 = -1 \) ), and the proof of these two formulas will be given at the end of the article.
We set some variables and substitute these two formulas into our previous problem.
Suppose: \ (w = e ^ {\ frac {2 \ pi i} {N}} \) , where \ (N = n + m \) , the nature of the variable \ (w \) will not be discussed first, and will be discussed later Yes again
Substituting these variables into the DFT formula gives:
According to the above formula, DFT is related to our target polynomial \ (C (x) \) , and naturally the coefficient of the polynomial can be calculated by IDFT \ (c_j \) :
However, since I do n’t know the specific value of \ (c_j \) (if I know it, I ’ll finish the flowering), I ca n’t use DFT to calculate \ (C (w ^ k) \)
However, we know: \ (C (x) = A (x) * B (x) \) , and the coefficients of the polynomial \ (A (x) B (x) \) are known, so we can “curve to save the country ":
Use this formula to calculate \ (C (w ^ k) \) , and then use IDFT to calculate \ (c_j \) .
The above is a summary of FFT, the following discussion
One cheese: N times unit root
Discussion In order to better \ (^ W = E {\ FRAC {2 \ I PI {N}}} \) , we from Euler's formula Speaking
The proof of the formula is also given at the end of the article.
\ (e ^ {i \ theta} \) is a complex number, the value of its real part is \ (\ cos \ theta \) and the value of the imaginary part is \ (\ sin \ theta \) , so, \ (e ^ {i \ theta} \) corresponding to the complex plane of a distance between the point of origin is a constant, as shown in
Because \ (\ sin \ theta, \ cos \ theta \) is a periodic function (period is \ (2 \ pi \) ), it can be concluded that:
And no matter what value \ (\ theta \) takes, \ (e ^ {i \ theta} \) is distributed on the unit circle of the complex plane. Since it is a unit element, \ (\ theta \) is equal to It is the arc length on the circle from 1 (starting point) to \ (e ^ {i \ theta} \) .
The Euler formula is briefly introduced above, and the following returns to the variable we defined: \ (w = e ^ {\ frac {2 \ pi i} {n}} \) , for convenience in the previous overview, \ (w \) No subscripts are added, a clearer representation will be added to \ (w \) here : \ (w_n = e ^ {\ frac {2 \ pi i} {n}} \)
It can be guided from the discussion of the surface Euler formula, \ (e ^ {2 \ pi i} = 1 \) , which is equivalent to going around the unit circle and returning to the starting point, and \ (\ frac {2 \ pi } {n} \) is equivalent to this unit circle divided into \ (n \) equal divisions, and \ (w_n ^ k \) corresponds to the \ (k \) equal division point on the unit circle ( \ (k = 0 , 1,2, ···, n-1 \) )
This is an example of \ (n = 18 \) , and two values are marked \ (\ left \ {w_n ^ k | k = 2,10 \ right \} \) . Through the previous discussion and this chestnut, it should be I have a more intuitive understanding of \ (w_n ^ k \). Having said so much, I should be able to guess the Nth unit root refers to it. About the Nth unit root, I introduce several properties:
Property 1 is the elimination lemma , property 2 is the halving lemma , property 3 I forgot to call it. . .
Calculation \ (C (w_N ^ k) \)
First, define \ (N = m + n \) (n, m are the number of coefficients of polynomial \ (A (x), B (x) \) respectively). As mentioned earlier, DFT cannot be used directly to calculate \ (C ( w_n ^ k) \) , you need to calculate \ (A (w_N ^ k), B (w_N ^ k) \)
If the singular number directly put \ (\ left \ {w_N ^ k | k = 0,1,2, ···, N-1 \ right \} \) into the simple and rough generation, the time complexity is still \ (O ( N ^ 2) \) , regardless the back calculation, can not reduce the complexity of the algorithm, because some methods require the use of, to reduce \ (a (w_N ^ k) , B (w_N ^ k) \) time
For example, we have a polynomial:
We can separate its odd and even terms:
And \ (H1 (x), H2 (x) \) can also be calculated recursively, the method used in \ (A (x), B (x) \) is:
The time complexity becomes:
In addition, you can also use the properties of the unit root discussed earlier to reduce the amount of calculation, for example, \ (0 \ leq k <\ frac {n} {2} \) :
In this way, the general value range of \ (k \) can be calculated to get the result of the entire value range, so after calculating \ (A (w_N ^ k), B (w_N ^ k) \) , you can pass Simple multiplication to calculate \ (C (w_N ^ k) \) :
Solve the \ (C (x) \) coefficient
This step of calculation is almost half done, just use the IDFT formula to solve the coefficients of \ (C (x) \) :
In the above formula \ (C_k = C (w_N ^ k) \) , in addition, for the purpose of expression, usually an N-1 degree polynomial \ (D (x) \) is constructed , and its coefficients are each \ (C_k \ ) Value:
Therefore, the final \ (c_j \) calculation formula can be written as:
The second part of the above formula uses the property of unit root 3:
to sum up
1. Take N unit roots: [ \ (w_N ^ 0 \ \ w_N ^ 1 \ \ w_N ^ 2 \ \ ··· \ \ w_N ^ {N-1} \) ]
2. They are substituted into the polynomial \ (A (x), B (x) \) in
3. Calculate \ (C (w_N ^ k) = A (w_N ^ k) B (w_N ^ k) \)
4. Construct a new polynomial \ (D (x) = C_0 + C_1x ^ 1 + C_2x ^ 2 + ·· + C_ {N-1} x ^ {N-1} \)
5. Calculation \ (D (w_N ^ k) \)
6. Calculate the polynomial \ (C (x) \) coefficients \ (c_j = \ frac {1 } {N} D (w_N ^ {Nj}), j = 0,1,2, ···, N-1 \)
at last (to be continued)
- Proof of Euler's formula
- DFT and IDTF certification