# Discrete Sum of Function over a Region

I might have completely missed something in my search. I want to discretely sum over a function, $$f(x_i,y_j)$$ multiplied by some other function $$g$$ over a general region $$S$$.

$$\sum_{(x,y)\in S}f(x,y)g\Delta x \Delta y$$

where the region S is given, for example, by a polygon $$P$$.

1. For the polygon case, I know Mathematica can do this for an Integral as seen in the following example:

pol = Polygon[CirclePoints[4 \[Pi]/3, 6]]; Integrate[1, {x, y} \[Element] pol]

But this wont work if I try to do the same with Sum[].

I think one solution is to calculate the boundary of the polygon by hand, and then plug it into the Sum[] function. But there must be a better solution, given the complexity of the Polygon[] function?

1. What if it's a general region, for example by an inequality $$f(x_i,y_j)<0$$. Is there an easy way to do the sum over this region?

Thanks in advance! Any thoughts would be appreicated!

Update:

Henrik suggested DiscretizeRegion, it looks like it does discretize the region into triangles. But still, it won't work inside the Sum[] function.

• If the region consists of a continuoum of points, your sum does not make sense at all. – Henrik Schumacher Aug 5 at 19:17
• Yes I was hoping there is way to discretize the region nicely... – Histoscienology Aug 5 at 19:19
• Try DiscretizeRegion. But every meaningful sum would actually be only the discretization of an integral. And NIntegrate does the discretization automatically if needed. – Henrik Schumacher Aug 5 at 19:21
• Okay thanks, it looks like it does discretize the region geometrically but not computationally?... Am I missing something? – Histoscienology Aug 5 at 19:26
• What is "it"? Yes, DiscretizeRegion will only discretize geometrically in to a MeshRegion. NIntgrate approximates the integral by doing the geometric discretization under the hood. – Henrik Schumacher Aug 5 at 19:28