Content uploaded by Diaz Toca

Author content

All content in this area was uploaded by Diaz Toca

Content may be subject to copyright.

The Berlekamp-Massey Algorithm revisited

Nadia Ben Atti (∗), Gema M. Diaz–Toca (†) Henri Lombardi (‡)

Abstract

We propose a slight modiﬁcation of the Berlekamp-Massey Algorithm for obtaining the minimal

polynomial of a given linearly recurrent sequence. Such a modiﬁcation enables to explain it in a

simpler way and to adapt it to lazy evaluation.

MSC 2000: 68W30, 15A03

Key words: Berlekamp-Massey Algorithm. Linearly recurrent sequences.

1 Introduction: The usual Berlekamp-Massey algorithm

Let Kbe an arbitrary ﬁeld. Given a linearly recurrent sequence, denoted by S(x) =

∞

P

i=0

aixi,ai∈

K, we wish to compute its minimal polynomial, denoted by P(x). Recall that if P(x) is given by

P(x) =

d

P

i=0

pixidenotes such polynomial, then P(x) is the polynomial of the smallest degree such that

d

P

i=0

piaj+i= 0,for all jin N.

Let suppose that the minimal polynomial of S(x) has degree bound n. Under such hypothesis, the

Berlekamp-Massey Algorithm only requires the ﬁrst 2ncoeﬃcients of S(x) in order to compute the

minimal polynomial. Such coeﬃcients deﬁne the polynomial S=P2n−1

i=0 aixi.

A large literature can be consulted nowadays in relation to the Berlekamp’s Algorithm. The (orig-

inal) Berlekamp’s Algorithm was created for decoding Bose-Chaudhuri-Hocquenghem (BCH) codes in

1968 (see [1]). One year later, the original version of this algorithm has been simpliﬁed by Massey

(see [5]). The similarity of the algorithm to the extended Euclidean Algorithm can be found in several

articles, for instance, in [2],[3], [6], [9] and [10]. Some more recent interpretations of the Berlekamp-

Massey Algorithm in terms of Hankel Matrices and Pad´e approximations can be found in [4] and

[7].

The usual interpretation of the Berlekamp-Massey Algorithm for obtaining P(x) is expressed in

pseudocode in Algorithm 1.

In practice, we must apply the simpliﬁcation of the extended Euclidean Algorithm given in [3], to

ﬁnd exactly the Berlekamp-Massey Algorithm. Such simpliﬁcation is based on the fact that initial R0

is equal to x2n.

Although Algorithm 1 is not complicated, it seems to be no easy to ﬁnd a direct and transparent

explanation for the determination of the degree of P. In the literature, we think there is a little

confusion with the diﬀerent deﬁnitions of minimal polynomial and with the diﬀerent ways of deﬁning

∗Equipe de Math´ematiques, CNRS UMR 6623, UFR des Sciences et Techniques, Universit´e de Franche-Comt´e, 25

030 Besan¸con cedex, France. nadia.benatti@ensi.rnu.tn

†Dpto. de Matematicas Aplicada. Universidad de Murcia, Spain. gemadiaz@um.es, partially supported by the

Galois Theory and Explicit Methods in Arithmetic Project HPRN-CT-2000-00114

‡Equipe de Math´ematiques, CNRS UMR 6623, UFR des Sciences et Techniques, Universit´e de Franche-Comt´e,

25 030 Besan¸con cedex, France, lombardi@math.univ-fcomte.fr, partially supported by the European Union funded

project RAAG CT-2001-00271

1

Algorithm 1 The Usual Berlekamp-Massey Algorithm

Input: n∈N. The ﬁrst 2ncoeﬃcients of a linearly recurrent sequence deﬁned over K, given by the list

[a0, a1, . . . , a2n−1]. The minimal polynomial has degree bound n.

Output : The minimal polynomial Pof the sequence.

Start

Local variables : R, R0, R1, V , V0, V1, Q : polynomials in x

# initialization

R0:= x2n;R1:= P2n−1

i=0 aixi;V0= 0 ;V1= 1 ;

# loop

while n≤deg(R1)do

(Q, R) := quotient and remainder of R0divided by R1;

V:= V0−Q V1;

V0:= V1;V1:= V;R0:= R1;R1:= R;

end while

# exit

d:= max(deg(V1),1 + deg(R1)) ;P:= xdV1(1/x); Return P:= P/leadcoeﬀ (P).

End.

the sequence. Here, we introduce a slight modiﬁcation of the algorithm which makes it more compre-

hensible and natural. We did not ﬁnd in the literature such a modiﬁcation before the ﬁrst submission

of this article (May 2004). However, we would like to add that you can also ﬁnd it in [8], published in

2005, without any reference.

