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

Greetings,

I noticed that after a  recent commit (a44114a0d5) I now get an error for code that previously ran fine. Here is my minimal example

{a,b,c,d,e,f,g,h,i,j,k,l,m,n#}::Indices(values={x, y}).

Adn := { A_{x} = Ax, A_{y} = Ay }.
Aup := { A^{x} = Bx, A^{y} = By }.

myDot := A^{a} A_{a}.

evaluate (myDot, Aup+Adn)

I now get the following error

Traceback (most recent call last):   File "/opt/cadabra/bin/cadabra2", line 256, in \     exec(cmp)   File "foo.cdb", line 8, in \     evaluate (myDot, Aup+Adn) RuntimeError: substitute: Argument is neither a replacement rule nor an equality

I agree that I could manually add the pair of lists myself (and thus give Cadabra just one list) but I'd like to know how I can convince Cadabra to add this pair of lists. Is there a new way to combine lists?

Cheers, Leo

in Bug reports by (1.8k points)

2 Answers

+3 votes
 
Best answer

Apart from the 'tie' operator, there is now also the 'join' function. So you can do either

ex1:={A,B};
ex2:={C,D};
ex3:= @(ex1) ~ @(ex2);

to get {A,B,C,D}, or you can do

ex1:={A,B};
ex2:={C,D};
ex3 = join(ex1, ex2)

Join on a single element and a list will just add that element to the list, and join on two single elements will create a two-element list.

This was a quick hack not really thought through very deeply, so please report issues with this if you find any.

Added: Just to explain why this was all necessary: I am working on fast numerical evaluation of symbolic expressions. This frequently involves component-wise addition of lists or nested lists. Since both Numpy and Mathematica use '+' for component-wise list addition, I decided to follow that.

by (82.9k points)
selected by

Thank you K., this update is a great news for those who used the joined lists extensively!

Hi Kasper, I've tested the latest version of cadabra2 (on macOS silicon) and your changes work prefectly. Many thanks. I have many many cases where I join lists so this is great news. Thanks. Cheers, Leo

+3 votes

I have just pushed a change which enables the 'tie' operator '~' to join two lists in a Cadabra expression. Will still introduce something that works directly on two lists at Python level.

by (82.9k points)

Hi Kasper, Many thanks for the update. Much appreciated. Cheers, Leo

...