Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm having some trouble with identical code giving different answers. On a fresh kernel (MM 9.0.0.0, Windows 64-bit), running the same code, copy-paste, gives two different answers:

In[1]:= Integrate[
  E^(-\[Rho]^2/2) \[Rho]^(
   p + m + 1) (\[CapitalDelta]z^2 + \[Rho]^2)^-(m + 1/2)
  , {\[Rho], 0, \[Infinity]}, 
  Assumptions -> {{m, p} \[Element] Integers, m >= 0, 
    p >= 0, \[CapitalDelta]z > 0}] // FullSimplify

Out[1]= 1/2 \[Pi] (2^(1/2 (1 - m + p))
 Hypergeometric1F1Regularized[1/2 + m, 1/2 (1 + m - p), \[CapitalDelta]z^2/2]
 - (\[CapitalDelta]z^(1 - m + p) Gamma[1/2 (2 + m + p)] 
Hypergeometric1F1Regularized[1/2 (2 + m + p), 1/2 (3 - m + p), \[CapitalDelta]z^2/2])/
   Gamma[1/2 + m]) Sec[1/2 (m - p) \[Pi]]

In[2]:= Integrate[
  E^(-\[Rho]^2/2) \[Rho]^(
   p + m + 1) (\[CapitalDelta]z^2 + \[Rho]^2)^-(m + 1/2)
  , {\[Rho], 0, \[Infinity]}, 
  Assumptions -> {{m, p} \[Element] Integers, m >= 0, 
    p >= 0, \[CapitalDelta]z > 0}] // FullSimplify

Out[2]= 2^(1/2 (-1 - m + p))
  Gamma[1/2 (2 + m + p)] HypergeometricU[1/2 + m, 1/2 (1 + m - p), \[CapitalDelta]z^2/2]

Subsequent runs of the same code consistently churn out, as far as I can tell, the second expression.

To make things even weirder, the first answer contains a global factor of $$\sec\left(\frac\pi2(m-p)\right),$$ which is singular for $m-p$ an odd integer. This makes useless in half the cases covered in the assumptions I explicitly gave to Integrate ({m, p} \[Element] Integers, m >= 0, p >= 0).

I also get analogous behaviour, with a slightly different first answer, if I drop the FullSimplify.

Could someone shed some light on this?

share|improve this question
2  
The second evaluation is using cached values. If you use ClearSystemCache[] before each evaluation you get the first result repeatedly see ClearSystemCache –  kguler Mar 11 '13 at 11:07
    
@Nasser, I get 0 when I run FullSimplify[% - %%, Assumptions -> {{m, p} \[Element] Integers, m >= 0, p >= 0, \[CapitalDelta]z > 0}]. –  kguler Mar 11 '13 at 11:31
    
@kguler I can see how clearing the cache would make it revert to the first result. I can't see why it wouldn't use those results the first time around, though. –  episanty Mar 11 '13 at 11:41
1  
@episanty, I can't see why either. –  kguler Mar 11 '13 at 11:54
add comment

1 Answer

up vote 5 down vote accepted

The second and subsequent evaluations of the same expression are using cached values.If you use ClearSystemCache[] before each evaluation you get the first result repeatedly. (see ClearSystemCache)

ClearSystemCache[];
Integrate[E^(-\[Rho]^2/2) \[Rho]^(p + m + 1) (\[CapitalDelta]z^2 + \[Rho]^2)^-(m + 1/2),
{\[Rho],  0, \[Infinity]}, Assumptions -> {{m, p} \[Element] Integers, 
m >= 0, p >= 0, \[CapitalDelta]z > 0}] // FullSimplify

gives

enter image description here

Evaluating the expression second time:

 Integrate[E^(-\[Rho]^2/2) \[Rho]^(p + m + 1) (\[CapitalDelta]z^2 + \[Rho]^2)^-(m + 1/2), 
 {\[Rho],  0, \[Infinity]}, Assumptions -> {{m, p} \[Element] Integers, 
 m >= 0, p >= 0, \[CapitalDelta]z > 0}] // FullSimplify

gives

enter image description here

and

 FullSimplify[% - %%, Assumptions -> {{m, p} \[Element] Integers, 
   m >= 0, p >= 0, \[CapitalDelta]z > 0}]

gives 0.

Finally, if you repeat the assumptions of Integrate inside FullSimplify

ClearSystemCache[];
Integrate[ E^(-\[Rho]^2/2) \[Rho]^(p + m +  1) (\[CapitalDelta]z^2 + \[Rho]^2)^-(m + 1/2), 
 {\[Rho], 0, \[Infinity]}, Assumptions -> {{m, p} \[Element] Integers,
  m >= 0,  p >= 0, \[CapitalDelta]z > 0}] // 
 FullSimplify[#,  Assumptions -> {{m, p} \[Element] Integers, m >= 0, 
 p >= 0, \[CapitalDelta]z > 0}] &

you get the output

enter image description here

directly (without having to re-evaluate Integrate[...]).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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