# Replace pattern for exponentials

Ultimately, I want to replace every Exp[(const) w[i,j]] to T[i,j] and Exp[-(const) w[i,j]] to 1/T[i,j] in the following expression

(-1 + (E^(w[1, 0] - 1.55432 w[1, 1]) -
E^(-w[1, 0] + 1.55432 w[1, 1]))^2/(E^(w[1, 0] - 1.55432 w[1, 1]) +
E^(-w[1, 0] + 1.55432 w[1, 1]))^2)


However, when I use the replacement rule

/. (E^(x[i_, j_] w[i_, j_] + x[m_, l_] w[m_, l_]))-> (E^(x[i, j] w[i, j]) E^(x[m, l] w[m, l]))


as an intermediate step, the replacement does not do anything on the expression. Any suggestion?

Thanks, SJS

• Mathematica automatically simplifies Exp[a] Exp[b] to Exp[a + b]. You if you make an intermediate step where you replace E by exp (lowercase is important!), then do your replacement (or something like it) with exp in place of E, it should work. Alternatively, you could wrap the expression with Inactivate or something. See my answer here for one possibility. – march May 2 '16 at 20:16

## 1 Answer

expr = (-1 + (E^(w[1, 0] - 1.55432 w[1, 1]) - E^(-w[1, 0] + 1.55432 w[1, 1]))^2 /
(E^(w[1, 0] -  1.55432 w[1, 1]) + E^(-w[1, 0] + 1.55432 w[1, 1]))^2) expr /. Power[E, Plus[x_, y__]] :> Inactive[Times][Power[E, x], Power[E, y]]/.
{Power[E, Times[c_, w[i_, j_], ___]] :> Power[T[i, j], Sign[c]],
Power[E,  w[i_, j_]] :>T[i, j]} //Activate For version 9:

expr /. Power[E, Plus[x_, y__]] :> times[Power[E, x], Power[E, y]] /.
{Power[E,   Times[c_, w[i_, j_], ___]] :> Power[T[i, j], Sign[c]],
Power[E, w[i_, j_]] :> T[i, j]} /. times -> Times


Update: A slightly more general form allows arbitrary number of terms in the exponent:

f = # /. Power -> power /.  power[E, x : PatternSequence[___]] :> (
Times @@ (power[E, #] & /@ x)) /.
{power[E, Times[c_, w[i_, j_], ___]] :> Power[T[i, j], Sign[c]],
power[E, w[i_, j_]] :> T[i, j]} /. power -> Power &
f @ expr


same output as above

 expr2 = (-1 + (E^(w[1, 0] - 1.55432 w[1, 1] + 2 w[1, 2]) -
E^(-w[1, 0] + 1.55432 w[1, 1] - 3 w[3, 1]))^2/
(E^(w[1, 0] - 1.55432 w[1, 1]) + E^(-w[1, 0] + 1.55432 w[1, 1]))^2) f @ expr2 • I was also having similar problem, @kglr. How is it extended to the case when one has more than two terms in each of the exponentials? Say, the number of terms is arbitrary and not known a priori? – dbm May 2 '16 at 20:24
• @dbm, good question. I will post an update if i can come up with a generalization. – kglr May 2 '16 at 21:22