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

Dear all, I'm following the calculations on the Schwarzschild tutorial to develop my own calculation.

I'd like to consider the Einstein equations with cosmological constant

einseq := Eq_{\mu \nu} = G_{\mu \nu}  + \Lambda g_{\mu \nu};

Then, I'd like to substitute the expressions for the Einstein tensor ($G{\mu\nu}$) and the metric ($g{\mu \nu}$),

substitute(einseq, eins);

but the substitution is not complete (see the picture).


  • Even if I try to substitute the metric, there is no substitution rule for the metric
  • Whether I try to substitute two tensorial expressions, I obtain a weird equation (See picture)


  • Is there a way of substitute multiple tensor expressions on a equation?
  • Is it possible to substitute the metric?
in General questions by (7.9k points)

1 Answer

+1 vote
Best answer

That 'weird' equation does look ok, but it's perhaps a bit of an unusual notation. Can you run collect_components after that, and let me know if that makes more sense?

The logic behind all this is that Cadabra has the concept of an 'anonymous component tensor', which is what you get when you substitute values for components. Such a tensor is displayed as a 'box' with the indices of the original tensor, and then a list of all components following the large bracket. In this way you can have expressions which are 'half evaluated' (as you noticed in your first picture, where the metric has not yet been substituted).

We are working on making this somewhat less scary to look at, but until that work is done, it usually helps to 'collect all anonymous tensors in a sum', which is what collect_components does.

by (64.9k points)
selected by

Hi Kasper, I tried the collect_components algorithm, but it crashes the kernel.

I'm using Version 2.2.7 (build 2140.d81535e3eb dated 2019-07-22)

Thank you for explaining the philosophy behind Cadabra!

Can you email info@cadabra.science a minimal example notebook which exhibits the crash? Then I'll have a look.

Sent! (sorry for the delay)

Hi again Kasper, I saw that you created a new branch on github fix/collectcomponent. Should I try compiling the new branch? Thank you.

You can, but it doesn't yet solve your problem, so I didn't ping you yet about it.

One thing that your example messes up is that at some stage you create the sum of an expression which is an equation, plus another expression. That 'looks' right, but internally it is rubbish. The new branch will warn you against that, but there is still something else not quite right that prevents collect_components from working right.

Sorry, have been very busy...

Hi @Kasper

I was checking the dev branch fix/collectcomponent and noticed that I can proceed with my calculations. I'm not at work now, but I'll send you feedback tomorrow. Thank you very much.

All is merged into master now, please use that branch. You will need to be careful about doing things like

ex1:= A = B;
ex2:= C;
ex3:= @(ex1) - @(ex2);

as that is not allowed, but you can do

ex1:= A = B;
ex2:= C = D;  
ex3:= @(ex1) - @(ex2);

in which case ex3 reads

 A-C = B-D

Let me know.