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


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.

  • 1
    $\begingroup$ 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. $\endgroup$
    – march
    Feb 22, 2016 at 18:05
  • 1
    $\begingroup$ 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 ) $\endgroup$
    – george2079
    Feb 22, 2016 at 18:07
  • 3
    $\begingroup$ If you post a specific example, Mathematica input + desired result, it might be easier to make useful suggestions. $\endgroup$ Feb 22, 2016 at 18:08
  • 1
    $\begingroup$ @Dmitri. It seems that you have now asked 8 questions, many of which have excellent answers, but you have yet to accept any of them. While it is the intent of this site (and it is the motivation of the majority of its users) to provide answers to general questions that many people (not just the asker) can benefit from, it is still the case that answerers like to be thanked by having an answer that they spent time on accepted. Please consider spending a few seconds to either accept answers that answered your questions or commenting on those answers. $\endgroup$
    – march
    Feb 22, 2016 at 19:10
  • 2
    $\begingroup$ 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 $\endgroup$ Feb 22, 2016 at 22:49

1 Answer 1


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]}


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)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.