n_is_prime_pocklington
#include <flint/ulong_extras.h>Pocklington–Lehmer test [Poc1914; BLS1975]. Returns 1 if n is proved prime, 0 if it is composite, and -1 if nothing was proved because the bases 2, \ldots, \mathit{iterations} - 1 were not enough. If \mathit{iterations} is 0 or 1, the number of bases is not limited and -1 is never returned for this reason.
Most of the time goes into factoring n - 1 with n_factor_partial (trial division, then Hart's one-line algorithm [Har2012] or SQUFOF), which stops once the factored part F of n - 1 is at least (n - 1)^{1/3}. If F \le \sqrt n, the cube root criterion of Brillhart, Lehmer and Selfridge is applied in addition. Then, for each prime q dividing F, n_is_prime_pocklington tries the bases a = 2, 3, \ldots, \mathit{iterations} - 1 until a^{(n-1)/q} \ne 1, returning 0 if some a^{n-1} \not\equiv 1 \pmod n and -1 if no base works. Finally it checks that n is coprime to the product of the values a^{(n-1)/q} - 1. In most cases a larger number of iterations hardly affects the running time.
References#
- [Poc1914] H. C. Pocklington, "The determination of the prime or composite nature of large numbers by Fermat's theorem", Proceedings of the Cambridge Philosophical Society 18 (1914), 29–30
- [BLS1975] J. Brillhart, D. H. Lehmer and J. L. Selfridge, "New primality criteria and factorizations of 2^m ± 1", Mathematics of Computation 29 (1975), 620–647
- [Har2012] Hart, William B.. (2012) A one line factoring algorithm. Journal of the Australian Mathematical Society, Volume 92 (Number 1). pp. 61-69.
The FLINT team, “n_is_prime_pocklington (ulong_extras.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/ulong_extras/n_is_prime_pocklington.html (generated 2026-10-20).
@misc{flint-doc-ulong-extras-n-is-prime-pocklington,
author = {{The FLINT team}},
title = {{n\_is\_prime\_pocklington (ulong\_extras.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/ulong_extras/n_is_prime_pocklington.html},
note = {Generated 2026-10-20}
}