<<

The Great Trinomial Hunt Richard P. Brent and Paul Zimmermann

trinomial is a in one vari- illustrate why this might be true, consider a able with three nonzero terms, for sequence (z0, z1, z2, . . .) satisfying the recurrence example P = 6x7 + 3x3 − 5. If the co- (1) zn = zn−s + zn−r mod 2, efficients of a polynomial P (in this case 6, 3, −5) are in some ring or field where r and s are given positive integers, r > s > 0, A and the initial values z , z , . . . , z are also given. F, we say that P is a polynomial over F, and 0 1 r−1 write P ∈ F[x]. The operations of addition and The recurrence then defines all the remaining terms multiplication of in F[x] are defined in zr , zr+1,... in the sequence. the usual way, with the operations on coefficients It is easy to build hardware to implement the performed in F. recurrence (1). All we need is a shift register capable Classically the most common cases are F = of storing r bits and a circuit capable of computing Z, Q, R, or C, respectively the integers, rationals, the addition mod 2 (equivalently, the “exclusive reals, or complex numbers. However, polynomials or”) of two bits separated by r − s positions in the over finite fields are also important in applications. shift register and feeding the output back into the We restrict our attention to polynomials over the shift register. This is illustrated in Figure 1 for r = 7, s = 3. simplest finite field: the field GF(2) of two elements, usually written as 0 and 1. The field operations

of addition and multiplication are defined as for ! integers modulo 2, so 0 + 1 = 1, 1 + 1 = 0, 0 × 1 = 0, ! 1 × 1 = 1, etc.

An important consequence of the definitions is + ! that, for polynomials P,Q ∈ GF(2)[x], we have !

(P + Q)2 = P 2 + Q2 Output Figure 1. Hardware implementation of because the “cross term” 2PQ vanishes. High z = z + z mod 2. school would have been much easier if we n n−3 n−7 had used polynomials over GF(2) instead of over R! The recurrence (1) looks similar to the well- Trinomials over GF(2) are important in cryp- known Fibonacci recurrence tography and random number generation. To Fn = Fn−1 + Fn−2;

Richard Brent is professor of mathematics at the Mathe- indeed, the Fibonacci numbers mod 2 satisfy matical Sciences Institute of the Australian National Uni- our recurrence with r = 2, s = 1. This gives a versity, Canberra. His email address is [email protected]. sequence (0, 1, 1, 0, 1, 1, . . .) with period 3: not very Paul Zimmermann is directeur de recherche at INRIA interesting. However, if we take r larger, we can Nancy. His email address is [email protected]. get much longer periods.

