Primality: Baillie-PSW
17 Dec 2021
§ Motivation
We didn't cover this in our MATH-470 course, but I was reading the source code for the GNU MP library and saw that mpz_probab_prime_p()
uses Baillie-PSW[1] on top of Miller-Rabin when checking if is a probable prime; so, I decided to learn more about it.
We've previously looked at the Miller-Rabin primality test which is a Fermat test, however, there exists strong pseudoprimes that pass Fermat tests against many bases; e.g. there exists a Carmichael number that is a strong pseudoprime to all prime bases less than 307[2]. The BPSW algorithm uses a Lucas probable prime test on top of a Fermat prime test. There are few overlapping pseudoprimes between the Lucas and Fermat tests, making BPSW less likely to fail.
§ Legendre and Jacobi Symbols
Legendre Symbol
Given an integer and odd prime , the Legendre symbol is written as , and is defined by
Jacobi Symbol
Given an integer and odd positive integer , the Jacobi symbol is written as , it is defined by the product of Legendre symbols,
where .
Properties of the Jacobi:
- Let .
- If is an odd prime, then the Jacobi is equivalent to the Legendre.
- If , then .
- .
- .
- .
- .
- .
- .
- .
- .
Properties common between the Jacobi and Legendre:
- If then is a quadratic non-residue modulo .
- If is a quadratic residue modulo , and , then .
As we will find out later, factorization is problem that lies in as such we conjecture that there is no efficient (classical polynomial-time) algorithm to compute a non-trivial number's factorization. As such, relying on the formal definition of the Jacobi is impractical to do when testing very large integers for primality. Utilizing the properties of the Jacobi, we can compute the Jacobi in time, as opposed to at best sub-exponential time using factorization.
§ The (Strong) Baillie-PSW Primality Test
Baillie-PSW
Suppose we want to determine if an odd positive integer is prime.
- Perform a base 2 strong probable prime test.
- If is not a strong probable prime base 2, stop; is composite.
- This is effectively a Miller-Rabin test with base 2.
- Find the first in the sequence for which the Jacobi symbol is . Set .
- Perform a strong Lucas probable prime test on using parameters . If is not a strong Lucas probable prime, stop; is composite.
- If the algorithm has not terminated, then is a probable prime.
Number Theoretic Functions, GNU MP Library Manual. ↩︎
Arnault, François. “Constructing Carmichael Numbers Which Are Strong Pseudoprimes to Several Bases.” Journal of Symbolic Computation, vol. 20, no. 2, 1995, pp. 151–161., https://doi.org/10.1006/jsco.1995.1042. ↩︎