# Shorten a sum of many terms by introducing a rule for scalar product and Kronecker deltas and using repeated replacements

There is a sum of many terms that I would like to simplify by introducing a notation for scalar product of two vectors. Each term is a product of constants and of several components of 3D vectors: b;n;x. So application of this kind of rule for scalar product would combine 3 terms into 1.

Using UpValue for the notation of subindexes as the vector components:

x /: MakeBoxes[x[a_], fmt_] := MakeBoxes[Subscript[x, a], fmt]
b /: MakeBoxes[b[a_], fmt_] := MakeBoxes[Subscript[b, a], fmt]
n /: MakeBoxes[n[a_], fmt_] := MakeBoxes[Subscript[n, a], fmt]



Defining a tensor that appears in the sum

cs[i_, j_, k_, l_] :=
(2 \[Mu] \[Nu]/(1 - 2 \[Nu])) KroneckerDelta[i,j] KroneckerDelta[k,l] + \[Mu] (KroneckerDelta[i,k] KroneckerDelta[j, l] + KroneckerDelta[i, l] KroneckerDelta[j, k])


Using the vectors and the tensor defined above, we can compute the following sum below. This sum has many terms.

sum=Sum[cs[k, p, i, m] b[
k]  (-((
KroneckerDelta[j, m] x[i] +
KroneckerDelta[i, m] x[j] + ((-3 + 4 \[Nu]) KroneckerDelta[i, j] -
3 x[i] x[j]) x[m])/(
16 \[Pi] r^2 \[Mu] (-1 + \[Nu])))) n[p], {k, 1, 3}, {p, 1, 3}, {i,
1, 3}, {m, 1, 3}]


Now, you can see my attempt to simplify sum. I have tried to simplify it by usingReplaceRepeatedand HoldPattern:

sum //. {
HoldPattern[
a_ v1_[1] v2_[1] + a_ v1_[2] v2_[2] + a_ v1_[3] v2_[3]] :>
a \[LeftAngleBracket]v1 , v2\[RightAngleBracket],
HoldPattern[
a_ v1_[1] KroneckerDelta[1,j_] + a_ v1_[2] KroneckerDelta[2,j_] + a_ v1_[3] KroneckerDelta[3,j_]] :>
a v1[j]}
% // Simplify


This approach appears to simplify some terms by introducing a notation for scalar product like <n,x> and for Kronecker delta functions, perhaps not all of them. My question is: can this sum be further simplified with this type of definition for scalar products?