# Partial derivative (double indexing) of double sum

Assume an expression $$E = \sum\limits_{i}\sum\limits_{j} \log a_{ij} - \sum\limits_{i=1}^j r_i\left(\sum\limits_{j} a_{ij} - 1\right)$$ I need to find following derivative $$\frac{\partial E}{\partial a_{ij}}$$ So $$\frac{\partial E}{\partial a_{ij}} = \frac{\partial \sum_{i}\sum_{j} \log a_{ij}}{\partial a_{ij}} - \frac{\partial \sum_{i=1}^j r_i (\sum_{j} a_{ij} - 1)}{\partial a_{ij}} \\$$ Then $$\frac{\partial \sum_{i}\sum_{j} \log a_{ij}}{\partial a_{ij}} = \frac{1}{a_{ij}}\\$$ But I'm not really sure what to do with the second component. It feels like this expression in brackets should be equal to $$1$$ after differentiation, but I don't know how to prove that. It doesn't also help to write a few terms for i.e. $$i = 2$$ and $$j = 3$$, as there is $$j$$ in the upper limit in the first sum, and it confuses me a bit.

It is not a problem of differentiation. Your expression $$\sum_{i=1}^j r_i\left(\sum_{j} a_{ij} - 1\right)$$ is not well-formed, for the reason you mention yourself.
If you replace it by $$\sum_ir_i\left(\sum_{j} a_{ij} - 1\right)$$ then its partial derivative with respect to $$a_{i,j}$$ will be $$r_i.$$
But if you insist on restricting your double sum to $$i\le j,$$ rather replace it by $$\sum_ir_i\left(\sum_{j\ge i} a_{ij} - 1\right)$$: then, its partial derivative with respect to $$a_{i,j}$$ will be $$r_i$$ if $$i\le j,$$ and $$0$$ if $$i>j.$$