4
$\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

8
$\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$ Commented May 9, 2019 at 12:29
  • $\begingroup$ @Roman, great point. Updated with default patterns. $\endgroup$ Commented May 9, 2019 at 12:49
  • $\begingroup$ @Shadowray, thank you; I added the needed _.s. $\endgroup$ Commented May 9, 2019 at 13:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.