Karim BELABAS on Fri, 6 Dec 2002 18:50:50 +0100 (MET)


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

Re: primetables SEGV


On Fri, 6 Dec 2002, Karim BELABAS wrote:

> On Thu, 5 Dec 2002, Igor Schein wrote:
> > % gp -q -f -p 2156858852
> > Segmentation fault
> >
> > 1 extra check is needed.
> >
> > That's with 32bit binary.
>
> There's this one suspicious couple of lines in initprimes0()
>
>   /* Checked to be enough up to 40e6, attained at 155893 */
>   size = (long) (1.09 * maxnum/log((double)maxnum)) + 145;
>
> For a fact, 'size' is too small in your example, and
> maxnum = 2156858852 > 40e6
>
> Gerhard what was the basis for your bound ?

OK, I understand now: this is a weak upper bound for pi(x); it can be
made tighter by using Rosser-Shoenfeld bound ( x/log(x) [ 1 + 3/2log(x) ] ).

This bounds the number of _primes_ less than x. But after Ilya's patches,
primes may require more than one char, whenever the difference between two
consecutive primes is >= 255. And this occurs frequently in this range.

Hum. I don't see an easy way out, except using a naive growarray [ malloc
twice Rosser-Shoenfeld bound. When the bound is reached, copy everything
in an array twice as large ].

On the other hand, I do not see any application for huge precomputed prime
lists. So it might be a much better idea to disable huge maxnum values, and
extend forprime() and friends to use the initprimes() mechanism to quickly
generated online prime numbers (up to primelimit^2).

Opinions ?

    Karim.
-- 
Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
--
PARI/GP Home Page: http://www.parigp-home.de/