Gerhard Niklasch on Fri, 27 Mar 1998 12:12:56 +0100


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

Hm, I've just discovered some new primes...


<Presumption>This will be Official Patch 16, even before Karim has had
a chance to see it.</Presumption>

It prevents numbers in the range 2^31...2^32-1 (on 32-bit machines)
or 2^63...2^64-1 (on 64-bit machines) from being all declared prime
by isprime().  (nextprime() and prevprime() were not affected.)

This buglet was introduced with version 2.0.5.alpha.  Don't ask me how
long I had to stare at the code before I saw it.  Having noted a great
many _even_ `primes' up there, and not having tried any odd numbers yet,
I spent ages barking up the mpodd tree...


--- src/basemath/arith1.c.orig  Fri Mar 27 11:52:20 1998
+++ src/basemath/arith1.c       Fri Mar 27 11:52:26 1998
@@ -1193,7 +1193,7 @@
   GEN t,t1,c,c2;
   
   if (!signe(n)) return 0;
-  if (lgefint(n)==3 && n[2]<=3) return !gcmp1(n); /* |n| <= 3 */
+  if (lgefint(n)==3 && (ulong)(n[2])<=3) return !gcmp1(n); /* |n| <= 3 */
   if (!mpodd(n)) return 0;
 
   av = avma; n = absi(n); t=addis(n,-1); r1=vali(t);


(I found this accidentally whilst trying -- in vain so far -- to narrow
down the following.  Yesterday I started a long nested loop, had second
thoughts about it, interrupted it, and caught a segfault immediately
afterwards.  For what it's worth, here's what I typed and saw:
---8<---
{for(i1=2,85,pi1=prime(i1);
for(i2=i1+1,87,pi2=prime(i2);
for(i3=i2+1,89,pi3=prime(i3);
for(i4=i3+1,91,pi4=prime(i4);
for(i5=i4+1,93,pi5=prime(i5);
for(i6=i5+1,99,pi6=prime(i6);N0=pi1*pi2*pi3*pi4*pi5*pi6;
for(i7=i6+1,120,pi7=prime(i7);N=N0*pi7;
if((N-1)%(pi7-1),next);
if((N-1)%(pi6-1),next);
if((N-1)%(pi5-1),next);
if((N-1)%(pi4-1),next);
if((N-1)%(pi3-1),next);
if((N-1)%(pi2-1),next);
if((N-1)%(pi1-1),next);
print(pi1"*"pi2"*"pi3"*"pi4"*"pi5"*"pi6"*"pi7);print(" = "N);
if(((N-1)/(pi7-1)-1)%(1+pi7+sqr(pi7)),next,print1("  ."));
if(((N-1)/(pi6-1)-1)%(1+pi6+sqr(pi6)),print;next,print1("."));
if(((N-1)/(pi5-1)-1)%(1+pi5+sqr(pi5)),print;next,print1("."));
if(((N-1)/(pi4-1)-1)%(1+pi4+sqr(pi4)),print;next,print1("."));
if(((N-1)/(pi3-1)-1)%(1+pi3+sqr(pi3)),print;next,print1("."));
if(((N-1)/(pi2-1)-1)%(1+pi2+sqr(pi2)),print;next,print1("."));
if(((N-1)/(pi1-1)-1)%(1+pi1+sqr(pi1)),print;next);
print(". Hit!")
)))))))}
  ***   user interrupt after 5mn, 39,370 ms.

  ***   segmentation fault: bug in GP (please report).
--->8---
First person to guess correctly why I launched _that_ can have a free
measure of beer on me next time he/she/it happens to see me in Munich. :^)

Enjoy, Gerhard