1
$\begingroup$

I have 500 terms. and I want replace them with below function

rule1 := {       
 E^(Wr - (z___*Mr)/4 - (Gr*((Yr*Mr)/x___ + x___*Cr)) - 
             (Mr*((2*Mr)/y___ + (y___*Cr)/(2*Mr)))/2) :>
          
Ex[-(x+y+z)/4*Er^2]*
 (-(Mr^2/x) - Mr^2/y - Cr/(x+y+z))
       } ;

but I have some terms that don't have z (z=0) or y (y=0) for example:

E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - Gr (Cr x + (Mr Yr)/x) - (
 Mr z)/4)

and rule1 couldn't contain all terms. how can I modify rule1 to contain all terms?

for example, I face this problem

term1 = E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - Gr (Cr x + 
       (Mr*Yr)/x) - (Mr z)/4) 
        + E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - Gr (Cr x + (Mr 
        Yr)/x))
        + E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - (Mr z)/4) 
        + E^(Wr - (1/2) Mr ((2 Mr)/y + (Cr y)/(2 Mr)));

after replacing only last term has changed

term1 //. rule1
E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr))) 
+ E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - Gr (Cr x + (Mr Yr)/x)) 
+ E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) 
- (Mr z)/4) + (-(Mr^2/x) - Mr^2/y - Cr/(x + y + z)) Ex[1/4 Er^2 (-x - y 
- z)]
$\endgroup$
4
  • $\begingroup$ You can not use the same name for 2 different things:" x___ + x_*Cr". Further in "(2*Mr)/y___ + (y___*Cr" y is the same expression, is this what you want? $\endgroup$ Nov 11, 2021 at 9:42
  • $\begingroup$ dear @DanielHuber thanks for your comment I edited it but still, it doesn't work. $\endgroup$
    – asal
    Nov 11, 2021 at 11:19
  • $\begingroup$ rule1 now matches your expression: E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - Gr (Cr x + (Mr Yr)/x) - ( Mr z)/4) $\endgroup$ Nov 11, 2021 at 11:48
  • $\begingroup$ dear@DanielHuber Again, the problem is not solved I think I did not explain my problem correctly, so I corrected the text, maybe my problem will be clearer $\endgroup$
    – asal
    Nov 12, 2021 at 6:48

1 Answer 1

4
$\begingroup$

It is getting too complicated for a comment.

You may define the different cases as "Alternatives" like:

term1 = (E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - 
       Gr (Cr x + (Mr*Yr)/x) - (Mr z)/4)
    + E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - 
       Gr (Cr x + (Mr Yr)/x))
    + E^(Wr - 1/2 Mr ((2 Mr)/y + (Cr y)/(2 Mr)) - (Mr z)/4)
    + E^(Wr - (1/2) Mr ((2 Mr)/y + (Cr y)/(2 Mr))));

rule1 := (E^(Wr - (Mr*((2*Mr)/y___ + (y___*Cr)/(2*Mr)))/2)) | 
    (E^(Wr - (Gr*((Yr*Mr)/x___ + 
            x___*Cr)) - (Mr*((2*Mr)/y___ + (y___*Cr)/(2*Mr)))/
         2)) | (E^(Wr - (z___*Mr)/
         4 - (Mr*((2*Mr)/y___ + (y___*Cr)/(2*Mr)))/
         2)) | (E^(Wr - (z___*Mr)/
         4 - (Gr*((Yr*Mr)/x___ + 
            x___*Cr)) - (Mr*((2*Mr)/y___ + (y___*Cr)/(2*Mr)))/2)) :> 
   Ex[-(x + y + z)/4*Er^2]*(-(Mr^2/x) - Mr^2/y - Cr/(x + y + z));

And then you get:

term1 /. rule1

enter image description here

$\endgroup$
1
  • $\begingroup$ Dear @DanielHuber Thank you very much for your valuable comment. it solved my problem $\endgroup$
    – asal
    Nov 13, 2021 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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