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.