# Collect terms in a sum

Suppose I have this expression

    Sum[F[i, j] KroneckerDelta[j, k], {j, 1, 3}]

(* F[i, 1] KroneckerDelta[1, k] + F[i, 2] KroneckerDelta[2, k] +
F[i, 3] KroneckerDelta[3, k] *)


Is it possible for Mathematica to present the contracted result

F[i,k]


?

• note this is only true for i,k integers in {1,2,3}. That said even with appropriate assumptions it doesn't simplify as you'd like. – george2079 Jun 24 '14 at 18:56

While doing the Sum over j, you turn the second argument of F into a number. This concrete substitution has to be avoided.

To do this, we have to tell Mathematica that F[i,j] with a concrete number for j should be rewritten immediately as an expression that can be simplified to something involving F[i,k]. To do this, I add the following symbolic rule for F:

Clear[i, j, k];
F[i_, j_?NumericQ] := F[i, k] KroneckerDelta[k, j]

Assuming[k > 0 && k ∈ Integers && k < 4,
Simplify[Sum[F[i, j] KroneckerDelta[j, k], {j, 1, 3}]
]
]

(* ==> F[i, k] *)

• interesting but it seems not all that useful in general since you can only handle the one specific symbol k that way. – george2079 Jun 25 '14 at 15:58
• @george2079 Well, that's what the question is about. – Jens Jun 25 '14 at 16:58