Small updates to math.primes
parent
798139f2e7
commit
774cb858d5
|
@ -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
|
||||
|
||||
<PRIVATE
|
||||
|
@ -11,14 +10,16 @@ IN: math.primes.factors
|
|||
|
||||
: (count) ( n d -- n' )
|
||||
[ (factor) ] { } make
|
||||
[ [ first ] keep length 2array , ] unless-empty ;
|
||||
[ [ first ] [ length ] bi 2array , ] unless-empty ;
|
||||
|
||||
: (unique) ( n d -- n' )
|
||||
[ (factor) ] { } make
|
||||
[ first , ] unless-empty ;
|
||||
|
||||
: (factors) ( quot list n -- )
|
||||
dup 1 > [ 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
|
||||
|
|
|
@ -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
|
||||
|
||||
<PRIVATE
|
||||
|
@ -45,8 +44,7 @@ PRIVATE>
|
|||
} cond ; foldable
|
||||
|
||||
: primes-between ( low high -- seq )
|
||||
primes-upto
|
||||
[ 1- next-prime ] dip
|
||||
[ natural-search drop ] keep [ length ] keep <slice> ; foldable
|
||||
primes-upto [ 1- next-prime ] dip
|
||||
[ natural-search drop ] [ length ] [ ] tri <slice> ; foldable
|
||||
|
||||
: coprime? ( a b -- ? ) gcd nip 1 = ; foldable
|
||||
|
|
Loading…
Reference in New Issue