HELP: factors
{ $values { "n" "a positive integer" } { "seq" sequence } }
-{ $description { "Return an ordered list of a number's prime factors, possibly repeated." } }
+{ $description { "Return an ordered list of a number's prime factors, possibly repeated, using the Pollard Rho Brent algorithm in the " { $vocab-link "math.primes.pollard-rho-brent" } " vocabulary." } }
{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 factors ." "{ 2 2 3 5 5 }" } } ;
HELP: group-factors
! Copyright (C) 2007-2009 Samuel Tardieu.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs combinators command-line io kernel make
-math math.functions math.parser math.primes math.ranges
-namespaces sequences sequences.product sorting splitting ;
+math math.functions math.parser math.primes
+math.primes.pollard-rho-brent math.ranges namespaces sequences
+sequences.product sorting splitting ;
IN: math.primes.factors
<PRIVATE
: unique-factors ( n -- seq ) group-factors keys ; flushable
-: factors ( n -- seq )
- group-factors [ first2 swap <array> ] map concat ; flushable
+: factors ( n -- seq ) brent-factors ; flushable
: totient ( n -- t )
{
USING: math.primes.pollard-rho-brent sorting tools.test ;
IN: math.primes.pollard-rho-brent.tests
-{ { 2 2 2507191691 1231026625769 } } [ 12345678910111213141516 brent-factors natural-sort ] unit-test
-{ { 2 2 2 2 3 257 7221391 696389341 } } [ 62036506940903331216 brent-factors natural-sort ] unit-test
-{ { 13 4253 15823 32472893749823741 } } [ 28408516453955558205925627 brent-factors natural-sort ] unit-test
+{ { 2 2 2507191691 1231026625769 } } [ 12345678910111213141516 brent-factors ] unit-test
+{ { 2 2 2 2 3 257 7221391 696389341 } } [ 62036506940903331216 brent-factors ] unit-test
+{ { 13 4253 15823 32472893749823741 } } [ 28408516453955558205925627 brent-factors ] unit-test
! Copyright (C) 2021 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel make math math.order math.primes math.ranges
-random ;
+random sorting ;
IN: math.primes.pollard-rho-brent
! https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/
drop { }
] [
[ (brent-factors) ] { } make
- ] if ;
+ ] if natural-sort ;