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

If I define an object like

expr:= A^{\mu \nu} B_{\nu \rho} C^{\rho \lambda};

and perform some manipulation (for instance the following)

rename_dummies(expr);

How do I access the resulting expression to perform further manipulations? For example, I'd like to do something like

\partial_\sigma expr

or

D_{\kappa \mu} expr

or something like that such that the resulting object has the appropriate free indices. Is there a way to do this without explicitly inserting the original value?

in General questions by (740 points)
edited by

2 Answers

+2 votes
 
Best answer

Your own answer works, but makes it impossible to use that same expression with a different free index. A more Cadabra-like way of doing this is to declare

{\mu,\nu,\rho,\lambda,\phi,\chi}::Indices.
ex1:= T^{\mu\lambda} = A^{\mu \nu} B_{\nu \rho} C^{\rho \lambda};
ex2 := D_{\kappa \mu\nu} T^{\mu\nu};

and then substitute expr with

 substitute(ex2, ex1);

In Cadabra, equations have names, but those names are not themselves tensors. Those equation names (ex1 and ex2 above) do not carry indices.

by (82.5k points)
selected by

Thanks for your response. But how do I now access the result of the substitution as a tensor?

You can do something similar there; e.g. instead of what I wrote for ex2, write

ex2:= S_{\kappa} = D_{\kappa\mu\nu} T^{\mu\nu};

Then you can use this $S_\kappa$ tensor again in another expression and substitute similar to what I did above.

In other words: do not view the Python name for an expression (ex1 and ex2) above as a tensor; rather, write out that tensor explicitly. If you find it confusing, you could e.g. write

 T:= T^{\mu\lambda} = ...

instead of the first line, so use the same name T for the expression and for the tensor that it defines.

This all comes from the fact that in Cadabra there is a difference between the "programming language" (Python) and the "maths language" (LaTeX). Python names do not know about indices.

+1 vote

Couldn't find this in the documentation, but this seems to work:

expr:= A^{\mu \nu} B_{\nu \rho} C^{\rho \lambda};

rename_dummies(expr);

D_{\kappa \mu} @(expr);
by (740 points)
...