44
The complete analysis of a polynomial factorization algorithm over finite fields Philippe Flajolet Algorithms Project, INRIA Rocquencourt, F-78153 Le Chesnay, France E-mail: Xavier Gourdon Algorithms Project, INRIA Rocquencourt, F-78153 Le Chesnay, France E-mail: and Daniel Panario School of Mathematics and Statistics, Carleton University, Ottawa, K1S 5B6, Canada. E-mail: Communicated by H. Prodinger Received 2000; revised 2000; accepted 2001 A unified treatment of parameters relevant to factoring polynomials over finite fields is given. The framework is based on generating functions for describing parameters of interest and on singularity analysis for extracting asymptotic values. An outcome is a complete analysis of the standard polynomial factorization chain that is based on elimination of repeated factors, distinct degree factorization, and equal degree separation. Several basic statistics on polynomials over finite fields are obtained in the course of the analysis. Key Words: Analysis of algorithms, analytic combinatorics, computer algebra, finite fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication January 2001). c Academic Press, 2001. INTRODUCTION Factoring polynomials over finite fields intervenes in many areas of computer science and computational mathematics like symbolic computation at large [24], polynomial factorization over the integers [12, 40], cryptography [10, 44, 48], num- ber theory [5], or coding theory [4]. The implications include finding complete 1

The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

The complete analysis ofa polynomial factorization algorithm

over finite fields

Philippe Flajolet

Algorithms Project, INRIA Rocquencourt, F-78153 Le Chesnay, FranceE-mail: Philippe.Flajolet�inria.fr

Xavier Gourdon

Algorithms Project, INRIA Rocquencourt, F-78153 Le Chesnay, FranceE-mail: Xavier.Gourdon�inria.fr

and

Daniel Panario

School of Mathematics and Statistics, Carleton University, Ottawa, K1S 5B6, Canada.E-mail: daniel�math. arleton. a

Communicated by H. Prodinger

Received 2000; revised 2000; accepted 2001

A unified treatment of parameters relevant to factoring polynomials over finite fields isgiven. The framework is based on generating functions for describing parameters of interestand on singularity analysis for extracting asymptotic values. An outcome is a completeanalysis of the standard polynomial factorization chain that is based on elimination ofrepeated factors, distinct degree factorization, and equal degree separation. Several basicstatistics on polynomials over finite fields are obtained in the course of the analysis.

Key Words: Analysis of algorithms, analytic combinatorics, computeralgebra, finitefields, factorization algorithms, random polynomials

Journal of Algorihms, to appear (accepted for publication January 2001).c Academic Press, 2001.

INTRODUCTION

Factoring polynomials over finite fields intervenes in many areas of computerscience and computational mathematics like symbolic computation at large [24],polynomial factorization over the integers [12, 40], cryptography [10, 44, 48], num-ber theory [5], or coding theory [4]. The implications include finding complete

1

Page 2: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

2 P. FLAJOLET, X. GOURDON, D. PANARIO

partial fraction decompositions, designing cyclic redundancy codes, computingthe number of points on elliptic curves, and building arithmetic public key cryp-tosystems. In particular, the factorization ofrandompolynomials over finite fieldsis directly needed in the randomized index calculus method for computing discretelogarithms over finite fields [48].

This paper derives basic probabilistic properties of random polynomials overfinite fields that are of interest in the study of polynomial factorization algorithms.We show that the main characteristics of random polynomial can be treated sys-tematically by methods of “analytic combinatorics” based on the combined useof generating functions and of singularity analysis. Our object of study is theclassical factorization chain which is described in Fig. 1 and which, despite itssimplicity, does not appear to have been totally analysed sofar. In this paper, weprovide a complete average-case analysis.

In asymptotic terms, the algorithm that we study need not be the fastest availableat the moment; compare with [25, 26, 34, 55, 56]. For instance, Shoup [55] providesthe average-case analysis of an algorithm he proposes and his highly interestingmethods are based on estimates for the number of solutions ofequations overfinite fields and Weil’s bounds—the scope is however quite different from theframework of this paper. One of the good reasons for studyingthe classical chainis that it is representative of what is often implemented in general purpose computeralgebra systems and of what is likely to be practically relevant for many problemsof “moderate” size. In effect, the book by Geddeset al. [28] describes a chainvery much similar to ours on which the design of polynomial factorization in theMaple system is based—a fact easily confirmed by tracing facilities availableunder the system. Knuth’s authoritative treatise [40] and the remarkable recentbook of von zur Gathen and Gerhard [24] expose the fundamental aspects of theclassical chain in detail. We refer globally to [40, p. 449] and [24, pp. 393–397]for the historical context of this and closely related algorithms, with some of theoriginators being Legendre, Gauß, Galois, Berlekamp, Cantor, and Zassenhaus.

An important reason for our interest in these questions is methodological. In-deed, the discipline of analysing completely an algorithm,which is in the line ofKnuth’s works [39, 40, 41, 42], reveals parameters that are of general interest forpolynomial factorization algorithms and for problems thatdeal with polynomialsover finite fields at large. A specific illustration is the paper of Panario and Rich-mond [52] that deals with testing polynomial irreducibility along lines similar tothose of the present paper.

