Fast Fourier Transform Lecture 23 November 17, 2015 Sariel (UIUC) - - PowerPoint PPT Presentation

fast fourier transform
SMART_READER_LITE
LIVE PREVIEW

Fast Fourier Transform Lecture 23 November 17, 2015 Sariel (UIUC) - - PowerPoint PPT Presentation

NEW CS 473: Theory II, Fall 2015 Fast Fourier Transform Lecture 23 November 17, 2015 Sariel (UIUC) New CS473 1 Fall 2015 1 / 38 23.1: Introduction Sariel (UIUC) New CS473 2 Fall 2015 2 / 38 Polynomials and point value pairs Some


slide-1
SLIDE 1

NEW CS 473: Theory II, Fall 2015

Fast Fourier Transform

Lecture 23

November 17, 2015

Sariel (UIUC) New CS473 1 Fall 2015 1 / 38

slide-2
SLIDE 2

23.1: Introduction

Sariel (UIUC) New CS473 2 Fall 2015 2 / 38

slide-3
SLIDE 3

Polynomials and point value pairs

  • 1

1 2 3 4 5

  • 2
  • 1

1 2 3 4 5 x Some polynomials of degree two, passing through two fixed points 4 + x

2 − 5 2x2

3 + x

2 − 3 2x2

2 + x

2 − 1 2x2 1 2 + x 2 + 2x2 3 2 + x 2

− 1

2 + x 2 + 2x2

−2 + x

2 + 7 2x2

−1 + x

2 + 5 2x2

Sariel (UIUC) New CS473 3 Fall 2015 3 / 38

slide-4
SLIDE 4

Multiplying polynomials quickly

Definition

polynomial p(x) of degree n:a function p(x) = n

j=0 ajxj = a0 + x(a1 + x(a2 + . . . + xan)).

x0: p(x0) can be computed in O(n) time. “dual” (and equivalent) representation...

Theorem

For any set

  • (x0, y0), (x1, y1), . . . , (xn−1, yn−1)
  • f n

point-value pairs such that all the xk values are distinct, there is a unique polynomial p(x) of degree n − 1, such that yk = p(xk), for k = 0, . . . , n − 1.

Sariel (UIUC) New CS473 4 Fall 2015 4 / 38

slide-5
SLIDE 5

Polynomial via point-value

  • (x0, y0), (x1, y1), (x2, y2)
  • : polynomial through points:

p(x) = y0

✘✘✘✘✘ ✘ ❳❳❳❳❳ ❳

(x − x0)(x − x1)(x − x2)

❳❳❳❳❳ ❳

(x0 − x0)(x0 − x1)(x0 − x2) + y1 (x − x0)✘✘✘✘✘

✘ ❳❳❳❳❳ ❳

(x − x1)(x − x2) (x1 − x0)❳❳❳❳❳

(x1 − x1)(x1 − x2) + y2 (x − x0)(x − x1)✘✘✘✘✘

✘ ❳❳❳❳❳ ❳

(x − x2) (x2 − x0)(x2 − x1)❳❳❳❳❳

(x2 − x2)

Sariel (UIUC) New CS473 5 Fall 2015 5 / 38

slide-6
SLIDE 6

Polynomial via point-value

  • (x0, y0), (x1, y1), (x2, y2)
  • : polynomial through points:

p(x) = y0 (x − x1)(x − x2) (x0 − x1)(x0 − x2) + y1 (x − x0)(x − x2) (x1 − x0)(x1 − x2) + y2 (x − x0)(x − x1) (x2 − x0)(x2 − x1)

Sariel (UIUC) New CS473 5 Fall 2015 5 / 38

slide-7
SLIDE 7

Polynomial via point-value

  • (x0, y0), (x1, y1), . . . , (xn−1, yn−1)
  • : polynomial through

points: p(x) =

n−1

  • i=0

yi

  • j=i(x − xj)
  • j=i(xi − xj).

ith is zero for x = x1, . . . , xi−1, xi+1, . . . , xn−1, and is equal to yi for x = xi.

Sariel (UIUC) New CS473 6 Fall 2015 6 / 38

slide-8
SLIDE 8

Polynomials: regular vs. point-value pair representation

Just because.

1

Given n point-value pairs. Can compute p(x) in O(n2) time.

2

Point-value pairs representation: Multiply polynomials quickly!

3

p, q polynomial of degree n − 1, both represented by 2n point-value pairs

  • (x0, y0), (x1, y1), . . . , (x2n−1, y2n−1)
  • for p(x),

and

  • (x0, y′

0), (x1, y′ 1), . . . , (x2n−1, y′ 2n−1)

  • for q(x).

4

r(x) = p(x)q(x): product.

Sariel (UIUC) New CS473 7 Fall 2015 7 / 38

slide-9
SLIDE 9

Polynomials: regular vs. point-value pair representation

Just because.

1

Given n point-value pairs. Can compute p(x) in O(n2) time.

2

Point-value pairs representation: Multiply polynomials quickly!

3

p, q polynomial of degree n − 1, both represented by 2n point-value pairs

  • (x0, y0), (x1, y1), . . . , (x2n−1, y2n−1)
  • for p(x),

and

  • (x0, y′

0), (x1, y′ 1), . . . , (x2n−1, y′ 2n−1)

  • for q(x).

4

r(x) = p(x)q(x): product.

Sariel (UIUC) New CS473 7 Fall 2015 7 / 38

slide-10
SLIDE 10

Polynomials: regular vs. point-value pair representation

Just because.

1

Given n point-value pairs. Can compute p(x) in O(n2) time.

2

Point-value pairs representation: Multiply polynomials quickly!

3

p, q polynomial of degree n − 1, both represented by 2n point-value pairs

  • (x0, y0), (x1, y1), . . . , (x2n−1, y2n−1)
  • for p(x),

and

  • (x0, y′

0), (x1, y′ 1), . . . , (x2n−1, y′ 2n−1)

  • for q(x).

4

r(x) = p(x)q(x): product.

Sariel (UIUC) New CS473 7 Fall 2015 7 / 38

slide-11
SLIDE 11

Polynomials: regular vs. point-value pair representation

Just because.

1

Given n point-value pairs. Can compute p(x) in O(n2) time.

2

Point-value pairs representation: Multiply polynomials quickly!

3

