Karim Belabas on Tue, 06 Feb 2024 17:56:30 +0100


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

Re: vec* functions on lists


* Bill Allombert [2024-02-06 16:47]:
> On Mon, Jan 08, 2024 at 06:04:27AM -0500, Max Alekseyev wrote:
> > In PARI/GP version 2.16.1 I see
> > 
> > ? vecmin(List([1,2,3]))
> > %1 = List([1, 2, 3])
> > 
> > ? vecprod(List([1,2,3]))
> >   ***   at top-level: vecprod(List([1,2,3]))
> >   ***                 ^----------------------
> >   *** vecprod: incorrect type in vecprod (t_LIST).
> >   ***   Break loop: type 'break' to go back to GP prompt
> > 
> > Can vector functions be extended to support List arguments (as if they were
> > vectors)?
> 
> As a rule, I convert lists to vectors as soon as I have finished to fill them.
> I always do
> fun(...) = my(L=List());....;Vec(L); 

1) I did extend vecmin() and vecmax() for lists: the previous behavior (return
a full copy of the list) was both surprising and useless.

2) Status for other vec* commands:

- concat, vecsearch, vecsort, vecmin, vecmax: support t_LISTs

- vecextract: Error. Since we already allow List[a..b] and List[^i],
  vecextract could be extended to return a sublist; on the other hand
  the code is already complicated and this would risk introduce bugs for
  a limited usecase.

- vecprod / vecsum: Error. No particular argument to support or not
  support it. It's a very generic and simple code, easy to test. We
  might as well support t_LISTs.

Cheers,

    K.B.
-- 
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/