3
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – march
    May 2, 2016 at 20:16

1 Answer 1

5
$\begingroup$
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)

Mathematica graphics

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

Mathematica graphics

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)

Mathematica graphics

f @ expr2

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – dbm
    May 2, 2016 at 20:24
  • 1
    $\begingroup$ @dbm, good question. I will post an update if i can come up with a generalization. $\endgroup$
    – kglr
    May 2, 2016 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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