1 Fast Polynomial and Integer Multiplication Jeremy R. Johnson.

Slides:



Advertisements
Similar presentations
Chapter 8 Introduction to Number Theory. Prime Numbers prime numbers only have divisors of 1 and self –they cannot be written as a product of other numbers.
Advertisements

Fast Fourier Transform Lecture 6 Spoken Language Processing Prof. Andrew Rosenberg.
FFT1 The Fast Fourier Transform. FFT2 Outline and Reading Polynomial Multiplication Problem Primitive Roots of Unity (§10.4.1) The Discrete Fourier Transform.
Richard Fateman CS 282 Lecture 101 The Finite-Field FFT Lecture 10.
CSE 421 Algorithms Richard Anderson Lecture 15 Fast Fourier Transform.
Fast Fourier Transform. Agenda Historical Introduction CFT and DFT Derivation of FFT Implementation.
FFT1 The Fast Fourier Transform by Jorge M. Trabal.
Complexity1 Pratt’s Theorem Proved. Complexity2 Introduction So far, we’ve reduced proving PRIMES  NP to proving a number theory claim. This is our next.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fast Fourier Transform Jean Baptiste Joseph Fourier ( ) These lecture.
Reconfigurable Computing S. Reda, Brown University Reconfigurable Computing (EN2911X, Fall07) Lecture 16: Application-Driven Hardware Acceleration (1/4)
CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer.
Introduction to Algorithms
ON MULTIVARIATE POLYNOMIAL INTERPOLATION
The Fourier series A large class of phenomena can be described as periodic in nature: waves, sounds, light, radio, water waves etc. It is natural to attempt.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 14 Instructor: Paul Beame.
Fast Fourier Transform Irina Bobkova. Overview I. Polynomials II. The DFT and FFT III. Efficient implementations IV. Some problems.
Introduction to Modular Arithmetic and Public Key Cryptography.
CPSC 3730 Cryptography and Network Security
The Polynomial Time Algorithm for Testing Primality George T. Gilbert.
By: Hector L Contreras SSGT / USMC
Great Theoretical Ideas in Computer Science.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Fingerprinting techniques. 2 Is X equal to Y? = ? = ?
FFT1 The Fast Fourier Transform. FFT2 Outline and Reading Polynomial Multiplication Problem Primitive Roots of Unity (§10.4.1) The Discrete Fourier Transform.
5.6 Convolution and FFT. 2 Fast Fourier Transform: Applications Applications. n Optics, acoustics, quantum physics, telecommunications, control systems,
The Fast Fourier Transform
Advanced Algebraic Algorithms on Integers and Polynomials Prepared by John Reif, Ph.D. Analysis of Algorithms.
Basic Number Theory Divisibility Let a,b be integers with a≠0. if there exists an integer k such that b=ka, we say a divides b which is denoted by a|b.
Chapter 4 – Finite Fields
Karatsuba’s Algorithm for Integer Multiplication
Applied Symbolic Computation1 Applied Symbolic Computation (CS 300) Karatsuba’s Algorithm for Integer Multiplication Jeremy R. Johnson.
The Fast Fourier Transform and Applications to Multiplication
Chinese Remainder Theorem Dec 29 Picture from ………………………
1 Network and Computer Security (CS 475) Modular Arithmetic and the RSA Public Key Cryptosystem Jeremy R. Johnson.
Information Security Lab. Dept. of Computer Engineering 87/121 PART I Symmetric Ciphers CHAPTER 4 Finite Fields 4.1 Groups, Rings, and Fields 4.2 Modular.
Network and Computer Security (CS 475) Modular Arithmetic
Cryptography and Network Security Chapter 4. Introduction  will now introduce finite fields  of increasing importance in cryptography AES, Elliptic.
Ch1 - Algorithms with numbers Basic arithmetic Basic arithmetic Addition Addition Multiplication Multiplication Division Division Modular arithmetic Modular.
Algorithms 2005 Ramesh Hariharan. Polynomial Computation.
Introduction to Number Theory Department of Computer Engineering Sharif University of Technology 3/8/2006.
Applied Symbolic Computation1 Applied Symbolic Computation (CS 567) The Fast Fourier Transform (FFT) and Convolution Jeremy R. Johnson TexPoint fonts used.
May 9, 2001Applied Symbolic Computation1 Applied Symbolic Computation (CS 680/480) Lecture 6: Multiplication, Interpolation, and the Chinese Remainder.
Number-Theoretic Algorithms
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Polynomial + Fast Fourier Transform
Applied Symbolic Computation
September 4, 1997 Applied Symbolic Computation (CS 300) Fast Polynomial and Integer Multiplication Jeremy R. Johnson.
Applied Symbolic Computation
Applied Symbolic Computation (CS 300) Modular Arithmetic
Applied Symbolic Computation
DFT and FFT By using the complex roots of unity, we can evaluate and interpolate a polynomial in O(n lg n) An example, here are the solutions to 8 =
September 4, 1997 Applied Symbolic Computation (CS 300) Fast Polynomial and Integer Multiplication Jeremy R. Johnson.
The Fast Fourier Transform
Advanced Algorithms Analysis and Design
Applied Symbolic Computation (CS 300) Modular Arithmetic
Systems Architecture I
Applied Symbolic Computation
Applied Symbolic Computation
September 4, 1997 Applied Symbolic Computation (CS 567) Fast Polynomial and Integer Multiplication Jeremy R. Johnson.
Applied Symbolic Computation (CS 300) Modular Arithmetic
Applied Symbolic Computation
Algorithmic Number Theory and Cryptography (CS 303) Modular Arithmetic
Applied Symbolic Computation
Applied Symbolic Computation (CS 300) Modular Arithmetic
Applied Symbolic Computation (CS 300) Modular Arithmetic
The Fast Fourier Transform
Applied Symbolic Computation (CS 300) Modular Arithmetic
Applied Symbolic Computation
Fast Polynomial and Integer Multiplication
Presentation transcript:

1 Fast Polynomial and Integer Multiplication Jeremy R. Johnson

2 Introduction Objective: To obtain fast algorithms for polynomial and integer multiplication based on the FFT. In order to do this we will compute the FFT over a finite field. The existence of FFTs over Z p is related to the prime number theorem. –Polynomial multiplication using interpolation –Feasibility of mod p FFTs –Fast polynomial multiplication –Fast integer multiplication (3 primes algorithm) References: Lipson, Cormen et al.

3 Polynomial Multiplication using Interpolation Compute C(x) = A(x)B(x), where degree(A(x)) = m, and degree(B(x)) = n. Degree(C(x)) = m+n, and C(x) is uniquely determined by its value at m+n+1 distinct points. [Evaluation] Compute A(  i ) and B(  i ) for distinct  i, i=0,…,m+n. [Pointwise Product] Compute C(  i ) = A(  i ) * B(  i ) for i=0,…,m+n. [Interpolation] Compute the coefficients of C(x) = c n x m+n + … + c 1 x +c 0 from the points C(  i ) = A(  i ) * B(  i ) for i=0,…,m+n.

4 Primitive Element Theorem Theorem. Let F be a finite field with q = p k elements. Let F* be the q-1 non-zero elements of F. Then F* = = {1, ,  2, …,  q-2 } for some   F*.  is called a primitive element. In particular there exist a primitive element for Z p for all prime p. E.G. (Z5)* = {1, 2,2 2 =4,2 3 =3} (Z17)* = {1, 3, 3 2 = 9, 3 3 = 10, 3 4 = 13, 3 5 = 5, 3 6 = 15, 3 7 = 11, 3 8 = 16, 3 9 = 14, 3 10 = 8, 3 11 = 7, 3 12 = 4, 3 13 = 12, 3 14 = 2, 3 15 = 6}

5 Modular Discrete Fourier Transform The n-point DFT is defined over Z p if there is a primitive nth root of unity in Z p (same is true for any finite field) Let  be a primitive n th root of unity.

