# How to replace variable with power?

I would like to replace variable with power. For example,

x^6 /. x^4 -> a + b


which I supposed to get $x^2(a+b)$ but I get $x^6$ and I can't use

x^6 /. x -> Sqrt[Sqrt[a + b]]


because I want to replace $x^4$ only.

• Last@PolynomialReduce[x^6, {x^4 - a - b}, x] seems to work on this very specific problem. It's unlikely you will get a replacement rule to work, since they don't break things down algebraically (into x^4 * x^2, for example). They work on literal matches to patterns. Nov 17 '16 at 3:53
• @MichaelE2 If this question is more complicate, for example, we change $x^4->a+b$ to $x^4->x^2+a+b$, how to deal with this one?
– NaC
Nov 17 '16 at 4:11
• I don't understand: if you want to "replace $x^4$ only," as you state, then x^6 doesn't match what you want, and the answer you get is correct (no replacement happens).
– Jens
Nov 17 '16 at 4:37
• x^6 /. x^n_ :> (a+b)^Quotient[n,4]* x^Mod[n,4] gives you x^2* (a+b)
– Bill
Nov 17 '16 at 4:59
• My 5 cents to this beautiful question: rule = x^n_ /; n >= 4 && n \[Element] Integers -> x^(n - 4)*(a + b); and then x^6 /. rule gives (a + b) x^2. But what would you like to do with x^8 /. rule giving (a + b) x^4? Nov 17 '16 at 7:56

Based on Bill's comment above the following use of TagSetDelayed ensures that multiples of exponent 4 are properly substituted all the time:
f[x_] := a + b + x^2;

If we Expand, the substitution works as well:
Expand[x^3 (a + b + x^2)] (* a x^3 + b x^3 + x^5 *)