Algorithmic framework. Let Fq be the finite field withq elements. The algo-rithmic problem that we address is as follows: given a monic univariate polynomialf 2 Fq [x℄, find the complete factorizationf = fe11 � � � ferr , wheref1; : : : ; fk arepairwise distinct monic irreducible polynomials ande1; : : : ; er are (strictly) pos-itive integers. The basic factorization chain (see Fig. 1) operates in three stages.

Page 3: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 3pro edure fa tor(f : polynomial);1. a:=ERF(f);{"a" is squarefree}2. b:=DDF(a);{"b" is a partial fa t. into distin t degrees}F:=1;3. for k from 1 to n doF:=F.EDF(b[k℄,k);{refine distin t degree fa t. for deg. "k"}od;4. return(F.fa tor(f/a));end;FIG. 1. The complete factorization chain.

ERF: elimination of repeated factorsreplaces a polynomialf = fe11 � � � ferrby a squarefree one that contains all the irreducible factors of the original polyno-mial but with exponents reduced to 1:f 7! a =Yj fj :

DDF: distinct-degree factorizationsplits a squarefree polynomial into polyno-mials whose irreducible factors all have the same degree:a 7! b1 � b2 � � � bn where bk = Ydeg(fj)=k fj :

EDF: equal-degree factorizationcompletely splits a polynomial whose irre-ducible factors are already constrained to have the same degree:bk 7! bk;1 � � � bk;`k where deg(bk;j = k):An often used variant of the first stage is:

SFF: squarefree factorizationdetermines directly thedecompositionf =Qi giiwhere thegi are squarefree and pairwise coprime so thatgi =Qej=i fj .

Page 4: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

4 P. FLAJOLET, X. GOURDON, D. PANARIO

As implied by the results of Section 2 the difference in costsinduced by the twoversions, ERF and SFF, is marginal, while consideration of ERF greatly simplifiesthe whole analysis. We refer globally to [24, Ch. 14] for a complete discussion ofthis and other algorithmic aspects.

Given a polynomial over the integers, likeg = x9 � 3x8 + 4x7 � 3x6 + 2x5 � 2x4 + x3 + x2 � 2x+ 1;most general-purpose computer algebra will approach the factorization via mod-ular reductions. For instance, the reduction modulo 5 givesf � (g mod 5) = x9 + 2x8 + 4x7 + 2x6 + 2x5 + 3x4 + x3 + x2 + 3x+ 1:Elimination of repeated factors (ERF) is easily achieved bygcd computations andit produces, modulo 5, the partial factorizationf = (x+ 4)a = (x+ 4)(x8 + 3x7 + 2x6 + 4x5 + x4 + 4x3 + x+ 4): (1)

The next phase of distinct-degree factorization (DDF) thenuncovers a partialfactorization of the eighth degree factor asa = b1 � b2 = �x2 + 2x+ 2� � �x6 + x5 + 3x4 + x3 + 3x2 + x+ 2� : (2)

There, in two successive steps, the groups of factors of degree 1 (there must be twosuch factors) and of degree 2 (there must be three such factors) have been isolated.Finally, the second and sixth degree polynomials are split by two separate callsto the equal-degree factorization (EDF) algorithm into their linear and quadraticfactors:b1 = (x + 3)(x+ 4); b2 = (x2 + x+ 1)(x2 + x+ 2)(x2 + 4x+ 1): (3)

In this way, the complete factorization off modulo 5 is obtained from (1), (2), (3):f = (x+ 3)(x+ 4)2(x2 + x+ 1)(x2 + x+ 2)(x2 + 4x+ 1):Various methods,not discussed in this paper, then permit one to lift the factorizationto the integers; see [24, Ch. 15]. Here, this eventually produces the completefactorization overZ[x℄,f = (x� 1)2(x2 � x+ 1)(x2 + x+ 1)(x3 � x2 + 1):In this case, the squarefree factorization (SFF) approach would only lead to ex-tracting the repeated factor(x� 1)2, or (x+ 4)2 mod 5, at an early stage.

Page 5: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 5

Computational model.We fix a finite field Fq with q = pm (p prime) andconsider the ring of polynomialsFq [x℄; see [4, 24, 28, 40, 45] for background.The probabilistic modelassumes allqn monic polynomials of degreen to beequally likely and all average-case analyses are expressedas asymptotic forms inn, the degree of the polynomial to be factored. Thecomplexity modelassumesthat a basic field operation has costO(1), the cost of a sum isO(n), and thecost of a product, a division or a gcd isO(n2), when applied to polynomials ofdegree� n. For dominant asymptotics, we can freely restrict our attention topolynomial products and gcds. We take asM(n) = �1n2 the cost of multiplyingtwo polynomials of degree less thann modulo a polynomial of degreen, and asG(n) = �2n2 the cost of a gcd between a polynomial of degreen and a polynomialof degree at mostn. (There,�1 and�2 are system and implementation dependentconstants.) What we have in mind is a general purpose factorization algorithmtypically applied to polynomials of moderate size and degree, where operationsare often implemented by quadratic algorithms. Similar studies could be conductedusing FFT (fast Fourier transform) based algorithms.

Summary of results. Figure 2 summarizes the interplay between probabilisticproperties of random polynomials and polynomial factorization. We offer here afew comments.

A random polynomial of degreen is irreducible with a small probability ofabout1=n and has close tologn factors on average and with a high probability(Section 1). Thus, the factorization of a random polynomialover a finite field isalmost surely nontrivial. Each of the various phases of polynomial factorizationhas its own “physics” with implications on the corresponding costs. Here is a briefsummary.

ERF: The first phase of the factorization is the elimination of repeated fac-tors, ERF. It is deterministic and described in Section 2. This ERF stage returnsthe squarefree partof the original polynomial in which each irreducible factorof the original polynomial appears exactly once (the remaining factors form thenon-squarefree part). In fact, the squarefree polynomials have a positive density(asymptotically) and the non-squarefree part of a random polynomial is with highprobability of degreeO(1) as expressed by Theorem 2.1. In a precise technicalsense, the cost of the ERF phase is asymptotically that of a single gcd (Theo-rem 2.2), so that most of the factorization cost results fromthe subsequent phases,namely, DDF and EDF.

DDF: The second phase DDF, also deterministic and describedin Section 3,splits the squarefree parta of the polynomial to be factored into a producta =b1 � b2 � � � bn, wherebk is formed by the product of all the irreducible factors ofa

Page 6: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

6 P. FLAJOLET, X. GOURDON, D. PANARIO

Phase Properties Refs.

(Sec. 1) Fraction of irreducibles is� 1n . Eq. (8); [4, 40]The number of irreducible factors has mean�log n and a limiting Gaussian law.

Eq. (13); [4, 7, 21, 40]

ERF(Sec. 2)

Non squarefree part has sizeO(1)on average andwith high probability.

Thm. 2.1; [4, 9, 18]

Algorithmic cost of ERF is� G(n) on averageand with high probability

Thm 2.2; [18]

DDF(Sec. 3)

Largest degree is�(n) with Dickman distribu-tion and mean� g n whereg := 0:62432.

Thm 3.1; [30, 50]

Modified Dickman laws hold for two largest de-grees.

Thm 3.2; [30, 50]

Algorithmic cost of DDF isO(nM(n) log q);three stopping rules are compared.

Thm 3.3; [18]

(Sec. 4) DDF yields a complete factorization with proba-bility close toe� .

Thm 4.1; [18, 32, 38]

Total degree of unfactored part after DDF hasmeanO(log n), but “soft” distribution tails andstandard deviationO(pn). Thm 4.2; [18, 35]

ERF(Sec. 5)

The probability of repeated irreducible factors ofdegreek is approximately Poisson(1=k) Thm 5.1; [37]

Algorithmic cost of ERF isO(n2 log q) on aver-age, as opposed to a worst-caseO(n3 log q). Thm 5.2; [18]

FIG. 2. Main properties of random polynomials of degreen and of corresponding factorizations,together with some relevant references. HereM(n) := �1n2 represents the cost of a polynomialmultiplication andG(n) := �2n2 the cost of a gcd.

that have degreek. A random polynomial has with high probability several largefactors, that is, of degrees�(n). This is quantified by Theorems 3.1 and 3.2 wherethe Dickman function and some of its relatives serve to express the correspondingprobability distributions. Such estimates form the basis of a precise comparison ofthree stopping rules: the “naıve” rule, the “half-degree” rule and the “early abort”rule whose costs are found to be in the approximate proportion 1 :: 34 :: 23 ; seeTheorem 3.3. At the end of the DDF phase, the factorization iscomplete witha probability ranging asymptotically between0:56 and0:67 (Theorem 4.1). Inaddition, the number of degree values such that more than oneirreducible factor

Page 7: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 7

of that degree occurs is typicallyO(1), and the total degree passed to EDF isO(logn) on average, though it has a large variability (Theorem 4.2).EDF: The third phase, EDF, is a randomized procedure described in Section 5.

It involves a recursive refinement process based on randomized splittings thatturns out to be closely related to digital trees, also known as “tries”, see [41]. Theanalysis combines properties of polynomials (Theorem 5.1)with properties of thesplitting process (Lemma 5.1). As a consequence, the expected cost of EDF isproved to be comparatively small, beingO(n2 log q) (Theorem 5.2).

Precise statements are given in the next sections with an explicit dependence onthe field cardinalityq. (Some of them involve number-theoretic functions that canbe both evaluated and estimated easily.) A simplified picture is as follows. TheERF phase involves with high probability little more than a single polynomial gcd,so that its expected cost isO(n2). The DDF phase of costO(n3 log q) (both onaverage and in the worst-case) is the one that is most intensive computationally,where control by the “early-abort” strategy is expected to bring gains close to36%. The last phase of EDF is typically executed less than 50%of the timeand its cost,O(n2 log q) on average, is again small compared to that of DDF. Acomparison between worst-case costs and average-case costs for each phase isdrawn in Section 6.

Note on methodology.An earlier but almost identical version of this papersub-mitted to another journal dedicated to computing was met with sharp criticism fromtwo referees. One criticism had to do with the asymptotically suboptimal charac-ter of the algorithms that we analyse. However, record-breaking computations areonly one facet of the story and, from the authors’ experiencewith computeralgebrasystems, much usage involves polynomials of moderate degree having moderatelylarge coefficients. For this, good implementations are definitely wanted; thus, weclaim some justification for interest in algorithms that aresuboptimal in the strictasymptotic sense but may very well turn out in many practicalcontexts to performbetter than asymptotically optimal algorithms.

Anothercriticism had to do with the model of random polynomials that we adopt,namely the uniform distribution over theqn polynomials of degreen. One refereesaid: “most polynomials are not sampled at random over the set of allpolynomi-als”. This is certainly true in a narrow-minded perspective. However, we makethe following observations:(i) a large body of algorithms building on top of fac-torization over finite fieldsdoalready involve a randomization that is expected to“propagate”, see for example Ben-Or’s construction of irreducible polynomials [3]or the index calculus method described in [48];(ii) no one is aware of any explicitconstruction law that would bias polynomials towards beingmore likely to be irre-ducible than factorizable [47, Problem 27]—indeed such a law would be a major

Page 8: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

8 P. FLAJOLET, X. GOURDON, D. PANARIO

discovery!—so that the randomness assumption, even if somewhat heuristic1, isone decent way of coping with the current lack of our knowledge; (iii) simu-lations amply confirm that many varieties of polynomials produced by all sortsof processes behave “as expected” with respect to factorization (see below for astriking example);(iv) accordingly, there exist several theoretical results demon-strating rigorously the fact that various systematic “laws” produce polynomialswhose behaviour with respect to factorization is just as predicted by the uniformrandomness model. As a typical illustration of the latter point, Hensley [33] hasestablished a “Dirichlet’s theorem” for the ring of polynomials over a finite fieldto the effect that the distribution of irreducibles in any arithmetic progression (i.e.,a sequencea(x)n(x) + b(x) with a; b fixed) conforms to “normality”.

To demonstrate our point, here is an easily reproducible experiment. We buildquite specific polynomials by a deterministic process and examine the mean num-ber of irreducible factors that they contain. Letpj be thejth prime and letM(n; r)be the Hankel matrix filled with primes starting withpr: the(i; j) entry ofM ispi+j+r�1; the test polynomial�n;r(x) 2 Z[x℄ is the characteristic polynomialof M(n; r). In the experiment, we fix the dimensionn = 20 and reduce the�polynomials modulo various primesp (actually the primes of rank4; 16; 64 : : :)upon averaging over valuesr = 0; : : : ; 99. Here is the observed mean over eachsample of size 100 as compared to the values predicted by the uniform model andgiven in [40, Ex. 4.6.2.5].p 7 53 311 1619 8161 38873

Exact mean 3.690 3.607 3.599 3.598 3.597 3.597Sample mean 3.84 3.57 3.60 3.53 3.40 3.50

We purposely took here asmall sample ofspecialpolynomials (characteristicpolynomials) associated withstructuredmatrices (of Hankel type) built onpar-ticular coefficients (here the prime numbers). We indeed verify thatthe empiricaldata conform quite well to what the uniform randomness modelpredicts.

This paper constitutes the journal version of an extended abstract presented at theICALP’96 Conference [18]. It is also organized as a survey ofmajor probabilisticproperties of polynomials that are relevant to basic factorization algorithms.

1. ANALYTIC–COMBINATORIAL METHODS1For instance the design of Pollard’s “rho method” for integer factoring is entirely based on similarheuristics regarding integers; these were later largely vindicated by Bach [2].

Page 9: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 9

This section gathers basic tools needed to analyse properties of random poly-nomials. It centres around the use of generating functions,either univariate ormultivariate, whose functional relations reflect the algebraic decompositions ofvarious classes of polynomials. The asymptotic analysis ofcoefficients of gener-ating functions is then attained by means of singularities.The results in this sectionare classical, but they are needed to set the stage for subsequent analyses. Generalreferences for this section are Chapter 3 of Berlekamp’s book [4], the exercisesection 4.6.2 of Knuth’s book [40], the paper [19] or Odlyzko’s survey [49] forasymptotic techniques, and the book [20] for the interplay between combinatorialand analytic methods.

1.1. Generating functions

We present first a few general principles that enable one to set up “symboli-cally” equations for generating functions starting from combinatorial specifica-tions. Given a combinatorial object!, the formal identity11� ! = 1 + ! + !2 + � � �generates symbolically arbitrary sequences composed of!. Let I be a family of“primitive” combinatorial objects. Then, the productsQ = Y!2I(1 + !); and P = Y!2I(1� !)�1: (4)

generate respectively the class of all finite sets and multisets (sets with possiblerepetitions) of elements taken fromI. (This results simply from expansion bydistributivity and the remark above concerning the meaningof (1� !)�1.)

We now specialize the discussion tomonicpolynomials2 and takeI to be thecollection of all monic irreducible polynomials. Then, by the unique factorizationproperty of polynomials,P gives rise to the collection of all monic polynomialsandQ becomes the collection of all monic squarefree polynomialsoverFq . Let zbe a formal variable, andj!j be the degree of the polynomial!. The substitution! 7! zj!j in formal sums and products of objects gives rise to countinggeneratingfunction. ForI itself identified with the formal sum

P!2I !, the generatingfunction is I(z) = X!2I zj!j =Xn Inzn;2All subsequent enumeration results are for polynomials normailized so as to be monic.

Page 10: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

10 P. FLAJOLET, X. GOURDON, D. PANARIO

whereIn is the number of polynomials inI having degreen. Similarly, thegenerating functions ofQ andP are obtained as reflexes of the decompositions (4):Q(z) = Y!2I(1 + zj!j) = 1Yn=1(1 + zn)InP (z) = Y!2I(1� zj!j)�1 = 1Yn=1(1� zn)�In : (5)

The coefficientsQn = [zn℄Q(z) andPn = [zn℄P (z) evaluate to the number ofmonic squarefree polynomials of degreen, and to the number of monic polyno-mials of degreen, respectively. Obviously,Pn = qn, and therefore we haveapriori P (z) = 11� qz : (6)

In other words, we knowP (z) elementarily whileI(z) andQ(z) are bound bytheir relations toP (z).

First and foremost, the number of irreducible polynomials,In, is determinedimplicitly from the second equation of (5) that relates it toP (z). A well-knownprocess based on the Moebius inversion formula gives it in explicit form; see [9,p. 41], and Theorem 3.43 in [4, p. 84]. Indeed, taking logarithms and rearrangingthe sums leads tolog 11� qz = 1Xk=1 I(zk)k ; and

qnn =Xkjn In=kk : (7)

The relation is then solved forIn by means of Moebius inversion, which yieldsIn = 1nXkjn �(k)qn=k; and I(z) = 1Xk=1 �(k)k log 11� qzk :In summary:Fa t. The numberIn of irreducible polynomials overFq [x℄ satisfiesIn = 1nXkjn �(k)qn=k = qnn +O�qn=2n � : (8)

Thus, a fraction very close to1=n of the polynomials of degreen is irreducible.

This theorem is an analogue of the prime number theorem for integers. As anaside, it was first proven by Gauss in the case of prime fields and it appeared inhis posthumous opus [27]; see also [15, 53] for early references.

Page 11: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 11

Next the numberQn of squarefree polynomials is entirely determined by theknowledge ofIn, given Equation (5). A direct way to makeQn explicit goes asfollows: each polynomialf factors uniquely asf = s � t2, wheres is a squarefreepolynomial andt is an arbitrary polynomial (separate the irreducible factors of faccording to the parity of their exponents). We thus haveP (z) = Q(z) � P (z2),so that Q(z) = P (z)P (z2) = 1� qz21� qz :Thus, the number of squarefree polynomials of degreen in Fq [x℄ isQn = � qn if n = 0; 1;qn�1(q � 1) if n � 2: (9)

This result seems to have appeared for the first time in Carlitz’s study [9].

1.2. Parameters

We need extensions of the symbolic method in order to take care of characteristicparameters of polynomial factorization. Let� be a class of monic polynomials,and�some integer–valued parameteron�. Then, the bivariate generating function�(z; u) = X!2� zj!ju�(!)is such that the coefficient[znuk℄�(z; u) represents the number of polynomialsof degreen in � with �–parameter equal tok. Bivariate generating functionscontain all information related to the distribution of a parameter. Averages andstandard deviations are obtained by successive differentiations of these bivariategenerating functions with respect tou (the variable marking the parameter), andthen by settingu = 1.

If the parameter� is additive, meaning that�(f �g) = �(f)+�(g) for relativelyprimef; g 2 Fq [x℄, then product decompositions of the form (5) generalize underthe translation rule! 7! zj!ju�(!). The technique of rearranging logarithms ofinfinite products employed in (7) is then useful in simplifying such expressions.For instance, the bivariate generating function of all polynomials with� the numberof their irreducible factors (multiplicity being counted)isP (z; u) = Yn�1 (1� uzn)�In = exp 1Xk=1uk I(zk)k ! : (10)

Much use is made of this technique in the next four sections.

Page 12: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

12 P. FLAJOLET, X. GOURDON, D. PANARIO

A graphical rendering of the factorization types of 5 polynomials of degree 100 overF7 :

Each circle represents the degree of an irreducible factor with the circle areas being pro-portional to degrees. On this experiment, the 5 factorization types found are[1; 2; 9; 19; 69℄; [3; 7; 26; 64℄; [1; 1; 2; 5; 8; 11; 19; 53℄; [1; 1; 1; 1; 5; 91℄; [2; 2; 96℄:This illustrates the property that factorizations overfinite fields are usually nontrivial and thatthere tends to be one ora few irreducible factors of comparatively large degree (Theorems 3.1and 3.2).

FIG. 3. Simulations of random polynomial factorizations.

1.3. Asymptotic analysis

Generating functions encode complete information on theircoefficients. Fur-thermore, the behaviour of a generating function near its dominant positive singu-larity (“dominant” means in this context “of smallest modulus”) is an importantsource of coefficient asymptotics.

The generating functionsf(z) to be studied in this paper are singular atz = 1=qand most have there an isolated singularity. Consequently,their coefficientsfn =[zn℄f(z) satisfy an estimate of the formfn � qn�(n), wherelim sup j�(n)j1=n =1 is a subexponential factor that reflects the nature of the singularity atz = 1=q.In particular, an expansion nearz = 1=q of the formf(z) = 1(1� qz)� �log 11� qz�k (1 + o(1)) (11)

translates into coefficients by the method known as singularity analysis [19, 49]:fn = [zn℄f(z) = qnn��1�(�) (logn)k (1 + o(1)): (12)

The transition from (11) to (12) is ensured by transfer theorems that require analyticcontinuation off(z) outside its circle of convergence, a condition that is verifiedby inspection in most cases considered here.

A typical instance is the analysis of the number of irreducible factors in a randompolynomial of degreen. The bivariate generating function appears already in (10).Differentiating with respect tou, settingu = 1 and then analysing the singularityatu = 1 provides moment estimates [40, Ex. 4.6.2.5]; methods that build furtheron singularity analysis even give access to a limiting distribution [7, 21].

Page 13: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 13Fa t. LetXn be the random variable that represents the number of irreduciblefactors in a random polynomial of degreen. Then the meanE(Xn) and varianceVar(Xn) satisfyE(Xn) = logn+O(1); Var(Xn) = logn+O(1): (13)

In addition the distribution of(Xn � E(Xn))=pVar(Xn) is asymptotically nor-mal.

Thus, the factorization of a polynomial is with high probability nontrivial; seeFigure 3 for a graphic illustration.

Anotheruseful asymptotic coefficient extractionmethod isDarboux’s method [13,32] whose principle is as follows: if an analytic functionf(z) defined in the closeddisk jzj �1 isk times continuously differentiable (Ck) on jzj = 1, then its coeffi-cients satisfy [zn℄f(z) = o(1=nk): (14)

A recourse to Darboux’s method is needed in Section 4, given the existence ofnatural boundaries for generating functions that occur specifically there.

1.4. The permutation model and large fields

The following fact is well-known: As the cardinalityq of the fieldFq goes toinfinity (n staying fixed!), the joint distribution of the degrees of theirreduciblefactors in a random polynomial of degreen converges to the joint distribution of thelengths of cycles in a random permutation of sizen. This property is visible at thegenerating functions level, whenever a generating function of polynomials taken atz=q converges (asq ! 1) to the corresponding exponential generating functionof permutations. For instance, the generating function of all monic polynomials,when normalized with the change of variablez 7! z=q, isP �zq� = 11� z = 1Xn=0n!znn! ;which is also the exponential generating function of all permutations. Similarly,we have I �zq� !(q!1) log 11� z = 1Xn=1(n� 1)!znn! ;the exponential generating function of cyclic permutations. The relation (10)betweenP (z) andI(z) that expresses the unique factorization property for poly-

Page 14: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

14 P. FLAJOLET, X. GOURDON, D. PANARIOpro edure ERF(f : polynomial);g := g d(f,f'); h := f/g; k := g d(g,h);while k<>1 do g := g/k; k := g d(g,h) od;if g <> 1 then h := h*ERF(g^(1/p)) fi;return(h); {"h" is squarefree}end;FIG. 4. The elimination of repeated factors algorithm (ERF).

nomials reduces asq !1 to11� z = exp�log 11� z� ;which is well-kknown to express the unique decomposition ofpermutations intocycles; see [20, 29] for background.

This gives rise to a useful heuristic: probabilistic properties of polynomial fac-torization are expected to have a shape resembling that of correspondingpropertiesof the cycle decompositionof permutations3. A precise instance of this fact is men-tioned by Greene and Knuth [32] in connection with the probability that a randompolynomial admits factors of distinct degrees, which, for largeq and largen isfound to approache� . Such phenomena are clearly useful in understanding thebehaviour of polynomial factorizations in fields of “large”cardinalities—the caseof “small” fields then appearing as a “q–deformation” with a typically mild effect.Section 4 provides several examples related to quantifyingthe output of the DDFfactorization.

2. ELIMINATION OF REPEATED FACTORS (ERF)

The first step in the factorization chain summarized in Figure 4 is the eliminationof its repeated factors. In characteristic zero, this is achieved thanks to the followingproperty: A gcd between a polynomialf and its derivativef 0 extracts all therepeated factors off .

In Fq with q = pm and p a prime number, additional control is needed inorder to deal withpth powers whose derivatives are identically 0. The first lineof the algorithm in Figure 4 collects inh one copy of each of the irreduciblefactors off , except the ones whose multiplicity is a multiple ofp. The while3There is a similar “resemblance” between properties of natural numbers whose representation inbaseq has lengthn and polynomials of degreen in Fq [x℄. For additive properties, this correspondsto a rough equivalence between additions with or without carries; for mixed additive-multiplicativeproperties, the analogy lies however far deeper and is accordingly much less understood.

Page 15: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 15

loop stores ing the factors whose multiplicity is a power ofp, without eliminatingtheir repetitions. The last part of the algorithm adds toh the factors ing withrepetitions eliminated. The auxiliary computation ofpth roots,g1=p, is performedin the classical way [28, p. 344], using the identity(ap + bp)1=p = (a + b).There exist alternative algorithms giving the full squarefree factorization (see [40],Ex. 4.6.2.36); however, as Theorem 2.1 below shows, the reduction of degreeinduced by the additional computational effort is onlyO(1). We have opted for theelimination of repeated factors by ERF (rather than the morecommon squarefreefactorization SFF) as the analysis develops more transparently while the overallcosts of the complete factorization chain are onlyverymarginally affected by thealgorithm chosen for the first stage.Theorem 2.1. (i) A random polynomial of degreen � 2 in Fq [x℄ has aprobability1� 1=q to be squarefree.(ii) The total degree� of the non-squarefree part of a random polynomial ofdegreen has an expected value that tends to the limitCq =Xk�1 kIkq2k � qk ;in addition, the quantityCq satisfiesCq � 1=q asq !1.(iii) The tail probabilities of� decay exponentially fast:Pr(�(f) = k; jf j = n) = O �23�k! :

Proof. Part(i) is a classical result that we have already derived in (9). As forpart(ii), the bivariate generating function of the degree of the non-squarefree partof monic polynomials inFq [x℄ is, by the symbolic method of Section 1,P (z; u) = Yk�1�1 + zk1� ukzk�Ik :The mean degree of the non-squarefree part is obtained by setting u = 1 in thederivative ofP (z; u) with respect tou and the asymptotic estimate follows bysingularity analysis,�P (z; u)�u ����u=1 = P (z) �Xk�1 Ik z2k1� zk�z!1=q 11� qzXk�1 Ik q�2k1� q�k ;

Page 16: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

16 P. FLAJOLET, X. GOURDON, D. PANARIO

hence the stated value ofCq . The asymptotic limit ofCq asq ! 1 is obtainedfrom there by the expansionk Ik = qk +O(qk=2).

As regards part(iii), consider the functionP (z; 3=2) and compare it withQ(z),the generating function of squarefree polynomials:P (z; 3=2)Q(z) = Yk�1 1 + z2k( 32 )k(1 + zk)(1� ( 32 )kzk)!Ik :The infinite product is convergent and analytic in a disk thatproperly containsjzj � 1=q. Thus,P (z; 3=2) has a simple pole atz = 1=q, and by singularityanalysis, one has1qn [zn℄P (z; 3=2) � 1qn Xjf j=n�32��(f) = O(1):Thus the expectationE((3=2)�) remains bounded, which implies the exponential

tail bound.

Theorem 2.1 has meaningful consequences for the recursive structure of thefa torprocedure. The exponential tail of Part(iii) implies that any polynomiallybounded function of the non-squarefree part stays of orderO(1) on average. Inparticular, the overall cost of the recursive calls (Step 4 in the top-level factorprocedure of Figure 1) isO(1) on average. Accordingly, the ERF phase has a costentirely dominated by that of its first gcd, namelyg d(f; f 0).Theorem 2.2. The expected cost of the ERF phase applied to a randompolynomial of degreen is asymptotically that of a single gcd,�ERF n � �2n2:

3. DISTINCT-DEGREE FACTORIZATION (DDF)

The second stage of the factorization chain is the distinct-degree factorizationand it involves splitting a squarefree polynomial into polynomials whose irre-ducible factors all have the same degree. This means expressing the squarefreepolynomiala in the formb1 � b2 � � � bn wherebk is the product of all the irreduciblefactors of degreek that figure ina (assumed to be squarefree). The basic algorithmis described in Fig. 5 and its design relies on the following property (see, e.g., [45],

Page 17: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 17pro edure DDF(a : polynomial);["a" is a moni squarefree polynomial℄n := deg(a); g := a; h := x;for k := 1 to n do1. h := h^q mod g;2. b[k℄ := g d(h-x,g);3. g := g/b[k℄;{"a" without fa tors of deg <=k}4. if b[k℄ <> 1 then h := h mod g fi;od;return(b[1℄.b[2℄...b[n℄);{b[k℄ is prod. of irred. of deg.=k}end;FIG. 5. The “basic strategy” of the distinct-degree factorizationalgorithm (DDF).

p. 91, Theorem 3.20):For k � 1, the polynomial�k := xqk � x 2 Fq [x℄ is theproduct of all monic irreducible polynomials inFq [x℄ whose degree dividesk.Thus sweeping over successive values ofk and computing gcd’s with�k leads toa partial factorization. Three different stopping rules can be considered:

— Thebasic strategyexplores all the valuesk = 1 : : n and corresponds to theversion given in the algorithm in Fig. 5.

— Thehalf-degree strategyconsists in stopping the DDF loop whenk = n=2,since at that moment the remaining factor is either1 or irreducible.

— Theearly-abort strategystops the main loop of DDF as soon as2k exceedsthe degree of the remaining factorg. In this case, the remaining factor is bynecessity irreducible.

The first rule is too naıve to be of algorithmic interest but it serves the purposeof introducing the basic methods needed. The analyses are carried out in Sub-section 3.2. They benefit from informations regarding the two largest irreduciblefactors of a random polynomial, a topic that we address first in Subsection 3.1.See Figures 6 and 7 for numerical data.

3.1. Distribution of largest degrees of factors

A random polynomial has with high probability several irreducible factorswhose degree is of the order ofn. The distribution of the largest degree amongthe irreducible factors of a random polynomial overFq underlies many prob-lems dealing with polynomials over finite fields. For instance, information on

Page 18: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

18 P. FLAJOLET, X. GOURDON, D. PANARIO

this distribution is useful when computing discrete logarithms in order to discardpolynomials that cannot be written in terms of smooth ones [48].

Specifically, we consider the two largest degreesD[1℄n ,D[2℄n of the distinct factorsof a random polynomial of degreen in Fq . Statistics on the largest degree of theirreducible factors of a random polynomial inFq [x℄ have already been consideredin the literature. Car [8] first obtained an asymptotic expression for the cumulativedistribution function ofD[1℄n in terms of theDickman function. This function is aclassical number-theoretic function that was originally introduced to describe thedistribution of the largest prime divisor of a random integer. We refer to [14, 16,41, 43, 57] as general references to the Dickman function in relation to arithmeticproblems, especially Tenebaum’s analytic treatment of theDickman function [57],the paper of Knuth and Trabb Pardo on integer factorization [43], and Knuth’saccount in [41, Sec. 4.5.4].Fa t. The distribution of the largest degreeD[1℄n satisfies for allx 2 (0; 1):limn!1PrfD[1℄n � xg = F (x);whereF (x) = �(1=x)and�denotes the Dickman function. The Dickman functionis defined as the unique continuous solution of the difference-differential equation�(u) = 1 (0 � u � 1); u�0(u) = ��(u� 1) (u > 1): (15)

In particular, one has E(D[1℄n ) � gn;whereg := 0:62432 is known as Golomb’s constant; see [17].

In the context of this paper, fine properties ofD[1℄n , D[2℄n provide insight on thestopping condition for the DDF stage. The statements of Theorems 3.1 and 3.2that follow are borrowed4 from [50]. The proofs given in [50] rely on an orig-inal approach of Gourdon [30, 31] that leads to local limit theorems. Indeed,Theorems 3.1, 3.2 below, give the asymptotic distribution of the two largest de-greesD[1℄n ; D[2℄n where the limit density functions are accessed via their Laplacetransforms. A key role is played by the exponential integral functionE defined byE(t) = Z +1t e�vv dv:4The authors take this opportunity to correct mistakes in thestatements of Theorems 1 and 2 of [50]:the error terms inadvertently written there as multiplicative terms should be read as additive correc-tion terms (in accordance to the proofs that stand). See Tenenbaum’s informative review of [50] inMathematical Reviews, 2001, in press.

Page 19: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 19

0

0.2

0.4

0.6

0.8

1

0.2 0.4 0.6 0.8 1

FIG. 6. A plot of the “density” of the largest irreducible factor degree for polynomials ofF7 [x℄:the representation of(xn) Pr(D1 = xn), for degreesn = 1; : : : ; 25 andx 2 [0; 1℄ (dashed lines)shows fast convergence against the limitf(x) (continuous curve).Theorem 3.1. The largest degreeD[1℄n among the irreducible factors of arandom polynomial of degreen overFq satisfies the “local limit” estimatePr(D[1℄n = m) = 1mf �mn �+O� lognm2 � ;wheref(�) is a continuous function that is defined by the inverse Laplace integral:f(�) = 12�i Z 1+i11�i1 e�E(�h)h e(1��)h dh: (16)

In other words, the largest degree is on averageO(n), and the probability that itsvalue equalsm is about1=m with a modulation factor that involves the Dickmanfunction. (It can be verified by direct Laplace transform calculations thatf(�) =�(1=�� 1), with � the Dickman function as defined by (15).) The next theoremshows that similar estimates involving “Dickman-like” functions hold if a gap isimposed or if one considers the joint distribution of the twolargest factors.Theorem 3.2. The two largest degreesD[1℄n andD[2℄n of the distinct factorsof a random polynomial of degreen in Fq satisfy(i)for 0 � m � n,Pr(D[1℄n = m;D[2℄n � m=2) = 1mg1 �mn �+O� lognm2 � ;

Page 20: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

20 P. FLAJOLET, X. GOURDON, D. PANARIO

10

20

30

40

50

20 40 60 80 100

FIG. 7. Two largest degrees for 1,000 random polynomials of degreen = 100 in F7 [x℄: eachcircle represents a value of the pair(D1;D2).whereg1(�) is defined by the inverse Laplace integral,g1(�) = 12�i Z 1+i11�i1 e�E(�h=2)h e(1��)h dh;(ii)for 0 � m2 < m1 � n,Pr(D[1℄n = m1; D[2℄n = m2) = 1m1m2 g2 �m1n ; m2n �+O� lognm1m22� ;whereg2(�1; �2) is defined byg2(�1; �2) = 12�i Z 1+i11�i1 e�E(�2h)h e(1��1��2)h dh:

Figure 7 exemplifies the phenomena at stake by means of simulations. Estimatessimilar to Theorems 3.1 and 3.2 hold for largest cycles in permutations [54] (thisis in agreement with the earlier discussion of the random permutation model ofSection 1.4) and for integers as shown by Knuth and Trabb Pardo in [43]. Arratia,Barbour, and Tavare [1] present an interesting asymptotic model, the Poisson-Dirichlet process, that puts these facts in perspective andcovers random mappings,integer partitions, permutations, integers, as well as polynomials.

3.2. Analysis of the distinct-degree factorization

The main result of this section, Theorem 3.3, provides a quantitative comparisonof the three stopping rules for the DDF algorithm. It is basedon three lemmas,one for each of the strategies to be analysed.

Page 21: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 21

We first fix some notation. The DDF algorithm in its basic version is specifiedin Fig. 5. The computation in Step 1 is done by means of the classical binarypoweringmethod [40, p. 441-442] that leads to introducing two number-theoreticfunctions.Definition 3.1. The function�(q) is the number of ones in the binaryrepresentation ofq. The function�(q) is defined as�(q) = blog2 q + �(q)� 1; (17)

and it represents the number of products needed to computehq mod g by binarypowering.

By the exponential tail result of Theorem 2.1, we need only consider the cost ofDDF applied to the squarefree parta of the input polynomialf , and our subsequentanalyses are all relative to the statistics induced by a random inputf of degreen.

Let dk denote the degree of polynomialg when thekth iteration of the mainloop of DDF starts. The parameterdk is also the sum of the degrees of the distinctfactors off with degree� k.Theorem 3.3. The expected cost of the DDF phase satisfies�DDF (S)n � �(S) (�(q)�1 + �2)n3 �(q) = blog2 q + �(q)� 1;where�(S) is a constant depending on the strategyS,�(B) = 512 := 0:46667; �(HD) = 516 = 0:3125;�(EA) = 512 � 13 Z 10 e�2x exp�� Z 1x e�uu du� 1� x2x dx := 0:2668903307;for thebasic(B), half-degree(HD) or early-abort(EA) strategy, respectively.

Proof. The cost of the basic DDF isC1 + C2 + C3 + C4, whereCj denotesthe cost of line numberj in the algorithm of Fig 5. LetCj be the expectation ofCj . The mean number of irreducible factors off isO(logn), so thatC3 + C4 =O(n2 logn); thus it suffices to considerC1 + C2.

The quantitydk is the sum of the degrees of the distinct factors off with degree� k. Then, the quantityC1 + C2 is equal to(�(q)�1 + �2)�, where� = X1�k�N d2k; (18)

Page 22: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

22 P. FLAJOLET, X. GOURDON, D. PANARIO

with N the stopping value for the DDF loop. We haveN = n for the basic strat-egy,N = n=2 for the half degree rule,N = maxfD1=2; D2g for the early abortstrategy, whereD1,D2 are the largest and second largest degree of the distinct irre-ducible factors of the polynomial. The theorem follows fromthe three lemmas be-

low.

By (18) taken withN = n, the analysis of the basic strategy only involves anadditive parameter of polynomial factorizations. It is thus dealt with directly bybivariate generating functions and singularity analysis,as summarized in Section 1.The estimate also serves (by difference) in the analysis of the other two strategies.Lemma 3.1. The expected value of� in the basic strategy satisfies, asn!1,�(B)n � 512 n3:

Proof. The parameterdk is by definition the sum of the degrees of the distinctfactors off with individual degree� k and the parameter�(B) of (18) is�(B) =Pnk=1 d2k. The bivariate generating function ofdk is, by the basic decompositions,Pk(z; u) = Yj<k� 11� zj�Ij Yj�k�1 + uj zj1� zj�Ij :The expected value of�(B) is then given by�(B)n = 1qn [zn℄�(z); �(z) =Xk�1 ��2Pk�u2 (z; u) + �Pk�u (z; u)�����u=1 :

The basic relation (5) and a computation of�(z) by logarithmic derivativesimply that�(z) = P (z) (�1(z) + �2(z)) where�1(z) =Xj�1 j3Ij(zj � z2j) and �2(z) =Xk�10�Xj�k jIjzj1A2 :The function�1(z) is a simple variant ofI(z), namely�1(z) = �z ddz�3�I(z)� 18I(z2)� :Thus,�1(z) has its dominant singularity atz = 1=q and near this point,P (z)�1(z) � 2(1� qz)4 :

Page 23: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 23

Singularity analysis then yields[zn℄P (z)�1(z) � qn n3=3.We next turn to�2(z). The estimatejIj = qj+O(qj=2) entails, forjzj < 1+�,Xj�k jIj �zq�j = zk1� z + Sk(z); Sk(z) = O� zkqk=2� ;

so that�2�zq� = z21 + z 1(1� z)3 + S(z); S(z) =Xk�1�2zkSk(z)1� z + Sk(z)2� :The bounds satisfied bySk(z) makeS(z) regular beyond the unit disk. Thus,singularity analysis can be applied to the functionP (z=q)�2(z=q). There are twodominant singularities at1 and�1, but the one atz = 1 has greater weight. Theresulting estimate, asz ! 1,P �zq� �2�zq� � 12(1� z)4 ;implies that thenth coefficient is asymptotic ton3=12. Thus, finally,�(B)n �(1=3 + 1=12)n3 = 5n3=12.

The analysis of the half-degree rule is related to Theorem 3.1 since it involvesthe distribution ofD[1℄. In fact, it only depends on areas where the Dickmanfunction simplifies so that a direct argument can be applied.Lemma 3.2. The expected value of� for the half-degree rule satisfies, asn!1, �(HD)n � 516 n3:

Proof. We now have�(HD) =Pk�n=2 d2k. It suffices to consider the differ-

ence�0 = �(B) � �(HD) = Pn=2<k�n d2k. If the largest degreeD[1℄n satisfiesD[1℄n � n=2, we have�0 = 0. Otherwise we have�0 = (D[1℄n � bn=2 ) (D[1℄n )2since there can be only one factor of degree larger thann=2, namelyD[1℄n . Thus,the mean value of�0 is given by�0n = Xn=2<k�nPr(D[1℄n = k)�k � jn2k� k2: (19)

Page 24: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

24 P. FLAJOLET, X. GOURDON, D. PANARIO

By the symbolic method of Section 1, the generating functionof polynomialsfor which all factors have degree� m is�m(z) = mYk=1� 11� zk�Ik : (20)

Thus, the generating function of polynomials for whichD[1℄n = m is�m(z) = �m(z)� �m�1(z) = �m(z) �1� (1� zm)Im� ; (21)

and the probabilityPr(D[1℄n = k) is related to this generating function byPr(D[1℄n = k) = 1qn [zn℄�k(z):Whenk > n=2, thenth coefficient of�k(z) is obtained from�k(z) = P (z) �1� (1� zk)Ik�Yj>k(1� zj)Ij = P (z) �Ikzk +O(zn+1)�

which entailsPr(D[1℄n = k) = Ik=qk � 1=k for n=2 < k � n. Plugging thisestimate into (19) gives�0n � 548 n3. Thus�(HD)n = �(B)n � �0n � 516 n3.

The early-abort strategy needs to be handled in a more technical way. Thereis a striking parallel with the analysis of integer factoring by trial divisions, asgiven by Knuth and Trabb-Pardo [43]. The joint distributionof D1; D2 stated inTheorem 3.2 now intervenes.Lemma 3.3. The expected value of� in the early-abort rule satisfies, asn!1, �(EA)n � Æ n3;whereÆ = 512 � 13 Z 10 e�2x exp�� Z 1x e�uu du� 1� x2x dx := 0:2668903307:

(22)

Proof. (i) Algebra. As above, we denote byD1 the degree of the largestirreducible factor off , and byD2 the degree of the second largest irreduciblefactor off (setD2 = 0 if f is irreducible). The iteration is now aborted at step

Page 25: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 25k0 = maxfbD1=2 ; D2g and�(EA) =Pk�k0 d2k. Consider the difference�00 = �(B) � �(EA) = XmaxfbD1=2 ;D2g<k�n d2k:We need to prove the mean-value estimate�00n � ( 512 � Æ)n3.

We have�00 = (D1 � bD1=2 )D21 if D1=2 � D2, and�00 = (D1 �D2)D21 ifD1=2 < D2. Thus, the mean value of�00 is�00n = nXD1=1D21 �D1 � �D12 ��Pr(D[1℄n = D1; D[2℄n � D1=2) (23)+ XD2<D1�2D2D21(D1 �D2) Pr(D[1℄n = D1; D[2℄n = D2):Hence, the generating function(z)of the cumulated values of the parameter�00

is expressible in terms of the generating functione�D1(z) of polynomials for whichD[1℄n = D1; D[2℄n � D1=2, and the generating function�D1 ;D2(z) of polynomials

for whichD[1℄n = D1; D[2℄n = D2. By symbolic methods, the generating functionof polynomials for whichD[1℄n = m andD[2℄n � m=2 ise�m(z) = �bm=2 (z) Imzm1� zm ; (24)

with �m(z) defined in (20). In the same way, the generating function of polyno-mials withD[n℄1 = m1 andD[n℄2 = m2, m2 < m1 is�m1;m2(z) = �m2(z) Im1zm11� zm1 ; (25)

with �m(z) defined in (21). Thus,(z) =XD1 �D1 � �D12 ��D21 e�D1(z)+ XD2<D1�2D2(D1�D2)D21 �D1;D2(z):(ii)Analysis.The analysis of the generating function(z) near the positive sin-gularity z = 1=q is done by approximating sums with integrals (Euler-Maclaurinsummation). The following property summarizes what is needed.Logarithmi Remainder Estimate. The remainders of the logarithmicseries,rm(z) :=Pk>m zk=k, are approximable in terms of the exponential inte-gral, rm(e�h) = E(mh) +O� 1m� ; (26)

Page 26: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

26 P. FLAJOLET, X. GOURDON, D. PANARIO

where theO–error term is uniform with respect toh > 0.

Justifying this for anyh > 0 only requires the Euler Maclaurin formula and“subtraction of singularities”,rm(e�h) = Z +1h Xk>m e�ku! du = Z +1mh e�v v=mev=m � 1 dvv= E(mh) +Rm(mh); Rm(u) = 1m Z +1u e�v� � vm� dv;with �(z) = 1=(ez � 1)� 1=z that is continuous over the positive half-line.

The estimate of Equation (26) applied to�m(z) and�m(z) entails�m�e�hq � = e�E(mh)+O(1=m)1� e�h ; �m �e�hq � = e�E(mh)+O(1=m)1� e�h e�mhm :(27)

Whenz = e�t=qwith t > 0, the evaluation (27) together with the expressions (24)and (25) of the intervening generating functions givee�D1(z) � e�tD1D1 e�E(bD1=2 t)t ; �D1 ;D2(z) � e�(D1+D2)tD1D2 e�E(D2t)t :Approximating sums by integrals, whenz = e�t=q with t! 0+, yields(z) � 12t Z 10 x2e�txe�E(xt=2) dx+1t Zy<x<2y(x�y)x2 e�(x+y)txy e�E(ty) dx dy:The change of variablestx 7! x andty 7! y, rephrases the double integral as�e�tq � � 4t4 Z 10 x2e�2x�E(x) dx+ 1t4 Z 10 e�2y 2 + y � e�y(2 + 3y + 2y2)y dy:These integrals simplify under partial integration, and one finds�e�tq � � t4 (t! 0+); = 52 � 6Æ: (28)(iii)Coefficients.The asymptotic form (28) of(z) ast! 0 is consistent withthe assertion that [zn℄(z) � 6qnn3; (29)

though it does not imply it. Indeed, an asymptotic estimate like (28) is confined tothe vicinity of the real line, since it can be proved that the function(z) admits its

Page 27: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 27

circle of convergence as a natural boundary. Thus singularity analysis cannot beapplied. (A Tauberian theorem could be tried,but Tauberianside conditions appearto be delicate to establish.) We then proceed instead by an Abelian argument thatis based on a direct proof of existence of the limit$ := limn!1 1qnn3 [zn℄(z): (30)

Indeed, Theorem 3.2 applied to Formula (23) guarantees the existence of the limitin (30) since�00n � nXD1=1D1�D1 � �D12 �� g1�D1n �+ XD2<D1�2D2D1�D1D2 � 1� g2�D1n ; D2n �� "Z 10 x22 g1(x) dx + Z 10 x Z xx=2�xy � 1� g2(x; y)dy! dx# n3;where, in the second line, Riemann sums have been approximated by integrals.

This is sufficient to conclude on the existence of$ in (30). This value must then be

identical to =6 in accordance with (28) and (29).

The constantÆ in the above proof is a close relative of the famous Golombconstant that intervenes in the expectation of the longest cycle in a random per-mutation [54].

The global savings of the early abort strategy is thus of 36% compared to thebasic strategy, and of 15% compared to the half-degree rule.The expected cost ofDDF isO(n3 log q) and this cost dominates in the whole factorization chain.

4. THE OUTPUT CONFIGURATION OF DDF

The DDF procedure does not completely factor a polynomial that has differentirreducible factors of the same degree. However, as shown bythe following results,“most” of the factoring has been completed after DDF. First,the DDF procedureproduces a complete factorization with asymptotic probability greater than1=2(Theorem 4.1). Next, the number of calls to the subsequent phase of EDF, thatis to say the number of degree values for which more than one factor occurs,is only O(1), and the sum of the degrees where this happens (the total degreeof the fragments passed to EDF) isO(logn). However, this total degree has afairly large variability so that the cost of EDF (to be analysed in the next section)

Page 28: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

28 P. FLAJOLET, X. GOURDON, D. PANARIO

is comparatively small but not entirely negligible. Theorem 4.2 quantifies someof these phenomena. They are established here by means of a hybridization ofsingularity analysis and Darboux’s method, a general technique that we explain insome detail when we first encounter it in the next theorem.Theorem 4.1. The asymptotic probability for the distinct-degree factoriza-tion to be the complete factorization is q = Yk�1�1 + Ikqk � 1� (1� q�k)Ik :In particular: 2 := 0:6656; 3 := 0:6123; 5 := 0:5861; 47 := 0:5635; 257 :=0:5618, and 1 = e� := 0:5614; where is Euler’s constant.

Proof. (i) Permutation model.We start with the analysis of the permutationmodel, as this illustrates a “bare-bones” version of the method. By remarks above,this corresponds to the limit caseq = 1. The probability that a permutation oflengthn has all its cycles of different lengths is[zn℄F (z), where the generatingfunctionF (z) is susceptible to a variety of expressions obtained by the techniqueof convergence factors:F (z) := 1Yk=1�1 + zkk �= e�z 1 + z1� z 1Yk=2�1 + zkk � e�zk=k= �1 + z1� z exp��12Li2 �z2���� e�z+z2=2 1Yk=2�1 + zkk � e�zk=k+z2k=(2k2)!= S(z) � R(z): (31)

Here Li2(z) :=Pk�1 zk=k2 is the classicaldilogarithmfunction. The first factor,S(z), in the bottom equality of (31) satisfies the conditions of singularity analysis,while the second one,R(z) is continuously differentiable (of classC1) on theclosed unit discD, since it is of the former(z) where the coefficient[zn℄r(z) isO(n�3).

We thus have a situation where the generating function of interest is the productof a singular partS(z) that satisfies strong analyticity properties outside ofz = �1,and of a functionR(z)of the Darboux type that is smooth on the closed unit discD.

Page 29: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 29

We only need to justify the fact that dominant asymptotics ofthe coefficients[zn℄F (z) can be extracted “as though”R(z) were itself analytic onD.The local expansions ofS(z) at its singularities�1 are readily found to beS+1(z) = 2e��(2)=2� 11� z + log e1=22(1� z) +O((1� z) log2(1� z))�S�1(z) = 14e��(2)=2 (2(z + 1) +O((z + 1) log(z + 1));

with the error terms beingC0 onD. In summary, we have found thatF (z) = �2e��(2)=2 11� z + log(1� z) + t(z)� �R(z); (32)

for somet(z) that isC0, andR(z) that isC1 onD.The expansionR(z) = R(1) + U(z)(z � 1) with a functionU(z) that isC0,

can then be inserted in (32). Darboux’s method applies to theresulting form forF (z) (see the discussion relative to Equation (14) in Section 1.3), and one has[zn℄F (z) = 2R(1)e��(2)=2+ o(1); R(1) := e�1=2 1Yk=2�1 + 1k� e�1=k+1=(2k2):This finally simplifies using the infinite product formula for�(1):[zn℄F (z) = 1Yk=1�1 + 1k� e�1=k + o(1) = e� + o(1):

This last estimate has been already established by Greene and Knuth [32] bymeans of a Tauberian argument combined with bootstrapping.The method usedhere is in contrast a hybrid of singularity analysis and of Darboux’s method. Itcan be employed to derive complete asymptotic expansions, with roots of unitythat intervene in successive asymptotic terms corresponding to smaller and smallersingularity weights. (This leads to fluctuating terms involving successive roots ofunity.)(ii) Finite field model.We next turn to the case of a finite field of fixed cardinal-ity q to which the same principles apply. The generating functionof polynomialswith irreducible factors all of distinct degrees (but with single factors possiblyrepeated) is, by standard decomposition formulæ,F (z) = Yk�1 �1 + Ik(zk + z2k + z3k + � � � )� = Yk�1�1 + Ik zk1� zk� : (33)

Page 30: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

30 P. FLAJOLET, X. GOURDON, D. PANARIO

An equivalent form that reveals the pole-like singularity at z = 1=q is obtained bymultiplying each term of the product (33) by(1� zk)Ik ,F (z) = 11� qz Yk�1�1 + Ik zk1� zk� (1� zk)Ik :Thus, asz ! q�1, we haveF (z) � q1� qz ; q = 1Yk=1�1 + Ik 1qk � 1� (1� q�k)Ik ; (34)

and the preceding discussion applies, with the role of the dilogarithm function nowplayed by �2(z) = 1Xk=1� Ikqk � 1�2 zk:The hybrid method then yields,[zn℄F �zq� = q + o(1);which, by (34), is our statement.

Theorem 4.1 was obtained by Knopfmacher and Warlimont [38] and indepen-dently by the authors in [18]. The methods used in [18] as wellas in the presentpaper are however rather different from those of [38]. The paper [38] uses ele-mentary techniques and derives constructive bounds. The methods developed hereare geared towards full asymptotic expansions and have beensuccessfully used byGourdon [30] to solve the Golomb-Knuth conjecture [39, Ex. 1.3.3.23] regardingthe expectation of maximal cycle lengths in random permutations.Theorem 4.2. The numberN0 of degree values for which there is more thanone irreducible factor produced by DDF has an average that isasymptotic to theconstant �0 =Xk�1(1� q�k)Ik �(1� q�k)�Ik � 1� Ikq�k1� q�k� :The total degreeN1of the corresponding polynomials has expectationlogn+O(1)and standard deviation of order

pn.

Page 31: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 31

Proof. Given a familyF of elements, the expressionY!2F 11� !formally generates all (finite) multisets of elements takenfromF . The expression1 + X!2F !1� ! + u Y!2F 11� ! � 1�X!2F !1� !!formally generates all multisets each affected by a coefficient of u if there aredifferent elements comprising themultiset, andby acoefficient of1otherwise. Thisapplies to the class of irreducible polynomials of each degreen, takingF = In.Thus, the bivariate generating function of the numberN0 of degree values forwhich there are repeated elements isP0(z; u) = Yk�1�1 + Ikzk1� zk + u�(1� zk)�Ik � 1� Ikzk1� zk�� : (35)

The logarithmic derivative with respect tou satisfiesP 00(z; 1)P0(z; 1) =Xk�1(1� zk)Ik �(1� zk)�Ik � 1� Ikzk1� zk� : (36)

By our general discussion of the hybrid singularity analysis and Darboux method,the quantityN0 has an expectation that is asymptotic to the limit�0 of P 00(z; 1)=P0(z; 1) asz ! 1=q. This quantity is thus nothing but the value of the right handside of (36) atz = 1=q.

For the sumN1 of the degrees of these polynomials, an adaptation of (35) yieldsthe bivariate generating function,P1(z; u) = Yk�1 �1 + uk zk1� zk�Ik � (uk � 1)Ik zk1� zk! :We only discuss briefly the first moment ofN1. The mean value isq�n[zn℄R(z),whereR(z) equalsP 01(z; u)ju=1. Thanks to the expansionkIk = qk +O(qk=2),nearz = 1=q,R(z) is asymptotic to(1�qz)�1 log(1�qz)�1. Thus, the expecta-tion ofN1 taken overpolynomials ofdegreen isq�n[zn℄R(z) � logn. The secondfactorial moment ofN1 is obtained by a further differentiation ofP1(z; u) atu = 1.

Page 32: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

32 P. FLAJOLET, X. GOURDON, D. PANARIO

The analysis ofN1 in Theorem 4.2 was given in [18] and Knopfmacher [35]has independently obtained an estimate of the first two moments ofN0.

It should be clear that the hybrid asymptotic method has great flexibility. As afinal illustration, we discuss a question of von zur Gathen and consider the quantityeN that is the largest degree for which two or more factors occur. The generatingfunction of polynomials such thateN � r is in this caseF (r)(z) = Yk�r(1� zk)�Ik Yk>r�1 + Ik zk1� zk� :Thus, the probability ofeN � r is, for large degreen and fixedr, asymptotic to (r)q = Yk>r(1� q�k)�Ik �1 + Ik q�k1� q�k� ; (37)

and for large field cardinalities, these constants have a limit, (r)1 = e� Yk�r�1 + 1k��1 e1=k: (38)

We have1 � (r)q = O(1=r) for all fixed q, some representative values withq =1 being: 1 := 0:5614; (1)1 := 0:7631; (2)1 := 0:8387; (5)1 := 0:9179; (10)1 := 0:9549:Thus, (37) and (38) give the following simplified picture in the asymptotic limit(n andq large).Fa t. A random polynomial has a small number,O(1), of “colliding” de-grees; the largest colliding degree has a probability distribution tail that decayslike O(1=r2) (for r � n=2). Because of this slow tail decay, the largest collidingdegree alone has a first moment that isO(Pr r�1) = O(logn), but a secondmoment that isO(Pr 1) = O(n).

These observations are seen to be consistent with what Theorem 4.2 asserts.

5. EQUAL-DEGREE FACTORIZATION (EDF)

After the first two stages of the general algorithm, the factorization problem hasbeen eventually reduced to factoring a collection of monic squarefree polynomialsbk all of whose irreducible factors have the same (known) degree k. The thirdstep in the factorization process, the equal-degree factorization algorithm (EDF),

Page 33: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 33pro edure EDF( : polynomial, k : integer);{" " is a produ t of irredu ibles of degree "k"}if degree( ) <= k then return( ) fi;h := randpoly(degree( )-1);{draw a random polynomial}1. a := h^((q^k-1)/2)-1 mod ;2. d := g d(a, );return(EDF(d,k).EDF( /d,k));end;FIG. 8. The equal-degree factorization algorithm (EDF).

focuses on polynomials with this special form. Our reference chain uses theclassical Cantor-Zassenhausalgorithm [6] for this purpose. The analysis combinesa recursive partitioning problem akin to digital trees —also known as “tries” [41,46]— together with estimates on the degrees of irreducible factors of randompolynomials [37]. The net result is that the global cost of EDF is quadratic, asharp contrast with the cubic cost of DDF. For convenience, we first assume thatq is odd, and relegate to Section 5.4 the case of a characteristic equal to 2.

The EDF algorithm is described in Fig. 8, and we briefly recallthe principlehere.Prin iple of EDF. Let be a polynomial that is a product ofj irreduciblefactors = f1; : : : ; fj , with eachfi of degreek. The Chinese remainder theoremimplies the ring homomorphism,Fq [x℄=( ) �= Fq [x℄=(f1)� � � � � Fq [x℄=(fj);and a random elementh of Fq [x℄=( ) is associated to aj-tuple(h1; : : : ; hj), whereeachhi is a random element ofFq [x℄=(fi).

The following splitting principle makes it possible to isolate the variousfi. Sinceeachfi is irreducible, the multiplicative group of each componentFq [x℄=(fi) isa field isomorphic toFqk . Such a group being cyclic, there are the same num-

ber(qk � 1)=2 of squares and nonsquares. The testh(qk�1)=2i = 1 discriminatesthe squares in this multiplicative group. Thus, taking a randomh and computinga := h(qk�1)=2�1 mod , we have thatg d(a; ) “extracts” the product of all thefi for whichh is a square inFq [x℄=(fi).

From the algorithmic standpoint, taking random polynomialsh, leads to succes-sive refinements of each factor = bk known to be composed solely of irreduciblepolynomials of degreek. The computation develops as a tree (Figure 9). From

Page 34: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

34 P. FLAJOLET, X. GOURDON, D. PANARIO

ABCDE

1

BE

E B

ACD

ACD

C AD

A D

FIG. 9. A tree of successive refinements by EDF of the factorizationb = ABCDE.

the probabilistic point of view, each componenthi that is random inFq [x℄=(fi)has probability� = 12 � 12q of being discriminated by the gcd test and the dual

probability,� = 12 + 12q of being a nonsquare—the (small) difference between�and� is accounted for by the possibility of having noninvertiblecomponents.

Then, the analysis of the complete EDF phase (Section 5.3) requires a purelycombinatorial analysis of what takes place at each degreek (Section 5.2) com-bined with an estimate of the probability that there arej irreducible factors ofdegreek in a random polynomial of degreen. These probabilities give interestinginformation on random polynomials and have been obtained byKnopfmacher andKnopfmacher [37] whose results we recall in Section 5.1.

5.1. Irreducible factors of each degree

Let �n(k) be the random variable counting the number of distinct irreduciblefactors of degreek in a random polynomial of degreen. We consider herek asfixed. The corresponding probability distribution was given in [37]. It can beeasily computed by the decomposition techniques of Section1, as we now show.Theorem 5.1 (Knopfmacher and Knopfmacher).The probability that thereare j distinct irreducible factors of degreek in a random polynomial of degreenis, for n large enough(n � kIk), given by the binomial distributionB(Ik; q�k),namely, Prf�n(k) = jg = �Ikj �(q�k)j(1� q�k)Ik�j :

Page 35: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 35

Proof. The bivariate generating function for the number of irreducibles ofdegreek is, by the basic decomposition,Qk(z; u) = �1 + u zk1� zk�Ik Y6=k(1� z`)�I`= 11� qz (1 + (u� 1)zk)Ik :The asymptotics asn!1 are derived from the polar singularity atz = 1=q: theprobability generating function of the distribution is in the limit n!1,(1 + (u� 1)q�k)Ik ;that is to say, the probability generating functionof abinomial distributionB(Ik; q�k).As is easily observed, this asymptotic formula is even exactas soon asn � kIk.

Since a binomial distribution corresponding to rare eventsconverges to a Poissondistribution, one has:Fa t. The probability distribution of the number of factors of degreek in arandom polynomial of degreen is approximately a Poisson law of parameter1=k,Prf�n(k) = jg � e�1=k k�jj! :

This fact is in accordance with the known distribution of cycle lengths in therandom permutation model [54]. The table below provides numerical values ofPrf�n(k) = jg for j = 1; 2; 3, whenk = 1; 2; 3. The data corresponding todegreen = 20 (for values ofq = 2; 17) show an excellent fit with the Poisson law(q =1), even in the non-asymptotic regime.q k = 1 k = 2 k = 3j = 1 j = 2 j = 3 j = 1 j = 2 j = 3 j = 1 j = 2 j = 3

2 0.250 0.250 0.187 0.750 0.187 0.046 0.765 0.191 0.035

17 0.356 0.356 0.188 0.624 0.293 0.069 0.717 0.238 0.03961 0.367 0.367 0.183 0.606 0.303 0.075 0.716 0.238 0.039

5.2. EDF and splitting trees

Page 36: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

36 P. FLAJOLET, X. GOURDON, D. PANARIO

For each value ofk, we can regard the EDF phase as an abstract splitting processas follows. Start with a groupG formed ofm individuals. (In EDF, if the degree ofbk iskj, then,m = j.) By flipping coins, separateG randomly into two subgroups,G0 andG1, with the probabilities for each element to be sent toG0 andG1 being� and�. The process is repeated recursively until all elements have been isolated.Clearly, any such recursive execution is described by a binary tree (Figure 9). Thecorresponding randomness modelPr �jG0j = m0 �� jGj = m� = �mm0��m0�m�m0 ;� = 12 � 12q ; � = 12 + 12q ; (39)

that is induced by independent splittings then coincides with the one underlyingdigital trees. Given the importance of the digital tree in the design and analysis ofalgorithms many properties are known. We cite here:Fa t. The expectation of the number of binary nodes in a splitting tree,relative tom individuals and with probabilities(�; �), ismH (1 + �(m)) + o(m); H = � log2 1� + � log2 1� ;with �(m) a fluctuating function of amplitude typically< 10�5. The expectationof the height of the tree is2K log2m+O(1); K = log2(�2 + �2)�1:

The size estimate due to Knuth and De Bruijn around 1965 (published in the1973 edition of [41]) involves the entropy functionH ; the height estimate firstappeared in [22] (a paper already motivated by polynomial factorization) and itinvolves the “coincidence probability”�2 + �2. Nowadays, these results arebest understood in the context of Vallee’s general theory of dynamical sources;see [11, 58]. As a consequence of these estimates, splittingtrees tend to be fairlywell balanced so that the cost of an EDF phase is expected to beclose to that ofa perfect splitting. The lemma below provides an explicit expression for the costsinduced by the computational model at hand.Lemma 5.1. The expected costCj;k of the EDF algorithm applied to anyproduct ofj irreducible factors of degreek is j(j � 1)2�� + j 1Xm=0 mX=0�m��m�`�` �1� (1� �m�`�`)j�1�! (�k�1+�2)k2;

Page 37: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 37

where�k = �((qk � 1)=2) = jlog2 qk�12 k+ � � qk�12 �� 1:Proof. It is convenient to regard an execution of the splitting process as a treet

and to consider, witht0; t1 the root subtrees, a general cost function of the additivetype, C[t℄ = ejtj + C[t0℄ + C[t1℄: (40)

Hereejtj is a (problem specific) “toll” function that depends on the sizejtj, that isto say, the number of irreducible factors (of degreek) to be separated.

The subtree sizes obey the Bernoulli probability of (39). Also the subproblemsdescribed byt0; t1 have, by design, the same characteristics as the whole tree.Thus, the expectation j of C[t℄ over trees of sizej satisfies the recurrence j = ej + jX=0�j��`�j�`( ` + j�`) = ej + jX=0�j�(�`�j�` + �j�`�`) `:This translates in terms of the exponential generating functionsC(z) =Xj jzj=j!; E(z) =Xj ejzj=j!;into the functional equationC(z) = E(z) + e�zC(�z) + e�zC(�z):This difference equation iterates, leading to the explicitgenerating function solu-tion C(z) = 1Xj=0 jX=0�j�E(�j�`�`z)ez(1��j�`�`): (41)

The analysis is completed by specializing this discussion to the EDF costs. Thetoll function that arises from the top-level execution of the EDF procedure is thenbej = (�k�1 + �2)(kj)2;for j � 2. There,�k is the number of multiplications of the binary poweringmethod, and the quadratic costs are induced by the naıve multiplication and gcdalgorithms considered here. The toll functionej = j2(1�Æ1;j) corresponds to thegenerating functionE(z) = z(ez(1 + z) � 1) in (41). Extracting coefficients ofthe resulting generating functionC(z) in (41) and rescaling bybej=ej then yields the

statement.

Page 38: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

38 P. FLAJOLET, X. GOURDON, D. PANARIO

5.3. Complete analysis

Completing the analysis of EDF only requires weighting the costs given byLemma 5.1 by the probabilityPr(�n(k) = j) of finding j irreducible factors ofdegreek given by Theorem 5.1. By Lemma 5.1, the cost is of the formO(j2k3),and by Theorem 5.1, the probabilities are approximatelye�1=kk�j=j!; thus, weexpect the total cost of the DDF phase to be of the order ofXk;j �j2k3� � �k�jj! � = O(n2):The main result of this section gives a firm basis to this heuristic computation anddetermines the implied constant. In order to prove the final estimate of Theorem 5.2below, we need two technical lemmas.Lemma 5.2. Whenk !1, one has for allj such thatkj � nPr(�n(k) = j) = �Ikj �qkj (1 +O(1=k)) ;where theO(1=k) is uniform inj. Moreover, the following uniform estimate holdsPr(�n(k) = j) = O� 1j!kj� :

Proof. Whenkj � n, Theorem 5.1 yieldsPr(�n(k) = j) = �Ikj �qkj (1+�); � = NX=1(�1)` �Ik�j` �qk` ; N = min(bn=k �j; Ik�j):Whenk is large, one has� = O(1=k) sincej�j � Ik�jX=1 �Ik�j` �qk` = (1 + q�k)Ik�j � 1 � (1 + q�k)Ik � 1 = O(1=k):This proves the first estimate. As for the second one, it suffices to note that�Ikj � � Ijkj! = O� qkjj!kj� ;and to use the first estimate of the lemma.

Page 39: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 39Lemma 5.3. The average costsCj;k of Lemma 5.1 satisfy for allkC0;k = C1;k = 0; C2;k = 2�� (�k�1 + �2) k2;and, uniformly, Cj;k = O(j2k3):

Proof. The first relations are direct applications of Lemma 5.1. Forthe estimateof Cj;k , the inequality1� (1� u)j�1 � (j � 1)u impliesCj;k � 0�j(j � 1)2�� + j Xm�0 mX=0�m�(j � 1)�2(m�`)�2`1A (�k�1 + �2) k2= j(j � 1)�� (�k�1 + �2) k2:The last equality holds sinceXm�0 mX=0�m��2(m�`)�2` = Xm�0(�2 + �2)m = 12�� :Since�k = O(k), the statement follows.

We are now ready to prove the main result of this section.Theorem 5.2. The expected cost of the EDF phase satisfies�EDF n � �1�� dn=2eXk=1 �k; �k = �log2 qk � 12 �+ � �qk � 12 �� 1:In addition, this cost isO(n2 log q) and�EDF n � �34�1 q2q2 � 1 log2 q� (1 + �n) � n2; �13 + o(1) � �n � 13 + o(1):

(42)

Proof. The intuition behind the proof is that the major contribution comesfrom situations where just 2 factors are present, the other cases having globallya very small probability of occurrence. LetEk be the expected value of the

Page 40: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

40 P. FLAJOLET, X. GOURDON, D. PANARIO

cost of the EDF algorithm corresponding to degreek. By definition, we haveEk =Pj�2 Pr(�n(k) = j)Cj;k, whereCj;k is given by Lemma 5.1.When2k � n, Lemma 5.2 and Lemma 5.3 entail, ask !1,EDFk = C2;k �Ik2 �q2k (1 +O(1=k)) +Xj�3O�k�jj! j2k3� = �1�� �k +O(1):

When2k > n, we haveEDFk = 0. Thus, the overall cost of the EDF componentisPk Ek = �1�� Pdn=2ek=1 �k+O(n). The second form of the cost is obtained from

the general inequality1 � �(m) � 1 + log2m, upon subtracting from�(m) its

“mean value”12 log2m.

The quantity�n in the statement measures the default of uniformity in binaryrepresentations of numbers related to the powers ofq. Under the unproven as-sumption that such representations behave like random integers, the arithmeticfunction�n should be close to0. This assumption is well supported by empiricalevidence: for instance, withq = 17, we have�5 = �0:425; �10 = �0:060; �20 = �0:024; �50 = �0:016:For all practical purposes, we may safely regard�n as being asymptotic to 0.

5.4. Equal-degree factorization in characteristic 2

In the previous sections, we have analysed in detail the equal-degree factoriza-tion over finite fields with odd characteristic. For these cases, we have followed thealgorithm by Cantor and Zassenhaus [6] who also provide a solution for the evencase that relies on factoring the polynomial in a quadratic extension. Ben-Or [3]showed that this detour is not needed while proposing a method based on tracecomputations.

Trace computations introduce only a small change in the EDF algorithm ofFig. 8. Letm be such thatq = 2m. In order to compute the traces, we replaceline 1 by1'. a := h+h^2+h^(2^2)+...+h^(2^(km-1)) mod b;

We observe that the analysis for the odd case is valid for the even case. First, thesplitting process is the same (with probabilities� = � = 1=2). Then, the cost ofcomputing line1' is the same as the cost of computing line1 in Fig. 8. Indeed, thetrace computations can be determined using basicallykmproducts of a polynomialcontainingj factors of degreek. This costs essentiallykm(jk)2 = k3j2 log q, thesame cost as in the odd case.

Page 41: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 41

Phase Worst-case Average-case

ERF O(n2) �2n2DDF O(n3 log q) 0:26689 (�(q)�1 + �2)n3EDF O(n3 log q) � 34�1 q2q2�1 log q � n2� (1� 13 + o(1))

FIG. 10. A comparison of the worst cases and the average cases of the three phases of polynomialfactorization. (The cost of multiplying two polynomials ofdegree less thann modulo a polynomialfof degreen is �1n2, and the cost of a gcd betweenf and a polynomial of degree less thann is �2n2.The number of products needed to computehq modf is �(q) = blog2 q + �(q)� 1.)

6. CONCLUSIONS

In this paper we have shown how analytic combinatorics adapts well to the caseof polynomials over finite fields. A systematic usage of this methodology leadsnot only to the derivation of basic probabilistic properties of random polynomialsover finite fields but also to the average-case analysis of a complete polynomialfactoring algorithm. Figure 10 summarizes the main resultsof the paper in terms ofthe average-case analysis of the factoring algorithm and itprovides a comparisonwith worst-case behaviour.

It should be clear that a large number of variants of the factorization chain canbe analysed by our methods. For instance, specifics of the elimination of repeatedfactors stage are largely immaterial from the expected complexity standpoint,sincethey lead to identical results in asymptotic terms. A radical possibility is then tobypass completely the first stage. In this variant, DDF not only produces thepolynomials for the EDF part but also returns a polynomial containing the non-squarefree part of the original polynomial. Once more, there is no difference inasymptotic terms.

Several authors [26, 34] have stated that from a worst-case perspective, and evenwhen considering fast arithmetic instead of the classical one, DDF is the bottleneckfor the factorization process. Our results confirm that suchis also the case froman average-case perspective. Chapter 15 of the recent book [24] further illustratesthis point with striking graphics.

Finally, we should mention here a few other algorithms that have been subjectedto a “Knuthian” analysis similar to what was conducted here.Panario and Rich-mond analyse in [52] the irreducibility test of Ben-Or that is based on trial DDF:the analysis involves statistics on smallest degrees of irreducible factors and theBuchstab function, a dual of the Dickman function. Rabin’s probabilistic construc-

Page 42: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

42 P. FLAJOLET, X. GOURDON, D. PANARIO

tion of irreducible polynomials is also dealt with in [51]. Last but not least, theEuclidean algorithm turns out to be somewhat easier to analyse for polynomialsthan for integers: see the analyses by Knopfmacher and Knopfmacher [36] as wellas by Friesen and Hensley [23].

ACKNOWLEDGMENTThe work of Philippe Flajolet was supported in part by theAl om-FT Project (number IST-1999-

14186) of the European Union. The work of Daniel Panario was done for the most part while with theDepartment of Computer Science of the University of Toronto. We are grateful to Joachim von zurGathen for having put us in contact and for having incited us to analyse polynomial factorization indetail. Thanks to Brigitte Vallee for many constructive suggestions regarding the generalorganizationof the paper. Thanks also to Helmut Prodinger and Allan Borodin for much appreciated support.

REFERENCES1. Arratia, R., Barbour, A. D., and Tavar�e, S. Random combinatorial structures and

prime factorizations.Notices of the American Mathematical Society 44(1997), 903–910.

2. Ba h, E. Toward a theory of Pollard’s rho method.Information and Computation 90(1991),139–155.

3. Ben-Or, M. Probabilistic algorithms in finite fields. InProc. 22nd IEEE Symp. FoundationsComputer Science(1981), pp. 394–398.

4. Berlekamp, E. Algebraic Coding Theory. McGraw Hill, New York NY, 1968.

5. Bu hmann, J. Complexity of algorithms in algebraic number theory. InNumber Theory. Proc.First Conf. Canadian Number Theory Assoc.Walter de Gruyter, 1990, pp. 37–53.

6. Cantor, D., and Zassenhaus, H. A new algorithm for factoring polynomials over finitefields. Math. Comp. 36(1981), 587–592.

7. Car, M. Factorisation dansFq [x℄. C. R. Acad. Sci. Paris Ser. I 294(1982), 147–150.

8. Car, M. Theoremes de densite dansFq [X℄. Acta Arith. 48(1987), 145–165.

9. Carlitz, L. The arithmetic of polynomials in a Galois field.Amer. J. Math. 54(1932), 39–50.

10. Chor, B., and Rivest, R. A knapsack-type public key cryptosystem based on arithmetic infinite field. IEEE Trans. Inform. Theory. 34(1988), 901–909.

11. Cl�ement, J., Flajolet, P., and Vall�ee, B. Dynamical sources in information theory: ageneral analysis of trie structures",Algorithmica 29(2001), 307–369.

12. Collins, G. Factoring univariate integral polynomials in polynomial average time. InProc.EUROSAM 79(1979), vol. 72 ofLecture Notes in Computer Science, pp. 317–329.

13. Comtet, L. Advanced Combinatorics. Reidel, Dordrecht, 1974.

14. de Bruijn, N. On the number of positive integers� x and free of prime factors> y. Indag.Math. 13(1951), 2–12.

15. Dedekind, R. Abriss einer Theorie der hohern Congruenzen in Bezug auf einen reellenPrimzahlmodulus.J. reine u. angew. Math. 54(1857), 1–26.

16. Di kman, K. On the frequency of numbers containing prime factors of a certain relative magni-tude.Ark. Mat. Astr.Fys. 22(1930), 1–14.

17. Fin h, S. Golomb-Dickman constant. InFavorite Mathematical Constants(2000). Publishedelectronically athttp://algo.inria.fr/bsolve/ onstant/ onstant.html.

Page 43: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

ANALYSIS OF POLYNOMIAL FACTORIZATION 43

18. Flajolet, P., Gourdon, X., and Panario, D. Random polynomials and polynomialfactorization. InAutomata, Languages, and Programming(1996), F. Meyer auf der Heide andB. Monien, Eds., vol. 1099 ofLecture Notes in Computer Science, Springer-Verlag, pp. 232–243.Proceedings of the 23rd ICALP Conference, Paderborn, July 1996.

19. Flajolet, P., and Odlyzko, A. Singularity analysis of generating functions.SIAM Journalon Discrete Mathematics 3:2(1990), 216–240.

20. Flajolet, P., and Sedgewi k, R. Analytic Combinatorics.Book in preparation (2000).

21. Flajolet, P., and Soria, M. Gaussian limiting distributions for the number of componentsin combinatorial structures.Journal of Combinatorial Theory,Series A53 (1990), 165–182.

22. Flajolet, P., and Steyaert, J. A branching process arising in dynamic hashing, triesearching and polynomial factorization. InProc. 9th ICALP Symp. 1982(1982), vol. 140 ofLecture Notes in Computer Science, Springer-Verlag, pp. 239–251.

23. Friesen, C. and Hensley, D., The statistics of continued fractions for polynomials over afinite field. Proc. Amer. Math. Soc. 124(1996), 2661–2673.

24. von zur Gathen, J., and Gerhard J. Modern Computer Algebra. Cambridge UniversityPress, 1999.

25. von zur Gathen, J., and Panario, D. Factoring polynomials over finite fields: a survey.To appear inJ. of Symb. Comp., 2000.

26. von zur Gathen, J., and Shoup, V. Computing Frobenius maps and factoring polynomials.Comput. Complexity 2(1992), 187–224.

27. Gauss, C. Untersuchungen uber hohere Mathematik. Chelsea, New York, 1889.

28. Geddes, K., Czapor, S., and Labahn, G. Algorithms for Computer Algebra. KluwerAcademic Publishers, Boston, 1992.

29. Goulden, I., and Ja kson, D. Combinatorial Enumeration. John Wiley, New York, 1983.

30. Gourdon, X. Combinatoire, algorithmique et geometrie des polynomes. These,Ecole Poly-technique, 1996.

31. Gourdon, X. Largest components in random combinatorial structures.Discrete Mathematics180 (1998), 185–209.

32. Greene, D., and Knuth, D. Mathematics for the Analysis of Algorithms, 3 ed. Birkhauser,Boston, 1990.

33. Hensley, D. Dirichlet’s theorem for the ring of polynomials overGF(2). Pacific Journal ofMathematics 123(1986), 93–101.

34. Kaltofen, E., and Shoup, V. Subquadratic-time factoring of polynomials over finite fields.In Proc. 27th ACM Symp. Theory of Computing(1995), pp. 398–406.

35. Knopfma her, A. On the degrees of irreducible factors of polynomials over a finite field.Disc.Math. 196(1999), 197–206.

36. Knopfma her, J., and Knopfma her, A. The exact length of the Euclidean algorithm inFq [X℄. Mathematika 35(1988), 297-304.

37. Knopfma her, J., and Knopfma her, A. Counting irreducible factors of polynomialsover a finite field.SIAM Journal on Discrete Mathematics 112(1993), 103–118.

38. Knopfma her, A., and Warlimont, R. Distinct degree factorizations for polynomials overa finite field.Trans. Amer. Math. Soc. 347(1995), 2235–2243.

39. Knuth, D. The Art of Computer Programming, Vol.1: Fundamental Algorithms, 3 ed. Addison-Wesley, Reading MA, 1997.

40. Knuth, D. The Art of Computer Programming, Vol.2: Seminumerical Algorithms, 3 ed. Addison-Wesley, Reading MA, 1997.

Page 44: The complete analysis of a polynomial factorization algorithm ......fields, factorization algorithms, random polynomials Journal of Algorihms, to appear (accepted for publication

44 P. FLAJOLET, X. GOURDON, D. PANARIO

41. Knuth, D. The Art of Computer Programming, Vol.3: Sorting and Searching, 2 ed. Addison-Wesley, Reading MA, 1998.

42. Knuth, D. Selected Papers on Analysis of Algorithms.CSLI Publications, Stanford, CA, 2000.

43. Knuth, D., and Trabb-Pardo, L. Analysis of a simple factorization algorithm.TheoreticalComputer Science 3(1976), 321–348.

44. Lenstra, H. On the Chor-Rivest knapsack cryptosystem.J. of Cryptology 3(1991), 149–155.

45. Lidl, R., and Niederreiter, H. Finite Fields, vol. 20 ofEncyclopedia of Mathematics andits Applications. Addison-Wesley, 1983.

46. Mahmoud, H. Evolution of Random Search Trees. John Wiley, New York, 1992.

47. Mullen, G. L., and Shparlinski, I. Open problems in finite fields. InProc. 3rd Conferenceof Finite Fields and their Applications.London Math. Soc.,Lect. Note Series 233(1996), 243–268.

48. Odlyzko, A. Discrete logarithms and their cryptographic significance.In Advances in Cryp-tology, Proceedings of Eurocrypt 1984(1985), vol. 209 ofLecture Notes in Computer Science,Springer-Verlag, pp. 224–314.

49. Odlyzko, A. Asymptotic enumeration methods. InHandbook of Combinatorics, R. Graham,M. Grotschel, and L. Lovasz, Eds., vol. 2. Elsevier, 1995, pp. 1063–1229.

50. Panario, D., Gourdon, X., and Flajolet, P. An analytic approach to smooth polyno-mials. InAlgorithmic Number Theory Symposium(1998), vol. 1423 ofLecture Notes in ComputerScience, Springer-Verlag, pp. 226-236.

51. Panario, D., Pittel, B., Ri hmond, B., and Viola, A.AnalysisofRabin’s irreducibilitytest for polynomials over finite fields. Preprint, 2000.

52. Panario, D., and Ri hmond, B.Analysis of Ben-Or’s polynomial irreducibility test.RandomStruct. Alg. 13(1998), 439–456.

53. S h�onemann, T. Grundzuge einer allgemeinen Theorie der hoheren Congruenzen, deren Moduleine reelle Primzahl ist.J. f. d. reine u. angew. Math. 31(1846), 269–325.

54. Shepp, L., and Lloyd, S. Ordered cycle lengths in a random permutation.Trans. Amer. Math.Soc. 121(1966), 340–357.

55. Shoup, V. On the deterministic complexity of factoring polynomials over finite fields. Inform.Process. Lett. 33(1990), 261–267.

56. Shoup, V. A new polynomial factorization algorithm and its implementation. J. Symb. Comp.20 (1996), 363–397.

57. Tenenbaum, G. Introduction to Analytic and Probabilistic Number Theory. Cambridge Uni-versity Press, 1995.

58. Vall�ee, B. Dynamical sources in information theory: fundamental intervals and word prefixes,Algorithmica 29(2001), 262–306.