I have some terms contain



(a^2)^p_. ->  -dx[p] Exp[-x[p]] x^2

but Mathematica only replace power 2 of a. how can I fix this problem

1/a^4 + a + a^6 - E^-x[1] x^2 dx[1]

The issue is the form of the exponents after expansion: ww looks like Plus[Power[a, -4], a, Power[a, 2], Power[a, 6]] (see FullForm in the documentation).

When you use a replacement of (a^2)^p_, it looks to replace terms which appear as Power[Power[a, 2], p_]. These aren't the same thing to the symbolic parser, even if mathematically they can often be intended to mean the same thing.

You can work around this by instead searching for powers which are divisible by 2:

ww /. (a^p_ /; Divisible[p, 2] :> -dx[p/2] Exp[-x[p/2]] x^2)

This can be read roughly as: ww but replace a^p_ where p is divisible by 2 with the expression (but substituting in p/2 where appropriate).

  • $\begingroup$ dear @eyorble, thank you so much for this helpful answer. $\endgroup$ – asal Aug 29 '20 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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