Skip to main content

simplifying expressions - Mathematica rule to express exponentials as multiplication


I'm sorry if this has been asked before, but it is a very simple question and I would imagine it shouldn't be terribly hard for someone that knows to answer.


I'm essentially trying to tell mathematica to not simplify


Exp[x] Exp[y] -> Exp[x+y]


I am using an add on package which is having a hard time with some replacement rules. So, the question is, is it possible to force mathematica to express Exp[x] Exp[y] as is and not simplify it?


A secondary question, which should just be an extension of the first, I would like (Exp[x] Exp[y] )^2 to be replaced as Exp[x]^2 Exp[y]^2 not Exp[2x+2y]! Or even being left as is is ok.



Answer



One possibility is to execute your entire code in some dynamic environment, where certain simplification rules are permanently or temporarily blocked. Here is the generic environment generator:


ClearAll[withBlockedSymbols];
withBlockedSymbols[syms : {__Symbol}] :=
Function[code, Block[syms, code], HoldAll];

We can now produce an environment generator specifically for Exp:


withBlockedExp = withBlockedSymbols[{Exp}]


Now, any code executed inside this wrapper, will not use the automatic simplification rules for Exp, which will be inert inside this wrapper. For example:


withBlockedExp[Hold[Evaluate[Exp[x] Exp[y]]]]

(* Hold[Exp[x] Exp[y]] *)

withBlockedExp[Hold[Evaluate[(Exp[x] Exp[y])^2]]]

(* Hold[Exp[x]^2 Exp[y]^2] *)


The only reason I needed to use Hold@Evaluate was to prevent the simplification happening after the execution exits withBlockedExp. Hold@Evaluate@expr allows us to preserve a final form of expr evaluated inside dynamic environment. If you have less trivial transformations, you will see the utility of withBlockedExp better, since you don't have to use Hold etc. for intermediate steps inside withBlockedExp.


Comments