Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Lucas pseudoprime
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Implementing a Lucas probable prime test== Before embarking on a probable prime test, one usually verifies that ''n'', the number to be tested for primality, is odd, is not a perfect square, and is not divisible by any small prime less than some convenient limit. Perfect squares are easy to detect using [[Newton's method]] for square roots. We choose a Lucas sequence where the Jacobi symbol <math>\left(\tfrac{D}{n}\right)=-1</math>, so that δ(''n'') = ''n'' + 1. Given ''n'', one technique for choosing ''D'' is to use trial and error to find the first ''D'' in the sequence 5, −7, 9, −11, ... such that <math>\left(\tfrac{D}{n}\right)=-1</math>. Note that <math>\left(\tfrac{k}{n}\right)\left(\tfrac{-k}{n}\right)=-1</math>. (If ''D'' and ''n'' have a prime factor in common, then <math>\left(\tfrac{D}{n}\right)=0.</math>). With this sequence of ''D'' values, the average number of ''D'' values that must be tried before we encounter one whose Jacobi symbol is −1 is about 1.79.{{r|lpsp|p=1416}} Once we have ''D'', we set <math>P=1</math> and <math>Q=(1-D)/4</math>. It is a good idea to check that ''n'' has no prime factors in common with ''P'' or ''Q''. This method of choosing ''D'', ''P'', and ''Q'' was suggested by [[John Selfridge]]. (This search will never succeed if ''n'' is square, and conversely if it does succeed, that is proof that ''n'' is not square. Thus, some time can be saved by delaying testing ''n'' for squareness until after the first few search steps have all failed.) Given ''D'', ''P'', and ''Q'', there are recurrence relations that enable us to quickly compute <math>U_{n+1}</math> and <math>V_{n+1}</math> in <math>O(\log_2 n)</math> steps; see {{slink|Lucas sequence|Other relations}}. To start off, :<math>U_1=1</math> :<math>V_1=P</math> :<math>Q^1=Q</math> First, we can double the subscript from <math>k</math> to <math>2k</math> in one step using the recurrence relations :<math>U_{2k}=U_k\cdot V_k,</math> :<math>V_{2k}=V_k^2-2Q^k=\frac{V_k^2+DU_k^2}{2},</math> :<math>Q^{2k}=(Q^k)^2.</math> Next, we can increase the subscript by 1 using the recurrences :<math>U_{2k+1}=(P\cdot U_{2k}+V_{2k})/2,</math> :<math>V_{2k+1}=(D\cdot U_{2k}+P\cdot V_{2k})/2,</math> :<math>Q^{2k+1}=Q\cdot Q^{2k}.</math> At each stage, we reduce all of the variables modulo ''n''. When dividing by 2 [[modular arithmetic|modulo]] ''n'', if the numerator is odd add ''n'' (which does not change the value modulo ''n'') to make it even before dividing by 2.' We use the bits of the binary expansion of ''n'' to determine ''which'' terms in the sequence to compute. For example, if ''n''+1 = 44 (= 101100 in binary), then, taking the bits one at a time from left to right, we obtain the sequence of indices to compute: 1<sub>2</sub> = 1, 10<sub>2</sub> = 2, 100<sub>2</sub> = 4, 101<sub>2</sub> = 5, 1010<sub>2</sub> = 10, 1011<sub>2</sub> = 11, 10110<sub>2</sub> = 22, 101100<sub>2</sub> = 44. Therefore, we compute ''U''<sub>1</sub>, ''U''<sub>2</sub>, ''U''<sub>4</sub>, ''U''<sub>5</sub>, ''U''<sub>10</sub>, ''U''<sub>11</sub>, ''U''<sub>22</sub>, and ''U''<sub>44</sub>. We also compute the same-numbered terms in the ''V'' sequence, along with ''Q''<sup>1</sup>, ''Q''<sup>2</sup>, ''Q''<sup>4</sup>, ''Q''<sup>5</sup>, ''Q''<sup>10</sup>, ''Q''<sup>11</sup>, ''Q''<sup>22</sup>, and ''Q''<sup>44</sup>. By the end of the calculation, we will have computed ''U<sub>n+1</sub>'', ''V<sub>n+1</sub>'', and ''Q<sup>n+1</sup>'', (mod ''n''). We then check congruence ({{EquationNote|2}}) using our expected value of ''U<sub>n+1</sub>''. When the parameters ''D'', ''P'', and ''Q'' are chosen as described above, the first 10 Lucas pseudoprimes are:{{r|lpsp|p=1401}} 323, 377, 1159, 1829, 3827, 5459, 5777, 9071, 9179, and 10877 {{OEIS|id=A217120}} The '''strong''' versions of the Lucas test can be implemented in a similar way. With the same parameters, the first 10 ''strong'' Lucas pseudoprimes are: 5459, 5777, 10877, 16109, 18971, 22499, 24569, 25199, 40309, and 58519 {{OEIS|id=A217255}} ''Extra strong'' Lucas pseudoprimes use different parameters: fix <math>Q = 1</math>. Then try ''P'' = 3, 4, 5, 6, ..., until a value of <math>D=P^2-4Q</math> is found so that the Jacobi symbol <math>\left(\tfrac{D}{n}\right)=-1</math>. The first 10 ''extra strong'' Lucas pseudoprimes are 989, 3239, 5777, 10877, 27971, 29681, 30739, 31631, 39059, and 72389 {{OEIS|id=A217719}} ===Checking additional congruence conditions=== If we have checked that congruence ({{EquationNote|2}}) is true, there are additional congruence conditions we can check that have almost no additional computational cost. By providing an additional opportunity for ''n'' to be proved composite, these increase the reliability of the test. If ''n'' is an odd prime and <math>\left(\tfrac{D}{n}\right)=-1</math>, then we have the following:{{r|lpsp|p=1392 Eq. 2}} {{NumBlk|:|<math>V_{n+1} \equiv 2 Q \pmod n.</math>|{{EquationRef|3}}}} Although this congruence condition is not part of the Lucas probable prime test proper, it is almost free to check this condition because, as noted above, the easiest way to compute ''U''<sub>''n''+1</sub> is to compute ''V''<sub>''n''+1</sub> as well. If Selfridge's method (above) for choosing parameters is modified so that, if it selects ''D'' = 5, it uses the parameters ''P'' = ''Q'' = 5 rather than ''P'' = 1, ''Q'' = −1, then 913 = 11·83 is the ''only'' composite less than 10<sup>8</sup> for which congruence ({{EquationNote|3}}) is true (see page 1409 and Table 6 of;<ref name="lpsp"/>). More extensive calculations show that, with this method of choosing ''D'', ''P'', and ''Q'', there are only five odd, composite numbers less than 10<sup>15</sup> for which congruence ({{EquationNote|3}}) is true.<ref name=bpsw2>{{cite journal |first1=Robert |last1=Baillie |first2=Andrew |last2=Fiori |first3=Samuel S. Jr. |last3=Wagstaff |author-link3=Samuel S. Wagstaff, Jr. |title=Strengthening the Baillie-PSW Primality Test |journal=Mathematics of Computation |date=July 2021 |volume=90 |issue=330 |pages=1931–1955 |doi=10.1090/mcom/3616 |arxiv=2006.14425 |s2cid=220055722 }}</ref> If <math>Q \neq \pm 1 </math> (and GCD(''n'', ''Q'') = 1), then an [[Euler–Jacobi probable prime]] test to the base Q can also be implemented at minor computational cost. The computation of <math>V_{n+1}</math> depends on <math>V_{(n+1)/2}</math> and <math>Q^{(n+1)/2}</math>. This is <math>Q</math> times <math>Q^{(n-1)/2}</math>, and if ''n'' is prime, then by [[Euler's criterion]], :<math> Q^{(n-1)/2} \equiv \left(\tfrac{Q}{n}\right) \pmod {n} </math> . (Here, <math>\left(\tfrac{Q}{n}\right)</math> is the [[Legendre symbol]]; if ''n'' is prime, this is the same as the Jacobi symbol). Therefore, if ''n'' is prime, we must have, {{NumBlk|:|<math>Q^{(n+1)/2} \equiv Q \cdot Q^{(n-1)/2} \equiv Q \cdot \left(\tfrac{Q}{n}\right) \pmod n.</math>|{{EquationRef|4}}}} The Jacobi symbol on the right side is easy to compute, so this congruence is easy to check. If this congruence does not hold, then ''n'' cannot be prime. Provided GCD(''n, Q'') = 1 then testing for congruence ({{EquationNote|4}}) is equivalent to augmenting our Lucas test with a "base Q" [[Solovay–Strassen primality test]]. There is one more<!--There are two conditions, equations (3) and (4) from the paper, but if the V_{n+1} condition (2) is true, then they are equivalent.--> congruence condition on <math>U_n</math> and <math>V_n</math> which must be true if ''n'' is prime and can be checked.{{r|lpsp|p=§2,6}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)