# Mathematica is unreliable about recognizing orthogonal functions

Hermite polynomials should be orthogonal over a Gaussian measure. However when the orders of the polynomials are larger than a few, Mathematica gets this wrong. Strangely, it seems to hinge on whether orders of the two polynomials are both even or both odd (failure), or if one is even and the other is odd (success).

To illustrate, this gives the correct answer:

In[27]:= Integrate[
HermiteH[9, x] HermiteH[18, x] Exp[-  x^2], {x, -Infinity, Infinity}]

Out[27]= 0


But this doesn't:

In[25]:= Integrate[
HermiteH[8, x] HermiteH[18,
x] Exp[-(1/2) x^2] Exp[-(1/2) x^2], {x, -Infinity, Infinity}]

During evaluation of In[25]:= Integrate::idiv: Integral of E^-x^2 (105-840 x^2+840 x^4-224 x^6+16 x^8) (-34459425+620269650 x^2-1654052400 x^4+1543782240 x^6-661620960 x^8+147026880 x^10-17821440 x^12+1175040 x^14-39168 x^16+512 x^18) does not converge on {-\[Infinity],\[Infinity]}. >>

Out[25]= \!$$\*SubsuperscriptBox[\(\[Integral]$$, $$-\[Infinity]$$, \
$$\[Infinity]$$]$$\( \*SuperscriptBox[\(E$$, $$- \*SuperscriptBox[\(x$$, $$2$$]\)]\ $$(1680 - 13440\ \*SuperscriptBox[\(x$$, $$2$$] + 13440\
\*SuperscriptBox[$$x$$, $$4$$] - 3584\
\*SuperscriptBox[$$x$$, $$6$$] + 256\
\*SuperscriptBox[$$x$$, $$8$$])\)\ $$(\(-17643225600$$ + 317578060800\
\*SuperscriptBox[$$x$$, $$2$$] - 846874828800\
\*SuperscriptBox[$$x$$, $$4$$] + 790416506880\
\*SuperscriptBox[$$x$$, $$6$$] - 338749931520\
\*SuperscriptBox[$$x$$, $$8$$] + 75277762560\
\*SuperscriptBox[$$x$$, $$10$$] - 9124577280\
\*SuperscriptBox[$$x$$, $$12$$] + 601620480\
\*SuperscriptBox[$$x$$, $$14$$] - 20054016\
\*SuperscriptBox[$$x$$, $$16$$] + 262144\
\*SuperscriptBox[$$x$$, $$18$$])\)\) \[DifferentialD]x\)\)

• What version are you on? Version 11 seems to cope with the Hermite polynomials. – J. M.'s ennui Aug 12 '16 at 15:14
• Both the $H_9(x)H_{18}(x)$ and $H_8(x)H_{18}(x)$ examples give zero on my machine on v11 and v10.4.1. – Emilio Pisanty Aug 12 '16 at 15:17
• You might also want to see this. – J. M.'s ennui Aug 12 '16 at 15:18
• Both give 0 for me, V10.0.1 on Mac OS 10.10.5. – march Aug 12 '16 at 15:30
• I also got 0 in v9.0.1 – Hector Aug 12 '16 at 17:30

The OP's example works fine for me in Mma 11. However, if we're talking about unreliable, notice that expressions using assumptions may give you unexpected results. For example,

Assuming[k \[Element] Integers \[And] j \[Element] Integers,
Integrate[Sin[k x] Sin[j x], {x, 0, 2 Pi}]]


returns a bland zero, which is of course mathematically incorrect, since the result is \[Pi] for j==k (as Mma will readily confirm if you add that assumption). I remember having some discussions about this with Wolfram support. To sum it up, Wolfram argues that this is not a bug, and that returning zero to an expression like the above is proper, since it's true most of the time. I happen to disagree, as follows:

Following J.M.'s comment below, Wolfram argues that the result is "generically correct", incorrectly, I would argue: Notice that in this particular case, the entire set that is tested is countable, just as the set where the result is wrong. Thus there is a one-to-one mapping available that matches each and every single case where the result is correct to a case where the result is false. In other words, in a strict sense there are exactly as many cases where the result is wrong as there are cases where it's correct. One might colloquially put this in the form of "this result is just as likely to be wrong as it is likely to be correct". Of course, since we're talking about countable infinite sets, there's a bit of a sleight-of-hand here...

But, let's consider this one:

Assuming[k \[Element] Integers \[And] j \[Element] Integers
\[And] j <= k <= j + 1 \[And] 0 <= k <= 20,
Integrate[Sin[k x] Sin[j x], {x, 0, 2 Pi}]]


Now we can see that even without considering infinite sets, Mathematica returns a result that's wrong half the time. Anyone willing to defend that one?

• "...Wolfram argues that this is not a bug, and that returning zero to an expression like the above is proper, since it's true most of the time." - i.e., the expression is generically correct, since it only fails on a countable set of cases. – J. M.'s ennui Aug 12 '16 at 17:15
• @J.M.: Yep, that's exactly the argument. I still don't buy it. Notice that in this particular case, the entire set that is tested is countable, just as the set where the result is wrong. Thus there is a one-to-one mapping available that matches each and every single case where the result is false to a case where the result is correct. One might colloquially put this in the form of "this result is just as likely to be wrong as it is likely to be correct". Of course, since we're talking about countable infinite sets, there's a bit of a sleight-of-hand here... – Pirx Aug 12 '16 at 17:37
• P.S.: (Note added after looking at your link): So, my example above is qualitatively different from the case you linked to: In that case, we are comparing a set with a single element to an infinite set, whereas in my case, we are comparing two infinite sets that both have the same cardinality. – Pirx Aug 12 '16 at 17:43
• Better to use ii = Integrate[Sin[k x] Sin[j x], {x, 0, 2 Pi}, Assumptions -> k \[Element] Integers \[And] j \[Element] Integers \[And] j <= k <= j + 1 \[And] 0 <= k <= 20]. Check here for some remarks on why Assuming outside Integrate can be different from Assumptions->... inside. – Daniel Lichtblau Aug 13 '16 at 15:07
• I will add that, in addition to being substantially a duplicate of several prior questions, the main thrust of this response is not related to the issue raised in the original post of this thread. – Daniel Lichtblau Aug 13 '16 at 15:12