p, q polynomial of degree n − 1, both represented by 2n point-value pairs

  • (x0, y0), (x1, y1), . . . , (x2n−1, y2n−1)
  • for p(x),

and

  • (x0, y′

0), (x1, y′ 1), . . . , (x2n−1, y′ 2n−1)

  • for q(x).

4

r(x) = p(x)q(x): product.

Sariel (UIUC) New CS473 7 Fall 2015 7 / 38

slide-12
SLIDE 12

Polynomials: regular vs. point-value pair representation

Just because.

1

In point-value representation representation of r(x) is

  • (x0, r(x0)), . . . , (x2n−1, r(x2n−1))
  • =
  • x0, p(x0)q(x0)
  • , . . . ,
  • x2n−1, p(x2n−1)q(x2n−1)
  • =
  • (x0, y0y′

0), . . . , (x2n−1, y2n−1y′ 2n−1)

  • .

Sariel (UIUC) New CS473 8 Fall 2015 8 / 38

slide-13
SLIDE 13

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-14
SLIDE 14

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-15
SLIDE 15

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-16
SLIDE 16

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-17
SLIDE 17

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-18
SLIDE 18

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-19
SLIDE 19

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-20
SLIDE 20

Which implies...

1

p(x) and q(x): point-value pairs = ⇒ compute r(x) = p(x)q(x) in linear time!

2

...but r(x) is in point-value representation. Bummer.

3

...but we can compute r(x) from this representation.

4

Purpose: Translate quickly (i.e., O(n log n) time) from the standard r to point-value pairs representation of polynomials.

5

...and back!

6

= ⇒ computing product of two polynomials in O(n log n) time.

7

Fast Fourier Transform is a way to do this.

8

choosing the xi values carefully, and using divide and conquer.

Sariel (UIUC) New CS473 9 Fall 2015 9 / 38

slide-21
SLIDE 21

23.2: Computing a polynomial quickly on n values

Sariel (UIUC) New CS473 10 Fall 2015 10 / 38

slide-22
SLIDE 22

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-23
SLIDE 23

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-24
SLIDE 24

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-25
SLIDE 25

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-26
SLIDE 26

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-27
SLIDE 27

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-28
SLIDE 28

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-29
SLIDE 29

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-30
SLIDE 30

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-31
SLIDE 31

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-32
SLIDE 32

Computing a polynomial quickly on n values

Lets just use some magic.

1

Assume: polynomials have degree n − 1, where n = 2k.

2

.. pad polynomials with terms having zero coefficients.

3

Magic set of numbers: Ψ = {x1, . . . , xn}. Property: |SQ(Ψ)| = n/2, where SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

4

|square(Ψ)| = |Ψ| /2.

5

Easy to find such set...

6

Magic: Have this property repeatedly... SQ(SQ(Ψ)) has n/4 distinct values.

7

SQ(SQ(SQ(Ψ))) has n/8 values.

8

SQi(Ψ) has n/2i distinct values.

9

Oops: No such set of real numbers.

10 NO SUCH SET. Sariel (UIUC) New CS473 11 Fall 2015 11 / 38

slide-33
SLIDE 33

Collapsible sets

Assume magic...

Let us for the time being ignore this technicality, and fly, for a moment, into the land of fantasy, and assume that we do have such a set of numbers, so that |SQi(Ψ)| = n/2i numbers, for i = 0, . . . , k. Let us call such a set of numbers collapsible.

Sariel (UIUC) New CS473 12 Fall 2015 12 / 38

slide-34
SLIDE 34

Breaking the input polynomial into...

... two polynomials of half the degree

1

For a set X = {x0, . . . , xn} and polynomial p(x), let p

  • X
  • =
  • x0, p(x0)
  • , . . . ,
  • xn, p(xn)
  • .

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2), where

u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

3

all even degree terms in u(·), all odd degree terms in v(·).

4

maximum degree of u(y), v(y) is n/2.

Sariel (UIUC) New CS473 13 Fall 2015 13 / 38

slide-35
SLIDE 35

Breaking the input polynomial into...

... two polynomials of half the degree

1

For a set X = {x0, . . . , xn} and polynomial p(x), let p

  • X
  • =
  • x0, p(x0)
  • , . . . ,
  • xn, p(xn)
  • .

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2), where

u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

3

all even degree terms in u(·), all odd degree terms in v(·).

4

maximum degree of u(y), v(y) is n/2.

Sariel (UIUC) New CS473 13 Fall 2015 13 / 38

slide-36
SLIDE 36

Breaking the input polynomial into...

... two polynomials of half the degree

1

For a set X = {x0, . . . , xn} and polynomial p(x), let p

  • X
  • =
  • x0, p(x0)
  • , . . . ,
  • xn, p(xn)
  • .

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2), where

u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

3

all even degree terms in u(·), all odd degree terms in v(·).

4

maximum degree of u(y), v(y) is n/2.

Sariel (UIUC) New CS473 13 Fall 2015 13 / 38

slide-37
SLIDE 37

Breaking the input polynomial into...

... two polynomials of half the degree

1

For a set X = {x0, . . . , xn} and polynomial p(x), let p

  • X
  • =
  • x0, p(x0)
  • , . . . ,
  • xn, p(xn)
  • .

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2), where

u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

3

all even degree terms in u(·), all odd degree terms in v(·).

4

maximum degree of u(y), v(y) is n/2.

Sariel (UIUC) New CS473 13 Fall 2015 13 / 38

slide-38
SLIDE 38

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-39
SLIDE 39

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-40
SLIDE 40

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-41
SLIDE 41

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-42
SLIDE 42

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-43
SLIDE 43

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-44
SLIDE 44

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-45
SLIDE 45

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-46
SLIDE 46

FFT: The dividing stage

1

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

2

Ψ: collapsible set of size n.

3

p(Ψ): compute polynomial of degree n − 1 on n values.

4

Decompose: u(y) =

n/2−1

  • i=0

a2iyi and v(y) =

n/2−1

  • i=0

a1+2iyi.

5

Need to compute u(x2), for all x ∈ Ψ.

6

Need to compute v(x2), for all x ∈ Ψ.

7

SQ(Ψ) =

  • x2
  • x ∈ Ψ
  • .

8

= ⇒ Need to compute u(SQ(Ψ)), v(SQ(Ψ)).

