]> gitweb.factorcode.org Git - factor.git/commitdiff
math.primes.miller-rabin: actually, this is better.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 Dec 2014 03:48:32 +0000 (19:48 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 Dec 2014 03:48:32 +0000 (19:48 -0800)
basis/math/primes/miller-rabin/miller-rabin.factor

index 1638f31ec1eb831303fdde5b998caf0573733d84..f46af202496a9ea545307b3036daeb59f3eb42f4 100644 (file)
@@ -7,7 +7,8 @@ IN: math.primes.miller-rabin
 <PRIVATE
 
 :: (miller-rabin) ( n trials -- ? )
-    n 1 - factor-2s :> ( r s )
+    n 1 - :> n-1
+    n-1 factor-2s :> ( r s )
     0 :> a!
     trials iota [
         drop
@@ -16,7 +17,7 @@ IN: math.primes.miller-rabin
             f
         ] [
             r iota [
-                2^ s * a swap n ^mod n - -1 =
+                2^ s * a swap n ^mod n-1 =
             ] any? not
         ] if
     ] any? not ;