FFT-Fast Fourier Transformation

Source: Internet
Author: User

· Taught by a Chinese PE Instructor

· The age limit for this article is 16 +

· All the above two items are successful.

Honestly, I don't want to write this thing at all ......

But delayyy has written all of them. Can you tell me if I can?> <~

For more information, see:

1. algorithm collection-polynomial multiplication (Zhang Jialin)

2. Introduction to algorithms: chapter on Fast Fourier Transformation.

3. The method for getting an integer from point X in All Integer FFT (Baidu space aekdycoin)

 

  

I wrote the proof of the plural ...... After a long time.

Set W (k, n) to the unit root of 1 n times(Note that in the case of a plural number, there are exactly n solutions). W (k, n) has the following properties:

W (k, n) =Cos (2 * π * k/n) + I * sin (2 * π * k/N)

Half discount:W (k, n) = W (2 k, 2n) (directly approx)

Periodicity:W (k, n) = W (K + n, n) (the period of the trigonometric function is N)

Semi-inverse:W (k, n) =-W (K + n/2, n) (same as above, you can understand YY trigonometric functions)

 

The formula sub-Proofs in the FFT main algorithm are as follows:

S (x) = g (x) + x · f (x)

S (w (k, n) = g (w (k, n) ²) + W (k, n) · F (w (k, n) ²)

S (w (k, n) = g (w (k, n/2) + W (k, n) · F (w (k, n/2 ))

And:

S (w (K + n/2, n) = g (w (k, n/2) + W (K + n/2, n) · F (w (k, n/2 ))

S (w (K + n/2, n) = g (w (k, n/2)-W (K + n/2, n) · F (w (k, n/2 ))

 

In addition, the proof of interpolation after the main algorithm will not be put ...... Please Google

The above proof is that the division of FFT is still very powerful ......

 

Refer:Csdn edevil live FFT high-precision Multiplication

Csdn delayyy FFT

 

Below is a very frustrating code (Using FFT to optimize high-precision multiplication)

# Include <cmath> # include <cstdio> # include <cstdlib> # include <algorithm> const double Pi = ACOs (double)-1); Using namespace STD; char s [10010]; long C [10010]; int len_a, len_ B, N, T; struct line {Double X, Y;} A [10010], B [10010], W [10010], Y [10010]; line operator-(Line & A, line & B) {line C; C. X =. x-B. x; C. y =. y-B. y; return C;} line operator + (line & A, line & B) {line C; C. X =. X + B. x; c. Y =. Y + B. y; return C;} line operator * (line & A, line & B) {line C; C. X =. x * B. x-. y * B. y; C. y =. x * B. Y +. y * B. x; return C;} void FFT (line * a, int S, int t) {int Len = n> T; If (LEN = 1) return; line wk; FFT (A, s, t + 1); FFT (A, S + (1 <t), t + 1); For (int K = 0; k <(LEN> 1); ++ K) {int P = S + (k <(t + 1 )); wk = W [k <t] * A [p + (1 <t)]; y [k] = A [p] + wk, Y [K + (Len> 1)] = A [p]-wk;} For (int K = 0; k <Len; ++ k) A [S + (k <t)] = Y [k];} void set (char * s, line * a, Int & Len) // read, four digits one press {int Lenk, STA, I; gets (S + 1); Lenk = strlen (S + 1); STA = Lenk % 4; Len = (Lenk + 4)/4-1; for (I = 1; I <= sta; ++ I) A [Len]. X = A [Len]. x * 10 + s [I]-'0'; For (; I <= Lenk; I + = 4) A [-- Len]. X = (s [I]-'0') * 1000 + (s [I + 1]-'0 ') * 100 + (s [I + 2]-'0') * 10 + s [I + 3]-'0'; Len = (Lenk + 3)/4;} int main () {freopen ("input.txt", "r", stdin ); freopen ("output.txt", "W", stdout); set (s, A, len_a); Set (S, B, len_ B); n = len_a + len_ B; for (t = 1; t <n; t <= 1); n = t; for (INT I = 0; I <n; ++ I) W [I]. X = cos (pI * I * 2/N), W [I]. y = sin (pI * 2 * I/n); FFT (A, 0, 0); // FFT (B, 0, 0) of the point value process ); // B-based point value process for (INT I = 0; I <n; ++ I) A [I] = A [I] * B [I], W [I]. y = -W [I]. y; // inverse matrix processing FFT (A, 0, 0); // Interpolation Process for (INT I = 0; I <n; ++ I) c [I] + = (long) round (A [I]. x/N), C [I + 1] = C [I]/10000, C [I] %= 10000; int Top = N; while (! C [Top] & top> 0) -- top; printf ("% d", C [Top]); For (INT I = Top-1; I> = 0; -- I) printf ("% 04d", C [I]);}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.