Loïc Grenié on Sat, 04 May 2024 10:15:27 +0200


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

Re: Simpler PARI/GP code than this?


     Hi,

On Sat 4 May 2024 at 00:19, Hermann wrote:
On 2024-05-03 18:19, Bill Allombert wrote:
> ...
> Also, if you just the latest GIT master branch, you can use a map for
> o:
>
> maplistput(~M,k,v) = mapapply(~M,k,(~y)->listput(~y,v),()->List(v));
> z(p) = znorder(Mod(2,p));
> o = Map(); forprime(p=3,2^16+1,maplistput(~o,z(p),p));
> foreach(Vec(o),i, print("-", i, ", ", strjoin(Vec(mapget(o,i)), ", "),
> ","));
>
> Cheers,
> Bill.
>
Thanks, good to know about map functions.

I thought about the problem again (I am a big fan t_VEC constructors
with "<-", 2-tuples and vecsort).

There are 6542 primes <2^16:

? primes(9999)[6542..6543]
[65521, 65537]

    You can use primes() with a range: primes([3,2^16]) gives the list
  of primes between 3 and 2^16 (inclusive, even if it does not matter for
  the upper bound in that case). This makes the one-liner slightly more
  readable.

L is of type t_POL which is != compared to any t_INT.

Whitespace is not important, so this one-liner creates the same sequence
of numbers(!):

$ cat gen2.gp
foreach(vecsort([[znorder(Mod(2,p)),p]|p<-primes(6542)[2..6542]]),t,[o,p]=t;if(L!=o,L=o;print1(-o,","));print1(p,","))

    Substitute primes(6542)[2..6542] with primes([3,2^16]), it's clearer.
$ gp -q < gen2.gp | head --bytes 65; echo
-2,3,-3,7,-4,5,-5,31,-7,127,-8,17,-9,73,-10,11,-11,23,89,-12,13,-
$ gp -q < gen2.gp | tail --bytes 65
65292,65293,-65308,65309,-65322,65323,-65356,65357,-65370,65371,
      Best,

           Loïc