Merge branch 'for-slava' of git://git.rfc1149.net/factor into new_ui
commit
ff1e15466f
|
@ -1,13 +1,17 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: binary-search kernel math.primes.list math.ranges sequences
|
USING: binary-search compiler.units kernel math.primes math.ranges
|
||||||
prettyprint ;
|
memoize prettyprint sequences ;
|
||||||
IN: benchmark.binary-search
|
IN: benchmark.binary-search
|
||||||
|
|
||||||
: binary-search-benchmark ( -- )
|
[
|
||||||
1 1000000 [a,b] [ primes-under-million sorted-member? ] map length . ;
|
MEMO: primes-under-million ( -- seq ) 1000000 primes-upto ;
|
||||||
|
] with-compilation-unit
|
||||||
|
|
||||||
! Force computation of the primes list before benchmarking the binary search
|
! Force computation of the primes list before benchmarking the binary search
|
||||||
primes-under-million drop
|
primes-under-million drop
|
||||||
|
|
||||||
|
: binary-search-benchmark ( -- )
|
||||||
|
1 1000000 [a,b] [ primes-under-million sorted-member? ] map length . ;
|
||||||
|
|
||||||
MAIN: binary-search-benchmark
|
MAIN: binary-search-benchmark
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
USING: checksums checksums.crc32 io.encodings.ascii io.files kernel math ;
|
USING: checksums checksums.crc32 io.encodings.ascii io.files kernel math ;
|
||||||
IN: benchmark.crc32
|
IN: benchmark.crc32
|
||||||
|
|
||||||
: crc32-primes-list ( -- )
|
: crc32-file ( -- )
|
||||||
10 [
|
10 [
|
||||||
"resource:extra/math/primes/list/list.factor"
|
"resource:basis/mime/multipart/multipart-tests.factor"
|
||||||
crc32 checksum-file drop
|
crc32 checksum-file drop
|
||||||
] times ;
|
] times ;
|
||||||
|
|
||||||
MAIN: crc32-primes-list
|
MAIN: crc32-file
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
USING: checksums checksums.md5 io.files kernel ;
|
USING: checksums checksums.md5 io.files kernel ;
|
||||||
IN: benchmark.md5
|
IN: benchmark.md5
|
||||||
|
|
||||||
: md5-primes-list ( -- )
|
: md5-file ( -- )
|
||||||
"resource:extra/math/primes/list/list.factor" md5 checksum-file drop ;
|
"resource:basis/mime/multipart/multipart-tests.factor" md5 checksum-file drop ;
|
||||||
|
|
||||||
MAIN: md5-primes-list
|
MAIN: md5-file
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
USING: checksums checksums.sha1 io.files kernel ;
|
USING: checksums checksums.sha1 io.files kernel ;
|
||||||
IN: benchmark.sha1
|
IN: benchmark.sha1
|
||||||
|
|
||||||
: sha1-primes-list ( -- )
|
: sha1-file ( -- )
|
||||||
"resource:extra/math/primes/list/list.factor" sha1 checksum-file drop ;
|
"resource:basis/mime/multipart/multipart-tests.factor" sha1 checksum-file drop ;
|
||||||
|
|
||||||
MAIN: sha1-primes-list
|
MAIN: sha1-file
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Samuel Tardieu
|
|
@ -1,3 +1,5 @@
|
||||||
|
! Copyright (C) 2009 Samuel Tardieu.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: bit-arrays kernel math math.functions math.ranges sequences ;
|
USING: bit-arrays kernel math math.functions math.ranges sequences ;
|
||||||
IN: math.primes.erato
|
IN: math.primes.erato
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Eratosthene sieve
|
|
@ -1,6 +1,8 @@
|
||||||
USING: math.primes.factors tools.test ;
|
USING: math.primes.factors tools.test ;
|
||||||
|
|
||||||
{ { 999983 999983 1000003 } } [ 999969000187000867 factors ] unit-test
|
{ { 999983 999983 1000003 } } [ 999969000187000867 factors ] unit-test
|
||||||
|
{ { } } [ -5 factors ] unit-test
|
||||||
{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 group-factors ] unit-test
|
{ { { 999983 2 } { 1000003 1 } } } [ 999969000187000867 group-factors ] unit-test
|
||||||
{ { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test
|
{ { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test
|
||||||
{ 999967000236000612 } [ 999969000187000867 totient ] unit-test
|
{ 999967000236000612 } [ 999969000187000867 totient ] unit-test
|
||||||
|
{ 0 } [ 1 totient ] unit-test
|
||||||
|
|
|
@ -1,39 +1,36 @@
|
||||||
! Copyright (C) 2007 Samuel Tardieu.
|
! Copyright (C) 2007-2009 Samuel Tardieu.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays kernel lists make math math.primes sequences ;
|
USING: arrays kernel lists make math math.primes sequences ;
|
||||||
IN: math.primes.factors
|
IN: math.primes.factors
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: (factor) ( n d -- n' )
|
: count-factor ( n d -- n' c )
|
||||||
2dup mod zero? [ [ / ] keep dup , (factor) ] [ drop ] if ;
|
0 [ [ 2dup mod zero? ] dip swap ] [ [ [ / ] keep ] dip 1+ ] [ ] while nip ;
|
||||||
|
|
||||||
|
: (factor) ( n d -- n' ) dup [ , ] curry [ count-factor ] dip times ;
|
||||||
|
|
||||||
: (count) ( n d -- n' )
|
: (count) ( n d -- n' )
|
||||||
[ (factor) ] { } make
|
dup [ swap 2array , ] curry
|
||||||
[ [ first ] [ length ] bi 2array , ] unless-empty ;
|
[ count-factor dup zero? [ drop ] ] dip if ;
|
||||||
|
|
||||||
: (unique) ( n d -- n' )
|
: (unique) ( n d -- n' )
|
||||||
[ (factor) ] { } make
|
dup [ , ] curry [ count-factor zero? ] dip unless ;
|
||||||
[ first , ] unless-empty ;
|
|
||||||
|
|
||||||
: (factors) ( quot list n -- )
|
: (factors) ( quot list n -- )
|
||||||
dup 1 > [
|
dup 1 > [
|
||||||
swap uncons swap [ pick call ] dip swap (factors)
|
swap uncons swap [ pick call ] dip swap (factors)
|
||||||
] [ 3drop ] if ;
|
] [ 3drop ] if ; inline recursive
|
||||||
|
|
||||||
: (decompose) ( n quot -- seq )
|
: decompose ( n quot -- seq ) [ lprimes rot (factors) ] { } make ; inline
|
||||||
[ lprimes rot (factors) ] { } make ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: factors ( n -- seq )
|
: factors ( n -- seq ) [ (factor) ] decompose ; flushable
|
||||||
[ (factor) ] (decompose) ; foldable
|
|
||||||
|
|
||||||
: group-factors ( n -- seq )
|
: group-factors ( n -- seq ) [ (count) ] decompose ; flushable
|
||||||
[ (count) ] (decompose) ; foldable
|
|
||||||
|
|
||||||
: unique-factors ( n -- seq )
|
: unique-factors ( n -- seq ) [ (unique) ] decompose ; flushable
|
||||||
[ (unique) ] (decompose) ; foldable
|
|
||||||
|
|
||||||
: totient ( n -- t )
|
: totient ( n -- t )
|
||||||
dup 2 < [
|
dup 2 < [
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Doug Coleman
|
|
|
@ -1,4 +0,0 @@
|
||||||
USING: math.primes memoize ;
|
|
||||||
IN: math.primes.list
|
|
||||||
|
|
||||||
MEMO: primes-under-million ( -- seq ) 1000000 primes-upto ;
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
USING: project-euler.057 tools.test ;
|
||||||
|
|
||||||
|
{ 153 } [ euler057 ] unit-test
|
Loading…
Reference in New Issue