This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.27
in repository libmath-prime-util-perl.

commit 0540efda916ce5665f16122a4c62de1ed41a8d03
Author: Dana Jacobsen <d...@acm.org>
Date:   Mon Apr 22 14:42:33 2013 -0700

    Speedups for pure perl factoring of small numbers
---
 Changes                   |  4 ++++
 lib/Math/Prime/Util/PP.pm | 21 ++++++++++-----------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/Changes b/Changes
index c2d3246..121078e 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension Math::Prime::Util.
 
+0.27 xx April 2013
+
+    - Speedup pure Perl factoring of small numbers.
+
 0.26 21 April 2013
 
     - Pure Perl factoring:
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index 4207bd9..a1349f7 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1122,16 +1122,17 @@ sub trial_factor {
   return @factors if $n < 4;
 
   my $limit = int( sqrt($n) + 0.001);
-  my $f = 3;
-  while ($f <= $limit) {
-    if ( ($n % $f) == 0) {
-      while ( ($n % $f) == 0) {
-        push @factors, $f;
-        $n = int($n/$f);
+  my $f = 7;
+  SEARCH: while ($f <= $limit) {
+    foreach my $finc (4, 2, 4, 2, 4, 6, 2, 6) {
+      if ( (($n % $f) == 0) && ($f <= $limit) ) {
+        do { push @factors, $f; $n = int($n/$f); } while (($n % $f) == 0);
+        $n = int($n->bstr) if ref($n) eq 'Math::BigInt' && $n <= ~0;
+        last SEARCH if $n == 1 || Math::Prime::Util::is_prob_prime($n);
+        $limit = int( sqrt($n) + 0.001);
       }
-      $limit = int( sqrt($n) + 0.001);
+      $f += $finc;
     }
-    $f += 2;
   }
   push @factors, $n  if $n > 1;
   @factors;
@@ -1139,8 +1140,6 @@ sub trial_factor {
 
 my $_holf_r;
 my @_fsublist = (
-  sub { my $n = shift; return ($n) unless $n < $_half_word;
-        holf_factor   ($n,      64*1024, $_holf_r); $_holf_r +=  64*1024; },
   sub { prho_factor   (shift,    8*1024, 3) },
   sub { pbrent_factor (shift,   32*1024, 1) },
   sub { pminus1_factor(shift,    10_000); },
@@ -1165,7 +1164,7 @@ sub factor {
   _validate_positive_integer($n);
   $n = $n->copy if ref($n) eq 'Math::BigInt';
 
-  return trial_factor($n) if $n < 100000;
+  return trial_factor($n) if $n < 1_000_000;
 
   my @factors = _basic_factor($n);
   return @factors if $n < 4;

-- 
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

Reply via email to