3
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ You might consider multiplying your summand with the factor Boole[2 x + 3 y + 5 z == 3] instead. $\endgroup$ – J. M. will be back soon Oct 15 '16 at 15:08
  • $\begingroup$ @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$. $\endgroup$ – user58955 Oct 15 '16 at 15:38
  • 1
    $\begingroup$ 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". $\endgroup$ – J. M. will be back soon Oct 15 '16 at 15:42
  • $\begingroup$ @J.M. I see, it gave the same answer after more than one hour... $\endgroup$ – user58955 Oct 16 '16 at 1:02
  • $\begingroup$ Are x,y,z restricted to integers? Is the R cubed an error? $\endgroup$ – mikado Oct 16 '16 at 10:57
2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – user58955 Oct 17 '16 at 8:27
  • $\begingroup$ Suggest you ask a new question. It will get more attention than a comment on an answered question. $\endgroup$ – mikado Oct 17 '16 at 17:35

Your Answer

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

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