Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fast Multiplication Polynomial multiplication Toom–Cook method

Similar presentations


Presentation on theme: "Fast Multiplication Polynomial multiplication Toom–Cook method"— Presentation transcript:

1 Fast Multiplication Polynomial multiplication Toom–Cook method
3. Primitive Roots of Unity 4. The Discrete Fourier Transform 5. The FFT Algorithm 6. Schönhage-Strassen’s method 7. Conclusion

2 1. Polynomial multiplication
(-5, 1, 2) evaluation interpolation 或者 {(-1,-4),(0,-5),(1,-2)} (p(-1), p(0), p(1)) by Lagrange Interpolating Polynomial

3 1. Polynomial multiplication
Lagrange Interpolating Polynomial

4 1. Polynomial multiplication
Given coefficients (a0,a1,a2,…,an-1) and (b0,b1,b2,…,bn-1) defining two polynomials, p() and q(), and number x, compute p(x)q(x).

5 1. Polynomial multiplication
P(x)=a0+a1x+…+an-1xn-1 q(x)=b0+b1x+…+bn-1xn-1 (a0,a1,a2,…,an-1) (b0,b1,b2,…,bn-1) 選2n+1個點 (p(w0), p(w1),…, p(w2n) ) (q(w0), q(w1),…, q(w2n) ) evaluation multiplication Polynomial Multiplication (p(w0)*q(w0), p(w1)*q(w1),… , p(w2n)*q(w2n) ) (c0,c1,c2,…,cn,…,c2n-1) interpolation

6 1. Polynomial multiplication
P(x)=5+x q(x)=1+2x (5,1) (1,2) 選3個點 (p(0)=5, p(1)=6, p(2)=7 ) (q(0)=1, q(1)=3, q(2)=5 ) evaluation multiplication Polynomial Multiplication C(0)=5, C(1)=18, C(2)=3 (5,11,2) interpolation

7 1. Polynomial multiplication
慎選特殊的點可以降低運算 Evaluation O(n) Total O(n2)

8 1. Polynomial multiplication
Polynomial Evaluation Horner’s Rule: Given coefficients (a0,a1,a2,…,an-1), defining polynomial Given x, we can evaluate p(x) in O(n) time using the equation Eval(A,x): [Where A=(a0,a1,a2,…,an-1)] If n=1, then return a0 Else, Let A’=(a1,a2,…,an-1) [assume this can be done in constant time] return a0+x*Eval(A’,x)

9 2.Toom–Cook method Toom-k :
a simplification of a description of Toom–Cook polynomial multiplication described by Marco Bodrato in 2007. 給定兩整數M, N,擬計算M*N five main steps: Splitting (將整數轉成多項式) Evaluation (找出多項式對應的點) Pointwise multiplication (點値相乘) Interpolation (由點找出多項式) Recomposition (將多項式轉成整數) Marco Bodrato. Towards Optimal Toom–Cook Multiplication for Univariate and Multivariate Polynomials in Characteristic 2 and 0. In WAIFI'07 proceedings, volume 4547 of LNCS, pages June 21-22, author website

10 2.Toom–Cook method:Toom-3
N= (1) Splitting (將整數轉成多項式) 切成3等份,取base B=108 * m0 = m1 = m2 = n0 = n1 = n2 = 98765 p(x) = m0 + m1x + m2x2 q(x) = n0 + n1x + n2x2

11 2.Toom–Cook method:Toom-3
(2) Evaluation (找出多項式對應的點) p(x) = m0 + m1x + m2x2 q(x) = n0 + n1x + n2x2 p(0) = m0 = = p(1) = m0 + m1 + m2 = = p(−1) = m0 − m1 + m2 = − = − p(−2) = m0 − 2m1 + 4m2 = − 2× × = − p(∞) = m2 = = q(0) = n0 = = q(1) = n0 + n1 + n2 = = q(−1) = n0 − n1 + n2 = − = q(−2) = n0 − 2n1 + 4n2 = − 2× ×98765 = − q(∞) = n2 = = 98765 *

12 2.Toom–Cook method:Toom-3
(3) Pointwise multiplication (點値相乘) r(x)=p(x)q(x) r(0) = p(0)q(0) = × = r(1) = p(1)q(1) = × = r(−1) = p(−1)q(−1) = − × = − r(−2) = p(−2)q(−2) = − × − = r(∞) = p(∞)q(∞) = × = *

13 2.Toom–Cook method:Toom-3
(4) Interpolation (由點找出多項式) *

14 2.Toom–Cook method:Toom-3
(4) Interpolation (由點找出多項式) *

15 2.Toom–Cook method:Toom-3
(4) Interpolation (由點找出多項式) one sequence given by Bodrato *

16 2.Toom–Cook method:Toom-3
(4) Interpolation (由點找出多項式) *

17 2.Toom–Cook method:Toom-3
(5) Recomposition (將多項式轉成整數) *

18 2.Toom–Cook method: Complexity
Toom-3 reduces 9 multiplications to 5, and runs in Θ(nlog(5)/log(3)), about Θ(n1.465). In general, Toom-k runs in Θ(c(k)ne), where e = log(2k-1) / log(k), ne is the time spent on sub-multiplications, and c is the time spent on additions and multiplication by small constants * (in Knuth’s book)

19 Polynomial multiplication
慎選特殊的點可以降低運算-Primitive Roots of Unity 執行DFT 得到 只需O(nlogn) Evaluation O(n) Total O(n2)

