math.primes.miller-rabin: minor cleanup;

db4
John Benediktsson 2014-12-04 19:46:30 -08:00
parent 31b22494a1
commit 9d4336d774
1 changed files with 7 additions and 9 deletions

View File

@ -1,14 +1,13 @@
! Copyright (c) 2008-2009 Doug Coleman. ! Copyright (c) 2008-2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: combinators combinators.short-circuit kernel locals math USING: combinators kernel locals math math.functions math.ranges
math.functions math.ranges random sequences sets ; random sequences ;
IN: math.primes.miller-rabin IN: math.primes.miller-rabin
<PRIVATE <PRIVATE
:: (miller-rabin) ( n trials -- ? ) :: (miller-rabin) ( n trials -- ? )
n 1 - :> n-1 n 1 - factor-2s :> ( r s )
n-1 factor-2s :> ( r s )
0 :> a! 0 :> a!
trials iota [ trials iota [
drop drop
@ -25,11 +24,10 @@ IN: math.primes.miller-rabin
PRIVATE> PRIVATE>
: miller-rabin* ( n numtrials -- ? ) : miller-rabin* ( n numtrials -- ? )
over { {
{ [ dup 1 <= ] [ 3drop f ] } { [ over 1 <= ] [ 2drop f ] }
{ [ dup 2 = ] [ 3drop t ] } { [ over even? ] [ drop 2 = ] }
{ [ dup even? ] [ 3drop f ] } [ (miller-rabin) ]
[ drop (miller-rabin) ]
} cond ; } cond ;
: miller-rabin ( n -- ? ) 10 miller-rabin* ; : miller-rabin ( n -- ? ) 10 miller-rabin* ;