In the following expression, how can I group apart the terms in the exponential with a and b coefficients so that I can express the expression as the product of two exponentials with same-kind coefficients?

expr = C * E^(a1*w[i] + b1*x[i] + (a2 + b2) p[i])

I would like to be able to simplify the above expression to get

C * E^(a1*w[i] + a2*p[i]) * E^(b1*x[i] + b2*p[i])


Thanks to J. M. needs help. I realize that in attempting to simplify my original problem I was asking for something non-sensical. So here is a bigger part the expression I'm trying to simplify

toSimplify = (E^((a2 + b2) p[i] + a1 w[i] + b x[i]) w[i])/(1 + E^(a2 p[i] + a1 w[i]))^2


fA[i] = E^(a2*p[i] + a1*w[i])/(1 + E^(a2*p[i] + a1*w[i]))
fB[i] = E^(b2*p[i] + b1*w[i])

So that I can get something like this

desired = fA[i]*((1 - fA[i])*fB[id]*w[i]
  • $\begingroup$ Did you try evaluating E^(a1*w[i] + a2*p[i])*E^(b1*x[i] + b2*p[i]) yourself to see what happens? $\endgroup$ Apr 10, 2018 at 1:56
  • $\begingroup$ @J.M. Thanks for pointing that out. I have edited my question to something more meaningful. $\endgroup$
    – Maturin
    Apr 10, 2018 at 3:38

2 Answers 2


One can use the ComplexityFunction option in FullSimplify. In your example the following works:

toSimplify = (E^((a2 + b2) p[i] + a1 w[i] + b x[i]) w[i])/(1 +E^(a2 p[i] + a1 w[i]))^2
varsa = a1 | a2
varsb = b | b2
f[e_] := LeafCount[e] + 
      1000 Total@ Boole@(! Or[FreeQ[#, varsa], FreeQ[#, varsb]] & /@ List @@ e)
FullSimplify[toSimplify, ComplexityFunction -> f]

$$\frac{w(i) e^{b x(i)+\text{b2} p(i)}}{2 \cosh (\text{a1} w(i)+\text{a2} p(i))+2}$$


You might make the following steps:

expr1 = MapAt[Expand, 
    toSimplify, {1, 2}] /. {a2 p[i] + a1 w[i] -> X} /. 
  b2 p[i] + b x[i] -> Y

(*   (E^(X + Y) w[i])/(1 + E^X)^2   *)


expr2 = expr1 /. (Exp[X + Y]*a_)/(1 + Exp[X])^2 -> 
   fA*HoldForm[Exp[Y]/(1 + Exp[X])]*a

enter image description here


expr3 = ReleaseHold[expr2] /. E^Y -> fB

(* (fA fB w[i])/(1 + E^X)  *)

I guess that it is not exactly what you had in mind, but that's how you have defined the transformations, and I followed them strictly.

Have fun


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.