5
$\begingroup$

I have a problem to dinstinguish the following two mathematica codes, the only difference is the first use FullSimplify and the second is Simplify. but the results are totally different. what is wrong, is it a bug or not ? I really cannot figure it out

first codes are

f = WaveletPsi[MorletWavelet[], x]; 
g = FourierTransform[f, x, y, FourierParameters -> {0, -2 Pi}] // FullSimplify; 
Plot[g, {y, -3, 3}, PlotRange -> All] 

the output figure is

enter image description here

the second codes are

f = WaveletPsi[MorletWavelet[], x]; 
g = FourierTransform[f, x, y, FourierParameters -> {0, -2 Pi}] // Simplify; 
Plot[g, {y, -3, 3}, PlotRange -> All] 

the output figure is
enter image description here

Why is there so big difference of the output figures? I just modify the first codes from FullSimplify to Simplify !

anyone understand it ? Is it bug or not ?

I,due to low reputation, cannot post the formula about difference between the output formula with FullSimplify and Simplify: Ok, now I can post the formula: enter image description here

anyone understand it ? Thanks.

thank you very mcuh, everyone, to give the advice. by the way, how can I acknowledge your contributions ?

thanks to the firends below, I have found the hints for this problem. this is due to the floating point error in numerical calculation inlcuding substractive cancellation, loss of significance, etc. In In usual cases, the default precision may deal with these erros well, however, for diverging term, the default precision may not handle it. so increasing precision may solve it. or by changing algrithom, like what Submit has done, may also handle it without changing precision. well, thank you !

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Jun 30 '16 at 4:24
  • 1
    $\begingroup$ Have you looked at the output of Simplify and FullSimplify? $\endgroup$ – Michael E2 Jun 30 '16 at 4:25
  • $\begingroup$ sorry, I try to post the figures of the outputs of Simplify and Fullsimplify, but I cannot due to low reputation. I think it may be a bug of mathematica. $\endgroup$ – athosanian Jun 30 '16 at 4:53
  • 1
    $\begingroup$ I can't run your code at the moment (I'm on a tablet), but I suspect that FullSimplify may be generating a simpler expression that happens to be less sensitive to numerical precision problems. Perhaps you could try adding the option WorkingPrecision -> $MachinePrecision to the Plot after Simplify, and see if anything changes. $\endgroup$ – MarcoB Jun 30 '16 at 4:56
  • 3
    $\begingroup$ Yes, it's ol' "subtractive cancellation" all over again. Notice that in the result of Simplify[], you have a result composed of adding and subtracting a bunch of $\cosh$ and $\sinh$ terms, which get big pretty quick, to get a result that is not very big. It's a recipe for screw-ups. Stick with FullSimplify[]. $\endgroup$ – J. M. is away Jun 30 '16 at 4:59
5
$\begingroup$

It happens if there is a diverging term appears in the middle. For your case If we consider

FourierTransform[f, x, y, FourierParameters -> {0, -2 Pi}] = [Pi]^(1/4)/ Sqrt@2 (c1 + c2 + c3 + c4)

c1 = Cosh[1/2 \[Pi]^2 (-2 y + Sqrt[2/Log[2]])^2]
c2 = Cosh[1/2 \[Pi]^2 (2 y + Sqrt[2/Log[2]])^2]
c3 = -Sinh[1/2 \[Pi]^2 (-2 y + Sqrt[2/Log[2]])^2]
c4 = -Sinh[1/2 \[Pi]^2 (2 y + Sqrt[2/Log[2]])^2]

Individually these functions are diverging

Plot[Evaluate@{c1, c2, c3, c4}, {y, -1.5, 1.5}, PlotRange -> All, 
    PlotLegends -> {"c1", "c2", "c3", "c4"}]

enter image description here

But their combination might have aslower divergence

Plot[Evaluate@{c1 + c3, c2 + c4}, {y, -.5, .5}, PlotRange -> All, 
   PlotLegends -> {"c1+c3", "c2+c4"}]

enter image description here

When you are using Simplify or FullSimplify they follow certain algorithm to handle these divergences which give you different results. It sometimes may depend on how you write your expression as well. For example

Plot[(c1 + c2 + c3 + c4), {y, -1.5, 1.5}, PlotRange -> All, PlotLabel -> "(c1+c2+c3+c4)"]
Plot[(c1 + c3 + c2 + c4), {y, -1.5, 1.5}, PlotRange -> All, PlotLabel -> "(c1+c3+c2+c4)"]
Plot[(c1 + c3) + (c2 + c4), {y, -1.5, 1.5}, PlotRange -> All, PlotLabel -> "(c1+c3)+(c2+c4)"]

enter image description here

Fortunately I don't know any further details, so I can stop here.

$\endgroup$
  • $\begingroup$ thanks a lot, Sumit, you are quite right, due to these diverging terms, the working precision will influence the results of Mathematica.significantly. at first, i do not know this point, by default working precision, expression c1+c2+c3+c4 give a wrong result, but thanks to advice of Szabolc, when i set WorkingPrecision ->60 in the Plot[], the expression c1+c2+c3+c4 can give the right figure like (c1+c3)+(c2+c4) $\endgroup$ – athosanian Jun 30 '16 at 14:30

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.