Bill Allombert on Fri, 22 Sep 2006 11:17:56 +0200

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

Re: Multiple substitutions (wishlist)

On Thu, Sep 21, 2006 at 04:37:19PM +0200, Jeroen Demeyer wrote:
> Hello list,
> Many times I have wanted to do some kind of "multiple simultaneous 
> subst()" in PARI/GP.  I mean the following:
> gp> subst(x^2 + 3*y, x,y, y,z)
> %1 = y^2 + 3*z
> Where the 2nd argument is replaced by the 3rd, the 4th by the 5th, and 
> so on...

You are looking for the function substvec()

? ??substvec

   v being a vector of monomials (variables),  w a vector of expressions of the
same  length,   replace in the expression x all occurences of v_i by w_i.   The
substitutions  are  done  simultaneously;    more precisely,  the v_i are first
replaced by new variables in x, then these are replaced by the w_i:

   ? substvec([x,y], [x,y], [y,x])
   %1 = [y, x]
   ? substvec([x,y], [x,y], [y,x+y])
   %2 = [y, x + y]     \\ not [y, 2*y]
   The library syntax is gsubstvec(x,v,w).

> I have absolutely no idea how easy/difficult it would be to implement 
> this, but I would appreciate it :-)

This is not possible to implement in a robust way in the old variable
priority model. I hope to introduce a new model that allow that. The
patch I posted recently is a part of that.

> One non-trivial point it that the subst()s have to happen 
> simultaneously, to make things like subst(f, x,y, y,x) possible (which 
> would swap x and y in the expression f).

This actually works.