2 Some good reasons to modify the usual algorithm

By the one hand, as it can be observed at the end of Algorithm 1, we have to compute the (nearly)

reverse polynomial of V1, in order to obtain the right polynomial. The following example helps us to

understand what happens:

n=d= 3,

S=a0+a1x+a2x2+a3x3+a4x4+a5x5= 1 + 2x+ 7x2−9x3+ 2x4+ 7x5,

Algorithm 1(3,[1,2,7,−9,2,7]) ⇒P=x+x2+x3,

with V1=v0+v1x+v2x2= 49/67(1 + x+x2),

and Rsuch that S V1=Rmod x6,deg(R)=2

which implies that

coeﬀ(S V1, x, 3) = a1v2+a2v1+a3v0= 2v2+ 7v1−9v0= 0,

coeﬀ(S V1, x, 4) = a2v2+a3v1+a4v0= 7v2−9v1+ 2v0= 0,

coeﬀ(S V1, x, 5) = a3v2+a4v1+a5v0=−9v2+ 2v1+ 7v0= 0.

Hence, the right degree of Pis given by the degree of the last R1plus one because xdivides P. Observe

that a0v2+a1v1+a2v0= 490/67 6= 0. We would like to obtain directly the desired polynomial from

V1.

Moreover, by the other hand, in Algorithm 1 all the ﬁrst 2 ncoeﬃcients are required to start the

usual algorithm, where nonly provides a degree bound for the minimal polynomial. Consequently,

it may be possible that the true degree of Pis much smaller that nand so, less coeﬃcients of the

sequence are required to obtain the wanted polynomial.

So, we suggest a more natural, eﬃcient and direct way to obtain P. Our idea is to consider the

polynomial b

S=P2n−1

i=0 aix2n−1−ias the initial R1. Observe that in this case, using the same notation

2

as in Algorithm 1, the same example shows that it is not necessary to reverse the polynomial V1at

the end of the algorithm.

n=d= 3,

b

S=a0x5+a1x4+a2x3+a3x2+a4x+a5=x5+ 2 x4+ 7 x3−9x2+ 2 x+ 7,

Algorithm 2 (3,[1,2,7,−9,2,7]) ⇒P=x+x2+x3,

with V1=v0+v1x+v2x2+v3x3=−9/670(x+x2+x3),

and Rsuch that b

S V1=Rmod x6,deg(R)=2

which implies that

coeﬀ ( b

S V1, x, 3) = a2v0+a3v1+a4v2+a5v3=−9v1+ 2v2+ 7v3= 0,

coeﬀ ( b

S V1, x, 4) = a1v0+a2v1+a3v2+a4v3= 7v1−9v2+ 2v3= 0,

coeﬀ ( b

S V1, x, 5) = a0v0+a1v1+a2v2+a3v3= 2v1+ 7v2−9v3= 0.

Furthermore, when nÀdeg(P), the algorithm can admit a lazy evaluation. In other words, the

algorithm can be initiated with less coeﬃcients than 2nand if the outcome does not provide the

wanted polynomial, we increase the number of coeﬃcients but remark that it is not necessary to

initiate again the algorithm because we can take advantages of the computations done before. We will

explain this application of the algorithm in Section 3.

Next, we introduce our modiﬁed Berlekamp-Massey Algorithm in pseudocode (Algorithm 2):

Algorithm 2 Modiﬁed Berlekamp-Massey Algorithm

Input: n∈N. The ﬁrst 2ncoeﬃcients of a linearly recurrent sequence deﬁned over K, given by the list

[a0, a1, . . . , a2n−1]. The minimal polynomial has degree bound n.

Output : The minimal polynomial Pof the sequence.

Start

Local variables : R, R0, R1, V , V0, V1, Q : polynomials in x;m= 2n−1: integer.

# initialization

m:= 2n−1;R0:= x2n;R1:= Pm

i=0 am−ixi;V0= 0 ;V1= 1 ;

# loop

while n≤deg(R1)do

(Q, R) := quotient and remainder of R0divided by R1;

V:= V0−Q V1;

V0:= V1;V1:= V;R0:= R1;R1:= R;

end while

# exit

Return P:= V1/lc(V1);

End.

Now we prove our result. Let a= (an)n∈be an arbitrary list and i, r, p ∈N. Let Ha

i,r,p denote

the following Hankel matrix of order r×p,

Ha

i,r,p =

aiai+1 ai+2 . . . ai+p−1

ai+1 ai+2 ai+p

ai+2

.

.

..

.

.

ai+r−1ai+r. . . . . . ai+r+p−2

and let Pa(x) be the minimal polynomial of a.

The next proposition shows the well known relation between the rank of Hankel matrix and the

