The Lehmann primality test.
davidkendal.net
davidkendal.net
For any value 0 < a < n, a^((n-1)/2) = (a^6)^144 = 1^144 = 1 mod 7.
For any value 0 < a < n, a^((n-1)/2) = (a^12)^72 = 1^72 = 1 mod 13.
For any value 0 < a < n, a^((n-1)/2) = (a^18)^48 = 1^48 = 1 mod 19.
Thus 1729 will pass the Lehmann test for all a. (Unsurprisingly 1729 is a Carmichael number; not all Carmichael numbers will pass all Lehmann tests, but any number which passes all Lehmann tests will be Carmichael.)
I'm pretty sure that the Alford-Granville-Pomerance proof of n^(2/7) Carmichael numbers can be extended to give the same order result for "Lehmann-Carmichael" numbers, but I'm not going to do it at 5:30 AM when I'm struggling with a 102F fever.
However, running it with k=50 gave a random set of them each time. So perhaps the probability data I gave was not right.
EDIT: And of course I forgot about non-relatively-prime values. But those are asymptotically sparse; you're seeing a random set of pseudoprimes for k=50 because with that many trials you have a good chance of catching small primes, but for larger Carmichael numbers you'll need a very large number of trials to get good odds.
(a^6)^144 = (0^6)^144 = 0 mod 7.
We can confirm this (using python):
>>> (7864)%1729
742L
Still, the density of values not relatively prime to a Carmichael number is asymptotically zero, so the test is still broken.
742
Pick a = 1722.
a^[(n-1)÷2] mod n = 742
Therefore 1729 is composite.
The test seems to hold, here.
The Solovay–Strassen and Miller–Rabin tests, which are fast and accurate, but not easy to implement: the former requires understanding the Legendre and Jacobi symbols (arcane mathematical concepts) and the latter requires an efficient factorisation algorithm.
Its very frustrating how often this comes up: an answer is well known but "hard to implement". The answer here should have clearly been "so then I used Solovay–Strassen and Miller–Rabin". You'd think there would be SOME sample code out there or that translating the math wouldn't be too difficult, yet I often run into this problem myself. The divide between mathematical notation, or perhaps the "language of CS papers" and actual code is distressing.I've stuck a very simple version (in C#) here - https://github.com/elemeno/SimpleMillerRabin/blob/master/Sim...
When the author was talking about the "Project Triangle" in the context of primality testing, I thought he was going to bring up AKS!
What could I or others do about this problem?
IIRC numbers under 341,550,071,728,321 could be accurately tested for primality on the "instant" timescale.
See the repo on github: https://github.com/rkneufeld/mr_prime/blob/master/lib/mr_pri...
The documentation and download links for Plan at http://plan.dpk.org.uk seem to be broken so i'm not sure if this has bigints.
It should have bigints, though.
I'm sorry, but WHAT?
Writing the dumbest implementation of trial-division that I could, in C++ on my laptop, in Debug mode, took 0.0247046 ms to determine definitively if 27,644,437 is prime.
My dumbest-possible implementation, in Debug mode, is 48.5 times faster, and doesn't get confused by Carmichael numbers.
Move along, folks, nothing to see here.
"The trial-division method... gets slow quickly."
That may be true, but using the number 27,644,437 as a benchmark will not get you anywhere near that "slow" point.
I unfortunately can't share all of the code, because of the timer code I used.
The author is a bit confused. Miller-Rabin, when testing n, only requires factoring to the extent of determining the largest power of 2 that divides n-1. In other words, you have to have factor n-1 into the form 2^s d, where d is odd. This is trivial to do efficiently.
http://rosettacode.org/wiki/Arbitrary-precision_integers_%28...
This assertion is false if I understood the test correctly.
Take n = 5, a = 2.
a ^ ((n - 1) / 2) = 2 ^ ((5 - 1) / 2) = 2 ^ 2 = 4 and 4 mod 5 = 4.
Therefore the test will say 5 is composite.