Basics algorithms and resultant for polynomials in Chebyshev basis by Olivier Ruatta XLIM-DMI 6172 Université de Limoges - CNRS Email:
[email protected]
1 Introduction This note deals with algorithms for polynomials expressed in Chebyshev basis. The original motivation of this work come from problem arising in computational physic. The results given here have several years (most of them were presented during a meeting of the ANR project GECKO in 2007). The results on the multiplication was rediscovered by Pascal Giorgi and published in a very more accurate way in [PG]. This paper is a first step on the algorithms of polynomial in basis of polynomials solutions of a “short” recurrence relation.
2 Basics on Chebyshev polynomials In this section, we recall some basic well known facts on Chebyshev polynomials. This not exhaustive list of result and the only motivation of this section is to keep the paper self-contained. The classical Chebyshev polynomials, noted (Tn(z))n∈N∪{0}, are usually defined by the following recurrence : ! Tn+2(z) = 2zTn+1(z) − Tn(z), ∀n∈N\{1}, T0(z) = 1, T1(z) = z. Since the sequence (Tn(z))n∈N∪{0} is given by a linear recurrence (of order two), it generating " n serie T (z , u) = +∞ n=0 Tn(z) u is a rational serie. The generating series formalism was used to produced different sum and product formulae, but we will use the following one : ∀i and j ∈ N ∪ {0}, we have Ti(z) T j (z) =
1 1 Ti+ j (z) + T|j −i|(z). 2 2
(1)
3 Multiplication in Chebyshev basis In this section, we give a algorithm to compute the product of two polynomials expressed in Chebyshev basis with the same complexity as in the classical power basis.
3.1 Multiplication by a Chebyshev polynomial The first consequence of formula 1 is the following proposition : " Proposition 1. Let f (z) = di=0 fi Ti(z) be a polynomial of degree d expressed in the Chebyshev basis and let T j (z) be a Chebyshev polynomial, then the product T j (z) f (z) can be expressed in the Chebyshev basis using O(d) arithmetic operations. 1
2
Section 3
Proof. We decompose T j (z) f (z) in the following way : T j (z) f (z) =
d d j −1 1# 1# 1# fi Ti+ j (z) + fi Ti−j (z) + fi T j −i 2 2 2 i=0
i=j
i=0
and each term of the right side of the previous equality can be compute using O(d) arithmetic operations. ! This result is really similar to want happen in the case of the multiplication by a monomial in the classical power basis. This leads directly to an algorithm to multiply to polynomials of degree d expressed in the Chebyshev basis using O(d2) arithmetic operations. In this the next subsections, we show how to reduce this cost to the same as for the classical power basis.
3.2 Karatsuba for Chebyshev polynomials In this subsection we generalize to polynomial expressed in the Chebyshev basis the Karasuba product algorithm. Recalling that the classical Karatsuba algorithm is obtained in reducing to 3 the number of multiplication in the ground field needed insted of 4 using the naive approach. We show that we have a very similar algorithm in the Chebyshev basis. Consider p(z) = a + bz and q(z) = c + dz, than p(z) q(z) = ab+ (ad + b c) z +bdz 2, which can be computed using 4 multiplications and additions. Consider the quantites A = a c, B = (a + b) (c + d) and C = bd. Those quantities can be computed using 3 products and additions. Then remark that p(z) q(z) = A+ (B − A − C) z +C z 2 which is obtained from A, B and C using only additions. This way, the product p(z) q(z) can be computed using only 3 products and a constant number of additions. The Karatsuba algorithm use this idea recursively to compute the product of two polynomials of arbitrary degrees. Suppose that the degrees of the two polynod
d
mials are bounded by d = 2n, then p(z) = a(z) + z 2 b(z) and q(z) = c(z) + z 2 d(z), with d a(z), b(z), c(z) and d(z) polynomials of degree 2 . Since p(z) q(z) = A(z) + (B(z) − A(z) − d
C(z)) z 2 + C(z) z d, with A(z) = a(z) b(z), B(z) = (a(z) + b(z)) (c(z) + d(z)) and C(z) = b(z) d(z), if K(d) denote the number of arithmetic operation needed to compute the product of two $ poly% d
log(3)
nomials of degree d, then K(d) = 3K( 2 ) + Ud where U ∈ R∗+. It is to say that K(d) ∈ O d log(2) and
log (3) log (2)
< 1.6 < 2. This is a good improvement of algorithm to compute the product.
In order to be able to generalize this approach to polynomials expressed in the Chebyshev basis, we need to make several remarks. Let p(z) = aT0(z) + bT j (z) and q(z) = cT0(z) + d T j (z), 1 1 where a, b, c and d are scalars, then p(z) q(z) = abT0 + (ad+bc) T j (z) +bd ( 2 T2 j (z) + 2 T0(z)) = 1 1 (ab + 2 bd) T0(z) +(ad+ bc) T j (z) + 2 bd T2 j (z). This situation recall the one of the formula used for the Karatsuba algorithm and the idea is to try to apply the same trick. The first point is to " show that if p(z) = di=0 pi Ti(z) then it can be write p(z) = a(z) + T j (z) b(z) for j " d, which is " j −1 less obvious than for the power basis case. First remark that if p(z) = i=0 pi Ti(z) and p¯ (z) = "d− j ¯ (z). Then, remark that Ti+j = 2 Ti T j − T j −i using fori=0 pi+ j Ti+ j (z), then p(z) = p(z) + p " j "d− j mula 1, in a way that p¯ (z) = 2 T j d− ˆ(z) − pˇ(z). i=0 ai+ jTi(z) − i=0 ai+ j T j −i(z) = 2 T j (z) p With this two remarks, we have that p(z) = p(z) − pˇ(z) + 2T j (z) pˆ(z). Now, assume that d = 2n d and take j = 2n−1, then p(z) = a(z) + T j (z) b(z) where a(z) and b(z) have degree at most 2 . This is resumed in the following lemma: "d Lemma 2. Let p(z) = i=0 pi Ti(z) = p(z) + p¯ (z), with the above notations and d = 2n, then d p(z) can be written p(z) = a(z) + T d (z) b(z) with a(z) and b(z) of degree less or equal to 2 . Fur2
thermore, a(z) = p(z) − pˇ(z) and b(z) = 2 pˆ(z) and so they can be computed using O(d) arithmetic operations (i.e. reversion and additions). Using this lemma we are able to give a generalization of the Karatsuba algorithm for polynomials expressed in the Chebyshev basis. First we describe the algorithm :
Multiplication in Chebyshev basis
3
Algorithm [Chebyshev-Karatsuba] "d "d Input: p(z) = i=0 pi Ti(z) and q(z) = i=0 qi Ti(z) with d = 2n •
if n = 0 then −
−
C ← p1 q1
−
return (A + 2 C)T0(z) + (B − A − C) T1(z) + 2 C T2(z)
−
a←
−
b←2
− •
A ← p0 q0
else
−
B ← (p0 + p1)(q0 + q1) 1
c←
" d −1 2
i=0
"d 2
i=1
" d −1 2
i=0
"
d 2
1
"d 2 pi Ti(z)- i=1 p d +i T d −i+1(z) 2
2
p d +i Ti−1(z) 2
qi Ti(z) −
"d 2
i=1
q d +i T d −i+1(z) 2
−
d←2
−
A ← Chebyshev-Karatsuba(a, c)
−
C ← Chebyshev-Karatsuba(b, d)
−
−
i=1
2
q d +i Ti−1(z) 2
B ← Chebyshev-Karatsuba(a + b, c + d) 1
1
return (A + 2 C) + (B − A − C) T d (z) + 2 CTd(z) 2
Proposition 3. Let p(z) and q(z) two polynomials, then $the previous algorithm compute the % log(3)
product of those polynomials in the Chebyshev basis using O d log(2)
arithmetic operations.
3.3 Assymptotically fast algorithm for product In this section we show that if M (d) is the cost of the multiplication of two polynomials of degree d expressed in the power basis, then the product of two polynomials of degree d expressed in the Chebyshev basis lies in O(M (d)). To show this result, we show that multiply a polynomial with an other in Chebyshev basis has a simple and effective interpretation in terms of structured matrices. We briefly recall some basics on Toeplitz and Hankel matrices sending interested reader to [VP] for the complete necessary background. 3.3.1 Toeplitz and Hankel matrices We first introduce the Toeplitz and Hankel matrices and show that the multiplication of a vector by such a matrix is a particular case of a polynomial product of polynomial in the power basis. Definition 4. Let T = (ti,j ) ∈ Mn×m a matrix with n rows and m columns, this matrix is said to be of Toeplitz type if ti+1,j +1 = ti, j for all i ∈ {1, , n − 1} and j ∈ {1, , m − 1}. We denote Tn,m the set of Toeplitz matrix with n rows and m columns. The coefficients of a Toeplitz matrix are constant along the diagonals. One can easily see that Tn,m is a vector space of dimension n + m − 1 since a Toeplitz matrix is completly determined from its first row and first column. Definition 5. Let H = (hi, j ) ∈ Mn×m a matrix with n rows and m columns, this matrix is said to be of Hankel type if hi+1, j −1 = hi, j for all i ∈ {1, , n − 1} and j ∈ {2, , m}. We denote Hn,m the set of Hankel matrices with n rows and m columns.
4
Section 3
The coefficients of an Hankel matrix are constant along the conter-diagonals. One can easy see that Hn,m is a vector space of dimension n + m −⎛1 since ⎞ an Hankel matrix is completly
determine from its last row and last column. If An = ⎝
0
1
1
0
⎠
denote the conter-identity of
size n, this matrix define an isomorphism (involution) between Tn,n and Hn,n. Proposition 6. Let M be in Tn,n or Hn,n and V be a vector of size m, then the matrix-vector product MV can be computed using O(M (n)) arithmetic operations.
We give a proof of this result in order to illustrate the use we will do of structured matrices and their relations with polynomials in power basis. More genrale method are known (see [VP] for more uniform approach to this topic). Proof. Without lost of generality, we can consider M ∈ Tn,n ⎛ t0 t1 tn−1 ⎜ t−1 t0 tn−2 ⎜ M =⎝ t1−n t2−n t0 and consider V
⎛
=⎝
v0
vn −1
⎞
⎠.
: ⎞ ⎟ ⎟ ⎠
To M we associate the polynomial M (z) =
"2 n −1 i=0
ti+1−n z i and to
"n−1 V the polynomial V (z) = i=0 vi z n+i. We can see M has a restriction of the multiplication by M (z) in the vector space of the polynomial in the power basis. The restriction of the source is on the space generated by 1, , z n −1 and the restriction on the target is on the vector space generated by z n , , z 2 n −1. It is to say that, to compute the matrix-vector product MV , one has to compute the polynomial product M (z) V (z) and to take the vector of the coefficients of z n , , z 2 n −1. Since this polynomial product can be computed using M (n) arithmetic operations, we proved that MV can be computed using O(M (n)) arithmetic operations. ! 3.3.2 Multiplication by a polynomial expressed in the Chebyshev basis " " Now, we consider two polynomials p(z) = di=0 pi Ti(z) et q(z) = ei=0 qi Ti(z). We first introduce some operations used to compose the product. Without lose of generality, we assume that d # e. Definition 7. Let us define the following operations : " " • p(z)$q(z) = di=0 ej =0 pi q j Ti+ j (z), •
p(z) % q(z) =
•
p(z)!q(z) =
"d
i=0
"d
i=0
"i
j =0
"e
pi q j Ti− j (z),
j =i+1
pi q j T j −i(z). 1
Proposition 8. We have p(z) q(z) = 2 ( p(z)$q(z) + p(z)!q(z) + p(z) % q(z) ). Proof. "e "d
We
have
p(z) "e
q(z)
=
T j (z))= 2 i=0 j =0 pi q j ( Ti+ j (z) + T|i−j |) = d "e "e 1 1" p q T (z) + i j i+j i=0 j =0 i=0 j=0 pi q j T|i−j |(z). By definition, we have 2 2 d "e "d "e 1" p q T (z) = p(z)$q(z). Now, we have i j i+ j i=0 j =0 i=0 j=0 pi q j T|i−j |(z) = 2 "d "i "d "e "d "i i=0 j =0 pi q j Ti−j (z) + i=0 j =i+1 pi q j T j −i(z). Since, i=0 j =0 pi q j Ti−j (z) = "d "e p(z) % q(z) and ! i=0 j =i+1 pi q j T j −i(z) = p(z)!q(z), the result is shown. i=0 "d
j =0
pi
qj
(Ti(z)
d 1"
Lemma 9. The operation p(z)$q(z) can be computed using O(M (d + e)) arithmetic operations.
Euclidian algorithm in Chebyshev basis
5
Proof. Consider the matrix of the linear map q(z) p(z) $ q(z) in the Chebyshev basis with restriction in the source on and in the target on . The matrix Mf ! of this linear map is as follows : ⎛ ⎞ pd p0 ⎠ M f ! =⎝ p0 pd
!
which is a Toeplitz matrix.
Lemma 10. The operation p(z)!q(z) can be computed using O(M (d + e)) arithmetic operations. Proof. Consider the matrix of the linear map q(z) p(z)!q(z) from . The matrix M f ! is given as follows : ⎞ ⎛ pe−1 0 p0 ⎠ ⎝ 0 0 p0
, Te > to n. Bf Bf ⎛ 0,1 1,1 T0 a1 a0 ⎜ a1 T1 a2 ⎜ ⎜ ⎜ ⎜ ⎜ S1 = ⎜ Tn ⎜ ⎜ am−1 am ⎜ ⎜ am Tm ⎜ ⎜ 0 ⎜ ⎝ Tn+m−1 0 ⎛ 0 0 ⎜ 0 a0 ⎜ ⎜ S2 = ⎜ ⎜ ⎜ ⎝ 0 0
f g g Bn−1,1 B0,1 B1,1
an−1 b0 b1 an−2 b1 am
g Bm−1,1
bn
0
bn bn
0 an−1
⎞ 0 0 bm 0 ⎟ ⎟ ⎟ ⎟ ⎟ b0 ⎟ 0 0 ⎠ 0 0
0 0 0 b0 0 0
a0 0
⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠
This way, we have Resm,n(f , g) = det (S0 + S1 + S2). This way, one can use fast iterative algorithm as Wiedeman algorithm to compute the resultant of polynomials express in Chebyshev basis. Since this kind of algorithm use only fast matrix-vector product, one can do this fast using the structure of those three matrices. We give now some examples of the construction of this kind of polynomials. Example 14. Let f (z) = a0 T0(z) + a1T1(z) + a2T2(z) and g(z) = b0 T0(z) + b1 T1(z) + b2 T2(z) then, using the same notations as above, we have: • •
1
1
T0 f = f (z) = 2 (a0T0 + a1T1 + a2T2) + 2 (a0T0 + a1T1 + a2T2) 1
1
1
1
T1 f = a0T0T1 + a1T1T1 + a2T2T1 = 2 a0 T1 + 2 a0 T1 + 2 (a1T0 + a1T2) + 2 (a2T3 + a2T1) and this is the same with g. Then, the resultant is given by : ⎞ ⎛ ⎞ ⎛ ⎞⎞ ⎛⎛ a0 a1 b0 b1 0 0 0 0 a0 0 b 0 0 $ %4 ⎜⎜ a1 a0 b1 b0 ⎟ ⎜ a1 a2 b1 b2 ⎟ ⎜ 0 a0 0 b0 ⎟⎟ 1 ⎟ ⎜ ⎟⎟ ⎟ ⎜ ⎜ Res2,2(f , g) = det⎜ ⎝⎝ a2 a1 b2 b1 ⎠+⎝ a2 0 b2 0 ⎠+⎝ 0 0 0 0 ⎠⎠. 2 0 a2 0 b2 0 0 0 0 0 0 0 0
Example 15. Let f (z) = a0T0 + a1T1 + a2T2 + a3T3 and g(z) = b0T0 + b1T1. we have :
Resultant in Chebyshev basis
9
⎛⎛ a0 $ %4 ⎜⎜ a1 1 ⎜ Res3,1(f , g) = det⎜ ⎝⎝ a2 2 a3
b0 b1 0 0
0 b0 b1 0
⎞ ⎛ a0 0 ⎜ a1 0 ⎟ ⎟+⎜ b0 ⎠ ⎝ a 2 b1 a3
b0 b1 0 0
b1 0 0 0
⎞ ⎛ 0 0 0 ⎜ 0 0 0 ⎟ ⎟+⎜ 0 ⎠ ⎝ 0 0 0 0 0
0 b0 0 0
⎞⎞ 0 ⎟ b1 ⎟ ⎟⎟ ⎠ b0 ⎠ 0
Informally, here is the way to design an algorithm to perform resultant matrix computation. We will build the three matrix, but we do not compute the products Ti f or T j g. Even if it is very chip, do nothing is even chiper. I will explain how it works in one of the two bloc of each of the three matrices occuring in the sum. We start with the following: ⎛ ⎞ ⎛ ⎞ ⎛ ⎞ a0 0 0 a0 ∗ ∗ ⎜ a1 ⎟ ⎜ a1 ⎟ ⎜ 0 ⎟ ∗ ∗ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ a2 ⎟ ⎜ a2 ⎟ ⎜ 0 ⎟ 0 ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎜ ⎜ ⎟ ⎟ ⎟ ∗ ∗ ⎜ ⎟+⎜ ⎟+⎜ ⎟ ⎜ ⎜ ⎜ am ⎟ ⎟ ⎟ ∗ ∗ 0 ⎜ ⎟ ⎜ am ⎟ ⎜ 0 ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ 0 ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎝ ⎠ ⎝ ⎠ ⎝ ⎠ 0 0
On the matrix of the left we shift the first column down to obtain the second column. On the second matrix we shift the first column up, but a0 will go out the matrix and it is push on the third matrix, just as follows: ⎛
a0 a1 a0 a2 a1
⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ am ⎜ ⎜ am ⎜ ⎝
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
⎞ ⎛ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟+⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎠ ⎝
a0 a1 a1 a2 a2 am am
⎞ ⎛
∗ ∗ ∗ ∗ ∗ ∗ ∗
0 0 0 a0 0 0
0 0 ∗ 0 0
⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟+⎜ ⎟ ⎜ 0 ⎟ ⎜ ⎟ ⎜ 0 ⎟ ⎜ ⎠ ⎝ 0 0
0 0 0
⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠
and we do one time the same execept that in the third we shift the column down and had the new value “lost” in the second matrix at the “top” of the column. Just has below: ⎛ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎝
⎛
a0 a1 a0 a2 a1 a0 a2 a1 am a2 am am 0 0 0 0 a 0 a1 0 0 a0
⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ 0 ⎜ ⎜ 0 ⎜ ⎝ 0 0
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ 0 0 0 ∗ ∗ 0 0 ∗ 0 0 0 0 0
⎛
⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠
⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠
+
⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎝
a0 a1 a 2 a1 a2 a2 am am am
And so on until we reach the wanted degree for each block.
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠
+
10
Section
5.2 Bézout matrices
5.3 Companion matrix
Bibliography [PG] Pascal Giorgi, On Polynomial Multiplication in Chebyshev Basis, Preprint, ouvertes.fr/hal-00520207/fr/.
http://hal.archives-
[TR] Theodore J. Rivlin, The Chebyshev Polynomials, Pure and Applied Mathematics, Wiley-Intersciences, John Wiley and Sons, New York, 1974. [VP] Victor Y. Pan, Structured Matrices and polynomials, Springer-Birkhäuser, 2001. [LR] Luc Rebillard, Etude théorique et algorithmique des séries de Chebyshev solutions d’équations différentielles, Ph.D. Université de Grenoble.