Bill Allombert on Tue, 14 May 2019 21:52:02 +0200


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

Re: Conversion (MATHEMATICA to PARI/GP)


On Tue, May 14, 2019 at 07:23:56PM +0000, Predrag Terzic wrote:
> For more info see this post : https://mathoverflow.net/q/286304

In this case it is easier to rewrite it in GP from scratch.

xmat(r,n) = [2*x, -1; 1, 0]*Mod(1,x^r-1)*Mod(1,n)
smallestr(n)=
{ 
  if(n==1 || n%2==0, return(0));
  forprime(r = 3, oo,
    my(u=n%r);
    if (u==0 && r < n, return(0));
    if (u!=0 && u!=1 && u!=r-1, return(r)));
}

myisprime(n)=
{
  my(r = smallestr(n));
  if (r == 0, return(n == 2));
  my(xp = xmat(r,n)^n*[x,1]~);
  xp[2] == Mod(x*Mod(1,n),x^r-1)^n;
}
for(n=1,100,if(myisprime(n),print(n)))

Cheers,
Bill.