Prime Numbers
Prime Numbers Prime Numbers
3.6 Lucas pseudoprimes 145 Because of Exercise 3.26, it is convenient to rule out the polynomial x 2 − x + 1 when dealing with Lucas pseudoprimes. A similar problem occurs with x 2 + x + 1, and we rule out this polynomial, too. No other polynomials with nonsquare discriminants are ruled out, though. (Only x 2 ± x + 1 are monic, irreducible over the rationals, and have their roots also being roots of 1.) 3.6.2 Grantham’s Frobenius test The key role of the Frobenius automorphism (raising to the p-th power) in the Lucas test has been put in center stage in a new test of J. Grantham. It allows for an arbitrary polynomial in the place of x 2 − ax + b, but even in the case of quadratic polynomials, it is stronger than the Lucas test. One of the advantages of Grantham’s approach is that it cuts the tie to recurrent sequences. We describe below his test for quadratic polynomials. A little is said about the general test in Section 3.6.5. For more on Frobenius pseudoprimes see [Grantham 2001]. The argument that establishes Theorem 3.6.3 also establishes on the way (3.10) and (3.11). But Theorem 3.6.3 only extracts part of the information from these congruences. The Frobenius test maintains their full strength. Definition 3.6.5. Let a, b be integers with ∆ = a 2 −4b not a square. We say that a composite number n with gcd(n, 2b∆) = 1 is a Frobenius pseudoprime with respect to f(x) =x 2 − ax + b if x n ∆ a − x (mod (f(x),n)), if n = −1, ≡ x (mod (f(x),n)), if ∆ n =1. (3.12) At first glance it may seem that we are still throwing away half of (3.10) and (3.11), but we are not; see Exercise 3.27. It is easy to give a criterion for a Frobenius pseudoprime with respect to a quadratic polynomial, in terms of the Lucas sequences (Um), (Vm). Theorem 3.6.6. Let a, b be integers with ∆=a2 − 4b not a square and let n be a composite number with gcd(n, 2b∆) = 1. Then n is a Frobenius pseudoprime with respect to x2 − ax + b if and only if ∆ 2b, when U ∆ n−( n) ≡ 0(modn) and Vn−( ∆ n) ≡ Proof. Let f(x) =x 2 − ax + b. Weusetheidentity n = −1 2, when ∆ n =1. 2x m ≡ (2x − a)Um + Vm (mod (f(x),n)), which is self-evident from (3.8). Then the congruences in the theorem lead to xn+1 ≡ b (mod (f(x),n)) in the case ∆ n−1 n = −1 andx ≡ 1(mod(f(x),n)) in the case ∆ n n = 1. The latter case immediately gives x ≡ x (mod (f(x),n)),
146 Chapter 3 RECOGNIZING PRIMES AND COMPOSITES and the former, via x(a − x) ≡ b (mod (f(x),n)), leads to xn ≡ a − x (mod (f(x),n)). Thus, n is a Frobenius pseudoprime with respect to f(x). Now suppose n is a Frobenius pseudoprime with respect to f(x). Exercise 3.27 shows that n is a Lucas pseudoprime with respect to f(x), namely that U ∆ n−( ≡ 0(modn). Thus, from the identity above, 2xn−(∆n) ≡ n) V ∆ n−( n) (mod (f(x),n)). Suppose ∆ n+1 n = −1. Then x ≡ (a − x)x ≡ b (mod (f(x),n)), so that Vn+1 ≡ 2b (mod n). Finally, suppose ∆ n =1.Then since x is invertible modulo (f(x),n), we have xn−1 ≡ 1(mod(f(x),n)), which gives Vn−1 ≡ 2(modn). ✷ The first Frobenius pseudoprime n with respect to x2 − x − 1 is 4181 (the nineteenth Fibonacci number), and the first with 5 n = −1 is 5777. We thus see that not every Lucas pseudoprime is a Frobenius pseudoprime, that is, the Frobenius test is more stringent. In fact, the Frobenius pseudoprime test can be very effective. For example, for x2 +5x + 5 we don’t know any examples at all of a Frobenius pseudoprime n with 5 n = −1, though such numbers are conjectured to exist; see Exercise 3.42. 3.6.3 Implementing the Lucas and quadratic Frobenius tests It turns out that we can implement the Lucas test in about twice the time of an ordinary pseudoprime test, and we can implement the Frobenius test in about three times the time of an ordinary pseudoprime test. However, if we approach these tests naively, the running time is somewhat more than just claimed. To achieve the factors two and three mentioned, a little cleverness is required. As before, we let a, b be integers with ∆ = a 2 − 4b not a square, and we define the sequences (Uj), (Vj) as in (3.8). We first remark that it is easy to deal solely with the sequence (Vj). If we have Vm and Vm+1, wemay immediately recover Um via the identity Um =∆ −1 (2Vm+1 − aVm). (3.13) We next remark that it is easy to compute Vm for large m from earlier values using the following simple rule: If 0 ≤ j ≤ k, then Vj+k = VjVk − b j Vk−j. (3.14) Suppose now that b = 1. We record the formula (3.14) in the special cases k = j and k = j +1: V2j = V 2 j − 2, V2j+1 = VjVj+1 − a (in the case b =1). (3.15) Thus, if we have the residues Vj (mod n), Vj+1 (mod n), then we may compute, via (3.15), either the pair V2j (mod n), V2j+1 (mod n) or the pair V2j+1 (mod n), V2j+2 (mod n), with each choice taking 2 multiplications modulo n and an addition modulo n. Starting from V0,V1 we can recursively
- Page 108 and 109: 94 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
- Page 160 and 161: 3.6 Lucas pseudoprimes 147 use (3.1
- Page 162 and 163: 3.6 Lucas pseudoprimes 149 gcd(n, 2
- Page 164 and 165: 3.6 Lucas pseudoprimes 151 Theorem
- Page 166 and 167: 3.7 Counting primes 153 Label the c
- Page 168 and 169: 3.7 Counting primes 155 for b ≥ 2
- Page 170 and 171: 3.7 Counting primes 157 The heart o
- Page 172 and 173: 3.7 Counting primes 159 t =Im(s) ra
- Page 174 and 175: 3.7 Counting primes 161 Indeed, the
- Page 176 and 177: 3.8 Exercises 163 3.3. Prove that i
- Page 178 and 179: 3.8 Exercises 165 3.12. Show that a
- Page 180 and 181: 3.8 Exercises 167 3.28. Show that t
- Page 182 and 183: 3.9 Research problems 169 with W (n
- Page 184 and 185: 3.9 Research problems 171 3.50. The
- Page 186 and 187: 174 Chapter 4 PRIMALITY PROVING Rem
- Page 188 and 189: 176 Chapter 4 PRIMALITY PROVING sma
- Page 190 and 191: 178 Chapter 4 PRIMALITY PROVING Sin
- Page 192 and 193: 180 Chapter 4 PRIMALITY PROVING Let
- Page 194 and 195: 182 Chapter 4 PRIMALITY PROVING Rec
- Page 196 and 197: 184 Chapter 4 PRIMALITY PROVING (mo
- Page 198 and 199: 186 Chapter 4 PRIMALITY PROVING pol
- Page 200 and 201: 188 Chapter 4 PRIMALITY PROVING if
- Page 202 and 203: 190 Chapter 4 PRIMALITY PROVING 4.3
- Page 204 and 205: 192 Chapter 4 PRIMALITY PROVING j =
- Page 206 and 207: 194 Chapter 4 PRIMALITY PROVING The
146 Chapter 3 RECOGNIZING PRIMES AND COMPOSITES<br />
and the former, via x(a − x) ≡ b (mod (f(x),n)), leads to xn ≡ a − x<br />
(mod (f(x),n)). Thus, n is a Frobenius pseudoprime with respect to f(x).<br />
Now suppose n is a Frobenius pseudoprime with respect to f(x). Exercise<br />
3.27 shows that n is a Lucas pseudoprime with respect to f(x), namely<br />
that U ∆ n−( ≡ 0(modn). Thus, from the identity above, 2xn−(∆n)<br />
≡<br />
n)<br />
V ∆ n−( n) (mod (f(x),n)). Suppose <br />
∆<br />
n+1<br />
n = −1. Then x ≡ (a − x)x ≡ b<br />
(mod (f(x),n)), so that Vn+1 ≡ 2b (mod n). Finally, suppose <br />
∆<br />
n =1.Then<br />
since x is invertible modulo (f(x),n), we have xn−1 ≡ 1(mod(f(x),n)),<br />
which gives Vn−1 ≡ 2(modn). ✷<br />
The first Frobenius pseudoprime n with respect to x2 − x − 1 is 4181 (the<br />
nineteenth Fibonacci number), and the first with <br />
5<br />
n = −1 is 5777. We thus<br />
see that not every Lucas pseudoprime is a Frobenius pseudoprime, that is, the<br />
Frobenius test is more stringent. In fact, the Frobenius pseudoprime test can<br />
be very effective. For example, for x2 +5x + 5 we don’t know any examples<br />
at all of a Frobenius pseudoprime n with <br />
5<br />
n = −1, though such numbers are<br />
conjectured to exist; see Exercise 3.42.<br />
3.6.3 Implementing the Lucas and quadratic Frobenius tests<br />
It turns out that we can implement the Lucas test in about twice the time<br />
of an ordinary pseudoprime test, and we can implement the Frobenius test in<br />
about three times the time of an ordinary pseudoprime test. However, if we<br />
approach these tests naively, the running time is somewhat more than just<br />
claimed. To achieve the factors two and three mentioned, a little cleverness is<br />
required.<br />
As before, we let a, b be integers with ∆ = a 2 − 4b not a square, and<br />
we define the sequences (Uj), (Vj) as in (3.8). We first remark that it is<br />
easy to deal solely with the sequence (Vj). If we have Vm and Vm+1, wemay<br />
immediately recover Um via the identity<br />
Um =∆ −1 (2Vm+1 − aVm). (3.13)<br />
We next remark that it is easy to compute Vm for large m from earlier values<br />
using the following simple rule: If 0 ≤ j ≤ k, then<br />
Vj+k = VjVk − b j Vk−j. (3.14)<br />
Suppose now that b = 1. We record the formula (3.14) in the special cases<br />
k = j and k = j +1:<br />
V2j = V 2<br />
j − 2, V2j+1 = VjVj+1 − a (in the case b =1). (3.15)<br />
Thus, if we have the residues Vj (mod n), Vj+1 (mod n), then we may<br />
compute, via (3.15), either the pair V2j (mod n), V2j+1 (mod n) or the pair<br />
V2j+1 (mod n), V2j+2 (mod n), with each choice taking 2 multiplications<br />
modulo n and an addition modulo n. Starting from V0,V1 we can recursively