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

Hi Folks,

I know that the following code works

sub1 := {A_{x} -> Ax, A_{y} ->Ay, A_{z} -> Az};
sub2 := {B_{x} -> Bx, B_{y} ->By, B_{z} -> Bz};

foo := A_{a} B_{b};
evaluate (foo, sub1+sub2);

Is there a simple way to create a third rule such as

sub3 := sub1 + sub2;

so that I can use

evaluate (foo, sub3);

I know that this doesn't work but I'm wondering if there a correct way to construct sub3 from sub1 and sub2?

I'm asking this because I have some code that uses many many sub rules and my evaluate line is getting exceedingly long.

Cheers, Leo

in General questions by (1.8k points)

1 Answer

+1 vote
 
Best answer

It's easier than you think:

sub3 = sub1 + sub2

The reason is that 'sub1' and 'sub2' are both Python objects, and the line above simply does a Python addition and assigns that to Python object 'sub3'.

The := is to assign a Cadabra expression (the right-hand side) to a Python object (handle, the left-hand side).

by (82.6k points)
selected by

Ah, it's so easy. I'm pleased, many thanks.

...