Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to define a Einstein summation convention in Mathematica?

Say, how to let Mathematica know T[i,i] equals T[1,1]+T[2,2]+T[3,3]? How to define the function T[i,j]?

I know there are several Mathematica-abased programs that can do this, but still I want to know how to define my own.

share|improve this question

migrated from Nov 15 '12 at 14:19

This question came from our site for professional and enthusiast programmers.

This is partially related ? – chris Dec 15 '12 at 16:01
up vote 5 down vote accepted

For a single Function T this is pretty easy:

T[i_, i_] /; ! NumberQ[i] := Sum[T[j, j], {j, 3}]

A quick test gives:

In[7]:= T[i, i]

Out[7]= T[1, 1] + T[2, 2] + T[3, 3]

If you want to always sum over two equal indices for several functions, this might need some extra work though.

share|improve this answer
Thanks, einbandi. The answer is just what I want. – pengfei_guo Nov 15 '12 at 6:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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