# double sum in NSum

I was trying to evaluate the sum of $e^{-\pi(x^2+y^2+z^2)}$ over lattice points $(x,y,z)\in \mathbb{Z}^3$ that satisfies $2x+3y+5z=3$ using the following code.

c = 3;
{x0, y0, z0} = {x, y, z} /.
Flatten[FindInstance[2 x + 3 y + 5 z == c, {x, y, z}, Integers]];
NSum[Exp[-Pi ((x0 + u)^2 + (y0 + u + 5 v)^2 + (z0 - u -
3 v)^2)], {u, -Infinity, Infinity}, {v, -Infinity, Infinity}]


And I got the following error message:

NSum::nsnum: Summand (or its derivative) -1. 3.14159 (2. u-2. (-1. u-3. v)+2. (1. +u+5. v)) Exp[-3.14159 (u^2+(-1. u-3. v)^2+(1+u+5. v)^2)] is not numerical at point v = 15.

while it still outputted some answer

0.0450814

I read the help file of NSum, which states that NSum can be used to evaluate multi-dimensional sums, so why is that error message? Doesn't NSum use some method that work in multidimensional case directly instead of reducing the dimension one by one?

Another question is, with that error message, how reliable is the answer?

• You might consider multiplying your summand with the factor Boole[2 x + 3 y + 5 z == 3] instead. – J. M.'s technical difficulties Oct 15 '16 at 15:08
• @J.M. I don't understand, I've written $(x,y,z)$ as $(x,y,z) = (x_0+u, y_0+u+5v, z_0-u-3v)$ for $(u,v)\in\mathbb{Z}^2$ so the sum is now taken over $u,v\in \mathbb{Z}^2$. – user58955 Oct 15 '16 at 15:38
• I'm merely suggesting a simpler approach that you can use to see if your purported transformation is doing what it's supposed to do: sum Boole[2 x + 3 y + 5 z == 3] Exp[-π (x^2 +y^2 +z^2)], considering you asked "how reliable is the answer". – J. M.'s technical difficulties Oct 15 '16 at 15:42
• @J.M. I see, it gave the same answer after more than one hour... – user58955 Oct 16 '16 at 1:02
• Are x,y,z restricted to integers? Is the R cubed an error? – mikado Oct 16 '16 at 10:57

The summand decays so rapidly that it is easy to see that the answer is correct. Consider all the solutions inside some sphere

sols =
Solve[x^2 + y^2 + z^2 < 12 && 2 x + 3 y + 5 z == 3, {x, y, z},
Integers]
(* {{x -> -2, y -> -1, z -> 2}, {x -> -1, y -> 0,
z -> 1}, {x -> 0, y -> 1, z -> 0}, {x -> 1, y -> 2,
z -> -1}, {x -> 2, y -> -2, z -> 1}, {x -> 3, y -> -1, z -> 0}} *)


The contributions at the largest radii are negligible. As the radius of the sphere increase, the contributions will drop off far faster than their number will increase.

Exp[-π (x^2 + y^2 + z^2)] /. N[sols]
(* {5.25549*10^-13, 0.00186744, 0.0432139, 6.51241*10^-9,
5.25549*10^-13, 2.2711*10^-14} *)


their total is very close to the value that Mathematica gave you via NSum

Total[%]
(* 0.0450814 *)


In this case, at least, the warning can be ignored. I think that it probably arises through some minor bug/feature in Mathematica that attempts symbolic evaluation of the sum without assigning values to all the variables.

• The Solve[] with range constraint is ridiculously slow when there are 5 variables (say i want integral solutions to 2x+3y+5z+7u+11v=3 --- much slower than writing 5 loops). Any way to boost the speed? – user58955 Oct 17 '16 at 8:27
• Suggest you ask a new question. It will get more attention than a comment on an answered question. – mikado Oct 17 '16 at 17:35