Number of primes up to a given bound
MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
numlib::pi(x) returns the number of primes
not exceeding x.
If the argument
x is a real number (an integer,
rational, or floating-point number), then the number of primes below
x is a complex number,
with an error. For every other kind of arithmetical expression
an unevaluated call is returned.
numlib::pi becomes slightly faster if the
internal prime number table is large.
the limit of the internal prime number table; it can be set by the
user via the command line flag
Internally, a fast kernel function with constant memory consumption is used for the computation.
There are two primes less or equal 3:
Also larger inputs can be handled fast:
Floating point arguments are allowed, too.
Non-negative integer or an unevaluated call to
A Lehmer-type algorithm is used, with no precomputed sieve array and no remember tables. In contrast to the algorithm in “Computing π: The Meissel-Lehmer method”, this means constant memory consumption, at the price of slowness.
 Lagarias, J.C., V.S. Miller, and A.M. Odlyzko. “Computing π: The Meissel-Lehmer method”, Math. Comp., Vol. 44, No. 170 (1985), pp. 537-560