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

Hi. . 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}

to

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

thanks

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};
evaluate(ex);

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.

by (82.6k points)

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

{t,x,y,z}::Coordinate.
{\mu,\nu}::Indices(values={t,x,y,z}).

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

The following works:

{\mu,\nu}::Indices(values={1,2,3,4}, position=fixed);
\partial{#}::PartialDerivative;
{A^{1},A^{2},A^{3},A^{4}}::Depends(\partial{#});
ex:=\partial_{\mu}{A^{\mu}};
evaluate(ex);

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

A^{\mu}::Depends(\partial{#});

which would be more natural.

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

{t,x,y,z}::Coordinate.
{\mu,\nu}::Indices(values={t,x,y,z}).
g_{\mu\nu}::Metric.
g^{\mu\nu}::InverseMetric.
\partial{#}::PartialDerivative.
g_{\mu\nu}::Depends(\partial{#}).
metric:={g_{t t}=z,g_{x x}=z,g_{y y}=z,g_{z z}=z};
complete(_,$g^{\mu\nu}$);
ex:=\partial^{\mu}{g_{\mu\nu}} A^{\nu};
evaluate(_,metric,rhsonly=True);

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.

...