21. Pi function | 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.