9

u(SQ(Ψ)), v(SQ(Ψ)): comp. poly. degree n

2 − 1 on n 2

values.

Sariel (UIUC) New CS473 14 Fall 2015 14 / 38

slide-47
SLIDE 47

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-48
SLIDE 48

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-49
SLIDE 49

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-50
SLIDE 50

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-51
SLIDE 51

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-52
SLIDE 52

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-53
SLIDE 53

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-54
SLIDE 54

FFT: The conquering stage

1

Ψ: Collapsible set of size n.

2

p(x) = n−1

i=0 aixi as p(x) = u(x2) + x · v(x2).

3

u(y) = n/2−1

i=0

a2iyi and v(y) = n/2−1

i=0

a1+2iyi.

4

u(SQ(Ψ)), v(SQ(Ψ)): Computed recursively.

5

Need to compute p(Ψ).

6

For x ∈ Ψ: Compute p(x) = u(x2) + x · v(x2).

7

Takes constant time per single element x ∈ Ψ.

8

Takes O(n) time overall.

Sariel (UIUC) New CS473 15 Fall 2015 15 / 38

slide-55
SLIDE 55

FFT algorithm

FFTAlg(p, X)// X: A collapsible set of n elements. input: p(x): polynomial deg. n: p(x) = n−1

i=0 aixi

  • utput:

p(X) u(y) = n/2−1

i=0

a2iyi v(y) = n/2−1

i=0

a1+2iyi. Y = SQ(X) =

  • x2
  • x ∈ X
  • .

U = FFTAlg(u, Y ) // U = u(Y ) V = FFTAlg(v, Y ) // V = v(Y ) Out ← ∅

for x ∈ X do

// p(x) = u(x2) + x ∗ v(x2) (x, p(x)) ← (x, U[x2] + x · V [x2]) // U[x2] ≡ u(x2) Out ← Out ∪ {(x, p(x))}

return Out

Sariel (UIUC) New CS473 16 Fall 2015 16 / 38

slide-56
SLIDE 56

Running time analysis...

...an old foe emerges once again to serve

1

T (m, n): Time of computing a polynomial of degree m on n values.

2

We have that: T (n − 1, n) = 2T (n/2 − 1, n/2) + O(n).

3

The solution to this recurrence is O(n log n).

Sariel (UIUC) New CS473 17 Fall 2015 17 / 38

slide-57
SLIDE 57

Running time analysis...

...an old foe emerges once again to serve

1

T (m, n): Time of computing a polynomial of degree m on n values.

2

We have that: T (n − 1, n) = 2T (n/2 − 1, n/2) + O(n).

3

The solution to this recurrence is O(n log n).

Sariel (UIUC) New CS473 17 Fall 2015 17 / 38

slide-58
SLIDE 58

Running time analysis...

...an old foe emerges once again to serve

1

T (m, n): Time of computing a polynomial of degree m on n values.

2

We have that: T (n − 1, n) = 2T (n/2 − 1, n/2) + O(n).

3

The solution to this recurrence is O(n log n).

Sariel (UIUC) New CS473 17 Fall 2015 17 / 38

slide-59
SLIDE 59

Generating Collapsible Sets

1

How to generate collapsible sets?

2 Sariel (UIUC) New CS473 18 Fall 2015 18 / 38

slide-60
SLIDE 60

Generating Collapsible Sets

1

How to generate collapsible sets?

2

Trick: Use complex numbers!

Sariel (UIUC) New CS473 18 Fall 2015 18 / 38

slide-61
SLIDE 61

Complex numbers – a quick reminder

1

Complex number: pair (α, β) of real numbers. Written as τ = α + iβ.

2

α: real part, β: imaginary part.

3

i is the root of −1.

4

Geometrically: a point in the complex plane:

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ)

2

r =

  • α2 + β2 and φ = arcsin(β/α).

Sariel (UIUC) New CS473 19 Fall 2015 19 / 38

slide-62
SLIDE 62

Complex numbers – a quick reminder

1

Complex number: pair (α, β) of real numbers. Written as τ = α + iβ.

2

α: real part, β: imaginary part.

3

i is the root of −1.

4

Geometrically: a point in the complex plane:

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ)

2

r =

  • α2 + β2 and φ = arcsin(β/α).

Sariel (UIUC) New CS473 19 Fall 2015 19 / 38

slide-63
SLIDE 63

Complex numbers – a quick reminder

1

Complex number: pair (α, β) of real numbers. Written as τ = α + iβ.

2

α: real part, β: imaginary part.

3

i is the root of −1.

4

Geometrically: a point in the complex plane:

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ)

2

r =

  • α2 + β2 and φ = arcsin(β/α).

Sariel (UIUC) New CS473 19 Fall 2015 19 / 38

slide-64
SLIDE 64

Complex numbers – a quick reminder

1

Complex number: pair (α, β) of real numbers. Written as τ = α + iβ.

2

α: real part, β: imaginary part.

3

i is the root of −1.

4

Geometrically: a point in the complex plane:

Im Re α β τ = α + βi

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ)

2

r =

  • α2 + β2 and φ = arcsin(β/α).

Sariel (UIUC) New CS473 19 Fall 2015 19 / 38

slide-65
SLIDE 65

Complex numbers – a quick reminder

1

Complex number: pair (α, β) of real numbers. Written as τ = α + iβ.

2

α: real part, β: imaginary part.

3

i is the root of −1.

4

Geometrically: a point in the complex plane:

Im Re α β τ = α + βi

r φ

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ)

2

r =

  • α2 + β2 and φ = arcsin(β/α).

Sariel (UIUC) New CS473 19 Fall 2015 19 / 38

slide-66
SLIDE 66

Complex numbers – a quick reminder

1

Complex number: pair (α, β) of real numbers. Written as τ = α + iβ.

2

α: real part, β: imaginary part.

3

i is the root of −1.

4

Geometrically: a point in the complex plane:

Im Re α β τ = α + βi

r φ

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ)

2

r =

  • α2 + β2 and φ = arcsin(β/α).

Sariel (UIUC) New CS473 19 Fall 2015 19 / 38

slide-67
SLIDE 67

A useful formula: cos φ + i sin φ = eiφ

1

