Algorithms for Finding Almost Irreducible
and Almost Primitive Trinomials
Abstract.
Consider polynomials over . We describe efficient algorithms for finding trinomials with large irreducible (and possibly primitive) factors, and give examples of trinomials having a primitive factor of degree for all Mersenne exponents in the range , although there is no irreducible trinomial of degree . We also give trinomials with a primitive factor of degree for . These trinomials enable efficient representations of the finite field . We show how trinomials with large primitive factors can be used efficiently in applications where primitive trinomials would normally be used.
1991 Mathematics Subject Classification:
Primary 11B83, 11Y16; Secondary 11-04, 11K35, 11N35, 11R09, 11T06, 12-04, 12Y05, 68Q251. Introduction
Irreducible and primitive polynomials over finite fields have many applications in cryptography, coding theory, random number generation, etc. See, for example, [13, 15, 17, 20, 21].
For simplicity we restrict our attention to the finite field ; the generalization to other finite fields is straightforward. All polynomials are assumed to be in , and computations on polynomials are performed in or in a specified quotient ring. A polynomial may be written as if the argument is clear from the context. We recall some standard definitions.
Definition 1.1.
A polynomial with has period if is the least positive integer such that . We say that has order .
Definition 1.2.
A polynomial is reducible if it has nontrivial factors; otherwise it is irreducible.
Definition 1.3.
A polynomial of degree is primitive if is irreducible and has period . (Recall our assumption that .)
If is primitive, then is a generator for the multiplicative group of the field , giving a concrete representation of . See Lidl and Niederreiter [20] or Menezes et al. [21] for background information.
There is an interest in discovering primitive polynomials of high degree for applications in random number generation [4, 7] and cryptography [21]. In such applications it is often desirable to use primitive polynomials with a small number of nonzero terms, i.e. a small weight. In particular, we are interested in trinomials of the form , where (so there are exactly three nonzero terms).
If is irreducible and , then the order of in is a divisor of . To test if is primitive, we must test if the order of is exactly . To do this efficiently111Here “efficiently” means in time polynomial in the degree . it appears that we need to know the complete prime factorization of . At the time of writing these factorizations are known for and certain larger , see [8].
We say that is a Mersenne exponent if is prime. In this case the factorization of is trivial and an irreducible polynomial of degree is necessarily primitive. Large Mersenne exponents are known [14], so there is a possibility of finding primitive trinomials of high degree. To test if a trinomial of prime degree is reducible takes time , so to test all trinomials of degree takes time .
Several authors [16, 18, 19, 27] have computed primitive trinomials whose degree is a Mersenne exponent, up to some bound imposed by the computing resources available. Recently Brent, Larvala and Zimmermann [6] gave a new algorithm, more efficient than those used previously, and computed all the primitive trinomials of Mersenne exponent (subsequently extended to ).
For some , irreducible trinomials of given degree do not exist. Swan’s theorem (see §2) rules out and also most . Since about half of the known Mersenne exponents are , we can only hope to find primitive trinomials of degree for about half the Mersenne exponents .
In the cases where primitive trinomials are ruled out by Swan’s theorem, the conventional approach is to use primitive polynomials with more than three nonzero terms. A polynomial with an even number of nonzero terms is divisible by , so we must use polynomials with five or more nonzero terms [18, 19, 21]. This is considerably more expensive in applications because the number of operations required for multiplication or division by a sparse polynomial is approximately proportional to the number of nonzero terms.
In §2 we discuss Swan’s theorem, then in §3 we introduce “almost irreducible” and “almost primitive” polynomials as a way of circumventing the implications of Swan’s theorem. An algorithm (AIT) for computing almost irreducible trinomials, and an extension (APT) for almost primitive trinomials, are described in §4. Algorithm APT has been used to find almost primitive trinomials with high degree in cases where Swan’s theorem shows that primitive trinomials do not exist. Computational results and examples are given in §§5–6. In §7 we give some computational results on almost primitive trinomials that are useful for representing the finite fields , . In §8 we explain how to use almost irreducible/primitive trinomials efficiently in applications. Finally, in §9, we conclude with some theoretical results on the density of almost irreducible and almost primitive polynomials, and some computational results on the density of the corresponding trinomials. We thank Shuhong Gao and the referees for their comments on a draft of this paper.
2. Swan’s theorem and its implications
Swan’s theorem is a rediscovery of results of Pellet [23], Stickelberger [24], Dickson [10] and Dalen [9] – see Swan [25, p. 1099] and von zur Gathen [12]. Let denote the number of irreducible factors (counted according to their multiplicity) of a polynomial .
Theorem 2.1.
Swan [25, Corollary 5].
Suppose , odd. Then
iff one of the following holds:
a) even, , ;
b) , ;
c) , .
If both and are odd, we can replace by (leaving the number of irreducible factors unchanged, since ) and apply Swan’s theorem. If and are both even, then is a square and is even. Thus, in all cases we can determine using Swan’s theorem.
Since a polynomial that has an even number of irreducible factors is reducible, we have:
Corollary 2.2.
If is prime, , , , then is reducible over .
Corollary 2.2 shows that there are no irreducible trinomials with degree a Mersenne exponent (except possibly for or ). This appears to prevent us from using trinomials with periods in these cases. Fortunately, there is a way to circumvent Swan’s theorem and avoid paying a significant speed penalty in most applications of irreducible/primitive trinomials. We describe this in the following section.
3. Almost primitive trinomials
Tromp, Zhang and Zhao [26] asked the following question: given an integer , do there exist integers such that
is a primitive polynomial of degree ? They verified that the answer is “yes” for , and conjectured that the answer is always “yes”.
Blake, Gao and Lambert [3] confirmed the conjecture for . They also relaxed the condition slightly and asked: do there exist integers such that has a primitive factor of degree ? Motivated by [3], we make some definitions.
Definition 3.1.
A polynomial of degree is almost primitive (almost irreducible) if and has a primitive (irreducible) factor of degree , for some . We say that has exponent and increment .
For example, the trinomial is almost primitive with exponent 13 and increment 3, because
where
is primitive. From a computational viewpoint it is more efficient to work in the ring than in the field . In §8 we outline how it is possible to work in the field , while performing most arithmetic in the ring , and without explicitly computing the dense primitive polynomial .
Note that, according to Definition 3.1, a primitive polynomial is a fortiori an almost primitive polynomial (the case ). Similarly, an irreducible polynomial other than or is almost irreducible. The restriction in Definition 3.1 ensures that polynomials such as are not regarded as almost irreducible.
4. Searching for almost irreducible/primitive trinomials
In this section we outline algorithms for finding almost irreducible or almost primitive trinomials with large exponent . In the latter case we assume that the complete factorization of is known. The algorithms are generalizations of those given in [6, 13, 21], which handle the case .
4.1. An algorithm for almost irreducible trinomials
Suppose , , and we wish to test if the trinomial is almost irreducible with exponent (see Definition 3.1). If it is not then we discard it, and (perhaps) try again with different .
We first state the algorithm, then explain the steps whose justification
is not immediately obvious.
Input to the algorithm is and a
sieving bound . The optimal is
implementation-dependent:
see the discussion in [6].
In the computation of Table 1 we used .
Recall that polynomials are in ,
so computations on polynomials are performed in or in a
quotient ring such as .
Algorithm AIT
-
(1)
If then return false.
-
(2)
; ; ; ;
for to do
;
; ;
; ; -
(3)
if or then return false.
-
(4)
for to do
;
if then return false. -
(5)
if then return false.
-
(6)
for each prime divisor of
if then return false. -
(7)
return true. [ is almost irreducible with exponent .] ∎
If , Algorithm AIT reduces to a standard algorithm for finding irreducible trinomials. We can assume that , because the only irreducible polynomials of degree 1 are and , and neither can be a factor of a trinomial. Hence, we need only consider .
Step 1 discards trinomials that are squares (see Theorem 4.1 below). If this step is passed then , so is square-free.
Step 2 may be called sieving, although it is done by GCD computations. By computing for , we find the product of all irreducible factors of such that . We have , where is some polynomial of degree , and .
Step 3 returns false if or is incompatible with the assumption that has an irreducible factor of degree . Note that Swan’s theorem gives .
In Step 4, suppose . Thus is a factor of , and . If then is reducible. If then splits into factors of degree at most , so again is reducible. Thus, we can return false.
In Step 5, sieving has failed to discard , so a full irreducibility test of is required. We can discard (i.e. return false) if , but is in general a dense polynomial, so we perform an equivalent computation that only involves exponentiation mod . Note that the computation of takes only bit-operations, since is a trinomial.
4.2. Algorithm APT for almost primitive trinomials
To search foralmost primitive trinomials with exponent , we apply Theorem 4.2 below, and then algorithm AIT, to find a candidate trinomial that is almost irreducible with exponent . Unless is prime, it is necessary to verify that the irreducible factor of degree has period and not some proper divisor of . This can be done by verifying that, for each prime divisor of ,
4.3. Refinements
Several refinements are possible.
1. The fast algorithm of [6, §4] can be used to accelerate the computation of in steps 2, 4–6 of Algorithm AIT if is odd.
2. Sieving can often be curtailed. Suppose that step 2 of Algorithm AIT has been performed for , so we have found all irreducible factors ofdegree . Suppose that the sum of their degrees is . If
(4.1) |
then the constraint can not be satisfied and we can return false. Also, if , then (4.1) can be replaced by the weaker condition
(4.2) |
3. If is a Mersenne exponent, computation of the small factor can be avoided. Define , so is a multiple of the period of , and . Step 2 of Algorithm AIT can easily be modified to compute instead of , and to save at iteration . Step 4 can be modified to return false if . Step 5 can be modified to return false if
(4.3) |
The computation involved is almost the same as for the “standard” method of testing irreducibility of a trinomial [6, §3]: the significant difference is that we start with instead of . This variation of algorithm AIT was used to compute most of the entries in Table 1.
Theorem 4.1.
Let be an almost irreducible trinomial. Then is odd.
Proof.
Assume that is even. Then is a square, so can not have an irreducible factor of degree greater than . ∎
We remark that is irreducible (though not primitive) over , and in this case .
Theorem 4.2.
Let be an almost primitive trinomial. Then .
Proof.
Suppose . From Theorem 4.1 we can assume that . Write . Thus , where , . The order of is at most . Thus, the order of is at most . If is almost primitive with exponent , then the order of is . Thus
Now by Definition 3.1, so
(4.4) |
The right-hand side of (4.4) is a decreasing function of for . Thus,
(4.5) |
It is easy to verify that (4.5) can not hold for , but if then , which is a contradiction. Hence . ∎
5. Computational results
We conducted a search for almost primitive trinomials whose exponent is also a Mersenne exponent. For all Mersenne exponents with , primitive trinomials of degree are known, see [6]. Here we consider the cases , where the existence of irreducible trinomials is ruled out by Swan’s theorem (except for or , but the only known cases are ). For each exponent we searched for all almost primitive trinomials with the minimal increment for which at least one almost primitive trinomial exists. The search has been completed for all Mersenne exponents .
In all cases of Mersenne exponent , where , we have found at least one almost primitive trinomial with exponent and some increment . The results are summarized in Table 1. The first four entries are from [3, Table 4]; the other entries are new. They were computed using Algorithm APT, with some simplifications that are possible because is a Mersenne exponent (see §4.3.3 above).
For all but two of the almost primitive trinomials given in Table 1, the period satisfies . Thus, the period is greater than the greatest period () that can be obtained for any polynomial of degree less than . In the two exceptional cases the small factors of degree are not primitive, having period .
For the largest known Mersenne exponent, , we have not yet started an extensive computation, but we have shown that and (see Theorem 6.3).
Small factors and remarks | ||||
13 | 3 | 3 | 7 | |
19 | 3 | 3 | 7 | |
61 | 5 | 17 | 31 | |
107 | 2 | 8 | 3 | |
14 | 3 | |||
17 | 3 | |||
2203 | 3 | 355 | 7 | |
4253 | 8 | 1806 | 255 | |
1960 | 85 | |||
9941 | 3 | 1077 | 7 | |
11213 | 6 | 227 | 63 | |
21701 | 3 | 6999 | 7 | |
7587 | 7 | |||
86243 | 2 | 2288 | 3 | |
216091 | 12 | 42930 | 3937 | |
1257787 | 3 | 74343 | 7 | |
1398269 | 5 | 417719 | 21 | |
2976221 | 8 | 1193004 | 85 | |
13466917 | ? | ? | ? | None for or |
Some almost primitive trinomials over .
has a primitive factor of degree ;
is minimal; ; the period .
6. Examples and special cases
We considered the almost primitive trinomial in §3. Here we give an example with much higher degree: , . We have
where
and is a (dense) primitive polynomial of degree 216091. The factor of degree 12 splits into a product of two primitive polynomials, and . The contribution to the period from these factors is .
Theorem 6.1.
If is an almost irreducible trinomial with exponent 216091 and increment , then .
Proof.
As is a trinomial, it is not divisible by or , so
.Assume that is almost irreducible
with , where.
Thus where is irreducible, ,
is odd and we can assume that is even (otherwise
replace by ).
Since is a Mersenne exponent, is primitive and is
almost primitive.
Let . We consider the cases
in turn and show that each case leads to a contradiction.
A. . and , so by Swan’s theorem
. From Theorem 4.2, , so the only
possibility is .
Now , so .
Thus , a contradiction.
B. .
, so .
Thus does not divide , but is the only irreducible
polynomial of degree 2, and hence the only possibility for ,
a contradiction.
C. .
, but can not have irreducible factors of degree 2,
since is the only irreducible polynomial of degree 2,
and is square-free. Thus
is irreducible of degree 4 and a divisor of .
We have
and , so by Swan’s theorem
and Theorem 4.2
we must have .
Now , so
,
but is irreducible.
Thus has no factor of degree 4, a contradiction.
D. .
could be of the
form , or ,
where are irreducible of degree .
If then and, by Swan’s theorem and
Theorem 4.2, . However, ,
so , a contradiction.
If then .
Now , so ,
and in each of the 15 cases we find that .
If then
.
Now, so , and
. Thus .
∎
Theorem 6.2.
If is an almost irreducible trinomial with exponent 2976221 and increment , then .
Proof.
The proof is similar to that of Theorem 6.1. Assume that and that is even. If we must have . Now , so, and thus has an irreducible factor . If , again we must have . In this case , and a computation shows that . Finally, if , we have , so has no irreducible factor of degree 4. ∎
Theorem 6.3.
If is an almost irreducible trinomial with exponent 13466917 and increment , then .
Proof.
As above, we can assume that , is odd, and without loss of generality is even. If the only case to consider is , but , so , and thus is divisible by . If then , so is never divisible by . If then must be irreducible of degree 4, and the only possibility is . Now , but is irreducible, so has no irreducible factor of degree 4. ∎
7. The Fermat connection
If we have found an almost irreducible trinomial with exponent , then to check if is almost primitive we need the complete factorization of . In §5 we chose so the factorization was trivial, because was a Mersenne prime. Another case of interest, considered in this section, is when is a power of two, say . Then
where is the -th Fermat number. The complete factorizations of these are known for (see [5]) so we can factor for .
In Table 2 we give almost primitive trinomials with exponent for . Thus where is primitive and has degree . We also give in factored form. The irreducible factors of are not always primitive. The period of is .
By Swan’s theorem, a primitive trinomial of degree does not exist for . However, we can work efficiently in the finite fields , , using the trinomials listed in Table 2 and the implicit algorithms of §8.
Small factor | |||||
3 | 8 | 5 | 1 | 31 | |
2 | 7 | ||||
4 | 16 | 11 | 2 | 7 | |
5 | 32 | 8 | 3 | 1 | |
6 | 64 | 10 | 3 | 21 | |
21 | 341 | ||||
7 | 128 | 2 | 17 | 1 | |
8 | 256 | 16 | 45 | 1 | |
9 | 512 | 9 | 252 | 31 | |
10 | 1024 | 3 | 22 | 7 | |
11 | 2048 | 10 | 101 | 341 | |
12 | 4096 | 3 | 600 | 7 | |
628 | 7 | ||||
1399 | 7 |
Some almost primitive trinomials over .
has a primitive factor of degree ;
is minimal; ; the period .
8. Implicit algorithms
Suppose we wish to work in the finite field where is the exponent of an almost primitive trinomial . We can write , where , . Thus
but because is dense we wish to avoid working directly with , or even explicitly computing . We show that it is possible to work modulo the trinomial .
We can regard as a redundant representation of . Each element can be represented as
where is the “canonical representation” that would be obtained if we worked in , and is some polynomial of degree less than .
We can perform computations such as addition, multiplication and exponentiation in , taking advantage of the sparsity of in the usual way.If and we wish to map to its canonical representation , we use the identity
where the division by the (small) polynomial is exact. A straightforward implementation requires only operations. We avoid computing directly; in fact we never compute the (large and dense) polynomial : it is sufficient that is determined by the trinomial and the small polynomial .
In applications such as random number generation [7], where the trinomial is the denominator of the generating function for a linear recurrence , it is possible (by choosing appropriate initial conditions that annihilate the unwanted component) to generate a sequence that satisfies the recurrence defined by the polynomial . However, this is not necessary if all that matters is that the linear recurrence generates a sequence with period at least .
9. The density of almost irreducible/primitive polynomials
In this section we state some theorems regarding the distribution of almost irreducible polynomials. The proofs are straightforward, and similar to the proof of Theorem 1.2 in [11], which generalizes our Corollary 9.2. We would like to prove similar theorems about almost irreducible trinomials, but this seems to be difficult.
Let denote the number of irreducible polynomials of degree , excluding the polynomial , and let denote the number of almost irreducible polynomials with exponent and increment . Thus and, by Möbius inversion,
Theorem 9.1.
If , then .
Proof.
The case is immediate, so assume that . Thus . For each irreducible polynomial of degree , and each polynomial of degree such that , there is an almost irreducible polynomial . Also, by the constraint , determines and uniquely. Thus, the result follows by a counting argument, since there are possibilities for and possibilities for . ∎
Corollary 9.2.
If , , and is chosen uniformly at random from the polynomials of degree with , then the probability that is almost irreducible with exponent is .
Corollary 9.3.
If and is chosen uniformly at random from the polynomials of degree with , then the probability that is almostirreducible with some valid exponent is .
An analogy
The density of almost primitive polynomials
The number of primitive polynomials of degree is , where denotes Euler’s phi function, see for example Lidl [20]. If is replaced by in Theorem 9.1, then we obtain the number of almost primitive polynomials with exponent and increment . It is easy to deduce an analogue of Corollary 9.2. To obtain an analogue of Corollary 9.3 for almost primitive polynomials we would need to estimate . For the approximate value is 0.507.
Computational results for trinomials
Let be the number of almost irreducible trinomials with . Consider the smoothed and normalized value . If a result like Corollary 9.3 applies for trinomials, at least in the limit as , , then it is plausible to conjecture that
(9.1) |
for some positive constant . We have computed and for ;the numerical results support the conjecture (9.1) with . For example, and . For almost primitive trinomials the corresponding limit seems smaller (if it exists). Our computations give and .
Existence of almost irreducible/primitive trinomials
We have shown by computation that an almost irreducible trinomial of degree exists for all. Similarly, we have shown that an almost primitive trinomial of degree exists for all . In the exceptional case (degree 12), has primitive factors of degrees 3, 4, and 5, but degree is too small, so is not “almost primitive” by Definition 3.1. The other candidate that is not excluded by Theorem 4.2 is ; this is irreducible but not primitive, having period .
Rather than asking for an almost irreducible (or almost primitive) trinomial of given degree, we can ask for one of given exponent. This is close to the spirit of [3, 26]. For all there is an almost irreducible trinomial with exponent and (minimal) increment . The extreme increment occurs for , and the mean value of for is . A plausible conjecture is that .
Similarly, for all there is an almost primitive trinomial with exponent and (minimal) increment . The extreme occurs for , and the mean value of for is .
References
- [1] E. R. Berlekamp, Algebraic Coding Theory, McGraw-Hill, New York, 1968.
- [2] I. F. Blake, S. Gao and R. J. Lambert, Constructive problems for irreducible polynomials over finite fields, in Information Theory and Applications (A. Gulliver and N. Secord, eds.), Lecture Notes in Computer Science 793, Springer-Verlag, Berlin, 1994, 1–23.
- [3] I. F. Blake, S. Gao and R. Lambert, Construction and distribution problems for irreducible trinomials over finite fields, in Applications of Finite Fields (D. Gollmann, ed.), Oxford, Clarendon Press, 1996, 19–32. www.math.clemson.edu/~sgao/pub.html
- [4] R. P. Brent, Uniform random number generators for supercomputers, Proc. Fifth Australian Supercomputer Conference, Melbourne, Dec. 1992, 95–104.
- [5] R. P. Brent, Factorization of the tenth Fermat number, Math. Comp. 68 (1999), 429–451.
- [6] R. P. Brent, S. Larvala and P. Zimmermann, A fast algorithm for testing reducibility of trinomials mod 2 and some new primitive trinomials of degree 3021377, Math. Comp. 72 (2003), 1443–1452. Update at http://www.comlab.ox.ac.uk/oucl/work/richard.brent/pub/pub199.html
- [7] R. P. Brent and P. Zimmermann, Random number generators with period divisible by a Mersenne prime, Proc. ICCSA 2003, Montreal, to appear in Lecture Notes in Computer Science. http://www.comlab.ox.ac.uk/oucl/work/richard.brent/pub/pub211.html
- [8] J. Brillhart, D. H. Lehmer, J. L. Selfridge, B. Tuckerman, and S. S. Wagstaff, Jr., Factorizations of , up to High Powers, third edition, Amer. Math. Soc., Providence, RI, 2002. http://www.ams.org/online_bks/conm22/
- [9] K. Dalen, On a theorem of Stickelberger, Math. Scand. 3, 124–126, 1955.
- [10] L. E. Dickson, Criteria for the irreducibility of functions in a finite field, Bulletin Amer. Math. Soc. 13(1) (1906), 1–8.
- [11] S. Gao, Elements of provable high orders in finite fields, Proc. Amer. Math. Soc. 127(6) (1999), 1615–1623.
- [12] J. von zur Gathen, Irreducible trinomials over finite fields, Math. Comp. 71 (2002), 1699–1734.
- [13] J. von zur Gathen and J. Gerhard, Modern Computer Algebra, Cambridge University Press, Cambridge, UK, 1999.
- [14] GIMPS, The Great Internet Mersenne Prime Search. http://www.mersenne.org/
- [15] S. W. Golomb, Shift Register Sequences, Aegean Park Press, revised edition, 1982.
- [16] J. R. Heringa, H. W. J. Blöte and A. Compagner, New primitive trinomials of Mersenne-exponent degrees for random-number generation, International J. of Modern Physics C 3 (1992), 561–564.
- [17] D. E. Knuth, The Art of Computer Programming, Volume 2: Seminumerical Algorithms, Addison-Wesley, Menlo Park, CA, third edition, 1998.
- [18] T. Kumada, H. Leeb, Y. Kurita and M. Matsumoto, New primitive -nomials , over whose degree is a Mersenne exponent, Math. Comp. 69 (2000), 811–814. Corrigenda: ibid 71 (2002), 1337–1338.
- [19] Y. Kurita and M. Matsumoto, Primitive -nomials over whose degree is a Mersenne exponent , Math. Comp. 56 (1991), 817–821.
- [20] R. Lidl and H. Niederreiter, Introduction to Finite Fields and their Applications, Cambridge Univ. Press, Cambridge, second edition, 1994.
- [21] A. J. Menezes, P. C. van Oorschot and S. A. Vanstone, Handbook of Applied Cryptography, CRC Press, Boca Raton, Florida, 1997. http://cacr.math.uwaterloo.ca/hac/
- [22] K. K. Norton, Numbers with small prime factors, and the least -th power nonresidue, Memoirs Amer. Math. Soc. 106 (1971), 1–106.
- [23] A.-E. Pellet, Sur la décomposition d’une fonction entière en facteurs irréductibles suivant un module premier , Comptes Rendus de l’Académie des Sciences Paris 86 (1878), 1071–1072.
- [24] L. Stickelberger, Über eine neue Eigenschaft der Diskriminanten algebraischer Zahlkörper, Verhandlungen des ersten Internationalen Mathematiker-Kongresses, Zürich, 1897, 182–193.
- [25] R. G. Swan, Factorization of polynomials over finite fields, Pacific J. Mathematics 12 (1962), 1099–1106.
- [26] J. Tromp, L. Zhang and Y. Zhao, Small weight bases for Hamming codes, Theoretical Computer Science 181(2), 1997, 337–345.
- [27] N. Zierler, Primitive trinomials whose degree is a Mersenne exponent, Information and Control 15 (1969), 67–69.