]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/math/primes/miller-rabin/miller-rabin.factor
factor: trim using lists
[factor.git] / basis / math / primes / miller-rabin / miller-rabin.factor
old mode 100755 (executable)
new mode 100644 (file)
index 04b1330..5b40c00
@@ -1,7 +1,7 @@
 ! Copyright (c) 2008-2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: combinators combinators.short-circuit kernel locals math
-math.functions math.ranges random sequences sets ;
+USING: combinators kernel math math.functions ranges
+random sequences ;
 IN: math.primes.miller-rabin
 
 <PRIVATE
@@ -10,26 +10,25 @@ IN: math.primes.miller-rabin
     n 1 - :> n-1
     n-1 factor-2s :> ( r s )
     0 :> a!
-    trials [
+    trials <iota> [
         drop
-        2 n 2 - [a,b] random a!
+        2 n 2 - [a..b] random a!
         a s n ^mod 1 = [
             f
         ] [
-            r iota [
-                2^ s * a swap n ^mod n - -1 =
-            ] any? not
+            r <iota> [
+                2^ s * a swap n ^mod n-1 =
+            ] none?
         ] if
-    ] any? not ;
+    ] none? ;
 
 PRIVATE>
 
 : miller-rabin* ( n numtrials -- ? )
-    over {
-        { [ dup 1 <= ] [ 3drop f ] }
-        { [ dup 2 = ] [ 3drop t ] }
-        { [ dup even? ] [ 3drop f ] }
-        [ drop (miller-rabin) ]
+    {
+        { [ over 1 <= ] [ 2drop f ] }
+        { [ over even? ] [ drop 2 = ] }
+        [ (miller-rabin) ]
     } cond ;
 
 : miller-rabin ( n -- ? ) 10 miller-rabin* ;