February 2011 Notices of the AMS 233 The period can be as large as 2r − 1, which We are interested in primitive polynomials makes such sequences interesting as components because x is a generator of the multiplicative group in pseudo-random number generators or stream of the finite field GF(2)[x]/P(x) if P(x) is primitive. ciphers. In fact, the period is 2r − 1 if the initial If r is large and 2r − 1 is not prime, it can be values are not all zero and the associated trinomial difficult to test primitivity of a polynomial of degree xr + xs + 1, r, because we need to know the prime factors of 2r − 1. Thanks to the Cunningham project [20], regarded as a polynomial over GF(2), is primitive. these are known for all r < 929, but not in general A primitive polynomial is one that is irreducible (it for larger r. On the other hand, if 2r − 1 is prime, has no nontrivial factors) and satisfies an additional then all irreducible polynomials of degree r are condition given in the “Mathematical Foundations” primitive. This is the reason that we consider section below. degrees r that are Mersenne exponents. A Mersenne prime is a prime of the form 2r − 1. Such primes are named after Marin Mersenne (1588–1648), who corresponded with many of the Starting the Search scholars of his day, and in 1644 gave a list (not In the year 2000 the authors were communicating quite correct) of the Mersenne primes with r ≤ 257. by email with each other and with Samuli Larvala A Mersenne exponent is the exponent r of a when the topic of efficient algorithms for testing Mersenne prime 2r − 1. A Mersenne exponent irreducibility or primitivity of trinomials over is necessarily prime, but not conversely. For GF(2) arose. The first author had been interested example, 11 is not a Mersenne exponent because in this topic for many years because of the 211 − 1 = 23 · 89 is not prime. application to pseudo-random number generators. The topic of this article is a search for primitive Publication of a paper by Kumada et al. [12], trinomials of large degree r, and its interplay with describing a search for primitive trinomials of a search for large Mersenne primes. First, we need degree 859 433 (a Mersenne exponent), prompted to explain the connection between these two topics the three of us to embark on a search for primitive and briefly describe the GIMPS project. Then we trinomials of degree r, for r ranging over all describe the algorithms used in our search, which known Mersenne exponents. At that time, the can be split into two distinct periods, “classical” largest known Mersenne exponents were 3 021 377 and “modern”. Finally, we describe the results and 6 972 593. The existing programs took time obtained in the modern period. proportional to r 3. Since (6972593/859433)3 ≈ 534, and the computation by Kumada et al. had Mathematical Foundations taken three months on nineteen processors, it was As stated above, we consider polynomials over quite a challenge. the finite field GF(2). An is a polynomial that is not divisible by any The GIMPS Project nontrivial polynomial other than itself. For example, GIMPS stands for Great Internet Mersenne Prime 5 + 2 + 5 + + x x 1 is irreducible, but x x 1 is not, since Search. It is a distributed computing project x5 + x + 1 = (x2 + x + 1)(x3 + x2 + 1) in GF(2)[x]. started by George Woltman, with home page We do not consider binomials xr + 1, because they http://www.mersenne.org. The goal of GIMPS is are divisible by x + 1, and thus reducible for r > 1. to find new Mersenne primes. As of December 2010, An irreducible polynomial P of degree r > 1 GIMPS has found thirteen new Mersenne primes yields a representation of the finite field GF(2r ) of in fourteen years and has held the record for the 2r elements: any polynomial of degree less than r largest known prime since the discovery of M represents an element, the addition is polynomial 35 addition, whose result still has degree less than r, in 1996. Mersenne primes are usually numbered 2 and the multiplication is defined modulo P: one in increasing order of size: M1 = 2 − 1 = 3, M2 = 3 5 7 first multiplies both inputs and then reduces their 2 − 1 = 7, M3 = 2 − 1 = 31, M4 = 2 − 1 = 127, 6972593 product modulo P. Thus GF(2r ) ' GF(2)[x]/P(x). …, M38 = 2 − 1, etc. An irreducible polynomial P of degree r > 0 Since GIMPS does not always find Mersenne over GF(2) is said to be primitive iff P(x) 6= x primes in order, there can be some uncertainty in and the residue classes xk mod P, 0 ≤ k < 2r − 1, numbering the largest known Mersenne primes. 0 are distinct. In order to check primitivity of an We write Mn for the nth Mersenne prime in order irreducible polynomial P, it is only necessary to of discovery. There are gaps in the search above k 13466917 0 0 check that x 6= 1 mod P for those k that are M39 = 2 −1. Thus we can have Mn > Mn+1 for r 0 43112609 maximal nontrivial divisors of 2 − 1. For example, n > 39. For example, M45 = 2 − 1 was found 5 2 6 3 0 37156667 0 42643801 x + x + 1 is primitive; x + x + 1 is irreducible before M46 = 2 − 1 and M47 = 2 − 1. but not primitive, since x9 = 1 mod (x6 + x3 + 1). At the time of writing this article, forty-seven Here 9 divides 26 − 1 = 63 and is a maximal divisor Mersenne primes are known, and the largest is 0 43112609 as 63/9 = 7 is prime. M45 = 2 − 1.

234 Notices of the AMS Volume 58, Number 2 It is convenient to write rn for the exponent of A GCD computation for polynomials of degree 0 0 Mn, and rn for the exponent of Mn. For example, bounded by r costs O(M(r) log r) using a “divide 0 r45 = 43 112 609. and conquer” approach combined with Schönhage’s fast polynomial multiplication. The costs are Swan’s Theorem summarized in Table 1. We state a useful theorem known as Swan’s theorem, although the result was found much earlier by Table 1: Cost of the basic operations. Pellet [14] and Stickelberger [18]. In fact, there are several theorems in Swan’s paper [19]. We state a modular squaring O(r) simplified version of Swan’s Corollary 5. modular product O(M(r)) GCD O(M(r) log r) Theorem 1. Let r > s > 0, and assume r + s is r s odd. Then Tr,s (x) = x + x + 1 has an even number of irreducible factors over GF(2) in the following cases: Testing Irreducibility 2r a) r even, r 6= 2s, rs/2 = 0 or 1 mod 4. Let Pr (x) = x − x. As was known to Gauss, Pr (x) b) r odd, s not a divisor of 2r, r = ±3 mod 8. is the product of all irreducible polynomials of c) r odd, s a divisor of 2r, r = ±1 mod 8. degree d, where d runs over the divisors of r. For In all other cases xr + xs + 1 has an odd number of example, irreducible factors. 3 3 2 P3(x) = x(x + 1)(x + x + 1)(x + x + 1) If both r and s are even, then Tr,s is a square in GF(2)[x]. Here x and x + 1 are the irreducible and has an even number of irreducible factors. If polynomials of degree 1, and the other factors both r and s are odd, we can apply the theorem to are the irreducible polynomials of degree 3. Note r the “reciprocal polynomial” Tr,r−s (x) = x T(1/x) = that we can always write “+” instead of “−” when r r−s x + x + 1, since Tr,s (x) and Tr,r−s (x) have the working over GF(2), since 1 = −1 (or, equivalently, same number of irreducible factors. 1 + 1 = 0). For r an odd prime and excluding the easily In particular, if r is an odd prime, then a checked cases s = 2 or r − 2, case (b) says that the polynomial P(x) ∈ GF(2)[x] with degree r is trinomial has an even number of irreducible factors, irreducible iff and hence must be reducible, if r = ±3 mod 8. 2r Thus we only need to consider those Mersenne (2) x = x mod P(x) . exponents with r = ±1 mod 8. Of the fourteen (If r is not prime, then (2) is necessary but not known Mersenne exponents r > 106, only eight sufficient: we have to check a further condition to satisfy this condition. guarantee irreducibility; see [8].) When r is prime, equation (2) gives a simple test Cost of the Basic Operations for irreducibility (or primitivity, in the case that r The basic operations that we need are squarings is a Mersenne exponent): just perform r modular modulo the trinomial T = xr +xs +1, multiplications squarings, starting from x, and check whether the modulo T , and greatest common divisors (GCDs) result is x. Since the cost of each squaring is O(r), between T and a polynomial of degree less than r. the cost of the irreducibility test is O(r 2). We measure the cost of these operations in terms There are more sophisticated algorithms for of the number of bit or word operations required to testing irreducibility based on modular composi- implement them. In GF(2)[x], squarings cost O(r), tion [11] and fast matrix multiplication [3]. However, due to the fact that the square of xi + xj is x2i + x2j . these algorithms are actually slower than the classi- The reduction modulo T of a polynomial of degree cal algorithm when applied to trinomials of degree 7 less than 2r costs O(r), due to the sparsity of T ; less than about 10 . thus modular squarings cost O(r). When searching for irreducible trinomials of Modular multiplications cost O(M(r)), where degree r, we can assume that s ≤ r/2, since r s M(r) is the cost of multiplication of two poly- x +x +1 is irreducible iff the reciprocal polynomial r r−s nomials of degree less than r over GF(2); the x + x + 1 is irreducible. This simple observation reduction modulo T costs O(r), so the multipli- saves a factor of 2. In the following, we always cation cost dominates the reduction cost. The assume that s ≤ r/2. “classical” polynomial multiplication algorithm has M(r) = O(r 2), but an algorithm1 due to Schönhage Degrees of Factors has M(r) = O(r log r log log r) [16]. In order to predict the expected behavior of our algorithm, we need to know the expected 1This algorithm differs from the Schönhage-Strassen distribution of degrees of irreducible factors. Our integer-multiplication algorithm, which does not work complexity estimates are based on the assumption over GF(2). For details see [2, 16]. that trinomials of degree r behave like the set of all

