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 b88fdb78ae87f0fa3a750570e778893436b6ed02 Author: Dana Jacobsen <d...@acm.org> Date: Sun Nov 18 02:39:51 2012 -0800 Update some examples --- .gitignore | 2 ++ MANIFEST | 7 ++++ examples/find_mr_bases.pl | 85 +++++++++++++++++++++++++++++++++++++++++++++ examples/test-bpsw.pl | 7 ++-- examples/test-euler-pari.pl | 7 ++-- 5 files changed, 102 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 04fde6f..4681eb4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ util.o lehmer.o aks.o blib* +b[0-9][0-9][0-9][0-9][0-9][0-9].txt +script-test-data.bs diff --git a/MANIFEST b/MANIFEST index bcc1329..2c17b15 100644 --- a/MANIFEST +++ b/MANIFEST @@ -45,6 +45,13 @@ examples/test-nthapprox.pl examples/test-pcapprox.pl examples/sophie_germain.pl examples/twin_primes.pl +examples/find_mr_bases.pl +examples/test-bpsw.pl +examples/test-euler-pari.pl +examples/test-factor-gnufactor.pl +examples/make-script-test-data.pl +examples/test-primes-script.pl +examples/test-primes-script2.pl bin/primes.pl bin/factor.pl t/01-load.t diff --git a/examples/find_mr_bases.pl b/examples/find_mr_bases.pl new file mode 100644 index 0000000..5eeaeac --- /dev/null +++ b/examples/find_mr_bases.pl @@ -0,0 +1,85 @@ +#!/usr/bin/env perl +use warnings; +use strict; +use threads; +use threads::shared; +use Math::Prime::Util qw/-nobigint is_prime is_strong_pseudoprime/; +my $nthreads = 12; + +# Single base. + +my @composites; +for my $n (3 .. 1000000) { + push @composites, $n if $n % 2 && !is_prime($n); +} + +# Serial: +# my $base = 2; +# my $maxn = 2; +# while (1) { +# for my $n (@composites) { +# if (is_strong_pseudoprime($n,$base)) { +# if ($n > $maxn) { +# print "base $base good up to $n\n"; +# $maxn = $n; +# } +# last; +# } +# } +# $base++; +# } + +# Parallel: +my $maxn :shared; +my $start = 1; # People have mined below ~ 2^52 +$maxn = 2047; +my $nextn = 2049; +my @threads; +push @threads, threads->create('search_bases', $start, $_) for (0..$nthreads-1); +# We should sit here doing cond_waits on a results array. +$_->join() for (@threads); + +sub search_bases { + my($start, $t) = @_; + my $base = $start + $t; + while (1) { + do { $base += $t; next; } if is_strong_pseudoprime($nextn, $base); + for my $n (@composites) { + if (is_strong_pseudoprime($n,$base)) { + if ($n > $maxn) { + lock($maxn); + print "base $base good up to $n\n"; + $maxn = $n; + $nextn = $n+2; $nextn++ while is_prime($nextn); + } + last; + } + } + $base += $t; + } +} + +__END__ + +base 2 good up to 2047 +base 1320 good up to 4097 +base 4712 good up to 4711 +base 5628 good up to 5627 +base 7252 good up to 7251 +base 7852 good up to 7851 +base 14787 good up to 9409 +base 17340 good up to 10261 +base 61380 good up to 11359 +base 78750 good up to 13747 +base 254923 good up to 18299 +base 486605 good up to 25761 +base 1804842 good up to 32761 +base 4095086 good up to 38323 +base 12772344 good up to 40501 +base 42162995 good up to 97921 + +(best results known, not found with this program) +2011-02-12 base 814494960528 good up to 132239 +2012-07-02 base 64390572806844 good up to 161701 +2012-10-15 base 1769236083487960 good up to 192001 +2012-10-17 base 1948244569546278 good up to 212321 diff --git a/examples/test-bpsw.pl b/examples/test-bpsw.pl index 383822a..63a0a96 100755 --- a/examples/test-bpsw.pl +++ b/examples/test-bpsw.pl @@ -96,10 +96,11 @@ foreach my $r (1 .. int($nrandom/50)) { print "\n"; } -use bigint try => 'GMP'; -my $num_rns = 50; +my $num_rns = 100; my $len_rns = 100; -my $count = -.1; +my $count = -1; + +use bigint try => 'GMP'; my @rns; # make the primality tests at least lift a finger. while (@rns < $num_rns) { diff --git a/examples/test-euler-pari.pl b/examples/test-euler-pari.pl index a2a0893..2e86359 100755 --- a/examples/test-euler-pari.pl +++ b/examples/test-euler-pari.pl @@ -7,8 +7,8 @@ use Math::Prime::Util qw/-nobigint/; use Math::Pari; Math::Prime::Util::prime_precalc(10_000_000); -my $nlinear = 1000000; -my $nrandom = shift || 1000000; +my $nlinear = 100000; +my $nrandom = shift || 100000; my $randmax = ~0; # Looks like MPU is 4x faster than Pari for 1 .. 1M, 5x faster for 1M - 10_000M. @@ -27,11 +27,12 @@ foreach my $n (2 .. $nlinear) { } print " numbers\n"; print "Testing random numbers from $nlinear to ", $randmax, "\n"; +my $mod = int($nrandom / 80); while ($nrandom-- > 0) { my $n = $nlinear + 1 + int(rand($randmax - $nlinear)); die "failure for eulerphi($n)" unless Math::Prime::Util::euler_phi($n) == Math::Pari::eulerphi($n); die "failure for moebius($n)" unless Math::Prime::Util::moebius($n) == Math::Pari::moebius($n); - print "." if ($nrandom % 256) == 0; + print "." if ($nrandom % $mod) == 0; } print "\n"; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits