in reply to redmist's Diabolical Scheme for Prime Domination

Any "modern, efficient" method of finding primes is very advanced math intensive. Applied Cryptography has a good section of prime factoring and determining if a number is likely prime. Public key encryption systems based on large prime numbers (RSA) don't actually factor the large prime numbers. They generate numbers using a technique that ensures that they are probably prime. This is a great shortcut, but won't work for claiming a mathematical record like you are proposing as the number is only probably prime (extremely high certainty that it is prime, but still not %100 guaranteed).

There are many simple prime number algorightms around, unfortunately the simple ones aren't efficient. The Sieve of Erastothenes is a classic example. I do not know of any perl modules that explicitly implement prime number type functionality. Below is a simple and extermely inefficient is_prime function.

sub is_prime{ my $n=shift; return 0 if($n != int($n)); my $m=sqrt($n); for(my $c=2;$c<=$m;$c++){ return 0 if($n/$c == int($n/$c)); } return 1; }

Any way you slice it, I don't think Perl is the best language for a high performance prime number analyzer. Your best bet would be to find a language designed explicitly for doing large number math if you seriously want to go after a "largest prime number" record.

Replies are listed 'Best First'.
RE: Re: redmist's Diabolical Scheme for Prime Domination
by redmist (Deacon) on Aug 02, 2000 at 16:49 UTC
    Thanks lhoward. I looked at the web page that you recommended and it helped me some with my thought on how I am going to approach the math in this project. As for your suggestion to use another, more mathematically inclined language, it's not an issue for me because this project is to learn Perl (and stick it to the man).

    redmist
    redmist.dyndns.org
    redmist@users.sourceforge.net
RE: Re: redmist's Diabolical Scheme for Prime Domination
by BlaisePascal (Monk) on Aug 02, 2000 at 18:17 UTC
    Here's my attempt at a Sieve of Eratothenes... I don't use grep that much, so I won't claim that this works...
    @numbers = (2 .. 1_000_000); @primes = ( ); while (my $prime = shift @numbers) { push @primes,$prime; @numbers = grep { ($_ % $prime) != 0 } @numbers; } print $primes;