Notable Transforms and Polynomial Exponentiation
In questa pagina 3
Two applications of the FFT. First, the structure of the vector is exploited to compute the DFT with fewer operations than the general FFT (Fast Fourier TransformThe FFT computes the DFT_n (n a power of two) by divide and conquer: split the coefficients by index parity, p(x) = p0(x^2) + x p1(x^2), and by the halving lemma two DFTs of order n/2 suffice; y_i = y0_i + w^i y1_i and y_{i+n/2} = y0_i - w^i y1_i. The recurrence T(n) = 2T(n/2) + 2n with T(1) = 0 has exact solution 2 n log2 n. The inverse has matrix F^{-1}_{ij} = w^{-ij}/n and is obtained with the FFT on negative powers (then dividing by n outside the recursion) or with a reversed DFT_n(y). LIN_CONV multiplies two polynomials with n coefficients in 12 n log2(2n) + 4n operations.Fast Fourier Transform →); second, the representation by values is used to compute the coefficients of the power . The method is the same as in the whole chapter: modify the substructure property of the FFT with the extra information on the instance and derive the new recurrence.
Transforms known a priori
Component of is the dot product of row of with ; the first row is all ones.
Constant vector. If then .
Proof. . For , by the summation lemma ( is not a multiple of ).
Only the first component. If then .
Proof. and is the first column of , all ones. Equivalently takes the value everywhere.
More generally is column of , . Example : and .
-sparse vectors
Definition. For powers of two, , is -sparse if whenever .
Only the components at multiples of may be nonzero (separated by zeros). An -sparse vector looks like . Extremes: every vector is -sparse; an -sparse vector has only (known DFT).
Goal. A D&C algorithm computing for -sparse with : for the usual , for no operations.
Strengthened substructure. With the even and odd vectors, for ( even):
- is -sparse: is zero if , i.e. ;
- is the zero vector: has odd index, never a multiple of the power of two .
So and the FFT recombination becomes , : the DFT is concatenated with itself, with no arithmetic.
SPARSE_FFT(x, k)
n <- x.len
if k = 1 then return FFT(x)
if k = n then return (x[0], x[0], ..., x[0]) { n copies }
x0 <- (x[0], x[2], ..., x[n-2])
y0 <- SPARSE_FFT(x0, k/2)
for i <- 0 to n/2 - 1
y[i] <- y0[i]; y[i + n/2] <- y0[i]
return yCorrectness follows from that of the FFT and the strengthened substructure, by induction on .
Cost. Conquer contains only assignments (not counted as arithmetic operations): Unfolding: , also valid for and (). If each assignment cost one unit, the work would be linear and the total .
Consequence. The DFT of an -sparse vector is made of copies of . Directly: (cancellation), periodic in with period .
Example (, ). : repeated times: .
Example (decomposition by linearity). : the first is constant with DFT , the second is -sparse with DFT . Sum: .
Strategy (repeatable): look at the structure, decompose (also by linearity) into pieces with known transforms, or rewrite the FFT substructure using the structure and study the recurrence.
Exponentiation of polynomials
Given and an integer , find the coefficients of , i.e. ( times). The degree bound of is .
Approach 1: repeated squaring with convolution
Convolution is associative, so apply Fast Exponentiation by Repeated SquaringPower x^n with an associative operator having an identity, cost = number of applications of the operator; STUPID_POWER costs n-1, the substructure x^n = (x^floor(n/2))^2 (times x for odd n) gives POWER with T(n) = floor(log2 n) + (number of 1 bits of n) - 1, Theta(log n) (worst case 2 floor(log2 n), n = 2^t - 1); iterative versions POWER2 and POWER3 from the binary representation of n; example with the Fibonacci matrix; unit-cost model valid only if the operator does not make operands grow.Fast Exponentiation by Repeated Squaring → with as the operator. Let and : .
EXPONENTIATE(a, k)
d <- floor(log2 k) + 1
h <- k { h = (k_{d-1} ... k_0) in base 2 }
y <- a { at iteration i: y = a^(2^i) }
z <- (1) { identity of the convolution; accumulates the product }
for i <- 0 to d - 1
if h is odd then z <- LIN_CONV(z, y) { digit k_i = 1 }
y <- LIN_CONV(y, y) { y = a^(2^(i+1)) }
h <- floor(h / 2)
return zLIN_CONV is used in its arbitrary-length version (padding to a power of two). Analysis. At the start of iteration , y has length at most (length of is ) and z has length less than . So , and since :
Approach 2: power of the values
Given values of on an extended base with points, the values of are the powers of the values: . So evaluate, raise, interpolate.
EXPONENTIATE2(a, k)
n <- a.len
h <- 2^ceil(log2((n-1)*k + 1)) { first power of two >= (n-1)k+1 }
yp <- FFT((a | 0_{h-n}))
for i <- 0 to h - 1
yq[i] <- POWER3(yp[i], k) { scalar power by squaring, O(log k) }
return INV_FFT(yq)Correctness: has bound , so determines it and INV_FFT returns its coefficients (followed by padding zeros). Cost: FFT and INV_FFT on size : ; plus scalar powers of products each: . Total : the same order as Approach 1, but simpler and with better constants (one forward transform, one inverse and powers, instead of convolutions of ever longer vectors).
Example (, ). , bound of : , so . , :
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
|---|---|---|---|---|---|---|---|---|
(e.g. , so .) The inverse transform is : , with three padding zeros.
Versione ripasso
- Notable (DFT and Roots of UnityThe DFT of order n evaluates a polynomial with degree bound n at the n n-th roots of unity, y_i = p(w^i) with w = e^{2 pi i/n}; it is the product by the Fourier matrix F_n, an invertible Vandermonde matrix. The roots form a multiplicative group and satisfy three lemmas: cancellation (w_{dn}^{dk} = w_n^k, w_n^{n/2} = -1), halving (the squares of the n roots are the n/2 roots of order n/2, each twice) and summation (the sum of the powers of w^k is n if k is a multiple of n, 0 otherwise). Linear convolution theorem: (c|0) = DFT^{-1}{2n}(DFT{2n}(a|0) times DFT_{2n}(b|0)).DFT and Roots of Unity →): (row of all ones; rows by the summation lemma); (first column of ). : , .
- -sparse: if ( powers of two). For : is -sparse (from ) and (odd indices), so with no operations. The DFT is copies of ; directly by cancellation, periodic with period .
- SPARSE_FFT: : FFT; : copies of ; else recurse on and duplicate. Cost (assignments not counted): (Fast Fourier TransformThe FFT computes the DFT_n (n a power of two) by divide and conquer: split the coefficients by index parity, p(x) = p0(x^2) + x p1(x^2), and by the halving lemma two DFTs of order n/2 suffice; y_i = y0_i + w^i y1_i and y_{i+n/2} = y0_i - w^i y1_i. The recurrence T(n) = 2T(n/2) + 2n with T(1) = 0 has exact solution 2 n log2 n. The inverse has matrix F^{-1}_{ij} = w^{-ij}/n and is obtained with the FFT on negative powers (then dividing by n outside the recursion) or with a reversed DFT_n(y). LIN_CONV multiplies two polynomials with n coefficients in 12 n log2(2n) + 4n operations.Fast Fourier Transform →); counting assignments, .
- Examples: : repeated times. , by linearity .
- Strategy: inspect the structure, decompose by linearity or rewrite the FFT substructure, study the two-parameter recurrence.
- Exponentiation, approach 1: of the with (scheme of Fast Exponentiation by Repeated SquaringPower x^n with an associative operator having an identity, cost = number of applications of the operator; STUPID_POWER costs n-1, the substructure x^n = (x^floor(n/2))^2 (times x for odd n) gives POWER with T(n) = floor(log2 n) + (number of 1 bits of n) - 1, Theta(log n) (worst case 2 floor(log2 n), n = 2^t - 1); iterative versions POWER2 and POWER3 from the binary representation of n; example with the Fibonacci matrix; unit-cost model valid only if the operator does not make operands grow.Fast Exponentiation by Repeated Squaring → with LIN_CONV). At iteration vectors have length and cost ; with the total is .
- Approach 2 (EXPONENTIATE2): the degree bound of is ; ; , each value to the with POWER3 (), then
INV_FFT. Cost , simpler than approach 1. Example : , , inverse . - Pseudocode:
EXPONENTIATE(a,k):y <- a; z <- (1); h <- k; for : if oddz <- LIN_CONV(z,y);y <- LIN_CONV(y,y);h <- floor(h/2); returnz.EXPONENTIATE2(a,k):h <- 2^ceil(log2((n-1)k+1));yp <- FFT((a|0));yq[i] <- POWER3(yp[i],k); returnINV_FFT(yq). - Quick check: a polynomial with coefficients raised to the sixth power: , points.
- Common mistakes: using or instead of a power of two ; counting assignments as operations; swapping the families and ; forgetting that sparsity needs a power of two.