# Replace a an expression in Exponential only but not in other terms?

I want to replace the A in the Exponent only but when I use the replace rule it also replaces the Derivative of A.

Exp[A + 2 B] (3 Derivative[1][A] + 4 Derivative[2][A]) /. A -> A + 6 Subscript[f, 3]


which gives me the output

Times[Power[E,Plus[A,Times[2,B],Times[6,Subscript[f,3]]]],Plus[Times[3,Derivative[1][Plus[A,Times[6,Subscript[f,3]]]]],Times[4,Derivative[2][Plus[A,Times[6,Subscript[f,3]]]]]]]


I want the output to show like this

Exp[A + 6 Subscript[f, 3] + 2B] (3 Derivative[1][A] + 4 Derivative[2][A])


Any idea?. Thanks a lot.

• I typically do that like this: Exp[A + 2 B] (3 Derivative[1][A] + 4 Derivative[2][A]) /. Exp[a_] :> Exp[a /. A -> A + 6 Subscript[f, 3]]. Sort of nested replacement. – march Dec 20 '18 at 16:13

You can save the derivatives by prepending another rule to the one you already use. I.e. use:

rules = {e : Derivative[_][A] -> e, A -> A + 6 Subscript[f, 3]}
yourExpression /. rules


Try being more explicit

Exp[A + 2 B] (3 Derivative[1][A] + 4 Derivative[2][A]) /.
Exp[A + 2 B] -> Exp[A + 6 Subscript[f, 3] + B]


E^(A + B + 6 Subscript[f, 3]) (3 Derivative[1][A] + 4 A^[Prime][Prime])

Does that help?

On a seperate point I would recommend against using Subscript. You can simply use f[3] and this works well if you need to have a symbolic value in the subscript i.e. f[n]

I hope you enjoy Mathematica.