Ilya Zakharevich on Sat, 27 Jan 2024 04:08:44 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Big GOTCHAs WITH forprime() — segfault


On Thu, Jan 25, 2024 at 03:12:37PM +0100, Bill Allombert wrote:
> So it seems the first bad commit is
> 
> commit a286058de199e0477bb51d82a3f092ca71a47ad9
> Author: Karim Belabas <Karim.Belabas@math.u-bordeaux1.fr>
> Date:   Mon May 26 11:56:00 2014 +0200
> 
>     25- (gp -p N) or (primelimit=N in gprc_ for N >= 436273290 resulted in an
>        incorrect primetable. N.B. Such commands are now useless: needed primes
>        are produced dynamically anyway.

> the "obvious" fix is
> 
> -    NEXT_PRIME_VIADIFF(p, d); /* starts at p = 3 */
> +    NEXT_PRIME_VIADIFF_CHECK(p, d); /* starts at p = 3 */
> 
> which leads to

No, I think this ends the sieving too early (or has a potential to do
so).  (And adds an extra conditional in the tight loop. — Though this
may be not THAT important nowadays…)

The “more” obvious fix is:

  • Make PARI know (and REPORT!) the correct primelimit;
  • Fix the code which decides whether to call this function. 

The current logic is not able to detect hitting the last known
prime — so one should plan to stop at last␣known␣prime^2-1.

Hope this helps,
Ilya