I'd like my expressions like A^d get interpreted as MatrixPower[A, d] for matrix arguments A, any suggestions how to do this?

  • 3
    $\begingroup$ Power (^) is a built-in symbol. My suggestion: Don't mess with built-in symbols. You will be happier in the long run if you don't. $\endgroup$ Commented Sep 23, 2019 at 0:53
  • $\begingroup$ Yes, I'm aware this may break some things $\endgroup$ Commented Sep 23, 2019 at 1:15

1 Answer 1


One way to do it is to use Notation package.


distinguishMatrixPowerAndPower[A_, d_] := 
 If[SquareMatrixQ[A], MatrixPower[A, d], Power[A, d]]

Notation[A_^d_\[DoubleLongRightArrow]distinguishMatrixPowerAndPower[A_,d_]] (* this line is inserted using Notation Palette. *)

This is the result:

In[]:= {{1, 1}, {1, 2}}^2

Out[]= {{2, 3}, {3, 5}}

In[]:= 5^2

Out[]= 25

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.