--- /dev/null
+Samuel Tardieu
--- /dev/null
+USING: help.markup help.syntax math sequences ;
+IN: math.primes.factors
+
+{ factors group-factors unique-factors } related-words
+
+HELP: factors
+{ $values { "n" "a positive integer" } { "seq" sequence } }
+{ $description { "Return an ordered list of a number's prime factors, possibly repeated." } }
+{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 factors ." "{ 2 2 3 5 5 }" } } ;
+
+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 "USING: math.primes.factors prettyprint ;" "300 group-factors ." "{ { 2 2 } { 3 1 } { 5 2 } }" } } ;
+
+HELP: unique-factors
+{ $values { "n" "a positive integer" } { "seq" sequence } }
+{ $description { "Return an ordered list of a number's unique prime factors." } }
+{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 unique-factors ." "{ 2 3 5 }" } } ;
+
+HELP: totient
+{ $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" } "." } } ;
--- /dev/null
+USING: math.primes.factors tools.test ;
+
+{ { 999983 999983 1000003 } } [ 999969000187000867 factors ] unit-test
+{ { } } [ -5 factors ] unit-test
+{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 group-factors ] unit-test
+{ { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test
+{ 999967000236000612 } [ 999969000187000867 totient ] unit-test
+{ 0 } [ 1 totient ] unit-test
--- /dev/null
+! Copyright (C) 2007-2009 Samuel Tardieu.
+! See http://factorcode.org/license.txt for BSD license.
+USING: arrays combinators kernel make math math.primes sequences ;
+IN: math.primes.factors
+
+<PRIVATE
+
+: count-factor ( n d -- n' c )
+ [ 1 ] 2dip [ /i ] keep
+ [ dupd /mod zero? ] curry [ nip [ 1+ ] dip ] [ drop ] while
+ swap ;
+
+: write-factor ( n d -- n' d )
+ 2dup mod zero? [ [ [ count-factor ] keep swap 2array , ] keep ] when ;
+
+PRIVATE>
+
+: group-factors ( n -- seq )
+ [ 2 [ over 1 > ] [ write-factor next-prime ] [ ] while 2drop ] { } make ;
+
+: unique-factors ( n -- seq ) group-factors [ first ] map ;
+
+: factors ( n -- seq ) group-factors [ first2 swap <array> ] map concat ;
+
+: totient ( n -- t )
+ {
+ { [ dup 2 < ] [ drop 0 ] }
+ [ dup unique-factors [ 1 [ 1- * ] reduce ] [ product ] bi / * ]
+ } cond ; foldable
--- /dev/null
+Prime factors decomposition
+++ /dev/null
-Samuel Tardieu
+++ /dev/null
-USING: help.markup help.syntax math sequences ;
-IN: math.primes.factors
-
-{ factors group-factors unique-factors } related-words
-
-HELP: factors
-{ $values { "n" "a positive integer" } { "seq" sequence } }
-{ $description { "Return an ordered list of a number's prime factors, possibly repeated." } }
-{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 factors ." "{ 2 2 3 5 5 }" } } ;
-
-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 "USING: math.primes.factors prettyprint ;" "300 group-factors ." "{ { 2 2 } { 3 1 } { 5 2 } }" } } ;
-
-HELP: unique-factors
-{ $values { "n" "a positive integer" } { "seq" sequence } }
-{ $description { "Return an ordered list of a number's unique prime factors." } }
-{ $examples { $example "USING: math.primes.factors prettyprint ;" "300 unique-factors ." "{ 2 3 5 }" } } ;
-
-HELP: totient
-{ $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" } "." } } ;
+++ /dev/null
-USING: math.primes.factors tools.test ;
-
-{ { 999983 999983 1000003 } } [ 999969000187000867 factors ] unit-test
-{ { } } [ -5 factors ] unit-test
-{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 group-factors ] unit-test
-{ { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test
-{ 999967000236000612 } [ 999969000187000867 totient ] unit-test
-{ 0 } [ 1 totient ] unit-test
+++ /dev/null
-! Copyright (C) 2007-2009 Samuel Tardieu.
-! See http://factorcode.org/license.txt for BSD license.
-USING: arrays combinators kernel make math math.primes sequences ;
-IN: math.primes.factors
-
-<PRIVATE
-
-: count-factor ( n d -- n' c )
- [ 1 ] 2dip [ /i ] keep
- [ dupd /mod zero? ] curry [ nip [ 1+ ] dip ] [ drop ] while
- swap ;
-
-: write-factor ( n d -- n' d )
- 2dup mod zero? [ [ [ count-factor ] keep swap 2array , ] keep ] when ;
-
-PRIVATE>
-
-: group-factors ( n -- seq )
- [ 2 [ over 1 > ] [ write-factor next-prime ] [ ] while 2drop ] { } make ;
-
-: unique-factors ( n -- seq ) group-factors [ first ] map ;
-
-: factors ( n -- seq ) group-factors [ first2 swap <array> ] map concat ;
-
-: totient ( n -- t )
- {
- { [ dup 2 < ] [ drop 0 ] }
- [ dup unique-factors [ 1 [ 1- * ] reduce ] [ product ] bi / * ]
- } cond ; foldable
+++ /dev/null
-Prime factors decomposition