February 2011 Notices of the AMS 235 polynomials of the same degree, up to a constant If T = xr + xs + 1 and 2d < r, we can reduce this factor: to the computation of a GCD of polynomials of d 0 d 0 0 r s degree less than 2 . Let d = 2 − 1, r = r mod d , Assumption 1. Over all trinomials x + x + 1 of 0 0 d0 s = s mod d . Then Pd = x(x − 1), degree r over GF(2), the probability πd that a tri- 0 0 0 nomial has no nontrivial factor of degree ≤ d is T = xr + xs + 1 mod (xd − 1), at most c/d, where c is an absolute constant and 1 < d ≤ r/ ln r. so we only need to compute

0 0 0 This assumption is plausible and in agreement gcd(xr + xs + 1, xd − 1). with experiments, though not proven. It is not criti- cal, because the correctness of our algorithms does We call this process “sieving” by analogy with not depend on the assumption—only the predicted the process of sieving out small prime factors of running time depends on it. The upper bound integers, even though it is performed using GCD r/ ln r on d is large enough for our application to computations. predict the running time. An upper bound of r If the trinomials that have factors of degree

on d would probably be incorrect, since it would less than log2(r) are excluded by sieving, then imply at most c irreducible trinomials of degree r, by Assumption 1 we are left with O(r/ log r) but we expect this number to be unbounded. trinomials to test. The cost of sieving is negligible. Some evidence for the assumption, in the case Thus the overall search has cost O(r 3/ log r). r = r38, is presented in Table 2. The maximum value of dπd is 2.08, occurring at d = 226 887. It The Importance of Certificates would be interesting to try to explain the exact Primitive trinomials of degree r < r = 756 839 values of dπ for small d, but this would lead us 32 d are listed in Heringa et al. [10]. Kumada et al. [12] too far afield. reported a search for primitive trinomials of

degree r33 = 859 433 (they did not consider r32). Table 2: Statistics for r = r38 They found one primitive trinomial; however, they missed the trinomial x859433 + x170340 + 1, because d dπ d of a bug in their sieving routine. We discovered the 1 1.00 2 1.33 missing trinomial in June 2000 while testing our 3 1.43 program on the known cases. 4 1.52 This motivated us to produce certificates of 5 1.54 reducibility for all the trinomials that we tested 6 1.60 (excluding, of course, the small number that turned 7 1.60 out to be irreducible). A certificate of reducibility 8 1.67 is, ideally, a nontrivial factor. If a trinomial T 9 1.64 is found by sieving to have a small factor, then 10 1.65 it is easy to keep a record of this factor. If we 100 1.77 do not know a factor, but the trinomial fails 1000 1.76 the irreducibility test (2), then we can record the 10000 1.88 residue R(x) = x2r − x mod T . Because the residue 226887 2.08 can be large, we might choose to record only part of it, e.g., R(x) mod x32.

