Ilya Zakharevich on Thu, 25 Jan 2024 13:40:15 +0100


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

Re: Big GOTCHAs WITH forprime()


On Thu, Jan 25, 2024 at 10:39:35AM +0100, Bill Allombert wrote:
> >   https://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=2520#10
> 
> Yes, I was running the immediate running version but without
> primelimit=400000000000
> 
> Now on linux, with GP 2.15.4:
> 
> % gp -qf --default primelimit=400000000000
> ? my((f(s)=forprime(p=s,s+10^8,)),n=98,x=190333*10^12,y=x+2*10^12,t,z,t0);while(n>0,t=getwalltime();n-=1+if(if(1,f(z=(x+3*y)/4);20000<(t0=-(t-(t=getwalltime())))),x=z;4,y=z;0);print([1.*x,1.*y,t0,n]))
> 
> [190333000000000000.00000000000000000000, 190334500000000000.00000000000000000000, 10650, 97]
> [190334125000000000.00000000000000000000, 190334500000000000.00000000000000000000, 32178, 92]
> [190334125000000000.00000000000000000000, 190334406250000000.00000000000000000000, 10259, 91]
> [190334125000000000.00000000000000000000, 190334335937500000.00000000000000000000, 10436, 90]
> [190334125000000000.00000000000000000000, 190334283203125000.00000000000000000000, 10284, 89]
> [190334125000000000.00000000000000000000, 190334243652343750.00000000000000000000, 10629, 88]
> [190334125000000000.00000000000000000000, 190334213989257812.50000000000000000000, 10562, 87]

Thanks for reporting back!  However:

I repeat the 4th time:
     This is not the code mentioned above, in 2520#10.
(And I repeat the 3rd time: the bisecting is timing-sensitive, so 20000 should be
tuned up correspondingly. — But this is not needed for #10, where
bisecting already reached ∼pre␣prime␣gap(282)^2.  Compare with
      https://en.wikipedia.org/wiki/Prime_gap#Numerical_results
 . As reported there, bisecting segfaults on ≈190334138131456478.) 

> % valgrind gp -qf --default primelimit=400000000000
> ==135725== Memcheck, a memory error detector
> ==135725== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
> ==135725== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
> ==135725== Command: gp -qf --default primelimit=400000000000
> ==135725==
> ? my((f(s)=forprime(p=s,s+10^8,)),n=98,x=190333*10^12,y=x+2*10^12,t,z,t0);while(n>0,t=getwalltime();n-=1+if(if(1,f(z=(x+3*y)/4);20000<(t0=-(t-(t=getwalltime())))),x=z;4,y=z;0);print([1.*x,1.*y,t0,n]))
> [190334500000000000.00000000000000000000, 190335000000000000.00000000000000000000, 93983, 93]
> [190334875000000000.00000000000000000000, 190335000000000000.00000000000000000000, 93132, 88]
> [190334968750000000.00000000000000000000, 190335000000000000.00000000000000000000, 92726, 83]

Likewise (but — if wanted — the timing for bisecting should be tuned “in the other direction”).

Hope this helps,
Ilya