| Bill Allombert on Fri, 09 Jun 2023 13:09:27 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: efficient determination of smallest quadratic non-residue / t++ works, t=nextprime(t) hangs |
On Fri, Jun 09, 2023 at 11:26:25AM +0200, hermann@stamm-wilbrandt.de wrote:
> 1)
> If I replace "t++" in
>
> smallest_qnr(m) = {
> t=2;
> while(kronecker(t, m) != -1, t++;);
> t;
> }
>
> with "t=nextprime(t)", computation hangs for the bigger numbers "n".
> Is that a bug?
No for historical reason nextprime(p)=p, so you should do nextprime(p+1).
But it is much better to use forprime
forprime(t=2,oo,if( kronecker(t, m)==-1, return(t)));
or
forprime(tt=2,oo,if( kronecker(tt, m)==-1, t=tt; break()));
> 2)
> Is there a better way (like C/C++/Python argv) than I did to pass value of
> "n" when executing a script with "gp .... < script.gp"?
Not really, but you can use environment variables.
env GPARG1="3756801695685 * 2 ^ 666669 + 1" gp < script.gp
and in your script do
n = eval(Strexpand("$GPARG1"));
to get n.
> Is "if (type(n) != "t_INT", ...)" a good way to deal with input errors?
Yes.
Cheers,
Bill.