1
$\begingroup$

I have the following expression:

Exp[r*t*x + e*r*y + t*x*r^2 + y^2*e*Sqrt[r]]

I want to choose some arbitrary terms in the power and for example write the expression in the form:

Exp[t*x*r^2] Exp[r*t*x + e*r*y + y^2*e*Sqrt[r]]]

or as another example for choosing t*x*r^2 and r*t*x

Exp[t*x*r^2] Exp[r*t*x] Exp[e*r*y + y^2*e*Sqrt[r]]]

How can I do this manipulation of expressions?

$\endgroup$

2 Answers 2

1
$\begingroup$

From your earlier question you know Mathematica likes to combine exponentials automatically. If this is for display purposes only the you can do

ClearAll["Global`*"]
expr = Exp[r*t*x + e*r*y + t*x*r^2 + y^2*e*Sqrt[r]]

$$ e^{e \sqrt{r} y^2+e r y+r^2 t x+r t x} $$

term = t*x*r^2
Dot[Exp[(Last@expr /. term -> 0)], Exp[term]]

$$ e^{e \sqrt{r} y^2+e r y+r t x}.e^{r^2 t x} $$

And for your second example

term = r*t*x
Dot[Exp[(Last@expr /. term -> 0)], Exp[term]]

$$ e^{e \sqrt{r} y^2+e r y+r^2 t x}.e^{r t x} $$

But the result is Dot and you'd have to replace that with * to use it. The above method ofcourse works on the example you have shown. It is not meant to be a general method as it does no checking, (for example, it assumes the argument inside Exp is a sum of terms.

but with more error checking it can be made into a Module and used as black box.

$\endgroup$
1
$\begingroup$

Try the following function:

factorizeExp[expr_, lst_] := Module[{exprA, exprB},
  exprA = expr[[2]][[Sequence@lst]];
  exprB = expr[[2]] - exprA;
  Inactive[Exp][exprA]*Inactive[Exp][exprB]
  ]

where the arguments are as follows: expr is the expression to be factorized, and lst is the list of terms in the exponent that you need to present as a separate exponent. For example, if you wish to separate out the terms r*t*x + t*x*r^2 you make lst={1,3}.

Let us try this function

factorizeExp[Exp[r*t*x + e*r*y + t*x*r^2 + y^2*e*Sqrt[r]], {4}]

(*  Inactive[Exp][e Sqrt[r] y^2] Inactive[Exp][r t x + r^2 t x + e r y]*)

factorizeExp[Exp[r*t*x + e*r*y + t*x*r^2 + y^2*e*Sqrt[r]], {1}]

(*    Inactive[Exp][r t x] Inactive[Exp][r^2 t x + e r y + e Sqrt[r] y^2] *)
    
factorizeExp[Exp[r*t*x + e*r*y + t*x*r^2 + y^2*e*Sqrt[r]], {1, 4}]

  (*  Inactive[Exp][r^2 t x + e r y] Inactive[Exp][r t x + e Sqrt[r] y^2]  *)

On the screen, you will see a bit different image than you see above. Here is what you see on the screen:

enter image description here

The expression is inactivated. If you intend to make further calculations with it, do not forget to first activate it with the function Activate. Its application, however, removes the formatting.

Instead of Inactivate one can use HoldForm as follows:

factorizeExp2[expr_, lst_] := Module[{exprA, exprB},
  exprA = expr[[2]][[Sequence@lst]];
  exprB = expr[[2]] - exprA;
  HoldForm[Evaluate[Exp[exprA]]]*HoldForm[Evaluate[Exp[exprB]]]
  ]

Then its application

expr = factorizeExp2[
  Exp[r*t*x + e*r*y + t*x*r^2 + y^2*e*Sqrt[r]], {1, 4}]

returns the following:

enter image description here

For further calculation (if any) you need to apply ReleaseHold to it. Some more details please find in my recent post here

Have fun!

$\endgroup$

Your Answer

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

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