# Simplification for a double summation where the upper limit of the inner index depends on the value of the outer index?

$$\sum_{x=1}^{N} \sum_{y=1}^{M(x)} (1 + a\cdot f\left(x\right))(1 + b \cdot f\left(y\right)) \tag{1}$$

where $$N$$, $$a$$, and $$b$$ are integer constants. $$M$$ is also an integer but changes for every value of x, which makes the index of the second summation dependent on the first. The problem is the relationship $$M(x)$$ is analytically difficult to define. Is there a way to simplify this expression?

• +1 for such an interesting question! Oct 4, 2020 at 19:16

I would evaluate this expression in the following way (in order):

1. Select the $$x$$ value (starting with $$x=1$$)
2. Then evaluate $$M(x)$$
3. Now you have a sum of the form, where now we have $$M\equiv M(x),f\equiv f(x)$$:

$$\tag{1} \sum_{y=1}^{M} \left(1 + a\cdot f\right)(1 + b \cdot f\left(y\right))$$

1. Proceed to the next value of $$x$$ (in this case it's $$x=2$$)
2. Go back to Step 2, 3, and 4, where the $$M$$ and $$f$$ can be slightly different (depending on the new value of $$x$$) from what you had before.

I'm certain that there's no way to "simplify" your expression without knowing the functional form of $$M(x)$$, for example is it $$M(x)=\cos(x)$$ or is it $$M(x)=x^2 - \log(x) + \max(x,y,f(x),f(y),f(x)-f(y))$$?

• Yup, I expanded the inner summation first: \displaystyle \begin{aligned} \sum_{x=1}^N \sum_{y=1}^{M(x)} (1+af(x))(1+bf(y)) & = \sum_{x=1}^N \sum_{y=1}^{M(x)} 1 + af(x) + bf(y) + abf(x)f(y) \\[0.3cm] & = \sum_{x=1}^N \bigg[ M(x)[1+ af(x)] \bigg] + b \sum_{x=1}^N \bigg[ [1 + af(x)] \sum_{y=1}^{M(x)} f(y) \bigg]\end{aligned} Oct 4, 2020 at 19:23
• Well done !!!!! But you'd still have to use the procedure in my answer to take care of the $b$ term in your last expression. Oct 4, 2020 at 19:38
• Yup, for loop all the way 😉! Thank you for your help and the edits. Oct 4, 2020 at 19:45

Not sure what you are looking for but you can change the order of integration as long as you include all cells in the yellow triangle. For instance,

$$\sum_{y=1}^{N} \sum_{x = M^{-1}(y)}^N (1 + a f(x))(1 + b(f(y))$$

is the same.

If $$M(x) = x$$, the sum is over the yellow trangular region

You can also expand the product

$$\sum_{x=1}^{N} \sum_{y = 1}^{M(x)} (1 + a f(x))(1 + b(f(y)) = \sum_{x=1}^{N} \sum_{y = 1}^{M(x)} 1 + a f(x) + bf(y) + abf(x)f(y)$$