From 9d4336d77446fb79fd56403906c8e89e973ccbf3 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 4 Dec 2014 19:46:30 -0800 Subject: [PATCH] math.primes.miller-rabin: minor cleanup; --- .../math/primes/miller-rabin/miller-rabin.factor | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/basis/math/primes/miller-rabin/miller-rabin.factor b/basis/math/primes/miller-rabin/miller-rabin.factor index ac5c2df705..1638f31ec1 100644 --- a/basis/math/primes/miller-rabin/miller-rabin.factor +++ b/basis/math/primes/miller-rabin/miller-rabin.factor @@ -1,14 +1,13 @@ ! 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 locals math math.functions math.ranges +random sequences ; IN: math.primes.miller-rabin n-1 - n-1 factor-2s :> ( r s ) + n 1 - factor-2s :> ( r s ) 0 :> a! trials iota [ drop @@ -25,11 +24,10 @@ IN: math.primes.miller-rabin 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* ;