New GP function mapapply

Bill Allombert <[email protected]> Sun, 14 Jan 2024 17:36:16 +0100
Newsgroups gmane.comp.mathematics.pari.devel
Message-ID <ZaQNgPvB8ftsAv3c@seventeen>
Dear PARI developers,

I have added a new GP function mapapply:

mapapply(~M,x,f):

   Applies the closure f to the image y of x by the map M and returns the evaluation of f. The closure f is eventually allowed to modify
the components of y in place.

   To apply f to all entries of M use apply(f, M) instead.

There are two main use cases: * performing a computation on a value without copying it:

   ? M=Map();mapput(~M,"a",mathilbert(100));
   ? for(i=1,1000,matsize(mapget(M,"a"))) \\ Slow
   ? for(i=1,1000,mapapply(M,"a",matsize)) \\ Fast

* modifying the components of the value in place, for example to append an element to a value of a map of lists.   This require to use ~
in the function declaration.

   ? maplistput(~M,k,v) = mapapply(~M,k,(~y)->listput(~y,v));
   ? M = Map(["a",List(); "b",List()]);
   ? maplistput(~M,"a",1234); M
   %3 = Map(["a",List([1234]);"b",List([])])

Cheers,
Bill