[libmath-prime-util-perl] 43/72: Updates for release
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:49:39 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.32
in repository libmath-prime-util-perl.
commit 5b0992f346f1a92cb236af9e47d0848ba6852117
Author: Dana Jacobsen <dana at acm.org>
Date: Tue Sep 24 18:58:54 2013 -0700
Updates for release
---
examples/test-factor-gnufactor.pl | 2 +-
factor.c | 8 ++++----
lib/Math/Prime/Util.pm | 14 +++++++++++---
xt/primality-proofs.pl | 21 +++++++++++++++------
4 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/examples/test-factor-gnufactor.pl b/examples/test-factor-gnufactor.pl
index b618b59..4546910 100755
--- a/examples/test-factor-gnufactor.pl
+++ b/examples/test-factor-gnufactor.pl
@@ -29,7 +29,7 @@ my $num = 1000;
# GNU factor gets its result by multiple shells out to /usr/bin/factor with
# the numbers as command line arguments. This adds a lot of overhead that
# has nothing to do with their implementation. For comparison, try turning
-# on the MPU factor.pl script, and weep for Perl's startup cost.
+# on the MPU factor.pl script, and weep at Perl's startup cost.
my $do_gnu = 1;
my $do_pari = 1;
diff --git a/factor.c b/factor.c
index 4c08193..82d09c7 100644
--- a/factor.c
+++ b/factor.c
@@ -320,7 +320,7 @@ UV _XS_divisor_sum(UV n, UV k)
while (i+1 < nfac && f == factors[i+1]) { e++; i++; }
if (e > 1) {
UV pke = f;
- for (j = 1; j < e; j++) {
+ for (j = 1; j < (int)e; j++) {
pke *= f;
fmult += pke;
}
@@ -330,13 +330,13 @@ UV _XS_divisor_sum(UV n, UV k)
} else {
for (i = 0; i < nfac; i++) {
UV e = 1, f = factors[i];
- UV fmult, pk = f;
- for (j = 1; j < k; j++) pk *= f;
+ UV fmult, pk = f;
+ for (j = 1; j < (int)k; j++) pk *= f;
while (i+1 < nfac && f == factors[i+1]) { e++; i++; }
fmult = 1 + pk;
if (e > 1) {
UV pke = pk;
- for (j = 1; j < e; j++) {
+ for (j = 1; j < (int)e; j++) {
pke *= pk;
fmult += pke;
}
diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index 880a877..3efc1cf 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -2828,10 +2828,16 @@ and iterating through it, this is more memory efficient and perhaps more
convenient. This will almost always be the fastest way to loop over a range
of primes. Nesting and using in threads are allowed.
+Math::BigInt objects may be used for the range.
+
For some uses an iterator (L</prime_iterator>, L</prime_iterator_object>)
or a tied array (L<Math::Prime::Util::PrimeArray>) may be more convenient.
-Objects can be passed to functions, and allow early loop exits which are
-only possible in L</forprimes> by using an exception.
+Objects can be passed to functions, and allow early loop exits without
+exceptions. Here is a clumsy L</forprimes> exception example:
+
+ use bigint;
+ eval { forprimes { die "$_\n" if $_ % 123 == 1 } 2**100, 2**101 };
+ my $n = 0+$@;
=head2 prime_iterator
@@ -2863,7 +2869,9 @@ or L<Math::Prime::Util::PrimeArray> (a tied array).
Returns a L<Math::Prime::Util::PrimeIterator> object. A shortcut that loads
the package if needed, calls new, and returns the object. See the
-documentation for that package for details.
+documentation for that package for details. This object has more features
+than the simple one above (e.g. the iterator is bi-directional), and also
+handles iterating across bigints.
=head2 prime_count
diff --git a/xt/primality-proofs.pl b/xt/primality-proofs.pl
index 7dfb951..c4cdf85 100755
--- a/xt/primality-proofs.pl
+++ b/xt/primality-proofs.pl
@@ -9,12 +9,19 @@ $|++;
# The number of tests performed. 71 makes a nice display for 80 columns.
my $num = 71;
# Select random primes with sizes randomly between 4 and this number of bits.
-my $size = 300;
-# Which selection method?
-# mpu is 2x faster than pari, but it's our code
-# pari works pretty well, and is 2x faster than Crypt::Primes
-# cpmaurer is slow and can produce composites
-my $prime_method = 'pari'; # mpu, pari, or cpmaurer
+my $size = 500;
+# Which selection method? Ideally we would use some independent code. Time
+# for one thousand random primes from rand(4-300) or rand(4-600) bits:
+#
+# 300bits 600bits which
+# 2sec 6sec mpu (with mpu::gmp installed)
+# 31sec 124sec pari
+# 97sec 254sec cpmaurer
+#
+# We don't seem to have any practical choice other than MPU's
+# random_nbit_prime as the other random prime code is just so slow.
+#
+my $prime_method = 'mpu'; # mpu, pari, or cpmaurer
my @ns;
print "Generate ";
@@ -29,6 +36,8 @@ foreach my $i (1..$num) {
} elsif ($prime_method eq 'pari') {
require Math::Pari;
require Crypt::Random;
+ # This is ~4x faster, has awful distribution. Still much slower than MPU.
+ # $n = Math::Pari::nextprime( ...makerandom... );
do { $n = Crypt::Random::makerandom(Size=>$bits,Strength=>0); }
while !Math::Pari::isprime($n);
} elsif ($prime_method eq 'mpu') {
--
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