The Fast Fourier Transform. Andreas Klappenecker

Similar documents
5.6 Convolution and FFT

Design and Analysis of Algorithms

Algorithm Design and Analysis

FFT: Fast Polynomial Multiplications

The Fast Fourier Transform: A Brief Overview. with Applications. Petros Kondylis. Petros Kondylis. December 4, 2014

Computational Methods CMSC/AMSC/MAPL 460

How to Multiply. 5.5 Integer Multiplication. Complex Multiplication. Integer Arithmetic. Complex multiplication. (a + bi) (c + di) = x + yi.

CSE 548: Analysis of Algorithms. Lecture 4 ( Divide-and-Conquer Algorithms: Polynomial Multiplication )

DIVIDE AND CONQUER II

Divide and Conquer algorithms

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences

Fast Fourier Transform

Sequential Fast Fourier Transform (PSC ) Sequential FFT

Fast Convolution; Strassen s Method

Multiplying huge integers using Fourier transforms

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201

CS711008Z Algorithm Design and Analysis

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

CS S Lecture 5 January 29, 2019

Sequential Fast Fourier Transform

Algorithms and data structures

Lecture 20: Discrete Fourier Transform and FFT

DIVIDE AND CONQUER II

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn

Chapter 1 Divide and Conquer Algorithm Theory WS 2016/17 Fabian Kuhn

Chapter 5. Divide and Conquer. CS 350 Winter 2018

Fast Polynomial Multiplication

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem

E The Fast Fourier Transform

Chapter 5 Divide and Conquer

Mid-term Exam Answers and Final Exam Study Guide CIS 675 Summer 2010

CS483 Design and Analysis of Algorithms

4.3 The Discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT)

Math 421 Homework 1. Paul Hacking. September 22, 2015

Interpolation on the unit circle

Chapter 23. Fast Fourier Transform Introduction. By Sariel Har-Peled, November 28, Version: 0.11

DIVIDE AND CONQUER II

Lecture 7 January 26, 2016

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. Prof. R. Fateman

The divide-and-conquer strategy solves a problem by: Chapter 2. Divide-and-conquer algorithms. Multiplication

CSE 421. Dynamic Programming Shortest Paths with Negative Weights Yin Tat Lee

Divide and conquer. Philip II of Macedon

The Fast Fourier Transform

Space- and Time-Efficient Polynomial Multiplication

DIVIDE AND CONQUER II

The Fast Fourier Transform

CS168: The Modern Algorithmic Toolbox Lecture #11: The Fourier Transform and Convolution

Introduction to Algorithms 6.046J/18.401J/SMA5503

DISCRETE FOURIER TRANSFORM

Speedy Maths. David McQuillan

Solving the general quadratic congruence. y 2 Δ (mod p),

PYTHAGOREAN TRIPLES KEITH CONRAD

The Graphs of Polynomial Functions

LECTURE 16 GAUSS QUADRATURE In general for Newton-Cotes (equispaced interpolation points/ data points/ integration points/ nodes).

The O () notation. Definition: Let f(n), g(n) be functions of the natural (or real)

Divide and Conquer. Andreas Klappenecker

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Linear Algebra 1 Exam 2 Solutions 7/14/3

Toeplitz matrices. Niranjan U N. May 12, NITK, Surathkal. Definition Toeplitz theory Computational aspects References

Periodic motions. Periodic motions are known since the beginning of mankind: Motion of planets around the Sun; Pendulum; And many more...

THE FOURIER TRANSFORM OF FUNCTIONS OF THE GREATEST COMMON DIVISOR. Wolfgang Schramm Schulgasse 62 / 11, A-1180 Vienna, AUSTRIA

Divide-and-conquer algorithms

EE 229B ERROR CONTROL CODING Spring 2005

An Approach to Hensel s Lemma

x 9 or x > 10 Name: Class: Date: 1 How many natural numbers are between 1.5 and 4.5 on the number line?

Polynomial Review Problems

Inverses. Stephen Boyd. EE103 Stanford University. October 28, 2017

23. The Finite Fourier Transform and the Fast Fourier Transform Algorithm

Fast Multipole Methods: Fundamentals & Applications. Ramani Duraiswami Nail A. Gumerov

Chapter 1 Numerical approximation of data : interpolation, least squares method

MATH 101A: ALGEBRA I, PART D: GALOIS THEORY 11

An overview of key ideas

Lecture 3: Divide and Conquer: Fast Fourier Transform

2.161 Signal Processing: Continuous and Discrete Fall 2008

Lectures 9-10: Polynomial and piecewise polynomial interpolation

Number theoretic algorithms for cryptographic applications

be any ring homomorphism and let s S be any element of S. Then there is a unique ring homomorphism

Frequency Domain Finite Field Arithmetic for Elliptic Curve Cryptography

Week 9-10: Recurrence Relations and Generating Functions

COMS E F15. Lecture 22: Linearity Testing Sparse Fourier Transform

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Fast Polynomials Multiplication Using FFT

Old and new algorithms for computing Bernoulli numbers

Mathematical Olympiad Training Polynomials

Algorithms and Data Structures

You should be comfortable with everything below (and if you aren t you d better brush up).

Integer multiplication with generalized Fermat primes

Complex numbers, the exponential function, and factorization over C

lecture 7: Trigonometric Interpolation

Implementation of the DKSS Algorithm for Multiplication of Large Numbers

Kartsuba s Algorithm and Linear Time Selection

Parallelism in Computer Arithmetic: A Historical Perspective

A description of a math circle set of activities around polynomials, especially interpolation.

Points of Finite Order

Unit 1 Vocabulary. A function that contains 1 or more or terms. The variables may be to any non-negative power.

On the computational complexity of mathematical functions

The tangent FFT. D. J. Bernstein University of Illinois at Chicago

Parallel Numerical Algorithms

UNDERSTANDING RULER AND COMPASS CONSTRUCTIONS WITH FIELD THEORY

NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt):

Transcription:

The Fast Fourier Transform Andreas Klappenecker

Motivation There are few algorithms that had more impact on modern society than the fast Fourier transform and its relatives. The applications of the fast Fourier transform touch nearly every area of science and engineering in some way. For example, it changed medicine by enabling magnetic resonance imaging. It sparked a revolution in the music industry. It even finds uses in applications such as the fast multiplication of large integers.

A Brief History Gauss (1805, 1866). Used the FFT in calculations in astronomy. Danielson-Lanczos (1942). Gave an efficient algorithm, but low impact as digital computer were just emerging. Cooley-Tukey (1965). Rediscovered and popularized FFT. The importance was immediately recognized, and this is one of the most widely cited papers in science and engineering.

Key Property The fast Fourier transform allows one to quickly multiply polynomials, that is, given A(x) = a 0 + a 1 x +... + a n-1 x n-1 B(x) = b 0 + b 1 x +... + b n-1 x n-1 calculate C(x) = A(x)B(x) = i,j a i b j x i+j = k ( i a k-i b i ) x k

Representations of Polynomials

Coefficient Representation A polynomial A(x) = a 0 + a 1 x +... + a n-1 x n-1 can be represented in various ways. The most common way is to specify its coefficients (a 0, a 1,..., a n-1 ); this is called the coefficient representation.

Operations in C. Representation Given polynomials in coefficient representation: A(x) = a 0 + a 1 x +... + a n-1 x n-1 and B(x) = b 0 + b 1 x +... + b n-1 x n-1 Addition in O(n): A(x)+B(x) = (a 0 +b 0 ) + (a 1 +b 1 )x +... + (a n-1 +b n-1 )x n-1 Evaluation in O(n) using Horner s scheme: A(w) = a 0 + (a 1 +...(a n-3 + (a n-2 + a n-1 w)w)w...)w

