6
$\begingroup$

I was trying to get Mathematica to simplify some moderately ugly sums and I ran into some pretty weird behaviour, which I tracked down to the following example. I'm working with Christoffel-Darboux-type sums of Hermite polynomials, which are known to simplify nicely, a fact of which Mathematica is aware:

Sum[(HermiteH[k, x] HermiteH[k, y])/(2^k k!), {k, 0, n}]

Out[1]= (2^(-1 - n) (HermiteH[n, y] HermiteH[1 + n, x] - 
HermiteH[n, x] HermiteH[1 + n, y]))/((x - y) n!)

So far so good. However, even simple changes to the above expression make Mathematica output a far more complex answer which is not what I'm looking for in general and which in this case is evidently rather wrong:

Sum[(HermiteH[k, -x] HermiteH[k, y])/(2^k k!), {k, 0, n}]

enter image description here

The problem is somewhat related to this question on Simplify, but I can't see why Mathematica would think the code above is in any way simpler than just

-(2^(-1 - n) (HermiteH[n, y] HermiteH[1 + n, -x] - 
HermiteH[n, -x] HermiteH[1 + n, y]))/((x + y) n!)

Can anyone share some insight? or is this some kind of bug?

$\endgroup$

1 Answer 1

3
$\begingroup$

Before I answer your question, I would like to share some results. Since there was no guarantee that the Christoffel–Darboux formula would be invariant under such a change of variables, I did a simple check:

In[25]:= Sum[(HermiteH[k, -x] HermiteH[k, y])/(2^k k!), {k, 0, 3}]

Out[25]= 1 - 2 x y + 1/8 (-2 + 4 x^2) (-2 + 4 y^2) 
       + 1/48 (12 x - 8 x^3) (-12 y + 8 y^3)

In[26]:= Sum[(HermiteH[k, x] HermiteH[k, y])/(2^k k!), 
             {k, 0,n}] /. {x -> -x, n -> 3}

Out[26]= ((12 - 48 x^2 + 16 x^4) (-12 y + 8 y^3) - (12 x - 
8 x^3) (12 - 48 y^2 + 16 y^4))/(96 (-x - y))

In[34]:= (-1/96)(PolynomialReduce[Numerator@%26, {x + y}, {x, y}])[[1, 1]] 
        == %25 // Expand

Out[34]= True

And, it works at higher values of n, also. Similarly,

In[39]:= Sum[(HermiteH[k, -x] HermiteH[k, y])/(2^k k!), {k, 0, n}];
         (% /. n -> 3) == %25 // Expand

Out[40]= True

This leads me to believe that the answer you're given is absolutely correct, just not in its simplest form.

As to why Mathematica does not recognize the simplification, the answer is simply because it does not know everything, and while such a variable transformation seems easy to us, it is not necessarily straightforward to program.

Edit: Sum behaves this way because the form

Sum[(HermiteH[k, x] HermiteH[k, y])/(2^k k!), {k, 0,n}]

is recognized and the substitution can be made immediately. To allow for the more complex simplification that you wish, we need to create a custom rule for it, as follows

Unprotect[Sum]
Sum[(HermiteH[k_, x_] HermiteH[k_, y_])/(2^k_ (k_)!), {k_, 0, n_}] := 
 (2^(-1 - n) (HermiteH[n, y] HermiteH[1 + n, x] 
  - HermiteH[n, x] HermiteH[1 + n, y]))/((x - y) n!)
Protect[Sum]

which when used with

Sum[(HermiteH[k, -x] HermiteH[k, y])/(2^k k!), {k, 0, n}]

gives the desired result.

A couple of words of caution, though. This is deliberately overriding the built-in behavior of Sum and may affect its behavior in uncertain ways. So, if you decide to take this route, make the substitutions as specific as possible, so that you do not run into unintended behavior.

$\endgroup$
11
  • $\begingroup$ I don't doubt that it is a correct expression, but for symbolic manipulation it is quite useless, since I am trying to get simple algebraic expressions for more complicated quantities than the ones shown here (i.e. sums that I can't do by hand like this one and would like to know whether they simplify or not in "known mathematics"). The question is, why exactly does Mathematica think its answer is simpler than mine, and can this be changed? $\endgroup$ Commented Apr 13, 2012 at 10:38
  • $\begingroup$ @episanty I answered the question of why it thinks its form is simpler: it does not know about the alternatives. Also, there may be cases where the alternative explicitly does not work, so then Mathematica's answer would be the correct one. It is those cases you have to be careful of before you attempt to alter its behavior. That said, I added a method to do exactly that in my answer. $\endgroup$
    – rcollyer
    Commented Apr 13, 2012 at 14:40
  • $\begingroup$ Wouldn't it be safer to create a set of rules ? $\endgroup$ Commented Apr 13, 2012 at 14:44
  • $\begingroup$ @b.gatessucks on the surface, yes. But, the form Sum[...] /. ... doesn't work in this case because the simplification occurs first. The Sum has to be held. So, while not quite as safe as a rule, this was the most straightforward method to accomplish the task automatically. $\endgroup$
    – rcollyer
    Commented Apr 13, 2012 at 14:50
  • 1
    $\begingroup$ @rcollyer hmmmm. Looks like a problem without any reasonable solution, then. Thanks! $\endgroup$ Commented Apr 15, 2012 at 2:50

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