Karim Belabas on Sun, 12 May 2024 09:56:51 +0200


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

Re: Using builtin PARI operators in gp


* Ilya Zakharevich [2024-05-12 05:06]:
> Up to some extent, one can “reach” the builtin PARI operators in gp:
> 
>   (20:25) gp > ?_+_
>   x+y: sum of x and y.
> 
>   (20:00) gp > ?+_
>   +_: copy and return its argument
> 
> Should not there be a way to specify these functions as arguments to
> other gp functions?  Something like
> 
>   SUM = fold(array, `"_+_");
> 
> ?

There is one already:

  ? alias(plus, "_+_")
  ? fold(plus, [1,2,3])
  %2 = 6

It's even (sort of) documented:

  ?  ???_+_
  alias 

  ?  ??alias

  Defines the symbol newsym as an alias for the symbol sym:
  [...]
  You  are  not restricted to ordinary functions,  as in the above example: to
  alias (from/to) member functions, prefix them with `_.'; to alias operators,
  use  their  internal  name,   obtained by writing _ in lieu of the operators
  argument:  for  instance,  _! and !_ are the internal names of the factorial
  and the logical negation, respectively


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/