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

Hai, I have a problem defining a new function.

I am using Cadabra for perturbation analysis in which I want to calculate higher-order perturbation terms. I have to define the result of each order term as independent tensors i.e, I have

Teffμν=T(0)μν+ϵT(1)μν+ϵ2T(2)μν+ϵ3T(3)μν.

then I redefined the equation as the form

T(eff)μν=a0T(0)μν+a1T(1)μν+a2T(2)μν+a3T(3)μν.

I would like to obtain the T0μν, T1μν, T2μν and T3μν by substituting a0=a2=a3=0 like conditions, for which have used the command as

Ex:=T_{\mu \nu}^(eff)=a^{0} T_{\mu  \nu}^(0)
    +a^{1}  T_{\mu  \nu}^(1)
    +a^{2} T_{\mu  \nu}^(2)
    +a^{3}T_{\mu  \nu}^(3);
T_{\mu \nu}^{0}:=substitute(Ex,$a^{1}->0,a^{2}->0,a^{3}->0$);
T_{\mu \nu}^{1}:=substitute(Ex,$a^{0}->0,a^{2}->0,a^{3}->0$);
T_{\mu \nu}^{2}:=substitute(Ex,$a^{0}->0,a^{1}->0,a^{3}->0$);
T_{\mu \nu}^{3}:=substitute(Ex,$a^{0}->0,a^{1}->0,a^{2}->0$);

But the results are showing the same. How can I rectify it?

in General questions by (210 points)
edited by

1 Answer

+1 vote

Almost all Cadabra functions modify the expression in-place. So you first need to make a copy of the expression, and then apply the substitution.

There are a few other things not quite right in your example: Ex is a class name (so you cannot use it as the name of an expression; use ex with lowercase instead), and expressions must have valid Python names (so you cannot call them T_{\mu\nu}^{1}).

Here's something that works:

ex:=Teff_{\mu \nu} = a^{0} T0_{\mu \nu}
    +a^{1} T1_{\mu  \nu}
    +a^{2} T2_{\mu  \nu}
    +a^{3} T3_{\mu  \nu};

T0 = rhs(ex)
substitute(T0, $a^{0}=1, a^{1}=0, a^{2}=0, a^{3}=0$);

This sets the Python variable T0 equal to the mathematical expression T0μν.

by (85.0k points)
...