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

Mathematically I expect g(.,v) to be a co-vector. Now, given:

import cdb.core.component as comp
{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};
gv:=evaluate(ex,join(g,v), rhsonly=True)
w:=w_{a};

I would like to loop through components of gv and assign component values produce the desired co-vector w:

w_{b}=comp.get_component(w, b);

I have tried many approaches which fail.

in General questions by (230 points)
edited by

2 Answers

+1 vote

Hi, Paul If you write something like:

ex:= v_{b} = g_{a b} v^{a};
gv = evaluate(ex,join(g,v), rhsonly=True);
wb = comp.components_to_subrule(gv);

You get a list consisting of the components of the v_b co-vector.

by (1.7k points)

Thank you Arina for your answer.

I have a related question but I cannot think of a concise sentence that encapulates it.

I am not sure if this is what I really want as I get

<class 'cadabra2.Ex'> {g{0 0} = 28, g{0 1} = 2, g{1 0} = 3, g{1 1} = -1} <class 'cadabra2.Ex'> {v^{0} = 12, v^{1} = -11} <class 'cadabra2.Ex'> {v{1} → 303, v{1} → 35}

I was expecting "=" symbol not "->".

0 votes

Hi paul.

Following your approach

{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};

You can assing the evaluated expression to a variable using python's notation (the = asignation, not the := from cadabra)

evaluate(ex,join(g,v), rhsonly=True);
w = _;

If you want to loop the components of the resulting expression, I'd use (again) python's notation

import cdb.core.component as comp
for xx in range(2):
  comp.get_component(w, Ex(f"{xx}"));

Hope this would be useful. Dox.

by (14.8k points)
...