# Leave Kronecker deltas unevaluated

When performing sums over Kronecker deltas, how can I tell Mathematica to leave deltas that are not summed over unevaluated? In particular, the following expression contains indices $i$, $j$, $k$, $l$. Only $k$ and $l$ are summed over. I'd like Mathematica not to resort to cases but give output that still shows the $i,j$ index structure.

Assuming[N \[Element] Integers && N > 1,
Sum[KroneckerDelta[i, j]
(a KroneckerDelta[i, 1] KroneckerDelta[l, 1] KroneckerDelta[i, l] + b (KroneckerDelta[i, l] +
2 KroneckerDelta[i, 1] KroneckerDelta[l, 1]))
KroneckerDelta[k, l]
(a KroneckerDelta[j, 1] KroneckerDelta[k, 1] KroneckerDelta[i,
l] + b (KroneckerDelta[j, k] + 2 KroneckerDelta[j, 1] KroneckerDelta[k, 1])), {k, N}, {l, N}]]


Output: $$\begin{array}{ll} (a+3 b)^2 & i=1\land j=1\land N>1 \\ -b^2 (\lceil j\rceil -\lfloor j\rfloor -1) & i-j=0\land j>1\land j-N\leq 0\land N>1 \\ \end{array}$$

You can use Inactive to render part of the formula inert to evaluation. So Inactive[KroneckerDelta][i, j] will format nicely as a delta, but it will not be considered for any evaluation rules.

This should probably do what you want:

Assuming[{n, i, j} \[Element] Integers && n > 1 && i > 1 && j > 1,
Sum[Inactive[KroneckerDelta][i,
j] (a Inactive[KroneckerDelta][i, 1] KroneckerDelta[l,
1] KroneckerDelta[i, l] +
b (KroneckerDelta[i, l] +
2 Inactive[KroneckerDelta][i, 1] KroneckerDelta[l,
1])) KroneckerDelta[k,
l] (a Inactive[KroneckerDelta][j, 1] KroneckerDelta[k,
1] KroneckerDelta[i, l] +
b (KroneckerDelta[j, k] +
2 Inactive[KroneckerDelta][j, 1] KroneckerDelta[k, 1])), {k,
n}, {l, n}]]


Furthermore, I strongly advice against using capital letters as variables. In your code it seems that everything went okay, but the symbol N has a built-in meaning and it's very easy to cause difficult-to-trace errors when you use it as a variable. As a rule of thumb: if the symbol turns black on its own (instead of blue), then use something else. Even better: just don't use symbols that start with capitals.

• There seems to be a mistake here. Running your code, I get a result that is completely independent of $a$. Oct 9 '17 at 15:51
• Maybe you could describe the desired output so I can try to work towards that? I'm not quite sure I understand where you want to end up. Oct 10 '17 at 9:08