[libmath-prime-util-perl] 04/43: Speedup for exp_mangoldt

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:53:05 UTC 2015


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

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

commit 9dbf0972cc9667af838b7c8a452da534484b9099
Author: Dana Jacobsen <dana at acm.org>
Date:   Tue Mar 4 18:53:24 2014 -0800

    Speedup for exp_mangoldt
---
 Changes |  2 ++
 util.c  | 13 +++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Changes b/Changes
index c688a15..5be7e68 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,8 @@ Revision history for Perl module Math::Prime::Util
 
     - Update PP Frobenius-Underwood test.
 
+    - Speed up exp_mangoldt.
+
 
 0.39  2014-03-01
 
diff --git a/util.c b/util.c
index b5374c9..be03129 100644
--- a/util.c
+++ b/util.c
@@ -1197,13 +1197,14 @@ UV exp_mangoldt(UV n) {
   if      (n <= 1)           return 1;
   else if ((n & (n-1)) == 0) return 2;     /* Power of 2 */
   else if ((n & 1) == 0)     return 1;     /* Even number (not 2) */
+  else if (is_prob_prime(n)) return n;
   else {
-    UV i, factors[MPU_MAX_FACTORS+1];
-    UV nfactors = factor(n, factors);
-    for (i = 1; i < nfactors; i++)
-      if (factors[i] != factors[0])
-        return 1;
-    return factors[0];
+    int k = powerof(n);
+    if (k >= 2) {
+      n = (k==2) ? isqrt(n) : (UV)(pow(n,1.0/k)+0.0000001);
+      if (is_prob_prime(n)) return n;
+    }
+    return 1;
   }
 }
 

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