Polynomials - Representations and Convolution
In questa pagina 7
The FFT chapter starts from an algebraic problem: multiply two polynomials. The idea is to have two representations of the same object, each with different easy operations, and to convert quickly between them. Here: the two representations, exact costs of the operations and of the general conversions. Polynomials are functions with complex coefficients; the cost is the number of arithmetic operations between complex scalars (each counts ).
Representation by coefficients
Definition (degree bound ). is represented by , written . is the degree bound; the actual degree is .
The vector can be padded with zeros without changing the polynomial: . Padding serves algorithms that require a fixed size, e.g. a power of two (the FFT).
Representation by values and the interpolation theorem
Theorem (interpolation). Given pairs with distinct , there is exactly one polynomial with degree bound such that .
Proof. is the linear system with , a Vandermonde matrix . If there is a unique solution, and Determinant, by induction on . : (empty product). Step: subtract times the previous column from each column, from the last to the second (, ): the determinant is unchanged, the new entry is , and row becomes . Expanding along it and extracting from each row,
Definition (representation by values). For a base with distinct components, is represented by , . Different bases give different representations.
Example. on is . This representation can also be extended (adding , ) but less trivially than coefficient padding.
Sum and product by coefficients
Sum. , cost (with bounds : ).
Product. If , have bound , has degree at most : bound . The coefficient collects all with , with .
Definition (linear convolution). For , with Then . For lengths the result has length .
Example. , : , , , , ; so .
Theorem (cost by definition). with takes products and sums: .
Proof. Each pair , , contributes to exactly one component : products. There are components and one with addends needs sums; total addends , so sums are .
For : . is commutative and associative (as the polynomial product).
Sum and product by values
Only possible if both are represented on the same base : Both cost : the product by values is linear, against quadratic by coefficients.
Beware of the degree bound. The product has bound , so it needs at least points. With only points does not represent the product. Counterexample: on base : , whose bound- polynomial is . On the extended base : , the values of .
Coefficients values: evaluation
By definition:
V(a, z)
n <- a.len
y <- a[0]; pow <- 1
for i <- 1 to n-1
pow <- pow * z
y <- y + a[i] * pow
return yOne sum and two products per iteration: .
Horner's rule. :
HORNER(a, z)
n <- a.len
y <- a[n-1]
for j <- 2 to n
y <- a[n-j] + z * y
return yCorrectness (invariant). At the end of iteration (), . Before the loop (the formula for ""). If true for , the new value is , where has exponent : true for . At , .
One sum and one product per iteration: , a third fewer than V. Example: at : .
Evaluation on a base repeats Horner times:
VAL(a, x)
n <- a.len
for i <- 0 to n-1
y[i] <- HORNER(a, x[i])
return y. No better is known for a generic base; the FFT exploits a special one.
Values coefficients: interpolation
Linear system. Solve with Gauss-Jordan: .
Lagrange formula. : each fraction is at , at the other , and has degree ; by uniqueness it is the interpolating polynomial. Coefficients in :
- coefficients of : one factor at a time, each, total;
- for each , by Ruffini's rule ();
- by Horner () and add to the coefficients of (). Steps 2 and 3 repeat times: .
Example. Points : ; with ; with ; with . .
Why a special base is needed
The generic conversions cost or more, so the path "coefficients values on an extended base coefficients" costs , like the direct convolution. But if a base existed where evaluation and interpolation cost , the polynomial product would cost . It exists: the roots of unity. The transformation is the DFT (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 →), computed by the 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 →). In signal terms, the linear convolution of two finite sequences is the response of an FIR system and equals the product of the polynomials in .
Versione ripasso
- By coefficients: , degree bound (actual degree ). Zero padding does not change : . Costs in complex operations.
- By values: with distinct , . Interpolation theorem: pairs with distinct determine a unique polynomial with bound ; solve , (Vandermonde).
- Vandermonde determinant: . Proof by induction: (right to left), row becomes , extract from each row, left with .
- Sum: , cost (by coefficients, and by values on the same base).
- Linear convolution: , , the polynomial product. Each pair lands in : products and sums, (: ).
- Example: .
- Product by values: in , but needs a base of at least points. Counterexample: on base gives , hence ; on it gives , correct.
- Evaluation: definition operations; Horner
y <- a[n-j] + z*yfor , operations, invariant . at : . On points: . - Interpolation: system with Gauss-Jordan, . Lagrange: , , (Ruffini): in , then per a division, an evaluation and an accumulation in ; total .
- Lagrange example: , , with , with : .
- Idea: conversions on generic bases cost or more, so multiplying through values gains nothing; with a special base (roots of unity, 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 →) they drop to (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 →).
- Pseudocode:
HORNER(a,z):y <- a[n-1]; for j <- 2 to n: y <- a[n-j] + z*y; return y.VAL(a,x):y[i] <- HORNER(a, x[i])for each , cost . Bounds : sum , product of length . - Common mistakes: points for the product instead of ; counting instead of sums in the convolution; saying Horner makes iterations (it is ); forgetting the points must be distinct.