I don't think that commit 302867c9a70b32e8a6da82dd4df72589a63dc4a4
which patches the documentation is right.

The problem that Rupert mentionned is that using
: problem ( n -- ? ) [ sieve ] [ swap marked-prime? ] bi ;
throws an exception if n is a multiple of 30 (his number was
2010=30*67) because the generated sieve is too small.

The documentation for sieve says that n should be an odd number here :
HELP: sieve
{ $values { "n" "the greatest odd number to consider" } { "arr" "a bit
array" } }
...

Using sieve with an even number (and a multiple of 30 is obviously
even) is undocumented.

However, the patched documentation now says that marked-prime? needs
an odd number, which is a very artificial restriction. In fact, the
marked-prime? algorithm is designed to work with even numbers because
they are masked (look at the constant "masks").

I would accept Rupert's patch that makes sieve work with any integer >
0 with no performance penalty, and change the documentation for sieve
and marked-prime? to remove the restriction that the number should be
odd.

Samuel, what do you think ?

Jon



On Thu, Oct 21, 2010 at 3:11 PM, Jon Harper <jon.harpe...@gmail.com> wrote:
> The doc says that n should be an odd number. For example,
> "2011 2011 sieve marked-prime?" works
>
> But maybe the word should be changed to work with even number as well.
>
> Also, there's a typo in the documentation. Here's a patch that fixes it:
> ----------------------------
> diff --git a/basis/math/primes/erato/erato-docs.factor
> b/basis/math/primes/erato/erato-docs.factor
> index 1e32818..9279f8f 100644
> --- a/basis/math/primes/erato/erato-docs.factor
> +++ b/basis/math/primes/erato/erato-docs.factor
> @@ -3,7 +3,7 @@ IN: math.primes.erato
>
>  HELP: sieve
>  { $values { "n" "the greatest odd number to consider" } { "arr" "a
> bit array" } }
> -{ $description "Apply Eratostene sieve up to " { $snippet "n" } ".
> Primality can then be tested using " { $link sieve } "." } ;
> +{ $description "Apply Eratostene sieve up to " { $snippet "n" } ".
> Primality can then be tested using " { $link marked-prime? } "." } ;
>
>  HELP: marked-prime?
>  { $values { "n" "an integer" } { "arr" "a byte array returned by " {
> $link sieve } } { "?" "a boolean" } }
> ----------------------------
> Jon
>
> On Thu, Oct 21, 2010 at 12:50 PM, Rupert Swarbrick <rswarbr...@gmail.com> 
> wrote:
>> I bumped into this today and I've attached a patch with test-case.
>>
>> Cheers,
>>
>> Rupert
>>
>>
>> ------------------------------------------------------------------------------
>> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
>> Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
>> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
>> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
>> http://p.sf.net/sfu/nokia-dev2dev
>> _______________________________________________
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>>
>

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to