I have the following as the output of a calculation


and I would like Mathematica to evaluate this to zero. Is there a way to specify that for my purposes (-a).b is the same as -(a.b)?

(I've been searching for a solution and tried a number of things but thought it would be better to keep my question clear and concise not to distract with irrelevant descriptions of my attempts solving it.)

  • 4
    $\begingroup$ Try TensorExpand[a . b + (-a) . b] and report back. $\endgroup$ – J. M.'s ennui Jan 28 at 11:26
  • $\begingroup$ That solves it! Thank you very much. If you want you can submit it as an answer such that I can accept it. $\endgroup$ – Alwin Jan 28 at 11:59
  • 1
    $\begingroup$ Another way around: (a.b + (-a).b) /. (-x_).y_ :> -x.y returns zero. $\endgroup$ – Alexei Boulbitch Jan 28 at 13:11
  • $\begingroup$ Thank you for this alternative, it also works well for my purposes. But could you tell me why you use the :> operator and not the -> operator in the ReplaceAll command? The normal arrow also works for this example. I see that in the documentation they moslty use the normal arrow and sometimes the colon-arrow, though without explanation. It seems that the colon version is more used to replace patterns and normal arrow to replace symbols, but this is also not generally true. $\endgroup$ – Alwin Jan 29 at 14:28

Your Answer

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

Browse other questions tagged or ask your own question.