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

I need Cadabra to understand that the indices of derivatives can be swapped. For example, part of my expression looks like this:

2 \chi w**(3) M**(\xi+1) \delta{z} 
    \partial_{a b}{z} \partial_{a c d}{z} v_{b} v_{c} v_{d} - 
2 \chi w**(3) M**(\xi+1) \delta{z} 
    \partial_{a b}{z} \partial_{c d a}{z} v_{b} v_{c} v_{d}

In theory, these 2 terms should contract, but they do not.

The indices are given as:

{a,b,c,d,f,i,j,h,k,l,m,n,p,r,s,t,u,v,w,z}::Indices("flat",position = free).
{a,b,c,d,f,i,j,h,k,l,m,o,p,r,s,t,u,v,w,z}::Integer(1..N) .

Partial derivative as

\partial{#}::PartialDerivative.
in General questions by

1 Answer

0 votes

Hi bin_go.

I'm noting there is plenty of space in your code to improve, but I'm not here for that (in particular because I don't know your workcase scenario).

So, let me illustrate the use of the algorithm indexsort with an example inspired in your code.

My example

First, I'll define the indices and the symbol for the partial derivative.

{a,b,c,d}::Indices("flat",position = free).
{a,b,c,d}::Integer(1..N).
\partial{#}::PartialDerivative.

In this example, I'd define some functions of the "coordinates", but saying that they depends on the derivative

{z,w,v{#}}::Depends(\partial{#});

Define the expression

 ex := 2 \chi w**(3) M**(\xi+1) \delta{z} 
    \partial_{a b}{z} \partial_{a c d}{z} v_{b} v_{c} v_{d} - 
2 \chi w**(3) M**(\xi+1) \delta{z} 
    \partial_{a b}{z} \partial_{c d a}{z} v_{b} v_{c} v_{d};

Note that the result is not simplified, unless we sort the indices

 indexsort(ex);

Hope this would help.

Cheers, Dox.

by (15.0k points)

That helped, thank you very much!

You're welcome.

...