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

The following snippet shows the issue I'm having right now:

expr_test := \nabla_{\mu}{ A_{\alpha } } * \nabla^{\mu}{ A_{\beta} } + \nabla^{\mu}{ A_{\alpha } } * \nabla_{\mu}{ A_{\beta} };
sort_product(_);
sort_sum(_);
canonicalise(_);

At the end I still get:

\nabla_{\mu}{A_{\alpha}} \nabla^{\mu}{A_{\beta}}\discretionary{}{}{}
+
\nabla_{\mu}{A_{\beta}} \nabla^{\mu}{A_{\alpha}}

all indices are position=independent, but I tried switching to fixed and didn't help this particular issue.

Also, nabla is declared as:

\nabla{#}::Derivative.

But AFAIU the non-commutativity of Derivative should only affect order of indices, not the resulting object.

in General questions by (230 points)

1 Answer

0 votes

Make sure to reset your kernel if you change properties like this. For me, the following works:

{\mu,\nu,\alpha,\beta}::Indices(position=fixed);
\nabla{#}::Derivative;
expr_test := \nabla_{\mu}{ A_{\alpha } } * \nabla^{\mu}{ A_{\beta} } 
           + \nabla^{\mu}{ A_{\alpha } } * \nabla_{\mu}{ A_{\beta} };
canonicalise(_);

and returns $2\nabla^{\mu} A_{\alpha} \nabla_{\mu} A_{\beta}$.

The logic is that with position=independent, the canonicalise algorithm is not allowed to raise/lower the $\mu$ indices in pairs. With position=fixed, this is allowed.

by (86.5k points)

I tried restarting the kernel after making sure position is set to fixed, but still getting the same behaviour.

I'm using appImage version on ubuntu 22.04 (Version 2.5.14 (build 1.a4ab1c9 dated 2025-07-31), perhaps it's something elready fixed in development branch?

I just tried with that same AppImage, and the example in my post above works. Does that really not work for you in isolation?

This is the minimal notebook I can reproduce the issue:

import sympy
import cdb.core.manip as manip
import cdb.core.component as comp
import cdb.sympy.solvers as solv

coordinates=$t, r, \theta, \phi$;
coordinates::Coordinate.
index_list := {\mu,\nu,\rho,\sigma,\alpha,\beta,\gamma,\tau,\chi,\psi,\lambda,\lambda#}.
@(index_list)::SortOrder.
@(index_list)::Indices(spacetime, position=fixed, values=@(coordinates)).
Integer(index_list, Ex(rf"1..{len(coordinates)}"))

g_{\mu \nu}::Metric(signature=-1);
g^{\mu \nu}::InverseMetric(signature=-1);
g^{\mu}_{\nu}::KroneckerDelta;
g_{\mu}^{\nu}::KroneckerDelta;
\partial{#}::PartialDerivative;
\nabla{#}::Derivative;

A_{\mu}::Depends(coordinates ,\partial{#});

expr_test := \nabla_{\mu}{ A_{\alpha } } * \nabla^{\mu}{ A_{\beta} } + \nabla^{\mu}{ A_{\alpha } } * \nabla_{\mu}{ A_{\beta} };
eliminate_metric(_);
rename_dummies(_);
sort_product(_);
sort_sum(_);
canonicalise(_);

the result is 6 lines with the same output:

\nabla^{\mu}{A_{\alpha}} \nabla_{\mu}{A_{\beta}}\discretionary{}{}{}+\nabla^{\mu}{A_{\beta}} \nabla_{\mu}{A_{\alpha}}

just finished building from source, and I'm still seeing the same behavior running from the cli interface.

I noticed that the build added library dependencies from my anaconda3 environment, including libpython3.10.so. Cannot really think what else might be the source of discrepancy.

ok I think I found the reason of the discrepancy:

my test expression is this:

expr_test := \nabla_{\mu}{ A_{\alpha } } * \nabla^{\mu}{ A_{\beta} } + \nabla^{\mu}{ A_{\beta } } * \nabla_{\mu}{ A_{\alpha} };

yours is slightly different, and in fact if I try yours it canonicalises correctly:

expr_test := \nabla_{\mu}{ A_{\alpha } } * \nabla^{\mu}{ A_{\beta} } + \nabla^{\mu}{ A_{\alpha } } * \nabla_{\mu}{ A_{\beta} };

update:

canonicalise succeeds on your expression, but meld fails on it.

canonicalise fails on my expression, but meld succeeds on it

...