Charles Greathouse on Mon, 22 Feb 2010 19:18:22 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Getting the variable number of a lexical local variable |
> 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). I guess what I was trying to find was the lexical variable number, then. I do want to use a V prototype code so that a user (in GP) can type sumformal(y=1, n, x*y^3 + y) and I can pull the relevant variable out of the polynomial. Charles Greathouse Analyst/Programmer Case Western Reserve University On Mon, Feb 22, 2010 at 11:42 AM, Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr> wrote: > 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. >