Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+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}.

I've tried adding

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

or

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

before the calculations, but none of them work.

Thanks.

in General questions by (160 points)
edited by

1 Answer

+1 vote
 
Best answer

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.

by (83.1k points)
selected by

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.

Add

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}$.

Add

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

to your post_process function.

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?

Anyway, thanks a lot for your quick answer. =)

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}

I'm using cadabra 2.1.7.

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.

...