Skip to content

PrimePi ​

The prime-counting function: how many primes are ≤ n.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaPrime-counting functionMathWorldPrimeCountingFunctionWikidataQ251922DLMF27.1227.2.E2FungrimPrimePi✓Fungrim entry04427b4fa169✓OEISA000720Wolfram LanguagePrimePi!
PrimePi(n)count of primes ≤n\le n.
SageMathprime_pi(n)✓SymPyprimepi(n)mpmathprimepi(n)Rustprime_pi(n)
Typed signatures
TypePackageApplies
(real) -> integercompute-enginealways
(real) -> integernumber-theoryreplaces compute-enginealways

Domain: Number theory

Details
  • Inverse of NthPrime: π(pn)=n\pi(p_n)=n.
  • Asymptotically π(x)∼x/ln⁡x\pi(x)\sim x/\ln x, the prime number theorem.
  • Counts exactly up to 101510^{15} (the Deléglise–Rivat combinatorial count, seconds at the top); past that the call stays unevaluated.
  • n need not be an integer or prime itself -- PrimePi(n) counts primes up to whatever real value is given.
  • Threads element-wise over a list, as Wolfram's Listable heads do.

Plot

Examples

15 more kept as data, checked against the oracles
Basic #

No primes are ≤ 1

live ↗
InPrimePi(1)\mathrm{PrimePi}(1)Out00
live ↗
InPrimePi(2)\mathrm{PrimePi}(2)Out11
live ↗
InPrimePi(15)\mathrm{PrimePi}(15)Out66
live ↗
InPrimePi(100)\mathrm{PrimePi}(100)Out2525
Scope #

Threads element-wise over a list, as Wolfram's Listable heads do

live ↗
InPrimePi([10,100])\mathrm{PrimePi}(\bigl\lbrack10, 100\bigr\rbrack)Out[4,25]\bigl\lbrack4, 25\bigr\rbrack

Rational arguments: the primes up to 7/27/2 are 2 and 3

live ↗
InPrimePi(72)\mathrm{PrimePi}(\frac{7}{2})Out22

Real arguments

live ↗
InPrimePi(15.25)\mathrm{PrimePi}(15.25)Out6.06.0

The primes below a million

live ↗
InPrimePi(1 000 000)\mathrm{PrimePi}(1\,000\,000)Out78 49878\,498

Listable: threads over a list

live ↗
InPrimePi([3,5,17,25])\mathrm{PrimePi}(\bigl\lbrack3, 5, 17, 25\bigr\rbrack)Out[2,3,7,9]\bigl\lbrack2, 3, 7, 9\bigr\rbrack

Exact at 101110^{11}

live ↗
InPrimePi(100 000 000 000)\mathrm{PrimePi}(100\,000\,000\,000)Out4 118 054 8134\,118\,054\,813

Exact at 101310^{13}, by the combinatorial count

live ↗
InPrimePi(10 000 000 000 000)\mathrm{PrimePi}(10\,000\,000\,000\,000)Out346 065 536 839346\,065\,536\,839

Known value · OEIS A006880

Exact at 101410^{14}, a couple of seconds by the combinatorial count

live ↗
InPrimePi(100 000 000 000 000)\mathrm{PrimePi}(100\,000\,000\,000\,000)Out3 204 941 750 8023\,204\,941\,750\,802

Known value · OEIS A006880

live ↗
InPrimePi(1+1017)\mathrm{PrimePi}(1+10^{17})OutPrimePi(100 000 000 000 000 001)\mathrm{PrimePi}(100\,000\,000\,000\,000\,001)
Applications #

The 25 primes below 100, via the count

live ↗
InNthPrime(1..PrimePi(100))\mathrm{NthPrime}(1..\mathrm{PrimePi}(100))Out[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]\bigl\lbrack2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97\bigr\rbrack

669 primes up to 5000

live ↗
InPrimePi(5 000)\mathrm{PrimePi}(5\,000)Out669669
Properties #

Same inverse relation viewed from PrimePi's side. See NthPrime

live ↗
InPrimePi(NthPrime(50))=50\mathrm{PrimePi}(\mathrm{NthPrime}(50))=50OutTrue\mathrm{True}

Counting up to the 100th prime returns 100

live ↗
InPrimePi(NthPrime(100))\mathrm{PrimePi}(\mathrm{NthPrime}(100))Out100100

168 primes below a thousand

live ↗
InPrimePi(1 000)\mathrm{PrimePi}(1\,000)Out168168

Still 4: the primes up to 10 are 2, 3, 5, 7

live ↗
InPrimePi(10)\mathrm{PrimePi}(10)Out44

Known value · Wolfram MathematicalFunctionData, PrimePi

Possible issues #

No primes are ≤ a negative number

live ↗
InPrimePi(−1)\mathrm{PrimePi}(-1)Out00

Past 101510^{15} the exact tiers decline, so the call stays unevaluated at once instead of counting for minutes

live ↗
InPrimePi(10 000 000 000 000 000.0)\mathrm{PrimePi}(10\,000\,000\,000\,000\,000.0)OutPrimePi(10 000 000 000 000 000.0)\mathrm{PrimePi}(10\,000\,000\,000\,000\,000.0)
About
Examples36
Checked againstWolfram Language 34 agree2 differSageMath 33 agree2 unevaluatedSymPy 31 agree4 errormpmath 27 agree6 errormathlib4 22 agree11 errorRust 26 agree9 error
CrosswalkWikipediaMathWorldWikidataDLMF ×2FungrimFungrim entry ×2OEISWolfram LanguageSageMathSymPympmathRust

Implementation

mappedwolframpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedmathlib4packages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts

See also: NthPrime, NextPrime