Sieving The Classical Period When testing a large integer N for primality, it The period 2000–2003 could be called the classical is sensible to check whether it has any small period. We used efficient implementations of the factors before applying a primality test such as classical algorithms outlined above. Since different the AKS, ECPP, or (if we are willing to accept trinomials could be tested on different computers, a small probability of error) Rabin-Miller test. it was easy to conduct a search in parallel, using as Similarly, when testing a high-degree polynomial many processors as were available. For example, for irreducibility, it is wise to check whether it has we often made use of PCs in an undergraduate any small factors before applying the O(r 2) test. teaching laboratory during the vacation, when the Since the irreducible polynomials of degree d students were away. divide Pd (x), we can check whether a trinomial T In this way, we found three primitive trinomials has a factor of degree d (or some divisor of d) by of degree r32 = 756 839 (in June 2000), two of computing degree r37 = 3 021 377 (August and December gcd(T , Pd ). 2000), and one of degree r38 = 6 972 593 (in

236 Notices of the AMS Volume 58, Number 2 2 August 2002). The computation for degree r38 was not irreducible. Since a GCD typically takes about completed and double-checked by July 2003. 40 times as long as a modular multiplication for 0 For degree r38 = 6 972 593, there turned out r ≈ r41, blocking can give a large speedup. to be only one primitive trinomial xr + xs + 1 During a visit by the second author to the (assuming, as usual, that s ≤ r/2).3 How can we first author in February 2007, we realized that be sure that we did not miss any? For each a second level of blocking could be used to nonprimitive trinomial we had a certificate, and replace most modular multiplications by squarings. these certificates were checked in an independent Since a modular multiplication might take 400 0 computation. In fact, we found a small number times as long as a squaring (for r ≈ r41), this of discrepancies, possibly due to memory parity second level of blocking can provide another large errors in some of the older PCs that were used. speedup. The details are described in [6]. Here This is a risk in any long computation—we should we merely note that m multiplications and m not assume that computers are infallible. The squarings can be replaced by one multiplication same phenomenon was observed by Nicely [13] in and m2 squarings. The optimal value of m is p his computation of Brun’s constant (which also m0 ≈ M(r)/S(r), where M(r) is the cost of a uncovered the infamous “Pentium bug”). modular multiplication and S(r) is the cost of a Since we had caught up with the GIMPS project, modular squaring, and the resulting speedup is we thought (not for the last time) that this game about m0/2. If M(r)/S(r) = 400, then m0 ≈ 20 and had finished and published our results in [4, 5]. the speedup over single-level blocking is roughly a However, GIMPS soon overtook us by finding several factor of ten. larger Mersenne primes with exponents ±1 mod 8: Using these ideas, combined with a fast im- 0 0 r41 = 24 036 583, . . . , r44 = 32 582 657. plementation of polynomial multiplication (for The search for degree r38 = 6 972 593 had taken details, see [2]) and a subquadratic GCD algorithm, more than two years (February 2001 to July 2003), we were able to find ten primitive trinomials of so it did not seem feasible to tackle the new degrees r 0 , . . . , r 0 by January 2008. Once again, 0 0 41 44 Mersenne exponents r41, . . . , r44. we thought we were finished and published our results [7], only to have GIMPS leap ahead again The Modern Period 0 0 by discovering M45 in August 2008 and M46 and 0 0 We realized that, in order to extend the compu- M47 shortly afterward. The exponent r46 was ruled tation, we had to find more efficient algorithms. out by Swan’s theorem, but we had to set to work 0 The expensive part of the computation was testing on degrees r45 = 43 112 609 and (later) the slightly 0 irreducibility using equation (2). If we could sieve smaller r47 = 42 643 801. 0 much further, we could avoid most of the irre- The search for degree r45 ran from September ducibility tests. From Assumption 1, if we could 2008 to May 2009, with assistance from Dan sieve to degree r/ ln r, then we would expect only Bernstein and Tanja Lange, who kindly allowed us O(log r) irreducibility tests. to use their computing resources in Eindhoven, What we needed was an algorithm that would and resulted in four primitive trinomials of record find the smallest factor of a sparse polynomial degree. (specifically, a trinomial) in a time that was fast on 0 The search for degree r47 ran from June 2009 to average. August 2009 and found five primitive trinomials. There are many algorithms for factoring poly- In this case we were lucky to have access to a nomials over finite fields; see, for example, [8]. The new computing cluster with 224 processors at the cost of most of them is dominated by GCD com- Australian National University, so the computation putations. However, it is possible to replace most took less time than the earlier searches. GCD computations by modular multiplications, The results of our computations in the “modern using a process called blocking (introduced by period” are given in Table 3. There does not seem Pollard [15] in the context of integer to be any predictable pattern in the s values. and by von zur Gathen and Shoup [9] for polyno- The number of primitive trinomials for a given mial factorization). The idea is simple: instead of Mersenne exponent r = ±1 mod 8 appears to follow computing gcd(T , P1), . . . , gcd(T , Pk) in the hope a Poisson distribution with mean about 3.2 (and of finding a nontrivial GCD (and hence a factor hence it is unlikely to be bounded by an absolute of T ), we compute gcd(T , P1P2 ··· Pk mod T) and constant—see the discussion of Assumption 1 backtrack if necessary to split factors if they are above).

