1 ! Copyright (C) 2014 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: combinators kernel math math.extras math.extras.private
5 math.functions ranges random sequences ;
7 IN: math.primes.solovay-strassen
11 :: (solovay-strassen) ( n numtrials -- ? )
14 n 1 - [1..b) random :> a
15 a n simple-gcd 1 > [ t ] [
17 a n 1 - 2 /i n ^mod = not
23 : solovay-strassen* ( n numtrials -- ? )
25 { [ over 1 <= ] [ 2drop f ] }
26 { [ over even? ] [ drop 2 = ] }
27 [ (solovay-strassen) ]
30 : solovay-strassen ( n -- ? ) 32 solovay-strassen* ;