evaluate
Evaluate components of a tensor expression.
Given an abstract tensor expression and a set of rules for the components of tensors occurring in this
expression, evaluate the components of the full expression.
The minimal information needed for this to work is a declaration of the indices used, and a declaration
of the values that those indices use:{r,t}::Coordinate.
{m,n,p,s}::Indices(values={t,r}).
ex:= A_{n m} B_{m n p} ( C_{p s} + D_{s p} );
\(\displaystyle{}A_{n m} B_{m n p} \left(C_{p s} +D_{s p}\right)\)
A_{n m} B_{m n p} (C_{p s} + D_{s p})
The list of component values should be given just like the list of rules for the
substitute
algorithm,
that is, as equalitiesrl:= [ A_{r t} = 3, B_{t r t} = 2, B_{t r r} = 5, C_{t r} = 1, D_{r t} = r**2*t, D_{t r}=t**2 ];
\(\displaystyle{}\left[A_{r t} = 3, B_{t r t} = 2, B_{t r r} = 5, C_{t r} = 1, D_{r t} = {r}^{2} t, D_{t r} = {t}^{2}\right]\)
{A_{r t} = 3, B_{t r t} = 2, B_{t r r} = 5, C_{t r} = 1, D_{r t} = (r)**2 t, D_{t r} = (t)**2}
The
evaluate
algorithm then works out the values of the components of the ex
expression,
which will be denoted with a 'box' in its output,evaluate(ex, rl);
\(\displaystyle{}\square{}_{s}\left\{\begin{aligned}\square{}_{r}& = 6{r}^{2} t +6\\[-.5ex]
\square{}_{t}& = 15{t}^{2}\\[-.5ex]
\end{aligned}\right.
\)
\components_{s}({{r} = 6(r)**2 t + 6, {t} = 15(t)**2})
Note how the composite tensor of the original expression is now replaced with an 'anonymous tensor' represented by a box (which carries the free indices of the original expression), and all the components of the tensor are listed.
{i,j}::Indices(space).
{i,j}::Integer(1..3).
ex:= A_{i} B^{i}.
evaluate(ex);
\(\displaystyle{}A_{1} B^{1} +A_{2} B^{2} +A_{3} B^{3}\)
A_{1} B^{1} + A_{2} B^{2} + A_{3} B^{3}
ex:= A_{i} B^{i};
rl1:= { A_{1} = q1, A_{2} = q2 };
rl2:= { B^{1} = q3, B^{2} = q4 };
evaluate(ex, join(rl1, rl2));
\(\displaystyle{}A_{i} B^{i}\)
A_{i} B^{i}
\(\displaystyle{}\left[A_{1} = {q_{1}}, A_{2} = {q_{2}}\right]\)
{A_{1} = q1, A_{2} = q2}
\(\displaystyle{}\left[B^{1} = {q_{3}}, B^{2} = {q_{4}}\right]\)
{B^{1} = q3, B^{2} = q4}
\(\displaystyle{}{q_{1}} {q_{3}} +{q_{2}} {q_{4}}\)
q1 q3 + q2 q4
It often happens that you want to evaluate the components of a tensor only on the right-hand side of an equality, for instance when you are trying to build substitution or evaluation rules for subsequent steps. To do this, use the
rhsonly=True
parameter,ex2:= T_{m n} = A_{m p} B_{p n};
evaluate(ex2, rl, rhsonly=True);
\(\displaystyle{}T_{m n} = A_{m p} B_{p n}\)
T_{m n} = A_{m p} B_{p n}
\(\displaystyle{}T_{m n} = \square{}_{m}{}_{n}\left\{\begin{aligned}\square{}_{r}{}_{t}& = 3B_{t t}\\[-.5ex]
\square{}_{r}{}_{r}& = 3B_{t r}\\[-.5ex]
\end{aligned}\right.
\)
T_{m n} = \components_{m n}({{r, t} = 3B_{t t}, {r, r} = 3B_{t r}})