Fast Multiplication of Large Numbers Using Fourier Techniques
Download
Report
Transcript Fast Multiplication of Large Numbers Using Fourier Techniques
Fast Multiplication of Large
Numbers Using Fourier
Techniques
0011 0010 1010 1101 0001 0100 1011
1
2
4
Henry Skiba
Advisor: Dr. Marcus Pendergrass
1
What is Multiplication?
0011 0010 1010 1101 0001 0100 1011
• Multiplication of small numbers
123
123
654
400 80 12
654
5000 1000 150
60000 12000 1800
492
6150
73800
80442
1
12x0 (8 15) x (4 10 18) x 2 (5 12) x3 6x 4
– where x is equal to 10
2
4
• This can also be represented in the
following way:
2
Multiplication in a New Way
0011 0010 1010 1101 0001 0100 1011
• Represent basic numbers as
polynomials when x equals 10
123 p( x) 3x0 2x 1x 2
654 q( x) 4 x0 5x 6 x 2
1
2
4
• Multiply two polynomials together
p( x) q( x) (3 4) x0 (3 5 4 2)x (3 6 2 5 1 4) x 2 (2 6 1 5) x3 (1 6) x 4
3
General Polynomial Multiplication
0011 0010 1010 1101 0001 0100 1011
• General Polynomials
p( x) p0 x 0 p1 x p2 x 2 ... pn1 x n 1 pn x n
1
q( x) q0 x 0 q1 x q2 x 2 ... qm1 x m1 qm x m
• General Polynomial Multiplication
2
4
r( x) p( x) q( x) ( p0q0 ) x ( p1q0 q1 p0 ) x ( p2q0 p1q1 p0q2 ) x ... ( pn1qm pn qm1 ) xmn1 ( pn qm ) xmn
0
2
• Even More General Form
–
m n
r ( x) ri x i
i 0
• Convolution
i
where ri pk qi k
k 0
4
What is Convolution?
0011 0010 1010 1101 0001 0100 1011
• s h(t ) s(u)h(t u)du
•
i
ri p qi pk qi k
k 0
1
2
4
• This opens the door for use of the Fast
Fourier Transform (FFT) for
multiplication
5
Using the FFT to Convolve
0011 0010 1010 1101 0001 0100 1011
• Convolution in the time domain is point
wise multiplication in the frequency
domain
p FFT
P
q
Q
FFT
p q FFT1 ( P Q)
• But
1
FFT ( P Q) p q
1
2
4
6
Using the FFT to Convolve (cont.)
0011 0010 1010 1101 0001 0100 1011
• Arrays are zero padded to make and
equivalent
– p = [p0,p1,p2,…,pn-1,pn,0,0,0,0,0…]
000123
045600
with zero
padding
vs.
124123
645645
without zero
padding
1
2
4
7
Algorithm
0011 0010 1010 1101 0001 0100 1011
1.
2.
3.
4.
5.
6.
Starts with two arrays, p and q
Zero pads p and q
p, q FFT
P, Q
P Q Multiply
PQ
FFT 1
PQ p q
carry p q
1
2
4
8
Testing vs. Regular Convolution
in Time Domain
0011 0010 1010 1101 0001 0100 1011
• Timed how long it took to multiply to random
numbers of a certain length
2
– 10,000 to 100,000 with digit stepping of 10,000
1
• Repeated iteration 5 times
• Used theoretical times to plot “fit” based on
average of 10,000 digit time values
– FFT Multiplication: nlog10n
– Convolution: n2
4
9
Results
0.11
0.1
0.09
0011 0010 1010 1101 0001 0100 1011
0.08
0.07
0.06
60
0.05
0.04
50
0.03
0.02
0.01
40
1
2
3
4
30
2
10
20
1
10
10
0
10
0
1
2
3
4
5
6
7
8
9
10
-1
10
4
x 10
-2
10
-3
10
1
2
3
1
5
6
7
2
8
5
6
7
10
4
x 10
4
4
9
8
10
9
10
4
x 10
Questions?
0011 0010 1010 1101 0001 0100 1011
1
2
4
11