How can I automate this tensor computation?
You can write it directly as you see it
xxv[i_,j_,k_]:= 1/6( x[i]x[j]v[k]+x[i]x[k]v[j]
+x[j]x[i]v[k]+x[k]x[j]v[i]
+x[j]x[k]v[i]+x[k]x[i]v[j] )
-1/5( KroneckerDelta[i,j]Sum[x[l]x[l],{l,3}]v[k]
+KroneckerDelta[i,k]Sum[x[l]v[l],{l,3}]x[j]
+KroneckerDelta[j,k]Sum[x[l]v[l],{l,3}]x[i] )
FullSimplify[ Sum[xxv[i,j,k] xxv[i,j,k],{i,3},{j,3},{k,3}],
Assumptions->Sum[x[i]^2,{i,3}]==1
&&Sum[x[i]v[i],{i,3}]==xv
&&Sum[v[i]v[i],{i,3}]==vv]
Out[1]= 2/25 (4 vv + xv^2)
where I assumed that your vector x
is normalized
You can cast this as a symbolic tensor question, and make use of my TensorSimplify
package. Install the paclet with:
PacletInstall[
"TensorSimplify",
"Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"
]
Once installed, load the package with:
<<TensorSimplify`
Now, define your tensor using TensorProduct
:
XXV = 1/3 (TensorProduct[X,X,V] + TensorProduct[X,V,X] + TensorProduct[V,X,X]) -
1/5 (X.X TensorProduct[Inactive[IdentityMatrix][3], V] +
X.V TensorTranspose[TensorProduct[Inactive[IdentityMatrix][3],X],{1,3,2}] +
X.V TensorProduct[X,Inactive[IdentityMatrix][3]]
);
Note the use of Inactive[IdentityMatrix][3]
instead of IdentityMatrix[3]
. Then:
TensorSimplify[
TensorContract[TensorProduct[XXV, XXV], {{1, 4}, {2, 5}, {3, 6}}],
Assumptions -> (X|V) ∈ Vectors[3]
]
2/25 (V.X)^2 X.X + 8/25 V.V (X.X)^2
Using X.X == 1
reproduces your result.
This is how I'd do it; maybe it's useful for you.
Define $\vec{X}$ and $\vec{V}$ as vectors:
X = Array[x, 3];
V = Array[v, 3];
useful $3\times3\times3$ tensors for assembling:
a = Outer[Times, X, X, V];
b = (X.X) Outer[Times, IdentityMatrix[3], V];
c = (X.V) Outer[Times, IdentityMatrix[3], X];
assemble $XXV$:
XXV = (a + Transpose[a, {3, 1, 2}] + Transpose[a, {2, 3, 1}])/3 -
(b + Transpose[c, {3, 1, 2}] + Transpose[c, {2, 3, 1}])/5;
check a formula:
Total[XXV*XXV, 3] == 2/25 (X.X) ((X.V)^2 + 4 (X.X) (V.V)) // FullSimplify
(* True *)