Sum with two indices, how to handle the condition $i\neq j$? I'm given
$$
\sum_{i,j=1, i \neq j}^{N} ij \tag 1
$$
I assume this is a short hand for
$$
\sum_{i=1}^{N}
\Bigg (
\sum_{j=1}^{N} ij 
\Bigg ) 
\qquad? \tag 2
$$
But where does $i\neq j$ belong, to the inner or outer sum?
Example with $N=2$ and $i\neq j$ in the inner sum:
\begin{align}
\sum_{i,j=1 \\i\neq j}^{2} ij
&=
\sum_{i=1}^{2}
\Bigg (
\sum_{j=1, i \neq j}^{2} ij 
\Bigg ) 
\tag 3
\\
&=\sum_{i=1}^{2}
\Bigg (
i1+i2
\Bigg )
\tag 4
\\
&=
(11+12 + 21 + 22)
\tag 5
\\
&\text{\{Now discard 11 och 22\}}\\
&=23
\end{align}
I guess the end result is correct, but I don't think my approach is correct ("Now discard"). How should I handle the condition $i\neq j$?
 A: The sum $\sum_{i, j}^N ij$ could be thought as the iterative product of a column of natural numbers from $1$ to $N$ with $N$ lines of a list of numbers from $1$ to $N$. That makes $N^2$ computations:
$$\sum_{i, j}^N ij = (1\times 1 + 1\times2 +...+1\times N) + (2\times 1 + 2\times2 +...+2\times N) + (...) + (N \times 1 + N \times 2 +... + N \times N)$$
Now with the condition $i \neq j$ you exclude all products whose indices are the same (meaning every $1\times1, 2\times2 ... N\times N$). Now you have $N \times (N-1)$ computations.
$$\sum_{i, j : i \neq j}^N ij = (1\times2 +...+1\times N) + (...) + (N \times 1 + N \times 2 +... + N \times N-1)$$
You could also think of it as:
$$\sum_{i, j : i \neq j}^N ij =\sum_{i, j}^N ij - \sum_{i}^N ii $$
A: A simple way is to develop the square of $\sum_{i=1}^N{i}$ and to separate the two cases, $i=j$ and $i \ne j$:
$$\left(\sum_{i=1}^N {i}\right)^2 = \sum_{i,j=1}^N{ij} = \sum_{i,j=1 ; i \ne j}^N{ij} + \sum_{i,j=1; i=j}^N{ij}$$
$$ = \sum_{i,j=1; \,i \ne j}^N{ij} + \sum_{i=1}^N{i^2}$$
As
$$\sum_{i=1}^N {i} = \frac{N(N+1)}{2} $$
And
$$\sum_{i=1}^N {i^2} = \frac{N(N+1)(2N+1)}{6} $$
We get
$$ \sum_{i,j=1 ;\,i \ne j}^N{ij} = \frac{N^2(N+1)^2}{4} - \frac{N(N+1)(2N+1)}{6} = \frac{3N^4+2N^3-3N^2-2N}{12}$$
A: If you're familiar with the Kronecker delta You can write that sum as the following:
$$\sum_{i=1}^{N}\sum_{j=1}^N (1 -\delta_{ij}) ij$$
If $i = j$ then $\delta_{ij}= 1$ and that will cancel that turm of the sum
