From 8bc631f5ed3bbb4f7df8025ec149d6740a2495da Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Mon, 14 Jan 2008 11:33:08 -0500 Subject: [PATCH] Rename count-factors to group-factors and update docs --- extra/math/primes/factors/factors-docs.factor | 25 +++++++++++-------- .../math/primes/factors/factors-tests.factor | 2 +- extra/math/primes/factors/factors.factor | 2 +- extra/project-euler/common/common.factor | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/extra/math/primes/factors/factors-docs.factor b/extra/math/primes/factors/factors-docs.factor index 2238420d32..f5b14b5a5a 100644 --- a/extra/math/primes/factors/factors-docs.factor +++ b/extra/math/primes/factors/factors-docs.factor @@ -1,20 +1,23 @@ -USING: help.markup help.syntax ; +USING: help.markup help.syntax math sequences ; IN: math.primes.factors -{ factors count-factors unique-factors } related-words +{ factors group-factors unique-factors } related-words HELP: factors -{ $values { "n" "a positive integer" } { "seq" "a sequence" } } -{ $description { "Factorize an integer and return an ordered list of factors, possibly repeated." } } ; +{ $values { "n" "a positive integer" } { "seq" sequence } } +{ $description { "Return an ordered list of a number's prime factors, possibly repeated." } } +{ $examples { $example "300 factors ." "{ 2 2 3 5 5 }" } } ; -HELP: count-factors -{ $values { "n" "a positive integer" } { "seq" "a sequence" } } -{ $description { "Return a sequence of pairs representing each factor in the number and its corresponding power." } } ; +HELP: group-factors +{ $values { "n" "a positive integer" } { "seq" sequence } } +{ $description { "Return a sequence of pairs representing each prime factor in the number and its corresponding power (multiplicity)." } } +{ $examples { $example "300 group-factors ." "{ { 2 2 } { 3 1 } { 5 2 } }" } } ; HELP: unique-factors -{ $values { "n" "a positive integer" } { "seq" "a sequence" } } -{ $description { "Return an ordered list of unique prime factors." } } ; +{ $values { "n" "a positive integer" } { "seq" sequence } } +{ $description { "Return an ordered list of a number's unique prime factors." } } +{ $examples { $example "300 unique-factors ." "{ 2 3 5 }" } } ; HELP: totient -{ $values { "n" "a positive integer" } { "t" "an integer" } } -{ $description { "Return the number of integers between 1 and " { $snippet "n-1" } " relatively prime to " { $snippet "n" } "." } } ; +{ $values { "n" "a positive integer" } { "t" integer } } +{ $description { "Return the number of integers between 1 and " { $snippet "n-1" } " that are relatively prime to " { $snippet "n" } "." } } ; diff --git a/extra/math/primes/factors/factors-tests.factor b/extra/math/primes/factors/factors-tests.factor index 71bdd56a81..70b905f4ab 100644 --- a/extra/math/primes/factors/factors-tests.factor +++ b/extra/math/primes/factors/factors-tests.factor @@ -1,6 +1,6 @@ USING: math.primes.factors tools.test ; { { 999983 999983 1000003 } } [ 999969000187000867 factors ] unit-test -{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 count-factors ] unit-test +{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 group-factors ] unit-test { { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test { 999967000236000612 } [ 999969000187000867 totient ] unit-test diff --git a/extra/math/primes/factors/factors.factor b/extra/math/primes/factors/factors.factor index 66ec748535..2f70ab24b4 100644 --- a/extra/math/primes/factors/factors.factor +++ b/extra/math/primes/factors/factors.factor @@ -27,7 +27,7 @@ PRIVATE> : factors ( n -- seq ) [ (factor) ] (decompose) ; foldable -: count-factors ( n -- seq ) +: group-factors ( n -- seq ) [ (count) ] (decompose) ; foldable : unique-factors ( n -- seq ) diff --git a/extra/project-euler/common/common.factor b/extra/project-euler/common/common.factor index 6279606481..67cce7d31a 100644 --- a/extra/project-euler/common/common.factor +++ b/extra/project-euler/common/common.factor @@ -88,7 +88,7 @@ PRIVATE> ! The divisor function, counts the number of divisors : tau ( m -- n ) - count-factors flip second 1 [ 1+ * ] reduce ; + group-factors flip second 1 [ 1+ * ] reduce ; ! Optimized brute-force, is often faster than prime factorization : tau* ( m -- n )