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

Hello,

I am trying to extract the free indices out of some expression, and the result seems to depend on the order of factors. For example:

{a,b,c,d#,z}::Indices.

ex:= 1/2 C^{a b c} D_{b} A_{c};
try:
    next(ex.top().free_indices())
    print("there's at least a free index")
except:
    print("no free indices!")

ex:= 1/2 D_{b} C^{a b c} A_{c};
try:
    next(ex.top().free_indices())
    print("there's at least a free index")
except:
    print("no free indices!")

ex:= 1/2 D_{b} A_{c} C^{a b c};
try:
    next(ex.top().free_indices())
    print("there's at least a free index")
except:
    print("no free indices!")

returns

 1/2 C^{a b c} D_{b} A_{c}
there's at least a free index
 1/2 D_{b} C^{a b c} A_{c}
no free indices!
 1/2 D_{b} A_{c} C^{a b c}
no free indices!
in Bug reports by (200 points)

1 Answer

0 votes

Well spotted, that's a bug indeed. It's fixed on github now.

by (82.6k points)

It works, thank you very much !

However, I still have the following problem:

ex:= 1/2 C^{a b c} D_{b} A_{c} - X_{b} C^{a b c} A_{c};
for i in ex.top().free_indices():
    print(i)

returns

 1/2 C^{a b c} D_{b} A_{c}-X_{b} C^{a b c} A_{c}
a
a

That's the expected result: there is one free index 'a' on the first term, and one on the second term. Consider this:

ex:= 1/2 C^{a b c} D_{b} A_{c} - X_{b} C^{a b c} A_{c};
q=0
for i in ex.top().free_indices():
   i.name='d'+str(q)
   q=q+1

ex;

It turns that expression into

1/2 C^{d0 b c} D_{b} A_{c} - X_{b} C^{d1 b c} A_{c};

(which is invalid, but that's not the point of course).

I see.

That means that if I want to get the name of the actual free index of the tensorial expression I need to do

ex:= 1/2 C^{a b c} D_{b} A_{c} - X_{b} C^{a b c} A_{c};
for i in next(ex.top().terms()).free_indices():
    print(i)

right?

In particular, the expand_nabla function always needs a prior distribute, right?

That next(ex.top().terms()) selects the 2nd term, so that's why that loop shows only one index. Yes, as it stands, that expand_nabla requires that you distribute first (it was only meant as an example).

You mean the first term right? Anyway, thank you very much for the clarifications !

Yes, sorry, I keep messing up python and C++ iterators.

...