21. Pi function {VeryLargeIntegers} | R Documentation |
Pi Function Approximation for vli Objects
Description
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
.
Usage
Pi(x)
## Default S3 method:
Pi(x)
## S3 method for class 'numeric'
Pi(x)
## S3 method for class 'vli'
Pi(x)
Arguments
x |
positive integer; vli class object or 32 bits integer |
Details
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.
Value
number of primes up to x
; object of class vli
Author(s)
Javier Leiva Cuadrado
Examples
x <- as.vli("89235489145293876129784691")
Pi(x)