Cadabra

Automatic multi-term simplification

This notebook illustrates how the automatic multi-term simplification algorithm meld can be used in a post_process function to simplify expressions immediately. For simpler computations, or computations that are already working and for which you do not want to show these simplifications at every step, this can be useful.
def post_process(ex): meld(ex) collect_terms(ex)
R_{a b c d}::RiemannTensor;
\(\displaystyle{}\text{Property TableauSymmetry attached to }R_{a b c d}.\)
By the first Bianchi identity, the sum of cyclic permutations of three indices is zero:
ex:=R_{a b c d} + R_{b c a d} + R_{c a b d};
\(\displaystyle{}0\,\)
Let's define a fully anti-symmetric tensor $A^{a b c}$ and a fully symmetric tensor $S^{a b c}$:
A^{a b c}::AntiSymmetric;
\(\displaystyle{}\text{Property AntiSymmetric attached to }A^{a b c}.\)
S_{a b c}::Symmetric;
\(\displaystyle{}\text{Property Symmetric attached to }S_{a b c}.\)
Contracting a fully anti-symmetric tensor with the Riemann tensor leads to the first Bianchi identity again, so should vanish:
ex:=R_{a b c d} A^{a b c};
\(\displaystyle{}0\,\)
ex:= (A^{a b c} + A^{c a b}) S_{a b c};
\(\displaystyle{}2\,A^{a b c} S_{a b c}\)
Note that the post-processing function only applies the meld algorithm once, so the best it could do was to combine the two anti-symmetric tensors. If you apply meld again, it sees the zero:
meld(ex, repeat=True);
\(\displaystyle{}0\,\)
You could have achieved the above by instead using a converge construction inside the post-processing function.
Some other assorted examples now. Meld will automatically factor out scalar expressions:
ex:= a A^{a b c} + b A^{b a c};
\(\displaystyle{}\left(a -\,b\right) A^{a b c}\)
Not all expressions quadratic in the Riemann tensor are independent:
ex:=R_{a b c d} R_{a b c d} + R_{a b c d} R_{a c b d};
\(\displaystyle{}\frac{3}{2}\,R_{a b c d} R_{a b c d}\)
Here's an example that appears in a separate notebook elsewhere, now reduced to a single line.
W_{m n p q}::WeylTensor.
ex:= W_{p q r s} W_{p t r u} W_{t v q w} W_{u v s w} - W_{p q r s} W_{p q t u} W_{r v t w} W_{s v u w} - W_{m n a b} W_{n p b c} W_{m s c d} W_{s p d a} + (1/4) W_{m n a b} W_{p s b a} W_{m p c d} W_{n s d c};
\(\displaystyle{}0\,\)