Charles Greathouse on Wed, 04 Dec 2024 19:52:29 +0100


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

Re: setunion() on a vector of sets


It wouldn't be hard, I think -- just naively calling fold gives something like

GEN
setunion0(GEN x, GEN y)
{
  if(y) return setunion(x, y);
  pari_sp ltop = avma;
  GEN res = genfold(strtofunction("setunion"), gp_call2, x);
  res = gerepilecopy(ltop, p1);
  return res;
}

and it could always be optimized later if there was a need.

On Wed, Dec 4, 2024 at 11:40 AM Max Alekseyev <maxale@gmail.com> wrote:
Dear Bill,

Thank you for the pointer to fold(). 
I think it'd still be beneficial (and uniform in view of other functions) to provide the syntax setunion(x,{y}).

Regards,
Max


On Wed, Dec 4, 2024 at 10:03 AM Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> wrote:
On Wed, Dec 04, 2024 at 09:50:39AM -0500, Max Alekseyev wrote:
> Can setunion() be extended to support a vector of arguments, like gcd() and
> other functions?

You can use fold:

? fold(setunion,[[1,2,3],[2,3,4],[4,5,6]])
%2 = [1,2,3,4,5,6]

Cheers,
Bill.