2
$\begingroup$

Starting with the expression

eq1 = 5 Exp[1 + 2 x + 3 x^2 + 4 x^3];

I want to implement the following transformation:

eq1 /.  Exp[a_ x^2 + b_ x^3] ->   f[a/b]

However, I am not getting the desired output $5 f[3/4]\exp(1+2 x)$.

Further, I also need to perform the following transformation.

eq2 = c Exp[a SuperStar[\[Alpha]] + b \[Alpha]];
eq2 /. d1_ Exp[d2 SuperStar[\[Alpha]_]] -> f[d2]

I am providing the above expressions again in latex font for clarification. $$ \text{eq2}=c \exp \left(a \alpha ^*+\alpha b\right); $$

$$ \text{eq2}\text{/.}\, \text{d1$\_$} \exp \left(\alpha \_{}^* \text{d2}\right)\to f(\text{d2}) $$

Any help will be appreciated.

$\endgroup$

1 Answer 1

6
$\begingroup$
eq1 /. Exp[a_. x^2 + b_. x^3 + c_.] -> Exp[c] f[a/b]

5 E^(1 + 2 x) f[3/4]

eq2 /. d1_. Exp[d2_. SuperStar[α_] + d3_.] -> Exp[d3] f[d2]

E^(b α) f[a]

$\endgroup$
3
  • 3
    $\begingroup$ If you use defaults in the replacement pattern (dots after the patterns), they become more versatile: Exp[a_. x^2 + b_. x^3 + c_.] -> Exp[c] f[a/b]. This will also work with eq1a = 5 Exp[x^2 + 4 x^3], for example. Also, d1_. Exp[d2_. SuperStar[α_] + d3_.] -> Exp[d3] f[d2] for the second one. $\endgroup$
    – Roman
    May 9, 2019 at 12:29
  • $\begingroup$ @Roman, great point. Updated with default patterns. $\endgroup$
    – kglr
    May 9, 2019 at 12:49
  • $\begingroup$ @Shadowray, thank you; I added the needed _.s. $\endgroup$
    – kglr
    May 9, 2019 at 13:52

Your Answer

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

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