Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

In first, thanks to invent this useful tool

my question is

is there a way to expand dummy indices?

i want to change expression

A^{\mu} A_{\mu}


A^{1} A_{1} + A^{2} A_{2} + A^{3} A_{3} + A^{4} A_{4}


asked in General questions by

1 Answer

+1 vote

You need to declare the \mu index to run over the range that you want, e.g.

{\mu,\nu}::Indices(values={1,2,3,4}, position=fixed);

The fixed is there to tell cadabra that there is a distinction between upper and lower indices; for your problem that's not relevant. Then you can do

ex:=A^{\mu} A_{\mu};

to get what you want.

The evaluate algorithm can do much more, all having to do with evaluating tensor expressions in components, but if you do not tell it what the components are, it will just keep them as A_{1}, A_{2} and so on. If instead of the above you do e.g.

ex:= A^{\mu} A_{\mu};
evaluate(ex, $A_{1} -> x, A_{2} -> x+y, A_{4}->c$);

you would get $x A^{1} + (x+y) A^{2} + c A^{4}$. And so on.

answered by (61.8k points)

If there are derivative terms, e.g. $\partial_{\mu}{A^{\mu}}$, do we have to add the following definition?


Is it still prossible to use {0,1,2,3}?

The following works:

{\mu,\nu}::Indices(values={1,2,3,4}, position=fixed);

It does not yet work if you replace the 3rd line with


which would be more natural.

If i want to implement the following code using {},

metric:={g_{t t}=z,g_{x x}=z,g_{y y}=z,g_{z z}=z};
ex:=\partial^{\mu}{g_{\mu\nu}} A^{\nu};

how to do it?( sometimes, it seems be more nature to use {0,1,2,...})

You can't, at the moment, because the evaluate algorithm does not know that the shorthand $\partial_{1}{x^{1}}$ should evaluate to $1$. You can add that kind of stuff with substitution rules but it is going to be ugly. It's on the todo list to make this more natural, but it is not my highest priority item at the moment.

Ok, I see. Thanks.