Bill Allombert on Thu, 30 May 2024 11:57:54 +0200


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

Re: Using builtin PARI operators in gp


On Wed, May 29, 2024 at 04:14:07PM -0700, Ilya Zakharevich wrote:
> Additionally, I have no clue what alias() is actually doing.  For

Think
#define SIN sin

> example, is
>   alias(SIN, sin)
> a “glorified version” of SIN = sin, or of SIN = builtin::sin?  What

No.

When you do sin (without () ) in GP it need to generate a GP closure that emulate
the C function interface.

install(closure_disassemble,vG,disassemble)
? disassemble(sin)
00001   checkargs       0x1
00002   precreal
00003   callgen2        sin
? disassemble(x->sin(x))
00001   getargs         1
00002   pushlex         -1
00003   precreal
00004   callgen2        sin
? Sin=sin
%2 = sin
? disassemble(x->Sin(x))
00001   getargs         1
00002   pushdyn         Sin
00003   pushlex         -1
00004   calluser        1
? alias(SIN,sin)
? disassemble(x->SIN(x))
00001   getargs         1
00002   pushlex         -1
00003   precreal
00004   callgen2        sin

? for(i=1,10^7,sin(0))
? ##
  ***   last result computed in 556 ms.
? for(i=1,10^7,Sin(0))
? ##
  ***   last result computed in 845 ms.
? for(i=1,10^7,SIN(0))
? ##
  ***   last result computed in 554 ms.

> about
>   alias(SIN, "sin")

Same as alias(SIN, sin)

> ?  Or: is
>   Sin = sin; alias(SIN, Sin)
> (ALWAYS) the same as alias(SIN, sin) ?

No. 

Cheers,
Bill.