Operations in C. Representation Given polynomials in coefficient representation: A(x) = a 0 + a 1 x +... + a n-1 x n-1 and B(x) = b 0 + b 1 x +... + b n-1 x n-1 Multiplication in O(n 2 ): A(x)B(x) = i,j a i b j x i+j = k ( i a k-i b i ) x k

Point-Value Representation A polynomial A(x) = a 0 + a 1 x +... + a n-1 x n-1 can be understood as a function x -> y = A(x). We can specify a polynomial by n point and value pairs: { (x 0, y 0 ), (x 1, y 1 ),..., (x n-1, y n-1 ) } A polynomial of degree n-1 is uniquely specified by giving n pointvalue pairs for n distinct points.

Operations in PV Representation Suppose that we are given two polynomials in PV representation: A(x): { (x 0, y 0 ), (x 1, y 1 ),..., (x n-1, y n-1 ) } B(x): { (x 0, z 0 ), (x 1, z 1 ),..., (x n-1, z n-1 ) } Addition in O(n): A(x) + B(x): { (x 0, y 0 +z 0 ), (x 1, y 1 +z 1 ),..., (x n-1, y n-1 +z n-1 ) } Multiplication in O(n), but need at least 2n-1 distinct points: A(x)B(x): { (x 0, y 0 z 0 ), (x 1, y 1 z 1 ),..., (x 2n-2, y 2n-2 z 2n-2 ) }

Operations in PV Representation Evaluate. We can evaluate a polynomial in PV representation using some interpolation formula. Given A(x): { (x 0, y 0 ), (x 1, y 1 ),..., (x n-1, y n-1 ) } one can evaluate at a point w e.g. using Lagrange s interpolation formula A(w) = k y k j: k j (w-x j )/(x k -x j ) However, evaluation uses O(n 2 ) operations.

Tradeoffs Representation Multiply Evaluate Coefficient O(n 2 ) O(n) Point-value O(n) O(n 2 )

Converting between the Representations For a polynomial A(x) = a 0 + a 1 x +... + a n-1 x n-1 of degree n-1, a conversion from coefficient representation to p.v. representation at n distinct points x 0, x 1,..., x n-1 can be done as follows: 0 B @ y 0 y 1... y n 1 1 C A = 0 B @ 1 x 0 x 2 0... x n 0 1 1 x 1 x 2 1... x n 1 1............... 1 x n 1 x 2 n 1... x n n 1 1 The Vandermonde matrix is invertible iff the x i s are distinct. Drawback: Conversions are not fast! PV 1 C A 0 B @ O(n 2 ) O(n 3 ) a 0 a 1... a n 1 C 1 C A

The Fast Fourier Transform II Andreas Klappenecker

Divide-and-Conquer

Motivation We can speed up the evaluation by choosing suitable points x 0,...,x n-1 that have sufficient structure so that we can reuse computational results.

Divide We can divide the polynomial A(x) by splitting it into its even and odd powers: A(x) = A even (x 2 ) + x A odd (x 2 ) a 0 a 1 a 2 a 3 a 4 a 5 a 6 a 7 For example, if A(x) = a 0 +a 1 x+...+a 7 x 7 then A even (x) = a 0 +a 2 x+a 4 x 2 +a 6 x 3 and A odd (x) = a 1 +a 3 x+a 5 x 2 +a 7 x 3

Key Idea Divide A(x) = a 0 + a 1 x + a 2 x 2 + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7 into even and odd powers: A even (x) = a 0 + a 2 x + a 4 x 2 + a 6 x 3 and A odd (x) = a 1 + a 3 x + a 5 x 2 + a 7 x 3. Evaluate at two points w and -w by evaluating two smaller polys at w 2 A(w) = A even (w 2 ) + w A odd (w 2 ). A(-w) = A even (w 2 ) - w A odd (w 2 ).

