# Rule for multiplying of Kronecker-delta-type functions

I am trying to introduce a rule of multiplication of entries of a matrix which would have the following property:

delta[k,i]*delta[k,j]=delta[k,i]*delta[i,j]


and then produce some manipulation with the matrix, for example, calculate its square with respect to this rule. How can I introduce such rule in Mathematica? Of course, the multiplication of entries which have not equal indexes should be usual one.

UPD Also delta is symmetric. So, I expect instead of

In[1]:= Clear[delta];
delta[k_, i_]*delta[k_, j_] :> delta[k, i]*delta[i, j];
delta[k_, i_] :> delta[i, k];
FullSimplify[delta[0, 1] (delta[0, 2] - delta[2, 1])]
Out[33]= delta[0, 1] (delta[0, 2] - delta[2, 1])


to get 0 as the answer.

• Is there a problem with just directly using KroneckerDelta? If so, can you provide more details about your actual use-case? It's a little unclear exactly what you would need. Something like a replacement Rule that looks inside expressions and sees when arguments to deltas overlap could work, but we need more info. For instance, are you manipulating symbolic matrices defined with these deltas? Are repeated indices implicitly summed over? Etc. Feb 22, 2016 at 18:05
• start with this: delta[k_, i_]*delta[k_, j_] :> delta[k, i]*delta[i, j]. ( This may not work if your products are actually embedded in more complicated expressions ) Feb 22, 2016 at 18:07
• If you post a specific example, Mathematica input + desired result, it might be easier to make useful suggestions. Feb 22, 2016 at 18:08
• If you make delta orderless then a replacement rule for zero might suffice: In[1391]:= Clear[delta]; Attributes[delta] = {Orderless}; In[1393]:= Expand[delta[0, 1] (delta[0, 2] - delta[2, 1])] /. delta[k_, i_]*delta[k_, j_] - delta[k_, i_]*delta[i_, j_] :> 0 Out[1393]= 0 Feb 22, 2016 at 22:49

note for your symmetry rule I expect you want to put the indices in some canonical order, here put lowest index first.

Expand[delta[0, 1] (delta[0, 2] - delta[2, 1]) ] //. {
delta[k_, j_] /; k > j :> delta[j, k] ,
delta[k_, i_]*delta[k_, j_] :> delta[k, i]*delta[i, j]}


0

Note expand is needed so the products appear explicitly. This is going to break if you have certain more complicated expressions such as products with more than two deltas.

I expect this can be handled using Simplify with TransformationFunctions as well. (That would obviate the need for Expand and leave expressions alone if no simplification is possible)

• Many thanks! It seems that it works even for some products with more factors. Feb 23, 2016 at 6:36