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


Is there a quick way to get around the error

RuntimeError: substitute: Index error in replacement rule. Triple index \sigma? inside a single factor found.

which appears even if all the indices involved are treated as symbols?

I'm attaching below a short code for this issue. It will be generalized to obtain some recurrence relations for operators in a nuclear physics setting.


{\Gamma^{\dagger}_{\tau?}, N_{a? \tau?}, G_{n? \sigma?}}::NonCommuting.
{\Gamma^{\dagger}_{\tau?}, N_{a? \tau?}}::Depends(\commutator{#});

rule:={N_{a? \tau?} G_{n?? \sigma?} -> n?? G_{(n??-1) \sigma?}
\commutator{N_{a? \tau?}}{\Gamma^{\dagger}_{\sigma?}} +1/2 n?? (n??-1)
\commutator{\commutator{N_{a? \tau?}}{\Gamma^{\dagger}_{\sigma?}}}{\Gamma^{\dagger}_{\sigma?}} G_{(n??-2) \sigma?}};

ex:=N_{a \tau} G_{n \sigma};

Thank you very much!

PS our paper introducing Cadabra to the nuclear physics community is out arXiv:1901.04759, hopefully soon to be published; thank you again!

asked in General questions by (180 points)
edited by

I have started adding the logic to make this possible, but it's slightly more complicated than I first thought. Give me another day or two. I'm very glad that you found Cadabra useful in the context of nuclear physics, and am happy to add other functionality you think is missing for your particular applications.


Thanks for your support! Sorry to bother you, I just wanted to ask if you think a fix is still feasible. Otherwise, I have to come up with some other way to do the computation. Thank you again!

1 Answer

+2 votes
Best answer

I have pushed a fix for this to github master just now. It took a little while longer than planned as this was probably the first time such expressions got tested properly, and in that process I ran into a subtle other substitute bug which I wanted to fix as well.

Let me know if this does what you need (or not, in which case I'll be happy to make more changes/fixes).

answered by (44.9k points)
selected by

Just tried a couple of small tests and they work now! I'm so excited! Thank you so much! I will keep you posted!

Sort product with symbols


I think I found a small bug in the conditional version of substitute with multiple symbol indices. Below is a sample code:

ex:=L_{1 2 3 4};
rule:=(L_{a?}_{b?}_{c?}_{d?} | a? > 3 -> L_{a?-1}_{b?}_{c?}_{d?});
ex:=A_{1} B_{2} C_{3} D_{4}};
rule2:=(A_{a?} B_{b?} C_{c?} D_{d?} | a? > 3 -> A_{a?-1} B_{b?} C_{c?} D_{d?});

I obtain L_{0234} although the condition is not met. The second expression is computed correctly (it remains unaltered).

Thank you!

This is now fixed on github, please let me know if I overlooked anything.

And just to clarify: the problem was caused by the fact that conditions on substitution rules with a single factor on the left-hand side were never evaluated.

Hi, sorry for the delay, I had to wait for some lengthy computations to finish before upgrading to the new version. It works perfectly now! Thank you!