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

I tried to substitute the delta symbol instead of the product of metrics, but the expression in the end somehow equals 0. Am I doing something wrong or is this a bug?

{a,b,c,d,e,f,g,h,i,j,k,l,m,n,q,r,s,u,v,w,z#}::Indices(position=independent).
h_{m n}::Metric.
h^{m n}::InverseMetric.
\delta^{m?}_{n?}::KroneckerDelta.
\delta_{m?}^{n?}::KroneckerDelta.
{\partial{#}}::PartialDerivative.
{\nabla{#},\delta{#}}::Derivative.
delh_{m n}::Depends(\nabla{#}, \partial{#}).
delh^{m n}::Depends(\nabla{#}, \partial{#}).
h_{m n}::Depends(\partial{#}, \delta{#}).
h^{m n}::Depends(\partial{#},\delta{#}).
\Dh::LaTeXForm("\sqrt{-h}").          
delh{#}::LaTeXForm("\delta h").  

ex:= \nabla_{a}{\nabla_{b}{delh^{c a}}}h_{c d} h^{d b};
substitute(ex, $h_{m1 m2} h^{m2 m3} -> \delta_{m1}^{m3}$);
in General questions by (1.8k points)

1 Answer

+1 vote

You cannot use \delta{#} for the Kronecker delta and the variational delta at the same time. By making \delta{#} a Derivative, the \delta_{m1}^{m3} gets interpreted as 'a second-order derivative in the m1 and m3 directions, acting on nothing', which is zero.

The least confusing is if you rename your variational delta (you can still use a LaTeXForm property to make it print as a $\delta$ symbol). Alternatively, be a bit less generic with your patterns, as in the working example below.

{a,b,c,d,e,f,g,h,i,j,k,l,m,n,q,r,s,u,v,w,z#}::Indices(position=independent).
h_{m n}::Metric.
h^{m n}::InverseMetric.
\delta^{m?}_{n?}::KroneckerDelta.
\delta_{m?}^{n?}::KroneckerDelta.
\partial{#}}::PartialDerivative.
{\nabla{#}, \delta{A??}}::Derivative.
delh_{m n}::Depends(\nabla{#}, \partial{#}).
delh^{m n}::Depends(\nabla{#}, \partial{#}).
h_{m n}::Depends(\partial{#}, \delta{#}).
h^{m n}::Depends(\partial{#}, \delta{#}).
\Dh::LaTeXForm("\sqrt{-h}").          
delh{#}::LaTeXForm("\delta h").  

ex:= \nabla_{a}{\nabla_{b}{delh^{c a}}} h_{c d} h^{d b};
substitute(ex, $h_{m1 m2} h^{m2 m3} -> \delta_{m1}^{m3}$);

To understand why this works, remember that the pattern # stands for 'any number of arguments', while A?? stands for 'any object'.

by (83.1k points)

Thank you, I really missed that.

...