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?
 A: I would evaluate this expression in the following way (in order):

*

*Select the $x$ value (starting with $x=1$)

*Then evaluate $M(x)$

*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))
$$


*Proceed to the next value of $x$ (in this case it's $x=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))$?
A: 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)$