By Taylor’s expansion: sin x = x − x3 3! + x5 5! − x7 7! + · · · , cos x = 1 − x2 2! + x4 4! − x6 6! + · · · , and ex = 1 + x 1! + x2 2! + x3 3! + · · · .

2

Since i2 = −1: eix = 1 + i x 1! − x2 2! − ix3 3! + x4 4! + ix5 5! − x6 6! · · · = cos x + i sin x.

Sariel (UIUC) New CS473 20 Fall 2015 20 / 38

slide-68
SLIDE 68

A useful formula: cos φ + i sin φ = eiφ

1

By Taylor’s expansion: sin x = x − x3 3! + x5 5! − x7 7! + · · · , cos x = 1 − x2 2! + x4 4! − x6 6! + · · · , and ex = 1 + x 1! + x2 2! + x3 3! + · · · .

2

Since i2 = −1: eix = 1 + i x 1! − x2 2! − ix3 3! + x4 4! + ix5 5! − x6 6! · · · = cos x + i sin x.

Sariel (UIUC) New CS473 20 Fall 2015 20 / 38

slide-69
SLIDE 69

Back to polar form

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ) = reiφ,

2

τ = reiφ, τ ′ = r′eiφ′: complex numbers.

3

τ · τ ′ = reiφ · r′eiφ′ = rr′ei(φ+φ′).

4

eiφ is 2π periodic (i.e., eiφ = ei(φ+2π)), and 1 = ei0.

5

nth root of 1: complex number τ – raise it to power n get 1.

6

τ = reiφ, such that τ n = rneinφ = ei0.

7

= ⇒ r = 1, and there must be an integer j, such that nφ = 0 + 2πj = ⇒ φ = j(2π/n).

Sariel (UIUC) New CS473 21 Fall 2015 21 / 38

slide-70
SLIDE 70

Back to polar form

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ) = reiφ,

2

τ = reiφ, τ ′ = r′eiφ′: complex numbers.

3

τ · τ ′ = reiφ · r′eiφ′ = rr′ei(φ+φ′).

4

eiφ is 2π periodic (i.e., eiφ = ei(φ+2π)), and 1 = ei0.

5

nth root of 1: complex number τ – raise it to power n get 1.

6

τ = reiφ, such that τ n = rneinφ = ei0.

7

= ⇒ r = 1, and there must be an integer j, such that nφ = 0 + 2πj = ⇒ φ = j(2π/n).

Sariel (UIUC) New CS473 21 Fall 2015 21 / 38

slide-71
SLIDE 71

Back to polar form

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ) = reiφ,

2

τ = reiφ, τ ′ = r′eiφ′: complex numbers.

3

τ · τ ′ = reiφ · r′eiφ′ = rr′ei(φ+φ′).

4

eiφ is 2π periodic (i.e., eiφ = ei(φ+2π)), and 1 = ei0.

5

nth root of 1: complex number τ – raise it to power n get 1.

6

τ = reiφ, such that τ n = rneinφ = ei0.

7

= ⇒ r = 1, and there must be an integer j, such that nφ = 0 + 2πj = ⇒ φ = j(2π/n).

Sariel (UIUC) New CS473 21 Fall 2015 21 / 38

slide-72
SLIDE 72

Back to polar form

1

polar form: τ = r cos φ + ir sin φ = r(cos φ + i sin φ) = reiφ,

2

τ = reiφ, τ ′ = r′eiφ′: complex numbers.

3

τ · τ ′ = reiφ · r′eiφ′ = rr′ei(φ+φ′).

4

eiφ is 2π periodic (i.e., eiφ = ei(φ+2π)), and 1 = ei0.

5

nth root of 1: complex number τ – raise it to power n get 1.

6

τ = reiφ, such that τ n = rneinφ = ei0.

7

= ⇒ r = 1, and there must be an integer j, such that nφ = 0 + 2πj = ⇒ φ = j(2π/n).

Sariel (UIUC) New CS473 21 Fall 2015 21 / 38

slide-73
SLIDE 73

Roots of unity

The desire to avoid war?

For j = 0, . . . , n − 1, we get the n distinct roots of unity.

1 γ1(4) = β3(4) = i γ2(4) = β2(4) = −1 γ3(4) = β1(4) = −i

1 γ1(8) = β7(8) γ2(8) = β6(8) = i γ3(8) = β5(8) γ4(8) = β4(8) = −1 γ5(8) = β3(8) γ6(8) = β2(8) = −i γ7(8) = β1(8)

(n = 4) (n = 8) (n = 16)

Sariel (UIUC) New CS473 22 Fall 2015 22 / 38

slide-74
SLIDE 74

Back to collapsible sets

1

Can do all basic calculations on complex numbers in O(1) time.

2

Idea: Work over the complex numbers.

3

Use roots of unity!

4

γ: nth root of unity. There are n such roots, and let γj(n) denote the jth root. γj(n) = cos((2πj)/n) + i sin((2πj)/n) = γj. Let A(n) = {γ0(n), . . . , γn−1(n)}.

5

|SQ(A(n))| has n/2 entries.

6

SQ(A(n)) = A(n/2)

7

n to be a power of 2, then A(n) is the required collapsible set.

Sariel (UIUC) New CS473 23 Fall 2015 23 / 38

slide-75
SLIDE 75

Back to collapsible sets

1

Can do all basic calculations on complex numbers in O(1) time.

2

Idea: Work over the complex numbers.

3

Use roots of unity!

4

γ: nth root of unity. There are n such roots, and let γj(n) denote the jth root. γj(n) = cos((2πj)/n) + i sin((2πj)/n) = γj. Let A(n) = {γ0(n), . . . , γn−1(n)}.

5

|SQ(A(n))| has n/2 entries.

6

SQ(A(n)) = A(n/2)

7

n to be a power of 2, then A(n) is the required collapsible set.

Sariel (UIUC) New CS473 23 Fall 2015 23 / 38

slide-76
SLIDE 76

Back to collapsible sets

1

Can do all basic calculations on complex numbers in O(1) time.

2

Idea: Work over the complex numbers.

3

Use roots of unity!

4

γ: nth root of unity. There are n such roots, and let γj(n) denote the jth root. γj(n) = cos((2πj)/n) + i sin((2πj)/n) = γj. Let A(n) = {γ0(n), . . . , γn−1(n)}.

5

|SQ(A(n))| has n/2 entries.

6

SQ(A(n)) = A(n/2)

7

n to be a power of 2, then A(n) is the required collapsible set.

Sariel (UIUC) New CS473 23 Fall 2015 23 / 38

slide-77
SLIDE 77

Back to collapsible sets

1

Can do all basic calculations on complex numbers in O(1) time.

2

Idea: Work over the complex numbers.

3

Use roots of unity!

4

γ: nth root of unity. There are n such roots, and let γj(n) denote the jth root. γj(n) = cos((2πj)/n) + i sin((2πj)/n) = γj. Let A(n) = {γ0(n), . . . , γn−1(n)}.

5

|SQ(A(n))| has n/2 entries.

6

SQ(A(n)) = A(n/2)

7

n to be a power of 2, then A(n) is the required collapsible set.

Sariel (UIUC) New CS473 23 Fall 2015 23 / 38

slide-78
SLIDE 78

Back to collapsible sets

1

Can do all basic calculations on complex numbers in O(1) time.

2

Idea: Work over the complex numbers.

3

Use roots of unity!

4

γ: nth root of unity. There are n such roots, and let γj(n) denote the jth root. γj(n) = cos((2πj)/n) + i sin((2πj)/n) = γj. Let A(n) = {γ0(n), . . . , γn−1(n)}.

5

|SQ(A(n))| has n/2 entries.

6

SQ(A(n)) = A(n/2)

7

n to be a power of 2, then A(n) is the required collapsible set.

Sariel (UIUC) New CS473 23 Fall 2015 23 / 38

slide-79
SLIDE 79

Back to collapsible sets

1

Can do all basic calculations on complex numbers in O(1) time.

2

Idea: Work over the complex numbers.

3

Use roots of unity!

4

γ: nth root of unity. There are n such roots, and let γj(n) denote the jth root. γj(n) = cos((2πj)/n) + i sin((2πj)/n) = γj. Let A(n) = {γ0(n), . . . , γn−1(n)}.

5

|SQ(A(n))| has n/2 entries.

6

SQ(A(n)) = A(n/2)

7

n to be a power of 2, then A(n) is the required collapsible set.

Sariel (UIUC) New CS473 23 Fall 2015 23 / 38

slide-80
SLIDE 80

Back to collapsible sets

1

Can do all basic calculations on complex numbers in O(1) time.

2

Idea: Work over the complex numbers.

3

Use roots of unity!

4

γ: nth root of unity. There are n such roots, and let γj(n) denote the jth root. γj(n) = cos((2πj)/n) + i sin((2πj)/n) = γj. Let A(n) = {γ0(n), . . . , γn−1(n)}.

5

|SQ(A(n))| has n/2 entries.

6

SQ(A(n)) = A(n/2)

7

n to be a power of 2, then A(n) is the required collapsible set.

Sariel (UIUC) New CS473 23 Fall 2015 23 / 38

slide-81
SLIDE 81

The first result...

Theorem

Given polynomial p(x) of degree n, where n is a power of two, then we can compute p(X) in O(n log n) time, where X = A(n) is the set of n different powers of the nth root of unity over the complex numbers.

Sariel (UIUC) New CS473 24 Fall 2015 24 / 38

slide-82
SLIDE 82

Problem...

We can go, but can we come back?

1

Can multiply two polynomials quickly

2

by transforming them to the point-value pairs representation...

3

  • ver the nth roots of unity.

4

Q: How to transform this representation back to the regular representation.

5

A: Do some confusing math...

Sariel (UIUC) New CS473 25 Fall 2015 25 / 38

slide-83
SLIDE 83

Problem...

We can go, but can we come back?

1

Can multiply two polynomials quickly

2

by transforming them to the point-value pairs representation...

3

  • ver the nth roots of unity.

4

Q: How to transform this representation back to the regular representation.

5

A: Do some confusing math...

Sariel (UIUC) New CS473 25 Fall 2015 25 / 38

slide-84
SLIDE 84

Problem...

We can go, but can we come back?

1

Can multiply two polynomials quickly

2

by transforming them to the point-value pairs representation...

3

  • ver the nth roots of unity.

4

Q: How to transform this representation back to the regular representation.

5

A: Do some confusing math...

Sariel (UIUC) New CS473 25 Fall 2015 25 / 38

slide-85
SLIDE 85

Problem...

We can go, but can we come back?

1

Can multiply two polynomials quickly

2

by transforming them to the point-value pairs representation...

3

  • ver the nth roots of unity.

4

Q: How to transform this representation back to the regular representation.

5

A: Do some confusing math...

Sariel (UIUC) New CS473 25 Fall 2015 25 / 38

slide-86
SLIDE 86

Problem...

We can go, but can we come back?

1

Can multiply two polynomials quickly

2

by transforming them to the point-value pairs representation...

3

  • ver the nth roots of unity.

4

Q: How to transform this representation back to the regular representation.

5

A: Do some confusing math...

Sariel (UIUC) New CS473 25 Fall 2015 25 / 38

slide-87
SLIDE 87

23.3: Recovering the polynomial

Sariel (UIUC) New CS473 26 Fall 2015 26 / 38

slide-88
SLIDE 88

Recovering the polynomial

Think about FFT as a matrix multiplication operator. p(x) = n−1

i=0 aixi. Evaluating p(·) on A(n):

       y0 y1 y2 . . . yn−1        =            1 γ0 γ2 γ3 · · · γn−1 1 γ1 γ2

1

γ3

1

· · · γn−1

1

1 γ2 γ2

2

γ3

2

· · · γn−1

2

1 γ3 γ2

3

γ3

3

· · · γn−1

3

. . . . . . . . . . . . · · · . . . 1 γn−1 γ2

n−1

γ3

n−1

· · · γn−1

n−1

          

  • the matrix V

         a0 a1 a2 a3 . . . an−1          , where γj = γj(n) = (γ1(n))j is the jth power of the nth root of unity, and yj = p(γj).

Sariel (UIUC) New CS473 27 Fall 2015 27 / 38

slide-89
SLIDE 89

The Vandermonde matrix

Because every matrix needs a name

V is the Vandermonde matrix. V −1: inverse matrix of V Vandermonde matrix. And let multiply the above formula from the

  • left. We get:

       y0 y1 y2 . . . yn−1        = V          a0 a1 a2 a3 . . . an−1          = ⇒          a0 a1 a2 a3 . . . an−1          = V −1        y0 y1 y2 . . . yn−1       

Sariel (UIUC) New CS473 28 Fall 2015 28 / 38

slide-90
SLIDE 90

The inverse Vandermonde matrix

..for the rescue

1

Recover the polynomial p(x) from the point-value pairs

  • (γ0, p(γ0)), (γ1, p(γ1)), . . . , (γn−1, p(γn−1))
  • 2

by doing a single matrix multiplication of V −1 by the vector [y0, y1, . . . , yn−1].

3

Multiplying a vector with n entries with n × n matrix takes O(n2) time.

4

No benefit so far...

Sariel (UIUC) New CS473 29 Fall 2015 29 / 38

slide-91
SLIDE 91

The inverse Vandermonde matrix

..for the rescue

1

Recover the polynomial p(x) from the point-value pairs

  • (γ0, p(γ0)), (γ1, p(γ1)), . . . , (γn−1, p(γn−1))
  • 2

by doing a single matrix multiplication of V −1 by the vector [y0, y1, . . . , yn−1].

3

Multiplying a vector with n entries with n × n matrix takes O(n2) time.

4

No benefit so far...

Sariel (UIUC) New CS473 29 Fall 2015 29 / 38

slide-92
SLIDE 92

The inverse Vandermonde matrix

..for the rescue

1

Recover the polynomial p(x) from the point-value pairs

  • (γ0, p(γ0)), (γ1, p(γ1)), . . . , (γn−1, p(γn−1))
  • 2

by doing a single matrix multiplication of V −1 by the vector [y0, y1, . . . , yn−1].

3

Multiplying a vector with n entries with n × n matrix takes O(n2) time.

4

No benefit so far...

Sariel (UIUC) New CS473 29 Fall 2015 29 / 38

slide-93
SLIDE 93

The inverse Vandermonde matrix

..for the rescue

1

Recover the polynomial p(x) from the point-value pairs

  • (γ0, p(γ0)), (γ1, p(γ1)), . . . , (γn−1, p(γn−1))
  • 2

by doing a single matrix multiplication of V −1 by the vector [y0, y1, . . . , yn−1].

3

Multiplying a vector with n entries with n × n matrix takes O(n2) time.

4

No benefit so far...

Sariel (UIUC) New CS473 29 Fall 2015 29 / 38

slide-94
SLIDE 94

What is the inverse of the Vandermonde matrix

Vandermonde matrix is famous, beautiful and well known – a celebrity matrix

Claim

V −1 = 1 n          1 β0 β2 β3 · · · βn−1 1 β1 β2

1

β3

1

· · · βn−1

1

1 β2 β2

2

β3

2

· · · βn−1

2

1 β3 β2

3

β3

3

· · · βn−1

3

. . . . . . . . . . . . · · · . . . 1 βn−1 β2

n−1

β3

n−1

· · · βn−1

n−1

         , where βj = (γj(n))−1.

Sariel (UIUC) New CS473 30 Fall 2015 30 / 38

slide-95
SLIDE 95

Proof

Consider the (u, v) entry in the matrix C = V −1V . We have Cu,v =

n−1

  • j=0

(βu)j(γj)v n . As γj = (γ1)j.Thus, Cu,v =

n−1

  • j=0

(βu)j((γ1)j)v n =

n−1

  • j=0

(βu)j((γ1)v)j n =

n−1

  • j=0

(βuγv)j n . Clearly, if u = v then Cu,u = 1 n

n−1

  • j=0

(βuγu)j = 1 n

n−1

  • j=0

(1)j = n n = 1.

Sariel (UIUC) New CS473 31 Fall 2015 31 / 38

slide-96
SLIDE 96

Proof continued...

If u = v then, βuγv = (γu)−1γv = (γ1)−uγv

1 = (γ1)v−u = γv−u.

And Cu,v = 1 n

n−1

  • j=0

(γv−u)j = 1 n · γn

v−u − 1

γv−u − 1 = 1 n · 1 − 1 γv−u − 1 = 0, Proved that the matrix C have ones on the diagonal and zero everywhere else.

Sariel (UIUC) New CS473 32 Fall 2015 32 / 38

slide-97
SLIDE 97

Recap...

1

n point-value pairs {(γ0, y0), . . . , (γn−1, yn−1)}: of polynomial p(x) = n−1

i=0 aixi over nth roots of unity.

2

Recover coefficients of polynomial by multiplying [y0, y1, . . . , yn] by V −1:        a0 a1 a2 . . . an−1        = 1 n          1 β0 β2 β3 · · · βn−1 1 β1 β2

1

β3

1

· · · βn−1

1

1 β2 β2

2

β3

2

· · · βn−1

2

1 β3 β2

3

β3

3

· · · βn−1

3

. . . . . . . . . . . . · · · . . . 1 βn−1 β2

n−1

β3

n−1

· · · βn−1

n−1

        

  • V −1

         y0 y1 y2 y3 . . . yn−1         

3

W (x) =

n−1

  • i=0

(yi/n)xi: ai = W (βi).

Sariel (UIUC) New CS473 33 Fall 2015 33 / 38

slide-98
SLIDE 98

Recap...

1

n point-value pairs {(γ0, y0), . . . , (γn−1, yn−1)}: of polynomial p(x) = n−1

i=0 aixi over nth roots of unity.

2

Recover coefficients of polynomial by multiplying [y0, y1, . . . , yn] by V −1:        a0 a1 a2 . . . an−1        = 1 n          1 β0 β2 β3 · · · βn−1 1 β1 β2

1

β3

1

· · · βn−1

1

1 β2 β2

2

β3

2

· · · βn−1

2

1 β3 β2

3

β3

3

· · · βn−1

3

. . . . . . . . . . . . · · · . . . 1 βn−1 β2

n−1

β3

n−1

· · · βn−1

n−1

        

  • V −1

         y0 y1 y2 y3 . . . yn−1         

3

W (x) =

n−1

  • i=0

(yi/n)xi: ai = W (βi).

Sariel (UIUC) New CS473 33 Fall 2015 33 / 38

slide-99
SLIDE 99

Recap...

1

n point-value pairs {(γ0, y0), . . . , (γn−1, yn−1)}: of polynomial p(x) = n−1

i=0 aixi over nth roots of unity.

