# Substitute metric contraction to delta

+1 vote

Hello,

I was wondering how to make this contraction to be displayed as a delta automatically (without having to call substitute function everytime, as I don't know if there will be deltas or not until I've already done the calculation)

{a,b,c}::Indices.
g_{a b}::Metric.

d:=g_{a b} g^{b c};
eliminate_metric(_);


That is, the output is g_{a}^{c} and I'd like to get \delta_{a}^{c}.

\delta_{a}^{b}::KroneckerDelta.


or

g_{a}^{b}::KroneckerDelta.


before the calculations, but none of them work.

Thanks.

edited

+1 vote

In general, if you want to automatically run certain commands after each computation step, you need to redefine your post_process function. In your case, put

def post_process(ex):
eliminate_metric(ex)
collect_terms(ex)


at the top of your file. The default only contains the collect_terms(ex) line.

This way you have full control over which types of simplifications you want to run automatically.

selected

The problem is that what I get is

g_{a}^{c}


and what I expect is

\delta_{a}^{c}


I'm updating the question accordingly.

substitute(ex, $g_{a}^{b} = \delta_{a}^{b}$)


to your post_process function.

By the way, the property

g_{a}^{b}::KroneckerDelta.


only tells Cadabra that $g_{a}{}^{b}$ is a Kronecker delta. It does not tell it to display it as a $\delta_{a}{}^{b}$. If you want that to happen automatically, use

g_{a}^{b}::LaTeXForm("\delta").


This keeps it g_{a}^{b} internally, but displays as $\delta_{a}{}^{b}$.

substitute(ex, $g_{a}^{b} = \delta_{a}^{b}$)


Yes, I know that will definitely work, but I was thinking about why does it give that answer, as there does not exist a metric with one index of each kind, it's a Kronecker delta (and it's treated like that by cadabra).

My point is: don't you think that the substitution should be automatic?

If you want that to happen automatically, use

g_{a}^{b}::LaTeXForm("\delta").


This keeps it g_{a}^{b} internally, but displays as δab.

I tried

{a,b,c}::Indices.
g_{a b}::Metric.
g_{a}^{b}::LaTeXForm("\delta")

d:=g_{a b} g^{b c};
eliminate_metric(_);


And it doesn't work. What am I doing wrong?

There is something to be said for that, but in general Cadabra takes a 'conservative' approach in the sense of not pushing things down the users' throats.

Keep in mind that even though you define

 g_{a b}::Metric;


this does not attach any property to the g symbol with indices in different places. Yes, for a metric it probably would make sense to automatically attach meaning to the object with mixed and the object with upper indices, but at the moment it does not do that.

This works:

{a,b,c}::Indices(position=fixed).
g_{a b}::Metric.
g_{a}^{b}::LaTeXForm("\delta").

d:=g_{a b} g^{b c};
eliminate_metric(_);


Note that I added the position=fixed argument to the Indices property (to indicate that upper indices mean something different than lower indices) and I also added a full stop after the LaTeXForm property.

It doesn't work for me, it gives this:

g_{a b}*g^{b c}
g_{a}^{c}


LaTeXForm only works in the notebook interface, not on the command line.

OK, so I guess the only way to do that is by substituting in the post_process function. :_(

Thanks a lot for all your time and patience.