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

I'm using the get_component function to obtain an expression. I'd like to assign the expression to a variable, in order for further processing it.

I've tried things like

A00 := get_component(A, $t,t$);

and

get_component(A, $t,t$)
A00 := _;

but I get a SyntaxError message.

Any ideas?

in General questions by (13.2k points)

1 Answer

+1 vote
 
Best answer

The get_component function returns a Python object, which you can directly assign to another symbol, e.g. A00. So a complete example would be

from cdb.core.component import *

{t,x}::Coordinate;
{i,j}::Indices(values={t,x});
ex:= a_{i};
evaluate(ex, $a_{t}=1, a_{x}=2$);

A00=get_component(ex, $x$)

and then A00 is a cadabra Ex object as usual.

by (76.4k points)
selected by

Dear Kasper, thank you for the answer. Actually, as you pointed, the equal sign assigns the value to A00. However, it seems that I cannot use the value for further manipulations.

I'm trying to write a demo notebook for students, and it occurs to me that it might be possible to solve the Schwarzschild spacetime. I got inspired by your notebook, but used

ss:= { g_{t t} = - \exp(A),
 g_{r r} = \exp(B),
 g_{\theta\theta} = r**2,
 g_{\phi\phi}=r**2 \sin(\theta)**2 }. 

for the metric.

After calculating the Ricci tensor rc, I call the components,

from cdb.core.component import *
r00=get_component(rc, $t,t$)[1];
r11=get_component(rc, $r,r$)[1];

but then I cannot use those expressions (it seems)

See image

Both r00 and r11 are Cadabra expressions. If you want to pull those into a mathematical expression elsewhere, you need to use @, as in

 exp1:= r  \exp( B - A ) @(r00) - @(r11);

Here r, A and B are mathematical symbols (not Python objects), and if you do not write @ then r00 and r11 would be seen as such too. If you want Cadabra to look up a Python expression, you need to say that explicitly with @.

I completely forgot the (at) symbols! Thank you again Kasper.

...