Question: subsitution of a variable with a certain power in a multivariable polynomial.

Hi Everyone, I am trying to make a special substitution which neither subs nor algsubs seem to be able to make. I have long polynomials (maybe with 3000 terms), but for the sake of clarity here is an example with a short one: Poly:=a[1]^3+a[1]*a[3]^2+a[2]+a[1]*a[2]; Now I would like to substitute a[1] by a[1]^2, but only in the terms that have a[1] (to the power of one). (It is important that the a[1]^3 in the original Poly is not changed to a[1]^6 ). So after substitution the polynomial should become: Poly:=a[1]^3+a[1]^2*a[3]^2+a[2]+a[1]^2*a[2]; Otherwise, the only thing I can think of is a little procedure. Say the original power of a[1] is a[1]^s and we want to change all the terms that contain "a[1]^s" to "a[1]^r". Then we can do: s := 1; r := 2; for i to nops(Poly) do P[i] := op(Poly)[i]; if degree(P[i], a[1]) = s then P[i] := P[i]*a[1]^r/a[1]^s else fi: od: NewPoly:= add(A[j], j = 1 .. nops(Poly)); But, is there a more efficient way? (especially because I may have to subsitute more than one variable). Thank you for your help and reading, Al
Please Wait...