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

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

commit 1fa0cbe0fc916fbe067808b8af453b3f73df6fc2
Author: Dana Jacobsen <d...@acm.org>
Date:   Wed Jun 26 18:16:35 2013 -0700

    Add braindead p+1 factoring
---
 Changes  |  1 +
 TODO     |  2 ++
 XS.xs    |  5 +++++
 factor.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+)

diff --git a/Changes b/Changes
index d1aa936..2e7b980 100644
--- a/Changes
+++ b/Changes
@@ -12,6 +12,7 @@ Revision history for Perl extension Math::Prime::Util.
     - Added:
         is_frobenius_underwood_pseudoprime
         lucas_sequence
+        pplus1_factor
 
 0.29 30 May 2013
 
diff --git a/TODO b/TODO
index 33f6bc5..42b72f2 100644
--- a/TODO
+++ b/TODO
@@ -48,3 +48,5 @@
 
 - Write a standalone function that demonstrates the memory leak with MULTICALL,
   so we can use MULTICALL.
+
+- Tests, documentation, optimizations, and comparisons for p+1 factoring
diff --git a/XS.xs b/XS.xs
index 502a95d..fe7851a 100644
--- a/XS.xs
+++ b/XS.xs
@@ -420,6 +420,11 @@ pminus1_factor(IN UV n, IN UV B1 = 1*1024*1024, IN UV B2 = 
0)
       B2 = 10*B1;
     SIMPLE_FACTOR_2ARG(pminus1_factor, n, B1, B2);
 
+void
+pplus1_factor(IN UV n, IN UV B = 200)
+  PPCODE:
+    SIMPLE_FACTOR(pplus1_factor, n, B);
+
 int
 _XS_is_pseudoprime(IN UV n, IN UV a)
 
diff --git a/factor.c b/factor.c
index 61e2025..2be4af2 100644
--- a/factor.c
+++ b/factor.c
@@ -943,6 +943,57 @@ int pminus1_factor(UV n, UV *factors, UV B1, UV B2)
   return 1;
 }
 
+/* Simple Williams p+1 */
+int pplus1_factor(UV n, UV *factors, UV B)
+{
+  UV i, f, b;
+  UV P1, P2, P3, U1, U2, U3, V1, V2, V3;
+
+  /* Calculate 3 sequences at once */
+  P1 =  5 % n;
+  P2 =  9 % n;
+  P3 = 13 % n;
+  U1 = P1;  U2 = P2;  U3 = P3;
+  for (i = 1; i < B; i++) {
+    { UV v = i; b = 1; while (v >>= 1) b++; }
+    V1 = mulsubmod(P1, P1, 2, n);
+    V2 = mulsubmod(P2, P2, 2, n);
+    V3 = mulsubmod(P3, P3, 2, n);
+    while (b > 1) {
+      b--;
+      if ( (i >> (b-1)) & UVCONST(1) ) {
+        U1 = mulsubmod(U1, V1, P1, n);
+        V1 = mulsubmod(V1, V1,  2, n);
+        U2 = mulsubmod(U2, V2, P2, n);
+        V2 = mulsubmod(V2, V2,  2, n);
+        U3 = mulsubmod(U3, V3, P3, n);
+        V3 = mulsubmod(V3, V3,  2, n);
+      } else {
+        V1 = mulsubmod(U1, V1, P1, n);
+        U1 = mulsubmod(U1, U1,  2, n);
+        V2 = mulsubmod(U2, V2, P2, n);
+        U2 = mulsubmod(U2, U2,  2, n);
+        V3 = mulsubmod(U3, V3, P3, n);
+        U3 = mulsubmod(U3, U3,  2, n);
+      }
+    }
+    P1 = U1;  P2 = U2;  P3 = U3;
+    f = gcd_ui(n, submod(U1, 2, n));
+    if (f == 1 || f == n)
+      f = gcd_ui(n, submod(U2, 2, n));
+    if (f == 1 || f == n)
+      f = gcd_ui(n, submod(U3, 2, n));
+    if (f > 1 && f != n) {
+      factors[0] = f;
+      factors[1] = n/f;
+      MPUassert( factors[0] * factors[1] == n , "incorrect factoring");
+      return 2;
+    }
+  }
+  factors[0] = n;
+  return 1;
+}
+
 
 /* My modification of Ben Buhrow's modification of Bob Silverman's SQUFOF code.
  */

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