]> gitweb.factorcode.org Git - factor.git/commitdiff
Do not use Eratosthene sieve if n < 1e6 since we have a static primes list
authorSamuel Tardieu <sam@rfc1149.net>
Wed, 26 Dec 2007 19:35:35 +0000 (20:35 +0100)
committerSamuel Tardieu <sam@rfc1149.net>
Wed, 26 Dec 2007 19:35:35 +0000 (20:35 +0100)
extra/math/erato/erato.factor

index 4993f39e44ff95bee05f4dd325841dd795f7669b..9b9ad5346933905e370a326489107a8e8171071f 100644 (file)
@@ -1,6 +1,7 @@
 ! Copyright (c) 2007 Samuel Tardieu.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: bit-arrays kernel lazy-lists math math.functions math.ranges sequences ;
+USING: bit-arrays kernel lazy-lists math math.functions math.primes.list
+       math.ranges sequences ;
 IN: math.erato
 
 <PRIVATE
@@ -35,4 +36,8 @@ TUPLE: erato limit bits latest ;
 PRIVATE>
 
 : lerato ( n -- lazy-list )
-  <erato> 2 [ drop next-prime ] curry* lfrom-by [ ] lwhile ;
+  dup 1000003 < [
+    0 primes-under-million seq>list swap [ <= ] curry lwhile
+  ] [
+    <erato> 2 [ drop next-prime ] curry* lfrom-by [ ] lwhile
+  ] if ;