I have written a larger code that uses the TensorSimplify package written by Carl Woll for tensor manipulations. The code, however, produces unexpected results, which I have been able to narrow down to a few lines using TensorProduct and subsequently TensorContract and FromTensor. Here is a typical example in a standalone form (including installation of the package):

  "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"];
<< TensorSimplify`
$Assumptions = {(u|v) \[Element] Vectors[d],A \[Element] Matrices[{d, d}]};
TensorContract[u\[TensorProduct]A\[TensorProduct]v, {{1, 3}, {2, 4}}] // FromTensor
TensorContract[A\[TensorProduct]u\[TensorProduct]v, {{1, 4}, {2, 3}}] // FromTensor

Both evaluation lines produce v.Transpose[A].u while I would in both cases expect v.A.u. Is there something trivial about the way that TensorContract or FromTensor works that I am misunderstanding?

  • 1
    $\begingroup$ This is a bug in FromTensor (I forgot that Dot[a] autoevaluates to a). I will push a fix tonight. $\endgroup$
    – Carl Woll
    Oct 3, 2019 at 21:49

1 Answer 1


This was a bug in my code, fixed with version 0.0.3. Should work now. From a fresh kernel:

$Assumptions={(u|v) ∈ Vectors[d],A ∈ Matrices[{d,d}]};
TensorContract[u \[TensorProduct] A \[TensorProduct]v,{{1,3},{2,4}}]//FromTensor
TensorContract[A \[TensorProduct] u \[TensorProduct]v,{{1,4},{2,3}}]//FromTensor



  • $\begingroup$ Fantastic!!! Thank you so much for the quick fix of the bug! $\endgroup$ Oct 4, 2019 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.