Abstract

A simple and efficient algorithm for finding the GCD of a pair of univariate polynomials is derived. The process requires only successive subtraction of two monic polynomials. Amazingly, this approach gives the desired GCD for a pair of test polynomials of very high degree, such as (π‘₯+1)∧1000 and its derivative.

1. Introduction

The computation of the greatest common divisor (GCD) of a pair of polynomials is an important issue in computational mathematics and also plays a crucial role in many science and engineering fields. Several numerical methods have been proposed for the derivation of polynomial GCD [1–5]. Some are based on the classical Euclidean algorithm and the others are based on the procedures involving Sylvester resultant matrix. Most of them require algorithm of some advanced mathematics, such as the singular value decomposition and the least square iteration process.

In this paper a simple and effective method to find the GCD of a pair of given polynomials is presented. The process requires only the successive subtraction of two monic polynomials. It is modified purposely from the longhand polynomial divisions employed in the classical Euclidean GCD computation. The entire computations require only simple elementary arithmetic operations, such as division and subtraction.

A MATLAB code is provided, along with a typical numerical example. Amazingly, this routine gives the GCD for a pair of test polynomials of very high degree.

2. Mathematical Formulation

From the classical Euclidean algorithm for computing polynomial GCD, the longhand polynomial division is consecutively employed:π‘π‘˜(π‘₯)=π‘π‘˜βˆ’2(π‘₯)βˆ’π‘π‘˜βˆ’1(π‘₯)π‘žπ‘˜(π‘₯),(2.1)where quotient π‘žπ‘˜(π‘₯) and remainder π‘π‘˜(π‘₯) are obtained from dividing dividend π‘π‘˜βˆ’2(π‘₯) by divisor π‘π‘˜βˆ’1(π‘₯). If the quotient π‘žπ‘˜(π‘₯) in every recurrent process can be converted into a numerical constant or even equal to 1, π‘žπ‘˜(π‘₯)=1, by making both π‘π‘˜βˆ’2(π‘₯) and π‘π‘˜βˆ’1(π‘₯) equal degree and monic, then the longhand polynomial division becomes simply a pair of β€œmonic polynomials subtraction”: π‘π‘˜(π‘₯)=π‘π‘˜βˆ’2(π‘₯)βˆ’π‘π‘˜βˆ’1(π‘₯).(2.2) The recurrent process of this approach may therefore be summarized as follows.

Given a pair of polynomials 𝑏(π‘₯) and π‘Ž(π‘₯) of degrees 𝑛 and π‘š, 𝑏(π‘₯)=𝑛𝑗=0𝑏𝑗π‘₯π‘›βˆ’π‘—=𝑏𝑐(π‘₯)π‘₯𝑛𝑧,π‘Ž(π‘₯)=π‘šξ“π‘—=0π‘Žπ‘—π‘₯π‘šβˆ’π‘—=π‘Žπ‘(π‘₯)π‘₯π‘šπ‘§,(2.3)where 𝑏(π‘₯) and π‘Ž(π‘₯) have 𝑛𝑧 and π‘šπ‘§β€‰zero trailing coefficients, respectively, and 𝑏𝑐(π‘₯) and π‘Žπ‘(π‘₯) represent the polynomials without zero trailing coefficients, assuming that 𝑛𝑐β‰₯π‘šπ‘, where 𝑛𝑐=deg(𝑏𝑐(π‘₯))andπ‘šπ‘=deg(π‘Žπ‘(π‘₯)).

Before finding our desired 𝑔(π‘₯)=gcd(𝑏(π‘₯),π‘Ž(π‘₯)), we first consider 𝑔𝑐(π‘₯)=gcd(𝑏𝑐(π‘₯),π‘Žπ‘(π‘₯)) by setting𝑝0𝑏(π‘₯)=𝑐(π‘₯)𝑏0,𝑝1π‘Ž(π‘₯)=𝑐(π‘₯)π‘₯π‘›π‘βˆ’π‘šπ‘π‘Ž0.(2.4) Both polynomials 𝑝0(π‘₯) and 𝑝1(π‘₯) are now in the same degree and monic. Applying the monic polynomial subtraction consecutively starting from π‘˜=2 until π‘˜=𝐾+1, such that 𝑝𝐾+1(π‘₯)=π‘πΎβˆ’1(π‘₯)βˆ’π‘πΎ(π‘₯)=0,(2.5) we get𝑝𝐾𝑝(π‘₯)=gcd0(π‘₯),𝑝1𝑏(π‘₯)=gcd𝑐(π‘₯),π‘Žπ‘(π‘₯)π‘₯π‘›π‘βˆ’π‘šπ‘ξ€Έξ€·π‘=gcd𝑐(π‘₯),π‘Žπ‘(ξ€Έ.π‘₯)(2.6) Finally our desired polynomial GCD is found𝑔(π‘₯)=gcd(𝑏(π‘₯),π‘Ž(π‘₯))=𝑝𝐾(π‘₯)π‘₯min(𝑛𝑧,π‘šπ‘§).(2.7)