2

Recover coefficients of polynomial by multiplying [y0, y1, . . . , yn] by V −1:        a0 a1 a2 . . . an−1        = 1 n          1 β0 β2 β3 · · · βn−1 1 β1 β2

1

β3

1

· · · βn−1

1

1 β2 β2

2

β3

2

· · · βn−1

2

1 β3 β2

3

β3

3

· · · βn−1

3

. . . . . . . . . . . . · · · . . . 1 βn−1 β2

n−1

β3

n−1

· · · βn−1

n−1

        

  • V −1

         y0 y1 y2 y3 . . . yn−1         

3

W (x) =

n−1

  • i=0

(yi/n)xi: ai = W (βi).

Sariel (UIUC) New CS473 33 Fall 2015 33 / 38

slide-100
SLIDE 100

Recovering continued...

1

recover coefficients of p(·)...

2

... compute W (·) on n values: β0, . . . , βn−1.

3

{β0, . . . , βn−1} = {γ0, . . . , γn−1}.

4

Indeed βn

i = (γ−1 i

)n = (γn

i )−1 = 1−1 = 1.

5

Apply the FFTAlg algorithm on W (x) to compute a0, . . . , an−1.

Sariel (UIUC) New CS473 34 Fall 2015 34 / 38

slide-101
SLIDE 101

Recovering continued...

1

recover coefficients of p(·)...

2

... compute W (·) on n values: β0, . . . , βn−1.

3

{β0, . . . , βn−1} = {γ0, . . . , γn−1}.

4

Indeed βn

i = (γ−1 i

)n = (γn

i )−1 = 1−1 = 1.

5

Apply the FFTAlg algorithm on W (x) to compute a0, . . . , an−1.

Sariel (UIUC) New CS473 34 Fall 2015 34 / 38

slide-102
SLIDE 102

Recovering continued...

1

recover coefficients of p(·)...

2

... compute W (·) on n values: β0, . . . , βn−1.

3

{β0, . . . , βn−1} = {γ0, . . . , γn−1}.

4

Indeed βn

i = (γ−1 i

)n = (γn

i )−1 = 1−1 = 1.

5

Apply the FFTAlg algorithm on W (x) to compute a0, . . . , an−1.

Sariel (UIUC) New CS473 34 Fall 2015 34 / 38

slide-103
SLIDE 103

Recovering continued...

1

recover coefficients of p(·)...

2

... compute W (·) on n values: β0, . . . , βn−1.

3

{β0, . . . , βn−1} = {γ0, . . . , γn−1}.

4

Indeed βn

i = (γ−1 i

)n = (γn

i )−1 = 1−1 = 1.

5

Apply the FFTAlg algorithm on W (x) to compute a0, . . . , an−1.

Sariel (UIUC) New CS473 34 Fall 2015 34 / 38

slide-104
SLIDE 104

Recovering continued...

1

recover coefficients of p(·)...

2

... compute W (·) on n values: β0, . . . , βn−1.

3

{β0, . . . , βn−1} = {γ0, . . . , γn−1}.

4

Indeed βn

i = (γ−1 i

)n = (γn

i )−1 = 1−1 = 1.

5

Apply the FFTAlg algorithm on W (x) to compute a0, . . . , an−1.

Sariel (UIUC) New CS473 34 Fall 2015 34 / 38

slide-105
SLIDE 105

Result

Theorem

Given n point-value pairs of a polynomial p(x) of degree n − 1 over the set of n powers of the nth roots of unity, we can recover the polynomial p(x) in O(n log n) time.

Theorem

Given two polynomials of degree n, they can be multiplied in O(n log n) time.

Sariel (UIUC) New CS473 35 Fall 2015 35 / 38

slide-106
SLIDE 106

23.4: Convolutions

Sariel (UIUC) New CS473 36 Fall 2015 36 / 38

slide-107
SLIDE 107

Convolutions

1

Two vectors: A = [a0, a1, . . . , an] and B = [b0, . . . , bn].

2

dot product A · B = A, B = n

i=0 aibi.

3

Ar: shifting of A by n − r locations to the left

4

Padded with zeros:, aj = 0 for j / ∈ {0, . . . , n}).

5

Ar =

  • an−r, an+1−r, an+2−r, . . . , a2n−r
  • where aj = 0 if j /

  • 0, . . . , n
  • .

6

Observation: An = A.

Sariel (UIUC) New CS473 37 Fall 2015 37 / 38

slide-108
SLIDE 108

Convolutions

1

Two vectors: A = [a0, a1, . . . , an] and B = [b0, . . . , bn].

2

dot product A · B = A, B = n

i=0 aibi.

3

Ar: shifting of A by n − r locations to the left

4

Padded with zeros:, aj = 0 for j / ∈ {0, . . . , n}).

5

Ar =

  • an−r, an+1−r, an+2−r, . . . , a2n−r
  • where aj = 0 if j /

  • 0, . . . , n
  • .

6

Observation: An = A.

Sariel (UIUC) New CS473 37 Fall 2015 37 / 38

slide-109
SLIDE 109

Convolutions

1

Two vectors: A = [a0, a1, . . . , an] and B = [b0, . . . , bn].

2

dot product A · B = A, B = n

i=0 aibi.

3

Ar: shifting of A by n − r locations to the left

4

Padded with zeros:, aj = 0 for j / ∈ {0, . . . , n}).

5

Ar =

  • an−r, an+1−r, an+2−r, . . . , a2n−r
  • where aj = 0 if j /

  • 0, . . . , n
  • .

6

Observation: An = A.

Sariel (UIUC) New CS473 37 Fall 2015 37 / 38

slide-110
SLIDE 110

Convolutions

1

Two vectors: A = [a0, a1, . . . , an] and B = [b0, . . . , bn].

2

dot product A · B = A, B = n

i=0 aibi.

3

Ar: shifting of A by n − r locations to the left

4

Padded with zeros:, aj = 0 for j / ∈ {0, . . . , n}).

5

Ar =

  • an−r, an+1−r, an+2−r, . . . , a2n−r
  • where aj = 0 if j /

  • 0, . . . , n
  • .

6

Observation: An = A.

Sariel (UIUC) New CS473 37 Fall 2015 37 / 38

slide-111
SLIDE 111

Convolutions

1

