# Define implicit dummy index?

I've been looking for a solution to this question for a while. I was wondering if anyone is aware of a way of defining symbolic dummy indices to implement Einstein's convention.

Let me explain with an example. I would like to define, say, an object with one index, defined this way (more or less):

T[i_]:=a[i,something]b[something]


so that, if I call the object multiple times, the variable "something" is always named in a different way. For example, I would like

T[i]T[i]


to return something like

a[i,symbol1]b[symbol1]a[i,symbol2]b[symbol2]


Does anyone know of a way to implement this?

I think that this should do the trick.

Module[{idx = 0},
T[i_] := (idx += 1; a[i, Subscript[s, idx]] b[Subscript[s, idx]])
]

• This is precisely what I was looking for! Thanks.
– Einj
Commented Sep 1, 2020 at 13:57

You might consider using the symbolic tensor capabilities of Mathematica. For example, define a to be a matrix and b to be a vector:

\$Assumptions = a ∈ Matrices[{d,d}] && b ∈ Vectors[d];


Then T is defined as:

T = TensorContract[TensorProduct[a,b],{{2,3}}];


and T.T is:

res = TensorContract[TensorProduct[T, T], {{1, 2}}]


TensorContract[TensorProduct[TensorContract[TensorProduct[a, b], {{2, 3}}], TensorContract[TensorProduct[a, b], {{2, 3}}]], {{1, 2}}]

This can be simplified with TensorReduce:

TensorReduce[res]


TensorContract[TensorProduct[a, a, b, b], {{1, 3}, {2, 6}, {4, 5}}]

For you particular example, it is possible to use the ResourceFunctions "ToTensor" and "FromTensor" and avoid TensorContract/TensorProduct:

T = a . b;
TensorReduce[T . T //ResourceFunction["ToTensor"]] //ResourceFunction["FromTensor"]


b.Transpose[a].a.b