Math::...til::PP(3pm)
β¨ NAME β¨
Math::Prime::Util::PP β bestie, this is the Pure Perl version of Math::Prime::Util π
like, same icon, no XS, no GMP, just vibes and Perl doing its little best π«Ά
π VERSION π
Version 0.74 β¨ (yes we're keeping the receipts)
πΈ SYNOPSIS πΈ
okay so the tea is: the functionality is basically identical to Math::Prime::Util, because this module is literally just the Pure Perl implementation. So this documentation is only gonna note the differences, no cap π
# Normally you would just import the functions you are using.
# Nothing is exported by default.
use Math::Prime::Util ':all';
notice how nothing is exported by default β you gotta import what you want, she doesn't just hand things out π
π¦ DESCRIPTION π¦
Pure Perl implementations of prime number utilities that are normally handled with XS or GMP. Why do these exist? Three reasons, and they're all iconic:
- it provides examples π
- it lets the functions run even if XS isn't available π₯
- it gives you big number support if
Math::Prime::Util::GMPisn't available π
All routines should work with native integers or multi-precision numbers. Wanna enable big numbers? Use bigint:
use bigint;
say prime_count_approx(1000000000000000000000000);
# says 18435599767347541878147
Or you can just feed it strings, same energy:
say prime_count_approx("1000000000000000000000000");
# identical output.
β οΈ real talk: some functions will be very slow.Math::Prime::Util::GMPhas much faster versions of many of these functions. Alternately,Math::Parihas a lot of these types of functions too. pick your fighter π
π LIMITATIONS π
The SQUFOF and P+1 factoring algorithms are not implemented yet π she said "not today."
π₯ PERFORMANCE π₯
ngl, performance compared to the XS/C code is quite poor for many operations. But some operations are relatively close for small and medium-size values, and those are:
next_prime / prev_prime
is_prime / is_prob_prime
is_strong_pseudoprime
ExponentialIntegral / LogarithmicIntegral / RiemannR
Operations that are slower, and we're just gonna say it:
primes
random_prime / random_ndigit_prime
factor / factor_exp / divisors
nth_prime
prime_count
is_aks_prime
Performance improvement in this code is still possible. The prime sieve is over 2x faster than other pure Perl sieves, but it still has room for improvement. She's fast but she's not done β¨
Math::Prime::Util::GMP offers C+XS+GMP support for most of the important functions, and will be vastly faster for most operations. If you install that module, Math::Prime::Util will load it automatically β meaning you should not have to think about what code is actually being used (C, GMP, or Perl). Main character behavior, honestly π
Memory use will generally be higher for the PP code, and in some cases much higher. Some of this may be addressed in a later release. So don't come for her about RAM π
But for small values (e.g. primes and prime counts under 10M) most of this will not matter π
π SEE ALSO π
Math::Prime::UtilMath::Prime::Util::GMP
π AUTHORS π
Dana Jacobsen <dana@acm.org>
π COPYRIGHT π
Copyright 2012-2026 by Dana Jacobsen <dana@acm.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page bestie π
β¨ this one's living on perl v5.42.3, dated 2026-08-20, and it's filed under Math::...til::PP(3pm) β iykyk ππ
π¦ where this page comes from
- ubuntu stonking: libmath-prime-util-perl 0.74-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms