Message Boards Message Boards

5 Replies
1 Total Likes
View groups...
Share this post:

Recursive ReplaceRepeated fails

Posted 10 years ago
Hi !

I've developed a little function to split an exponential in 2 if its argument is a sum :
replace[e_] := e //. Exp[x_ + y_] :> HoldForm[E^x E^y];

Here is the Failing case :
xx = ReleaseHold[
   E^(-(((1 + r) (t - t1))/(2 Q tau)) - t/tau1 - t1/tau1)];
xx = replace[xx]; xx = replace[xx]
Here is the reult :

May I ask you why the function does not operate recursively despite the use of  //. (ReplaceRepeated[ ]) ?
POSTED BY: Sylvain Rousseau
5 Replies
You could do 
output /. Expand -> Identity
It should do it automatically though....
POSTED BY: Sander Huisman
Thanks Sanders !
POSTED BY: Sylvain Rousseau
If you look closely at the output of replace, you see that there is nothing that matches the form:
Exp[x_ + y_]
Instead, you only see "E" to the power of  "some product". Yes this might be a product of sums, but Mathematica will not expand out the products unless it is told to do so.

You may consider using Expand first:
exponent = Expand[(-(((1 + r) (t - t1))/(2 Q tau)) - t/tau1 - t1/tau1)]

You can then run:
Or you may consider building Expand into your definition of replace.
POSTED BY: Sean Clarke
Many thanks Sean !
Absent-mindedness affair !
POSTED BY: Sylvain Rousseau
Dear Sean,

I 'am trapped in a new pitfall.. here my new code :
replace[e_] := Module[
   z = e /. Exp[x_] :> Exp[Expand[x]];
   z = z //. Exp[u_ + v_] :> HoldForm[E^u E^v]
Here is the result :

May I ask you how to remove this Expand[] from the result ?


POSTED BY: Sylvain Rousseau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract