Prime Numbers
Prime Numbers Prime Numbers
94 Chapter 2 NUMBER-THEORETICAL TOOLS we saw above, we can “create” the finite field Fpk by coming up with an irreducible polynomial f(x) inFp[x] ofdegreek. Wethussayalittleabout how one might do this. Every element a in Fpk has the property that apk = a, thatis,ais a root of xpk − x. In fact this polynomial splits into linear factors over Fpk with no repeated factors. We can use this idea to see that xpk − x is the product of all monic irreducible polynomials in Fp[x] of degrees dividing k. Fromthiswe get a formula for the number Nk(p) of monic irreducible polynomials in Fp[x] of exact degree k: One begins with the identity dNd(p) =p k , d|k on which we can use Möbius inversion to get Nk(p) = 1 k p d µ(k/d). (2.5) d|k Here, µ is the Möbius function discussed in Section 1.4.1. It is easy to see that the last sum is dominated by the term d = k, sothatNk(p) is approximately p k /k. That is, about 1 out of every k monic polynomials of degree k in Fp[x] is irreducible. Thus a random search for one of these should be successful in O(k) trials. But how can we recognize an irreducible polynomial? An answer is afforded by the following result. Theorem 2.2.8. Suppose that f(x) is a polynomial in Fp[x] of positive degree k. The following statements are equivalent: (1) f(x) is irreducible; (2) gcd(f(x),xpj − x) =1for each j =1, 2,...,⌊k/2⌋; (3) xpk ≡ x (mod f(x)) and gcd(f(x),xpk/q − x) =1for each prime q|k. This theorem, whose proof is left as Exercise 2.15, is then what is behind the following two irreducibility tests. Algorithm 2.2.9 (Irreducibility test 1). Given prime p and a polynomial f(x) ∈ Fp[x] of degree k ≥ 2, this algorithm determines whether f(x) is irreducible over Fp. 1. [Initialize] g(x) =x; 2. [Testing loop] for(1 ≤ i ≤⌊k/2⌋) { g(x) =g(x) p mod f(x); // Powering by Algorithm 2.1.5. d(x) =gcd(f(x),g(x) − x); // Polynomial gcd by Algorithm 2.2.1. if(d(x) = 1) return NO; } return YES; // f is irreducible.
2.2 Polynomial arithmetic 95 Algorithm 2.2.10 (Irreducibility test 2). Given a prime p, a polynomial f(x) ∈ Fp[x] of degree k ≥ 2, and the distinct primes q1 >q2 >...>ql which divide k, this algorithm determines whether f(x) is irreducible over Fp. 1. [Initialize] ql+1 =1; g(x) =x pk/q 1 mod f(x); // Powering by Algorithm 2.1.5. 2. [Testing loop] for(1 ≤ i ≤ l) { d(x) =gcd(f(x),g(x) − x); if(d(x) = 1) return NO; // Polynomial gcd by Algorithm 2.2.1. g(x) =g(x) pk/qi+1 −p k/qi mod f(x); // Powering by Algorithm 2.1.5. } 3. [Final congruence] if(g(x) = x) return NO; return YES; // f is irreducible. Using the naive arithmetic subroutines of this chapter, Algorithm 2.2.9 is slower than Algorithm 2.2.10 for large values of k, given the much larger number of gcd’s which must be computed in the former algorithm. However, using a more sophisticated method for polynomial gcd’s, (see [von zur Gathen and Gerhard 1999, Sec. 11.1]), the two methods are roughly comparable in time. Let us now recapitulate the manner of field computations. Armed with a suitable irreducible polynomial f of degree k over Fp, one represents any element a ∈ F p k as a = a0 + a1x + a2x 2 + ···+ ak−1x k−1 , with each ai ∈{0,...,p− 1}. That is, we represent a as a vector in F k p . Note that there are clearly p k such vectors. Addition is ordinary vector addition, but of course the arithmetic in each coordinate is modulo p. Multiplication is more complicated: We view it merely as multiplication of polynomials, but not only is the coordinate arithmetic modulo p, but we also reduce highdegree polynomials modulo f(x). That is to say, to multiply a ∗ b in F p k,we simply form a polynomial product a(x)b(x),doingamodp reduction when a coefficient during this process exceeds p−1, then taking this product mod f(x) via polynomial mod, again reducing mod p whenever appropriate during that process. In principle, one could just form the unrestricted product a(x)b(x), doamodf reduction, then take a final mod p reduction, in which case the final result would be the same but the interior integer multiplies might run out of control, especially if there were many polynomials being multiplied. It is best to take a reduction modulo p at every meaningful juncture. Here is an example for explicit construction of a field of characteristic 2, namely F16. According to our formula (2.5), there are exactly 3 irreducible degree-4 polynomials in F2[x], and a quick check shows that they are x 4 +x+1, x 4 + x 3 +1,andx 4 + x 3 + x 2 + x +1.Thougheachofthesecanbeusedto
- Page 58 and 59: 44 Chapter 1 PRIMES! sums. These su
- Page 60 and 61: 46 Chapter 1 PRIMES! Vinogradov’s
- Page 62 and 63: 48 Chapter 1 PRIMES! been beyond re
- Page 64 and 65: 50 Chapter 1 PRIMES! prime? What is
- Page 66 and 67: 52 Chapter 1 PRIMES! This kind of c
- Page 68 and 69: 54 Chapter 1 PRIMES! where p runs o
- Page 70 and 71: 56 Chapter 1 PRIMES! While the prim
- Page 72 and 73: 58 Chapter 1 PRIMES! Exercise 1.35.
- Page 74 and 75: 60 Chapter 1 PRIMES! this recreatio
- Page 76 and 77: 62 Chapter 1 PRIMES! so that A3(x)
- Page 78 and 79: 64 Chapter 1 PRIMES! Conclude that
- Page 80 and 81: 66 Chapter 1 PRIMES! implies that
- Page 82 and 83: 68 Chapter 1 PRIMES! the Riemann-Si
- Page 84 and 85: 70 Chapter 1 PRIMES! such sums can
- Page 86 and 87: 72 Chapter 1 PRIMES! Cast this sing
- Page 88 and 89: 74 Chapter 1 PRIMES! 10 10 . The me
- Page 90 and 91: 76 Chapter 1 PRIMES! These numbers
- Page 92 and 93: 78 Chapter 1 PRIMES! Next, as for q
- Page 94 and 95: 80 Chapter 1 PRIMES! (see [Bach 199
- Page 96 and 97: 82 Chapter 1 PRIMES! If one invokes
- Page 98 and 99: 84 Chapter 2 NUMBER-THEORETICAL TOO
- Page 100 and 101: 86 Chapter 2 NUMBER-THEORETICAL TOO
- Page 102 and 103: 88 Chapter 2 NUMBER-THEORETICAL TOO
- Page 104 and 105: 90 Chapter 2 NUMBER-THEORETICAL TOO
- Page 106 and 107: 92 Chapter 2 NUMBER-THEORETICAL TOO
- Page 110 and 111: 96 Chapter 2 NUMBER-THEORETICAL TOO
- Page 112 and 113: 98 Chapter 2 NUMBER-THEORETICAL TOO
- Page 114 and 115: 100 Chapter 2 NUMBER-THEORETICAL TO
- Page 116 and 117: 102 Chapter 2 NUMBER-THEORETICAL TO
- Page 118 and 119: 104 Chapter 2 NUMBER-THEORETICAL TO
- Page 120 and 121: 106 Chapter 2 NUMBER-THEORETICAL TO
- Page 122 and 123: 108 Chapter 2 NUMBER-THEORETICAL TO
- Page 124 and 125: 110 Chapter 2 NUMBER-THEORETICAL TO
- Page 126 and 127: 112 Chapter 2 NUMBER-THEORETICAL TO
- Page 128 and 129: 114 Chapter 2 NUMBER-THEORETICAL TO
- Page 130 and 131: Chapter 3 RECOGNIZING PRIMES AND CO
- Page 132 and 133: 3.1 Trial division 119 d =3; while(
- Page 134 and 135: 3.2 Sieving 121 3.2 Sieving Sieving
- Page 136 and 137: 3.2 Sieving 123 this number’s ent
- Page 138 and 139: 3.2 Sieving 125 noticed that it was
- Page 140 and 141: 3.2 Sieving 127 } S = S \ (pS ∩ [
- Page 142 and 143: 3.3 Recognizing smooth numbers 129
- Page 144 and 145: 3.4 Pseudoprimes 131 } g =gcd(s, x)
- Page 146 and 147: 3.4 Pseudoprimes 133 Theorem 3.4.4.
- Page 148 and 149: 3.5 Probable primes and witnesses 1
- Page 150 and 151: 3.5 Probable primes and witnesses 1
- Page 152 and 153: 3.5 Probable primes and witnesses 1
- Page 154 and 155: 3.5 Probable primes and witnesses 1
- Page 156 and 157: 3.6 Lucas pseudoprimes 143 The Fibo
2.2 Polynomial arithmetic 95<br />
Algorithm 2.2.10 (Irreducibility test 2). Given a prime p, a polynomial<br />
f(x) ∈ Fp[x] of degree k ≥ 2, and the distinct primes q1 >q2 >...>ql<br />
which divide k, this algorithm determines whether f(x) is irreducible over Fp.<br />
1. [Initialize]<br />
ql+1 =1;<br />
g(x) =x pk/q 1<br />
mod f(x); // Powering by Algorithm 2.1.5.<br />
2. [Testing loop]<br />
for(1 ≤ i ≤ l) {<br />
d(x) =gcd(f(x),g(x) − x);<br />
if(d(x) = 1) return NO;<br />
// Polynomial gcd by Algorithm 2.2.1.<br />
g(x) =g(x) pk/qi+1 −p k/qi mod f(x); // Powering by Algorithm 2.1.5.<br />
}<br />
3. [Final congruence]<br />
if(g(x) = x) return NO;<br />
return YES; // f is irreducible.<br />
Using the naive arithmetic subroutines of this chapter, Algorithm 2.2.9<br />
is slower than Algorithm 2.2.10 for large values of k, given the much larger<br />
number of gcd’s which must be computed in the former algorithm. However,<br />
using a more sophisticated method for polynomial gcd’s, (see [von zur Gathen<br />
and Gerhard 1999, Sec. 11.1]), the two methods are roughly comparable in<br />
time.<br />
Let us now recapitulate the manner of field computations. Armed with<br />
a suitable irreducible polynomial f of degree k over Fp, one represents any<br />
element a ∈ F p k as<br />
a = a0 + a1x + a2x 2 + ···+ ak−1x k−1 ,<br />
with each ai ∈{0,...,p− 1}. That is, we represent a as a vector in F k p . Note<br />
that there are clearly p k such vectors. Addition is ordinary vector addition,<br />
but of course the arithmetic in each coordinate is modulo p. Multiplication<br />
is more complicated: We view it merely as multiplication of polynomials, but<br />
not only is the coordinate arithmetic modulo p, but we also reduce highdegree<br />
polynomials modulo f(x). That is to say, to multiply a ∗ b in F p k,we<br />
simply form a polynomial product a(x)b(x),doingamodp reduction when a<br />
coefficient during this process exceeds p−1, then taking this product mod f(x)<br />
via polynomial mod, again reducing mod p whenever appropriate during that<br />
process. In principle, one could just form the unrestricted product a(x)b(x),<br />
doamodf reduction, then take a final mod p reduction, in which case the<br />
final result would be the same but the interior integer multiplies might run<br />
out of control, especially if there were many polynomials being multiplied. It<br />
is best to take a reduction modulo p at every meaningful juncture.<br />
Here is an example for explicit construction of a field of characteristic 2,<br />
namely F16. According to our formula (2.5), there are exactly 3 irreducible<br />
degree-4 polynomials in F2[x], and a quick check shows that they are x 4 +x+1,<br />
x 4 + x 3 +1,andx 4 + x 3 + x 2 + x +1.Thougheachofthesecanbeusedto