2 Primitive trinomials of degree r34, r35, and r36 were ruled 0 The Modern Algorithm—Some Details out by Swan’s theorem, as were r39 and r40. 3The unique primitive trinomial of degree 6 972 593 is To summarize the “modern” algorithm for finding x6972593 + x3037958 + 1. It was named Bibury after the vil- primitive trinomials, we improve on the classical lage that the three authors of [5] were visiting on the day algorithm by sieving much further to find a factor that it was discovered. of smallest degree, using a factoring algorithm

February 2011 Notices of the AMS 237 Table 3: Primitive trinomials xr + xs + 1 whose modular squaring. Thus, from Table 1, the cost degree r is a Mersenne exponent, for s ≤ r/2. per value of d is O(M(r) log r). However, this does not take into account the speedup due to blocking, r s discussed above. 24 036 583 8 412 642, 8 785 528 25 964 951 880 890, 4 627 670, 4 830 131, 6 383 880 The critical fact is that most trinomials have a 30 402 457 2 162 059 small factor, so the search runs fast on average. 32 582 657 5 110 722, 5 552 421, 7 545 455 After searching unsuccessfully for factors of 42 643 801 55 981, 3 706 066, 3 896 488, 6 12 899 278, 20 150 445 degree d < 10 , say, we could switch to the 43 112 609 3 569 337, 4 463 337, 17 212 521, 21 078 848 classical irreducibility test (2), which is faster than factoring if the factor has degree greater than about 106. However, in that case our list based on fast multiplication and two levels of of certificates would be incomplete. Since it is blocking. In the following paragraphs we give some rare to find a factor of degree greater than 106, details of the modern algorithm and compare it we let the program run until it finds a factor or with the classical algorithms. outputs “irreducible”. In the latter case, of course, Given a trinomial T = xr + xs + 1, we search for we can verify the result using the classical test. a factor of smallest degree d ≤ r/2. (In fact, using Of the certificates (smallest irreducible factors) Swan’s theorem, we can usually restrict the search found during our searches, the largest is a factor to d ≤ r/3, because we know that the trinomial has P(x) = x10199457 + x10199450 + · · · + x4 + x + 1 of an odd number of irreducible factors.) If such a the trinomial x42643801 + x3562191 + 1. Note that, factor is found, we know that T is reducible, so the program outputs “reducible” and saves the factor although the trinomial is sparse and has a compact for a certificate of reducibility. The factor can be representation, the factor is dense and hence too d large to present here in full. found by taking the GCD of T and x2 + x; if this GCD is nontrivial, then T has at least one factor of degree dividing d. If factors of degree smaller than Classical versus Modern d have already been ruled out, then the GCD only For simplicity we use the Oe notation that ignores contains factors of degree d (possibly a product log factors. The “classical” algorithm takes an of several such factors). This is known as distinct expected time O(re 2) per trinomial, or O(re 3) to degree factorization (DDF). cover all trinomials of degree r. If the GCD has degree λd for λ > 1, and one The “modern” algorithm takes expected time wants to split the product into λ factors of degree O(r)e per trinomial, or O(re 2) to cover all trinomials d, then an equal degree factorization algorithm of degree r. (EDF) is used. If the EDF is necessary it is usually In practice, the modern algorithm is faster by a

