1
ADVANCED ALGORITHMS
Polynomials and the FFT(UNIT-3)
2
1. Polynomials : A polynomial in the variable x over an algebraic field F represents a function A(x) as a formal sum :
A(x) = aj xj j = 0 to n-1
Here, we call the values a0, a1, a2, a3,….,an-1 as the coefficients of the polynomial.A polynomial has degree k, if its highest non-zero coefficient is ak.
Any integer strictly greater than the degree of a polynomial ‘k’, is degree-bound ‘n’. i.e., n > k.
3
The representation of a Polynomial :
Ex-1 : A(x) = 𝑥3 − 2 − 1 𝑥Here, A(x) has degree 3.
A(x) has degree bounds 4,5,6,..A(x) has coefficients (-1,-2,0,1)
Ex-2 : 𝑥4 + 𝑥2 − 1
Here, A(x) has degree 4. A(x) has degree bounds 5,6,7,.. A(x) has coefficients (-1,0,1,0,1)
4
Coefficient Representation : (CR)
A CR of a polynomial of degree bound ‘n’ is a vector of coefficients
a =
Adding Polynomials : Let a = (a0,a1,a2,… , an-1)
b = (b0,b1,b2,… , bn-1)
Sum is the coefficient vector C, wherec = (c0,c1,c2,… , cn-1)
Here, cj = aj + bj j = 0,1,2,..,n-1.
5
Multiplying Polynomials :Multiplying of two degree-bound ‘n’ polynomials A(x) and B(x) :
C(x) =
Ex-3 : Add & Multiply the following two polynomials :A(x) = x2 - 10 x + 9B(x) = x2 + 4 x - 5
A(x) + B(x) = 2x2 - 6 x + 4
A(x) X B(x) = x4 – 6 x3 – 36 x2 + 86 x - 45
6
2. Horner’s Rule :Given the Polynomial :p(x) = ai xi
= a0 + a1 x + a2 x2 + … + an xn
i = 0 to n
Here, i = 0,1,2,..,n-1,n ai is a real number.
The above polynomial can be written in the form :p(x) = a0 + x (a1 + x (a2 + x (a3 + …. +
x (an-1 + an x )……)) Let x = x0
Now, assume bn := an
bn-1 := an-1 + bn xo ………….. b0 := a0 + b1 xo
7
Here let us substitute b values into expression of p(x0).
So, p(x0) = a0 + x0 (a1 + x0 (a2 + x0 (a3 + …. + x0 (an-1 + bn x0 )……))
= a0 + x0 (a1 + x0 (a2 + x0 (a3 + …. + x0 bn-1 )……))
= ………… = a0 + x0 (a1 + x0 (a2 + x0 b3 ))
= a0 + x0 (a1 + x0 b2)
= a0 + x0 b1 = b0
Hence p(x0) = b0
8
Ex-4 : Evaluate 2x3 - 6x2 + 2x - 1 for x = 3
Synthetic Division : (Horner’s Method)
x0 | x3 x2 x1 x0
---------------------------------------- 3 | 2 - 6 2 - 1
| 6 0 6-----------------------------------------
2 0 2 5
i.e., The Value of p(x0) is 5.
9
Ex-5 : Evaluate x3 - 6x2 + 11 x - 6 for x = 2
Synthetic Division : (Horner’s Method)
x0 | x3 x2 x1 x0
---------------------------------------- 2 | 1 - 6 11 - 6
| 2 - 8 6-----------------------------------------
1 - 4 3 0
i.e., The Value of p(x0) is 0.
10
3. Point-Value Representation : A Point-Value Representation of a polynomial A(x) of degree-bound n is a set of n point-value pairs :
{(x0 ,y0), (x1 ,y1), (x2 ,y2),…, (xn-1 ,yn-1),}
such that all of the xk are distinct and yk = A(xk) for k = 0,1,2,…,n-1.
Ex-6 : A(x) = x3 - 2 x + 1Here, xk : 0, 1, 2, 3
A(xk ) : 1, 0, 5, 22 { (0,1), (1,0), (2,5), (3,22) }
11
Interpolation of PVR : The inverse of evaluation is Interpolation. - determines coefficient form of polynomial from
point value representation.
Theorem : (Uniqueness of an interpolating polynomial)
“For any set {(x0 ,y0), (x1 ,y1), (x2 ,y2),…, (xn-1 ,yn-1),}
of n point-value pairs all the xk values are distinct,
there is a unique polynomial A(x) of degree-bound n such that yk = A(xk) for k = 0, 1, 2, …, n-1.”
12
The above theorem can be written as :
The matrix on the left is denoted V(x0 , x1 , x2 , …, xn-1). It is known as : Vander-monde Matrix.
i.e., a = V -1 y.
13
Lagrange’s Formula :
A(x) = yk Z, wherek = 0 to n-1
Z = j k (x – xj) / j k (xk – xj)
Ex-7 : Consider the PVR :[ (0,1), (1,0), (2,5), (3,22) ]
Here, 1.[(x-1)(x-2)(x-3)] / [(0-1) (0-2) (0-3)]= (x3 - 6x2 + 11 x - 6) / - 6= (-x3 + 6x2 - 11 x + 6) / 6 ….(1)
And 0.[(x-0)(x-2)(x-3)] / [(1-0) (1-2) (1-3)]= 0 ….(2)
14
And 5.[(x-0)(x-1)(x-3)] / [(2-0) (2-1) (2-3)]= 5. (x3 - 4x2 + 3 x ) / (-2)= (-15 x3 + 60 x2 - 45 x ) / 6 …..(3)
And 22.[(x-0)(x-1)(x-2)] / [(3-0) (3-1) (3-2)]= 22 (x3 - 3 x2 + 2 x ) / 6= (22 x3 - 66 x2 + 44 x ) / 6 ……(4)
(1) + (2) + (3) + (4) : (6 x3 + 0 x2 - 12 x + 6) / 6= x3 - 2 x + 1 …Answer
The above is the polynomial for the given PVR.
15
Adding Polynomials using PVR : Let C(x) = A(x) + B(x)
A : [(x0 ,y0), (x1 ,y1), (x2 ,y2),…, (xn-1 ,yn-1)]
B : [(x0 ,z0), (x1 ,z1), (x2 ,z2),…, (xn-1 ,zn-1)]
C : [ (x0 , y0+ z0), (x1 , y1+ z1), ….,(xn-1 , yn-1+ zn-1) ]
Ex-8 : Find the value of C(x) in PVR, whereA(x) = x3 - 2 x + 1B(x) = x3 + x2 + 1
Let x = (0,1,2,3)
Then A : [(0,1), (1,0), (2, 5), (3,22) ] B : [ (0,1), (1,3), (2, 13), (3, 37) ]
Hence C : [(0,2), (1, 3), (2, 18), (3, 59) ]
16
Multiplying Polynomials using PVR :Let C(x) = A(x) . B(x) A : [(x0 ,y0), (x1 ,y1), (x2 ,y2),…, (x2n-1 ,y2n-1)]
B : [(x0 ,z0), (x1 ,z1), (x2 ,z2),…, (x2n-1 ,z2n-1)]
C : [ (x0 , y0 z0), (x1 , y1 z1),….,(x2n-1 , y2n-1+ z2n-1) ]
Ex-9 : Find the value of C(x) in PVR, whereA(x) = x3 - 2 x + 1 ; B(x) = x3 + x2 + 1
Let x = (-3,-2,-1,0,1,2,3)
A : [(-3,20), (-2,-3), (-1,2),(0,1), (1,0), (2, 5), (3,22) ]B : [ (-3,-17),(-2,-3), (-1, 1),(0,1), (1,3), (2, 13), (3,17)]C : [(-3,340),(-2,9),(-1,2),(0,1), (1, 0), (2, 65), (3,814) ]
17
Ex-8 Contd… There are FOUR cordinates :
C : [(0,2), (1, 3), (2, 18), (3, 59) ]
Basing on First & Second Coordinates : - 2 x3 + 12 x2 - 22 x + 12 …..(1) 9 x3 - 45 x2 + 54 x …..(2)
Basing on Third & Fourth Coordinates :- 54 x3 + 216 x2 - 162 x …..(1) 59 x3 - 177 x2 + 118 x …..(2)
The denominator is 6. Finally 2 x3 + x2 - 2 x + 2
18
4. Complex Roots of Unity : A complex nth root of unity (1) is a complex number such that n = 1. There are exactly n complex nth roots of unity :
e2 i k / n for k = 0, 1, 2, …., n-1 where eiu = cos (u) + i sin (u)
Using e2 i k / n = cos(2 k / n) + i sin(2 k / n)
we can check that it is a root.
(e2 i k / n)n = e2 i k
= cos(2 k) + i sin (2k) = 1 + 0 = 1
19
Degrees : 00 450 900 1800
SIN 0 1/ 2 1 0COS 1 1/ 2 0 -1
Principal nth Root of Unity : The Value n = e 2 ∏ i /n
is called the ‘principal nth root of unity’.
All of the other complex nth roots of unity are powers of n .
The n complex nth roots of unity are : n
0, n1, n
2,….., nn-1
Note : Here, nn = n
0 = 1
20
Ex-10 : Find the 8th complex roots of unity.
The two roots of unity are : +1, - 1The complex 4th roots of unity are :
1, - 1, i, - i where (-1) = iIn general, the n complex roots of unity are equally spaced around the circle of unit radius centered at the origin of the complex plane.
Note : nj . n
k = nj+k = n
(j + k) mod n
21
Visualizing 8 Complex 8th Roots of Unity :
22
First Root : 80
= 88
= 1Here, k = 0, n = 8
So, 80 = e 2 ∏ i k / n = e 0 = 1
Second Root : Here, k = 1, n = 88
1 = e 2 ∏ i k / n = e 2 ∏ i / 8 = e ∏ i / 4
by using the formula eiu = cos (u) + i sin (u)
So, 81
= cos (/4) + i sin (/4)
= 1 / 2 + i / 2
23
Third Root : Here, k = 2, n = 88
2 = e 2 ∏ i k / n = e 2 ∏ i 2 / 8 = e ∏ i / 2
So, 82
= cos (/2) + i sin (/2) = i
Fourth Root : Here, k = 3, n = 88
3 = e 2 ∏ i k / n = e 2 ∏ i 3 / 8 = e ∏ i 3 / 4
So, 83
= cos (3/4) + i sin (3/4)= cos ( - /4) + i sin ( - /4)= - cos /4 + i sin /4)
[since cos ( - x) = - cos x, sin ( - x) = sin x]
= - 1 / 2 + i /2
24
Fifth Root : Here, k = 4, n = 88
4 = e 2 ∏ i k / n = e 2 ∏ i 4 / 8 = e ∏ i
So, 84
= cos () + i sin () = - 1
Sixth Root : Here, k = 5, n = 88
5 = e 2 ∏ i k / n = e 2 ∏ i 5 / 8 = e ∏ i 5 / 4
So, 85
= cos (5/4) + i sin (5/4)= cos ( + /4) + i sin ( + /4)= - cos /4 + i (- sin /4)
[since cos ( + x) = - cos x, sin ( + x) = - sin x]
= - 1 / 2 - i /2
25
Seventh Root : Here, k = 6, n = 88
6 = e 2 ∏ i k / n = e 2 ∏ i 6 / 8 = e 3∏ i / 2
So, 86
= cos ( + /2 ) + i sin ( + /2) = - cos (/2) + i (- sin (/2) )
= - 0 + i ( - 1) = - iEighth Root : Here, k = 7, n = 8
87 = e 2 ∏ i k / n = e 2 ∏ i 7 / 8 = e ∏ i 7 / 4
So, 87 = cos (7/4) + i sin (7/4)
= cos ( + 3/4) + i sin ( + 3/4)= - cos 3/4 + i (- sin 3/4)
[since cos ( + x) = - cos x, sin ( + x) = - sin x]= cos /4 + i (- sin /4) = 1 / 2 - i /2