Function Repository Resource:

QuadraticLatticeSum

Source Notebook

Sum an expression over integer lattice points inside a quadratic region

Contributed by: Arnoud Buzing

ResourceFunction["QuadraticLatticeSum"][expr,{x1,x2,,xn},Q,L,B]

sums expr over integer lattice points inside the quadratic region .

Details and Options

The lattice points x are defined by x∈ℤn.
The argument Q must be a nn symmetric positive definite numeric matrix.
The argument L is a numeric vector of length n.
The argument B is a numeric scalar constant term.

Examples

Basic Examples (3) 

Sum 1 over all integers satisfying x2-4<=0:

In[1]:=
ResourceFunction["QuadraticLatticeSum"][1, {x}, {{1}}, {0}, -4]
Out[1]=

Sum 1 over all points in or on the unit disk, x2+y2<=1:

In[2]:=
ResourceFunction["QuadraticLatticeSum"][1, {x, y}, IdentityMatrix[2], {0, 0}, -1]
Out[2]=

There are 5 points, namely (0,0), (-1,0), (1,0), (0,-1), (0,1):

In[3]:=
RegionPlot[x^2 + y^2 - 1 <= 0, {x, -2, 2}, {y, -2, 2}, GridLines -> {Range[-2, 2, 1], Range[-2, 2, 1]}]
Out[3]=

Compute a lattice sum over an ellipsoid:

In[4]:=
ResourceFunction["QuadraticLatticeSum"][
 x^2 - y^2, {x, y}, {{2, 0}, {0, 1}}, {0, 2}, -7]
Out[4]=

Plot the ellipsoid:

In[5]:=
RegionPlot[
 Transpose[{x, y}] . {{2, 0}, {0, 1}} . {x, y} + {0, 2} . {x, y} - 7 <= 0, {x, -4, 4}, {y, -5, 3}, GridLines -> {Range[-4, 4, 1], Range[-5, 3, 1]}]
Out[5]=

Scope (2) 

Compute x2+y2 over lattice points defined by an ellipsoid:

In[6]:=
ResourceFunction["QuadraticLatticeSum"][
 x^2 + 2 y, {x, y}, {{2, 0}, {0, 1}}, {0, -2}, -3]
Out[6]=

Plot the corresponding ellipsoid:

In[7]:=
RegionPlot[
 Transpose[{x, y}] . {{2, 0}, {0, 1}} . {x, y} + {0, -2} . {x, y} - 3 <= 0, {x, -3, 3}, {y, -2, 4}, GridLines -> {Range[-3, 3, 1], Range[-2, 4, 1]}]
Out[7]=

Compute the number of lattice points in a sphere with radius 2:

In[8]:=
ResourceFunction[
 "QuadraticLatticeSum"][1, {x, y, z}, {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {0, 0, 0}, -4]
Out[8]=

Plot the region:

In[9]:=
RegionPlot3D[
 Transpose[{x, y, z}] . {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}} . {x, y, z} + {0, 0, 0} . {x, y, z} - 4 <= 0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Mesh -> None, PlotStyle -> Opacity[.5]]
Out[9]=

Possible Issues (4) 

The number of variables must match the dimensionality of the region:

In[10]:=
ResourceFunction[
 "QuadraticLatticeSum"][1, {x, y, z}, {{1, 0}, {0, 1}}, {0, 0}, -1]
Out[10]=

You must give a non-empty list of symbols:

In[11]:=
ResourceFunction[
 "QuadraticLatticeSum"][1, {}, {{1, 0}, {0, 1}}, {0, 0}, -1]
Out[11]=

Coefficients must have all numerical values:

In[12]:=
ResourceFunction[
 "QuadraticLatticeSum"][1, {x, y}, {{1, 0}, {0, 1}}, {"a", 0}, -1]
Out[12]=

Specified matrices must be positive-definite:

In[13]:=
ResourceFunction[
 "QuadraticLatticeSum"][1, {x, y}, {{1, -2}, {0, 1}}, {0, 0}, -1]
Out[13]=

Publisher

Arnoud Buzing

Version History

  • 1.0.0 – 25 March 2026

Related Resources

License Information