Message Boards Message Boards

0
|
3714 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

Recursive ReplaceRepeated fails

Posted 11 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[ ]) ?
Cheers!
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:
replace[Exp[exponent]]
Or you may consider building Expand into your definition of replace.
POSTED BY: Sean Clarke
Many thanks Sean !
Absent-mindedness affair !
Regards
POSTED BY: Sylvain Rousseau
Dear Sean,

I 'am trapped in a new pitfall.. here my new code :
replace[e_] := Module[
   {z},
   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 ?

Regards

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

Group Abstract Group Abstract