Given a polynomial, for instance A+A^2+A^3, how can I replace A->x, ending with x+A^2+A^3?


The problem is I cannot do it without also replacing the higher-order terms. For example, A+A^2+A^3 /.{A^exp_/;exp==1->x} does nothing. Another obvious choice, A+A^2+A^3 /.{A^1->x}, returns x+x^2+x^3. On the other hand, the inverse works: A+A^2+A^3 /.{A^exp_/;exp!=1->x^exp} does lead to A+x^2+x^3.

This leads to a second question: Why does A^1 matches any power of A but A^x_/;x==1 matches nothing?

  • $\begingroup$ How would you want to treat constants? eg 1 + A + A^2 + A^3 $\endgroup$ Commented Oct 24, 2022 at 13:44

3 Answers 3


What about

poly + SeriesCoefficient[poly,{A,0,1}]*(x-A)
rule = {{b_. Power[c_, d_] :> b Power[c, d], a_. A :> a x}};

A + A^2 + A^3 /. rule

{A^2 + A^3 + x}

a A + 4 A^2 + A^3 /. rule

{4 A^2 + A^3 + a x}

ReplaceAll[w A + x A^2 + y A^3, {p_Power :> p, A -> z}]
A^2 x + A^3 y + w z

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.