I have a double lattice sum and I was wondering how I could calculate this with Mathematica. In particular, I have a function $F:\mathbb{R}^2 \times \mathbb{R}^2 \to \mathbb{R}$ which takes as arguments a pair of points $x,y\in\mathbb{R}^2$, and I want to evaluate the sum
$$ \sum_{x\in L}\sum_{y\in L} F(x,y) $$
where $L\subset\mathbb{R}^2$ is some finite lattice, i.e. a collection of points in $\mathbb{R}^2$.
Now, I have tried using Outer
for this via
Total[Flatten@Outer[F[#1,#2] &, L, L]]
but with this, I obtain a sum of $F$ evaluated at real pairs $s,t\in\mathbb{R}$
F[s,t] + ...
which doesn't make sense, instead of $F$ evaluated at real vector pairs $x=(x_1,x_2),y=(y_1,y_2)\in\mathbb{R}^2$
F[{x_1,x_2},{y_1,y_2}] + ...
as it should be. I'm not sure how to remedy this, but any help with this would be much appreciated.
I am also open to recommendations for any alternative/better ways to perform such a double sum.
Extra Information
My function F
is defined as a conditional, i.e.
F[{x_,y_},{s_,t_}] = If[Abs[g[{x, y}]] < eps || Abs[g[{s, t}]] < eps, 0, W[{x - s, y - t}] * g[{x, y}] * g[{s, y}]]
for some other lattice functions g
and W
.
Thanks to answer below, I am able to evaluate the summation, but I obtain as an answer
If[Abs[\[Piecewise] 1 {-(27/2),(7 Sqrt[3])/2}==0&&0<={-27,7 Sqrt[3]}<=2 Sqrt[3]&&{-(27/2)+8 Sqrt[3],Sqrt[3]/2}==0 0 True ]<2.22045*10^-14,0,W[{{-(27/2),(7 Sqrt[3])/2},{-(27/2),(7 Sqrt[3])/2}}] g[{{-(27/2),(7 Sqrt[3])/2},{-(27/2),(7 Sqrt[3])/2}}]] +...
It seems that the double summation has not been executed entirely.
Edit
Thank you for all the solutions and comments, they have been helpful and I shall surely use those in the future. Sadly, due to the nature of my functions, they didn't work perfectly, but that was just because of how my functions were defined.
Although, I have found a solution that seems to work: To evaluate the double sum, I used the Map function twice
Total[Flatten@Map[Function[y, Map[Function[x, F[x,y]], L, L]]]]
I found this solution in another post given by @halirutan
F
toF[{x_, y_}, {s_, t_}] = If[Abs[g[{x, y}]] < eps || Abs[g[{s, t}]] < eps, 0, W[{x - s, y - t}]*g[{x, y}]*g[{s, y}]] // PiecewiseExpand
However, without the definitions of your functions andeps
the result gets unwieldly. $\endgroup$