5
$\begingroup$

I have a function that when I operate FullSimplify on, produces widly different results depending on if the parameters are left symbolic or values are substituted in before the simplification. I've narrowed down the part of my function that FullSimplify messes up.:

func = E^(-((-(x^2 + y^2 + z^2)^
     p + \[Rho])^2/\[Sigma])) + E^(-(((x^2 + y^2 + z^2)^
    p + \[Rho])^2/\[Sigma]))

This is just two gaussians translated symmetrically about the origin. Now, If I do FullSimplify on this function, I get the expected result which is that basically nothing happens. The function is already pretty simple. But if I input some parameter values:

E^(-33.3333 (0.8 - (x^2 + y^2 + 
      z^2)^0.26)^2) + E^(-33.3333 (0.8 + (x^2 + y^2 + z^2)^0.26)^2)

Then pass FullSimplify to this, Mathematica reduces it to zero.

FullSimplify[E^(-33.3333 (0.8 - (x^2 + y^2 + 
      z^2)^0.26)^2) + E^(-33.3333 (0.8 + (x^2 + y^2 + z^2)^0.26)^2)]

---> (*0.*)

This is really strange and almost introduced mistakes into my research since I didnt catch it at first. Luckily, I did some consistency checks and analysis and found the mistake. Unfortunately, the functions I work with are really large, so I would like to use simplification early on in the code so that it reduces computation time later.

Is there a way I can still use simplification without Mathematica killing the result? I see there have been some other issues with FullSimplify, but I think this one is unique enough to warrant a separate question, given the use of Exponentials.

I appreciate any insight and help!

$\endgroup$
0
5
$\begingroup$

Floats cause that. The Rationalize command helps.

FullSimplify[Rationalize[E^(-33.3333 (0.8 - (x^2 + y^2 + z^2)^0.26)^2) + 
E^(-33.3333 (0.8 + (x^2 + y^2 + z^2)^0.26)^2), 10^-40]]

E^(-((333333 (4 - 5 (x^2 + y^2 + z^2)^(13/50))^2)/250000)) + E^(-(( 333333 (4/5 + (x^2 + y^2 + z^2)^(13/50))^2)/10000))

Addition. Maybe, the result of

FullSimplify[E^Expand@Rationalize[(-33.3333 (0.8 - (x^2 + y^2 + z^2)^0.26)^2), 
 10^-40] +  E^Expand@Rationalize[(-33.3333 (0.8 + (x^2 + y^2 + z^2)^0.26)^2), 
 10^-40], Assumptions -> {x, y, z} \[Element] Reals]

E^(-((333333 (4 + 5 (x^2 + y^2 + z^2)^(13/50))^2)/ 250000)) (1 + E^((333333 (x^2 + y^2 + z^2)^(13/50))/3125))

is more preferable.

$\endgroup$
1
  • $\begingroup$ Thanks! yea I figured it was floating point errors coming in. I was just surprised how much the simplification changed the result so I thought it could be something else. I already changed my code to wait until the last minute to input parameter values and that fixed it. $\endgroup$ – shanedrum Jan 21 at 10:06
5
$\begingroup$

Try first to simplify, then to substitute:

Simplify[func, {\[Rho] > 0, p > 0, \[Sigma] > 0}] /. {\[Sigma] -> 3./
   100, p -> 0.26, \[Rho] -> 0.8}

(* E^(-33.3333 (-0.8 + (x^2 + y^2 + 
      z^2)^0.26)^2) + E^(-33.3333 (0.8 + (x^2 + y^2 + z^2)^0.26)^2)  *)

Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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