]> gitweb.factorcode.org Git - factor.git/commitdiff
math.primes: Use Pollard-Rho-Brent `brent-factors` as default `factors` word.
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 29 Dec 2021 07:42:43 +0000 (01:42 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 29 Dec 2021 07:55:38 +0000 (01:55 -0600)
Related to #2401

basis/math/primes/factors/factors-docs.factor
basis/math/primes/factors/factors.factor
basis/math/primes/pollard-rho-brent/pollard-rho-brent-tests.factor
basis/math/primes/pollard-rho-brent/pollard-rho-brent.factor

index b22d1ba1a511964c832aa518920e1733c62da473..6ac74b517b910681b9fb7092bbbafdfa28b665a0 100644 (file)
@@ -5,7 +5,7 @@ IN: math.primes.factors
 
 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
index 98cbd9ac9b3bca5b377d40a1cc92ab4a1193548b..ba0c613e32e20ee5289ffecfe989ef1ebb50533b 100644 (file)
@@ -1,8 +1,9 @@
 ! 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
@@ -34,8 +35,7 @@ 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 )
     {
index 7f219556931a73f11d4061a4769c5407e0e06628..cff46202ed6883b4903876ec062c6c18610f52d4 100644 (file)
@@ -3,6 +3,6 @@
 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
index 90f3f960675bcd48bba2777f93f352e1859cf16f..7ea0f673f1ef8baad324aff735e4bf2942c05b49 100644 (file)
@@ -1,7 +1,7 @@
 ! 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/
@@ -65,4 +65,4 @@ DEFER: brent-factors
         drop { }
     ] [
         [ (brent-factors) ] { } make
-    ] if ;
+    ] if natural-sort ;