Group Abstract Group Abstract

Message Boards Message Boards

0
|
12.4K Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

EDITED:same computation gives different results

Posted 10 years ago

I am computing an integral symbolically using Mathematica. With a fresh kernel the computation gives one form of the result but if I re-run the computation I get another form. I am wondering why this occurs. An example is shown below.

In[1]:= Clear["Global`*"]

In[2]:= g1[\[Theta]_, d_, n_, \[Lambda]_] = 
 2 Integrate[(1 - (2 x/d)^2)^
    n Cos[2 \[Pi] x Sin[\[Theta]]/\[Lambda]], {x, 0, d/2}, 
   Assumptions -> 
    d \[Element] Reals && \[Lambda] \[Element] Reals && \[Lambda] > 
      0 && n \[Element] Reals && n >= 0 && 
     d > 0 && \[Theta] \[Element] Reals]

Out[2]= 2^(-(1/2) + n) \[Pi]^-n (\[Lambda]/d)^n Sqrt[d \[Lambda]]
  Abs[Sin[\[Theta]]]^(-(1/2) - n)
  BesselJ[1/2 + n, (d \[Pi] Abs[Sin[\[Theta]]])/\[Lambda]] Gamma[1 + n]

In[3]:= g0 = Limit[g1[\[Theta], d, n, 1], \[Theta] -> 0]

Out[3]= ((1/d)^n d^(1 + n) Sqrt[\[Pi]] Gamma[1 + n])/(2 Gamma[3/2 + n])

In[4]:= glin[\[Theta]_, n_, d_] = 
 10 Log10[(g1[\[Theta], d, n, 1]/g0)^2]

Out[4]= (10 Log[
  d^(-1 - 2 n) (\[Pi]/2)^(-1 - 2 n) Abs[Sin[\[Theta]]]^(-1 - 2 n)
    BesselJ[1/2 + n, d \[Pi] Abs[Sin[\[Theta]]]]^2 Gamma[
    3/2 + n]^2])/Log[10]

In[5]:= Clear["Global`*"]

In[6]:= g1[\[Theta]_, d_, n_, \[Lambda]_] = 
 2 Integrate[(1 - (2 x/d)^2)^
    n Cos[2 \[Pi] x Sin[\[Theta]]/\[Lambda]], {x, 0, d/2}, 
   Assumptions -> 
    d \[Element] Reals && \[Lambda] \[Element] Reals && \[Lambda] > 
      0 && n \[Element] Reals && n >= 0 && 
     d > 0 && \[Theta] \[Element] Reals]

Out[6]= 1/2 d Sqrt[\[Pi]]
  Gamma[1 + n] Hypergeometric0F1Regularized[
  3/2 + n, -((d^2 \[Pi]^2 Sin[\[Theta]]^2)/(4 \[Lambda]^2))]

In[7]:= g0 = Limit[g1[\[Theta], d, n, 1], \[Theta] -> 0]

Out[7]= (d Sqrt[\[Pi]] Gamma[1 + n])/(2 Gamma[3/2 + n])

In[8]:= glin[\[Theta]_, n_, d_] = 
 10 Log10[(g1[\[Theta], d, n, 1]/g0)^2]

Out[8]= (10 Log[
  Gamma[3/2 + n]^2 Hypergeometric0F1Regularized[
    3/2 + n, -(1/4) d^2 \[Pi]^2 Sin[\[Theta]]^2]^2])/Log[10]

I am interested in differentiating the function with respect to theta but with the first form of the result this results in the derivative of the absolute value function which cannot be numerically evaluated. The derivative of the second form of the result can be evaluated numerically.

I can always run my notebook twice to solve my problem. I just wonder why a newly started kernel can give a different answer the second time it attempts a calculation.

Edit: The behavior described above only occurs with the Windows version of Mathematica 10.3. The Mac version always returns the second version of the integral.

POSTED BY: Mike Luntz
7 Replies
Posted 10 years ago

I just finished reading Daniel's interesting paper on Mathematica's Integration function. Most of it is related to the design considerations of an earlier version of Mathematica. However there was one passage in the paper dealing with conditions that I have quoted below and that appears to be something that can impact users of Mathematica. I hope Daniel can comment on whether this consideration is still something that users should be aware of.

Often one may wish to ignore conditions. This happens for example in cases where we know in advance that they will be satisfied by parameter values we may later choose. A problem is that results can depend on what path is taken in the code. If the integration is split into parts, say because the path is split, and if the parts take paths in the code that make different assumptions about parameters, then results might be entirely incorrect. One manifestation might be incorrect cancellation.

POSTED BY: Mike Luntz

I am not aware of any changes that would have the effect of making that particular issue go away. We may have made improvements in guarding against it in some cases, but not in all possible cases.

The same is likely to be true for every general issue raised in that paper.

POSTED BY: Daniel Lichtblau
Posted 10 years ago

Thanks for the paper Daniel. Perhaps it will explain other idiosyncrasies that I may encounter in the future.

POSTED BY: Mike Luntz
Posted 10 years ago

Daniel, Thanks for suggesting a reason for this behavior. As stated in my edit, the behavior is different on a Mac. Could this be due to a difference in machine speeds interacting with the time-constrained simplifications your mentioned?

POSTED BY: Mike Luntz

Yes, differences in machine speed can give rise to the behaviors you have seen.

There may be some relevant discussion here. I tried to cover a number of issues that show up in definite integration (also indefinite, but more focus on definite).

POSTED BY: Daniel Lichtblau
Manipulate[PolarPlot[(10 Log[d^(-1 - 2 n) (\[Pi]/2)^(-1 - 2 n)  Abs[Sin[\[Theta]]]^(-1 - 2 n)   BesselJ[1/2 + n, d \[Pi] Abs[Sin[\[Theta]]]]^2 Gamma[  3/2 + n]^2])/Log[10], {\[Theta], 0, 2 \[Pi]}], {d, -8, 8}, {n, -8, 8}]

enter image description here

POSTED BY: Simon Cadrin

Intermediate caching, and interactions with time-constrained simplifications inside Integrate, can give rise to this. I'm pretty sure this has come up in past but I am having trouble finding links to prior discussions on the topic. If I do locate some I will add them to this response.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard