Math::Pari is great--I wish I understood more of it than the ~1% that currently I do :)--but it's not so good for primes. By default (AS PPM version), primes() only knows the first 41561 primes:

C:\test>p1 Perl> use Math::Pari qw[ prime primes nextprime precprime ];; Perl> print prime 41561;; 500257 Perl> print prime 41562;; PARI: *** not enough precalculated primes at (eval 7) line 1, <STDIN +> line 4.

It will generate larger primes using nextprime(), but it pretty slow, taking around 64 seconds to get to the 1 millionth:

Perl> print scalar localtime; $p = 500257; $p = nextprime ++$p for 41562 .. 1000000; print scalar localtime; print $p;; Tue Nov 14 04:36:02 2006 Tue Nov 14 04:37:07 2006 15485863

But the biggest problem is that it forgets all the bigger primes as soon as it has returned them (below is a continuation of the previous session):

Perl> print prime 41562;; PARI: *** not enough precalculated primes at (eval 9) line 1, <STDIN +> line 6.

From the error message I guess it might be possible to increase the number of precalculated primes if you manage to build it yourself? But if you Linux guys have trouble with it, you can guess my chances :)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^2: Math help: Finding Prime Numbers by BrowserUk
in thread Math help: Finding Prime Numbers by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.