sequence.

3

Proposition 1 Let abe a linearly recurrent sequence . If ahas a generating polynomial of degree

≤n, then the degree dof its minimal polynomial Pais equal to the rank of the Hankel matrix

Ha

0,n,n =

a0a1a2· · · an−2an−1

a1a2...an−1an

a2.......

.

..

.

.

.

.

........

.

..

.

.

an−2an−1· · · · · · a2n−2a2n−1

an−1an· · · · · · a2n−1a2n−2

.

The coeﬃcients of Pa(x) = xd−Pd−1

i=0 gixi∈K[x]are provided by the unique solution of the linear

system

Ha

0,d,d G= Ha

d,d,1,

that is,

a0a1a2· · · ad−1

a1a2...ad

a2.......

.

.

.

.

........

.

.

ad−1ad· · · · · · a2d−2

g0

g1

g2

.

.

.

gd−1

=

ad

ad+1

ad+2

.

.

.

a2d−1

.(1)

As an immediate corollary of Proposition 1, we have the following result.

Corollary 2 Using the notation of Proposition 1, a vector Y= (p0, . . . , pn)is solution of

Ha

0,n,n+1 Y= 0,

that is,

a0a1a2· · · an−1an

a1a2...anan+1

a2.......

.

..

.

.

.

.

........

.

..

.

.

an−1an· · · · · · a2n−2a2n−1

p0

p1

p2

.

.

.

pn−1

pn

= 0 (2)

if and only if the polynomial P(x) = Pn

i=0 pixi∈K[x]is multiple of Pa(x).

Proof.

By Proposition 1 the dimension of Ker(Ha

0,n,n+1) is n−d. For 0 ≤j≤n−1, let Cjdenote the

jth column of Ha

0,n,n+1, that is Cj= Ha

j,n,1= [aj, aj+1, . . . , an+j−1]t. Since Pa(x) is a generating

polynomial of a, for d≤j≤n−1, we obtain that

Cj−Xj−1

i=j−dgi−j+dCi= 0.

Thus the linear independent columns [−g0,...,−gd−1,1,0, . . . , 0]t, . . . , [0, . . . , 0,−g0, . . . , −gd−1,1]tde-

ﬁne a basis of Ker(Ha

0,n,n+1). Therefore, Y= (p0, . . . , pn) veriﬁes Ha

0,n,n+1 Y= 0 if and only if the

polynomial P(x) = Pn

i=0 pixiis a multiple of Pa(x).

If we consider m= 2n−1 and b

S=Pm

i=0 am−ixi, by applying Equation (2) we obtain:

∃R, U ∈K[x] such that deg(R)< n, deg(P)≤nand P(x)S(x) + U(x)x2n=R(x).(3)

Hence, it turns out that ﬁnding the minimal polynomial of ais equivalent to solving (3) for the

minimum degree of P. Moreover, it’s well known that

4

•the extended Euclidean Algorithm, with x2nand b

S, provides an equality as (3) when the ﬁrst

remainder of degree smaller than < n is reached. Let denote such remainder by Rk,

•if we consider other polynomials P0(x), U0(x) and R0(x) such that P0(x)b

S(x)+ U0(x)x2n=R0(x)

and deg(R0)<deg(Rk−1), then deg(P0)≥deg(P) and deg(U0)≥deg(U).

That proves that our modiﬁcation of Berlekamp-Massey Algorithm is right.

3 Lazy Evaluation

Our modiﬁed Berlekamp-Massey Algorithm admits a lazy evaluation, which may be very useful in

solving the following problem.

Let f(x)∈K[x] be a squarefree polynomial of degree n. Let Bbe the universal decomposition

algebra of f(x), let Abe a quotient algebra of Band a∈A. Thus, Ais a zero–dimensional algebra

given by

A'K[X1, . . . , Xn]/hf1, . . . , fni,

where f1, . . . , fndeﬁne a Gr¨obner basis. Our aim is to compute the minimal polynomial of a, or

at least, one of its factors. However, the dimension of A, denoted by m, over Kas vector space is

normally too big to manipulate matrices of order m. Therefore, we apply the idea of Wiedemann’s

Algorithm, by computing the coeﬃcients of a linearly recurrent sequence, at=φ(xt), where φis a

linear form over A. Moreover, since the computation of xtis usually very expensive and the minimal

polynomial is likely to have degree smaller than the dimension, we are interested in computing the

smallest possible number of coeﬃcients in order to get the wanted polynomial.

Hence, we ﬁrst choose l < m. We start Algorithm 2 with land [φ(x0), . . . , φ(x2l−1)] as input,

obtaining a polynomial as a result. Now, we test if such a polynomial is the minimal one. If this is not

