Bill Allombert on Mon, 22 Feb 2010 18:09:35 +0100

 Re: Getting the variable number of a lexical local variable

```On Sun, Feb 21, 2010 at 11:47:14PM -0500, Charles Greathouse wrote:
> I still can't seem to make it work properly with multiple variables.
> If I'm in a loop with formal variable y and I check polcoeff0(expr, 3,
> -1) with expr = 3*y + 5*x, it gives me 5, not 3.  I would like a way
> to get 3 when the formal variable is y and 5 when the formal variable
> is x.  Can this be done?

You should not use the prototype code V, but the code n instead.
This will give you the formal variable number (your function need to
take an extra argument of type 'long int').

The prototype code V is for functions that use the code E or I.
Such local variables are not formal variables and does not have a
formal variable number (but they have a lexical variable number).

There are two very different notions:
1) formal variables and polynomials expressions
2) GP variable and GP code.

for 1) you use the code n, G and the function subst (or poleval, etc.)
for 2) you use the code V, E and push_lex/set_lex and closure_evalvoid/closure_evalgen.

> I've attached my source, if this would help anyone understand what I'm
> doing.  Faulhaber(n, a) returns the n-Faulhaber polynomial (in a).
>
> GEN
> sumformal(GEN start, GEN end, GEN expr)

What is prototype code do you use ?

I would suggest to use  "nGGG" and change the prototype to:
sumformal(long vy, GEN start, GEN end, GEN expr)
(vy will be the variable number of y).

Cheers,
Bill.

```