Simplifying sums over distinct indices I'm currently working quite a bit with sums of the form
$$S = \sum_{a = 1}^N \sum_{b = 1}^N  \sum_{c = 1}^N \mathbf{I} \left[ a, b, c \text{ all distinct} \right] f (a, b, c) $$
where $f$ often has some symmetries with respect to its arguments.
For my purposes, it is often useful to rewrite such expressions in the form
$$S = \sum_{a = 1}^N \sum_{b = 1}^N  \sum_{c = 1}^N f (a, b, c) - 3 \sum_{a = 1}^N \sum_{b = 1}^N f(a, b, b) + 2\sum_{a = 1}^N  f (a, a, a)$$
(the above holds when $f$ is symmetric in its arguments) and similar.
My question is whether there is a good reference for simplifications of this form.
If it comes to it, I can derive these expressions carefully by hand by applying the inclusion-exclusion principle, and so on, but by the stage that I'm working with quadruple sums, I don't trust my own calculations as much. It would be useful to have a reference text against which to check these calculations.
 A: Firs, let us drop the symmetry assumption. Let $f$ have $n$ arguments. This can be solved using Möbius inversion over the poset of partitions of $n$, ordered by refinement (see the last example). It turns out there is a nice formula for this, which leads to a nice formula when the symmetry assumption is added back in.
Specifically, assuming symmetry, your sum ranges over all integer partitions $\lambda$ of $n$, where the size of each part indicates a number of arguments constrained to be equal. Given a partition, let $m_i$ be the number of occurrences of $i$ (the multiplicity of $i$). Then the coefficient of the summation corresponding to $\lambda$ is
$$
(-1)^{n-(m_1+\dots+m_n)}\frac{n!}{\prod_{i=1}^n i^{m_i}\cdot m_i!}
$$
Coincidentally (?), the absolute value of this coefficient is the number of permutations of $\{1,\dots,n\}$ whose cycle structure is $\lambda$.
This agrees with your example:
$$
\begin{array}{l|l|c}
\text{Summation} & \lambda & \text{Coefficient}\\\hline
\sum\sum\sum f(a,b,c) & (1,1,1)&(-1)^{3-(3)}\frac{3!}{1^3\cdot 3!}=1
\\
\sum\sum f(a,a,b) & (2,1)&(-1)^{3-(1+1)}\frac{3!}{1^1\cdot 1!\cdot 2^1\cdot 1!}=-3
\\
\sum f(a,a,a) & (3)&(-1)^{3-(1)}\frac{3!}{3^1\cdot 1!}=2
\end{array}
$$

I found a self-contained proof of why this works! Let's deal with a $d$-dimensional sum, your post was $d=3$. Furthermore, I will not assume $f$ is symmetric at first, then add that assumption in at the end.
Let $V=\{1,\dots,N\}^d$ be the total set of index vectors, and let $W$ be the set of index vectors where the indices are distinct. Furthermore, given $v\in V$ and $\pi \in S_d$, let $\pi(v)$ denote the vector obtained by permuting the indices of $v$ according to $\pi$. I claim that
$$
\sum_{w\in W}f(w)=\sum_{\substack{v\in V,\pi \in S_d\\\pi(v)=v}}(-1)^{\text{sign}(\pi)} f(v)
$$
To be clear, the second summation is over all ordered pairs $(v,\pi)$ which satisfy $\pi(v)=v$. The idea is that for any $v$ with repeated indices, the permutations fixing $v$ come in pairs with opposite sign, so the net contribution of $v$ is zero, while permutations with distinct indices appear exactly once as $(v,\text{id})$.
Therefore, letting $P$ range over partitions of $V$ and $V_P$ be the set of index vectors such that $v_i=v_j$ when $i$ and $j$ are in the same part of $P$, then
\begin{align}
\sum_{w\in W}f(w)
  &=\sum_{\pi}(-1)^{\text{sign}(\pi)}\sum_{\pi(v)=v}f(v)
\\&=\sum_{P} (-1)^{n-|P|}(\text{# $\pi$ w/ cycle structure $P$})\sum_{v\in V_P}f(v)
\\&=\sum_{P} (-1)^{n-|P|}\left(\prod_i (P_i-1)!\right)\sum_{v\in V_P}f(v)
\end{align}
Finally, if we add in the assumption that $f$ is symmetric, then letting $V_{\lambda}$ be the set of vectors where the first $\lambda_1$ are equal, and the next $\lambda_2$ are equal, etc, and letting $m_1,m_2,\dots,$ denote the multiplicities of this $\lambda$, then
$$
\begin{align}
\sum_{w\in W}f(w)
&= \sum_{\lambda}(-1)^{n-\text{len}(\lambda)}\left(\prod_i (\lambda_i-1)!\right)(\text{# $P$ w/ shape $\lambda$})\sum_{v\in V_\lambda}f(v)
\\&= \sum_{\lambda}(-1)^{n-\text{len}(\lambda)}\left(\prod_i (\lambda_i-1)!\right)\binom{d}{\lambda_1,\lambda_2,\dots}\frac1{m_1!m_2!\cdots}\sum_{v\in V_\lambda}f(v)
\\&= \sum_{\lambda}(-1)^{n-\text{len}(\lambda)}\frac{d!}{\prod_i i^{m_i}\cdot m_i!}\sum_{v\in V_\lambda}f(v)
\end{align}
$$
