Finding small primes (fast determanistic tests)

  • Thread starter CRGreathouse
  • Start date
  • Tags
    Primes
In summary, the conversation is about the search for efficient algorithms to test for prime numbers, specifically those representable as ints or longs less than 2^63. The individual asking for help is currently using a combination of the naive division algorithm and strong n-probable prime tests with bounds due to Jaeschke. They are looking for a faster method and have considered using elliptic curves, but have found them to be slow for small numbers. They have also looked into other resources such as MathWorld and Daniel Bernstein's survey of primality testing methods, but have not found a suitable solution. Suggestions such as asking Carl Pomerance and using PARI's deterministic tests have been made, but the individual is still looking for a faster method
  • #1
CRGreathouse
Science Advisor
Homework Helper
2,844
0
I'm looking for an algorithm or three to use in testing for prime numbers. I'm most concerned about those representable as ints or longs (that is, less than 2^63). In that range, what tests are efficient?

At the moment, I'm using a combination of:

* The naive division algorithm with a precomputed list of primes (the empyrically-derived cutoff is 5,500,000, checking primes up to 2341).
* Strong n-probable prime tests, plus bounds due to Jaeschke that turn this into a determanistic test. (2- and 3- SPrPs below 1,373,653 are prime; 2-, 3-, and 5- SPrPs below 25,326,001 are prime; 2-, 3-, 5- and 7- SPrPs below 118,670,087,467 are either 3,215,031,751 or prime; etc.)

The problem is that I don't know how to extend the latter test beyond 341,550,071,728,321 (testing all the primes up to 17), and I don't know if there's a faster method at some cutoff. Any help here?

Edit: Bleichenbacher has numbers that extend this test to 10^16, but I'd still like to go higher. Any thoughts?
 
Last edited:
Physics news on Phys.org
  • #2
about 25 years ago, Adelman, Pomerance and Rumely gave an enhancement of the fermat test to recognize primes, that got a lot of attention.

In the interim it has been further enhanced and there must be many of them out there. some more sophisticated using elliptic curves, have you searched on primality testing?
 
  • #4
I'm quite familiar with the MathWorld primality testing page; I've read it over many times, and finished my most recent read though just a few minutes before posting here. It didn't seem to address my issue, which is why I posted here.

I'm also familliar with APR, though I'm a little confused about implementing it. Regardless, it doesn't seem relevant here; Cohen and Lenstra 1987 mentions testing numbrs "up to 213 decimal digits", and surely with the thousandfold increase in computing power since, not to mention theoretical improvements, its reach is further. I'm looking to test small integers -- less than 20 decimal digits (in particular, odd integers less than 2^63).

The elliptic curve algorithms seem to take a long time for small numbers, relatively speaking. I'm looking for something that will be fast for these sizes.

Since testing numbers in this range could take as many as about [tex]\text{Ri}(\sqrt{2^{63}-1})\approx 146,144,918[/tex] primes with the naive division algorithm, I'm looking for a faster way. I've been told that a good implementation of the naive algorithm is best for small numbers; in my testing, 5 million is the practical limit when other algorithms take over.

At the moment I'm using the test mentioned in my first post; between that and the division test, it calculates the primes under 50 million in about 29 seconds (~48 billion cycles, including idles). This is just for testing; if I really wanted to find that, I'd look into the wheel sieve.
 
  • #5
In addition to
http://mathworld.wolfram.com/PrimalityTest.html
I would recommend Daniel Bernstein's
http://cr.yp.to/primetests.html
as a 'survey' of primality testing methods. I had hoped Chris Caldwell's page
http://primes.utm.edu/prove/prove2_3.html
would be relevant here, but it doesn't contain recent information (nothing since Jaeschke's 1993 paper). I also read these over carefully before posting, but saw no methods that struck me immediately as useful for my purpose (except the one I was already using).

I'd look at commercial or free math programs, but most of the ones I know use probable-prime methods internally rather than EXP, P or ZPP methods. PARI and Mathematica come to mind, for example.
 
Last edited:
  • #7