6 Example

7 Fast Fourier Transform Assume that n = 2m, then Let T(n) be the computing time of the FFT and assume that n=2 k, then T(n) = 2T(n/2) +  (n) T(n) =  (nlogn)

8 FFT Factorization over Z 5

9 Inverse DFT

10 Example

11 Feasibility of mod p FFTs Theorem: Z p has a primitive Nth root of unity iff N|(p-1) Proof. By the primitive element theorem there exist an element  of order (p-1) Z p. If p-1 = qN, then  q is an Nth root of unity. To compute a mod p FFT of size 2 m, we must find p = 2 e k + 1 (k odd), where e  m. Theorem. Let a and b be relatively prime integers. The number of primes  x in the arithmetic progression ak + b (k=1,2,…) is approximately (somewhat greater) (x/log x)/  (a)

12 Fast Polynomial Multiplication Compute C(x) = a(x)b(x), where degree(a(x)) = m, and degree(b(x)) = n. Degree(c(x)) = m+n, and c(x) is uniquely determined by its value at m+n+1 distinct points. Let N  m+n+1. [Fourier Evaluation] Compute FFT(N,a(x), ,A); FFT(N,b(x), ,B). [Pointwise Product] Compute C k = 1/N A k * B k, k=0,…,N-1. [Fourier Interpolation] Compute FFT(N,C,  -1,c(x)).

13 Fast Modular and Integral Polynomial Multiplication If Z p has a primitive Nth root of unity then the previous algorithm works fine. If Z p does not have a primitive Nth root of unity, find a q that does and perform the computation in Z pq, then reduce the coefficients mod p. In Z[x] use a set of primes p 1,…,p t that have an Nth root of unity with p 1 * … * p t  size of the resulting integral coefficients (this can easily be computed from the input polynomials) and then use the CRT

14 Fast Integer Multiplication Let A = (a n-1,…,a 1,a 0 )  = a n-1  n-1 + … + a 1  + a 0 B = (b n-1,…,b 1,b 0 )  = b n-1  n-1 + … + b 1  + b 0 C = AB = c(  ) = a(  )b(  ), where a(x) = a n-1 x n-1 + … + a 1 x + a 0, b(x) = b n-1 x n-1 + … + b 1 x + b 0, and c(x) = a(x)b(x). Idea: Compute a(x)b(x) using FFT-based polynomial multiplication and then evaluate the result at . Computation will be performed mod p for several word sized “Fourier” primes and the Chinese Remainder Theorem will be used to recover the integer product.

15 Three Primes Algorithm Compute C = AB, where length(A) = m, and length(B) = n. Let a(x) and b(x) be the polynomials whose coefficients are the digits of A and B respectively The algorithm requires K “Fourier primes” p = 2 e k + 1 for sufficiently large e [Polynomial multiplication] Compute c i (x) = a(x)b(x) mod p i for i=1,…,K using FFT-based polynomial multiplication. [CRT] Compute c(x)  c i (x) (mod p i ) i=1,…,K. [Evaluation at radix] C = c(  ).

16 Analysis of Three Primes Algorithm Determine K –Since the kth coefficient of c(x),, the coefficients of c(x) are bounded by n  2 –Therefore, we need the product p 1 …p K  n  2 –If we choose p i > , then this is true if  K  n  2 –Assuming n <  [  is typically wordsize - for 32-bit words,   10 9 ], only 3 primes are required Theorem. Assume that mod p operations can be performed in O(1) time. Then the 3-primes algorithm can multiply two n- digit numbers in time O(nlogn) provided: –n <  –n  2 E-1, where three Fourier primes p = 2 e k + 1 (p >  ) can be found with e  E (need to perform the FFT of size 2n)

17 Limitations of 3 Primes Algorithms If we choose the primes to be wordsize for 32-bit words –  < p i < W = –  = 10 9 –n  2 E-1 = 2 23  8.38  10 6