# Redefining a function

+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

$$T_{\mu \nu}^{\text{eff}}= T_{\mu \nu}^{(0)}+\epsilon T_{\mu \nu}^{(1)}+\epsilon^{2} T_{\mu \nu}^{(2)}+\epsilon^{3}T_{\mu \nu}^{(3)}.$$

then I redefined the equation as the form

$$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)}.$$

I would like to obtain the $T_{\mu \nu}^{0}$, $T_{\mu \nu}^{1}$, $T_{\mu \nu}^{2}$ and $T_{\mu \nu}^{3}$ by substituting $a^{0}=a^{2}=a^{3}=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?

edited

+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_{\mu\nu}$.

by (65.1k points)