mathwonk said:
you might ask carl pomerance: he is a nice guy.

carl.pomerance@dartmouth.edu

That's... a great idea. Does he actually respond to mortals? I've sent him a quick note; I suppose I'll find out now.
 
  • #8
CRGreathouse said:
I'd look at commercial or free math programs, but most of the ones I know use probable-prime methods internally rather than EXP, P or ZPP methods. PARI and Mathematica come to mind, for example.

pari has deterministic tests, apcrl and Selfridge-Pocklington-Lehmer's p-1 test. (It has pseudoprime tests as well of course).
 
  • #9
The good news is that Pomerance responded (rather rapidly and quite politely); the bad news is that he doesn't know of any more recent work in the area. He recommended n-1 tests for small primes, so I guess I'll look into whatever's fast for smallish numbers. Any recommendations?

shmoe said:
pari has deterministic tests, apcrl and Selfridge-Pocklington-Lehmer's p-1 test. (It has pseudoprime tests as well of course).

Oh yes, I use PARI regularly. I meant in the basic isprime or equivilent. PARI's isprime uses Baillie-PSW by default, as I recall. There are a ton of methods it has built in, though, as you rightly mention.
 
  • #10
CRGreathouse said:
Oh yes, I use PARI regularly. I meant in the basic isprime or equivilent. PARI's isprime uses Baillie-PSW by default, as I recall. There are a ton of methods it has built in, though, as you rightly mention.

isprime runs the Baille-PSW test if it's guaranteed to work on the given input, which was something like up to 10^13 at the time of the last version, otherwise it uses spl or apcrl, whichever is appropriate (or you can force their use with flags in isprime).

In any case isprime only returns true for proven prime numbers (barring bugs of course).
 
  • #11
shmoe said:
isprime runs the Baille-PSW test if it's guaranteed to work on the given input, which was something like up to 10^13 at the time of the last version, otherwise it uses spl or apcrl, whichever is appropriate (or you can force their use with flags in isprime).

In any case isprime only returns true for proven prime numbers (barring bugs of course).

Ah, I was mistaken then. Still, it's not uncommon to use nondetermanistic/nonproven methods in such software, and PARI is no exception in general (though it is in this case): quadclassunit uses the GRH, and I think some of the bnf functons do too.
 
  • #12
pari does have an "ispseudoprime" function as well that's faster, but of course no guarantee you get a prime.
 

1. What is the significance of finding small primes?

Finding small primes is important in many areas of mathematics and computer science. They are used in cryptography, data encryption, and data compression algorithms. They also play a crucial role in number theory and serve as building blocks for larger prime numbers.

2. How are small primes typically found?

There are several methods for finding small primes, but the most commonly used one is through trial division. This involves dividing the number in question by all smaller numbers and checking for divisibility. Another method is the Sieve of Eratosthenes, which is more efficient for finding a large list of small primes.

3. What is a fast deterministic test for finding small primes?

The most popular fast deterministic test for finding small primes is the Miller-Rabin primality test. It is based on the Miller-Rabin theorem and uses modular exponentiation to test if a number is prime. This test is more efficient than trial division and has a very low error rate.

4. How accurate is the Miller-Rabin primality test?

The Miller-Rabin primality test is considered to be highly accurate. It has been proven to correctly identify prime numbers up to 2^64, which is a very large number. However, as with any algorithm, there is always a small chance of error, but the probability of this happening is extremely low.

5. Are there any other tests for finding small primes?

Yes, there are other tests for finding small primes, such as the Lucas-Lehmer test and the Solovay-Strassen test. However, these tests are not as widely used as the Miller-Rabin test due to their limitations and lower efficiency. The Miller-Rabin test remains the most popular and reliable method for finding small primes.

Similar threads

  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Linear and Abstract Algebra
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
739
  • Linear and Abstract Algebra
Replies
11
Views
2K
  • Linear and Abstract Algebra
Replies
8
Views
4K
  • Linear and Abstract Algebra
Replies
2
Views
2K
  • Linear and Abstract Algebra
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
Replies
10
Views
7K
Back
Top