diff --git a/extra/math/primes/factors/factors.factor b/extra/math/primes/factors/factors.factor index 059bd67c18..80c93f2ae0 100644 --- a/extra/math/primes/factors/factors.factor +++ b/extra/math/primes/factors/factors.factor @@ -1,7 +1,6 @@ ! Copyright (C) 2007 Samuel Tardieu. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays kernel lists math math.primes namespaces make -sequences ; +USING: arrays kernel lists make math math.primes sequences ; IN: math.primes.factors [ swap uncons swap >r pick call r> swap (factors) ] [ 3drop ] if ; + dup 1 > [ + swap uncons swap [ pick call ] dip swap (factors) + ] [ 3drop ] if ; : (decompose) ( n quot -- seq ) [ lprimes rot (factors) ] { } make ; @@ -38,5 +39,5 @@ PRIVATE> dup 2 < [ drop 0 ] [ - dup unique-factors dup 1 [ 1- * ] reduce swap product / * + dup unique-factors [ 1 [ 1- * ] reduce ] [ product ] bi / * ] if ; foldable diff --git a/extra/math/primes/primes.factor b/extra/math/primes/primes.factor index feb60c555d..820d5b6c4a 100644 --- a/extra/math/primes/primes.factor +++ b/extra/math/primes/primes.factor @@ -1,8 +1,7 @@ ! Copyright (C) 2007 Samuel Tardieu. ! See http://factorcode.org/license.txt for BSD license. -USING: combinators kernel lists.lazy math math.functions math.miller-rabin - math.order math.primes.list math.ranges sequences sorting - binary-search ; +USING: binary-search combinators kernel lists.lazy math math.functions + math.miller-rabin math.primes.list sequences ; IN: math.primes } cond ; foldable : primes-between ( low high -- seq ) - primes-upto - [ 1- next-prime ] dip - [ natural-search drop ] keep [ length ] keep ; foldable + primes-upto [ 1- next-prime ] dip + [ natural-search drop ] [ length ] [ ] tri ; foldable : coprime? ( a b -- ? ) gcd nip 1 = ; foldable