This is a follow-up on / clarification of this thread.

I have the following in a notebook:

enter image description here

$Assumptions = A ∈ Matrices[{3,3},Reals] && B ∈ Matrices[{3,3},Reals]

(* MatrixPower[A + B, 2] *)

Apparently, TensorExpand does not expand the dot product if the two arguments of the dot product are equal. Is there any way I can expand these kinds of dot products of tensors in Mathematica, i.e. to get A.A + A.B + B.A + B.B in the above example?

  • 1
    $\begingroup$ Please always post copyable code, not just screenshots. $\endgroup$
    – Szabolcs
    Commented Oct 16, 2017 at 12:10
  • $\begingroup$ You could try Distribute. $\endgroup$
    – Szabolcs
    Commented Oct 16, 2017 at 12:13
  • 2
    $\begingroup$ Please add code examples as text instead of images. That makes it much easier for others to try your example and help you. $\endgroup$ Commented Oct 16, 2017 at 12:13
  • $\begingroup$ I'm not sure if MatrixPower works out of the box with Tensors. You could try building your own version, where you can build Dot in terms of TensorProduct and TensorContract as shown here in section Properties&Relations (search for: "TensorProduct, in combination with TensorContract, can be used to implement Dot:") $\endgroup$ Commented Oct 16, 2017 at 12:19
  • $\begingroup$ Added the copyable code. :) $\endgroup$
    – arriopolis
    Commented Oct 16, 2017 at 12:32

1 Answer 1


For this specific case, Distribute will work.

Distribute[(A + B).(A + B)]
(* A.A + A.B + B.A + B.B *)

(* A.B + B.A + MatrixPower[A, 2] + MatrixPower[B, 2] *)

Keep in mind that Distribute is a purely structural operation without any mathematical smarts.


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.