I would like to detect prime numbers within an interval $\mathcal{I}:[a,b]$. The only problem is that the interval contains very large numbers - in excess of 10000 digits each and $\# \mathcal{I}$ is also very large.
One of my tasks involves answering the following question:
"Given a positive integer $i\in\mathcal I$, is $i$ prime?"
Testing for primality using PrimeQ[] takes far too long for this many large numbers. So, I thought about first gathering a list of probable primes, before engaging in any rigorous prime-proving process.
So basically what I'm asking is whether there exists a function like ProbablePrimeQ[] that can return very fast and give a first indication whether the input is prime. Does such a function exist in Mathematica?
PrimeQis already the fast probabilistic primality test. It combines small prime testing, Miller-Rabin testing in base 2 & 3 and a Lucas Test. This procedure is known to produce no false positive for $<2^{64}$. Mathematica features a provable prime testProvablePrimeQ(in the primality proving package<<PrimalityProving) which is much slower thanPrimeQ. If you need to generate a list of good candidates, just do your own small prime tests beforehand with the first few thousand primes or so. This should be reasonable fast. – Julien Kluge Jan 11 '23 at 11:31TableForm @ Map[ AbsoluteTiming[PrimeQ[#]]& , (Round[Pi*10^11111, 2] + 1 + 2*Range[25] ) ]– rhermans Jan 11 '23 at 12:03PrimeQ[], and assuming I have to check $10^9$ numbers in the interval, I would require 142 years to complete the task. If I go through $10^{10}$ numbers, then that changes to 1425 years. I don't think I can wait that long. – Klangen Jan 11 '23 at 12:29ProvablePrimeQis slower thanPrimeQ. Unless you present a more constrained case with a clever idea to be implemented, this is as far one can go with your general question. – rhermans Jan 11 '23 at 13:51PrimeQ, when assessing numbers that are in fact prime, is the use of the Lucas test. So you might just implement Miller-Rabin for a couple of bases. But there might then be a handful of composites that are claimed as prime. – Daniel Lichtblau Jan 11 '23 at 17:16