Example Choose w 2 =1, so that its square root w=1 or w=-1. Then A(1) = A even (1) + A odd (1). A(-1) = A even (1) - A odd (1). So to evaluate A(x) at 1 and -1, we only need to evaluate two polynomials A even (1) and A odd (1). Benefit: Evaluation of both A even (x) and A odd (x) has the same complexity as a single evaluation of A(x).

The FFT Trick Our goal is to repeatedly use the same trick, so we need to use square roots of 1 (so 1 and -1) and square roots of -1 (so i and -i). A( 1) = A even (1) + 1 A odd (1) A(-1) = A even (1) - 1 A odd (1) A( i) = A even (-1) + i A odd (-1) A(-i) = A even (-1) - i A odd (-1) A even (1) = A even,even (1) + A even,odd (1) A even (-1) = A even,even (1) - A even,odd (1) A odd (1) = A odd,even (1) + A odd,odd (1) A odd (-1) = A odd,even (1) - A odd,odd (1)

Roots of Unity The evaluation at n=2 k different points can be accomplished by repeatedly taking the square roots, starting with 1. {1} -> {1, -1} -> {1, -1, i, -i} ->... -> { 1, ω, ω 2,... ω n-1 } where ω is a primitive n-th root of unity, that is, ω n =1 and ω m 1 for 1 <= m < n. We can choose ω = exp(2πi/n).

Roots of Unity The set of n-th roots of unity is explicitly given by {ω k = exp(2πi k/n) 0 k n 1}. Each number in this set has absolute value 1, since exp(2πik/n) 2 = exp(2πik/n)exp( 2πik/n) = exp(0) = 1.

Geometric Interpretation We can write the n-th roots of unity in the form ω k = exp(2πi k/n) = cos(2πk/n) + i sin(2πk/n), so they lie on the unit circle. For example, ω 8 = cos(2π/8) + i sin(2π/8) = cos(π/4) + i sin(π/4) = 1 1 + i. 2 2

Properties of Roots of Unity Suppose that n is even. An n-th root of unity ω satisfies ω n/2 = -1. Indeed, (ω n/2 ) 2 = ω n = 1, so ω n/2 must be equal to 1 or -1. However, 1 is impossible, as ω is a primitive n-th root of unity, hence the claim. Consequence: ω n/2+j = -ω j for all j. Notice that { (ω k ) 2 : 0 <= k < n } =: { ν m : 0 <= m < n/2 } is the set of all n/2-th roots of unity.

Fast Fourier Transform Evaluate a degree n-1 polynomial A(x) = a 0 +... + a n-1 x n-1 at its n th roots of unity: ω 0, ω 1,, ω n-1. Divide. Divide the polynomial into even and odd powers. A(x) = A even (x 2 ) + x A odd (x 2 ). Conquer. Evaluate A even (x) and A odd (x) at the ½n th roots of unity: ν 0, ν 1,, ν n/2-1. Combine. A(ω k ) = A even (ν k ) + ω k A odd (ν k ), 0 k < n/2 A(ω k+n/2 ) = A even (ν k ) - ω k A odd (ν k ), 0 k < n/2

FFT Algorithm FFT(n, a 0,a 1,,a n-1 ) { if (n == 1) return a 0 (e 0,e 1,,e n/2-1 ) FFT(n/2, a 0,a 2,a 4,,a n-2 ) (d 0,d 1,,d n/2-1 ) FFT(n/2, a 1,a 3,a 5,,a n-1 ) for k = 0 to n/2-1 { ω k e 2πik/n y k e k + ω k d k } y k+n/2 e k - ω k d k } return (y 0,y 1,,y n-1 )

Running Time of FFT We have T(n) = 2T(n/2) + Θ(n) Therefore, the running time is T(n) = Θ(n log n).

Summary The FFT evaluates a polynomial of degree n-1 at n-th roots of unity in O(n log n) steps. Inverse of FFT just as fast. Can multiply two polynomials of degree n-1 in O(n log n) time using FFT of length 2n. Find more details in CLRS or Kleinberg/Tardos.