How does Mathematica calculate the nth prime?

4

1

When I enter Prime[2000000000000], the two-trillionth prime, Mathematica gives 61427839512211 for the answer after several minutes of calculation.

I wonder how it calculates to get this number. Apparently, it does not pull that number out from a list, since it spends several minutes to get the answer.

TCL

Posted 2013-05-24T15:43:49.210

Reputation: 149

1

Related: What is so special about Prime? Another possibly interesting Why does iterating Prime in reverse order require much more time?

– Artes – 2013-05-24T15:51:53.907

Answers

6

From Some Notes On Internal Implementation:

Prime and PrimePi use sparse caching and sieving. For large $n$, the Lagarias-Miller-Odlyzko algorithm for PrimePi is used, based on asymptotic estimates of the density of primes, and is inverted to give Prime.

J. M.'s ennui

Posted 2013-05-24T15:43:49.210

Reputation: 115 520

1I believe community wiki abuse is mentioned as a scientific perversion somewhere in the Marquis de Sade complete works. – Dr. belisarius – 2013-05-24T20:21:26.873

@bel, I would have left it as a comment, but it was too damn long. :P – J. M.'s ennui – 2013-05-25T01:29:11.207