My goal is to algebraically simplify expressions involving tensor products and taking the trace.
That is, I would like to compute $\operatorname{Tr}\left( \prod_i(id+a_i \otimes b_i) \right)$,
using the rules of tensor algebra. E.g. $$\operatorname{Tr}(a_i \otimes b_i)=a_i.b_i$$ and $$a_1 \otimes b_1 a_2 \otimes b_2= b_1.a_2 a_1 \otimes b_2.$$
The final expression should be of the form
$$ \sum_i \prod_j a_{i_j}.b_{i_j}.$$
Any implementation to let Mathematica do this for me would be much appreciated.
So far I tried to use the built-in tensor algebra package
$Assumptions = {Element[a1, Vectors[3, Reals]],
Element[a2, Vectors[3, Reals]], Element[b1, Vectors[3, Reals]],
Element[b2, Vectors[3, Reals]], Element[n, Vectors[3, Reals]],
Element[m, Vectors[3, Reals]], Element[id, Matrices[{3, 3}]]};
and define simplification rules such as
SimId[expr_] :=
expr //. {Dot[id, tensor___] :> tensor, Dot[tensor___, id] :> tensor,
MatrixPower[id, 2] :> id, MatrixPower[id, 3] :> id,
MatrixPower[id, 4] :> id}
SimTP[expr_] :=
expr //. {Dot[TensorProduct[before1_, before2_],
TensorProduct[after1_, after2_]] :>
Dot[before2, after1] TensorProduct[before1, after2]}
This works fine for simple expressions such as
SimId[SimTP[
TensorProduct[a2 + b1,
n1].(id + TensorProduct[a1, a1 + b2]).TensorProduct[b1, b2] //
TensorExpand]]
However, once I enter more complex expressions, it seems to go wrong and give me
SimId[SimTP[
TensorProduct[a2, n1].TensorProduct[b2, n1].TensorProduct[a2,
b1].TensorProduct[a2, b2] // TensorExpand]]
I am still getting invalid expression of the form
a2.b1 (n1.b2 a2\[TensorProduct]n1).a2\[TensorProduct]b2
and they don't really make sense.
@
is already in use in Mathematica, seePrefix
$\endgroup$ – rhermans Feb 8 '16 at 19:32