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

Greetings,

This short example

{a,b,c,d,e,f#}::Indices.

foo := A^{a} A^{b} g_{a b}.
substitute (foo,$A^{a}->B^{a}$)

does what you'd expect. It returns

foo := B^{a} B^{b} g_{a b}

But the following code

foo := A^{a} A^{b} g_{a b}.
substitute (foo,$A^{a}->{B}^{a}$)

returns

foo := B B g_{a b}

Now that seems wrong to me.

Any thoughts?

My guess is that the curly-braces around B in the second assignment disconnects B from the following indices. Those indices are orphaned and are thus lost in the substitution.

The simple answer is -- Don't use unnecessary curly-braces.

Cheers, Leo

in Bug reports by (2.1k points)

1 Answer

+1 vote

Yes, the general advice is to not sprinkle curly braces around if you don't need them. I agree though that this is unexpected and should at least throw an error. I have added this to the issue tracker so it doesn't get lost, https://github.com/kpeeters/cadabra2/issues/355.

by (85.9k points)
...