20 3. Primitive Roots of Unity
A number w is a primitive n-th root of unity, for n>1, if wn = 1 The numbers 1, w, w2, …, wn-1 are all distinct Example 1: Z*11: 22=4, 62=3, 72=5, 82=9 are 5-th roots of unity in Z*11 2-1=6, 3-1=4, 4-1=3, 5-1=9, 6-1=2, 7-1=8, 8-1=7, 9-1=5 Example 2: The complex number e2pi/n is a primitive n-th root of unity, where

21 3. Primitive Roots of Unity
Inverse Property: If w is a primitive root of unity, then w -1=wn-1 Proof: wwn-1=wn=1 Cancellation Property: For non-zero -n<k<n, Proof: Reduction Property: If w is a primitve (2n)-th root of unity, then w2 is a primitive n-th root of unity. Proof: If 1,w,w2,…,w2n-1 are all distinct, so are 1,w2,(w2)2,…,(w2)n-1 Reflective Property: If n is even, then wn/2 = -1. Proof: By the cancellation property, for k=n/2: Corollary: wk+n/2= -wk.

22 4.The Discrete Fourier Transform
Given coefficients (a0,a1,a2,…,an-1) for an (n-1)-degree polynomial p(x) The Discrete Fourier Transform is to evaluate p at the values 1,w,w2,…,wn-1 We produce (y0,y1,y2,…,yn-1), where yj=p(wj)

23 4.The Discrete Fourier Transform
Matrix form: y=Fa, where F[i,j]=wij. The Inverse Discrete Fourier Transform recovers the coefficients of an (n-1)-degree polynomial given its values at 1,w,w2,…,wn-1 Matrix form: a=F -1y, where F -1[i,j]=w-ij/n. 註: the matrix F 中column彼此互相orthogonal滿足 FF*=nI,其中F*為F之conjugate

24 4.The Discrete Fourier Transform
The DFT and inverse DFT really are inverse operations Proof: Let A=F -1F. We want to show that A=I, where If i=j, then If i and j are different, then

25 4.The Discrete Fourier Transform
Convolution The DFT and the inverse DFT can be used to multiply two polynomials So we can get the coefficients of the product polynomial quickly if we can compute the DFT (and its inverse) quickly…

26 4.The Discrete Fourier Transform
Convolutions Convolutions 127356 (3,11,37,47,42) ×

27 4.The Discrete Fourier Transform
Convolutions 127356 × × acyclic convolutions (37,50,53) negacyclic convolutions (37,44,31)

28 4.The Discrete Fourier Transform
Convolution theorem CyclicConvolution(X, Y) = IDFT(DFT(X) · DFT(Y))

29 5.The Fast Fourier Transform
The FFT is an efficient algorithm for computing the DFT The FFT is based on the divide-and-conquer paradigm: If n is even, we can divide a polynomial into two polynomials and we can write

30 5.The Fast Fourier Transform
Given coefficients (a0,a1,a2,…,a7) and w primitive 8-th root of unity

31 5.The Fast Fourier Transform

32 5.The Fast Fourier Transform

33 5.The Fast Fourier Transform

34 5.The Fast Fourier Transform
a0 a1 a2 a3 a a a6 a7

35 5.The Fast Fourier Transform
T(n)=2T(n/2)+O(n) The running time is O(n log n). [inverse FFT is similar]

36 Polynomial multiplication
p(x)=a0+a1x+…+an-1xn-1 q(x)=b0+b1x+…+bn-1xn-1 選w primitive m-th root of unity (m2n) (a0,a1,a2,…,an-1) (b0,b1,b2,…,bn-1) (p(w0), p(w1),…, p(wm-1) ) (q(w0), q(w1),…, q(wm-1) ) Evaluation FFT multiplication Polynomial Multiplication (p(w0)*q(w0), p(w1)*q(w1),… , p(wm-1)*q(wm-1) ) (c0,c1,c2,…,cn,…,cm-1) The running time is O(n log n). Interpolation IFFT

37 6.Schönhage-Strassen’s method
給定兩大數M,N。計算M*N (1) Splitting (將整數轉成多項式) 令B=2k,則可產生degree 最多n-1之兩個多項式 p(x)=a0+a1B+…+an-1Bn-1 q(x)=b0+b1B+…+bn-1Bn-1 P=(a0,a1,a2,…,an-1) Q=(b0,b1,b2,…,bn-1) (2) Evaluation (找出多項式對應的點) 選w primitive m-th root of unity (m2n)

38 6. Schönhage-Strassen’s method
(3) Pointwise multiplication (點値相乘) (4) Interpolation (由點找出多項式) 對上述點執行the inverse Fourier transform

39 6. Schönhage-Strassen’s method
(5)Recomposition (將多項式轉成整數) 令x=B

40 6. Schönhage-Strassen’s method
Complexity 分析 The running time is O(n log n) 單位? The bound on the numerical errors α on the ci after the FFT process can be proved to be where ε ≅ 1.e-16 α ≤ 6n2B2log(n)ε the number of digits of these basic numbers should be of the order of log(B)+log(n)

41 6. Schönhage-Strassen’s method
Complexity 分析 The running time is O(n log n(log(B) + log(n))2) 然而如果針對所有乘法都採用recursive觀念,即 得到

42 7. Conclusion Method* complexity integer classical Karatsuba 1962
10,000位數 Toom–3 1963 Toom–Cook (knuth) 1966 40,000位數 Schönhage-Strassen 1971 Fürer 2007 M. Bodrato. Toward Optimal Toom-Cook Multiplication.... In WAIFI'07, Springer, 2007 Schönhage and V. Strassen, "Schnelle Multiplikation großer Zahlen", Computing 7 (1971), pp. 281–292. Martin Fürer, "Faster integer multiplication", STOC 2007 Proceedings, pp


Download ppt "Fast Multiplication Polynomial multiplication Toom–Cook method"

Similar presentations


Ads by Google