[libmath-prime-util-perl] 07/50: Add primorial and pn_primorial
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:45:32 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.13
in repository libmath-prime-util-perl.
commit 78e0015bf645821c34852cfc31cb0f4f2f4dff63
Author: Dana Jacobsen <dana at acm.org>
Date: Thu Aug 2 16:54:11 2012 -0600
Add primorial and pn_primorial
---
Changes | 18 ++++++++-----
TODO | 10 +++-----
lib/Math/Prime/Util.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 12 deletions(-)
diff --git a/Changes b/Changes
index 25ac83c..121f279 100644
--- a/Changes
+++ b/Changes
@@ -1,14 +1,20 @@
Revision history for Perl extension Math::Prime::Util.
-0.12 30 July 2012
- - Add RiemannZeta function. We used this before for Riemann R, but now
- it is exported and should be accurate for small numbers (it was only
- used for integers > 40 before).
- - add prime_set_config(), including ability to set assume_rh to let all
- functions assume the Riemann Hypothesis.
+0.12 2 August 2012
+ - Add:
+ primorial product of primes <= n
+ pn_primorial product of first n primes
+ prime_set_config set config options
+ RiemannZeta export and make accurate for small reals
+
+ - Add 'assume_rh' configuration option (default: false) which can be set
+ to allow functions to assume the Riemann Hypothesis.
+
- Use the Schoenfeld bound for Pi(x) (x large) if assume_rh is true.
+
- valgrind testing
+
0.11 23 July 2012
- Turn off threading tests on Cygwin, as threads on some Cygwin platforms
give random panics (my Win7 64-bit works fine, XP 32-bit does not).
diff --git a/TODO b/TODO
index 9e91c36..4b7b42d 100644
--- a/TODO
+++ b/TODO
@@ -2,8 +2,6 @@
- Examine behavior near 32-bit limit on 32-bit machines.
(done for factoring)
-- GMP versions of all routines.
-
- segment sieve should itself use a segment for its primes.
Today we'd need sqrt(2^64) max = 140MB. Segmenting would yield under 1MB.
@@ -15,10 +13,6 @@
- Faster SQUFOF
-- better prime count upper/lower bounds:
- - Dusart 2010 "Estimates of Some Functions Over Primes without R.H."
- - Schoenfeld or Stoll for with-RH limits
-
- Move .c / .h files into separate directory.
version does it in a painful way. Something simpler to be had?
@@ -26,3 +20,7 @@
- After the factoring changes, we need to use Devel::Cover again to ferret
out numbers that pass the early tests.
+
+- tests for primorial
+
+- document prime_set_config
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 3bff7b5..921441a 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -22,6 +22,7 @@ our @EXPORT_OK = qw(
prime_count prime_count_lower prime_count_upper prime_count_approx
nth_prime nth_prime_lower nth_prime_upper nth_prime_approx
random_prime random_ndigit_prime random_nbit_prime random_maurer_prime
+ primorial pn_primorial
factor all_factors moebius euler_phi
ExponentialIntegral LogarithmicIntegral RiemannZeta RiemannR
);
@@ -634,6 +635,28 @@ sub primes {
}
}
+sub primorial {
+ my $n = shift;
+ _validate_positive_integer($n);
+
+ return Math::Prime::Util::GMP::primorial($n)
+ if $_HAVE_GMP && defined &Math::Prime::Util::GMP::primorial;
+
+ my $pn = 1;
+ $pn = Math::BigInt->new->bone if defined $bigint::VERSION &&
+ $n >= (($_Config{'maxbits'} == 32) ? 29 : 53);
+
+ foreach my $p ( @{ primes($n) } ) {
+ $pn *= $p;
+ }
+ return $pn;
+}
+
+sub pn_primorial {
+ return primorial( nth_prime($_[0]) );
+}
+
+
sub all_factors {
my $n = shift;
my @factors = factor($n);
@@ -1335,6 +1358,11 @@ Version 0.12
# Moebius function used to calculate Mertens
$sum += moebius($_) for (1..200); say "Mertens(200) = $sum";
+ # The primorial n# (product of all primes <= n)
+ say "15# (2*3*5*7*11*13) is ", primorial(15);
+ # The primorial p(n)# (product of first n primes)
+ say "P(9)# (2*3*5*7*11*13*17*19*23) is ", pn_primorial(9);
+
# Ei, li, and Riemann R functions
my $ei = ExponentialIntegral($x); # $x a real: $x != 0
my $li = LogarithmicIntegral($x); # $x a real: $x >= 0
@@ -1695,6 +1723,44 @@ C<n E<lt> 1>. This follows the logic used by SAGE. Mathematic/WolframAlpha
also returns 0 for input 0, but returns C<euler_phi(-n)> for C<n E<lt> 0>.
+=head2 primorial
+
+ $prim = primorial(11); # 11# = 2*3*5*7*11 = 2310
+
+Returns the primorial C<n#> of the positive integer input, defined as the
+product of the prime numbers less than or equal to C<n>. This is the
+L<OEIS series A034386|http://oeis.org/A034386>: primorial numbers second
+definition.
+
+ primorial(0) == 1
+ primorial($n) == pn_primorial( prime_count($n) )
+
+The result will be calculated using native numbers if neither bigint nor
+L<Math::Prime::Util::GMP> are loaded.
+
+Be careful about which version (C<primorial> or C<pn_primorial>) matches the
+definition you want to use. Not all sources agree on the terminology, though
+they should give a clear definition of which of the two versions they mean.
+OEIS, Wikipedia, and Mathworld are all consistent, and these functions should
+match that terminology.
+
+
+=head2 pn_primorial
+
+ $prim = pn_primorial(5); # p_5# = 2*3*5*7*11 = 2310
+
+Returns the primorial number C<p_n#> of the positive integer input, defined as
+the product of the first C<n> prime numbers (compare to the factorial, which
+is the product of the first C<n> natural numbers). This is the
+L<OEIS series A002110|http://oeis.org/A002110>: primorial numbers first
+definition.
+
+ pn_primorial(0) == 1
+ pn_primorial($n) == primorial( nth_prime($n) )
+
+The result will be calculated using native numbers if neither bigint nor
+L<Math::Prime::Util::GMP> are loaded.
+
=head2 random_prime
@@ -2220,6 +2286,8 @@ excellent versions in the public domain).
=item Douglas A. Stoll and Patrick Demichel , "The impact of ζ(s) complex zeros on π(x) for x E<lt> 10^{10^{13}}", Mathematics of Computation, v80, n276, pp 2381-2394, October 2011. L<http://www.ams.org/journals/mcom/2011-80-276/S0025-5718-2011-02477-4/home.html>
+=item L<OEIS: Primorial|http://oeis.org/wiki/Primorial>.
+
=back
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list