How to Simplify exponents?

I need to divide a Gaussian Mixture by it’s widest component. When I do this, the exponents of the output end up a mess of terms in need of simplification, but Simplify[] doesn’t do it. How can I make this work?

gauMix[x_, means_, vars_] :=
(1/Length[vars])*Total[(E^-(((x -means)^2)/(2*vars)))/Sqrt[2*Pi*vars]];
means = {-2, 2, 5};
vars = {1, 2, 2};
widest = Flatten[Position[vars, _?(# == Max[vars] &)]];
h[x_, v_] :=
gauMix[x, means, vars + v]/gauMix[x, {Mean[means[[widest]]]},{vars[[Min[widest]]] + v}];
Expand[h[x, v]]

√v+2exp((x−72)22(v+2)−(x+2)22(v+1))3√v+1+13exp((x−72)22(v+2)−(x−5)22(v+2))+13exp((x−72)22(v+2)−(x−2)22(v+2))\frac{\sqrt{v+2} \exp \left(\frac{\left(x-\frac{7}{2}\right)^2}{2 (v+2)}-\frac{(x+2)^2}{2 (v+1)}\right)}{3 \sqrt{v+1}}+\frac{1}{3} \exp
\left(\frac{\left(x-\frac{7}{2}\right)^2}{2 (v+2)}-\frac{(x-5)^2}{2 (v+2)}\right)+\frac{1}{3} \exp \left(\frac{\left(x-\frac{7}{2}\right)^2}{2
(v+2)}-\frac{(x-2)^2}{2 (v+2)}\right)

I would like to see, the exponents individually Simplify[]’d and Together[]’d into something like this:

√v+2exp(−44vx+33v−4×2−60x+178(v+1)(v+2))3√v+1+13e33−12x8v+16+13e3(4x−17)8(v+2)\frac{\sqrt{v+2} \exp \left(\frac{-44 v x+33 v-4 x^2-60 x+17}{8 (v+1) (v+2)}\right)}{3 \sqrt{v+1}}+\frac{1}{3} e^{\frac{33-12 x}{8 v+16}}+\frac{1}{3}
e^{\frac{3 (4 x-17)}{8 (v+2)}}




h[x, v] // Simplify ?
– Dr. belisarius
Feb 21 ’15 at 0:34



13e(7−2x)28(v+2)(e−(x−5)22(v+2)+e−(x−2)22(v+2)+e−(x+2)22(v+1)√v+1v+2)\frac{1}{3} e^{\frac{(7-2 x)^2}{8 (v+2)}} \left(e^{-\frac{(x-5)^2}{2 (v+2)}}+e^{-\frac{(x-2)^2}{2 (v+2)}}+\frac{e^{-\frac{(x+2)^2}{2 (v+1)}}}{\sqrt{\frac{v+1}{v+2}}}\right)
– Dr. belisarius
Feb 21 ’15 at 0:36



@belisarius No, that’s just dividing back out the wide gaussian that I just multiplied in. What I want is for each of those exponents to get individually simplified. For example, in the 2nd and 3rd terms, the x^2 term of the exponent polynomials will cancel out.
– Jerry Guern
Feb 21 ’15 at 0:41



perhaps you should write down the expected result
– Dr. belisarius
Feb 21 ’15 at 0:46



@belisarius Okay, I did that.
– Jerry Guern
Feb 21 ’15 at 1:16


2 Answers


Explicitly replacing the exponents with simplifications:

expr /. {Exp[x_] :> Exp[Together@FullSimplify[x]]}

This results in:

\frac{\sqrt{v+2} \exp \left(\frac{-44 v x+33 v-4 x^2-60 x+17}{8 (v+1)
(v+2)}\right)}{3 \sqrt{v+1}}+\frac{1}{3} e^{\frac{3 (4 x-17)}{8
(v+2)}}+\frac{1}{3} e^{-\frac{3 (4 x-11)}{8 (v+2)}}



P.S. A simpler way to find the parameters of the widest gaussian: Mean@MaximalBy[Transpose[{means, vars}], Last]. You can apply Sequence to put it into your function without extracting the parts separately.
– 2012rcampion
Feb 21 ’15 at 2:28



I didn’t really understand you PS comment, but thank you for this answer.
– Jerry Guern
Apr 10 at 7:38

gauMix[x_, means_, vars_] := (1/Length[vars])*
Total[(E^-(((x – means)^2)/(2*vars)))/Sqrt[2*Pi*vars]];
means = {-2, 2, 5};
vars = {1, 2, 2};
widest = Flatten[Position[vars, _?(# == Max[vars] &)]];
h[x_, v_] :=
gauMix[x, means, vars + v]/
gauMix[x, {Mean[means[[widest]]]}, {vars[[Min[widest]]] + v}];
Simplify[Expand[h[x, v]] /. E^(a__ /b__ + c__ /b__) -> E^((a + c)/b)]

\frac{1}{3} e^{\frac{8 x^2-44 x+65}{4 v+8}}+\frac{1}{3}



This gives wrong results. The x^2 terms should be cancelling out of the exponents of two of the terms.
– Jerry Guern
Feb 21 ’15 at 1:15