21. Pi function {VeryLargeIntegers} | R Documentation |
Pi function approximation for vli (Very Large Integers) objects. It is also called "Prime-counting function".
Given a positive integer x
, the Pi function returns the number of primes up to x
.
pi(x) ## Default S3 method: pi(x) ## S3 method for class 'numeric' pi(x) ## S3 method for class 'vli' pi(x)
x |
positive integer; vli class object or 32 bits integer |
The implemented algorithm is based in the fact that x/log(x)
is asymptotically equal to pi(x)
, also known as "Prime Number Theorem".
Closer approximations could be implemented by using the Logarithmic Integral Function. The function countprimes
of the present package is another way to get a better approximation (in return for a less efficient computation) of pi(x)
. Alhought the algorithm is not deterministic, it is based in the Miller-Rabin Probabilistic Primality Test, therefore the error can be arbitrarily reduced.
number of primes up to x
; object of class vli
Javier Leiva Cuadrado
x <- as.vli("89235489145293876129784691") pi(x)