I'm manipulating abstract tensors with Mathematica. I have a question. With the assumptions

$Assumptions = (R | r) ∈ Arrays[{4}];

I can do two operations: R.r and TensorContract[R \[TensorProduct] r, {{1, 2}}] which are the same obviously. The problem is that doing

 R.r - TensorContract[R \[TensorProduct] r, {{1, 2}}]

I cannot get 0 as expected. I try to apply TensorReduce, TensorExpand, FullSimplify and their combination without any result. What can I do?

  • 1
    $\begingroup$ Mathematica's tensor abilities are still rather kludgy, and not as powerful as some its more well-developed capabilities. There may be a way to do this with a user-defined rule, and hopefully someone will provide an answer to that effect. In the meantime, I would suggest using one form or the other (not both) throughout your code to perform this operation. $\endgroup$ – Michael Seifert Sep 16 '16 at 17:53
  • 1
    $\begingroup$ Do you know if some effort is being made to develop these abilities (as well as indices manipulation) or Mathematica staff is not interested in this branch of developing? $\endgroup$ – MaPo Sep 16 '16 at 17:59
  • $\begingroup$ related: Ways to compute inner products of tensors, but this is different because it's about purely symbolic tensors. $\endgroup$ – Jens Sep 17 '16 at 15:56

You could use my TensorSimplify package to do this. Install the paclet with:

    "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"

Once installed, you can load the package with:


The basic issue is that TensorReduce does not handle a mixture of Dot and TensorContract objects very well. So, if one converts everything to the same types of objects (Dot or TensorContract), then TensorReduce will be able to make headway. The TensorSimplify package includes two functions to help with this: ToTensor and FromTensor. Let's see these in action:

$Assumptions = (R | r) \[Element] Arrays[{4}];
expr = R.r-TensorContract[TensorProduct[R, r], {{1, 2}}];




It turns out that TensorReduce is not even needed for this example. One could also use TensorSimplify:




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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