I would like to have TensorExpand
distribute across repeated matrices involving outer products. This question notes that TensorExpand
has a problem with expressions of a matrix raised to a power greater than one:
$Assumptions = u \[Element] Vectors[m, Reals] &&
A \[Element] Matrices[{m, m}, Reals] &&
B \[Element] Matrices[{m, m}, Reals];
TensorExpand[u . (A) . (A) .u ]
yields an expression involving MatrixProduct
, u.MatrixPower[A, 2].u
, whereas
TensorExpand[u . (A) . (B) .u ]
simply yields u.A.B.u
. The solution proposed by @Szabolcs is to use Distribute
:
Distribute[u . (A) . (A) .u ]
yields u.A.A.u
. However, this doesn't work if the matrices in the quadratic form involve outer products:
Idm = IdentityMatrix[m];
Distribute[ u . (Idm + u\[TensorProduct]u) . (Idm + u\[TensorProduct]u) .u ]
yields u.u + 2 (u.u)^2 + u.MatrixPower[u\[TensorProduct]u, 2].u
and just plain Distribute
doesn't simplify the outer products. How can I avoid this behavior? I.e, have the above evaluate to u.u + 2 (u.u)^2 + (u.u)^3
?