I am trying to calculate the polynomial kernel expansion using Mathematica. I have tried the Expand and Simplify functions with no success.

I do:

(Sum[Subscript[x, i] * Subscript[y, i], {i, n}] + c)^2 // Expand

And I get (which seems correct):

$$ \left(\sum_{i=1}^n x_i y_i + c\right)^2 = c^2 + 2c\sum_i^n x_iy_i +\left(\sum_i^n x_iy_i\right)^2 $$

I try to expand the last part by doing:

Sum[Subscript[x, i] * Subscript[y, i], {i, n}]^2 // Expand

But again I get the same form:

$$ \left(\sum_i^n x_iy_i\right)^2 $$

I would like to get something closer to:

$$ \left(\sum_{i=1}^n x_i y_i\right)^2 = \sum_{i=1}^n \left(x_i^2\right) \left(y_i^2 \right) + \sum_{i=2}^n \sum_{j=1}^{i-1} \left( \sqrt{2} x_i x_j \right) \left( \sqrt{2} y_i y_j \right) $$

Any ideas on how to approach this?

  • $\begingroup$ In the first instance, you are expanding (a + c)^2, which Mathematica handles routinely, even if a is a Sum. In the second, you are asking Mathematica to restructure the Sum itself, which it does not do routinely. $\endgroup$ – bbgodfrey Feb 27 '16 at 5:06
  • $\begingroup$ To follow up on @bbgodfrey's comment: in short, Mathematica won't do that for you. You will have to implement your own transformation rule based on the multinomial theorem. $\endgroup$ – MarcoB Feb 29 '16 at 14:43
  • $\begingroup$ Thanks, I will look into transformation rules. $\endgroup$ – JC1 Feb 29 '16 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.