Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to understand the behavior of Mathematica for the following code.

E^(-m0 + e1/2 + 1/2 (-e1 - e2) + e2/ 2 + (e1 + e2)/2) /. {Power[E, a___] -> Power[E, Expand[a]]}

I expected to see

E^(-m0 + e1/2 + e2/2)

but instead, Mathematica returns

E^(-m0 + e1/2 + 1/2 (-e1 - e2) + e2/ 2 + (e1 + e2)/2)

Why is it? If there is any suggestion, could you reply to me? Thanks a lot.

share|improve this question

closed as off-topic by Sjoerd C. de Vries, rasher, Kuba, m_goldberg, Artes Apr 29 at 0:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Sjoerd C. de Vries, rasher, Kuba, m_goldberg, Artes
If this question can be reworded to fit the rules in the help center, please edit the question.

    
You need to use RuleDelayed and it will work the way you expect –  gpap Apr 28 at 11:07
    
I will add to the above that RuleDelayed can be invoked by replacing -> with :>. –  Saran Tunyasuvunakool Apr 28 at 11:20
    
It works! Thanks a lot. –  Joonho Kim Apr 28 at 11:35
    
I will add to the above that Rule doesn't work here because the righthand side is evaluated before the replacement takes place. The rhs Expand[a] results in just a. –  Sjoerd C. de Vries Apr 28 at 11:38
add comment