Two vectors: A = [a0, a1, . . . , an] and B = [b0, . . . , bn].

2

dot product A · B = A, B = n

i=0 aibi.

3

Ar: shifting of A by n − r locations to the left

4

Padded with zeros:, aj = 0 for j / ∈ {0, . . . , n}).

5

Ar =

  • an−r, an+1−r, an+2−r, . . . , a2n−r
  • where aj = 0 if j /

  • 0, . . . , n
  • .

6

Observation: An = A.

Sariel (UIUC) New CS473 37 Fall 2015 37 / 38

slide-112
SLIDE 112

Convolutions

1

Two vectors: A = [a0, a1, . . . , an] and B = [b0, . . . , bn].

2

dot product A · B = A, B = n

i=0 aibi.

3

Ar: shifting of A by n − r locations to the left

4

Padded with zeros:, aj = 0 for j / ∈ {0, . . . , n}).

5

Ar =

  • an−r, an+1−r, an+2−r, . . . , a2n−r
  • where aj = 0 if j /

  • 0, . . . , n
  • .

6

Observation: An = A.

Sariel (UIUC) New CS473 37 Fall 2015 37 / 38

slide-113
SLIDE 113

Example of shifting

Example

For A = [3, 7, 9, 15], n = 3 A2 = [7, 9, 15, 0], A5 = [0, 0, 3, 7].

Sariel (UIUC) New CS473 38 Fall 2015 38 / 38

slide-114
SLIDE 114

Definition

Definition

Let ci = Ai · B = 2n−i

j=n−i ajbj−n+i, for i = 0, . . . , 2n. The

vector [c0, . . . , c2n] is the convolution of A and B.

question

How to compute the convolution of two vectors of length n?

Sariel (UIUC) New CS473 39 Fall 2015 39 / 38

slide-115
SLIDE 115

Convolution via multiplication polynomials

1

p(x) = n

i=0 αixi, and q(x) = n i=0 βixi.

2

Coefficient of xi in r(x) = p(x)q(x) is di = i

j=0 αjβi−j.

3

Want to compute ci = Ai · B = 2n−i

j=n−i ajbj−n+i.

4

Set αi = ai and βl = bn−l−1.

Sariel (UIUC) New CS473 40 Fall 2015 40 / 38

slide-116
SLIDE 116

Convolution via multiplication polynomials

1

p(x) = n

i=0 αixi, and q(x) = n i=0 βixi.

2

Coefficient of xi in r(x) = p(x)q(x) is di = i

j=0 αjβi−j.

3

Want to compute ci = Ai · B = 2n−i

j=n−i ajbj−n+i.

4

Set αi = ai and βl = bn−l−1.

Sariel (UIUC) New CS473 40 Fall 2015 40 / 38

slide-117
SLIDE 117

Convolution via multiplication polynomials

1

p(x) = n

i=0 αixi, and q(x) = n i=0 βixi.

2

Coefficient of xi in r(x) = p(x)q(x) is di = i

j=0 αjβi−j.

3

Want to compute ci = Ai · B = 2n−i

j=n−i ajbj−n+i.

4

Set αi = ai and βl = bn−l−1.

Sariel (UIUC) New CS473 40 Fall 2015 40 / 38

slide-118
SLIDE 118

Convolution via multiplication polynomials

1

p(x) = n

i=0 αixi, and q(x) = n i=0 βixi.

2

Coefficient of xi in r(x) = p(x)q(x) is di = i

j=0 αjβi−j.

3

Want to compute ci = Ai · B = 2n−i

j=n−i ajbj−n+i.

4

Set αi = ai and βl = bn−l−1.

Sariel (UIUC) New CS473 40 Fall 2015 40 / 38

slide-119
SLIDE 119

Convolution by example

1

Consider coefficient of x2 in product of p(x) = a0 + a1x + a2x2 + a3x3 and q(x) = b0 + b1x + b2x2 + b3x3.

2

Sum of the entries on the anti diagonal: a0+ a1x +a2x2 +a3x3 b0 a2b0x2 +b1x a1b1x2 +b2x2 a0b2x2 +b3x3

3

entry in the ith row and jth column is aibj.

Sariel (UIUC) New CS473 41 Fall 2015 41 / 38

slide-120
SLIDE 120

Convolution by example

1

Consider coefficient of x2 in product of p(x) = a0 + a1x + a2x2 + a3x3 and q(x) = b0 + b1x + b2x2 + b3x3.

2

Sum of the entries on the anti diagonal: a0+ a1x +a2x2 +a3x3 b0 a2b0x2 +b1x a1b1x2 +b2x2 a0b2x2 +b3x3

3

entry in the ith row and jth column is aibj.

Sariel (UIUC) New CS473 41 Fall 2015 41 / 38

slide-121
SLIDE 121

Convolution by example

1

Consider coefficient of x2 in product of p(x) = a0 + a1x + a2x2 + a3x3 and q(x) = b0 + b1x + b2x2 + b3x3.

2

Sum of the entries on the anti diagonal: a0+ a1x +a2x2 +a3x3 b0 a2b0x2 +b1x a1b1x2 +b2x2 a0b2x2 +b3x3

3

entry in the ith row and jth column is aibj.

Sariel (UIUC) New CS473 41 Fall 2015 41 / 38

slide-122
SLIDE 122

Convolution

Theorem

Given two vectors A = [a0, a1, . . . , an], B = [b0, . . . , bn] one can compute their convolution in O(n log n) time.

Proof.

Let p(x) = n

i=0 an−ixi and let q(x) = n i=0 bixi. Compute

r(x) = p(x)q(x) in O(n log n) time using the convolution

  • theorem. Let c0, . . . , c2n be the coefficients of r(x). It is easy to

verify, as described above, that [c0, . . . , c2n] is the convolution of A and B.

Sariel (UIUC) New CS473 42 Fall 2015 42 / 38

slide-123
SLIDE 123

Notes

Sariel (UIUC) New CS473 43 Fall 2015 43 / 38

slide-124
SLIDE 124

Notes

Sariel (UIUC) New CS473 44 Fall 2015 44 / 38

slide-125
SLIDE 125

Notes

Sariel (UIUC) New CS473 45 Fall 2015 45 / 38

slide-126
SLIDE 126

Notes

Sariel (UIUC) New CS473 46 Fall 2015 46 / 38