It is noted that the complete set of π‘π‘˜(π‘₯), referred to as β€œpolynomial remainder sequence” [3, 4], may also be computed during the recurrent process. The entire computations involve only elementary arithmetic operations without any advanced mathematics. The total numbers of recurrent process for computing GCD of the two given polynomials 𝑏(π‘₯) and π‘Ž(π‘₯) are amazingly fewer than 𝑛𝑐+π‘šπ‘.

3. Computer Routine in MATLAB

The computer code polygcd.m in MATLAB is presented. The inputs p and q are coefficient vectors of two given polynomials 𝑏(π‘₯) and π‘Ž(π‘₯), and the output g is the desired greatest common divisor 𝑔(π‘₯). The input data can be either real or complex numbers. See Algorithm 1.

function g = polygcd(p,q)
% *** Find GCD of two given polynomials ***
%   through β€œMonic polynomial subtraction”
%   by F C Chang 03/03/2011
%
  mz = min(length(p)-max(find(p)),length(q)-max(find(q)));
  p0 = p(min(find(p)):max(find(p)));
  q0 = q(min(find(q)):max(find(q)));
 if min(length(p0),length(q0)) < 2,
  g = [1,zeros(1,mz)]; return, end;
  g1 = p0/p0(1);              P{1} = g1;
  g2 = q0/q0(1);              P{2} = g2;
for k = 3:length(p0) + length(q0),
  l12 = length(g1)-length(g2); l21 = -l12;
  g3 = [g2,zeros(1,l12)]-[g1, zeros(1,l21)];
  g3 = g3(min(find(abs(g3)>1.e-8)):max(find(abs(g3)>1.e-8)));
  if norm(g3,inf)/norm(g2,inf) < 1.e-3, break; end;
  if length(g1) >= length(g2),
  g1 = g2;            end;
  g2 = g3/g3(1);              P{k} = g2;
end;
  g = [g1,zeros(1,mz)];
                     % celldisp(P);

4. Typical Example

If one test polynomial 𝑝(π‘₯) is derived from ξ€·π‘₯𝑝(π‘₯)=(π‘₯+3)2ξ€Έβˆ’5π‘₯+62ξ€·π‘₯5+3π‘₯4+8π‘₯3+8π‘₯2ξ€Έ+7π‘₯+53π‘₯5(π‘₯βˆ’1)7,(4.1) that is,𝑝(π‘₯)=π‘₯32βˆ’5π‘₯31+2π‘₯30βˆ’6π‘₯29+76π‘₯28+140π‘₯27βˆ’802π‘₯26+954π‘₯25βˆ’4251π‘₯24+13663π‘₯23βˆ’18740π‘₯22+28472π‘₯21βˆ’53504π‘₯20+45776π‘₯19+5212π‘₯18βˆ’77580π‘₯17+185243π‘₯16βˆ’220631π‘₯15+104794π‘₯14+52458π‘₯13βˆ’193356π‘₯12+248612π‘₯11βˆ’146266π‘₯10+9202π‘₯9+65791π‘₯8βˆ’87555π‘₯7+55800π‘₯6βˆ’13500π‘₯5+0π‘₯4+0π‘₯3+0π‘₯2+0π‘₯+0,(4.2) and the another polynomial π‘ž(π‘₯) is the derivative of 𝑝(π‘₯), π‘ž(π‘₯)=π‘ξ…ž(π‘₯),(4.3) then, applying the routine polygcd.m, the desired GCD of 𝑝(π‘₯) and π‘ž(π‘₯) is readily computed:𝑔𝑝(π‘₯)=gcd(π‘₯),π‘ξ…žξ€Έ(π‘₯)=π‘₯22βˆ’5π‘₯21+10π‘₯20βˆ’36π‘₯19+116π‘₯18βˆ’188π‘₯17+308π‘₯16βˆ’620π‘₯15+694π‘₯14βˆ’214π‘₯13βˆ’496π‘₯12+1348π‘₯11βˆ’1740π‘₯10+1012π‘₯9+28π‘₯8βˆ’692π‘₯7+929π‘₯6βˆ’605π‘₯5+150π‘₯4+0π‘₯3+0π‘₯2+0π‘₯+0.(4.4)

Finally it is fairly easy to check thatξ€·π‘₯𝑔(π‘₯)=2π‘₯βˆ’5π‘₯+6ξ€Έξ€·5+3π‘₯4+8π‘₯3+8π‘₯2ξ€Έ+7π‘₯+52π‘₯4(π‘₯βˆ’1)6.(4.5)

See Algotithm 2.

≫
≫ p = [1β€‰β€‰β€‰βˆ’5   2β€‰β€‰β€‰βˆ’6   76   140β€‰β€‰β€‰βˆ’802 954β€‰β€‰β€‰βˆ’4251   13663β€‰β€‰β€‰βˆ’18740   28472β€‰β€‰β€‰βˆ’53504   45776   5212β‹―
β€ƒβ€ƒβ€ƒβ€‰β€‰βˆ’77580   185243β€‰β€‰β€‰βˆ’220631   104794   52458β€‰β€‰β€‰βˆ’193356   248612β€‰β€‰β€‰βˆ’146266   9202   65791β‹―
β€ƒβ€ƒβ€ƒβ€‰β€‰βˆ’87555 55800β€ƒβˆ’13500  0  0  0  0  0];
≫ q = polyder(p);
≫ q = polygcd(p,q);
≫ p, q, g,
   p =
       1β€ƒβ€‰β€‰β€‰β€ƒβˆ’5   2β€ƒβ€‰β€‰β€ƒβˆ’6        76  140β€ƒβ€‰β€‰β€‰β€‰βˆ’802     954β€ƒβ€‰β€‰β€‰β€‰β€‰β€‰βˆ’4251
      13663β€‰β€‰β€‰β€‰β€‰β€‰βˆ’18740  28472β€‰β€‰β€‰β€‰β€‰β€‰βˆ’53504         45776     5212β€‰β€‰β€‰β€‰β€‰βˆ’77580        185243     –220631
   104794         52458β€‰β€‰βˆ’193356     248612β€‰β€‰β€‰β€‰βˆ’146266     9202    65791β€‰β€‰β€‰β€‰β€‰β€‰βˆ’87555    55800
β€ƒβ€ƒβ€ƒβ€‰βˆ’13500   0   0   0     0        0
   q =
     32β€ƒβ€‰β€‰β€‰βˆ’155     60β€ƒβ€ƒβ€‰β€‰β€‰βˆ’174           2128            3780β€‰β€‰β€‰β€‰β€‰β€‰β€‰β€‰β€‰βˆ’20852     23850β€ƒβ€‰β€‰βˆ’102024
    314249β€‰β€‰βˆ’412280      597912β€‰β€‰β€‰β€‰β€‰β€‰β€‰βˆ’1070080    869744        93816  –1318860 2963888     –3309465
     1467116     681954β€‰β€‰βˆ’2320272       2734732  –1462660       82818         526328β€‰βˆ’612885    334800
β€ƒβ€ƒβ€ƒβ€‰βˆ’67500   0       0       0   0
   g =
    1β€ƒβ€ƒβ€ƒβ€‰β€‰β€‰β€‰βˆ’5     10β€ƒβ€ƒβˆ’36       116β€ƒβˆ’188  308β€ƒβ€ƒβ€‰β€‰βˆ’620  694
β€ƒβ€ƒβ€‰β€‰β€‰β€‰βˆ’214β€ƒβ€‰β€‰β€ƒβ€‰β€‰β€‰βˆ’496    1348β€ƒβˆ’1740      1012   28β€ƒβ€‰β€‰β€‰βˆ’692      929β€‰β€‰β€‰β€‰β€‰β€‰β€‰β€‰β€‰β€‰βˆ’605
   150     0       0   0   0