cheap, since the total degree λd is usually small if factor of about 160 for r = r38 = 6 972 593, and by 0 λ > 1. a factor of about 1000 for r = r45 = 43 112 609. 0 In this way we produce certificates of reducibility Thus, comparing the computation for r = r45 that consist just of a nontrivial factor of smallest with that for r = r38: using the classical algorithm possible degree, and the lexicographically least would take about 240 times longer (impractical), 4 such factor if there are several. The certificates but using the modern algorithm saves a factor of can be checked, for example with an independent 1000. program using NTL [17], much faster than the original computation (typically in less than one How to Speed Up the Search hour for any of the degrees listed in Table 3). The key ideas are summarized here. Points (1)–(4) d For large d, when 2  r, we do not compute apply to both the classical and modern algorithms; 2d x + x itself, but its remainder, say h, modulo T . points (5)–(6) apply only to the modern algorithm. Indeed, gcd(T , x2d + x) = gcd(T , h). To compute h, (1) Since the computations for each trinomial we start from x, perform d modular squarings, and can be performed independently, it is easy add x. In this way, we work with polynomials of to conduct a search in parallel, using as degree less than 2r. Checking for factors of degree many computers as are available. d costs d modular squarings and one GCD. Since (2) Because the coefficients of polynomials we check potential degrees d in ascending order, d d−1 over GF(2) are just 0 or 1, there is a one- x2 mod T is computed from x2 mod T , which one correspondence between polynomials was obtained at the previous step, with one extra of degree < d and binary numbers with d bits. Thus, on a 64-bit computer, we 4It is worth going to the trouble to find the lexicographi- cally least factor, since this makes the certificate unique can encode a polynomial of degree d in and allows us to compare different versions of the pro- d(d+1)/64e computer words. If we take care gram and locate bugs more easily than would otherwise writing the programs, we can operate on be the case. such polynomials using full-word computer

238 Notices of the AMS Volume 58, Number 2 operations, thus doing 64 operations in References parallel. 1. W. Bosma and J. Cannon, Handbook of (3) Squaring of polynomials over GF(2) can be Magma Functions, School of Mathematics done in linear time (linear in the degree of and Statistics, University of Sydney, 1995. the polynomial), because the cross terms http://magma.maths.usyd.edu.au/ 2. , and in the square vanish: R. P. Brent, P. Gaudry, E. Thomé P. Zimmer- mann, Faster multiplication in GF(2)[x], Proc. ANTS  2 VIII 2008, Lecture Notes in Computer Science 5011, X k X 2k 153–166.  akx  = akx . k k 3. R. P. Brent and H. T. Kung, Fast algorithms for ma- nipulating formal power series, J. ACM 25 (1978), (4) Reduction of a polynomial of degree 2(r −1) 581–595. r s modulo a trinomial T = x +x +1 of degree 4. R. P. Brent, S. Larvala, and P. Zimmermann,A r can also be done in linear time. Simply fast algorithm for testing reducibility of trinomials use the identity xn = xn+s−r + xn−r mod T mod 2 and some new primitive trinomials of degree for n = 2r − 2, 2r − 3, . . . , r to replace the 3021377, Math. Comp. 72 (2003), 1443–1452. terms of degree ≥ r by lower-degree terms. 5. , A primitive trinomial of degree 6972593, (5) Most GCD computations involving polyno- Math. Comp. 74 (2005), 1001–1002. 6. R. P. Brent and P. Zimmermann, A multi-level block- mials can be replaced by multiplication of ing distinct-degree factorization algorithm, Finite polynomials, using a technique known as Fields and Applications: Contemporary Mathematics “blocking” (described above). 461 (2008), 47–58. (6) Most multiplications of polynomials can be 7. , Ten new primitive binary trinomials, Math. replaced by squarings, using another level Comp. 78 (2009), 1197–1199. of blocking, as described in [6]. 8. J. von zur Gathen and J. Gerhard, Modern Computer Algebra, Cambridge Univ. Press, 1999. Conclusion 9. J. von zur Gathen and V. Shoup, Computing Frobe- nius maps and factoring polynomials, Computational The combination of these six ideas makes it Complexity 2 (1992), 187–224. feasible to find primitive trinomials of very large 10. J. R. Heringa, H. W. J. Blöte, and A. Compagner, New degree. In fact, the current record degree is the primitive trinomials of Mersenne-exponent degrees same as the largest known Mersenne exponent, for random-number generation, International J. of 0 Modern Physics C 3 (1992), 561–564. r = r45 = 43 112 609. We are ready to find more primitive trinomials as soon as GIMPS finds another 11. K. Kedlaya and C. Umans, Fast modular composition Mersenne prime that is not ruled out by Swan’s in any characteristic, Proc. FOCS 2008, 146–155. 12. T. Kumada, H. Leeb, Y. Kurita, and M. Matsumoto, theorem. Our task is easier than that of GIMPS, New primitive t-nomials (t = 3, 5) over GF(2) because finding a primitive trinomial of degree r, whose degree is a Mersenne exponent, Math. Comp. and verifying that a single value of r is a Mersenne 69 (2000), 811–814. Corrigenda: ibid 71 (2002), exponent, both cost about the same: O(re 2). 1337–1338. The trinomial hunt has resulted in improved 13. T. Nicely, A new error analysis for Brun’s constant, software for operations on polynomials over GF(2), Virginia Journal of Science 52 (2001), 45–55. and has shown that the best algorithms in theory are 14. A.-E. Pellet, Sur la décomposition d’une fonction not always the best in practice. It has also provided entière en facteurs irréductibles suivant un mod- ule premier p, Comptes Rendus de l’Académie des a large database of factors of trinomials over GF(2), Sciences Paris 86 (1878), 1071–1072. leading to several interesting conjectures that are 15. J. M. Pollard, A Monte Carlo method for a topic for future research. factorization, BIT 15 (1975), 331–334, 16. A. Schönhage, Schnelle Multiplikation von Poly- Acknowledgments nomen über Körpern der Charakteristik 2, Acta We thank Allan Steel for verifying many of our Informatica 7 (1977), 395–398. 17. , NTL: A library for doing number theory. primitive trinomials using Magma [1], and Philippe V. Shoup http://www.shoup.net/ntl/ Falandry, Shuhong Gao, Robert Hedges, Samuli 18. L. Stickelberger, Über eine neue Eigenschaft der Larvala, Brendan McKay, Éric Schost, Julian Seward, Diskriminanten algebraischer Zahlkörper, Verhand- Victor Shoup, Andrew Tridgell, and George Woltman lungen des ersten Internationalen Mathematiker- for their advice and assistance in various ways. Nate Kongresses, Zürich, 1897, 182–193. Begeman, Dan Bernstein, Nicolas Daminelli, Tanja 19. R. G. Swan, Factorization of polynomials over finite Lange, Ernst Mayer, Barry Mead, Mark Rodenkirch, fields, Pacific J. Math. 12 (1962), 1099–1106. Juan Luis Varona, and Mike Yoder contributed 20. S. Wagstaff Jr., The Cunningham Project. machine cycles to the search. Finally, we thank http://homes.cerias.purdue.edu/~ssw/cun/ 21. G. Woltman et al., GIMPS, The Great Inter- the University of Oxford, the Australian National net Mersenne Prime Search, http://www. University, and INRIA for use of their computing mersenne.org/ facilities and the Australian Research Council for its support.

February 2011 Notices of the AMS 239