# Strange timings of integrals involving Hermite's polynomials

I have used Mathematica to calculate tunneling for quantum harmonic oscillator. The code is simple:

ψ[n_, x_] := 1/Sqrt[Sqrt[Pi] 2^n n!] Exp[-x^2/2] HermiteH[n, x];
t512 = {};
For[i = 0, i <= 512, i++,
tim = Timing[
N[2*Integrate[ψ[i, x]^2, {x, Sqrt[2 i + 1], Infinity}]]];
Print[tim[[1]]]; Print[i];
AppendTo[t512, tim[[2]]]];
ListLinePlot[t512]


So, essentially, we are calculating symbolically integrals of squares of the Hermite polynomials multiplied by a Gaussian. To my surprise timings (in seconds) show quasi-periodic minima:

What can be the reason?

• Your code doesn't work (just gives a bunch of error messages), and it's not clear how you got the graph you obtained. Please fix it and post a working example that produces the graph that you obtained. – DumpsterDoofus Jan 17 '15 at 22:13
• I edited it to try fixing the issue; if this is incorrect, feel free to revert the edit. – DumpsterDoofus Jan 17 '15 at 22:21
• Thanks for for fixing my code, which I messed up when trying to make it short. And thanks for your observation about these square roots once in a while being integers. It did not occur to me. – arkajad Jan 19 '15 at 9:45
• Probably the calculation of values of high order polynomials at integer points is faster. – arkajad Jan 19 '15 at 10:07

Try this:

Flatten@Position[Sqrt[2 Range[512] + 1], _Integer, 1]


resulting in

{4, 12, 24, 40, 60, 84, 112, 144, 180, 220, 264, 312, 364, 420, 480}


You'll notice that the quasi-periodic oscillations are centered at the numbers in the list above. This is due to the fact that $\sqrt{2i+1}\in\mathbb{Z}$ for those values of $i$, and presumably Integrate's symbolic method for definite integration goes quicker at integer bounds.

As to why that Integrate executes faster at integers, I have no idea; Mathematica's symbolic integration methods are really complicated and I don't understand them, but perhaps someone else will have an answer for that.

• I wouldn't be surprised if most of Mathematica's symbolic techniques are faster on integers....Mine are.:) – Michael E2 Jan 18 '15 at 3:46