the case, we choose again another l0,l < l0≤m, and we repeat the process with 2l0coeﬃcients. How-

ever, in this next step, it is possible to take advantages of all the quotients computed before (with the

exception of the last one), such that Euclidean Algorithm starts at R0=U0x2l0+V0

2l0−1

P

i=0

(φ(x2l0−1−i)xi)

and R1=U1x2l0+V1

2l0−1

P

i=0

(φ(x2l0−1−i)xi), where U0,V0,U1and V1are Bezout coeﬃcients computed

in the previous step. Manifestly, repeating this argument again and again, we obtain the minimal

polynomial.

The following pseudocode tries to facilitate the understanding of our lazy version of Berlekamp-

Massey Algorithm.

Obviously, the choice of lis not unique. Here we have started at l=m/4, adding two coeﬃcients

in every further step. In practice, the particular characteristics of the given problem could help to

choose a proper land the method of increasing it through the algorithm. Of course, the simpliﬁcation

of the Euclidean Algorithm in [3] must be considered to optimize the procedure.

5

Algorithm 3 The lazy Berlekamp-Massey Algorithm (in some particular context)

Input: m∈N,C∈Kn,G: Gr¨obner basis, a∈A. The minimal polynomial has degree bound m.

Output : The minimal polynomial Pof a

Start

Local variables : l, i: integers, R, R−1, R0, R1, V, V−1, V0, V1, U, U−1, U0, U1, S0, S1, Q : polynomials in

x,L, W :lists, validez;

# initialization

l=bm/4c;

L:= [1, a];W:= [1,Value(a, C)];

S0:= x2l;S1=W[1] x2l−1+W[2] x2l−2;

# loop

for ifrom 3to 2ldo

L[i] := normalf(L[i−1]a, G); V[i] := Value(L[i], C); S1=S1+V[i]x2l−i;

end for

R0:= S0;R1:= S1;V0= 0 ;V1= 1 ;U0= 1 ;V1= 0;

# loop

while l≤deg(R1)do

(Q, R) := quotient and remainder of R0divided by R1;

V:= V0−QV1;U:= U0−QU1;U−1:= U0;V−1:= V0;

V0:= V1;V1:= V;U0:= U1;U1:= U;R0:= R1;R1:= R;

end while

validez:=Subs(x=a, V1);

# loop

while validez 6= 0 do

l:= l+ 1;

# loop

for ifrom 2l−1to 2ldo

L[i] := normalf(L[i−1]a, G);

W[i] := Value(L[i], C);

end for

S0=x2S0;S1=x2S1+W[2l−1]x+W[2l];

R0:= U−1S0+V−1S1;R1:= U0S0+V0S1;

U1:= U0;V1:= V0;U0:= U−1;V0:= V−1;

# loop

while l≤deg(R1)do

(Q, R) := quotient and remainder of R0divided by R1;

V:= V0−QV1;U:= U0−QU1;U−1:= U0;V−1:= V0;

V0:= V1;V1:= V;U0:= U1;U1:= U;R0:= R1;R1:= R;

end while

validez:=Subs(x=a, V1)

end while # exit

Return P:= V1/leadcoeﬀ(P).

End.

References

[1] E.R. Berlekamp, Algebraic Coding Theory, McGraw-Hill, New York, ch. 7 (1968).

[2] U. Cheng, On the continued fraction and Berlekamp’s algorithm, IEEE Trans. Inform. Theory,

vol. IT-30, 541–44 (1984).

6

[3] J.L. Dornstetter, On the equivalence Between Berlekamp’s and Euclid’s Algorithm, IEEE Trans.

Inform. Theory, vol. IT-33, no 3,428–431 (1987).

[4] E. Jonckheere and C. Ma, A simple Hankel Interpretation of the Berlekamp–Massey Algorith,

Linear Algebra and its Applications 125, 65–76 (1989).

[5] J.L. Massey, Shift register synthesis and BCH decoding, IEEE Trans. Inform. Theory, vol. IT-15,

122–127 (1969).

[6] W.H. Mills, Continued Fractions and Linear Recurrences, Math. Comput. 29, 173–180 (1975).

[7] V. Pan, New Techniques for the Computation of linear recurrence coeﬃcients, Finite Fields and

Their Applications 6, 93–118 (2000).

[8] V. Shoup, A Computational Introduction to Number Theory and Algebra, Cambridge University

Press (2005).

[9] Y. Sugiyama et al. A method for solving key equation for decoding Goppa codes, Infor. Contr.

vol 27, 87–99 (1975).

[10] L.R. Welch and R.A. Scholtx, Continued fractions and Berlekamp’s algorithm, IEEE Trans.

Inform. Theory, vol. IT-25, 18–27 (1979).

7