From 7716ac276eca4d0288cf8cc66980c5f348b2eb1e Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 26 Dec 2008 20:58:46 +0100 Subject: [PATCH] Mark parts of math.miller-rabin as private --- basis/math/miller-rabin/miller-rabin.factor | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/basis/math/miller-rabin/miller-rabin.factor b/basis/math/miller-rabin/miller-rabin.factor index afaa66e68f..374616ba40 100755 --- a/basis/math/miller-rabin/miller-rabin.factor +++ b/basis/math/miller-rabin/miller-rabin.factor @@ -4,9 +4,9 @@ USING: combinators io locals kernel math math.functions math.ranges namespaces random sequences hashtables sets ; IN: math.miller-rabin -: >even ( n -- int ) dup even? [ 1- ] unless ; foldable +odd ( n -- int ) dup even? [ 1+ ] when ; foldable -: next-odd ( m -- n ) dup even? [ 1+ ] [ 2 + ] if ; TUPLE: positive-even-expected n ; @@ -28,6 +28,10 @@ TUPLE: positive-even-expected n ; ] unless drop ] each prime? ] ; +PRIVATE> + +: next-odd ( m -- n ) dup even? [ 1+ ] [ 2 + ] if ; + : miller-rabin* ( n numtrials -- ? ) over { { [ dup 1 <= ] [ 3drop f ] } @@ -46,11 +50,15 @@ TUPLE: positive-even-expected n ; ERROR: no-relative-prime n ; + [ 2 + (find-relative-prime) ] [ nip ] if ; +PRIVATE> + : find-relative-prime* ( n guess -- p ) #! find a prime relative to n with initial guess >odd (find-relative-prime) ;