]> gitweb.factorcode.org Git - factor.git/commitdiff
Move math.primes.factors from extra to basis
authorSamuel Tardieu <sam@rfc1149.net>
Wed, 7 Jan 2009 22:01:27 +0000 (23:01 +0100)
committerSamuel Tardieu <sam@rfc1149.net>
Wed, 7 Jan 2009 22:01:27 +0000 (23:01 +0100)
basis/math/primes/factors/authors.txt [new file with mode: 0644]
basis/math/primes/factors/factors-docs.factor [new file with mode: 0644]
basis/math/primes/factors/factors-tests.factor [new file with mode: 0644]
basis/math/primes/factors/factors.factor [new file with mode: 0644]
basis/math/primes/factors/summary.txt [new file with mode: 0644]
extra/math/primes/factors/authors.txt [deleted file]
extra/math/primes/factors/factors-docs.factor [deleted file]
extra/math/primes/factors/factors-tests.factor [deleted file]
extra/math/primes/factors/factors.factor [deleted file]
extra/math/primes/factors/summary.txt [deleted file]

diff --git a/basis/math/primes/factors/authors.txt b/basis/math/primes/factors/authors.txt
new file mode 100644 (file)
index 0000000..f3b0233
--- /dev/null
@@ -0,0 +1 @@
+Samuel Tardieu
diff --git a/basis/math/primes/factors/factors-docs.factor b/basis/math/primes/factors/factors-docs.factor
new file mode 100644 (file)
index 0000000..f9fe4d5
--- /dev/null
@@ -0,0 +1,23 @@
+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" } "." } } ;
diff --git a/basis/math/primes/factors/factors-tests.factor b/basis/math/primes/factors/factors-tests.factor
new file mode 100644 (file)
index 0000000..f247683
--- /dev/null
@@ -0,0 +1,8 @@
+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
diff --git a/basis/math/primes/factors/factors.factor b/basis/math/primes/factors/factors.factor
new file mode 100644 (file)
index 0000000..05d6b26
--- /dev/null
@@ -0,0 +1,29 @@
+! 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
diff --git a/basis/math/primes/factors/summary.txt b/basis/math/primes/factors/summary.txt
new file mode 100644 (file)
index 0000000..1440ddd
--- /dev/null
@@ -0,0 +1 @@
+Prime factors decomposition
diff --git a/extra/math/primes/factors/authors.txt b/extra/math/primes/factors/authors.txt
deleted file mode 100644 (file)
index f3b0233..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Samuel Tardieu
diff --git a/extra/math/primes/factors/factors-docs.factor b/extra/math/primes/factors/factors-docs.factor
deleted file mode 100644 (file)
index f9fe4d5..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-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" } "." } } ;
diff --git a/extra/math/primes/factors/factors-tests.factor b/extra/math/primes/factors/factors-tests.factor
deleted file mode 100644 (file)
index f247683..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-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
diff --git a/extra/math/primes/factors/factors.factor b/extra/math/primes/factors/factors.factor
deleted file mode 100644 (file)
index 05d6b26..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-! 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
diff --git a/extra/math/primes/factors/summary.txt b/extra/math/primes/factors/summary.txt
deleted file mode 100644 (file)
index 1440ddd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Prime factors decomposition