≫

5. Applications

One of the most important applications of polynomial GCD is to find the roots with multiplicities of high-degree multiple-root polynomials [3].

Let a univariate polynomial 𝑝(π‘₯) of degree 𝑁 be given, and then the 𝐾 roots π‘§π‘˜ with multiplicities π‘šπ‘˜ are to be sought, such that𝑝(π‘₯)=𝑁𝑖=0𝑏𝑖π‘₯π‘›βˆ’π‘–=πΎξ‘π‘˜=1ξ€·π‘₯βˆ’π‘§π‘˜ξ€Έπ‘šπ‘˜.(5.1)

We are now to find the rational function π‘Ÿ(π‘₯) or its related polynomials 𝑒(π‘₯) and 𝑣(π‘₯), such thatπ‘Ÿ(π‘₯)=𝑒(π‘₯)=𝑣(π‘₯)πΎξ“π‘˜=1π‘šπ‘˜π‘₯βˆ’π‘§π‘˜,(5.2) where𝑝𝑒(π‘₯)=(π‘₯)𝑝𝑔(π‘₯),𝑣(π‘₯)=ξ…ž(π‘₯)𝑔(π‘₯),(5.3) and 𝑔(π‘₯) is the polynomial GCD of 𝑝(π‘₯) and π‘ξ…ž(π‘₯):𝑔(π‘₯)=gcd𝑝(π‘₯),π‘ξ…žξ€Έ=(π‘₯)πΎξ‘π‘˜=1ξ€·π‘₯βˆ’π‘§π‘˜ξ€Έπ‘šπ‘˜βˆ’1.(5.4) Then, π‘§π‘˜ and π‘šπ‘˜ are simply the poles and residues of the rational function π‘Ÿ(π‘₯). Therefore, instead of directly solving for π‘§π‘˜ and π‘šπ‘˜ from the original 𝑁-degree multiple-root polynomial, we may now easily find the roots π‘§π‘˜ from the 𝐾-degree simple-root polynomial,𝑒(π‘₯)=πΎξ‘π‘˜=1ξ€·π‘₯βˆ’π‘§π‘˜ξ€Έ,(5.5) and the corresponding multiplicities π‘šπ‘˜ by the partial fraction expansion coefficients of the rational function π‘Ÿ(π‘₯)=𝑣(π‘₯)/𝑒(π‘₯),π‘šπ‘˜=ξ€·π‘₯βˆ’π‘§π‘˜ξ€Έπ‘£(π‘₯)||||𝑒(π‘₯)π‘₯=π‘§π‘˜=π‘£ξ€·π‘§π‘˜ξ€Έπ‘’ξ…žξ€·π‘§π‘˜ξ€Έ,(5.6)

A short program code poly_roots.m for solving multiple-root polynomials is presented. It uses only basic built-in MATLAB routines except the function polygcd.m for computing polynomial GCD. See Algorithm 3.

function Z = poly_roots(p)
% *** Solve multiple-root polymonials ***
%
  mz = length(p)-max(find(p));
  p0 = p(min(find(p)):max(find(p)));
  q0 = polyder(p0);
if length(p0) < 2, Z = [0,mz]; return, end;
  g = polygcd(p,q);
  u0 = deconv(p0,g0);
  v0 = deconv(q0,g0);
  w0 = polyder(u0);
  z0 = roots(u0);
  m0 = polyval(v0,z0)./polyval(w0,z0);
  Z = [z0,round(abs(m0))];
if mz > 0, Z = [Z; 0,mz]; end;

6. Conclusion

The very simple and efficient algorithm for the calculation of GCD of a pair of given polynomials is developed. The entire computations involve only simple elementary arithmetic operations. Amazingly, the derived routine gives the desired results for the test polynomials of very high degrees, such as (π‘₯+1)1000,(π‘₯βˆ’123456789)30, and (1234π‘₯+56789)50, and their respective derivatives.

One of the most important applications for polynomial GCD is to find the roots with multiplicities of polynomials with high degrees [1–3]. It reveals that the higher the root multiplicities of the given polynomial are, the more efficient this approach becomes. This is contrary to the usual experience that the most difficult part of solving for the roots of a polynomial is calculating those that have high multiplicities [1].