I have a horrid expression, which is basically a sum of exponents with coefficients. Here's a taste:

What I want to do is to replace ks with another expression, but to do so only when ks appears outside an exponent. Alternatively, I want to preform this replacement, but keep the arguments of all exponents unchanged.
For example I want
SpecialReplace[(ks-foo*bar) Exp[ks^foo-bar],ks->Y]
to yield
(Y-foo*bar) Exp[ks^foo-bar]
How would I do that?
Answer
Use two rules in the replacement with a dummy rule to replace exponents with themselves.
Along the lines of.
(ks-foo*bar) Exp[ks^foo-bar] /. {x:Exp[___]->x, ks->Y}
So anything that is an exponent is 'caught' by the first rule and the kx replacement rule doesn't get a look in.
Comments
Post a Comment