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

I am able to compute g(v,v) but have to repeat the definition of the component definitions (values or functions). Below is the is the code that "works" but it is strange that I have to repeat the definition of g and v in the line

evaluate(ex, $g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1, 
    v^{0}=12, v^{1}=-11 , v^{0}=12, v^{1}=-11$, rhsonly=True)

I want to write something like

evaluate(ex, [g, v])

or prefereably

evaluate(g(v,v))
 ############################ 
 #CODE

{m,n,a,b,c,d,q,r,s}::Indices(values={0,1}).
g_{a b}::Metric.
g^{a b}::InverseMetric.
g:={g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1}.
display(g)
display("......................0")
v:={v^{0}=12, v^{1}=-11}.
display(v)
display("......................1")
ex:=g_{a b} v^{b}.
display(ex)
display("......................2")
evaluate(ex, $v^{0}=12, v^{1}=-11$, rhsonly=True)
display(ex)
display("......................3")
ex:=g_{a b} v^{b}.
evaluate(ex, $g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1, v^{0}=12, v^{1}=-11$, rhsonly=True)
display(ex)
display("......................4")
ex:=g_{a b} v^{a} v^{b}.
display(ex)
display("......................5")
evaluate(ex, $g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1, v^{0}=12, v^{1}=-11 , v^{0}=12, v^{1}=-11$, rhsonly=True)
display(ex)
display("......................6")
in General questions by (210 points)
edited by

1 Answer

+1 vote

If you have the rules g and v which define the component values, you can feed those into evaluate. For example, to compute $g_{a b} v^{a} v^{b}$ with the values of your example, do

{m,n,a,b,c,d,q,r,s}::Indices(values={0,1}).
g_{a b}::Metric.
g^{a b}::InverseMetric.

g:={g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1};
v:={v^{0}=12, v^{1}=-11};

ex:=g_{a b} v^{a} v^{b};

evaluate(ex, join(g,v));

Does that answer your question?

by (80.4k points)

Thanks for your quick reply. It looks like I may be missing some library for join. Linux Debian Bullseye. Script file from commandline: usul@primate:~/Documents/projects/cadabra$ cadabra2 ss4.cdb

Traceback (most recent call last): File "/usr/bin/cadabra2", line 256, in exec(cmp) File "ss4.cdb", line 22, in evaluate(ex,join(g,v)); NameError: name 'join' is not defined

The join function was added in 2.4.0. If you type

__cdbkernel__.version;

you will see which version you have.

There is 2.4.5.3 available for Bullseye from the Cadabra download page, I should probably update that to the most current sometime soon.

For older versions you can, instead of join, just use +, so

evaluate(ex, g + v);

Indeed this works: g+v Thank you.

As for the version: usul@primate:~/Documents/projects/cadabra$ cdbkernel.version; bash: cdbkernel.version: command not found usul@primate:~/Documents/projects/cadabra$ dpkg -s cadabra | grep '^Version:' Version: 1.46-5 usul@primate:~/Documents/projects/cadabra$ dpkg -s cadabra2 | grep '^Version:' Version: 2.3.6.8-1

So I will download latest Bullseye.

But I only see Stretch and Buster.

For Bullseye: From synaptic I aleady installed cadabra2.

...