From f8a0d7403d5e0657b4c384b3fd688a45413ec15c Mon Sep 17 00:00:00 2001 From: Doug Coleman <erg@jjjj.local> Date: Sat, 12 Jan 2008 21:46:53 -1000 Subject: [PATCH] small cleanup in miller-rabin --- extra/math/miller-rabin/miller-rabin.factor | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/extra/math/miller-rabin/miller-rabin.factor b/extra/math/miller-rabin/miller-rabin.factor index 824bb88cb9..da8da8b7c3 100644 --- a/extra/math/miller-rabin/miller-rabin.factor +++ b/extra/math/miller-rabin/miller-rabin.factor @@ -20,17 +20,12 @@ SYMBOL: trials : random-bits ( m -- n ) 2^ random ; foldable -: (factor-2s) ( s n -- s n ) - dup even? [ -1 shift >r 1+ r> (factor-2s) ] when ; - : factor-2s ( n -- r s ) #! factor an even number into 2 ^ s * m - dup even? over 0 > and [ - "input must be positive and even" throw - ] unless 0 swap (factor-2s) ; + dup even? [ -1 shift >r 1+ r> factor-2s ] when ; :: (miller-rabin) | n prime?! | - n 1- factor-2s s set r set + 0 n 1- factor-2s s set r set trials get [ n 1- [1,b] random a set a get s get n ^mod 1 = [